From 69a34489c5d862545173d754ee577cd61463fc82 Mon Sep 17 00:00:00 2001 From: Arthur Date: Fri, 13 Dec 2024 14:40:09 +0100 Subject: [PATCH 01/16] Changes made to improve the function: - Replaced some L_add_sat+Mpy_32_16_1 using Word16 by Madd_32_32 using Word32 (better accuracy) - Computed often used shift operand only once outside the loop - divided cldfb loop with inner IF-statements into 2 loops without inner IF-statements - replaced smoothing constant 16-Bit values for 1/6 and 1/20 by 32-Bit values (better accuracy) The output file is slightly different (9e-5), the WMOPS are reduced by 34 (max. 150 -> 116). --- lib_com/options.h | 3 +- lib_dec/ivas_spar_decoder.c | 104 ++++++++++++++++++++++++++++++++---- 2 files changed, 96 insertions(+), 11 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 2954fb8a4..76927e2db 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -55,7 +55,7 @@ #define SUPPORT_JBM_TRACEFILE /* Support for JBM tracefile, which is needed for 3GPP objective/subjective testing, but not relevant for real-world implementations */ -/*#define WMOPS*/ /* Activate complexity and memory counters */ +/*#define WMOPSi*/ /* Activate complexity and memory counters */ #ifdef WMOPS /*#define WMOPS_PER_FRAME*/ /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ /*#define WMOPS_DETAIL*/ /* Output detailed complexity printout for every function. Increases runtime overhead */ @@ -91,4 +91,5 @@ #define FIX_1054_IF_ELSE_CMPLX /* VA: Fix 1054 incorrect counting of complexity when ELSE-IF sequence is encoutered in two functions */ #define FIX_1052_COPY_CMPLX_DISCREPANCY /* VA: modify IF-ELSE statements used in Copy*() functions to avoid dependency on x[] and y[] in RAM */ #define FIX_1049_SHR_RO_COMPLEXITY /* VA: fix for issue 1049: incorrect counting of complexity in the shr_ro() function */ +#define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF /* FhG: fix for issue 1101: complexity of spar dec upmixer */ #endif diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index fdace42d8..f0497a038 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -1160,6 +1160,8 @@ void ivas_spar_get_parameters_fx( split_band = SPAR_DIRAC_SPLIT_START_BAND; move16(); + Word16 add_weight_fx = sub( MAX_WORD16, weight_fx ); + Word16 add_weight_20ms_fx = sub( MAX_WORD16, weight_20ms_fx ); FOR( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) { FOR( out_ch = 0; out_ch < num_ch_out; out_ch++ ) @@ -1175,8 +1177,8 @@ void ivas_spar_get_parameters_fx( IF( GT_16( hSpar->i_subframe, 3 ) ) { - par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts0][out_ch][in_ch][spar_band], sub( MAX_WORD16, weight_fx ) ), - Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts1][out_ch][in_ch][spar_band], weight_fx ) ); /*hSpar->hMdDec->Q_mixer_mat*/ + par_mat_fx[out_ch][in_ch][spar_band] = Madd_32_16( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts1][out_ch][in_ch][spar_band], weight_fx ), + hSpar->hMdDec->mixer_mat_prev_fx[ts0][out_ch][in_ch][spar_band], add_weight_fx ); move32(); } ELSE @@ -1193,7 +1195,8 @@ void ivas_spar_get_parameters_fx( /* 20ms Transport channel reconstruction with matching encoder/decoder processing */ Word16 prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */ move16(); - par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[prev_idx][out_ch][in_ch][spar_band], sub( MAX_WORD16, weight_20ms_fx ) ), Mpy_32_16_1( hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band], weight_20ms_fx ) ); /*hSpar->hMdDec->Q_mixer_mat*/ + par_mat_fx[out_ch][in_ch][spar_band] = Madd_32_16( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[prev_idx][out_ch][in_ch][spar_band], add_weight_20ms_fx ), + hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band], weight_20ms_fx); /*hSpar->hMdDec->Q_mixer_mat*/ move32(); } } @@ -1353,9 +1356,9 @@ static void ivas_spar_calc_smooth_facs_fx( smooth_long_avg_fx[b] = L_add( smooth_long_avg_fx[b], smooth_buf_fx[b][i] ); // Q0 move32(); } - smooth_short_avg_fx[b] = Mpy_32_16_1( smooth_short_avg_fx[b], 5461 /*(1/6 in Q15)*/ ); // Q0 + smooth_short_avg_fx[b] = Mpy_32_32( smooth_short_avg_fx[b], 357913941 /*(1/6 in Q31)*/ ); // Q0 move32(); - smooth_long_avg_fx[b] = Mpy_32_16_1( smooth_long_avg_fx[b], 1639 /*(1/20 in Q15)*/ ); // Q0 + smooth_long_avg_fx[b] = Mpy_32_32( smooth_long_avg_fx[b], 107374182 /*(1/20 in Q31)*/ ); // Q0 move32(); /* calculate smoothing factor based on energy averages */ @@ -1843,6 +1846,8 @@ void ivas_spar_dec_upmixer_sf_fx( ivas_spar_calc_smooth_facs_fx( cldfb_in_ts_re_fx[0], cldfb_in_ts_im_fx[0], q_cldfb, num_spar_bands, hSpar->subframe_nbslots[hSpar->subframes_rendered], hSpar->subframes_rendered == 0, &hSpar->hFbMixer->pFb->fb_bin_to_band, hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_buf_fx ); } + + Word16 sh_l = sub( 31, q1 ); FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { md_idx = hSpar->render_to_md_map[( ts + slot_idx_start )]; /*Q0*/ @@ -1870,7 +1875,7 @@ void ivas_spar_dec_upmixer_sf_fx( } } } - +#ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF FOR( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ ) { Word32 out_re_fx[IVAS_SPAR_MAX_CH]; @@ -1902,8 +1907,8 @@ void ivas_spar_dec_upmixer_sf_fx( FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ - Word16 tmp = extract_l( L_shr( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 7 ) ); /*Q15*/ - cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ + Word32 tmp = L_shl( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31*/ + cldfb_par_fx = Madd_32_32( cldfb_par_fx, mixer_mat_fx[out_ch][in_ch][spar_band], tmp ); /*q1*/ } } @@ -1918,13 +1923,92 @@ void ivas_spar_dec_upmixer_sf_fx( /*update CLDFB data with the parameter-modified data*/ FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) { - cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ + cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ + move32(); + cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sh_l ); /*Q=6*/ + move32(); + } + } +#else + /* Note: This version splits the cldfb band loop into 2 loops, removing some inner-loop IF_statements */ + Word16 min_cldf_band = s_min( CLDFB_PAR_WEIGHT_START_BAND, num_cldfb_bands ); + Word32 out_re_fx[IVAS_SPAR_MAX_CH]; + Word32 out_im_fx[IVAS_SPAR_MAX_CH]; + Word32 cldfb_par_fx; /*q1*/ + ivas_fb_bin_to_band_data_t *bin2band = &hSpar->hFbMixer->pFb->fb_bin_to_band; + + /* First loop from cldfb_band=0 till min_cldf_band (CLDFB_PAR_WEIGHT_START_BAND) */ + FOR( cldfb_band = 0; cldfb_band < min_cldf_band; cldfb_band++ ) + { + spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; /*Q0*/ + move16(); + FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) + { + out_re_fx[out_ch] = 0; + move32(); + out_im_fx[out_ch] = 0; + move32(); + FOR( in_ch = 0; in_ch < numch_in; in_ch++ ) + { + IF( b_skip_mat[out_ch][in_ch] == 0 ) + { + cldfb_par_fx = mixer_mat_fx[out_ch][in_ch][spar_band]; /*q1*/ + move32(); + out_re_fx[out_ch] = Madd_32_32( out_re_fx[out_ch], cldfb_in_ts_re_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ + move32(); + out_im_fx[out_ch] = Madd_32_32( out_im_fx[out_ch], cldfb_in_ts_im_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ + move32(); + } + } + } + /*update CLDFB data with the parameter-modified data*/ + FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) + { + cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ move32(); - cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ + cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sh_l ); /*Q=6*/ move32(); } } + + /* Second loop from min_cldf_band (CLDFB_PAR_WEIGHT_START_BAND) till num_cldfb_bands */ + FOR( ; cldfb_band < num_cldfb_bands; cldfb_band++ ) + { + FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) + { + Word32 Out_re_fx = L_add(0,0); + Word32 Out_im_fx = L_add(0,0); + FOR( in_ch = 0; in_ch < numch_in; in_ch++ ) + { + IF( b_skip_mat[out_ch][in_ch] == 0 ) + { + cldfb_par_fx = 0; + move32(); + FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) + { + /* accumulate contributions from all SPAR bands */ + Word32 tmp = L_shl( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31*/ + cldfb_par_fx = Madd_32_32( cldfb_par_fx, mixer_mat_fx[out_ch][in_ch][spar_band], tmp ); /*q1*/ + } + Out_re_fx = Madd_32_32( Out_re_fx, cldfb_in_ts_re_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ + Out_im_fx = Madd_32_32( Out_im_fx, cldfb_in_ts_im_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ + } + } + out_re_fx[out_ch] = Out_re_fx; + out_im_fx[out_ch] = Out_im_fx; + } + + /*update CLDFB data with the parameter-modified data*/ + FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) + { + cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ + move32(); + cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sh_l ); /*Q=6*/ + move32(); + } + } +#endif test(); IF( ( EQ_16( ( add( add( slot_idx_start, ts ), 1 ) ), hSpar->num_slots ) ) || ( NE_16( ( shr( md_idx, 2 ) /* md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME */ ), ( hSpar->render_to_md_map[( ( slot_idx_start + ts ) + 1 )] / JBM_CLDFB_SLOTS_IN_SUBFRAME /*It's value is 4*/ ) ) ) ) { -- GitLab From 3fd5ba73895775af39d58838aa48adfde316fd8c Mon Sep 17 00:00:00 2001 From: Arthur Date: Fri, 13 Dec 2024 14:50:48 +0100 Subject: [PATCH 02/16] fix clang format issue --- lib_dec/ivas_spar_decoder.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index f0497a038..cce6f4c1e 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -1178,7 +1178,7 @@ void ivas_spar_get_parameters_fx( { par_mat_fx[out_ch][in_ch][spar_band] = Madd_32_16( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts1][out_ch][in_ch][spar_band], weight_fx ), - hSpar->hMdDec->mixer_mat_prev_fx[ts0][out_ch][in_ch][spar_band], add_weight_fx ); + hSpar->hMdDec->mixer_mat_prev_fx[ts0][out_ch][in_ch][spar_band], add_weight_fx ); move32(); } ELSE @@ -1196,7 +1196,7 @@ void ivas_spar_get_parameters_fx( Word16 prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */ move16(); par_mat_fx[out_ch][in_ch][spar_band] = Madd_32_16( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[prev_idx][out_ch][in_ch][spar_band], add_weight_20ms_fx ), - hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band], weight_20ms_fx); /*hSpar->hMdDec->Q_mixer_mat*/ + hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band], weight_20ms_fx ); /*hSpar->hMdDec->Q_mixer_mat*/ move32(); } } @@ -1908,7 +1908,7 @@ void ivas_spar_dec_upmixer_sf_fx( { /* accumulate contributions from all SPAR bands */ Word32 tmp = L_shl( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31*/ - cldfb_par_fx = Madd_32_32( cldfb_par_fx, mixer_mat_fx[out_ch][in_ch][spar_band], tmp ); /*q1*/ + cldfb_par_fx = Madd_32_32( cldfb_par_fx, mixer_mat_fx[out_ch][in_ch][spar_band], tmp ); /*q1*/ } } @@ -1977,8 +1977,8 @@ void ivas_spar_dec_upmixer_sf_fx( { FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) { - Word32 Out_re_fx = L_add(0,0); - Word32 Out_im_fx = L_add(0,0); + Word32 Out_re_fx = L_add( 0, 0 ); + Word32 Out_im_fx = L_add( 0, 0 ); FOR( in_ch = 0; in_ch < numch_in; in_ch++ ) { IF( b_skip_mat[out_ch][in_ch] == 0 ) -- GitLab From 879caf9863ccfd10877afcbaf3955aa32a0e81f9 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Mon, 16 Dec 2024 13:06:07 +0100 Subject: [PATCH 03/16] fix typo in /*#define WMOPSi*/ --- lib_com/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 76927e2db..778082d9b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -55,7 +55,7 @@ #define SUPPORT_JBM_TRACEFILE /* Support for JBM tracefile, which is needed for 3GPP objective/subjective testing, but not relevant for real-world implementations */ -/*#define WMOPSi*/ /* Activate complexity and memory counters */ +/*#define WMOPS*/ /* Activate complexity and memory counters */ #ifdef WMOPS /*#define WMOPS_PER_FRAME*/ /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ /*#define WMOPS_DETAIL*/ /* Output detailed complexity printout for every function. Increases runtime overhead */ -- GitLab From dfd18633e8b75c87b4011be9acc218620476d845 Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 17 Dec 2024 11:49:21 +0100 Subject: [PATCH 04/16] Add fixes for issue 1101, see FIX_1101 macros in options.h --- lib_com/options.h | 6 ++++ lib_dec/ivas_spar_decoder.c | 63 ++++++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 7f5d5c422..88eb56b66 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -101,4 +101,10 @@ #define FIX_1109_OPTIM_MCT_STEREO_IGF_DEC /* FhG: optimize mctStereoIGF_dec_fx() */ #define FIX_1110_OPTIM_DIRAC_DECORR_PROC /* FhG: optimize ivas_dirac_dec_decorr_process() */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF /* FhG: fix for issue 1101: complexity of spar dec upmixer */ +/* Note: each compile switch (FIX_1101_...) is independent from the other ones */ +#define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_USE_MADD_ADD_WEIGHTS /* FhG: Defines 1.0f-weight variables, uses Madd operation instead of L_add_sat */ +#define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SPLIT_LOOPS /* FhG: Splits single loop with IF-statements into two low-complex loops */ +#define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SATURATE_WEIGHTS /* FhG: BUGFIX: Saturate weight parameters during reformatting, fixes overflow in extract_l */ +#define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_HQ_CONSTANTS /* FhG: IMPROVE PRECISION: Uses 1/6 and 1/20 in full-precise Q31 constants instead of Q15 */ +#define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_USE_UNIQUE_SHL /* FhG: Uses unique shift amount in each loop iteration */ #endif diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index cce6f4c1e..43600c6c1 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -1160,8 +1160,10 @@ void ivas_spar_get_parameters_fx( split_band = SPAR_DIRAC_SPLIT_START_BAND; move16(); +#ifdef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_USE_MADD_ADD_WEIGHTS Word16 add_weight_fx = sub( MAX_WORD16, weight_fx ); Word16 add_weight_20ms_fx = sub( MAX_WORD16, weight_20ms_fx ); +#endif FOR( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) { FOR( out_ch = 0; out_ch < num_ch_out; out_ch++ ) @@ -1176,9 +1178,13 @@ void ivas_spar_get_parameters_fx( { IF( GT_16( hSpar->i_subframe, 3 ) ) { - +#ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_USE_MADD_ADD_WEIGHTS + par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts0][out_ch][in_ch][spar_band], sub( MAX_WORD16, weight_fx ) ), + Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts1][out_ch][in_ch][spar_band], weight_fx ) ); /*hSpar->hMdDec->Q_mixer_mat*/ +#else par_mat_fx[out_ch][in_ch][spar_band] = Madd_32_16( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts1][out_ch][in_ch][spar_band], weight_fx ), hSpar->hMdDec->mixer_mat_prev_fx[ts0][out_ch][in_ch][spar_band], add_weight_fx ); +#endif move32(); } ELSE @@ -1195,8 +1201,12 @@ void ivas_spar_get_parameters_fx( /* 20ms Transport channel reconstruction with matching encoder/decoder processing */ Word16 prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */ move16(); +#ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_USE_MADD_ADD_WEIGHTS + par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[prev_idx][out_ch][in_ch][spar_band], sub( MAX_WORD16, weight_20ms_fx ) ), Mpy_32_16_1( hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band], weight_20ms_fx ) ); /*hSpar->hMdDec->Q_mixer_mat*/ +#else par_mat_fx[out_ch][in_ch][spar_band] = Madd_32_16( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[prev_idx][out_ch][in_ch][spar_band], add_weight_20ms_fx ), hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band], weight_20ms_fx ); /*hSpar->hMdDec->Q_mixer_mat*/ +#endif move32(); } } @@ -1356,10 +1366,17 @@ static void ivas_spar_calc_smooth_facs_fx( smooth_long_avg_fx[b] = L_add( smooth_long_avg_fx[b], smooth_buf_fx[b][i] ); // Q0 move32(); } +#ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_HQ_CONSTANTS + smooth_short_avg_fx[b] = Mpy_32_16_1( smooth_short_avg_fx[b], 5461 /*(1/6 in Q15)*/ ); // Q0 + move32(); + smooth_long_avg_fx[b] = Mpy_32_16_1( smooth_long_avg_fx[b], 1639 /*(1/20 in Q15)*/ ); // Q0 + move32(); +#else smooth_short_avg_fx[b] = Mpy_32_32( smooth_short_avg_fx[b], 357913941 /*(1/6 in Q31)*/ ); // Q0 move32(); smooth_long_avg_fx[b] = Mpy_32_32( smooth_long_avg_fx[b], 107374182 /*(1/20 in Q31)*/ ); // Q0 move32(); +#endif /* calculate smoothing factor based on energy averages */ /* reduce factor for higher short-term energy */ @@ -1846,8 +1863,9 @@ void ivas_spar_dec_upmixer_sf_fx( ivas_spar_calc_smooth_facs_fx( cldfb_in_ts_re_fx[0], cldfb_in_ts_im_fx[0], q_cldfb, num_spar_bands, hSpar->subframe_nbslots[hSpar->subframes_rendered], hSpar->subframes_rendered == 0, &hSpar->hFbMixer->pFb->fb_bin_to_band, hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_buf_fx ); } - +#ifdef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_USE_UNIQUE_SHL Word16 sh_l = sub( 31, q1 ); +#endif FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { md_idx = hSpar->render_to_md_map[( ts + slot_idx_start )]; /*Q0*/ @@ -1875,7 +1893,7 @@ void ivas_spar_dec_upmixer_sf_fx( } } } -#ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF +#ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SPLIT_LOOPS FOR( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ ) { Word32 out_re_fx[IVAS_SPAR_MAX_CH]; @@ -1907,8 +1925,13 @@ void ivas_spar_dec_upmixer_sf_fx( FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ - Word32 tmp = L_shl( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31*/ +#ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SATURATE_WEIGHTS + Word16 tmp = extract_l( L_shr( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 7 ) ); /*Q15*/ + cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ +#else + Word32 tmp = L_shl_sat( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31(sat)*/ cldfb_par_fx = Madd_32_32( cldfb_par_fx, mixer_mat_fx[out_ch][in_ch][spar_band], tmp ); /*q1*/ +#endif } } @@ -1923,13 +1946,20 @@ void ivas_spar_dec_upmixer_sf_fx( /*update CLDFB data with the parameter-modified data*/ FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) { +#ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_USE_UNIQUE_SHL + cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ + move32(); + cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ + move32(); +#else cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ move32(); cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sh_l ); /*Q=6*/ move32(); +#endif } } -#else +#else /* FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SPLIT_LOOPS */ /* Note: This version splits the cldfb band loop into 2 loops, removing some inner-loop IF_statements */ Word16 min_cldf_band = s_min( CLDFB_PAR_WEIGHT_START_BAND, num_cldfb_bands ); Word32 out_re_fx[IVAS_SPAR_MAX_CH]; @@ -1964,10 +1994,17 @@ void ivas_spar_dec_upmixer_sf_fx( /*update CLDFB data with the parameter-modified data*/ FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) { +#ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_USE_UNIQUE_SHL + cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ + move32(); + cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ + move32(); +#else cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ move32(); cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sh_l ); /*Q=6*/ move32(); +#endif } } @@ -1988,8 +2025,13 @@ void ivas_spar_dec_upmixer_sf_fx( FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ - Word32 tmp = L_shl( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31*/ +#ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SATURATE_WEIGHTS + Word16 tmp = extract_l( L_shr( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 7 ) ); /*Q15*/ + cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ +#else + Word32 tmp = L_shl_sat( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31(sat)*/ cldfb_par_fx = Madd_32_32( cldfb_par_fx, mixer_mat_fx[out_ch][in_ch][spar_band], tmp ); /*q1*/ +#endif } Out_re_fx = Madd_32_32( Out_re_fx, cldfb_in_ts_re_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ Out_im_fx = Madd_32_32( Out_im_fx, cldfb_in_ts_im_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ @@ -2002,13 +2044,20 @@ void ivas_spar_dec_upmixer_sf_fx( /*update CLDFB data with the parameter-modified data*/ FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) { +#ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_USE_UNIQUE_SHL + cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ + move32(); + cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ + move32(); +#else cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ move32(); cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sh_l ); /*Q=6*/ move32(); +#endif } } -#endif +#endif /* FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SPLIT_LOOPS */ test(); IF( ( EQ_16( ( add( add( slot_idx_start, ts ), 1 ) ), hSpar->num_slots ) ) || ( NE_16( ( shr( md_idx, 2 ) /* md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME */ ), ( hSpar->render_to_md_map[( ( slot_idx_start + ts ) + 1 )] / JBM_CLDFB_SLOTS_IN_SUBFRAME /*It's value is 4*/ ) ) ) ) { -- GitLab From b01a6c47fc4b5a96c55ae49c5a1e98f9dbedae8f Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 17 Dec 2024 11:56:30 +0100 Subject: [PATCH 05/16] fix formatting --- lib_dec/ivas_spar_decoder.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 43600c6c1..9845a01a4 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -1179,8 +1179,8 @@ void ivas_spar_get_parameters_fx( IF( GT_16( hSpar->i_subframe, 3 ) ) { #ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_USE_MADD_ADD_WEIGHTS - par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts0][out_ch][in_ch][spar_band], sub( MAX_WORD16, weight_fx ) ), - Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts1][out_ch][in_ch][spar_band], weight_fx ) ); /*hSpar->hMdDec->Q_mixer_mat*/ + par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts0][out_ch][in_ch][spar_band], sub( MAX_WORD16, weight_fx ) ), + Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts1][out_ch][in_ch][spar_band], weight_fx ) ); /*hSpar->hMdDec->Q_mixer_mat*/ #else par_mat_fx[out_ch][in_ch][spar_band] = Madd_32_16( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts1][out_ch][in_ch][spar_band], weight_fx ), hSpar->hMdDec->mixer_mat_prev_fx[ts0][out_ch][in_ch][spar_band], add_weight_fx ); @@ -1372,7 +1372,7 @@ static void ivas_spar_calc_smooth_facs_fx( smooth_long_avg_fx[b] = Mpy_32_16_1( smooth_long_avg_fx[b], 1639 /*(1/20 in Q15)*/ ); // Q0 move32(); #else - smooth_short_avg_fx[b] = Mpy_32_32( smooth_short_avg_fx[b], 357913941 /*(1/6 in Q31)*/ ); // Q0 + smooth_short_avg_fx[b] = Mpy_32_32( smooth_short_avg_fx[b], 357913941 /*(1/6 in Q31)*/ ); // Q0 move32(); smooth_long_avg_fx[b] = Mpy_32_32( smooth_long_avg_fx[b], 107374182 /*(1/20 in Q31)*/ ); // Q0 move32(); @@ -1930,7 +1930,7 @@ void ivas_spar_dec_upmixer_sf_fx( cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ #else Word32 tmp = L_shl_sat( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31(sat)*/ - cldfb_par_fx = Madd_32_32( cldfb_par_fx, mixer_mat_fx[out_ch][in_ch][spar_band], tmp ); /*q1*/ + cldfb_par_fx = Madd_32_32( cldfb_par_fx, mixer_mat_fx[out_ch][in_ch][spar_band], tmp ); /*q1*/ #endif } } @@ -1952,7 +1952,7 @@ void ivas_spar_dec_upmixer_sf_fx( cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ move32(); #else - cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ + cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ move32(); cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sh_l ); /*Q=6*/ move32(); @@ -2030,7 +2030,7 @@ void ivas_spar_dec_upmixer_sf_fx( cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ #else Word32 tmp = L_shl_sat( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31(sat)*/ - cldfb_par_fx = Madd_32_32( cldfb_par_fx, mixer_mat_fx[out_ch][in_ch][spar_band], tmp ); /*q1*/ + cldfb_par_fx = Madd_32_32( cldfb_par_fx, mixer_mat_fx[out_ch][in_ch][spar_band], tmp ); /*q1*/ #endif } Out_re_fx = Madd_32_32( Out_re_fx, cldfb_in_ts_re_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ @@ -2050,7 +2050,7 @@ void ivas_spar_dec_upmixer_sf_fx( cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ move32(); #else - cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ + cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ move32(); cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sh_l ); /*Q=6*/ move32(); -- GitLab From d8677827590b7e4780edfcc37af135dc07bc8e7f Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 17 Dec 2024 16:09:26 +0100 Subject: [PATCH 06/16] Fix MR 871 by replacing back Madd_32_32 by L_add_sat+Mpy_32_32 --- lib_dec/ivas_spar_decoder.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 9845a01a4..eeee6c663 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -1930,7 +1930,7 @@ void ivas_spar_dec_upmixer_sf_fx( cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ #else Word32 tmp = L_shl_sat( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31(sat)*/ - cldfb_par_fx = Madd_32_32( cldfb_par_fx, mixer_mat_fx[out_ch][in_ch][spar_band], tmp ); /*q1*/ + cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ #endif } } @@ -2030,7 +2030,7 @@ void ivas_spar_dec_upmixer_sf_fx( cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ #else Word32 tmp = L_shl_sat( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31(sat)*/ - cldfb_par_fx = Madd_32_32( cldfb_par_fx, mixer_mat_fx[out_ch][in_ch][spar_band], tmp ); /*q1*/ + cldfb_par_fx = L_add_sat(cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ #endif } Out_re_fx = Madd_32_32( Out_re_fx, cldfb_in_ts_re_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ -- GitLab From 081fdd3cb85ca80e7096e23c1621cb9b412e7e0f Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 17 Dec 2024 16:16:58 +0100 Subject: [PATCH 07/16] formatting --- lib_dec/ivas_spar_decoder.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index eeee6c663..4daac74df 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -1929,8 +1929,8 @@ void ivas_spar_dec_upmixer_sf_fx( Word16 tmp = extract_l( L_shr( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 7 ) ); /*Q15*/ cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ #else - Word32 tmp = L_shl_sat( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31(sat)*/ - cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ + Word32 tmp = L_shl_sat( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31(sat)*/ + cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ #endif } } @@ -1952,7 +1952,7 @@ void ivas_spar_dec_upmixer_sf_fx( cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ move32(); #else - cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ + cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ move32(); cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sh_l ); /*Q=6*/ move32(); @@ -2029,8 +2029,8 @@ void ivas_spar_dec_upmixer_sf_fx( Word16 tmp = extract_l( L_shr( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 7 ) ); /*Q15*/ cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ #else - Word32 tmp = L_shl_sat( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31(sat)*/ - cldfb_par_fx = L_add_sat(cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ + Word32 tmp = L_shl_sat( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31(sat)*/ + cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ #endif } Out_re_fx = Madd_32_32( Out_re_fx, cldfb_in_ts_re_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ @@ -2050,7 +2050,7 @@ void ivas_spar_dec_upmixer_sf_fx( cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ move32(); #else - cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ + cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ move32(); cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sh_l ); /*Q=6*/ move32(); -- GitLab From 3ea17c239833b1d024dee6f7625586a8f84143f1 Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 13 Jan 2025 11:40:59 +0100 Subject: [PATCH 08/16] added rounding (L_shr_r) for coeff calculation (was L_shr) --- lib_com/ivas_spar_com.c | 4 ++++ lib_com/options.h | 1 + 2 files changed, 5 insertions(+) mode change 100644 => 100755 lib_com/ivas_spar_com.c mode change 100644 => 100755 lib_com/options.h diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c old mode 100644 new mode 100755 index 7ab41d5ed..52bdbebf2 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -3832,7 +3832,11 @@ void ivas_compute_spar_params_fx( } ELSE { +#ifdef FIX_11_1_IVAS_SPAR_DEC_UPMIXER_SF_RND_COEFFS + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shr_r( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i], sub( tmp, 22 ) ); // q22 +#else hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shr( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i], sub( tmp, 22 ) ); // q22 +#endif move32(); } } diff --git a/lib_com/options.h b/lib_com/options.h old mode 100644 new mode 100755 index 88eb56b66..04172816b --- a/lib_com/options.h +++ b/lib_com/options.h @@ -107,4 +107,5 @@ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SATURATE_WEIGHTS /* FhG: BUGFIX: Saturate weight parameters during reformatting, fixes overflow in extract_l */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_HQ_CONSTANTS /* FhG: IMPROVE PRECISION: Uses 1/6 and 1/20 in full-precise Q31 constants instead of Q15 */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_USE_UNIQUE_SHL /* FhG: Uses unique shift amount in each loop iteration */ +#define FIX_11_1_IVAS_SPAR_DEC_UPMIXER_SF_RND_COEFFS /* FhG ivas_spar_com.c: Zeroes very small negative coeffs via L_shr_r (was L_shr) */ #endif -- GitLab From 487ba7ca826a1888f556723f363608f815d12482 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 14 Jan 2025 14:25:14 +0100 Subject: [PATCH 09/16] formatting --- lib_com/ivas_spar_com.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 lib_com/ivas_spar_com.c diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c old mode 100755 new mode 100644 index 895748044..d82a01138 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -2636,7 +2636,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( #ifdef FIX_ISSUE_1122 recon_uu_re[i][j] = L_shr( recon_uu_re[i][j], 1 ); // q_recon_uu_re[i][j] - 1 #else - re1[m] = L_shr( re1[m], 1 ); // q_recon_uu_re[i][j]-1 + re1[m] = L_shr( re1[m], 1 ); // q_recon_uu_re[i][j]-1 #endif move32(); q_recon_uu_re[i][j] = sub( q_recon_uu_re[i][j], 1 ); -- GitLab From 50fabd3d4daa13095cc1e8d0b1007cacf6891c30 Mon Sep 17 00:00:00 2001 From: Arthur Date: Fri, 17 Jan 2025 18:16:32 +0100 Subject: [PATCH 10/16] changed format of spar cldfb weights from Q22 to Q31, fixing overflow issue for weights[55+][11] --- lib_com/ivas_fb_mixer.c | 10 +++++++++- lib_com/options.h | 3 ++- lib_dec/ivas_spar_decoder.c | 8 ++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 78603c1db..4d369a630 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -1098,8 +1098,16 @@ static Word16 ivas_calculate_abs_fr_fx( Word16 exp_diff = 0; move16(); +#ifndef FIX_1101_IVAS_SPAR_DEC_SATURATE_WEIGHTS_IN_Q31 Word16 tmp = BASOP_Util_Divide3232_Scale( pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i], sum_over_spar_bands_fx, &exp_diff ); - pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i] = L_shl( L_deposit_l( tmp ), add( Q7, exp_diff ) ); // Q22 + pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i] = L_min(0x003FFFFF, L_shl( L_deposit_l( tmp ), add( Q7, exp_diff ) ) ); // Q22 +#else + /* Note: 16-bit division result has bad accuracy for num=denom */ + Word32 L_tmp = BASOP_Util_Divide3232_Scale_cadence( pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i], sum_over_spar_bands_fx, &exp_diff ); // Q31 + if (exp_diff != 0) + L_tmp = L_shl_sat(L_tmp, exp_diff); /* convert to Q31 with saturation */ + pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i] = L_tmp; // Q31 +#endif move32(); } pFb->fb_bin_to_band.p_spar_start_bands[j] = spar_start; diff --git a/lib_com/options.h b/lib_com/options.h index 198149741..e4695a95b 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -120,7 +120,8 @@ /* Note: each compile switch (FIX_1101_...) is independent from the other ones */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_USE_MADD_ADD_WEIGHTS /* FhG: Defines 1.0f-weight variables, uses Madd operation instead of L_add_sat */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SPLIT_LOOPS /* FhG: Splits single loop with IF-statements into two low-complex loops */ -#define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SATURATE_WEIGHTS /* FhG: BUGFIX: Saturate weight parameters during reformatting, fixes overflow in extract_l */ +#define FIX_1101_IVAS_SPAR_DEC_SATURATE_WEIGHTS_IN_Q31 /* FhG: BUGFIX2: +ivas_fb_mixer.c: Saturate weight parameters during reformatting in Q31, BUGFIX1 is obsolete */ +#define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SATURATE_WEIGHTS /* FhG: BUGFIX1: Saturate weight parameters during reformatting in Q22, fixes overflow in extract_l */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_HQ_CONSTANTS /* FhG: IMPROVE PRECISION: Uses 1/6 and 1/20 in full-precise Q31 constants instead of Q15 */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_USE_UNIQUE_SHL /* FhG: Uses unique shift amount in each loop iteration */ #define FIX_11_1_IVAS_SPAR_DEC_UPMIXER_SF_RND_COEFFS /* FhG ivas_spar_com.c: Zeroes very small negative coeffs via L_shr_r (was L_shr) */ diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 4daac74df..576f9096c 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -1925,6 +1925,7 @@ void ivas_spar_dec_upmixer_sf_fx( FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ +#ifndef FIX_1101_IVAS_SPAR_DEC_SATURATE_WEIGHTS_IN_Q31 #ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SATURATE_WEIGHTS Word16 tmp = extract_l( L_shr( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 7 ) ); /*Q15*/ cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ @@ -1932,6 +1933,9 @@ void ivas_spar_dec_upmixer_sf_fx( Word32 tmp = L_shl_sat( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31(sat)*/ cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ #endif +#else + cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32(mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ) ); /*q1*/ +#endif /* FIX_1101_IVAS_SPAR_DEC_SATURATE_WEIGHTS_IN_Q31 */ } } @@ -2025,6 +2029,7 @@ void ivas_spar_dec_upmixer_sf_fx( FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ +#ifndef FIX_1101_IVAS_SPAR_DEC_SATURATE_WEIGHTS_IN_Q31 #ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SATURATE_WEIGHTS Word16 tmp = extract_l( L_shr( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 7 ) ); /*Q15*/ cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ @@ -2032,6 +2037,9 @@ void ivas_spar_dec_upmixer_sf_fx( Word32 tmp = L_shl_sat( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31(sat)*/ cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ #endif +#else + cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32(mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ) ); /*q1*/ +#endif /* FIX_1101_IVAS_SPAR_DEC_SATURATE_WEIGHTS_IN_Q31 */ } Out_re_fx = Madd_32_32( Out_re_fx, cldfb_in_ts_re_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ Out_im_fx = Madd_32_32( Out_im_fx, cldfb_in_ts_im_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ -- GitLab From 5d7f116fc04bf4f3c79874abca6604c8c6f7df54 Mon Sep 17 00:00:00 2001 From: Arthur Date: Fri, 17 Jan 2025 19:51:57 +0100 Subject: [PATCH 11/16] fix clang format issues --- lib_com/ivas_fb_mixer.c | 8 ++++---- lib_dec/ivas_spar_decoder.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 4d369a630..c02ad387b 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -1100,13 +1100,13 @@ static Word16 ivas_calculate_abs_fr_fx( move16(); #ifndef FIX_1101_IVAS_SPAR_DEC_SATURATE_WEIGHTS_IN_Q31 Word16 tmp = BASOP_Util_Divide3232_Scale( pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i], sum_over_spar_bands_fx, &exp_diff ); - pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i] = L_min(0x003FFFFF, L_shl( L_deposit_l( tmp ), add( Q7, exp_diff ) ) ); // Q22 + pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i] = L_min( 0x003FFFFF, L_shl( L_deposit_l( tmp ), add( Q7, exp_diff ) ) ); // Q22 #else /* Note: 16-bit division result has bad accuracy for num=denom */ Word32 L_tmp = BASOP_Util_Divide3232_Scale_cadence( pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i], sum_over_spar_bands_fx, &exp_diff ); // Q31 - if (exp_diff != 0) - L_tmp = L_shl_sat(L_tmp, exp_diff); /* convert to Q31 with saturation */ - pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i] = L_tmp; // Q31 + if ( exp_diff != 0 ) + L_tmp = L_shl_sat( L_tmp, exp_diff ); /* convert to Q31 with saturation */ + pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i] = L_tmp; // Q31 #endif move32(); } diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 576f9096c..51ea05b8d 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -1934,7 +1934,7 @@ void ivas_spar_dec_upmixer_sf_fx( cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ #endif #else - cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32(mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ) ); /*q1*/ + cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ) ); /*q1*/ #endif /* FIX_1101_IVAS_SPAR_DEC_SATURATE_WEIGHTS_IN_Q31 */ } } @@ -1956,7 +1956,7 @@ void ivas_spar_dec_upmixer_sf_fx( cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ move32(); #else - cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ + cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ move32(); cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sh_l ); /*Q=6*/ move32(); @@ -2038,7 +2038,7 @@ void ivas_spar_dec_upmixer_sf_fx( cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ #endif #else - cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32(mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ) ); /*q1*/ + cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ) ); /*q1*/ #endif /* FIX_1101_IVAS_SPAR_DEC_SATURATE_WEIGHTS_IN_Q31 */ } Out_re_fx = Madd_32_32( Out_re_fx, cldfb_in_ts_re_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ @@ -2058,7 +2058,7 @@ void ivas_spar_dec_upmixer_sf_fx( cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ move32(); #else - cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ + cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ move32(); cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sh_l ); /*Q=6*/ move32(); -- GitLab From 11e32e27899adf6f55f37f2b4d72e9f9b24fbe4f Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 20 Jan 2025 17:12:27 +0100 Subject: [PATCH 12/16] deactivated macro for SPAR coeffs in Q31 instead of Q22 - fails for SBA rendering --- lib_com/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index e4695a95b..8587a25d7 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -120,7 +120,7 @@ /* Note: each compile switch (FIX_1101_...) is independent from the other ones */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_USE_MADD_ADD_WEIGHTS /* FhG: Defines 1.0f-weight variables, uses Madd operation instead of L_add_sat */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SPLIT_LOOPS /* FhG: Splits single loop with IF-statements into two low-complex loops */ -#define FIX_1101_IVAS_SPAR_DEC_SATURATE_WEIGHTS_IN_Q31 /* FhG: BUGFIX2: +ivas_fb_mixer.c: Saturate weight parameters during reformatting in Q31, BUGFIX1 is obsolete */ +//#define FIX_1101_IVAS_SPAR_DEC_SATURATE_WEIGHTS_IN_Q31 /* FhG: BUGFIX2-FAILURE: +ivas_fb_mixer.c: Saturate weight parameters during reformatting in Q31, BUGFIX1 is obsolete, do not activate, fails with SBA rendering */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SATURATE_WEIGHTS /* FhG: BUGFIX1: Saturate weight parameters during reformatting in Q22, fixes overflow in extract_l */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_HQ_CONSTANTS /* FhG: IMPROVE PRECISION: Uses 1/6 and 1/20 in full-precise Q31 constants instead of Q15 */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_USE_UNIQUE_SHL /* FhG: Uses unique shift amount in each loop iteration */ -- GitLab From d62b512dac1eb5bb2e2c3f2b68a85062f83ff2a1 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Thu, 30 Jan 2025 09:23:33 +0100 Subject: [PATCH 13/16] remove switch FIX_1101_IVAS_SPAR_DEC_SATURATE_WEIGHTS_IN_Q31 --- lib_com/ivas_fb_mixer.c | 8 -------- lib_com/options.h | 1 - lib_dec/ivas_spar_decoder.c | 10 ---------- 3 files changed, 19 deletions(-) diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 7fe747aba..53aee57e3 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -1095,15 +1095,7 @@ static Word16 ivas_calculate_abs_fr_fx( move16(); } -#ifndef FIX_1101_IVAS_SPAR_DEC_SATURATE_WEIGHTS_IN_Q31 pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i] = L_shr( Mult_32_16( pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i], tmp ), exp_diff ); -#else - /* Note: 16-bit division result has bad accuracy for num=denom */ - Word32 L_tmp = BASOP_Util_Divide3232_Scale_cadence( pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i], sum_over_spar_bands_fx, &exp_diff ); // Q31 - if ( exp_diff != 0 ) - L_tmp = L_shl_sat( L_tmp, exp_diff ); /* convert to Q31 with saturation */ - pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i] = L_tmp; // Q31 -#endif move32(); } pFb->fb_bin_to_band.p_spar_start_bands[j] = spar_start; diff --git a/lib_com/options.h b/lib_com/options.h index 80d3d4378..50bdb9878 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -140,7 +140,6 @@ /* Note: each compile switch (FIX_1101_...) is independent from the other ones */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_USE_MADD_ADD_WEIGHTS /* FhG: Defines 1.0f-weight variables, uses Madd operation instead of L_add_sat */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SPLIT_LOOPS /* FhG: Splits single loop with IF-statements into two low-complex loops */ -//#define FIX_1101_IVAS_SPAR_DEC_SATURATE_WEIGHTS_IN_Q31 /* FhG: BUGFIX2-FAILURE: +ivas_fb_mixer.c: Saturate weight parameters during reformatting in Q31, BUGFIX1 is obsolete, do not activate, fails with SBA rendering */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SATURATE_WEIGHTS /* FhG: BUGFIX1: Saturate weight parameters during reformatting in Q22, fixes overflow in extract_l */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_HQ_CONSTANTS /* FhG: IMPROVE PRECISION: Uses 1/6 and 1/20 in full-precise Q31 constants instead of Q15 */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_USE_UNIQUE_SHL /* FhG: Uses unique shift amount in each loop iteration */ diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 68380f381..435fcd0b3 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -1928,21 +1928,15 @@ void ivas_spar_dec_upmixer_sf_fx( FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ -#ifndef FIX_1101_IVAS_SPAR_DEC_SATURATE_WEIGHTS_IN_Q31 #ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SATURATE_WEIGHTS acc = W_mac_32_32( acc, mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ); // q1+ Q23 #else Word32 tmp = L_shl_sat( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31(sat)*/ cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ #endif -#else - cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ) ); /*q1*/ -#endif /* FIX_1101_IVAS_SPAR_DEC_SATURATE_WEIGHTS_IN_Q31 */ } -#ifndef FIX_1101_IVAS_SPAR_DEC_SATURATE_WEIGHTS_IN_Q31 #ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SATURATE_WEIGHTS cldfb_par_fx = W_shl_sat_l( acc, -23 ); // q1 -#endif #endif } @@ -2036,7 +2030,6 @@ void ivas_spar_dec_upmixer_sf_fx( FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ -#ifndef FIX_1101_IVAS_SPAR_DEC_SATURATE_WEIGHTS_IN_Q31 #ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SATURATE_WEIGHTS Word16 tmp = extract_l( L_shr( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 7 ) ); /*Q15*/ cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ @@ -2044,9 +2037,6 @@ void ivas_spar_dec_upmixer_sf_fx( Word32 tmp = L_shl_sat( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31(sat)*/ cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ #endif -#else - cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ) ); /*q1*/ -#endif /* FIX_1101_IVAS_SPAR_DEC_SATURATE_WEIGHTS_IN_Q31 */ } Out_re_fx = Madd_32_32( Out_re_fx, cldfb_in_ts_re_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ Out_im_fx = Madd_32_32( Out_im_fx, cldfb_in_ts_im_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ -- GitLab From 3765f23b71867965a740fa7970e3c099ba7dfb84 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Thu, 30 Jan 2025 09:27:56 +0100 Subject: [PATCH 14/16] fix formatting --- lib_dec/ivas_spar_decoder.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 435fcd0b3..c1e485bc5 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -1957,7 +1957,7 @@ void ivas_spar_dec_upmixer_sf_fx( cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ move32(); #else - cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ + cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ move32(); cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sh_l ); /*Q=6*/ move32(); @@ -2055,7 +2055,7 @@ void ivas_spar_dec_upmixer_sf_fx( cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ move32(); #else - cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ + cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ move32(); cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sh_l ); /*Q=6*/ move32(); -- GitLab From a218f535610a77234668f429a8401f2b306f4faa Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Thu, 30 Jan 2025 10:59:08 +0100 Subject: [PATCH 15/16] remove FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SATURATE_WEIGHTS, propage changes to affected code part to 2nd loop --- lib_com/options.h | 1 - lib_dec/ivas_spar_decoder.c | 19 +++++-------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 50bdb9878..b575414d8 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -140,7 +140,6 @@ /* Note: each compile switch (FIX_1101_...) is independent from the other ones */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_USE_MADD_ADD_WEIGHTS /* FhG: Defines 1.0f-weight variables, uses Madd operation instead of L_add_sat */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SPLIT_LOOPS /* FhG: Splits single loop with IF-statements into two low-complex loops */ -#define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SATURATE_WEIGHTS /* FhG: BUGFIX1: Saturate weight parameters during reformatting in Q22, fixes overflow in extract_l */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_HQ_CONSTANTS /* FhG: IMPROVE PRECISION: Uses 1/6 and 1/20 in full-precise Q31 constants instead of Q15 */ #define FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_USE_UNIQUE_SHL /* FhG: Uses unique shift amount in each loop iteration */ #define FIX_11_1_IVAS_SPAR_DEC_UPMIXER_SF_RND_COEFFS /* FhG ivas_spar_com.c: Zeroes very small negative coeffs via L_shr_r (was L_shr) */ diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index c1e485bc5..a7ce5aad8 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -1928,16 +1928,9 @@ void ivas_spar_dec_upmixer_sf_fx( FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ -#ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SATURATE_WEIGHTS acc = W_mac_32_32( acc, mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ); // q1+ Q23 -#else - Word32 tmp = L_shl_sat( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31(sat)*/ - cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ -#endif } -#ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SATURATE_WEIGHTS cldfb_par_fx = W_shl_sat_l( acc, -23 ); // q1 -#endif } out_re_fx[out_ch] = Madd_32_32( out_re_fx[out_ch], cldfb_in_ts_re_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ @@ -2025,19 +2018,17 @@ void ivas_spar_dec_upmixer_sf_fx( { IF( b_skip_mat[out_ch][in_ch] == 0 ) { + Word64 acc = 0; + move64(); + cldfb_par_fx = 0; move32(); FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ -#ifndef FIX_1101_IVAS_SPAR_DEC_UPMIXER_SF_SATURATE_WEIGHTS - Word16 tmp = extract_l( L_shr( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 7 ) ); /*Q15*/ - cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ -#else - Word32 tmp = L_shl_sat( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 9 ); /*Q22 -> Q31(sat)*/ - cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ -#endif + acc = W_mac_32_32( acc, mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ); // q1+ Q23 } + cldfb_par_fx = W_shl_sat_l( acc, -23 ); // q1 Out_re_fx = Madd_32_32( Out_re_fx, cldfb_in_ts_re_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ Out_im_fx = Madd_32_32( Out_im_fx, cldfb_in_ts_im_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ } -- GitLab From 55b91ae27fa39ca52b975518c76da04e36596df0 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Thu, 30 Jan 2025 11:01:13 +0100 Subject: [PATCH 16/16] formatting --- lib_dec/ivas_spar_decoder.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index a7ce5aad8..0bdc62756 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -1950,7 +1950,7 @@ void ivas_spar_dec_upmixer_sf_fx( cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ move32(); #else - cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ + cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ move32(); cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sh_l ); /*Q=6*/ move32(); @@ -2028,7 +2028,7 @@ void ivas_spar_dec_upmixer_sf_fx( /* accumulate contributions from all SPAR bands */ acc = W_mac_32_32( acc, mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ); // q1+ Q23 } - cldfb_par_fx = W_shl_sat_l( acc, -23 ); // q1 + cldfb_par_fx = W_shl_sat_l( acc, -23 ); // q1 Out_re_fx = Madd_32_32( Out_re_fx, cldfb_in_ts_re_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ Out_im_fx = Madd_32_32( Out_im_fx, cldfb_in_ts_im_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ } @@ -2046,7 +2046,7 @@ void ivas_spar_dec_upmixer_sf_fx( cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ move32(); #else - cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ + cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/ move32(); cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sh_l ); /*Q=6*/ move32(); -- GitLab