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