summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/libmad/layer3.c
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/libmad/layer3.c') (more/less context) (show whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmad/layer3.c222
1 files changed, 209 insertions, 13 deletions
diff --git a/core/multimedia/opieplayer/libmad/layer3.c b/core/multimedia/opieplayer/libmad/layer3.c
index 03f13fe..3c5dd9e 100644
--- a/core/multimedia/opieplayer/libmad/layer3.c
+++ b/core/multimedia/opieplayer/libmad/layer3.c
@@ -1,9 +1,9 @@
1/* 1/*
2 * libmad - MPEG audio decoder library 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
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.
9 * 9 *
@@ -285,14 +285,14 @@ unsigned char const sfb_8000_short[] = {
285 36, 2, 2, 2, 2, 2, 2, 2, 2, 2, 26, 26, 26 285 36, 2, 2, 2, 2, 2, 2, 2, 2, 2, 26, 26, 26
286}; 286};
287 287
288# define sfb_12000_mixed sfb_16000_mixed 288# define sfb_12000_mixed sfb_16000_mixed
289# define sfb_11025_mixed sfb_12000_mixed 289# define sfb_11025_mixed sfb_12000_mixed
290 290
291/* the 8000 Hz short block scalefactor bands do not break after the first 36 291/* the 8000 Hz short block scalefactor bands do not break after
292 frequency lines, so this is probably wrong */ 292 the first 36 frequency lines, so this is probably wrong */
293static 293static
294unsigned char const sfb_8000_mixed[] = { 294unsigned char const sfb_8000_mixed[] = {
295 /* long */ 12, 12, 12, 295 /* long */ 12, 12, 12,
296 /* short */ 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16, 296 /* short */ 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16,
297 20, 20, 20, 24, 24, 24, 28, 28, 28, 36, 36, 36, 297 20, 20, 20, 24, 24, 24, 28, 28, 28, 36, 36, 36,
298 2, 2, 2, 2, 2, 2, 2, 2, 2, 26, 26, 26 298 2, 2, 2, 2, 2, 2, 2, 2, 2, 26, 26, 26
@@ -1572,12 +1572,199 @@ void III_aliasreduce(mad_fixed_t xr[576], int lines)
1572 } 1572 }
1573} 1573}
1574 1574
1575# if defined(ASO_IMDCT) 1575# if defined(ASO_IMDCT)
1576void III_imdct_l(mad_fixed_t const [18], mad_fixed_t [36], unsigned int); 1576void III_imdct_l(mad_fixed_t const [18], mad_fixed_t [36], unsigned int);
1577# else 1577# else
1578# if 1
1579static
1580void fastsdct(mad_fixed_t const x[9], mad_fixed_t y[18])
1581{
1582 mad_fixed_t a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12;
1583 mad_fixed_t a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25;
1584 mad_fixed_t m0, m1, m2, m3, m4, m5, m6, m7;
1585
1586 enum {
1587 c0 = MAD_F(0x1f838b8d), /* 2 * cos( 1 * PI / 18) */
1588 c1 = MAD_F(0x1bb67ae8), /* 2 * cos( 3 * PI / 18) */
1589 c2 = MAD_F(0x18836fa3), /* 2 * cos( 4 * PI / 18) */
1590 c3 = MAD_F(0x1491b752), /* 2 * cos( 5 * PI / 18) */
1591 c4 = MAD_F(0x0af1d43a), /* 2 * cos( 7 * PI / 18) */
1592 c5 = MAD_F(0x058e86a0), /* 2 * cos( 8 * PI / 18) */
1593 c6 = -MAD_F(0x1e11f642) /* 2 * cos(16 * PI / 18) */
1594 };
1595
1596 a0 = x[3] + x[5];
1597 a1 = x[3] - x[5];
1598 a2 = x[6] + x[2];
1599 a3 = x[6] - x[2];
1600 a4 = x[1] + x[7];
1601 a5 = x[1] - x[7];
1602 a6 = x[8] + x[0];
1603 a7 = x[8] - x[0];
1604
1605 a8 = a0 + a2;
1606 a9 = a0 - a2;
1607 a10 = a0 - a6;
1608 a11 = a2 - a6;
1609 a12 = a8 + a6;
1610 a13 = a1 - a3;
1611 a14 = a13 + a7;
1612 a15 = a3 + a7;
1613 a16 = a1 - a7;
1614 a17 = a1 + a3;
1615
1616 m0 = mad_f_mul(a17, -c3);
1617 m1 = mad_f_mul(a16, -c0);
1618 m2 = mad_f_mul(a15, -c4);
1619 m3 = mad_f_mul(a14, -c1);
1620 m4 = mad_f_mul(a5, -c1);
1621 m5 = mad_f_mul(a11, -c6);
1622 m6 = mad_f_mul(a10, -c5);
1623 m7 = mad_f_mul(a9, -c2);
1624
1625 a18 = x[4] + a4;
1626 a19 = 2 * x[4] - a4;
1627 a20 = a19 + m5;
1628 a21 = a19 - m5;
1629 a22 = a19 + m6;
1630 a23 = m4 + m2;
1631 a24 = m4 - m2;
1632 a25 = m4 + m1;
1633
1634 /* output to every other slot for convenience */
1635
1636 y[ 0] = a18 + a12;
1637 y[ 2] = m0 - a25;
1638 y[ 4] = m7 - a20;
1639 y[ 6] = m3;
1640 y[ 8] = a21 - m6;
1641 y[10] = a24 - m1;
1642 y[12] = a12 - 2 * a18;
1643 y[14] = a23 + m0;
1644 y[16] = a22 + m7;
1645}
1646
1647static inline
1648void sdctII(mad_fixed_t const x[18], mad_fixed_t X[18])
1649{
1650 mad_fixed_t tmp[9];
1651 int i;
1652
1653 /* scale[i] = 2 * cos(PI * (2 * i + 1) / (2 * 18)) */
1654 static mad_fixed_t const scale[9] = {
1655 MAD_F(0x1fe0d3b4), MAD_F(0x1ee8dd47), MAD_F(0x1d007930),
1656 MAD_F(0x1a367e59), MAD_F(0x16a09e66), MAD_F(0x125abcf8),
1657 MAD_F(0x0d8616bc), MAD_F(0x08483ee1), MAD_F(0x02c9fad7)
1658 };
1659
1660 /* divide the 18-point SDCT-II into two 9-point SDCT-IIs */
1661
1662 /* even input butterfly */
1663
1664 for (i = 0; i < 9; i += 3) {
1665 tmp[i + 0] = x[i + 0] + x[18 - (i + 0) - 1];
1666 tmp[i + 1] = x[i + 1] + x[18 - (i + 1) - 1];
1667 tmp[i + 2] = x[i + 2] + x[18 - (i + 2) - 1];
1668 }
1669
1670 fastsdct(tmp, &X[0]);
1671
1672 /* odd input butterfly and scaling */
1673
1674 for (i = 0; i < 9; i += 3) {
1675 tmp[i + 0] = mad_f_mul(x[i + 0] - x[18 - (i + 0) - 1], scale[i + 0]);
1676 tmp[i + 1] = mad_f_mul(x[i + 1] - x[18 - (i + 1) - 1], scale[i + 1]);
1677 tmp[i + 2] = mad_f_mul(x[i + 2] - x[18 - (i + 2) - 1], scale[i + 2]);
1678 }
1679
1680 fastsdct(tmp, &X[1]);
1681
1682 /* output accumulation */
1683
1684 for (i = 3; i < 18; i += 8) {
1685 X[i + 0] -= X[(i + 0) - 2];
1686 X[i + 2] -= X[(i + 2) - 2];
1687 X[i + 4] -= X[(i + 4) - 2];
1688 X[i + 6] -= X[(i + 6) - 2];
1689 }
1690}
1691
1692static inline
1693void dctIV(mad_fixed_t const y[18], mad_fixed_t X[18])
1694{
1695 mad_fixed_t tmp[18];
1696 int i;
1697
1698 /* scale[i] = 2 * cos(PI * (2 * i + 1) / (4 * 18)) */
1699 static mad_fixed_t const scale[18] = {
1700 MAD_F(0x1ff833fa), MAD_F(0x1fb9ea93), MAD_F(0x1f3dd120),
1701 MAD_F(0x1e84d969), MAD_F(0x1d906bcf), MAD_F(0x1c62648b),
1702 MAD_F(0x1afd100f), MAD_F(0x1963268b), MAD_F(0x1797c6a4),
1703 MAD_F(0x159e6f5b), MAD_F(0x137af940), MAD_F(0x11318ef3),
1704 MAD_F(0x0ec6a507), MAD_F(0x0c3ef153), MAD_F(0x099f61c5),
1705 MAD_F(0x06ed12c5), MAD_F(0x042d4544), MAD_F(0x0165547c)
1706 };
1707
1708 /* scaling */
1709
1710 for (i = 0; i < 18; i += 3) {
1711 tmp[i + 0] = mad_f_mul(y[i + 0], scale[i + 0]);
1712 tmp[i + 1] = mad_f_mul(y[i + 1], scale[i + 1]);
1713 tmp[i + 2] = mad_f_mul(y[i + 2], scale[i + 2]);
1714 }
1715
1716 /* SDCT-II */
1717
1718 sdctII(tmp, X);
1719
1720 /* scale reduction and output accumulation */
1721
1722 X[0] /= 2;
1723 for (i = 1; i < 17; i += 4) {
1724 X[i + 0] = X[i + 0] / 2 - X[(i + 0) - 1];
1725 X[i + 1] = X[i + 1] / 2 - X[(i + 1) - 1];
1726 X[i + 2] = X[i + 2] / 2 - X[(i + 2) - 1];
1727 X[i + 3] = X[i + 3] / 2 - X[(i + 3) - 1];
1728 }
1729 X[17] = X[17] / 2 - X[16];
1730}
1731
1732/*
1733 * NAME:imdct36
1734 * DESCRIPTION:perform X[18]->x[36] IMDCT using Szu-Wei Lee's fast algorithm
1735 */
1736static inline
1737void imdct36(mad_fixed_t const x[18], mad_fixed_t y[36])
1738{
1739 mad_fixed_t tmp[18];
1740 int i;
1741
1742 /* DCT-IV */
1743
1744 dctIV(x, tmp);
1745
1746 /* convert 18-point DCT-IV to 36-point IMDCT */
1747
1748 for (i = 0; i < 9; i += 3) {
1749 y[i + 0] = tmp[9 + (i + 0)];
1750 y[i + 1] = tmp[9 + (i + 1)];
1751 y[i + 2] = tmp[9 + (i + 2)];
1752 }
1753 for (i = 9; i < 27; i += 3) {
1754 y[i + 0] = -tmp[36 - (9 + (i + 0)) - 1];
1755 y[i + 1] = -tmp[36 - (9 + (i + 1)) - 1];
1756 y[i + 2] = -tmp[36 - (9 + (i + 2)) - 1];
1757 }
1758 for (i = 27; i < 36; i += 3) {
1759 y[i + 0] = -tmp[(i + 0) - 27];
1760 y[i + 1] = -tmp[(i + 1) - 27];
1761 y[i + 2] = -tmp[(i + 2) - 27];
1762 }
1763}
1764# else
1578/* 1765/*
1579 * NAME:imdct36 1766 * NAME:imdct36
1580 * DESCRIPTION:perform X[18]->x[36] IMDCT 1767 * DESCRIPTION:perform X[18]->x[36] IMDCT
1581 */ 1768 */
1582static inline 1769static inline
1583void imdct36(mad_fixed_t const X[18], mad_fixed_t x[36]) 1770void imdct36(mad_fixed_t const X[18], mad_fixed_t x[36])
@@ -1862,12 +2049,13 @@ void imdct36(mad_fixed_t const X[18], mad_fixed_t x[36])
1862 MAD_F_MLA(hi, lo, X[14], -MAD_F(0x04cfb0e2)); 2049 MAD_F_MLA(hi, lo, X[14], -MAD_F(0x04cfb0e2));
1863 MAD_F_MLA(hi, lo, X[15], -MAD_F(0x03768962)); 2050 MAD_F_MLA(hi, lo, X[15], -MAD_F(0x03768962));
1864 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x00b2aa3e)); 2051 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x00b2aa3e));
1865 2052
1866 x[26] = x[27] = MAD_F_MLZ(hi, lo) + t5; 2053 x[26] = x[27] = MAD_F_MLZ(hi, lo) + t5;
1867} 2054}
2055# endif
1868 2056
1869/* 2057/*
1870 * NAME:III_imdct_l() 2058 * NAME:III_imdct_l()
1871 * DESCRIPTION:perform IMDCT and windowing for long blocks 2059 * DESCRIPTION:perform IMDCT and windowing for long blocks
1872 */ 2060 */
1873static 2061static
@@ -1926,23 +2114,31 @@ void III_imdct_l(mad_fixed_t const X[18], mad_fixed_t z[36],
1926# else 2114# else
1927 for (i = 0; i < 36; ++i) z[i] = mad_f_mul(z[i], window_l[i]); 2115 for (i = 0; i < 36; ++i) z[i] = mad_f_mul(z[i], window_l[i]);
1928# endif 2116# endif
1929 break; 2117 break;
1930 2118
1931 case 1: /* start block */ 2119 case 1: /* start block */
1932 for (i = 0; i < 18; ++i) z[i] = mad_f_mul(z[i], window_l[i]); 2120 for (i = 0; i < 18; i += 3) {
2121 z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]);
2122 z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]);
2123 z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]);
2124 }
1933 /* (i = 18; i < 24; ++i) z[i] unchanged */ 2125 /* (i = 18; i < 24; ++i) z[i] unchanged */
1934 for (i = 24; i < 30; ++i) z[i] = mad_f_mul(z[i], window_s[i - 18]); 2126 for (i = 24; i < 30; ++i) z[i] = mad_f_mul(z[i], window_s[i - 18]);
1935 for (i = 30; i < 36; ++i) z[i] = 0; 2127 for (i = 30; i < 36; ++i) z[i] = 0;
1936 break; 2128 break;
1937 2129
1938 case 3: /* stop block */ 2130 case 3: /* stop block */
1939 for (i = 0; i < 6; ++i) z[i] = 0; 2131 for (i = 0; i < 6; ++i) z[i] = 0;
1940 for (i = 6; i < 12; ++i) z[i] = mad_f_mul(z[i], window_s[i - 6]); 2132 for (i = 6; i < 12; ++i) z[i] = mad_f_mul(z[i], window_s[i - 6]);
1941 /* (i = 12; i < 18; ++i) z[i] unchanged */ 2133 /* (i = 12; i < 18; ++i) z[i] unchanged */
1942 for (i = 18; i < 36; ++i) z[i] = mad_f_mul(z[i], window_l[i]); 2134 for (i = 18; i < 36; i += 3) {
2135 z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]);
2136 z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]);
2137 z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]);
2138 }
1943 break; 2139 break;
1944 } 2140 }
1945} 2141}
1946# endif /* ASO_IMDCT */ 2142# endif /* ASO_IMDCT */
1947 2143
1948/* 2144/*
@@ -2039,37 +2235,37 @@ void III_overlap(mad_fixed_t const output[36], mad_fixed_t overlap[18],
2039 register mad_fixed_t tmp1, tmp2; 2235 register mad_fixed_t tmp1, tmp2;
2040 2236
2041 tmp1 = overlap[0]; 2237 tmp1 = overlap[0];
2042 tmp2 = overlap[1]; 2238 tmp2 = overlap[1];
2043 2239
2044 for (i = 0; i < 16; i += 2) { 2240 for (i = 0; i < 16; i += 2) {
2045 sample[i + 0][sb] = output[i + 0] + tmp1; 2241 sample[i + 0][sb] = output[i + 0 + 0] + tmp1;
2046 overlap[i + 0] = output[i + 0 + 18]; 2242 overlap[i + 0] = output[i + 0 + 18];
2047 tmp1 = overlap[i + 2]; 2243 tmp1 = overlap[i + 2];
2048 2244
2049 sample[i + 1][sb] = output[i + 1] + tmp2; 2245 sample[i + 1][sb] = output[i + 1 + 0] + tmp2;
2050 overlap[i + 1] = output[i + 1 + 18]; 2246 overlap[i + 1] = output[i + 1 + 18];
2051 tmp2 = overlap[i + 3]; 2247 tmp2 = overlap[i + 3];
2052 } 2248 }
2053 2249
2054 sample[16][sb] = output[16] + tmp1; 2250 sample[16][sb] = output[16 + 0] + tmp1;
2055 overlap[16] = output[16 + 18]; 2251 overlap[16] = output[16 + 18];
2056 sample[17][sb] = output[17] + tmp2; 2252 sample[17][sb] = output[17 + 0] + tmp2;
2057 overlap[17] = output[17 + 18]; 2253 overlap[17] = output[17 + 18];
2058 } 2254 }
2059# elif 0 2255# elif 0
2060 for (i = 0; i < 18; i += 2) { 2256 for (i = 0; i < 18; i += 2) {
2061 sample[i + 0][sb] = output[i + 0] + overlap[i + 0]; 2257 sample[i + 0][sb] = output[i + 0 + 0] + overlap[i + 0];
2062 overlap[i + 0] = output[i + 0 + 18]; 2258 overlap[i + 0] = output[i + 0 + 18];
2063 2259
2064 sample[i + 1][sb] = output[i + 1] + overlap[i + 1]; 2260 sample[i + 1][sb] = output[i + 1 + 0] + overlap[i + 1];
2065 overlap[i + 1] = output[i + 1 + 18]; 2261 overlap[i + 1] = output[i + 1 + 18];
2066 } 2262 }
2067# else 2263# else
2068 for (i = 0; i < 18; ++i) { 2264 for (i = 0; i < 18; ++i) {
2069 sample[i][sb] = output[i] + overlap[i]; 2265 sample[i][sb] = output[i + 0] + overlap[i];
2070 overlap[i] = output[i + 18]; 2266 overlap[i] = output[i + 18];
2071 } 2267 }
2072# endif 2268# endif
2073} 2269}
2074 2270
2075/* 2271/*
@@ -2451,18 +2647,18 @@ int mad_layer_III(struct mad_stream *stream, struct mad_frame *frame)
2451 if (result == 0) { 2647 if (result == 0) {
2452 error = III_decode(&ptr, frame, &si, nch); 2648 error = III_decode(&ptr, frame, &si, nch);
2453 if (error) { 2649 if (error) {
2454 stream->error = error; 2650 stream->error = error;
2455 result = -1; 2651 result = -1;
2456 } 2652 }
2457 }
2458 2653
2459 /* designate ancillary bits */ 2654 /* designate ancillary bits */
2460 2655
2461 stream->anc_ptr = ptr; 2656 stream->anc_ptr = ptr;
2462 stream->anc_bitlen = md_len * CHAR_BIT - data_bitlen; 2657 stream->anc_bitlen = md_len * CHAR_BIT - data_bitlen;
2658 }
2463 2659
2464# if 0 && defined(DEBUG) 2660# if 0 && defined(DEBUG)
2465 fprintf(stderr, 2661 fprintf(stderr,
2466 "main_data_begin:%u, md_len:%u, frame_free:%u, " 2662 "main_data_begin:%u, md_len:%u, frame_free:%u, "
2467 "data_bitlen:%u, anc_bitlen: %u\n", 2663 "data_bitlen:%u, anc_bitlen: %u\n",
2468 si.main_data_begin, md_len, frame_free, 2664 si.main_data_begin, md_len, frame_free,