rtoss - Diff between revs 14 and 26

Subversion Repositories:
Rev:
Show entire file - Ignore whitespace
Rev 14 Rev 26
Line 1... Line 1...
1 /* 1 /*
2  * libmad - MPEG audio decoder library 2  * libmad - MPEG audio decoder library
3  * Copyright (C) 2000-2003 Underbit Technologies, Inc. -  
-   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.
Line 14... Line 14...
14  * 14  *
15  * You should have received a copy of the GNU General Public License 15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software 16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  * 18  *
19  * $Id: layer3.c,v 1.41 2003/05/28 04:24:36 rob Exp $ -  
-   19  * $Id: layer3.c,v 1.43 2004/01/23 09:41:32 rob Exp $
20  */ 20  */
21 21
22 # ifdef HAVE_CONFIG_H 22 # ifdef HAVE_CONFIG_H
23 #  include "config.h" 23 #  include "config.h"
24 # endif 24 # endif
Line 564... Line 564...
564           channel->region0_count = 8; 564           channel->region0_count = 8;
565 565
566         for (i = 0; i < 2; ++i) 566         for (i = 0; i < 2; ++i)
567           channel->table_select[i] = mad_bit_read(ptr, 5); 567           channel->table_select[i] = mad_bit_read(ptr, 5);
568 568
569 # if 0 && defined(DEBUG) -  
-   569 # if defined(DEBUG)
570         channel->table_select[2] = 4;  /* not used */ 570         channel->table_select[2] = 4;  /* not used */
571 # endif 571 # endif
572 572
573         for (i = 0; i < 3; ++i) 573         for (i = 0; i < 3; ++i)
574           channel->subblock_gain[i] = mad_bit_read(ptr, 3); 574           channel->subblock_gain[i] = mad_bit_read(ptr, 3);
Line 904... Line 904...
904     } 904     }
905   } 905   }
906   else { 906   else {
907     if (exp >= 5) { 907     if (exp >= 5) {
908       /* overflow */ 908       /* overflow */
909 # if 0 && defined(DEBUG) -  
-   909 # if defined(DEBUG)
910       fprintf(stderr, "requantize overflow (%f * 2^%d)\n", 910       fprintf(stderr, "requantize overflow (%f * 2^%d)\n",
911               mad_f_todouble(requantized), exp); 911               mad_f_todouble(requantized), exp);
912 # endif 912 # endif
913       requantized = MAD_F_MAX; 913       requantized = MAD_F_MAX;
914     } 914     }
Line 1573... Line 1573...
1573 } 1573 }
1574 1574
1575 # if defined(ASO_IMDCT) 1575 # if defined(ASO_IMDCT)
1576 void III_imdct_l(mad_fixed_t const [18], mad_fixed_t [36], unsigned int); 1576 void III_imdct_l(mad_fixed_t const [18], mad_fixed_t [36], unsigned int);
1577 # else 1577 # else
-   1578 #  if 1
-   1579 static
-   1580 void 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
-   1647 static inline
-   1648 void 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
-   1692 static inline
-   1693 void 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  */
-   1736 static inline
-   1737 void 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  */
1582 static __inline -  
-   1769 static inline
1583 void imdct36(mad_fixed_t const X[18], mad_fixed_t x[36]) 1770 void imdct36(mad_fixed_t const X[18], mad_fixed_t x[36])
1584 { 1771 {
1585   mad_fixed_t t0, t1, t2,  t3,  t4,  t5,  t6,  t7; 1772   mad_fixed_t t0, t1, t2,  t3,  t4,  t5,  t6,  t7;
1586   mad_fixed_t t8, t9, t10, t11, t12, t13, t14, t15; 1773   mad_fixed_t t8, t9, t10, t11, t12, t13, t14, t15;
1587   register mad_fixed64hi_t hi; 1774   register mad_fixed64hi_t hi;
Line 1863... Line 2050...
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  */
Line 1927... Line 2115...
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
Line 2074... Line 2270...
2074 2270
2075 /* 2271 /*
2076  * NAME:        III_overlap_z() 2272  * NAME:        III_overlap_z()
2077  * DESCRIPTION: perform "overlap-add" of zero IMDCT outputs 2273  * DESCRIPTION: perform "overlap-add" of zero IMDCT outputs
2078  */ 2274  */
2079 static __inline -  
-   2275 static inline
2080 void III_overlap_z(mad_fixed_t overlap[18], 2276 void III_overlap_z(mad_fixed_t overlap[18],
2081                    mad_fixed_t sample[18][32], unsigned int sb) 2277                    mad_fixed_t sample[18][32], unsigned int sb)
2082 { 2278 {
2083   unsigned int i; 2279   unsigned int i;
2084 2280
Line 2337... Line 2533...
2337       return -1; 2533       return -1;
2338     } 2534     }
2339   } 2535   }
2340 2536
2341   if (frame->overlap == 0) { 2537   if (frame->overlap == 0) {
2342     //frame->overlap = calloc(2 * 32 * 18, sizeof(mad_fixed_t)); -  
2343         frame->overlap = malloc(2 * 32 * 18 * sizeof(mad_fixed_t)); -  
2344         memset(frame->overlap, 0, 2 * 32 * 18 * sizeof(mad_fixed_t)); -  
-   2538     frame->overlap = calloc(2 * 32 * 18, sizeof(mad_fixed_t));
2345     if (frame->overlap == 0) { 2539     if (frame->overlap == 0) {
2346       stream->error = MAD_ERROR_NOMEM; 2540       stream->error = MAD_ERROR_NOMEM;
2347       return -1; 2541       return -1;
2348     } 2542     }
2349   } 2543   }