From 6a4b4df57df4f48ff9b54650a5d94889a6a2ec6b Mon Sep 17 00:00:00 2001 From: Jonas Sv Date: Wed, 18 Dec 2024 15:21:34 +0100 Subject: [PATCH 1/6] addressed USAN_warnings in phaseEcu time_offs and seed variables --- lib_com/options.h | 2 +- lib_dec/FEC_HQ_phase_ecu.c | 58 ++++++++++++++++++++++++++++++-------- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index b26b2d81c5..635c2ba437 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -162,7 +162,7 @@ #define TMP_FIX_1119_SPLIT_RENDERING_VOIP /* FhG: Add error check for unsupported config: split rendering with VoIP mode */ #define FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE /* VA: issue 1228: Exit the processing when a HRTF binary file with wrong sampling rate is provided */ #define FIX_1225_DISCLAIMER /* VA: issue 1225: Add disclaimer for external renderer + Add info about IVAS reference version */ - +#define FIX_1179_USAN_PHASEECU /* Eri: issue 1179: better handling of 16 bit wrap around for very long(>200ms) FER-bursts */ /* #################### End BE switches ################################## */ /* #################### Start NON-BE switches ############################ */ diff --git a/lib_dec/FEC_HQ_phase_ecu.c b/lib_dec/FEC_HQ_phase_ecu.c index 425ff21fe9..862d2e2c89 100644 --- a/lib_dec/FEC_HQ_phase_ecu.c +++ b/lib_dec/FEC_HQ_phase_ecu.c @@ -288,9 +288,9 @@ static void trans_ana( *ph_dith = 0.0f; /* softly shift attenuation just a bit later for estimated "stable" music_content */ - burst_phdith_thresh = BURST_PHDITH_THRESH + (int16_t) ( est_mus_content * 1.0f + 0.5f ); - burst_att_thresh = BURST_ATT_THRESH + (int16_t) ( est_mus_content * 1.0f + 0.5f ); - att_per_frame = (float) ( ATT_PER_FRAME - (int16_t) ( est_mus_content * 1.0f + 0.5f ) ); /* only slighty less att for music */ + burst_phdith_thresh = BURST_PHDITH_THRESH + ( int16_t )( est_mus_content * 1.0f + 0.5f ); + burst_att_thresh = BURST_ATT_THRESH + ( int16_t )( est_mus_content * 1.0f + 0.5f ); + att_per_frame = (float) ( ATT_PER_FRAME - ( int16_t )( est_mus_content * 1.0f + 0.5f ) ); /* only slighty less att for music */ att_per_frame *= 0.1f; if ( burst_len > burst_phdith_thresh ) @@ -974,7 +974,7 @@ static void subst_spec( float beta_local; sincos = sincos_t_ext + 128; - Lprot = (int16_t) ( L_PROT32k * output_frame / 640 ); + Lprot = ( int16_t )( L_PROT32k * output_frame / 640 ); Lprot_1 = 1.0f / Lprot; Lecu = output_frame * 2; @@ -1092,7 +1092,7 @@ static void subst_spec( Xph = corr_phase[m]; /* extract fractional phase integer index in the range [0...1023] */ - Xph_short = (int16_t) ( 0x000003ff & (int32_t) ( ( Xph * 512 ) / EVS_PI ) ); + Xph_short = ( int16_t )( 0x000003ff & ( int32_t )( ( Xph * 512 ) / EVS_PI ) ); if ( Xph_short >= 512 ) @@ -1138,7 +1138,7 @@ static void subst_spec( mag_chg_local *= 0.5f + ( 1.0f - ( 1.0f / PHASE_DITH ) * ph_dith ) * 0.5f; } - Xph_short = (int16_t) ( ( (int32_t) ( ( Xph * 512 ) / EVS_PI ) ) & 0x000003ff ); + Xph_short = ( int16_t )( ( ( int32_t )( ( Xph * 512 ) / EVS_PI ) ) & 0x000003ff ); if ( Xph_short >= 512 ) { @@ -1355,12 +1355,12 @@ static void rec_wtda( else { /* Smoothen onset of ECU frame */ - xf_len = (int16_t) ( (float) output_frame * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) - ( output_frame - Lprot / 2 ); + xf_len = ( int16_t )( (float) output_frame * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) - ( output_frame - Lprot / 2 ); p_ecu = xsubst_ + 2 * output_frame - Lprot + timesh; tbl_delta = 64.f / xf_len; /* 64 samples = 1/4 cycle in sincos_t */ for ( i = 0; i < xf_len; i++, p_ecu++ ) { - g = sincos_t[( (int16_t) ( i * tbl_delta ) )]; + g = sincos_t[( ( int16_t )( i * tbl_delta ) )]; g *= g; *p_ecu = g * ( *p_ecu ); } @@ -1532,7 +1532,7 @@ static void fec_ecu_pitch( /* Resampling to work at 8Khz */ fir_dwn( prevsynth, Asr_LP, prevsynth_LP, 2 * L, filt_size, *decimatefator ); /* resampling without delay */ - Lon20 = (int16_t) ( ( L / 20 ) / *decimatefator ); + Lon20 = ( int16_t )( ( L / 20 ) / *decimatefator ); /* Correlation analysis */ *min_corr = 0; @@ -1953,7 +1953,7 @@ static void fec_noise_filling( kk = 0; } - Rnd_N_noise = (int16_t) ( (float) N_noise * tmp ); + Rnd_N_noise = ( int16_t )( (float) N_noise * tmp ); sinq( (const float) EVS_PI / ( 2.0f * (float) Rnd_N_noise ), (const float) EVS_PI / ( 4.0f * (float) Rnd_N_noise ), (const int16_t) Rnd_N_noise, SS ); @@ -2031,7 +2031,7 @@ static void fec_alg( fec_noise_filling( prevsynth, synthesis, output_frame, N * decimatefactor, HqVoicing, gapsynth, ni_seed_forfec, element_mode, old_out ); - n = (int16_t) ( (float) output_frame * N_ZERO_MDCT_NS / FRAME_SIZE_NS ); + n = ( int16_t )( (float) output_frame * N_ZERO_MDCT_NS / FRAME_SIZE_NS ); wtda( synthesis + ( output_frame - n ), ecu_rec, NULL, ALDO_WINDOW, ALDO_WINDOW, output_frame ); return; @@ -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,22 +2103,46 @@ 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)output_frame; + 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 += 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 { +#ifdef FIX_1179_USAN_PHASEECU + *time_offs += (int16_t) output_frame; /* cast added for USAN */ +#else *time_offs += output_frame; +#endif if ( *time_offs <= 0 ) { /* detect wrap around of st->time_offs */ - *time_offs = MAX16B; /* continued muting will ensure that the now fixed seeds are not creating tones */ +#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; +#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 +2154,11 @@ static void hq_phase_ecu( seed = *time_offs; if ( *num_p > 0 ) { +#ifdef FIX_1179_USAN_PHASEECU + seed += ( int16_t )( plocs[*num_p - 1] ); /* explicit cast, i.e. the seed value may wrap */ +#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 From 38c58f5ce69b63b1dcf60f085b38ebd5312cc2ab Mon Sep 17 00:00:00 2001 From: Jonas Sv Date: Wed, 18 Dec 2024 15:26:26 +0100 Subject: [PATCH 2/6] formatting --- lib_dec/FEC_HQ_phase_ecu.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib_dec/FEC_HQ_phase_ecu.c b/lib_dec/FEC_HQ_phase_ecu.c index 862d2e2c89..688b7bb85c 100644 --- a/lib_dec/FEC_HQ_phase_ecu.c +++ b/lib_dec/FEC_HQ_phase_ecu.c @@ -288,9 +288,9 @@ static void trans_ana( *ph_dith = 0.0f; /* softly shift attenuation just a bit later for estimated "stable" music_content */ - burst_phdith_thresh = BURST_PHDITH_THRESH + ( int16_t )( est_mus_content * 1.0f + 0.5f ); - burst_att_thresh = BURST_ATT_THRESH + ( int16_t )( est_mus_content * 1.0f + 0.5f ); - att_per_frame = (float) ( ATT_PER_FRAME - ( int16_t )( est_mus_content * 1.0f + 0.5f ) ); /* only slighty less att for music */ + burst_phdith_thresh = BURST_PHDITH_THRESH + (int16_t) ( est_mus_content * 1.0f + 0.5f ); + burst_att_thresh = BURST_ATT_THRESH + (int16_t) ( est_mus_content * 1.0f + 0.5f ); + att_per_frame = (float) ( ATT_PER_FRAME - (int16_t) ( est_mus_content * 1.0f + 0.5f ) ); /* only slighty less att for music */ att_per_frame *= 0.1f; if ( burst_len > burst_phdith_thresh ) @@ -974,7 +974,7 @@ static void subst_spec( float beta_local; sincos = sincos_t_ext + 128; - Lprot = ( int16_t )( L_PROT32k * output_frame / 640 ); + Lprot = (int16_t) ( L_PROT32k * output_frame / 640 ); Lprot_1 = 1.0f / Lprot; Lecu = output_frame * 2; @@ -1092,7 +1092,7 @@ static void subst_spec( Xph = corr_phase[m]; /* extract fractional phase integer index in the range [0...1023] */ - Xph_short = ( int16_t )( 0x000003ff & ( int32_t )( ( Xph * 512 ) / EVS_PI ) ); + Xph_short = (int16_t) ( 0x000003ff & (int32_t) ( ( Xph * 512 ) / EVS_PI ) ); if ( Xph_short >= 512 ) @@ -1138,7 +1138,7 @@ static void subst_spec( mag_chg_local *= 0.5f + ( 1.0f - ( 1.0f / PHASE_DITH ) * ph_dith ) * 0.5f; } - Xph_short = ( int16_t )( ( ( int32_t )( ( Xph * 512 ) / EVS_PI ) ) & 0x000003ff ); + Xph_short = (int16_t) ( ( (int32_t) ( ( Xph * 512 ) / EVS_PI ) ) & 0x000003ff ); if ( Xph_short >= 512 ) { @@ -1355,12 +1355,12 @@ static void rec_wtda( else { /* Smoothen onset of ECU frame */ - xf_len = ( int16_t )( (float) output_frame * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) - ( output_frame - Lprot / 2 ); + xf_len = (int16_t) ( (float) output_frame * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) - ( output_frame - Lprot / 2 ); p_ecu = xsubst_ + 2 * output_frame - Lprot + timesh; tbl_delta = 64.f / xf_len; /* 64 samples = 1/4 cycle in sincos_t */ for ( i = 0; i < xf_len; i++, p_ecu++ ) { - g = sincos_t[( ( int16_t )( i * tbl_delta ) )]; + g = sincos_t[( (int16_t) ( i * tbl_delta ) )]; g *= g; *p_ecu = g * ( *p_ecu ); } @@ -1532,7 +1532,7 @@ static void fec_ecu_pitch( /* Resampling to work at 8Khz */ fir_dwn( prevsynth, Asr_LP, prevsynth_LP, 2 * L, filt_size, *decimatefator ); /* resampling without delay */ - Lon20 = ( int16_t )( ( L / 20 ) / *decimatefator ); + Lon20 = (int16_t) ( ( L / 20 ) / *decimatefator ); /* Correlation analysis */ *min_corr = 0; @@ -1953,7 +1953,7 @@ static void fec_noise_filling( kk = 0; } - Rnd_N_noise = ( int16_t )( (float) N_noise * tmp ); + Rnd_N_noise = (int16_t) ( (float) N_noise * tmp ); sinq( (const float) EVS_PI / ( 2.0f * (float) Rnd_N_noise ), (const float) EVS_PI / ( 4.0f * (float) Rnd_N_noise ), (const int16_t) Rnd_N_noise, SS ); @@ -2031,7 +2031,7 @@ static void fec_alg( fec_noise_filling( prevsynth, synthesis, output_frame, N * decimatefactor, HqVoicing, gapsynth, ni_seed_forfec, element_mode, old_out ); - n = ( int16_t )( (float) output_frame * N_ZERO_MDCT_NS / FRAME_SIZE_NS ); + n = (int16_t) ( (float) output_frame * N_ZERO_MDCT_NS / FRAME_SIZE_NS ); wtda( synthesis + ( output_frame - n ), ecu_rec, NULL, ALDO_WINDOW, ALDO_WINDOW, output_frame ); return; @@ -2112,11 +2112,11 @@ static void hq_phase_ecu( { #ifdef FIX_1179_USAN_PHASEECU if ( element_mode != EVS_MONO ) - { - *time_offs += (int16_t)output_frame; + { + *time_offs += (int16_t) output_frame; 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 */ + { /* 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 @@ -2155,7 +2155,7 @@ static void hq_phase_ecu( if ( *num_p > 0 ) { #ifdef FIX_1179_USAN_PHASEECU - seed += ( int16_t )( plocs[*num_p - 1] ); /* explicit cast, i.e. the seed value may wrap */ + seed += (int16_t) ( plocs[*num_p - 1] ); /* explicit cast, i.e. the seed value may wrap */ #else seed += plocs[*num_p - 1]; #endif -- GitLab From cb27453d0c95e95c04a8c848e4ba988a6e316044 Mon Sep 17 00:00:00 2001 From: Jonas Sv Date: Wed, 18 Dec 2024 15:51:46 +0100 Subject: [PATCH 3/6] added explicit cast in PhaseEcu in framesize addition to time_offs --- lib_dec/FEC_HQ_phase_ecu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/FEC_HQ_phase_ecu.c b/lib_dec/FEC_HQ_phase_ecu.c index 688b7bb85c..3a4483ae9a 100644 --- a/lib_dec/FEC_HQ_phase_ecu.c +++ b/lib_dec/FEC_HQ_phase_ecu.c @@ -2121,7 +2121,7 @@ static void hq_phase_ecu( } else { - *time_offs += output_frame; /* EVS_MONO BE compatible, but EVS CR needed as wrap will cause burst length muting envelope instability issues */ + *time_offs += (int16_t)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; @@ -2131,7 +2131,7 @@ static void hq_phase_ecu( else { #ifdef FIX_1179_USAN_PHASEECU - *time_offs += (int16_t) output_frame; /* cast added for USAN */ + *time_offs += (int16_t)output_frame; /* cast added for USAN */ #else *time_offs += output_frame; #endif -- GitLab From 11260329c4bf7c11c8a67063e2e3d3a685e7c5da Mon Sep 17 00:00:00 2001 From: Jonas Sv Date: Thu, 19 Dec 2024 11:42:43 +0100 Subject: [PATCH 4/6] removed += to avoid int to int16_t truncatio warning when we do deliberate 16bit border wrapping --- lib_dec/FEC_HQ_phase_ecu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_dec/FEC_HQ_phase_ecu.c b/lib_dec/FEC_HQ_phase_ecu.c index 3a4483ae9a..88622222ae 100644 --- a/lib_dec/FEC_HQ_phase_ecu.c +++ b/lib_dec/FEC_HQ_phase_ecu.c @@ -2121,7 +2121,7 @@ static void hq_phase_ecu( } else { - *time_offs += (int16_t)output_frame; /* EVS_MONO BE compatible, but EVS CR needed as wrap will cause burst length muting envelope instability issues */ + *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; @@ -2131,7 +2131,7 @@ static void hq_phase_ecu( else { #ifdef FIX_1179_USAN_PHASEECU - *time_offs += (int16_t)output_frame; /* cast added for USAN */ + *time_offs = (int16_t)(*time_offs + output_frame) ; /* cast added for USAN, "+=" avoided as it may creat a truncation from int to int16_t */ #else *time_offs += output_frame; #endif @@ -2154,8 +2154,8 @@ static void hq_phase_ecu( seed = *time_offs; if ( *num_p > 0 ) { -#ifdef FIX_1179_USAN_PHASEECU - seed += (int16_t) ( plocs[*num_p - 1] ); /* explicit cast, i.e. the seed value may wrap */ +#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 -- GitLab From 322e6f05ee44373d7ab484c8fdfd624925f0ada4 Mon Sep 17 00:00:00 2001 From: Jonas Sv Date: Thu, 19 Dec 2024 13:07:55 +0100 Subject: [PATCH 5/6] formatting for ci pass --- lib_dec/FEC_HQ_phase_ecu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_dec/FEC_HQ_phase_ecu.c b/lib_dec/FEC_HQ_phase_ecu.c index 88622222ae..3a645a42bd 100644 --- a/lib_dec/FEC_HQ_phase_ecu.c +++ b/lib_dec/FEC_HQ_phase_ecu.c @@ -2121,7 +2121,7 @@ static void hq_phase_ecu( } 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 */ + *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; @@ -2131,7 +2131,7 @@ static void hq_phase_ecu( else { #ifdef FIX_1179_USAN_PHASEECU - *time_offs = (int16_t)(*time_offs + output_frame) ; /* cast added for USAN, "+=" avoided as it may creat a truncation from int to int16_t */ + *time_offs = (int16_t) ( *time_offs + output_frame ); /* cast added for USAN, "+=" avoided as it may creat a truncation from int to int16_t */ #else *time_offs += output_frame; #endif @@ -2154,8 +2154,8 @@ 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 */ +#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 -- GitLab From 0687948af2cd0c9a0f339c9a2b4daf9d79101f32 Mon Sep 17 00:00:00 2001 From: Jonas Svedberg Date: Mon, 23 Dec 2024 10:13:01 +0000 Subject: [PATCH 6/6] Update FEC_HQ_phase_ecu.c, avoid "+=" when accumulating a variable of type int16_t --- lib_dec/FEC_HQ_phase_ecu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/FEC_HQ_phase_ecu.c b/lib_dec/FEC_HQ_phase_ecu.c index 3a645a42bd..a500166677 100644 --- a/lib_dec/FEC_HQ_phase_ecu.c +++ b/lib_dec/FEC_HQ_phase_ecu.c @@ -2113,7 +2113,7 @@ static void hq_phase_ecu( #ifdef FIX_1179_USAN_PHASEECU if ( element_mode != EVS_MONO ) { - *time_offs += (int16_t) output_frame; + *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 */ -- GitLab