From 9f21eabe2188c78c1d67063a4469d8a6d6490dee Mon Sep 17 00:00:00 2001 From: Antonio Giner Date: Sun, 14 Aug 2016 23:55:45 +0200 Subject: [PATCH] Try to fix audio delay regression caused when fixing -refreshspeed for -sound xaudio2 --- src/osd/modules/sound/xaudio2_sound.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/osd/modules/sound/xaudio2_sound.cpp b/src/osd/modules/sound/xaudio2_sound.cpp index 1da4794501b..3fb02b13d54 100644 --- a/src/osd/modules/sound/xaudio2_sound.cpp +++ b/src/osd/modules/sound/xaudio2_sound.cpp @@ -596,6 +596,10 @@ 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 + if (state.BuffersQueued > 2) + m_sourceVoice->FlushSourceBuffers(); + std::lock_guard lock(m_buffer_lock); // Roll the buffer