Fixed crash and garbled output when converting from F32 to S16 audio.

This commit is contained in:
Sam Lantinga 2013-07-25 18:11:09 -07:00
parent e2a14cf5dd
commit 5623b2c61d

View file

@ -360,9 +360,7 @@ SDL_RunAudio(void *devicep)
device->convert.len_mult; device->convert.len_mult;
} }
#endif #endif
stream_len = device->convert.len;
/* stream_len = device->convert.len; */
stream_len = device->spec.size;
} else { } else {
stream_len = device->spec.size; stream_len = device->spec.size;
} }
@ -958,12 +956,6 @@ open_audio_device(const char *devname, int iscapture,
return 0; 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 */ /* See if we need to do any conversion */
build_cvt = SDL_FALSE; build_cvt = SDL_FALSE;
if (obtained->freq != device->spec.freq) { if (obtained->freq != device->spec.freq) {
@ -987,6 +979,16 @@ open_audio_device(const char *devname, int iscapture,
build_cvt = SDL_TRUE; 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) { if (build_cvt) {
/* Build an audio conversion block */ /* Build an audio conversion block */
if (SDL_BuildAudioCVT(&device->convert, if (SDL_BuildAudioCVT(&device->convert,
@ -998,7 +1000,7 @@ open_audio_device(const char *devname, int iscapture,
return 0; return 0;
} }
if (device->convert.needed) { 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.len_ratio);
device->convert.buf = device->convert.buf =