From 731bc970fbee83f5a8ea22d9dccbb684531daa05 Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Thu, 22 Apr 2004 00:22:33 +0000 Subject: update libmad to 0.15.1b CVS patchset: 6419 CVS date: 2004/04/22 00:22:33 --- src/libmad/D.dat | 4 +- src/libmad/bit.c | 4 +- src/libmad/bit.h | 4 +- src/libmad/fixed.c | 48 +++++++++- src/libmad/frame.c | 20 ++-- src/libmad/frame.h | 7 +- src/libmad/global.h | 14 ++- src/libmad/huffman.c | 33 ++++--- src/libmad/huffman.h | 4 +- src/libmad/imdct_s.dat | 4 +- src/libmad/layer12.c | 66 ++++++++++--- src/libmad/layer12.h | 4 +- src/libmad/layer3.c | 244 ++++++++++++++++++++++++++++++++++++++++++++----- src/libmad/layer3.h | 4 +- src/libmad/stream.c | 5 +- src/libmad/stream.h | 5 +- src/libmad/synth.c | 4 +- src/libmad/synth.h | 4 +- src/libmad/timer.c | 18 ++-- src/libmad/timer.h | 4 +- src/libmad/version.c | 24 ++--- src/libmad/version.h | 14 +-- 22 files changed, 424 insertions(+), 114 deletions(-) diff --git a/src/libmad/D.dat b/src/libmad/D.dat index 8dd6feb25..31c6cd4fa 100644 --- a/src/libmad/D.dat +++ b/src/libmad/D.dat @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: D.dat,v 1.2 2002/04/30 18:46:58 miguelfreitas Exp $ + * $Id: D.dat,v 1.3 2004/04/22 00:22:33 miguelfreitas Exp $ */ /* diff --git a/src/libmad/bit.c b/src/libmad/bit.c index 200e3ab77..8d9571e8f 100755 --- a/src/libmad/bit.c +++ b/src/libmad/bit.c @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: bit.c,v 1.2 2002/04/30 18:46:58 miguelfreitas Exp $ + * $Id: bit.c,v 1.3 2004/04/22 00:22:35 miguelfreitas Exp $ */ # ifdef HAVE_CONFIG_H diff --git a/src/libmad/bit.h b/src/libmad/bit.h index 641b026be..6c09d5493 100644 --- a/src/libmad/bit.h +++ b/src/libmad/bit.h @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: bit.h,v 1.2 2002/04/30 18:46:58 miguelfreitas Exp $ + * $Id: bit.h,v 1.3 2004/04/22 00:22:36 miguelfreitas Exp $ */ # ifndef LIBMAD_BIT_H diff --git a/src/libmad/fixed.c b/src/libmad/fixed.c index d02a7299e..ae02360ca 100644 --- a/src/libmad/fixed.c +++ b/src/libmad/fixed.c @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: fixed.c,v 1.2 2002/04/30 18:46:58 miguelfreitas Exp $ + * $Id: fixed.c,v 1.3 2004/04/22 00:22:36 miguelfreitas Exp $ */ # ifdef HAVE_CONFIG_H @@ -35,3 +35,47 @@ mad_fixed_t mad_f_abs(mad_fixed_t x) { return x < 0 ? -x : x; } + +/* + * NAME: fixed->div() + * DESCRIPTION: perform division using fixed-point math + */ +mad_fixed_t mad_f_div(mad_fixed_t x, mad_fixed_t y) +{ + mad_fixed_t q, r; + unsigned int bits; + + q = mad_f_abs(x / y); + + if (x < 0) { + x = -x; + y = -y; + } + + r = x % y; + + if (y < 0) { + x = -x; + y = -y; + } + + if (q > mad_f_intpart(MAD_F_MAX) && + !(q == -mad_f_intpart(MAD_F_MIN) && r == 0 && (x < 0) != (y < 0))) + return 0; + + for (bits = MAD_F_FRACBITS; bits && r; --bits) { + q <<= 1, r <<= 1; + if (r >= y) + r -= y, ++q; + } + + /* round */ + if (2 * r >= y) + ++q; + + /* fix sign */ + if ((x < 0) != (y < 0)) + q = -q; + + return q << bits; +} diff --git a/src/libmad/frame.c b/src/libmad/frame.c index 537bc8da2..6fe1970c0 100755 --- a/src/libmad/frame.c +++ b/src/libmad/frame.c @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: frame.c,v 1.2 2002/04/30 18:46:58 miguelfreitas Exp $ + * $Id: frame.c,v 1.3 2004/04/22 00:22:36 miguelfreitas Exp $ */ # ifdef HAVE_CONFIG_H @@ -210,10 +210,17 @@ int decode_header(struct mad_header *header, struct mad_stream *stream) /* emphasis */ header->emphasis = mad_bit_read(&stream->ptr, 2); - if (header->emphasis == 2) { +# if defined(OPT_STRICT) + /* + * ISO/IEC 11172-3 says this is a reserved emphasis value, but + * streams exist which use it anyway. Since the value is not important + * to the decoder proper, we allow it unless OPT_STRICT is defined. + */ + if (header->emphasis == MAD_EMPHASIS_RESERVED) { stream->error = MAD_ERROR_BADEMPHASIS; return -1; } +# endif /* error_check() */ @@ -283,10 +290,6 @@ int free_bitrate(struct mad_stream *stream, struct mad_header const *header) stream->freerate = rate * 1000; -# if 0 && defined(DEBUG) - fprintf(stderr, "free bitrate == %lu\n", stream->freerate); -# endif - return 0; } @@ -373,7 +376,8 @@ int mad_header_decode(struct mad_header *header, struct mad_stream *stream) /* calculate free bit rate */ if (header->bitrate == 0) { - if ((stream->freerate == 0 || !stream->sync) && + if ((stream->freerate == 0 || !stream->sync || + (header->layer == MAD_LAYER_III && stream->freerate > 640000)) && free_bitrate(stream, header) == -1) goto fail; diff --git a/src/libmad/frame.h b/src/libmad/frame.h index b68777168..270420ab8 100755 --- a/src/libmad/frame.h +++ b/src/libmad/frame.h @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: frame.h,v 1.2 2002/04/30 18:46:58 miguelfreitas Exp $ + * $Id: frame.h,v 1.3 2004/04/22 00:22:36 miguelfreitas Exp $ */ # ifndef LIBMAD_FRAME_H @@ -42,7 +42,8 @@ enum mad_mode { enum mad_emphasis { MAD_EMPHASIS_NONE = 0, /* no emphasis */ MAD_EMPHASIS_50_15_US = 1, /* 50/15 microseconds emphasis */ - MAD_EMPHASIS_CCITT_J_17 = 3 /* CCITT J.17 emphasis */ + MAD_EMPHASIS_CCITT_J_17 = 3, /* CCITT J.17 emphasis */ + MAD_EMPHASIS_RESERVED = 2 /* unknown emphasis */ }; struct mad_header { diff --git a/src/libmad/global.h b/src/libmad/global.h index 8d6723016..2f4b41db5 100644 --- a/src/libmad/global.h +++ b/src/libmad/global.h @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: global.h,v 1.3 2003/02/28 02:51:49 storri Exp $ + * $Id: global.h,v 1.4 2004/04/22 00:22:36 miguelfreitas Exp $ */ # ifndef LIBMAD_GLOBAL_H @@ -39,7 +39,7 @@ # endif # if defined(OPT_SPEED) && !defined(OPT_SSO) -# define OPT_SSO 1 +# define OPT_SSO # endif # if defined(HAVE_UNISTD_H) && defined(HAVE_WAITPID) && \ @@ -47,4 +47,12 @@ # define USE_ASYNC # endif +# if !defined(HAVE_ASSERT_H) +# if defined(NDEBUG) +# define assert(x) /* nothing */ +# else +# define assert(x) do { if (!(x)) abort(); } while (0) +# endif +# endif + # endif diff --git a/src/libmad/huffman.c b/src/libmad/huffman.c index 58b8e7014..5d34c0142 100644 --- a/src/libmad/huffman.c +++ b/src/libmad/huffman.c @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: huffman.c,v 1.3 2002/04/30 18:46:58 miguelfreitas Exp $ + * $Id: huffman.c,v 1.4 2004/04/22 00:22:36 miguelfreitas Exp $ */ # ifdef HAVE_CONFIG_H @@ -34,13 +34,19 @@ * These tables support decoding up to 4 Huffman code bits at a time. */ -# if defined(__GNUC__) -# define PTR(offs, bits) { ptr: { 0, bits, offs } } -# define V(v, w, x, y, hlen) { value: { 1, hlen, v, w, x, y } } +# if defined(__GNUC__) || \ + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901) +# define PTR(offs, bits) { .ptr = { 0, bits, offs } } +# define V(v, w, x, y, hlen) { .value = { 1, hlen, v, w, x, y } } # else # define PTR(offs, bits) { { 0, bits, offs } } -# define V(v, w, x, y, hlen) { { 1, hlen, (v << 0) | (w << 1) | \ - (x << 2) | (y << 3) } } +# if defined(WORDS_BIGENDIAN) +# define V(v, w, x, y, hlen) { { 1, hlen, (v << 11) | (w << 10) | \ + (x << 9) | (y << 8) } } +# else +# define V(v, w, x, y, hlen) { { 1, hlen, (v << 0) | (w << 1) | \ + (x << 2) | (y << 3) } } +# endif # endif static @@ -106,12 +112,17 @@ union huffquad const hufftabB[] = { # undef V # undef PTR -# if defined(__GNUC__) -# define PTR(offs, bits) { ptr: { 0, bits, offs } } -# define V(x, y, hlen) { value: { 1, hlen, x, y } } +# if defined(__GNUC__) || \ + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901) +# define PTR(offs, bits) { .ptr = { 0, bits, offs } } +# define V(x, y, hlen) { .value = { 1, hlen, x, y } } # else # define PTR(offs, bits) { { 0, bits, offs } } -# define V(x, y, hlen) { { 1, hlen, (x << 0) | (y << 4) } } +# if defined(WORDS_BIGENDIAN) +# define V(x, y, hlen) { { 1, hlen, (x << 8) | (y << 4) } } +# else +# define V(x, y, hlen) { { 1, hlen, (x << 0) | (y << 4) } } +# endif # endif static diff --git a/src/libmad/huffman.h b/src/libmad/huffman.h index 4a21c1cb9..2f00c00a1 100644 --- a/src/libmad/huffman.h +++ b/src/libmad/huffman.h @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: huffman.h,v 1.3 2002/04/30 18:46:58 miguelfreitas Exp $ + * $Id: huffman.h,v 1.4 2004/04/22 00:22:41 miguelfreitas Exp $ */ # ifndef LIBMAD_HUFFMAN_H diff --git a/src/libmad/imdct_s.dat b/src/libmad/imdct_s.dat index 1974f3d3d..c938859e0 100644 --- a/src/libmad/imdct_s.dat +++ b/src/libmad/imdct_s.dat @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: imdct_s.dat,v 1.2 2002/04/30 18:46:58 miguelfreitas Exp $ + * $Id: imdct_s.dat,v 1.3 2004/04/22 00:22:41 miguelfreitas Exp $ */ /* 0 */ { MAD_F(0x09bd7ca0) /* 0.608761429 */, diff --git a/src/libmad/layer12.c b/src/libmad/layer12.c index 32feab351..25fd04d70 100755 --- a/src/libmad/layer12.c +++ b/src/libmad/layer12.c @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: layer12.c,v 1.2 2002/04/30 18:46:58 miguelfreitas Exp $ + * $Id: layer12.c,v 1.3 2004/04/22 00:22:41 miguelfreitas Exp $ */ # ifdef HAVE_CONFIG_H @@ -42,7 +42,7 @@ * used in both Layer I and Layer II decoding */ static -mad_fixed_t const sf_table[63] = { +mad_fixed_t const sf_table[64] = { # include "sf_table.dat" }; @@ -163,10 +163,17 @@ int mad_layer_I(struct mad_stream *stream, struct mad_frame *frame) if (allocation[ch][sb]) { scalefactor[ch][sb] = mad_bit_read(&stream->ptr, 6); +# if defined(OPT_STRICT) + /* + * Scalefactor index 63 does not appear in Table B.1 of + * ISO/IEC 11172-3. Nonetheless, other implementations accept it, + * so we only reject it if OPT_STRICT is defined. + */ if (scalefactor[ch][sb] == 63) { stream->error = MAD_ERROR_BADSCALEFACTOR; return -1; } +# endif } } } @@ -334,20 +341,44 @@ int mad_layer_II(struct mad_stream *stream, struct mad_frame *frame) if (header->flags & MAD_FLAG_LSF_EXT) index = 4; + else if (header->flags & MAD_FLAG_FREEFORMAT) + goto freeformat; else { - switch (nch == 2 ? header->bitrate / 2 : header->bitrate) { - case 32000: - case 48000: - index = (header->samplerate == 32000) ? 3 : 2; - break; + unsigned long bitrate_per_channel; + + bitrate_per_channel = header->bitrate; + if (nch == 2) { + bitrate_per_channel /= 2; + +# if defined(OPT_STRICT) + /* + * ISO/IEC 11172-3 allows only single channel mode for 32, 48, 56, and + * 80 kbps bitrates in Layer II, but some encoders ignore this + * restriction. We enforce it if OPT_STRICT is defined. + */ + if (bitrate_per_channel <= 28000 || bitrate_per_channel == 40000) { + stream->error = MAD_ERROR_BADMODE; + return -1; + } +# endif + } + else { /* nch == 1 */ + if (bitrate_per_channel > 192000) { + /* + * ISO/IEC 11172-3 does not allow single channel mode for 224, 256, + * 320, or 384 kbps bitrates in Layer II. + */ + stream->error = MAD_ERROR_BADMODE; + return -1; + } + } - case 56000: - case 64000: - case 80000: + if (bitrate_per_channel <= 48000) + index = (header->samplerate == 32000) ? 3 : 2; + else if (bitrate_per_channel <= 80000) index = 0; - break; - - default: + else { + freeformat: index = (header->samplerate == 48000) ? 0 : 1; } } @@ -431,12 +462,19 @@ int mad_layer_II(struct mad_stream *stream, struct mad_frame *frame) if (scfsi[ch][sb] & 1) scalefactor[ch][sb][1] = scalefactor[ch][sb][scfsi[ch][sb] - 1]; +# if defined(OPT_STRICT) + /* + * Scalefactor index 63 does not appear in Table B.1 of + * ISO/IEC 11172-3. Nonetheless, other implementations accept it, + * so we only reject it if OPT_STRICT is defined. + */ if (scalefactor[ch][sb][0] == 63 || scalefactor[ch][sb][1] == 63 || scalefactor[ch][sb][2] == 63) { stream->error = MAD_ERROR_BADSCALEFACTOR; return -1; } +# endif } } } diff --git a/src/libmad/layer12.h b/src/libmad/layer12.h index 5518c3818..645bb6405 100644 --- a/src/libmad/layer12.h +++ b/src/libmad/layer12.h @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: layer12.h,v 1.2 2002/04/30 18:46:58 miguelfreitas Exp $ + * $Id: layer12.h,v 1.3 2004/04/22 00:22:49 miguelfreitas Exp $ */ # ifndef LIBMAD_LAYER12_H diff --git a/src/libmad/layer3.c b/src/libmad/layer3.c index 5e3214b39..c0f59dfd5 100755 --- a/src/libmad/layer3.c +++ b/src/libmad/layer3.c @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: layer3.c,v 1.5 2003/12/07 15:34:30 f1rmb Exp $ + * $Id: layer3.c,v 1.6 2004/04/22 00:23:03 miguelfreitas Exp $ */ # ifdef HAVE_CONFIG_H @@ -28,13 +28,16 @@ # include # include +# ifdef HAVE_ASSERT_H +# include +# endif + # ifdef HAVE_LIMITS_H # include # else # define CHAR_BIT 8 # endif -# include "xineutils.h" # include "fixed.h" # include "bit.h" # include "stream.h" @@ -285,8 +288,8 @@ unsigned char const sfb_8000_short[] = { # define sfb_12000_mixed sfb_16000_mixed # define sfb_11025_mixed sfb_12000_mixed -/* the 8000 Hz short block scalefactor bands do not break after the first 36 - frequency lines, so this is probably wrong */ +/* the 8000 Hz short block scalefactor bands do not break after + the first 36 frequency lines, so this is probably wrong */ static unsigned char const sfb_8000_mixed[] = { /* long */ 12, 12, 12, @@ -379,7 +382,7 @@ mad_fixed_t const ca[8] = { * IMDCT coefficients for short blocks * derived from section 2.4.3.4.10.2 of ISO/IEC 11172-3 * - * imdct_s[i/even][k] = cos((PI / 24) * (2 * (i / 2) + 7) * (2 * k + 1)) + * imdct_s[i/even][k] = cos((PI / 24) * (2 * (i / 2) + 7) * (2 * k + 1)) * imdct_s[i /odd][k] = cos((PI / 24) * (2 * (6 + (i-1)/2) + 7) * (2 * k + 1)) */ static @@ -458,7 +461,7 @@ mad_fixed_t const is_table[7] = { * derived from section 2.4.3.2 of ISO/IEC 13818-3 * * is_lsf_table[0][i] = (1 / sqrt(sqrt(2)))^(i + 1) - * is_lsf_table[1][i] = (1 / sqrt(2))^(i + 1) + * is_lsf_table[1][i] = (1 / sqrt(2)) ^(i + 1) */ static mad_fixed_t const is_lsf_table[2][15] = { @@ -1247,7 +1250,7 @@ enum mad_error III_huffdecode(struct mad_bitptr *ptr, mad_fixed_t xr[576], } } - _x_assert(-bits_left <= (MAD_BUFFER_GUARD * CHAR_BIT)); + assert(-bits_left <= MAD_BUFFER_GUARD * CHAR_BIT); # if 0 && defined(DEBUG) if (bits_left < 0) @@ -1572,6 +1575,193 @@ void III_aliasreduce(mad_fixed_t xr[576], int lines) # if defined(ASO_IMDCT) void III_imdct_l(mad_fixed_t const [18], mad_fixed_t [36], unsigned int); # else +# if 1 +static +void fastsdct(mad_fixed_t const x[9], mad_fixed_t y[18]) +{ + mad_fixed_t a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12; + mad_fixed_t a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25; + mad_fixed_t m0, m1, m2, m3, m4, m5, m6, m7; + + enum { + c0 = MAD_F(0x1f838b8d), /* 2 * cos( 1 * PI / 18) */ + c1 = MAD_F(0x1bb67ae8), /* 2 * cos( 3 * PI / 18) */ + c2 = MAD_F(0x18836fa3), /* 2 * cos( 4 * PI / 18) */ + c3 = MAD_F(0x1491b752), /* 2 * cos( 5 * PI / 18) */ + c4 = MAD_F(0x0af1d43a), /* 2 * cos( 7 * PI / 18) */ + c5 = MAD_F(0x058e86a0), /* 2 * cos( 8 * PI / 18) */ + c6 = -MAD_F(0x1e11f642) /* 2 * cos(16 * PI / 18) */ + }; + + a0 = x[3] + x[5]; + a1 = x[3] - x[5]; + a2 = x[6] + x[2]; + a3 = x[6] - x[2]; + a4 = x[1] + x[7]; + a5 = x[1] - x[7]; + a6 = x[8] + x[0]; + a7 = x[8] - x[0]; + + a8 = a0 + a2; + a9 = a0 - a2; + a10 = a0 - a6; + a11 = a2 - a6; + a12 = a8 + a6; + a13 = a1 - a3; + a14 = a13 + a7; + a15 = a3 + a7; + a16 = a1 - a7; + a17 = a1 + a3; + + m0 = mad_f_mul(a17, -c3); + m1 = mad_f_mul(a16, -c0); + m2 = mad_f_mul(a15, -c4); + m3 = mad_f_mul(a14, -c1); + m4 = mad_f_mul(a5, -c1); + m5 = mad_f_mul(a11, -c6); + m6 = mad_f_mul(a10, -c5); + m7 = mad_f_mul(a9, -c2); + + a18 = x[4] + a4; + a19 = 2 * x[4] - a4; + a20 = a19 + m5; + a21 = a19 - m5; + a22 = a19 + m6; + a23 = m4 + m2; + a24 = m4 - m2; + a25 = m4 + m1; + + /* output to every other slot for convenience */ + + y[ 0] = a18 + a12; + y[ 2] = m0 - a25; + y[ 4] = m7 - a20; + y[ 6] = m3; + y[ 8] = a21 - m6; + y[10] = a24 - m1; + y[12] = a12 - 2 * a18; + y[14] = a23 + m0; + y[16] = a22 + m7; +} + +static inline +void sdctII(mad_fixed_t const x[18], mad_fixed_t X[18]) +{ + mad_fixed_t tmp[9]; + int i; + + /* scale[i] = 2 * cos(PI * (2 * i + 1) / (2 * 18)) */ + static mad_fixed_t const scale[9] = { + MAD_F(0x1fe0d3b4), MAD_F(0x1ee8dd47), MAD_F(0x1d007930), + MAD_F(0x1a367e59), MAD_F(0x16a09e66), MAD_F(0x125abcf8), + MAD_F(0x0d8616bc), MAD_F(0x08483ee1), MAD_F(0x02c9fad7) + }; + + /* divide the 18-point SDCT-II into two 9-point SDCT-IIs */ + + /* even input butterfly */ + + for (i = 0; i < 9; i += 3) { + tmp[i + 0] = x[i + 0] + x[18 - (i + 0) - 1]; + tmp[i + 1] = x[i + 1] + x[18 - (i + 1) - 1]; + tmp[i + 2] = x[i + 2] + x[18 - (i + 2) - 1]; + } + + fastsdct(tmp, &X[0]); + + /* odd input butterfly and scaling */ + + for (i = 0; i < 9; i += 3) { + tmp[i + 0] = mad_f_mul(x[i + 0] - x[18 - (i + 0) - 1], scale[i + 0]); + tmp[i + 1] = mad_f_mul(x[i + 1] - x[18 - (i + 1) - 1], scale[i + 1]); + tmp[i + 2] = mad_f_mul(x[i + 2] - x[18 - (i + 2) - 1], scale[i + 2]); + } + + fastsdct(tmp, &X[1]); + + /* output accumulation */ + + for (i = 3; i < 18; i += 8) { + X[i + 0] -= X[(i + 0) - 2]; + X[i + 2] -= X[(i + 2) - 2]; + X[i + 4] -= X[(i + 4) - 2]; + X[i + 6] -= X[(i + 6) - 2]; + } +} + +static inline +void dctIV(mad_fixed_t const y[18], mad_fixed_t X[18]) +{ + mad_fixed_t tmp[18]; + int i; + + /* scale[i] = 2 * cos(PI * (2 * i + 1) / (4 * 18)) */ + static mad_fixed_t const scale[18] = { + MAD_F(0x1ff833fa), MAD_F(0x1fb9ea93), MAD_F(0x1f3dd120), + MAD_F(0x1e84d969), MAD_F(0x1d906bcf), MAD_F(0x1c62648b), + MAD_F(0x1afd100f), MAD_F(0x1963268b), MAD_F(0x1797c6a4), + MAD_F(0x159e6f5b), MAD_F(0x137af940), MAD_F(0x11318ef3), + MAD_F(0x0ec6a507), MAD_F(0x0c3ef153), MAD_F(0x099f61c5), + MAD_F(0x06ed12c5), MAD_F(0x042d4544), MAD_F(0x0165547c) + }; + + /* scaling */ + + for (i = 0; i < 18; i += 3) { + tmp[i + 0] = mad_f_mul(y[i + 0], scale[i + 0]); + tmp[i + 1] = mad_f_mul(y[i + 1], scale[i + 1]); + tmp[i + 2] = mad_f_mul(y[i + 2], scale[i + 2]); + } + + /* SDCT-II */ + + sdctII(tmp, X); + + /* scale reduction and output accumulation */ + + X[0] /= 2; + for (i = 1; i < 17; i += 4) { + X[i + 0] = X[i + 0] / 2 - X[(i + 0) - 1]; + X[i + 1] = X[i + 1] / 2 - X[(i + 1) - 1]; + X[i + 2] = X[i + 2] / 2 - X[(i + 2) - 1]; + X[i + 3] = X[i + 3] / 2 - X[(i + 3) - 1]; + } + X[17] = X[17] / 2 - X[16]; +} + +/* + * NAME: imdct36 + * DESCRIPTION: perform X[18]->x[36] IMDCT using Szu-Wei Lee's fast algorithm + */ +static inline +void imdct36(mad_fixed_t const x[18], mad_fixed_t y[36]) +{ + mad_fixed_t tmp[18]; + int i; + + /* DCT-IV */ + + dctIV(x, tmp); + + /* convert 18-point DCT-IV to 36-point IMDCT */ + + for (i = 0; i < 9; i += 3) { + y[i + 0] = tmp[9 + (i + 0)]; + y[i + 1] = tmp[9 + (i + 1)]; + y[i + 2] = tmp[9 + (i + 2)]; + } + for (i = 9; i < 27; i += 3) { + y[i + 0] = -tmp[36 - (9 + (i + 0)) - 1]; + y[i + 1] = -tmp[36 - (9 + (i + 1)) - 1]; + y[i + 2] = -tmp[36 - (9 + (i + 2)) - 1]; + } + for (i = 27; i < 36; i += 3) { + y[i + 0] = -tmp[(i + 0) - 27]; + y[i + 1] = -tmp[(i + 1) - 27]; + y[i + 2] = -tmp[(i + 2) - 27]; + } +} +# else /* * NAME: imdct36 * DESCRIPTION: perform X[18]->x[36] IMDCT @@ -1862,6 +2052,7 @@ void imdct36(mad_fixed_t const X[18], mad_fixed_t x[36]) x[26] = x[27] = MAD_F_MLZ(hi, lo) + t5; } +# endif /* * NAME: III_imdct_l() @@ -1926,7 +2117,11 @@ void III_imdct_l(mad_fixed_t const X[18], mad_fixed_t z[36], break; case 1: /* start block */ - for (i = 0; i < 18; ++i) z[i] = mad_f_mul(z[i], window_l[i]); + for (i = 0; i < 18; i += 3) { + z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]); + z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]); + z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]); + } /* (i = 18; i < 24; ++i) z[i] unchanged */ for (i = 24; i < 30; ++i) z[i] = mad_f_mul(z[i], window_s[i - 18]); for (i = 30; i < 36; ++i) z[i] = 0; @@ -1936,7 +2131,11 @@ void III_imdct_l(mad_fixed_t const X[18], mad_fixed_t z[36], for (i = 0; i < 6; ++i) z[i] = 0; for (i = 6; i < 12; ++i) z[i] = mad_f_mul(z[i], window_s[i - 6]); /* (i = 12; i < 18; ++i) z[i] unchanged */ - for (i = 18; i < 36; ++i) z[i] = mad_f_mul(z[i], window_l[i]); + for (i = 18; i < 36; i += 3) { + z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]); + z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]); + z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]); + } break; } } @@ -2039,31 +2238,31 @@ void III_overlap(mad_fixed_t const output[36], mad_fixed_t overlap[18], tmp2 = overlap[1]; for (i = 0; i < 16; i += 2) { - sample[i + 0][sb] = output[i + 0] + tmp1; + sample[i + 0][sb] = output[i + 0 + 0] + tmp1; overlap[i + 0] = output[i + 0 + 18]; tmp1 = overlap[i + 2]; - sample[i + 1][sb] = output[i + 1] + tmp2; + sample[i + 1][sb] = output[i + 1 + 0] + tmp2; overlap[i + 1] = output[i + 1 + 18]; tmp2 = overlap[i + 3]; } - sample[16][sb] = output[16] + tmp1; + sample[16][sb] = output[16 + 0] + tmp1; overlap[16] = output[16 + 18]; - sample[17][sb] = output[17] + tmp2; + sample[17][sb] = output[17 + 0] + tmp2; overlap[17] = output[17 + 18]; } # elif 0 for (i = 0; i < 18; i += 2) { - sample[i + 0][sb] = output[i + 0] + overlap[i + 0]; + sample[i + 0][sb] = output[i + 0 + 0] + overlap[i + 0]; overlap[i + 0] = output[i + 0 + 18]; - sample[i + 1][sb] = output[i + 1] + overlap[i + 1]; + sample[i + 1][sb] = output[i + 1 + 0] + overlap[i + 1]; overlap[i + 1] = output[i + 1 + 18]; } # else for (i = 0; i < 18; ++i) { - sample[i][sb] = output[i] + overlap[i]; + sample[i][sb] = output[i + 0] + overlap[i]; overlap[i] = output[i + 18]; } # endif @@ -2430,7 +2629,8 @@ int mad_layer_III(struct mad_stream *stream, struct mad_frame *frame) *stream->main_data + stream->md_len - si.main_data_begin); if (md_len > si.main_data_begin) { - _x_assert((stream->md_len + md_len - si.main_data_begin) <= MAD_BUFFER_MDLEN); + assert(stream->md_len + md_len - + si.main_data_begin <= MAD_BUFFER_MDLEN); memcpy(*stream->main_data + stream->md_len, mad_bit_nextbyte(&stream->ptr), @@ -2450,12 +2650,12 @@ int mad_layer_III(struct mad_stream *stream, struct mad_frame *frame) stream->error = error; result = -1; } - } - /* designate ancillary bits */ + /* designate ancillary bits */ - stream->anc_ptr = ptr; - stream->anc_bitlen = md_len * CHAR_BIT - data_bitlen; + stream->anc_ptr = ptr; + stream->anc_bitlen = md_len * CHAR_BIT - data_bitlen; + } # if 0 && defined(DEBUG) fprintf(stderr, diff --git a/src/libmad/layer3.h b/src/libmad/layer3.h index 620ae4d94..3dca5b3b8 100644 --- a/src/libmad/layer3.h +++ b/src/libmad/layer3.h @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: layer3.h,v 1.2 2002/04/30 18:46:58 miguelfreitas Exp $ + * $Id: layer3.h,v 1.3 2004/04/22 00:23:06 miguelfreitas Exp $ */ # ifndef LIBMAD_LAYER3_H diff --git a/src/libmad/stream.c b/src/libmad/stream.c index af794fb81..fecc87434 100644 --- a/src/libmad/stream.c +++ b/src/libmad/stream.c @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: stream.c,v 1.2 2002/04/30 18:46:58 miguelfreitas Exp $ + * $Id: stream.c,v 1.3 2004/04/22 00:23:07 miguelfreitas Exp $ */ # ifdef HAVE_CONFIG_H @@ -145,6 +145,7 @@ char const *mad_stream_errorstr(struct mad_stream const *stream) case MAD_ERROR_BADCRC: return "CRC check failed"; case MAD_ERROR_BADBITALLOC: return "forbidden bit allocation value"; case MAD_ERROR_BADSCALEFACTOR: return "bad scalefactor index"; + case MAD_ERROR_BADMODE: return "bad bitrate/mode combination"; case MAD_ERROR_BADFRAMELEN: return "bad frame length"; case MAD_ERROR_BADBIGVALUES: return "bad big_values count"; case MAD_ERROR_BADBLOCKTYPE: return "reserved block_type"; diff --git a/src/libmad/stream.h b/src/libmad/stream.h index b40db3197..b99b87582 100644 --- a/src/libmad/stream.h +++ b/src/libmad/stream.h @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: stream.h,v 1.2 2002/04/30 18:46:58 miguelfreitas Exp $ + * $Id: stream.h,v 1.3 2004/04/22 00:23:12 miguelfreitas Exp $ */ # ifndef LIBMAD_STREAM_H @@ -44,6 +44,7 @@ enum mad_error { MAD_ERROR_BADCRC = 0x0201, /* CRC check failed */ MAD_ERROR_BADBITALLOC = 0x0211, /* forbidden bit allocation value */ MAD_ERROR_BADSCALEFACTOR = 0x0221, /* bad scalefactor index */ + MAD_ERROR_BADMODE = 0x0222, /* bad bitrate/mode combination */ MAD_ERROR_BADFRAMELEN = 0x0231, /* bad frame length */ MAD_ERROR_BADBIGVALUES = 0x0232, /* bad big_values count */ MAD_ERROR_BADBLOCKTYPE = 0x0233, /* reserved block_type */ diff --git a/src/libmad/synth.c b/src/libmad/synth.c index 0259f9923..be3eace56 100755 --- a/src/libmad/synth.c +++ b/src/libmad/synth.c @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: synth.c,v 1.2 2002/04/30 18:46:58 miguelfreitas Exp $ + * $Id: synth.c,v 1.3 2004/04/22 00:23:13 miguelfreitas Exp $ */ # ifdef HAVE_CONFIG_H diff --git a/src/libmad/synth.h b/src/libmad/synth.h index bf27b882f..d5a63589e 100644 --- a/src/libmad/synth.h +++ b/src/libmad/synth.h @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: synth.h,v 1.2 2002/04/30 18:46:58 miguelfreitas Exp $ + * $Id: synth.h,v 1.3 2004/04/22 00:23:24 miguelfreitas Exp $ */ # ifndef LIBMAD_SYNTH_H diff --git a/src/libmad/timer.c b/src/libmad/timer.c index 69a2efb40..9aa2e8924 100755 --- a/src/libmad/timer.c +++ b/src/libmad/timer.c @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: timer.c,v 1.5 2003/12/07 15:34:30 f1rmb Exp $ + * $Id: timer.c,v 1.6 2004/04/22 00:23:26 miguelfreitas Exp $ */ # ifdef HAVE_CONFIG_H @@ -26,9 +26,10 @@ # include "global.h" # include -# include /* For abort() */ -# include "xineutils.h" +# ifdef HAVE_ASSERT_H +# include +# endif # include "timer.h" @@ -77,7 +78,7 @@ void mad_timer_negate(mad_timer_t *timer) */ mad_timer_t mad_timer_abs(mad_timer_t timer) { - if (mad_timer_sign(timer) < 0) + if (timer.seconds < 0) mad_timer_negate(&timer); return timer; @@ -123,7 +124,7 @@ void reduce_rational(unsigned long *numer, unsigned long *denom) factor = gcd(*numer, *denom); - _x_assert(factor != 0); + assert(factor != 0); *numer /= factor; *denom /= factor; @@ -140,7 +141,7 @@ unsigned long scale_rational(unsigned long numer, unsigned long denom, reduce_rational(&numer, &denom); reduce_rational(&scale, &denom); - _x_assert(denom != 0); + assert(denom != 0); if (denom < scale) return numer * (scale / denom) + numer * (scale % denom) / denom; @@ -326,7 +327,8 @@ unsigned long mad_timer_fraction(mad_timer_t timer, unsigned long denom) switch (denom) { case 0: - return MAD_TIMER_RESOLUTION / timer.fraction; + return timer.fraction ? + MAD_TIMER_RESOLUTION / timer.fraction : MAD_TIMER_RESOLUTION + 1; case MAD_TIMER_RESOLUTION: return timer.fraction; diff --git a/src/libmad/timer.h b/src/libmad/timer.h index 64e8d58d3..88e997d5e 100755 --- a/src/libmad/timer.h +++ b/src/libmad/timer.h @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: timer.h,v 1.2 2002/04/30 18:46:58 miguelfreitas Exp $ + * $Id: timer.h,v 1.3 2004/04/22 00:23:27 miguelfreitas Exp $ */ # ifndef LIBMAD_TIMER_H diff --git a/src/libmad/version.c b/src/libmad/version.c index ca9e71518..8fc70f408 100644 --- a/src/libmad/version.c +++ b/src/libmad/version.c @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: version.c,v 1.1 2002/04/30 18:46:58 miguelfreitas Exp $ + * $Id: version.c,v 1.2 2004/04/22 00:23:27 miguelfreitas Exp $ */ # ifdef HAVE_CONFIG_H @@ -32,6 +32,16 @@ char const mad_copyright[] = "Copyright (C) " MAD_PUBLISHYEAR " " MAD_AUTHOR; char const mad_author[] = MAD_AUTHOR " <" MAD_EMAIL ">"; char const mad_build[] = "" +# if defined(DEBUG) + "DEBUG " +# elif defined(NDEBUG) + "NDEBUG " +# endif + +# if defined(EXPERIMENTAL) + "EXPERIMENTAL " +# endif + # if defined(FPM_64BIT) "FPM_64BIT " # elif defined(FPM_INTEL) @@ -78,14 +88,4 @@ char const mad_build[] = "" # if defined(OPT_STRICT) "OPT_STRICT " # endif - -# if defined(EXPERIMENTAL) - "EXPERIMENTAL " -# endif - -# if defined(DEBUG) - "DEBUG " -# elif defined(NDEBUG) - "NDEBUG " -# endif ; diff --git a/src/libmad/version.h b/src/libmad/version.h index c786006d2..c056e6fc9 100644 --- a/src/libmad/version.h +++ b/src/libmad/version.h @@ -1,6 +1,6 @@ /* * libmad - MPEG audio decoder library - * Copyright (C) 2000-2001 Robert Leslie + * Copyright (C) 2000-2004 Underbit Technologies, Inc. * * 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 @@ -16,15 +16,15 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: version.h,v 1.1 2002/04/30 18:46:58 miguelfreitas Exp $ + * $Id: version.h,v 1.2 2004/04/22 00:23:29 miguelfreitas Exp $ */ # ifndef LIBMAD_VERSION_H # define LIBMAD_VERSION_H # define MAD_VERSION_MAJOR 0 -# define MAD_VERSION_MINOR 14 -# define MAD_VERSION_PATCH 2 +# define MAD_VERSION_MINOR 15 +# define MAD_VERSION_PATCH 1 # define MAD_VERSION_EXTRA " (beta)" # define MAD_VERSION_STRINGIZE(str) #str @@ -35,9 +35,9 @@ MAD_VERSION_STRING(MAD_VERSION_PATCH) \ MAD_VERSION_EXTRA -# define MAD_PUBLISHYEAR "2000-2001" -# define MAD_AUTHOR "Robert Leslie" -# define MAD_EMAIL "rob@mars.org" +# define MAD_PUBLISHYEAR "2000-2004" +# define MAD_AUTHOR "Underbit Technologies, Inc." +# define MAD_EMAIL "info@underbit.com" extern char const mad_version[]; extern char const mad_copyright[]; -- cgit v1.2.3