From aca82f400ac8cbc0ae98279a0b56751f9dd9d959 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 25 Aug 2022 21:27:05 -0500 Subject: [PATCH] Never use fewer than 480 samples to avoid causing issues on PulseAudio systems Fixes #830 Fixes #858 --- app/streaming/audio/renderers/sdlaud.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/streaming/audio/renderers/sdlaud.cpp b/app/streaming/audio/renderers/sdlaud.cpp index 0d931a43..c9fcf26c 100644 --- a/app/streaming/audio/renderers/sdlaud.cpp +++ b/app/streaming/audio/renderers/sdlaud.cpp @@ -26,11 +26,10 @@ bool SdlAudioRenderer::prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATION* want.format = AUDIO_S16; want.channels = opusConfig->channelCount; - // This is supposed to be a power of 2, but our - // frames contain a non-power of 2 number of samples, - // so the slop would require buffering another full frame. - // Specifying non-Po2 seems to work for our supported platforms. - want.samples = opusConfig->samplesPerFrame; + // On PulseAudio systems, setting a value too small can cause underruns for other + // applications sharing this output device. We impose a floor of 480 samples (10 ms) + // to mitigate this issue. + want.samples = SDL_max(480, opusConfig->samplesPerFrame); m_FrameSize = opusConfig->samplesPerFrame * sizeof(short) * opusConfig->channelCount;