From f600f4a25619912080989912810543c80eebdee3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 30 Nov 2008 14:25:56 +0100 Subject: shout: fixed the lame input buffer allocation "float (*lamebuf)[2] = g_malloc()" does NOT allocate two float* buffers. The formula is even wrong: it should be applied to LAME's output buffer, not its input buffer. Converted "lamebuf" to the two variables "left" and "right", and allocate them independently with the exact buffer size. Set right=left if mono output is configured. --- src/output/shout_mp3.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/output/shout_mp3.c b/src/output/shout_mp3.c index 5063470d7..7fae699b0 100644 --- a/src/output/shout_mp3.c +++ b/src/output/shout_mp3.c @@ -133,8 +133,7 @@ static int shout_mp3_encoder_encode(struct shout_data *sd, { const int16_t *src = (const int16_t*)chunk; unsigned int i; - int j; - float (*lamebuf)[2]; + float *left, *right; struct shout_buffer *buf = &(sd->buf); unsigned int samples; int bytes = audio_format_sample_size(&sd->audio_format); @@ -142,21 +141,28 @@ static int shout_mp3_encoder_encode(struct shout_data *sd, int bytes_out; samples = len / (bytes * sd->audio_format.channels); - /* rough estimate, from lame.h */ - lamebuf = g_malloc(sizeof(float) * (1.25 * samples + 7200)); + left = g_malloc(sizeof(left[0]) * samples); + if (sd->audio_format.channels > 1) + right = g_malloc(sizeof(left[0]) * samples); + else + right = left; /* this is for only 16-bit audio */ for (i = 0; i < samples; i++) { - for (j = 0; j < sd->audio_format.channels; j++) { - lamebuf[j][i] = *src++; - } + left[i] = src[0]; + if (right != left) + right[i] = src[1]; + src += sd->audio_format.channels; } - bytes_out = lame_encode_buffer_float(ld->gfp, lamebuf[0], lamebuf[1], + bytes_out = lame_encode_buffer_float(ld->gfp, left, right, samples, buf->data, sizeof(buf->data) - buf->len); - free(lamebuf); + + g_free(left); + if (right != left) + g_free(right); if (0 > bytes_out) { g_warning("error encoding lame buffer for shout\n"); -- cgit v1.2.3