From 8b3835aed14dd4a3aa0d3436db146b0a3fb1f8f7 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 16 May 2025 12:26:14 +0530 Subject: [PATCH 1/3] Fix for 3GPP issue 1469: Somewhat high MLD on a single MASA selection test material case with BASOP decoder Link #1469 --- lib_com/prot_fx.h | 2 +- lib_com/stat_noise_uv_mod_fx.c | 58 +++++++++++++++++++--------------- lib_dec/acelp_core_dec_fx.c | 6 ++++ lib_dec/stat_noise_uv_dec_fx.c | 2 +- lib_enc/acelp_core_enc_fx.c | 5 +-- lib_enc/prot_fx_enc.h | 2 +- lib_enc/stat_noise_uv_enc_fx.c | 2 +- 7 files changed, 45 insertions(+), 32 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 6d3e28de2..a1e633c17 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -8234,7 +8234,7 @@ void stat_noise_uv_mod_ivas_fx( const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q=15*/ Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q=12*/ Word16 *exc2, /* i/o: excitation buffer Q=Q_exc*/ - Word16 Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ + Word16 *Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ const Word16 bfi, /* i : Bad frame indicator */ Word32 *ge_sm, /* i/o: smoothed excitation gain Q=Q_stat_noise_ge (6)*/ Word16 *uv_count, /* i/o: unvoiced counter */ diff --git a/lib_com/stat_noise_uv_mod_fx.c b/lib_com/stat_noise_uv_mod_fx.c index 67ca21cd2..c259745f2 100644 --- a/lib_com/stat_noise_uv_mod_fx.c +++ b/lib_com/stat_noise_uv_mod_fx.c @@ -330,7 +330,6 @@ void stat_noise_uv_mod_fx( } } } - /*--------------------------------------------------------------------* * stat_noise_uv_mod() * @@ -345,7 +344,7 @@ void stat_noise_uv_mod_ivas_fx( const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q=15*/ Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q=12*/ Word16 *exc2, /* i/o: excitation buffer Q=Q_exc*/ - Word16 Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ + Word16 *Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ const Word16 bfi, /* i : Bad frame indicator */ Word32 *ge_sm, /* i/o: smoothed excitation gain Q=Q_stat_noise_ge (6)*/ Word16 *uv_count, /* i/o: unvoiced counter */ @@ -370,8 +369,9 @@ void stat_noise_uv_mod_ivas_fx( Word16 oldlsp_mix[M]; Word16 midlsp_mix[M]; Word16 newlsp_mix[M]; - Word16 beta; /* Q15 */ - Word16 Noimix_fract; /* (noimix_fac - 1.0) in Q15 */ + Word16 beta; /* Q15 */ + Word16 Noimix_fract; /* (noimix_fac - 1.0) in Q15 */ + Word32 L_Noimix_fract; /* (noimix_fac - 1.0) in Q15 */ /* noimix_fax * x <-> x + Noimix_fract * x */ Word16 i_subfr; Word16 i, k; @@ -382,7 +382,8 @@ void stat_noise_uv_mod_ivas_fx( Word32 L_tmp_res, L_tmp, L_tmp3, L_Ge; Word16 En_shift, Tmp; - Word16 Exc2_local[L_FRAME]; /* local_copy in scaled Q_local*/ + Word16 Exc2_local[L_FRAME]; /* local_copy in scaled Q_local*/ + Word32 L_Exc2_local[L_FRAME]; /* local_copy in scaled Q_local*/ #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); @@ -437,9 +438,9 @@ void stat_noise_uv_mod_ivas_fx( Copy( exc2, Exc2_local, L_FRAME ); /* bound Q for internal use, optimization possible */ - Q_local = s_min( 11, s_max( -1, Q_exc ) ); + Q_local = s_min( 11, s_max( -1, *Q_exc ) ); /* local excitation Q and incoming excitation Q*/ - Qdiff = sub( Q_local, Q_exc ); + Qdiff = sub( Q_local, *Q_exc ); /* only shift if incoming Q is outside [11..-1] shift is done in energy calculations aswell */ Scale_sig( Exc2_local, L_FRAME, Qdiff ); /* current excitation Q and previous stat_noise states Q */ @@ -539,14 +540,11 @@ void stat_noise_uv_mod_ivas_fx( L_tmp_res = L_mac( 0, alpha, alpha ); L_tmp_res = L_mac( L_tmp_res, alpha_m1, alpha_m1 ); tmp_den = round_fx( L_Frac_sqrtQ31( L_tmp_res ) ); - - tmp_nom = sub( 32767, tmp_den ); - tmp_shift = norm_s( tmp_den ); - tmp_den = shl( tmp_den, tmp_shift ); - tmp_res = div_s( tmp_nom, tmp_den ); - - Noimix_fract = shr( tmp_res, tmp_shift ); /* float value is in range 0.0 to 0.42 */ - + Word16 exp_sqr = 0; + move16(); + tmp_res = BASOP_Util_Divide1616_Scale( 32767, tmp_den, &exp_sqr ); // 15-exp_sqr + Noimix_fract = tmp_res; // 15-exp_sqr + move16(); /* L_Ge might be 0 in unvoiced WB */ L_Ge = L_max( L_Ge, 1 ); tmp_shift = norm_l( L_Ge ); @@ -555,9 +553,7 @@ void stat_noise_uv_mod_ivas_fx( L_tmp_res = Mult_32_16( *ge_sm, tmp_res ); /* Q_stat_noise_ge+45-Q_local-Q_ge-tmp_shift-15 */ L_tmp_res = Mult_32_16( L_tmp_res, sub( 32767, beta ) ); /*30-Q_local-tmp_shift+15-15 */ L_tmp_res = L_add_sat( L_shl_sat( L_tmp_res, sub( add( Q_local, tmp_shift ), 15 ) ), beta ); /* Q15 */ - tmp_res = extract_h( L_shl_o( L_tmp_res, 15, &Overflow ) ); /* 15+15-16=14 */ - - Noimix_fract = extract_l( Mult_32_16( L_tmp_res, Noimix_fract ) ); /*15+15-15 */ + L_Noimix_fract = Mult_32_16( L_tmp_res, Noimix_fract ); /*15+15-exp_sqr-15 =15-exp_sqr */ FOR( i = 0; i < L_FRAME; i++ ) { @@ -573,18 +569,27 @@ void stat_noise_uv_mod_ivas_fx( randval = mult_r( 28378, randval ); /* Q downscaled by 2 bits ends up in Q14 */ /*sqrt(12.0f) in Q13*/ randval = extract_l( L_shl( Mult_32_16( L_Ge, randval ), sub( 1, *Q_stat_noise_ge ) ) ); /*Q_local+Q_ge+14-15+1-Q_ge=Q_local */ - L_tmp = L_mult( Exc2_local[i], alpha ); /* Q_local + 16 */ - L_tmp = L_mac( L_tmp, randval, alpha_m1 ); /* Q_local + 16 */ - L_tmp3 = Mult_32_16( L_tmp, Noimix_fract ); /* Q_local+16+15-15 */ - L_tmp = L_add_sat( L_tmp3, L_shl_sat( Mult_32_16( L_tmp, tmp_res ), 1 ) ); /* Q_local+16+14-15+1 */ - Exc2_local[i] = extract_h( L_tmp ); /*Q_local */ + L_tmp = L_mult( Exc2_local[i], alpha ); /* Q_local + 16 */ + L_tmp = L_mac( L_tmp, randval, alpha_m1 ); /* Q_local + 16 */ + L_tmp3 = Mult_32_32( L_tmp, L_Noimix_fract ); /* Q_local+16+15-exp_sqr-15 =Q_local +1 */ + L_Exc2_local[i] = L_add( L_shr( L_tmp3, 1 ), Mpy_32_32( L_tmp, L_tmp_res ) ); // Q_local + 16 +15 -31 = Q_local + move32(); + } + Word32 max_val; + maximum_abs_32_fx( L_Exc2_local, L_FRAME, &max_val ); + Word16 shift = 0; + move16(); + IF( GT_32( max_val, ONE_IN_Q15 ) ) + { + shift = norm_l( max_val ); + shift = sub( Q31 - Q15, shift ); + *Q_exc = sub( Q_local, shift ); // Q_exc = Q_local -shift move16(); } *Q_stat_noise = Q_local; /* update for next call, routine can only be called once every frame */ move16(); - Qdiff = sub( Q_exc, Q_local ); /* local excitation and incoming excitation */ - Scale_sig( Exc2_local, L_FRAME, Qdiff ); - Copy( Exc2_local, exc2, L_FRAME ); + + Copy_Scale_sig_32_16( L_Exc2_local, exc2, L_FRAME, negate( shift ) ); // Q_exc /*--------------------------------------------------------------------* * Generate low-pass filtered version of ISP coefficients @@ -635,6 +640,7 @@ void stat_noise_uv_mod_ivas_fx( } } } + /*---------------------------------------------------------------------------* * calc_tilt() * diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 2c72bba78..2fff712f9 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -1165,7 +1165,13 @@ ivas_error acelp_core_dec_fx( test(); IF( !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) && NE_16( st->nelp_mode_dec, 1 ) && !( EQ_16( st->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) ) { + Word16 temp_q_exc = st->Q_exc; + move16(); stat_noise_uv_dec_fx( st, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag ); + IF( NE_16( temp_q_exc, st->Q_exc ) ) + { + scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM + st->L_frame, sub( st->Q_exc, temp_q_exc ) ); + } } /*------------------------------------------------------------* diff --git a/lib_dec/stat_noise_uv_dec_fx.c b/lib_dec/stat_noise_uv_dec_fx.c index d2fa36b9b..4e4d7ca30 100644 --- a/lib_dec/stat_noise_uv_dec_fx.c +++ b/lib_dec/stat_noise_uv_dec_fx.c @@ -76,7 +76,7 @@ void stat_noise_uv_dec_fx( IF( !st_fx->Opt_AMR_WB ) { - stat_noise_uv_mod_fx( coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq, exc2, st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, + stat_noise_uv_mod_ivas_fx( coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq, exc2, &st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index ceba860a1..6ba21136e 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -1449,8 +1449,9 @@ ivas_error acelp_core_enc_ivas_fx( { /* exc2 buffer is needed only for updating of Aq[] which is needed for core switching */ Copy( exc_fx, exc2_fx, st->L_frame ); // Q_new - - stat_noise_uv_enc_ivas_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, Q_new ); + Word16 q_exc2 = Q_new; + move16(); + stat_noise_uv_enc_ivas_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, &q_exc2 ); } /*-----------------------------------------------------------------* diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 968ab0082..72137bdce 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2189,7 +2189,7 @@ void stat_noise_uv_enc_ivas_fx( Word16 *Aq, /* i : A(z) quantized for the 4 subframes Q=12 */ Word16 *exc2, /* i/o: excitation buffer Q=Q_stat_noise */ const Word16 uc_two_stage_flag, /* o : flag undicating two-stage UC */ - Word16 Q_new ); + Word16 *Q_new ); void analy_sp_fx( const Word16 element_mode, /* i : element mode */ diff --git a/lib_enc/stat_noise_uv_enc_fx.c b/lib_enc/stat_noise_uv_enc_fx.c index 1445559a1..24932542c 100644 --- a/lib_enc/stat_noise_uv_enc_fx.c +++ b/lib_enc/stat_noise_uv_enc_fx.c @@ -118,7 +118,7 @@ void stat_noise_uv_enc_ivas_fx( Word16 *Aq, /* i : A(z) quantized for the 4 subframes Q=12 */ Word16 *exc2, /* i/o: excitation buffer Q=Q_stat_noise */ const Word16 uc_two_stage_flag, /* o : flag undicating two-stage UC */ - Word16 Q_new ) + Word16 *Q_new ) { Word16 noisiness = 0; move16(); -- GitLab From 2af7b50f076aabae91b52c2ba32beca40c9b892a Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 16 May 2025 12:32:36 +0530 Subject: [PATCH 2/3] Clang formatting changes --- lib_com/prot_fx.h | 2 +- lib_dec/stat_noise_uv_dec_fx.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index a1e633c17..c7d35daca 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -8234,7 +8234,7 @@ void stat_noise_uv_mod_ivas_fx( const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q=15*/ Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q=12*/ Word16 *exc2, /* i/o: excitation buffer Q=Q_exc*/ - Word16 *Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ + Word16 *Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ const Word16 bfi, /* i : Bad frame indicator */ Word32 *ge_sm, /* i/o: smoothed excitation gain Q=Q_stat_noise_ge (6)*/ Word16 *uv_count, /* i/o: unvoiced counter */ diff --git a/lib_dec/stat_noise_uv_dec_fx.c b/lib_dec/stat_noise_uv_dec_fx.c index 4e4d7ca30..e2dc1460e 100644 --- a/lib_dec/stat_noise_uv_dec_fx.c +++ b/lib_dec/stat_noise_uv_dec_fx.c @@ -77,9 +77,9 @@ void stat_noise_uv_dec_fx( IF( !st_fx->Opt_AMR_WB ) { stat_noise_uv_mod_ivas_fx( coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq, exc2, &st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, - st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, - &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, - &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); + st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, + &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, + &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); } -- GitLab From 0a38b3a4e97fbdf7641bec3ca9173bf1e4131295 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 16 May 2025 14:45:18 +0530 Subject: [PATCH 3/3] Fix for EVS bitexactness issue --- lib_dec/stat_noise_uv_dec_fx.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib_dec/stat_noise_uv_dec_fx.c b/lib_dec/stat_noise_uv_dec_fx.c index e2dc1460e..c87e30ffe 100644 --- a/lib_dec/stat_noise_uv_dec_fx.c +++ b/lib_dec/stat_noise_uv_dec_fx.c @@ -76,10 +76,20 @@ void stat_noise_uv_dec_fx( IF( !st_fx->Opt_AMR_WB ) { - stat_noise_uv_mod_ivas_fx( coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq, exc2, &st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, - st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, - &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, - &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); + IF( st_fx->element_mode > EVS_MONO ) + { + stat_noise_uv_mod_ivas_fx( coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq, exc2, &st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, + st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, + &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, + &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); + } + ELSE + { + stat_noise_uv_mod_fx( coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq, exc2, st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, + st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, + &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, + &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); + } } -- GitLab