author | harlekin <harlekin> | 2002-04-19 16:08:55 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-04-19 16:08:55 (UTC) |
commit | 7ea4abeb652e6787e57a938e1ca028d25fd249ce (patch) (unidiff) | |
tree | ee08f2d9d6aaa8adb1c5f07f4124da8a61eb8cd5 /core/multimedia/opieplayer/libmad/layer3.c | |
parent | caa7ced77b9014526607f9f65c58aabe7e0ba631 (diff) | |
download | opie-7ea4abeb652e6787e57a938e1ca028d25fd249ce.zip opie-7ea4abeb652e6787e57a938e1ca028d25fd249ce.tar.gz opie-7ea4abeb652e6787e57a938e1ca028d25fd249ce.tar.bz2 |
new libmad version, less cpu usage
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,8 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * mad - MPEG audio decoder | 2 | * libmad - MPEG audio decoder library |
3 | * Copyright (C) 2000-2001 Robert Leslie | 3 | * Copyright (C) 2000-2001 Robert Leslie |
4 | * | 4 | * |
5 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by | 6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or | 7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. | 8 | * (at your option) any later version. |
@@ -24,13 +24,16 @@ | |||
24 | # endif | 24 | # endif |
25 | 25 | ||
26 | # include "libmad_global.h" | 26 | # include "libmad_global.h" |
27 | 27 | ||
28 | # include <stdlib.h> | 28 | # include <stdlib.h> |
29 | # include <string.h> | 29 | # include <string.h> |
30 | |||
31 | # ifdef HAVE_ASSERT_H | ||
30 | # include <assert.h> | 32 | # include <assert.h> |
33 | # endif | ||
31 | 34 | ||
32 | # ifdef HAVE_LIMITS_H | 35 | # ifdef HAVE_LIMITS_H |
33 | # include <limits.h> | 36 | # include <limits.h> |
34 | # else | 37 | # else |
35 | # define CHAR_BIT 8 | 38 | # define CHAR_BIT 8 |
36 | # endif | 39 | # endif |
@@ -48,12 +51,17 @@ enum { | |||
48 | count1table_select = 0x01, | 51 | count1table_select = 0x01, |
49 | scalefac_scale = 0x02, | 52 | scalefac_scale = 0x02, |
50 | preflag = 0x04, | 53 | preflag = 0x04, |
51 | mixed_block_flag = 0x08 | 54 | mixed_block_flag = 0x08 |
52 | }; | 55 | }; |
53 | 56 | ||
57 | enum { | ||
58 | I_STEREO = 0x1, | ||
59 | MS_STEREO = 0x2 | ||
60 | }; | ||
61 | |||
54 | struct sideinfo { | 62 | struct sideinfo { |
55 | unsigned int main_data_begin; | 63 | unsigned int main_data_begin; |
56 | unsigned int private_bits; | 64 | unsigned int private_bits; |
57 | 65 | ||
58 | unsigned char scfsi[2]; | 66 | unsigned char scfsi[2]; |
59 | 67 | ||
@@ -500,13 +508,13 @@ static | |||
500 | enum mad_error III_sideinfo(struct mad_bitptr *ptr, unsigned int nch, | 508 | enum mad_error III_sideinfo(struct mad_bitptr *ptr, unsigned int nch, |
501 | int lsf, struct sideinfo *si, | 509 | int lsf, struct sideinfo *si, |
502 | unsigned int *data_bitlen, | 510 | unsigned int *data_bitlen, |
503 | unsigned int *priv_bitlen) | 511 | unsigned int *priv_bitlen) |
504 | { | 512 | { |
505 | unsigned int ngr, gr, ch, i; | 513 | unsigned int ngr, gr, ch, i; |
506 | enum mad_error result = 0; | 514 | enum mad_error result = MAD_ERROR_NONE; |
507 | 515 | ||
508 | *data_bitlen = 0; | 516 | *data_bitlen = 0; |
509 | *priv_bitlen = lsf ? ((nch == 1) ? 1 : 2) : ((nch == 1) ? 5 : 3); | 517 | *priv_bitlen = lsf ? ((nch == 1) ? 1 : 2) : ((nch == 1) ? 5 : 3); |
510 | 518 | ||
511 | si->main_data_begin = mad_bit_read(ptr, lsf ? 8 : 9); | 519 | si->main_data_begin = mad_bit_read(ptr, lsf ? 8 : 9); |
512 | si->private_bits = mad_bit_read(ptr, *priv_bitlen); | 520 | si->private_bits = mad_bit_read(ptr, *priv_bitlen); |
@@ -599,13 +607,13 @@ unsigned int III_scalefactors_lsf(struct mad_bitptr *ptr, | |||
599 | start = *ptr; | 607 | start = *ptr; |
600 | 608 | ||
601 | scalefac_compress = channel->scalefac_compress; | 609 | scalefac_compress = channel->scalefac_compress; |
602 | index = (channel->block_type == 2) ? | 610 | index = (channel->block_type == 2) ? |
603 | ((channel->flags & mixed_block_flag) ? 2 : 1) : 0; | 611 | ((channel->flags & mixed_block_flag) ? 2 : 1) : 0; |
604 | 612 | ||
605 | if (!((mode_extension & 0x1) && gr1ch)) { | 613 | if (!((mode_extension & I_STEREO) && gr1ch)) { |
606 | if (scalefac_compress < 400) { | 614 | if (scalefac_compress < 400) { |
607 | slen[0] = (scalefac_compress >> 4) / 5; | 615 | slen[0] = (scalefac_compress >> 4) / 5; |
608 | slen[1] = (scalefac_compress >> 4) % 5; | 616 | slen[1] = (scalefac_compress >> 4) % 5; |
609 | slen[2] = (scalefac_compress % 16) >> 2; | 617 | slen[2] = (scalefac_compress % 16) >> 2; |
610 | slen[3] = scalefac_compress % 4; | 618 | slen[3] = scalefac_compress % 4; |
611 | 619 | ||
@@ -640,13 +648,13 @@ unsigned int III_scalefactors_lsf(struct mad_bitptr *ptr, | |||
640 | channel->scalefac[n++] = mad_bit_read(ptr, slen[part]); | 648 | channel->scalefac[n++] = mad_bit_read(ptr, slen[part]); |
641 | } | 649 | } |
642 | 650 | ||
643 | while (n < 39) | 651 | while (n < 39) |
644 | channel->scalefac[n++] = 0; | 652 | channel->scalefac[n++] = 0; |
645 | } | 653 | } |
646 | else { /* (mode_extension & 0x1) && gr1ch (i.e. ch == 1) */ | 654 | else { /* (mode_extension & I_STEREO) && gr1ch (i.e. ch == 1) */ |
647 | scalefac_compress >>= 1; | 655 | scalefac_compress >>= 1; |
648 | 656 | ||
649 | if (scalefac_compress < 180) { | 657 | if (scalefac_compress < 180) { |
650 | slen[0] = scalefac_compress / 36; | 658 | slen[0] = scalefac_compress / 36; |
651 | slen[1] = (scalefac_compress % 36) / 6; | 659 | slen[1] = (scalefac_compress % 36) / 6; |
652 | slen[2] = (scalefac_compress % 36) % 6; | 660 | slen[2] = (scalefac_compress % 36) % 6; |
@@ -772,12 +780,34 @@ unsigned int III_scalefactors(struct mad_bitptr *ptr, struct channel *channel, | |||
772 | } | 780 | } |
773 | 781 | ||
774 | return mad_bit_length(&start, ptr); | 782 | return mad_bit_length(&start, ptr); |
775 | } | 783 | } |
776 | 784 | ||
777 | /* | 785 | /* |
786 | * The Layer III formula for requantization and scaling is defined by | ||
787 | * section 2.4.3.4.7.1 of ISO/IEC 11172-3, as follows: | ||
788 | * | ||
789 | * long blocks: | ||
790 | * xr[i] = sign(is[i]) * abs(is[i])^(4/3) * | ||
791 | * 2^((1/4) * (global_gain - 210)) * | ||
792 | * 2^-(scalefac_multiplier * | ||
793 | * (scalefac_l[sfb] + preflag * pretab[sfb])) | ||
794 | * | ||
795 | * short blocks: | ||
796 | * xr[i] = sign(is[i]) * abs(is[i])^(4/3) * | ||
797 | * 2^((1/4) * (global_gain - 210 - 8 * subblock_gain[w])) * | ||
798 | * 2^-(scalefac_multiplier * scalefac_s[sfb][w]) | ||
799 | * | ||
800 | * where: | ||
801 | * scalefac_multiplier = (scalefac_scale + 1) / 2 | ||
802 | * | ||
803 | * The routines III_exponents() and III_requantize() facilitate this | ||
804 | * calculation. | ||
805 | */ | ||
806 | |||
807 | /* | ||
778 | * NAME:III_exponents() | 808 | * NAME:III_exponents() |
779 | * DESCRIPTION:calculate scalefactor exponents | 809 | * DESCRIPTION:calculate scalefactor exponents |
780 | */ | 810 | */ |
781 | static | 811 | static |
782 | void III_exponents(struct channel const *channel, | 812 | void III_exponents(struct channel const *channel, |
783 | unsigned char const *sfbwidth, signed int exponents[39]) | 813 | unsigned char const *sfbwidth, signed int exponents[39]) |
@@ -853,43 +883,29 @@ static | |||
853 | mad_fixed_t III_requantize(unsigned int value, signed int exp) | 883 | mad_fixed_t III_requantize(unsigned int value, signed int exp) |
854 | { | 884 | { |
855 | mad_fixed_t requantized; | 885 | mad_fixed_t requantized; |
856 | signed int frac; | 886 | signed int frac; |
857 | struct fixedfloat const *power; | 887 | struct fixedfloat const *power; |
858 | 888 | ||
859 | /* | 889 | frac = exp % 4; /* assumes sign(frac) == sign(exp) */ |
860 | * long blocks: | ||
861 | * xr[i] = sign(is[i]) * abs(is[i])^(4/3) * | ||
862 | * 2^((1/4) * (global_gain - 210)) * | ||
863 | * 2^-(scalefac_multiplier * | ||
864 | * (scalefac_l[sfb] + preflag * pretab[sfb])) | ||
865 | * | ||
866 | * short blocks: | ||
867 | * xr[i] = sign(is[i]) * abs(is[i])^(4/3) * | ||
868 | * 2^((1/4) * (global_gain - 210 - 8 * subblock_gain[w])) * | ||
869 | * 2^-(scalefac_multiplier * scalefac_s[sfb][w]) | ||
870 | * | ||
871 | * where: | ||
872 | * scalefac_multiplier = (scalefac_scale + 1) / 2 | ||
873 | */ | ||
874 | |||
875 | frac = exp % 4; | ||
876 | exp /= 4; | 890 | exp /= 4; |
877 | 891 | ||
878 | power = &rq_table[value]; | 892 | power = &rq_table[value]; |
879 | requantized = power->mantissa; | 893 | requantized = power->mantissa; |
880 | exp += power->exponent; | 894 | exp += power->exponent; |
881 | 895 | ||
882 | if (exp < 0) { | 896 | if (exp < 0) { |
883 | if (-exp >= sizeof(mad_fixed_t) * CHAR_BIT) { | 897 | if (-exp >= sizeof(mad_fixed_t) * CHAR_BIT) { |
884 | /* underflow */ | 898 | /* underflow */ |
885 | requantized = 0; | 899 | requantized = 0; |
886 | } | 900 | } |
887 | else | 901 | else { |
902 | requantized += 1L << (-exp - 1); | ||
888 | requantized >>= -exp; | 903 | requantized >>= -exp; |
889 | } | 904 | } |
905 | } | ||
890 | else { | 906 | else { |
891 | if (exp >= 5) { | 907 | if (exp >= 5) { |
892 | /* overflow */ | 908 | /* overflow */ |
893 | # if defined(DEBUG) | 909 | # if defined(DEBUG) |
894 | fprintf(stderr, "requantize overflow (%f * 2^%d)\n", | 910 | fprintf(stderr, "requantize overflow (%f * 2^%d)\n", |
895 | mad_f_todouble(requantized), exp); | 911 | mad_f_todouble(requantized), exp); |
@@ -1248,13 +1264,13 @@ enum mad_error III_huffdecode(struct mad_bitptr *ptr, mad_fixed_t xr[576], | |||
1248 | xrptr[0] = 0; | 1264 | xrptr[0] = 0; |
1249 | xrptr[1] = 0; | 1265 | xrptr[1] = 0; |
1250 | 1266 | ||
1251 | xrptr += 2; | 1267 | xrptr += 2; |
1252 | } | 1268 | } |
1253 | 1269 | ||
1254 | return 0; | 1270 | return MAD_ERROR_NONE; |
1255 | } | 1271 | } |
1256 | 1272 | ||
1257 | # undef MASK | 1273 | # undef MASK |
1258 | # undef MASK1BIT | 1274 | # undef MASK1BIT |
1259 | 1275 | ||
1260 | /* | 1276 | /* |
@@ -1263,43 +1279,45 @@ enum mad_error III_huffdecode(struct mad_bitptr *ptr, mad_fixed_t xr[576], | |||
1263 | */ | 1279 | */ |
1264 | static | 1280 | static |
1265 | void III_reorder(mad_fixed_t xr[576], struct channel const *channel, | 1281 | void III_reorder(mad_fixed_t xr[576], struct channel const *channel, |
1266 | unsigned char const sfbwidth[39]) | 1282 | unsigned char const sfbwidth[39]) |
1267 | { | 1283 | { |
1268 | mad_fixed_t tmp[32][3][6]; | 1284 | mad_fixed_t tmp[32][3][6]; |
1269 | unsigned int sb, l, sfbi, f, w, sbw[3], sw[3]; | 1285 | unsigned int sb, l, f, w, sbw[3], sw[3]; |
1270 | 1286 | ||
1271 | /* this is probably wrong for 8000 Hz mixed blocks */ | 1287 | /* this is probably wrong for 8000 Hz mixed blocks */ |
1272 | 1288 | ||
1273 | if (channel->flags & mixed_block_flag) | 1289 | sb = 0; |
1274 | sb = 2, sfbi = 3 * 3; | 1290 | if (channel->flags & mixed_block_flag) { |
1275 | else | 1291 | sb = 2; |
1276 | sb = 0, sfbi = 0; | 1292 | |
1293 | l = 0; | ||
1294 | while (l < 36) | ||
1295 | l += *sfbwidth++; | ||
1296 | } | ||
1277 | 1297 | ||
1278 | for (w = 0; w < 3; ++w) { | 1298 | for (w = 0; w < 3; ++w) { |
1279 | sbw[w] = sb; | 1299 | sbw[w] = sb; |
1280 | sw[w] = 0; | 1300 | sw[w] = 0; |
1281 | } | 1301 | } |
1282 | 1302 | ||
1283 | f = sfbwidth[sfbi]; | 1303 | f = *sfbwidth++; |
1284 | w = 0; | 1304 | w = 0; |
1285 | 1305 | ||
1286 | for (l = 18 * sb; l < 576; ++l) { | 1306 | for (l = 18 * sb; l < 576; ++l) { |
1307 | if (f-- == 0) { | ||
1308 | f = *sfbwidth++ - 1; | ||
1309 | w = (w + 1) % 3; | ||
1310 | } | ||
1311 | |||
1287 | tmp[sbw[w]][w][sw[w]++] = xr[l]; | 1312 | tmp[sbw[w]][w][sw[w]++] = xr[l]; |
1288 | 1313 | ||
1289 | if (sw[w] == 6) { | 1314 | if (sw[w] == 6) { |
1290 | sw[w] = 0; | 1315 | sw[w] = 0; |
1291 | ++sbw[w]; | 1316 | ++sbw[w]; |
1292 | } | 1317 | } |
1293 | |||
1294 | if (--f == 0) { | ||
1295 | if (++w == 3) | ||
1296 | w = 0; | ||
1297 | |||
1298 | f = sfbwidth[++sfbi]; | ||
1299 | } | ||
1300 | } | 1318 | } |
1301 | 1319 | ||
1302 | memcpy(&xr[18 * sb], &tmp[sb], (576 - 18 * sb) * sizeof(mad_fixed_t)); | 1320 | memcpy(&xr[18 * sb], &tmp[sb], (576 - 18 * sb) * sizeof(mad_fixed_t)); |
1303 | } | 1321 | } |
1304 | 1322 | ||
1305 | /* | 1323 | /* |
@@ -1312,29 +1330,24 @@ enum mad_error III_stereo(mad_fixed_t xr[2][576], | |||
1312 | struct mad_header *header, | 1330 | struct mad_header *header, |
1313 | unsigned char const *sfbwidth) | 1331 | unsigned char const *sfbwidth) |
1314 | { | 1332 | { |
1315 | short modes[39]; | 1333 | short modes[39]; |
1316 | unsigned int sfbi, l, n, i; | 1334 | unsigned int sfbi, l, n, i; |
1317 | 1335 | ||
1318 | enum { | ||
1319 | i_stereo = 0x1, | ||
1320 | ms_stereo = 0x2 | ||
1321 | }; | ||
1322 | |||
1323 | if (granule->ch[0].block_type != | 1336 | if (granule->ch[0].block_type != |
1324 | granule->ch[1].block_type || | 1337 | granule->ch[1].block_type || |
1325 | (granule->ch[0].flags & mixed_block_flag) != | 1338 | (granule->ch[0].flags & mixed_block_flag) != |
1326 | (granule->ch[1].flags & mixed_block_flag)) | 1339 | (granule->ch[1].flags & mixed_block_flag)) |
1327 | return MAD_ERROR_BADSTEREO; | 1340 | return MAD_ERROR_BADSTEREO; |
1328 | 1341 | ||
1329 | for (i = 0; i < 39; ++i) | 1342 | for (i = 0; i < 39; ++i) |
1330 | modes[i] = header->mode_extension; | 1343 | modes[i] = header->mode_extension; |
1331 | 1344 | ||
1332 | /* intensity stereo */ | 1345 | /* intensity stereo */ |
1333 | 1346 | ||
1334 | if (header->mode_extension & i_stereo) { | 1347 | if (header->mode_extension & I_STEREO) { |
1335 | struct channel const *right_ch = &granule->ch[1]; | 1348 | struct channel const *right_ch = &granule->ch[1]; |
1336 | mad_fixed_t const *right_xr = xr[1]; | 1349 | mad_fixed_t const *right_xr = xr[1]; |
1337 | unsigned int is_pos; | 1350 | unsigned int is_pos; |
1338 | 1351 | ||
1339 | header->flags |= MAD_FLAG_I_STEREO; | 1352 | header->flags |= MAD_FLAG_I_STEREO; |
1340 | 1353 | ||
@@ -1384,20 +1397,20 @@ enum mad_error III_stereo(mad_fixed_t xr[2][576], | |||
1384 | if (max) | 1397 | if (max) |
1385 | lower = start; | 1398 | lower = start; |
1386 | 1399 | ||
1387 | /* long blocks */ | 1400 | /* long blocks */ |
1388 | 1401 | ||
1389 | for (i = 0; i < lower; ++i) | 1402 | for (i = 0; i < lower; ++i) |
1390 | modes[i] = header->mode_extension & ~i_stereo; | 1403 | modes[i] = header->mode_extension & ~I_STEREO; |
1391 | 1404 | ||
1392 | /* short blocks */ | 1405 | /* short blocks */ |
1393 | 1406 | ||
1394 | w = 0; | 1407 | w = 0; |
1395 | for (i = start; i < max; ++i) { | 1408 | for (i = start; i < max; ++i) { |
1396 | if (i < bound[w]) | 1409 | if (i < bound[w]) |
1397 | modes[i] = header->mode_extension & ~i_stereo; | 1410 | modes[i] = header->mode_extension & ~I_STEREO; |
1398 | 1411 | ||
1399 | w = (w + 1) % 3; | 1412 | w = (w + 1) % 3; |
1400 | } | 1413 | } |
1401 | } | 1414 | } |
1402 | else { /* right_ch->block_type != 2 */ | 1415 | else { /* right_ch->block_type != 2 */ |
1403 | unsigned int bound; | 1416 | unsigned int bound; |
@@ -1414,13 +1427,13 @@ enum mad_error III_stereo(mad_fixed_t xr[2][576], | |||
1414 | } | 1427 | } |
1415 | 1428 | ||
1416 | right_xr += n; | 1429 | right_xr += n; |
1417 | } | 1430 | } |
1418 | 1431 | ||
1419 | for (i = 0; i < bound; ++i) | 1432 | for (i = 0; i < bound; ++i) |
1420 | modes[i] = header->mode_extension & ~i_stereo; | 1433 | modes[i] = header->mode_extension & ~I_STEREO; |
1421 | } | 1434 | } |
1422 | 1435 | ||
1423 | /* now do the actual processing */ | 1436 | /* now do the actual processing */ |
1424 | 1437 | ||
1425 | if (header->flags & MAD_FLAG_LSF_EXT) { | 1438 | if (header->flags & MAD_FLAG_LSF_EXT) { |
1426 | unsigned char const *illegal_pos = granule[1].ch[1].scalefac; | 1439 | unsigned char const *illegal_pos = granule[1].ch[1].scalefac; |
@@ -1429,17 +1442,17 @@ enum mad_error III_stereo(mad_fixed_t xr[2][576], | |||
1429 | /* intensity_scale */ | 1442 | /* intensity_scale */ |
1430 | lsf_scale = is_lsf_table[right_ch->scalefac_compress & 0x1]; | 1443 | lsf_scale = is_lsf_table[right_ch->scalefac_compress & 0x1]; |
1431 | 1444 | ||
1432 | for (sfbi = l = 0; l < 576; ++sfbi, l += n) { | 1445 | for (sfbi = l = 0; l < 576; ++sfbi, l += n) { |
1433 | n = sfbwidth[sfbi]; | 1446 | n = sfbwidth[sfbi]; |
1434 | 1447 | ||
1435 | if (!(modes[sfbi] & i_stereo)) | 1448 | if (!(modes[sfbi] & I_STEREO)) |
1436 | continue; | 1449 | continue; |
1437 | 1450 | ||
1438 | if (illegal_pos[sfbi]) { | 1451 | if (illegal_pos[sfbi]) { |
1439 | modes[sfbi] &= ~i_stereo; | 1452 | modes[sfbi] &= ~I_STEREO; |
1440 | continue; | 1453 | continue; |
1441 | } | 1454 | } |
1442 | 1455 | ||
1443 | is_pos = right_ch->scalefac[sfbi]; | 1456 | is_pos = right_ch->scalefac[sfbi]; |
1444 | 1457 | ||
1445 | for (i = 0; i < n; ++i) { | 1458 | for (i = 0; i < n; ++i) { |
@@ -1465,19 +1478,19 @@ enum mad_error III_stereo(mad_fixed_t xr[2][576], | |||
1465 | } | 1478 | } |
1466 | } | 1479 | } |
1467 | else { /* !(header->flags & MAD_FLAG_LSF_EXT) */ | 1480 | else { /* !(header->flags & MAD_FLAG_LSF_EXT) */ |
1468 | for (sfbi = l = 0; l < 576; ++sfbi, l += n) { | 1481 | for (sfbi = l = 0; l < 576; ++sfbi, l += n) { |
1469 | n = sfbwidth[sfbi]; | 1482 | n = sfbwidth[sfbi]; |
1470 | 1483 | ||
1471 | if (!(modes[sfbi] & i_stereo)) | 1484 | if (!(modes[sfbi] & I_STEREO)) |
1472 | continue; | 1485 | continue; |
1473 | 1486 | ||
1474 | is_pos = right_ch->scalefac[sfbi]; | 1487 | is_pos = right_ch->scalefac[sfbi]; |
1475 | 1488 | ||
1476 | if (is_pos >= 7) { /* illegal intensity position */ | 1489 | if (is_pos >= 7) { /* illegal intensity position */ |
1477 | modes[sfbi] &= ~i_stereo; | 1490 | modes[sfbi] &= ~I_STEREO; |
1478 | continue; | 1491 | continue; |
1479 | } | 1492 | } |
1480 | 1493 | ||
1481 | for (i = 0; i < n; ++i) { | 1494 | for (i = 0; i < n; ++i) { |
1482 | register mad_fixed_t left; | 1495 | register mad_fixed_t left; |
1483 | 1496 | ||
@@ -1489,23 +1502,23 @@ enum mad_error III_stereo(mad_fixed_t xr[2][576], | |||
1489 | } | 1502 | } |
1490 | } | 1503 | } |
1491 | } | 1504 | } |
1492 | 1505 | ||
1493 | /* middle/side stereo */ | 1506 | /* middle/side stereo */ |
1494 | 1507 | ||
1495 | if (header->mode_extension & ms_stereo) { | 1508 | if (header->mode_extension & MS_STEREO) { |
1496 | register mad_fixed_t invsqrt2; | 1509 | register mad_fixed_t invsqrt2; |
1497 | 1510 | ||
1498 | header->flags |= MAD_FLAG_MS_STEREO; | 1511 | header->flags |= MAD_FLAG_MS_STEREO; |
1499 | 1512 | ||
1500 | invsqrt2 = root_table[3 + -2]; | 1513 | invsqrt2 = root_table[3 + -2]; |
1501 | 1514 | ||
1502 | for (sfbi = l = 0; l < 576; ++sfbi, l += n) { | 1515 | for (sfbi = l = 0; l < 576; ++sfbi, l += n) { |
1503 | n = sfbwidth[sfbi]; | 1516 | n = sfbwidth[sfbi]; |
1504 | 1517 | ||
1505 | if (modes[sfbi] != ms_stereo) | 1518 | if (modes[sfbi] != MS_STEREO) |
1506 | continue; | 1519 | continue; |
1507 | 1520 | ||
1508 | for (i = 0; i < n; ++i) { | 1521 | for (i = 0; i < n; ++i) { |
1509 | register mad_fixed_t m, s; | 1522 | register mad_fixed_t m, s; |
1510 | 1523 | ||
1511 | m = xr[0][l + i]; | 1524 | m = xr[0][l + i]; |
@@ -1514,13 +1527,13 @@ enum mad_error III_stereo(mad_fixed_t xr[2][576], | |||
1514 | xr[0][l + i] = mad_f_mul(m + s, invsqrt2); /* l = (m + s) / sqrt(2) */ | 1527 | xr[0][l + i] = mad_f_mul(m + s, invsqrt2); /* l = (m + s) / sqrt(2) */ |
1515 | xr[1][l + i] = mad_f_mul(m - s, invsqrt2); /* r = (m - s) / sqrt(2) */ | 1528 | xr[1][l + i] = mad_f_mul(m - s, invsqrt2); /* r = (m - s) / sqrt(2) */ |
1516 | } | 1529 | } |
1517 | } | 1530 | } |
1518 | } | 1531 | } |
1519 | 1532 | ||
1520 | return 0; | 1533 | return MAD_ERROR_NONE; |
1521 | } | 1534 | } |
1522 | 1535 | ||
1523 | /* | 1536 | /* |
1524 | * NAME:III_aliasreduce() | 1537 | * NAME:III_aliasreduce() |
1525 | * DESCRIPTION:perform frequency line alias reduction | 1538 | * DESCRIPTION:perform frequency line alias reduction |
1526 | */ | 1539 | */ |
@@ -1530,34 +1543,31 @@ void III_aliasreduce(mad_fixed_t xr[576], int lines) | |||
1530 | mad_fixed_t const *bound; | 1543 | mad_fixed_t const *bound; |
1531 | int i; | 1544 | int i; |
1532 | 1545 | ||
1533 | bound = &xr[lines]; | 1546 | bound = &xr[lines]; |
1534 | for (xr += 18; xr < bound; xr += 18) { | 1547 | for (xr += 18; xr < bound; xr += 18) { |
1535 | for (i = 0; i < 8; ++i) { | 1548 | for (i = 0; i < 8; ++i) { |
1536 | register mad_fixed_t *aptr, *bptr, a, b; | 1549 | register mad_fixed_t a, b; |
1537 | register mad_fixed64hi_t hi; | 1550 | register mad_fixed64hi_t hi; |
1538 | register mad_fixed64lo_t lo; | 1551 | register mad_fixed64lo_t lo; |
1539 | 1552 | ||
1540 | aptr = &xr[-1 - i]; | 1553 | a = xr[-1 - i]; |
1541 | bptr = &xr[ i]; | 1554 | b = xr[ i]; |
1542 | |||
1543 | a = *aptr; | ||
1544 | b = *bptr; | ||
1545 | 1555 | ||
1546 | # if defined(ASO_ZEROCHECK) | 1556 | # if defined(ASO_ZEROCHECK) |
1547 | if (a | b) { | 1557 | if (a | b) { |
1548 | # endif | 1558 | # endif |
1549 | MAD_F_ML0(hi, lo, a, cs[i]); | 1559 | MAD_F_ML0(hi, lo, a, cs[i]); |
1550 | MAD_F_MLA(hi, lo, -b, ca[i]); | 1560 | MAD_F_MLA(hi, lo, -b, ca[i]); |
1551 | 1561 | ||
1552 | *aptr = MAD_F_MLZ(hi, lo); | 1562 | xr[-1 - i] = MAD_F_MLZ(hi, lo); |
1553 | 1563 | ||
1554 | MAD_F_ML0(hi, lo, b, cs[i]); | 1564 | MAD_F_ML0(hi, lo, b, cs[i]); |
1555 | MAD_F_MLA(hi, lo, a, ca[i]); | 1565 | MAD_F_MLA(hi, lo, a, ca[i]); |
1556 | 1566 | ||
1557 | *bptr = MAD_F_MLZ(hi, lo); | 1567 | xr[ i] = MAD_F_MLZ(hi, lo); |
1558 | # if defined(ASO_ZEROCHECK) | 1568 | # if defined(ASO_ZEROCHECK) |
1559 | } | 1569 | } |
1560 | # endif | 1570 | # endif |
1561 | } | 1571 | } |
1562 | } | 1572 | } |
1563 | } | 1573 | } |
@@ -2138,13 +2148,13 @@ void III_freqinver(mad_fixed_t sample[18][32], unsigned int sb) | |||
2138 | 2148 | ||
2139 | /* | 2149 | /* |
2140 | * NAME:III_decode() | 2150 | * NAME:III_decode() |
2141 | * DESCRIPTION:decode frame main_data | 2151 | * DESCRIPTION:decode frame main_data |
2142 | */ | 2152 | */ |
2143 | static | 2153 | static |
2144 | int III_decode(struct mad_bitptr *ptr, struct mad_frame *frame, | 2154 | enum mad_error III_decode(struct mad_bitptr *ptr, struct mad_frame *frame, |
2145 | struct sideinfo *si, unsigned int nch) | 2155 | struct sideinfo *si, unsigned int nch) |
2146 | { | 2156 | { |
2147 | struct mad_header *header = &frame->header; | 2157 | struct mad_header *header = &frame->header; |
2148 | unsigned int sfreqi, ngr, gr; | 2158 | unsigned int sfreqi, ngr, gr; |
2149 | 2159 | ||
2150 | { | 2160 | { |
@@ -2166,24 +2176,24 @@ int III_decode(struct mad_bitptr *ptr, struct mad_frame *frame, | |||
2166 | /* scalefactors, Huffman decoding, requantization */ | 2176 | /* scalefactors, Huffman decoding, requantization */ |
2167 | 2177 | ||
2168 | ngr = (header->flags & MAD_FLAG_LSF_EXT) ? 1 : 2; | 2178 | ngr = (header->flags & MAD_FLAG_LSF_EXT) ? 1 : 2; |
2169 | 2179 | ||
2170 | for (gr = 0; gr < ngr; ++gr) { | 2180 | for (gr = 0; gr < ngr; ++gr) { |
2171 | struct granule *granule = &si->gr[gr]; | 2181 | struct granule *granule = &si->gr[gr]; |
2172 | unsigned char const *sfbwidth = 0; | 2182 | unsigned char const *sfbwidth[2]; |
2173 | mad_fixed_t xr[2][576]; | 2183 | mad_fixed_t xr[2][576]; |
2174 | unsigned int ch; | 2184 | unsigned int ch; |
2175 | enum mad_error error; | 2185 | enum mad_error error; |
2176 | 2186 | ||
2177 | for (ch = 0; ch < nch; ++ch) { | 2187 | for (ch = 0; ch < nch; ++ch) { |
2178 | struct channel *channel = &granule->ch[ch]; | 2188 | struct channel *channel = &granule->ch[ch]; |
2179 | unsigned int part2_length; | 2189 | unsigned int part2_length; |
2180 | 2190 | ||
2181 | sfbwidth = sfbwidth_table[sfreqi].l; | 2191 | sfbwidth[ch] = sfbwidth_table[sfreqi].l; |
2182 | if (channel->block_type == 2) { | 2192 | if (channel->block_type == 2) { |
2183 | sfbwidth = (channel->flags & mixed_block_flag) ? | 2193 | sfbwidth[ch] = (channel->flags & mixed_block_flag) ? |
2184 | sfbwidth_table[sfreqi].m : sfbwidth_table[sfreqi].s; | 2194 | sfbwidth_table[sfreqi].m : sfbwidth_table[sfreqi].s; |
2185 | } | 2195 | } |
2186 | 2196 | ||
2187 | if (header->flags & MAD_FLAG_LSF_EXT) { | 2197 | if (header->flags & MAD_FLAG_LSF_EXT) { |
2188 | part2_length = III_scalefactors_lsf(ptr, channel, | 2198 | part2_length = III_scalefactors_lsf(ptr, channel, |
2189 | ch == 0 ? 0 : &si->gr[1].ch[1], | 2199 | ch == 0 ? 0 : &si->gr[1].ch[1], |
@@ -2191,21 +2201,21 @@ int III_decode(struct mad_bitptr *ptr, struct mad_frame *frame, | |||
2191 | } | 2201 | } |
2192 | else { | 2202 | else { |
2193 | part2_length = III_scalefactors(ptr, channel, &si->gr[0].ch[ch], | 2203 | part2_length = III_scalefactors(ptr, channel, &si->gr[0].ch[ch], |
2194 | gr == 0 ? 0 : si->scfsi[ch]); | 2204 | gr == 0 ? 0 : si->scfsi[ch]); |
2195 | } | 2205 | } |
2196 | 2206 | ||
2197 | error = III_huffdecode(ptr, xr[ch], channel, sfbwidth, part2_length); | 2207 | error = III_huffdecode(ptr, xr[ch], channel, sfbwidth[ch], part2_length); |
2198 | if (error) | 2208 | if (error) |
2199 | return error; | 2209 | return error; |
2200 | } | 2210 | } |
2201 | 2211 | ||
2202 | /* joint stereo processing */ | 2212 | /* joint stereo processing */ |
2203 | 2213 | ||
2204 | if (header->mode == MAD_MODE_JOINT_STEREO && header->mode_extension) { | 2214 | if (header->mode == MAD_MODE_JOINT_STEREO && header->mode_extension) { |
2205 | error = III_stereo(xr, granule, header, sfbwidth); | 2215 | error = III_stereo(xr, granule, header, sfbwidth[0]); |
2206 | if (error) | 2216 | if (error) |
2207 | return error; | 2217 | return error; |
2208 | } | 2218 | } |
2209 | 2219 | ||
2210 | /* reordering, alias reduction, IMDCT, overlap-add, frequency inversion */ | 2220 | /* reordering, alias reduction, IMDCT, overlap-add, frequency inversion */ |
2211 | 2221 | ||
@@ -2213,13 +2223,13 @@ int III_decode(struct mad_bitptr *ptr, struct mad_frame *frame, | |||
2213 | struct channel const *channel = &granule->ch[ch]; | 2223 | struct channel const *channel = &granule->ch[ch]; |
2214 | mad_fixed_t (*sample)[32] = &frame->sbsample[ch][18 * gr]; | 2224 | mad_fixed_t (*sample)[32] = &frame->sbsample[ch][18 * gr]; |
2215 | unsigned int sb, l, i, sblimit; | 2225 | unsigned int sb, l, i, sblimit; |
2216 | mad_fixed_t output[36]; | 2226 | mad_fixed_t output[36]; |
2217 | 2227 | ||
2218 | if (channel->block_type == 2) { | 2228 | if (channel->block_type == 2) { |
2219 | III_reorder(xr[ch], channel, sfbwidth_table[sfreqi].s); | 2229 | III_reorder(xr[ch], channel, sfbwidth[ch]); |
2220 | 2230 | ||
2221 | # if !defined(OPT_STRICT) | 2231 | # if !defined(OPT_STRICT) |
2222 | /* | 2232 | /* |
2223 | * According to ISO/IEC 11172-3, "Alias reduction is not applied for | 2233 | * According to ISO/IEC 11172-3, "Alias reduction is not applied for |
2224 | * granules with block_type == 2 (short block)." However, other | 2234 | * granules with block_type == 2 (short block)." However, other |
2225 | * sources suggest alias reduction should indeed be performed on the | 2235 | * sources suggest alias reduction should indeed be performed on the |
@@ -2297,13 +2307,13 @@ int III_decode(struct mad_bitptr *ptr, struct mad_frame *frame, | |||
2297 | if (sb & 1) | 2307 | if (sb & 1) |
2298 | III_freqinver(sample, sb); | 2308 | III_freqinver(sample, sb); |
2299 | } | 2309 | } |
2300 | } | 2310 | } |
2301 | } | 2311 | } |
2302 | 2312 | ||
2303 | return 0; | 2313 | return MAD_ERROR_NONE; |
2304 | } | 2314 | } |
2305 | 2315 | ||
2306 | /* | 2316 | /* |
2307 | * NAME:layer->III() | 2317 | * NAME:layer->III() |
2308 | * DESCRIPTION:decode a single Layer III frame | 2318 | * DESCRIPTION:decode a single Layer III frame |
2309 | */ | 2319 | */ |