mirror of
https://github.com/thepigeongenerator/sdl_template.git
synced 2025-12-17 05:55:47 +01:00
fix: not checking success for SDL_BuildAudioCVT
This commit is contained in:
@@ -64,7 +64,13 @@ static void audiomixer(void* const userdata, uint8_t* const stream, int32_t cons
|
||||
static int8_t audio_cvt(audiodevice const* dev, SDL_AudioSpec const* spec, uint8_t** bufptr, uint32_t* len) {
|
||||
// init the converter
|
||||
SDL_AudioCVT cvt;
|
||||
SDL_BuildAudioCVT(&cvt, spec->format, spec->channels, spec->freq, dev->fmt, dev->channels, dev->freq);
|
||||
if (SDL_BuildAudioCVT(&cvt, spec->format, spec->channels, spec->freq, dev->fmt, dev->channels, dev->freq) < 0) {
|
||||
error("%s:%u could not build the audio converter! SDL Error: %s", __FILE_NAME__, __LINE__, SDL_GetError());
|
||||
free(*bufptr); // free the buffer upon an error, as we won't be using this
|
||||
return 1;
|
||||
} else if (!cvt.needed) { // ensure the conversion is necessary
|
||||
return 0;
|
||||
}
|
||||
cvt.len = (*len) * spec->channels; // calculate the size of the source data in bytes by multiplying the length by the amount of channels (warn: uint32_t -> int32_t)
|
||||
cvt.buf = realloc(*bufptr, cvt.len * cvt.len_mult); // grow the inputted buffer for the conversion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user