From f4321d6c24f14701d3bbfa937ecabfae7d796126 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 6 Feb 2026 18:08:52 +0100 Subject: [PATCH 1/2] FIX_2424_REMOVE_GAUSS_L2_ENC --- lib_com/options.h | 1 + lib_dec/dec_uv_fx.c | 7 ++++--- lib_dec/gaus_dec_fx.c | 14 +++++++++----- lib_enc/cod_uv_fx.c | 8 +++++--- lib_enc/enc_uv_fx.c | 4 ++++ lib_enc/prot_fx_enc.h | 3 ++- 6 files changed, 25 insertions(+), 12 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 61a3c10cc..0488d5fe0 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -94,6 +94,7 @@ #define FIX_2404_HARM_SIGNAL_CLAS /* VA: basop-2404, harmonize signal_clas and signa_ivas_clas */ #define HARMONIZE_ACELP_ENC /* VA: basop issue 2400: Remove duplicated main ACELP encoder function */ #define FIX_2392_MSAN_DESTROY_DEC /* VA: basop issue 2392: fix MSAN in ivas_destroy_dec_fx() */ +#define FIX_2424_REMOVE_GAUSS_L2_ENC /* VA: basop issue 2424: Remove duplicated code in gauss_L2_ivas_fx() */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/dec_uv_fx.c b/lib_dec/dec_uv_fx.c index 83e5666b4..a2d59c08a 100644 --- a/lib_dec/dec_uv_fx.c +++ b/lib_dec/dec_uv_fx.c @@ -78,9 +78,10 @@ void decod_unvoiced_fx( &voice_fac_fx, &gain_pit_fx, pt_pitch_fx, exc_fx, &gain_code_fx, exc2_fx, bwe_exc_fx, &( st_fx->Q_exc ), st_fx->Q_subfr ); } ELSE - { /*----------------------------------------------------------------* - * Unvoiced subframe processing in two stages - *----------------------------------------------------------------*/ + { + /*----------------------------------------------------------------* + * Unvoiced subframe processing in two stages + *----------------------------------------------------------------*/ /* No adaptive codebook (UC) */ set16_fx( exc_fx + i_subfr_fx, 0, L_SUBFR ); diff --git a/lib_dec/gaus_dec_fx.c b/lib_dec/gaus_dec_fx.c index 0d38c40bc..4fcbaf514 100644 --- a/lib_dec/gaus_dec_fx.c +++ b/lib_dec/gaus_dec_fx.c @@ -12,7 +12,7 @@ * Local function prototypes *---------------------------------------------------------------------*/ -void gaus_dec2v_fx( Decoder_State *st_fx, Word16 *code, const Word16 lg, const Word16 nb_bits ); +static void gaus_dec2v_fx( Decoder_State *st_fx, Word16 *code, const Word16 lg, const Word16 nb_bits ); static void dec_2pos_fx( Word16 index, Word16 *ind1, Word16 *ind2, Word16 *sign1, Word16 *sign2, Word16 log2_n ); /*---------------------------------------------------------------------* @@ -22,6 +22,7 @@ static void dec_2pos_fx( Word16 index, Word16 *ind1, Word16 *ind2, Word16 *sign1 * - decode the codebook indices, * - find the excitation *---------------------------------------------------------------------*/ + void gaus_dec_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ const Word16 i_subfr, /* i : subframe index */ @@ -53,6 +54,7 @@ void gaus_dec_fx( /*------------------------------------------------------------------------------------------* * Unvoiced : Gaussian codebook *------------------------------------------------------------------------------------------*/ + nb_bits = st_fx->acelp_cfg.fixed_cdk_index[( i_subfr / 64 )]; move16(); @@ -61,6 +63,7 @@ void gaus_dec_fx( /*------------------------------------------------------------------------------------------* * - Gain of Gaussian excitation and normalized Gaussian excitation *------------------------------------------------------------------------------------------*/ + /* gain_inov = 1.0f / (float)sqrt((dot_product(code, code, L_SUBFR) + 0.01f) / L_SUBFR) */ L_tmp = Dot_product12( code, code, L_SUBFR, &exp ); exp = sub( exp, 18 /*24*/ + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ @@ -141,7 +144,7 @@ void gaus_dec_fx( * One Gaussian vector of 190 values *-----------------------------------------------------*/ -void gaus_dec2v_fx( +static void gaus_dec2v_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 *code, /* o : decoded gaussian vector Q12-exp */ const Word16 lg, /* i : codevector length Q0 */ @@ -211,13 +214,14 @@ void gaus_dec2v_fx( * * Decode the codevectors positions and signs *-----------------------------------------------------*/ + static void dec_2pos_fx( - Word16 index, /* i : quantization index Q0 */ + Word16 index, /* i : quantization index Q0 */ Word16 *ind1, /* o : 1st vector index Q0 */ Word16 *ind2, /* o : 2nd vector index Q0 */ Word16 *sign1, /* o : 1st vector sign Q0 */ Word16 *sign2, /* o : 2nd vector sign Q0 */ - Word16 log2_n /* i : Log2(number of vector) Q0 */ + Word16 log2_n /* i : Log2(number of vector) Q0 */ ) { Word16 i; @@ -257,6 +261,7 @@ static void dec_2pos_fx( * * One Gaussian vector *-----------------------------------------------------*/ + void gaus_L2_dec( Word16 *code, /* o : decoded gaussian codevector Q9 */ Word16 tilt_code, /* i : tilt of code Q15 */ @@ -289,6 +294,5 @@ void gaus_L2_dec( /*Shape the gaussian excitation*/ cb_shape_fx( 1, 0, 0, 1, 0, formant_enh, FORMANT_SHARPENING_G2, A, code, tilt_code, 0, 1, L_SUBFR ); - return; } diff --git a/lib_enc/cod_uv_fx.c b/lib_enc/cod_uv_fx.c index 684282bdb..d795733b4 100644 --- a/lib_enc/cod_uv_fx.c +++ b/lib_enc/cod_uv_fx.c @@ -5,7 +5,6 @@ #include #include "options.h" #include -//#include "prot_fx.h" #include "rom_com.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -19,6 +18,7 @@ * * Gaussian excitation is generated by a white noise and shapes it with LPC-derived filter *-------------------------------------------------------------------*/ + void gauss_L2_fx( const Word16 h[], /* i : weighted LP filter impulse response Q14+s */ Word16 code[], /* o : gaussian excitation Q9 */ @@ -36,7 +36,6 @@ void gauss_L2_fx( Word16 i, tmp16; Word32 tmp32, tmp32_2; - assert( gain_pit == 0 ); /*-----------------------------------------------------------------* @@ -86,8 +85,10 @@ void gauss_L2_fx( g_corr->y1y2_e = sub( 31 - 18, tmp16 ); move16(); move16(); -} + return; +} +#ifndef FIX_2424_REMOVE_GAUSS_L2_ENC void gauss_L2_ivas_fx( const Word16 h[], /* i : weighted LP filter impulse response Q14+s */ Word16 code[], /* o : gaussian excitation Q9 */ @@ -157,3 +158,4 @@ void gauss_L2_ivas_fx( move16(); move16(); } +#endif diff --git a/lib_enc/enc_uv_fx.c b/lib_enc/enc_uv_fx.c index 160814bc0..256bb92e2 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -180,15 +180,19 @@ void encod_unvoiced_fx( move16(); move16(); +#ifndef FIX_2424_REMOVE_GAUSS_L2_ENC assert( gain_pit_fx == 0 ); IF( st_fx->element_mode == EVS_MONO ) { +#endif gauss_L2_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift ); +#ifndef FIX_2424_REMOVE_GAUSS_L2_ENC } ELSE { gauss_L2_ivas_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift ); } +#endif /*----------------------------------------------------------* * - Compute the fixed codebook gain * diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 4310137b0..c2d066b75 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2145,6 +2145,7 @@ void gauss_L2_fx( Word16 *seed_acelp, /*i/o : random seed Q0 */ const Word16 shift ); +#ifndef FIX_2424_REMOVE_GAUSS_L2_ENC void gauss_L2_ivas_fx( const Word16 h[], /* i : weighted LP filter impulse response Q14+s */ Word16 code2[], /* o : gaussian excitation Q9 */ @@ -2158,7 +2159,7 @@ void gauss_L2_ivas_fx( const Word16 formant_enh, /* i : formant enhancement factor Q15 */ Word16 *seed_acelp, /*i/o : random seed Q0 */ const Word16 shift ); - +#endif Word32 SFM_Cal_fx( Word32 magn[], Word16 n ); -- GitLab From d0c00010e3bbde899154279011d7f987b1fdee33 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 9 Feb 2026 11:40:52 +0100 Subject: [PATCH 2/2] fix to keep BE --- lib_enc/cod_ace_fx.c | 4 ++++ lib_enc/cod_uv_fx.c | 50 ++++++++++++++++++++++++++++++++++++++++--- lib_enc/enc_uv_fx.c | 6 +++--- lib_enc/prot_fx_enc.h | 3 +++ 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index f4b74b351..92b08554e 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -290,8 +290,12 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * IF( EQ_16( acelp_cfg->gains_mode[j_subfr], 7 ) ) { +#ifdef FIX_2424_REMOVE_GAUSS_L2_ENC + gauss_L2_fx( st->element_mode, h1, code2, y2, y22, &gain_code2, &g_corr, gain_pit, hLPDmem->tilt_code, p_Aq, acelp_cfg->formant_enh_num, &( st->seed_acelp ), shift ); +#else assert( gain_pit == 0 ); gauss_L2_fx( h1, code2, y2, y22, &gain_code2, &g_corr, gain_pit, hLPDmem->tilt_code, p_Aq, acelp_cfg->formant_enh_num, &( st->seed_acelp ), shift ); +#endif } ELSE { diff --git a/lib_enc/cod_uv_fx.c b/lib_enc/cod_uv_fx.c index d795733b4..99636b306 100644 --- a/lib_enc/cod_uv_fx.c +++ b/lib_enc/cod_uv_fx.c @@ -20,6 +20,9 @@ *-------------------------------------------------------------------*/ void gauss_L2_fx( +#ifdef FIX_2424_REMOVE_GAUSS_L2_ENC + const Word16 element_mode, /* i : element mode */ +#endif const Word16 h[], /* i : weighted LP filter impulse response Q14+s */ Word16 code[], /* o : gaussian excitation Q9 */ const Word16 y2[], /* i : zero-memory filtered code. excitation Q9 */ @@ -35,6 +38,17 @@ void gauss_L2_fx( { Word16 i, tmp16; Word32 tmp32, tmp32_2; +#ifdef FIX_2424_REMOVE_GAUSS_L2_ENC + Word16 Q_fac; + + Q_fac = Q18; + move16(); + if ( element_mode != EVS_MONO ) + { + Q_fac = Q16; + move16(); + } +#endif assert( gain_pit == 0 ); @@ -64,25 +78,55 @@ void gauss_L2_fx( Scale_sig( y11, L_SUBFR, sub( 1, shift ) ); /* Q9 */ *gain = L_deposit_l( 0 ); move32(); + /*Update correlations for gains coding */ +#ifdef FIX_2424_REMOVE_GAUSS_L2_ENC + tmp32 = L_shr( 21474836l /*0.01f Q31*/, 31 - Q_fac ); /* Q_fac */ + tmp32_2 = L_shr( 21474836l /*0.01f Q31*/, 31 - Q_fac ); /* Q_fac */ +#else tmp32 = L_shr( 21474836l /*0.01f Q31*/, 31 - 18 ); /* Q18 */ tmp32_2 = L_shr( 21474836l /*0.01f Q31*/, 31 - 18 ); /* Q18 */ +#endif - FOR( i = 0; i < L_SUBFR; i++ ) +#ifdef FIX_2424_REMOVE_GAUSS_L2_ENC + IF( element_mode == EVS_MONO ) + { +#endif + FOR( i = 0; i < L_SUBFR; i++ ) + { + tmp32 = L_mac0_sat( tmp32, y11[i], y11[i] ); /* Q18 */ + tmp32_2 = L_mac0_sat( tmp32_2, y11[i], y2[i] ); /* Q18 */ + } +#ifdef FIX_2424_REMOVE_GAUSS_L2_ENC + } + ELSE { - tmp32 = L_mac0_sat( tmp32, y11[i], y11[i] ); /* Q18 */ - tmp32_2 = L_mac0_sat( tmp32_2, y11[i], y2[i] ); /* Q18 */ + FOR( i = 0; i < L_SUBFR; i++ ) + { + tmp16 = shr( y11[i], 1 ); + tmp32 = L_mac0( tmp32, tmp16, tmp16 ); /* Q16 */ + tmp32_2 = L_mac0( tmp32_2, tmp16, shr( y2[i], 1 ) ); /* Q16 */ + } } +#endif tmp16 = norm_l( tmp32 ); g_corr->y1y1 = round_fx_sat( L_shl( tmp32, tmp16 ) ); +#ifdef FIX_2424_REMOVE_GAUSS_L2_ENC + g_corr->y1y1_e = sub( sub( 31, Q_fac ), tmp16 ); +#else g_corr->y1y1_e = sub( 31 - 18, tmp16 ); +#endif move16(); move16(); tmp16 = norm_l( tmp32_2 ); g_corr->y1y2 = round_fx_sat( L_shl( tmp32_2, tmp16 ) ); +#ifdef FIX_2424_REMOVE_GAUSS_L2_ENC + g_corr->y1y2_e = sub( sub( 31, Q_fac ), tmp16 ); +#else g_corr->y1y2_e = sub( 31 - 18, tmp16 ); +#endif move16(); move16(); diff --git a/lib_enc/enc_uv_fx.c b/lib_enc/enc_uv_fx.c index 256bb92e2..118fc8251 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -180,13 +180,13 @@ void encod_unvoiced_fx( move16(); move16(); -#ifndef FIX_2424_REMOVE_GAUSS_L2_ENC +#ifdef FIX_2424_REMOVE_GAUSS_L2_ENC + gauss_L2_fx( st_fx->element_mode, h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift ); +#else assert( gain_pit_fx == 0 ); IF( st_fx->element_mode == EVS_MONO ) { -#endif gauss_L2_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift ); -#ifndef FIX_2424_REMOVE_GAUSS_L2_ENC } ELSE { diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index c2d066b75..643d96912 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2132,6 +2132,9 @@ void E_ACELP_xy2_corr( Word16 exp_xn ); void gauss_L2_fx( +#ifdef FIX_2424_REMOVE_GAUSS_L2_ENC + const Word16 element_mode, /* i : element mode */ +#endif const Word16 h[], /* i : weighted LP filter impulse response Q14+s */ Word16 code2[], /* o : gaussian excitation Q9 */ const Word16 y2[], /* i : zero-memory filtered code. excitation Q9 */ -- GitLab