X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=mp3dec.c;h=763ca37f2288eab98d0bcb34d6f641f7d4b38793;hp=dd7887d51f830409289f389ffa4bd5fd9f897717;hb=cd8aecdb81f2ffb1a6e34a866d6156f8c915a467;hpb=40cbbb95e256e63e1e6958e9034311d4904604af diff --git a/mp3dec.c b/mp3dec.c index dd7887d5..763ca37f 100644 --- a/mp3dec.c +++ b/mp3dec.c @@ -1,22 +1,10 @@ /* - * Copyright (C) 2005-2006 Andre Noll + * Copyright (C) 2005-2008 Andre Noll * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Licensed under the GPL v2. For licencing details see COPYING. */ -/** \file mp3dec.c paraslash's mp3 decoder */ +/** \file mp3dec.c Paraslash's mp3 decoder. */ #include "para.h" #include "list.h" @@ -26,30 +14,23 @@ #include #include "string.h" -/** the output buffer size */ -#define MP3_OUTBUF_SIZE 128 * 1024 +/** The output buffer size. */ +#define MP3_OUTBUF_SIZE (128 * 1024) -/** \cond a helper macro */ -#define MAD_TO_SHORT(f) (f) >= MAD_F_ONE? SHRT_MAX :\ +/** Convert a sample value from libmad to a signed short. */ +#define MAD_TO_SHORT(f) (f) >= MAD_F_ONE? SHRT_MAX :\ (f) <= -MAD_F_ONE? -SHRT_MAX : (signed short) ((f) >> (MAD_F_FRACBITS - 15)) -/** \endcond */ -/** - * data specific to the mp3dec filter - * - * \sa filter, filter_node - */ +/** Data specific to the mp3dec filter. */ struct private_mp3dec_data { - /** information on the current mp3 stream */ + /** Information on the current mp3 stream. */ struct mad_stream stream; - /** information about the frame which is currently decoded */ + /** Information about the frame which is currently decoded. */ struct mad_frame frame; - /** contains the PCM output */ + /** Contains the PCM output. */ struct mad_synth synth; }; -/* TODO: Convert all input if possible */ -#define FRAME_HEADER_SIZE 4 static ssize_t mp3dec(char *inbuffer, size_t len, struct filter_node *fn) { int i, ret; @@ -62,11 +43,8 @@ static ssize_t mp3dec(char *inbuffer, size_t len, struct filter_node *fn) pmd->stream.error = 0; next_frame: ret = mad_header_decode(&pmd->frame.header, &pmd->stream); - if (ret < 0) { - if (!MAD_RECOVERABLE(pmd->stream.error)) - goto out; - return FRAME_HEADER_SIZE; - } + if (ret < 0) + goto out; fn->fc->samplerate = pmd->frame.header.samplerate; fn->fc->channels = MAD_NCHANNELS(&pmd->frame.header); ret = mad_frame_decode(&pmd->frame, &pmd->stream); @@ -79,14 +57,13 @@ next_frame: mad_synth_frame(&pmd->synth, &pmd->frame); for (i = 0; i < pmd->synth.pcm.length; i++) { - /* output format: unsigned 16 bit little endian */ - signed short s = MAD_TO_SHORT(pmd->synth.pcm.samples[0][i]); - fn->buf[fn->loaded++] = s & 0xff; - fn->buf[fn->loaded++] = s >> 8; + int s = MAD_TO_SHORT(pmd->synth.pcm.samples[0][i]); + write_int16_host_endian(fn->buf + fn->loaded, s); + fn->loaded += 2; if (MAD_NCHANNELS(&pmd->frame.header) == 2) { /* stereo */ s = MAD_TO_SHORT(pmd->synth.pcm.samples[1][i]); - fn->buf[fn->loaded++] = s & 0xff; - fn->buf[fn->loaded++] = s >> 8; + write_int16_host_endian(fn->buf + fn->loaded, s); + fn->loaded += 2; } if (fn->loaded != fn->bufsize) /* output buffer not full */ continue; @@ -98,8 +75,8 @@ next_frame: out: if (pmd->stream.next_frame) { /* we still have some data */ size_t off = pmd->stream.bufend - pmd->stream.next_frame; - PARA_DEBUG_LOG("converted %zd, rate: %u, returning %zd\n", len - off, - fn->fc->samplerate, copy - off); +// PARA_INFO_LOG("off: %zd, rate: %u, returning %zd\n", off, +// fn->fc->samplerate, copy - off); return copy - off; } return copy; @@ -131,10 +108,13 @@ static void mp3dec_open(struct filter_node *fn) fn->bufsize = MP3_OUTBUF_SIZE; fn->buf = para_calloc(fn->bufsize); } + /** - * the init function of the mp3dec filter + * The init function of the mp3dec filter. + * + * \param f Pointer to the filter struct to initialize. * - * \sa filter::init + * \sa filter::init. */ void mp3dec_init(struct filter *f) {