From 42fff7ce2b619ce83b7db115e43dd853c97f7074 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 10 Oct 2017 22:18:46 -0400 Subject: [PATCH] audio: Don't stack-allocate resampler padding. (I thought padding size ranged from 5 frames to ~30 frames (based around RESAMPLER_ZERO_CROSSINGS, which is 5), but it's actually between 512 and several thousands (based on RESAMPLER_SAMPLES_PER_ZERO_CROSSING)). It gets big fast when downsampling. --- src/audio/SDL_audiocvt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/audio/SDL_audiocvt.c b/src/audio/SDL_audiocvt.c index 68e0b4cad0db0..073e7ee953ccd 100644 --- a/src/audio/SDL_audiocvt.c +++ b/src/audio/SDL_audiocvt.c @@ -722,16 +722,15 @@ SDL_ResampleCVT(SDL_AudioCVT *cvt, const int chans, const SDL_AudioFormat format SDL_assert(format == AUDIO_F32SYS); /* we keep no streaming state here, so pad with silence on both ends. */ - padding = SDL_stack_alloc(float, paddingsamples); + padding = (float *) SDL_calloc(paddingsamples, sizeof (float)); if (!padding) { SDL_OutOfMemory(); return; } - SDL_memset(padding, '\0', paddingsamples * sizeof (float)); cvt->len_cvt = SDL_ResampleAudio(chans, inrate, outrate, padding, padding, src, srclen, dst, dstlen); - SDL_stack_free(padding); + SDL_free(padding); SDL_memcpy(cvt->buf, dst, cvt->len_cvt); /* !!! FIXME: remove this if we can get the resampler to work in-place again. */