From 0d0159347cca1302c486a66b76de4d05816566a4 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 30 Sep 2025 15:41:44 +0200 Subject: [PATCH] Added FIX_1179_USAN_PHASEECU for porting MR1921 from float --- lib_com/options.h | 1 + lib_dec/FEC_HQ_phase_ecu.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index b72019e28..7de7a9c45 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -188,6 +188,7 @@ #define FIX_ISSUE_2008_MISSING_CODE_FROM_PORTING /* FhG: Issue 2008: Code deleted while porting float-main MR !1504 (BASOP issue 1565)*/ #define ADJUST_MCT_CHANNELS_MAX /* FhG: set correct max mct channels constant*/ #define FIX_1053_REVERB_RECONFIGURATION +#define FIX_1179_USAN_PHASEECU /* Eri: issue 1179: better handling of 16 bit wrap around for very long(>200ms) FER-bursts */ /* #################### End BASOP porting switches ############################ */ diff --git a/lib_dec/FEC_HQ_phase_ecu.c b/lib_dec/FEC_HQ_phase_ecu.c index 4ad3f28fb..363447e2f 100644 --- a/lib_dec/FEC_HQ_phase_ecu.c +++ b/lib_dec/FEC_HQ_phase_ecu.c @@ -2089,6 +2089,12 @@ static void hq_phase_ecu( if ( !prev_bfi || ( prev_bfi && *last_fec && ( *time_offs == output_frame ) ) ) { +#ifdef FIX_1179_USAN_PHASEECU + if ( !( prev_bfi && *last_fec && ( element_mode == EVS_MONO ) ) ) + { + *time_offs = 0; /* IVAS reset of offset time counter, timeoffset variable later also used to calculate burst length */ + } +#else if ( prev_bfi && *last_fec && element_mode == EVS_MONO ) { *time_offs += 0; @@ -2097,13 +2103,30 @@ static void hq_phase_ecu( { *time_offs = 0; } +#endif trans_ana( prevsynth + 2 * output_frame - Lprot - *time_offs + ph_ecu_lookahead, mag_chg, &ph_dith, mag_chg_1st, output_frame, *time_offs, env_stab, *last_fec, alpha, beta, beta_mute, Xavg ); spec_ana( prevsynth + 2 * output_frame - Lprot - *time_offs + ph_ecu_lookahead, plocs, plocsi, num_p, X_sav, output_frame, bwidth, element_mode, &noise_fac, pcorr ); if ( prev_bfi && *last_fec ) { + +#ifdef FIX_1179_USAN_PHASEECU + if ( element_mode != EVS_MONO ) + { + *time_offs = (int16_t) ( *time_offs + output_frame ); /* USAN avoid risk of internal int32_t in "+=" */ + if ( *time_offs <= 0 ) + { /* detected wrap around of st->time_offs */ + *time_offs = (int16_t) INT16_MAX; /* keep a very high value so that the long term muting stays on */ + } + } + else + { + *time_offs = (int16_t) ( *time_offs + output_frame ); /* EVS_MONO BE compatible, but EVS CR needed as wrap will cause burst length muting envelope instability issues */ + } +#else *time_offs += output_frame; +#endif } } else @@ -2112,7 +2135,11 @@ static void hq_phase_ecu( if ( *time_offs <= 0 ) { /* detect wrap around of st->time_offs */ +#ifdef FIX_1179_USAN_PHASEECU + *time_offs = (int16_t) INT16_MAX; /* high value --> continued muting will ensure that the now saturated seed is not creating tones */ +#else *time_offs = MAX16B; /* continued muting will ensure that the now fixed seeds are not creating tones */ +#endif } trans_ana( prevsynth + 2 * output_frame - Lprot, mag_chg, &ph_dith, mag_chg_1st, output_frame, *time_offs, env_stab, 0, alpha, beta, beta_mute, Xavg ); /* 1.0 stable-music, 0.0 speech-like */ @@ -2124,7 +2151,11 @@ static void hq_phase_ecu( seed = *time_offs; if ( *num_p > 0 ) { +#ifdef FIX_1179_USAN_PHASEECU + seed = (int16_t) ( seed + plocs[*num_p - 1] ); /* explicit cast and "+=" not used, as it "+=" may create a cast from 32 bit to 16 bit, triggering USAN */ +#else seed += plocs[*num_p - 1]; +#endif } subst_spec( plocs, plocsi, num_p, *time_offs, X, mag_chg, ph_dith, old_is_transient, output_frame, &seed, alpha, beta, *beta_mute, Xavg, element_mode, ph_ecu_lookahead, noise_fac ); -- GitLab