From 3327a86fcdcaeb4fdfe9155cabe0351a572e9891 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 21 May 2026 11:37:51 +0200 Subject: [PATCH 01/14] add macro and code for HARMONIZE_2598_tcx_arith_decode_envelope --- lib_com/options.h | 2 + lib_com/prot_fx.h | 26 +++- lib_dec/arith_coder_dec_fx.c | 226 ++++++++++++++++++++++------------- lib_dec/dec_tcx_fx.c | 27 +++++ 4 files changed, 197 insertions(+), 84 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 27e64a41c..b28b6315f 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -92,6 +92,8 @@ #define NONBE_FIX_ISSUE_2206_AVOID_OVERFLOW_MSVQ_Interpol_Tran_fx /* FhG: Fix saturation crash in MSVQ_Interpol_Tran_fx() */ #define NONBE_FIX_ISSUE_2206_SWB_EXPERIMENT_FIX_2527 /* Fix crash from issue #2527 */ #define FIX_FLOAT_1539_G192_FORMAT_SWITCH /* VA/Nokia: reintroduce format switching for g192 bitstreams */ +#define HARMONIZE_2598_tcx_arith_decode_envelope /* FhG: harmonize tcx_arith_decode_envelope between EVS and IVAS versions */ + /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 196a37583..523bc504d 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -7997,6 +7997,7 @@ void decoder_tcx_post_fx( Word16 *A, Word16 bfi ); +#ifndef HARMONIZE_2598_tcx_arith_decode_envelope void tcx_arith_decode_envelope_fx( Word32 q_spectrum[], /* o: quantised MDCT coefficients Q31-e */ Word16 *q_spectrum_e, /* o: MDCT exponent Q0 */ @@ -8014,6 +8015,7 @@ void tcx_arith_decode_envelope_fx( Word16 *nf_seed, /* o: noise filling seed Q0 */ Word16 low_complexity /* i: low-complexity flag Q0 */ ); +#endif void tcx_decoder_memory_update( Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer : Q0 */ @@ -9958,9 +9960,28 @@ void tcx_arith_render_envelope_ivas_fx( Word32 env[] /* o : shaped signal envelope Q16*/ ); +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope +void tcx_arith_decode_envelope_fx( + Decoder_State *st, + /* i/o: coder state */ /*EVS: move argument 5->1 */ + Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */ + Word16 *q_spectrum_e, /* o : MDCT exponent */ + const Word16 L_frame, /* i : frame or MDCT length */ + Word16 L_spec, /* i : length w/o BW limitation */ + const Word16 A_ind[], /* i : quantised LPC coefficients */ + const Word16 target_bits, /* i : number of available bits */ + Word16 prm[], /* i : bitstream parameters */ + const Word16 use_hm, /* i : use HM in current frame? */ + Word16 prm_hm[], /* i : HM parameter area */ + Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/ + Word16 *arith_bits, /* o : bits used for ari. coding */ + Word16 *signaling_bits, /* o : bits used for signaling */ + Word16 *nf_seed, /* o : noise filling seed Q0 */ + const Word16 low_complexity /* i : low-complexity flag */ +#else void tcx_arith_decode_envelope_ivas_fx( Decoder_State *st, /* i/o: coder state */ - Word32 q_spectrum[], /* o : quantised MDCT coefficients */ + Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */ Word16 *q_spectrum_e, /* o : MDCT exponent */ const Word16 L_frame, /* i : frame or MDCT length */ Word16 L_spec, /* i : length w/o BW limitation */ @@ -9968,11 +9989,12 @@ void tcx_arith_decode_envelope_ivas_fx( const Word16 target_bits, /* i : number of available bits */ Word16 prm[], /* i : bitstream parameters */ const Word16 use_hm, /* i : use HM in current frame? */ - const Word16 prm_hm[], /* i : HM parameter area */ + Word16 prm_hm[], /* i : HM parameter area */ Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/ Word16 *arith_bits, /* o : bits used for ari. coding */ Word16 *signaling_bits, /* o : bits used for signaling */ const Word16 low_complexity /* i : low-complexity flag */ +#endif ); void UnmapIndex_fx( diff --git a/lib_dec/arith_coder_dec_fx.c b/lib_dec/arith_coder_dec_fx.c index 3ac4963c0..789234c57 100644 --- a/lib_dec/arith_coder_dec_fx.c +++ b/lib_dec/arith_coder_dec_fx.c @@ -90,6 +90,7 @@ static Word16 tcx_arith_decode_fx( return bp; } +#ifndef HARMONIZE_2598_tcx_arith_decode_envelope void tcx_arith_decode_envelope_fx( Word32 q_spectrum[], /* o : quantised MDCT coefficients Q31-e */ Word16 *q_spectrum_e, /* o : MDCT exponent Q0 */ @@ -209,6 +210,7 @@ void tcx_arith_decode_envelope_fx( set32_fx( q_spectrum + L_spec, 0, sub( L_frame, L_spec ) ); } +#endif /*-------------------------------------------------------* * tcx_arith_decode() @@ -293,6 +295,25 @@ static Word16 tcx_arith_decode_ivas_fx( * *-------------------------------------------------------*/ +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope +void tcx_arith_decode_envelope_fx( + Decoder_State *st, + /* i/o: coder state */ /*EVS: move argument 5->1 */ + Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */ + Word16 *q_spectrum_e, /* o : MDCT exponent */ + const Word16 L_frame, /* i : frame or MDCT length */ + Word16 L_spec, /* i : length w/o BW limitation */ + const Word16 A_ind[], /* i : quantised LPC coefficients */ + const Word16 target_bits, /* i : number of available bits */ + Word16 prm[], /* i : bitstream parameters */ + const Word16 use_hm, /* i : use HM in current frame? */ + Word16 prm_hm[], /* i : HM parameter area */ + Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/ + Word16 *arith_bits, /* o : bits used for ari. coding */ + Word16 *signaling_bits, /* o : bits used for signaling */ + Word16 *nf_seed, /* o : noise filling seed Q0 */ + const Word16 low_complexity /* i : low-complexity flag */ +#else void tcx_arith_decode_envelope_ivas_fx( Decoder_State *st, /* i/o: coder state */ Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */ @@ -308,106 +329,147 @@ void tcx_arith_decode_envelope_ivas_fx( Word16 *arith_bits, /* o : bits used for ari. coding */ Word16 *signaling_bits, /* o : bits used for signaling */ const Word16 low_complexity /* i : low-complexity flag */ +#endif ) -{ - Word32 env[N_MAX_ARI]; /* unscaled envelope (Q16) */ - Word16 *envelope; /* scaled envelope (Q15-e) */ - Word16 envelope_e; - Word16 L_spec_core; - TCX_CONFIG_HANDLE hTcxCfg; - TCX_DEC_HANDLE hTcxDec; - Word16 gamma_w, gamma_uw; - Word16 hm_bits; - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( GT_16( L_spec, N_MAX_ARI ) || ( ( st->element_mode == EVS_MONO ) && GT_16( target_bits, ( ACELP_13k20 / FRAMES_PER_SEC ) ) ) || - ( EQ_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE / FRAMES_PER_SEC ) ) ) ) || - ( GT_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE_CPE / FRAMES_PER_SEC ) ) ) ) || - ( target_bits <= 0 ) ) { - /* this could happen in case of bit errors */ - st->BER_detect = 1; - move16(); - L_spec = N_MAX_ARI; - move16(); - *signaling_bits = 0; - move16(); - *arith_bits = 0; - move16(); - set32_fx( q_spectrum, 0, L_frame ); + Word32 env[N_MAX_ARI]; /* unscaled envelope (Q16) */ + Word16 *envelope; /* scaled envelope (Q15-e) */ + Word16 envelope_e; + Word16 L_spec_core; + TCX_CONFIG_HANDLE hTcxCfg; + TCX_DEC_HANDLE hTcxDec; + Word16 gamma_w, gamma_uw; + Word16 hm_bits; + + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( GT_16( L_spec, N_MAX_ARI ) || ( EQ_16( st->element_mode, EVS_MONO ) && GT_16( target_bits, ( ACELP_13k20 / FRAMES_PER_SEC ) ) ) || + ( EQ_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE / FRAMES_PER_SEC ) ) ) ) || + ( GT_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE_CPE / FRAMES_PER_SEC ) ) ) ) || + ( target_bits <= 0 ) ) + { + /* this could happen in case of bit errors */ + st->BER_detect = 1; + move16(); + L_spec = N_MAX_ARI; + move16(); + *signaling_bits = 0; + move16(); + *arith_bits = 0; + move16(); + set32_fx( q_spectrum, 0, L_frame ); - return; - } + return; + } - hTcxCfg = st->hTcxCfg; - hTcxDec = st->hTcxDec; - *signaling_bits = 0; - move16(); + hTcxCfg = st->hTcxCfg; + hTcxDec = st->hTcxDec; + *signaling_bits = 0; + move16(); - assert( hTcxDec->enableTcxLpc ); - gamma_w = MAX16B; - move16(); - gamma_uw = st->inv_gamma; - move16(); + assert( hTcxDec->enableTcxLpc ); + gamma_w = MAX16B; + move16(); + gamma_uw = st->inv_gamma; + move16(); +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + tcx_arith_render_envelope( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); + } + ELSE + { +#endif + tcx_arith_render_envelope( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope + } +#endif + tcx_arith_render_envelope_ivas_fx( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); - tcx_arith_render_envelope_ivas_fx( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); - IF( use_hm != 0 ) - { - IF( prm_hm[0] != 0 ) + IF( use_hm != 0 ) { - tcx_hm_decode( L_spec, env, target_bits, st->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); - - IF( hm_bits < 0 ) + IF( prm_hm[0] != 0 ) { - st->BER_detect = 1; - move16(); - *signaling_bits = 0; - move16(); - *arith_bits = 0; +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + tcx_hm_decode( L_spec, env, target_bits, hTcxCfg->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); + } + ELSE + { +#endif + tcx_hm_decode( L_spec, env, target_bits, st->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope + } +#endif + + IF( hm_bits < 0 ) + { + st->BER_detect = 1; + move16(); + *signaling_bits = 0; + move16(); + *arith_bits = 0; + move16(); + set32_fx( q_spectrum, 0, L_frame ); + + return; + } + } + ELSE + { + hm_bits = 1; move16(); - set32_fx( q_spectrum, 0, L_frame ); - - return; } + *signaling_bits = add( *signaling_bits, hm_bits ); + move16(); } - ELSE +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope + IF( EQ_16( st->element_mode, EVS_MONO ) && ( use_hm == 0 ) ) { - hm_bits = 1; + prm_hm[0] = 0; /* just to be sure */ move16(); } - *signaling_bits = add( *signaling_bits, hm_bits ); +#endif + + L_spec_core = L_spec; move16(); - } + IF( st->igf ) + { + L_spec_core = s_min( L_spec_core, st->hIGFDec->infoIGFStartLine ); + } - L_spec_core = L_spec; - move16(); - IF( st->igf ) - { - L_spec_core = s_min( L_spec_core, st->hIGFDec->infoIGFStartLine ); - } + envelope = (Word16 *) env; + tcx_arith_scale_envelope( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e ); +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope + IF( EQ_16( st->element_mode, EVS_MONO ) && ( use_hm == 0 ) ) + { + *arith_bits = tcx_arith_decode_fx( L_spec, envelope, envelope_e, target_bits, prm, q_spectrum, q_spectrum_e, nf_seed ); + } + ELSE + { +#endif + *arith_bits = tcx_arith_decode_ivas_fx( L_spec, envelope, envelope_e, target_bits, prm, q_spectrum, q_spectrum_e ); +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope + } +#endif + move16(); - envelope = (Word16 *) env; - tcx_arith_scale_envelope( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e ); + /* safety check in case of bit errors */ + IF( *arith_bits < 0 ) + { + st->BER_detect = 1; + move16(); + set32_fx( q_spectrum, 0, L_frame ); + } - *arith_bits = tcx_arith_decode_ivas_fx( L_spec, envelope, envelope_e, target_bits, prm, q_spectrum, q_spectrum_e ); - move16(); + set32_fx( q_spectrum + L_spec, 0, sub( L_frame, L_spec ) ); - /* safety check in case of bit errors */ - IF( *arith_bits < 0 ) - { - st->BER_detect = 1; - move16(); - set32_fx( q_spectrum, 0, L_frame ); + return; } - - set32_fx( q_spectrum + L_spec, 0, sub( L_frame, L_spec ) ); - - return; -} diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index db29982a5..dbe1f50b2 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -356,6 +356,24 @@ void decoder_tcx_fx( move16(); } +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope + tcx_arith_decode_envelope_fx( + st, + x, &x_e, + L_frame, + L_spec, + Aind, + *prm_target, + prm_sqQ, + tmp8, + prm_hm, /* HM parameter area */ + hTcxDec->tcx_hm_LtpPitchLag, + &arith_bits, + &signaling_bits, + &nf_seed, + shr( st->bwidth, 1 ) /* equivalent to: (st->bwidth > WB)?1:0 */ + ); +#else tcx_arith_decode_envelope_fx( x, &x_e, L_frame, @@ -372,6 +390,7 @@ void decoder_tcx_fx( &nf_seed, shr( st->bwidth, 1 ) /* equivalent to: (st->bwidth > WB)?1:0 */ ); +#endif hTcxDec->resQBits[frame_cnt] = sub( *prm_target, arith_bits ); move16(); @@ -4252,11 +4271,19 @@ void decoder_tcx_invQ_fx( IF( GT_32( st->bwidth, WB ) ) { +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope + tcx_arith_decode_envelope_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, 0, 1 ); +#else tcx_arith_decode_envelope_ivas_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, 1 ); +#endif } ELSE { +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope + tcx_arith_decode_envelope_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, 0, 0 ); +#else tcx_arith_decode_envelope_ivas_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, 0 ); +#endif } hTcxDec->resQBits[frame_cnt] = sub( *prm_target, arith_bits ); -- GitLab From 0141007227cde024b02dbabbe60b36673b24aa71 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 21 May 2026 11:47:33 +0200 Subject: [PATCH 02/14] clang patch --- lib_com/prot_fx.h | 32 ++--- lib_dec/arith_coder_dec_fx.c | 220 +++++++++++++++++------------------ 2 files changed, 126 insertions(+), 126 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 523bc504d..95e61f678 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9963,21 +9963,21 @@ void tcx_arith_render_envelope_ivas_fx( #ifdef HARMONIZE_2598_tcx_arith_decode_envelope void tcx_arith_decode_envelope_fx( Decoder_State *st, - /* i/o: coder state */ /*EVS: move argument 5->1 */ - Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */ - Word16 *q_spectrum_e, /* o : MDCT exponent */ - const Word16 L_frame, /* i : frame or MDCT length */ - Word16 L_spec, /* i : length w/o BW limitation */ - const Word16 A_ind[], /* i : quantised LPC coefficients */ - const Word16 target_bits, /* i : number of available bits */ - Word16 prm[], /* i : bitstream parameters */ - const Word16 use_hm, /* i : use HM in current frame? */ - Word16 prm_hm[], /* i : HM parameter area */ - Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/ - Word16 *arith_bits, /* o : bits used for ari. coding */ - Word16 *signaling_bits, /* o : bits used for signaling */ - Word16 *nf_seed, /* o : noise filling seed Q0 */ - const Word16 low_complexity /* i : low-complexity flag */ + /* i/o: coder state */ /*EVS: move argument 5->1 */ + Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */ + Word16 *q_spectrum_e, /* o : MDCT exponent */ + const Word16 L_frame, /* i : frame or MDCT length */ + Word16 L_spec, /* i : length w/o BW limitation */ + const Word16 A_ind[], /* i : quantised LPC coefficients */ + const Word16 target_bits, /* i : number of available bits */ + Word16 prm[], /* i : bitstream parameters */ + const Word16 use_hm, /* i : use HM in current frame? */ + Word16 prm_hm[], /* i : HM parameter area */ + Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/ + Word16 *arith_bits, /* o : bits used for ari. coding */ + Word16 *signaling_bits, /* o : bits used for signaling */ + Word16 *nf_seed, /* o : noise filling seed Q0 */ + const Word16 low_complexity /* i : low-complexity flag */ #else void tcx_arith_decode_envelope_ivas_fx( Decoder_State *st, /* i/o: coder state */ @@ -9989,7 +9989,7 @@ void tcx_arith_decode_envelope_ivas_fx( const Word16 target_bits, /* i : number of available bits */ Word16 prm[], /* i : bitstream parameters */ const Word16 use_hm, /* i : use HM in current frame? */ - Word16 prm_hm[], /* i : HM parameter area */ + Word16 prm_hm[], /* i : HM parameter area */ Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/ Word16 *arith_bits, /* o : bits used for ari. coding */ Word16 *signaling_bits, /* o : bits used for signaling */ diff --git a/lib_dec/arith_coder_dec_fx.c b/lib_dec/arith_coder_dec_fx.c index 789234c57..92b836dd9 100644 --- a/lib_dec/arith_coder_dec_fx.c +++ b/lib_dec/arith_coder_dec_fx.c @@ -307,7 +307,7 @@ void tcx_arith_decode_envelope_fx( const Word16 target_bits, /* i : number of available bits */ Word16 prm[], /* i : bitstream parameters */ const Word16 use_hm, /* i : use HM in current frame? */ - Word16 prm_hm[], /* i : HM parameter area */ + Word16 prm_hm[], /* i : HM parameter area */ Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/ Word16 *arith_bits, /* o : bits used for ari. coding */ Word16 *signaling_bits, /* o : bits used for signaling */ @@ -331,145 +331,145 @@ void tcx_arith_decode_envelope_ivas_fx( const Word16 low_complexity /* i : low-complexity flag */ #endif ) - { - Word32 env[N_MAX_ARI]; /* unscaled envelope (Q16) */ - Word16 *envelope; /* scaled envelope (Q15-e) */ - Word16 envelope_e; - Word16 L_spec_core; - TCX_CONFIG_HANDLE hTcxCfg; - TCX_DEC_HANDLE hTcxDec; - Word16 gamma_w, gamma_uw; - Word16 hm_bits; - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( GT_16( L_spec, N_MAX_ARI ) || ( EQ_16( st->element_mode, EVS_MONO ) && GT_16( target_bits, ( ACELP_13k20 / FRAMES_PER_SEC ) ) ) || - ( EQ_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE / FRAMES_PER_SEC ) ) ) ) || - ( GT_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE_CPE / FRAMES_PER_SEC ) ) ) ) || - ( target_bits <= 0 ) ) - { - /* this could happen in case of bit errors */ - st->BER_detect = 1; - move16(); - L_spec = N_MAX_ARI; - move16(); - *signaling_bits = 0; - move16(); - *arith_bits = 0; - move16(); - set32_fx( q_spectrum, 0, L_frame ); - - return; - } +{ + Word32 env[N_MAX_ARI]; /* unscaled envelope (Q16) */ + Word16 *envelope; /* scaled envelope (Q15-e) */ + Word16 envelope_e; + Word16 L_spec_core; + TCX_CONFIG_HANDLE hTcxCfg; + TCX_DEC_HANDLE hTcxDec; + Word16 gamma_w, gamma_uw; + Word16 hm_bits; - hTcxCfg = st->hTcxCfg; - hTcxDec = st->hTcxDec; - *signaling_bits = 0; + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( GT_16( L_spec, N_MAX_ARI ) || ( EQ_16( st->element_mode, EVS_MONO ) && GT_16( target_bits, ( ACELP_13k20 / FRAMES_PER_SEC ) ) ) || + ( EQ_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE / FRAMES_PER_SEC ) ) ) ) || + ( GT_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE_CPE / FRAMES_PER_SEC ) ) ) ) || + ( target_bits <= 0 ) ) + { + /* this could happen in case of bit errors */ + st->BER_detect = 1; move16(); - - assert( hTcxDec->enableTcxLpc ); - gamma_w = MAX16B; + L_spec = N_MAX_ARI; move16(); - gamma_uw = st->inv_gamma; + *signaling_bits = 0; + move16(); + *arith_bits = 0; move16(); + set32_fx( q_spectrum, 0, L_frame ); + + return; + } + + hTcxCfg = st->hTcxCfg; + hTcxDec = st->hTcxDec; + *signaling_bits = 0; + move16(); + + assert( hTcxDec->enableTcxLpc ); + gamma_w = MAX16B; + move16(); + gamma_uw = st->inv_gamma; + move16(); #ifdef HARMONIZE_2598_tcx_arith_decode_envelope - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - tcx_arith_render_envelope( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); - } - ELSE - { + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + tcx_arith_render_envelope( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); + } + ELSE + { #endif - tcx_arith_render_envelope( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); + tcx_arith_render_envelope( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); #ifdef HARMONIZE_2598_tcx_arith_decode_envelope - } + } #endif - tcx_arith_render_envelope_ivas_fx( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); + tcx_arith_render_envelope_ivas_fx( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); - IF( use_hm != 0 ) + IF( use_hm != 0 ) + { + IF( prm_hm[0] != 0 ) { - IF( prm_hm[0] != 0 ) - { #ifdef HARMONIZE_2598_tcx_arith_decode_envelope - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - tcx_hm_decode( L_spec, env, target_bits, hTcxCfg->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); - } - ELSE - { + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + tcx_hm_decode( L_spec, env, target_bits, hTcxCfg->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); + } + ELSE + { #endif - tcx_hm_decode( L_spec, env, target_bits, st->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); + tcx_hm_decode( L_spec, env, target_bits, st->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); #ifdef HARMONIZE_2598_tcx_arith_decode_envelope - } + } #endif - IF( hm_bits < 0 ) - { - st->BER_detect = 1; - move16(); - *signaling_bits = 0; - move16(); - *arith_bits = 0; - move16(); - set32_fx( q_spectrum, 0, L_frame ); - - return; - } - } - ELSE + IF( hm_bits < 0 ) { - hm_bits = 1; + st->BER_detect = 1; + move16(); + *signaling_bits = 0; + move16(); + *arith_bits = 0; move16(); + set32_fx( q_spectrum, 0, L_frame ); + + return; } - *signaling_bits = add( *signaling_bits, hm_bits ); - move16(); } -#ifdef HARMONIZE_2598_tcx_arith_decode_envelope - IF( EQ_16( st->element_mode, EVS_MONO ) && ( use_hm == 0 ) ) + ELSE { - prm_hm[0] = 0; /* just to be sure */ + hm_bits = 1; move16(); } + *signaling_bits = add( *signaling_bits, hm_bits ); + move16(); + } +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope + IF( EQ_16( st->element_mode, EVS_MONO ) && ( use_hm == 0 ) ) + { + prm_hm[0] = 0; /* just to be sure */ + move16(); + } #endif - L_spec_core = L_spec; - move16(); - IF( st->igf ) - { - L_spec_core = s_min( L_spec_core, st->hIGFDec->infoIGFStartLine ); - } + L_spec_core = L_spec; + move16(); + IF( st->igf ) + { + L_spec_core = s_min( L_spec_core, st->hIGFDec->infoIGFStartLine ); + } - envelope = (Word16 *) env; - tcx_arith_scale_envelope( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e ); + envelope = (Word16 *) env; + tcx_arith_scale_envelope( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e ); #ifdef HARMONIZE_2598_tcx_arith_decode_envelope - IF( EQ_16( st->element_mode, EVS_MONO ) && ( use_hm == 0 ) ) - { - *arith_bits = tcx_arith_decode_fx( L_spec, envelope, envelope_e, target_bits, prm, q_spectrum, q_spectrum_e, nf_seed ); - } - ELSE - { + IF( EQ_16( st->element_mode, EVS_MONO ) && ( use_hm == 0 ) ) + { + *arith_bits = tcx_arith_decode_fx( L_spec, envelope, envelope_e, target_bits, prm, q_spectrum, q_spectrum_e, nf_seed ); + } + ELSE + { #endif - *arith_bits = tcx_arith_decode_ivas_fx( L_spec, envelope, envelope_e, target_bits, prm, q_spectrum, q_spectrum_e ); + *arith_bits = tcx_arith_decode_ivas_fx( L_spec, envelope, envelope_e, target_bits, prm, q_spectrum, q_spectrum_e ); #ifdef HARMONIZE_2598_tcx_arith_decode_envelope - } + } #endif - move16(); + move16(); - /* safety check in case of bit errors */ - IF( *arith_bits < 0 ) - { - st->BER_detect = 1; - move16(); - set32_fx( q_spectrum, 0, L_frame ); - } + /* safety check in case of bit errors */ + IF( *arith_bits < 0 ) + { + st->BER_detect = 1; + move16(); + set32_fx( q_spectrum, 0, L_frame ); + } - set32_fx( q_spectrum + L_spec, 0, sub( L_frame, L_spec ) ); + set32_fx( q_spectrum + L_spec, 0, sub( L_frame, L_spec ) ); - return; - } + return; +} -- GitLab From 8720a844e096cfeede9ecc19f562ace8d03998cb Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 21 May 2026 13:36:04 +0200 Subject: [PATCH 03/14] fixed common path in harmonized function --- lib_com/prot_fx.h | 3 +-- lib_dec/arith_coder_dec_fx.c | 36 +++++++++++++++++------------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 95e61f678..2382b6994 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9962,8 +9962,7 @@ void tcx_arith_render_envelope_ivas_fx( #ifdef HARMONIZE_2598_tcx_arith_decode_envelope void tcx_arith_decode_envelope_fx( - Decoder_State *st, - /* i/o: coder state */ /*EVS: move argument 5->1 */ + Decoder_State *st, /* i/o: coder state */ /*EVS: move argument 5->1 */ Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */ Word16 *q_spectrum_e, /* o : MDCT exponent */ const Word16 L_frame, /* i : frame or MDCT length */ diff --git a/lib_dec/arith_coder_dec_fx.c b/lib_dec/arith_coder_dec_fx.c index 92b836dd9..6e86bb3a6 100644 --- a/lib_dec/arith_coder_dec_fx.c +++ b/lib_dec/arith_coder_dec_fx.c @@ -298,21 +298,21 @@ static Word16 tcx_arith_decode_ivas_fx( #ifdef HARMONIZE_2598_tcx_arith_decode_envelope void tcx_arith_decode_envelope_fx( Decoder_State *st, - /* i/o: coder state */ /*EVS: move argument 5->1 */ - Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */ - Word16 *q_spectrum_e, /* o : MDCT exponent */ - const Word16 L_frame, /* i : frame or MDCT length */ - Word16 L_spec, /* i : length w/o BW limitation */ - const Word16 A_ind[], /* i : quantised LPC coefficients */ - const Word16 target_bits, /* i : number of available bits */ - Word16 prm[], /* i : bitstream parameters */ - const Word16 use_hm, /* i : use HM in current frame? */ - Word16 prm_hm[], /* i : HM parameter area */ - Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/ - Word16 *arith_bits, /* o : bits used for ari. coding */ - Word16 *signaling_bits, /* o : bits used for signaling */ - Word16 *nf_seed, /* o : noise filling seed Q0 */ - const Word16 low_complexity /* i : low-complexity flag */ + /* i/o: coder state */ /*EVS: move argument 5->1 */ + Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */ + Word16 *q_spectrum_e, /* o : MDCT exponent */ + const Word16 L_frame, /* i : frame or MDCT length */ + Word16 L_spec, /* i : length w/o BW limitation */ + const Word16 A_ind[], /* i : quantised LPC coefficients */ + const Word16 target_bits, /* i : number of available bits */ + Word16 prm[], /* i : bitstream parameters */ + const Word16 use_hm, /* i : use HM in current frame? */ + Word16 prm_hm[], /* i : HM parameter area */ + Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/ + Word16 *arith_bits, /* o : bits used for ari. coding */ + Word16 *signaling_bits, /* o : bits used for signaling */ + Word16 *nf_seed, /* o : noise filling seed Q0 */ /*IVAS: 0*/ + const Word16 low_complexity /* i : low-complexity flag */ #else void tcx_arith_decode_envelope_ivas_fx( Decoder_State *st, /* i/o: coder state */ @@ -368,11 +368,10 @@ void tcx_arith_decode_envelope_ivas_fx( } hTcxCfg = st->hTcxCfg; - hTcxDec = st->hTcxDec; *signaling_bits = 0; move16(); - assert( hTcxDec->enableTcxLpc ); + assert( st->hTcxDec->enableTcxLpc ); gamma_w = MAX16B; move16(); gamma_uw = st->inv_gamma; @@ -385,11 +384,10 @@ void tcx_arith_decode_envelope_ivas_fx( ELSE { #endif - tcx_arith_render_envelope( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); + tcx_arith_render_envelope_ivas_fx( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); #ifdef HARMONIZE_2598_tcx_arith_decode_envelope } #endif - tcx_arith_render_envelope_ivas_fx( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); IF( use_hm != 0 ) -- GitLab From 518426e8ec936aa3a75297698a5dc19450c9e0b5 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 21 May 2026 13:51:11 +0200 Subject: [PATCH 04/14] clang patch --- lib_com/prot_fx.h | 3 ++- lib_dec/arith_coder_dec_fx.c | 31 ++++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 2382b6994..95e61f678 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9962,7 +9962,8 @@ void tcx_arith_render_envelope_ivas_fx( #ifdef HARMONIZE_2598_tcx_arith_decode_envelope void tcx_arith_decode_envelope_fx( - Decoder_State *st, /* i/o: coder state */ /*EVS: move argument 5->1 */ + Decoder_State *st, + /* i/o: coder state */ /*EVS: move argument 5->1 */ Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */ Word16 *q_spectrum_e, /* o : MDCT exponent */ const Word16 L_frame, /* i : frame or MDCT length */ diff --git a/lib_dec/arith_coder_dec_fx.c b/lib_dec/arith_coder_dec_fx.c index 6e86bb3a6..bd8c938f8 100644 --- a/lib_dec/arith_coder_dec_fx.c +++ b/lib_dec/arith_coder_dec_fx.c @@ -298,21 +298,22 @@ static Word16 tcx_arith_decode_ivas_fx( #ifdef HARMONIZE_2598_tcx_arith_decode_envelope void tcx_arith_decode_envelope_fx( Decoder_State *st, - /* i/o: coder state */ /*EVS: move argument 5->1 */ - Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */ - Word16 *q_spectrum_e, /* o : MDCT exponent */ - const Word16 L_frame, /* i : frame or MDCT length */ - Word16 L_spec, /* i : length w/o BW limitation */ - const Word16 A_ind[], /* i : quantised LPC coefficients */ - const Word16 target_bits, /* i : number of available bits */ - Word16 prm[], /* i : bitstream parameters */ - const Word16 use_hm, /* i : use HM in current frame? */ - Word16 prm_hm[], /* i : HM parameter area */ - Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/ - Word16 *arith_bits, /* o : bits used for ari. coding */ - Word16 *signaling_bits, /* o : bits used for signaling */ - Word16 *nf_seed, /* o : noise filling seed Q0 */ /*IVAS: 0*/ - const Word16 low_complexity /* i : low-complexity flag */ + /* i/o: coder state */ /*EVS: move argument 5->1 */ + Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */ + Word16 *q_spectrum_e, /* o : MDCT exponent */ + const Word16 L_frame, /* i : frame or MDCT length */ + Word16 L_spec, /* i : length w/o BW limitation */ + const Word16 A_ind[], /* i : quantised LPC coefficients */ + const Word16 target_bits, /* i : number of available bits */ + Word16 prm[], /* i : bitstream parameters */ + const Word16 use_hm, /* i : use HM in current frame? */ + Word16 prm_hm[], /* i : HM parameter area */ + Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/ + Word16 *arith_bits, /* o : bits used for ari. coding */ + Word16 *signaling_bits, /* o : bits used for signaling */ + Word16 *nf_seed, + /* o : noise filling seed Q0 */ /*IVAS: 0*/ + const Word16 low_complexity /* i : low-complexity flag */ #else void tcx_arith_decode_envelope_ivas_fx( Decoder_State *st, /* i/o: coder state */ -- GitLab From b2c52dd8600aac797ae823d7307135c4cd8546e6 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 21 May 2026 13:58:24 +0200 Subject: [PATCH 05/14] fix buildwarning --- lib_dec/arith_coder_dec_fx.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib_dec/arith_coder_dec_fx.c b/lib_dec/arith_coder_dec_fx.c index bd8c938f8..11a1a998a 100644 --- a/lib_dec/arith_coder_dec_fx.c +++ b/lib_dec/arith_coder_dec_fx.c @@ -338,7 +338,6 @@ void tcx_arith_decode_envelope_ivas_fx( Word16 envelope_e; Word16 L_spec_core; TCX_CONFIG_HANDLE hTcxCfg; - TCX_DEC_HANDLE hTcxDec; Word16 gamma_w, gamma_uw; Word16 hm_bits; -- GitLab From 309c087d9144b6d729e6f2c0cfacf3dffc039012 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 21 May 2026 14:44:07 +0200 Subject: [PATCH 06/14] fixed error in EVS path --- lib_dec/arith_coder_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/arith_coder_dec_fx.c b/lib_dec/arith_coder_dec_fx.c index 11a1a998a..95ba38caa 100644 --- a/lib_dec/arith_coder_dec_fx.c +++ b/lib_dec/arith_coder_dec_fx.c @@ -446,7 +446,7 @@ void tcx_arith_decode_envelope_ivas_fx( envelope = (Word16 *) env; tcx_arith_scale_envelope( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e ); #ifdef HARMONIZE_2598_tcx_arith_decode_envelope - IF( EQ_16( st->element_mode, EVS_MONO ) && ( use_hm == 0 ) ) + IF( EQ_16( st->element_mode, EVS_MONO ) ) { *arith_bits = tcx_arith_decode_fx( L_spec, envelope, envelope_e, target_bits, prm, q_spectrum, q_spectrum_e, nf_seed ); } -- GitLab From 666fd6002cbbc2d5264165d2f6c8f0e70e8c38cd Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 21 May 2026 14:57:16 +0200 Subject: [PATCH 07/14] added macro for HARMONIZE_2598_tcx_arith_encode_envelope --- lib_com/options.h | 1 + 1 file changed, 1 insertion(+) diff --git a/lib_com/options.h b/lib_com/options.h index b28b6315f..7538821b3 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -93,6 +93,7 @@ #define NONBE_FIX_ISSUE_2206_SWB_EXPERIMENT_FIX_2527 /* Fix crash from issue #2527 */ #define FIX_FLOAT_1539_G192_FORMAT_SWITCH /* VA/Nokia: reintroduce format switching for g192 bitstreams */ #define HARMONIZE_2598_tcx_arith_decode_envelope /* FhG: harmonize tcx_arith_decode_envelope between EVS and IVAS versions */ +#define HARMONIZE_2598_tcx_arith_encode_envelope /* FhG: harmonize tcx_arith_encode_envelope between EVS and IVAS versions */ /* #################### End BE switches ################################## */ -- GitLab From d258eb2493740780af7489190318393a09279826 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 21 May 2026 15:07:15 +0200 Subject: [PATCH 08/14] added code for HARMONIZE_2598_tcx_arith_encode_envelope --- lib_enc/arith_coder_enc_fx.c | 50 ++++++++++++++++++++++++++++++++++-- lib_enc/cod_tcx_fx.c | 5 +++- lib_enc/prot_fx_enc.h | 23 +++++++++++++++++ 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/lib_enc/arith_coder_enc_fx.c b/lib_enc/arith_coder_enc_fx.c index f61345df5..44668abe4 100644 --- a/lib_enc/arith_coder_enc_fx.c +++ b/lib_enc/arith_coder_enc_fx.c @@ -658,7 +658,7 @@ static Word16 tcx_arith_encode( * * *-------------------------------------------------------------------*/ - +#ifndef HARMONIZE_2598_tcx_arith_encode_envelope void tcx_arith_encode_envelope_fx( Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ @@ -800,8 +800,29 @@ void tcx_arith_encode_envelope_fx( return; } +#endif - +#ifdef HARMONIZE_2598_tcx_arith_encode_envelope +void tcx_arith_encode_envelope_fx( + Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ + Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ + Word16 signs[], /* o : signs (spectrum[.]<0) Q0 */ + const Word16 L_frame, /* i : frame or MDCT length Q0 */ + const Word16 L_spec, /* i : frame or MDCT length Q0 */ + Encoder_State *st, /* i/o: coder state */ + const Word16 A_ind[], /* i : quantised LPC coefficients Q12 */ + Word16 target_bits, /* i : number of available bits Q0 */ + Word16 prm[], /* o : bitstream parameters Q0 */ + const Word8 use_hm, /* i : use HM in current frame? */ + Word16 prm_hm[], /* o : HM parameter area Q0 */ + const Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a Q0*/ + Word16 *arith_bits, /* o : bits used for ari. coding Q0 */ + Word16 *signaling_bits, /* o : bits used for signaling Q0 */ + Word16 *nf_seed, + /*IVAS:0*/ /* o : noise filling seed Q0 */ + const Word16 low_complexity /* i : low-complexity flag Q0 */ +) +#else void tcx_arith_encode_envelope_ivas_fx( Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ @@ -819,6 +840,7 @@ void tcx_arith_encode_envelope_ivas_fx( Word16 *signaling_bits, /* o : bits used for signaling Q0 */ const Word16 low_complexity /* i : low-complexity flag Q0 */ ) +#endif { Word32 env[N_MAX_ARI]; /* unscaled envelope (Q16) */ Word16 *envelope; /* scaled envelope (Q15-e) */ @@ -834,6 +856,9 @@ void tcx_arith_encode_envelope_ivas_fx( Word16 gamma_w, gamma_uw; Word16 hm_bits; Word32 L_tmp; +#ifdef HARMONIZE_2598_tcx_arith_encode_envelope + Word64 W_tmp2; +#endif Word16 tmp; TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; @@ -919,8 +944,21 @@ void tcx_arith_encode_envelope_ivas_fx( move16(); /* Multiply back the signs */ +#ifdef HARMONIZE_2598_tcx_arith_encode_envelope + if ( EQ_16( st->element_mode, EVS_MONO ) ) + { + W_tmp2 = 0; + move32(); + } +#endif FOR( k = 0; k <= kMax; k++ ) { +#ifdef HARMONIZE_2598_tcx_arith_encode_envelope + if ( EQ_16( st->element_mode, EVS_MONO ) ) + { + W_tmp2 = W_mac_16_16( W_tmp2, q_spectrum[k], k ); + } +#endif if ( signs[k] != 0 ) L_tmp = L_mult( q_spectrum[k], -( 1 << ( 30 - SPEC_EXP_DEC ) ) ); if ( signs[k] == 0 ) @@ -933,5 +971,13 @@ void tcx_arith_encode_envelope_ivas_fx( move16(); set32_fx( spectrum + k, 0, sub( s_max( L_frame, L_spec ), k ) ); +#ifdef HARMONIZE_2598_tcx_arith_encode_envelope + if ( EQ_16( st->element_mode, EVS_MONO ) ) + { + /* noise filling seed */ + *nf_seed = extract_l( W_extract_l( W_tmp2 ) ); + move16(); + } +#endif return; } diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 8b1875207..93e557452 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -3493,8 +3493,11 @@ void QuantizeTCXSpectrum_fx( low_complexiety = 1; move16(); } +#ifdef HARMONIZE_2598_tcx_arith_encode_envelope + tcx_arith_encode_envelope_fx( spectrum_fx, spectrum_e, hm_cfg->indexBuffer, L_frame, L_spec, st, Aqind, sqTargetBits, sqQ, tmp8, prm_hm, /* HM parameter area */ LtpPitchLag, &sqBits, &signaling_bits, 0, low_complexiety ); +#else tcx_arith_encode_envelope_ivas_fx( spectrum_fx, spectrum_e, hm_cfg->indexBuffer, L_frame, L_spec, st, Aqind, sqTargetBits, sqQ, tmp8, prm_hm, /* HM parameter area */ LtpPitchLag, &sqBits, &signaling_bits, low_complexiety ); - +#endif sqTargetBits = sub( sqTargetBits, signaling_bits ); *prm_target = sqTargetBits; move16(); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 675710bcb..e8e76f1db 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1891,6 +1891,7 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( Word16 *stop, /* Q0 */ CONTEXT_HM_CONFIG *hm_cfg ); +#ifndef HARMONIZE_2598_tcx_arith_encode_envelope void tcx_arith_encode_envelope_fx( Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ @@ -1909,7 +1910,28 @@ void tcx_arith_encode_envelope_fx( Word16 *nf_seed, /* o : noise filling seed Q0 */ const Word16 low_complexity /* i : low-complexity flag Q0 */ ); +#endif +#ifdef HARMONIZE_2598_tcx_arith_encode_envelope +void tcx_arith_encode_envelope_fx( + Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ + Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ + Word16 signs[], /* o : signs (spectrum[.]<0) Q0 */ + const Word16 L_frame, /* i : frame or MDCT length Q0 */ + const Word16 L_spec, /* i : frame or MDCT length Q0 */ + Encoder_State *st, /* i/o: coder state */ + const Word16 A_ind[], /* i : quantised LPC coefficients Q12 */ + Word16 target_bits, /* i : number of available bits Q0 */ + Word16 prm[], /* o : bitstream parameters Q0 */ + const Word8 use_hm, /* i : use HM in current frame? */ + Word16 prm_hm[], /* o : HM parameter area Q0 */ + const Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a Q0*/ + Word16 *arith_bits, /* o : bits used for ari. coding Q0 */ + Word16 *signaling_bits, /* o : bits used for signaling Q0 */ + Word16 *nf_seed, /*IVAS:0*/ /* o : noise filling seed Q0 */ + const Word16 low_complexity /* i : low-complexity flag Q0 */ + ); +#else void tcx_arith_encode_envelope_ivas_fx( Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ @@ -1927,6 +1949,7 @@ void tcx_arith_encode_envelope_ivas_fx( Word16 *signaling_bits, /* o : bits used for signaling Q0 */ const Word16 low_complexity /* i : low-complexity flag Q0 */ ); +#endif void QuantizeGain( Word16 n, -- GitLab From 65b12f07998a50364f8a491087920ee0b1d2cd52 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 21 May 2026 15:07:56 +0200 Subject: [PATCH 09/14] deactivated HARMONIZE_2598_tcx_arith_encode_envelope --- 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 7538821b3..a9990bbc8 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -93,7 +93,7 @@ #define NONBE_FIX_ISSUE_2206_SWB_EXPERIMENT_FIX_2527 /* Fix crash from issue #2527 */ #define FIX_FLOAT_1539_G192_FORMAT_SWITCH /* VA/Nokia: reintroduce format switching for g192 bitstreams */ #define HARMONIZE_2598_tcx_arith_decode_envelope /* FhG: harmonize tcx_arith_decode_envelope between EVS and IVAS versions */ -#define HARMONIZE_2598_tcx_arith_encode_envelope /* FhG: harmonize tcx_arith_encode_envelope between EVS and IVAS versions */ +//#define HARMONIZE_2598_tcx_arith_encode_envelope /* FhG: harmonize tcx_arith_encode_envelope between EVS and IVAS versions */ /* #################### End BE switches ################################## */ -- GitLab From 1bdbbd0ce5bb0ecc460053ec5f94eb772ee90a9a Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 21 May 2026 15:16:53 +0200 Subject: [PATCH 10/14] reactivated macro for HARMONIZE_2598_tcx_arith_encode_envelope --- 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 a9990bbc8..7538821b3 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -93,7 +93,7 @@ #define NONBE_FIX_ISSUE_2206_SWB_EXPERIMENT_FIX_2527 /* Fix crash from issue #2527 */ #define FIX_FLOAT_1539_G192_FORMAT_SWITCH /* VA/Nokia: reintroduce format switching for g192 bitstreams */ #define HARMONIZE_2598_tcx_arith_decode_envelope /* FhG: harmonize tcx_arith_decode_envelope between EVS and IVAS versions */ -//#define HARMONIZE_2598_tcx_arith_encode_envelope /* FhG: harmonize tcx_arith_encode_envelope between EVS and IVAS versions */ +#define HARMONIZE_2598_tcx_arith_encode_envelope /* FhG: harmonize tcx_arith_encode_envelope between EVS and IVAS versions */ /* #################### End BE switches ################################## */ -- GitLab From 7e7c3ba007547f8a74c3ddbfbc12764937a48757 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 21 May 2026 15:55:09 +0200 Subject: [PATCH 11/14] clang patch --- lib_enc/prot_fx_enc.h | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index e8e76f1db..f311697f0 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1914,23 +1914,24 @@ void tcx_arith_encode_envelope_fx( #ifdef HARMONIZE_2598_tcx_arith_encode_envelope void tcx_arith_encode_envelope_fx( - Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ - Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ - Word16 signs[], /* o : signs (spectrum[.]<0) Q0 */ - const Word16 L_frame, /* i : frame or MDCT length Q0 */ - const Word16 L_spec, /* i : frame or MDCT length Q0 */ - Encoder_State *st, /* i/o: coder state */ - const Word16 A_ind[], /* i : quantised LPC coefficients Q12 */ - Word16 target_bits, /* i : number of available bits Q0 */ - Word16 prm[], /* o : bitstream parameters Q0 */ - const Word8 use_hm, /* i : use HM in current frame? */ - Word16 prm_hm[], /* o : HM parameter area Q0 */ - const Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a Q0*/ - Word16 *arith_bits, /* o : bits used for ari. coding Q0 */ - Word16 *signaling_bits, /* o : bits used for signaling Q0 */ - Word16 *nf_seed, /*IVAS:0*/ /* o : noise filling seed Q0 */ + Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ + Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ + Word16 signs[], /* o : signs (spectrum[.]<0) Q0 */ + const Word16 L_frame, /* i : frame or MDCT length Q0 */ + const Word16 L_spec, /* i : frame or MDCT length Q0 */ + Encoder_State *st, /* i/o: coder state */ + const Word16 A_ind[], /* i : quantised LPC coefficients Q12 */ + Word16 target_bits, /* i : number of available bits Q0 */ + Word16 prm[], /* o : bitstream parameters Q0 */ + const Word8 use_hm, /* i : use HM in current frame? */ + Word16 prm_hm[], /* o : HM parameter area Q0 */ + const Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a Q0*/ + Word16 *arith_bits, /* o : bits used for ari. coding Q0 */ + Word16 *signaling_bits, /* o : bits used for signaling Q0 */ + Word16 *nf_seed, + /*IVAS:0*/ /* o : noise filling seed Q0 */ const Word16 low_complexity /* i : low-complexity flag Q0 */ - ); +); #else void tcx_arith_encode_envelope_ivas_fx( Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ -- GitLab From 47bc9aea0f3fa0e2cb15c10aff42379f9e901bb9 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Tue, 26 May 2026 07:10:25 +0200 Subject: [PATCH 12/14] fix buildwarning --- lib_enc/arith_coder_enc_fx.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib_enc/arith_coder_enc_fx.c b/lib_enc/arith_coder_enc_fx.c index 44668abe4..651e37215 100644 --- a/lib_enc/arith_coder_enc_fx.c +++ b/lib_enc/arith_coder_enc_fx.c @@ -945,11 +945,8 @@ void tcx_arith_encode_envelope_ivas_fx( /* Multiply back the signs */ #ifdef HARMONIZE_2598_tcx_arith_encode_envelope - if ( EQ_16( st->element_mode, EVS_MONO ) ) - { - W_tmp2 = 0; - move32(); - } + W_tmp2 = 0; + move32(); #endif FOR( k = 0; k <= kMax; k++ ) { -- GitLab From 3acda6ad10c82e11742c073f35c1ae6bea1dd411 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Wed, 27 May 2026 20:38:53 +0200 Subject: [PATCH 13/14] simplifications --- lib_dec/arith_coder_dec_fx.c | 20 +------------------- lib_enc/arith_coder_enc_fx.c | 4 ++++ lib_enc/cod_tcx_fx.c | 2 +- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/lib_dec/arith_coder_dec_fx.c b/lib_dec/arith_coder_dec_fx.c index 95ba38caa..96efe3fcd 100644 --- a/lib_dec/arith_coder_dec_fx.c +++ b/lib_dec/arith_coder_dec_fx.c @@ -394,18 +394,7 @@ void tcx_arith_decode_envelope_ivas_fx( { IF( prm_hm[0] != 0 ) { -#ifdef HARMONIZE_2598_tcx_arith_decode_envelope - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - tcx_hm_decode( L_spec, env, target_bits, hTcxCfg->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); - } - ELSE - { -#endif - tcx_hm_decode( L_spec, env, target_bits, st->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); -#ifdef HARMONIZE_2598_tcx_arith_decode_envelope - } -#endif + tcx_hm_decode( L_spec, env, target_bits, st->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); IF( hm_bits < 0 ) { @@ -428,13 +417,6 @@ void tcx_arith_decode_envelope_ivas_fx( *signaling_bits = add( *signaling_bits, hm_bits ); move16(); } -#ifdef HARMONIZE_2598_tcx_arith_decode_envelope - IF( EQ_16( st->element_mode, EVS_MONO ) && ( use_hm == 0 ) ) - { - prm_hm[0] = 0; /* just to be sure */ - move16(); - } -#endif L_spec_core = L_spec; move16(); diff --git a/lib_enc/arith_coder_enc_fx.c b/lib_enc/arith_coder_enc_fx.c index 651e37215..ea3e900d8 100644 --- a/lib_enc/arith_coder_enc_fx.c +++ b/lib_enc/arith_coder_enc_fx.c @@ -957,9 +957,13 @@ void tcx_arith_encode_envelope_ivas_fx( } #endif if ( signs[k] != 0 ) + { L_tmp = L_mult( q_spectrum[k], -( 1 << ( 30 - SPEC_EXP_DEC ) ) ); + } if ( signs[k] == 0 ) + { L_tmp = L_mult( q_spectrum[k], 1 << ( 30 - SPEC_EXP_DEC ) ); + } spectrum[k] = L_tmp; move32(); } diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 93e557452..b4e7d09c1 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -3494,7 +3494,7 @@ void QuantizeTCXSpectrum_fx( move16(); } #ifdef HARMONIZE_2598_tcx_arith_encode_envelope - tcx_arith_encode_envelope_fx( spectrum_fx, spectrum_e, hm_cfg->indexBuffer, L_frame, L_spec, st, Aqind, sqTargetBits, sqQ, tmp8, prm_hm, /* HM parameter area */ LtpPitchLag, &sqBits, &signaling_bits, 0, low_complexiety ); + tcx_arith_encode_envelope_fx( spectrum_fx, spectrum_e, hm_cfg->indexBuffer, L_frame, L_spec, st, Aqind, sqTargetBits, sqQ, tmp8, prm_hm, /* HM parameter area */ LtpPitchLag, &sqBits, &signaling_bits, NULL, low_complexiety ); #else tcx_arith_encode_envelope_ivas_fx( spectrum_fx, spectrum_e, hm_cfg->indexBuffer, L_frame, L_spec, st, Aqind, sqTargetBits, sqQ, tmp8, prm_hm, /* HM parameter area */ LtpPitchLag, &sqBits, &signaling_bits, low_complexiety ); #endif -- GitLab From a2262106769e60c5eb848751a4b60f67531c7343 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Wed, 27 May 2026 22:50:12 +0200 Subject: [PATCH 14/14] conditiosn for nf_seed update --- lib_enc/arith_coder_enc_fx.c | 36 ++++++++++++++++++------------------ lib_enc/prot_fx_enc.h | 31 +++++++++++++++---------------- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/lib_enc/arith_coder_enc_fx.c b/lib_enc/arith_coder_enc_fx.c index ea3e900d8..1469136ec 100644 --- a/lib_enc/arith_coder_enc_fx.c +++ b/lib_enc/arith_coder_enc_fx.c @@ -804,22 +804,21 @@ void tcx_arith_encode_envelope_fx( #ifdef HARMONIZE_2598_tcx_arith_encode_envelope void tcx_arith_encode_envelope_fx( - Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ - Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ - Word16 signs[], /* o : signs (spectrum[.]<0) Q0 */ - const Word16 L_frame, /* i : frame or MDCT length Q0 */ - const Word16 L_spec, /* i : frame or MDCT length Q0 */ - Encoder_State *st, /* i/o: coder state */ - const Word16 A_ind[], /* i : quantised LPC coefficients Q12 */ - Word16 target_bits, /* i : number of available bits Q0 */ - Word16 prm[], /* o : bitstream parameters Q0 */ - const Word8 use_hm, /* i : use HM in current frame? */ - Word16 prm_hm[], /* o : HM parameter area Q0 */ - const Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a Q0*/ - Word16 *arith_bits, /* o : bits used for ari. coding Q0 */ - Word16 *signaling_bits, /* o : bits used for signaling Q0 */ - Word16 *nf_seed, - /*IVAS:0*/ /* o : noise filling seed Q0 */ + Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ + Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ + Word16 signs[], /* o : signs (spectrum[.]<0) Q0 */ + const Word16 L_frame, /* i : frame or MDCT length Q0 */ + const Word16 L_spec, /* i : frame or MDCT length Q0 */ + Encoder_State *st, /* i/o: coder state */ + const Word16 A_ind[], /* i : quantised LPC coefficients Q12 */ + Word16 target_bits, /* i : number of available bits Q0 */ + Word16 prm[], /* o : bitstream parameters Q0 */ + const Word8 use_hm, /* i : use HM in current frame? */ + Word16 prm_hm[], /* o : HM parameter area Q0 */ + const Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a Q0*/ + Word16 *arith_bits, /* o : bits used for ari. coding Q0 */ + Word16 *signaling_bits, /* o : bits used for signaling Q0 */ + Word16 *nf_seed, /* o : noise filling seed; might be NULL Q0 */ const Word16 low_complexity /* i : low-complexity flag Q0 */ ) #else @@ -951,7 +950,7 @@ void tcx_arith_encode_envelope_ivas_fx( FOR( k = 0; k <= kMax; k++ ) { #ifdef HARMONIZE_2598_tcx_arith_encode_envelope - if ( EQ_16( st->element_mode, EVS_MONO ) ) + if ( nf_seed != NULL ) { W_tmp2 = W_mac_16_16( W_tmp2, q_spectrum[k], k ); } @@ -973,12 +972,13 @@ void tcx_arith_encode_envelope_ivas_fx( set32_fx( spectrum + k, 0, sub( s_max( L_frame, L_spec ), k ) ); #ifdef HARMONIZE_2598_tcx_arith_encode_envelope - if ( EQ_16( st->element_mode, EVS_MONO ) ) + if ( nf_seed != NULL ) { /* noise filling seed */ *nf_seed = extract_l( W_extract_l( W_tmp2 ) ); move16(); } #endif + return; } diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 848036084..a1945f7fc 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1914,22 +1914,21 @@ void tcx_arith_encode_envelope_fx( #ifdef HARMONIZE_2598_tcx_arith_encode_envelope void tcx_arith_encode_envelope_fx( - Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ - Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ - Word16 signs[], /* o : signs (spectrum[.]<0) Q0 */ - const Word16 L_frame, /* i : frame or MDCT length Q0 */ - const Word16 L_spec, /* i : frame or MDCT length Q0 */ - Encoder_State *st, /* i/o: coder state */ - const Word16 A_ind[], /* i : quantised LPC coefficients Q12 */ - Word16 target_bits, /* i : number of available bits Q0 */ - Word16 prm[], /* o : bitstream parameters Q0 */ - const Word8 use_hm, /* i : use HM in current frame? */ - Word16 prm_hm[], /* o : HM parameter area Q0 */ - const Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a Q0*/ - Word16 *arith_bits, /* o : bits used for ari. coding Q0 */ - Word16 *signaling_bits, /* o : bits used for signaling Q0 */ - Word16 *nf_seed, - /*IVAS:0*/ /* o : noise filling seed Q0 */ + Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ + Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ + Word16 signs[], /* o : signs (spectrum[.]<0) Q0 */ + const Word16 L_frame, /* i : frame or MDCT length Q0 */ + const Word16 L_spec, /* i : frame or MDCT length Q0 */ + Encoder_State *st, /* i/o: coder state */ + const Word16 A_ind[], /* i : quantised LPC coefficients Q12 */ + Word16 target_bits, /* i : number of available bits Q0 */ + Word16 prm[], /* o : bitstream parameters Q0 */ + const Word8 use_hm, /* i : use HM in current frame? */ + Word16 prm_hm[], /* o : HM parameter area Q0 */ + const Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a Q0*/ + Word16 *arith_bits, /* o : bits used for ari. coding Q0 */ + Word16 *signaling_bits, /* o : bits used for signaling Q0 */ + Word16 *nf_seed, /* o : noise filling seed, may be NULL Q0 */ const Word16 low_complexity /* i : low-complexity flag Q0 */ ); #else -- GitLab