Never use fewer than 480 samples to avoid causing issues on PulseAudio systems

Fixes #830
Fixes #858
This commit is contained in:
Cameron Gutman 2022-08-25 21:27:05 -05:00
parent c1f663cec1
commit aca82f400a

View File

@ -26,11 +26,10 @@ bool SdlAudioRenderer::prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATION*
want.format = AUDIO_S16; want.format = AUDIO_S16;
want.channels = opusConfig->channelCount; want.channels = opusConfig->channelCount;
// This is supposed to be a power of 2, but our // On PulseAudio systems, setting a value too small can cause underruns for other
// frames contain a non-power of 2 number of samples, // applications sharing this output device. We impose a floor of 480 samples (10 ms)
// so the slop would require buffering another full frame. // to mitigate this issue.
// Specifying non-Po2 seems to work for our supported platforms. want.samples = SDL_max(480, opusConfig->samplesPerFrame);
want.samples = opusConfig->samplesPerFrame;
m_FrameSize = opusConfig->samplesPerFrame * sizeof(short) * opusConfig->channelCount; m_FrameSize = opusConfig->samplesPerFrame * sizeof(short) * opusConfig->channelCount;