From 83e3cd8be9ce97dc46165ebd03a78f6aa1106f60 Mon Sep 17 00:00:00 2001 From: reuk Date: Thu, 27 Nov 2025 17:10:22 +0000 Subject: [PATCH] WASAPI: Fix issue where current buffer size could be misreported in non-low-latency non-exclusive mode In shared mode (i.e. non-low-latency, non-exclusive) the driver has sole responsibility for setting the wakeup period, and this cannot be changed by the application. This change ensures that the audio device always uses the buffer size reported by the audio hardware, even when that differs from the buffer size that was requested by the program. --- .../native/juce_WASAPI_windows.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/juce_audio_devices/native/juce_WASAPI_windows.cpp b/modules/juce_audio_devices/native/juce_WASAPI_windows.cpp index 6c85b989ff..d47ab3d213 100644 --- a/modules/juce_audio_devices/native/juce_WASAPI_windows.cpp +++ b/modules/juce_audio_devices/native/juce_WASAPI_windows.cpp @@ -1375,8 +1375,21 @@ public: return lastError; } - currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize); - currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate; + currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate; + currentBufferSizeSamples = std::invoke ([&] + { + if (bufferSizeSamples <= 0) + return defaultBufferSize; + + if (deviceMode == WASAPIDeviceMode::shared) + { + // In shared mode, the wakeup period is decided by the driver, frequently around 10ms + return defaultBufferSize; + } + + return jmax (bufferSizeSamples, minBufferSize); + }); + lastKnownInputChannels = inputChannels; lastKnownOutputChannels = outputChannels;