aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2007-02-19 07:58:08 +0000
committerEric Wong <normalperson@yhbt.net>2007-02-19 07:58:08 +0000
commit08a7a86be21d98bc542988bb36c91c0747643435 (patch)
tree9527c69ef97d4a34dc2dd6822daabd39714c74e3
parent658b8f53df5e13711632a36741e7c2b7a46ae8aa (diff)
downloadmpd-08a7a86be21d98bc542988bb36c91c0747643435.tar.gz
mpd-08a7a86be21d98bc542988bb36c91c0747643435.tar.xz
mpd-08a7a86be21d98bc542988bb36c91c0747643435.zip
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
Diffstat (limited to '')
-rw-r--r--src/pcm_utils.c16
1 files changed, 12 insertions, 4 deletions
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);