From 12fee45845235e1c5423a37e677ff1d6be678fe6 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Mon, 15 Dec 2025 14:52:03 +0100 Subject: [PATCH] fix OOB indxing in E_gain_closed_loop_search --- lib_com/options.h | 1 + lib_enc/enc_gain.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 59daf40a86..61c42648a5 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -162,6 +162,7 @@ /*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #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 FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH /* FhG: fix oob indexing USAN complaint */ /* #################### End BE switches ################################## */ diff --git a/lib_enc/enc_gain.c b/lib_enc/enc_gain.c index b78ed92f2a..28a72a1e6a 100644 --- a/lib_enc/enc_gain.c +++ b/lib_enc/enc_gain.c @@ -147,7 +147,11 @@ int16_t E_GAIN_closed_loop_search( { float corr_v[32 + 2 * L_INTERPOL1 + 1]; float cor_max, max_val, temp; +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + int16_t corr_idx; +#else float *corr; +#endif int16_t i, fraction, frac1, frac2, step; int16_t t0, t_min, t_max; @@ -159,22 +163,45 @@ int16_t E_GAIN_closed_loop_search( t_min = t0_min - L_INTERPOL1; t_max = t0_max + L_INTERPOL1; +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + corr_idx = -t_min; +#else /* allocate memory to normalized correlation vector */ corr = &corr_v[-t_min]; /* corr[t_min..t_max] */ +#endif /* Compute normalized correlation between target and filtered excitation */ +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + norm_corr( exc, xn, h, t_min, t_max, &corr_v[0] + corr_idx, L_subfr ); +#else norm_corr( exc, xn, h, t_min, t_max, corr, L_subfr ); +#endif /* find integer pitch */ +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + max_val = corr_v[t0_min + corr_idx]; +#else max_val = corr[t0_min]; +#endif t0 = t0_min; for ( i = t0_min + 1; i <= t0_max; i++ ) { +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + float corr_tmp; + + corr_tmp = corr_v[corr_idx + i]; + if ( corr_tmp >= max_val ) + { + max_val = corr_tmp; + t0 = i; + } +#else if ( corr[i] >= max_val ) { max_val = corr[i]; t0 = i; } +#endif } /* If first subframe and t0 >= pit_fr1, do not search fractionnal pitch */ @@ -220,13 +247,24 @@ int16_t E_GAIN_closed_loop_search( frac2 = t0_max_frac; } assert( frac1 <= 0 && frac2 >= 0 && frac2 > frac1 ); +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + corr_idx += t0; +#endif if ( pit_res_max == 6 ) { +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + cor_max = E_GAIN_norm_corr_interpolate6( &corr_v[corr_idx], frac1 ); +#else cor_max = E_GAIN_norm_corr_interpolate6( &corr[t0], frac1 ); +#endif fraction = frac1; for ( i = ( frac1 + step ); i <= frac2; i += step ) { +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + temp = E_GAIN_norm_corr_interpolate6( &corr_v[corr_idx], i ); +#else temp = E_GAIN_norm_corr_interpolate6( &corr[t0], i ); +#endif if ( temp > cor_max ) { cor_max = temp; @@ -236,11 +274,19 @@ int16_t E_GAIN_closed_loop_search( } else { +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + cor_max = E_GAIN_norm_corr_interpolate( &corr_v[corr_idx], frac1 ); +#else cor_max = E_GAIN_norm_corr_interpolate( &corr[t0], frac1 ); +#endif fraction = frac1; for ( i = ( frac1 + step ); i <= frac2; i += step ) { +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + temp = E_GAIN_norm_corr_interpolate( &corr_v[corr_idx], i ); +#else temp = E_GAIN_norm_corr_interpolate( &corr[t0], i ); +#endif if ( temp > cor_max ) { cor_max = temp; -- GitLab