use the device channels and sample size when computing the default buffer size.

This commit is contained in:
Jeffery Myers 2025-04-16 18:13:41 -07:00
parent 5b940692ea
commit 5185d4c427

View file

@ -2104,8 +2104,12 @@ AudioStream LoadAudioStream(unsigned int sampleRate, unsigned int sampleSize, un
// The size of a streaming buffer must be at least double the size of a period // The size of a streaming buffer must be at least double the size of a period
unsigned int periodSize = AUDIO.System.device.playback.internalPeriodSizeInFrames; unsigned int periodSize = AUDIO.System.device.playback.internalPeriodSizeInFrames;
// If the buffer is not set, compute one that would give us a buffer good enough for a decent frame rate // If the buffer is not set, compute one that would give us a buffer good enough for a decent frame rate at the device bit size/rate
unsigned int subBufferSize = (AUDIO.Buffer.defaultSize == 0)? AUDIO.System.device.sampleRate/30 : AUDIO.Buffer.defaultSize; int deviceBitsPerSample = AUDIO.System.device.playback.format;
if (deviceBitsPerSample > 4) deviceBitsPerSample = 4;
deviceBitsPerSample *= AUDIO.System.device.playback.channels;
unsigned int subBufferSize = (AUDIO.Buffer.defaultSize == 0) ? (AUDIO.System.device.sampleRate / 30 * deviceBitsPerSample) : AUDIO.Buffer.defaultSize;
if (subBufferSize < periodSize) subBufferSize = periodSize; if (subBufferSize < periodSize) subBufferSize = periodSize;