Diffstat (limited to 'core/multimedia/opieplayer/libmad/layer3.c') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/libmad/layer3.c | 146 |
1 files changed, 78 insertions, 68 deletions
diff --git a/core/multimedia/opieplayer/libmad/layer3.c b/core/multimedia/opieplayer/libmad/layer3.c index 194fc7e..03f13fe 100644 --- a/core/multimedia/opieplayer/libmad/layer3.c +++ b/core/multimedia/opieplayer/libmad/layer3.c @@ -1,3 +1,3 @@ /* - * mad - MPEG audio decoder + * libmad - MPEG audio decoder library * Copyright (C) 2000-2001 Robert Leslie @@ -29,3 +29,6 @@ # include <string.h> + +# ifdef HAVE_ASSERT_H # include <assert.h> +# endif @@ -53,2 +56,7 @@ enum { +enum { + I_STEREO = 0x1, + MS_STEREO = 0x2 +}; + struct sideinfo { @@ -505,3 +513,3 @@ enum mad_error III_sideinfo(struct mad_bitptr *ptr, unsigned int nch, unsigned int ngr, gr, ch, i; - enum mad_error result = 0; + enum mad_error result = MAD_ERROR_NONE; @@ -604,3 +612,3 @@ unsigned int III_scalefactors_lsf(struct mad_bitptr *ptr, - if (!((mode_extension & 0x1) && gr1ch)) { + if (!((mode_extension & I_STEREO) && gr1ch)) { if (scalefac_compress < 400) { @@ -645,3 +653,3 @@ unsigned int III_scalefactors_lsf(struct mad_bitptr *ptr, } - else { /* (mode_extension & 0x1) && gr1ch (i.e. ch == 1) */ + else { /* (mode_extension & I_STEREO) && gr1ch (i.e. ch == 1) */ scalefac_compress >>= 1; @@ -777,2 +785,24 @@ unsigned int III_scalefactors(struct mad_bitptr *ptr, struct channel *channel, /* + * The Layer III formula for requantization and scaling is defined by + * section 2.4.3.4.7.1 of ISO/IEC 11172-3, as follows: + * + * long blocks: + * xr[i] = sign(is[i]) * abs(is[i])^(4/3) * + * 2^((1/4) * (global_gain - 210)) * + * 2^-(scalefac_multiplier * + * (scalefac_l[sfb] + preflag * pretab[sfb])) + * + * short blocks: + * xr[i] = sign(is[i]) * abs(is[i])^(4/3) * + * 2^((1/4) * (global_gain - 210 - 8 * subblock_gain[w])) * + * 2^-(scalefac_multiplier * scalefac_s[sfb][w]) + * + * where: + * scalefac_multiplier = (scalefac_scale + 1) / 2 + * + * The routines III_exponents() and III_requantize() facilitate this + * calculation. + */ + +/* * NAME: III_exponents() @@ -858,19 +888,3 @@ mad_fixed_t III_requantize(unsigned int value, signed int exp) - /* - * long blocks: - * xr[i] = sign(is[i]) * abs(is[i])^(4/3) * - * 2^((1/4) * (global_gain - 210)) * - * 2^-(scalefac_multiplier * - * (scalefac_l[sfb] + preflag * pretab[sfb])) - * - * short blocks: - * xr[i] = sign(is[i]) * abs(is[i])^(4/3) * - * 2^((1/4) * (global_gain - 210 - 8 * subblock_gain[w])) * - * 2^-(scalefac_multiplier * scalefac_s[sfb][w]) - * - * where: - * scalefac_multiplier = (scalefac_scale + 1) / 2 - */ - - frac = exp % 4; + frac = exp % 4; /* assumes sign(frac) == sign(exp) */ exp /= 4; @@ -886,5 +900,7 @@ mad_fixed_t III_requantize(unsigned int value, signed int exp) } - else + else { + requantized += 1L << (-exp - 1); requantized >>= -exp; } + } else { @@ -1253,3 +1269,3 @@ enum mad_error III_huffdecode(struct mad_bitptr *ptr, mad_fixed_t xr[576], - return 0; + return MAD_ERROR_NONE; } @@ -1268,3 +1284,3 @@ void III_reorder(mad_fixed_t xr[576], struct channel const *channel, mad_fixed_t tmp[32][3][6]; - unsigned int sb, l, sfbi, f, w, sbw[3], sw[3]; + unsigned int sb, l, f, w, sbw[3], sw[3]; @@ -1272,6 +1288,10 @@ void III_reorder(mad_fixed_t xr[576], struct channel const *channel, - if (channel->flags & mixed_block_flag) - sb = 2, sfbi = 3 * 3; - else - sb = 0, sfbi = 0; + sb = 0; + if (channel->flags & mixed_block_flag) { + sb = 2; + + l = 0; + while (l < 36) + l += *sfbwidth++; + } @@ -1282,3 +1302,3 @@ void III_reorder(mad_fixed_t xr[576], struct channel const *channel, - f = sfbwidth[sfbi]; + f = *sfbwidth++; w = 0; @@ -1286,2 +1306,7 @@ void III_reorder(mad_fixed_t xr[576], struct channel const *channel, for (l = 18 * sb; l < 576; ++l) { + if (f-- == 0) { + f = *sfbwidth++ - 1; + w = (w + 1) % 3; + } + tmp[sbw[w]][w][sw[w]++] = xr[l]; @@ -1292,9 +1317,2 @@ void III_reorder(mad_fixed_t xr[576], struct channel const *channel, } - - if (--f == 0) { - if (++w == 3) - w = 0; - - f = sfbwidth[++sfbi]; - } } @@ -1317,7 +1335,2 @@ enum mad_error III_stereo(mad_fixed_t xr[2][576], - enum { - i_stereo = 0x1, - ms_stereo = 0x2 - }; - if (granule->ch[0].block_type != @@ -1333,3 +1346,3 @@ enum mad_error III_stereo(mad_fixed_t xr[2][576], - if (header->mode_extension & i_stereo) { + if (header->mode_extension & I_STEREO) { struct channel const *right_ch = &granule->ch[1]; @@ -1389,3 +1402,3 @@ enum mad_error III_stereo(mad_fixed_t xr[2][576], for (i = 0; i < lower; ++i) - modes[i] = header->mode_extension & ~i_stereo; + modes[i] = header->mode_extension & ~I_STEREO; @@ -1396,3 +1409,3 @@ enum mad_error III_stereo(mad_fixed_t xr[2][576], if (i < bound[w]) - modes[i] = header->mode_extension & ~i_stereo; + modes[i] = header->mode_extension & ~I_STEREO; @@ -1419,3 +1432,3 @@ enum mad_error III_stereo(mad_fixed_t xr[2][576], for (i = 0; i < bound; ++i) - modes[i] = header->mode_extension & ~i_stereo; + modes[i] = header->mode_extension & ~I_STEREO; } @@ -1434,3 +1447,3 @@ enum mad_error III_stereo(mad_fixed_t xr[2][576], - if (!(modes[sfbi] & i_stereo)) + if (!(modes[sfbi] & I_STEREO)) continue; @@ -1438,3 +1451,3 @@ enum mad_error III_stereo(mad_fixed_t xr[2][576], if (illegal_pos[sfbi]) { - modes[sfbi] &= ~i_stereo; + modes[sfbi] &= ~I_STEREO; continue; @@ -1470,3 +1483,3 @@ enum mad_error III_stereo(mad_fixed_t xr[2][576], - if (!(modes[sfbi] & i_stereo)) + if (!(modes[sfbi] & I_STEREO)) continue; @@ -1476,3 +1489,3 @@ enum mad_error III_stereo(mad_fixed_t xr[2][576], if (is_pos >= 7) { /* illegal intensity position */ - modes[sfbi] &= ~i_stereo; + modes[sfbi] &= ~I_STEREO; continue; @@ -1494,3 +1507,3 @@ enum mad_error III_stereo(mad_fixed_t xr[2][576], - if (header->mode_extension & ms_stereo) { + if (header->mode_extension & MS_STEREO) { register mad_fixed_t invsqrt2; @@ -1504,3 +1517,3 @@ enum mad_error III_stereo(mad_fixed_t xr[2][576], - if (modes[sfbi] != ms_stereo) + if (modes[sfbi] != MS_STEREO) continue; @@ -1519,3 +1532,3 @@ enum mad_error III_stereo(mad_fixed_t xr[2][576], - return 0; + return MAD_ERROR_NONE; } @@ -1535,3 +1548,3 @@ void III_aliasreduce(mad_fixed_t xr[576], int lines) for (i = 0; i < 8; ++i) { - register mad_fixed_t *aptr, *bptr, a, b; + register mad_fixed_t a, b; register mad_fixed64hi_t hi; @@ -1539,7 +1552,4 @@ void III_aliasreduce(mad_fixed_t xr[576], int lines) - aptr = &xr[-1 - i]; - bptr = &xr[ i]; - - a = *aptr; - b = *bptr; + a = xr[-1 - i]; + b = xr[ i]; @@ -1551,3 +1561,3 @@ void III_aliasreduce(mad_fixed_t xr[576], int lines) - *aptr = MAD_F_MLZ(hi, lo); + xr[-1 - i] = MAD_F_MLZ(hi, lo); @@ -1556,3 +1566,3 @@ void III_aliasreduce(mad_fixed_t xr[576], int lines) - *bptr = MAD_F_MLZ(hi, lo); + xr[ i] = MAD_F_MLZ(hi, lo); # if defined(ASO_ZEROCHECK) @@ -2143,3 +2153,3 @@ void III_freqinver(mad_fixed_t sample[18][32], unsigned int sb) static -int III_decode(struct mad_bitptr *ptr, struct mad_frame *frame, +enum mad_error III_decode(struct mad_bitptr *ptr, struct mad_frame *frame, struct sideinfo *si, unsigned int nch) @@ -2171,3 +2181,3 @@ int III_decode(struct mad_bitptr *ptr, struct mad_frame *frame, struct granule *granule = &si->gr[gr]; - unsigned char const *sfbwidth = 0; + unsigned char const *sfbwidth[2]; mad_fixed_t xr[2][576]; @@ -2180,5 +2190,5 @@ int III_decode(struct mad_bitptr *ptr, struct mad_frame *frame, - sfbwidth = sfbwidth_table[sfreqi].l; + sfbwidth[ch] = sfbwidth_table[sfreqi].l; if (channel->block_type == 2) { - sfbwidth = (channel->flags & mixed_block_flag) ? + sfbwidth[ch] = (channel->flags & mixed_block_flag) ? sfbwidth_table[sfreqi].m : sfbwidth_table[sfreqi].s; @@ -2196,3 +2206,3 @@ int III_decode(struct mad_bitptr *ptr, struct mad_frame *frame, - error = III_huffdecode(ptr, xr[ch], channel, sfbwidth, part2_length); + error = III_huffdecode(ptr, xr[ch], channel, sfbwidth[ch], part2_length); if (error) @@ -2204,3 +2214,3 @@ int III_decode(struct mad_bitptr *ptr, struct mad_frame *frame, if (header->mode == MAD_MODE_JOINT_STEREO && header->mode_extension) { - error = III_stereo(xr, granule, header, sfbwidth); + error = III_stereo(xr, granule, header, sfbwidth[0]); if (error) @@ -2218,3 +2228,3 @@ int III_decode(struct mad_bitptr *ptr, struct mad_frame *frame, if (channel->block_type == 2) { - III_reorder(xr[ch], channel, sfbwidth_table[sfreqi].s); + III_reorder(xr[ch], channel, sfbwidth[ch]); @@ -2302,3 +2312,3 @@ int III_decode(struct mad_bitptr *ptr, struct mad_frame *frame, - return 0; + return MAD_ERROR_NONE; } |