📄 layer3.c
字号:
real tmpval; \ tmpval = tmp[(v)] + tmp[17-(v)]; \ out2[9+(v)] = REAL_MUL(tmpval, w[27+(v)]); \ out2[8-(v)] = REAL_MUL(tmpval, w[26-(v)]); \ tmpval = tmp[(v)] - tmp[17-(v)]; \ ts[SBLIMIT*(8-(v))] = out1[8-(v)] + REAL_MUL(tmpval, w[8-(v)]); \ ts[SBLIMIT*(9+(v))] = out1[9+(v)] + REAL_MUL(tmpval, w[9+(v)]); }{ register real *out2 = o2; register real *w = wintab; register real *out1 = o1; register real *ts = tsbuf; MACRO(0); MACRO(1); MACRO(2); MACRO(3); MACRO(4); MACRO(5); MACRO(6); MACRO(7); MACRO(8);}#else {#define MACRO0(v) { \ real tmp; \ out2[9+(v)] = REAL_MUL((tmp = sum0 + sum1), w[27+(v)]); \ out2[8-(v)] = REAL_MUL(tmp, w[26-(v)]); } \ sum0 -= sum1; \ ts[SBLIMIT*(8-(v))] = out1[8-(v)] + REAL_MUL(sum0, w[8-(v)]); \ ts[SBLIMIT*(9+(v))] = out1[9+(v)] + REAL_MUL(sum0, w[9+(v)]);#define MACRO1(v) { \ real sum0,sum1; \ sum0 = tmp1a + tmp2a; \ sum1 = REAL_MUL((tmp1b + tmp2b), tfcos36[(v)]); \ MACRO0(v); }#define MACRO2(v) { \ real sum0,sum1; \ sum0 = tmp2a - tmp1a; \ sum1 = REAL_MUL((tmp2b - tmp1b), tfcos36[(v)]); \ MACRO0(v); } register const real *c = COS9; register real *out2 = o2; register real *w = wintab; register real *out1 = o1; register real *ts = tsbuf; real ta33,ta66,tb33,tb66; ta33 = REAL_MUL(in[2*3+0], c[3]); ta66 = REAL_MUL(in[2*6+0], c[6]); tb33 = REAL_MUL(in[2*3+1], c[3]); tb66 = REAL_MUL(in[2*6+1], c[6]); { real tmp1a,tmp2a,tmp1b,tmp2b; 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]); 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]); 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]); 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]); MACRO1(0); MACRO2(8); } { real tmp1a,tmp2a,tmp1b,tmp2b; tmp1a = REAL_MUL(( in[2*1+0] - in[2*5+0] - in[2*7+0] ), c[3]); tmp1b = REAL_MUL(( in[2*1+1] - in[2*5+1] - in[2*7+1] ), c[3]); 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]; 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]; MACRO1(1); MACRO2(7); } { real tmp1a,tmp2a,tmp1b,tmp2b; 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]); 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]); 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]); 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]); MACRO1(2); MACRO2(6); } { real tmp1a,tmp2a,tmp1b,tmp2b; 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]); 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]); 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]); 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]); MACRO1(3); MACRO2(5); } { real sum0,sum1; sum0 = in[2*0+0] - in[2*2+0] + in[2*4+0] - in[2*6+0] + in[2*8+0]; 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]); MACRO0(4); } }#endif }}/* * new DCT12 */static void dct12(real *in,real *rawout1,real *rawout2,register real *wi,register real *ts){#define DCT12_PART1 \ in5 = in[5*3]; \ in5 += (in4 = in[4*3]); \ in4 += (in3 = in[3*3]); \ in3 += (in2 = in[2*3]); \ in2 += (in1 = in[1*3]); \ in1 += (in0 = in[0*3]); \ \ in5 += in3; in3 += in1; \ \ in2 = REAL_MUL(in2, COS6_1); \ in3 = REAL_MUL(in3, COS6_1); \#define DCT12_PART2 \ in0 += REAL_MUL(in4, COS6_2); \ \ in4 = in0 + in2; \ in0 -= in2; \ \ in1 += REAL_MUL(in5, COS6_2); \ \ in5 = REAL_MUL((in1 + in3), tfcos12[0]); \ in1 = REAL_MUL((in1 - in3), tfcos12[2]); \ \ in3 = in4 + in5; \ in4 -= in5; \ \ in2 = in0 + in1; \ in0 -= in1; { real in0,in1,in2,in3,in4,in5; register real *out1 = rawout1; ts[SBLIMIT*0] = out1[0]; ts[SBLIMIT*1] = out1[1]; ts[SBLIMIT*2] = out1[2]; ts[SBLIMIT*3] = out1[3]; ts[SBLIMIT*4] = out1[4]; ts[SBLIMIT*5] = out1[5]; DCT12_PART1 { real tmp0,tmp1 = (in0 - in4); { real tmp2 = REAL_MUL((in1 - in5), tfcos12[1]); tmp0 = tmp1 + tmp2; tmp1 -= tmp2; } ts[(17-1)*SBLIMIT] = out1[17-1] + REAL_MUL(tmp0, wi[11-1]); ts[(12+1)*SBLIMIT] = out1[12+1] + REAL_MUL(tmp0, wi[6+1]); ts[(6 +1)*SBLIMIT] = out1[6 +1] + REAL_MUL(tmp1, wi[1]); ts[(11-1)*SBLIMIT] = out1[11-1] + REAL_MUL(tmp1, wi[5-1]); } DCT12_PART2 ts[(17-0)*SBLIMIT] = out1[17-0] + REAL_MUL(in2, wi[11-0]); ts[(12+0)*SBLIMIT] = out1[12+0] + REAL_MUL(in2, wi[6+0]); ts[(12+2)*SBLIMIT] = out1[12+2] + REAL_MUL(in3, wi[6+2]); ts[(17-2)*SBLIMIT] = out1[17-2] + REAL_MUL(in3, wi[11-2]); ts[(6 +0)*SBLIMIT] = out1[6+0] + REAL_MUL(in0, wi[0]); ts[(11-0)*SBLIMIT] = out1[11-0] + REAL_MUL(in0, wi[5-0]); ts[(6 +2)*SBLIMIT] = out1[6+2] + REAL_MUL(in4, wi[2]); ts[(11-2)*SBLIMIT] = out1[11-2] + REAL_MUL(in4, wi[5-2]); } in++; { real in0,in1,in2,in3,in4,in5; register real *out2 = rawout2; DCT12_PART1 { real tmp0,tmp1 = (in0 - in4); { real tmp2 = REAL_MUL((in1 - in5), tfcos12[1]); tmp0 = tmp1 + tmp2; tmp1 -= tmp2; } out2[5-1] = REAL_MUL(tmp0, wi[11-1]); out2[0+1] = REAL_MUL(tmp0, wi[6+1]); ts[(12+1)*SBLIMIT] += REAL_MUL(tmp1, wi[1]); ts[(17-1)*SBLIMIT] += REAL_MUL(tmp1, wi[5-1]); } DCT12_PART2 out2[5-0] = REAL_MUL(in2, wi[11-0]); out2[0+0] = REAL_MUL(in2, wi[6+0]); out2[0+2] = REAL_MUL(in3, wi[6+2]); out2[5-2] = REAL_MUL(in3, wi[11-2]); ts[(12+0)*SBLIMIT] += REAL_MUL(in0, wi[0]); ts[(17-0)*SBLIMIT] += REAL_MUL(in0, wi[5-0]); ts[(12+2)*SBLIMIT] += REAL_MUL(in4, wi[2]); ts[(17-2)*SBLIMIT] += REAL_MUL(in4, wi[5-2]); } in++; { real in0,in1,in2,in3,in4,in5; register real *out2 = rawout2; out2[12]=out2[13]=out2[14]=out2[15]=out2[16]=out2[17]=0.0; DCT12_PART1 { real tmp0,tmp1 = (in0 - in4); { real tmp2 = REAL_MUL((in1 - in5), tfcos12[1]); tmp0 = tmp1 + tmp2; tmp1 -= tmp2; } out2[11-1] = REAL_MUL(tmp0, wi[11-1]); out2[6 +1] = REAL_MUL(tmp0, wi[6+1]); out2[0+1] += REAL_MUL(tmp1, wi[1]); out2[5-1] += REAL_MUL(tmp1, wi[5-1]); } DCT12_PART2 out2[11-0] = REAL_MUL(in2, wi[11-0]); out2[6 +0] = REAL_MUL(in2, wi[6+0]); out2[6 +2] = REAL_MUL(in3, wi[6+2]); out2[11-2] = REAL_MUL(in3, wi[11-2]); out2[0+0] += REAL_MUL(in0, wi[0]); out2[5-0] += REAL_MUL(in0, wi[5-0]); out2[0+2] += REAL_MUL(in4, wi[2]); out2[5-2] += REAL_MUL(in4, wi[5-2]); }}/* * III_hybrid */static void III_hybrid(real fsIn[SBLIMIT][SSLIMIT], real tsOut[SSLIMIT][SBLIMIT], int ch,struct gr_info_s *gr_info, mpg123_handle *fr){ real (*block)[2][SBLIMIT*SSLIMIT] = fr->hybrid_block; int *blc = fr->hybrid_blc; real *tspnt = (real *) tsOut; real *rawout1,*rawout2; int bt,sb = 0; { int b = blc[ch]; rawout1=block[b][ch]; b=-b+1; rawout2=block[b][ch]; blc[ch] = b; } if(gr_info->mixed_block_flag) { sb = 2; opt_dct36(fr)(fsIn[0],rawout1,rawout2,win[0],tspnt); opt_dct36(fr)(fsIn[1],rawout1+18,rawout2+18,win1[0],tspnt+1); rawout1 += 36; rawout2 += 36; tspnt += 2; } bt = gr_info->block_type; if(bt == 2) { for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) { dct12(fsIn[sb] ,rawout1 ,rawout2 ,win[2] ,tspnt); dct12(fsIn[sb+1],rawout1+18,rawout2+18,win1[2],tspnt+1); } } else { for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) { opt_dct36(fr)(fsIn[sb],rawout1,rawout2,win[bt],tspnt); opt_dct36(fr)(fsIn[sb+1],rawout1+18,rawout2+18,win1[bt],tspnt+1); } } for(;sb<SBLIMIT;sb++,tspnt++) { int i; for(i=0;i<SSLIMIT;i++) { tspnt[i*SBLIMIT] = *rawout1++; *rawout2++ = DOUBLE_TO_REAL(0.0); } }}/* * main layer3 handler */int do_layer3(mpg123_handle *fr){ int gr, ch, ss,clip=0; int scalefacs[2][39]; /* max 39 for short[13][3] mode, mixed: 38, long: 22 */ struct III_sideinfo sideinfo; int stereo = fr->stereo; int single = fr->single; int ms_stereo,i_stereo; int sfreq = fr->sampling_frequency; int stereo1,granules; if(stereo == 1) { /* stream is mono */ stereo1 = 1; single = SINGLE_LEFT; } else if(single != SINGLE_STEREO) /* stream is stereo, but force to mono */ stereo1 = 1; else stereo1 = 2; if(fr->mode == MPG_MD_JOINT_STEREO) { ms_stereo = (fr->mode_ext & 0x2)>>1; i_stereo = fr->mode_ext & 0x1; } else ms_stereo = i_stereo = 0; if(fr->lsf) { granules = 1; } else { granules = 2; } /* quick hack to keep the music playing */ /* after having seen this nasty test file... */ if(III_get_side_info(fr, &sideinfo,stereo,ms_stereo,sfreq,single)) { error("bad frame - unable to get valid sideinfo"); return clip; } set_pointer(fr,sideinfo.main_data_begin); for (gr=0;gr<granules;gr++) { ALIGNED(16) real hybridIn[2][SBLIMIT][SSLIMIT]; ALIGNED(16) real hybridOut[2][SSLIMIT][SBLIMIT]; { struct gr_info_s *gr_info = &(sideinfo.ch[0].gr[gr]); long part2bits; if(fr->lsf) part2bits = III_get_scale_factors_2(fr, scalefacs[0],gr_info,0); else part2bits = III_get_scale_factors_1(fr, scalefacs[0],gr_info,0,gr); if(III_dequantize_sample(fr, hybridIn[0], scalefacs[0],gr_info,sfreq,part2bits)) return clip; } if(stereo == 2) { struct gr_info_s *gr_info = &(sideinfo.ch[1].gr[gr]); long part2bits; if(fr->lsf) part2bits = III_get_scale_factors_2(fr, scalefacs[1],gr_info,i_stereo); else part2bits = III_get_scale_factors_1(fr, scalefacs[1],gr_info,1,gr); if(III_dequantize_sample(fr, hybridIn[1],scalefacs[1],gr_info,sfreq,part2bits)) return clip; if(ms_stereo) { int i; int maxb = sideinfo.ch[0].gr[gr].maxb; if(sideinfo.ch[1].gr[gr].maxb > maxb) maxb = sideinfo.ch[1].gr[gr].maxb; for(i=0;i<SSLIMIT*maxb;i++) { real tmp0 = ((real *)hybridIn[0])[i]; real tmp1 = ((real *)hybridIn[1])[i]; ((real *)hybridIn[0])[i] = tmp0 + tmp1; ((real *)hybridIn[1])[i] = tmp0 - tmp1; } } if(i_stereo) III_i_stereo(hybridIn,scalefacs[1],gr_info,sfreq,ms_stereo,fr->lsf); if(ms_stereo || i_stereo || (single == SINGLE_MIX) ) { if(gr_info->maxb > sideinfo.ch[0].gr[gr].maxb) sideinfo.ch[0].gr[gr].maxb = gr_info->maxb; else gr_info->maxb = sideinfo.ch[0].gr[gr].maxb; } switch(single) { case SINGLE_MIX: { register int i; register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1]; for(i=0;i<SSLIMIT*gr_info->maxb;i++,in0++) *in0 = (*in0 + *in1++); /* *0.5 done by pow-scale */ } break; case SINGLE_RIGHT: { register int i; register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1]; for(i=0;i<SSLIMIT*gr_info->maxb;i++) *in0++ = *in1++; } break; } } for(ch=0;ch<stereo1;ch++) { struct gr_info_s *gr_info = &(sideinfo.ch[ch].gr[gr]); III_antialias(hybridIn[ch],gr_info); III_hybrid(hybridIn[ch], hybridOut[ch], ch,gr_info, fr); }#ifdef OPT_I486 if (fr->synth != opt_synth_1to1(fr) || single != SINGLE_STEREO) {#endif for(ss=0;ss<SSLIMIT;ss++) { if(single != SINGLE_STEREO) { clip += (fr->synth_mono)(hybridOut[0][ss], fr); } else { clip += (fr->synth)(hybridOut[0][ss], 0, fr, 0); clip += (fr->synth)(hybridOut[1][ss], 1, fr, 1); }#ifdef VARMODESUPPORT if (playlimit < 128) { fr->buffer.fill -= playlimit >> 1; playlimit = 0; } else playlimit -= 128;#endif }#ifdef OPT_I486 } else { /* Only stereo, 16 bits benefit from the 486 optimization. */ ss=0; while (ss < SSLIMIT) { int n; n=(fr->buffer.size - fr->buffer.fill) / (2*2*32); if (n > (SSLIMIT-ss)) n=SSLIMIT-ss; synth_1to1_486(hybridOut[0][ss], 0, fr, n); synth_1to1_486(hybridOut[1][ss], 1, fr, n); ss+=n; fr->buffer.fill+=(2*2*32)*n; } }#endif } return clip;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -