コード例 #1
0
ファイル: audio_importer.cpp プロジェクト: amzeratul/halley
std::vector<float> AudioImporter::resampleChannel(int from, int to, gsl::span<const float> src)
{
	AudioResampler resampler(from, to, 1, 1.0f);
	std::vector<float> dst(resampler.numOutputSamples(src.size()) + 1024);
	auto result = resampler.resampleInterleaved(src, dst);
	if (result.nRead != src.size()) {
		throw Exception("Only read " + toString(result.nRead) + " samples, expected " + toString(src.size()));
	}
	if (result.nWritten == dst.size()) {
		throw Exception("Resample dst buffer overflow.");
	}
	dst.resize(result.nWritten);
	return dst;
}
コード例 #2
0
ファイル: device.cpp プロジェクト: pakoito/TemplePlus
	VertexBufferPtr RenderingDevice::CreateVertexBufferRaw(gsl::span<const uint8_t> data) {
		CComPtr<IDirect3DVertexBuffer9> result;

		D3DLOG(mDevice->CreateVertexBuffer(data.size(), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &result, nullptr));

		void* dataOut;
		D3DLOG(result->Lock(0, data.size(), &dataOut, D3DLOCK_DISCARD));

		memcpy(dataOut, &data[0], data.size());

		D3DLOG(result->Unlock());

		return std::make_shared<VertexBuffer>(result, data.size());
	}
コード例 #3
0
ファイル: audio_importer.cpp プロジェクト: amzeratul/halley
static void writeBytes(Bytes& dst, gsl::span<const gsl::byte> src)
{
	size_t start = dst.size();
	size_t size = src.size();
	dst.resize(start + size);
	memcpy(dst.data() + start, src.data(), size);
}
コード例 #4
0
ファイル: buffer.hpp プロジェクト: janucaria/molphene
 void subdata(GLintptr offset, gsl::span<const data_type> cont) const noexcept
 {
   bind();
   glBufferSubData(target,
                   offset * sizeof(data_type),
                   cont.size() * sizeof(data_type),
                   cont.data());
 }
コード例 #5
0
ファイル: device.cpp プロジェクト: pakoito/TemplePlus
	IndexBufferPtr RenderingDevice::CreateIndexBuffer(gsl::span<const uint16_t> data) {
		CComPtr<IDirect3DIndexBuffer9> result;

		D3DLOG(mDevice->CreateIndexBuffer(data.size_bytes(),
			D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
			D3DFMT_INDEX16,
			D3DPOOL_DEFAULT,
			&result, nullptr));

		void* dataOut;
		D3DLOG(result->Lock(0, data.size(), &dataOut, D3DLOCK_DISCARD));

		memcpy(dataOut, &data[0], data.size() * sizeof(uint16_t));

		D3DLOG(result->Unlock());

		return std::make_shared<IndexBuffer>(result, data.size());
	}
コード例 #6
0
/** Ported more or less directly from SanOS. */
int Virtio::Queue::enqueue(gsl::span<Token> buffers){
  debug ("Enqueuing %i tokens \n", buffers.size());

  uint16_t last = _free_head;
  uint16_t first = _free_head;
  // Place each buffer in a token
  for( auto buf : buffers )  {
    debug (" buf @ %p \n", buffers.data());

    // Set read / write flags
    _queue.desc[_free_head].flags =
      buf.direction() ? VIRTQ_DESC_F_NEXT : VIRTQ_DESC_F_NEXT | VIRTQ_DESC_F_WRITE;

    // Assign raw buffer
    _queue.desc[_free_head].addr = (uint64_t) buf.data();
    _queue.desc[_free_head].len = buf.size();

    last = _free_head;
    _free_head = _queue.desc[_free_head].next;
  }

  _desc_in_flight += buffers.size();
  Ensures(_desc_in_flight <= size());

  // No continue on last buffer
  _queue.desc[last].flags &= ~VIRTQ_DESC_F_NEXT;


  // Place the head of this current chain in the avail ring
  uint16_t avail_index = (_queue.avail->idx + _num_added) % _size;

  // we added a token
  _num_added++;

  _queue.avail->ring[avail_index] = first;

  debug("<Q %i> avail_index: %i size: %i, _free_head %i \n",
        _pci_index, avail_index, size(), _free_head );

  debug ("Free tokens: %i \n", num_free());

  return buffers.size();
}
コード例 #7
0
ファイル: comm.cpp プロジェクト: PW-Sat2/PWSat2OBC
static gsl::span<std::uint8_t> ReceiveSpan(std::uint16_t frameSize, gsl::span<std::uint8_t> buffer)
{
    if (buffer.size() <= frameSize + 6)
    {
        return buffer;
    }
    else
    {
        return buffer.subspan(0, frameSize + 6);
    }
}
コード例 #8
0
ファイル: audio_sdl.cpp プロジェクト: amzeratul/halley
void AudioSDL::queueAudio(gsl::span<const AudioSamplePack> data)
{
	Expects(device);

	const size_t numSamples = data.size() * 16;

	// Float
	if (outputFormat.format == AudioSampleFormat::Float) {
		doQueueAudio(gsl::as_bytes(data));
	}
	
	// Int16
	else if (outputFormat.format == AudioSampleFormat::Int16) {
		if (tmpShort.size() < numSamples) {
			tmpShort.resize(numSamples);
		}
		for (ptrdiff_t i = 0; i < data.size(); ++i) {
			for (size_t j = 0; j < 16; ++j) {
				tmpShort[i * 16 + j] = static_cast<short>(data[i].samples[j] * 32768.0f);
			}
		}

		doQueueAudio(gsl::as_bytes(gsl::span<short>(tmpShort)));
	}
	
	// Int32
	else if (outputFormat.format == AudioSampleFormat::Int32) {
		if (tmpInt.size() < numSamples) {
			tmpInt.resize(numSamples);
		}
		for (ptrdiff_t i = 0; i < data.size(); ++i) {
			for (size_t j = 0; j < 16; ++j) {
				tmpInt[i * 16 + j] = static_cast<int>(data[i].samples[j] * 2147483648.0f);
			}
		}

		doQueueAudio(gsl::as_bytes(gsl::span<int>(tmpInt)));
	}
}
コード例 #9
0
ファイル: comm.cpp プロジェクト: PW-Sat2/PWSat2OBC
bool CommObject::ReceiveFrame(gsl::span<std::uint8_t> buffer, CommFrame& frame)
{
    if (buffer.size() < 2)
    {
        return false;
    }

    bool status = this->SendCommandWithResponse(CommReceiver, ReceiverGetFrame, buffer.subspan(0, 2));
    if (!status)
    {
        return status;
    }

    Reader reader(buffer.subspan(0, 2));
    auto size = reader.ReadWordLE();
    buffer = ReceiveSpan(size, buffer);
    status = this->SendCommandWithResponse(CommReceiver, ReceiverGetFrame, buffer);
    if (!status)
    {
        return status;
    }

    reader.Initialize(buffer);
    const auto fullSize = reader.ReadWordLE();
    const auto doppler = reader.ReadWordLE();
    const auto rssi = reader.ReadWordLE();
    gsl::span<std::uint8_t> frameContent;
    if (!reader.Status())
    {
        LOG(LOG_LEVEL_ERROR, "[comm] Failed to receive frame");
    }
    else
    {
        LOGF(LOG_LEVEL_DEBUG, "[comm] Received frame %d bytes", static_cast<int>(fullSize));
        auto span = reader.ReadArray(reader.RemainingSize());
        frameContent = gsl::span<std::uint8_t>(const_cast<std::uint8_t*>(span.data()), span.size());
    }

    frame = CommFrame(doppler, rssi, fullSize, std::move(frameContent));

    //    if (fullSize == 0 || (doppler & 0xf000) != 0 || (rssi & 0xf000) != 0)
    //    {
    //        LOGF(LOG_LEVEL_ERROR, "[comm] Received invalid frame. Size: %d, Doppler: 0x%X, RSSI: 0x%X. ", fullSize, doppler, rssi);
    //        return false;
    //    }

    return status;
}
コード例 #10
0
std::string
disassemble(const gsl::span<const uint8_t> &binary, bool isSubroutine)
{
   disassembler::State state;
   state.binary = binary;
   state.cfPC = 0;
   state.groupPC = 0;

   for (auto i = 0; i < binary.size(); i += sizeof(ControlFlowInst)) {
      auto cf = *reinterpret_cast<const ControlFlowInst *>(binary.data() + i);
      auto id = cf.word1.CF_INST();
      auto type = cf.word1.CF_INST_TYPE();

      switch (type) {
      case SQ_CF_INST_TYPE_NORMAL:
         disassembler::disassembleNormal(state, cf);
         break;
      case SQ_CF_INST_TYPE_EXPORT:
         disassembler::disassembleExport(state, cf);
         break;
      case SQ_CF_INST_TYPE_ALU:
      case SQ_CF_INST_TYPE_ALU_EXTENDED:
         disassembler::disassembleControlFlowALU(state, cf);
         break;
      default:
         decaf_abort(fmt::format("Invalid top level instruction type {}", type));
      }

      if (cf.word1.CF_INST() == SQ_CF_INST_RETURN && isSubroutine) {
         break;
      }

      if (cf.word1.CF_INST_TYPE() == SQ_CF_INST_TYPE_NORMAL
       || cf.word1.CF_INST_TYPE() == SQ_CF_INST_TYPE_EXPORT) {
         if (cf.word1.END_OF_PROGRAM()) {
            break;
         }
      }

      state.cfPC++;
      state.out << "\n";
   }

   return state.out.str();
}
コード例 #11
0
ファイル: network_service.cpp プロジェクト: amzeratul/halley
bool NetworkService::isValidConnectionRequest(gsl::span<const gsl::byte> data)
{
	HandshakeOpen open;
	return acceptingConnections && data.size() == sizeof(open) && memcmp(data.data(), &open, sizeof(open.handshake)) == 0;
}
コード例 #12
0
ファイル: buffer.hpp プロジェクト: janucaria/molphene
 void data(gsl::span<const data_type> cont) noexcept
 {
   size_ = cont.size();
   bind();
   glBufferData(target, size_bytes(), cont.data(), usage);
 }
コード例 #13
0
ファイル: aasrenderer.cpp プロジェクト: pakoito/TemplePlus
void AasRenderer::RenderShadowMapShadow(gsl::span<gfx::AnimatedModel*> models,
										gsl::span<const gfx::AnimatedModelParams*> modelParams,
										const XMFLOAT3 &center,
										float radius,
										float height,
										const XMFLOAT4 &lightDir,
										float alpha,
										bool softShadows) {

	Expects(models.size() == modelParams.size());

	float shadowMapWorldX, shadowMapWorldWidth,
		shadowMapWorldZ, shadowMapWorldHeight;

	if (lightDir.x < 0.0) {
		shadowMapWorldX = center.x - 2 * radius + lightDir.x * height;
		shadowMapWorldWidth = 4 * radius - lightDir.x * height;
	} else {
		shadowMapWorldX = center.x - 2 * radius;
		shadowMapWorldWidth = lightDir.x * height + 4 * radius;
	}

	if (lightDir.z < 0.0) {
		shadowMapWorldZ = center.z - 2 * radius + lightDir.z * height;
		shadowMapWorldHeight = 4 * radius - lightDir.z * height;
	} else {
		shadowMapWorldZ = center.z - 2 * radius;
		shadowMapWorldHeight = lightDir.z + height + 4 * radius;
	}

	CComPtr<IDirect3DSurface9> currentTarget;
	D3DLOG(mDevice.GetDevice()->GetRenderTarget(0, &currentTarget));
	D3DLOG(mDevice.GetDevice()->SetRenderTarget(0, mShadowTarget->GetSurface()));
	CComPtr<IDirect3DSurface9> depthStencil;
	mDevice.GetDevice()->GetDepthStencilSurface(&depthStencil);
	mDevice.GetDevice()->SetDepthStencilSurface(nullptr);

	mDevice.SetMaterial(mShadowMapMaterial);
	// Set shader params
	XMFLOAT4 floats{ shadowMapWorldX, shadowMapWorldZ, shadowMapWorldWidth, shadowMapWorldHeight };
	mDevice.GetDevice()->SetVertexShaderConstantF(0, &floats.x, 1);
	mDevice.GetDevice()->SetVertexShaderConstantF(1, &lightDir.x, 1);
	floats.x = center.y;
	mDevice.GetDevice()->SetVertexShaderConstantF(2, &floats.x, 1);
	XMCOLOR color(0, 0, 0, 0.5f);
	XMStoreFloat4(&floats, PackedVector::XMLoadColor(&color));
	mDevice.GetDevice()->SetVertexShaderConstantF(4, &floats.x, 1);

	D3DLOG(mDevice.GetDevice()->Clear(0, nullptr, D3DCLEAR_TARGET, 0, 0, 0));

	for (size_t i = 0; i < models.size(); ++i) {
		RenderWithoutMaterial(models[i], *modelParams[i]);
	}
		
	if (softShadows) {
		mDevice.SetMaterial(mGaussBlurHor);
		D3DLOG(mDevice.GetDevice()->SetRenderTarget(0, mShadowTargetTmp->GetSurface()));
		mShapeRenderer2d.DrawFullScreenQuad();

		mDevice.SetMaterial(mGaussBlurVer);
		D3DLOG(mDevice.GetDevice()->SetRenderTarget(0, mShadowTarget->GetSurface()));
		mShapeRenderer2d.DrawFullScreenQuad();
	}
	
	D3DLOG(mDevice.GetDevice()->SetRenderTarget(0, currentTarget));
	D3DLOG(mDevice.GetDevice()->SetDepthStencilSurface(depthStencil));

	auto shadowMapWorldBottom = shadowMapWorldZ + shadowMapWorldHeight;
	auto shadowMapWorldRight = shadowMapWorldX + shadowMapWorldWidth;

	std::array<gfx::ShapeVertex3d, 4> corners;
	corners[0].pos = { shadowMapWorldX, center.y, shadowMapWorldZ };
	corners[1].pos = { shadowMapWorldX, center.y, shadowMapWorldBottom };
	corners[2].pos = { shadowMapWorldRight, center.y, shadowMapWorldBottom };
	corners[3].pos = { shadowMapWorldRight, center.y, shadowMapWorldZ };
	corners[0].uv = { 0, 0 };
	corners[1].uv = { 0, 1 };
	corners[2].uv = { 1, 1 };
	corners[3].uv = { 1, 0 };

	mShapeRenderer3d.DrawQuad(corners, 0xFFFFFFFF, mShadowTarget);	

}
コード例 #14
0
void BufferObject::set_data(gsl::span<const gsl::byte> data, Usage usage) {
  bind();
  GL(glBufferData(GLenum(target_), data.size(), data.data(), GLenum(usage)));
}