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