From bc608051ab64a442d57a2162efccf214b1872f34 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Thu, 5 Sep 2024 13:54:33 -0400 Subject: [PATCH 1/8] proposed fix for 874 --- lib_com/options.h | 3 +++ lib_dec/ivas_stereo_dft_dec_fx.c | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 6b9976ba5..75364c385 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -180,6 +180,9 @@ #define FIX_869_WRONG_UVGAIN_STEP /* VA: Fix wrong decoding of uv gain quantizer for td-stereo*/ #define FIX_871_REMOVE_UNNECESSARY_CONDITION /* VA: remove a condition that is not needed and prevented correct frame classification of the secondary channel of the TD stereo */ + +#define FIX_874_INCREASE_ITD_PRECISION /*VA : Fix issue 874 by increasing ITD precision already when decoding index */ +#define FIX_874_INCREASE_ITD_PRECISION_A /*VA : Fix a possible issue where 2*PI should be used instead of PI (to be confirmed) */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 19973a3df..8159e4398 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -926,7 +926,11 @@ void stereo_dft_dec_smooth_parameters_fx( Word16 q_val; IF( GT_32( L_sub( hStereoDft->gipd_fx[add( k, k_offset )], hStereoDft->ipd_xfade_prev_fx ), EVS_PI_FX_Q27 ) ) { +#ifdef FIX_874_INCREASE_ITD_PRECISION_A + hStereoDft->ipd_xfade_target_fx = L_sub( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 << 1 ); +#else hStereoDft->ipd_xfade_target_fx = L_sub( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 ); +#endif move32(); hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); move32(); @@ -2450,12 +2454,16 @@ static void stereo_dft_compute_td_stefi_params_fx( static void stereo_dft_dequantize_ipd_fx( Word16 *ind, Word32 *out_fx, +#ifndef FIX_874_INCREASE_ITD_PRECISION const Word16 N, +#endif const Word16 bits ) { - Word16 i; Word16 delta_fx; +#ifndef FIX_874_INCREASE_ITD_PRECISION + Word16 i; Word32 temp_out; +#endif IF( EQ_16( bits, 2 ) ) /* 2-bit phase quantization for the highest frequency band only */ { delta_fx = ( EVS_PI_FX ) >> 1; @@ -2478,12 +2486,17 @@ static void stereo_dft_dequantize_ipd_fx( assert( 0 ); } +#ifndef FIX_874_INCREASE_ITD_PRECISION FOR( i = 0; i < N; i++ ) { temp_out = L_sub( L_mult0( ind[i], delta_fx ), ( EVS_PI_FX ) ); *out_fx = L_shl( temp_out, 14 ); move32(); } +#else + *out_fx = L_sub( W_sat_l( W_mult_32_16( L_shl( ind[0], 13 ), delta_fx ) ), EVS_PI_FX_Q27 ); + move32(); +#endif return; } @@ -3782,7 +3795,11 @@ void stereo_dft_dec_read_BS_fx( move16(); nb = add( nb, STEREO_DFT_GIPD_NBITS ); n_bits = add( n_bits, STEREO_DFT_GIPD_NBITS ); +#ifndef FIX_874_INCREASE_ITD_PRECISION stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), 1, STEREO_DFT_GIPD_NBITS ); +#else + stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), STEREO_DFT_GIPD_NBITS ); +#endif } } ELSE IF( LE_16( *nb_bits, ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - STEREO_DFT_FLAG_BITS - STEREO_DFT_SID_GIPD_NBITS - SID_FORMAT_NBITS ) ) ) @@ -3798,7 +3815,11 @@ void stereo_dft_dec_read_BS_fx( move16(); nb = add( nb, STEREO_DFT_SID_GIPD_NBITS ); n_bits = add( n_bits, STEREO_DFT_SID_GIPD_NBITS ); +#ifndef FIX_874_INCREASE_ITD_PRECISION stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), 1, STEREO_DFT_SID_GIPD_NBITS ); +#else + stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), STEREO_DFT_SID_GIPD_NBITS ); +#endif } } ELSE -- GitLab From 68b584217c9c3d7d4a5b530b2ec85d8b2ad25e54 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Thu, 17 Oct 2024 10:48:17 +0200 Subject: [PATCH 2/8] change to left shift operation for consistency with the previous case --- lib_dec/ivas_stereo_dft_dec_fx.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index b6c58eb7c..b3fdec88b 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -949,7 +949,11 @@ void stereo_dft_dec_smooth_parameters_fx( } ELSE IF( GT_32( L_sub( hStereoDft->ipd_xfade_prev_fx, hStereoDft->gipd_fx[add( k, k_offset )] ), EVS_PI_FX_Q27 ) ) { +#ifndef FIX_874_INCREASE_ITD_PRECISION_A hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], L_shl( EVS_PI_FX_Q27, 1 ) ); +#else + hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 <<1 ); +#endif move32(); hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); q_val = add( q_val, Q9 ); /* Q27 - (Q15 - q_val + (-3))*/ -- GitLab From 06d212d3a6854d74ed29124a4c9b6167dbe5644f Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 18 Oct 2024 16:06:51 +0200 Subject: [PATCH 3/8] fix for corner cases where ipd differences are exactly pi, but fixed point calculation rounding enables changes for cases when <> pi --- lib_dec/ivas_stereo_dft_dec_fx.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index b3fdec88b..42e9d86ec 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -898,11 +898,17 @@ void stereo_dft_dec_smooth_parameters_fx( Word32 diff_ipd; Word16 nbands; Word32 max_res_pred_ind; +#ifdef FIX_874_INCREASE_ITD_PRECISION + Word32 PI_round; +#endif N_div = STEREO_DFT_NBDIV; move16(); k_offset = STEREO_DFT_OFFSET; move16(); +#ifdef FIX_874_INCREASE_ITD_PRECISION + PI_round = EVS_PI_FX_Q27 + EPSILLON_FX; /*add error corrections when comparing ipds with exactly a difference of pi*/ +#endif test(); IF( hStereoDft->frame_sid_nodata || prev_sid_nodata ) @@ -1242,12 +1248,20 @@ void stereo_dft_dec_smooth_parameters_fx( /* Smoothing of IPDs*/ pgIpd = hStereoDft->gipd_fx + ( add( k, k_offset ) ); diff_ipd = L_sub( pgIpd[0], pgIpd[-hStereoDft->prm_res[add( k, k_offset )]] ); +#ifndef FIX_874_INCREASE_ITD_PRECISION IF( LT_32( diff_ipd, -EVS_PI_FX_Q27 ) ) +#else + IF( LT_32( diff_ipd, -PI_round ) ) +#endif { pgIpd[0] = L_add( pgIpd[0], EVS_2PI_FX_Q27 ); move32(); } +#ifndef FIX_874_INCREASE_ITD_PRECISION ELSE IF( GT_32( diff_ipd, EVS_PI_FX_Q27 ) ) +#else + ELSE IF( GT_32( diff_ipd, PI_round ) ) +#endif { pgIpd[0] = L_sub( pgIpd[0], EVS_2PI_FX_Q27 ); move32(); @@ -1264,6 +1278,7 @@ void stereo_dft_dec_smooth_parameters_fx( { pgIpd[0] = L_add( L_shr( pgIpd[0], 1 ), L_shr( pgIpd[-hStereoDft->prm_res[add( k, k_offset )]], 1 ) ); move32(); + printf("offset = %d \n", hStereoDft->prm_res[add( k, k_offset )]); } } @@ -3837,6 +3852,7 @@ void stereo_dft_dec_read_BS_fx( move16(); move16(); + dbgwrite(hStereoDft->gipd_fx, sizeof(Word32), 3, 1, "res/gipd_fx"); /*------------------------------------------------------------------* * read Residual parameters *-----------------------------------------------------------------*/ -- GitLab From f9a144747651413ecd1631f45ac23810baef1840 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 18 Oct 2024 16:10:47 +0200 Subject: [PATCH 4/8] rename define to reflect IPD changes and not ITD --- lib_com/options.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 31444407e..c671abd75 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -181,8 +181,8 @@ #define FIX_871_REMOVE_UNNECESSARY_CONDITION /* VA: remove a condition that is not needed and prevented correct frame classification of the secondary channel of the TD stereo */ -#define FIX_874_INCREASE_ITD_PRECISION /*VA : Fix issue 874 by increasing ITD precision already when decoding index */ -#define FIX_874_INCREASE_ITD_PRECISION_A /*VA : Fix a possible issue where 2*PI should be used instead of PI (to be confirmed) */ +#define FIX_874_INCREASE_IPD_PRECISION /*VA : Fix issue 874 by increasing ITD precision already when decoding index */ +#define FIX_874_INCREASE_IPD_PRECISION_A /*VA : Fix a possible issue where 2*PI should be used instead of PI (to be confirmed) */ #define FIX_875_SATURATION_DURING_ROUNDING /* VA: fix a possible saturation when rounding */ #define FIX_882_LOW_LEVEL_DISCONTINUITIES /* VA: Fix 882, discontinuities for low level signal by adding a scaling function that uses rounding, this function is more complex than normal one, has to be used only when necessary*/ #define FIX_879_DIFF_CONCEAL_PATH /* FhG: Fix for issue 879 and different concelalment paths that led to crash */ -- GitLab From 921ac0ec794c31b801af536c7ecea9271ab9e3cc Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 18 Oct 2024 16:10:57 +0200 Subject: [PATCH 5/8] remove debugging code --- lib_dec/ivas_stereo_dft_dec_fx.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 42e9d86ec..f21290554 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -898,7 +898,7 @@ void stereo_dft_dec_smooth_parameters_fx( Word32 diff_ipd; Word16 nbands; Word32 max_res_pred_ind; -#ifdef FIX_874_INCREASE_ITD_PRECISION +#ifdef FIX_874_INCREASE_IPD_PRECISION Word32 PI_round; #endif @@ -906,7 +906,7 @@ void stereo_dft_dec_smooth_parameters_fx( move16(); k_offset = STEREO_DFT_OFFSET; move16(); -#ifdef FIX_874_INCREASE_ITD_PRECISION +#ifdef FIX_874_INCREASE_IPD_PRECISION PI_round = EVS_PI_FX_Q27 + EPSILLON_FX; /*add error corrections when comparing ipds with exactly a difference of pi*/ #endif @@ -932,7 +932,7 @@ void stereo_dft_dec_smooth_parameters_fx( Word16 q_val; IF( GT_32( L_sub( hStereoDft->gipd_fx[add( k, k_offset )], hStereoDft->ipd_xfade_prev_fx ), EVS_PI_FX_Q27 ) ) { -#ifdef FIX_874_INCREASE_ITD_PRECISION_A +#ifdef FIX_874_INCREASE_IPD_PRECISION_A hStereoDft->ipd_xfade_target_fx = L_sub( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 << 1 ); #else hStereoDft->ipd_xfade_target_fx = L_sub( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 ); @@ -955,7 +955,7 @@ void stereo_dft_dec_smooth_parameters_fx( } ELSE IF( GT_32( L_sub( hStereoDft->ipd_xfade_prev_fx, hStereoDft->gipd_fx[add( k, k_offset )] ), EVS_PI_FX_Q27 ) ) { -#ifndef FIX_874_INCREASE_ITD_PRECISION_A +#ifndef FIX_874_INCREASE_IPD_PRECISION_A hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], L_shl( EVS_PI_FX_Q27, 1 ) ); #else hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 <<1 ); @@ -1248,7 +1248,7 @@ void stereo_dft_dec_smooth_parameters_fx( /* Smoothing of IPDs*/ pgIpd = hStereoDft->gipd_fx + ( add( k, k_offset ) ); diff_ipd = L_sub( pgIpd[0], pgIpd[-hStereoDft->prm_res[add( k, k_offset )]] ); -#ifndef FIX_874_INCREASE_ITD_PRECISION +#ifndef FIX_874_INCREASE_IPD_PRECISION IF( LT_32( diff_ipd, -EVS_PI_FX_Q27 ) ) #else IF( LT_32( diff_ipd, -PI_round ) ) @@ -1257,7 +1257,7 @@ void stereo_dft_dec_smooth_parameters_fx( pgIpd[0] = L_add( pgIpd[0], EVS_2PI_FX_Q27 ); move32(); } -#ifndef FIX_874_INCREASE_ITD_PRECISION +#ifndef FIX_874_INCREASE_IPD_PRECISION ELSE IF( GT_32( diff_ipd, EVS_PI_FX_Q27 ) ) #else ELSE IF( GT_32( diff_ipd, PI_round ) ) @@ -2473,13 +2473,13 @@ static void stereo_dft_compute_td_stefi_params_fx( static void stereo_dft_dequantize_ipd_fx( Word16 *ind, Word32 *out_fx, -#ifndef FIX_874_INCREASE_ITD_PRECISION +#ifndef FIX_874_INCREASE_IPD_PRECISION const Word16 N, #endif const Word16 bits ) { Word16 delta_fx; -#ifndef FIX_874_INCREASE_ITD_PRECISION +#ifndef FIX_874_INCREASE_IPD_PRECISION Word16 i; Word32 temp_out; #endif @@ -2505,7 +2505,7 @@ static void stereo_dft_dequantize_ipd_fx( assert( 0 ); } -#ifndef FIX_874_INCREASE_ITD_PRECISION +#ifndef FIX_874_INCREASE_IPD_PRECISION FOR( i = 0; i < N; i++ ) { temp_out = L_sub( L_mult0( ind[i], delta_fx ), ( EVS_PI_FX ) ); @@ -3814,7 +3814,7 @@ void stereo_dft_dec_read_BS_fx( move16(); nb = add( nb, STEREO_DFT_GIPD_NBITS ); n_bits = add( n_bits, STEREO_DFT_GIPD_NBITS ); -#ifndef FIX_874_INCREASE_ITD_PRECISION +#ifndef FIX_874_INCREASE_IPD_PRECISION stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), 1, STEREO_DFT_GIPD_NBITS ); #else stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), STEREO_DFT_GIPD_NBITS ); @@ -3834,7 +3834,7 @@ void stereo_dft_dec_read_BS_fx( move16(); nb = add( nb, STEREO_DFT_SID_GIPD_NBITS ); n_bits = add( n_bits, STEREO_DFT_SID_GIPD_NBITS ); -#ifndef FIX_874_INCREASE_ITD_PRECISION +#ifndef FIX_874_INCREASE_IPD_PRECISION stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), 1, STEREO_DFT_SID_GIPD_NBITS ); #else stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), STEREO_DFT_SID_GIPD_NBITS ); @@ -3852,7 +3852,6 @@ void stereo_dft_dec_read_BS_fx( move16(); move16(); - dbgwrite(hStereoDft->gipd_fx, sizeof(Word32), 3, 1, "res/gipd_fx"); /*------------------------------------------------------------------* * read Residual parameters *-----------------------------------------------------------------*/ -- GitLab From 548f6b251802b92d9b9157802548a6e14ab5957b Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 18 Oct 2024 16:14:37 +0200 Subject: [PATCH 6/8] remove more debugging code --- lib_dec/ivas_stereo_dft_dec_fx.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index f21290554..a5286b3ae 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -1278,7 +1278,6 @@ void stereo_dft_dec_smooth_parameters_fx( { pgIpd[0] = L_add( L_shr( pgIpd[0], 1 ), L_shr( pgIpd[-hStereoDft->prm_res[add( k, k_offset )]], 1 ) ); move32(); - printf("offset = %d \n", hStereoDft->prm_res[add( k, k_offset )]); } } -- GitLab From d1a5956cc25aed21630fdd87a58c833e518f144e Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 18 Oct 2024 16:16:42 +0200 Subject: [PATCH 7/8] add assignment macro --- lib_dec/ivas_stereo_dft_dec_fx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index a5286b3ae..4563dafd6 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -908,6 +908,7 @@ void stereo_dft_dec_smooth_parameters_fx( move16(); #ifdef FIX_874_INCREASE_IPD_PRECISION PI_round = EVS_PI_FX_Q27 + EPSILLON_FX; /*add error corrections when comparing ipds with exactly a difference of pi*/ + move32(); #endif test(); -- GitLab From 3b101a3ea4998450b84ee6e513a62cc6322bc819 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 18 Oct 2024 16:42:09 +0200 Subject: [PATCH 8/8] clang format --- lib_dec/ivas_stereo_dft_dec_fx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 4563dafd6..40c8baf96 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -898,7 +898,7 @@ void stereo_dft_dec_smooth_parameters_fx( Word32 diff_ipd; Word16 nbands; Word32 max_res_pred_ind; -#ifdef FIX_874_INCREASE_IPD_PRECISION +#ifdef FIX_874_INCREASE_IPD_PRECISION Word32 PI_round; #endif @@ -906,7 +906,7 @@ void stereo_dft_dec_smooth_parameters_fx( move16(); k_offset = STEREO_DFT_OFFSET; move16(); -#ifdef FIX_874_INCREASE_IPD_PRECISION +#ifdef FIX_874_INCREASE_IPD_PRECISION PI_round = EVS_PI_FX_Q27 + EPSILLON_FX; /*add error corrections when comparing ipds with exactly a difference of pi*/ move32(); #endif @@ -959,7 +959,7 @@ void stereo_dft_dec_smooth_parameters_fx( #ifndef FIX_874_INCREASE_IPD_PRECISION_A hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], L_shl( EVS_PI_FX_Q27, 1 ) ); #else - hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 <<1 ); + hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 << 1 ); #endif move32(); hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); -- GitLab