Mercurial > mplayer.hg
annotate mp3lib/layer3.c @ 20376:bac6402e25a2
sync w/r20341
author | gpoirier |
---|---|
date | Sun, 22 Oct 2006 19:31:49 +0000 |
parents | 0783dd397f74 |
children | d986b47f1451 |
rev | line source |
---|---|
15167
07e7a572bd84
Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents:
12134
diff
changeset
|
1 /* |
18783 | 2 * Modified for use with MPlayer, for details see the changelog at |
3 * http://svn.mplayerhq.hu/mplayer/trunk/ | |
15167
07e7a572bd84
Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents:
12134
diff
changeset
|
4 * $Id$ |
07e7a572bd84
Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents:
12134
diff
changeset
|
5 */ |
07e7a572bd84
Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents:
12134
diff
changeset
|
6 |
10343 | 7 /* |
1 | 8 * Mpeg Layer-3 audio decoder |
9 * -------------------------- | |
10343 | 10 * copyright (c) 1995-1999 by Michael Hipp. |
1 | 11 * All rights reserved. See also 'README' |
12 * | |
10343 | 13 * Optimize-TODO: put short bands into the band-field without the stride |
14 * of 3 reals | |
15 * Length-optimze: unify long and short band code where it is possible | |
1 | 16 */ |
17 | |
10343 | 18 #if 0 |
19 #define L3_DEBUG 1 | |
20 #endif | |
21 | |
22 #if 0 | |
23 #define CUT_HF | |
24 #endif | |
25 | |
26 # define REAL_MUL(x, y) ((x) * (y)) | |
27 | |
1 | 28 static real ispow[8207]; |
29 static real aa_ca[8],aa_cs[8]; | |
30 static real COS1[12][6]; | |
31 static real win[4][36]; | |
32 static real win1[4][36]; | |
10343 | 33 static real gainpow2[256+118+4]; |
1 | 34 |
10343 | 35 /* non static for external 3dnow functions */ |
36 real COS9[9]; | |
1 | 37 static real COS6_1,COS6_2; |
10343 | 38 real tfcos36[9]; |
39 | |
1 | 40 static real tfcos12[3]; |
10343 | 41 #define NEW_DCT9 |
1 | 42 #ifdef NEW_DCT9 |
43 static real cos9[3],cos18[3]; | |
44 #endif | |
45 | |
46 struct bandInfoStruct { | |
47 int longIdx[23]; | |
48 int longDiff[22]; | |
49 int shortIdx[14]; | |
50 int shortDiff[13]; | |
51 }; | |
52 | |
12131
d155623271e3
fix symbol clashes when linking with libmp3lame including mp3 decoder, man, mp3lib is so much bloated
alex
parents:
10388
diff
changeset
|
53 static int longLimit[9][23]; |
d155623271e3
fix symbol clashes when linking with libmp3lame including mp3 decoder, man, mp3lib is so much bloated
alex
parents:
10388
diff
changeset
|
54 static int shortLimit[9][14]; |
1 | 55 |
12131
d155623271e3
fix symbol clashes when linking with libmp3lame including mp3 decoder, man, mp3lib is so much bloated
alex
parents:
10388
diff
changeset
|
56 static struct bandInfoStruct bandInfo[9] = { |
1 | 57 |
58 /* MPEG 1.0 */ | |
59 { {0,4,8,12,16,20,24,30,36,44,52,62,74, 90,110,134,162,196,238,288,342,418,576}, | |
60 {4,4,4,4,4,4,6,6,8, 8,10,12,16,20,24,28,34,42,50,54, 76,158}, | |
61 {0,4*3,8*3,12*3,16*3,22*3,30*3,40*3,52*3,66*3, 84*3,106*3,136*3,192*3}, | |
62 {4,4,4,4,6,8,10,12,14,18,22,30,56} } , | |
63 | |
64 { {0,4,8,12,16,20,24,30,36,42,50,60,72, 88,106,128,156,190,230,276,330,384,576}, | |
65 {4,4,4,4,4,4,6,6,6, 8,10,12,16,18,22,28,34,40,46,54, 54,192}, | |
66 {0,4*3,8*3,12*3,16*3,22*3,28*3,38*3,50*3,64*3, 80*3,100*3,126*3,192*3}, | |
67 {4,4,4,4,6,6,10,12,14,16,20,26,66} } , | |
68 | |
69 { {0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576} , | |
10343 | 70 {4,4,4,4,4,4,6,6,8,10,12,16,20,24,30,38,46,56,68,84,102, 26} , |
71 {0,4*3,8*3,12*3,16*3,22*3,30*3,42*3,58*3,78*3,104*3,138*3,180*3,192*3} , | |
1 | 72 {4,4,4,4,6,8,12,16,20,26,34,42,12} } , |
73 | |
74 /* MPEG 2.0 */ | |
75 { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, | |
10343 | 76 {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 } , |
1 | 77 {0,4*3,8*3,12*3,18*3,24*3,32*3,42*3,56*3,74*3,100*3,132*3,174*3,192*3} , |
78 {4,4,4,6,6,8,10,14,18,26,32,42,18 } } , | |
10343 | 79 /* changed 19th value fropm 330 to 332 */ |
80 { {0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,332,394,464,540,576}, | |
81 {6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,54,62,70,76,36 } , | |
1 | 82 {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,136*3,180*3,192*3} , |
83 {4,4,4,6,8,10,12,14,18,24,32,44,12 } } , | |
84 | |
85 { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, | |
86 {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 }, | |
87 {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,134*3,174*3,192*3}, | |
88 {4,4,4,6,8,10,12,14,18,24,30,40,18 } } , | |
89 /* MPEG 2.5 */ | |
90 { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} , | |
10343 | 91 {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54}, |
1 | 92 {0,12,24,36,54,78,108,144,186,240,312,402,522,576}, |
93 {4,4,4,6,8,10,12,14,18,24,30,40,18} }, | |
94 { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} , | |
95 {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54}, | |
10343 | 96 {0,12,24,36,54,78,108,144,186,240,312,402,522,576}, |
1 | 97 {4,4,4,6,8,10,12,14,18,24,30,40,18} }, |
98 { {0,12,24,36,48,60,72,88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576}, | |
99 {12,12,12,12,12,12,16,20,24,28,32,40,48,56,64,76,90,2,2,2,2,2}, | |
100 {0, 24, 48, 72,108,156,216,288,372,480,486,492,498,576}, | |
101 {8,8,8,12,16,20,24,28,36,2,2,2,26} } , | |
102 }; | |
103 | |
104 static int mapbuf0[9][152]; | |
105 static int mapbuf1[9][156]; | |
106 static int mapbuf2[9][44]; | |
107 static int *map[9][3]; | |
108 static int *mapend[9][3]; | |
109 | |
110 static unsigned int n_slen2[512]; /* MPEG 2.0 slen for 'normal' mode */ | |
111 static unsigned int i_slen2[256]; /* MPEG 2.0 slen for intensity stereo */ | |
112 | |
113 static real tan1_1[16],tan2_1[16],tan1_2[16],tan2_2[16]; | |
114 static real pow1_1[2][16],pow2_1[2][16],pow1_2[2][16],pow2_2[2][16]; | |
115 | |
116 /* | |
117 * init tables for layer-3 | |
118 */ | |
12131
d155623271e3
fix symbol clashes when linking with libmp3lame including mp3 decoder, man, mp3lib is so much bloated
alex
parents:
10388
diff
changeset
|
119 static void init_layer3(int down_sample_sblimit) |
1 | 120 { |
121 int i,j,k,l; | |
122 | |
123 for(i=-256;i<118+4;i++) | |
1245
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
716
diff
changeset
|
124 { |
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
716
diff
changeset
|
125 if(_has_mmx) |
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
716
diff
changeset
|
126 gainpow2[i+256] = 16384.0 * pow((double)2.0,-0.25 * (double) (i+210) ); |
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
716
diff
changeset
|
127 else |
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
716
diff
changeset
|
128 gainpow2[i+256] = pow((double)2.0,-0.25 * (double) (i+210) ); |
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
716
diff
changeset
|
129 } |
1 | 130 for(i=0;i<8207;i++) |
131 ispow[i] = pow((double)i,(double)4.0/3.0); | |
132 | |
133 for (i=0;i<8;i++) | |
134 { | |
135 static double Ci[8]={-0.6,-0.535,-0.33,-0.185,-0.095,-0.041,-0.0142,-0.0037}; | |
136 double sq=sqrt(1.0+Ci[i]*Ci[i]); | |
137 aa_cs[i] = 1.0/sq; | |
138 aa_ca[i] = Ci[i]/sq; | |
139 } | |
140 | |
141 for(i=0;i<18;i++) | |
142 { | |
143 win[0][i] = win[1][i] = 0.5 * sin( M_PI / 72.0 * (double) (2*(i+0) +1) ) / cos ( M_PI * (double) (2*(i+0) +19) / 72.0 ); | |
144 win[0][i+18] = win[3][i+18] = 0.5 * sin( M_PI / 72.0 * (double) (2*(i+18)+1) ) / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 ); | |
145 } | |
146 for(i=0;i<6;i++) | |
147 { | |
148 win[1][i+18] = 0.5 / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 ); | |
149 win[3][i+12] = 0.5 / cos ( M_PI * (double) (2*(i+12)+19) / 72.0 ); | |
150 win[1][i+24] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+13) ) / cos ( M_PI * (double) (2*(i+24)+19) / 72.0 ); | |
151 win[1][i+30] = win[3][i] = 0.0; | |
152 win[3][i+6 ] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+1) ) / cos ( M_PI * (double) (2*(i+6 )+19) / 72.0 ); | |
153 } | |
154 | |
155 for(i=0;i<9;i++) | |
1245
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
716
diff
changeset
|
156 COS9[i] = cos( M_PI / 18.0 * (double) i); |
1 | 157 |
158 for(i=0;i<9;i++) | |
159 tfcos36[i] = 0.5 / cos ( M_PI * (double) (i*2+1) / 36.0 ); | |
160 for(i=0;i<3;i++) | |
161 tfcos12[i] = 0.5 / cos ( M_PI * (double) (i*2+1) / 12.0 ); | |
162 | |
163 COS6_1 = cos( M_PI / 6.0 * (double) 1); | |
164 COS6_2 = cos( M_PI / 6.0 * (double) 2); | |
165 | |
166 #ifdef NEW_DCT9 | |
167 cos9[0] = cos(1.0*M_PI/9.0); | |
168 cos9[1] = cos(5.0*M_PI/9.0); | |
169 cos9[2] = cos(7.0*M_PI/9.0); | |
170 cos18[0] = cos(1.0*M_PI/18.0); | |
171 cos18[1] = cos(11.0*M_PI/18.0); | |
172 cos18[2] = cos(13.0*M_PI/18.0); | |
173 #endif | |
174 | |
175 for(i=0;i<12;i++) | |
176 { | |
177 win[2][i] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+1) ) / cos ( M_PI * (double) (2*i+7) / 24.0 ); | |
178 for(j=0;j<6;j++) | |
179 COS1[i][j] = cos( M_PI / 24.0 * (double) ((2*i+7)*(2*j+1)) ); | |
180 } | |
181 | |
182 for(j=0;j<4;j++) { | |
183 static int len[4] = { 36,36,12,36 }; | |
184 for(i=0;i<len[j];i+=2) | |
185 win1[j][i] = + win[j][i]; | |
186 for(i=1;i<len[j];i+=2) | |
187 win1[j][i] = - win[j][i]; | |
188 } | |
189 | |
190 for(i=0;i<16;i++) | |
191 { | |
192 double t = tan( (double) i * M_PI / 12.0 ); | |
193 tan1_1[i] = t / (1.0+t); | |
194 tan2_1[i] = 1.0 / (1.0 + t); | |
195 tan1_2[i] = M_SQRT2 * t / (1.0+t); | |
196 tan2_2[i] = M_SQRT2 / (1.0 + t); | |
197 | |
198 for(j=0;j<2;j++) { | |
199 double base = pow(2.0,-0.25*(j+1.0)); | |
200 double p1=1.0,p2=1.0; | |
201 if(i > 0) { | |
202 if( i & 1 ) | |
203 p1 = pow(base,(i+1.0)*0.5); | |
204 else | |
205 p2 = pow(base,i*0.5); | |
206 } | |
207 pow1_1[j][i] = p1; | |
208 pow2_1[j][i] = p2; | |
209 pow1_2[j][i] = M_SQRT2 * p1; | |
210 pow2_2[j][i] = M_SQRT2 * p2; | |
211 } | |
212 } | |
213 | |
214 for(j=0;j<9;j++) | |
215 { | |
216 struct bandInfoStruct *bi = &bandInfo[j]; | |
217 int *mp; | |
218 int cb,lwin; | |
219 int *bdf; | |
220 | |
221 mp = map[j][0] = mapbuf0[j]; | |
222 bdf = bi->longDiff; | |
223 for(i=0,cb = 0; cb < 8 ; cb++,i+=*bdf++) { | |
224 *mp++ = (*bdf) >> 1; | |
225 *mp++ = i; | |
226 *mp++ = 3; | |
227 *mp++ = cb; | |
228 } | |
229 bdf = bi->shortDiff+3; | |
230 for(cb=3;cb<13;cb++) { | |
231 int l = (*bdf++) >> 1; | |
232 for(lwin=0;lwin<3;lwin++) { | |
233 *mp++ = l; | |
234 *mp++ = i + lwin; | |
235 *mp++ = lwin; | |
236 *mp++ = cb; | |
237 } | |
238 i += 6*l; | |
239 } | |
240 mapend[j][0] = mp; | |
241 | |
242 mp = map[j][1] = mapbuf1[j]; | |
243 bdf = bi->shortDiff+0; | |
244 for(i=0,cb=0;cb<13;cb++) { | |
245 int l = (*bdf++) >> 1; | |
246 for(lwin=0;lwin<3;lwin++) { | |
247 *mp++ = l; | |
248 *mp++ = i + lwin; | |
249 *mp++ = lwin; | |
250 *mp++ = cb; | |
251 } | |
252 i += 6*l; | |
253 } | |
254 mapend[j][1] = mp; | |
255 | |
256 mp = map[j][2] = mapbuf2[j]; | |
257 bdf = bi->longDiff; | |
258 for(cb = 0; cb < 22 ; cb++) { | |
259 *mp++ = (*bdf++) >> 1; | |
260 *mp++ = cb; | |
261 } | |
262 mapend[j][2] = mp; | |
263 | |
264 } | |
265 | |
266 for(j=0;j<9;j++) { | |
267 for(i=0;i<23;i++) { | |
268 longLimit[j][i] = (bandInfo[j].longIdx[i] - 1 + 8) / 18 + 1; | |
269 if(longLimit[j][i] > (down_sample_sblimit) ) | |
270 longLimit[j][i] = down_sample_sblimit; | |
271 } | |
272 for(i=0;i<14;i++) { | |
273 shortLimit[j][i] = (bandInfo[j].shortIdx[i] - 1) / 18 + 1; | |
274 if(shortLimit[j][i] > (down_sample_sblimit) ) | |
275 shortLimit[j][i] = down_sample_sblimit; | |
276 } | |
277 } | |
278 | |
279 for(i=0;i<5;i++) { | |
280 for(j=0;j<6;j++) { | |
281 for(k=0;k<6;k++) { | |
282 int n = k + j * 6 + i * 36; | |
10343 | 283 i_slen2[n] = i|(j<<3)|(k<<6)|(3<<12); |
1 | 284 } |
285 } | |
286 } | |
287 for(i=0;i<4;i++) { | |
288 for(j=0;j<4;j++) { | |
289 for(k=0;k<4;k++) { | |
290 int n = k + j * 4 + i * 16; | |
10343 | 291 i_slen2[n+180] = i|(j<<3)|(k<<6)|(4<<12); |
1 | 292 } |
293 } | |
294 } | |
295 for(i=0;i<4;i++) { | |
296 for(j=0;j<3;j++) { | |
297 int n = j + i * 3; | |
10343 | 298 i_slen2[n+244] = i|(j<<3) | (5<<12); |
299 n_slen2[n+500] = i|(j<<3) | (2<<12) | (1<<15); | |
1 | 300 } |
301 } | |
302 | |
303 for(i=0;i<5;i++) { | |
304 for(j=0;j<5;j++) { | |
305 for(k=0;k<4;k++) { | |
306 for(l=0;l<4;l++) { | |
307 int n = l + k * 4 + j * 16 + i * 80; | |
10343 | 308 n_slen2[n] = i|(j<<3)|(k<<6)|(l<<9)|(0<<12); |
1 | 309 } |
310 } | |
311 } | |
312 } | |
313 for(i=0;i<5;i++) { | |
314 for(j=0;j<5;j++) { | |
315 for(k=0;k<4;k++) { | |
316 int n = k + j * 4 + i * 20; | |
10343 | 317 n_slen2[n+400] = i|(j<<3)|(k<<6)|(1<<12); |
1 | 318 } |
319 } | |
320 } | |
321 } | |
322 | |
323 /* | |
10343 | 324 * read additional side information (for MPEG 1 and MPEG 2) |
1 | 325 */ |
10343 | 326 static int III_get_side_info(struct III_sideinfo *si,int stereo, |
327 int ms_stereo,long sfreq,int single,int lsf) | |
1 | 328 { |
329 int ch, gr; | |
330 int powdiff = (single == 3) ? 4 : 0; | |
331 | |
10343 | 332 static const int tabs[2][5] = { { 2,9,5,3,4 } , { 1,8,1,2,9 } }; |
333 const int *tab = tabs[lsf]; | |
334 | |
335 si->main_data_begin = getbits(tab[1]); | |
1 | 336 if (stereo == 1) |
10343 | 337 si->private_bits = getbits_fast(tab[2]); |
1 | 338 else |
10343 | 339 si->private_bits = getbits_fast(tab[3]); |
1 | 340 |
10343 | 341 if(!lsf) { |
342 for (ch=0; ch<stereo; ch++) { | |
343 si->ch[ch].gr[0].scfsi = -1; | |
344 si->ch[ch].gr[1].scfsi = getbits_fast(4); | |
345 } | |
1 | 346 } |
347 | |
10343 | 348 for (gr=0; gr<tab[0]; gr++) { |
1 | 349 for (ch=0; ch<stereo; ch++) { |
350 register struct gr_info_s *gr_info = &(si->ch[ch].gr[gr]); | |
351 | |
352 gr_info->part2_3_length = getbits(12); | |
353 gr_info->big_values = getbits(9); | |
354 if(gr_info->big_values > 288) { | |
10343 | 355 fprintf(stderr,"big_values too large!\n"); |
1 | 356 gr_info->big_values = 288; |
357 } | |
10343 | 358 gr_info->pow2gain = gainpow2+256 - getbits_fast(8) + powdiff; |
359 if(ms_stereo) | |
360 gr_info->pow2gain += 2; | |
361 gr_info->scalefac_compress = getbits(tab[4]); | |
1 | 362 |
10343 | 363 if(get1bit()) { /* window switch flag */ |
1 | 364 int i; |
10343 | 365 #ifdef L3_DEBUG |
366 if(2*gr_info->big_values > bandInfo[sfreq].shortIdx[12]) | |
367 fprintf(stderr,"L3: BigValues too large, doesn't make sense %d %d\n",2*gr_info->big_values,bandInfo[sfreq].shortIdx[12]); | |
368 #endif | |
369 | |
370 gr_info->block_type = getbits_fast(2); | |
1 | 371 gr_info->mixed_block_flag = get1bit(); |
10343 | 372 gr_info->table_select[0] = getbits_fast(5); |
373 gr_info->table_select[1] = getbits_fast(5); | |
1 | 374 /* |
375 * table_select[2] not needed, because there is no region2, | |
376 * but to satisfy some verifications tools we set it either. | |
377 */ | |
378 gr_info->table_select[2] = 0; | |
379 for(i=0;i<3;i++) | |
380 gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(3)<<3); | |
381 | |
382 if(gr_info->block_type == 0) { | |
10343 | 383 fprintf(stderr,"Blocktype == 0 and window-switching == 1 not allowed.\n"); |
384 return 0; | |
1 | 385 } |
10343 | 386 |
387 /* region_count/start parameters are implicit in this case. */ | |
388 if(!lsf || gr_info->block_type == 2) | |
389 gr_info->region1start = 36>>1; | |
390 else { | |
391 /* check this again for 2.5 and sfreq=8 */ | |
392 if(sfreq == 8) | |
393 gr_info->region1start = 108>>1; | |
394 else | |
395 gr_info->region1start = 54>>1; | |
396 } | |
1 | 397 gr_info->region2start = 576>>1; |
10343 | 398 } |
399 else { | |
1 | 400 int i,r0c,r1c; |
10349 | 401 #ifdef L3_DEBUG |
10343 | 402 if(2*gr_info->big_values > bandInfo[sfreq].longIdx[21]) |
403 fprintf(stderr,"L3: BigValues too large, doesn't make sense %d %d\n",2*gr_info->big_values,bandInfo[sfreq].longIdx[21]); | |
10349 | 404 #endif |
1 | 405 for (i=0; i<3; i++) |
406 gr_info->table_select[i] = getbits_fast(5); | |
407 r0c = getbits_fast(4); | |
408 r1c = getbits_fast(3); | |
409 gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ; | |
10343 | 410 if(r0c + r1c + 2 > 22) |
411 gr_info->region2start = 576>>1; | |
412 else | |
413 gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1; | |
1 | 414 gr_info->block_type = 0; |
415 gr_info->mixed_block_flag = 0; | |
416 } | |
10343 | 417 if(!lsf) |
418 gr_info->preflag = get1bit(); | |
1 | 419 gr_info->scalefac_scale = get1bit(); |
420 gr_info->count1table_select = get1bit(); | |
421 } | |
422 } | |
423 | |
10343 | 424 return !0; |
1 | 425 } |
426 | |
427 /* | |
428 * read scalefactors | |
429 */ | |
430 static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info) | |
431 { | |
10343 | 432 static const unsigned char slen[2][16] = { |
1 | 433 {0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4}, |
434 {0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3} | |
435 }; | |
436 int numbits; | |
437 int num0 = slen[0][gr_info->scalefac_compress]; | |
438 int num1 = slen[1][gr_info->scalefac_compress]; | |
439 | |
440 if (gr_info->block_type == 2) { | |
441 int i=18; | |
442 numbits = (num0 + num1) * 18; | |
10343 | 443 |
1 | 444 if (gr_info->mixed_block_flag) { |
10343 | 445 for (i=8;i;i--) |
446 *scf++ = getbits_fast(num0); | |
1 | 447 i = 9; |
448 numbits -= num0; /* num0 * 17 + num1 * 18 */ | |
449 } | |
10343 | 450 |
451 for (;i;i--) | |
452 *scf++ = getbits_fast(num0); | |
453 for (i = 18; i; i--) | |
454 *scf++ = getbits_fast(num1); | |
1 | 455 *scf++ = 0; *scf++ = 0; *scf++ = 0; /* short[13][0..2] = 0 */ |
10343 | 456 } |
457 else { | |
1 | 458 int i; |
459 int scfsi = gr_info->scfsi; | |
460 | |
461 if(scfsi < 0) { /* scfsi < 0 => granule == 0 */ | |
10343 | 462 for(i=11;i;i--) |
463 *scf++ = getbits_fast(num0); | |
464 for(i=10;i;i--) | |
465 *scf++ = getbits_fast(num1); | |
1 | 466 numbits = (num0 + num1) * 10 + num0; |
10343 | 467 *scf++ = 0; |
468 } | |
469 else { | |
1 | 470 numbits = 0; |
471 if(!(scfsi & 0x8)) { | |
10343 | 472 for (i=0;i<6;i++) |
473 *scf++ = getbits_fast(num0); | |
1 | 474 numbits += num0 * 6; |
10343 | 475 } |
476 else { | |
477 scf += 6; | |
1 | 478 } |
10343 | 479 |
1 | 480 if(!(scfsi & 0x4)) { |
10343 | 481 for (i=0;i<5;i++) |
482 *scf++ = getbits_fast(num0); | |
1 | 483 numbits += num0 * 5; |
10343 | 484 } |
485 else { | |
1 | 486 scf += 5; |
487 } | |
10343 | 488 |
1 | 489 if(!(scfsi & 0x2)) { |
10343 | 490 for(i=0;i<5;i++) |
491 *scf++ = getbits_fast(num1); | |
1 | 492 numbits += num1 * 5; |
493 } | |
10343 | 494 else { |
495 scf += 5; | |
496 } | |
497 | |
1 | 498 if(!(scfsi & 0x1)) { |
10343 | 499 for (i=0;i<5;i++) |
500 *scf++ = getbits_fast(num1); | |
1 | 501 numbits += num1 * 5; |
502 } | |
10343 | 503 else { |
504 scf += 5; | |
505 } | |
506 *scf++ = 0; /* no l[21] in original sources */ | |
1 | 507 } |
508 } | |
509 return numbits; | |
510 } | |
511 | |
512 static int III_get_scale_factors_2(int *scf,struct gr_info_s *gr_info,int i_stereo) | |
513 { | |
514 unsigned char *pnt; | |
515 int i,j; | |
516 unsigned int slen; | |
517 int n = 0; | |
518 int numbits = 0; | |
519 | |
520 static unsigned char stab[3][6][4] = { | |
521 { { 6, 5, 5,5 } , { 6, 5, 7,3 } , { 11,10,0,0} , | |
522 { 7, 7, 7,0 } , { 6, 6, 6,3 } , { 8, 8,5,0} } , | |
523 { { 9, 9, 9,9 } , { 9, 9,12,6 } , { 18,18,0,0} , | |
524 {12,12,12,0 } , {12, 9, 9,6 } , { 15,12,9,0} } , | |
525 { { 6, 9, 9,9 } , { 6, 9,12,6 } , { 15,18,0,0} , | |
526 { 6,15,12,0 } , { 6,12, 9,6 } , { 6,18,9,0} } }; | |
527 | |
528 if(i_stereo) /* i_stereo AND second channel -> do_layer3() checks this */ | |
529 slen = i_slen2[gr_info->scalefac_compress>>1]; | |
530 else | |
531 slen = n_slen2[gr_info->scalefac_compress]; | |
532 | |
533 gr_info->preflag = (slen>>15) & 0x1; | |
534 | |
535 n = 0; | |
536 if( gr_info->block_type == 2 ) { | |
537 n++; | |
538 if(gr_info->mixed_block_flag) n++; | |
539 } | |
540 | |
541 pnt = stab[n][(slen>>12)&0x7]; | |
542 | |
543 for(i=0;i<4;i++) { | |
544 int num = slen & 0x7; | |
545 slen >>= 3; | |
546 if(num) { | |
547 for(j=0;j<(int)(pnt[i]);j++) *scf++ = getbits_fast(num); | |
548 numbits += pnt[i] * num; | |
549 } | |
550 else { | |
551 for(j=0;j<(int)(pnt[i]);j++) *scf++ = 0; | |
552 } | |
553 } | |
554 | |
555 n = (n << 1) + 1; | |
556 for(i=0;i<n;i++) *scf++ = 0; | |
557 | |
558 return numbits; | |
559 } | |
560 | |
561 static int pretab1[22] = {0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0}; | |
562 static int pretab2[22] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; | |
563 | |
10343 | 564 #define getbitoffset() ((-bitindex)&0x7) |
565 #define getbyte() (*wordpointer++) | |
566 | |
1 | 567 /* |
10343 | 568 * Dequantize samples (includes huffman decoding) |
1 | 569 */ |
10343 | 570 /* 24 is enough because tab13 has max. a 19 bit huffvector */ |
571 #define BITSHIFT ((sizeof(long)-1)*8) | |
572 #define REFRESH_MASK \ | |
573 while(num < BITSHIFT) { \ | |
574 mask |= ((unsigned long)getbyte())<<(BITSHIFT-num); \ | |
575 num += 8; \ | |
576 part2remain -= 8; } | |
577 | |
1 | 578 static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf, |
579 struct gr_info_s *gr_info,int sfreq,int part2bits) | |
580 { | |
581 int shift = 1 + gr_info->scalefac_scale; | |
582 real *xrpnt = (real *) xr; | |
583 int l[3],l3; | |
584 int part2remain = gr_info->part2_3_length - part2bits; | |
585 int *me; | |
586 | |
10343 | 587 int num=getbitoffset(); |
588 long mask; | |
589 /* we must split this, because for num==0 the shift is undefined if you do it in one step */ | |
590 mask = ((unsigned long) getbits(num))<<BITSHIFT; | |
591 mask <<= 8-num; | |
592 part2remain -= num; | |
1 | 593 |
594 { | |
595 int bv = gr_info->big_values; | |
596 int region1 = gr_info->region1start; | |
597 int region2 = gr_info->region2start; | |
598 | |
599 l3 = ((576>>1)-bv)>>1; | |
600 /* | |
601 * we may lose the 'odd' bit here !! | |
10343 | 602 * check this later again |
1 | 603 */ |
604 if(bv <= region1) { | |
10343 | 605 l[0] = bv; l[1] = l[2] = 0; |
1 | 606 } |
607 else { | |
608 l[0] = region1; | |
609 if(bv <= region2) { | |
610 l[1] = bv - l[0]; l[2] = 0; | |
611 } | |
612 else { | |
613 l[1] = region2 - l[0]; l[2] = bv - region2; | |
614 } | |
615 } | |
616 } | |
617 | |
618 if(gr_info->block_type == 2) { | |
10343 | 619 /* |
620 * decoding with short or mixed mode BandIndex table | |
621 */ | |
1 | 622 int i,max[4]; |
10343 | 623 int step=0,lwin=3,cb=0; |
1 | 624 register real v = 0.0; |
10343 | 625 register int *m,mc; |
1 | 626 |
627 if(gr_info->mixed_block_flag) { | |
628 max[3] = -1; | |
629 max[0] = max[1] = max[2] = 2; | |
630 m = map[sfreq][0]; | |
631 me = mapend[sfreq][0]; | |
632 } | |
633 else { | |
634 max[0] = max[1] = max[2] = max[3] = -1; | |
635 /* max[3] not really needed in this case */ | |
636 m = map[sfreq][1]; | |
637 me = mapend[sfreq][1]; | |
638 } | |
639 | |
10343 | 640 mc = 0; |
1 | 641 for(i=0;i<2;i++) { |
642 int lp = l[i]; | |
643 struct newhuff *h = ht+gr_info->table_select[i]; | |
644 for(;lp;lp--,mc--) { | |
10343 | 645 register int x,y; |
646 if( (!mc) ) { | |
647 mc = *m++; | |
648 xrpnt = ((real *) xr) + (*m++); | |
649 lwin = *m++; | |
650 cb = *m++; | |
1 | 651 if(lwin == 3) { |
10343 | 652 v = gr_info->pow2gain[(*scf++) << shift]; |
1 | 653 step = 1; |
654 } | |
655 else { | |
10343 | 656 v = gr_info->full_gain[lwin][(*scf++) << shift]; |
1 | 657 step = 3; |
658 } | |
659 } | |
660 { | |
661 register short *val = h->table; | |
10343 | 662 REFRESH_MASK; |
1 | 663 while((y=*val++)<0) { |
10343 | 664 if (mask < 0) |
665 val -= y; | |
666 num--; | |
667 mask <<= 1; | |
1 | 668 } |
669 x = y >> 4; | |
670 y &= 0xf; | |
671 } | |
10343 | 672 if(x == 15 && h->linbits) { |
1 | 673 max[lwin] = cb; |
10343 | 674 REFRESH_MASK; |
675 x += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits); | |
676 num -= h->linbits+1; | |
677 mask <<= h->linbits; | |
678 if(mask < 0) | |
679 *xrpnt = REAL_MUL(-ispow[x], v); | |
680 else | |
681 *xrpnt = REAL_MUL(ispow[x], v); | |
682 mask <<= 1; | |
1 | 683 } |
684 else if(x) { | |
685 max[lwin] = cb; | |
10343 | 686 if(mask < 0) |
687 *xrpnt = REAL_MUL(-ispow[x], v); | |
688 else | |
689 *xrpnt = REAL_MUL(ispow[x], v); | |
690 num--; | |
691 mask <<= 1; | |
1 | 692 } |
693 else | |
10343 | 694 *xrpnt = 0.0; |
1 | 695 xrpnt += step; |
10343 | 696 if(y == 15 && h->linbits) { |
1 | 697 max[lwin] = cb; |
10343 | 698 REFRESH_MASK; |
699 y += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits); | |
700 num -= h->linbits+1; | |
701 mask <<= h->linbits; | |
702 if(mask < 0) | |
703 *xrpnt = REAL_MUL(-ispow[y], v); | |
704 else | |
705 *xrpnt = REAL_MUL(ispow[y], v); | |
706 mask <<= 1; | |
1 | 707 } |
708 else if(y) { | |
709 max[lwin] = cb; | |
10343 | 710 if(mask < 0) |
711 *xrpnt = REAL_MUL(-ispow[y], v); | |
712 else | |
713 *xrpnt = REAL_MUL(ispow[y], v); | |
714 num--; | |
715 mask <<= 1; | |
1 | 716 } |
717 else | |
10343 | 718 *xrpnt = 0.0; |
1 | 719 xrpnt += step; |
720 } | |
721 } | |
722 | |
10343 | 723 for(;l3 && (part2remain+num > 0);l3--) { |
1 | 724 struct newhuff *h = htc+gr_info->count1table_select; |
725 register short *val = h->table,a; | |
726 | |
10343 | 727 REFRESH_MASK; |
1 | 728 while((a=*val++)<0) { |
10343 | 729 if (mask < 0) |
1 | 730 val -= a; |
10343 | 731 num--; |
732 mask <<= 1; | |
733 } | |
734 if(part2remain+num <= 0) { | |
735 num -= part2remain+num; | |
736 break; | |
1 | 737 } |
738 | |
739 for(i=0;i<4;i++) { | |
740 if(!(i & 1)) { | |
741 if(!mc) { | |
742 mc = *m++; | |
10343 | 743 xrpnt = ((real *) xr) + (*m++); |
1 | 744 lwin = *m++; |
745 cb = *m++; | |
746 if(lwin == 3) { | |
10343 | 747 v = gr_info->pow2gain[(*scf++) << shift]; |
1 | 748 step = 1; |
749 } | |
750 else { | |
10343 | 751 v = gr_info->full_gain[lwin][(*scf++) << shift]; |
1 | 752 step = 3; |
753 } | |
754 } | |
755 mc--; | |
756 } | |
757 if( (a & (0x8>>i)) ) { | |
758 max[lwin] = cb; | |
10343 | 759 if(part2remain+num <= 0) { |
1 | 760 break; |
761 } | |
10343 | 762 if(mask < 0) |
763 *xrpnt = -v; | |
764 else | |
765 *xrpnt = v; | |
766 num--; | |
767 mask <<= 1; | |
1 | 768 } |
769 else | |
10343 | 770 *xrpnt = 0.0; |
1 | 771 xrpnt += step; |
772 } | |
773 } | |
10343 | 774 |
775 if(lwin < 3) { /* short band? */ | |
776 while(1) { | |
777 for(;mc > 0;mc--) { | |
778 *xrpnt = 0.0; xrpnt += 3; /* short band -> step=3 */ | |
779 *xrpnt = 0.0; xrpnt += 3; | |
780 } | |
781 if(m >= me) | |
782 break; | |
783 mc = *m++; | |
784 xrpnt = ((real *) xr) + *m++; | |
785 if(*m++ == 0) | |
786 break; /* optimize: field will be set to zero at the end of the function */ | |
1 | 787 m++; /* cb */ |
788 } | |
789 } | |
790 | |
791 gr_info->maxband[0] = max[0]+1; | |
792 gr_info->maxband[1] = max[1]+1; | |
793 gr_info->maxband[2] = max[2]+1; | |
794 gr_info->maxbandl = max[3]+1; | |
795 | |
796 { | |
797 int rmax = max[0] > max[1] ? max[0] : max[1]; | |
798 rmax = (rmax > max[2] ? rmax : max[2]) + 1; | |
799 gr_info->maxb = rmax ? shortLimit[sfreq][rmax] : longLimit[sfreq][max[3]+1]; | |
800 } | |
10343 | 801 |
1 | 802 } |
803 else { | |
10343 | 804 /* |
805 * decoding with 'long' BandIndex table (block_type != 2) | |
806 */ | |
1 | 807 int *pretab = gr_info->preflag ? pretab1 : pretab2; |
808 int i,max = -1; | |
809 int cb = 0; | |
10343 | 810 int *m = map[sfreq][2]; |
1 | 811 register real v = 0.0; |
10343 | 812 int mc = 0; |
1 | 813 |
10343 | 814 /* |
815 * long hash table values | |
816 */ | |
1 | 817 for(i=0;i<3;i++) { |
818 int lp = l[i]; | |
819 struct newhuff *h = ht+gr_info->table_select[i]; | |
820 | |
821 for(;lp;lp--,mc--) { | |
822 int x,y; | |
10343 | 823 |
1 | 824 if(!mc) { |
825 mc = *m++; | |
826 cb = *m++; | |
10343 | 827 #ifdef CUT_HF |
828 if(cb == 21) { | |
829 fprintf(stderr,"c"); | |
830 v = 0.0; | |
831 } | |
832 else | |
833 #endif | |
834 v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift]; | |
835 | |
1 | 836 } |
837 { | |
838 register short *val = h->table; | |
10343 | 839 REFRESH_MASK; |
1 | 840 while((y=*val++)<0) { |
10343 | 841 if (mask < 0) |
842 val -= y; | |
843 num--; | |
844 mask <<= 1; | |
1 | 845 } |
846 x = y >> 4; | |
847 y &= 0xf; | |
848 } | |
10343 | 849 |
850 if (x == 15 && h->linbits) { | |
1 | 851 max = cb; |
10343 | 852 REFRESH_MASK; |
853 x += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits); | |
854 num -= h->linbits+1; | |
855 mask <<= h->linbits; | |
856 if(mask < 0) | |
857 *xrpnt++ = REAL_MUL(-ispow[x], v); | |
858 else | |
859 *xrpnt++ = REAL_MUL(ispow[x], v); | |
860 mask <<= 1; | |
1 | 861 } |
862 else if(x) { | |
863 max = cb; | |
10343 | 864 if(mask < 0) |
865 *xrpnt++ = REAL_MUL(-ispow[x], v); | |
866 else | |
867 *xrpnt++ = REAL_MUL(ispow[x], v); | |
868 num--; | |
869 mask <<= 1; | |
1 | 870 } |
871 else | |
10343 | 872 *xrpnt++ = 0.0; |
1 | 873 |
10343 | 874 if (y == 15 && h->linbits) { |
1 | 875 max = cb; |
10343 | 876 REFRESH_MASK; |
877 y += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits); | |
878 num -= h->linbits+1; | |
879 mask <<= h->linbits; | |
880 if(mask < 0) | |
881 *xrpnt++ = REAL_MUL(-ispow[y], v); | |
882 else | |
883 *xrpnt++ = REAL_MUL(ispow[y], v); | |
884 mask <<= 1; | |
1 | 885 } |
886 else if(y) { | |
887 max = cb; | |
10343 | 888 if(mask < 0) |
889 *xrpnt++ = REAL_MUL(-ispow[y], v); | |
890 else | |
891 *xrpnt++ = REAL_MUL(ispow[y], v); | |
892 num--; | |
893 mask <<= 1; | |
1 | 894 } |
895 else | |
10343 | 896 *xrpnt++ = 0.0; |
1 | 897 } |
898 } | |
899 | |
10343 | 900 /* |
901 * short (count1table) values | |
902 */ | |
903 for(;l3 && (part2remain+num > 0);l3--) { | |
1 | 904 struct newhuff *h = htc+gr_info->count1table_select; |
905 register short *val = h->table,a; | |
906 | |
10343 | 907 REFRESH_MASK; |
1 | 908 while((a=*val++)<0) { |
10343 | 909 if (mask < 0) |
910 val -= a; | |
911 num--; | |
912 mask <<= 1; | |
913 } | |
914 if(part2remain+num <= 0) { | |
915 num -= part2remain+num; | |
916 break; | |
1 | 917 } |
918 | |
919 for(i=0;i<4;i++) { | |
920 if(!(i & 1)) { | |
921 if(!mc) { | |
922 mc = *m++; | |
923 cb = *m++; | |
10343 | 924 #ifdef CUT_HF |
925 if(cb == 21) { | |
926 fprintf(stderr,"c"); | |
927 v = 0.0; | |
928 } | |
929 else | |
930 #endif | |
931 v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift]; | |
1 | 932 } |
933 mc--; | |
934 } | |
935 if ( (a & (0x8>>i)) ) { | |
936 max = cb; | |
10343 | 937 if(part2remain+num <= 0) { |
1 | 938 break; |
939 } | |
10343 | 940 if(mask < 0) |
941 *xrpnt++ = -v; | |
942 else | |
943 *xrpnt++ = v; | |
944 num--; | |
945 mask <<= 1; | |
1 | 946 } |
947 else | |
10343 | 948 *xrpnt++ = 0.0; |
1 | 949 } |
950 } | |
951 | |
952 gr_info->maxbandl = max+1; | |
953 gr_info->maxb = longLimit[sfreq][gr_info->maxbandl]; | |
954 } | |
955 | |
10343 | 956 part2remain += num; |
957 // backbits(num); | |
958 bitindex -= num; wordpointer += (bitindex>>3); bitindex &= 0x7; | |
959 num = 0; | |
960 | |
961 while(xrpnt < &xr[SBLIMIT][0]) | |
962 *xrpnt++ = 0.0; | |
963 | |
964 while( part2remain > 16 ) { | |
1 | 965 getbits(16); /* Dismiss stuffing Bits */ |
966 part2remain -= 16; | |
967 } | |
10343 | 968 if(part2remain > 0) |
1 | 969 getbits(part2remain); |
970 else if(part2remain < 0) { | |
10343 | 971 fprintf(stderr,"mpg123: Can't rewind stream by %d bits!\n",-part2remain); |
1 | 972 return 1; /* -> error */ |
973 } | |
974 return 0; | |
975 } | |
976 | |
10343 | 977 |
978 | |
979 | |
1 | 980 /* |
981 * III_stereo: calculate real channel values for Joint-I-Stereo-mode | |
982 */ | |
983 static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac, | |
984 struct gr_info_s *gr_info,int sfreq,int ms_stereo,int lsf) | |
985 { | |
986 real (*xr)[SBLIMIT*SSLIMIT] = (real (*)[SBLIMIT*SSLIMIT] ) xr_buf; | |
987 struct bandInfoStruct *bi = &bandInfo[sfreq]; | |
10343 | 988 |
989 const real *tab1,*tab2; | |
1 | 990 |
10343 | 991 int tab; |
992 static const real *tabs[3][2][2] = { | |
993 { { tan1_1,tan2_1 } , { tan1_2,tan2_2 } }, | |
994 { { pow1_1[0],pow2_1[0] } , { pow1_2[0],pow2_2[0] } } , | |
995 { { pow1_1[1],pow2_1[1] } , { pow1_2[1],pow2_2[1] } } | |
996 }; | |
997 | |
998 tab = lsf + (gr_info->scalefac_compress & lsf); | |
999 tab1 = tabs[tab][ms_stereo][0]; | |
1000 tab2 = tabs[tab][ms_stereo][1]; | |
1001 #if 0 | |
1 | 1002 if(lsf) { |
1003 int p = gr_info->scalefac_compress & 0x1; | |
10343 | 1004 if(ms_stereo) { |
1 | 1005 tab1 = pow1_2[p]; tab2 = pow2_2[p]; |
1006 } | |
1007 else { | |
1008 tab1 = pow1_1[p]; tab2 = pow2_1[p]; | |
1009 } | |
1010 } | |
1011 else { | |
1012 if(ms_stereo) { | |
1013 tab1 = tan1_2; tab2 = tan2_2; | |
1014 } | |
1015 else { | |
1016 tab1 = tan1_1; tab2 = tan2_1; | |
1017 } | |
1018 } | |
10343 | 1019 #endif |
1 | 1020 |
10388 | 1021 // printf("III_i_st: tab1=%p tab2=%p tab=%d ms=%d \n", tab1, tab2, tab, ms_stereo); |
1022 | |
10343 | 1023 if (gr_info->block_type == 2) { |
1 | 1024 int lwin,do_l = 0; |
1025 if( gr_info->mixed_block_flag ) | |
1026 do_l = 1; | |
1027 | |
10343 | 1028 for (lwin=0;lwin<3;lwin++) { /* process each window */ |
1 | 1029 /* get first band with zero values */ |
1030 int is_p,sb,idx,sfb = gr_info->maxband[lwin]; /* sfb is minimal 3 for mixed mode */ | |
1031 if(sfb > 3) | |
1032 do_l = 0; | |
1033 | |
10343 | 1034 for(;sfb<12;sfb++) { |
1 | 1035 is_p = scalefac[sfb*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ |
1036 if(is_p != 7) { | |
1037 real t1,t2; | |
10343 | 1038 sb = bi->shortDiff[sfb]; |
1 | 1039 idx = bi->shortIdx[sfb] + lwin; |
10343 | 1040 t1 = tab1[is_p]; t2 = tab2[is_p]; |
1041 for (; sb > 0; sb--,idx+=3) { | |
1 | 1042 real v = xr[0][idx]; |
10343 | 1043 xr[0][idx] = REAL_MUL(v, t1); |
1044 xr[1][idx] = REAL_MUL(v, t2); | |
1 | 1045 } |
1046 } | |
1047 } | |
1048 | |
1049 #if 1 | |
1050 /* in the original: copy 10 to 11 , here: copy 11 to 12 | |
1051 maybe still wrong??? (copy 12 to 13?) */ | |
1052 is_p = scalefac[11*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ | |
10343 | 1053 sb = bi->shortDiff[12]; |
1054 idx = bi->shortIdx[12] + lwin; | |
1 | 1055 #else |
1056 is_p = scalefac[10*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ | |
10343 | 1057 sb = bi->shortDiff[11]; |
1058 idx = bi->shortIdx[11] + lwin; | |
1 | 1059 #endif |
10343 | 1060 if(is_p != 7) { |
1 | 1061 real t1,t2; |
1062 t1 = tab1[is_p]; t2 = tab2[is_p]; | |
10343 | 1063 for ( ; sb > 0; sb--,idx+=3 ) { |
1 | 1064 real v = xr[0][idx]; |
10343 | 1065 xr[0][idx] = REAL_MUL(v, t1); |
1066 xr[1][idx] = REAL_MUL(v, t2); | |
1 | 1067 } |
1068 } | |
1069 } /* end for(lwin; .. ; . ) */ | |
1070 | |
1071 /* also check l-part, if ALL bands in the three windows are 'empty' | |
1072 * and mode = mixed_mode | |
1073 */ | |
10343 | 1074 if (do_l) { |
1 | 1075 int sfb = gr_info->maxbandl; |
1076 int idx = bi->longIdx[sfb]; | |
1077 | |
10343 | 1078 for ( ; sfb<8; sfb++ ) { |
1 | 1079 int sb = bi->longDiff[sfb]; |
1080 int is_p = scalefac[sfb]; /* scale: 0-15 */ | |
1081 if(is_p != 7) { | |
1082 real t1,t2; | |
1083 t1 = tab1[is_p]; t2 = tab2[is_p]; | |
10343 | 1084 for ( ; sb > 0; sb--,idx++) { |
1 | 1085 real v = xr[0][idx]; |
10343 | 1086 xr[0][idx] = REAL_MUL(v, t1); |
1087 xr[1][idx] = REAL_MUL(v, t2); | |
1 | 1088 } |
1089 } | |
1090 else | |
1091 idx += sb; | |
1092 } | |
1093 } | |
1094 } | |
10343 | 1095 else { /* ((gr_info->block_type != 2)) */ |
1096 int sfb = gr_info->maxbandl; | |
1097 int is_p,idx = bi->longIdx[sfb]; | |
1098 | |
1099 /* hmm ... maybe the maxbandl stuff for i-stereo is buggy? */ | |
1100 if(sfb <= 21) { | |
1101 for ( ; sfb<21; sfb++) { | |
1 | 1102 int sb = bi->longDiff[sfb]; |
1103 is_p = scalefac[sfb]; /* scale: 0-15 */ | |
1104 if(is_p != 7) { | |
1105 real t1,t2; | |
1106 t1 = tab1[is_p]; t2 = tab2[is_p]; | |
10343 | 1107 for ( ; sb > 0; sb--,idx++) { |
1 | 1108 real v = xr[0][idx]; |
10343 | 1109 xr[0][idx] = REAL_MUL(v, t1); |
1110 xr[1][idx] = REAL_MUL(v, t2); | |
1 | 1111 } |
1112 } | |
1113 else | |
1114 idx += sb; | |
1115 } | |
1116 | |
10343 | 1117 is_p = scalefac[20]; |
1118 if(is_p != 7) { /* copy l-band 20 to l-band 21 */ | |
1 | 1119 int sb; |
1120 real t1 = tab1[is_p],t2 = tab2[is_p]; | |
1121 | |
10343 | 1122 for ( sb = bi->longDiff[21]; sb > 0; sb--,idx++ ) { |
1 | 1123 real v = xr[0][idx]; |
10343 | 1124 xr[0][idx] = REAL_MUL(v, t1); |
1125 xr[1][idx] = REAL_MUL(v, t2); | |
1 | 1126 } |
1127 } | |
10343 | 1128 } /* end: if(sfb <= 21) */ |
1 | 1129 } /* ... */ |
1130 } | |
1131 | |
10343 | 1132 static void III_antialias(real xr[SBLIMIT][SSLIMIT],struct gr_info_s *gr_info) { |
1 | 1133 int sblim; |
1134 | |
1135 if(gr_info->block_type == 2) { | |
10343 | 1136 if(!gr_info->mixed_block_flag) |
1137 return; | |
1 | 1138 sblim = 1; |
10343 | 1139 } |
1140 else { | |
1 | 1141 sblim = gr_info->maxb-1; |
1142 } | |
1143 | |
1144 /* 31 alias-reduction operations between each pair of sub-bands */ | |
1145 /* with 8 butterflies between each pair */ | |
1146 | |
10343 | 1147 { |
1148 int sb; | |
1 | 1149 real *xr1=(real *) xr[1]; |
1150 | |
1151 for(sb=sblim;sb;sb--,xr1+=10) { | |
1152 int ss; | |
1153 real *cs=aa_cs,*ca=aa_ca; | |
1154 real *xr2 = xr1; | |
1155 | |
1156 for(ss=7;ss>=0;ss--) { /* upper and lower butterfly inputs */ | |
1157 register real bu = *--xr2,bd = *xr1; | |
1158 *xr2 = (bu * (*cs) ) - (bd * (*ca) ); | |
1159 *xr1++ = (bd * (*cs++) ) + (bu * (*ca++) ); | |
1160 } | |
1161 } | |
1162 | |
1163 } | |
1164 } | |
1165 | |
1166 #include "dct64.c" | |
1167 #include "dct36.c" | |
1168 #include "dct12.c" | |
1169 | |
1170 #include "decod386.c" | |
1171 | |
1172 /* | |
1173 * III_hybrid | |
1174 */ | |
1245
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
716
diff
changeset
|
1175 |
12134 | 1176 static dct36_func_t dct36_func; |
1245
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
716
diff
changeset
|
1177 |
1 | 1178 static void III_hybrid(real fsIn[SBLIMIT][SSLIMIT],real tsOut[SSLIMIT][SBLIMIT], |
1179 int ch,struct gr_info_s *gr_info) | |
1180 { | |
1181 real *tspnt = (real *) tsOut; | |
1182 static real block[2][2][SBLIMIT*SSLIMIT] = { { { 0, } } }; | |
1183 static int blc[2]={0,0}; | |
1184 real *rawout1,*rawout2; | |
1185 int bt; | |
1186 int sb = 0; | |
1187 | |
1188 { | |
1189 int b = blc[ch]; | |
1190 rawout1=block[b][ch]; | |
1191 b=-b+1; | |
1192 rawout2=block[b][ch]; | |
1193 blc[ch] = b; | |
1194 } | |
1195 | |
1196 if(gr_info->mixed_block_flag) { | |
1197 sb = 2; | |
1245
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
716
diff
changeset
|
1198 (*dct36_func)(fsIn[0],rawout1,rawout2,win[0],tspnt); |
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
716
diff
changeset
|
1199 (*dct36_func)(fsIn[1],rawout1+18,rawout2+18,win1[0],tspnt+1); |
1 | 1200 rawout1 += 36; rawout2 += 36; tspnt += 2; |
1201 } | |
1202 | |
1203 bt = gr_info->block_type; | |
1204 if(bt == 2) { | |
1205 for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) { | |
1206 dct12(fsIn[sb],rawout1,rawout2,win[2],tspnt); | |
1207 dct12(fsIn[sb+1],rawout1+18,rawout2+18,win1[2],tspnt+1); | |
1208 } | |
1209 } | |
1210 else { | |
1211 for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) { | |
1245
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
716
diff
changeset
|
1212 (*dct36_func)(fsIn[sb],rawout1,rawout2,win[bt],tspnt); |
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
716
diff
changeset
|
1213 (*dct36_func)(fsIn[sb+1],rawout1+18,rawout2+18,win1[bt],tspnt+1); |
1 | 1214 } |
1215 } | |
1216 | |
1217 for(;sb<SBLIMIT;sb++,tspnt++) { | |
1218 int i; | |
1219 for(i=0;i<SSLIMIT;i++) { | |
1220 tspnt[i*SBLIMIT] = *rawout1++; | |
1221 *rawout2++ = 0.0; | |
1222 } | |
1223 } | |
1224 } | |
1225 | |
1226 /* | |
1227 * main layer3 handler | |
1228 */ | |
1229 /* int do_layer3(struct frame *fr,int outmode,struct audio_info_struct *ai) */ | |
1230 static int do_layer3(struct frame *fr,int single){ | |
1231 int gr, ch, ss,clip=0; | |
1232 int scalefacs[2][39]; /* max 39 for short[13][3] mode, mixed: 38, long: 22 */ | |
1233 struct III_sideinfo sideinfo; | |
1234 int stereo = fr->stereo; | |
1235 int ms_stereo,i_stereo; | |
1236 int sfreq = fr->sampling_frequency; | |
1237 int stereo1,granules; | |
1238 | |
1239 // if (fr->error_protection) getbits(16); /* skip crc */ | |
1240 | |
1241 if(stereo == 1) { /* stream is mono */ | |
1242 stereo1 = 1; | |
1243 single = 0; | |
1244 } else | |
1245 if(single >= 0) /* stream is stereo, but force to mono */ | |
1246 stereo1 = 1; | |
1247 else | |
1248 stereo1 = 2; | |
1249 | |
1250 if(fr->mode == MPG_MD_JOINT_STEREO) { | |
10388 | 1251 ms_stereo = (fr->mode_ext & 0x2)>>1; |
1 | 1252 i_stereo = fr->mode_ext & 0x1; |
1253 } else | |
1254 ms_stereo = i_stereo = 0; | |
1255 | |
10343 | 1256 if(!III_get_side_info(&sideinfo,stereo,ms_stereo,sfreq,single,fr->lsf)) |
1257 return -1; | |
1258 | |
1 | 1259 set_pointer(sideinfo.main_data_begin); |
1260 | |
10343 | 1261 granules = (fr->lsf) ? 1 : 2; |
1 | 1262 for (gr=0;gr<granules;gr++){ |
1263 static real hybridIn[2][SBLIMIT][SSLIMIT]; | |
1264 static real hybridOut[2][SSLIMIT][SBLIMIT]; | |
1265 | |
1266 { struct gr_info_s *gr_info = &(sideinfo.ch[0].gr[gr]); | |
1267 long part2bits; | |
1268 if(fr->lsf) | |
1269 part2bits = III_get_scale_factors_2(scalefacs[0],gr_info,0); | |
1270 else | |
1271 part2bits = III_get_scale_factors_1(scalefacs[0],gr_info); | |
1272 if(III_dequantize_sample(hybridIn[0], scalefacs[0],gr_info,sfreq,part2bits)) | |
1273 return clip; | |
1274 } | |
1275 | |
1276 if(stereo == 2) { | |
1277 struct gr_info_s *gr_info = &(sideinfo.ch[1].gr[gr]); | |
1278 | |
1279 long part2bits; | |
1280 if(fr->lsf) | |
1281 part2bits = III_get_scale_factors_2(scalefacs[1],gr_info,i_stereo); | |
1282 else | |
1283 part2bits = III_get_scale_factors_1(scalefacs[1],gr_info); | |
1284 | |
10343 | 1285 if(III_dequantize_sample(hybridIn[1],scalefacs[1],gr_info,sfreq,part2bits)) |
1 | 1286 return clip; |
10343 | 1287 |
1288 if(ms_stereo) { | |
1289 int i; | |
1290 int maxb = sideinfo.ch[0].gr[gr].maxb; | |
1291 if(sideinfo.ch[1].gr[gr].maxb > maxb) | |
1292 maxb = sideinfo.ch[1].gr[gr].maxb; | |
1293 for(i=0;i<SSLIMIT*maxb;i++) { | |
1294 real tmp0 = ((real *)hybridIn[0])[i]; | |
1295 real tmp1 = ((real *)hybridIn[1])[i]; | |
1296 ((real *)hybridIn[0])[i] = tmp0 + tmp1; | |
1297 ((real *)hybridIn[1])[i] = tmp0 - tmp1; | |
1298 } | |
1 | 1299 } |
1300 | |
1301 if(i_stereo) | |
1302 III_i_stereo(hybridIn,scalefacs[1],gr_info,sfreq,ms_stereo,fr->lsf); | |
1303 | |
1304 if(ms_stereo || i_stereo || (single == 3) ) { | |
1305 if(gr_info->maxb > sideinfo.ch[0].gr[gr].maxb) | |
1306 sideinfo.ch[0].gr[gr].maxb = gr_info->maxb; | |
1307 else | |
1308 gr_info->maxb = sideinfo.ch[0].gr[gr].maxb; | |
1309 } | |
1310 | |
1311 switch(single) { | |
1312 case 3: { | |
1313 register int i; | |
1314 register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1]; | |
1315 for(i=0;i<SSLIMIT*gr_info->maxb;i++,in0++) | |
1316 *in0 = (*in0 + *in1++); /* *0.5 done by pow-scale */ | |
1317 break; } | |
1318 case 1: { | |
1319 register int i; | |
1320 register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1]; | |
1321 for(i=0;i<SSLIMIT*gr_info->maxb;i++) | |
1322 *in0++ = *in1++; | |
1323 break; } | |
1324 } | |
1325 | |
1326 } // if(stereo == 2) | |
1327 | |
1328 for(ch=0;ch<stereo1;ch++) { | |
1329 struct gr_info_s *gr_info = &(sideinfo.ch[ch].gr[gr]); | |
1330 III_antialias(hybridIn[ch],gr_info); | |
1331 III_hybrid(hybridIn[ch], hybridOut[ch], ch,gr_info); | |
1332 } | |
1333 | |
1334 for(ss=0;ss<SSLIMIT;ss++) { | |
1335 if(single >= 0) { | |
1336 clip += (fr->synth_mono)(hybridOut[0][ss],pcm_sample,&pcm_point); | |
1337 } else { | |
1338 int p1 = pcm_point; | |
1339 clip += (fr->synth)(hybridOut[0][ss],0,pcm_sample,&p1); | |
1340 clip += (fr->synth)(hybridOut[1][ss],1,pcm_sample,&pcm_point); | |
1341 } | |
1342 } | |
1343 | |
1344 } | |
1345 | |
1346 return clip; | |
1347 } | |
1348 | |
1349 |