Loading lib_com/cnst.h +9 −0 Original line number Diff line number Diff line Loading @@ -1682,6 +1682,15 @@ enum #define HALF_D_STAB_TBL_FX ( (Word16) 422 ) /* Q13 0.1013138/2.0 */ #define NUM_ENV_STAB_PLC_STATES 2 /* Number of states of markov model */ #ifdef ENV_STAB_FIX #define ENV_STAB_EST1 2.93f /* env_stab estimation coefficient 1 */ #define ENV_STAB_EST2 (-2.20f) /* env_stab estimation coefficient 2 */ #define ENV_STAB_EST3 0.741f /* env_stab estimation coefficient 3 */ #define STAB_FAC_EST1 1.093f /* stab_fac HQ estimation coefficient 1 */ #define STAB_FAC_EST2 (-5.84e-05f) /* stab_fac HQ estimation coefficient 2, including Q12 scaling */ #define STAB_FAC_EST3 0.125f /* stab_fac HQ estimation coefficient 3 */ #endif #define ATT_LIM_HANGOVER 150 /* Number of hangover frames for disabling stability dependent attenuation */ #define DELTA_TH 5.0f /* Delta energy threshold for transient detection for envelope stability */ #define ENERGY_TH 100.0f /* Energy threshold for transient detection */ Loading lib_com/env_stab.c +79 −8 Original line number Diff line number Diff line Loading @@ -66,7 +66,12 @@ float env_stability( const int16_t *ynrm, /* i : Norm vector for current frame */ const int16_t nb_sfm, /* i : Number of sub-bands */ int16_t *mem_norm, /* i/o: Norm vector memory from past frame */ #ifdef ENV_STAB_FIX int16_t *mem_env_delta, /* i/o: Envelope stability memory for smoothing*/ const int16_t core_switching_flag /* i : Core switching flag */ #else int16_t *mem_env_delta /* i/o: Envelope stability memory for smoothing*/ #endif ) { Word16 env_delta; Loading @@ -82,6 +87,22 @@ float env_stability( Flag Overflow; #endif /* BASOP_NOGLOB */ #ifdef ENV_STAB_FIX if ( core_switching_flag ) { for ( i = 0; i < nb_sfm; i++ ) { mem_norm[i] = ynrm[i]; } #ifdef BASOP_NOGLOB Overflow = 0; env_delta = shl_o( *mem_env_delta, 1, &Overflow ); #else env_delta = shl_o( *mem_env_delta, 1 ); #endif } else { /* Calculate envelope stability parameter */ L_env_delta = L_deposit_l( 0 ); for ( i = 0; i < nb_sfm; i++ ) Loading Loading @@ -128,7 +149,57 @@ float env_stability( #else /* BASOP_NOGLOB */ env_delta = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /* Q13 */ #endif /* BASOP_NOGLOB */ } #else /* Calculate envelope stability parameter */ L_env_delta = L_deposit_l( 0 ); for ( i = 0; i < nb_sfm; i++ ) { tmp = sub( mem_norm[i], ynrm[i] ); L_env_delta = L_mac0( L_env_delta, tmp, tmp ); mem_norm[i] = ynrm[i]; } #ifdef DEBUGGING assert( nb_sfm == 27 || nb_sfm == 26 ); #endif inv_nb_sfm = 19418; /* Q19 */ if ( nb_sfm == 26 ) { inv_nb_sfm = 20165; /* Q19 */ } exp = norm_l( L_env_delta ); L_env_delta = Mult_32_16( L_shl( L_env_delta, exp ), inv_nb_sfm ); /* 0+exp+19-15 */ L_tmp = Sqrt_l( L_env_delta, &exp2 ); /* exp+4+31+exp2 */ exp = add( 35, add( exp, exp2 ) ); if ( sub( s_and( exp, 1 ), 1 ) == 0 ) { L_tmp = Mult_32_16( L_tmp, 23170 ); /* 1/sqrt(2) in Q15 */ } exp = shr( exp, 1 ); #ifndef BASOP_NOGLOB env_delta = round_fx( L_shl( L_tmp, sub( 26, exp ) ) ); /* Q10 */ L_tmp = L_mult0( 26214, env_delta ); /* 26214 is 0.1 in Q18. Q28 */ L_tmp = L_mac( L_tmp, 29491, *mem_env_delta ); /* 29491 is 0.9 in Q15. Q28 */ *mem_env_delta = round_fx( L_tmp ); /* Q12 */ #else /* BASOP_NOGLOB */ env_delta = round_fx_o( L_shl_o( L_tmp, sub( 26, exp ), &Overflow ), &Overflow ); /* Q10 */ L_tmp = L_mult0( 26214, env_delta ); /* 26214 is 0.1 in Q18. Q28 */ L_tmp = L_mac_o( L_tmp, 29491, *mem_env_delta, &Overflow ); /* 29491 is 0.9 in Q15. Q28 */ *mem_env_delta = round_fx_o( L_tmp, &Overflow ); /* Q12 */ #endif /* BASOP_NOGLOB */ Overflow = 0; #ifndef BASOP_NOGLOB env_delta = round_fx( L_shl( L_tmp, 1 ) ); /* Q13 */ #else /* BASOP_NOGLOB */ env_delta = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /* Q13 */ #endif /* BASOP_NOGLOB */ #endif if ( Overflow != 0 ) /* Saturated due to the above up-shifting operation. */ { env_stab = stab_trans_fx[L_STAB_TBL - 1]; /* The highest quantized index. */ Loading lib_com/options.h +1 −1 Original line number Diff line number Diff line Loading @@ -163,7 +163,7 @@ #define IMPROVE_CMDLINE_ROBUSTNESS /* Issue 233: Improve robustness of command-line parameters */ #define FIX_ITD_CNG /* Eri: Fix for CNG ITD */ #define ENV_STAB_FIX /* Contribution 23: HQ envelope stability memory fix */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ Loading lib_com/prot.h +15 −4 Original line number Diff line number Diff line Loading @@ -5432,7 +5432,13 @@ void hq_hr_dec( int16_t *ynrm, /* o : norm quantization index vector */ int16_t *is_transient, /* o : transient flag */ int16_t *hqswb_clas, /* o : HQ SWB class */ #ifdef ENV_STAB_FIX float *SWB_fenv, /* o : SWB frequency envelopes */ const int16_t core_switching_flag /* i : Core switching flag */ #else float *SWB_fenv /* o : SWB frequency envelopes */ #endif ); void hdecnrm_context( Loading Loading @@ -5859,7 +5865,12 @@ float env_stability( const int16_t *ynrm, /* i : Norm vector for current frame */ const int16_t nb_sfm, /* i : Number of sub-bands */ int16_t *mem_norm, /* i/o: Norm vector memory from past frame */ #ifdef ENV_STAB_FIX int16_t *mem_env_delta, /* i/o: Envelope stability memory for smoothing*/ const int16_t core_switching_flag /* i : Core switching flag */ #else int16_t *mem_env_delta /* i/o: Envelope stability memory for smoothing*/ #endif ); /*! r: New speech/music state */ Loading lib_dec/core_switching_dec.c +25 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,9 @@ ivas_error core_switching_pre_dec( { int16_t i, oldLenClasBuff, newLenClasBuff; ivas_error error; #ifdef ENV_STAB_FIX float tmp; #endif error = IVAS_ERR_OK; Loading Loading @@ -401,7 +404,11 @@ ivas_error core_switching_pre_dec( } } #ifdef ENV_STAB_FIX if ( st->core == HQ_CORE && ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE || ( ( st->element_mode != EVS_MONO ) && ( st->last_core != HQ_CORE ) ) ) ) #else if ( st->core == HQ_CORE && ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) ) #endif { set_f( st->hHQ_core->prev_env, 0, SFM_N_WB ); set_f( st->hHQ_core->prev_normq, 0, SFM_N_WB ); Loading @@ -418,10 +425,28 @@ ivas_error core_switching_pre_dec( set_f( st->hHQ_core->prev_coeff_out, 0, L_HQ_WB_BWE ); } #ifdef ENV_STAB_FIX if ( st->element_mode != EVS_MONO ) { /* Estimate mem_env_delta to reinit env_stab */ tmp = max( 0, ENV_STAB_EST1 + ( ENV_STAB_EST2 * st->stab_fac_smooth_lt ) + ( ENV_STAB_EST3 * st->log_energy_diff_lt ) ); st->hHQ_core->mem_env_delta = (int16_t) min( MAX16B, (int32_t) ( tmp * ( 1 << 12 ) ) ); /* Convert to Q12 and handle saturation */ if ( st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE ) { set_f( st->hHQ_core->old_out, 0, output_frame ); set_f( st->hHQ_core->old_outLB, 0, L_FRAME16k ); } st->hHQ_core->no_att_hangover = 0; st->hHQ_core->energy_lt = 300.0f; } #else set_f( st->hHQ_core->old_out, 0, output_frame ); set_f( st->hHQ_core->old_outLB, 0, L_FRAME16k ); #endif } /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */ if ( st->hHQ_core != NULL ) { Loading Loading
lib_com/cnst.h +9 −0 Original line number Diff line number Diff line Loading @@ -1682,6 +1682,15 @@ enum #define HALF_D_STAB_TBL_FX ( (Word16) 422 ) /* Q13 0.1013138/2.0 */ #define NUM_ENV_STAB_PLC_STATES 2 /* Number of states of markov model */ #ifdef ENV_STAB_FIX #define ENV_STAB_EST1 2.93f /* env_stab estimation coefficient 1 */ #define ENV_STAB_EST2 (-2.20f) /* env_stab estimation coefficient 2 */ #define ENV_STAB_EST3 0.741f /* env_stab estimation coefficient 3 */ #define STAB_FAC_EST1 1.093f /* stab_fac HQ estimation coefficient 1 */ #define STAB_FAC_EST2 (-5.84e-05f) /* stab_fac HQ estimation coefficient 2, including Q12 scaling */ #define STAB_FAC_EST3 0.125f /* stab_fac HQ estimation coefficient 3 */ #endif #define ATT_LIM_HANGOVER 150 /* Number of hangover frames for disabling stability dependent attenuation */ #define DELTA_TH 5.0f /* Delta energy threshold for transient detection for envelope stability */ #define ENERGY_TH 100.0f /* Energy threshold for transient detection */ Loading
lib_com/env_stab.c +79 −8 Original line number Diff line number Diff line Loading @@ -66,7 +66,12 @@ float env_stability( const int16_t *ynrm, /* i : Norm vector for current frame */ const int16_t nb_sfm, /* i : Number of sub-bands */ int16_t *mem_norm, /* i/o: Norm vector memory from past frame */ #ifdef ENV_STAB_FIX int16_t *mem_env_delta, /* i/o: Envelope stability memory for smoothing*/ const int16_t core_switching_flag /* i : Core switching flag */ #else int16_t *mem_env_delta /* i/o: Envelope stability memory for smoothing*/ #endif ) { Word16 env_delta; Loading @@ -82,6 +87,22 @@ float env_stability( Flag Overflow; #endif /* BASOP_NOGLOB */ #ifdef ENV_STAB_FIX if ( core_switching_flag ) { for ( i = 0; i < nb_sfm; i++ ) { mem_norm[i] = ynrm[i]; } #ifdef BASOP_NOGLOB Overflow = 0; env_delta = shl_o( *mem_env_delta, 1, &Overflow ); #else env_delta = shl_o( *mem_env_delta, 1 ); #endif } else { /* Calculate envelope stability parameter */ L_env_delta = L_deposit_l( 0 ); for ( i = 0; i < nb_sfm; i++ ) Loading Loading @@ -128,7 +149,57 @@ float env_stability( #else /* BASOP_NOGLOB */ env_delta = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /* Q13 */ #endif /* BASOP_NOGLOB */ } #else /* Calculate envelope stability parameter */ L_env_delta = L_deposit_l( 0 ); for ( i = 0; i < nb_sfm; i++ ) { tmp = sub( mem_norm[i], ynrm[i] ); L_env_delta = L_mac0( L_env_delta, tmp, tmp ); mem_norm[i] = ynrm[i]; } #ifdef DEBUGGING assert( nb_sfm == 27 || nb_sfm == 26 ); #endif inv_nb_sfm = 19418; /* Q19 */ if ( nb_sfm == 26 ) { inv_nb_sfm = 20165; /* Q19 */ } exp = norm_l( L_env_delta ); L_env_delta = Mult_32_16( L_shl( L_env_delta, exp ), inv_nb_sfm ); /* 0+exp+19-15 */ L_tmp = Sqrt_l( L_env_delta, &exp2 ); /* exp+4+31+exp2 */ exp = add( 35, add( exp, exp2 ) ); if ( sub( s_and( exp, 1 ), 1 ) == 0 ) { L_tmp = Mult_32_16( L_tmp, 23170 ); /* 1/sqrt(2) in Q15 */ } exp = shr( exp, 1 ); #ifndef BASOP_NOGLOB env_delta = round_fx( L_shl( L_tmp, sub( 26, exp ) ) ); /* Q10 */ L_tmp = L_mult0( 26214, env_delta ); /* 26214 is 0.1 in Q18. Q28 */ L_tmp = L_mac( L_tmp, 29491, *mem_env_delta ); /* 29491 is 0.9 in Q15. Q28 */ *mem_env_delta = round_fx( L_tmp ); /* Q12 */ #else /* BASOP_NOGLOB */ env_delta = round_fx_o( L_shl_o( L_tmp, sub( 26, exp ), &Overflow ), &Overflow ); /* Q10 */ L_tmp = L_mult0( 26214, env_delta ); /* 26214 is 0.1 in Q18. Q28 */ L_tmp = L_mac_o( L_tmp, 29491, *mem_env_delta, &Overflow ); /* 29491 is 0.9 in Q15. Q28 */ *mem_env_delta = round_fx_o( L_tmp, &Overflow ); /* Q12 */ #endif /* BASOP_NOGLOB */ Overflow = 0; #ifndef BASOP_NOGLOB env_delta = round_fx( L_shl( L_tmp, 1 ) ); /* Q13 */ #else /* BASOP_NOGLOB */ env_delta = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /* Q13 */ #endif /* BASOP_NOGLOB */ #endif if ( Overflow != 0 ) /* Saturated due to the above up-shifting operation. */ { env_stab = stab_trans_fx[L_STAB_TBL - 1]; /* The highest quantized index. */ Loading
lib_com/options.h +1 −1 Original line number Diff line number Diff line Loading @@ -163,7 +163,7 @@ #define IMPROVE_CMDLINE_ROBUSTNESS /* Issue 233: Improve robustness of command-line parameters */ #define FIX_ITD_CNG /* Eri: Fix for CNG ITD */ #define ENV_STAB_FIX /* Contribution 23: HQ envelope stability memory fix */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ Loading
lib_com/prot.h +15 −4 Original line number Diff line number Diff line Loading @@ -5432,7 +5432,13 @@ void hq_hr_dec( int16_t *ynrm, /* o : norm quantization index vector */ int16_t *is_transient, /* o : transient flag */ int16_t *hqswb_clas, /* o : HQ SWB class */ #ifdef ENV_STAB_FIX float *SWB_fenv, /* o : SWB frequency envelopes */ const int16_t core_switching_flag /* i : Core switching flag */ #else float *SWB_fenv /* o : SWB frequency envelopes */ #endif ); void hdecnrm_context( Loading Loading @@ -5859,7 +5865,12 @@ float env_stability( const int16_t *ynrm, /* i : Norm vector for current frame */ const int16_t nb_sfm, /* i : Number of sub-bands */ int16_t *mem_norm, /* i/o: Norm vector memory from past frame */ #ifdef ENV_STAB_FIX int16_t *mem_env_delta, /* i/o: Envelope stability memory for smoothing*/ const int16_t core_switching_flag /* i : Core switching flag */ #else int16_t *mem_env_delta /* i/o: Envelope stability memory for smoothing*/ #endif ); /*! r: New speech/music state */ Loading
lib_dec/core_switching_dec.c +25 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,9 @@ ivas_error core_switching_pre_dec( { int16_t i, oldLenClasBuff, newLenClasBuff; ivas_error error; #ifdef ENV_STAB_FIX float tmp; #endif error = IVAS_ERR_OK; Loading Loading @@ -401,7 +404,11 @@ ivas_error core_switching_pre_dec( } } #ifdef ENV_STAB_FIX if ( st->core == HQ_CORE && ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE || ( ( st->element_mode != EVS_MONO ) && ( st->last_core != HQ_CORE ) ) ) ) #else if ( st->core == HQ_CORE && ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) ) #endif { set_f( st->hHQ_core->prev_env, 0, SFM_N_WB ); set_f( st->hHQ_core->prev_normq, 0, SFM_N_WB ); Loading @@ -418,10 +425,28 @@ ivas_error core_switching_pre_dec( set_f( st->hHQ_core->prev_coeff_out, 0, L_HQ_WB_BWE ); } #ifdef ENV_STAB_FIX if ( st->element_mode != EVS_MONO ) { /* Estimate mem_env_delta to reinit env_stab */ tmp = max( 0, ENV_STAB_EST1 + ( ENV_STAB_EST2 * st->stab_fac_smooth_lt ) + ( ENV_STAB_EST3 * st->log_energy_diff_lt ) ); st->hHQ_core->mem_env_delta = (int16_t) min( MAX16B, (int32_t) ( tmp * ( 1 << 12 ) ) ); /* Convert to Q12 and handle saturation */ if ( st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE ) { set_f( st->hHQ_core->old_out, 0, output_frame ); set_f( st->hHQ_core->old_outLB, 0, L_FRAME16k ); } st->hHQ_core->no_att_hangover = 0; st->hHQ_core->energy_lt = 300.0f; } #else set_f( st->hHQ_core->old_out, 0, output_frame ); set_f( st->hHQ_core->old_outLB, 0, L_FRAME16k ); #endif } /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */ if ( st->hHQ_core != NULL ) { Loading