📄 g729ev_main_decod.c
字号:
/* 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(WMOPS) test(); test();#endif IF((sub(clas, G729EV_FEC_SIN_ONSET) == 0) && (sub(rate, 14000) >= 0) && (ind_fer[2] > 0)) { if (sub(rate, 16000) < 0) { /* Use reconstruct energy information when not present in bitstream */ L_enr_q = decstat->decStG729.Lenr_old;#if(WMOPS) move16();#endif } IF(sub(decstat->decStG729.bfi_cnt, 1) == 0) { G729EV_FEC_mod_adapt_codebook(decstat->decStG729.old_exc, ind_fer[2], pitch_buf, L_enr_q, BfAq + 3 * G729EV_G729_MP1); } ELSE { G729EV_FEC_mod_adapt_codebook(decstat->decStG729.old_exc, ind_fer[2], pitch_buf, L_enr_q, decstat->mem_Az + 3 * G729EV_G729_MP1); } } G729EV_G729_Copy(decstat->decStG729.mem_syn, mem_syntmp, G729EV_G729_M); decstat->decStG729.lp_gainc = (Word16) 0; decstat->decStG729.lp_gainp = (Word16) 0; decstat->decStG729.i_subfr_cnt = (Word16) 0;#if(WMOPS) move16(); move16(); move16();#endif /************************************************************** * Decoding of lower band : 8k core and 12k enhancement layer * **************************************************************/#if(WMOPS) move16();#endif j = (Word16) 0; FOR(i_frame = 0; i_frame < G729EV_MAIN_L_FRAME2; i_frame += G729EV_G729_L_FRAME) { /* get synthesis of G729/12k decoder (without postfilter) */ G729EV_CELP2S_decoder(&decstat->decStG729, coder_param_ptr, rate, j, &nb_celp_param, &BfAq[j * 2 * G729EV_G729_MP1], &coreExc[i_frame], &extExc[i_frame], pitch_buf, clas, bfi); j = add(j, 1); /* update bit counter */ IF(sub(rate, 12000) >= 0) { nb_bits_used = add(nb_bits_used, 120); } ELSE { nb_bits_used = add(nb_bits_used, 80); } /* update pointer to coder parameters offset */ coder_param_ptr += G729EV_G729_PRM_SIZE_MAX; } /* number of bits lefts for decoding after CELP decoding */ nb_bits_left = sub(nb_bits_left, nb_bits_used); G729EV_G729_syn(coreExc, extExc, decstat->decStG729.old_exc, BfAq, celp_output, decstat->decStG729.mem_syn, decstat->decStG729.rate); /* if clas is not tranmist */ IF(sub(rate, 12000) < 0) { G729EV_FEC_clas_dec(&clas, pitch_buf, decstat->lastgood, celp_output, decstat->synth_buf, &(decstat->lp_ener_FER)); } G729EV_FEC_pit_updt(clas, pitch_buf, decstat->lastgood, &(decstat->decStG729.upd_cnt), &(decstat->decStG729.old_fpitch), decstat->decStG729.fpitch); G729EV_FEC_scale_syn(nb_bits_left, clas, decstat->lastgood, celp_output, pitch_buf, L_enr_q, decstat->prev_bfi, BfAq, &(decstat->old_enrLP), mem_syntmp, coreExc, decstat->decStG729.Lenr_old, decstat->decStG729.old_exc, decstat->decStG729.mem_syn, decstat->decStG729.bfi_cnt); /*************************************************** * Decoding of higher band : 14k enhancement layer * ***************************************************/ IF(sub(rate, 14000) >= 0) { /* decode TDBWE parameters */ G729EV_TDBWE_dequantization(coder_param_ptr, parameters_tdbwe); G729EV_TDBWE_decoder(&decstat->tdbwe, &nb_celp_param, output_hiTdbwe, parameters_tdbwe); /* copy TDBWE parameters for FEC */ G729EV_G729_Copy(parameters_tdbwe, decstat->prev_parameters_tdbwe, G729EV_TDBWE_NB_PARAMETERS); FOR(i = 0; i < G729EV_MAIN_NB_SUBFR; i++) { decstat->prev_nb_celp_param.t0[i] = nb_celp_param.t0[i]; decstat->prev_nb_celp_param.t0_frac[i] = nb_celp_param.t0_frac[i]; decstat->prev_nb_celp_param.power_fix[i] = nb_celp_param.power_fix[i]; decstat->prev_nb_celp_param.power_ltp[i] = nb_celp_param.power_ltp[i];#if(WMOPS) move16(); move16(); move16(); move16();#endif } /* update bits counter and number of bits left */ nb_bits_used = add(nb_bits_used, 40); nb_bits_left = sub(nb_bits_left, 40); /* update pointer to coder parameters offset */ coder_param_ptr += 6; /* 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 { /* if rate < 14000 TDBWE output is forced to 0 */ G729EV_G729_Set_zero(output_hiTdbwe, G729EV_MAIN_L_FRAME2); } /************************************************************* * Decoding of full-band spectrum: 16-32k enhancement layers * *************************************************************/ IF(decstat->low_delay == 0) { /* update maximum number of bits for encoding based on previous layers */ nb_bits_max = sub(nb_bits_max, nb_bits_used); /* decode TDAC module - get norm_MDCT value */ norm_MDCT = *coder_param_ptr;#if(WMOPS) move16();#endif /* compute MDCT of the TDBWE synthesis */ norm_local = G729EV_TDAC_mdct(decstat->mem_mdct_hi, output_hiTdbwe, yt_hi, -15); G729EV_TDAC_mdct(decstat->mem_mdct_hi, output_hiTdbwe, yt_hi, norm_local); /* Update nb_bits (read FEC (5 bits) + norm_shift (4 bits)) */ nb_bits_max = sub(nb_bits_max, 9); IF(sub(rate, 16000) >= 0) { nb_bits_left = sub(nb_bits_left, 9); } ELSE { nb_bits_left = (Word16) 0; norm_MDCT = norm_local;#if(WMOPS) move16(); move16();#endif } /* rescale yt_hi to be norm_shift compliant */ diff_norm = sub(norm_MDCT, norm_local); FOR(i = 0; i < G729EV_MAIN_L_FRAME2; i++) { yt_hi[i] = shl(yt_hi[i], diff_norm);#if(WMOPS) move16();#endif } /* TDAC decoder */ G729EV_TDAC_decoder(&itu_192_bitstream[289], (Word16) nb_bits_left, (Word16) nb_bits_max, yt_hi, yq_lo, yq_hi, norm_MDCT); /* post-process reconstructed higher-band spectrum */ G729EV_TDAC_PostProcess(yq_hi, nb_bits_to_decode); /* inverse MDCT to obtain - reconstructed difference signal in lower band - reconstructed signal in higher band */ G729EV_TDAC_inv_mdct(diff_q, yq_lo, decstat->mem_inv_mdct_lo, norm_MDCT); G729EV_TDAC_inv_mdct(output_hi, yq_hi, decstat->mem_inv_mdct_hi, norm_MDCT); /* compute false alarm zones for pre/post-echo reduction */ G729EV_MAIN_PreechoFalseAlarm(diff_q, decstat->mem_inv_mdct_lo, &decstat->max_prev_lo, &begin_index_low, &end_index_low); G729EV_MAIN_PreechoFalseAlarm(output_hi, decstat->mem_inv_mdct_hi, &decstat->max_prev_hi, &begin_index_high, &end_index_high); /* apply inverse weighting filter to the reconstructed lower-band difference signal */ G729EV_MAIN_inverse_weighting_filter(decstat->mem_Az, decstat->mem_invWz_in, decstat->mem_invwsp, diff_q); /* signal upsampling */ FOR(i = 0; i < G729EV_MAIN_L_FRAME2; i++) { decstat->old_celp_output[i] = shl(decstat->old_celp_output[i], 1);#if(WMOPS) move16();#endif } /* preecho reduction & add 12k output to reconstructed difference signal */ G729EV_MAIN_envAdapt(output_lo, decstat->old_celp_output, diff_q, &decstat->vmlold, output_hi, decstat->sTdbweOld, output_hi, &decstat->vmhold, (Word16) (rate > 14000), begin_index_low, end_index_low, begin_index_high, end_index_high); FOR(j = 0; j < G729EV_MAIN_L_FRAME2; j++) { output_lo[j] = shr(output_lo[j], 1);#if(WMOPS) move16();#endif } /* update output for next frame */ G729EV_G729_Copy(output_hiTdbwe, decstat->sTdbweOld, G729EV_MAIN_L_FRAME2); G729EV_G729_Copy(celp_output, decstat->old_celp_output, G729EV_MAIN_L_FRAME2); } ELSE { G729EV_G729_Copy(celp_output, output_lo, G729EV_MAIN_L_FRAME2); G729EV_G729_Copy(output_hiTdbwe, output_hi, G729EV_MAIN_L_FRAME2); G729EV_G729_Copy(celp_output, decstat->old_celp_output, G729EV_MAIN_L_FRAME2); } /******************************** * Adapt bitrate switching gain * ********************************/ /* count number of frames with same bandwidth */ IF(sub(rate, 12000) <= 0) /* 12 kbit/s */ { nRcv_hi = (Word16) 1; } ELSE { nRcv_hi = (Word16) 0; }#if(WMOPS) move16(); test();#endif IF((nRcv_hi == 0) && (decstat->prev_nRcv_hi == 0)) { decstat->count_rcv = add(decstat->count_rcv, 1); if (sub(decstat->count_rcv, G729EV_MAIN_COUNT_RCV_MAX) > 0) { decstat->count_rcv = G729EV_MAIN_COUNT_RCV_MAX;#if(WMOPS) move16();#endif } } ELSE { IF(nRcv_hi != 0) {#if(WMOPS) test(); test(); test();#endif if ((decstat->first_frame != 0) || (decstat->prev_nRcv_hi != 0) || ((decstat->prev_nRcv_hi == 0) && (sub(decstat->count_rcv, G729EV_MAIN_COUNT_RCV_MAX) < 0))) { decstat->count_rcv = (Word16) 0;#if(WMOPS) move16();#endif } } } decstat->prev_nRcv_hi = nRcv_hi; decstat->first_frame = (Word16) 0;#if(WMOPS) move16(); move16();#endif /******************************* * Postfiltering in lower-band * *******************************/ /* set adaptive gamma parameters of postfilter */ G729EV_MAIN_set_gamma(output_lo, decstat->tab_Th, 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; IF(decstat->low_delay == 0) ptr_Az = decstat->mem_Az; ELSE ptr_Az = nb_celp_param.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) { IF(decstat->low_delay == 0) t0_first = decstat->mem_t0[(j / 2) * 2]; ELSE t0_first = nb_celp_param.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); } IF(decstat->low_delay == 0) { /* update memory of A(z) and t0_first */ G729EV_G729_Copy(nb_celp_param.Az, decstat->mem_Az, 4 * G729EV_G729_MP1); G729EV_G729_Copy(nb_celp_param.t0, decstat->mem_t0, 4); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -