Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed crash and garbled output when converting from F32 to S16 audio.
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jul 26, 2013
1 parent 9afe150 commit 8ca0c9b
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/audio/SDL_audio.c
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -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 =
Expand Down

0 comments on commit 8ca0c9b

Please sign in to comment.