From 8ca0c9bb7f04572c40cf72b8434c4de85d164e6a Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 25 Jul 2013 18:11:09 -0700 Subject: [PATCH] Fixed crash and garbled output when converting from F32 to S16 audio. --- src/audio/SDL_audio.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index a9c54b440..4d53e82b1 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -360,9 +360,7 @@ SDL_RunAudio(void *devicep) device->convert.len_mult; } #endif - - /* stream_len = device->convert.len; */ - stream_len = device->spec.size; + stream_len = device->convert.len; } else { stream_len = device->spec.size; } @@ -958,12 +956,6 @@ open_audio_device(const char *devname, int iscapture, return 0; } - /* If the audio driver changes the buffer size, accept it */ - if (device->spec.samples != obtained->samples) { - obtained->samples = device->spec.samples; - SDL_CalculateAudioSpec(obtained); - } - /* See if we need to do any conversion */ build_cvt = SDL_FALSE; if (obtained->freq != device->spec.freq) { @@ -987,6 +979,16 @@ open_audio_device(const char *devname, int iscapture, build_cvt = SDL_TRUE; } } + + /* If the audio driver changes the buffer size, accept it. + This needs to be done after the format is modified above, + otherwise it might not have the correct buffer size. + */ + if (device->spec.samples != obtained->samples) { + obtained->samples = device->spec.samples; + SDL_CalculateAudioSpec(obtained); + } + if (build_cvt) { /* Build an audio conversion block */ if (SDL_BuildAudioCVT(&device->convert, @@ -998,7 +1000,7 @@ open_audio_device(const char *devname, int iscapture, return 0; } if (device->convert.needed) { - device->convert.len = (int) (((double) obtained->size) / + device->convert.len = (int) (((double) device->spec.size) / device->convert.len_ratio); device->convert.buf =