📄 cod_amr.c
字号:
Word16 vad_flag; /* VAD decision flag */ Word16 compute_sid_flag; /* SID analysis flag */ Copy(new_speech, st->new_speech, L_FRAME); *usedMode = mode; move16 (); /* DTX processing */ if (st->dtx) { /* no test() call since this if is only in simulation env */ /* Find VAD decision */#ifdef VAD2 vad_flag = vad2 (st->new_speech, st->vadSt); vad_flag = vad2 (st->new_speech+80, st->vadSt) || vad_flag; logic16();#else vad_flag = vad1(st->vadSt, st->new_speech); #endif fwc (); /* function worst case */ /* NB! usedMode may change here */ compute_sid_flag = tx_dtx_handler(st->dtx_encSt, vad_flag, usedMode); } else { compute_sid_flag = 0; move16 (); } /*------------------------------------------------------------------------* * - Perform LPC analysis: * * * autocorrelation + lag windowing * * * Levinson-durbin algorithm to find a[] * * * convert a[] to lsp[] * * * quantize and code the LSPs * * * find the interpolated LSPs and convert to a[] for all * * subframes (both quantized and unquantized) * *------------------------------------------------------------------------*/ /* LP analysis */ lpc(st->lpcSt, mode, st->p_window, st->p_window_12k2, A_t); fwc (); /* function worst case */ /* From A(z) to lsp. LSP quantization and interpolation */ lsp(st->lspSt, mode, *usedMode, A_t, Aq_t, lsp_new, &ana); fwc (); /* function worst case */ /* Buffer lsp's and energy */ dtx_buffer(st->dtx_encSt, lsp_new, st->new_speech); /* Check if in DTX mode */ test(); if (sub(*usedMode, MRDTX) == 0) { dtx_enc(st->dtx_encSt, compute_sid_flag, st->lspSt->qSt, st->gainQuantSt->gc_predSt, &ana); Set_zero(st->old_exc, PIT_MAX + L_INTERPOL); Set_zero(st->mem_w0, M); Set_zero(st->mem_err, M); Set_zero(st->zero, L_SUBFR); Set_zero(st->hvec, L_SUBFR); /* set to zero "h1[-L_SUBFR..-1]" */ /* Reset lsp states */ lsp_reset(st->lspSt); Copy(lsp_new, st->lspSt->lsp_old, M); Copy(lsp_new, st->lspSt->lsp_old_q, M); /* Reset clLtp states */ cl_ltp_reset(st->clLtpSt); st->sharp = SHARPMIN; move16 (); } else { /* check resonance in the filter */ lsp_flag = check_lsp(st->tonStabSt, st->lspSt->lsp_old); move16 (); } /*----------------------------------------------------------------------* * - Find the weighted input speech w_sp[] for the whole speech frame * * - Find the open-loop pitch delay for first 2 subframes * * - Set the range for searching closed-loop pitch in 1st subframe * * - Find the open-loop pitch delay for last 2 subframes * *----------------------------------------------------------------------*/#ifdef VAD2 if (st->dtx) { /* no test() call since this if is only in simulation env */ st->vadSt->L_Rmax = 0; move32 (); st->vadSt->L_R0 = 0; move32 (); }#endif for(subfrNr = 0, i_subfr = 0; subfrNr < L_FRAME/L_FRAME_BY2; subfrNr++, i_subfr += L_FRAME_BY2) { /* Pre-processing on 80 samples */ pre_big(mode, gamma1, gamma1_12k2, gamma2, A_t, i_subfr, st->speech, st->mem_w, st->wsp); test (); test (); if ((sub(mode, MR475) != 0) && (sub(mode, MR515) != 0)) { /* Find open loop pitch lag for two subframes */ ol_ltp(st->pitchOLWghtSt, st->vadSt, mode, &st->wsp[i_subfr], &T_op[subfrNr], st->old_lags, st->ol_gain_flg, subfrNr, st->dtx); } } fwc (); /* function worst case */ test (); test(); if ((sub(mode, MR475) == 0) || (sub(mode, MR515) == 0)) { /* Find open loop pitch lag for ONE FRAME ONLY */ /* search on 160 samples */ ol_ltp(st->pitchOLWghtSt, st->vadSt, mode, &st->wsp[0], &T_op[0], st->old_lags, st->ol_gain_flg, 1, st->dtx); T_op[1] = T_op[0]; move16 (); } fwc (); /* function worst case */ #ifdef VAD2 if (st->dtx) { /* no test() call since this if is only in simulation env */ LTP_flag_update(st->vadSt, mode); }#endif#ifndef VAD2 /* run VAD pitch detection */ if (st->dtx) { /* no test() call since this if is only in simulation env */ vad_pitch_detection(st->vadSt, T_op); } #endif fwc (); /* function worst case */ if (sub(*usedMode, MRDTX) == 0) { goto the_end; } /*------------------------------------------------------------------------* * Loop for every subframe in the analysis frame * *------------------------------------------------------------------------* * To find the pitch and innovation parameters. The subframe size is * * L_SUBFR and the loop is repeated L_FRAME/L_SUBFR times. * * - find the weighted LPC coefficients * * - find the LPC residual signal res[] * * - compute the target signal for pitch search * * - compute impulse response of weighted synthesis filter (h1[]) * * - find the closed-loop pitch parameters * * - encode the pitch dealy * * - update the impulse response h1[] by including fixed-gain pitch * * - find target vector for codebook search * * - codebook search * * - encode codebook address * * - VQ of pitch and codebook gains * * - find synthesis speech * * - update states of weighting filter * *------------------------------------------------------------------------*/ A = A_t; /* pointer to interpolated LPC parameters */ Aq = Aq_t; /* pointer to interpolated quantized LPC parameters */ evenSubfr = 0; move16 (); subfrNr = -1; move16 (); for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR) { subfrNr = add(subfrNr, 1); evenSubfr = sub(1, evenSubfr); /* Save states for the MR475 mode */ test(); test(); if ((evenSubfr != 0) && (sub(*usedMode, MR475) == 0)) { Copy(st->mem_syn, mem_syn_save, M); Copy(st->mem_w0, mem_w0_save, M); Copy(st->mem_err, mem_err_save, M); sharp_save = st->sharp; } /*-----------------------------------------------------------------* * - Preprocessing of subframe * *-----------------------------------------------------------------*/ test(); if (sub(*usedMode, MR475) != 0) { subframePreProc(*usedMode, gamma1, gamma1_12k2, gamma2, A, Aq, &st->speech[i_subfr], st->mem_err, st->mem_w0, st->zero, st->ai_zero, &st->exc[i_subfr], st->h1, xn, res, st->error); } else { /* MR475 */ subframePreProc(*usedMode, gamma1, gamma1_12k2, gamma2, A, Aq, &st->speech[i_subfr], st->mem_err, mem_w0_save, st->zero, st->ai_zero, &st->exc[i_subfr], st->h1, xn, res, st->error); /* save impulse response (modified in cbsearch) */ test (); if (evenSubfr != 0) { Copy (st->h1, h1_sf0, L_SUBFR); } } /* copy the LP residual (res2 is modified in the CL LTP search) */ Copy (res, res2, L_SUBFR); fwc (); /* function worst case */ /*-----------------------------------------------------------------* * - Closed-loop LTP search * *-----------------------------------------------------------------*/ cl_ltp(st->clLtpSt, st->tonStabSt, *usedMode, i_subfr, T_op, st->h1, &st->exc[i_subfr], res2, xn, lsp_flag, xn2, y1, &T0, &T0_frac, &gain_pit, gCoeff, &ana, &gp_limit); /* update LTP lag history */ move16 (); test(); test (); if ((subfrNr == 0) && (st->ol_gain_flg[0] > 0)) { st->old_lags[1] = T0; move16 (); } move16 (); test(); test (); if ((sub(subfrNr, 3) == 0) && (st->ol_gain_flg[1] > 0)) { st->old_lags[0] = T0; move16 (); } fwc (); /* function worst case */ /*-----------------------------------------------------------------* * - Inovative codebook search (find index and gain) * *-----------------------------------------------------------------*/ cbsearch(xn2, st->h1, T0, st->sharp, gain_pit, res2, code, y2, &ana, *usedMode, subfrNr); fwc (); /* function worst case */ /*------------------------------------------------------* * - Quantization of gains. * *------------------------------------------------------*/ gainQuant(st->gainQuantSt, *usedMode, res, &st->exc[i_subfr], code, xn, xn2, y1, y2, gCoeff, evenSubfr, gp_limit, &gain_pit_sf0, &gain_code_sf0, &gain_pit, &gain_code, &ana); fwc (); /* function worst case */ /* update gain history */ update_gp_clipping(st->tonStabSt, gain_pit); test(); if (sub(*usedMode, MR475) != 0) { /* Subframe Post Porcessing */ subframePostProc(st->speech, *usedMode, i_subfr, gain_pit, gain_code, Aq, synth, xn, code, y1, y2, st->mem_syn, st->mem_err, st->mem_w0, st->exc, &st->sharp); } else { test(); if (evenSubfr != 0) { i_subfr_sf0 = i_subfr; move16 (); Copy(xn, xn_sf0, L_SUBFR); Copy(y2, y2_sf0, L_SUBFR); Copy(code, code_sf0, L_SUBFR); T0_sf0 = T0; move16 (); T0_frac_sf0 = T0_frac; move16 (); /* Subframe Post Porcessing */ subframePostProc(st->speech, *usedMode, i_subfr, gain_pit, gain_code, Aq, synth, xn, code, y1, y2, mem_syn_save, st->mem_err, mem_w0_save, st->exc, &st->sharp); st->sharp = sharp_save; move16(); } else { /* update both subframes for the MR475 */ /* Restore states for the MR475 mode */ Copy(mem_err_save, st->mem_err, M); /* re-build excitation for sf 0 */ Pred_lt_3or6(&st->exc[i_subfr_sf0], T0_sf0, T0_frac_sf0, L_SUBFR, 1); Convolve(&st->exc[i_subfr_sf0], h1_sf0, y1, L_SUBFR); Aq -= MP1; subframePostProc(st->speech, *usedMode, i_subfr_sf0, gain_pit_sf0, gain_code_sf0, Aq, synth, xn_sf0, code_sf0, y1, y2_sf0, st->mem_syn, st->mem_err, st->mem_w0, st->exc, &sharp_save); /* overwrites sharp_save */ Aq += MP1; /* re-run pre-processing to get xn right (needed by postproc) */ /* (this also reconstructs the unsharpened h1 for sf 1) */ subframePreProc(*usedMode, gamma1, gamma1_12k2, gamma2, A, Aq, &st->speech[i_subfr], st->mem_err, st->mem_w0, st->zero, st->ai_zero, &st->exc[i_subfr], st->h1, xn, res, st->error); /* re-build excitation sf 1 (changed if lag < L_SUBFR) */ Pred_lt_3or6(&st->exc[i_subfr], T0, T0_frac, L_SUBFR, 1); Convolve(&st->exc[i_subfr], st->h1, y1, L_SUBFR); subframePostProc(st->speech, *usedMode, i_subfr, gain_pit, gain_code, Aq, synth, xn, code, y1, y2, st->mem_syn, st->mem_err, st->mem_w0, st->exc, &st->sharp); } } fwc (); /* function worst case */ A += MP1; /* interpolated LPC parameters for next subframe */ Aq += MP1; } Copy(&st->old_exc[L_FRAME], &st->old_exc[0], PIT_MAX + L_INTERPOL); the_end: /*--------------------------------------------------* * Update signal for next frame. * *--------------------------------------------------*/ Copy(&st->old_wsp[L_FRAME], &st->old_wsp[0], PIT_MAX); Copy(&st->old_speech[L_FRAME], &st->old_speech[0], L_TOTAL - L_FRAME); fwc (); /* function worst case */ return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -