📄 g729ev_main_decod.c
字号:
/************************** * Postprocess lower band * **************************/ /* G729 postprocessing */ G729EV_G729_Copy(output_lo, pst_in, G729EV_MAIN_L_FRAME2); G729EV_MAIN_iir2(&decstat->mem_postpro, output_lo, G729EV_MAIN_L_FRAME2, G729EV_MAIN_b100, G729EV_MAIN_a100, 0); /* cross-fade output_lo and pst_out if bit rate switching */ IF(sub(rate, 12000) <= 0) /* 12 kbit/s */ { /* narrowband output (8, 12k modes) */ /* cross-fade two narrowband outputs (without or with postprocessing) if previous decoded frame was not postprocessed */ IF(decstat->mem_postflag == 0) { tmp16 = (Word16) 102;#if(WMOPS) move16();#endif FOR(i = 0; i < G729EV_MAIN_L_FRAME2; i += 1) { /* output_lo[i] = (REAL)( i/(len-1.0)*output_lo[i]+ (1-(REAL)i/(len-1.0))*pst_in[i] ); */ /* output_lo and pst_in both in Q14 */ Ltmp = L_mult(tmp16, output_lo[i]); Ltmp = L_mac(Ltmp, pst_in[i], sub(16384, tmp16)); output_lo[i] = round(L_shl(Ltmp, 2));#if(WMOPS) move16();#endif tmp16 = add(tmp16, 102); } } ELSE { /* put output_lo in Q15 */ FOR(i = 0; i < G729EV_MAIN_L_FRAME2; i++) { output_lo[i] = shl(output_lo[i], 1);#if(WMOPS) move16();#endif } } /* declare this frame as postprocessed */ decstat->mem_postflag = (Word16) 1;#if(WMOPS) move16();#endif } ELSE { /* wideband output (modes >= 14k) */ /* cross-fade two narrowband outputs (without or with postprocessing) if previous decoded frame was postprocessed otherwise copy non postprocessed output */ IF(decstat->mem_postflag == 1) { tmp16 = (Word16) 102;#if(WMOPS) move16();#endif FOR(i = 0; i < G729EV_MAIN_L_FRAME2; i += 1) { /*output_lo[i] = (REAL)( i/(len-1.0)*pst_in[i]+ (1-(REAL)i/(len-1.0))*output_lo[i] ); */ Ltmp = L_mult(tmp16, pst_in[i]); Ltmp = L_mac(Ltmp, output_lo[i], sub(16384, tmp16)); output_lo[i] = round(L_shl(Ltmp, 2));#if(WMOPS) move16();#endif tmp16 = add(tmp16, 102); } } ELSE { /* put output_lo in Q15 */ FOR(i = 0; i < G729EV_MAIN_L_FRAME2; i++) { output_lo[i] = shl(pst_in[i], 1);#if(WMOPS) move16();#endif } } decstat->mem_postflag = (Word16) 0;#if(WMOPS) move16();#endif } /***************************************************************** * Fold higher band and combine bands by QMF synthesis filterbank * ******************************************************************/ IF(decstat->f8 == 0) { /* test if 8kHz sampled output */ /* mirror signal prior to filterbank synthesis */ G729EV_MAIN_QMF_mirror(output_hi, G729EV_MAIN_L_FRAME2); /* synthesis filterbank */ G729EV_MAIN_QMF_syn(&decstat->qmf_syn, output_lo, output_hi, tabout, G729EV_MAIN_L_FRAME2, G729EV_MAIN_switching_gain[decstat->count_rcv]); } ELSE { G729EV_G729_Copy(output_lo, tabout, G729EV_MAIN_L_FRAME2); } /******************* * Update memories * *******************/ decstat->plast_good = decstat->lastgood; decstat->lastgood = clas; decstat->decStG729.bfi_cnt = (Word16) 0; decstat->prev_rate = rate;#if(WMOPS) move16(); move16(); move16(); move16();#endif } ELSE { /************************************************ FEC (bfi=1) ***********************************/ /*********************** * Decode 8-12k layers * ***********************/#if(WMOPS) test();#endif IF((decstat->decStG729.bfi_cnt > 0) || (decstat->low_delay > 0)) { /* FEC decoder */ G729EV_FEC_dec_bf(parm_FEC, decstat->old_celp_output, BfAq, bfi, &(decstat->lastgood), pitch_buf, decstat->old_enrLP, decstat->decStG729.old_exc, &(decstat->decStG729), clas, ind_fer[2]); /* Update to be done before decoding a good frame */ FerPitch = shr(add(pitch_buf[0], G729EV_FEC_QPIT2), G729EV_FEC_SQPIT); if (sub(FerPitch, G729EV_G729_PIT_MIN) < 0) { FerPitch = G729EV_G729_PIT_MIN;#if(WMOPS) move16();#endif } if (sub(FerPitch, G729EV_G729_PIT_MAX) > 0) { FerPitch = G729EV_G729_PIT_MAX;#if(WMOPS) move16();#endif } /* taming */ G729EV_G729_UpdateMemTam(&decstat->decStG729, decstat->decStG729.lp_gainp, FerPitch); G729EV_G729_UpdateMemTam(&decstat->decStG729, decstat->decStG729.lp_gainp, FerPitch); /* update memory of A(z) and t0_first */ G729EV_G729_Copy(BfAq, decstat->mem_Az, 4 * G729EV_G729_MP1); FOR(i = 0; i < 4; i++) { decstat->mem_t0[i] = shr(add(pitch_buf[i], G729EV_FEC_QPIT2), G729EV_FEC_SQPIT);#if(WMOPS) move16();#endif } } IF(decstat->low_delay == 0) { ind = sub(G729EV_TDAC_L_WIN2, 1); FOR(i = 0; i < G729EV_TDAC_L_WIN2; i++) { output_lo[i] = mac_r(L_mult(decstat->old_celp_output[i], 32767), decstat->mem_inv_mdct_lo[i], G729EV_TDAC_h[ind]); ind = sub(ind, 1); decstat->mem_inv_mdct_lo[i] = (Word16) 0;#if(WMOPS) move16(); move16();#endif } } ELSE { G729EV_G729_Copy(decstat->old_celp_output, output_lo, G729EV_MAIN_L_FRAME2); } /************************************ * Decode 14-32k enhancement layers * ************************************/ /* TDBWE decoder in FEC */ IF(sub(decstat->prev_rate, 14000) >= 0) /* 14 kbit/s */ { IF(sub(decstat->decStG729.bfi_cnt, 2) > 0) { FOR(i = 0; i < G729EV_TDBWE_NB_SUBFRAMES; i++) { tmp16 = sub(decstat->prev_parameters_tdbwe[i], 1024); /* -3 dB */ IF( sub(tmp16,(Word16)-1700)<0 ) { tmp16 = (Word16) -1700; } decstat->prev_parameters_tdbwe[i] = tmp16; } FOR(i = 0; i < G729EV_TDBWE_NB_SUBBANDS; i++) { tmp16 = sub(decstat->prev_parameters_tdbwe[i+G729EV_TDBWE_PAROFS_FREQ_ENVELOPE], 1024); /* -3 dB */ IF( sub(tmp16,(Word16)-11264)<0 ) { tmp16 = (Word16) -11264; } decstat->prev_parameters_tdbwe[i+G729EV_TDBWE_PAROFS_FREQ_ENVELOPE] = tmp16; } } G729EV_TDBWE_decoder(&decstat->tdbwe, &decstat->prev_nb_celp_param, output_hiTdbwe, decstat->prev_parameters_tdbwe); /* postprocessing of higher band (3 kHz low-pass filter) */ IF(decstat->low_delay > 0) { G729EV_MAIN_lp3k(&decstat->mem_lp3k, output_hiTdbwe, G729EV_MAIN_L_FRAME2); G729EV_G729_Set_zero(output_hiTdbwe, G729EV_MAIN_L_FRAME2); } } ELSE { G729EV_G729_Set_zero(output_hiTdbwe, G729EV_MAIN_L_FRAME2); } /* TDAC decoder in FEC */ IF(decstat->low_delay == 0) { /* set 3000-4000 Hz band of TDBWE synthesis to zero */ norm_local = G729EV_TDAC_mdct(decstat->mem_mdct_hi, output_hiTdbwe, yq_hi, -15); G729EV_TDAC_mdct(decstat->mem_mdct_hi, output_hiTdbwe, yq_hi, norm_local); G729EV_G729_Set_zero(&yq_hi[G729EV_MAIN_L_FRAME2 - G729EV_G729_L_SUBFR], G729EV_G729_L_SUBFR); /* inverse MDCT to obtain reconstructed signal in higher band */ G729EV_TDAC_inv_mdct(output_hi, yq_hi, decstat->mem_inv_mdct_hi, norm_local); } ELSE { G729EV_G729_Copy(output_hiTdbwe, output_hi, G729EV_MAIN_L_FRAME2); } /************************* * Postfilter lower band * *************************/ /* set adaptive gamma paramaters of postfilter */ G729EV_MAIN_set_gamma(output_lo, decstat->tab_Th, decstat->prev_rate, &ga1_post, &ga2_post); /* set post-filter input */ pf_in = &pf_in_buffer[G729EV_G729_M_LPC];#if(WMOPS) move16();#endif G729EV_G729_Copy(decstat->mem_pf_in, &pf_in[-G729EV_G729_M_LPC], G729EV_G729_M_LPC); G729EV_G729_Copy(output_lo, pf_in, G729EV_MAIN_L_FRAME2); G729EV_G729_Copy(&output_lo[(G729EV_MAIN_L_FRAME2) - G729EV_G729_M_LPC], decstat->mem_pf_in, G729EV_G729_M_LPC); /* postfilter */ pfstat = &decstat->mem_pf; ptr_Az = decstat->mem_Az;#if(WMOPS) move16(); move16();#endif j = (Word16) 0;#if(WMOPS) move16();#endif FOR(i = 0; i < (G729EV_MAIN_L_FRAME2); i += G729EV_G729_L_SUBFR) { t0_first = decstat->mem_t0[(j / 2) * 2];#if(WMOPS) move16();#endif G729EV_CELP2S_Post(pfstat, t0_first, &pf_in[i], ptr_Az, &output_lo[i], ga1_post, ga2_post, G729EV_MAIN_switching_gain[decstat->count_rcv], decstat->decStG729.ftyp[(int) (j / 2)]); ptr_Az += G729EV_G729_MP1; j = add(j, 1); } /************************** * Postprocess lower band * **************************/ /* G729 postprocessing */ G729EV_G729_Copy(output_lo, pst_in, G729EV_MAIN_L_FRAME2); G729EV_MAIN_iir2(&decstat->mem_postpro, output_lo, G729EV_MAIN_L_FRAME2, G729EV_MAIN_b100, G729EV_MAIN_a100, 1); IF(decstat->mem_postflag == 0) { /* wideband bit rate -> leave lower-band unprocessed */ FOR(i = 0; i < G729EV_MAIN_L_FRAME2; i++) { output_lo[i] = shl(pst_in[i], 1);#if(WMOPS) move16();#endif } } /****************************************************************** * Fold higher band and combine bands by QMF synthesis filterbank * ******************************************************************/ IF(decstat->f8 == 0) { /* test if 8kHz sampled output */ /* mirror signal prior to filterbank synthesis */ G729EV_MAIN_QMF_mirror(output_hi, G729EV_MAIN_L_FRAME2); /* synthesis filterbank */ G729EV_MAIN_QMF_syn(&decstat->qmf_syn, output_lo, output_hi, tabout, G729EV_MAIN_L_FRAME2, G729EV_MAIN_switching_gain[decstat->count_rcv]); } ELSE { G729EV_G729_Copy(output_lo, tabout, G729EV_MAIN_L_FRAME2); } /******************* * Update memories * *******************/ /* Update to be done before decoding a good frame */ decstat->decStG729.bfi_cnt = add(decstat->decStG729.bfi_cnt, 1); /* set buffer for W(z) */ G729EV_G729_Set_zero(decstat->mem_invWz_in, G729EV_G729_M); G729EV_G729_Set_zero(decstat->mem_invwsp, G729EV_G729_M); } decstat->prev_bfi = bfi;#if(WMOPS) move16();#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -