2
* Mpeg Layer-3 audio decoder
3
* --------------------------
4
* copyright (c) 1995-1999 by Michael Hipp.
5
* All rights reserved. See also 'README'
7
* Optimize-TODO: put short bands into the band-field without the stride
9
* Length-optimze: unify long and short band code where it is possible
28
static real ispow[8207];
29
static real aa_ca[8],aa_cs[8];
30
static real COS1[12][6];
31
static real win[4][36];
32
static real win1[4][36];
33
static real gainpow2[256+118+4];
35
/* non static for external 3dnow functions */
37
static real COS6_1,COS6_2;
40
static real tfcos12[3];
43
static real cos9[3],cos18[3];
46
struct bandInfoStruct {
54
int shortLimit[9][14];
56
struct bandInfoStruct bandInfo[9] = {
59
{ {0,4,8,12,16,20,24,30,36,44,52,62,74, 90,110,134,162,196,238,288,342,418,576},
60
{4,4,4,4,4,4,6,6,8, 8,10,12,16,20,24,28,34,42,50,54, 76,158},
61
{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},
62
{4,4,4,4,6,8,10,12,14,18,22,30,56} } ,
64
{ {0,4,8,12,16,20,24,30,36,42,50,60,72, 88,106,128,156,190,230,276,330,384,576},
65
{4,4,4,4,4,4,6,6,6, 8,10,12,16,18,22,28,34,40,46,54, 54,192},
66
{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},
67
{4,4,4,4,6,6,10,12,14,16,20,26,66} } ,
69
{ {0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576} ,
70
{4,4,4,4,4,4,6,6,8,10,12,16,20,24,30,38,46,56,68,84,102, 26} ,
71
{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} ,
72
{4,4,4,4,6,8,12,16,20,26,34,42,12} } ,
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,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} ,
78
{4,4,4,6,6,8,10,14,18,26,32,42,18 } } ,
80
{ {0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,330,394,464,540,576},
81
{6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,52,64,70,76,36 } ,
83
/* changed 19th value fropm 330 to 332 */
84
{ {0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,332,394,464,540,576},
85
{6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,54,62,70,76,36 } ,
86
{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} ,
87
{4,4,4,6,8,10,12,14,18,24,32,44,12 } } ,
89
{ {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
90
{6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 },
91
{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},
92
{4,4,4,6,8,10,12,14,18,24,30,40,18 } } ,
94
{ {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} ,
95
{6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54},
96
{0,12,24,36,54,78,108,144,186,240,312,402,522,576},
97
{4,4,4,6,8,10,12,14,18,24,30,40,18} },
98
{ {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} ,
99
{6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54},
100
{0,12,24,36,54,78,108,144,186,240,312,402,522,576},
101
{4,4,4,6,8,10,12,14,18,24,30,40,18} },
102
{ {0,12,24,36,48,60,72,88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576},
103
{12,12,12,12,12,12,16,20,24,28,32,40,48,56,64,76,90,2,2,2,2,2},
104
{0, 24, 48, 72,108,156,216,288,372,480,486,492,498,576},
105
{8,8,8,12,16,20,24,28,36,2,2,2,26} } ,
108
static int mapbuf0[9][152];
109
static int mapbuf1[9][156];
110
static int mapbuf2[9][44];
111
static int *map[9][3];
112
static int *mapend[9][3];
114
static unsigned int n_slen2[512]; /* MPEG 2.0 slen for 'normal' mode */
115
static unsigned int i_slen2[256]; /* MPEG 2.0 slen for intensity stereo */
117
static real tan1_1[16],tan2_1[16],tan1_2[16],tan2_2[16];
118
static real pow1_1[2][16],pow2_1[2][16],pow1_2[2][16],pow2_2[2][16];
121
* init tables for layer-3
123
void init_layer3(int down_sample_sblimit)
128
double tmparray[8207];
129
double twotothequarter = pow((double)2.0, (double)0.25);
130
double current = pow((double)2.0, (double)(0.25 * 47));
133
for(i=-256;i<118+4;i++) {
135
/* Possibly a few too many multiplies - single bit errors will
136
* propagate. It may change the gradient of the (log) power curve
138
current = current / twotothequarter;
139
gainpow2[i+256] = DOUBLE_TO_REAL(current);
142
if(!param.down_sample)
143
gainpow2[i+256] = 16384.0 * pow((double)2.0,-0.25 * (double) (i+210) );
146
gainpow2[i+256] = DOUBLE_TO_REAL(pow((double)2.0,-0.25 * (double) (i+210) ));
154
for(i=2;i<8207;i++) {
156
tmparray[i] = pow((double)i,(double)(4.0/3.0));
157
for(j = 2; (j <= i) && ((i * j) < 8207); j++) {
158
/* Degradation due to lots of multiplies: A double has
159
* 52 bits of mantissa. A long has 32 bits (on the IPaq).
160
* Hence we can create 20 bits of error without fussing.
161
* Assuming that a 1 bit error multiplies to 2 bits, then 4,
162
* then 8, and noting that 2^13 is 8196 (we go up to 8207),
163
* we may have a problem. Resolve this by limiting to 4
164
* multiplies before recalculating. */
165
for(k = i, l = 0; (k * j) <= 8207 && (l < 4); k *= j, l++) {
166
tmparray[k * j] = tmparray[k] * tmparray[j];
170
ispow[i] = DOUBLE_TO_REAL(tmparray[i]);
174
ispow[i] = DOUBLE_TO_REAL(pow((double)i,(double)4.0/3.0));
178
static double Ci[8]={-0.6,-0.535,-0.33,-0.185,-0.095,-0.041,-0.0142,-0.0037};
179
double sq=sqrt(1.0+Ci[i]*Ci[i]);
180
aa_cs[i] = DOUBLE_TO_REAL(1.0/sq);
181
aa_ca[i] = DOUBLE_TO_REAL(Ci[i]/sq);
185
win[0][i] = win[1][i] =
186
DOUBLE_TO_REAL(0.5 * sin( M_PI / 72.0 * (double) (2*(i+0) +1) ) / cos ( M_PI * (double) (2*(i+0) +19) / 72.0 ));
187
win[0][i+18] = win[3][i+18] =
188
DOUBLE_TO_REAL(0.5 * sin( M_PI / 72.0 * (double) (2*(i+18)+1) ) / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 ));
191
win[1][i+18] = DOUBLE_TO_REAL(0.5 / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 ));
192
win[3][i+12] = DOUBLE_TO_REAL(0.5 / cos ( M_PI * (double) (2*(i+12)+19) / 72.0 ));
193
win[1][i+24] = DOUBLE_TO_REAL(0.5 * sin( M_PI / 24.0 * (double) (2*i+13) ) / cos ( M_PI * (double) (2*(i+24)+19) / 72.0 ));
194
win[1][i+30] = win[3][i] = DOUBLE_TO_REAL(0.0);
195
win[3][i+6 ] = DOUBLE_TO_REAL(0.5 * sin( M_PI / 24.0 * (double) (2*i+1) ) / cos ( M_PI * (double) (2*(i+6 )+19) / 72.0 ));
199
COS9[i] = DOUBLE_TO_REAL(cos( M_PI / 18.0 * (double) i));
202
tfcos36[i] = DOUBLE_TO_REAL(0.5 / cos ( M_PI * (double) (i*2+1) / 36.0 ));
204
tfcos12[i] = DOUBLE_TO_REAL(0.5 / cos ( M_PI * (double) (i*2+1) / 12.0 ));
206
COS6_1 = DOUBLE_TO_REAL(cos( M_PI / 6.0 * (double) 1));
207
COS6_2 = DOUBLE_TO_REAL(cos( M_PI / 6.0 * (double) 2));
210
cos9[0] = DOUBLE_TO_REAL(cos(1.0*M_PI/9.0));
211
cos9[1] = DOUBLE_TO_REAL(cos(5.0*M_PI/9.0));
212
cos9[2] = DOUBLE_TO_REAL(cos(7.0*M_PI/9.0));
213
cos18[0] = DOUBLE_TO_REAL(cos(1.0*M_PI/18.0));
214
cos18[1] = DOUBLE_TO_REAL(cos(11.0*M_PI/18.0));
215
cos18[2] = DOUBLE_TO_REAL(cos(13.0*M_PI/18.0));
219
win[2][i] = DOUBLE_TO_REAL(0.5 * sin( M_PI / 24.0 * (double) (2*i+1) ) / cos ( M_PI * (double) (2*i+7) / 24.0 ));
221
COS1[i][j] = DOUBLE_TO_REAL(cos( M_PI / 24.0 * (double) ((2*i+7)*(2*j+1)) ));
225
static int len[4] = { 36,36,12,36 };
226
for(i=0;i<len[j];i+=2)
227
win1[j][i] = + win[j][i];
228
for(i=1;i<len[j];i+=2)
229
win1[j][i] = - win[j][i];
233
double t = tan( (double) i * M_PI / 12.0 );
234
tan1_1[i] = DOUBLE_TO_REAL(t / (1.0+t));
235
tan2_1[i] = DOUBLE_TO_REAL(1.0 / (1.0 + t));
236
tan1_2[i] = DOUBLE_TO_REAL(M_SQRT2 * t / (1.0+t));
237
tan2_2[i] = DOUBLE_TO_REAL(M_SQRT2 / (1.0 + t));
240
double base = pow(2.0,-0.25*(j+1.0));
241
double p1=1.0,p2=1.0;
244
p1 = pow(base,(i+1.0)*0.5);
246
p2 = pow(base,i*0.5);
248
pow1_1[j][i] = DOUBLE_TO_REAL(p1);
249
pow2_1[j][i] = DOUBLE_TO_REAL(p2);
250
pow1_2[j][i] = DOUBLE_TO_REAL(M_SQRT2 * p1);
251
pow2_2[j][i] = DOUBLE_TO_REAL(M_SQRT2 * p2);
256
struct bandInfoStruct *bi = &bandInfo[j];
261
mp = map[j][0] = mapbuf0[j];
263
for(i=0,cb = 0; cb < 8 ; cb++,i+=*bdf++) {
269
bdf = bi->shortDiff+3;
270
for(cb=3;cb<13;cb++) {
271
int l = (*bdf++) >> 1;
272
for(lwin=0;lwin<3;lwin++) {
282
mp = map[j][1] = mapbuf1[j];
283
bdf = bi->shortDiff+0;
284
for(i=0,cb=0;cb<13;cb++) {
285
int l = (*bdf++) >> 1;
286
for(lwin=0;lwin<3;lwin++) {
296
mp = map[j][2] = mapbuf2[j];
298
for(cb = 0; cb < 22 ; cb++) {
299
*mp++ = (*bdf++) >> 1;
308
longLimit[j][i] = (bandInfo[j].longIdx[i] - 1 + 8) / 18 + 1;
309
if(longLimit[j][i] > (down_sample_sblimit) )
310
longLimit[j][i] = down_sample_sblimit;
313
shortLimit[j][i] = (bandInfo[j].shortIdx[i] - 1) / 18 + 1;
314
if(shortLimit[j][i] > (down_sample_sblimit) )
315
shortLimit[j][i] = down_sample_sblimit;
322
int n = k + j * 6 + i * 36;
323
i_slen2[n] = i|(j<<3)|(k<<6)|(3<<12);
330
int n = k + j * 4 + i * 16;
331
i_slen2[n+180] = i|(j<<3)|(k<<6)|(4<<12);
338
i_slen2[n+244] = i|(j<<3) | (5<<12);
339
n_slen2[n+500] = i|(j<<3) | (2<<12) | (1<<15);
347
int n = l + k * 4 + j * 16 + i * 80;
348
n_slen2[n] = i|(j<<3)|(k<<6)|(l<<9)|(0<<12);
356
int n = k + j * 4 + i * 20;
357
n_slen2[n+400] = i|(j<<3)|(k<<6)|(1<<12);
364
* read additional side information (for MPEG 1 and MPEG 2)
366
static int III_get_side_info(struct III_sideinfo *si,int stereo,
367
int ms_stereo,long sfreq,int single,int lsf)
370
int powdiff = (single == 3) ? 4 : 0;
372
static const int tabs[2][5] = { { 2,9,5,3,4 } , { 1,8,1,2,9 } };
373
const int *tab = tabs[lsf];
375
si->main_data_begin = getbits(&bsi,tab[1]);
377
si->private_bits = getbits_fast(&bsi,tab[2]);
379
si->private_bits = getbits_fast(&bsi,tab[3]);
382
for (ch=0; ch<stereo; ch++) {
383
si->ch[ch].gr[0].scfsi = -1;
384
si->ch[ch].gr[1].scfsi = getbits_fast(&bsi,4);
388
for (gr=0; gr<tab[0]; gr++) {
389
for (ch=0; ch<stereo; ch++) {
390
register struct gr_info_s *gr_info = &(si->ch[ch].gr[gr]);
392
gr_info->part2_3_length = getbits(&bsi,12);
393
gr_info->big_values = getbits(&bsi,9);
394
if(gr_info->big_values > 288) {
396
fprintf(stderr,"big_values too large!\n");
397
gr_info->big_values = 288;
399
gr_info->pow2gain = gainpow2+256 - getbits_fast(&bsi,8) + powdiff;
401
gr_info->pow2gain += 2;
402
gr_info->scalefac_compress = getbits(&bsi,tab[4]);
404
if(get1bit(&bsi)) { /* window switch flag */
407
if(2*gr_info->big_values > bandInfo[sfreq].shortIdx[12])
408
fprintf(stderr,"L3: BigValues too large, doesn't make sense %d %d\n",2*gr_info->big_values,bandInfo[sfreq].shortIdx[12]);
411
gr_info->block_type = getbits_fast(&bsi,2);
412
gr_info->mixed_block_flag = get1bit(&bsi);
413
gr_info->table_select[0] = getbits_fast(&bsi,5);
414
gr_info->table_select[1] = getbits_fast(&bsi,5);
416
* table_select[2] not needed, because there is no region2,
417
* but to satisfy some verifications tools we set it either.
419
gr_info->table_select[2] = 0;
421
gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(&bsi,3)<<3);
423
if(gr_info->block_type == 0) {
425
fprintf(stderr,"Blocktype == 0 and window-switching == 1 not allowed.\n");
429
/* region_count/start parameters are implicit in this case. */
430
if(!lsf || gr_info->block_type == 2)
431
gr_info->region1start = 36>>1;
433
/* check this again for 2.5 and sfreq=8 */
435
gr_info->region1start = 108>>1;
437
gr_info->region1start = 54>>1;
439
gr_info->region2start = 576>>1;
444
if(2*gr_info->big_values > bandInfo[sfreq].longIdx[21])
445
fprintf(stderr,"L3: BigValues too large, doesn't make sense %d %d\n",2*gr_info->big_values,bandInfo[sfreq].longIdx[21]);
448
gr_info->table_select[i] = getbits_fast(&bsi,5);
449
r0c = getbits_fast(&bsi,4);
450
r1c = getbits_fast(&bsi,3);
451
gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
452
if(r0c + r1c + 2 > 22)
453
gr_info->region2start = 576>>1;
455
gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
456
gr_info->block_type = 0;
457
gr_info->mixed_block_flag = 0;
460
gr_info->preflag = get1bit(&bsi);
461
gr_info->scalefac_scale = get1bit(&bsi);
462
gr_info->count1table_select = get1bit(&bsi);
472
static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
474
static const unsigned char slen[2][16] = {
475
{0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4},
476
{0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3}
479
int num0 = slen[0][gr_info->scalefac_compress];
480
int num1 = slen[1][gr_info->scalefac_compress];
482
if (gr_info->block_type == 2) {
484
numbits = (num0 + num1) * 18;
486
if (gr_info->mixed_block_flag) {
488
*scf++ = getbits_fast(&bsi,num0);
490
numbits -= num0; /* num0 * 17 + num1 * 18 */
494
*scf++ = getbits_fast(&bsi,num0);
496
*scf++ = getbits_fast(&bsi,num1);
497
*scf++ = 0; *scf++ = 0; *scf++ = 0; /* short[13][0..2] = 0 */
501
int scfsi = gr_info->scfsi;
503
if(scfsi < 0) { /* scfsi < 0 => granule == 0 */
505
*scf++ = getbits_fast(&bsi,num0);
507
*scf++ = getbits_fast(&bsi,num1);
508
numbits = (num0 + num1) * 10 + num0;
515
*scf++ = getbits_fast(&bsi,num0);
524
*scf++ = getbits_fast(&bsi,num0);
533
*scf++ = getbits_fast(&bsi,num1);
542
*scf++ = getbits_fast(&bsi,num1);
548
*scf++ = 0; /* no l[21] in original sources */
554
static int III_get_scale_factors_2(int *scf,struct gr_info_s *gr_info,int i_stereo)
557
int i,j,n=0,numbits=0;
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} } };
568
if(i_stereo) /* i_stereo AND second channel -> do_layer3() checks this */
569
slen = i_slen2[gr_info->scalefac_compress>>1];
571
slen = n_slen2[gr_info->scalefac_compress];
573
gr_info->preflag = (slen>>15) & 0x1;
576
if( gr_info->block_type == 2 ) {
578
if(gr_info->mixed_block_flag)
582
pnt = stab[n][(slen>>12)&0x7];
585
int num = slen & 0x7;
588
for(j=0;j<(int)(pnt[i]);j++)
589
*scf++ = getbits_fast(&bsi,num);
590
numbits += pnt[i] * num;
593
for(j=0;j<(int)(pnt[i]);j++)
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};
609
* Dequantize samples (includes huffman decoding)
611
/* 24 is enough because tab13 has max. a 19 bit huffvector */
612
#define BITSHIFT ((sizeof(long)-1)*8)
613
#define REFRESH_MASK \
614
while(num < BITSHIFT) { \
615
mask |= ((unsigned long)getbyte(&bsi))<<(BITSHIFT-num); \
619
static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
620
struct gr_info_s *gr_info,int sfreq,int part2bits)
622
int shift = 1 + gr_info->scalefac_scale;
623
real *xrpnt = (real *) xr;
625
int part2remain = gr_info->part2_3_length - part2bits;
628
int num=getbitoffset(&bsi);
630
/* we must split this, because for num==0 the shift is undefined if you do it in one step */
631
mask = ((unsigned long) getbits(&bsi,num))<<BITSHIFT;
636
int bv = gr_info->big_values;
637
int region1 = gr_info->region1start;
638
int region2 = gr_info->region2start;
640
l3 = ((576>>1)-bv)>>1;
642
* we may lose the 'odd' bit here !!
643
* check this later again
646
l[0] = bv; l[1] = l[2] = 0;
651
l[1] = bv - l[0]; l[2] = 0;
654
l[1] = region2 - l[0]; l[2] = bv - region2;
659
if(gr_info->block_type == 2) {
661
* decoding with short or mixed mode BandIndex table
664
int step=0,lwin=3,cb=0;
665
register real v = 0.0;
668
if(gr_info->mixed_block_flag) {
670
max[0] = max[1] = max[2] = 2;
672
me = mapend[sfreq][0];
675
max[0] = max[1] = max[2] = max[3] = -1;
676
/* max[3] not really needed in this case */
678
me = mapend[sfreq][1];
684
struct newhuff *h = ht+gr_info->table_select[i];
689
xrpnt = ((real *) xr) + (*m++);
693
v = gr_info->pow2gain[(*scf++) << shift];
697
v = gr_info->full_gain[lwin][(*scf++) << shift];
702
register short *val = h->table;
704
while((y=*val++)<0) {
713
if(x == 15 && h->linbits) {
716
x += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits);
720
*xrpnt = REAL_MUL(-ispow[x], v);
722
*xrpnt = REAL_MUL(ispow[x], v);
728
*xrpnt = REAL_MUL(-ispow[x], v);
730
*xrpnt = REAL_MUL(ispow[x], v);
735
*xrpnt = DOUBLE_TO_REAL(0.0);
737
if(y == 15 && h->linbits) {
740
y += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits);
744
*xrpnt = REAL_MUL(-ispow[y], v);
746
*xrpnt = REAL_MUL(ispow[y], v);
752
*xrpnt = REAL_MUL(-ispow[y], v);
754
*xrpnt = REAL_MUL(ispow[y], v);
759
*xrpnt = DOUBLE_TO_REAL(0.0);
764
for(;l3 && (part2remain+num > 0);l3--) {
765
struct newhuff *h = htc+gr_info->count1table_select;
766
register short *val = h->table,a;
769
while((a=*val++)<0) {
775
if(part2remain+num <= 0) {
776
num -= part2remain+num;
784
xrpnt = ((real *) xr) + (*m++);
788
v = gr_info->pow2gain[(*scf++) << shift];
792
v = gr_info->full_gain[lwin][(*scf++) << shift];
798
if( (a & (0x8>>i)) ) {
800
if(part2remain+num <= 0) {
811
*xrpnt = DOUBLE_TO_REAL(0.0);
816
if(lwin < 3) { /* short band? */
819
*xrpnt = DOUBLE_TO_REAL(0.0); xrpnt += 3; /* short band -> step=3 */
820
*xrpnt = DOUBLE_TO_REAL(0.0); xrpnt += 3;
825
xrpnt = ((real *) xr) + *m++;
827
break; /* optimize: field will be set to zero at the end of the function */
832
gr_info->maxband[0] = max[0]+1;
833
gr_info->maxband[1] = max[1]+1;
834
gr_info->maxband[2] = max[2]+1;
835
gr_info->maxbandl = max[3]+1;
838
int rmax = max[0] > max[1] ? max[0] : max[1];
839
rmax = (rmax > max[2] ? rmax : max[2]) + 1;
840
gr_info->maxb = rmax ? shortLimit[sfreq][rmax] : longLimit[sfreq][max[3]+1];
846
* decoding with 'long' BandIndex table (block_type != 2)
848
int *pretab = gr_info->preflag ? pretab1 : pretab2;
851
int *m = map[sfreq][2];
852
register real v = 0.0;
856
* long hash table values
860
struct newhuff *h = ht+gr_info->table_select[i];
875
v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
879
register short *val = h->table;
881
while((y=*val++)<0) {
891
if (x == 15 && h->linbits) {
894
x += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits);
898
*xrpnt++ = REAL_MUL(-ispow[x], v);
900
*xrpnt++ = REAL_MUL(ispow[x], v);
906
*xrpnt++ = REAL_MUL(-ispow[x], v);
908
*xrpnt++ = REAL_MUL(ispow[x], v);
913
*xrpnt++ = DOUBLE_TO_REAL(0.0);
915
if (y == 15 && h->linbits) {
918
y += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits);
922
*xrpnt++ = REAL_MUL(-ispow[y], v);
924
*xrpnt++ = REAL_MUL(ispow[y], v);
930
*xrpnt++ = REAL_MUL(-ispow[y], v);
932
*xrpnt++ = REAL_MUL(ispow[y], v);
937
*xrpnt++ = DOUBLE_TO_REAL(0.0);
942
* short (count1table) values
944
for(;l3 && (part2remain+num > 0);l3--) {
945
struct newhuff *h = htc+gr_info->count1table_select;
946
register short *val = h->table,a;
949
while((a=*val++)<0) {
955
if(part2remain+num <= 0) {
956
num -= part2remain+num;
972
v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
976
if ( (a & (0x8>>i)) ) {
978
if(part2remain+num <= 0) {
989
*xrpnt++ = DOUBLE_TO_REAL(0.0);
993
gr_info->maxbandl = max+1;
994
gr_info->maxb = longLimit[sfreq][gr_info->maxbandl];
1001
while(xrpnt < &xr[SBLIMIT][0])
1002
*xrpnt++ = DOUBLE_TO_REAL(0.0);
1004
while( part2remain > 16 ) {
1005
getbits(&bsi,16); /* Dismiss stuffing Bits */
1009
getbits(&bsi,part2remain);
1010
else if(part2remain < 0) {
1012
fprintf(stderr,"mpg123: Can't rewind stream by %d bits!\n",-part2remain);
1013
return 1; /* -> error */
1019
* III_stereo: calculate real channel values for Joint-I-Stereo-mode
1021
static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac,
1022
struct gr_info_s *gr_info,int sfreq,int ms_stereo,int lsf)
1024
real (*xr)[SBLIMIT*SSLIMIT] = (real (*)[SBLIMIT*SSLIMIT] ) xr_buf;
1025
struct bandInfoStruct *bi = &bandInfo[sfreq];
1027
const real *tab1,*tab2;
1030
static const real *tabs[3][2][2] = {
1031
{ { tan1_1,tan2_1 } , { tan1_2,tan2_2 } },
1032
{ { pow1_1[0],pow2_1[0] } , { pow1_2[0],pow2_2[0] } } ,
1033
{ { pow1_1[1],pow2_1[1] } , { pow1_2[1],pow2_2[1] } }
1036
tab = lsf + (gr_info->scalefac_compress & lsf);
1037
tab1 = tabs[tab][ms_stereo][0];
1038
tab2 = tabs[tab][ms_stereo][1];
1041
int p = gr_info->scalefac_compress & 0x1;
1043
tab1 = pow1_2[p]; tab2 = pow2_2[p];
1046
tab1 = pow1_1[p]; tab2 = pow2_1[p];
1051
tab1 = tan1_2; tab2 = tan2_2;
1054
tab1 = tan1_1; tab2 = tan2_1;
1059
if (gr_info->block_type == 2) {
1061
if( gr_info->mixed_block_flag )
1064
for (lwin=0;lwin<3;lwin++) { /* process each window */
1065
/* get first band with zero values */
1066
int is_p,sb,idx,sfb = gr_info->maxband[lwin]; /* sfb is minimal 3 for mixed mode */
1070
for(;sfb<12;sfb++) {
1071
is_p = scalefac[sfb*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
1074
sb = bi->shortDiff[sfb];
1075
idx = bi->shortIdx[sfb] + lwin;
1076
t1 = tab1[is_p]; t2 = tab2[is_p];
1077
for (; sb > 0; sb--,idx+=3) {
1078
real v = xr[0][idx];
1079
xr[0][idx] = REAL_MUL(v, t1);
1080
xr[1][idx] = REAL_MUL(v, t2);
1086
/* in the original: copy 10 to 11 , here: copy 11 to 12
1087
maybe still wrong??? (copy 12 to 13?) */
1088
is_p = scalefac[11*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
1089
sb = bi->shortDiff[12];
1090
idx = bi->shortIdx[12] + lwin;
1092
is_p = scalefac[10*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
1093
sb = bi->shortDiff[11];
1094
idx = bi->shortIdx[11] + lwin;
1098
t1 = tab1[is_p]; t2 = tab2[is_p];
1099
for ( ; sb > 0; sb--,idx+=3 ) {
1100
real v = xr[0][idx];
1101
xr[0][idx] = REAL_MUL(v, t1);
1102
xr[1][idx] = REAL_MUL(v, t2);
1105
} /* end for(lwin; .. ; . ) */
1107
/* also check l-part, if ALL bands in the three windows are 'empty'
1108
* and mode = mixed_mode
1111
int sfb = gr_info->maxbandl;
1112
int idx = bi->longIdx[sfb];
1114
for ( ; sfb<8; sfb++ ) {
1115
int sb = bi->longDiff[sfb];
1116
int is_p = scalefac[sfb]; /* scale: 0-15 */
1119
t1 = tab1[is_p]; t2 = tab2[is_p];
1120
for ( ; sb > 0; sb--,idx++) {
1121
real v = xr[0][idx];
1122
xr[0][idx] = REAL_MUL(v, t1);
1123
xr[1][idx] = REAL_MUL(v, t2);
1131
else { /* ((gr_info->block_type != 2)) */
1132
int sfb = gr_info->maxbandl;
1133
int is_p,idx = bi->longIdx[sfb];
1135
/* hmm ... maybe the maxbandl stuff for i-stereo is buggy? */
1137
for ( ; sfb<21; sfb++) {
1138
int sb = bi->longDiff[sfb];
1139
is_p = scalefac[sfb]; /* scale: 0-15 */
1142
t1 = tab1[is_p]; t2 = tab2[is_p];
1143
for ( ; sb > 0; sb--,idx++) {
1144
real v = xr[0][idx];
1145
xr[0][idx] = REAL_MUL(v, t1);
1146
xr[1][idx] = REAL_MUL(v, t2);
1153
is_p = scalefac[20];
1154
if(is_p != 7) { /* copy l-band 20 to l-band 21 */
1156
real t1 = tab1[is_p],t2 = tab2[is_p];
1158
for ( sb = bi->longDiff[21]; sb > 0; sb--,idx++ ) {
1159
real v = xr[0][idx];
1160
xr[0][idx] = REAL_MUL(v, t1);
1161
xr[1][idx] = REAL_MUL(v, t2);
1164
} /* end: if(sfb <= 21) */
1168
static void III_antialias(real xr[SBLIMIT][SSLIMIT],struct gr_info_s *gr_info) {
1171
if(gr_info->block_type == 2) {
1172
if(!gr_info->mixed_block_flag)
1177
sblim = gr_info->maxb-1;
1180
/* 31 alias-reduction operations between each pair of sub-bands */
1181
/* with 8 butterflies between each pair */
1185
real *xr1=(real *) xr[1];
1187
for(sb=sblim;sb;sb--,xr1+=10) {
1189
real *cs=aa_cs,*ca=aa_ca;
1192
for(ss=7;ss>=0;ss--)
1193
{ /* upper and lower butterfly inputs */
1194
register real bu = *--xr2,bd = *xr1;
1195
*xr2 = REAL_MUL(bu, *cs) - REAL_MUL(bd, *ca);
1196
*xr1++ = REAL_MUL(bd, *cs++) + REAL_MUL(bu, *ca++);
1203
This is an optimized DCT from Jeff Tsay's maplay 1.2+ package.
1204
Saved one multiplication by doing the 'twiddle factor' stuff
1205
together with the window mul. (MH)
1207
This uses Byeong Gi Lee's Fast Cosine Transform algorithm, but the
1208
9 point IDCT needs to be reduced further. Unfortunately, I don't
1209
know how to do that, because 9 is not an even number. - Jeff.
1211
****************************************************************
1213
9 Point Inverse Discrete Cosine Transform
1215
This piece of code is Copyright 1997 Mikko Tommila and is freely usable
1216
by anybody. The algorithm itself is of course in the public domain.
1218
Again derived heuristically from the 9-point WFTA.
1220
The algorithm is optimized (?) for speed, not for small rounding errors or
1223
36 additions, 11 multiplications
1225
Again this is very likely sub-optimal.
1227
The code is optimized to use a minimum number of temporary variables,
1228
so it should compile quite well even on 8-register Intel x86 processors.
1229
This makes the code quite obfuscated and very difficult to understand.
1232
[1] S. Winograd: "On Computing the Discrete Fourier Transform",
1233
Mathematics of Computation, Volume 32, Number 141, January 1978,
1237
/*------------------------------------------------------------------*/
1239
/* Function: Calculation of the inverse MDCT */
1241
/*------------------------------------------------------------------*/
1243
void dct36(real *inbuf,real *o1,real *o2,real *wintab,real *tsbuf)
1250
register real *in = inbuf;
1252
in[17]+=in[16]; in[16]+=in[15]; in[15]+=in[14];
1253
in[14]+=in[13]; in[13]+=in[12]; in[12]+=in[11];
1254
in[11]+=in[10]; in[10]+=in[9]; in[9] +=in[8];
1255
in[8] +=in[7]; in[7] +=in[6]; in[6] +=in[5];
1256
in[5] +=in[4]; in[4] +=in[3]; in[3] +=in[2];
1257
in[2] +=in[1]; in[1] +=in[0];
1259
in[17]+=in[15]; in[15]+=in[13]; in[13]+=in[11]; in[11]+=in[9];
1260
in[9] +=in[7]; in[7] +=in[5]; in[5] +=in[3]; in[3] +=in[1];
1270
t0 = REAL_MUL(COS6_2, (in[8] + in[16] - in[4]));
1271
t1 = REAL_MUL(COS6_2, in[12]);
1275
tmp[1] = tmp[7] = t2 - t0;
1276
tmp[4] = t2 + t0 + t0;
1279
t2 = REAL_MUL(COS6_1, (in[10] + in[14] - in[2]));
1286
t0 = REAL_MUL(cos9[0], (in[4] + in[8] ));
1287
t1 = REAL_MUL(cos9[1], (in[8] - in[16]));
1288
t2 = REAL_MUL(cos9[2], (in[4] + in[16]));
1290
tmp[2] = tmp[6] = t3 - t0 - t2;
1291
tmp[0] = tmp[8] = t3 + t0 + t1;
1292
tmp[3] = tmp[5] = t3 - t1 + t2;
1298
t1 = REAL_MUL(cos18[0], (in[2] + in[10]));
1299
t2 = REAL_MUL(cos18[1], (in[10] - in[14]));
1300
t3 = REAL_MUL(COS6_1, in[6]);
1303
real t0 = t1 + t2 + t3;
1311
t3 = REAL_MUL(cos18[2], (in[2] + in[14]));
1324
real t0, t1, t2, t3, t4, t5, t6, t7;
1326
t1 = REAL_MUL(COS6_2, in[12]);
1327
t2 = REAL_MUL(COS6_2, (in[8] + in[16] - in[4]));
1330
t4 = in[0] - t1 - t1;
1332
tmp[4] = t4 + t2 + t2;
1334
t0 = REAL_MUL(cos9[0], (in[4] + in[8]));
1335
t1 = REAL_MUL(cos9[1], (in[8] - in[16]));
1337
t2 = REAL_MUL(cos9[2], (in[4] + in[16]));
1343
t2 = REAL_MUL(cos18[0], (in[2] + in[10]));
1344
t4 = REAL_MUL(cos18[1], (in[10] - in[14]));
1345
t7 = REAL_MUL(COS6_1, in[6]);
1350
t1 = REAL_MUL(cos18[2], (in[2] + in[14]));
1354
t0 = REAL_MUL(COS6_1, (in[10] + in[14] - in[2]));
1367
real t0, t1, t2, t3, t4, t5, t6, t7;
1369
t1 = REAL_MUL(COS6_2, in[13]);
1370
t2 = REAL_MUL(COS6_2, (in[9] + in[17] - in[5]));
1373
t4 = in[1] - t1 - t1;
1376
t0 = REAL_MUL(cos9[0], (in[5] + in[9]));
1377
t1 = REAL_MUL(cos9[1], (in[9] - in[17]));
1379
tmp[13] = REAL_MUL((t4 + t2 + t2), tfcos36[17-13]);
1380
t2 = REAL_MUL(cos9[2], (in[5] + in[17]));
1386
t2 = REAL_MUL(cos18[0], (in[3] + in[11]));
1387
t4 = REAL_MUL(cos18[1], (in[11] - in[15]));
1388
t7 = REAL_MUL(COS6_1, in[7]);
1391
tmp[17] = REAL_MUL((t0 + t1), tfcos36[17-17]);
1392
tmp[9] = REAL_MUL((t0 - t1), tfcos36[17-9]);
1393
t1 = REAL_MUL(cos18[2], (in[3] + in[15]));
1396
tmp[14] = REAL_MUL((t3 + t2), tfcos36[17-14]);
1397
t0 = REAL_MUL(COS6_1, (in[11] + in[15] - in[3]));
1398
tmp[12] = REAL_MUL((t3 - t2), tfcos36[17-12]);
1402
tmp[16] = REAL_MUL((t5 - t0), tfcos36[17-16]);
1403
tmp[10] = REAL_MUL((t5 + t0), tfcos36[17-10]);
1404
tmp[15] = REAL_MUL((t6 + t4), tfcos36[17-15]);
1405
tmp[11] = REAL_MUL((t6 - t4), tfcos36[17-11]);
1408
#define MACRO(v) { \
1410
tmpval = tmp[(v)] + tmp[17-(v)]; \
1411
out2[9+(v)] = REAL_MUL(tmpval, w[27+(v)]); \
1412
out2[8-(v)] = REAL_MUL(tmpval, w[26-(v)]); \
1413
tmpval = tmp[(v)] - tmp[17-(v)]; \
1414
ts[SBLIMIT*(8-(v))] = out1[8-(v)] + REAL_MUL(tmpval, w[8-(v)]); \
1415
ts[SBLIMIT*(9+(v))] = out1[9+(v)] + REAL_MUL(tmpval, w[9+(v)]); }
1418
register real *out2 = o2;
1419
register real *w = wintab;
1420
register real *out1 = o1;
1421
register real *ts = tsbuf;
1438
#define MACRO0(v) { \
1440
out2[9+(v)] = REAL_MUL((tmp = sum0 + sum1), w[27+(v)]); \
1441
out2[8-(v)] = REAL_MUL(tmp, w[26-(v)]); } \
1443
ts[SBLIMIT*(8-(v))] = out1[8-(v)] + REAL_MUL(sum0, w[8-(v)]); \
1444
ts[SBLIMIT*(9+(v))] = out1[9+(v)] + REAL_MUL(sum0, w[9+(v)]);
1445
#define MACRO1(v) { \
1447
sum0 = tmp1a + tmp2a; \
1448
sum1 = REAL_MUL((tmp1b + tmp2b), tfcos36[(v)]); \
1450
#define MACRO2(v) { \
1452
sum0 = tmp2a - tmp1a; \
1453
sum1 = REAL_MUL((tmp2b - tmp1b), tfcos36[(v)]); \
1456
register const real *c = COS9;
1457
register real *out2 = o2;
1458
register real *w = wintab;
1459
register real *out1 = o1;
1460
register real *ts = tsbuf;
1462
real ta33,ta66,tb33,tb66;
1464
ta33 = REAL_MUL(in[2*3+0], c[3]);
1465
ta66 = REAL_MUL(in[2*6+0], c[6]);
1466
tb33 = REAL_MUL(in[2*3+1], c[3]);
1467
tb66 = REAL_MUL(in[2*6+1], c[6]);
1470
real tmp1a,tmp2a,tmp1b,tmp2b;
1471
tmp1a = REAL_MUL(in[2*1+0], c[1]) + ta33 + REAL_MUL(in[2*5+0], c[5]) + REAL_MUL(in[2*7+0], c[7]);
1472
tmp1b = REAL_MUL(in[2*1+1], c[1]) + tb33 + REAL_MUL(in[2*5+1], c[5]) + REAL_MUL(in[2*7+1], c[7]);
1473
tmp2a = REAL_MUL(in[2*2+0], c[2]) + REAL_MUL(in[2*4+0], c[4]) + ta66 + REAL_MUL(in[2*8+0], c[8]);
1474
tmp2b = REAL_MUL(in[2*2+1], c[2]) + REAL_MUL(in[2*4+1], c[4]) + tb66 + REAL_MUL(in[2*8+1], c[8]);
1481
real tmp1a,tmp2a,tmp1b,tmp2b;
1482
tmp1a = REAL_MUL(( in[2*1+0] - in[2*5+0] - in[2*7+0] ), c[3]);
1483
tmp1b = REAL_MUL(( in[2*1+1] - in[2*5+1] - in[2*7+1] ), c[3]);
1484
tmp2a = REAL_MUL(( in[2*2+0] - in[2*4+0] - in[2*8+0] ), c[6]) - in[2*6+0] + in[2*0+0];
1485
tmp2b = REAL_MUL(( in[2*2+1] - in[2*4+1] - in[2*8+1] ), c[6]) - in[2*6+1] + in[2*0+1];
1492
real tmp1a,tmp2a,tmp1b,tmp2b;
1493
tmp1a = REAL_MUL(in[2*1+0], c[5]) - ta33 - REAL_MUL(in[2*5+0], c[7]) + REAL_MUL(in[2*7+0], c[1]);
1494
tmp1b = REAL_MUL(in[2*1+1], c[5]) - tb33 - REAL_MUL(in[2*5+1], c[7]) + REAL_MUL(in[2*7+1], c[1]);
1495
tmp2a = - REAL_MUL(in[2*2+0], c[8]) - REAL_MUL(in[2*4+0], c[2]) + ta66 + REAL_MUL(in[2*8+0], c[4]);
1496
tmp2b = - REAL_MUL(in[2*2+1], c[8]) - REAL_MUL(in[2*4+1], c[2]) + tb66 + REAL_MUL(in[2*8+1], c[4]);
1503
real tmp1a,tmp2a,tmp1b,tmp2b;
1504
tmp1a = REAL_MUL(in[2*1+0], c[7]) - ta33 + REAL_MUL(in[2*5+0], c[1]) - REAL_MUL(in[2*7+0], c[5]);
1505
tmp1b = REAL_MUL(in[2*1+1], c[7]) - tb33 + REAL_MUL(in[2*5+1], c[1]) - REAL_MUL(in[2*7+1], c[5]);
1506
tmp2a = - REAL_MUL(in[2*2+0], c[4]) + REAL_MUL(in[2*4+0], c[8]) + ta66 - REAL_MUL(in[2*8+0], c[2]);
1507
tmp2b = - REAL_MUL(in[2*2+1], c[4]) + REAL_MUL(in[2*4+1], c[8]) + tb66 - REAL_MUL(in[2*8+1], c[2]);
1515
sum0 = in[2*0+0] - in[2*2+0] + in[2*4+0] - in[2*6+0] + in[2*8+0];
1516
sum1 = REAL_MUL((in[2*0+1] - in[2*2+1] + in[2*4+1] - in[2*6+1] + in[2*8+1] ), tfcos36[4]);
1528
static void dct12(real *in,real *rawout1,real *rawout2,register real *wi,register real *ts)
1530
#define DCT12_PART1 \
1532
in5 += (in4 = in[4*3]); \
1533
in4 += (in3 = in[3*3]); \
1534
in3 += (in2 = in[2*3]); \
1535
in2 += (in1 = in[1*3]); \
1536
in1 += (in0 = in[0*3]); \
1538
in5 += in3; in3 += in1; \
1540
in2 = REAL_MUL(in2, COS6_1); \
1541
in3 = REAL_MUL(in3, COS6_1); \
1543
#define DCT12_PART2 \
1544
in0 += REAL_MUL(in4, COS6_2); \
1549
in1 += REAL_MUL(in5, COS6_2); \
1551
in5 = REAL_MUL((in1 + in3), tfcos12[0]); \
1552
in1 = REAL_MUL((in1 - in3), tfcos12[2]); \
1562
real in0,in1,in2,in3,in4,in5;
1563
register real *out1 = rawout1;
1564
ts[SBLIMIT*0] = out1[0]; ts[SBLIMIT*1] = out1[1]; ts[SBLIMIT*2] = out1[2];
1565
ts[SBLIMIT*3] = out1[3]; ts[SBLIMIT*4] = out1[4]; ts[SBLIMIT*5] = out1[5];
1570
real tmp0,tmp1 = (in0 - in4);
1572
real tmp2 = REAL_MUL((in1 - in5), tfcos12[1]);
1576
ts[(17-1)*SBLIMIT] = out1[17-1] + REAL_MUL(tmp0, wi[11-1]);
1577
ts[(12+1)*SBLIMIT] = out1[12+1] + REAL_MUL(tmp0, wi[6+1]);
1578
ts[(6 +1)*SBLIMIT] = out1[6 +1] + REAL_MUL(tmp1, wi[1]);
1579
ts[(11-1)*SBLIMIT] = out1[11-1] + REAL_MUL(tmp1, wi[5-1]);
1584
ts[(17-0)*SBLIMIT] = out1[17-0] + REAL_MUL(in2, wi[11-0]);
1585
ts[(12+0)*SBLIMIT] = out1[12+0] + REAL_MUL(in2, wi[6+0]);
1586
ts[(12+2)*SBLIMIT] = out1[12+2] + REAL_MUL(in3, wi[6+2]);
1587
ts[(17-2)*SBLIMIT] = out1[17-2] + REAL_MUL(in3, wi[11-2]);
1589
ts[(6 +0)*SBLIMIT] = out1[6+0] + REAL_MUL(in0, wi[0]);
1590
ts[(11-0)*SBLIMIT] = out1[11-0] + REAL_MUL(in0, wi[5-0]);
1591
ts[(6 +2)*SBLIMIT] = out1[6+2] + REAL_MUL(in4, wi[2]);
1592
ts[(11-2)*SBLIMIT] = out1[11-2] + REAL_MUL(in4, wi[5-2]);
1598
real in0,in1,in2,in3,in4,in5;
1599
register real *out2 = rawout2;
1604
real tmp0,tmp1 = (in0 - in4);
1606
real tmp2 = REAL_MUL((in1 - in5), tfcos12[1]);
1610
out2[5-1] = REAL_MUL(tmp0, wi[11-1]);
1611
out2[0+1] = REAL_MUL(tmp0, wi[6+1]);
1612
ts[(12+1)*SBLIMIT] += REAL_MUL(tmp1, wi[1]);
1613
ts[(17-1)*SBLIMIT] += REAL_MUL(tmp1, wi[5-1]);
1618
out2[5-0] = REAL_MUL(in2, wi[11-0]);
1619
out2[0+0] = REAL_MUL(in2, wi[6+0]);
1620
out2[0+2] = REAL_MUL(in3, wi[6+2]);
1621
out2[5-2] = REAL_MUL(in3, wi[11-2]);
1623
ts[(12+0)*SBLIMIT] += REAL_MUL(in0, wi[0]);
1624
ts[(17-0)*SBLIMIT] += REAL_MUL(in0, wi[5-0]);
1625
ts[(12+2)*SBLIMIT] += REAL_MUL(in4, wi[2]);
1626
ts[(17-2)*SBLIMIT] += REAL_MUL(in4, wi[5-2]);
1632
real in0,in1,in2,in3,in4,in5;
1633
register real *out2 = rawout2;
1634
out2[12]=out2[13]=out2[14]=out2[15]=out2[16]=out2[17]=0.0;
1639
real tmp0,tmp1 = (in0 - in4);
1641
real tmp2 = REAL_MUL((in1 - in5), tfcos12[1]);
1645
out2[11-1] = REAL_MUL(tmp0, wi[11-1]);
1646
out2[6 +1] = REAL_MUL(tmp0, wi[6+1]);
1647
out2[0+1] += REAL_MUL(tmp1, wi[1]);
1648
out2[5-1] += REAL_MUL(tmp1, wi[5-1]);
1653
out2[11-0] = REAL_MUL(in2, wi[11-0]);
1654
out2[6 +0] = REAL_MUL(in2, wi[6+0]);
1655
out2[6 +2] = REAL_MUL(in3, wi[6+2]);
1656
out2[11-2] = REAL_MUL(in3, wi[11-2]);
1658
out2[0+0] += REAL_MUL(in0, wi[0]);
1659
out2[5-0] += REAL_MUL(in0, wi[5-0]);
1660
out2[0+2] += REAL_MUL(in4, wi[2]);
1661
out2[5-2] += REAL_MUL(in4, wi[5-2]);
1668
static void III_hybrid(struct mpstr *mp,real fsIn[SBLIMIT][SSLIMIT],real tsOut[SSLIMIT][SBLIMIT],
1669
int ch,struct gr_info_s *gr_info,struct frame *fr)
1672
static real block[2][2][SBLIMIT*SSLIMIT] = { { { 0, } } };
1673
static int blc[2]={0,0};
1676
real *tspnt = (real *) tsOut;
1677
real *rawout1,*rawout2;
1681
int b = mp->hybrid_blc[ch];
1682
rawout1=mp->hybrid_block[b][ch];
1684
rawout2=mp->hybrid_block[b][ch];
1685
mp->hybrid_blc[ch] = b;
1688
if(gr_info->mixed_block_flag) {
1691
(fr->dct36)(fsIn[0],rawout1,rawout2,win[0],tspnt);
1692
(fr->dct36)(fsIn[1],rawout1+18,rawout2+18,win1[0],tspnt+1);
1694
dct36(fsIn[0],rawout1,rawout2,win[0],tspnt);
1695
dct36(fsIn[1],rawout1+18,rawout2+18,win1[0],tspnt+1);
1697
rawout1 += 36; rawout2 += 36; tspnt += 2;
1700
bt = gr_info->block_type;
1702
for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) {
1703
dct12(fsIn[sb] ,rawout1 ,rawout2 ,win[2] ,tspnt);
1704
dct12(fsIn[sb+1],rawout1+18,rawout2+18,win1[2],tspnt+1);
1708
for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) {
1710
(fr->dct36)(fsIn[sb],rawout1,rawout2,win[bt],tspnt);
1711
(fr->dct36)(fsIn[sb+1],rawout1+18,rawout2+18,win1[bt],tspnt+1);
1713
dct36(fsIn[sb],rawout1,rawout2,win[bt],tspnt);
1714
dct36(fsIn[sb+1],rawout1+18,rawout2+18,win1[bt],tspnt+1);
1719
for(;sb<SBLIMIT;sb++,tspnt++) {
1721
for(i=0;i<SSLIMIT;i++) {
1722
tspnt[i*SBLIMIT] = *rawout1++;
1723
*rawout2++ = DOUBLE_TO_REAL(0.0);
1731
* main layer3 handler
1733
int do_layer3(struct mpstr *mp,struct frame *fr,int outmode,struct audio_info_struct *ai)
1735
int gr, ch, ss,clip=0;
1736
int scalefacs[2][39]; /* max 39 for short[13][3] mode, mixed: 38, long: 22 */
1737
struct III_sideinfo sideinfo;
1738
int stereo = fr->stereo;
1739
int single = fr->single;
1740
int ms_stereo,i_stereo;
1741
int sfreq = fr->sampling_frequency;
1742
int stereo1,granules;
1744
if(stereo == 1) { /* stream is mono */
1748
else if(single >= 0) /* stream is stereo, but force to mono */
1753
if(fr->mode == MPG_MD_JOINT_STEREO) {
1754
ms_stereo = (fr->mode_ext & 0x2)>>1;
1755
i_stereo = fr->mode_ext & 0x1;
1758
ms_stereo = i_stereo = 0;
1760
granules = fr->lsf ? 1 : 2;
1761
if(!III_get_side_info(&sideinfo,stereo,ms_stereo,sfreq,single,fr->lsf))
1764
set_pointer(fr->sideInfoSize,sideinfo.main_data_begin);
1766
for (gr=0;gr<granules;gr++) {
1767
real hybridIn [2][SBLIMIT][SSLIMIT];
1768
real hybridOut[2][SSLIMIT][SBLIMIT];
1771
struct gr_info_s *gr_info = &(sideinfo.ch[0].gr[gr]);
1774
part2bits = III_get_scale_factors_2(scalefacs[0],gr_info,0);
1776
part2bits = III_get_scale_factors_1(scalefacs[0],gr_info);
1778
if(III_dequantize_sample(hybridIn[0], scalefacs[0],gr_info,sfreq,part2bits))
1783
struct gr_info_s *gr_info = &(sideinfo.ch[1].gr[gr]);
1786
part2bits = III_get_scale_factors_2(scalefacs[1],gr_info,i_stereo);
1788
part2bits = III_get_scale_factors_1(scalefacs[1],gr_info);
1790
if(III_dequantize_sample(hybridIn[1],scalefacs[1],gr_info,sfreq,part2bits))
1795
int maxb = sideinfo.ch[0].gr[gr].maxb;
1796
if(sideinfo.ch[1].gr[gr].maxb > maxb)
1797
maxb = sideinfo.ch[1].gr[gr].maxb;
1798
for(i=0;i<SSLIMIT*maxb;i++) {
1799
real tmp0 = ((real *)hybridIn[0])[i];
1800
real tmp1 = ((real *)hybridIn[1])[i];
1801
((real *)hybridIn[0])[i] = tmp0 + tmp1;
1802
((real *)hybridIn[1])[i] = tmp0 - tmp1;
1807
III_i_stereo(hybridIn,scalefacs[1],gr_info,sfreq,ms_stereo,fr->lsf);
1809
if(ms_stereo || i_stereo || (single == 3) ) {
1810
if(gr_info->maxb > sideinfo.ch[0].gr[gr].maxb)
1811
sideinfo.ch[0].gr[gr].maxb = gr_info->maxb;
1813
gr_info->maxb = sideinfo.ch[0].gr[gr].maxb;
1820
register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1];
1821
for(i=0;i<SSLIMIT*gr_info->maxb;i++,in0++)
1822
*in0 = (*in0 + *in1++); /* *0.5 done by pow-scale */
1828
register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1];
1829
for(i=0;i<SSLIMIT*gr_info->maxb;i++)
1836
for(ch=0;ch<stereo1;ch++) {
1837
struct gr_info_s *gr_info = &(sideinfo.ch[ch].gr[gr]);
1838
III_antialias(hybridIn[ch],gr_info);
1839
III_hybrid(mp,hybridIn[ch], hybridOut[ch], ch,gr_info,fr);
1843
if (fr->synth != synth_1to1 || single >= 0) {
1845
for(ss=0;ss<SSLIMIT;ss++) {
1847
clip += (fr->synth_mono)(hybridOut[0][ss],pcm_sample,&pcm_point);
1851
clip += (fr->synth)(hybridOut[0][ss],0,pcm_sample,&p1);
1852
clip += (fr->synth)(hybridOut[1][ss],1,pcm_sample,&pcm_point);
1855
if(pcm_point >= audiobufsize)
1856
audio_flush(outmode,ai);
1860
/* Only stereo, 16 bits benefit from the 486 optimization. */
1862
while (ss < SSLIMIT) {
1864
n=(audiobufsize - pcm_point) / (2*2*32);
1865
if (n > (SSLIMIT-ss)) n=SSLIMIT-ss;
1867
synth_1to1_486(hybridOut[0][ss],0,pcm_sample+pcm_point,n);
1868
synth_1to1_486(hybridOut[1][ss],1,pcm_sample+pcm_point,n);
1870
pcm_point+=(2*2*32)*n;
1872
if(pcm_point >= audiobufsize)
1873
audio_flush(outmode,ai);