From 7f93de8fce3737f062b5e3c7c11d5baaabe05c28 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Wed, 20 May 2026 11:35:40 +0200 Subject: [PATCH 1/3] added macro and code for HARMONIZE_2597_ShapeSpectrum --- lib_com/options.h | 1 + lib_enc/cod_tcx_fx.c | 55 ++++++++++++++++++++++++++++++--- lib_enc/core_enc_2div_fx.c | 29 ++++++++++++++++- lib_enc/ivas_mdct_core_enc_fx.c | 8 +++++ lib_enc/ivas_tcx_core_enc_fx.c | 4 +++ lib_enc/prot_fx_enc.h | 24 ++++++++------ 6 files changed, 107 insertions(+), 14 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index cd569d12b..6c8cf7af4 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -112,6 +112,7 @@ #define HARMONIZE_2553_TonalConceal_Init /* FhG: Harmonize TonalMDCTConceal_Init with its ivas derivate */ #define HARMONIZE_2553_TonalConceal_SaveFreqSignal /* FhG: Harmonize TonalConceal_SaveFreqSignal with its ivas derivate */ #define HARMONIZE_2553_TonalConceal_SaveTimeSignal /* FhG: Harmonize TonalConceal_SaveTimeSignal with its ivas derivate */ +#define HARMONIZE_2597_ShapeSpectrum /* FhG: Harmonize ShapeSpectrum with its ivas derivate */ /* #################### End BE switches ################################## */ diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index d043aeb49..88eb64451 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -221,6 +221,7 @@ void TNSAnalysis_fx( } } +#ifndef HARMONIZE_2597_ShapeSpectrum void ShapeSpectrum_fx( TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 A[], /* input: quantized coefficients NxAz_q[M+1] Q = 14 - norm(A[0])*/ @@ -460,18 +461,24 @@ void ShapeSpectrum_fx( PsychAdaptLowFreqEmph_fx( spectrum, gainlpc, gainlpc_e ); } } +#endif + +#ifdef HARMONIZE_2597_ShapeSpectrum +void ShapeSpectrum_fx( +#else void ShapeSpectrum_ivas_fx( +#endif TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 A[], /* input: quantized coefficients NxAz_q[M+1], Q = 14 - norm(A[0]) */ Word16 gainlpc[], /* output: MDCT gains for the previous frame Q(15-gainlpc_e)*/ Word16 gainlpc_e[], /* output: MDCT gains exponents */ Word16 L_frame_glob, /* input: frame length */ Word16 L_spec, - Word32 spectrum[], /* i/o: MDCT spectrum Q(31-spectrum_e) */ - Word16 *spectrum_e, /* i/o: MDCT spectrum exponent */ - Word8 pfUseTns, /* output: Flag indicating if TNS is used */ + Word32 spectrum[], /* i/o: MDCT spectrum */ + Word16 *spectrum_e, /* i/o: MDCT spectrum exponent */ + Word8 pfUseTns, /* output: Flag indicating if TNS is used */ Encoder_State *st, - Word32 *scf /* Q16 */ + Word32 *scf /* Q16 */ ) { Word16 L_frame; @@ -541,7 +548,20 @@ void ShapeSpectrum_ivas_fx( test(); test(); test(); +#ifdef HARMONIZE_2597_ShapeSpectrum + Word32 condition; + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + condition = ( EQ_32( total_brate, ACELP_9k60 ) && EQ_16( st->bwidth, SWB ) ) || ( EQ_32( total_brate, ACELP_13k20 ) && EQ_16( st->bwidth, SWB ) ); + } + ELSE + { + condition = ( LE_32( total_brate, ACELP_13k20 ) || ( LE_32( st->element_brate, IVAS_16k4 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( st->bwidth, SWB ); + } + IF( condition ) +#else IF( ( LE_32( total_brate, ACELP_13k20 ) || ( LE_32( st->element_brate, IVAS_16k4 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( st->bwidth, SWB ) ) +#endif { max_low_pre = 0; move32(); @@ -619,7 +639,19 @@ void ShapeSpectrum_ivas_fx( test(); test(); test(); +#ifdef HARMONIZE_2597_ShapeSpectrum + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + condition = ( EQ_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->bwidth, SWB ) ) || ( EQ_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->bwidth, SWB ) ); + } + ELSE + { + condition = ( LE_32( total_brate, ACELP_13k20 ) || ( LE_32( st->element_brate, IVAS_16k4 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( st->bwidth, SWB ); + } + IF( condition ) +#else IF( ( LE_32( total_brate, ACELP_13k20 ) || ( LE_32( st->element_brate, IVAS_16k4 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( st->bwidth, SWB ) ) +#endif { Word16 sf_width; Word16 dist_low, dist_high; @@ -724,7 +756,11 @@ void ShapeSpectrum_ivas_fx( { Word16 fac; fac = divide3232( max_low2, max_high ); +#ifdef HARMONIZE_2597_ShapeSpectrum + IF( GE_16( norm_s( fac ), max_fac_s ) || EQ_16( st->element_mode, EVS_MONO ) ) +#else IF( GE_16( norm_s( fac ), max_fac_s ) ) +#endif { fac = shl( mult_r( fac, max_fac_m ), max_fac_s ); FOR( i = 0; i < ( L_spec - L_frame ); i++ ) @@ -3836,12 +3872,23 @@ void coder_tcx_fx( ProcessIGF_fx( st, 0, spectrum, &q_spectrum, NULL, 0, powerSpec, &powerSpec_e, 1, 0, 0, 0 ); } +#ifdef HARMONIZE_2597_ShapeSpectrum + ShapeSpectrum_fx( hTcxCfg, A, gainlpc, gainlpc_e, + L_frame_glob, + L_spec, + spectrum, + 0, + hTcxEnc->fUseTns[0], + st, + 0 ); +#else ShapeSpectrum_fx( hTcxCfg, A, gainlpc, gainlpc_e, L_frame_glob, L_spec, spectrum, hTcxEnc->fUseTns[0], st ); +#endif if ( st->igf ) { nb_bits = sub( nb_bits, st->hIGFEnc->infoTotalBitsPerFrameWritten ); diff --git a/lib_enc/core_enc_2div_fx.c b/lib_enc/core_enc_2div_fx.c index 3012bb094..1ce69cce1 100644 --- a/lib_enc/core_enc_2div_fx.c +++ b/lib_enc/core_enc_2div_fx.c @@ -171,6 +171,19 @@ void core_encode_twodiv_fx( } /* Shape spectrum */ +#ifdef HARMONIZE_2597_ShapeSpectrum + ShapeSpectrum_fx( st->hTcxCfg, + A_q, + gainlpc[n], + gainlpc_e[n], + shr( st->L_frame, 1 ), + shr( st->hTcxCfg->tcx_coded_lines, 1 ), + spectrum[n], + 0, + hTcxEnc->fUseTns[n], + st, + 0 ); +#else ShapeSpectrum_fx( st->hTcxCfg, A_q, gainlpc[n], @@ -180,6 +193,7 @@ void core_encode_twodiv_fx( spectrum[n], hTcxEnc->fUseTns[n], st ); +#endif st->last_core = st->core; move16(); @@ -266,7 +280,19 @@ void core_encode_twodiv_fx( E_LPC_f_lsp_a_conversion( lsp_q, A_q, M ); - +#ifdef HARMONIZE_2597_ShapeSpectrum + ShapeSpectrum_fx( st->hTcxCfg, + A_q, + gainlpc[0], + gainlpc_e[0], + st->L_frame, + st->hTcxCfg->tcx_coded_lines, + spectrum[0], + 0, + hTcxEnc->fUseTns[0], + st, + 0 ); +#else ShapeSpectrum_fx( st->hTcxCfg, A_q, gainlpc[0], @@ -276,6 +302,7 @@ void core_encode_twodiv_fx( spectrum[0], hTcxEnc->fUseTns[0], st ); +#endif /*_DIFF_FLOAT_FIX_EVS_IVAS -> The line below is present in float */ // hTcxEnc->measuredBwRatio = 0x4000; diff --git a/lib_enc/ivas_mdct_core_enc_fx.c b/lib_enc/ivas_mdct_core_enc_fx.c index bae3e6f55..e5e0ab311 100644 --- a/lib_enc/ivas_mdct_core_enc_fx.c +++ b/lib_enc/ivas_mdct_core_enc_fx.c @@ -2125,7 +2125,11 @@ void ivas_mdct_core_whitening_enc_fx( move16(); /* Shape spectrum */ +#ifdef HARMONIZE_2597_ShapeSpectrum + ShapeSpectrum_fx( st->hTcxCfg, A_q_fx[ch][n], NULL, NULL, L_subframe, tcx_subframe_coded_lines, st->hTcxEnc->spectrum_fx[n], &st->hTcxEnc->spectrum_e[n], st->hTcxEnc->fUseTns[n], st, scf_q_fx[ch][n] ); +#else ShapeSpectrum_ivas_fx( st->hTcxCfg, A_q_fx[ch][n], NULL, NULL, L_subframe, tcx_subframe_coded_lines, st->hTcxEnc->spectrum_fx[n], &st->hTcxEnc->spectrum_e[n], st->hTcxEnc->fUseTns[n], st, scf_q_fx[ch][n] ); +#endif Scale_sig32( st->hTcxEnc->spectrum_fx[n] + L_subframe, sub( L_subframeTCX, L_subframe ), sub( exp_tmp, st->hTcxEnc->spectrum_e[n] ) ); } @@ -2265,7 +2269,11 @@ void ivas_mdct_core_whitening_enc_fx( move16(); /* Shape spectrum */ +#ifdef HARMONIZE_2597_ShapeSpectrum + ShapeSpectrum_fx( st->hTcxCfg, A_q_fx[ch][n], NULL, NULL, L_subframe, tcx_subframe_coded_lines, mdst_spectrum_fx[ch][n], &mdst_spectrum_e[ch][n], st->hTcxEnc->fUseTns[n], st, scf_q_fx[ch][n] ); +#else ShapeSpectrum_ivas_fx( st->hTcxCfg, A_q_fx[ch][n], NULL, NULL, L_subframe, tcx_subframe_coded_lines, mdst_spectrum_fx[ch][n], &mdst_spectrum_e[ch][n], st->hTcxEnc->fUseTns[n], st, scf_q_fx[ch][n] ); +#endif Scale_sig32( mdst_spectrum_fx[ch][n] + L_subframe, sub( L_subframeTCX, L_subframe ), sub( exp_tmp, mdst_spectrum_e[ch][n] ) ); } diff --git a/lib_enc/ivas_tcx_core_enc_fx.c b/lib_enc/ivas_tcx_core_enc_fx.c index 65f097eaa..98424d544 100644 --- a/lib_enc/ivas_tcx_core_enc_fx.c +++ b/lib_enc/ivas_tcx_core_enc_fx.c @@ -531,7 +531,11 @@ void stereo_tcx_core_enc( bitsAvailable = sub( bitsAvailable, nbits_lpc[n] ); /* Shape spectrum */ +#ifdef HARMONIZE_2597_ShapeSpectrum + ShapeSpectrum_fx( st->hTcxCfg, A_q_fx, gainlpc_fx[n], gainlpc_e[n], st->L_frame / n_subframes, st->hTcxCfg->tcx_coded_lines / n_subframes, hTcxEnc->spectrum_fx[n], &hTcxEnc->spectrum_e[n], hTcxEnc->fUseTns[n], st, NULL ); +#else ShapeSpectrum_ivas_fx( st->hTcxCfg, A_q_fx, gainlpc_fx[n], gainlpc_e[n], st->L_frame / n_subframes, st->hTcxCfg->tcx_coded_lines / n_subframes, hTcxEnc->spectrum_fx[n], &hTcxEnc->spectrum_e[n], hTcxEnc->fUseTns[n], st, NULL ); +#endif st->last_core = st->core; move16(); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 046f15211..036fa6da3 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2063,6 +2063,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( Word16 *Q_new, Word16 *q_win ); +#ifndef HARMONIZE_2597_ShapeSpectrum void ShapeSpectrum_fx( TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 A[], /* i : quantized coefficients NxAz_q[M+1] */ @@ -2073,19 +2074,24 @@ void ShapeSpectrum_fx( Word32 spectrum[], /* i/o: MDCT spectrum */ Word8 pfUseTns, /* o : Flag indicating if TNS is used */ Encoder_State *st ); +#endif +#ifdef HARMONIZE_2597_ShapeSpectrum +void ShapeSpectrum_fx( +#else void ShapeSpectrum_ivas_fx( - TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ - Word16 A[], /* i : quantized coefficients NxAz_q[M+1], Q = 14 - norm(A[0])*/ - Word16 gainlpc[], /* o : MDCT gains for the previous frame */ - Word16 gainlpc_e[], /* o : MDCT gains exponents */ - Word16 L_frame_glob, /* i : frame length */ +#endif + TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ + Word16 A[], /* input: quantized coefficients NxAz_q[M+1], Q = 14 - norm(A[0]) */ + Word16 gainlpc[], /* output: MDCT gains for the previous frame Q(15-gainlpc_e)*/ + Word16 gainlpc_e[], /* output: MDCT gains exponents */ + Word16 L_frame_glob, /* input: frame length */ Word16 L_spec, - Word32 spectrum[], /* i/o: MDCT spectrum */ - Word16 *spectrum_e, /* i/o: MDCT spectrum exponent */ - Word8 pfUseTns, /* output: Flag indicating if TNS is used */ + Word32 spectrum[], /* i/o: MDCT spectrum */ + Word16 * spectrum_e, /* i/o: MDCT spectrum exponent */ + Word8 pfUseTns, /* output: Flag indicating if TNS is used */ Encoder_State *st, - Word32 *scf /* Q16 */ + Word32 *scf /* Q16 */ ); void QuantizeSpectrum_fx( -- GitLab From 3af8e94d17c083ee1f79270f48d993a94fcbf28a Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Wed, 20 May 2026 11:49:32 +0200 Subject: [PATCH 2/3] clang patch --- lib_enc/cod_tcx_fx.c | 8 ++++---- lib_enc/prot_fx_enc.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 88eb64451..2945f81a1 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -474,11 +474,11 @@ void ShapeSpectrum_ivas_fx( Word16 gainlpc_e[], /* output: MDCT gains exponents */ Word16 L_frame_glob, /* input: frame length */ Word16 L_spec, - Word32 spectrum[], /* i/o: MDCT spectrum */ - Word16 *spectrum_e, /* i/o: MDCT spectrum exponent */ - Word8 pfUseTns, /* output: Flag indicating if TNS is used */ + Word32 spectrum[], /* i/o: MDCT spectrum */ + Word16 *spectrum_e, /* i/o: MDCT spectrum exponent */ + Word8 pfUseTns, /* output: Flag indicating if TNS is used */ Encoder_State *st, - Word32 *scf /* Q16 */ + Word32 *scf /* Q16 */ ) { Word16 L_frame; diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 036fa6da3..c85f0b393 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2087,11 +2087,11 @@ void ShapeSpectrum_ivas_fx( Word16 gainlpc_e[], /* output: MDCT gains exponents */ Word16 L_frame_glob, /* input: frame length */ Word16 L_spec, - Word32 spectrum[], /* i/o: MDCT spectrum */ - Word16 * spectrum_e, /* i/o: MDCT spectrum exponent */ - Word8 pfUseTns, /* output: Flag indicating if TNS is used */ + Word32 spectrum[], /* i/o: MDCT spectrum */ + Word16 *spectrum_e, /* i/o: MDCT spectrum exponent */ + Word8 pfUseTns, /* output: Flag indicating if TNS is used */ Encoder_State *st, - Word32 *scf /* Q16 */ + Word32 *scf /* Q16 */ ); void QuantizeSpectrum_fx( -- GitLab From d9299cc95f59df060885417c1a4a6402a1acd7e8 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Thu, 28 May 2026 14:38:05 +0200 Subject: [PATCH 3/3] align conditions to float --- lib_enc/cod_tcx_fx.c | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 127499730..dd98be924 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -548,20 +548,7 @@ void ShapeSpectrum_ivas_fx( test(); test(); test(); -#ifdef HARMONIZE_2597_ShapeSpectrum - Word32 condition; - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - condition = ( EQ_32( total_brate, ACELP_9k60 ) && EQ_16( st->bwidth, SWB ) ) || ( EQ_32( total_brate, ACELP_13k20 ) && EQ_16( st->bwidth, SWB ) ); - } - ELSE - { - condition = ( LE_32( total_brate, ACELP_13k20 ) || ( LE_32( st->element_brate, IVAS_16k4 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( st->bwidth, SWB ); - } - IF( condition ) -#else IF( ( LE_32( total_brate, ACELP_13k20 ) || ( LE_32( st->element_brate, IVAS_16k4 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( st->bwidth, SWB ) ) -#endif { max_low_pre = 0; move32(); @@ -639,19 +626,7 @@ void ShapeSpectrum_ivas_fx( test(); test(); test(); -#ifdef HARMONIZE_2597_ShapeSpectrum - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - condition = ( EQ_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->bwidth, SWB ) ) || ( EQ_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->bwidth, SWB ) ); - } - ELSE - { - condition = ( LE_32( total_brate, ACELP_13k20 ) || ( LE_32( st->element_brate, IVAS_16k4 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( st->bwidth, SWB ); - } - IF( condition ) -#else IF( ( LE_32( total_brate, ACELP_13k20 ) || ( LE_32( st->element_brate, IVAS_16k4 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( st->bwidth, SWB ) ) -#endif { Word16 sf_width; Word16 dist_low, dist_high; -- GitLab