From 47d8c77c6794de7fd1bdb3132399245d9c578a86 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 13 Sep 2023 10:27:11 -0400 Subject: [PATCH] audio: Choose better default sample frame counts. This might still need tweaking, but this is probably better than it was. --- src/audio/SDL_audio.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 15e28e793c..edcfd71a2b 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -1246,9 +1246,19 @@ static void PrepareAudioFormat(SDL_bool iscapture, SDL_AudioSpec *spec) } } -static int GetDefaultSampleFramesFromFreq(int freq) +static int GetDefaultSampleFramesFromFreq(const int freq) { - return SDL_powerof2((freq / 1000) * 46); // Pick the closest power-of-two to ~46 ms at desired frequency + if (freq <= 11025) { + return 512; + } else if (freq <= 22050) { + return 1024; + } else if (freq <= 48000) { + return 2048; + } else if (freq <= 96000) { + return 4096; + } else { + return 8192; // shrug + } } void SDL_UpdatedAudioDeviceFormat(SDL_AudioDevice *device)