Bug fix for SDL sound on FreeBSD OS (Issue #449). Force audio spec sample set size to be a power of 2 per SDL documentation.

This commit is contained in:
mjbudd77 2022-01-21 16:57:56 -05:00
parent 333d2364c1
commit ed4bb30ffe
1 changed files with 11 additions and 4 deletions

View File

@ -190,6 +190,7 @@ InitSound()
SDL_AudioSpec spec;
const char *driverName;
int frmRateSampleAdj = 0;
int samplesPerFrame;
g_config->getOption("SDL.Sound", &sound);
if (!sound)
@ -219,17 +220,23 @@ InitSound()
spec.freq = s_SampleRate = soundrate;
spec.format = AUDIO_S16SYS;
spec.channels = 1;
//spec.samples = 512;
spec.samples = (int)( ( (double)s_SampleRate / getBaseFrameRate() ) );
spec.samples = 512; // This must stay a power of two per SDL documentation
spec.callback = fillaudio;
spec.userdata = 0;
samplesPerFrame = (int)( ( (double)s_SampleRate / getBaseFrameRate() ) );
if ( samplesPerFrame >= 1024 )
{
spec.samples = 1024;
}
s_BufferSize = soundbufsize * soundrate / 1000;
// For safety, set a bare minimum:
if (s_BufferSize < spec.samples * 2)
if (s_BufferSize < spec.samples * 4)
{
s_BufferSize = spec.samples * 2;
s_BufferSize = spec.samples * 4;
}
s_BufferSize25 = s_BufferSize/4;
s_BufferSize50 = s_BufferSize/2;