author | llornkcor <llornkcor> | 2005-11-08 23:16:03 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2005-11-08 23:16:03 (UTC) |
commit | 6bd52d3658f01c966d690b12235592a5473a4d57 (patch) (side-by-side diff) | |
tree | 76e25003b738fde6ebbea5d338b7cf76b82f47fa /core/multimedia/opieplayer/libmad/layer12.c | |
parent | a8063e0797d6edf2ead22fc8c5346ddf187f0b5d (diff) | |
download | opie-6bd52d3658f01c966d690b12235592a5473a4d57.zip opie-6bd52d3658f01c966d690b12235592a5473a4d57.tar.gz opie-6bd52d3658f01c966d690b12235592a5473a4d57.tar.bz2 |
update libmad and add 64bit define
Diffstat (limited to 'core/multimedia/opieplayer/libmad/layer12.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/libmad/layer12.c | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/core/multimedia/opieplayer/libmad/layer12.c b/core/multimedia/opieplayer/libmad/layer12.c index d291174..512b6a5 100644 --- a/core/multimedia/opieplayer/libmad/layer12.c +++ b/core/multimedia/opieplayer/libmad/layer12.c @@ -1,69 +1,69 @@ /* * 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 * 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-1307 USA * * $Id$ */ # ifdef HAVE_CONFIG_H # include "libmad_config.h" # endif # include "libmad_global.h" # ifdef HAVE_LIMITS_H # include <limits.h> # else # define CHAR_BIT 8 # endif # include "fixed.h" # include "bit.h" # include "stream.h" # include "frame.h" # include "layer12.h" /* * scalefactor table * 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" }; /* --- Layer I ------------------------------------------------------------- */ /* linear scaling table */ static mad_fixed_t const linear_table[14] = { MAD_F(0x15555555), /* 2^2 / (2^2 - 1) == 1.33333333333333 */ MAD_F(0x12492492), /* 2^3 / (2^3 - 1) == 1.14285714285714 */ MAD_F(0x11111111), /* 2^4 / (2^4 - 1) == 1.06666666666667 */ MAD_F(0x10842108), /* 2^5 / (2^5 - 1) == 1.03225806451613 */ MAD_F(0x10410410), /* 2^6 / (2^6 - 1) == 1.01587301587302 */ MAD_F(0x10204081), /* 2^7 / (2^7 - 1) == 1.00787401574803 */ MAD_F(0x10101010), /* 2^8 / (2^8 - 1) == 1.00392156862745 */ MAD_F(0x10080402), /* 2^9 / (2^9 - 1) == 1.00195694716243 */ MAD_F(0x10040100), /* 2^10 / (2^10 - 1) == 1.00097751710655 */ MAD_F(0x10020040), /* 2^11 / (2^11 - 1) == 1.00048851978505 */ MAD_F(0x10010010), /* 2^12 / (2^12 - 1) == 1.00024420024420 */ MAD_F(0x10008004), /* 2^13 / (2^13 - 1) == 1.00012208521548 */ MAD_F(0x10004001), /* 2^14 / (2^14 - 1) == 1.00006103888177 */ MAD_F(0x10002000) /* 2^15 / (2^15 - 1) == 1.00003051850948 */ }; @@ -142,52 +142,59 @@ int mad_layer_I(struct mad_stream *stream, struct mad_frame *frame) allocation[ch][sb] = nb ? nb + 1 : 0; } } for (sb = bound; sb < 32; ++sb) { nb = mad_bit_read(&stream->ptr, 4); if (nb == 15) { stream->error = MAD_ERROR_BADBITALLOC; return -1; } allocation[0][sb] = allocation[1][sb] = nb ? nb + 1 : 0; } /* decode scalefactors */ for (sb = 0; sb < 32; ++sb) { for (ch = 0; ch < nch; ++ch) { 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 } } } /* decode samples */ for (s = 0; s < 12; ++s) { for (sb = 0; sb < bound; ++sb) { for (ch = 0; ch < nch; ++ch) { nb = allocation[ch][sb]; frame->sbsample[ch][s][sb] = nb ? mad_f_mul(I_sample(&stream->ptr, nb), sf_table[scalefactor[ch][sb]]) : 0; } } for (sb = bound; sb < 32; ++sb) { if ((nb = allocation[0][sb])) { mad_fixed_t sample; sample = I_sample(&stream->ptr, nb); for (ch = 0; ch < nch; ++ch) { frame->sbsample[ch][s][sb] = @@ -313,62 +320,86 @@ void II_samples(struct mad_bitptr *ptr, output[s] = mad_f_mul(requantized + quantclass->D, quantclass->C); /* s' = factor * s'' */ /* (to be performed by caller) */ } } /* * NAME: layer->II() * DESCRIPTION: decode a single Layer II frame */ int mad_layer_II(struct mad_stream *stream, struct mad_frame *frame) { struct mad_header *header = &frame->header; struct mad_bitptr start; unsigned int index, sblimit, nbal, nch, bound, gr, ch, s, sb; unsigned char const *offsets; unsigned char allocation[2][32], scfsi[2][32], scalefactor[2][32][3]; mad_fixed_t samples[3]; nch = MAD_NCHANNELS(header); 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; } } sblimit = sbquant_table[index].sblimit; offsets = sbquant_table[index].offsets; bound = 32; if (header->mode == MAD_MODE_JOINT_STEREO) { header->flags |= MAD_FLAG_I_STEREO; bound = 4 + header->mode_extension * 4; } if (bound > sblimit) bound = sblimit; start = stream->ptr; /* decode bit allocations */ for (sb = 0; sb < bound; ++sb) { nbal = bitalloc_table[offsets[sb]].nbal; for (ch = 0; ch < nch; ++ch) @@ -410,54 +441,61 @@ int mad_layer_II(struct mad_stream *stream, struct mad_frame *frame) for (sb = 0; sb < sblimit; ++sb) { for (ch = 0; ch < nch; ++ch) { if (allocation[ch][sb]) { scalefactor[ch][sb][0] = mad_bit_read(&stream->ptr, 6); switch (scfsi[ch][sb]) { case 2: scalefactor[ch][sb][2] = scalefactor[ch][sb][1] = scalefactor[ch][sb][0]; break; case 0: scalefactor[ch][sb][1] = mad_bit_read(&stream->ptr, 6); /* fall through */ case 1: case 3: scalefactor[ch][sb][2] = mad_bit_read(&stream->ptr, 6); } 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 } } } /* decode samples */ for (gr = 0; gr < 12; ++gr) { for (sb = 0; sb < bound; ++sb) { for (ch = 0; ch < nch; ++ch) { if ((index = allocation[ch][sb])) { index = offset_table[bitalloc_table[offsets[sb]].offset][index - 1]; II_samples(&stream->ptr, &qc_table[index], samples); for (s = 0; s < 3; ++s) { frame->sbsample[ch][3 * gr + s][sb] = mad_f_mul(samples[s], sf_table[scalefactor[ch][sb][gr / 4]]); } } else { for (s = 0; s < 3; ++s) frame->sbsample[ch][3 * gr + s][sb] = 0; } } |