diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 97cd573081879ca0cdf8d75191eda26f407c5baa..543a6fab9b817b7717090d2f70535f035ed6e16b 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -377,6 +377,8 @@ ivas_error init_encoder_fx( move16(); st_fx->hVAD->L_snr_sum_vad_fx = 0; move32(); + st_fx->hVAD->q_L_snr_sum_vad = Q31; + move16(); } ELSE { diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index e883d9ec1b5386d508348573c41e300f6f3a4416..d358f70991956fd0ceaa234c1ee9c89c662eb898 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -223,6 +223,7 @@ ivas_error pre_proc_front_ivas_fx( Word16 res_cod_SNR_M_fx_e[STEREO_DFT_BAND_MAX]; Word16 Qfact_PS, q_lf_E_fx; Word16 enerBuffer_fx_exp_buf[CLDFB_NO_CHANNELS_MAX]; + Word32 bckr_temp[NB_BANDS]; #ifdef DEBUG_MODE_INFO Word32 *in_buff_temp; Word16 in_q_temp; @@ -781,21 +782,9 @@ ivas_error pre_proc_front_ivas_fx( move16(); } - Word16 scale = add( L_norm_arr( st->hNoiseEst->enrO_fx, NB_BANDS ), st->hNoiseEst->q_enrO ); - scale = s_min( scale, fr_bands_fx_q ); - - scale_sig32( st->hNoiseEst->enrO_fx, NB_BANDS, sub( scale, st->hNoiseEst->q_enrO ) ); - st->hNoiseEst->q_enrO = scale; - move16(); - - scale_sig32( fr_bands_fx, 2 * NB_BANDS, sub( scale, fr_bands_fx_q ) ); - fr_bands_fx_q = scale; - move16(); - st->vad_flag = wb_vad_ivas_fx( st, fr_bands_fx, fr_bands_fx_q, &i, &i, &i, &snr_sum_he_fx, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr ), NULL, NULL, -MAX_16, -MAX_16 ); //-100000f == max 16bit float move16(); - #ifdef DEBUG_FORCE_DIR if ( st->force_dir[0] != '\0' ) { @@ -919,13 +908,13 @@ ivas_error pre_proc_front_ivas_fx( *----------------------------------------------------------------*/ noise_est_down_ivas_fx( fr_bands_fx, fr_bands_fx_q, st->hNoiseEst->bckr_fx, &st->hNoiseEst->q_bckr, tmpN_fx, &q_tmpN, tmpE_fx, &q_tmpE, st->min_band, st->max_band, - &st->hNoiseEst->totalNoise_fx, Etot_fx, &st->hNoiseEst->Etot_last_32fx, &st->hNoiseEst->Etot_v_h2_fx ); + &st->hNoiseEst->totalNoise_fx, Etot_fx, &st->hNoiseEst->Etot_last_32fx, &st->hNoiseEst->Etot_v_h2_32fx ); test(); IF( lr_vad_enabled && st->idchan == 0 ) { - noise_est_down_ivas_fx( fr_bands_LR_fx[0], fr_bands_LR_fx_q[0], hCPE->hFrontVad[0]->hNoiseEst->bckr_fx, &hCPE->hFrontVad[0]->hNoiseEst->q_bckr, tmpN_LR_fx[0], &q_tmpN_LR[0], tmpE_LR_fx[0], &q_tmpE_LR[0], st->min_band, st->max_band, &hCPE->hFrontVad[0]->hNoiseEst->totalNoise_fx, L_deposit_h( Etot_LR_fx[0] ), &hCPE->hFrontVad[0]->hNoiseEst->Etot_last_32fx, &hCPE->hFrontVad[0]->hNoiseEst->Etot_v_h2_fx ); - noise_est_down_ivas_fx( fr_bands_LR_fx[1], fr_bands_LR_fx_q[1], hCPE->hFrontVad[1]->hNoiseEst->bckr_fx, &hCPE->hFrontVad[1]->hNoiseEst->q_bckr, tmpN_LR_fx[1], &q_tmpN_LR[1], tmpE_LR_fx[1], &q_tmpE_LR[1], st->min_band, st->max_band, &hCPE->hFrontVad[1]->hNoiseEst->totalNoise_fx, L_deposit_h( Etot_LR_fx[1] ), &hCPE->hFrontVad[1]->hNoiseEst->Etot_last_32fx, &hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2_fx ); + noise_est_down_ivas_fx( fr_bands_LR_fx[0], fr_bands_LR_fx_q[0], hCPE->hFrontVad[0]->hNoiseEst->bckr_fx, &hCPE->hFrontVad[0]->hNoiseEst->q_bckr, tmpN_LR_fx[0], &q_tmpN_LR[0], tmpE_LR_fx[0], &q_tmpE_LR[0], st->min_band, st->max_band, &hCPE->hFrontVad[0]->hNoiseEst->totalNoise_fx, L_deposit_h( Etot_LR_fx[0] ), &hCPE->hFrontVad[0]->hNoiseEst->Etot_last_32fx, &hCPE->hFrontVad[0]->hNoiseEst->Etot_v_h2_32fx ); + noise_est_down_ivas_fx( fr_bands_LR_fx[1], fr_bands_LR_fx_q[1], hCPE->hFrontVad[1]->hNoiseEst->bckr_fx, &hCPE->hFrontVad[1]->hNoiseEst->q_bckr, tmpN_LR_fx[1], &q_tmpN_LR[1], tmpE_LR_fx[1], &q_tmpE_LR[1], st->min_band, st->max_band, &hCPE->hFrontVad[1]->hNoiseEst->totalNoise_fx, L_deposit_h( Etot_LR_fx[1] ), &hCPE->hFrontVad[1]->hNoiseEst->Etot_last_32fx, &hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2_32fx ); corr_shiftL_fx = correlation_shift_fx( hCPE->hFrontVad[0]->hNoiseEst->totalNoise_fx ); // Q15 corr_shiftR_fx = correlation_shift_fx( hCPE->hFrontVad[1]->hNoiseEst->totalNoise_fx ); // Q15 @@ -1249,7 +1238,7 @@ ivas_error pre_proc_front_ivas_fx( * Update estimated noise energy and voicing cut-off frequency *-----------------------------------------------------------------*/ - 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 ) ) ) ); + 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 ) ); @@ -1278,7 +1267,7 @@ ivas_error pre_proc_front_ivas_fx( 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, &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_fx, &st->hNoiseEst->bg_cnt, st->lgBin_E_fx, &dummy_fx, S_map_fx, + extract_h( st->hNoiseEst->Etot_v_h2_32fx ), &st->hNoiseEst->bg_cnt, st->lgBin_E_fx, &dummy_fx, S_map_fx, hStereoClassif, NULL, st->ini_frame ); test(); @@ -1321,14 +1310,14 @@ ivas_error pre_proc_front_ivas_fx( 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, 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_fx, &hCPE->hFrontVad[0]->hNoiseEst->bg_cnt, + extract_h( hCPE->hFrontVad[0]->hNoiseEst->Etot_l_lp_32fx ), extract_h( 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, 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_fx, &hCPE->hFrontVad[1]->hNoiseEst->bg_cnt, + extract_h( hCPE->hFrontVad[1]->hNoiseEst->Etot_l_lp_32fx ), extract_h( hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2_32fx ), &hCPE->hFrontVad[1]->hNoiseEst->bg_cnt, st->lgBin_E_fx, &dummy_fx, S_map_LR_fx, NULL, hCPE->hFrontVad[1], hCPE->hFrontVad[0]->ini_frame ); } @@ -1346,14 +1335,14 @@ ivas_error pre_proc_front_ivas_fx( * Find spectral tilt * UC and VC frame selection *-----------------------------------------------------------------*/ + scale = s_min( Q31, s_min( add( st->hNoiseEst->q_bckr, L_norm_arr( st->hNoiseEst->bckr_fx, NB_BANDS ) ), add( fr_bands_fx_q, L_norm_arr( fr_bands_fx, 2 * NB_BANDS ) ) ) ); scale_sig32( fr_bands_fx, 2 * NB_BANDS, sub( scale, fr_bands_fx_q ) ); - scale_sig32( st->hNoiseEst->bckr_fx, NB_BANDS, sub( scale, st->hNoiseEst->q_bckr ) ); - st->hNoiseEst->q_bckr = fr_bands_fx_q = scale; - move16(); + Copy_Scale_sig32( st->hNoiseEst->bckr_fx, bckr_temp, NB_BANDS, sub( scale, st->hNoiseEst->q_bckr ) ); + fr_bands_fx_q = scale; move16(); - find_tilt_ivas_fx( fr_bands_fx, fr_bands_fx_q, st->hNoiseEst->bckr_fx, st->hNoiseEst->q_bckr, ee_fx, st->pitch, st->voicing_fx, lf_E_fx, q_lf_E_fx, + find_tilt_ivas_fx( fr_bands_fx, fr_bands_fx_q, bckr_temp, scale, ee_fx, st->pitch, st->voicing_fx, lf_E_fx, q_lf_E_fx, corr_shift_fx, st->input_bwidth, st->max_band, hp_E_fx, MODE1, &( st->bckr_tilt_lt ), st->Opt_SC_VBR ); st->coder_type = find_uv_ivas_fx( st, pitch_fr_fx, voicing_fr_fx, inp_12k8_fx, ee_fx, &dE1X_fx, corr_shift_fx, *relE_fx, extract_h( Etot_fx ), hp_E_fx, diff --git a/lib_enc/ivas_front_vad_fx.c b/lib_enc/ivas_front_vad_fx.c index ab090edb81bef6642c0d562b6f1c645670b0bb18..b3c563863e5ddfe94303a84817bf3a2551068477 100644 --- a/lib_enc/ivas_front_vad_fx.c +++ b/lib_enc/ivas_front_vad_fx.c @@ -282,16 +282,6 @@ ivas_error front_vad_fx( move16(); /* wb_vad */ - Word16 scale = s_min( q_fr_bands[n], add( hFrontVads[n]->hNoiseEst->q_enrO, L_norm_arr( hFrontVads[n]->hNoiseEst->enrO_fx, NB_BANDS ) ) ); - - scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, NB_BANDS, sub( scale, hFrontVads[n]->hNoiseEst->q_enrO ) ); // scale - hFrontVads[n]->hNoiseEst->q_enrO = scale; - move16(); - - scale_sig32( fr_bands_fx[n], 2 * NB_BANDS, sub( scale, q_fr_bands[n] ) ); // scale - q_fr_bands[n] = scale; - move16(); - hFrontVad->hVAD->vad_flag = wb_vad_ivas_fx( sts[n], fr_bands_fx[n], q_fr_bands[n], &dummy, &dummy, &dummy, &snr_sum_he_fx, &localVAD_HE_SAD[n], &dummy_short, hFrontVad->hVAD, hFrontVad->hNoiseEst, hFrontVad->lp_speech_fx, hFrontVad->lp_noise_fx ); // Q0 @@ -613,7 +603,7 @@ ivas_error front_vad_spar_fx( Word16 q_tmpN, q_tmpE; noise_est_down_ivas_fx( fr_bands_fx[0], q_fr_bands[0], hFrontVad->hNoiseEst->bckr_fx, &hFrontVad->hNoiseEst->q_bckr, tmpN_fx, &q_tmpN, tmpE_fx, &q_tmpE, st->min_band, st->max_band, - &hFrontVad->hNoiseEst->totalNoise_fx, L_deposit_h( Etot_fx[0] ) /*q8->q24*/, &hFrontVad->hNoiseEst->Etot_last_32fx, &hFrontVad->hNoiseEst->Etot_v_h2_fx ); + &hFrontVad->hNoiseEst->totalNoise_fx, L_deposit_h( Etot_fx[0] ) /*q8->q24*/, &hFrontVad->hNoiseEst->Etot_last_32fx, &hFrontVad->hNoiseEst->Etot_v_h2_32fx ); corr_shift_fx = correlation_shift_fx( hFrontVad->hNoiseEst->totalNoise_fx ); /* Q15 */ @@ -755,7 +745,7 @@ ivas_error front_vad_spar_fx( 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, 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_fx, + lf_E_fx[0], q_lf_E[0], &hFrontVad->hNoiseEst->harm_cor_cnt, extract_h( hFrontVad->hNoiseEst->Etot_l_lp_32fx ), extract_h( hFrontVad->hNoiseEst->Etot_v_h2_32fx ), &hFrontVad->hNoiseEst->bg_cnt, st->lgBin_E_fx, &sp_floor, S_map_fx, NULL, hFrontVad, hFrontVad->ini_frame ); MVR2R_WORD16( st->pitch, st->pitch, 3 ); diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index 733576975f1ca6574ff98f907ad2487225d6ffff..4f178214f47fe7d14821c7cdc9739a2c2de1a37f 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -361,13 +361,13 @@ void noise_est_init_ivas_fx( hNoiseEst->Etot_l_fx = 0; hNoiseEst->Etot_l_lp_32fx = 0; hNoiseEst->Etot_last_32fx = 0; - hNoiseEst->Etot_v_h2_fx = 0; + hNoiseEst->Etot_v_h2_32fx = 0; hNoiseEst->sign_dyn_lp_fx = 0; move16(); move16(); move16(); move16(); - move16(); + move32(); move32(); move32(); @@ -514,8 +514,8 @@ void noise_est_pre_32fx( move32(); hNoiseEst->Etot_last_32fx = Etot; // Q24 move32(); - hNoiseEst->Etot_v_h2_fx = 0; - move16(); + hNoiseEst->Etot_v_h2_32fx = 0; + move32(); Etot_lp_32fx = Etot; move32(); hNoiseEst->sign_dyn_lp_fx = 0; @@ -750,7 +750,7 @@ void noise_est_down_ivas_fx( Word16 *totalNoise, /* o : noise estimate over all critical bands */ Word32 Etot, /* i : Energy of current frame Q24*/ Word32 *Etot_last, /* i/o: Energy of last frame Q24 */ - Word16 *Etot_v_h2 /* i/o: Energy variations of noise frames Q8 */ + Word32 *Etot_v_h2 /* i/o: Energy variations of noise frames Q24 */ ) { @@ -773,7 +773,7 @@ void noise_est_down_ivas_fx( L_Etot = Etot; /*Q24 for later AR1 computations*/ move32(); L_Etot_last = *Etot_last; - L_Etot_v_h2 = L_shl( *Etot_v_h2, 16 ); + L_Etot_v_h2 = *Etot_v_h2; /*-----------------------------------------------------------------* * Estimate total noise energy @@ -901,7 +901,7 @@ void noise_est_down_ivas_fx( L_Etot_v_h2 = Madd_32_16( L_tmp, L_Etot_v_h2, 32113 /* 0.98 in Q15 */ ); // Q24 /* if (*Etot_v_h2 < 0.1f) { *Etot_v_h2 = 0.1f; } */ - *Etot_v_h2 = s_max( round_fx( L_Etot_v_h2 ), 26 /* 0.1 in Q8*/ ); // Q8 + *Etot_v_h2 = L_max( L_Etot_v_h2, 1677722 /* 0.1 in Q24*/ ); // Q24 move16(); return; @@ -3494,7 +3494,7 @@ void noise_est_ivas_fx( ) */ ELSE IF( ( LT_16( hNoiseEst->act_pred_fx, 26214 /* 0.8 in Q15*/ ) && ( ( aE_bgd != 0 ) || ( PAU != 0 ) ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 3277 /* 0.1 in q15*/ ) ) ) || ( ( LT_16( hNoiseEst->act_pred_fx, 22938 /* 0.70 in Q15 */ ) ) && ( ( aE_bgd != 0 ) || ( LT_16( non_staB, 17 * 256 /* 17.0 in Q8 */ ) ) ) && ( PAU != 0 ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 4915 /* 0.15 in Q15 */ ) ) ) || - ( GT_16( hNoiseEst->harm_cor_cnt, 80 ) && GT_16( hNoiseEst->totalNoise_fx, 5 * 256 /* 5.0 in Q8 */ ) && LT_16( Etot, s_max( 1 * 256, add( Etot_l_lp, add( hNoiseEst->Etot_v_h2_fx, shr( hNoiseEst->Etot_v_h2_fx, 1 ) ) /* 1.5= 1.0+.5 */ ) ) ) ) || + ( GT_16( hNoiseEst->harm_cor_cnt, 80 ) && GT_16( hNoiseEst->totalNoise_fx, 5 * 256 /* 5.0 in Q8 */ ) && LT_16( Etot, s_max( 1 * 256, add( Etot_l_lp, extract_h( L_add( hNoiseEst->Etot_v_h2_32fx, L_shr( hNoiseEst->Etot_v_h2_32fx, 1 ) ) ) /* 1.5= 1.0+.5 */ ) ) ) ) || ( GT_16( hNoiseEst->harm_cor_cnt, 50 ) && GT_16( hNoiseEst->first_noise_updt, 30 ) && ( aE_bgd != 0 ) && GT_16( hNoiseEst->lt_aEn_zero_fx, 16384 /*.5 in Q15*/ ) ) || ( tn_ini != 0 ) ) { updt_step = 3277; diff --git a/lib_enc/pitch_ol_fx.c b/lib_enc/pitch_ol_fx.c index 91181714af9242f49697b8f221c167f31d525faf..fdadcd318be997001ac0ec11996edee7c1423496 100644 --- a/lib_enc/pitch_ol_fx.c +++ b/lib_enc/pitch_ol_fx.c @@ -1686,13 +1686,17 @@ void pitch_ol_ivas_fx( move16(); /* enr1 = dotp( pt2, pt2, len[j] ) + 0.01f; */ - temp = 167772 /*0.01f in Q24*/; + temp = 0; move64(); FOR( m = 0; m < len[j]; m++ ) { temp = W_mac0_16_16( temp, pt2[m], pt2[m] ); // 2*qwsp } + temp = W_shl( temp, sub( Q24, shl( qwsp, 1 ) ) ); // Q24 + + temp = W_add( temp, 167772 ); /*0.01f in Q24*/ + enr1_exp = W_norm( temp ); enr1 = W_extract_h( W_shl( temp, enr1_exp ) ); // enr1_exp+24-32 enr1_exp = sub( 39, enr1_exp ); // 31-(enr1_exp+24-32) @@ -1724,13 +1728,18 @@ void pitch_ol_ivas_fx( move16(); /* enr1 = dotp(pt4, pt4, len1[j]) + 0.01f; */ - temp = 167772 /*0.01f in Q24*/; + temp = 0; + move64(); move64(); FOR( m = 0; m < len1[j]; m++ ) { temp = W_mac0_16_16( temp, pt4[m], pt4[m] ); // 2*qwsp } + temp = W_shl( temp, sub( Q24, shl( qwsp, 1 ) ) ); // Q24 + + temp = W_add( temp, 167772 ); /*0.01f in Q24*/ + enr1_exp = W_norm( temp ); enr1 = W_extract_h( W_shl( temp, enr1_exp ) ); // enr1_exp+24-32 enr1_exp = sub( 39, enr1_exp ); // 31-(enr1_exp+24-32) diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 05bb16832270f819264455f7242eea206765fa1f..1d85ae6de51b4add0b24f24bec1e6e80f2d3a0d0 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -371,7 +371,7 @@ void noise_est_down_ivas_fx( Word16 *totalNoise, /* o : noise estimate over all critical bands */ Word32 Etot, /* i : Energy of current frame Q24*/ Word32 *Etot_last, /* i/o: Energy of last frame Q24 */ - Word16 *Etot_v_h2 /* i/o: Energy variations of noise frames Q8 */ + Word32 *Etot_v_h2 /* i/o: Energy variations of noise frames Q24 */ ); void noise_est_fx( diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 3d6f23dd351949a7f05d1aed06e860c51aa84f0f..caca3173e0db49e4630ddf633ef91b4c20b817bb 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -224,7 +224,8 @@ typedef struct vad_structure Word16 trigger_SID; Word16 snr_sum_vad_fx; /*Q15 */ Word16 running_avg_fx; /*Q15 */ - Word32 L_snr_sum_vad_fx; /*Q4*/ + Word32 L_snr_sum_vad_fx; // EVS:Q4, IVAS:q_L_snr_sum_vad + Word16 q_L_snr_sum_vad; Word16 hangover_terminate_flag; /* CNG and DTX - flag indicating whether to early terminate DTX hangover */ Word16 vad_flag; /* VAD flag */ @@ -564,6 +565,7 @@ typedef struct noise_estimation_structure Word16 lt_aEn_zero_fx; /* Q15 */ Word16 Etot_v_h2_fx; + Word32 Etot_v_h2_32fx; /* Q24 */ Word16 sign_dyn_lp_fx; /*Q8*/ Word16 Etot_st_est_fx; /* Q8 Noise estimation - short term estimate of E{ Etot } */ diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index 531265236fae2161e076484894dfaf064846f61f..721a6e34875876d1a91f54b1a940fb20ea2de7d3 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -142,6 +142,8 @@ void wb_vad_init_ivas_fx( { hVAD->L_snr_sum_vad_fx = 0; move32(); + hVAD->q_L_snr_sum_vad = Q31; + move16(); hVAD->hangover_cnt = 0; move16(); /* Hangover counter initialized to 0 */ hVAD->nb_active_frames = ACTIVE_FRAMES_FX; @@ -1918,7 +1920,8 @@ Word16 wb_vad_ivas_fx( ) { Word16 i, flag = 0, hangover_short; - Word16 snr_sum, thr1 = 0, thr1_nb_mod, thr2 = 0, nk = 0, nc = 0, th_clean = 0; + Word16 snr_sum, thr1 = 0, thr1_nb_mod, thr2 = 0, nk = 0, th_clean = 0; + Word32 nc; Word16 lp_snr; /* Q8 */ const Word32 *pt1; const Word32 *pt2; @@ -1927,8 +1930,8 @@ Word16 wb_vad_ivas_fx( Word16 min_snr, sign_thr; Word32 L_snr, L_snr_sum; - Word32 ftmp, ftmp1, ftmp2; - Word16 m_noise_local, e_noise, e_num, m_num, snr_tmp, shift_snr, q_snr_tmp, q_snr; + Word32 ener, fr_enr, ftmp, ftmp1; + Word16 m_noise_local, e_noise, e_num, m_num, q_snr_tmp, q_snr; Word32 L_snr_tmp; Word16 snr_sumt; Word32 L_vad_thr; @@ -1947,7 +1950,7 @@ Word16 wb_vad_ivas_fx( Word16 nb_sig_snr; /* Q0 */ Word16 nv; - Word16 nv_ofs; /* Q8 */ + Word32 nv_ofs; /* Q24 */ Word32 L_snr_sum_HE_SAD; /* Q4 */ Word16 snr_sum_HE_SAD; /*Q8 log */ Word16 sign_thr_HE_SAD, min_snr_HE_SAD; @@ -1957,13 +1960,14 @@ Word16 wb_vad_ivas_fx( Word32 L_snr_sum_ol; Word16 snr_sum_ol; /* Q8 log */ - Word32 L_snr_outlier; + Word32 L_snr_outlier, L_snr_outlier_Q4; Word16 snr_outlier_index; Word32 L_accum_ener_L; Word32 L_accum_ener_H; Word16 vad_bwidth_fx; Word16 last_7k2_coder_type; - Word16 q_shift; + Word16 q_shift, q_ener, q_diff1, q_diff2; + Word16 q_L_snr_sum_ol, e_snr, f_snr; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); @@ -1978,7 +1982,7 @@ Word16 wb_vad_ivas_fx( move16(); /*thr1*/ move16(); /*thr2*/ move16(); /*nk*/ - move16(); /*nc*/ + move32(); /*nc*/ move16(); /*th_clean*/ move16(); /*flag*/ @@ -2051,12 +2055,12 @@ Word16 wb_vad_ivas_fx( { nk = 3277; move16(); /*0.1 Q15 */ - nc = 4122; - move16(); /*16.1 Q8 */ - nv = 525; - move16(); /* 2.05 Q8*/ - nv_ofs = 422; - move16(); /* 1.65 Q8*/ + nc = 270113178; + move32(); /*16.1 Q24 */ + nv = 8397; + move16(); /* 2.05 Q12*/ + nv_ofs = 27682406; + move32(); /* 1.65 Q24*/ th_clean = TH16_2_FX; move16(); /* 35 Q8 */ sign_thr = 21; @@ -2085,12 +2089,12 @@ Word16 wb_vad_ivas_fx( // move16(); nk = 3277; move16(); /* 0.1 Q15 */ - nc = 4096; - move16(); /* 16.0 Q8 */ - nv = 1024; - move16(); /* 4.0 Q8 */ - nv_ofs = 294; - move16(); /*1.15 Q8*/ + nc = 268435456; + move32(); /* 16.0 Q24 */ + nv = 16384; + move16(); /* 4.0 Q12 */ + nv_ofs = 19293798; + move32(); /*1.15 Q24*/ th_clean = TH8_1_FX; move16(); /*20 Q8 */ sign_thr = 28; @@ -2203,10 +2207,6 @@ Word16 wb_vad_ivas_fx( nb_sig_snr = 20; move16(); - pt1 = fr_bands; - pt2 = fr_bands + NB_BANDS; - pt3 = hNoiseEst->bckr_fx; - L_snr_sum = L_deposit_l( 0 ); L_snr_sum_HE_SAD = L_deposit_l( 0 ); Word16 q_snr_sum = 0; @@ -2226,81 +2226,89 @@ Word16 wb_vad_ivas_fx( q_snr = 0; move16(); move16(); - q_shift = add( sub( q_fr_bands, hNoiseEst->q_bckr ), 14 - 4 ); + + pt1 = fr_bands; + pt2 = fr_bands + NB_BANDS; + pt3 = hNoiseEst->bckr_fx; + + q_ener = s_min( q_fr_bands, hNoiseEst->q_enrO ); + q_diff1 = sub( q_ener, hNoiseEst->q_enrO ); + q_diff2 = sub( q_ener, q_fr_bands ); + q_shift = add( Q31 + Q1, sub( q_ener, hNoiseEst->q_bckr ) ); + FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ ) { - ftmp = L_add( *pt1++, 0 ); - ftmp1 = L_add( *pt2++, 0 ); - ftmp2 = L_add( *pt3++, 0 ); + ener = L_shl( hNoiseEst->enrO_fx[i], q_diff1 ); // q_ener + ftmp = L_shl( *pt1++, q_diff2 ); // q_ener + ftmp1 = L_shl( *pt2++, q_diff2 ); // q_ener /*fr_enr = ( 0.2f * st->enrO[i] + 0.4f * ftmp + 0.4f * ftmp1 );*/ - L_tmp = Mult_32_16( hNoiseEst->enrO_fx[i], 6554 ); /* L_tmp(high word) = Qenr0fx*Q15+1 -16 -> Qener0 */ - L_tmp1 = Madd_32_16( L_tmp, ftmp, 13107 ); /* 13107 = .4 in Q15 */ - L_tmp1 = Madd_32_16( L_tmp1, ftmp1, 13107 ); /* L_tmp1 re_used a bit later for final snr[i]*/ - - L_tmp2 = Madd_32_16( L_tmp, ftmp, 9830 ); /* 9830 = 0.3 in Q15 */ - L_tmp2 = Msub_32_16( L_tmp2, ftmp1, -16384 ); /* -16384= -0.5 in Q15 */ + L_tmp = Mpy_32_16_1( ener, 13107 /* 0.2 in Q16 */ ); // q_ener+1 + fr_enr = Madd_32_16( Madd_32_16( L_tmp, ftmp, 26214 /* 0.4 in Q16 */ ), ftmp1, 26214 /* 0.4 in Q16 */ ); // q_ener+1 IF( GT_32( ftmp, ftmp1 ) ) { - /*snr[i] = ( 0.2f * st->enrO[i] + 0.4f * ftmp + 0.4f * ftmp1 ) / ftmp2 ;*/ - /*snr[i] = L_tmp1/(ftmp2) */ - IF( ftmp2 != 0 ) + /* snr[i] = ( 0.2f * hNoiseEst->enrO[i] + 0.4f * ftmp + 0.4f * ftmp1 ) / *pt3++; */ + IF( *pt3 != 0 ) { - e_num = norm_l( L_tmp1 ); - m_num = extract_h( L_shl( L_tmp1, e_num ) ); // q_fr_bands+e_num-16 - - e_noise = norm_l( ftmp2 ); - m_noise_local = extract_h( L_shl( ftmp2, e_noise ) ); // hNoiseEst->q_bckr+e_noise-16 + /* Since fr_enr = 0.2f * hNoiseEst->enrO[i] + 0.4f * ftmp + 0.4f * ftmp1 */ + e_num = sub( norm_l( fr_enr ), 1 ); + m_num = extract_h( L_shl( fr_enr, e_num ) ); // q_ener+1+e_num-16 - m_num = shr( m_num, 1 ); // q_fr_bands-1+e_num-16 - shift_snr = add( sub( e_num, e_noise ), q_shift ); + e_noise = norm_l( *pt3 ); + m_noise_local = extract_h( L_shl( *pt3++, e_noise ) ); // hNoiseEst->q_bckr+e_noise-16 - snr_tmp = div_s( m_num, m_noise_local ); // q_fr_bands+e_num-hNoiseEst->q_bckr-e_noise - L_snr = L_shr_o( snr_tmp, shift_snr, &Overflow ); /* L_snr in Q4 */ + L_snr = L_deposit_h( div_s( m_num, m_noise_local ) ); // 31+(q_ener+1+e_num-16)-(hNoiseEst->q_bckr+e_noise-16) + q_snr_tmp = add( q_shift, sub( e_num, e_noise ) ); } ELSE { - L_snr = L_shl_o( L_tmp1, sub( Q4, q_fr_bands ), &Overflow ); // q_fr_bands -> Q4 + L_snr = Mpy_32_16_1( fr_enr, 18286 /* (1/E_MIN) in Q6 */ ); // q_ener+1+6-15 + q_snr_tmp = sub( q_ener, 8 ); } } ELSE { - /*snr[i] = ( 0.2f * st->enrO[i] + 0.3f * ftmp + 0.5f * ftmp1 ) / ftmp2 ;*/ - /*snr[i] =L_tmp2/( ftmp2 ) */ - IF( ftmp2 != 0 ) - { - e_num = norm_l( L_tmp2 ); - m_num = extract_h( L_shl( L_tmp2, e_num ) ); // q_fr_bands+e_num-16 + /* snr[i] = ( 0.2f * hNoiseEst->enrO[i] + 0.3f * ftmp + 0.5f * ftmp1 ) / *pt3++; */ + /* Since, L_tmp = 0.2f * hNoiseEst->enrO[i] */ + L_tmp = Msub_32_16( Madd_32_16( L_tmp, ftmp, 19661 /* 0.3 in Q16 */ ), ftmp1, -32768 /* -0.5 in Q16 */ ); // q_ener+1 - e_noise = norm_l( ftmp2 ); - m_noise_local = extract_h( L_shl( ftmp2, e_noise ) ); // hNoiseEst->q_bckr+e_noise-16 + IF( *pt3 != 0 ) + { + e_num = sub( norm_l( L_tmp ), 1 ); + m_num = extract_h( L_shl( L_tmp, e_num ) ); // q_ener+1+e_num-16 - m_num = shr( m_num, 1 ); // q_fr_bands-1+e_num-16 - shift_snr = add( sub( e_num, e_noise ), q_shift ); + e_noise = norm_l( *pt3 ); + m_noise_local = extract_h( L_shl( *pt3++, e_noise ) ); // hNoiseEst->q_bckr+e_noise-16 - snr_tmp = div_s( m_num, m_noise_local ); // q_fr_bands+e_num-hNoiseEst->q_bckr-e_noise - L_snr = L_shr_o( snr_tmp, shift_snr, &Overflow ); /* L_snr in Q4 */ + L_snr = L_deposit_h( div_s( m_num, m_noise_local ) ); // 31+(q_ener+1+e_num-16)-(hNoiseEst->q_bckr+e_noise-16) + q_snr_tmp = add( q_shift, sub( e_num, e_noise ) ); } ELSE { - L_snr = L_shl_o( L_tmp2, sub( Q4, q_fr_bands ), &Overflow ); // q_fr_bands -> Q4 + L_snr = Mpy_32_16_1( L_tmp, 18286 /* (1/E_MIN) in Q6 */ ); // q_ener+1+6-15 + q_snr_tmp = sub( q_ener, 8 ); } } - IF( LT_32( L_snr, 2 * ( 1 << 4 ) ) ) + if ( LT_32( L_snr, L_shl_sat( 2, q_snr_tmp ) ) ) { nb_sig_snr = sub( nb_sig_snr, 1 ); /* nb_sig_snr--; */ } - L_snr = L_max( L_snr, 1 * ( 1 << 4 ) ); /* if ( snr[i] < 1 ){snr[i] = 1;}*/ - + IF( LT_32( L_snr, L_shl_sat( 1, q_snr_tmp ) ) ) + { + L_snr = ONE_IN_Q30; + q_snr_tmp = Q30; + move32(); + move16(); + } /* snr[i] = (float)log10(snr[i]); */ Word16 exp = norm_l( L_snr ); Word16 val = Log2_norm_lc( L_shl( L_snr, exp ) ); - exp = sub( sub( 30, exp ), Q4 ); - L_snr = L_mac( L_deposit_h( exp ), val, 1 ); // Q16 - L_snr = Mpy_32_16_1( L_snr, 9864 /* log2 in Q15 */ ); // Q16 + exp = sub( sub( 30, exp ), q_snr_tmp ); + L_snr = L_mac( val, exp, ONE_IN_Q14 ); // Q15 + L_snr = Mpy_32_16_1( L_snr, 19728 /* log2 in Q16 */ ); // Q16 /* snr_sumt += snr[i];*/ L_snr_sumt = L_add( L_snr_sumt, L_snr ); // Q16 @@ -2373,22 +2381,22 @@ Word16 wb_vad_ivas_fx( L_mssnr_hov = BASOP_Util_Add_Mant32Exp( L_mssnr_hov, L_mssnr_hov_e, L_msnr, L_msnr_e, &L_mssnr_hov_e ); /*L_mssnr_hov_e mssnr_hov += msnr; */ /* recompute after he1 modifications */ - /* snr[i] = fr_enr / st->bckr[i] = L_tmp1/st->bckr[i];*/ + /* snr[i] = fr_enr / st->bckr[i] ;*/ IF( hNoiseEst->bckr_fx[i] != 0 ) { - e_num = sub( norm_l( L_tmp1 ), 1 ); - m_num = extract_h( L_shl( L_tmp1, e_num ) ); // q_fr_bands+e_num-16 + e_num = sub( norm_l( fr_enr ), 1 ); + m_num = extract_h( L_shl( fr_enr, e_num ) ); // q_ener+1+e_num-16 e_noise = norm_l( hNoiseEst->bckr_fx[i] ); m_noise_local = extract_h( L_shl( hNoiseEst->bckr_fx[i], e_noise ) ); // hNoiseEst->q_bckr+e_noise-16 - L_snr_tmp = L_deposit_h( div_s( m_num, m_noise_local ) ); // 32+q_fr_bands+e_num-hNoiseEst->q_bckr-e_noise - q_snr_tmp = add( 31, sub( add( q_fr_bands, e_num ), add( hNoiseEst->q_bckr, e_noise ) ) ); + L_snr_tmp = L_deposit_h( div_s( m_num, m_noise_local ) ); // 31+q_ener+1+e_num-hNoiseEst->q_bckr-e_noise + q_snr_tmp = add( 32, sub( add( q_ener, e_num ), add( hNoiseEst->q_bckr, e_noise ) ) ); } ELSE { - L_snr_tmp = Mpy_32_16_1( L_tmp1, 18286 /* 1/E_MIN in Q6 */ ); // q_fr_bands-9 - q_snr_tmp = sub( q_fr_bands, 9 ); + L_snr_tmp = Mpy_32_16_1( fr_enr, 18286 /* 1/E_MIN in Q6 */ ); // q_ener+1+6-15 + q_snr_tmp = sub( q_ener, 8 ); } /* conditional snrsum, snr_sum = snr_sum + snr[i];*/ @@ -2446,11 +2454,9 @@ Word16 wb_vad_ivas_fx( move16(); } } /* end of band loop */ - L_snr_sum = L_shl_o( L_snr_sum, sub( 4, q_snr_sum ), &Overflow ); // q_snr_sum->q4 L_snr_sum_HE_SAD = L_shl_o( L_snr_sum_HE_SAD, sub( 4, q_snr_sum_HE_SAD ), &Overflow ); // q_snr_sum_HE_SAD->q4 - L_snr_outlier = L_shl_sat( L_snr_outlier, sub( Q4, q_snr ) ); // q_snr -> Q4 - snr_sumt = extract_h( L_shl( L_snr_sumt, Q4 ) ); // Q16 -> Q4 + snr_sumt = extract_h( L_shl( L_snr_sumt, Q4 ) ); // Q16 -> Q4 test(); test(); @@ -2482,51 +2488,66 @@ Word16 wb_vad_ivas_fx( } } + L_snr_outlier_Q4 = L_shl_sat( L_snr_outlier, sub( Q4, q_snr ) ); // Q4 /* Separated SNR_SUM outlier modification */ - L_snr_sum_ol = L_snr_sum; /* snr_sum_ol = snr_sum; */ + /* snr_sum_ol = snr_sum; */ + L_snr_sum_ol = L_snr_sum; // q_snr_sum + q_L_snr_sum_ol = q_snr_sum; move32(); + move16(); test(); test(); test(); - IF( ( EQ_16( st_fx->max_band, 19 ) ) && LT_32( L_snr_outlier, MAX_SNR_OUTLIER_3_FX ) && GT_16( snr_outlier_index, 3 ) && LT_16( snr_outlier_index, MAX_SNR_OUTLIER_IND_FX ) ) + IF( ( EQ_16( st_fx->max_band, 19 ) ) && LT_32( L_snr_outlier_Q4, MAX_SNR_OUTLIER_3_FX ) && GT_16( snr_outlier_index, 3 ) && LT_16( snr_outlier_index, MAX_SNR_OUTLIER_IND_FX ) ) { + q_L_snr_sum_ol = s_min( add( norm_l( L_snr_sum_ol ), q_snr_sum ), add( norm_l( L_snr_outlier ), q_snr ) ); + L_tmp1 = L_shl( L_snr_sum_ol, sub( q_L_snr_sum_ol, q_snr_sum ) ); // q_L_snr_sum_ol + L_tmp2 = L_shl( L_snr_outlier, sub( q_L_snr_sum_ol, q_snr ) ); // q_L_snr_sum_ol test(); test(); IF( LT_32( L_accum_ener_H, Mult_32_16( L_accum_ener_L, INV_OUTLIER_THR_1_FX ) ) /* float:: (accum_ener_L*INV_OUTLIER_THR_1 > accum_ener_H ) !!! */ - || LT_32( L_snr_outlier, MAX_SNR_OUTLIER_1_FX ) ) + || LT_32( L_snr_outlier_Q4, MAX_SNR_OUTLIER_1_FX ) ) { - /* as weight1 is 1.0 we do not need to multiply here , i.e. no need to loose any precisison */ - L_snr_sum_ol = L_sub( L_snr_sum_ol, L_snr_outlier ); /*Q4 */ + /* snr_sum_ol = SNR_OUTLIER_WGHT_1 * ( snr_sum_ol - snr_outlier ); + As SNR_OUTLIER_WGHT_1 is 1.0f we do not need to multiply here , i.e. no need to loose any precisison */ + L_snr_sum_ol = L_sub( L_tmp1, L_tmp2 ); // q_L_snr_sum_ol } ELSE IF( LT_32( L_accum_ener_H, Mult_32_16( L_accum_ener_L, INV_OUTLIER_THR_2_FX ) ) /* float:: (accum_ener_L *INV_OUTLIER_THR_2 > accum_ener_H ) !!! */ - || LT_32( L_snr_outlier, MAX_SNR_OUTLIER_2_FX ) ) + || LT_32( L_snr_outlier_Q4, MAX_SNR_OUTLIER_2_FX ) ) { - /* L_snr_sum = SNR_OUTLIER_WGHT_2 * (snr_sum - snr_outlier); */ - - /* 1.01*x -> (1*x + 0.01*x) to not drop down to Q3 */ - L_tmp = L_sub( L_snr_sum_ol, L_snr_outlier ); - L_tmp2 = Mult_32_16( L_tmp, 20972 ); /* 0.01(in Q21)= 20972 Q4*Q21+1-16 -> Q10 */ - L_snr_sum_ol = L_add( L_tmp, L_shr( L_tmp2, 6 ) ); /* Q4 */ + /* snr_sum_ol = SNR_OUTLIER_WGHT_2 * (snr_sum_ol - snr_outlier); */ + L_snr_sum_ol = Mpy_32_32( 1084479242 /* 1.01f in Q30 */, L_sub( L_tmp1, L_tmp2 ) ); // q_L_snr_sum_ol+30-31 + q_L_snr_sum_ol = sub( q_L_snr_sum_ol, 1 ); } ELSE { - /* L_snr_sum = SNR_OUTLIER_WGHT_3 * (snr_sum - snr_outlier);*/ - /* 1.02*x -> (1*x + 0.02*x) to not drop down to Q3 */ - L_tmp = L_sub( L_snr_sum_ol, L_snr_outlier ); - L_tmp2 = Mult_32_16( L_tmp, 20972 ); /* 0.02(in Q20)= 20972 Q4*Q20+1-16 -> Q9 */ - L_snr_sum_ol = L_add( L_tmp, L_shr( L_tmp2, 5 ) ); /* Q4 */ + /* snr_sum_ol = SNR_OUTLIER_WGHT_2 * (snr_sum_ol - snr_outlier); */ + L_snr_sum_ol = Mpy_32_32( 1095216660 /* 1.02f in Q30 */, L_sub( L_tmp1, L_tmp2 ) ); // q_L_snr_sum_ol+30-31 + q_L_snr_sum_ol = sub( q_L_snr_sum_ol, 1 ); } } /*st_fx->snr_sum_vad_fx = 0.5f * st->snr_sum_vad + 0.5f * snr_sum_ol;*/ - hVAD->L_snr_sum_vad_fx = L_shr( L_add_o( hVAD->L_snr_sum_vad_fx, L_snr_sum_ol, &Overflow ), 1 ); /*Q4*/ + q_snr_tmp = s_min( add( hVAD->q_L_snr_sum_vad, norm_l( hVAD->L_snr_sum_vad_fx ) ), add( norm_l( L_snr_sum_ol ), q_L_snr_sum_ol ) ); + /* 0.5f * st->snr_sum_vad */ + L_tmp1 = L_shl( hVAD->L_snr_sum_vad_fx, sub( sub( q_snr_tmp, 1 ), hVAD->q_L_snr_sum_vad ) ); // q_snr_tmp + /* 0.5f * snr_sum_ol */ + L_tmp2 = L_shl( L_snr_sum_ol, sub( sub( q_snr_tmp, 1 ), q_L_snr_sum_ol ) ); // q_snr_tmp + hVAD->L_snr_sum_vad_fx = L_add( L_tmp1, L_tmp2 ); // q_snr_tmp + hVAD->q_L_snr_sum_vad = q_snr_tmp; move32(); + move16(); /* snr_sum_ol = 10.0f * (float)log10( snr_sum_ol ); */ - snr_sum_ol = vad_snr_log_fx( L_snr_sum_ol, LG10 ); + e_snr = norm_l( L_snr_sum_ol ); + f_snr = Log2_norm_lc( L_shl( L_snr_sum_ol, e_snr ) ); // Q15 + e_snr = sub( sub( 30, e_snr ), q_L_snr_sum_ol ); + L_tmp = L_mac( f_snr, e_snr, ONE_IN_Q14 ); // Q15 + L_snr_sum_ol = Mpy_32_16_1( L_tmp, 24660 /* 10*log(2) in Q13 */ ); // Q13 + snr_sum_ol = extract_h( L_shl( L_snr_sum_ol, Q24 - Q13 ) ); // Q8 snr_sum = snr_sum_ol; move16(); /* note for NB no outlier modification */ @@ -2555,9 +2576,9 @@ Word16 wb_vad_ivas_fx( /*thr1 = nk * lp_snr + nc*1.0 + nv * ( st->Etot_v_h2 - nv_ofs); */ /* Linear function for noisy speech */ - L_tmp = L_shl( L_mult( sub( hNoiseEst->Etot_v_h2_fx, nv_ofs ), nv ), 7 ); /* Q8+Q8+1 +7 --> Q24 */ - L_tmp = L_mac( L_tmp, nc, (Word16) 32767 ); /* Q8+Q15+1 = Q24 */ - thr1 = mac_r( L_tmp, lp_snr, nk ); /* Q8+Q15+1 - 16 --> Q8 */ + L_tmp = L_shl( Mpy_32_16_1( L_sub( hNoiseEst->Etot_v_h2_32fx, nv_ofs ), nv ), 3 ); // Q24 (24+12-15+3) + L_tmp = L_add( L_tmp, nc ); // Q24 + thr1 = mac_r( L_tmp, lp_snr, nk ); // Q24 test(); IF( st_fx->element_mode > EVS_MONO && LT_16( hNoiseEst->first_noise_updt_cnt, 100 ) ) @@ -2624,33 +2645,38 @@ Word16 wb_vad_ivas_fx( test(); IF( ( LE_16( snr_outlier_index, 4 ) && ( st_fx->last_coder_type > UNVOICED ) && !st_fx->Opt_SC_VBR ) || ( LE_16( snr_outlier_index, 4 ) && ( last_7k2_coder_type > UNVOICED ) && st_fx->Opt_SC_VBR ) ) - - { - thr1_ol = sub( thr1_ol, (Word16) ( 1 << 8 ) ); /*thr1_ol = thr1 - 1.0f ; */ + /*thr1_ol = thr1 - 1.0f ; */ + thr1_ol = sub( thr1, ONE_IN_Q8 ); // Q8 + /*snr_sum_ol = 10.0f * (float)log10( hVAD->L_snr_sum_vad_fx );*/ - snr_sum_ol = vad_snr_log_fx( hVAD->L_snr_sum_vad_fx, LG10 ); /* snr in Q8 */ + e_snr = norm_l( hVAD->L_snr_sum_vad_fx ); + f_snr = Log2_norm_lc( L_shl( hVAD->L_snr_sum_vad_fx, e_snr ) ); // Q15 + e_snr = sub( sub( 30, e_snr ), hVAD->q_L_snr_sum_vad ); + L_tmp = L_mac( f_snr, e_snr, ONE_IN_Q14 ); // Q15 + L_snr_sum_ol = Mpy_32_16_1( L_tmp, 24660 /* 10*log(2) in Q13 */ ); // Q13 + snr_sum_ol = round_fx( L_shl( L_snr_sum_ol, Q24 - Q13 ) ); // Q8 } - ELSE IF( ( ( LE_16( st_fx->last_coder_type, UNVOICED ) ) && ( LT_32( L_snr_outlier, MAX_SNR_OUTLIER_2_FX ) ) && ( st_fx->Opt_SC_VBR == 0 ) ) || - ( ( LE_16( last_7k2_coder_type, UNVOICED ) ) && ( LT_32( L_snr_outlier, MAX_SNR_OUTLIER_2_FX ) ) && ( st_fx->Opt_SC_VBR != 0 ) ) ) - + ELSE IF( ( ( LE_16( st_fx->last_coder_type, UNVOICED ) ) && ( LT_32( L_snr_outlier_Q4, MAX_SNR_OUTLIER_2_FX ) ) && ( st_fx->Opt_SC_VBR == 0 ) ) || + ( ( LE_16( last_7k2_coder_type, UNVOICED ) ) && ( LT_32( L_snr_outlier_Q4, MAX_SNR_OUTLIER_2_FX ) ) && ( st_fx->Opt_SC_VBR != 0 ) ) ) { /* thr1_ol = thr1 + (float)(1.0f - 0.04f * snr_outlier); */ - L_tmp2 = Msub_32_16( (Word32) ( 1 << ( 24 - 16 ) ), L_snr_outlier, 20972 ); /* (1.0)Q24(Q8 in high 32bit word) - Q4*Q19+1 */ - tmp2 = round_fx( L_shl( L_tmp2, 16 ) ); /* high word is in Q8 */ - thr1_ol = add( thr1_ol, tmp2 ); /* (Q8 , Q8) */ + L_tmp = Mpy_32_16_1( L_snr_outlier, 20972 /*0.04f in Q19*/ ); // q_snr+19-15 + L_tmp = L_shl( L_tmp, sub( Q24 - 4, q_snr ) ); // Q24 (24-(q_nsr+4)) + tmp2 = round_fx( L_sub( ONE_IN_Q24, L_tmp ) ); // Q8 + thr1_ol = add( thr1, tmp2 ); // Q8 } ELSE { - /*thr1_ol = thr1 + max(0, (float)(0.6f - 0.01f * L_snr_outlier)); */ - thr1_ol = thr1; - move16(); - L_tmp2 = Msub_32_16( (Word32) 614, L_snr_outlier, 20972 ); /* .6*1024= */ /* 0.6 Q26(Q10 in high word) - Q4*Q21+1 */ - tmp2 = round_fx( L_shl_o( L_tmp2, 14, &Overflow ) ); /* Q10(high word)+ 14 -16 --> Q8*/ - IF( L_tmp2 > 0 ) - { - thr1_ol = add( thr1_ol, tmp2 ); /* Q24 >>16 + Q8 */ - } + /*thr1_ol = thr1 + max(0, (float)(0.6f - 0.01f * snr_outlier)); */ + /* Saturation is added in the below step for 0.04f * snr_outlier in Q24. + In case of saturation, 0.04f * snr_outlier will be much greater than 0.6f and (0.6f - 0.01f * snr_outlier) becomes negative. + max(0, (float)(0.6f - 0.01f * snr_outlier)) gives zero. Hence addition of saturation has no impact */ + L_tmp = Mpy_32_16_1( L_snr_outlier, 20972 /*0.04f in Q21*/ ); // q_snr+21-15 + L_tmp = L_shl_sat( L_tmp, sub( Q24 - 6, q_snr ) ); // Q24 (24-(q_nsr+6)) + tmp2 = round_fx( L_sub( 10066330 /* 0.6 in Q24*/, L_tmp ) ); // Q8 + tmp2 = s_max( 0, tmp2 ); // Q8 + thr1_ol = add( thr1, tmp2 ); // Q8 } }