From 08a7a86be21d98bc542988bb36c91c0747643435 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 19 Feb 2007 07:58:08 +0000 Subject: pcm_utils: fix libsamplerate compilation with non-C99 compilers Mixing code and declarations is ugly, anyways. We could probably get away with using alloca(), but I'm not sure how good compiler support is for that, either. It's probably more supported than mixed declarations and code. Nevertheless; we'll trigger memory checkers on exit because we don't free the buffers; but we won't actually leak because we reuse those buffers (just like the non-SRC code path). git-svn-id: https://svn.musicpd.org/mpd/trunk@5397 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/pcm_utils.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/pcm_utils.c b/src/pcm_utils.c index c93a2359e..dff698e71 100644 --- a/src/pcm_utils.c +++ b/src/pcm_utils.c @@ -288,6 +288,7 @@ void pcm_convertAudioFormat(AudioFormat * inFormat, char *inBuffer, size_t #ifdef HAVE_LIBSAMPLERATE static SRC_STATE *state = NULL; static SRC_DATA data; + static size_t data_in_size, data_out_size; int error; static double ratio = 0; double newratio; @@ -313,10 +314,17 @@ void pcm_convertAudioFormat(AudioFormat * inFormat, char *inBuffer, size_t data.output_frames = pcm_sizeOfOutputBufferForAudioFormatConversion(inFormat, dataChannelLen, outFormat) / 2 / outFormat->channels; data.src_ratio = (double)data.output_frames / (double)data.input_frames; - float conversionInBuffer[data.input_frames * outFormat->channels]; - float conversionOutBuffer[data.output_frames * outFormat->channels]; - data.data_in = conversionInBuffer; - data.data_out = conversionOutBuffer; + if (data_in_size != (data.input_frames * + outFormat->channels)) { + data_in_size = data.input_frames * outFormat->channels; + data.data_in = xrealloc(data.data_in, data_in_size); + } + if (data_out_size != (data.output_frames * + outFormat->channels)) { + data_out_size = data.output_frames * + outFormat->channels; + data.data_out = xrealloc(data.data_out, data_out_size); + } src_short_to_float_array((short *)dataChannelConv, data.data_in, data.input_frames * outFormat->channels); error = src_process(state, &data); -- cgit v1.2.3