aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-11-30 14:25:56 +0100
committerMax Kellermann <max@duempel.org>2008-11-30 14:25:56 +0100
commitf600f4a25619912080989912810543c80eebdee3 (patch)
tree488089fe771d697ca277d80f1bb7754ad710b244 /src
parenta7b692a1df0a064350b6746f3ca207e1f288822c (diff)
downloadmpd-f600f4a25619912080989912810543c80eebdee3.tar.gz
mpd-f600f4a25619912080989912810543c80eebdee3.tar.xz
mpd-f600f4a25619912080989912810543c80eebdee3.zip
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.
Diffstat (limited to '')
-rw-r--r--src/output/shout_mp3.c24
1 files changed, 15 insertions, 9 deletions
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");