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