📄 dec_amr.cpp
字号:
{ Dec_lag6 (index, PIT_MIN_MR122, PIT_MAX, pit_flag, &T0, &T0_frac); if ( bfi == 0 && (pit_flag == 0 || sub (index, 61) < 0)) { } else { st->T0_lagBuff = T0; T0 = st->old_T0; T0_frac = 0; } Pred_lt_3or6 (st->exc, T0, T0_frac, L_SUBFR, 0); } *-------------------------------------------------------* * - (MR122 only: Decode pitch gain.) * * - Decode innovative codebook. * * - set pitch sharpening factor * *-------------------------------------------------------* if (sub (mode, MR475) == 0 || sub (mode, MR515) == 0) { // MR475, MR515 index = *parm++; // index of position i = *parm++; // signs decode_2i40_9bits (subfrNr, i, index, code); pit_sharp = shl (st->sharp, 1); } else if (sub (mode, MR59) == 0) { // MR59 index = *parm++; // index of position i = *parm++; // signs decode_2i40_11bits (i, index, code); pit_sharp = shl (st->sharp, 1); } else if (sub (mode, MR67) == 0) { // MR67 index = *parm++; // index of position i = *parm++; // signs decode_3i40_14bits (i, index, code); pit_sharp = shl (st->sharp, 1); } else if (sub (mode, MR795) <= 0) { // MR74, MR795 index = *parm++; // index of position i = *parm++; // signs decode_4i40_17bits (i, index, code); pit_sharp = shl (st->sharp, 1); } else if (sub (mode, MR102) == 0) { // MR102 dec_8i40_31bits (parm, code); parm += 7; pit_sharp = shl (st->sharp, 1); } else { // MR122 index = *parm++; if (bfi != 0) { ec_gain_pitch (st->ec_gain_p_st, st->state, &gain_pit); } else { gain_pit = d_gain_pitch (mode, index); } ec_gain_pitch_update (st->ec_gain_p_st, bfi, st->prev_bf, &gain_pit); dec_10i40_35bits (parm, code); parm += 10; // pit_sharp = gain_pit; // if (pit_sharp > 1.0) pit_sharp = 1.0; pit_sharp = shl (gain_pit, 1); } *-------------------------------------------------------* * - Add the pitch contribution to code[]. * *-------------------------------------------------------* for (i = T0; i < L_SUBFR; i++) { temp = mult (code[i - T0], pit_sharp); code[i] = add (code[i], temp); } *------------------------------------------------------------* * - Decode codebook gain (MR122) or both pitch * * gain and codebook gain (all others) * * - Update pitch sharpening "sharp" with quantized gain_pit * *------------------------------------------------------------* if (sub (mode, MR475) == 0) { // read and decode pitch and code gain if (evenSubfr != 0) { index_mr475 = *parm++; // index of gain(s) } if (bfi == 0) { Dec_gain(st->pred_state, mode, index_mr475, code, evenSubfr, &gain_pit, &gain_code); } else { ec_gain_pitch (st->ec_gain_p_st, st->state, &gain_pit); ec_gain_code (st->ec_gain_c_st, st->pred_state, st->state, &gain_code); } ec_gain_pitch_update (st->ec_gain_p_st, bfi, st->prev_bf, &gain_pit); ec_gain_code_update (st->ec_gain_c_st, bfi, st->prev_bf, &gain_code); pit_sharp = gain_pit; if (sub (pit_sharp, SHARPMAX) > 0) { pit_sharp = SHARPMAX; } } else if ((sub (mode, MR74) <= 0) || (sub (mode, MR102) == 0)) { // read and decode pitch and code gain index = *parm++; // index of gain(s) if (bfi == 0) { Dec_gain(st->pred_state, mode, index, code, evenSubfr, &gain_pit, &gain_code); } else { ec_gain_pitch (st->ec_gain_p_st, st->state, &gain_pit); ec_gain_code (st->ec_gain_c_st, st->pred_state, st->state, &gain_code); } ec_gain_pitch_update (st->ec_gain_p_st, bfi, st->prev_bf, &gain_pit); ec_gain_code_update (st->ec_gain_c_st, bfi, st->prev_bf, &gain_code); pit_sharp = gain_pit; if (sub (pit_sharp, SHARPMAX) > 0) { pit_sharp = SHARPMAX; } if (sub (mode, MR102) == 0) { if (sub (st->old_T0, add(L_SUBFR, 5)) > 0) { pit_sharp = shr(pit_sharp, 2); } } } else { // read and decode pitch gain index = *parm++; // index of gain(s) if (sub (mode, MR795) == 0) { // decode pitch gain if (bfi != 0) { ec_gain_pitch (st->ec_gain_p_st, st->state, &gain_pit); } else { gain_pit = d_gain_pitch (mode, index); } ec_gain_pitch_update (st->ec_gain_p_st, bfi, st->prev_bf, &gain_pit); // read and decode code gain index = *parm++; if (bfi == 0) { d_gain_code (st->pred_state, mode, index, code, &gain_code); } else { ec_gain_code (st->ec_gain_c_st, st->pred_state, st->state, &gain_code); } ec_gain_code_update (st->ec_gain_c_st, bfi, st->prev_bf, &gain_code); pit_sharp = gain_pit; if (sub (pit_sharp, SHARPMAX) > 0) { pit_sharp = SHARPMAX; } } else { // MR122 if (bfi == 0) { d_gain_code (st->pred_state, mode, index, code, &gain_code); } else { ec_gain_code (st->ec_gain_c_st, st->pred_state, st->state, &gain_code); } ec_gain_code_update (st->ec_gain_c_st, bfi, st->prev_bf, &gain_code); pit_sharp = gain_pit; } } // store pitch sharpening for next subframe // (for modes which use the previous pitch gain for // pitch sharpening in the search phase) // do not update sharpening in even subframes for MR475 if (sub(mode, MR475) != 0 || evenSubfr == 0) { st->sharp = gain_pit; if (sub (st->sharp, SHARPMAX) > 0) { st->sharp = SHARPMAX; } } pit_sharp = shl (pit_sharp, 1); if (sub (pit_sharp, 16384) > 0) { for (i = 0; i < L_SUBFR; i++) { temp = mult (st->exc[i], pit_sharp); L_temp = L_mult (temp, gain_pit); if (sub(mode, MR122)==0) { L_temp = L_shr (L_temp, 1); } excp[i] = pv_round (L_temp); } } *-------------------------------------------------------* * - Store list of LTP gains needed in the source * * characteristic detector (SCD) * *-------------------------------------------------------* if ( bfi == 0 ) { for (i = 0; i < 8; i++) { st->ltpGainHistory[i] = st->ltpGainHistory[i+1]; } st->ltpGainHistory[8] = gain_pit; } *-------------------------------------------------------* * - Limit gain_pit if in background noise and BFI * * for MR475, MR515, MR59 * *-------------------------------------------------------* if ( (st->prev_bf != 0 || bfi != 0) && st->inBackgroundNoise != 0 && ((sub(mode, MR475) == 0) || (sub(mode, MR515) == 0) || (sub(mode, MR59) == 0)) ) { if ( sub (gain_pit, 12288) > 0) // if (gain_pit > 0.75) in Q14 gain_pit = add( shr( sub(gain_pit, 12288), 1 ), 12288 ); // gain_pit = (gain_pit-0.75)/2.0 + 0.75; if ( sub (gain_pit, 14745) > 0) // if (gain_pit > 0.90) in Q14 { gain_pit = 14745; } } *-------------------------------------------------------* * Calculate CB mixed gain * *-------------------------------------------------------* Int_lsf(prev_lsf, st->lsfState->past_lsf_q, i_subfr, lsf_i); gain_code_mix = Cb_gain_average( st->Cb_gain_averState, mode, gain_code, lsf_i, st->lsp_avg_st->lsp_meanSave, bfi, st->prev_bf, pdfi, st->prev_pdf, st->inBackgroundNoise, st->voicedHangover); // make sure that MR74, MR795, MR122 have original code_gain if ((sub(mode, MR67) > 0) && (sub(mode, MR102) != 0) ) // MR74, MR795, MR122 { gain_code_mix = gain_code; } *-------------------------------------------------------* * - Find the total excitation. * * - Find synthesis speech corresponding to st->exc[]. * *-------------------------------------------------------* if (sub(mode, MR102) <= 0) // MR475, MR515, MR59, MR67, MR74, MR795, MR102 { pitch_fac = gain_pit; tmp_shift = 1; } else // MR122 { pitch_fac = shr (gain_pit, 1); tmp_shift = 2; } // copy unscaled LTP excitation to exc_enhanced (used in phase * dispersion below) and compute total excitation for LTP feedback for (i = 0; i < L_SUBFR; i++) { exc_enhanced[i] = st->exc[i]; // st->exc[i] = gain_pit*st->exc[i] + gain_code*code[i]; L_temp = L_mult (st->exc[i], pitch_fac); // 12.2: Q0 * Q13 // 7.4: Q0 * Q14 L_temp = L_mac (L_temp, code[i], gain_code); // 12.2: Q12 * Q1 // 7.4: Q13 * Q1 L_temp = L_shl (L_temp, tmp_shift); // Q16 st->exc[i] = pv_round (L_temp); } *-------------------------------------------------------* * - Adaptive phase dispersion * *-------------------------------------------------------* ph_disp_release(st->ph_disp_st); // free phase dispersion adaption if ( ((sub(mode, MR475) == 0) || (sub(mode, MR515) == 0) || (sub(mode, MR59) == 0)) && sub(st->voicedHangover, 3) > 0 && st->inBackgroundNoise != 0 && bfi != 0 ) { ph_disp_lock(st->ph_disp_st); // Always Use full Phase Disp. } // if error in bg noise // apply phase dispersion to innovation (if enabled) and compute total excitation for synthesis part ph_disp(st->ph_disp_st, mode, exc_enhanced, gain_code_mix, gain_pit, code, pitch_fac, tmp_shift); *-------------------------------------------------------* * - The Excitation control module are active during BFI.* * - Conceal drops in signal energy if in bg noise. * *-------------------------------------------------------* L_temp = 0; for (i = 0; i < L_SUBFR; i++) { L_temp = L_mac (L_temp, exc_enhanced[i], exc_enhanced[i] ); } L_temp = L_shr (L_temp, 1); // excEnergy = sqrt(L_temp) in Q0 L_temp = sqrt_l_exp(L_temp, &temp); // function result L_temp = L_shr(L_temp, add( shr(temp, 1), 15)); L_temp = L_shr(L_temp, 2); // To cope with 16-bit and excEnergy = extract_l(L_temp); // scaling in ex_ctrl() if ( ((sub (mode, MR475) == 0) || (sub (mode, MR515) == 0) || (sub (mode, MR59) == 0)) && sub(st->voicedHangover, 5) > 0 && st->inBackgroundNoise != 0 && sub(st->state, 4) < 0 && ( (pdfi != 0 && st->prev_pdf != 0) || bfi != 0 || st->prev_bf != 0) ) { carefulFlag = 0; if ( pdfi != 0 && bfi == 0 ) { carefulFlag = 1; } Ex_ctrl(exc_enhanced, excEnergy, st->excEnergyHist, st->voicedHangover, st->prev_bf, carefulFlag); } if ( st->inBackgroundNoise != 0 && ( bfi != 0 || st->prev_bf != 0 ) && sub(st->state, 4) < 0 ) { ; // do nothing! } else { // Update energy history for all modes for (i = 0; i < 8; i++) { st->excEnergyHist[i] = st->excEnergyHist[i+1]; } st->excEnergyHist[8] = excEnergy; } *-------------------------------------------------------* * Excitation control module end. * *-------------------------------------------------------* if (sub (pit_sharp, 16384) > 0) { for (i = 0; i < L_SUBFR; i++) { excp[i] = add (excp[i], exc_enhanced[i]); } agc2 (exc_enhanced, excp, L_SUBFR); Overflow = 0; Syn_filt (Az, excp, &synth[i_subfr], L_SUBFR, st->mem_syn, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -