📄 layer3.c
字号:
} /* * short (count1table) values */ for(;l3 && (part2remain+num > 0);l3--) { struct newhuff *h = htc+gr_info->count1table_select; register short *val = h->table,a; REFRESH_MASK; while((a=*val++)<0) { if (mask < 0) val -= a; num--; mask <<= 1; } if(part2remain+num <= 0) { num -= part2remain+num; break; } for(i=0;i<4;i++) { if(!(i & 1)) { if(!mc) { mc = *m++; cb = *m++; if(cb == 21) v = 0.0; else v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift]; } mc--; } if ( (a & (0x8>>i)) ) { max = cb; if(part2remain+num <= 0) { break; } if(mask < 0) *xrpnt++ = -v; else *xrpnt++ = v; num--; mask <<= 1; } else *xrpnt++ = 0.0; } } gr_info->maxbandl = max+1; gr_info->maxb = longLimit[sfreq][gr_info->maxbandl]; } part2remain += num; backbits(num); num = 0; while(xrpnt < &xr[SBLIMIT][0]) *xrpnt++ = 0.0; while( part2remain > 16 ) { getbits(16); /* Dismiss stuffing Bits */ part2remain -= 16; } if(part2remain > 0) getbits(part2remain); else if(part2remain < 0) { fprintf(stderr,"mpg123: Can't rewind stream by %d bits!\n",-part2remain); return 1; /* -> error */ } return 0;}/* * III_stereo: calculate real channel values for Joint-I-Stereo-mode */static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac, struct gr_info_s *gr_info,int sfreq,int ms_stereo,int lsf){ real (*xr)[SBLIMIT*SSLIMIT] = (real (*)[SBLIMIT*SSLIMIT] ) xr_buf; struct bandInfoStruct *bi = &bandInfo[sfreq]; const real *tab1,*tab2;#if 1 int tab;/* TODO: optimize as static */ static const real *tabs[3][2][2] = { { { tan1_1,tan2_1 } , { tan1_2,tan2_2 } }, { { pow1_1[0],pow2_1[0] } , { pow1_2[0],pow2_2[0] } } , { { pow1_1[1],pow2_1[1] } , { pow1_2[1],pow2_2[1] } } }; tab = lsf + (gr_info->scalefac_compress & lsf); tab1 = tabs[tab][ms_stereo][0]; tab2 = tabs[tab][ms_stereo][1];#else if(lsf) { int p = gr_info->scalefac_compress & 0x1; if(ms_stereo) { tab1 = pow1_2[p]; tab2 = pow2_2[p]; } else { tab1 = pow1_1[p]; tab2 = pow2_1[p]; } } else { if(ms_stereo) { tab1 = tan1_2; tab2 = tan2_2; } else { tab1 = tan1_1; tab2 = tan2_1; } }#endif if (gr_info->block_type == 2) { int lwin,do_l = 0; if( gr_info->mixed_block_flag ) do_l = 1; for (lwin=0;lwin<3;lwin++) { /* process each window */ /* get first band with zero values */ int is_p,sb,idx,sfb = gr_info->maxband[lwin]; /* sfb is minimal 3 for mixed mode */ if(sfb > 3) do_l = 0; for(;sfb<12;sfb++) { is_p = scalefac[sfb*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ if(is_p != 7) { real t1,t2; sb = bi->shortDiff[sfb]; idx = bi->shortIdx[sfb] + lwin; t1 = tab1[is_p]; t2 = tab2[is_p]; for (; sb > 0; sb--,idx+=3) { real v = xr[0][idx]; xr[0][idx] = v * t1; xr[1][idx] = v * t2; } } }#if 1/* in the original: copy 10 to 11 , here: copy 11 to 12 maybe still wrong??? (copy 12 to 13?) */ is_p = scalefac[11*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ sb = bi->shortDiff[12]; idx = bi->shortIdx[12] + lwin;#else is_p = scalefac[10*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ sb = bi->shortDiff[11]; idx = bi->shortIdx[11] + lwin;#endif if(is_p != 7) { real t1,t2; t1 = tab1[is_p]; t2 = tab2[is_p]; for ( ; sb > 0; sb--,idx+=3 ) { real v = xr[0][idx]; xr[0][idx] = v * t1; xr[1][idx] = v * t2; } } } /* end for(lwin; .. ; . ) *//* also check l-part, if ALL bands in the three windows are 'empty' * and mode = mixed_mode */ if (do_l) { int sfb = gr_info->maxbandl; int idx = bi->longIdx[sfb]; for ( ; sfb<8; sfb++ ) { int sb = bi->longDiff[sfb]; int is_p = scalefac[sfb]; /* scale: 0-15 */ if(is_p != 7) { real t1,t2; t1 = tab1[is_p]; t2 = tab2[is_p]; for ( ; sb > 0; sb--,idx++) { real v = xr[0][idx]; xr[0][idx] = v * t1; xr[1][idx] = v * t2; } } else idx += sb; } } } else { /* ((gr_info->block_type != 2)) */ int sfb = gr_info->maxbandl; int is_p,idx = bi->longIdx[sfb]; for ( ; sfb<21; sfb++) { int sb = bi->longDiff[sfb]; is_p = scalefac[sfb]; /* scale: 0-15 */ if(is_p != 7) { real t1,t2; t1 = tab1[is_p]; t2 = tab2[is_p]; for ( ; sb > 0; sb--,idx++) { real v = xr[0][idx]; xr[0][idx] = v * t1; xr[1][idx] = v * t2; } } else idx += sb; } is_p = scalefac[20]; if(is_p != 7) { /* copy l-band 20 to l-band 21 */ int sb; real t1 = tab1[is_p],t2 = tab2[is_p]; for ( sb = bi->longDiff[21]; sb > 0; sb--,idx++ ) { real v = xr[0][idx]; xr[0][idx] = v * t1; xr[1][idx] = v * t2; } } } /* ... */}static void III_antialias(real xr[SBLIMIT][SSLIMIT],struct gr_info_s *gr_info) { int sblim; if(gr_info->block_type == 2) { if(!gr_info->mixed_block_flag) return; sblim = 1; } else { sblim = gr_info->maxb-1; } /* 31 alias-reduction operations between each pair of sub-bands */ /* with 8 butterflies between each pair */ { int sb; real *xr1=(real *) xr[1]; for(sb=sblim;sb;sb--,xr1+=10) { int ss; real *cs=aa_cs,*ca=aa_ca; real *xr2 = xr1; for(ss=7;ss>=0;ss--) { /* upper and lower butterfly inputs */ register real bu = *--xr2,bd = *xr1; *xr2 = (bu * (*cs) ) - (bd * (*ca) ); *xr1++ = (bd * (*cs++) ) + (bu * (*ca++) ); } } }}/* // This is an optimized DCT from Jeff Tsay's maplay 1.2+ package.// Saved one multiplication by doing the 'twiddle factor' stuff// together with the window mul. (MH)//// This uses Byeong Gi Lee's Fast Cosine Transform algorithm, but the// 9 point IDCT needs to be reduced further. Unfortunately, I don't// know how to do that, because 9 is not an even number. - Jeff.//////////////////////////////////////////////////////////////////////// 9 Point Inverse Discrete Cosine Transform//// This piece of code is Copyright 1997 Mikko Tommila and is freely usable// by anybody. The algorithm itself is of course in the public domain.//// Again derived heuristically from the 9-point WFTA.//// The algorithm is optimized (?) for speed, not for small rounding errors or// good readability.//// 36 additions, 11 multiplications//// Again this is very likely sub-optimal.//// The code is optimized to use a minimum number of temporary variables,// so it should compile quite well even on 8-register Intel x86 processors.// This makes the code quite obfuscated and very difficult to understand.//// References:// [1] S. Winograd: "On Computing the Discrete Fourier Transform",// Mathematics of Computation, Volume 32, Number 141, January 1978,// Pages 175-199*//*------------------------------------------------------------------*//* *//* Function: Calculation of the inverse MDCT *//* *//*------------------------------------------------------------------*/static void dct36(real *inbuf,real *o1,real *o2,real *wintab,real *tsbuf){#ifdef NEW_DCT9 real tmp[18];#endif { register real *in = inbuf; in[17]+=in[16]; in[16]+=in[15]; in[15]+=in[14]; in[14]+=in[13]; in[13]+=in[12]; in[12]+=in[11]; in[11]+=in[10]; in[10]+=in[9]; in[9] +=in[8]; in[8] +=in[7]; in[7] +=in[6]; in[6] +=in[5]; in[5] +=in[4]; in[4] +=in[3]; in[3] +=in[2]; in[2] +=in[1]; in[1] +=in[0]; in[17]+=in[15]; in[15]+=in[13]; in[13]+=in[11]; in[11]+=in[9]; in[9] +=in[7]; in[7] +=in[5]; in[5] +=in[3]; in[3] +=in[1];#ifdef NEW_DCT9#if 1 { real t3; { real t0, t1, t2; t0 = COS6_2 * (in[8] + in[16] - in[4]); t1 = COS6_2 * in[12]; t3 = in[0]; t2 = t3 - t1 - t1; tmp[1] = tmp[7] = t2 - t0; tmp[4] = t2 + t0 + t0; t3 += t1; t2 = COS6_1 * (in[10] + in[14] - in[2]); tmp[1] -= t2; tmp[7] += t2; } { real t0, t1, t2; t0 = cos9[0] * (in[4] + in[8] ); t1 = cos9[1] * (in[8] - in[16]); t2 = cos9[2] * (in[4] + in[16]); tmp[2] = tmp[6] = t3 - t0 - t2; tmp[0] = tmp[8] = t3 + t0 + t1; tmp[3] = tmp[5] = t3 - t1 + t2; } } { real t1, t2, t3; t1 = cos18[0] * (in[2] + in[10]); t2 = cos18[1] * (in[10] - in[14]); t3 = COS6_1 * in[6]; { real t0 = t1 + t2 + t3; tmp[0] += t0; tmp[8] -= t0; } t2 -= t3; t1 -= t3; t3 = cos18[2] * (in[2] + in[14]); t1 += t3; tmp[3] += t1; tmp[5] -= t1; t2 -= t3; tmp[2] += t2; tmp[6] -= t2; }#else { real t0, t1, t2, t3, t4, t5, t6, t7; t1 = COS6_2 * in[12]; t2 = COS6_2 * (in[8] + in[16] - in[4]); t3 = in[0] + t1; t4 = in[0] - t1 - t1; t5 = t4 - t2; tmp[4] = t4 + t2 + t2; t0 = cos9[0] * (in[4] + in[8]); t1 = cos9[1] * (in[8] - in[16]); t2 = cos9[2] * (in[4] + in[16]); t6 = t3 - t0 - t2; t0 += t3 + t1; t3 += t2 - t1; t2 = cos18[0] * (in[2] + in[10]); t4 = cos18[1] * (in[10] - in[14]); t7 = COS6_1 * in[6]; t1 = t2 + t4 + t7; tmp[0] = t0 + t1; tmp[8] = t0 - t1; t1 = cos18[2] * (in[2] + in[14]); t2 += t1 - t7; tmp[3] = t3 + t2; t0 = COS6_1 * (in[10] + in[14] - in[2]); tmp[5] = t3 - t2; t4 -= t1 + t7; tmp[1] = t5 - t0; tmp[7] = t5 + t0; tmp[2] = t6 + t4; tmp[6] = t6 - t4; }#endif { real t0, t1, t2, t3, t4, t5, t6, t7; t1 = COS6_2 * in[13]; t2 = COS6_2 * (in[9] + in[17] - in[5]); t3 = in[1] + t1; t4 = in[1] - t1 - t1; t5 = t4 - t2; t0 = cos9[0] * (in[5] + in[9]); t1 = cos9[1] * (in[9] - in[17]); tmp[13] = (t4 + t2 + t2) * tfcos36[17-13]; t2 = cos9[2] * (in[5] + in[17]); t6 = t3 - t0 - t2; t0 += t3 + t1; t3 += t2 - t1; t2 = cos18[0] * (in[3] + in[11]); t4 = cos18[1] * (in[11] - in[15]); t7 = COS6_1 * in[7]; t1 = t2 + t4 + t7; tmp[17] = (t0 + t1) * tfcos36[17-17]; tmp[9] = (t0 - t1) * tfcos36[17-9]; t1 = cos18[2] * (in[3] + in[15]); t2 += t1 - t7; tmp[14] = (t3 + t2) * tfcos36[17-14]; t0 = COS6_1 * (in[11] + in[15] - in[3]); tmp[12] = (t3 - t2) * tfcos36[17-12]; t4 -= t1 + t7; tmp[16] = (t5 - t0) * tfcos36[17-16]; tmp[10] = (t5 + t0) * tfcos36[17-10]; tmp[15] = (t6 + t4) * tfcos36[17-15]; tmp[11] = (t6 - t4) * tfcos36[17-11]; }#define MACRO(v) { \ real tmpval; \ tmpval = tmp[(v)] + tmp[17-(v)]; \ out2[9+(v)] = tmpval * w[27+(v)]; \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -