diff --git a/lib_com/options.h b/lib_com/options.h index 3b6c3bade2392d413db375fb7141763f12ff4e23..8556b7947da99ce68a4bb78a9a9e2533cc1ec45e 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -222,6 +222,8 @@ #define NONBE_1118_EVS_LR_HQ_BITERROR /* VA: issue 1118: fix EVS decoder crash in LR-HQ in case of bit errors */ #define FIX_1139_REV_COLORATION_SHORT_T60 /* Nokia,FhG: Fix issue 1139, prevent sound coloration artefacts at very low reverberation times */ +#define NONBE_1328_FIX_NON_LINEARITY /* VA: Fix possible issue when computing bwe_exc_extended and previous frame were almost 0 */ + /* #################### End BASOP porting switches ############################ */ /* clang-format on */ diff --git a/lib_com/prot.h b/lib_com/prot.h index 5afa0a595afc24f35c4b32ae292b9c56093e87f2..5ad14bf8923c927321a13bc78bb56b6fbbcb5e2b 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2638,6 +2638,10 @@ void non_linearity( const int16_t coder_type, /* i : Coder Type */ const float *voice_factors, /* i : Voice Factors */ const int16_t L_frame /* i : ACELP frame length */ +#ifdef NONBE_1328_FIX_NON_LINEARITY + , + const int16_t element_mode /* i : element_mode to differentiate EVS and IVAS */ +#endif ); void interp_code_5over2( diff --git a/lib_com/swb_tbe_com.c b/lib_com/swb_tbe_com.c index a8d88c2b0fb5f5bb0386c946d3d18e2a7f3b5f3c..ed06e57636c1bb4fa0f19df5422c1125585b5edb 100644 --- a/lib_com/swb_tbe_com.c +++ b/lib_com/swb_tbe_com.c @@ -1353,6 +1353,10 @@ void non_linearity( const int16_t coder_type, /* i : Coder Type */ const float *voice_factors, /* i : Voice Factors */ const int16_t L_frame /* i : ACELP frame length */ +#ifdef NONBE_1328_FIX_NON_LINEARITY + , + const int16_t element_mode /* i : element_mode to differentiate EVS and IVAS */ +#endif ) { int16_t i, j; @@ -1365,7 +1369,9 @@ void non_linearity( int16_t en_abs = 0; float v_fac = 0, ths; int16_t nframes; - +#ifdef NONBE_1328_FIX_NON_LINEARITY + float sc_factor; +#endif if ( L_frame == L_FRAME16k ) { nframes = 5; @@ -1410,8 +1416,17 @@ void non_linearity( scale = 0.67f; } - +#ifdef NONBE_1328_FIX_NON_LINEARITY + sc_factor = 1024.0f; + if ( element_mode > EVS_MONO ) + { + sc_factor = (float) ( 1 << max( 13 - norm_s( j + 1 ), 0 ) ); /* Adapt the scaling factor allowed depending of max position */ + sc_factor = max( sc_factor, 2.0f ); + } + if ( *prev_scale <= 0.0 || *prev_scale > sc_factor * scale ) +#else if ( *prev_scale <= 0.0 || *prev_scale > 1024.0f * scale ) +#endif { scale_step = 1.0; *prev_scale = scale; @@ -1468,8 +1483,17 @@ void non_linearity( scale = 0.67f; } - +#ifdef NONBE_1328_FIX_NON_LINEARITY + sc_factor = 1024.0f; + if ( element_mode > EVS_MONO ) + { + sc_factor = (float) ( 1 << max( 12 - norm_s( j - length / 2 + 1 ), 0 ) ); /* allowed intra frame jump is smaller */ + sc_factor = max( sc_factor, 2.0f ); + } + if ( *prev_scale <= 0.0 || *prev_scale > sc_factor * scale ) +#else if ( *prev_scale <= 0.0 || *prev_scale > 1024.0f * scale ) +#endif { scale_step = 1.0; *prev_scale = scale; diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index 9d29df201ac458ab7d572dec23168bebd40c4ade..159702cfc63d1bdcc59c42d73ce915151cb35545 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -1442,7 +1442,12 @@ ivas_error acelp_core_dec( if ( !st->ppp_mode_dec && ( st->idchan == 0 || st->element_mode != IVAS_CPE_TD || ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD && st->tdm_LRTD_flag ) ) ) { - non_linearity( bwe_exc, bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale, st->coder_type, voice_factors, st->L_frame ); + non_linearity( bwe_exc, bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale, st->coder_type, voice_factors, st->L_frame +#ifdef NONBE_1328_FIX_NON_LINEARITY + , + st->element_mode +#endif + ); } if ( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 ) diff --git a/lib_dec/dec_acelp_tcx_main.c b/lib_dec/dec_acelp_tcx_main.c index 4689bdb7950e4df3c69452c5a114fc57a5070053..a591157e44e72a87adab547256f7e80b5326acca 100644 --- a/lib_dec/dec_acelp_tcx_main.c +++ b/lib_dec/dec_acelp_tcx_main.c @@ -425,7 +425,12 @@ void dec_acelp_tcx_frame( if ( st->core == ACELP_CORE && st->igf && st->con_tcx == 0 ) { - non_linearity( ptr_bwe_exc, bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale, st->coder_type, voice_factors, st->L_frame ); + non_linearity( ptr_bwe_exc, bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale, st->coder_type, voice_factors, st->L_frame +#ifdef NONBE_1328_FIX_NON_LINEARITY + , + st->element_mode +#endif + ); /* update the old BWE exe memory */ mvr2r( &old_bwe_exc[L_FRAME32k], st->hBWE_TD->old_bwe_exc, PIT16k_MAX * 2 ); diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 2958cf9205f0800bdfb851b1ca56206c7563d6e6..2d57baa825887887629e8c6e7ebd7ee04690cdd8 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -713,7 +713,12 @@ ivas_error acelp_core_enc( if ( !st->Opt_SC_VBR && ( st->idchan == 0 || st->element_mode != IVAS_CPE_TD || ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD && st->tdm_LRTD_flag ) ) ) { /* Apply a non linearity to the SHB excitation */ - non_linearity( bwe_exc, bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale, st->coder_type, voice_factors, st->L_frame ); + non_linearity( bwe_exc, bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale, st->coder_type, voice_factors, st->L_frame +#ifdef NONBE_1328_FIX_NON_LINEARITY + , + st->element_mode +#endif + ); } if ( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA ) diff --git a/lib_enc/enc_acelp_tcx_main.c b/lib_enc/enc_acelp_tcx_main.c index 6ede9b9bf18b75a00fcb10e70c379746b0da5e6a..8851d9be5e0c358e9470583a923ad7836d14c09b 100644 --- a/lib_enc/enc_acelp_tcx_main.c +++ b/lib_enc/enc_acelp_tcx_main.c @@ -99,7 +99,12 @@ void enc_acelp_tcx_main( /* Apply non linearity to the SHB excitation */ if ( st->core == ACELP_CORE && st->igf ) { - non_linearity( ptr_bwe_exc, bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale, st->coder_type, voice_factors, st->L_frame ); + non_linearity( ptr_bwe_exc, bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale, st->coder_type, voice_factors, st->L_frame +#ifdef NONBE_1328_FIX_NON_LINEARITY + , + st->element_mode +#endif + ); /* update the old_BWE_exc memory */ mvr2r( &old_bwe_exc[L_FRAME32k], st->hBWE_TD->old_bwe_exc, PIT16k_MAX * 2 );