diff --git a/lib_enc/find_tilt.c b/lib_enc/find_tilt.c index 59a7412fd5b4392ad354db5e6b1581ecd0579597..0c07d03a12d5419a992f0e39693b45bb27cea13e 100644 --- a/lib_enc/find_tilt.c +++ b/lib_enc/find_tilt.c @@ -56,22 +56,22 @@ * Find LF/HF energy ratio *-------------------------------------------------------------------*/ void find_tilt_ivas_fx( - const Word32 fr_bands[], /* i : energy in frequency bands Q_new*/ - const Word32 bckr[], /* i : per band background noise energy estimate Q_new*/ - Word32 ee[2], /* o : lf/hf E ration for present frame Q6*/ - const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ - const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ - const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new - 2*/ - const Word16 corr_shift, /* i : normalized correlation correction Q15*/ - const Word16 bwidth, /* i : input signal bandwidth Q0*/ - const Word16 max_band, /* i : maximum critical band Q0*/ - Word32 hp_E[], /* o : energy in HF Q_new*/ - const Word16 codec_mode, /* i : MODE1 or MODE2 Q0*/ - const Word16 Q_new, /* i : scaling factor */ - Word32 *bckr_tilt_lt /* i/o: lf/hf E ratio of background noise Q16*/ - , - Word16 Opt_vbr_mode /* Q0 */ -) + const Word32 fr_bands[], /* i : energy in frequency bands q_fr_bands*/ + const Word16 q_fr_bands, /* i : Q of fr_bands Q0*/ + const Word32 bckr[], /* i : per band background noise energy estimate q_bckr*/ + const Word16 q_bckr, /* i : Q of bckr Q0*/ + Word32 ee[2], /* o : lf/hf E ration for present frame Q6*/ + const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ + const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ + const Word32 *lf_E, /* i : per bin energy for low frequencies q_lf_E*/ + const Word16 q_lf_E, /* i : Q of lf_E */ + const Word16 corr_shift, /* i : normalized correlation correction Q15*/ + const Word16 bwidth, /* i : input signal bandwidth */ + const Word16 max_band, /* i : maximum critical band */ + Word32 hp_E[], /* o : energy in HF Q_new*/ + const Word16 codec_mode, /* i : MODE1 or MODE2 */ + Word32 *bckr_tilt_lt, /* i/o: lf/hf E ratio of background noise Q16 */ + Word16 Opt_vbr_mode ) { Word32 lp_bckr = 0, hp_bckr = 0, lp_E, Ltmp; const Word32 *pt_E, *pt_bands, *pt_bckr, *hf_bands, *tmp_E; @@ -81,6 +81,9 @@ void find_tilt_ivas_fx( Word16 m_Fs, e_Fs; Word16 m_cnt, e_cnt; Word16 m_hpE, e_hpE; + Word64 sum; + Word16 inv_bands, q_lp_E; + Word32 Le_min_scaled, Ltmp2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); @@ -91,7 +94,7 @@ void find_tilt_ivas_fx( * Initializations *-----------------------------------------------------------------*/ - IF( NE_16( bwidth, NB ) ) + IF( ( bwidth != NB ) ) { /* WB processing */ bin = BIN4_FX; @@ -100,16 +103,20 @@ void find_tilt_ivas_fx( tmp_E = lf_E; /* Q_new - 2 */ pt_bckr = bckr; /* Q_new */ nb_bands = 10; + inv_bands = 3277 /* 1/10 in Q15 */; + move16(); move16(); } ELSE { /* NB processing */ - bin = add( shl( BIN4_FX, 1 ), BIN4_FX ); /* First useful frequency bin ~ 150 Hz */ - pt_bands = fr_bands + 1; /* Exlcude 1st critical band */ - tmp_E = lf_E + 2; /* Start at the 3rd bin (150 Hz) */ - pt_bckr = bckr + 1; /* Exlcude 1st critical band */ + bin = 3 * BIN4_FX; /* First useful frequency bin ~ 150 Hz */ + pt_bands = fr_bands + 1; /* Exlcude 1st critical band */ + tmp_E = lf_E + 2; /* Start at the 3rd bin (150 Hz) */ + pt_bckr = bckr + 1; /* Exlcude 1st critical band */ nb_bands = 9; + inv_bands = 3641; /* 1/9 in Q15 */ + move16(); move16(); /* Nb. of "low" frequency bands taken into account in NB processing */ } @@ -122,21 +129,23 @@ void find_tilt_ivas_fx( /* bckr + voicing */ /*lp_bckr = mean( pt_bckr, nb_bands );*/ /* estimated noise E in first critical bands, up to 1270 Hz */ - lp_bckr = Mean32( pt_bckr, nb_bands ); - /*hp_bckr = 0.5f * (bckr[max_band-1] + bckr[max_band]);*/ /* estimated noise E in last 2 critical bands */ -#ifdef BASOP_NOGLOB - hp_bckr = L_shr( L_add_sat( bckr[max_band - 1], bckr[max_band] ), 1 ); /* Q_new - 1 */ -#else - hp_bckr = L_shr( L_add( bckr[max_band - 1], bckr[max_band] ), 1 ); -#endif - if ( hp_bckr == 0 ) /* Avoid division by zero. */ + sum = 0; + move64(); + FOR( i = 0; i < nb_bands; i++ ) + { + sum = W_mac_32_16( sum, pt_bckr[i], inv_bands ); // q_bckr+16 + } + lp_bckr = W_shl_sat_l( sum, -16 ); // q_bckr + /*hp_bckr = 0.5f * (bckr[max_band-1] + bckr[max_band]);*/ /* estimated noise E in last 2 critical bands */ + hp_bckr = W_extract_h( W_mac_32_32( W_mult_32_32( bckr[max_band - 1], ONE_IN_Q30 ), bckr[max_band], ONE_IN_Q30 ) ); // q_bckr + if ( hp_bckr == 0 ) /* Avoid division by zero. */ { hp_bckr = L_deposit_l( 1 ); } - Ltmp = BASOP_Util_Divide3232_Scale_cadence( lp_bckr, hp_bckr, &e_tmp ); /* exp(e_tmp) */ - Ltmp = Mpy_32_16_r( Ltmp, 3277 /* 0.1 in Q15 */ ); + Ltmp = BASOP_Util_Divide3232_Scale_cadence( lp_bckr, hp_bckr, &e_tmp ); + Ltmp = Mpy_32_16_r( Ltmp, 3277 /* 0.1f in Q15 */ ); Ltmp = L_shr_sat( Ltmp, sub( 15, e_tmp ) ); - *bckr_tilt_lt = L_add_sat( Mpy_32_16_r( *bckr_tilt_lt, 29491 ), Ltmp ); /* Q16 */ + *bckr_tilt_lt = L_add_sat( Mpy_32_16_r( *bckr_tilt_lt, 29491 /* 0.9f in Q15 */ ), Ltmp ); // Q16 move32(); test(); @@ -171,34 +180,31 @@ void find_tilt_ivas_fx( e_Fs = sub( 15, e_tmp ); f0 = shr( m_Fs, sub( e_Fs, 4 ) ); /* Q4 */ + Le_min_scaled = L_shl( E_MIN_FXQ31, sub( q_fr_bands, Q31 ) ); // q_fr_bands=q_bckr + FOR( i = 0; i < 2; i++ ) { - /*hp_E[i] = 0.5f * (hf_bands[max_band-1] + hf_bands[max_band]) - hp_bckr; */ /* averaged E in last 2 critical bands */ - Ltmp = L_add( L_shr( hf_bands[max_band - 1], 1 ), L_shr( hf_bands[max_band], 1 ) ); /* Q_new */ - hp_E[i] = L_sub( Ltmp, hp_bckr ); /* Q_new */ - move32(); - IF( Opt_vbr_mode == 0 ) - { - IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( hp_E[i], sub( 31, Q_new ), E_MIN_IVAS_FX, 31 - Q19 ), -1 ) ) - { - hp_E[i] = L_shl( E_MIN_IVAS_FX, sub( Q_new, Q19 ) ); - move32(); - } - } - ELSE + /*hp_E[i] = 0.5f * (hf_bands[max_band-1] + hf_bands[max_band]) - hp_bckr; */ /* averaged E in last 2 critical bands */ + Ltmp = W_extract_h( W_mac_32_32( W_mult_32_32( hf_bands[max_band - 1], ONE_IN_Q30 ), hf_bands[max_band], ONE_IN_Q30 ) ); // q_fr_bands + Ltmp = L_sub( Ltmp, hp_bckr ); // q_fr_bands + + Ltmp2 = L_max( Ltmp, L_shl_sat( 1, q_fr_bands ) ); // q_fr_bands, saturation is added because q_fr_bands is limited to 31 + if ( Opt_vbr_mode == 0 ) { - hp_E[i] = L_max( hp_E[i], L_shl( 1, Q_new ) ); - move32(); + Ltmp2 = L_max( Ltmp, Le_min_scaled ); // q_fr_bands } + hp_E[i] = L_max( Ltmp2, 1 ); // to prevent division by zero + move32(); test(); IF( GT_16( mean_voi, TH_COR_FX ) && LT_16( pitch[2], TH_PIT_FX ) ) /* High-pitched voiced frames */ { - freq = bin; - move16(); /* 1st useful frequency bin */ + freq = bin; // Q4 + move16(); /* 1st useful frequency bin */ m_cnt = 0; move16(); - lp_E = L_deposit_l( 0 ); + sum = 0; + move64(); f1 = add( shr( f0, 1 ), f0 ); /* Middle between 2 harmonics */ f2 = f0; @@ -208,14 +214,10 @@ void find_tilt_ivas_fx( FOR( ; freq <= f1; freq += BIN4_FX ) { /* include only bins sufficiently close to harmonics */ - tmp = sub( freq, f2 ); /* Q4 */ - IF( L_mac0( -(Word32) TH_D_FX * TH_D_FX, tmp, tmp ) < 0 ) + tmp = sub( freq, f2 ); + IF( L_mac0( -TH_D_FX * TH_D_FX, tmp, tmp ) < 0 ) { -#ifdef BASOP_NOGLOB - lp_E = L_add_o( *pt_E, lp_E, &Overflow ); /* Q_new - 1 */ -#else - lp_E = L_add( *pt_E, lp_E ); -#endif + sum = W_mac_32_16( sum, *pt_E, 1 ); // q_lf_E+1 m_cnt = add( m_cnt, 1 ); } pt_E++; @@ -229,52 +231,65 @@ void find_tilt_ivas_fx( #endif } /*lp_E = lp_E / (float)cnt - lp_bckr;*/ - e_tmp = sub( norm_l( lp_E ), 1 ); - m_tmp = extract_h( L_shl( lp_E, e_tmp ) ); - - e_tmp = sub( e_tmp, 2 ); /* lf_e divided by 4 in anal_sp */ + e_tmp = sub( W_norm( sum ), 1 ); + m_tmp = extract_h( W_extract_h( W_shl( sum, e_tmp ) ) ); // q_lf_E+1+e_tmp-32-16 + e_tmp = sub( add( q_lf_E, e_tmp ), 47 ); e_cnt = norm_s( m_cnt ); - m_cnt = shl( m_cnt, e_cnt ); - - m_tmp = div_s( m_tmp, m_cnt ); - e_tmp = sub( e_tmp, e_cnt ); + m_cnt = shl( m_cnt, e_cnt ); // e_cnt -#ifdef BASOP_NOGLOB - lp_E = L_sub_o( L_shr_o( m_tmp, sub( e_tmp, 1 ), &Overflow ), lp_bckr, &Overflow ); -#else - lp_E = L_sub( L_shr( m_tmp, sub( e_tmp, 1 ) ), lp_bckr ); -#endif + m_tmp = div_s( m_tmp, m_cnt ); // Q15+e_tmp-e_cnt + e_tmp = add( Q15, sub( e_tmp, e_cnt ) ); + sum = W_shl( m_tmp, sub( add( q_bckr, 1 ), e_tmp ) ); // q_bckr+1 + sum = W_msu_32_16( sum, lp_bckr, 1 ); // q_bckr+1 + q_lp_E = W_norm( sum ); + lp_E = W_extract_h( W_shl( sum, q_lp_E ) ); // q_bckr+1+q_lp_E-32 + q_lp_E = sub( add( q_lp_E, q_bckr ), Q31 ); pt_E = tmp_E + VOIC_BINS; /* Update for next half-frame Q_new - 1 */ } ELSE /* Other than high-pitched voiced frames */ { /*lp_E = mean( pt_bands, nb_bands ) - lp_bckr;*/ /* averaged E in first critical bands, up to 1270 Hz */ - lp_E = L_sub( Mean32( pt_bands, nb_bands ), lp_bckr ); - } - IF( Opt_vbr_mode == 0 ) - { - IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( lp_E, sub( 31, Q_new ), E_MIN_IVAS_FX, 31 - Q19 ), -1 ) ) + sum = 0; + move64(); + FOR( Word16 j = 0; j < nb_bands; j++ ) { - lp_E = L_shl( E_MIN_IVAS_FX, sub( Q_new, Q19 ) ); + sum = W_mac_32_16( sum, pt_bands[j], inv_bands ); // q_fr_bands+16 } + sum = W_mac_32_16( sum, lp_bckr, -ONE_IN_Q15 ); // q_fr_bands+16 + lp_E = W_round48_L( sum ); // q_fr_bands=q_bckr + q_lp_E = q_bckr; // q_fr_bands=q_bckr + move16(); + } + test(); + IF( Opt_vbr_mode == 0 && GT_32( L_shl_sat( Le_min_scaled, sub( q_lp_E, q_bckr ) ), lp_E ) ) + { + lp_E = E_MIN_FXQ31; + q_lp_E = Q31; + move32(); + move16(); } - ELSE + if ( Opt_vbr_mode != 0 ) { - lp_E = L_max( lp_E, 0 ); + lp_E = L_max( lp_E, 0 ); // q_lp_E } /*ee[i] = lp_E / hp_E[i];*/ /* LF/HF ratio */ + + if ( lp_E == 0 ) + { + ee[i] = 0; + move32(); + } test(); - IF( lp_E != 0 && hp_E[i] != 0 ) + IF( lp_E != 0 ) { e_tmp = sub( norm_l( lp_E ), 1 ); - m_tmp = extract_h( L_shl( lp_E, e_tmp ) ); + m_tmp = extract_h( L_shl( lp_E, e_tmp ) ); // e_tmp+q_lp_E-16 e_hpE = norm_l( hp_E[i] ); - m_hpE = extract_h( L_shl( hp_E[i], e_hpE ) ); - m_tmp = div_s( m_tmp, m_hpE ); /* e_tmp + e_hpE */ - e_tmp = sub( e_tmp, e_hpE ); - + m_hpE = extract_h( L_shl( hp_E[i], e_hpE ) ); // e_hpE+q_bckr-16 + m_tmp = div_s( m_tmp, m_hpE ); // Q15+(e_tmp+q_lp_E)-(e_hpE+q_bckr) + e_tmp = sub( add( e_tmp, q_lp_E ), add( e_hpE, q_bckr ) ); #ifdef BASOP_NOGLOB ee[i] = L_shr_o( m_tmp, add( e_tmp, 15 - 6 ), &Overflow ); /* ee in Q6 */ #else /* BASOP_NOGLOB */ @@ -282,18 +297,8 @@ void find_tilt_ivas_fx( #endif move32(); } - ELSE IF( lp_E == 0 ) - { - ee[i] = L_deposit_l( 0 ); - move32(); - } - ELSE - { - ee[i] = MAX_32; - move32(); - } - IF( EQ_16( bwidth, NB ) ) /* For NB input, compensate for the missing bands */ + IF( bwidth == NB ) /* For NB input, compensate for the missing bands */ { #ifdef BASOP_NOGLOB Ltmp = L_shl_o( ee[i], 3, &Overflow ); /* Q6 */ diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 20f2be0cfd5a168ea7e440c1c7d58d7e7ce4d9ab..090a880607fc28bc20746d6f9549695873fabe84 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -1267,25 +1267,6 @@ ivas_error pre_proc_front_ivas_fx( st->old_pitch_la = st->pitch[2]; /* Q0 */ move16(); - /*Scaling to avoid 0 values*/ - shift = L_norm_arr( st->hNoiseEst->enrO_fx, NB_BANDS ); - scale_sig32( st->hNoiseEst->enrO_fx, NB_BANDS, shift ); - st->hNoiseEst->q_enrO = add( st->hNoiseEst->q_enrO, shift ); - move16(); - - test(); - IF( lr_vad_enabled && st->idchan == 0 ) - { - /*Scaling to avoid 0 values*/ - FOR( Word16 j = 0; j < 2; j++ ) - { - shift = L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->enrO_fx, NB_BANDS ); - scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->enrO_fx, NB_BANDS, shift ); - hCPE->hFrontVad[j]->hNoiseEst->q_enrO = add( hCPE->hFrontVad[j]->hNoiseEst->q_enrO, shift ); - move16(); - } - } - shift = sub( norm_arr( old_wsp_fx, L_WSP ), 3 ); scale_sig( old_wsp_fx, L_WSP, shift ); @@ -1294,119 +1275,6 @@ ivas_error pre_proc_front_ivas_fx( Q_wsp = *q_old_wsp; move16(); - Word16 q_fr_bands = Q30; - move16(); - - shift = L_norm_arr( tmpN_fx, NB_BANDS ); - q_fr_bands = s_min( q_fr_bands, add( q_tmpN, shift ) ); - shift = L_norm_arr( tmpE_fx, NB_BANDS ); - q_fr_bands = s_min( q_fr_bands, add( q_tmpE, shift ) ); - shift = L_norm_arr( fr_bands_fx, 2 * NB_BANDS ); - q_fr_bands = s_min( q_fr_bands, sub( add( fr_bands_fx_q, shift ), 4 ) /* needs 4 gaurd bits for summation */ ); - shift = L_norm_arr( st->hNoiseEst->bckr_fx, NB_BANDS ); - q_fr_bands = s_min( q_fr_bands, add( st->hNoiseEst->q_bckr, shift ) ); - shift = s_min( L_norm_arr( st->hNoiseEst->fr_bands1_fx, NB_BANDS ), L_norm_arr( st->hNoiseEst->fr_bands2_fx, NB_BANDS ) ); - q_fr_bands = s_min( q_fr_bands, add( st->hNoiseEst->fr_bands_fx_q, shift ) ); - shift = s_min( L_norm_arr( st->hNoiseEst->ave_enr_fx, NB_BANDS ), L_norm_arr( st->hNoiseEst->ave_enr2_fx, NB_BANDS ) ); - q_fr_bands = s_min( q_fr_bands, add( st->hNoiseEst->ave_enr_q, shift ) ); - shift = L_norm_arr( lf_E_fx, 2 * VOIC_BINS ); - q_fr_bands = s_min( q_fr_bands, add( add( q_lf_E_fx, shift ), 2 ) ); - - test(); - IF( lr_vad_enabled && st->idchan == 0 ) - { - shift = s_min( L_norm_arr( lf_E_LR_fx[0], 2 * VOIC_BINS ), L_norm_arr( lf_E_LR_fx[1], 2 * VOIC_BINS ) ); - q_fr_bands = s_min( q_fr_bands, add( add( lf_E_LR_fx_q, shift ), 2 ) ); - FOR( Word16 j = 0; j < 2; j++ ) - { - shift = L_norm_arr( fr_bands_LR_fx[j], 2 * NB_BANDS ); - q_fr_bands = s_min( q_fr_bands, add( fr_bands_LR_fx_q[j], shift ) ); - shift = L_norm_arr( tmpN_LR_fx[j], NB_BANDS ); - q_fr_bands = s_min( q_fr_bands, add( q_tmpN_LR[j], shift ) ); - shift = L_norm_arr( tmpE_LR_fx[j], NB_BANDS ); - q_fr_bands = s_min( q_fr_bands, add( q_tmpE_LR[j], shift ) ); - shift = L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, NB_BANDS ); - q_fr_bands = s_min( q_fr_bands, add( hCPE->hFrontVad[j]->hNoiseEst->q_bckr, shift ) ); - shift = s_min( L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx, NB_BANDS ), L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx, NB_BANDS ) ); - q_fr_bands = s_min( q_fr_bands, add( hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q, shift ) ); - shift = 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 ) ); - q_fr_bands = s_min( q_fr_bands, add( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q, shift ) ); - } - } - - scale_sig32( tmpN_fx, NB_BANDS, sub( q_fr_bands, q_tmpN ) ); - q_tmpN = q_fr_bands; - move16(); - - scale_sig32( tmpE_fx, NB_BANDS, sub( q_fr_bands, q_tmpE ) ); - q_tmpE = q_fr_bands; - move16(); - - scale_sig32( fr_bands_fx, 2 * NB_BANDS, sub( q_fr_bands, fr_bands_fx_q ) ); - fr_bands_fx_q = q_fr_bands; - move16(); - - scale_sig32( st->hNoiseEst->bckr_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->q_bckr ) ); - st->hNoiseEst->q_bckr = q_fr_bands; - move16(); - - scale_sig32( st->hNoiseEst->fr_bands1_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->fr_bands_fx_q ) ); - scale_sig32( st->hNoiseEst->fr_bands2_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->fr_bands_fx_q ) ); - st->hNoiseEst->fr_bands_fx_q = q_fr_bands; - move16(); - - scale_sig32( st->hNoiseEst->ave_enr_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->ave_enr_q ) ); - scale_sig32( st->hNoiseEst->ave_enr2_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->ave_enr_q ) ); - st->hNoiseEst->ave_enr_q = q_fr_bands; - move16(); - - scale_sig32( lf_E_fx, 2 * VOIC_BINS, sub( sub( q_fr_bands, 2 ), q_lf_E_fx ) ); - q_lf_E_fx = sub( q_fr_bands, 2 ); - - test(); - IF( lr_vad_enabled && st->idchan == 0 ) - { - FOR( Word16 j = 0; j < 2; j++ ) - { - scale_sig32( lf_E_LR_fx[j], 2 * VOIC_BINS, sub( sub( q_fr_bands, 2 ), lf_E_LR_fx_q ) ); - scale_sig32( fr_bands_LR_fx[j], 2 * NB_BANDS, sub( q_fr_bands, fr_bands_LR_fx_q[j] ) ); - - scale_sig32( tmpN_LR_fx[j], NB_BANDS, sub( q_fr_bands, q_tmpN_LR[j] ) ); - q_tmpN_LR[j] = q_fr_bands; - move16(); - - scale_sig32( tmpE_LR_fx[j], NB_BANDS, sub( q_fr_bands, q_tmpE_LR[j] ) ); - q_tmpE_LR[j] = q_fr_bands; - move16(); - - scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->q_bckr ) ); - hCPE->hFrontVad[j]->hNoiseEst->q_bckr = q_fr_bands; - move16(); - - scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q ) ); - scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q ) ); - hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q = q_fr_bands; - move16(); - - FOR( Word16 k = 0; k < NB_BANDS; k++ ) - { - hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx[k] = L_max( 1, hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx[k] ); - move32(); - hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx[k] = L_max( 1, hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx[k] ); - move32(); - } - - scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q ) ); - scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr2_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q ) ); - hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q = q_fr_bands; - move16(); - fr_bands_LR_fx_q[j] = q_fr_bands; - move16(); - } - lf_E_LR_fx_q = q_fr_bands; - move16(); - } - Copy_Scale_sig_32_16( st->Bin_E_fx, st->lgBin_E_fx, L_FFT / 2, sub( Q7, st->q_Bin_E ) ); /* Q7 */ /* Detection of very short stable pitch period */ StableHighPitchDetect_ivas_fx( &flag_spitch, st->pitch, st->voicing_fx, wsp_fx, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, *q_old_wsp, st->lgBin_E_fx ); @@ -1444,26 +1312,96 @@ ivas_error pre_proc_front_ivas_fx( /*------------------------------------------------------------------* * Update estimated noise energy and voicing cut-off frequency *-----------------------------------------------------------------*/ - - FOR( Word16 k = 0; k < NB_BANDS; k++ ) { - fr_bands_fx[k] = L_max( 1, fr_bands_fx[k] ); - move32(); + // TODO: this scalings to be checked + scale = s_min( Q30, add( st->hNoiseEst->q_bckr, L_norm_arr( st->hNoiseEst->bckr_fx, NB_BANDS ) ) ); + scale = s_min( scale, sub( add( fr_bands_fx_q, L_norm_arr( fr_bands_fx, 2 * NB_BANDS ) ), 4 ) ); + scale_sig32( st->hNoiseEst->bckr_fx, NB_BANDS, sub( scale, st->hNoiseEst->q_bckr ) ); + scale_sig32( fr_bands_fx, 2 * NB_BANDS, sub( scale, fr_bands_fx_q ) ); + st->hNoiseEst->q_bckr = fr_bands_fx_q = scale; } - noise_est_ivas_fx( st, old_pitch1, tmpN_fx, epsP_h, epsP_l, Etot_fx, *relE_fx, corr_shift_fx, tmpE_fx, fr_bands_fx, cor_map_sum_fx, &ncharX_fx, &sp_div_fx, &q_sp_div, - &non_staX_fx, loc_harm, lf_E_fx, &st->hNoiseEst->harm_cor_cnt, st->hNoiseEst->Etot_l_lp_fx, st->hNoiseEst->Etot_v_h2_fx, &st->hNoiseEst->bg_cnt, st->lgBin_E_fx, sub( q_fr_bands, QSCALE ), L_shl( E_MIN_IVAS_FX, sub( q_fr_bands, Q19 ) ), &dummy_fx, S_map_fx, hStereoClassif, NULL, st->ini_frame ); + 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 ) ) ) ); + 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 ) ); + scale_sig32( st->hNoiseEst->ave_enr_fx, NB_BANDS, sub( scale, st->hNoiseEst->ave_enr_q ) ); + scale_sig32( st->hNoiseEst->ave_enr2_fx, NB_BANDS, sub( scale, st->hNoiseEst->ave_enr_q ) ); + st->hNoiseEst->ave_enr_q = q_tmpE = scale; + move16(); + move16(); + + scale = add( st->hNoiseEst->fr_bands_fx_q, s_min( L_norm_arr( st->hNoiseEst->fr_bands1_fx, NB_BANDS ), L_norm_arr( st->hNoiseEst->fr_bands2_fx, NB_BANDS ) ) ); + scale = s_min( scale, 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->fr_bands1_fx, NB_BANDS, sub( scale, st->hNoiseEst->fr_bands_fx_q ) ); + scale_sig32( st->hNoiseEst->fr_bands2_fx, NB_BANDS, sub( scale, st->hNoiseEst->fr_bands_fx_q ) ); + st->hNoiseEst->fr_bands_fx_q = fr_bands_fx_q = scale; + move16(); + move16(); + + noise_est_ivas_fx( st, old_pitch1, tmpN_fx, epsP_fx, 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, st->hNoiseEst->Etot_l_lp_fx, + st->hNoiseEst->Etot_v_h2_fx, &st->hNoiseEst->bg_cnt, st->lgBin_E_fx, &dummy_fx, S_map_fx, + hStereoClassif, NULL, st->ini_frame ); + test(); IF( lr_vad_enabled && st->idchan == 0 ) { + 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 ); + scale_sig32( tmpE_LR_fx[j], NB_BANDS, sub( scale, q_tmpE_LR[j] ) ); + scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_fx, NB_BANDS, sub( scale, hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q ) ); + scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr2_fx, NB_BANDS, sub( scale, hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q ) ); + hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q = q_tmpE_LR[j] = scale; + move16(); + move16(); + + scale = add( hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q, s_min( L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx, NB_BANDS ), L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx, NB_BANDS ) ) ); + scale = s_min( scale, add( fr_bands_LR_fx_q[j], L_norm_arr( fr_bands_LR_fx[j], 2 * NB_BANDS ) ) ); + scale_sig32( fr_bands_LR_fx[j], 2 * NB_BANDS, sub( scale, fr_bands_LR_fx_q[j] ) ); + scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx, NB_BANDS, sub( scale, hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q ) ); + scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx, NB_BANDS, sub( scale, hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q ) ); + hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q = fr_bands_LR_fx_q[j] = scale; + move16(); + move16(); + } + + *loc_harmLR_fx = *loc_harm; + move16(); + /* Run noise_est for Left and Right channel */ - *loc_harmLR_fx = *loc_harm; /* Q0 */ - noise_est_ivas_fx( st, old_pitch1, tmpN_LR_fx[0], epsP_h, epsP_l, Etot_LR_fx[0], sub( Etot_LR_fx[0], hCPE->hFrontVad[0]->lp_speech_fx ), corr_shiftL_fx, tmpE_LR_fx[0], fr_bands_LR_fx[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], &hCPE->hFrontVad[0]->hNoiseEst->harm_cor_cnt, hCPE->hFrontVad[0]->hNoiseEst->Etot_l_lp_fx, hCPE->hFrontVad[0]->hNoiseEst->Etot_v_h2_fx, &hCPE->hFrontVad[0]->hNoiseEst->bg_cnt, st->lgBin_E_fx, sub( q_fr_bands, QSCALE ), L_shl( E_MIN_IVAS_FX, sub( q_fr_bands, Q19 ) ), &dummy_fx, S_map_LR_fx, NULL, hCPE->hFrontVad[0], hCPE->hFrontVad[0]->ini_frame ); + 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, + hCPE->hFrontVad[0]->hNoiseEst->Etot_l_lp_fx, hCPE->hFrontVad[0]->hNoiseEst->Etot_v_h2_fx, &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_h, epsP_l, Etot_LR_fx[1], sub( Etot_LR_fx[1], hCPE->hFrontVad[1]->lp_speech_fx ), corr_shiftR_fx, tmpE_LR_fx[1], fr_bands_LR_fx[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], &hCPE->hFrontVad[1]->hNoiseEst->harm_cor_cnt, hCPE->hFrontVad[1]->hNoiseEst->Etot_l_lp_fx, hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2_fx, &hCPE->hFrontVad[1]->hNoiseEst->bg_cnt, st->lgBin_E_fx, sub( q_fr_bands, QSCALE ), L_shl( E_MIN_IVAS_FX, sub( q_fr_bands, Q19 ) ), &dummy_fx, S_map_LR_fx, NULL, hCPE->hFrontVad[1], hCPE->hFrontVad[0]->ini_frame ); + 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, + hCPE->hFrontVad[1]->hNoiseEst->Etot_l_lp_fx, hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2_fx, &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 ); } /*------------------------------------------------------------------* @@ -1480,10 +1418,18 @@ ivas_error pre_proc_front_ivas_fx( * Find spectral tilt * UC and VC frame selection *-----------------------------------------------------------------*/ - find_tilt_ivas_fx( fr_bands_fx, st->hNoiseEst->bckr_fx, ee_fx, st->pitch, st->voicing_fx, lf_E_fx, corr_shift_fx, st->input_bwidth, st->max_band, hp_E_fx, MODE1, q_fr_bands, - &( st->bckr_tilt_lt ), st->Opt_SC_VBR ); + 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(); + 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, + 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, Etot_fx, hp_E_fx, &flag_spitch, last_core_orig, hStereoClassif, *Q_new /*q_inp_12k8*/, q_fr_bands ); // Q0 + 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, Etot_fx, hp_E_fx, + &flag_spitch, last_core_orig, hStereoClassif, *Q_new /*q_inp_12k8*/, fr_bands_fx_q ); // Q0 Copy_Scale_sig_16_32( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) ); diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 5467d7854ab6ee0639860d08cf55b6859a71009a..d5be6f0605c17cce4b431384e2978b65e8a4f3de 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -196,7 +196,6 @@ ivas_error front_vad_fx( set_val_Word32( band_energies_LR_fx, 0, 2 * NB_BANDS ); Qband = -1; move16(); - Word16 Q_new_old = add( sub( Q_inp, Qband ), Q_add ); IF( *front_create_flag ) { @@ -205,8 +204,6 @@ ivas_error front_vad_fx( move16(); FOR( n = 0; n < n_chan; n++ ) { - scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, 20, sub( add( Q_new_old, QSCALE ), Q11 ) ); /* Q_new_old + QSCALE */ - scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, 20, sub( add( Q_new_old, QSCALE ), Q11 ) ); /* Q_new_old + QSCALE */ hFrontVads[n]->lp_speech_fx = shr( hFrontVads[n]->lp_speech_fx, 1 ); move16(); @@ -279,25 +276,15 @@ ivas_error front_vad_fx( v_add_fx( &band_energies_fx[0], &band_energies_LR_fx[0], &band_energies_LR_fx[0], 2 * NB_BANDS ); // q_band_energies_LR /* add up energies for later calculating average of channel energies */ - Q_new_old = Q_new; - move16(); Word32 Etot_fx = L_deposit_h( Etot_LR_fx[n] ); /* Q24 */ noise_est_pre_32fx( Etot_fx, hFrontVads[0]->ini_frame, hFrontVad->hNoiseEst, 0, 0, 0 ); /* wb_vad */ - Word16 scale = getScaleFactor32( hFrontVads[n]->hNoiseEst->bckr_fx, NB_BANDS ); - scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, NB_BANDS, scale ); // hFrontVads[n]->hNoiseEst->q_bckr + scale - hFrontVads[n]->hNoiseEst->q_bckr = add( hFrontVads[n]->hNoiseEst->q_bckr, scale ); - move16(); - - scale = getScaleFactor32( hFrontVads[n]->hNoiseEst->enrO_fx, NB_BANDS ); - scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, NB_BANDS, scale ); // hFrontVads[n]->hNoiseEst->q_enrO + scale - hFrontVads[n]->hNoiseEst->q_enrO = add( hFrontVads[n]->hNoiseEst->q_enrO, scale ); - move16(); - - scale = s_min( q_fr_bands[n], s_min( hFrontVads[n]->hNoiseEst->q_bckr, hFrontVads[n]->hNoiseEst->q_enrO ) ); + Word16 scale = add( hFrontVads[n]->hNoiseEst->q_bckr, L_norm_arr( hFrontVads[n]->hNoiseEst->bckr_fx, NB_BANDS ) ); + scale = s_min( scale, add( hFrontVads[n]->hNoiseEst->q_enrO, L_norm_arr( hFrontVads[n]->hNoiseEst->enrO_fx, NB_BANDS ) ) ); + scale = s_min( q_fr_bands[n], scale ); scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, NB_BANDS, sub( scale, hFrontVads[n]->hNoiseEst->q_bckr ) ); // scale hFrontVads[n]->hNoiseEst->q_bckr = scale; @@ -581,15 +568,6 @@ ivas_error front_vad_spar_fx( move16(); Word16 front_create_flag = 0; move16(); - Word16 Qband = -1; - move16(); - Word16 Q_bands = Q9; - move16(); - - Scale_sig32( hFrontVad->hNoiseEst->ave_enr_fx, NB_BANDS, ( Q_bands + QSCALE ) - hFrontVad->hNoiseEst->ave_enr_q ); /* Q_bands + QSCALE */ - Scale_sig32( hFrontVad->hNoiseEst->ave_enr2_fx, NB_BANDS, ( Q_bands + QSCALE ) - hFrontVad->hNoiseEst->ave_enr_q ); /* Q_bands + QSCALE */ - hFrontVad->hNoiseEst->ave_enr_q = ( Q_bands + QSCALE ); - move16(); Word16 tmp1; Word16 Q_inp_12k8 = hFrontVad->q_buffer_12k8; move16(); @@ -643,14 +621,6 @@ ivas_error front_vad_spar_fx( *-----------------------------------------------------------------*/ Word16 scale; - Word16 Q_new_old = add( sub( Q_inp, Qband ), Q_add ); - - Scale_sig32( hFrontVad->hNoiseEst->bckr_fx, 20, sub( add( Q_new_old, QSCALE + 2 ), hFrontVad->hNoiseEst->q_bckr ) ); // Q_new_old +QSCALE +2 - Scale_sig32( hFrontVad->hNoiseEst->enrO_fx, 20, sub( add( Q_new_old, QSCALE + 2 ), hFrontVad->hNoiseEst->q_enrO ) ); // Q_new_old +QSCALE +2 - hFrontVad->hNoiseEst->q_bckr = add( Q_new_old, QSCALE + 2 ); - move16(); - hFrontVad->hNoiseEst->q_enrO = hFrontVad->hNoiseEst->q_bckr; - move16(); Word16 Q_buffer = hFrontVad->q_buffer_12k8; move16(); Scale_sig( hFrontVad->mem_decim_fx, 2 * L_FILT_MAX, sub( Q_inp, hFrontVad->q_mem_decim ) ); /* Q_inp */ @@ -671,17 +641,16 @@ ivas_error front_vad_spar_fx( Q_inp_12k8 = hFrontVad->q_buffer_12k8; move16(); - Scale_sig32( fr_bands_fx[0], 40, sub( add( Q_bands, QSCALE ), q_fr_bands[0] ) ); // Q_bands+QSCALE - q_fr_bands[0] = add( Q_bands, QSCALE ); + scale = s_min( add( q_fr_bands[0], L_norm_arr( fr_bands_fx[0], 2 * NB_BANDS ) ), add( hFrontVad->hNoiseEst->q_bckr, L_norm_arr( hFrontVad->hNoiseEst->bckr_fx, NB_BANDS ) ) ); + scale_sig32( fr_bands_fx[0], 40, sub( scale, q_fr_bands[0] ) ); // scale + scale_sig32( hFrontVad->hNoiseEst->bckr_fx, NB_BANDS, sub( scale, hFrontVad->hNoiseEst->q_bckr ) ); // scale + hFrontVad->hNoiseEst->q_bckr = q_fr_bands[0] = scale; + move16(); move16(); - Word32 e_min_scaled; - e_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_bands, QSCALE ) ) ), 1 ), 1 ); + noise_est_down_ivas_fx( fr_bands_fx[0], q_fr_bands[0], hFrontVad->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, + &hFrontVad->hNoiseEst->totalNoise_fx, Etot_fx[0], &hFrontVad->hNoiseEst->Etot_last_fx, &hFrontVad->hNoiseEst->Etot_v_h2_fx ); - Scale_sig32( hFrontVad->hNoiseEst->bckr_fx, 20, sub( add( Q_bands, QSCALE ), hFrontVad->hNoiseEst->q_bckr ) ); /* Q_bands + QSCALE */ - hFrontVad->hNoiseEst->q_bckr = add( Q_bands, QSCALE ); - move16(); - noise_est_down_fx( fr_bands_fx[0], hFrontVad->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, &hFrontVad->hNoiseEst->totalNoise_fx, Etot_fx[0], &hFrontVad->hNoiseEst->Etot_last_fx, &hFrontVad->hNoiseEst->Etot_v_h2_fx, Q_bands, e_min_scaled ); corr_shift_fx = correlation_shift_fx( hFrontVad->hNoiseEst->totalNoise_fx ); /* Q15 */ dtx_ivas_fx( st, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8_fx, Q_inp_12k8 ); @@ -752,21 +721,42 @@ ivas_error front_vad_spar_fx( } loc_harm = multi_harm_fx( st->lgBin_E_fx, hFrontVad->hNoiseEst->old_S_fx, hFrontVad->hNoiseEst->cor_map_fx, &hFrontVad->hNoiseEst->multi_harm_limit_fx, st->total_brate, st->bwidth, cor_strong_limit, &st->hSpMusClas->mean_avr_dyn_fx, &st->hSpMusClas->last_sw_dyn_fx, &cor_map_sum_fx, &dummy_fx, S_map_fx ); /* Q0 */ } + scale = getScaleFactor32( epsP_fx, M + 1 ); Q_esp = add( Q_r[0], scale ); - Scale_sig32( epsP_fx, M + 1, scale ); - FOR( Word16 i = 0; i <= M; i++ ) - { - L_Extract( epsP_fx[i], &epsP_h[i], &epsP_l[i] ); - } - Q_bands = Q9; + Scale_sig32( epsP_fx, M + 1, scale ); // Q_esp + + scale = add( hFrontVad->hNoiseEst->ave_enr_q, s_min( L_norm_arr( hFrontVad->hNoiseEst->ave_enr_fx, NB_BANDS ), L_norm_arr( hFrontVad->hNoiseEst->ave_enr2_fx, NB_BANDS ) ) ); + scale = s_min( scale, add( hFrontVad->hNoiseEst->q_bckr, L_norm_arr( tmpE_fx, NB_BANDS ) ) ); + scale = sub( s_min( scale, Q31 ), 1 ); + scale_sig32( hFrontVad->hNoiseEst->ave_enr_fx, NB_BANDS, sub( scale, hFrontVad->hNoiseEst->ave_enr_q ) ); + scale_sig32( hFrontVad->hNoiseEst->ave_enr2_fx, NB_BANDS, sub( scale, hFrontVad->hNoiseEst->ave_enr_q ) ); + scale_sig32( tmpE_fx, NB_BANDS, sub( scale, hFrontVad->hNoiseEst->q_bckr ) ); + hFrontVad->hNoiseEst->ave_enr_q = scale; + move16(); + + scale = add( hFrontVad->hNoiseEst->q_bckr, s_min( L_norm_arr( hFrontVad->hNoiseEst->bckr_fx, NB_BANDS ), 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, hFrontVad->hNoiseEst->q_bckr ) ); + hFrontVad->hNoiseEst->q_bckr = scale; move16(); - Scale_sig32( lf_E_fx[0], 148, sub( add( Q_bands, QSCALE - 2 ), q_lf_E[0] ) ); // Q_bands+QSCALE-2 - q_lf_E[0] = add( Q_bands, QSCALE - 2 ); + 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 ); + scale_sig32( hFrontVad->hNoiseEst->fr_bands1_fx, NB_BANDS, sub( scale, hFrontVad->hNoiseEst->fr_bands_fx_q ) ); + scale_sig32( hFrontVad->hNoiseEst->fr_bands2_fx, NB_BANDS, sub( scale, hFrontVad->hNoiseEst->fr_bands_fx_q ) ); + scale_sig32( fr_bands_fx[0], 2 * NB_BANDS, sub( scale, q_fr_bands[0] ) ); + hFrontVad->hNoiseEst->fr_bands_fx_q = q_fr_bands[0] = scale; 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, + 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, hFrontVad->hNoiseEst->Etot_l_lp_fx, hFrontVad->hNoiseEst->Etot_v_h2_fx, + &hFrontVad->hNoiseEst->bg_cnt, st->lgBin_E_fx, &sp_floor, S_map_fx, NULL, hFrontVad, hFrontVad->ini_frame ); - noise_est_ivas_fx( st, old_pitch, tmpN_fx, epsP_h, epsP_l, Etot_fx[0], Etot_fx[0] - hFrontVad->lp_speech_fx, corr_shift_fx, tmpE_fx, fr_bands_fx[0], &cor_map_sum_fx, NULL, &sp_div_fx, &Q_sp_div, &non_staX_fx, &loc_harm, lf_E_fx[0], &hFrontVad->hNoiseEst->harm_cor_cnt, hFrontVad->hNoiseEst->Etot_l_lp_fx, hFrontVad->hNoiseEst->Etot_v_h2_fx, &hFrontVad->hNoiseEst->bg_cnt, st->lgBin_E_fx, Q_bands, e_min_scaled, &sp_floor, S_map_fx, NULL, hFrontVad, hFrontVad->ini_frame ); MVR2R_WORD16( st->pitch, st->pitch, 3 ); vad_param_updt_fx( st, st->pitch[1], corr_shift_fx, corr_shift_fx, A_fx, &hFrontVad, 1 ); /* 1st stage speech/music classification (GMM model) */ diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index 6e8890e4c0c954751e45887c54ac69b6bac57f42..6e9165a05c7d385983370eb98e148d8a9e8ffce2 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -161,7 +161,7 @@ Word16 select_stereo_mode( test(); test(); test(); - IF( EQ_16( stereo_switching_flag, 1 ) && GT_32( hCPE->element_brate, IVAS_13k2 ) && LT_16( hCPE->hCoreCoder[0]->hSpMusClas->past_dlp_fx[0], ONE_IN_Q9 ) && LT_32( hCPE->hCoreCoder[0]->hSpMusClas->wdlp_xtalk_fx, -5243 /* -0.01 in Q19*/ ) && EQ_16( hCPE->hCoreCoder[0]->vad_flag, 1 ) && ( hCPE->hStereoMdct->sw_uncorr || hStereoClassif->xtalk_decision ) ) + IF( EQ_16( stereo_switching_flag, 1 ) && GT_32( hCPE->element_brate, IVAS_13k2 ) && LT_16( hCPE->hCoreCoder[0]->hSpMusClas->past_dlp_fx[0], ONE_IN_Q9 ) && LT_32( hCPE->hCoreCoder[0]->hSpMusClas->wdlp_xtalk_fx, -335544 /* -0.01 in Q25 */ ) && EQ_16( hCPE->hCoreCoder[0]->vad_flag, 1 ) && ( hCPE->hStereoMdct->sw_uncorr || hStereoClassif->xtalk_decision ) ) { hStereoClassif->lrtd_mode = 1; move16(); diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index a52147004c2f8b19f42064d291e990a49da3ed3c..baf825e711e0d58d716e417c672083b5a9705f31 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -788,7 +788,7 @@ void noise_est_down_ivas_fx( move64(); FOR( i = min_band; i <= max_band; i++ ) { - sum = W_mac_32_32( sum, bckr[i], 1 ); // q_fr_bands+1 + sum = W_mac_32_16( sum, bckr[i], 1 ); // q_fr_bands+1 } q_sum = add( q_fr_bands, 1 ); IF( sum == 0 ) @@ -2262,27 +2262,27 @@ 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 Word16 epsP_h[], /* i : msb prediction error energies Q_r-1 */ - const Word16 epsP_l[], /* i : msb prediction error energies Q_r-1 */ + 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? */ const Word16 corr_shift, /* i : normalized correlation correction Q15 */ - const Word32 enr[], /* i : averaged energy over both subframes Q_new + Q_SCALE */ - Word32 fr_bands[], /* i : spectrum per critical bands of the current frame Q_new + Q_SCALE */ + const Word32 enr[], /* i : averaged energy over both subframes q_enr */ + const Word16 q_enr, /* i : q_enr of enr Q0 */ + Word32 fr_bands[], /* i : spectrum per critical bands of the current frame q_fr_bands */ + Word16 q_fr_bands, /* i : Q of q_fr_bands */ Word16 *cor_map_sum, /* o : Q8 */ Word16 *ncharX, /* o : Q11 */ Word16 *sp_div, /* o : Q_sp_div */ Word16 *Q_sp_div, /* o : Q factor for sp_div */ Word16 *non_staX, /* o : non-stationarity for sp/mus classifier Q8 */ Word16 *loc_harm, /* o : multi-harmonicity flag for UV classifier */ - const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE -2 */ + 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 */ Word16 *st_harm_cor_cnt, /* i/o : 1st harm correlation timer Q0 */ const Word16 Etot_l_lp, /* i : Smoothed low energy Q8 */ const Word16 Etot_v_h2, /* i : Energy variations Q8 */ Word16 *bg_cnt, /* i : Background burst length timer Q0 */ Word16 EspecdB[], /* i/o: log E spectrum (with f=0) of the current frame Q7 for multi harm */ - Word16 Q_new, /* i : SCaling of current frame */ - const Word32 Le_min_scaled, /*i : Minimum energy value in Q_new + Q_SCALE */ Word16 *sp_floor, /* o : noise floor estimate Q7 */ Word16 S_map[], /* o : short-term correlation map Q7 */ STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ @@ -2292,9 +2292,9 @@ void noise_est_ivas_fx( { Word16 alpha, alpha2, alpha2m1, alpham1; Word16 cor_min, cor_max, num, den, ExpNum, ExpDen, noise_chartmp; - Word16 wtmp1, wtmp, ExpLmax, ExpLmax2, tmpExp, nchar_thr, cor_tmp; + Word16 wtmp1, wtmp, nchar_thr, cor_tmp; Word16 i, tmp_pc, pc, th_eps; - Word32 th_sta, Lnum, Lden, non_sta, LepsP, Ltmpden; + Word32 th_sta, Lnum, Lden, non_sta, LepsP; Word16 e_ener, f_ener; Word32 Ltmp, Ltmp1, Lsum_num, Lsum_den, *pt1, *pt2, Ltmp2, Lnon_sta2; Word64 w_sum_num, w_tmp; @@ -2313,23 +2313,32 @@ void noise_est_ivas_fx( Word16 enr_bgd, cns_bgd, lp_bgd, ns_mask; Word16 lt_haco_mask, bg_haco_mask; - Word16 SD_1, SD_1_inv, bg_bgd3, PD_1, PD_2, PD_3, PD_4, PD_5; + Word16 SD_1, bg_bgd3, PD_1, PD_2, PD_3, PD_4, PD_5; Word16 non_staB; /* Q8 */ - Word32 L_tmp_enr, L_tmp_ave_enr, L_tmp_ave_enr2; - Word16 tmp_Q; + Word32 L_tmp_enr, L_tmp_ave, L_tmp_ave2; Word16 tmp, tmp2; /* 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 */ - Word16 vad_2nd_stage_fx; Word16 lim_Etot_fx; /* Q8 */ Word16 lim_Etot_sq_fx; /* Q2 */ Word16 st_E_var_est_fx; /* Q2 */ NOISE_EST_HANDLE hNoiseEst; SP_MUS_CLAS_HANDLE hSpMusClas; + Word32 Le_min_scaled; + Word64 temp; hSpMusClas = st_fx->hSpMusClas; + + Le_min_scaled = L_shl( E_MIN_FXQ31, sub( q_fr_bands, Q31 ) ); // q_fr_bands + + GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; + move32(); +#endif + /* Check if LR-VAD */ IF( hFrontVad != NULL ) { @@ -2340,56 +2349,61 @@ void noise_est_ivas_fx( hNoiseEst = st_fx->hNoiseEst; } - GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - move32(); -#endif - /*-----------------------------------------------------------------* * Initialization *-----------------------------------------------------------------*/ vad_bwidth_fx = st_fx->input_bwidth; move16(); - /*st_fx->ener_RAT = 10.0f * (float)log10( mean(lf_E, 8));*/ + /*st_fx->ener_RAT = 10.0f * (float)log10( mean(lf_E, 8));*/ + temp = 0; + move64(); IF( hFrontVad == NULL ) { - if ( hSpMusClas != NULL ) + IF( hSpMusClas != NULL ) { - Ltmp = L_shr( lf_E[0], 3 ); - FOR( i = 1; i < 8; i++ ) + /* E = mean( lf_E, 8 ); */ + FOR( i = 0; i < 8; i++ ) { - Ltmp = L_add( Ltmp, L_shr( lf_E[i], 3 ) ); + temp = W_mac_32_16( temp, lf_E[i], 1 ); // q_lf_E+1 } - IF( LT_32( Ltmp, L_shl( 1, add( Q_new, Q_SCALE - 2 ) ) ) ) + /* (temp / 8) */ + Ltmp = W_extract_l( W_shr( temp, 4 ) ); // q_lf_E+1 -> q_lf_E + + IF( LT_32( Ltmp, L_shl_sat( 1, q_lf_E ) ) ) { hSpMusClas->ener_RAT_fx = 0; - // PMT("hSpMusClas->ener_RAT_fx = 0, that should be validated") } ELSE { - Ltmp = L_max( Ltmp, (Word32) 1L ); /* make sure log2_norm_lc does not cause table reading out of bounds */ e_ener = norm_l( Ltmp ); f_ener = Log2_norm_lc( L_shl( Ltmp, e_ener ) ); e_ener = sub( 30, e_ener ); - e_ener = sub( e_ener, sub( add( Q_new, QSCALE ), 2 ) ); - Ltmp = Mpy_32_16( e_ener, f_ener, LG10 ); - wtmp = round_fx( L_shl( Ltmp, 10 ) ); /*Q8*/ - - /* st_fx->ener_RAT /= (Etot + 0.01f); */ - wtmp1 = add( Etot, 3 ); /*3 is 0.01 in Q8 */ - /* st_fx->ener_RAT_fx = wtmp/wtmp1 */ + e_ener = sub( e_ener, q_lf_E ); + Ltmp = L_mac( L_deposit_h( e_ener ), f_ener, 1 ); // Q16 + Ltmp = Mpy_32_16_1( Ltmp, LG10 ); // Q14 (16+13-15) + Ltmp = L_shl( Ltmp, 10 ); // Q24 + wtmp = round_fx( Ltmp ); /*Q8*/ + + /* st_fx->ener_RAT /= (Etot + 0.01f); + if ( st->hSpMusClas->ener_RAT > 1.0 ) + { + st->hSpMusClas->ener_RAT = 1.0f; + } + */ + + wtmp1 = add( Etot, 3 ); /* 0.01f in Q8 */ hSpMusClas->ener_RAT_fx = 0; move16(); IF( wtmp > 0 ) { hSpMusClas->ener_RAT_fx = 32767; move16(); /*Q15*/ - if ( GE_16( wtmp1, wtmp ) ) + IF( GE_16( wtmp1, wtmp ) ) { hSpMusClas->ener_RAT_fx = div_s( wtmp, wtmp1 ); /*Q15*/ /* wtmp1 gte than wtmp */ + move16(); } } } @@ -2403,7 +2417,7 @@ void noise_est_ivas_fx( * order" spectral envelope => the epsP ratio is much less effective. *-----------------------------------------------------------------*/ - IF( NE_16( vad_bwidth_fx, NB ) ) /* WB input */ + IF( vad_bwidth_fx != NB ) /* WB input */ { th_eps = TH_EPS16_FX; move16(); /*Q11*/ @@ -2474,95 +2488,115 @@ void noise_est_ivas_fx( /*-----------------------------------------------------------------* * Detection of frames with non-stationary spectral content *-----------------------------------------------------------------*/ - /* weighted sum of spectral changes per critical bands */ w_sum_num = 0; move64(); Lsum_den = L_deposit_l( 0 ); - /* Find a proper scaling to prevent overflow, but acheiving good computation on low level signals */ - tmpExp = 0; - move16(); - ExpLmax = sub( 30, norm_l( fr_bands[10] ) ); - ExpLmax2 = sub( 30, norm_l( hNoiseEst->fr_bands2_fx[10] ) ); - tmpExp = s_max( tmpExp, sub( shl( s_max( ExpLmax, ExpLmax2 ), 1 ), s_min( ExpLmax, ExpLmax2 ) ) ); - FOR( i = 11; i <= st_fx->max_band; i++ ) - { - ExpLmax = sub( 30, norm_l( fr_bands[i] ) ); - ExpLmax2 = sub( 30, norm_l( hNoiseEst->fr_bands2_fx[i] ) ); - tmpExp = s_max( tmpExp, sub( shl( s_max( ExpLmax, ExpLmax2 ), 1 ), s_min( ExpLmax, ExpLmax2 ) ) ); - } - tmpExp = sub( tmpExp, 30 - 4 - 4 ); /* 4bits for internal summation and 4 bits for comparaison */ - pt1 = fr_bands + 10; pt2 = hNoiseEst->fr_bands2_fx + 10; + Word64 w_sum_den; + Word16 exp, exp2; + w_sum_den = 0; + move64(); FOR( i = 10; i <= st_fx->max_band; i++ ) { - Lnum = L_max( *pt1, *pt2 ); /* Don't need if anymore */ -#ifdef BASOP_NOGLOB - Lsum_den = L_add_o( Lsum_den, Lnum, &Overflow ); -#else /* BASOP_NOGLOB */ - Lsum_den = L_add( Lsum_den, Lnum ); -#endif /* BASOP_NOGLOB */ - Ltmpden = L_min( *pt1, *pt2 ); - if ( Ltmpden == 0 ) + Lnum = L_max( *pt1, *pt2 ); + Lden = L_min( *pt1, *pt2 ); + + w_sum_den = W_mac_32_16( w_sum_den, Lnum, 1 ); // q_fr_bands+1 + + exp = sub( norm_l( Lnum ), 1 ); + Lnum = L_shl( Lnum, exp ); // q_fr_bands+exp + num = extract_h( Mpy_32_32( Lnum, Lnum ) ); // 2*(q_fr_bands+exp)-31-16 + ExpNum = add( sub( shl( q_fr_bands, 1 ), 47 ), shl( exp, 1 ) ); + + + den = E_MIN_FXQ31 >> 8; // 29360, 0.0035f in Q23 + ExpDen = Q23; + move32(); + move16(); + + IF( Lden != 0 ) { - Ltmpden = L_add( Ltmpden, 1 ); + exp = norm_l( Lden ); + den = extract_h( L_shl( Lden, exp ) ); // q_fr_bands+ExpDen-16 + ExpDen = sub( add( q_fr_bands, exp ), Q16 ); } - ExpNum = sub( norm_l( Lnum ), 1 ); - num = extract_h( L_shl( Lnum, ExpNum ) ); - num = mult_r( num, num ); - ExpDen = norm_l( Ltmpden ); - den = extract_h( L_shl( Ltmpden, ExpDen ) ); - num = div_s( num, den ); - w_tmp = W_shr( num, add( sub( sub( shl( ExpNum, 1 ), ExpDen ), 15 + 1 ), tmpExp ) ); + + num = div_s( num, den ); // Q15+ExpNum-ExpDen + w_tmp = W_shl( num, sub( q_fr_bands, sub( ExpNum, ExpDen ) ) ); // q_fr_bands+15 w_sum_num = W_add( w_sum_num, w_tmp ); pt1++; pt2++; } - Lsum_den = L_shr( Lsum_den, tmpExp ); ExpNum = W_norm( w_sum_num ); - Lsum_num = W_extract_h( W_shl( w_sum_num, ExpNum ) ); - ExpNum = sub( ExpNum, 32 ); + Lsum_num = W_extract_h( W_shl( w_sum_num, ExpNum ) ); // q_fr_bands+15+ExpNum-32 + ExpNum = add( q_fr_bands, sub( ExpNum, 17 ) ); + + ExpDen = W_norm( w_sum_den ); + Lsum_den = W_extract_h( W_shl( w_sum_den, ExpDen ) ); // q_fr_bands+1+ExpDen-32 + ExpDen = add( add( q_fr_bands, 1 ), sub( ExpDen, 32 ) ); /* calculation of spectral diversity */ /* THR_SPDIV_FX = 5 , 1/5 Q15 = 6554 */ spec_div = 0; move16(); - if ( GT_32( Mult_32_16( Lsum_num, 6554 ), L_shl_sat( Lsum_den, ExpNum ) ) ) /* Qx+Q15+1-16 ==> Qx */ + if ( GT_32( Mult_32_16( Lsum_num, 6554 ), L_shl_sat( Lsum_den, sub( ExpNum, ExpDen ) ) ) ) /* Qx+Q15+1-16 ==> Qx */ { spec_div = 1; move16(); } /* *sp_div = Lsum_num / (Lsum_den + 1e-5f); */ - Lsum_den = L_add( Lsum_den, 1 ); - Word16 exp = 0; + IF( Lsum_den == 0 ) + { + Lsum_den = 1407374884; // 1e-5 in Q47 + ExpDen = 47; + move32(); + move16(); + } + *sp_div = BASOP_Util_Divide3232_Scale( Lsum_num, Lsum_den, &exp ); move16(); - - *Q_sp_div = add( sub( 15, exp ), ExpNum ); + *Q_sp_div = add( sub( 15, exp ), sub( ExpNum, ExpDen ) ); move16(); /*-----------------------------------------------------------------* * Detection of frames with high energy content in high frequencies *-----------------------------------------------------------------*/ + pt1 = &fr_bands[st_fx->min_band]; + pt2 = &fr_bands[10]; + w_sum_num = 0; + w_sum_den = 0; + move64(); + move64(); + /* calculation of energy in first 10 critical bands */ - Ltmp = sum32_fx( &fr_bands[st_fx->min_band], sub( 10, st_fx->min_band ) ); + FOR( i = 0; i < sub( 10, st_fx->min_band ); i++ ) + { + w_sum_den = W_mac_32_16( w_sum_den, *pt1, 1 ); // q_fr_bands+1 + pt1++; + } + exp = W_norm( w_sum_den ); + Ltmp = W_extract_h( W_shl( w_sum_den, exp ) ); // q_fr_bands+1+exp-32 + exp = sub( add( q_fr_bands, exp ), 31 ); /* calculation of energy in the rest of bands */ - Ltmp2 = sum32_fx( &fr_bands[10], sub( st_fx->max_band, 9 ) ); + FOR( i = 0; i < sub( st_fx->max_band, 9 ); i++ ) + { + w_sum_num = W_mac_32_16( w_sum_num, *pt2, 1 ); + pt2++; + } + exp2 = sub( W_norm( w_sum_num ), 1 ); + Ltmp2 = W_extract_h( W_shl( w_sum_num, exp2 ) ); // q_fr_bands+1+exp2-32 + exp2 = sub( add( q_fr_bands, exp2 ), 31 ); -#ifdef BASOP_NOGLOB - wtmp = shl_o( 1, sub( add( Q_new, QSCALE ), 1 ), &Overflow ); -#else /* BASOP_NOGLOB */ - wtmp = shl( 1, sub( add( Q_new, QSCALE ), 1 ) ); -#endif /* BASOP_NOGLOB */ test(); - IF( L_msu( Ltmp, 100, wtmp ) < 0 || L_msu( Ltmp2, 100, wtmp ) < 0 ) + IF( LT_32( L_shr( Ltmp, exp ), 100 ) || LT_32( L_shr( Ltmp2, exp2 ), 100 ) ) { noise_chartmp = 0; move16(); @@ -2570,17 +2604,12 @@ void noise_est_ivas_fx( ELSE { /* ftemp2 /= ftemp */ - ExpNum = sub( norm_l( Ltmp2 ), 1 ); - num = extract_h( L_shl( Ltmp2, ExpNum ) ); - - ExpDen = norm_l( Ltmp ); - den = extract_h( L_shl( Ltmp, ExpDen ) ); - num = div_s( num, den ); + num = div_s( extract_h( Ltmp2 ), extract_h( Ltmp ) ); // 15+exp2-exp #ifdef BASOP_NOGLOB - noise_chartmp = extract_h( L_shr_o( num, add( sub( ExpNum, ExpDen ), 4 - 16 ), &Overflow ) ); /* Q11 */ -#else /* BASOP_NOGLOB */ - noise_chartmp = extract_h( L_shr( num, add( sub( ExpNum, ExpDen ), 4 - 16 ) ) ); /* Q11 */ -#endif /* BASOP_NOGLOB */ + noise_chartmp = shl_o( num, sub( sub( exp, exp2 ), 4 ), &Overflow ); // 15+exp2-exp1 -> Q11 +#else + noise_chartmp = shl( num, sub( sub( exp, exp2 ), 4 ) ); // 15+exp2-exp1 -> Q11 +#endif } if ( ncharX != NULL ) @@ -2607,16 +2636,16 @@ void noise_est_ivas_fx( } } - noise_chartmp = s_min( noise_chartmp, (Word16) 10 << 11 ); /* Q11 */ + noise_chartmp = s_min( noise_chartmp, 10 << 11 ); /* Q11 */ /* update LT value of the final parameter */ /* *st_noise_char = M_ALPHA * *st_noise_char + (1-M_ALPHA) * noise_chartmp */ hNoiseEst->noise_char_fx = mac_r( L_mult( M_ALPHA_FX, hNoiseEst->noise_char_fx ), ONE_MINUS_M_ALPHA, noise_chartmp ); - + move16(); nchar_thr = THR_NCHAR_WB_FX; move16(); /* 1.0 Q11 */ - if ( EQ_16( vad_bwidth_fx, NB ) ) + if ( vad_bwidth_fx == NB ) { nchar_thr = THR_NCHAR_NB_FX; move16(); /* 1.0 Q11 */ @@ -2631,8 +2660,8 @@ void noise_est_ivas_fx( } /* save the 2 last spectra per crit. bands for the future */ - Copy32( hNoiseEst->fr_bands1_fx, hNoiseEst->fr_bands2_fx, NB_BANDS ); - Copy32( fr_bands + NB_BANDS, hNoiseEst->fr_bands1_fx, NB_BANDS ); + Copy32( hNoiseEst->fr_bands1_fx, hNoiseEst->fr_bands2_fx, NB_BANDS ); // q_fr_bands + Copy32( fr_bands + NB_BANDS, hNoiseEst->fr_bands1_fx, NB_BANDS ); // q_fr_bands /*-----------------------------------------------------------------* * Non-stationarity estimation for each band @@ -2645,12 +2674,11 @@ void noise_est_ivas_fx( tmp = s_max( relE, 0 ); /* Q8 */ /* alpha = 0.064f * ftemp + 0.75f; */ - Ltmp = Mult_32_16( (Word32) 137438953L, tmp ); /* Q31(.064)+Q8+1-16 --> Q24 */ - Ltmp = L_mac( Ltmp, 256, 24576 ); /* Q8+Q15(.75)+1 --> Q24 */ + Ltmp = Madd_32_16( 12582912 /* 0.75 in Q24*/, 137438953, tmp ); // Q24 #ifdef BASOP_NOGLOB alpha = round_fx_o( L_shl_o( Ltmp, 7, &Overflow ), &Overflow ); /*Q24 +7 --> Q31 Q15*/ #else /* BASOP_NOGLOB */ - alpha = round_fx( L_shl( Ltmp, 7 ) ); /*Q24 +7 --> Q31 Q15*/ + alpha = round_fx( L_shl( Ltmp, 7 ) ); /*Q24 +7 --> Q31 Q15*/ #endif /* BASOP_NOGLOB */ /*if( alpha > 0.999f { alpha = 0.999f;} */ @@ -2673,60 +2701,59 @@ void noise_est_ivas_fx( alpha2m1 = 32767; move16(); } - Lnon_sta2 = L_deposit_l( 1 << 10 ); + Lnon_sta2 = L_deposit_l( 1 << 10 ); // Q10 - non_sta = L_deposit_l( 1 << 10 ); + non_sta = L_deposit_l( 1 << 10 ); // Q10 *non_staX = 0; move16(); non_staB = 0; move16(); + Le_min_scaled = L_shl( E_MIN_FXQ31, sub( q_enr, Q31 ) ); // q_enr + FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ ) { + Ltmp = L_shl( 1, q_enr ); // q_enr /* + 1.0f added to reduce sensitivity to non stationarity in low energies */ /* tmp_enr = enr[i] + 1.0f; */ - tmp_Q = add( Q_new, Q_SCALE ); - Ltmp = L_shl( (Word32) 1L, tmp_Q ); /* 1.0 added in the right dynamic domain */ -#ifdef BASOP_NOGLOB - L_tmp_enr = L_add_o( enr[i], Ltmp, &Overflow ); /* enr scale dynamic */ - L_tmp_ave_enr = L_add_o( hNoiseEst->ave_enr_fx[i], Ltmp, &Overflow ); /* ave__enr scale dynamic */ -#else /* BASOP_NOGLOB */ - L_tmp_enr = L_add( enr[i], Ltmp ); /* enr scale dynamic */ - L_tmp_ave_enr = L_add( hNoiseEst->ave_enr_fx[i], Ltmp ); /* ave__enr scale dynamic */ -#endif /* BASOP_NOGLOB */ - IF( LE_32( non_sta, th_sta ) ) /* Just to limit the saturation */ + L_tmp_enr = L_add( enr[i], Ltmp ); // q_enr + + IF( LE_32( non_sta, th_sta ) ) /* Just to limit the saturation */ { + L_tmp_ave = L_add( hNoiseEst->ave_enr_fx[i], Ltmp ); // q_enr + /* if( enr[i] > st_ave_enr2[i] ) */ /* non_sta2 = non_sta2 * ((enr[i]+1) / (st_ave_enr2[i]+1)) */ - Lnum = L_max( L_tmp_enr, L_tmp_ave_enr ); + Lnum = L_max( L_tmp_enr, L_tmp_ave ); // q_enr /* else */ /* non_sta2 = non_sta2 * ((st_ave_enr2[i]+1) / (enr[i]+1)) */ - Lden = L_min( L_tmp_enr, L_tmp_ave_enr ); + Lden = L_min( L_tmp_enr, L_tmp_ave ); // q_enr if ( Lden == 0 ) { - Lden = L_add( Lden, EPSILON_FX ); + Lden = L_max( Ltmp, EPSILON_FX ); // q_enr } ExpNum = sub( norm_l( Lnum ), 1 ); - num = extract_h( L_shl( Lnum, ExpNum ) ); - Lnum = L_shl( Lnum, ExpNum ); + num = extract_h( L_shl( Lnum, ExpNum ) ); // q_enr+ExpNum-16 + ExpDen = norm_l( Lden ); - den = extract_h( L_shl( Lden, ExpDen ) ); - num = div_s( num, den ); - Ltmp = Mult_32_16( non_sta, num ); + den = extract_h( L_shl( Lden, ExpDen ) ); // q_enr+ExpDen-16 + + num = div_s( num, den ); // 15+ExpNum-ExpDen + Ltmp1 = Mult_32_16( non_sta, num ); // 15+ExpNum-ExpDen+10-15 #ifdef BASOP_NOGLOB - non_sta = L_shr_o( Ltmp, sub( ExpNum, ExpDen ), &Overflow ); /* Q10 */ -#else /* BASOP_NOGLOB */ - non_sta = L_shr( Ltmp, sub( ExpNum, ExpDen ) ); /* Q10 */ -#endif /* BASOP_NOGLOB */ + non_sta = L_shr_o( Ltmp1, sub( ExpNum, ExpDen ), &Overflow ); /* Q10 */ +#else /* BASOP_NOGLOB */ + non_sta = L_shr( Ltmp1, sub( ExpNum, ExpDen ) ); /* Q10 */ +#endif /* BASOP_NOGLOB */ } /* st->ave_enr[i] = alpha * st->ave_enr[i] + (1-alpha) * enr[i];*/ /* update long-term average */ - Ltmp = Mult_32_16( hNoiseEst->ave_enr_fx[i], alpha ); - Ltmp = L_add_sat( Ltmp, Mult_32_16( enr[i], alpham1 ) ); - hNoiseEst->ave_enr_fx[i] = L_max( Le_min_scaled, Ltmp ); + Ltmp1 = Mult_32_16( hNoiseEst->ave_enr_fx[i], alpha ); // q_enr + Ltmp1 = Madd_32_16( Ltmp1, enr[i], alpham1 ); // q_enr + hNoiseEst->ave_enr_fx[i] = L_max( Le_min_scaled, Ltmp1 ); // q_enr move32(); /* calculation of another non-stationarity measure (following attacks) */ @@ -2740,41 +2767,36 @@ void noise_est_ivas_fx( } */ /* ave_enr2:: calculation of another non-stationarity measure (following attacks) */ - Ltmp = L_shl( (Word32) 1L, tmp_Q ); /* 1.0 added in the right dynamic domain */ - /*L_tmp_enr = L_add(enr[i] , Ltmp );*/ /* enr scale dynamic , done above */ -#ifdef BASOP_NOGLOB - L_tmp_ave_enr2 = L_add_o( hNoiseEst->ave_enr2_fx[i], Ltmp, &Overflow ); /* ave__enr scale dynamic */ -#else - L_tmp_ave_enr2 = L_add( hNoiseEst->ave_enr2_fx[i], Ltmp ); /* ave__enr scale dynamic */ -#endif IF( LE_32( Lnon_sta2, th_sta ) ) /* Just to limit the saturation */ { - Lnum = L_max( L_tmp_enr, L_tmp_ave_enr2 ); - Lden = L_min( L_tmp_enr, L_tmp_ave_enr2 ); + L_tmp_ave2 = L_add( hNoiseEst->ave_enr2_fx[i], Ltmp ); // q_enr + Lnum = L_max( L_tmp_enr, L_tmp_ave2 ); // q_enr + Lden = L_min( L_tmp_enr, L_tmp_ave2 ); // q_enr + if ( Lden == 0 ) { - Lden = L_add( Lden, EPSILON_FX ); + Lden = L_max( Ltmp, EPSILON_FX ); // q_enr } ExpNum = sub( norm_l( Lnum ), 1 ); - num = extract_h( L_shl( Lnum, ExpNum ) ); - Lnum = L_shl( Lnum, ExpNum ); + num = extract_h( L_shl( Lnum, ExpNum ) ); // q_enr+ExpNum-16 + ExpDen = norm_l( Lden ); - den = extract_h( L_shl( Lden, ExpDen ) ); - num = div_s( num, den ); - Ltmp1 = Mult_32_16( Lnon_sta2, num ); + den = extract_h( L_shl( Lden, ExpDen ) ); // q_enr+ExpDen-16 + + num = div_s( num, den ); // 15+ExpNum-ExpDen + Ltmp1 = Mult_32_16( Lnon_sta2, num ); // 15+ExpNum-ExpDen+10-15 #ifdef BASOP_NOGLOB Lnon_sta2 = L_shr_o( Ltmp1, sub( ExpNum, ExpDen ), &Overflow ); /* Q10 */ #else /* BASOP_NOGLOB */ - Lnon_sta2 = L_shr( Ltmp1, sub( ExpNum, ExpDen ) ); /* Q10 */ + Lnon_sta2 = L_shr( Ltmp1, sub( ExpNum, ExpDen ) ); /* Q10 */ #endif /* BASOP_NOGLOB */ } - /* st_ave_enr2[i] = (float)alpha2 * st_ave_enr2[i] - + (1.0f - alpha2) * (enr[i]) */ - Ltmp1 = Mult_32_16( hNoiseEst->ave_enr2_fx[i], alpha2 ); - Ltmp1 = L_add( Ltmp1, Mult_32_16( enr[i], alpha2m1 ) ); - hNoiseEst->ave_enr2_fx[i] = L_max( Le_min_scaled, Ltmp1 ); + /* st_ave_enr2[i] = (float)alpha2 * st_ave_enr2[i] + (1.0f - alpha2) * (enr[i]) */ + Ltmp1 = Mult_32_16( hNoiseEst->ave_enr2_fx[i], alpha2 ); // q_enr + Ltmp1 = Madd_32_16( Ltmp1, enr[i], alpha2m1 ); // q_enr + hNoiseEst->ave_enr2_fx[i] = L_max( Le_min_scaled, Ltmp1 ); // q_enr move32(); /* calculation of non-stationarity measure for speech/music classification */ @@ -2785,7 +2807,13 @@ void noise_est_ivas_fx( IF( GE_16( i, START_BAND_SPMUS ) && LT_16( i, NB_BANDS_SPMUS + START_BAND_SPMUS ) && st_fx->hSpMusClas != NULL ) { /* log_enr = (float)ln_fx(enr[i]); */ - log_enr16 = noise_est_ln_q8_fx( enr[i], 0, tmp_Q ); + Ltmp1 = L_max( enr[i], 1 ); + e_ener = norm_l( Ltmp1 ); + f_ener = Log2_norm_lc( L_shl( Ltmp1, e_ener ) ); + e_ener = sub( sub( 30, e_ener ), q_enr ); + Ltmp1 = L_mac( f_ener, e_ener, ONE_IN_Q14 ); // Q15 + Ltmp1 = Mpy_32_16_1( Ltmp1, 22713 ); // Q15 + log_enr16 = round_fx( L_shl( Ltmp1, 9 ) ); /* Q8 */ wtmp = abs_s( sub( log_enr16, hSpMusClas->past_log_enr_fx[i - START_BAND_SPMUS] ) ); #ifdef BASOP_NOGLOB *non_staX = add_o( *non_staX, wtmp, &Overflow ); @@ -2797,39 +2825,56 @@ void noise_est_ivas_fx( move16(); } } + + test(); IF( GE_16( i, 2 ) && LE_16( i, 16 ) ) { - IF( GE_16( ini_frame, 100 ) ) + tmp_enr = LN_E_MIN_PLUS_ONE_FX; // Q8 + move16(); + IF( enr[i] != 0 ) + { + Ltmp1 = L_add( enr[i], Ltmp ); // q_enr + e_ener = norm_l( Ltmp1 ); + f_ener = Log2_norm_lc( L_shl( Ltmp1, e_ener ) ); + e_ener = sub( sub( 30, e_ener ), q_enr ); + Ltmp1 = L_mac( f_ener, e_ener, ONE_IN_Q14 ); // Q15 + Ltmp1 = Mpy_32_16_1( Ltmp1, 22713 ); // Q15 + tmp_enr = round_fx( L_shl( Ltmp1, 9 ) ); /* Q8 */ + } + + IF( LT_16( ini_frame, 100 ) ) { - /* calculate non-stationarity feature relative background */ - tmp_enr = noise_est_ln_q8_fx( enr[i], 1, tmp_Q ); /* 1.0f added */ - tmp_floor = LN_E_MIN_PLUS_ONE_FX; - move16(); /* non dynamic init constant in Q8 */ - tmp_floor = noise_est_ln_q8_fx( hNoiseEst->bckr_fx[i], 1, tmp_Q ); #ifdef BASOP_NOGLOB - non_staB = add_o( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ), &Overflow ); /* Q8 */ -#else /* BASOP_NOGLOB */ + non_staB = add_o( non_staB, abs_s( sub( tmp_enr, LN_E_MIN_PLUS_ONE_FX ) ), &Overflow ); /* Q8 */ +#else /* BASOP_NOGLOB */ non_staB = add( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ) ); /* Q8 */ -#endif /* BASOP_NOGLOB */ +#endif } ELSE /*ini_frame < 100*/ { - /* calculate non-stationarity feature relative background */ - tmp_enr = noise_est_ln_q8_fx( enr[i], 1, tmp_Q ); /* 1.0f added */ - tmp_floor = LN_E_MIN_PLUS_ONE_FX; - move16(); /* non dynamic init constant in Q8 */ - tmp_floor = noise_est_ln_q8_fx( E_MIN_FX, 1, tmp_Q ); + tmp_floor = LN_E_MIN_PLUS_ONE_FX; // Q8 + move16(); + IF( hNoiseEst->bckr_fx[i] != 0 ) + { + Ltmp1 = L_add( hNoiseEst->bckr_fx[i], L_shl( 1, hNoiseEst->q_bckr ) ); // hNoiseEst->q_bckr + 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 ); + 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 */ + } #ifdef BASOP_NOGLOB non_staB = add_o( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ), &Overflow ); /* Q8 */ #else /* BASOP_NOGLOB */ non_staB = add( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ) ); /* Q8 */ -#endif /* BASOP_NOGLOB */ +#endif } } } /* end of band loop FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ ) */ - IF( LT_16( Etot, -1280 ) ) + IF( LT_16( Etot, -1280 /* -5.0f in Q8 */ ) ) { non_sta = L_deposit_l( 1024 ); /* 1.0 in Q10 */ Lnon_sta2 = L_deposit_l( 1024 ); /* 1.0 in Q10 */ @@ -2842,55 +2887,55 @@ void noise_est_ivas_fx( { /* Allow use of quicker filter during init - if needed */ /* st->Etot_st_est = 0.25f * lim_Etot + (1.0f-0.25F) * st->Etot_st_est; */ - hNoiseEst->Etot_st_est_fx = mac_r( L_mult( 8192, lim_Etot_fx ), 24576, hNoiseEst->Etot_st_est_fx ); + hNoiseEst->Etot_st_est_fx = mac_r( L_mult( 8192, lim_Etot_fx ), 24576, hNoiseEst->Etot_st_est_fx ); // Q8 move16(); /* st->Etot_sq_st_est = 0.25f * lim_Etot * lim_Etot + (1.0f-0.25f) * st->Etot_sq_st_est; */ - hNoiseEst->Etot_sq_st_est_fx = mac_r( L_mult( 8192, lim_Etot_sq_fx ), 24576, hNoiseEst->Etot_sq_st_est_fx ); + hNoiseEst->Etot_sq_st_est_fx = mac_r( L_mult( 8192, lim_Etot_sq_fx ), 24576, hNoiseEst->Etot_sq_st_est_fx ); // Q2 move16(); } ELSE { /* st->Etot_st_est = 0.25f * lim_Etot + (1.0f-0.25F) * st->Etot_st_est; */ - hNoiseEst->Etot_st_est_fx = mac_r( L_mult( 8192, lim_Etot_fx ), 24576, hNoiseEst->Etot_st_est_fx ); + hNoiseEst->Etot_st_est_fx = mac_r( L_mult( 8192, lim_Etot_fx ), 24576, hNoiseEst->Etot_st_est_fx ); // Q8 move16(); /* st->Etot_sq_st_est = 0.25f * lim_Etot * lim_Etot + (1.0f-0.25f) * st->Etot_sq_st_est; */ - hNoiseEst->Etot_sq_st_est_fx = mac_r( L_mult( 8192, lim_Etot_sq_fx ), 24576, hNoiseEst->Etot_sq_st_est_fx ); + hNoiseEst->Etot_sq_st_est_fx = mac_r( L_mult( 8192, lim_Etot_sq_fx ), 24576, hNoiseEst->Etot_sq_st_est_fx ); // Q2 move16(); } - st_E_var_est_fx = sub( hNoiseEst->Etot_sq_st_est_fx, extract_h( L_shl_r( L_mult( hNoiseEst->Etot_st_est_fx, hNoiseEst->Etot_st_est_fx ), 1 ) ) ); + st_E_var_est_fx = sub( hNoiseEst->Etot_sq_st_est_fx, extract_h( L_shl_r( L_mult( hNoiseEst->Etot_st_est_fx, hNoiseEst->Etot_st_est_fx ), 1 ) ) ); // Q2 /*-----------------------------------------------------------------* * Count frames since last correlation or harmonic event *-----------------------------------------------------------------*/ - Ltmp = L_mult( st_fx->voicing_fx[0], 16384 ); - Ltmp = L_mac( Ltmp, st_fx->voicing_fx[1], 16384 ); + Ltmp = L_mult( st_fx->voicing_fx[0], 16384 /* 0.5 in Q15 */ ); // Q31 + Ltmp = L_mac( Ltmp, st_fx->voicing_fx[1], 16384 /* 0.5 in Q15 */ ); // Q31 + *st_harm_cor_cnt = add( *st_harm_cor_cnt, 1 ); + move16(); test(); test(); - *st_harm_cor_cnt = add( *st_harm_cor_cnt, 1 ); - if ( ( Etot > 0 ) && ( ( *loc_harm > 0 ) || ( GT_16( round_fx( Ltmp ), COR_MAX_NNE_FX ) ) ) ) + if ( ( Etot > 0 ) && ( ( *loc_harm > 0 ) || ( GT_32( Ltmp, 1825361101 /* 0.85 in Q31 */ ) ) ) ) { *st_harm_cor_cnt = 0; move16(); } - IF( ( GT_16( *st_harm_cor_cnt, 1 ) ) && ( ( LT_16( Etot, 3840 ) ) || /* 15 in Q8 */ - ( GT_16( st_fx->ini_frame, 10 ) && - GT_16( sub( Etot, hNoiseEst->Etot_lp_fx ), 1792 ) ) ) /* 7 in Q8 */ - ) + test(); + test(); + test(); + if ( ( GT_16( *st_harm_cor_cnt, 1 ) ) && ( ( LT_16( Etot, 3840 /* 15 in Q8 */ ) ) || + ( GT_16( st_fx->ini_frame, 10 ) && + GT_16( sub( Etot, hNoiseEst->Etot_lp_fx ), 1792 /* 7 in Q8 */ ) ) ) ) { *st_harm_cor_cnt = 1; + move16(); } - if ( GT_16( *st_harm_cor_cnt, 1 ) && - GT_16( Etot, 7680 ) && /* 30.0f in Q8 */ - GT_16( st_E_var_est_fx, 32 ) /* 8.0f in Q2 */ - ) + IF( GT_16( *st_harm_cor_cnt, 1 ) && GT_16( Etot, 7680 /* 30.0f in Q8 */ ) && GT_16( st_E_var_est_fx, 32 /* 8.0f in Q2 */ ) ) { - /* st->harm_cor_cnt = max(1, (short) round_f( (float) st->harm_cor_cnt / 4.0f )) ; */ *st_harm_cor_cnt = s_max( 1, shr( add( *st_harm_cor_cnt, 2 ), 2 ) ); move16(); @@ -2928,23 +2973,20 @@ void noise_est_ivas_fx( *-----------------------------------------------------------------*/ /*epsP_0_2 = max(0 , min(8, epsP[0] / epsP[2])); */ - Ltmp = eps_quota_fx( epsP_h[0], epsP_l[0], - epsP_h[2], epsP_l[2], 12 ); /* Word32 Q12 */ - BASOP_SATURATE_WARNING_OFF_EVS /* may saturate*/ -#ifdef BASOP_NOGLOB - epsP_0_2 = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); /* Q12+16 -16 -> Q12 , NB saturation in Q12 sets max value to 7,999 */ -#else /* BASOP_NOGLOB */ - epsP_0_2 = round_fx( L_shl( Ltmp, 16 ) ); /* Q12+16 -16 -> Q12 , NB saturation in Q12 sets max value to 7,999 */ -#endif /* BASOP_NOGLOB */ - BASOP_SATURATE_WARNING_ON_EVS + exp = sub( norm_l( epsP[0] ), 1 ); + num = extract_h( L_shl( epsP[0], exp ) ); // Qx+exp-16 - epsP_0_2 = s_max( 0, epsP_0_2 ); /* min value is 0 , Q12 */ + exp2 = norm_l( epsP[2] ); + den = extract_h( L_shl( epsP[2], exp2 ) ); // Qx+exp2-16 + /* max(0, min(8, epsP[0] / epsP[2])) */ + epsP_0_2 = div_s( num, den ); // Q15+exp-exp2 + epsP_0_2 = shr_sat( epsP_0_2, add( sub( exp, exp2 ), 3 ) ); // Q12 + epsP_0_2 = s_max( 0, epsP_0_2 ); /* min value is 0 , Q12 */ /* st->epsP_0_2_lp = 0.15f * epsP_0_2 + (1.0f-0.15f) * st->epsP_0_2_lp; */ - alpha = 4915; - move16(); /*0.15 in Q15 */ - hNoiseEst->epsP_0_2_lp_fx = noise_est_AR1_Qx( epsP_0_2, hNoiseEst->epsP_0_2_lp_fx, alpha ); + hNoiseEst->epsP_0_2_lp_fx = mac_r( L_mult( epsP_0_2, 4915 /* 0.15 in Q15*/ ), hNoiseEst->epsP_0_2_lp_fx, 27853 /* 0.85 in Q15*/ ); // Q12 + move16(); /* epsP_0_2_ad = (float) fabs(epsP_0_2 - st->epsP_0_2_lp ); */ epsP_0_2_ad = abs_s( sub( epsP_0_2, hNoiseEst->epsP_0_2_lp_fx ) ); /* Q12 */ @@ -2954,13 +2996,17 @@ void noise_est_ivas_fx( } else { st->epsP_0_2_ad_lp = 0.2f * epsP_0_2_ad + (1.0f - 0.2f) * st->epsP_0_2_ad_lp; } */ - alpha = 6554; - move16(); /* 0.2 Q15 */ - if ( LT_16( epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx ) ) + + IF( LT_16( epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx ) ) { - alpha = shr( alpha, 1 ); /* 0.1 Q15 */ + hNoiseEst->epsP_0_2_ad_lp_fx = mac_r( L_mult( epsP_0_2_ad, 3277 /* 0.1 in Q15*/ ), hNoiseEst->epsP_0_2_ad_lp_fx, 29491 /* 0.9 in Q15*/ ); // Q12 + move16(); + } + ELSE + { + hNoiseEst->epsP_0_2_ad_lp_fx = mac_r( L_mult( epsP_0_2_ad, 6554 /* 0.2 in Q15*/ ), hNoiseEst->epsP_0_2_ad_lp_fx, 26214 /* 0.8 in Q15*/ ); // Q12 + move16(); } - hNoiseEst->epsP_0_2_ad_lp_fx = noise_est_AR1_Qx( epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx, alpha ); /* epsP_0_2_ad_lp_max = max(epsP_0_2_ad,st->epsP_0_2_ad_lp);*/ epsP_0_2_ad_lp_max = s_max( epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx ); /* Q12 */ @@ -2970,57 +3016,55 @@ void noise_est_ivas_fx( * Linear predition efficiency 2 to 16 order *-----------------------------------------------------------------*/ - /* epsP_2_16 = max(0 , min(8, epsP[2] / epsP[16])); */ - Ltmp = eps_quota_fx( epsP_h[2], epsP_l[2], - epsP_h[16], epsP_l[16], 12 ); /* Word32 Q12 */ - BASOP_SATURATE_WARNING_OFF_EVS /* may saturate*/ -#ifdef BASOP_NOGLOB - epsP_2_16 = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); /* Q12+16 -16 -> Q12 , - NB saturation in Q12 sets max value to 7,999 */ -#else /* BASOP_NOGLOB */ - epsP_2_16 = round_fx( L_shl( Ltmp, 16 ) ); /* Q12+16 -16 -> Q12 , - NB saturation in Q12 sets max value to 7,999 */ -#endif /* BASOP_NOGLOB */ - BASOP_SATURATE_WARNING_ON_EVS + /*epsP_2_16 = max(0 , min(8, epsP[2] / epsP[16])); */ + exp = sub( norm_l( epsP[2] ), 1 ); + num = extract_h( L_shl( epsP[2], exp ) ); // Qx+exp-16 - epsP_2_16 = s_max( 0, epsP_2_16 ); /* min value is 0 , Q12 */ + exp2 = norm_l( epsP[16] ); + den = extract_h( L_shl( epsP[16], exp2 ) ); // Qx+exp2-16 + epsP_2_16 = div_s( num, den ); // Q15+exp-exp2 + epsP_2_16 = shr_sat( epsP_2_16, add( sub( exp, exp2 ), 3 ) ); // Q12 + epsP_2_16 = s_max( 0, epsP_2_16 ); /* min value is 0 , Q12 */ /* if (epsP_2_16 > st->epsP_2_16_lp){ st->epsP_2_16_lp = 0.2f * epsP_2_16 + (1.0f-0.2f) * st->epsP_2_16_lp; } else { st->epsP_2_16_lp = 0.03f * epsP_2_16 + (1.0f-0.03f) * st->epsP_2_16_lp; - } - - st->epsP_2_16_lp2 = 0.02f * epsP_2_16 + (1.0f-0.02f) * st->epsP_2_16_lp2; */ + } */ - alpha = 983; - move16(); /* 0.03 Q15 */ - if ( GT_16( epsP_2_16, hNoiseEst->epsP_2_16_lp_fx ) ) + IF( GT_16( epsP_2_16, hNoiseEst->epsP_2_16_lp_fx ) ) { - alpha = 6554; - move16(); /* 0.2 Q15 */ + hNoiseEst->epsP_2_16_lp_fx = mac_r( L_mult( epsP_2_16, 6554 /* 0.2 in Q15*/ ), hNoiseEst->epsP_2_16_lp_fx, 26214 /* 0.8 in Q15*/ ); // Q12 + move16(); + } + ELSE + { + hNoiseEst->epsP_2_16_lp_fx = mac_r( L_mult( epsP_2_16, 983 /* 0.03 in Q15*/ ), hNoiseEst->epsP_2_16_lp_fx, 31785 /* 0.97 in Q15*/ ); // Q12 + move16(); } - hNoiseEst->epsP_2_16_lp_fx = noise_est_AR1_Qx( epsP_2_16, hNoiseEst->epsP_2_16_lp_fx, alpha ); - hNoiseEst->epsP_2_16_lp2_fx = noise_est_AR1_Qx( epsP_2_16, hNoiseEst->epsP_2_16_lp2_fx, 655 ); /* 0.02 */ + hNoiseEst->epsP_2_16_lp2_fx = mac_r( L_mult( epsP_2_16, 655 /* 0.02 in Q15*/ ), hNoiseEst->epsP_2_16_lp2_fx, 32113 /* 0.98 in Q15*/ ); // Q12 + move16(); epsP_2_16_dlp = sub( hNoiseEst->epsP_2_16_lp_fx, hNoiseEst->epsP_2_16_lp2_fx ); - /* if (epsP_2_16_dlp < st->epsP_2_16_dlp_lp2 ) { st->epsP_2_16_dlp_lp2 = 0.02f * epsP_2_16_dlp + (1.0f-0.02f) * st->epsP_2_16_dlp_lp2; } else { st->epsP_2_16_dlp_lp2 = 0.05f * epsP_2_16_dlp + (1.0f-0.05f) * st->epsP_2_16_dlp_lp2; }*/ - alpha = 1638; - move16(); /* 0.05 Q15 */ - if ( LT_16( epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2_fx ) ) + + IF( LT_16( epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2_fx ) ) { - alpha = 655; - move16(); /* 0.02 Q15 */ + hNoiseEst->epsP_2_16_dlp_lp2_fx = mac_r( L_mult( epsP_2_16_dlp, 655 /* 0.02 in Q15*/ ), hNoiseEst->epsP_2_16_dlp_lp2_fx, 32113 /* 0.98 in Q15*/ ); // Q12 + move16(); + } + ELSE + { + hNoiseEst->epsP_2_16_dlp_lp2_fx = mac_r( L_mult( epsP_2_16_dlp, 1638 /* 0.05 in Q15*/ ), hNoiseEst->epsP_2_16_dlp_lp2_fx, 31130 /* 0.95 in Q15*/ ); // Q12 + move16(); } - hNoiseEst->epsP_2_16_dlp_lp2_fx = noise_est_AR1_Qx( epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2_fx, alpha ); /* epsP_2_16_dlp_max = max(epsP_2_16_dlp,st->epsP_2_16_dlp_lp2); */ epsP_2_16_dlp_max = s_max( epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2_fx ); @@ -3038,14 +3082,17 @@ void noise_est_ivas_fx( tmp2 = 32767; move16(); } - hNoiseEst->lt_tn_track_fx = noise_est_AR1_Qx( tmp2, hNoiseEst->lt_tn_track_fx, 983 ); /*0.03 in Q15 ,Q15 state*/ + hNoiseEst->lt_tn_track_fx = mac_r( L_mult( tmp2, 983 /* 0.03 in Q15*/ ), hNoiseEst->lt_tn_track_fx, 31785 /* 0.97 in Q15*/ ); // Q12 + move16(); /* st->lt_tn_dist = 0.03f* (Etot - st->totalNoise) + 0.97f*st->lt_tn_dist; */ - hNoiseEst->lt_tn_dist_fx = noise_est_AR1_Qx( tmp, hNoiseEst->lt_tn_dist_fx, 983 ); /*0.03 in Q15 ,Q8 state*/ + hNoiseEst->lt_tn_dist_fx = mac_r( L_mult( tmp, 983 /* 0.03 in Q15*/ ), hNoiseEst->lt_tn_dist_fx, 31785 /* 0.97 in Q15*/ ); // Q8 + move16(); /* st->lt_Ellp_dist = 0.03f* (Etot - st->Etot_l_lp) + 0.97f*st->lt_Ellp_dist;*/ - tmp = sub( Etot, hNoiseEst->Etot_l_lp_fx ); /* Q8 */ - hNoiseEst->lt_Ellp_dist_fx = noise_est_AR1_Qx( tmp, hNoiseEst->lt_Ellp_dist_fx, 983 ); /*0.03 in Q15 ,Q8 state*/ + tmp = sub( Etot, hNoiseEst->Etot_l_lp_fx ); /* Q8 */ + hNoiseEst->lt_Ellp_dist_fx = mac_r( L_mult( tmp, 983 /* 0.03 in Q15*/ ), hNoiseEst->lt_Ellp_dist_fx, 31785 /* 0.97 in Q15*/ ); // Q8 + move16(); /* if (st->harm_cor_cnt == 0) { @@ -3055,29 +3102,30 @@ void noise_est_ivas_fx( } */ IF( *st_harm_cor_cnt == 0 ) { - hNoiseEst->lt_haco_ev_fx = noise_est_AR1_Qx( (Word16) 32767, hNoiseEst->lt_haco_ev_fx, 983 ); /*.03 in Q15 , Q15 state */ + hNoiseEst->lt_haco_ev_fx = mac_r( 64424509 /* 0.03 in Q32*/, hNoiseEst->lt_haco_ev_fx, 31785 /* 0.97 in Q15*/ ); // Q15 + move16(); } ELSE { hNoiseEst->lt_haco_ev_fx = mult_r( 32440, hNoiseEst->lt_haco_ev_fx ); /*.99 in Q15 , Q15 state */ + move16(); } - /* if (st->lt_tn_track < 0.05f) { st->low_tn_track_cnt++; } else { st->low_tn_track_cnt=0; }*/ - tmp = 0; - move16(); - move16(); - if ( LT_16( hNoiseEst->lt_tn_track_fx, 1638 ) ) /* 0.05 in Q15*/ + IF( LT_16( hNoiseEst->lt_tn_track_fx, 1638 ) ) /* 0.05 in Q15*/ { - tmp = add( hNoiseEst->low_tn_track_cnt, 1 ); + hNoiseEst->low_tn_track_cnt = add( hNoiseEst->low_tn_track_cnt, 1 ); + move16(); + } + ELSE + { + hNoiseEst->low_tn_track_cnt = 0; + move16(); } - hNoiseEst->low_tn_track_cnt = tmp; - move16(); - /* update of the long-term non-stationarity measure (between 0 and 1) */ /* if ( (non_sta > th_sta) || (*loc_harm > 0) ) { @@ -3085,35 +3133,21 @@ void noise_est_ivas_fx( } else { st->act_pred = M_GAMMA * st->act_pred + (1-M_GAMMA) * 0; }*/ - Ltmp = L_mult( M_GAMMA_FX, hNoiseEst->act_pred_fx ); /*Q15*Q15+1 --> Q31 , 32440= .99 Q15 */ - tmp = round_fx( Ltmp ); /* Q15 */ test(); - if ( ( GT_32( non_sta, th_sta ) ) /* float th_sta NB 5e10 , WB 3.5e10*/ - || ( *loc_harm > 0 ) ) + IF( ( GT_32( non_sta, th_sta ) ) || ( *loc_harm > 0 ) ) { - tmp = mac_r( Ltmp, ( -32768 + M_GAMMA_FX ), -32768 ); /* (-0.01)*(-1.0) */ + hNoiseEst->act_pred_fx = mac_r( 21474836 /* 1 - M_GAMMA in Q31 */, M_GAMMA_FX, hNoiseEst->act_pred_fx ); // Q31 + move16(); + } + ELSE + { + hNoiseEst->act_pred_fx = mult_r( M_GAMMA_FX, hNoiseEst->act_pred_fx ); /*Q15*Q15+1 --> Q31 , 32440= .99 Q15 */ + move16(); } - hNoiseEst->act_pred_fx = tmp; - move16(); - /*-----------------------------------------------------------------* * Background noise adaptation enable flag *-----------------------------------------------------------------*/ - Ltmp = L_mult( st_fx->voicing_fx[0], 16384 ); - Ltmp = L_mac( Ltmp, st_fx->voicing_fx[1], 16384 ); -#ifdef BASOP_NOGLOB - cor_tmp = mac_ro( Ltmp, corr_shift, MAX_16, &Overflow ); -#else /* BASOP_NOGLOB */ - cor_tmp = mac_r( Ltmp, corr_shift, MAX_16 ); -#endif - - LepsP = eps_quota_fx( epsP_h[2], epsP_l[2], - epsP_h[16], epsP_l[16], 11 ); /* L_epsP in Q11 */ - /* note this epsP2/eps16 is not limited to 8 as, epsP_2_16 is !! */ - - vad_2nd_stage_fx = 0; - move16(); /* background noise present - decrement counter */ /* if( ( (*st_harm_cor_cnt < 3*HC_CNT_SLOW ) && ( ( non_sta > th_sta ) || @@ -3135,6 +3169,16 @@ void noise_est_ivas_fx( cor_tmp = 0; move16(); } + /* epsP[2] / epsP[16] */ + exp = sub( norm_l( epsP[2] ), 1 ); + num = extract_h( L_shl( epsP[2], exp ) ); // Qx+exp-16 + + exp2 = norm_l( epsP[16] ); + den = extract_h( L_shl( epsP[16], exp2 ) ); // Qx+exp2-16 + + LepsP = extract_l( div_s( num, den ) ); // Q15+exp-exp2 + LepsP = L_shr( LepsP, add( sub( exp, exp2 ), 4 ) ); // Q11 + test(); test(); @@ -3146,31 +3190,35 @@ void noise_est_ivas_fx( test(); test(); test(); - - if ( ( ( LT_16( *st_harm_cor_cnt, ( 3 * HC_CNT_SLOW_FX ) ) ) && ( ( GT_32( non_sta, th_sta ) ) || ( LT_16( tmp_pc, TH_PC_FX ) ) || ( GT_16( noise_char, 0 ) ) ) ) || - ( ( GT_16( st_fx->ini_frame, HE_LT_CNT_INIT_FX ) ) && ( GT_16( sub( Etot, Etot_l_lp ), 2560 ) ) ) || - ( GT_16( cor_tmp, cor_max ) ) || /* Q15 */ - ( GT_32( LepsP, th_eps ) ) || /* Q11 */ - ( GT_16( *loc_harm, 0 ) ) || - ( ( GT_16( hNoiseEst->act_pred_fx, 26214 ) ) && ( GT_32( Lnon_sta2, th_sta ) ) ) /*act_pred in Q15 , th_sta in Q10 */ + IF( ( ( LT_16( *st_harm_cor_cnt, ( 3 * HC_CNT_SLOW_FX ) ) ) && ( ( GT_32( non_sta, th_sta ) ) || ( LT_16( tmp_pc, TH_PC_FX ) ) || ( noise_char > 0 ) ) ) || + ( ( GT_16( st_fx->ini_frame, HE_LT_CNT_INIT_FX ) ) && ( GT_16( sub( Etot, Etot_l_lp ), 2560 ) ) ) || + ( GT_16( cor_tmp, cor_max ) ) || /* Q15 */ + ( GT_32( LepsP, th_eps ) ) || /* Q11 */ + ( GT_16( *loc_harm, 0 ) ) || + ( ( GT_16( hNoiseEst->act_pred_fx, 26214 ) ) && ( GT_32( Lnon_sta2, th_sta ) ) ) /*act_pred in Q15 , th_sta in Q10 */ ) { - vad_2nd_stage_fx = 1; - move16(); /* active signal present - increment counter */ + /* hNoiseEst->aEn = hNoiseEst->aEn + 2; */ + hNoiseEst->aEn = add( hNoiseEst->aEn, 2 ); /* active signal present - increment counter */ + move16(); } - - tmp = 2; - move16(); /* Signal present */ - if ( vad_2nd_stage_fx == 0 ) + ELSE { - tmp = -1; - move16(); /* Background present */ + /* hNoiseEst->aEn = hNoiseEst->aEn - 1; */ + hNoiseEst->aEn = add( hNoiseEst->aEn, -1 ); /* background noise present - decrement counter */ + move16(); } - hNoiseEst->aEn = add( hNoiseEst->aEn, tmp ); + hNoiseEst->aEn = s_max( s_min( hNoiseEst->aEn, 6 ), 0 ); + move16(); - hNoiseEst->aEn = s_min( hNoiseEst->aEn, 6 ); - hNoiseEst->aEn = s_max( hNoiseEst->aEn, 0 ); + IF( LE_16( hNoiseEst->aEn, 1 ) ) + { + hNoiseEst->aEn_inac_cnt = add( hNoiseEst->aEn_inac_cnt, 1 ); + hNoiseEst->aEn_inac_cnt = s_min( hNoiseEst->aEn_inac_cnt, 128 ); + move16(); + move16(); + } /*-----------------------------------------------------------------* * Stereo classifier - save raw aEn *-----------------------------------------------------------------*/ @@ -3182,33 +3230,25 @@ void noise_est_ivas_fx( ( 0.5f * ( st->voicing[0] + st->voicing[1] ) > cor_max ) || ( epsP[2] / epsP[16] > th_eps ) || ( ( hNoiseEst->act_pred > 0.8f ) && ( non_sta2 > th_sta ) ) )*/ + wtmp = sub( hStereoClassif->aEn_raw[st_fx->idchan], 1 ); test(); test(); test(); test(); test(); - IF( ( GT_32( non_sta, th_sta ) ) || ( LT_16( tmp_pc, TH_PC_FX ) ) || - ( GT_16( cor_tmp, cor_max ) ) || - ( GT_32( LepsP, th_eps ) ) || - ( ( GT_16( hNoiseEst->act_pred_fx, 26214 ) ) && ( GT_32( Lnon_sta2, th_sta ) ) ) ) /*act_pred in Q15 , th_sta in Q10 */ + if ( ( GT_32( non_sta, th_sta ) ) || ( LT_16( tmp_pc, TH_PC_FX ) ) || + ( GT_16( cor_tmp, cor_max ) ) || + ( GT_32( LepsP, th_eps ) ) || + ( ( GT_16( hNoiseEst->act_pred_fx, 26214 ) ) && ( GT_32( Lnon_sta2, th_sta ) ) ) ) /*act_pred in Q15 , th_sta in Q10 */ { /* active signal present - increment counter */ - hStereoClassif->aEn_raw[st_fx->idchan] = hStereoClassif->aEn_raw[st_fx->idchan] + 2; - } - ELSE - { - /* background noise present - decrement counter */ - hStereoClassif->aEn_raw[st_fx->idchan] = hStereoClassif->aEn_raw[st_fx->idchan] - 1; + wtmp = add( hStereoClassif->aEn_raw[st_fx->idchan], 2 ); } + hStereoClassif->aEn_raw[st_fx->idchan] = wtmp; move16(); - if ( GT_16( hStereoClassif->aEn_raw[st_fx->idchan], 6 ) ) - { - hStereoClassif->aEn_raw[st_fx->idchan] = 6; - } - else if ( hStereoClassif->aEn_raw[st_fx->idchan] < 0 ) - { - hStereoClassif->aEn_raw[st_fx->idchan] = 0; - } + + wtmp = s_min( hStereoClassif->aEn_raw[st_fx->idchan], 6 ); + hStereoClassif->aEn_raw[st_fx->idchan] = s_max( wtmp, 0 ); move16(); } @@ -3217,7 +3257,7 @@ void noise_est_ivas_fx( /* comb_ahc_epsP = max(max(st->act_pred, st->lt_haco_ev), epsP_2_16_dlp); */ /* Q15 Q15 Q12 */ - comb_ahc_epsP = s_max( s_max( shr( hNoiseEst->act_pred_fx, 15 - 12 ), shr( hNoiseEst->lt_haco_ev_fx, 15 - 12 ) ), epsP_2_16_dlp ); /* Q12 */ + comb_ahc_epsP = s_max( shr( s_max( hNoiseEst->act_pred_fx, hNoiseEst->lt_haco_ev_fx ), 15 - 12 ), epsP_2_16_dlp ); /* Q12 */ /* comb_hcm_epsP = max(max(st->lt_haco_ev,epsP_2_16_dlp_max),epsP_0_2_ad_lp_max); */ @@ -3229,7 +3269,7 @@ void noise_est_ivas_fx( move16(); if ( *st_harm_cor_cnt == 0 ) { - tmp = (Word16) 32767; + tmp = 32767; move16(); } haco_ev_max = s_max( tmp, hNoiseEst->lt_haco_ev_fx ); /* Q15 */ @@ -3277,7 +3317,7 @@ void noise_est_ivas_fx( /* ns_mask = non_sta < 1e5f; */ ns_mask = 0; move16(); - if ( LT_32( non_sta, (Word32) 102400000L ) ) /* (1e5f in Q10)*/ + if ( LT_32( non_sta, 102400000 ) ) /* (1e5f in Q10)*/ { ns_mask = 1; move16(); /* Q0 */ @@ -3313,14 +3353,18 @@ void noise_est_ivas_fx( SD_1 = 1; move16(); /* Q0 */ } - SD_1_inv = sub( 1, SD_1 ); /* Q0 */ /* NB "STL::test()"; has a cost of 2, using bitwise "s_and" , "s_or" at a cost of 1 */ /* NB only lowest bit position is used, result is always 0 or 1 */ /* bg_bgd3 = enr_bgd || ( ( cns_bgd || lp_bgd ) && ns_mask && lt_haco_mask && SD_1==0 ); */ - tmp = s_and( s_and( s_and( s_or( cns_bgd, lp_bgd ), ns_mask ), lt_haco_mask ), SD_1_inv ); - bg_bgd3 = s_or( enr_bgd, tmp ); + test(); + test(); + test(); + test(); + test(); + bg_bgd3 = enr_bgd || ( ( cns_bgd || lp_bgd ) && ns_mask && lt_haco_mask && ( SD_1 == 0 ) ); + move16(); /*PD_1 = (epsP_2_16_dlp_max < 0.10f ) ; */ PD_1 = 0; @@ -3386,21 +3430,19 @@ void noise_est_ivas_fx( || ( (Etot < 55.0f) && (SD_1==0) && ( ( PD_3 && (PD_1 || PD_2 ) ) || ( PD_4 || PD_5 ) ) ); */ PAU = 0; - move16(); /*Q0*/ - if ( hNoiseEst->aEn == 0 ) + move16(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + if ( ( hNoiseEst->aEn == 0 ) || ( LT_16( Etot, 55 * 256 ) && ( SD_1 == 0 ) && ( ( PD_3 && ( PD_1 || PD_2 ) ) || ( PD_4 || PD_5 ) ) ) ) { PAU = 1; - move16(); /*Q0*/ - } - tmp = 0; - move16(); /*Q0*/ - if ( LT_16( Etot, 55 * 256 ) ) /*55.0 in Q8 */ - { - tmp = 1; - move16(); /*Q0*/ + move16(); } - tmp = s_and( tmp, SD_1_inv ); - PAU = s_or( PAU, s_and( tmp, s_or( s_and( PD_3, s_or( PD_1, PD_2 ) ), s_or( PD_4, PD_5 ) ) ) ); /* NEW_POS_BG = (PAU | BG_1) & bg_bgd3; note bitwise logic in float */ @@ -3416,7 +3458,6 @@ void noise_est_ivas_fx( move16(); } - /* When the signal dynamics is high and the energy is close to the background estimate */ /* sd1_bgd = (st->sign_dyn_lp > 15) && (Etot - st->Etot_l_lp ) < 2*st->Etot_v_h2 @@ -3439,34 +3480,27 @@ void noise_est_ivas_fx( st->lt_haco_ev < 0.15f || non_staB < 50.0f || aE_bgd );*/ - - tmp = 0; + tn_ini = 0; move16(); test(); test(); test(); test(); test(); - if ( ( ( LT_16( hNoiseEst->act_pred_fx, 19333 ) ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 7537 ) ) ) /* .59 in Q15 .23 in Q15 */ - || ( LT_16( hNoiseEst->act_pred_fx, 12452 ) ) /* .38 in Q15 */ - || ( ( EQ_16( st_fx->element_mode, EVS_MONO ) && LT_16( hNoiseEst->lt_haco_ev_fx, 4915 ) ) || ( GT_16( st_fx->element_mode, EVS_MONO ) && LT_16( hNoiseEst->lt_haco_ev_fx, 2621 ) ) ) /* .15 in Q15 || 0.08 */ - || ( LT_16( non_staB, 50 * 256 ) ) /* 50.0 in Q8 */ - || aE_bgd != 0 || ( ( LT_16( Etot, 10752 ) ) /* 42 in Q8 */ - && ( GT_16( hNoiseEst->harm_cor_cnt, 10 ) ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 11469 ) ) /* 0.35 in Q15 */ - && ( LT_16( hNoiseEst->act_pred_fx, 26214 ) ) /* 0.80 in Q15 */ - ) ) - { - tmp = 1; - move16(); - } - - tn_ini = 0; - move16(); test(); test(); - if ( ( LT_16( st_fx->ini_frame, HE_LT_CNT_INIT_FX ) ) && ( GT_16( hNoiseEst->harm_cor_cnt, 5 ) ) /* > 5 Q0 */ - && ( LT_16( sub( Etot, hNoiseEst->Etot_lp_fx ), 1792 ) ) /* 7 in Q8 */ - && ( NE_16( tmp, 0 ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + if ( LT_16( st_fx->ini_frame, HE_LT_CNT_INIT_FX ) && GT_16( hNoiseEst->harm_cor_cnt, 5 ) && LT_16( sub( Etot, hNoiseEst->Etot_lp_fx ), 1792 /* 7 in Q8 */ ) && + ( ( LT_16( hNoiseEst->act_pred_fx, 19333 /* 0.59 in Q15 */ ) && LT_16( hNoiseEst->lt_haco_ev_fx, 7537 /* 0.23 in Q15 */ ) ) || LT_16( hNoiseEst->act_pred_fx, 12452 /* 0.38 in Q15 */ ) || + ( ( ( st_fx->element_mode == EVS_MONO ) && LT_16( hNoiseEst->lt_haco_ev_fx, 4915 /* 0.15 in Q15 */ ) ) || ( ( st_fx->element_mode > EVS_MONO ) && LT_16( hNoiseEst->lt_haco_ev_fx, 2621 /* 0.08 in Q15 */ ) ) ) || + LT_16( non_staB, 50 * 256 /* 50 in Q8 */ ) || ( aE_bgd != 0 ) || ( LT_16( Etot, 10752 /* 42.0 in Q8 */ ) && GT_16( hNoiseEst->harm_cor_cnt, 10 ) && LT_16( hNoiseEst->lt_haco_ev_fx, 11469 /* 0.35 in Q8 */ ) && LT_16( hNoiseEst->act_pred_fx, 26214 /* 0.8 in Q8 */ ) ) ) ) { tn_ini = 1; move16(); @@ -3487,15 +3521,12 @@ void noise_est_ivas_fx( move16(); /* Q15 */ /*if (( bg_bgd2 && ( aE_bgd || sd1_bgd || st->lt_tn_track >0.90f || NEW_POS_BG ) ) || tn_ini ) */ - tmp = 0; - move16(); - if ( GT_16( hNoiseEst->lt_tn_track_fx, 29491 ) ) /* .90 in Q15 */ - { - tmp = 1; - move16(); - } - - IF( s_or( s_and( bg_bgd2, s_or( aE_bgd, s_or( sd1_bgd, s_or( tmp, NEW_POS_BG ) ) ) ), tn_ini ) ) + test(); + test(); + test(); + test(); + test(); + IF( ( bg_bgd2 && ( aE_bgd || sd1_bgd || GT_16( hNoiseEst->lt_tn_track_fx, 29491 /* 0.90 in Q15 */ ) || NEW_POS_BG ) ) || tn_ini ) { /*if( ( ( st->act_pred < 0.85f ) && (aE_bgd !=0) @@ -3538,20 +3569,15 @@ void noise_est_ivas_fx( test(); test(); test(); - IF( ( ( LT_16( hNoiseEst->act_pred_fx, 27853 ) ) /* 0.85 in Q15 */ - && ( NE_16( aE_bgd, 0 ) ) && ( ( LT_16( hNoiseEst->lt_Ellp_dist_fx, 10 * 256 ) ) || ( NE_16( sd1_bgd, 0 ) ) ) /* 10.0 in Q8*/ - && ( LT_16( hNoiseEst->lt_tn_dist_fx, 40 * 256 ) ) /* 40.0 in Q8*/ - && ( LT_16( sub( Etot, hNoiseEst->totalNoise_fx ), 10 * 256 ) ) /* 10.0 in Q8*/ - ) || - ( ( hNoiseEst->first_noise_updt == 0 ) && ( GT_16( hNoiseEst->harm_cor_cnt, 80 ) ) && ( aE_bgd != 0 ) && ( GT_16( hNoiseEst->lt_aEn_zero_fx, 16384 ) ) /*.5 in Q15*/ - ) || - ( ( tn_ini != 0 ) && ( ( aE_bgd != 0 ) || ( LT_16( non_staB, 10 * 256 ) ) || ( GT_16( hNoiseEst->harm_cor_cnt, 80 ) ) ) /* 10.0 in Q8*/ - ) ) - + IF( ( LT_16( hNoiseEst->act_pred_fx, 27853 /* 0.85 in Q15 */ ) && ( aE_bgd != 0 ) && ( LT_16( hNoiseEst->lt_Ellp_dist_fx, 10 * 256 /* 10 in Q8*/ ) || ( sd1_bgd != 0 ) ) && ( LT_16( hNoiseEst->lt_tn_dist_fx, 40 * 256 ) ) /* 40.0 in Q8*/ + && LT_16( sub( Etot, hNoiseEst->totalNoise_fx ), 10 * 256 /* 10 in Q8 */ ) /* 10.0 in Q8*/ ) || + ( ( hNoiseEst->first_noise_updt == 0 ) && GT_16( hNoiseEst->harm_cor_cnt, 80 ) && ( aE_bgd != 0 ) && GT_16( hNoiseEst->lt_aEn_zero_fx, 16384 /* 0.5 in Q15 */ ) ) || + ( ( tn_ini != 0 ) && ( ( aE_bgd != 0 ) || LT_16( non_staB, 10 * 256 /* 10 in Q8*/ ) || GT_16( hNoiseEst->harm_cor_cnt, 80 ) ) ) ) { updt_step = 32767; move16(); hNoiseEst->first_noise_updt = 1; + move16(); FOR( i = 0; i < NB_BANDS; i++ ) { hNoiseEst->bckr_fx[i] = tmpN[i]; @@ -3565,21 +3591,14 @@ void noise_est_ivas_fx( ( st->harm_cor_cnt > 50 && st->first_noise_updt > 30 && aE_bgd && st->lt_aEn_zero>0.5f ) || tn_ini ) */ - ELSE IF( ( ( LT_16( hNoiseEst->act_pred_fx, 26214 ) ) /* .8 in Q15*/ - && ( ( aE_bgd != 0 ) || ( PAU != 0 ) ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 3277 ) ) ) /* .10 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( (Word16) 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, 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 ) ) - + 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, 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; move16(); /* 0.1 in Q15 */ + /* if ( !aE_bgd && st->harm_cor_cnt < 50 && ( (st->act_pred > 0.6f) || ( (tn_ini==0) && (Etot_l_lp - st->totalNoise < 10.0f) && non_staB > 8.0f ) @@ -3591,37 +3610,31 @@ void noise_est_ivas_fx( test(); test(); test(); - IF( ( aE_bgd == 0 ) && ( LT_16( hNoiseEst->harm_cor_cnt, 50 ) ) && ( ( GT_16( hNoiseEst->act_pred_fx, 19661 ) ) /* 0.6 in Q15*/ - || ( ( tn_ini == 0 ) && ( LT_16( sub( Etot_l_lp, hNoiseEst->totalNoise_fx ), 10 * 256 ) ) /* 10.0 in Q8 */ - && ( GT_16( non_staB, 8 * 256 ) ) /* 8.0 in in Q8*/ - ) ) ) + if ( ( aE_bgd == 0 ) && LT_16( hNoiseEst->harm_cor_cnt, 50 ) && + ( GT_16( hNoiseEst->act_pred_fx, 19661 /* 0.6 in Q15*/ ) || + ( ( tn_ini == 0 ) && LT_16( sub( Etot_l_lp, hNoiseEst->totalNoise_fx ), 10 * 256 /* 10.0 in Q8 */ ) && GT_16( non_staB, 8 * 256 /* 8.0 in in Q8*/ ) ) ) ) { updt_step = 328; move16(); /* 0.01 Q15 */ } - /* - IF (updt_step > 0 ) - { - */ + hNoiseEst->first_noise_updt = 1; move16(); 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( tmpN[i], hNoiseEst->bckr_fx[i] ); /*Q_new+Q_SCALE*/ + Ltmp = L_sub( tmpN[i], hNoiseEst->bckr_fx[i] ); // hNoiseEst->q_bckr Ltmp = Mult_32_16( Ltmp, updt_step ); - /* Q_new+Q_SCALE+15+1 -16*/ - hNoiseEst->bckr_fx[i] = L_add( Ltmp, hNoiseEst->bckr_fx[i] ); + hNoiseEst->bckr_fx[i] = L_add( Ltmp, hNoiseEst->bckr_fx[i] ); // hNoiseEst->q_bckr move32(); } - /* - } */ } /*else if (aE_bgd || st->harm_cor_cnt > 100 )*/ - ELSE IF( ( aE_bgd != 0 ) || ( GT_16( hNoiseEst->harm_cor_cnt, 100 ) ) ) + ELSE IF( ( aE_bgd != 0 ) || GT_16( hNoiseEst->harm_cor_cnt, 100 ) ) { hNoiseEst->first_noise_updt = add( hNoiseEst->first_noise_updt, 1 ); + move16(); } } ELSE @@ -3629,18 +3642,17 @@ void noise_est_ivas_fx( /* If in music lower bckr to drop further */ test(); test(); - IF( ( GT_16( hNoiseEst->low_tn_track_cnt, 300 ) ) && ( GT_16( hNoiseEst->lt_haco_ev_fx, 29491 ) ) /*.9 in Q15 */ - && ( hNoiseEst->totalNoise_fx > 0 ) ) + IF( GT_16( hNoiseEst->low_tn_track_cnt, 300 ) && GT_16( hNoiseEst->lt_haco_ev_fx, 29491 /* 0.9 in Q15 */ ) && ( hNoiseEst->totalNoise_fx > 0 ) ) { updt_step = -655; move16(); /* for debug purposes */ FOR( i = 0; i < NB_BANDS; i++ ) { - IF( GT_32( hNoiseEst->bckr_fx[i], L_shl( Le_min_scaled, 1L ) ) ) /* 2*E_MIN(float) in float, here we use 2*Le_min_scaled Q_new+Q_SCALE */ + IF( GT_32( hNoiseEst->bckr_fx[i], L_shl_sat( E_MIN_FXQ31, sub( hNoiseEst->q_bckr, Q30 ) ) /* 2*E_MIN */ ) ) { /* st->bckr[i] = 0.98f*st->bckr[i]; */ - hNoiseEst->bckr_fx[i] = Mult_32_16( hNoiseEst->bckr_fx[i], 32113 ); /* .98 in Q15 */ - move32(); /* move to array */ + hNoiseEst->bckr_fx[i] = Mult_32_16( hNoiseEst->bckr_fx[i], 32113 /* .98 in Q15 */ ); // hNoiseEst->q_bckr + move32(); /* move to array */ } } } @@ -3651,10 +3663,12 @@ void noise_est_ivas_fx( move16(); if ( hNoiseEst->aEn == 0 ) { - tmp = 32767; + tmp = 6554; // 0.2 in Q15 move16(); } - hNoiseEst->lt_aEn_zero_fx = noise_est_AR1_Qx( tmp, hNoiseEst->lt_aEn_zero_fx, 6554 ); /* alpha=0.2 , Q15 */ + hNoiseEst->lt_aEn_zero_fx = mac_r( tmp, hNoiseEst->lt_aEn_zero_fx, 26214 /* 0.8 in Q15*/ ); // Q15 + move16(); + IF( st_fx->element_mode > EVS_MONO ) { test(); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 7af3830abdbb2a3877d8010aea0d41ede9a837a3..c96678a7a5dfee59c304f367629094b6e16159ef 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -226,22 +226,22 @@ Word16 ffr_getSfWord32( const Word16 len /*!< Length of i vector */ ); void find_tilt_ivas_fx( - const Word32 fr_bands[], /* i : energy in frequency bands Q_new*/ - const Word32 bckr[], /* i : per band background noise energy estimate Q_new*/ - Word32 ee[2], /* o : lf/hf E ration for present frame Q_bckr*/ - const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ - const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ - const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new - 2*/ - const Word16 corr_shift, /* i : normalized correlation correction Q15*/ - const Word16 bwidth, /* i : input signal bandwidth Q0*/ - const Word16 max_band, /* i : maximum critical band Q0*/ - Word32 hp_E[], /* o : energy in HF Q_new*/ - const Word16 codec_mode, /* i : MODE1 or MODE2 Q0*/ - const Word16 Q_new, /* i : scaling factor */ - Word32 *bckr_tilt_lt /* i/o: lf/hf E ratio of background noise Q16*/ - , - Word16 Opt_vbr_mode /* Q0 */ -); + const Word32 fr_bands[], /* i : energy in frequency bands q_fr_bands*/ + const Word16 q_fr_bands, /* i : Q of fr_bands Q0*/ + const Word32 bckr[], /* i : per band background noise energy estimate q_bckr*/ + const Word16 q_bckr, /* i : Q of bckr Q0*/ + Word32 ee[2], /* o : lf/hf E ration for present frame Q_bckr*/ + const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ + const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ + const Word32 *lf_E, /* i : per bin energy for low frequencies q_lf_E*/ + const Word16 q_lf_E, /* i : Q of lf_E */ + const Word16 corr_shift, /* i : normalized correlation correction Q15*/ + const Word16 bwidth, /* i : i signal bandwidth */ + const Word16 max_band, /* i : maximum critical band */ + Word32 hp_E[], /* o : energy in HF Q_new*/ + const Word16 codec_mode, /* i : MODE1 or MODE2 */ + Word32 *bckr_tilt_lt, + Word16 Opt_vbr_mode ); void find_tilt_fx( const Word32 fr_bands[], /* i : energy in frequency bands Q_new + Q_SCALE*/ @@ -409,27 +409,27 @@ 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 Word16 epsP_h[], /* i : msb prediction error energies Q_r-1 */ - const Word16 epsP_l[], /* i : msb prediction error energies Q_r-1 */ + 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? */ const Word16 corr_shift, /* i : normalized correlation correction Q15 */ - const Word32 enr[], /* i : averaged energy over both subframes Q_new + Q_SCALE */ - Word32 fr_bands[], /* i : spectrum per critical bands of the current frame Q_new + Q_SCALE */ + const Word32 enr[], /* i : averaged energy over both subframes q_enr */ + const Word16 q_enr, /* i : q_enr of enr Q0 */ + Word32 fr_bands[], /* i : spectrum per critical bands of the current frame q_fr_bands */ + Word16 q_fr_bands, /* i : Q of q_fr_bands */ Word16 *cor_map_sum, /* o : Q8 */ Word16 *ncharX, /* o : Q11 */ Word16 *sp_div, /* o : Q_sp_div */ Word16 *Q_sp_div, /* o : Q factor for sp_div */ Word16 *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_new + Q_SCALE -2 */ + 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 */ Word16 *st_harm_cor_cnt, /* i/o : 1st harm correlation timer Q0 */ const Word16 Etot_l_lp, /* i : Smoothed low energy Q8 */ const Word16 Etot_v_h2, /* i : Energy variations Q8 */ Word16 *bg_cnt, /* i : Background burst length timer Q0 */ Word16 EspecdB[], /* i/o: log E spectrum (with f=0) of the current frame Q7 for multi harm */ - Word16 Q_new, /* i : SCaling of current frame */ - const Word32 Le_min_scaled, /*i : Minimum energy value in Q_new + Q_SCALE */ Word16 *sp_floor, /* o : noise floor estimate Q7 */ Word16 S_map[], /* o : short-term correlation map Q7 */ STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index c5a131ac3d214d7863e6bf85624d5544a122eaab..8884f2624ff983c9d16cdf73df57b9fba1760658 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -2517,7 +2517,8 @@ Word16 ivas_smc_gmm_fx( /* xtalk classifier: apply long hysteresis to prevent LRTD on music */ - hSpMusClas->wdlp_xtalk_fx = L_add( Mpy_32_32( 2136746229, hSpMusClas->wdlp_xtalk_fx ), Mpy_32_32( 10737418, dlp_fx ) ); + hSpMusClas->wdlp_xtalk_fx = Madd_32_32( Mpy_32_32( 2136746230 /* 0.995f in Q31*/, hSpMusClas->wdlp_xtalk_fx /* Q25*/ ), 687194767 /* 0.005f in Q37 */, dlp_fx /* Q19*/ ); // Q25 + move32(); /*------------------------------------------------------------------* * Final speech/music decision diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index f4317fe8850ebc834f9a7ea25706f5978fc3c1ae..24c8b9fceda634925b49f6a6c159314a6d06e7b4 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -588,7 +588,7 @@ typedef struct sp_mus_clas_structure Word16 wrise_fx; /* Q9 */ Word16 wdlp_0_95_sp_fx; /* EVS - Q8 */ Word32 wdlp_0_95_sp_32fx; /* IVAS - Q24 */ - Word32 wdlp_xtalk_fx; /* Q19 */ + Word32 wdlp_xtalk_fx; /* Q25 */ Word16 sp_mus_state; Word16 past_dec[HANG_LEN - 1]; /* Speech/music classifier - buffer of past binary decisions */ Word16 past_dlp_fx[HANG_LEN - 1]; /* Speech/music classifier - buffer of past non-binary decisions Q9 */