diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index b378eabad1f8111a2abe65ff33a056cb9b3e7950..fff73a248cae6a23d5095adc19466514cf07fbb8 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -1228,16 +1228,7 @@ ivas_error pre_proc_front_ivas_fx( /*------------------------------------------------------------------* * Update estimated noise energy and voicing cut-off frequency *-----------------------------------------------------------------*/ - - Word16 scale = s_min( Q31, s_min( add( q_tmpN, L_norm_arr( tmpN_fx, NB_BANDS ) ), add( st->hNoiseEst->q_bckr, L_norm_arr( st->hNoiseEst->bckr_fx, NB_BANDS ) ) ) ); - scale = sub( scale, 1 ); // guard bits - scale_sig32( st->hNoiseEst->bckr_fx, NB_BANDS, sub( scale, st->hNoiseEst->q_bckr ) ); - scale_sig32( tmpN_fx, NB_BANDS, sub( scale, q_tmpN ) ); - st->hNoiseEst->q_bckr = q_tmpN = scale; - move16(); - move16(); - - scale = s_min( Q31, add( st->hNoiseEst->ave_enr_q, s_min( L_norm_arr( st->hNoiseEst->ave_enr_fx, NB_BANDS ), L_norm_arr( st->hNoiseEst->ave_enr2_fx, NB_BANDS ) ) ) ); + Word16 scale = s_min( Q31, add( st->hNoiseEst->ave_enr_q, s_min( L_norm_arr( st->hNoiseEst->ave_enr_fx, NB_BANDS ), L_norm_arr( st->hNoiseEst->ave_enr2_fx, NB_BANDS ) ) ) ); scale = s_min( scale, add( q_tmpE, L_norm_arr( tmpE_fx, NB_BANDS ) ) ); scale = sub( scale, 1 ); // guard bits scale_sig32( tmpE_fx, NB_BANDS, sub( scale, q_tmpE ) ); @@ -1256,7 +1247,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); move16(); - noise_est_ivas_fx( st, old_pitch1, tmpN_fx, epsP_fx, extract_h( Etot_fx ), *relE_fx, corr_shift_fx, tmpE_fx, q_tmpE, fr_bands_fx, fr_bands_fx_q, cor_map_sum_fx, + noise_est_ivas_fx( st, old_pitch1, tmpN_fx, q_tmpN, epsP_fx, extract_h( Etot_fx ), *relE_fx, corr_shift_fx, tmpE_fx, q_tmpE, fr_bands_fx, fr_bands_fx_q, cor_map_sum_fx, &ncharX_fx, &sp_div_fx, &q_sp_div, &non_staX_fx, loc_harm, lf_E_fx, q_lf_E_fx, &st->hNoiseEst->harm_cor_cnt, extract_h( st->hNoiseEst->Etot_l_lp_32fx ), st->hNoiseEst->Etot_v_h2_32fx, &st->hNoiseEst->bg_cnt, st->lgBin_E_fx, &dummy_fx, S_map_fx, hStereoClassif, NULL, st->ini_frame ); @@ -1265,14 +1256,6 @@ ivas_error pre_proc_front_ivas_fx( { FOR( Word16 j = 0; j < 2; j++ ) { - scale = s_min( add( q_tmpN_LR[j], L_norm_arr( tmpN_LR_fx[j], NB_BANDS ) ), add( hCPE->hFrontVad[j]->hNoiseEst->q_bckr, L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, NB_BANDS ) ) ); - scale = sub( s_min( Q31, scale ), 1 ); - scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, NB_BANDS, sub( scale, hCPE->hFrontVad[j]->hNoiseEst->q_bckr ) ); - scale_sig32( tmpN_LR_fx[j], NB_BANDS, sub( scale, q_tmpN_LR[j] ) ); - hCPE->hFrontVad[j]->hNoiseEst->q_bckr = q_tmpN_LR[j] = scale; - move16(); - move16(); - scale = add( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q, s_min( L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_fx, NB_BANDS ), L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->ave_enr2_fx, NB_BANDS ) ) ); scale = s_min( scale, add( q_tmpE_LR[j], L_norm_arr( tmpE_LR_fx[j], NB_BANDS ) ) ); scale = sub( s_min( Q31, scale ), 1 ); @@ -1297,14 +1280,14 @@ ivas_error pre_proc_front_ivas_fx( move16(); /* Run noise_est for Left and Right channel */ - noise_est_ivas_fx( st, old_pitch1, tmpN_LR_fx[0], epsP_fx, Etot_LR_fx[0], sub( Etot_LR_fx[0], hCPE->hFrontVad[0]->lp_speech_fx ), corr_shiftL_fx, + noise_est_ivas_fx( st, old_pitch1, tmpN_LR_fx[0], q_tmpN_LR[0], epsP_fx, Etot_LR_fx[0], sub( Etot_LR_fx[0], hCPE->hFrontVad[0]->lp_speech_fx ), corr_shiftL_fx, tmpE_LR_fx[0], q_tmpE_LR[0], fr_bands_LR_fx[0], fr_bands_LR_fx_q[0], &cor_map_sum_LR_fx[0], &ncharX_LR_fx, &sp_div_LR_fx, &q_sp_div_LR, &non_staX_LR_fx, loc_harmLR_fx, lf_E_LR_fx[0], lf_E_LR_fx_q, &hCPE->hFrontVad[0]->hNoiseEst->harm_cor_cnt, extract_h( hCPE->hFrontVad[0]->hNoiseEst->Etot_l_lp_32fx ), hCPE->hFrontVad[0]->hNoiseEst->Etot_v_h2_32fx, &hCPE->hFrontVad[0]->hNoiseEst->bg_cnt, st->lgBin_E_fx, &dummy_fx, S_map_LR_fx, NULL, hCPE->hFrontVad[0], hCPE->hFrontVad[0]->ini_frame ); /* Note: the index [0] in the last argument is intended, the ini_frame counter is only maintained in the zero-th channel's VAD handle */ - noise_est_ivas_fx( st, old_pitch1, tmpN_LR_fx[1], epsP_fx, Etot_LR_fx[1], sub( Etot_LR_fx[1], hCPE->hFrontVad[1]->lp_speech_fx ), corr_shiftR_fx, + noise_est_ivas_fx( st, old_pitch1, tmpN_LR_fx[1], q_tmpN_LR[1], epsP_fx, Etot_LR_fx[1], sub( Etot_LR_fx[1], hCPE->hFrontVad[1]->lp_speech_fx ), corr_shiftR_fx, tmpE_LR_fx[1], q_tmpE_LR[1], fr_bands_LR_fx[1], fr_bands_LR_fx_q[1], &cor_map_sum_LR_fx[1], &ncharX_LR_fx, &sp_div_LR_fx, &q_sp_div_LR, &non_staX_LR_fx, loc_harmLR_fx, lf_E_LR_fx[1], lf_E_LR_fx_q, &hCPE->hFrontVad[1]->hNoiseEst->harm_cor_cnt, extract_h( hCPE->hFrontVad[1]->hNoiseEst->Etot_l_lp_32fx ), hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2_32fx, &hCPE->hFrontVad[1]->hNoiseEst->bg_cnt, diff --git a/lib_enc/ivas_front_vad_fx.c b/lib_enc/ivas_front_vad_fx.c index ec6a918b9f6feeaa5518e286b7c869b4284dd0a8..1f62b6854b01955de104e106528d5c713a61ec4a 100644 --- a/lib_enc/ivas_front_vad_fx.c +++ b/lib_enc/ivas_front_vad_fx.c @@ -720,13 +720,6 @@ ivas_error front_vad_spar_fx( hFrontVad->hNoiseEst->ave_enr_q = scale; move16(); - scale = s_min( add( hFrontVad->hNoiseEst->q_bckr, L_norm_arr( hFrontVad->hNoiseEst->bckr_fx, NB_BANDS ) ), add( q_tmpN, L_norm_arr( tmpN_fx, NB_BANDS ) ) ); - scale = sub( s_min( Q31, scale ), 1 ); // guard bits - scale_sig32( hFrontVad->hNoiseEst->bckr_fx, NB_BANDS, sub( scale, hFrontVad->hNoiseEst->q_bckr ) ); - scale_sig32( tmpN_fx, NB_BANDS, sub( scale, q_tmpN ) ); - hFrontVad->hNoiseEst->q_bckr = scale; - move16(); - scale = add( hFrontVad->hNoiseEst->fr_bands_fx_q, s_min( L_norm_arr( hFrontVad->hNoiseEst->fr_bands1_fx, NB_BANDS ), L_norm_arr( hFrontVad->hNoiseEst->fr_bands2_fx, NB_BANDS ) ) ); scale = s_min( scale, add( q_fr_bands[0], L_norm_arr( fr_bands_fx[0], 2 * NB_BANDS ) ) ); scale = s_min( Q31, scale ); @@ -737,7 +730,7 @@ ivas_error front_vad_spar_fx( move16(); move16(); - noise_est_ivas_fx( st, old_pitch, tmpN_fx, epsP_fx, Etot_fx[0], sub( Etot_fx[0], hFrontVad->lp_speech_fx ), corr_shift_fx, tmpE_fx, + noise_est_ivas_fx( st, old_pitch, tmpN_fx, q_tmpN, epsP_fx, Etot_fx[0], sub( Etot_fx[0], hFrontVad->lp_speech_fx ), corr_shift_fx, tmpE_fx, hFrontVad->hNoiseEst->ave_enr_q, fr_bands_fx[0], q_fr_bands[0], &cor_map_sum_fx, NULL, &sp_div_fx, &Q_sp_div, &non_staX_fx, &loc_harm, lf_E_fx[0], q_lf_E[0], &hFrontVad->hNoiseEst->harm_cor_cnt, extract_h( hFrontVad->hNoiseEst->Etot_l_lp_32fx ), hFrontVad->hNoiseEst->Etot_v_h2_32fx, &hFrontVad->hNoiseEst->bg_cnt, st->lgBin_E_fx, &sp_floor, S_map_fx, NULL, hFrontVad, hFrontVad->ini_frame ); @@ -765,7 +758,8 @@ ivas_error front_vad_spar_fx( move16(); hSpar->front_vad_dtx_flag = 1; move16(); - if ( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA ) + test(); + if ( EQ_32( st->core_brate, SID_2k40 ) || st->core_brate == FRAME_NO_DATA ) { hSpar->front_vad_dtx_flag = 0; move16(); diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index 676696fd6c8d33a518d5f27935486c0fd057e857..7fb58941b3542e8673c35cf80aeea8fbee452620 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -2208,7 +2208,8 @@ void noise_est_fx( void noise_est_ivas_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 old_pitch1, /* i : previous frame OL pitch[1] */ - const Word32 tmpN[], /* i : temporary noise update Q_new + QSCALE */ + const Word32 tmpN[], /* i : temporary noise update q_tmpN */ + const Word16 q_tmpN, /* i : Q-factor of tmpN buffer */ const Word32 epsP[], /* i : msb prediction error energies Qx */ const Word16 Etot, /* i : total channel E (see find_enr_fx.c) Q8 */ const Word16 relE, /* i : (VA_CHECK addition) relative frame energy Q8? */ @@ -2221,7 +2222,7 @@ void noise_est_ivas_fx( Word16 *ncharX, /* o : Q11 */ Word16 *sp_div, /* o : Q_sp_div */ Word16 *Q_sp_div, /* o : Q factor for sp_div */ - Word32 *non_staX, /* o : non-stationarity for sp/mus classifier Q20 */ + Word32 *non_staX, /* o : non-stationarity for sp/mus classifier */ Word16 *loc_harm, /* o : multi-harmonicity flag for UV classifier */ const Word32 *lf_E, /* i : per bin energy for low frequencies q_lf_E */ const Word16 q_lf_E, /* i : Q of lf_E Q0 */ @@ -2264,7 +2265,7 @@ void noise_est_ivas_fx( Word16 non_staB; /* Q8 */ Word32 L_tmp_enr, L_tmp_ave, L_tmp_ave2; - Word16 tmp, tmp2; /* general temp registers */ + Word16 tmp, tmp2, diff; /* general temp registers */ Word16 tmp_enr, tmp_floor; /* constants in Q8 */ Word16 vad_bwidth_fx; /* vad ns control variabel for input bwidth from teh BWD */ /* for DTX operation */ @@ -2775,10 +2776,16 @@ void noise_est_ivas_fx( move16(); IF( hNoiseEst->bckr_fx[i] != 0 ) { - Ltmp1 = L_add( hNoiseEst->bckr_fx[i], L_shl( 1, hNoiseEst->q_bckr ) ); // hNoiseEst->q_bckr + diff = 1; + move16(); + IF( GT_16( hNoiseEst->q_bckr, 30 ) ) + { + diff = add( diff, sub( hNoiseEst->q_bckr, 30 ) ); + } + Ltmp1 = L_add( L_shr( hNoiseEst->bckr_fx[i], diff ), L_shl( 1, sub( hNoiseEst->q_bckr, diff ) ) ); // hNoiseEst->q_bckr - diff e_ener = norm_l( Ltmp1 ); f_ener = Log2_norm_lc( L_shl( Ltmp1, e_ener ) ); - e_ener = sub( sub( 30, e_ener ), hNoiseEst->q_bckr ); + e_ener = sub( sub( 30, e_ener ), sub( hNoiseEst->q_bckr, diff ) ); Ltmp1 = L_mac( f_ener, e_ener, ONE_IN_Q14 ); // Q15 Ltmp1 = Mpy_32_16_1( Ltmp1, 22713 ); // Q15 tmp_floor = round_fx( L_shl( Ltmp1, 9 ) ); /* Q8 */ @@ -3499,6 +3506,8 @@ void noise_est_ivas_fx( hNoiseEst->bckr_fx[i] = tmpN[i]; move32(); } + hNoiseEst->q_bckr = q_tmpN; + move16(); } /* else if ( ( ( st->act_pred < 0.80f ) && ( aE_bgd || PAU ) && st->lt_haco_ev < 0.10f ) || ( ( st->act_pred < 0.70f ) && ( aE_bgd || non_staB < 17.0f ) && PAU && st->lt_haco_ev < 0.15f ) @@ -3536,14 +3545,34 @@ void noise_est_ivas_fx( hNoiseEst->first_noise_updt = 1; move16(); - FOR( i = 0; i < NB_BANDS; i++ ) + IF( LT_16( q_tmpN, hNoiseEst->q_bckr ) ) { - /* st->bckr[i] = st->bckr[i] + updt_step * (tmpN[i]-st->bckr[i]);*/ - /* 32 bit state update */ - Ltmp = L_sub( tmpN[i], hNoiseEst->bckr_fx[i] ); // hNoiseEst->q_bckr - Ltmp = Mult_32_16( Ltmp, updt_step ); - hNoiseEst->bckr_fx[i] = L_add( Ltmp, hNoiseEst->bckr_fx[i] ); // hNoiseEst->q_bckr - move32(); + diff = sub( hNoiseEst->q_bckr, q_tmpN ); + FOR( i = 0; i < NB_BANDS; i++ ) + { + /* st->bckr[i] = st->bckr[i] + updt_step * (tmpN[i]-st->bckr[i]);*/ + /* 32 bit state update */ + Ltmp1 = L_shr( hNoiseEst->bckr_fx[i], diff ); + Ltmp = L_sub( tmpN[i], Ltmp1 ); // q_tmpN + Ltmp = Mult_32_16( Ltmp, updt_step ); + hNoiseEst->bckr_fx[i] = L_add( Ltmp, Ltmp1 ); // q_tmpN + move32(); + } + hNoiseEst->q_bckr = q_tmpN; + move16(); + } + ELSE + { + diff = sub( q_tmpN, hNoiseEst->q_bckr ); + FOR( i = 0; i < NB_BANDS; i++ ) + { + /* st->bckr[i] = st->bckr[i] + updt_step * (tmpN[i]-st->bckr[i]);*/ + /* 32 bit state update */ + Ltmp = L_sub( L_shr( tmpN[i], diff ), hNoiseEst->bckr_fx[i] ); // hNoiseEst->q_bckr + Ltmp = Mult_32_16( Ltmp, updt_step ); + hNoiseEst->bckr_fx[i] = L_add( Ltmp, hNoiseEst->bckr_fx[i] ); // hNoiseEst->q_bckr + move32(); + } } } /*else if (aE_bgd || st->harm_cor_cnt > 100 )*/ diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 9920874138ed5bb3107457e439154666268ec23b..691ce70049253ae03a9860686000078de97eaad0 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -385,7 +385,8 @@ void noise_est_fx( void noise_est_ivas_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 old_pitch1, /* i : previous frame OL pitch[1] */ - const Word32 tmpN[], /* i : temporary noise update Q_new + QSCALE */ + const Word32 tmpN[], /* i : temporary noise update q_tmpN */ + const Word16 q_tmpN, /* i : Q-factor of tmpN buffer */ const Word32 epsP[], /* i : msb prediction error energies Qx */ const Word16 Etot, /* i : total channel E (see find_enr_fx.c) Q8 */ const Word16 relE, /* i : (VA_CHECK addition) relative frame energy Q8? */ diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index 1cf7a5de8e6cea58d11cf74ec571e168bc005472..8f1fb6985dc38871880b73479201df4fdaf9fcbb 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -2369,10 +2369,10 @@ Word16 wb_vad_ivas_fx( } norm_tmp = norm_l( ftmp1 ); - scaled_tmp = L_shl( ftmp1, norm_tmp ); /*13+norm_tmp*/ + scaled_tmp = L_shl( ftmp1, norm_tmp ); /*16+norm_tmp*/ L_msnr = scaled_tmp; move32(); - L_msnr_e = sub( 18, norm_tmp ); + L_msnr_e = sub( 15, norm_tmp ); FOR( j = 1; j < stmp; j++ ) { L_msnr = Mult_32_32( L_msnr, scaled_tmp ); /*L_msnr_e msnr *= ftmp1;*/