annotate mp3lib/layer2.c @ 20639:2a2f3db46103

pass the interlacing info to the filter chain
author henry
date Sat, 04 Nov 2006 07:08:54 +0000
parents 0783dd397f74
children 1b1fdac4a68c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15167
07e7a572bd84 Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents: 13336
diff changeset
1 /*
18783
0783dd397f74 CVS --> Subversion in copyright notices
diego
parents: 15167
diff changeset
2 * Modified for use with MPlayer, for details see the changelog at
0783dd397f74 CVS --> Subversion in copyright notices
diego
parents: 15167
diff changeset
3 * http://svn.mplayerhq.hu/mplayer/trunk/
15167
07e7a572bd84 Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents: 13336
diff changeset
4 * $Id$
07e7a572bd84 Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents: 13336
diff changeset
5 */
07e7a572bd84 Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents: 13336
diff changeset
6
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 * Mpeg Layer-2 audio decoder
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 * --------------------------
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 //#include "mpg123.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 #include "l2tables.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 static int grp_3tab[32 * 3] = { 0, }; /* used: 27 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 static int grp_5tab[128 * 3] = { 0, }; /* used: 125 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 static int grp_9tab[1024 * 3] = { 0, }; /* used: 729 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 static real muls[27][64]; /* also used by layer 1 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 static void init_layer2(void)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 static double mulmul[27] = {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 0.0 , -2.0/3.0 , 2.0/3.0 ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 2.0/7.0 , 2.0/15.0 , 2.0/31.0, 2.0/63.0 , 2.0/127.0 , 2.0/255.0 ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 2.0/511.0 , 2.0/1023.0 , 2.0/2047.0 , 2.0/4095.0 , 2.0/8191.0 ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 2.0/16383.0 , 2.0/32767.0 , 2.0/65535.0 ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 -4.0/5.0 , -2.0/5.0 , 2.0/5.0, 4.0/5.0 ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 -8.0/9.0 , -4.0/9.0 , -2.0/9.0 , 2.0/9.0 , 4.0/9.0 , 8.0/9.0 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 static int base[3][9] = {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 { 1 , 0, 2 , } ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 { 17, 18, 0 , 19, 20 , } ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 { 21, 1, 22, 23, 0, 24, 25, 2, 26 } };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 int i,j,k,l,len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 real *table;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 static int tablen[3] = { 3 , 5 , 9 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 static int *itable,*tables[3] = { grp_3tab , grp_5tab , grp_9tab };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 for(i=0;i<3;i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 itable = tables[i];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 len = tablen[i];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 for(j=0;j<len;j++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 for(k=0;k<len;k++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 for(l=0;l<len;l++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 *itable++ = base[i][l];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 *itable++ = base[i][k];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 *itable++ = base[i][j];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 for(k=0;k<27;k++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 double m=mulmul[k];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 table = muls[k];
1245
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 1
diff changeset
59 if(_has_mmx)
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 1
diff changeset
60 {
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 1
diff changeset
61 for(j=3,i=0;i<63;i++,j--)
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 1
diff changeset
62 *table++ = 16384 * m * pow(2.0,(double) j / 3.0);
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 1
diff changeset
63 }
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 1
diff changeset
64 else
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 for(j=3,i=0;i<63;i++,j--)
1245
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 1
diff changeset
66 {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 *table++ = m * pow(2.0,(double) j / 3.0);
1245
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 1
diff changeset
68 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 *table++ = 0.0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 static void II_step_one(unsigned int *bit_alloc,int *scale,struct frame *fr)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 int stereo = fr->stereo-1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 int sblimit = fr->II_sblimit;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 int jsbound = fr->jsbound;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 int sblimit2 = fr->II_sblimit<<stereo;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 struct al_table *alloc1 = fr->alloc;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 static unsigned int scfsi_buf[64];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 unsigned int *scfsi,*bita;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 int sc,step;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 bita = bit_alloc;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 if(stereo)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 {
13336
55174e3d2917 Index must be positive to prevent endless loop on bad data
rtognimp
parents: 12131
diff changeset
89 for (i=jsbound;i>0;i--,alloc1+=(1<<step))
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 *bita++ = (char) getbits(step=alloc1->bits);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 *bita++ = (char) getbits(step);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 }
13336
55174e3d2917 Index must be positive to prevent endless loop on bad data
rtognimp
parents: 12131
diff changeset
94 for (i=sblimit-jsbound;i>0;i--,alloc1+=(1<<step))
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 bita[0] = (char) getbits(step=alloc1->bits);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 bita[1] = bita[0];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 bita+=2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 bita = bit_alloc;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 scfsi=scfsi_buf;
13336
55174e3d2917 Index must be positive to prevent endless loop on bad data
rtognimp
parents: 12131
diff changeset
102 for (i=sblimit2;i>0;i--)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 if (*bita++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 *scfsi++ = (char) getbits_fast(2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 else /* mono */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 {
13336
55174e3d2917 Index must be positive to prevent endless loop on bad data
rtognimp
parents: 12131
diff changeset
108 for (i=sblimit;i>0;i--,alloc1+=(1<<step))
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 *bita++ = (char) getbits(step=alloc1->bits);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 bita = bit_alloc;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 scfsi=scfsi_buf;
13336
55174e3d2917 Index must be positive to prevent endless loop on bad data
rtognimp
parents: 12131
diff changeset
112 for (i=sblimit;i>0;i--)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 if (*bita++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 *scfsi++ = (char) getbits_fast(2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 bita = bit_alloc;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 scfsi=scfsi_buf;
13336
55174e3d2917 Index must be positive to prevent endless loop on bad data
rtognimp
parents: 12131
diff changeset
119 for (i=sblimit2;i>0;i--)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 if (*bita++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 switch (*scfsi++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 case 0:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 *scale++ = getbits_fast(6);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 *scale++ = getbits_fast(6);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126 *scale++ = getbits_fast(6);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 case 1 :
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 *scale++ = sc = getbits_fast(6);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 *scale++ = sc;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 *scale++ = getbits_fast(6);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 case 2:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 *scale++ = sc = getbits_fast(6);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 *scale++ = sc;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 *scale++ = sc;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 default: /* case 3 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 *scale++ = getbits_fast(6);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 *scale++ = sc = getbits_fast(6);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 *scale++ = sc;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 static void II_step_two(unsigned int *bit_alloc,real fraction[2][4][SBLIMIT],int *scale,struct frame *fr,int x1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 int i,j,k,ba;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 int stereo = fr->stereo;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 int sblimit = fr->II_sblimit;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 int jsbound = fr->jsbound;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 struct al_table *alloc2,*alloc1 = fr->alloc;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154 unsigned int *bita=bit_alloc;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155 int d1,step;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157 for (i=0;i<jsbound;i++,alloc1+=(1<<step))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159 step = alloc1->bits;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 for (j=0;j<stereo;j++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162 if ( (ba=*bita++) )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 k=(alloc2 = alloc1+ba)->bits;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
165 if( (d1=alloc2->d) < 0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
166 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167 real cm=muls[k][scale[x1]];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 fraction[j][0][i] = ((real) ((int)getbits(k) + d1)) * cm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 fraction[j][1][i] = ((real) ((int)getbits(k) + d1)) * cm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 fraction[j][2][i] = ((real) ((int)getbits(k) + d1)) * cm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174 static int *table[] = { 0,0,0,grp_3tab,0,grp_5tab,0,0,0,grp_9tab };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175 unsigned int idx,*tab,m=scale[x1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176 idx = (unsigned int) getbits(k);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177 tab = (unsigned int *) (table[d1] + idx + idx + idx);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178 fraction[j][0][i] = muls[*tab++][m];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 fraction[j][1][i] = muls[*tab++][m];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180 fraction[j][2][i] = muls[*tab][m];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 scale+=3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
184 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185 fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
189 for (i=jsbound;i<sblimit;i++,alloc1+=(1<<step))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
191 step = alloc1->bits;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192 bita++; /* channel 1 and channel 2 bitalloc are the same */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193 if ( (ba=*bita++) )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
195 k=(alloc2 = alloc1+ba)->bits;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
196 if( (d1=alloc2->d) < 0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
197 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198 real cm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
199 cm=muls[k][scale[x1+3]];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200 fraction[1][0][i] = (fraction[0][0][i] = (real) ((int)getbits(k) + d1) ) * cm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
201 fraction[1][1][i] = (fraction[0][1][i] = (real) ((int)getbits(k) + d1) ) * cm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202 fraction[1][2][i] = (fraction[0][2][i] = (real) ((int)getbits(k) + d1) ) * cm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203 cm=muls[k][scale[x1]];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204 fraction[0][0][i] *= cm; fraction[0][1][i] *= cm; fraction[0][2][i] *= cm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
207 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
208 static int *table[] = { 0,0,0,grp_3tab,0,grp_5tab,0,0,0,grp_9tab };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209 unsigned int idx,*tab,m1,m2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210 m1 = scale[x1]; m2 = scale[x1+3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211 idx = (unsigned int) getbits(k);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212 tab = (unsigned int *) (table[d1] + idx + idx + idx);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
213 fraction[0][0][i] = muls[*tab][m1]; fraction[1][0][i] = muls[*tab++][m2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
214 fraction[0][1][i] = muls[*tab][m1]; fraction[1][1][i] = muls[*tab++][m2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
215 fraction[0][2][i] = muls[*tab][m1]; fraction[1][2][i] = muls[*tab][m2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
216 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
217 scale+=6;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
218 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
219 else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
220 fraction[0][0][i] = fraction[0][1][i] = fraction[0][2][i] =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
221 fraction[1][0][i] = fraction[1][1][i] = fraction[1][2][i] = 0.0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
222 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
223 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
224 should we use individual scalefac for channel 2 or
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
225 is the current way the right one , where we just copy channel 1 to
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
226 channel 2 ??
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
227 The current 'strange' thing is, that we throw away the scalefac
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
228 values for the second channel ...!!
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
229 -> changed .. now we use the scalefac values of channel one !!
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
230 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
231 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
232
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233 if(sblimit > (fr->down_sample_sblimit) )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
234 sblimit = fr->down_sample_sblimit;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
235
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
236 for(i=sblimit;i<SBLIMIT;i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
237 for (j=0;j<stereo;j++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
238 fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
239
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
240 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
241
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
242 static void II_select_table(struct frame *fr)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
243 {
9152
arpi
parents: 9130
diff changeset
244 static int translate[9][2][16] =
9130
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
245 { { { 0,2,2,2,2,2,2,0,0,0,1,1,1,1,1,0 } , /*44.1 stereo*/
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
246 { 0,2,2,0,0,0,1,1,1,1,1,1,1,1,1,0 } } , /*44.1 mono*/
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
247 { { 0,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0 } , /*48 stereo*/
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
248 { 0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0 } } , /*48 mono*/
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
249 { { 0,3,3,3,3,3,3,0,0,0,1,1,1,1,1,0 } , /*32 stereo*/
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
250 { 0,3,3,0,0,0,1,1,1,1,1,1,1,1,1,0 } } , /*32 mono*/
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
251 { { 2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,0 } , /*22.05 stereo*/
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
252 { 2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,0 } } , /*22.05 mono*/
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
253 { { 2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,0 } , /*24 stereo*/
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
254 { 2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,0 } } , /*24 mono*/
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
255 { { 2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,0 } , /*16 stereo*/
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
256 { 2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,0 } } , /*16 mono*/
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
257 { { 2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,0 } , /*11.025 stereo*/
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
258 { 2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,0 } } , /*11.025 mono*/
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
259 { { 2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,0 } , /*12 stereo*/
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
260 { 2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,0 } } , /*12 mono*/
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
261 { { 2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,0 } , /*8 stereo*/
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
262 { 2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,0 } } /*8 mono*/
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
263 /* 0 48 64 96 128 192 256 384 */
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
264 /* 32 56 80 112 160 224 320 XX*/
8a0a93d6b4c3 In mp3lib/sr1.c, look at the line 226:
arpi
parents: 1245
diff changeset
265 };
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
266
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
267 int table,sblim;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
268 static struct al_table *tables[5] =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
269 { alloc_0, alloc_1, alloc_2, alloc_3 , alloc_4 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
270 static int sblims[5] = { 27 , 30 , 8, 12 , 30 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
271
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
272 if(fr->lsf)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
273 table = 4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
274 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
275 table = translate[fr->sampling_frequency][2-fr->stereo][fr->bitrate_index];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
276 sblim = sblims[table];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
277
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
278 fr->alloc = tables[table];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
279 fr->II_sblimit = sblim;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
280 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
281
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
282
12131
d155623271e3 fix symbol clashes when linking with libmp3lame including mp3 decoder, man, mp3lib is so much bloated
alex
parents: 9152
diff changeset
283 static int do_layer2(struct frame *fr,int outmode)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
284 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
285 int clip=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
286 int i,j;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
287 int stereo = fr->stereo;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
288 real fraction[2][4][SBLIMIT]; /* pick_table clears unused subbands */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
289 unsigned int bit_alloc[64];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
290 int scale[192];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
291 int single = fr->single;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
292
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
293 II_select_table(fr);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
294 fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
295 (fr->mode_ext<<2)+4 : fr->II_sblimit;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
296
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
297 if(stereo == 1 || single == 3)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
298 single = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
299
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
300 II_step_one(bit_alloc, scale, fr);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
301
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
302 for (i=0;i<SCALE_BLOCK;i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
303 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
304 II_step_two(bit_alloc,fraction,scale,fr,i>>2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
305 for (j=0;j<3;j++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
306 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
307 if(single >= 0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
308 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
309 clip += (fr->synth_mono) (fraction[single][j],pcm_sample,&pcm_point);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
310 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
311 else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
312 int p1 = pcm_point;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
313 clip += (fr->synth) (fraction[0][j],0,pcm_sample,&p1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
314 clip += (fr->synth) (fraction[1][j],1,pcm_sample,&pcm_point);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
315 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
316
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
317 // if(pcm_point >= audiobufsize) audio_flush(outmode,ai);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
318 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
319 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
320
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
321 return clip;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
322 }