Mercurial > SDL_sound_CoreAudio
annotate decoders/mpglib/layer3.c @ 387:fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Fri, 05 Jul 2002 23:11:51 +0000 |
parents | 7b1df7526915 |
children | 9d0b5ec9cc26 |
rev | line source |
---|---|
261 | 1 /* |
2 * Mpeg Layer-3 audio decoder | |
3 * -------------------------- | |
4 * copyright (c) 1995,1996,1997 by Michael Hipp. | |
5 * All rights reserved. See also 'README' | |
6 */ | |
7 | |
8 #include <stdlib.h> | |
274
9e7f9e09ea0e
Removed fprintf() calls. Replaced with SNDDBG() and Sound_SetError() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
261
diff
changeset
|
9 |
9e7f9e09ea0e
Removed fprintf() calls. Replaced with SNDDBG() and Sound_SetError() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
261
diff
changeset
|
10 #include "SDL_sound.h" |
9e7f9e09ea0e
Removed fprintf() calls. Replaced with SNDDBG() and Sound_SetError() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
261
diff
changeset
|
11 |
9e7f9e09ea0e
Removed fprintf() calls. Replaced with SNDDBG() and Sound_SetError() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
261
diff
changeset
|
12 #define __SDL_SOUND_INTERNAL__ |
9e7f9e09ea0e
Removed fprintf() calls. Replaced with SNDDBG() and Sound_SetError() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
261
diff
changeset
|
13 #include "SDL_sound_internal.h" |
9e7f9e09ea0e
Removed fprintf() calls. Replaced with SNDDBG() and Sound_SetError() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
261
diff
changeset
|
14 |
261 | 15 #include "mpg123_sdlsound.h" |
16 #include "mpglib_sdlsound.h" | |
17 #include "huffman.h" | |
18 | |
19 #define MPEG1 | |
20 | |
21 static real ispow[8207]; | |
22 static real aa_ca[8],aa_cs[8]; | |
23 static real COS1[12][6]; | |
24 static real win[4][36]; | |
25 static real win1[4][36]; | |
26 static real gainpow2[256+118+4]; | |
27 static real COS9[9]; | |
28 static real COS6_1,COS6_2; | |
29 static real tfcos36[9]; | |
30 static real tfcos12[3]; | |
31 | |
32 struct bandInfoStruct { | |
33 short longIdx[23]; | |
34 short longDiff[22]; | |
35 short shortIdx[14]; | |
36 short shortDiff[13]; | |
37 }; | |
38 | |
39 int longLimit[9][23]; | |
40 int shortLimit[9][14]; | |
41 | |
42 struct bandInfoStruct bandInfo[9] = { | |
43 | |
44 /* MPEG 1.0 */ | |
45 { {0,4,8,12,16,20,24,30,36,44,52,62,74, 90,110,134,162,196,238,288,342,418,576}, | |
46 {4,4,4,4,4,4,6,6,8, 8,10,12,16,20,24,28,34,42,50,54, 76,158}, | |
47 {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}, | |
48 {4,4,4,4,6,8,10,12,14,18,22,30,56} } , | |
49 | |
50 { {0,4,8,12,16,20,24,30,36,42,50,60,72, 88,106,128,156,190,230,276,330,384,576}, | |
51 {4,4,4,4,4,4,6,6,6, 8,10,12,16,18,22,28,34,40,46,54, 54,192}, | |
52 {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}, | |
53 {4,4,4,4,6,6,10,12,14,16,20,26,66} } , | |
54 | |
55 { {0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576} , | |
56 {4,4,4,4,4,4,6,6,8,10,12,16,20,24,30,38,46,56,68,84,102, 26} , | |
57 {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} , | |
58 {4,4,4,4,6,8,12,16,20,26,34,42,12} } , | |
59 | |
60 /* MPEG 2.0 */ | |
61 { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, | |
62 {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 } , | |
63 {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} , | |
64 {4,4,4,6,6,8,10,14,18,26,32,42,18 } } , | |
65 | |
66 { {0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,330,394,464,540,576}, | |
67 {6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,52,64,70,76,36 } , | |
68 {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} , | |
69 {4,4,4,6,8,10,12,14,18,24,32,44,12 } } , | |
70 | |
71 { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, | |
72 {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 }, | |
73 {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}, | |
74 {4,4,4,6,8,10,12,14,18,24,30,40,18 } } , | |
75 /* MPEG 2.5 */ | |
76 { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} , | |
77 {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54}, | |
78 {0,12,24,36,54,78,108,144,186,240,312,402,522,576}, | |
79 {4,4,4,6,8,10,12,14,18,24,30,40,18} }, | |
80 { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} , | |
81 {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54}, | |
82 {0,12,24,36,54,78,108,144,186,240,312,402,522,576}, | |
83 {4,4,4,6,8,10,12,14,18,24,30,40,18} }, | |
84 { {0,12,24,36,48,60,72,88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576}, | |
85 {12,12,12,12,12,12,16,20,24,28,32,40,48,56,64,76,90,2,2,2,2,2}, | |
86 {0, 24, 48, 72,108,156,216,288,372,480,486,492,498,576}, | |
87 {8,8,8,12,16,20,24,28,36,2,2,2,26} } , | |
88 }; | |
89 | |
90 static int mapbuf0[9][152]; | |
91 static int mapbuf1[9][156]; | |
92 static int mapbuf2[9][44]; | |
93 static int *map[9][3]; | |
94 static int *mapend[9][3]; | |
95 | |
96 static unsigned int n_slen2[512]; /* MPEG 2.0 slen for 'normal' mode */ | |
97 static unsigned int i_slen2[256]; /* MPEG 2.0 slen for intensity stereo */ | |
98 | |
99 static real tan1_1[16],tan2_1[16],tan1_2[16],tan2_2[16]; | |
100 static real pow1_1[2][16],pow2_1[2][16],pow1_2[2][16],pow2_2[2][16]; | |
101 | |
102 /* | |
103 * init tables for layer-3 | |
104 */ | |
105 void init_layer3(int down_sample_sblimit) | |
106 { | |
107 int i,j,k,l; | |
108 | |
109 for(i=-256;i<118+4;i++) | |
110 gainpow2[i+256] = pow((double)2.0,-0.25 * (double) (i+210) ); | |
111 | |
112 for(i=0;i<8207;i++) | |
113 ispow[i] = pow((double)i,(double)4.0/3.0); | |
114 | |
115 for (i=0;i<8;i++) | |
116 { | |
117 static double Ci[8]={-0.6,-0.535,-0.33,-0.185,-0.095,-0.041,-0.0142,-0.0037}; | |
118 double sq=sqrt(1.0+Ci[i]*Ci[i]); | |
119 aa_cs[i] = 1.0/sq; | |
120 aa_ca[i] = Ci[i]/sq; | |
121 } | |
122 | |
123 for(i=0;i<18;i++) | |
124 { | |
125 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 ); | |
126 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 ); | |
127 } | |
128 for(i=0;i<6;i++) | |
129 { | |
130 win[1][i+18] = 0.5 / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 ); | |
131 win[3][i+12] = 0.5 / cos ( M_PI * (double) (2*(i+12)+19) / 72.0 ); | |
132 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 ); | |
133 win[1][i+30] = win[3][i] = 0.0; | |
134 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 ); | |
135 } | |
136 | |
137 for(i=0;i<9;i++) | |
138 COS9[i] = cos( M_PI / 18.0 * (double) i); | |
139 | |
140 for(i=0;i<9;i++) | |
141 tfcos36[i] = 0.5 / cos ( M_PI * (double) (i*2+1) / 36.0 ); | |
142 for(i=0;i<3;i++) | |
143 tfcos12[i] = 0.5 / cos ( M_PI * (double) (i*2+1) / 12.0 ); | |
144 | |
145 COS6_1 = cos( M_PI / 6.0 * (double) 1); | |
146 COS6_2 = cos( M_PI / 6.0 * (double) 2); | |
147 | |
148 for(i=0;i<12;i++) | |
149 { | |
150 win[2][i] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+1) ) / cos ( M_PI * (double) (2*i+7) / 24.0 ); | |
151 for(j=0;j<6;j++) | |
152 COS1[i][j] = cos( M_PI / 24.0 * (double) ((2*i+7)*(2*j+1)) ); | |
153 } | |
154 | |
155 for(j=0;j<4;j++) { | |
156 static int len[4] = { 36,36,12,36 }; | |
157 for(i=0;i<len[j];i+=2) | |
158 win1[j][i] = + win[j][i]; | |
159 for(i=1;i<len[j];i+=2) | |
160 win1[j][i] = - win[j][i]; | |
161 } | |
162 | |
163 for(i=0;i<16;i++) | |
164 { | |
165 double t = tan( (double) i * M_PI / 12.0 ); | |
166 tan1_1[i] = t / (1.0+t); | |
167 tan2_1[i] = 1.0 / (1.0 + t); | |
168 tan1_2[i] = M_SQRT2 * t / (1.0+t); | |
169 tan2_2[i] = M_SQRT2 / (1.0 + t); | |
170 | |
171 for(j=0;j<2;j++) { | |
172 double base = pow(2.0,-0.25*(j+1.0)); | |
173 double p1=1.0,p2=1.0; | |
174 if(i > 0) { | |
175 if( i & 1 ) | |
176 p1 = pow(base,(i+1.0)*0.5); | |
177 else | |
178 p2 = pow(base,i*0.5); | |
179 } | |
180 pow1_1[j][i] = p1; | |
181 pow2_1[j][i] = p2; | |
182 pow1_2[j][i] = M_SQRT2 * p1; | |
183 pow2_2[j][i] = M_SQRT2 * p2; | |
184 } | |
185 } | |
186 | |
187 for(j=0;j<9;j++) | |
188 { | |
189 struct bandInfoStruct *bi = &bandInfo[j]; | |
190 int *mp; | |
191 int cb,lwin; | |
192 short *bdf; | |
193 | |
194 mp = map[j][0] = mapbuf0[j]; | |
195 bdf = bi->longDiff; | |
196 for(i=0,cb = 0; cb < 8 ; cb++,i+=*bdf++) { | |
197 *mp++ = (*bdf) >> 1; | |
198 *mp++ = i; | |
199 *mp++ = 3; | |
200 *mp++ = cb; | |
201 } | |
202 bdf = bi->shortDiff+3; | |
203 for(cb=3;cb<13;cb++) { | |
204 int l = (*bdf++) >> 1; | |
205 for(lwin=0;lwin<3;lwin++) { | |
206 *mp++ = l; | |
207 *mp++ = i + lwin; | |
208 *mp++ = lwin; | |
209 *mp++ = cb; | |
210 } | |
211 i += 6*l; | |
212 } | |
213 mapend[j][0] = mp; | |
214 | |
215 mp = map[j][1] = mapbuf1[j]; | |
216 bdf = bi->shortDiff+0; | |
217 for(i=0,cb=0;cb<13;cb++) { | |
218 int l = (*bdf++) >> 1; | |
219 for(lwin=0;lwin<3;lwin++) { | |
220 *mp++ = l; | |
221 *mp++ = i + lwin; | |
222 *mp++ = lwin; | |
223 *mp++ = cb; | |
224 } | |
225 i += 6*l; | |
226 } | |
227 mapend[j][1] = mp; | |
228 | |
229 mp = map[j][2] = mapbuf2[j]; | |
230 bdf = bi->longDiff; | |
231 for(cb = 0; cb < 22 ; cb++) { | |
232 *mp++ = (*bdf++) >> 1; | |
233 *mp++ = cb; | |
234 } | |
235 mapend[j][2] = mp; | |
236 | |
237 } | |
238 | |
239 for(j=0;j<9;j++) { | |
240 for(i=0;i<23;i++) { | |
241 longLimit[j][i] = (bandInfo[j].longIdx[i] - 1 + 8) / 18 + 1; | |
242 if(longLimit[j][i] > (down_sample_sblimit) ) | |
243 longLimit[j][i] = down_sample_sblimit; | |
244 } | |
245 for(i=0;i<14;i++) { | |
246 shortLimit[j][i] = (bandInfo[j].shortIdx[i] - 1) / 18 + 1; | |
247 if(shortLimit[j][i] > (down_sample_sblimit) ) | |
248 shortLimit[j][i] = down_sample_sblimit; | |
249 } | |
250 } | |
251 | |
252 for(i=0;i<5;i++) { | |
253 for(j=0;j<6;j++) { | |
254 for(k=0;k<6;k++) { | |
255 int n = k + j * 6 + i * 36; | |
256 i_slen2[n] = i|(j<<3)|(k<<6)|(3<<12); | |
257 } | |
258 } | |
259 } | |
260 for(i=0;i<4;i++) { | |
261 for(j=0;j<4;j++) { | |
262 for(k=0;k<4;k++) { | |
263 int n = k + j * 4 + i * 16; | |
264 i_slen2[n+180] = i|(j<<3)|(k<<6)|(4<<12); | |
265 } | |
266 } | |
267 } | |
268 for(i=0;i<4;i++) { | |
269 for(j=0;j<3;j++) { | |
270 int n = j + i * 3; | |
271 i_slen2[n+244] = i|(j<<3) | (5<<12); | |
272 n_slen2[n+500] = i|(j<<3) | (2<<12) | (1<<15); | |
273 } | |
274 } | |
275 | |
276 for(i=0;i<5;i++) { | |
277 for(j=0;j<5;j++) { | |
278 for(k=0;k<4;k++) { | |
279 for(l=0;l<4;l++) { | |
280 int n = l + k * 4 + j * 16 + i * 80; | |
281 n_slen2[n] = i|(j<<3)|(k<<6)|(l<<9)|(0<<12); | |
282 } | |
283 } | |
284 } | |
285 } | |
286 for(i=0;i<5;i++) { | |
287 for(j=0;j<5;j++) { | |
288 for(k=0;k<4;k++) { | |
289 int n = k + j * 4 + i * 20; | |
290 n_slen2[n+400] = i|(j<<3)|(k<<6)|(1<<12); | |
291 } | |
292 } | |
293 } | |
294 } | |
295 | |
296 /* | |
297 * read additional side information | |
298 */ | |
299 #ifdef MPEG1 | |
300 static int III_get_side_info_1(struct III_sideinfo *si,int stereo, | |
301 int ms_stereo,long sfreq,int single) | |
302 { | |
303 int ch, gr; | |
304 int powdiff = (single == 3) ? 4 : 0; | |
305 | |
306 si->main_data_begin = getbits(9); | |
307 if (stereo == 1) | |
308 si->private_bits = getbits_fast(5); | |
309 else | |
310 si->private_bits = getbits_fast(3); | |
311 | |
312 for (ch=0; ch<stereo; ch++) { | |
313 si->ch[ch].gr[0].scfsi = -1; | |
314 si->ch[ch].gr[1].scfsi = getbits_fast(4); | |
315 } | |
316 | |
317 for (gr=0; gr<2; gr++) | |
318 { | |
319 for (ch=0; ch<stereo; ch++) | |
320 { | |
321 register struct gr_info_s *gr_info = &(si->ch[ch].gr[gr]); | |
322 | |
323 gr_info->part2_3_length = getbits(12); | |
324 gr_info->big_values = getbits_fast(9); | |
325 if(gr_info->big_values > 288) { | |
299
7b1df7526915
Patches for Visual C compatibility.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
326 SNDDBG(("MPGLIB: big_values too large!\n")); |
261 | 327 gr_info->big_values = 288; |
328 } | |
329 gr_info->pow2gain = gainpow2+256 - getbits_fast(8) + powdiff; | |
330 if(ms_stereo) | |
331 gr_info->pow2gain += 2; | |
332 gr_info->scalefac_compress = getbits_fast(4); | |
333 /* window-switching flag == 1 for block_Type != 0 .. and block-type == 0 -> win-sw-flag = 0 */ | |
334 if(get1bit()) | |
335 { | |
336 int i; | |
337 gr_info->block_type = getbits_fast(2); | |
338 gr_info->mixed_block_flag = get1bit(); | |
339 gr_info->table_select[0] = getbits_fast(5); | |
340 gr_info->table_select[1] = getbits_fast(5); | |
341 /* | |
342 * table_select[2] not needed, because there is no region2, | |
343 * but to satisfy some verifications tools we set it either. | |
344 */ | |
345 gr_info->table_select[2] = 0; | |
346 for(i=0;i<3;i++) | |
347 gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(3)<<3); | |
348 | |
349 if(gr_info->block_type == 0) { | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
299
diff
changeset
|
350 BAIL_MACRO("MPGLIB: Blocktype == 0 and window-switching == 1 not allowed.", 0); |
261 | 351 } |
352 /* region_count/start parameters are implicit in this case. */ | |
353 gr_info->region1start = 36>>1; | |
354 gr_info->region2start = 576>>1; | |
355 } | |
356 else | |
357 { | |
358 int i,r0c,r1c; | |
359 for (i=0; i<3; i++) | |
360 gr_info->table_select[i] = getbits_fast(5); | |
361 r0c = getbits_fast(4); | |
362 r1c = getbits_fast(3); | |
363 gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ; | |
364 gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1; | |
365 gr_info->block_type = 0; | |
366 gr_info->mixed_block_flag = 0; | |
367 } | |
368 gr_info->preflag = get1bit(); | |
369 gr_info->scalefac_scale = get1bit(); | |
370 gr_info->count1table_select = get1bit(); | |
371 } | |
372 } | |
373 return !0; | |
374 } | |
375 #endif | |
376 | |
377 /* | |
378 * Side Info for MPEG 2.0 / LSF | |
379 */ | |
380 static int III_get_side_info_2(struct III_sideinfo *si,int stereo, | |
381 int ms_stereo,long sfreq,int single) | |
382 { | |
383 int ch; | |
384 int powdiff = (single == 3) ? 4 : 0; | |
385 | |
386 si->main_data_begin = getbits(8); | |
387 if (stereo == 1) | |
388 si->private_bits = get1bit(); | |
389 else | |
390 si->private_bits = getbits_fast(2); | |
391 | |
392 for (ch=0; ch<stereo; ch++) | |
393 { | |
394 register struct gr_info_s *gr_info = &(si->ch[ch].gr[0]); | |
395 | |
396 gr_info->part2_3_length = getbits(12); | |
397 gr_info->big_values = getbits_fast(9); | |
398 if(gr_info->big_values > 288) { | |
299
7b1df7526915
Patches for Visual C compatibility.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
399 SNDDBG(("MPGLIB: big_values too large!\n")); |
261 | 400 gr_info->big_values = 288; |
401 } | |
402 gr_info->pow2gain = gainpow2+256 - getbits_fast(8) + powdiff; | |
403 if(ms_stereo) | |
404 gr_info->pow2gain += 2; | |
405 gr_info->scalefac_compress = getbits(9); | |
406 /* window-switching flag == 1 for block_Type != 0 .. and block-type == 0 -> win-sw-flag = 0 */ | |
407 if(get1bit()) | |
408 { | |
409 int i; | |
410 gr_info->block_type = getbits_fast(2); | |
411 gr_info->mixed_block_flag = get1bit(); | |
412 gr_info->table_select[0] = getbits_fast(5); | |
413 gr_info->table_select[1] = getbits_fast(5); | |
414 /* | |
415 * table_select[2] not needed, because there is no region2, | |
416 * but to satisfy some verifications tools we set it either. | |
417 */ | |
418 gr_info->table_select[2] = 0; | |
419 for(i=0;i<3;i++) | |
420 gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(3)<<3); | |
421 | |
422 if(gr_info->block_type == 0) { | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
299
diff
changeset
|
423 BAIL_MACRO("MPGLIB: Blocktype == 0 and window-switching == 1 not allowed.", 0); |
261 | 424 } |
425 /* region_count/start parameters are implicit in this case. */ | |
426 /* check this again! */ | |
427 if(gr_info->block_type == 2) | |
428 gr_info->region1start = 36>>1; | |
429 else if(sfreq == 8) | |
430 /* check this for 2.5 and sfreq=8 */ | |
431 gr_info->region1start = 108>>1; | |
432 else | |
433 gr_info->region1start = 54>>1; | |
434 gr_info->region2start = 576>>1; | |
435 } | |
436 else | |
437 { | |
438 int i,r0c,r1c; | |
439 for (i=0; i<3; i++) | |
440 gr_info->table_select[i] = getbits_fast(5); | |
441 r0c = getbits_fast(4); | |
442 r1c = getbits_fast(3); | |
443 gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ; | |
444 gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1; | |
445 gr_info->block_type = 0; | |
446 gr_info->mixed_block_flag = 0; | |
447 } | |
448 gr_info->scalefac_scale = get1bit(); | |
449 gr_info->count1table_select = get1bit(); | |
450 } | |
451 return !0; | |
452 } | |
453 | |
454 /* | |
455 * read scalefactors | |
456 */ | |
457 #ifdef MPEG1 | |
458 static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info) | |
459 { | |
460 static const unsigned char slen[2][16] = { | |
461 {0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4}, | |
462 {0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3} | |
463 }; | |
464 int numbits; | |
465 int num0 = slen[0][gr_info->scalefac_compress]; | |
466 int num1 = slen[1][gr_info->scalefac_compress]; | |
467 | |
468 if (gr_info->block_type == 2) { | |
469 int i=18; | |
470 numbits = (num0 + num1) * 18; | |
471 | |
472 if (gr_info->mixed_block_flag) { | |
473 for (i=8;i;i--) | |
474 *scf++ = getbits_fast(num0); | |
475 i = 9; | |
476 numbits -= num0; /* num0 * 17 + num1 * 18 */ | |
477 } | |
478 | |
479 for (;i;i--) | |
480 *scf++ = getbits_fast(num0); | |
481 for (i = 18; i; i--) | |
482 *scf++ = getbits_fast(num1); | |
483 *scf++ = 0; *scf++ = 0; *scf++ = 0; /* short[13][0..2] = 0 */ | |
484 } | |
485 else { | |
486 int i; | |
487 int scfsi = gr_info->scfsi; | |
488 | |
489 if(scfsi < 0) { /* scfsi < 0 => granule == 0 */ | |
490 for(i=11;i;i--) | |
491 *scf++ = getbits_fast(num0); | |
492 for(i=10;i;i--) | |
493 *scf++ = getbits_fast(num1); | |
494 numbits = (num0 + num1) * 10 + num0; | |
495 *scf++ = 0; | |
496 } | |
497 else { | |
498 numbits = 0; | |
499 if(!(scfsi & 0x8)) { | |
500 for (i=0;i<6;i++) | |
501 *scf++ = getbits_fast(num0); | |
502 numbits += num0 * 6; | |
503 } | |
504 else { | |
505 scf += 6; | |
506 } | |
507 | |
508 if(!(scfsi & 0x4)) { | |
509 for (i=0;i<5;i++) | |
510 *scf++ = getbits_fast(num0); | |
511 numbits += num0 * 5; | |
512 } | |
513 else { | |
514 scf += 5; | |
515 } | |
516 | |
517 if(!(scfsi & 0x2)) { | |
518 for(i=0;i<5;i++) | |
519 *scf++ = getbits_fast(num1); | |
520 numbits += num1 * 5; | |
521 } | |
522 else { | |
523 scf += 5; | |
524 } | |
525 | |
526 if(!(scfsi & 0x1)) { | |
527 for (i=0;i<5;i++) | |
528 *scf++ = getbits_fast(num1); | |
529 numbits += num1 * 5; | |
530 } | |
531 else { | |
532 scf += 5; | |
533 } | |
534 *scf++ = 0; /* no l[21] in original sources */ | |
535 } | |
536 } | |
537 return numbits; | |
538 } | |
539 #endif | |
540 | |
541 | |
542 static int III_get_scale_factors_2(int *scf,struct gr_info_s *gr_info,int i_stereo) | |
543 { | |
544 unsigned char *pnt; | |
545 int i,j; | |
546 unsigned int slen; | |
547 int n = 0; | |
548 int numbits = 0; | |
549 | |
550 static unsigned char stab[3][6][4] = { | |
551 { { 6, 5, 5,5 } , { 6, 5, 7,3 } , { 11,10,0,0} , | |
552 { 7, 7, 7,0 } , { 6, 6, 6,3 } , { 8, 8,5,0} } , | |
553 { { 9, 9, 9,9 } , { 9, 9,12,6 } , { 18,18,0,0} , | |
554 {12,12,12,0 } , {12, 9, 9,6 } , { 15,12,9,0} } , | |
555 { { 6, 9, 9,9 } , { 6, 9,12,6 } , { 15,18,0,0} , | |
556 { 6,15,12,0 } , { 6,12, 9,6 } , { 6,18,9,0} } }; | |
557 | |
558 if(i_stereo) /* i_stereo AND second channel -> do_layer3() checks this */ | |
559 slen = i_slen2[gr_info->scalefac_compress>>1]; | |
560 else | |
561 slen = n_slen2[gr_info->scalefac_compress]; | |
562 | |
563 gr_info->preflag = (slen>>15) & 0x1; | |
564 | |
565 n = 0; | |
566 if( gr_info->block_type == 2 ) { | |
567 n++; | |
568 if(gr_info->mixed_block_flag) | |
569 n++; | |
570 } | |
571 | |
572 pnt = stab[n][(slen>>12)&0x7]; | |
573 | |
574 for(i=0;i<4;i++) { | |
575 int num = slen & 0x7; | |
576 slen >>= 3; | |
577 if(num) { | |
578 for(j=0;j<(int)(pnt[i]);j++) | |
579 *scf++ = getbits_fast(num); | |
580 numbits += pnt[i] * num; | |
581 } | |
582 else { | |
583 for(j=0;j<(int)(pnt[i]);j++) | |
584 *scf++ = 0; | |
585 } | |
586 } | |
587 | |
588 n = (n << 1) + 1; | |
589 for(i=0;i<n;i++) | |
590 *scf++ = 0; | |
591 | |
592 return numbits; | |
593 } | |
594 | |
595 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}; | |
596 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}; | |
597 | |
598 /* | |
599 * don't forget to apply the same changes to III_dequantize_sample_ms() !!! | |
600 */ | |
601 static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf, | |
602 struct gr_info_s *gr_info,int sfreq,int part2bits) | |
603 { | |
604 int shift = 1 + gr_info->scalefac_scale; | |
605 real *xrpnt = (real *) xr; | |
606 int l[3],l3; | |
607 int part2remain = gr_info->part2_3_length - part2bits; | |
608 int *me; | |
609 | |
610 { | |
611 int bv = gr_info->big_values; | |
612 int region1 = gr_info->region1start; | |
613 int region2 = gr_info->region2start; | |
614 | |
615 l3 = ((576>>1)-bv)>>1; | |
616 /* | |
617 * we may lose the 'odd' bit here !! | |
618 * check this later again | |
619 */ | |
620 if(bv <= region1) { | |
621 l[0] = bv; l[1] = 0; l[2] = 0; | |
622 } | |
623 else { | |
624 l[0] = region1; | |
625 if(bv <= region2) { | |
626 l[1] = bv - l[0]; l[2] = 0; | |
627 } | |
628 else { | |
629 l[1] = region2 - l[0]; l[2] = bv - region2; | |
630 } | |
631 } | |
632 } | |
633 | |
634 if(gr_info->block_type == 2) { | |
635 /* | |
636 * decoding with short or mixed mode BandIndex table | |
637 */ | |
638 int i,max[4]; | |
639 int step=0,lwin=0,cb=0; | |
640 register real v = 0.0; | |
641 register int *m,mc; | |
642 | |
643 if(gr_info->mixed_block_flag) { | |
644 max[3] = -1; | |
645 max[0] = max[1] = max[2] = 2; | |
646 m = map[sfreq][0]; | |
647 me = mapend[sfreq][0]; | |
648 } | |
649 else { | |
650 max[0] = max[1] = max[2] = max[3] = -1; | |
651 /* max[3] not really needed in this case */ | |
652 m = map[sfreq][1]; | |
653 me = mapend[sfreq][1]; | |
654 } | |
655 | |
656 mc = 0; | |
657 for(i=0;i<2;i++) { | |
658 int lp = l[i]; | |
659 struct newhuff *h = ht+gr_info->table_select[i]; | |
660 for(;lp;lp--,mc--) { | |
661 register int x,y; | |
662 if( (!mc) ) { | |
663 mc = *m++; | |
664 xrpnt = ((real *) xr) + (*m++); | |
665 lwin = *m++; | |
666 cb = *m++; | |
667 if(lwin == 3) { | |
668 v = gr_info->pow2gain[(*scf++) << shift]; | |
669 step = 1; | |
670 } | |
671 else { | |
672 v = gr_info->full_gain[lwin][(*scf++) << shift]; | |
673 step = 3; | |
674 } | |
675 } | |
676 { | |
677 register short *val = h->table; | |
678 while((y=*val++)<0) { | |
679 if (get1bit()) | |
680 val -= y; | |
681 part2remain--; | |
682 } | |
683 x = y >> 4; | |
684 y &= 0xf; | |
685 } | |
686 if(x == 15) { | |
687 max[lwin] = cb; | |
688 part2remain -= h->linbits+1; | |
689 x += getbits(h->linbits); | |
690 if(get1bit()) | |
691 *xrpnt = -ispow[x] * v; | |
692 else | |
693 *xrpnt = ispow[x] * v; | |
694 } | |
695 else if(x) { | |
696 max[lwin] = cb; | |
697 if(get1bit()) | |
698 *xrpnt = -ispow[x] * v; | |
699 else | |
700 *xrpnt = ispow[x] * v; | |
701 part2remain--; | |
702 } | |
703 else | |
704 *xrpnt = 0.0; | |
705 xrpnt += step; | |
706 if(y == 15) { | |
707 max[lwin] = cb; | |
708 part2remain -= h->linbits+1; | |
709 y += getbits(h->linbits); | |
710 if(get1bit()) | |
711 *xrpnt = -ispow[y] * v; | |
712 else | |
713 *xrpnt = ispow[y] * v; | |
714 } | |
715 else if(y) { | |
716 max[lwin] = cb; | |
717 if(get1bit()) | |
718 *xrpnt = -ispow[y] * v; | |
719 else | |
720 *xrpnt = ispow[y] * v; | |
721 part2remain--; | |
722 } | |
723 else | |
724 *xrpnt = 0.0; | |
725 xrpnt += step; | |
726 } | |
727 } | |
728 for(;l3 && (part2remain > 0);l3--) { | |
729 struct newhuff *h = htc+gr_info->count1table_select; | |
730 register short *val = h->table,a; | |
731 | |
732 while((a=*val++)<0) { | |
733 part2remain--; | |
734 if(part2remain < 0) { | |
735 part2remain++; | |
736 a = 0; | |
737 break; | |
738 } | |
739 if (get1bit()) | |
740 val -= a; | |
741 } | |
742 | |
743 for(i=0;i<4;i++) { | |
744 if(!(i & 1)) { | |
745 if(!mc) { | |
746 mc = *m++; | |
747 xrpnt = ((real *) xr) + (*m++); | |
748 lwin = *m++; | |
749 cb = *m++; | |
750 if(lwin == 3) { | |
751 v = gr_info->pow2gain[(*scf++) << shift]; | |
752 step = 1; | |
753 } | |
754 else { | |
755 v = gr_info->full_gain[lwin][(*scf++) << shift]; | |
756 step = 3; | |
757 } | |
758 } | |
759 mc--; | |
760 } | |
761 if( (a & (0x8>>i)) ) { | |
762 max[lwin] = cb; | |
763 part2remain--; | |
764 if(part2remain < 0) { | |
765 part2remain++; | |
766 break; | |
767 } | |
768 if(get1bit()) | |
769 *xrpnt = -v; | |
770 else | |
771 *xrpnt = v; | |
772 } | |
773 else | |
774 *xrpnt = 0.0; | |
775 xrpnt += step; | |
776 } | |
777 } | |
778 | |
779 while( m < me ) { | |
780 if(!mc) { | |
781 mc = *m++; | |
782 xrpnt = ((real *) xr) + *m++; | |
783 if( (*m++) == 3) | |
784 step = 1; | |
785 else | |
786 step = 3; | |
787 m++; /* cb */ | |
788 } | |
789 mc--; | |
790 *xrpnt = 0.0; | |
791 xrpnt += step; | |
792 *xrpnt = 0.0; | |
793 xrpnt += step; | |
794 /* we could add a little opt. here: | |
795 * if we finished a band for window 3 or a long band | |
796 * further bands could copied in a simple loop without a | |
797 * special 'map' decoding | |
798 */ | |
799 } | |
800 | |
801 gr_info->maxband[0] = max[0]+1; | |
802 gr_info->maxband[1] = max[1]+1; | |
803 gr_info->maxband[2] = max[2]+1; | |
804 gr_info->maxbandl = max[3]+1; | |
805 | |
806 { | |
807 int rmax = max[0] > max[1] ? max[0] : max[1]; | |
808 rmax = (rmax > max[2] ? rmax : max[2]) + 1; | |
809 gr_info->maxb = rmax ? shortLimit[sfreq][rmax] : longLimit[sfreq][max[3]+1]; | |
810 } | |
811 | |
812 } | |
813 else { | |
814 /* | |
815 * decoding with 'long' BandIndex table (block_type != 2) | |
816 */ | |
817 int *pretab = gr_info->preflag ? pretab1 : pretab2; | |
818 int i,max = -1; | |
819 int cb = 0; | |
820 register int *m = map[sfreq][2]; | |
821 register real v = 0.0; | |
822 register int mc = 0; | |
823 #if 0 | |
824 me = mapend[sfreq][2]; | |
825 #endif | |
826 | |
827 /* | |
828 * long hash table values | |
829 */ | |
830 for(i=0;i<3;i++) { | |
831 int lp = l[i]; | |
832 struct newhuff *h = ht+gr_info->table_select[i]; | |
833 | |
834 for(;lp;lp--,mc--) { | |
835 int x,y; | |
836 | |
837 if(!mc) { | |
838 mc = *m++; | |
839 v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift]; | |
840 cb = *m++; | |
841 } | |
842 { | |
843 register short *val = h->table; | |
844 while((y=*val++)<0) { | |
845 if (get1bit()) | |
846 val -= y; | |
847 part2remain--; | |
848 } | |
849 x = y >> 4; | |
850 y &= 0xf; | |
851 } | |
852 if (x == 15) { | |
853 max = cb; | |
854 part2remain -= h->linbits+1; | |
855 x += getbits(h->linbits); | |
856 if(get1bit()) | |
857 *xrpnt++ = -ispow[x] * v; | |
858 else | |
859 *xrpnt++ = ispow[x] * v; | |
860 } | |
861 else if(x) { | |
862 max = cb; | |
863 if(get1bit()) | |
864 *xrpnt++ = -ispow[x] * v; | |
865 else | |
866 *xrpnt++ = ispow[x] * v; | |
867 part2remain--; | |
868 } | |
869 else | |
870 *xrpnt++ = 0.0; | |
871 | |
872 if (y == 15) { | |
873 max = cb; | |
874 part2remain -= h->linbits+1; | |
875 y += getbits(h->linbits); | |
876 if(get1bit()) | |
877 *xrpnt++ = -ispow[y] * v; | |
878 else | |
879 *xrpnt++ = ispow[y] * v; | |
880 } | |
881 else if(y) { | |
882 max = cb; | |
883 if(get1bit()) | |
884 *xrpnt++ = -ispow[y] * v; | |
885 else | |
886 *xrpnt++ = ispow[y] * v; | |
887 part2remain--; | |
888 } | |
889 else | |
890 *xrpnt++ = 0.0; | |
891 } | |
892 } | |
893 | |
894 /* | |
895 * short (count1table) values | |
896 */ | |
897 for(;l3 && (part2remain > 0);l3--) { | |
898 struct newhuff *h = htc+gr_info->count1table_select; | |
899 register short *val = h->table,a; | |
900 | |
901 while((a=*val++)<0) { | |
902 part2remain--; | |
903 if(part2remain < 0) { | |
904 part2remain++; | |
905 a = 0; | |
906 break; | |
907 } | |
908 if (get1bit()) | |
909 val -= a; | |
910 } | |
911 | |
912 for(i=0;i<4;i++) { | |
913 if(!(i & 1)) { | |
914 if(!mc) { | |
915 mc = *m++; | |
916 cb = *m++; | |
917 v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift]; | |
918 } | |
919 mc--; | |
920 } | |
921 if ( (a & (0x8>>i)) ) { | |
922 max = cb; | |
923 part2remain--; | |
924 if(part2remain < 0) { | |
925 part2remain++; | |
926 break; | |
927 } | |
928 if(get1bit()) | |
929 *xrpnt++ = -v; | |
930 else | |
931 *xrpnt++ = v; | |
932 } | |
933 else | |
934 *xrpnt++ = 0.0; | |
935 } | |
936 } | |
937 | |
938 /* | |
939 * zero part | |
940 */ | |
941 for(i=(&xr[SBLIMIT][0]-xrpnt)>>1;i;i--) { | |
942 *xrpnt++ = 0.0; | |
943 *xrpnt++ = 0.0; | |
944 } | |
945 | |
946 gr_info->maxbandl = max+1; | |
947 gr_info->maxb = longLimit[sfreq][gr_info->maxbandl]; | |
948 } | |
949 | |
950 while( part2remain > 16 ) { | |
951 getbits(16); /* Dismiss stuffing Bits */ | |
952 part2remain -= 16; | |
953 } | |
954 if(part2remain > 0) | |
955 getbits(part2remain); | |
956 else if(part2remain < 0) { | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
299
diff
changeset
|
957 /* !!! FIXME: Need formatting: by %d bits!\n",-part2remain);*/ |
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
299
diff
changeset
|
958 BAIL_MACRO("MPGLIB: Can't rewind stream!", 1); /* -> error */ |
261 | 959 } |
960 return 0; | |
961 } | |
962 | |
963 #if 0 | |
964 static int III_dequantize_sample_ms(real xr[2][SBLIMIT][SSLIMIT],int *scf, | |
965 struct gr_info_s *gr_info,int sfreq,int part2bits) | |
966 { | |
967 int shift = 1 + gr_info->scalefac_scale; | |
968 real *xrpnt = (real *) xr[1]; | |
969 real *xr0pnt = (real *) xr[0]; | |
970 int l[3],l3; | |
971 int part2remain = gr_info->part2_3_length - part2bits; | |
972 int *me; | |
973 | |
974 { | |
975 int bv = gr_info->big_values; | |
976 int region1 = gr_info->region1start; | |
977 int region2 = gr_info->region2start; | |
978 | |
979 l3 = ((576>>1)-bv)>>1; | |
980 /* | |
981 * we may lose the 'odd' bit here !! | |
982 * check this later gain | |
983 */ | |
984 if(bv <= region1) { | |
985 l[0] = bv; l[1] = 0; l[2] = 0; | |
986 } | |
987 else { | |
988 l[0] = region1; | |
989 if(bv <= region2) { | |
990 l[1] = bv - l[0]; l[2] = 0; | |
991 } | |
992 else { | |
993 l[1] = region2 - l[0]; l[2] = bv - region2; | |
994 } | |
995 } | |
996 } | |
997 | |
998 if(gr_info->block_type == 2) { | |
999 int i,max[4]; | |
1000 int step=0,lwin=0,cb=0; | |
1001 register real v = 0.0; | |
1002 register int *m,mc = 0; | |
1003 | |
1004 if(gr_info->mixed_block_flag) { | |
1005 max[3] = -1; | |
1006 max[0] = max[1] = max[2] = 2; | |
1007 m = map[sfreq][0]; | |
1008 me = mapend[sfreq][0]; | |
1009 } | |
1010 else { | |
1011 max[0] = max[1] = max[2] = max[3] = -1; | |
1012 /* max[3] not really needed in this case */ | |
1013 m = map[sfreq][1]; | |
1014 me = mapend[sfreq][1]; | |
1015 } | |
1016 | |
1017 for(i=0;i<2;i++) { | |
1018 int lp = l[i]; | |
1019 struct newhuff *h = ht+gr_info->table_select[i]; | |
1020 for(;lp;lp--,mc--) { | |
1021 int x,y; | |
1022 | |
1023 if(!mc) { | |
1024 mc = *m++; | |
1025 xrpnt = ((real *) xr[1]) + *m; | |
1026 xr0pnt = ((real *) xr[0]) + *m++; | |
1027 lwin = *m++; | |
1028 cb = *m++; | |
1029 if(lwin == 3) { | |
1030 v = gr_info->pow2gain[(*scf++) << shift]; | |
1031 step = 1; | |
1032 } | |
1033 else { | |
1034 v = gr_info->full_gain[lwin][(*scf++) << shift]; | |
1035 step = 3; | |
1036 } | |
1037 } | |
1038 { | |
1039 register short *val = h->table; | |
1040 while((y=*val++)<0) { | |
1041 if (get1bit()) | |
1042 val -= y; | |
1043 part2remain--; | |
1044 } | |
1045 x = y >> 4; | |
1046 y &= 0xf; | |
1047 } | |
1048 if(x == 15) { | |
1049 max[lwin] = cb; | |
1050 part2remain -= h->linbits+1; | |
1051 x += getbits(h->linbits); | |
1052 if(get1bit()) { | |
1053 real a = ispow[x] * v; | |
1054 *xrpnt = *xr0pnt + a; | |
1055 *xr0pnt -= a; | |
1056 } | |
1057 else { | |
1058 real a = ispow[x] * v; | |
1059 *xrpnt = *xr0pnt - a; | |
1060 *xr0pnt += a; | |
1061 } | |
1062 } | |
1063 else if(x) { | |
1064 max[lwin] = cb; | |
1065 if(get1bit()) { | |
1066 real a = ispow[x] * v; | |
1067 *xrpnt = *xr0pnt + a; | |
1068 *xr0pnt -= a; | |
1069 } | |
1070 else { | |
1071 real a = ispow[x] * v; | |
1072 *xrpnt = *xr0pnt - a; | |
1073 *xr0pnt += a; | |
1074 } | |
1075 part2remain--; | |
1076 } | |
1077 else | |
1078 *xrpnt = *xr0pnt; | |
1079 xrpnt += step; | |
1080 xr0pnt += step; | |
1081 | |
1082 if(y == 15) { | |
1083 max[lwin] = cb; | |
1084 part2remain -= h->linbits+1; | |
1085 y += getbits(h->linbits); | |
1086 if(get1bit()) { | |
1087 real a = ispow[y] * v; | |
1088 *xrpnt = *xr0pnt + a; | |
1089 *xr0pnt -= a; | |
1090 } | |
1091 else { | |
1092 real a = ispow[y] * v; | |
1093 *xrpnt = *xr0pnt - a; | |
1094 *xr0pnt += a; | |
1095 } | |
1096 } | |
1097 else if(y) { | |
1098 max[lwin] = cb; | |
1099 if(get1bit()) { | |
1100 real a = ispow[y] * v; | |
1101 *xrpnt = *xr0pnt + a; | |
1102 *xr0pnt -= a; | |
1103 } | |
1104 else { | |
1105 real a = ispow[y] * v; | |
1106 *xrpnt = *xr0pnt - a; | |
1107 *xr0pnt += a; | |
1108 } | |
1109 part2remain--; | |
1110 } | |
1111 else | |
1112 *xrpnt = *xr0pnt; | |
1113 xrpnt += step; | |
1114 xr0pnt += step; | |
1115 } | |
1116 } | |
1117 | |
1118 for(;l3 && (part2remain > 0);l3--) { | |
1119 struct newhuff *h = htc+gr_info->count1table_select; | |
1120 register short *val = h->table,a; | |
1121 | |
1122 while((a=*val++)<0) { | |
1123 part2remain--; | |
1124 if(part2remain < 0) { | |
1125 part2remain++; | |
1126 a = 0; | |
1127 break; | |
1128 } | |
1129 if (get1bit()) | |
1130 val -= a; | |
1131 } | |
1132 | |
1133 for(i=0;i<4;i++) { | |
1134 if(!(i & 1)) { | |
1135 if(!mc) { | |
1136 mc = *m++; | |
1137 xrpnt = ((real *) xr[1]) + *m; | |
1138 xr0pnt = ((real *) xr[0]) + *m++; | |
1139 lwin = *m++; | |
1140 cb = *m++; | |
1141 if(lwin == 3) { | |
1142 v = gr_info->pow2gain[(*scf++) << shift]; | |
1143 step = 1; | |
1144 } | |
1145 else { | |
1146 v = gr_info->full_gain[lwin][(*scf++) << shift]; | |
1147 step = 3; | |
1148 } | |
1149 } | |
1150 mc--; | |
1151 } | |
1152 if( (a & (0x8>>i)) ) { | |
1153 max[lwin] = cb; | |
1154 part2remain--; | |
1155 if(part2remain < 0) { | |
1156 part2remain++; | |
1157 break; | |
1158 } | |
1159 if(get1bit()) { | |
1160 *xrpnt = *xr0pnt + v; | |
1161 *xr0pnt -= v; | |
1162 } | |
1163 else { | |
1164 *xrpnt = *xr0pnt - v; | |
1165 *xr0pnt += v; | |
1166 } | |
1167 } | |
1168 else | |
1169 *xrpnt = *xr0pnt; | |
1170 xrpnt += step; | |
1171 xr0pnt += step; | |
1172 } | |
1173 } | |
1174 | |
1175 while( m < me ) { | |
1176 if(!mc) { | |
1177 mc = *m++; | |
1178 xrpnt = ((real *) xr[1]) + *m; | |
1179 xr0pnt = ((real *) xr[0]) + *m++; | |
1180 if(*m++ == 3) | |
1181 step = 1; | |
1182 else | |
1183 step = 3; | |
1184 m++; /* cb */ | |
1185 } | |
1186 mc--; | |
1187 *xrpnt = *xr0pnt; | |
1188 xrpnt += step; | |
1189 xr0pnt += step; | |
1190 *xrpnt = *xr0pnt; | |
1191 xrpnt += step; | |
1192 xr0pnt += step; | |
1193 /* we could add a little opt. here: | |
1194 * if we finished a band for window 3 or a long band | |
1195 * further bands could copied in a simple loop without a | |
1196 * special 'map' decoding | |
1197 */ | |
1198 } | |
1199 | |
1200 gr_info->maxband[0] = max[0]+1; | |
1201 gr_info->maxband[1] = max[1]+1; | |
1202 gr_info->maxband[2] = max[2]+1; | |
1203 gr_info->maxbandl = max[3]+1; | |
1204 | |
1205 { | |
1206 int rmax = max[0] > max[1] ? max[0] : max[1]; | |
1207 rmax = (rmax > max[2] ? rmax : max[2]) + 1; | |
1208 gr_info->maxb = rmax ? shortLimit[sfreq][rmax] : longLimit[sfreq][max[3]+1]; | |
1209 } | |
1210 } | |
1211 else { | |
1212 int *pretab = gr_info->preflag ? pretab1 : pretab2; | |
1213 int i,max = -1; | |
1214 int cb = 0; | |
1215 register int mc=0,*m = map[sfreq][2]; | |
1216 register real v = 0.0; | |
1217 #if 0 | |
1218 me = mapend[sfreq][2]; | |
1219 #endif | |
1220 | |
1221 for(i=0;i<3;i++) { | |
1222 int lp = l[i]; | |
1223 struct newhuff *h = ht+gr_info->table_select[i]; | |
1224 | |
1225 for(;lp;lp--,mc--) { | |
1226 int x,y; | |
1227 if(!mc) { | |
1228 mc = *m++; | |
1229 cb = *m++; | |
1230 v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift]; | |
1231 } | |
1232 { | |
1233 register short *val = h->table; | |
1234 while((y=*val++)<0) { | |
1235 if (get1bit()) | |
1236 val -= y; | |
1237 part2remain--; | |
1238 } | |
1239 x = y >> 4; | |
1240 y &= 0xf; | |
1241 } | |
1242 if (x == 15) { | |
1243 max = cb; | |
1244 part2remain -= h->linbits+1; | |
1245 x += getbits(h->linbits); | |
1246 if(get1bit()) { | |
1247 real a = ispow[x] * v; | |
1248 *xrpnt++ = *xr0pnt + a; | |
1249 *xr0pnt++ -= a; | |
1250 } | |
1251 else { | |
1252 real a = ispow[x] * v; | |
1253 *xrpnt++ = *xr0pnt - a; | |
1254 *xr0pnt++ += a; | |
1255 } | |
1256 } | |
1257 else if(x) { | |
1258 max = cb; | |
1259 if(get1bit()) { | |
1260 real a = ispow[x] * v; | |
1261 *xrpnt++ = *xr0pnt + a; | |
1262 *xr0pnt++ -= a; | |
1263 } | |
1264 else { | |
1265 real a = ispow[x] * v; | |
1266 *xrpnt++ = *xr0pnt - a; | |
1267 *xr0pnt++ += a; | |
1268 } | |
1269 part2remain--; | |
1270 } | |
1271 else | |
1272 *xrpnt++ = *xr0pnt++; | |
1273 | |
1274 if (y == 15) { | |
1275 max = cb; | |
1276 part2remain -= h->linbits+1; | |
1277 y += getbits(h->linbits); | |
1278 if(get1bit()) { | |
1279 real a = ispow[y] * v; | |
1280 *xrpnt++ = *xr0pnt + a; | |
1281 *xr0pnt++ -= a; | |
1282 } | |
1283 else { | |
1284 real a = ispow[y] * v; | |
1285 *xrpnt++ = *xr0pnt - a; | |
1286 *xr0pnt++ += a; | |
1287 } | |
1288 } | |
1289 else if(y) { | |
1290 max = cb; | |
1291 if(get1bit()) { | |
1292 real a = ispow[y] * v; | |
1293 *xrpnt++ = *xr0pnt + a; | |
1294 *xr0pnt++ -= a; | |
1295 } | |
1296 else { | |
1297 real a = ispow[y] * v; | |
1298 *xrpnt++ = *xr0pnt - a; | |
1299 *xr0pnt++ += a; | |
1300 } | |
1301 part2remain--; | |
1302 } | |
1303 else | |
1304 *xrpnt++ = *xr0pnt++; | |
1305 } | |
1306 } | |
1307 | |
1308 for(;l3 && (part2remain > 0);l3--) { | |
1309 struct newhuff *h = htc+gr_info->count1table_select; | |
1310 register short *val = h->table,a; | |
1311 | |
1312 while((a=*val++)<0) { | |
1313 part2remain--; | |
1314 if(part2remain < 0) { | |
1315 part2remain++; | |
1316 a = 0; | |
1317 break; | |
1318 } | |
1319 if (get1bit()) | |
1320 val -= a; | |
1321 } | |
1322 | |
1323 for(i=0;i<4;i++) { | |
1324 if(!(i & 1)) { | |
1325 if(!mc) { | |
1326 mc = *m++; | |
1327 cb = *m++; | |
1328 v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift]; | |
1329 } | |
1330 mc--; | |
1331 } | |
1332 if ( (a & (0x8>>i)) ) { | |
1333 max = cb; | |
1334 part2remain--; | |
1335 if(part2remain <= 0) { | |
1336 part2remain++; | |
1337 break; | |
1338 } | |
1339 if(get1bit()) { | |
1340 *xrpnt++ = *xr0pnt + v; | |
1341 *xr0pnt++ -= v; | |
1342 } | |
1343 else { | |
1344 *xrpnt++ = *xr0pnt - v; | |
1345 *xr0pnt++ += v; | |
1346 } | |
1347 } | |
1348 else | |
1349 *xrpnt++ = *xr0pnt++; | |
1350 } | |
1351 } | |
1352 for(i=(&xr[1][SBLIMIT][0]-xrpnt)>>1;i;i--) { | |
1353 *xrpnt++ = *xr0pnt++; | |
1354 *xrpnt++ = *xr0pnt++; | |
1355 } | |
1356 | |
1357 gr_info->maxbandl = max+1; | |
1358 gr_info->maxb = longLimit[sfreq][gr_info->maxbandl]; | |
1359 } | |
1360 | |
1361 while ( part2remain > 16 ) { | |
1362 getbits(16); /* Dismiss stuffing Bits */ | |
1363 part2remain -= 16; | |
1364 } | |
1365 if(part2remain > 0 ) | |
1366 getbits(part2remain); | |
1367 else if(part2remain < 0) { | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
299
diff
changeset
|
1368 /* !!! FIXME: Need formatting: by %d bits!\n",-part2remain);*/ |
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
299
diff
changeset
|
1369 BAIL_MACRO("MPGLIB: Can't rewind stream!", 1); /* -> error */ |
261 | 1370 } |
1371 return 0; | |
1372 } | |
1373 #endif | |
1374 | |
1375 /* | |
1376 * III_stereo: calculate real channel values for Joint-I-Stereo-mode | |
1377 */ | |
1378 static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac, | |
1379 struct gr_info_s *gr_info,int sfreq,int ms_stereo,int lsf) | |
1380 { | |
1381 real (*xr)[SBLIMIT*SSLIMIT] = (real (*)[SBLIMIT*SSLIMIT] ) xr_buf; | |
1382 struct bandInfoStruct *bi = &bandInfo[sfreq]; | |
1383 real *tab1,*tab2; | |
1384 | |
1385 if(lsf) { | |
1386 int p = gr_info->scalefac_compress & 0x1; | |
1387 if(ms_stereo) { | |
1388 tab1 = pow1_2[p]; tab2 = pow2_2[p]; | |
1389 } | |
1390 else { | |
1391 tab1 = pow1_1[p]; tab2 = pow2_1[p]; | |
1392 } | |
1393 } | |
1394 else { | |
1395 if(ms_stereo) { | |
1396 tab1 = tan1_2; tab2 = tan2_2; | |
1397 } | |
1398 else { | |
1399 tab1 = tan1_1; tab2 = tan2_1; | |
1400 } | |
1401 } | |
1402 | |
1403 if (gr_info->block_type == 2) | |
1404 { | |
1405 int lwin,do_l = 0; | |
1406 if( gr_info->mixed_block_flag ) | |
1407 do_l = 1; | |
1408 | |
1409 for (lwin=0;lwin<3;lwin++) /* process each window */ | |
1410 { | |
1411 /* get first band with zero values */ | |
1412 int is_p,sb,idx,sfb = gr_info->maxband[lwin]; /* sfb is minimal 3 for mixed mode */ | |
1413 if(sfb > 3) | |
1414 do_l = 0; | |
1415 | |
1416 for(;sfb<12;sfb++) | |
1417 { | |
1418 is_p = scalefac[sfb*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ | |
1419 if(is_p != 7) { | |
1420 real t1,t2; | |
1421 sb = bi->shortDiff[sfb]; | |
1422 idx = bi->shortIdx[sfb] + lwin; | |
1423 t1 = tab1[is_p]; t2 = tab2[is_p]; | |
1424 for (; sb > 0; sb--,idx+=3) | |
1425 { | |
1426 real v = xr[0][idx]; | |
1427 xr[0][idx] = v * t1; | |
1428 xr[1][idx] = v * t2; | |
1429 } | |
1430 } | |
1431 } | |
1432 | |
1433 #if 1 | |
1434 /* in the original: copy 10 to 11 , here: copy 11 to 12 | |
1435 maybe still wrong??? (copy 12 to 13?) */ | |
1436 is_p = scalefac[11*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ | |
1437 sb = bi->shortDiff[12]; | |
1438 idx = bi->shortIdx[12] + lwin; | |
1439 #else | |
1440 is_p = scalefac[10*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ | |
1441 sb = bi->shortDiff[11]; | |
1442 idx = bi->shortIdx[11] + lwin; | |
1443 #endif | |
1444 if(is_p != 7) | |
1445 { | |
1446 real t1,t2; | |
1447 t1 = tab1[is_p]; t2 = tab2[is_p]; | |
1448 for ( ; sb > 0; sb--,idx+=3 ) | |
1449 { | |
1450 real v = xr[0][idx]; | |
1451 xr[0][idx] = v * t1; | |
1452 xr[1][idx] = v * t2; | |
1453 } | |
1454 } | |
1455 } /* end for(lwin; .. ; . ) */ | |
1456 | |
1457 if (do_l) | |
1458 { | |
1459 /* also check l-part, if ALL bands in the three windows are 'empty' | |
1460 * and mode = mixed_mode | |
1461 */ | |
1462 int sfb = gr_info->maxbandl; | |
1463 int idx = bi->longIdx[sfb]; | |
1464 | |
1465 for ( ; sfb<8; sfb++ ) | |
1466 { | |
1467 int sb = bi->longDiff[sfb]; | |
1468 int is_p = scalefac[sfb]; /* scale: 0-15 */ | |
1469 if(is_p != 7) { | |
1470 real t1,t2; | |
1471 t1 = tab1[is_p]; t2 = tab2[is_p]; | |
1472 for ( ; sb > 0; sb--,idx++) | |
1473 { | |
1474 real v = xr[0][idx]; | |
1475 xr[0][idx] = v * t1; | |
1476 xr[1][idx] = v * t2; | |
1477 } | |
1478 } | |
1479 else | |
1480 idx += sb; | |
1481 } | |
1482 } | |
1483 } | |
1484 else /* ((gr_info->block_type != 2)) */ | |
1485 { | |
1486 int sfb = gr_info->maxbandl; | |
1487 int is_p,idx = bi->longIdx[sfb]; | |
1488 for ( ; sfb<21; sfb++) | |
1489 { | |
1490 int sb = bi->longDiff[sfb]; | |
1491 is_p = scalefac[sfb]; /* scale: 0-15 */ | |
1492 if(is_p != 7) { | |
1493 real t1,t2; | |
1494 t1 = tab1[is_p]; t2 = tab2[is_p]; | |
1495 for ( ; sb > 0; sb--,idx++) | |
1496 { | |
1497 real v = xr[0][idx]; | |
1498 xr[0][idx] = v * t1; | |
1499 xr[1][idx] = v * t2; | |
1500 } | |
1501 } | |
1502 else | |
1503 idx += sb; | |
1504 } | |
1505 | |
1506 is_p = scalefac[20]; /* copy l-band 20 to l-band 21 */ | |
1507 if(is_p != 7) | |
1508 { | |
1509 int sb; | |
1510 real t1 = tab1[is_p],t2 = tab2[is_p]; | |
1511 | |
1512 for ( sb = bi->longDiff[21]; sb > 0; sb--,idx++ ) | |
1513 { | |
1514 real v = xr[0][idx]; | |
1515 xr[0][idx] = v * t1; | |
1516 xr[1][idx] = v * t2; | |
1517 } | |
1518 } | |
1519 } /* ... */ | |
1520 } | |
1521 | |
1522 static void III_antialias(real xr[SBLIMIT][SSLIMIT],struct gr_info_s *gr_info) | |
1523 { | |
1524 int sblim; | |
1525 | |
1526 if(gr_info->block_type == 2) | |
1527 { | |
1528 if(!gr_info->mixed_block_flag) | |
1529 return; | |
1530 sblim = 1; | |
1531 } | |
1532 else { | |
1533 sblim = gr_info->maxb-1; | |
1534 } | |
1535 | |
1536 /* 31 alias-reduction operations between each pair of sub-bands */ | |
1537 /* with 8 butterflies between each pair */ | |
1538 | |
1539 { | |
1540 int sb; | |
1541 real *xr1=(real *) xr[1]; | |
1542 | |
1543 for(sb=sblim;sb;sb--,xr1+=10) | |
1544 { | |
1545 int ss; | |
1546 real *cs=aa_cs,*ca=aa_ca; | |
1547 real *xr2 = xr1; | |
1548 | |
1549 for(ss=7;ss>=0;ss--) | |
1550 { /* upper and lower butterfly inputs */ | |
1551 register real bu = *--xr2,bd = *xr1; | |
1552 *xr2 = (bu * (*cs) ) - (bd * (*ca) ); | |
1553 *xr1++ = (bd * (*cs++) ) + (bu * (*ca++) ); | |
1554 } | |
1555 } | |
1556 } | |
1557 } | |
1558 | |
1559 /* | |
1560 DCT insipired by Jeff Tsay's DCT from the maplay package | |
1561 this is an optimized version with manual unroll. | |
1562 | |
1563 References: | |
1564 [1] S. Winograd: "On Computing the Discrete Fourier Transform", | |
1565 Mathematics of Computation, Volume 32, Number 141, January 1978, | |
1566 Pages 175-199 | |
1567 */ | |
1568 | |
1569 static void dct36(real *inbuf,real *o1,real *o2,real *wintab,real *tsbuf) | |
1570 { | |
1571 { | |
1572 register real *in = inbuf; | |
1573 | |
1574 in[17]+=in[16]; in[16]+=in[15]; in[15]+=in[14]; | |
1575 in[14]+=in[13]; in[13]+=in[12]; in[12]+=in[11]; | |
1576 in[11]+=in[10]; in[10]+=in[9]; in[9] +=in[8]; | |
1577 in[8] +=in[7]; in[7] +=in[6]; in[6] +=in[5]; | |
1578 in[5] +=in[4]; in[4] +=in[3]; in[3] +=in[2]; | |
1579 in[2] +=in[1]; in[1] +=in[0]; | |
1580 | |
1581 in[17]+=in[15]; in[15]+=in[13]; in[13]+=in[11]; in[11]+=in[9]; | |
1582 in[9] +=in[7]; in[7] +=in[5]; in[5] +=in[3]; in[3] +=in[1]; | |
1583 | |
1584 | |
1585 { | |
1586 | |
1587 #define MACRO0(v) { \ | |
1588 real tmp; \ | |
1589 out2[9+(v)] = (tmp = sum0 + sum1) * w[27+(v)]; \ | |
1590 out2[8-(v)] = tmp * w[26-(v)]; } \ | |
1591 sum0 -= sum1; \ | |
1592 ts[SBLIMIT*(8-(v))] = out1[8-(v)] + sum0 * w[8-(v)]; \ | |
1593 ts[SBLIMIT*(9+(v))] = out1[9+(v)] + sum0 * w[9+(v)]; | |
1594 #define MACRO1(v) { \ | |
1595 real sum0,sum1; \ | |
1596 sum0 = tmp1a + tmp2a; \ | |
1597 sum1 = (tmp1b + tmp2b) * tfcos36[(v)]; \ | |
1598 MACRO0(v); } | |
1599 #define MACRO2(v) { \ | |
1600 real sum0,sum1; \ | |
1601 sum0 = tmp2a - tmp1a; \ | |
1602 sum1 = (tmp2b - tmp1b) * tfcos36[(v)]; \ | |
1603 MACRO0(v); } | |
1604 | |
1605 register const real *c = COS9; | |
1606 register real *out2 = o2; | |
1607 register real *w = wintab; | |
1608 register real *out1 = o1; | |
1609 register real *ts = tsbuf; | |
1610 | |
1611 real ta33,ta66,tb33,tb66; | |
1612 | |
1613 ta33 = in[2*3+0] * c[3]; | |
1614 ta66 = in[2*6+0] * c[6]; | |
1615 tb33 = in[2*3+1] * c[3]; | |
1616 tb66 = in[2*6+1] * c[6]; | |
1617 | |
1618 { | |
1619 real tmp1a,tmp2a,tmp1b,tmp2b; | |
1620 tmp1a = in[2*1+0] * c[1] + ta33 + in[2*5+0] * c[5] + in[2*7+0] * c[7]; | |
1621 tmp1b = in[2*1+1] * c[1] + tb33 + in[2*5+1] * c[5] + in[2*7+1] * c[7]; | |
1622 tmp2a = in[2*0+0] + in[2*2+0] * c[2] + in[2*4+0] * c[4] + ta66 + in[2*8+0] * c[8]; | |
1623 tmp2b = in[2*0+1] + in[2*2+1] * c[2] + in[2*4+1] * c[4] + tb66 + in[2*8+1] * c[8]; | |
1624 | |
1625 MACRO1(0); | |
1626 MACRO2(8); | |
1627 } | |
1628 | |
1629 { | |
1630 real tmp1a,tmp2a,tmp1b,tmp2b; | |
1631 tmp1a = ( in[2*1+0] - in[2*5+0] - in[2*7+0] ) * c[3]; | |
1632 tmp1b = ( in[2*1+1] - in[2*5+1] - in[2*7+1] ) * c[3]; | |
1633 tmp2a = ( in[2*2+0] - in[2*4+0] - in[2*8+0] ) * c[6] - in[2*6+0] + in[2*0+0]; | |
1634 tmp2b = ( in[2*2+1] - in[2*4+1] - in[2*8+1] ) * c[6] - in[2*6+1] + in[2*0+1]; | |
1635 | |
1636 MACRO1(1); | |
1637 MACRO2(7); | |
1638 } | |
1639 | |
1640 { | |
1641 real tmp1a,tmp2a,tmp1b,tmp2b; | |
1642 tmp1a = in[2*1+0] * c[5] - ta33 - in[2*5+0] * c[7] + in[2*7+0] * c[1]; | |
1643 tmp1b = in[2*1+1] * c[5] - tb33 - in[2*5+1] * c[7] + in[2*7+1] * c[1]; | |
1644 tmp2a = in[2*0+0] - in[2*2+0] * c[8] - in[2*4+0] * c[2] + ta66 + in[2*8+0] * c[4]; | |
1645 tmp2b = in[2*0+1] - in[2*2+1] * c[8] - in[2*4+1] * c[2] + tb66 + in[2*8+1] * c[4]; | |
1646 | |
1647 MACRO1(2); | |
1648 MACRO2(6); | |
1649 } | |
1650 | |
1651 { | |
1652 real tmp1a,tmp2a,tmp1b,tmp2b; | |
1653 tmp1a = in[2*1+0] * c[7] - ta33 + in[2*5+0] * c[1] - in[2*7+0] * c[5]; | |
1654 tmp1b = in[2*1+1] * c[7] - tb33 + in[2*5+1] * c[1] - in[2*7+1] * c[5]; | |
1655 tmp2a = in[2*0+0] - in[2*2+0] * c[4] + in[2*4+0] * c[8] + ta66 - in[2*8+0] * c[2]; | |
1656 tmp2b = in[2*0+1] - in[2*2+1] * c[4] + in[2*4+1] * c[8] + tb66 - in[2*8+1] * c[2]; | |
1657 | |
1658 MACRO1(3); | |
1659 MACRO2(5); | |
1660 } | |
1661 | |
1662 { | |
1663 real sum0,sum1; | |
1664 sum0 = in[2*0+0] - in[2*2+0] + in[2*4+0] - in[2*6+0] + in[2*8+0]; | |
1665 sum1 = (in[2*0+1] - in[2*2+1] + in[2*4+1] - in[2*6+1] + in[2*8+1] ) * tfcos36[4]; | |
1666 MACRO0(4); | |
1667 } | |
1668 } | |
1669 | |
1670 } | |
1671 } | |
1672 | |
1673 /* | |
1674 * new DCT12 | |
1675 */ | |
1676 static void dct12(real *in,real *rawout1,real *rawout2,register real *wi,register real *ts) | |
1677 { | |
1678 #define DCT12_PART1 \ | |
1679 in5 = in[5*3]; \ | |
1680 in5 += (in4 = in[4*3]); \ | |
1681 in4 += (in3 = in[3*3]); \ | |
1682 in3 += (in2 = in[2*3]); \ | |
1683 in2 += (in1 = in[1*3]); \ | |
1684 in1 += (in0 = in[0*3]); \ | |
1685 \ | |
1686 in5 += in3; in3 += in1; \ | |
1687 \ | |
1688 in2 *= COS6_1; \ | |
1689 in3 *= COS6_1; \ | |
1690 | |
1691 #define DCT12_PART2 \ | |
1692 in0 += in4 * COS6_2; \ | |
1693 \ | |
1694 in4 = in0 + in2; \ | |
1695 in0 -= in2; \ | |
1696 \ | |
1697 in1 += in5 * COS6_2; \ | |
1698 \ | |
1699 in5 = (in1 + in3) * tfcos12[0]; \ | |
1700 in1 = (in1 - in3) * tfcos12[2]; \ | |
1701 \ | |
1702 in3 = in4 + in5; \ | |
1703 in4 -= in5; \ | |
1704 \ | |
1705 in2 = in0 + in1; \ | |
1706 in0 -= in1; | |
1707 | |
1708 | |
1709 { | |
1710 real in0,in1,in2,in3,in4,in5; | |
1711 register real *out1 = rawout1; | |
1712 ts[SBLIMIT*0] = out1[0]; ts[SBLIMIT*1] = out1[1]; ts[SBLIMIT*2] = out1[2]; | |
1713 ts[SBLIMIT*3] = out1[3]; ts[SBLIMIT*4] = out1[4]; ts[SBLIMIT*5] = out1[5]; | |
1714 | |
1715 DCT12_PART1 | |
1716 | |
1717 { | |
1718 real tmp0,tmp1 = (in0 - in4); | |
1719 { | |
1720 real tmp2 = (in1 - in5) * tfcos12[1]; | |
1721 tmp0 = tmp1 + tmp2; | |
1722 tmp1 -= tmp2; | |
1723 } | |
1724 ts[(17-1)*SBLIMIT] = out1[17-1] + tmp0 * wi[11-1]; | |
1725 ts[(12+1)*SBLIMIT] = out1[12+1] + tmp0 * wi[6+1]; | |
1726 ts[(6 +1)*SBLIMIT] = out1[6 +1] + tmp1 * wi[1]; | |
1727 ts[(11-1)*SBLIMIT] = out1[11-1] + tmp1 * wi[5-1]; | |
1728 } | |
1729 | |
1730 DCT12_PART2 | |
1731 | |
1732 ts[(17-0)*SBLIMIT] = out1[17-0] + in2 * wi[11-0]; | |
1733 ts[(12+0)*SBLIMIT] = out1[12+0] + in2 * wi[6+0]; | |
1734 ts[(12+2)*SBLIMIT] = out1[12+2] + in3 * wi[6+2]; | |
1735 ts[(17-2)*SBLIMIT] = out1[17-2] + in3 * wi[11-2]; | |
1736 | |
1737 ts[(6+0)*SBLIMIT] = out1[6+0] + in0 * wi[0]; | |
1738 ts[(11-0)*SBLIMIT] = out1[11-0] + in0 * wi[5-0]; | |
1739 ts[(6+2)*SBLIMIT] = out1[6+2] + in4 * wi[2]; | |
1740 ts[(11-2)*SBLIMIT] = out1[11-2] + in4 * wi[5-2]; | |
1741 } | |
1742 | |
1743 in++; | |
1744 | |
1745 { | |
1746 real in0,in1,in2,in3,in4,in5; | |
1747 register real *out2 = rawout2; | |
1748 | |
1749 DCT12_PART1 | |
1750 | |
1751 { | |
1752 real tmp0,tmp1 = (in0 - in4); | |
1753 { | |
1754 real tmp2 = (in1 - in5) * tfcos12[1]; | |
1755 tmp0 = tmp1 + tmp2; | |
1756 tmp1 -= tmp2; | |
1757 } | |
1758 out2[5-1] = tmp0 * wi[11-1]; | |
1759 out2[0+1] = tmp0 * wi[6+1]; | |
1760 ts[(12+1)*SBLIMIT] += tmp1 * wi[1]; | |
1761 ts[(17-1)*SBLIMIT] += tmp1 * wi[5-1]; | |
1762 } | |
1763 | |
1764 DCT12_PART2 | |
1765 | |
1766 out2[5-0] = in2 * wi[11-0]; | |
1767 out2[0+0] = in2 * wi[6+0]; | |
1768 out2[0+2] = in3 * wi[6+2]; | |
1769 out2[5-2] = in3 * wi[11-2]; | |
1770 | |
1771 ts[(12+0)*SBLIMIT] += in0 * wi[0]; | |
1772 ts[(17-0)*SBLIMIT] += in0 * wi[5-0]; | |
1773 ts[(12+2)*SBLIMIT] += in4 * wi[2]; | |
1774 ts[(17-2)*SBLIMIT] += in4 * wi[5-2]; | |
1775 } | |
1776 | |
1777 in++; | |
1778 | |
1779 { | |
1780 real in0,in1,in2,in3,in4,in5; | |
1781 register real *out2 = rawout2; | |
1782 out2[12]=out2[13]=out2[14]=out2[15]=out2[16]=out2[17]=0.0; | |
1783 | |
1784 DCT12_PART1 | |
1785 | |
1786 { | |
1787 real tmp0,tmp1 = (in0 - in4); | |
1788 { | |
1789 real tmp2 = (in1 - in5) * tfcos12[1]; | |
1790 tmp0 = tmp1 + tmp2; | |
1791 tmp1 -= tmp2; | |
1792 } | |
1793 out2[11-1] = tmp0 * wi[11-1]; | |
1794 out2[6 +1] = tmp0 * wi[6+1]; | |
1795 out2[0+1] += tmp1 * wi[1]; | |
1796 out2[5-1] += tmp1 * wi[5-1]; | |
1797 } | |
1798 | |
1799 DCT12_PART2 | |
1800 | |
1801 out2[11-0] = in2 * wi[11-0]; | |
1802 out2[6 +0] = in2 * wi[6+0]; | |
1803 out2[6 +2] = in3 * wi[6+2]; | |
1804 out2[11-2] = in3 * wi[11-2]; | |
1805 | |
1806 out2[0+0] += in0 * wi[0]; | |
1807 out2[5-0] += in0 * wi[5-0]; | |
1808 out2[0+2] += in4 * wi[2]; | |
1809 out2[5-2] += in4 * wi[5-2]; | |
1810 } | |
1811 } | |
1812 | |
1813 /* | |
1814 * III_hybrid | |
1815 */ | |
1816 static void III_hybrid(real fsIn[SBLIMIT][SSLIMIT],real tsOut[SSLIMIT][SBLIMIT], | |
279
52b9f37998db
Removed global state variable; should be thread safe now.
Ryan C. Gordon <icculus@icculus.org>
parents:
274
diff
changeset
|
1817 int ch,struct gr_info_s *gr_info,struct mpstr *mp) |
261 | 1818 { |
1819 real *tspnt = (real *) tsOut; | |
279
52b9f37998db
Removed global state variable; should be thread safe now.
Ryan C. Gordon <icculus@icculus.org>
parents:
274
diff
changeset
|
1820 real (*block)[2][SBLIMIT*SSLIMIT] = mp->hybrid_block; |
52b9f37998db
Removed global state variable; should be thread safe now.
Ryan C. Gordon <icculus@icculus.org>
parents:
274
diff
changeset
|
1821 int *blc = mp->hybrid_blc; |
261 | 1822 real *rawout1,*rawout2; |
1823 int bt; | |
1824 int sb = 0; | |
1825 | |
1826 { | |
1827 int b = blc[ch]; | |
1828 rawout1=block[b][ch]; | |
1829 b=-b+1; | |
1830 rawout2=block[b][ch]; | |
1831 blc[ch] = b; | |
1832 } | |
1833 | |
1834 | |
1835 if(gr_info->mixed_block_flag) { | |
1836 sb = 2; | |
1837 dct36(fsIn[0],rawout1,rawout2,win[0],tspnt); | |
1838 dct36(fsIn[1],rawout1+18,rawout2+18,win1[0],tspnt+1); | |
1839 rawout1 += 36; rawout2 += 36; tspnt += 2; | |
1840 } | |
1841 | |
1842 bt = gr_info->block_type; | |
1843 if(bt == 2) { | |
1844 for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) { | |
1845 dct12(fsIn[sb],rawout1,rawout2,win[2],tspnt); | |
1846 dct12(fsIn[sb+1],rawout1+18,rawout2+18,win1[2],tspnt+1); | |
1847 } | |
1848 } | |
1849 else { | |
1850 for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) { | |
1851 dct36(fsIn[sb],rawout1,rawout2,win[bt],tspnt); | |
1852 dct36(fsIn[sb+1],rawout1+18,rawout2+18,win1[bt],tspnt+1); | |
1853 } | |
1854 } | |
1855 | |
1856 for(;sb<SBLIMIT;sb++,tspnt++) { | |
1857 int i; | |
1858 for(i=0;i<SSLIMIT;i++) { | |
1859 tspnt[i*SBLIMIT] = *rawout1++; | |
1860 *rawout2++ = 0.0; | |
1861 } | |
1862 } | |
1863 } | |
1864 | |
1865 /* | |
1866 * main layer3 handler | |
1867 */ | |
281
ad4c8f34136a
Minor formatting updates.
Ryan C. Gordon <icculus@icculus.org>
parents:
279
diff
changeset
|
1868 int do_layer3(struct frame *fr,unsigned char *pcm_sample, |
ad4c8f34136a
Minor formatting updates.
Ryan C. Gordon <icculus@icculus.org>
parents:
279
diff
changeset
|
1869 int *pcm_point,struct mpstr *mp) |
261 | 1870 { |
1871 int gr, ch, ss,clip=0; | |
1872 int scalefacs[2][39]; /* max 39 for short[13][3] mode, mixed: 38, long: 22 */ | |
1873 struct III_sideinfo sideinfo; | |
1874 int stereo = fr->stereo; | |
1875 int single = fr->single; | |
1876 int ms_stereo,i_stereo; | |
1877 int sfreq = fr->sampling_frequency; | |
1878 int stereo1,granules; | |
1879 | |
1880 if(stereo == 1) { /* stream is mono */ | |
1881 stereo1 = 1; | |
1882 single = 0; | |
1883 } | |
1884 else if(single >= 0) /* stream is stereo, but force to mono */ | |
1885 stereo1 = 1; | |
1886 else | |
1887 stereo1 = 2; | |
1888 | |
1889 if(fr->mode == MPG_MD_JOINT_STEREO) { | |
1890 ms_stereo = fr->mode_ext & 0x2; | |
1891 i_stereo = fr->mode_ext & 0x1; | |
1892 } | |
1893 else | |
1894 ms_stereo = i_stereo = 0; | |
1895 | |
1896 if(fr->lsf) { | |
1897 granules = 1; | |
1898 if(!III_get_side_info_2(&sideinfo,stereo,ms_stereo,sfreq,single)) | |
1899 return -1; | |
1900 } | |
1901 else { | |
1902 granules = 2; | |
1903 #ifdef MPEG1 | |
1904 if(!III_get_side_info_1(&sideinfo,stereo,ms_stereo,sfreq,single)) | |
1905 return -1; | |
1906 #else | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
299
diff
changeset
|
1907 __Sound_SetError("MPGLIB: Not supported!"); |
261 | 1908 #endif |
1909 } | |
1910 | |
279
52b9f37998db
Removed global state variable; should be thread safe now.
Ryan C. Gordon <icculus@icculus.org>
parents:
274
diff
changeset
|
1911 if(set_pointer(sideinfo.main_data_begin,mp) == MP3_ERR) |
261 | 1912 return -1; |
1913 | |
1914 for (gr=0;gr<granules;gr++) | |
1915 { | |
1916 real hybridIn[2][SBLIMIT][SSLIMIT]; | |
1917 real hybridOut[2][SSLIMIT][SBLIMIT]; | |
1918 | |
1919 { | |
1920 struct gr_info_s *gr_info = &(sideinfo.ch[0].gr[gr]); | |
1921 long part2bits; | |
1922 if(fr->lsf) | |
1923 part2bits = III_get_scale_factors_2(scalefacs[0],gr_info,0); | |
1924 else { | |
1925 #ifdef MPEG1 | |
1926 part2bits = III_get_scale_factors_1(scalefacs[0],gr_info); | |
1927 #else | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
299
diff
changeset
|
1928 __Sound_SetError("MPGLIB: Not supported!"); |
261 | 1929 #endif |
1930 } | |
1931 if(III_dequantize_sample(hybridIn[0], scalefacs[0],gr_info,sfreq,part2bits)) | |
1932 return clip; | |
1933 } | |
1934 if(stereo == 2) { | |
1935 struct gr_info_s *gr_info = &(sideinfo.ch[1].gr[gr]); | |
1936 long part2bits; | |
1937 if(fr->lsf) | |
1938 part2bits = III_get_scale_factors_2(scalefacs[1],gr_info,i_stereo); | |
1939 else { | |
1940 #ifdef MPEG1 | |
1941 part2bits = III_get_scale_factors_1(scalefacs[1],gr_info); | |
1942 #else | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
299
diff
changeset
|
1943 __Sound_SetError("MPGLIB: Not supported!"); |
261 | 1944 #endif |
1945 } | |
1946 | |
1947 if(III_dequantize_sample(hybridIn[1],scalefacs[1],gr_info,sfreq,part2bits)) | |
1948 return clip; | |
1949 | |
1950 if(ms_stereo) { | |
1951 int i; | |
1952 for(i=0;i<SBLIMIT*SSLIMIT;i++) { | |
1953 real tmp0,tmp1; | |
1954 tmp0 = ((real *) hybridIn[0])[i]; | |
1955 tmp1 = ((real *) hybridIn[1])[i]; | |
1956 ((real *) hybridIn[0])[i] = tmp0 + tmp1; | |
1957 ((real *) hybridIn[1])[i] = tmp0 - tmp1; | |
1958 } | |
1959 } | |
1960 | |
1961 if(i_stereo) | |
1962 III_i_stereo(hybridIn,scalefacs[1],gr_info,sfreq,ms_stereo,fr->lsf); | |
1963 | |
1964 if(ms_stereo || i_stereo || (single == 3) ) { | |
1965 if(gr_info->maxb > sideinfo.ch[0].gr[gr].maxb) | |
1966 sideinfo.ch[0].gr[gr].maxb = gr_info->maxb; | |
1967 else | |
1968 gr_info->maxb = sideinfo.ch[0].gr[gr].maxb; | |
1969 } | |
1970 | |
1971 switch(single) { | |
1972 case 3: | |
1973 { | |
1974 register int i; | |
1975 register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1]; | |
1976 for(i=0;i<SSLIMIT*gr_info->maxb;i++,in0++) | |
1977 *in0 = (*in0 + *in1++); /* *0.5 done by pow-scale */ | |
1978 } | |
1979 break; | |
1980 case 1: | |
1981 { | |
1982 register int i; | |
1983 register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1]; | |
1984 for(i=0;i<SSLIMIT*gr_info->maxb;i++) | |
1985 *in0++ = *in1++; | |
1986 } | |
1987 break; | |
1988 } | |
1989 } | |
1990 | |
1991 for(ch=0;ch<stereo1;ch++) { | |
1992 struct gr_info_s *gr_info = &(sideinfo.ch[ch].gr[gr]); | |
1993 III_antialias(hybridIn[ch],gr_info); | |
279
52b9f37998db
Removed global state variable; should be thread safe now.
Ryan C. Gordon <icculus@icculus.org>
parents:
274
diff
changeset
|
1994 III_hybrid(hybridIn[ch], hybridOut[ch], ch,gr_info,mp); |
261 | 1995 } |
1996 | |
1997 for(ss=0;ss<SSLIMIT;ss++) { | |
1998 if(single >= 0) { | |
279
52b9f37998db
Removed global state variable; should be thread safe now.
Ryan C. Gordon <icculus@icculus.org>
parents:
274
diff
changeset
|
1999 clip += synth_1to1_mono(hybridOut[0][ss],pcm_sample,pcm_point,mp); |
261 | 2000 } |
2001 else { | |
2002 int p1 = *pcm_point; | |
279
52b9f37998db
Removed global state variable; should be thread safe now.
Ryan C. Gordon <icculus@icculus.org>
parents:
274
diff
changeset
|
2003 clip += synth_1to1(hybridOut[0][ss],0,pcm_sample,&p1,mp); |
52b9f37998db
Removed global state variable; should be thread safe now.
Ryan C. Gordon <icculus@icculus.org>
parents:
274
diff
changeset
|
2004 clip += synth_1to1(hybridOut[1][ss],1,pcm_sample,pcm_point,mp); |
261 | 2005 } |
2006 } | |
2007 } | |
2008 | |
2009 return clip; | |
2010 } | |
2011 | |
2012 |