Ejemplo n.º 1
0
// Submits any buffers that have currently been queued,
// assuming they are needed based on current queue depth
void sound_xaudio2::submit_needed()
{
	XAUDIO2_VOICE_STATE state;
	m_sourceVoice->GetState(&state, XAUDIO2_VOICE_NOSAMPLESPLAYED);

	std::lock_guard<std::mutex> lock(m_buffer_lock);

	// If we have buffers queued into XAudio and our current in-memory buffer
	// isn't yet full, there's no need to submit it
	if (state.BuffersQueued >= 1 && m_queue.empty())
		return;

	// We do however want to achieve some kind of minimal latency, so if the queued buffers
	// are greater than 2, flush them to re-sync the audio
	if (state.BuffersQueued > 2)
	{
		m_sourceVoice->FlushSourceBuffers();
		m_overflows++;
	}

	// Roll the buffer
	roll_buffer();

	// Submit the next buffer
	submit_next_queued();
}
Ejemplo n.º 2
0
void sound_xaudio2::update_audio_stream(
	bool is_throttled,
	INT16 const *buffer,
	int samples_this_frame)
{
	if ((sample_rate() == 0) || !m_buffer)
		return;

	UINT32 const bytes_this_frame = samples_this_frame * m_sample_bytes;

	std::lock_guard<std::mutex> lock(m_buffer_lock);

	UINT32 bytes_left = bytes_this_frame;

	while (bytes_left > 0)
	{
		UINT32 chunk = MIN(m_buffer_size, bytes_left);

		// Roll the buffer if needed
		if (m_writepos + chunk >= m_buffer_size)
		{
			roll_buffer();
		}

		// Copy in the data
		memcpy(m_buffer.get() + m_writepos, buffer, chunk);
		m_writepos += chunk;
		bytes_left -= chunk;
	}

	// Signal data available
	SetEvent(m_hEventDataAvailable);
}
Ejemplo n.º 3
0
void sound_xaudio2::update_audio_stream(
	bool is_throttled,
	int16_t const *buffer,
	int samples_this_frame)
{
	if (!m_initialized || sample_rate() == 0 || !m_buffer)
		return;

	uint32_t const bytes_this_frame = samples_this_frame * m_sample_bytes;

	std::lock_guard<std::mutex> lock(m_buffer_lock);

	uint32_t bytes_left = bytes_this_frame;

	while (bytes_left > 0)
	{
		uint32_t chunk = std::min(uint32_t(m_buffer_size), bytes_left);

		// Roll the buffer if needed
		if (m_writepos + chunk >= m_buffer_size)
		{
			roll_buffer();
		}

		// Copy in the data
		memcpy(m_buffer.get() + m_writepos, buffer, chunk);
		m_writepos += chunk;
		bytes_left -= chunk;
	}

	// Signal data available
	SetEvent(m_hEventDataAvailable);
}
Ejemplo n.º 4
0
// Submits any buffers that have currently been queued,
// assuming they are needed based on current queue depth
void sound_xaudio2::submit_needed()
{
	XAUDIO2_VOICE_STATE state;
	m_sourceVoice->GetState(&state, XAUDIO2_VOICE_NOSAMPLESPLAYED);

	// If we have a buffer on the queue, no reason to submit
	if (state.BuffersQueued >= 1)
		return;

	std::lock_guard<std::mutex> lock(m_buffer_lock);

	// Roll the buffer
	roll_buffer();

	// Submit the next buffer
	submit_next_queued();
}