From 30cf980dd60281de54e5478462eba9fb69b6ea65 Mon Sep 17 00:00:00 2001 From: Antonio Giner Date: Thu, 11 Aug 2016 13:58:20 +0200 Subject: [PATCH] Fix audio distortion with -refreshspeed and -sound xaudio2 (MT 06199) --- src/osd/modules/sound/xaudio2_sound.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/osd/modules/sound/xaudio2_sound.cpp b/src/osd/modules/sound/xaudio2_sound.cpp index dc14acff64d..1da4794501b 100644 --- a/src/osd/modules/sound/xaudio2_sound.cpp +++ b/src/osd/modules/sound/xaudio2_sound.cpp @@ -45,6 +45,7 @@ #define INITIAL_BUFFER_COUNT 4 #define SUBMIT_FREQUENCY_TARGET_MS 20 +#define RESAMPLE_TOLERANCE 1.20f //============================================================ // Macros @@ -494,7 +495,7 @@ void sound_xaudio2::create_buffers(const WAVEFORMATEX &format) // buffer size is equal to the bytes we need to hold in memory per X tenths of a second where X is audio_latency float audio_latency_in_seconds = m_audio_latency / 10.0f; UINT32 format_bytes_per_second = format.nSamplesPerSec * format.nBlockAlign; - UINT32 total_buffer_size = format_bytes_per_second * audio_latency_in_seconds; + UINT32 total_buffer_size = format_bytes_per_second * audio_latency_in_seconds * RESAMPLE_TOLERANCE; // We want to be able to submit buffers every X milliseconds // I want to divide these up into "packets" so figure out how many buffers we need @@ -595,10 +596,6 @@ 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 lock(m_buffer_lock); // Roll the buffer