diff --git a/lib_com/options.h b/lib_com/options.h index 7dd1b43a0e20557dad6ebdd57944492f72316bf2..f2d58b90061044e84f65334570bb2d1a3839d7fb 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -179,6 +179,7 @@ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ #define NONBE_SVD_OPTIMIZATION +#define NONBE_1328_FIX_NON_LINEARITY /* VA: Fix possible issue when computing bwe_exc_extended and previous frame were almost 0 */ /* ##################### End NON-BE switches ########################### */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_com/prot.h b/lib_com/prot.h index c1dd64527d4f837abebd075615dac52be7be50b6..efb77f0a3f8067eae9f448e8a7c78e2ec5782e92 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2653,6 +2653,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 8e3a5cff68807a4b5cf4fd71f44a74d75629f54d..d488d4479efb0225490c17226df1ef6c3e79afa9 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -1414,7 +1414,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 535a52430ebcf3d24c780fe89e8dd6ca8f2ea651..33bef3e67a26bc212898ab133ba1c5a5ad420f4a 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -695,7 +695,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 );