diff options
author | 2016-08-17 23:40:50 -0400 | |
---|---|---|
committer | 2016-08-17 23:40:50 -0400 | |
commit | 6b83b0dbee760766c13b0150384da7342876255d (patch) | |
tree | 5821536a52618b72b3f44c6bdff883545f6e091f | |
parent | bffc4d03d8712d9090927d99a6a79e39ff78d812 (diff) |
Minor XAudio2 tweak to not always submit buffers if not needed (nw)
-rw-r--r-- | src/osd/modules/sound/xaudio2_sound.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/osd/modules/sound/xaudio2_sound.cpp b/src/osd/modules/sound/xaudio2_sound.cpp index 3fb02b13d54..f835f690644 100644 --- a/src/osd/modules/sound/xaudio2_sound.cpp +++ b/src/osd/modules/sound/xaudio2_sound.cpp @@ -229,6 +229,7 @@ public: m_overflows(0), m_underflows(0), m_in_underflow(FALSE), + XAudio2Create(nullptr), m_initialized(FALSE) { } @@ -596,11 +597,20 @@ void sound_xaudio2::submit_needed() XAUDIO2_VOICE_STATE state; m_sourceVoice->GetState(&state, XAUDIO2_VOICE_NOSAMPLESPLAYED); - // If we have a too many buffers on the queue, flush to resync + 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(); - - std::lock_guard<std::mutex> lock(m_buffer_lock); + m_overflows++; + } // Roll the buffer roll_buffer(); @@ -685,7 +695,7 @@ void sound_xaudio2::roll_buffer() m_writepos = 0; // We only want to keep a maximum number of buffers at any given time - // so remove any from queue greater than MAX_QUEUED_BUFFERS + // so remove any from queue greater than our target count if (m_queue.size() > m_buffer_count) { xaudio2_buffer *next_buffer = &m_queue.front(); |