Debian Codegraph @

Xmp3/layer3.c

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