From 556608f757feebcf49295e970bdd086d6c42fcce Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 20 Mar 2025 15:47:00 +0530 Subject: [PATCH] Bug fix in CNG_enc_ivas_fx, saturation removal and correction of macro value for MASA path --- lib_com/ivas_cnst.h | 2 +- lib_com/rom_com.c | 15 +++++++++++++++ lib_com/rom_com.h | 19 ++++++++++--------- lib_com/swb_tbe_com_fx.c | 2 +- lib_enc/cng_enc_fx.c | 8 ++++---- lib_enc/swb_tbe_enc_fx.c | 24 ++++++++++++------------ 6 files changed, 43 insertions(+), 27 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 2abb790f1..9243b3f50 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1285,7 +1285,7 @@ enum #define MASA_RATIO_THRESHOLD 0.1f #define MASA_ANGLE_TOLERANCE 0.5f #define MASA_RATIO_THRESHOLD_FX 214748365 // 0.1 in Q31 -#define MASA_RATIO_TOLERANCE_FX 214748364/*0.1 Q30*/ +#define MASA_RATIO_TOLERANCE_FX 107374182 // 0.1 in Q30 #define MASA_ANGLE_TOLERANCE_FX ONE_IN_Q21 // 0.5 in Q22 #define MASA_LIMIT_NO_BANDS_SUR_COH 8 #define MINIMUM_BIT_BUDGET_NORMAL_META 100 diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index 87b323d0a..e6f392ff0 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -25351,6 +25351,21 @@ const Word16 lsp_shb_prev_tbl_fx[LPC_SHB_ORDER] = { 13107, 14746 }; + +const Word16 lsp_shb_prev_tbl_swb_tbe_enc_fx[LPC_SHB_ORDER] = { + // Q15 + 32767, + 31165, + 26509, + 19262, + 10123, + 0, + -10124, + -19261, + -26509, + -31166, +}; + const Word16 ivas_lsp_shb_prev_tbl_fx[LPC_SHB_ORDER] = { /* Q15 */ 1489, diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 10bce5bb2..73156b989 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -1504,15 +1504,16 @@ extern const Word16 tab_hup_l_fx[]; // Q15 extern const Word16 mfreq_loc_Q2fx[]; // Q0 extern const Word16 mfreq_loc_div_25[]; // Q0 -extern const Word16 band_len_idx[]; // Q0 -extern const Word16 band_len_ener_shift[]; // Q0 -extern const Word16 fine_gain_pred_sqrt_bw[]; // Q11 -extern const Word16 ivas_band_len_idx[]; // Q0 -extern const Word16 ivas_band_len_ener_shift[]; // Q0 -extern const Word16 ivas_fine_gain_pred_sqrt_bw[]; // Q11 -extern const Word16 Mean_isf_wb[]; // Q2.56 -extern const Word16 lsp_shb_prev_tbl_fx[]; // Q15 -extern const Word16 ivas_lsp_shb_prev_tbl_fx[]; // Q15 +extern const Word16 band_len_idx[]; // Q0 +extern const Word16 band_len_ener_shift[]; // Q0 +extern const Word16 fine_gain_pred_sqrt_bw[]; // Q11 +extern const Word16 ivas_band_len_idx[]; // Q0 +extern const Word16 ivas_band_len_ener_shift[]; // Q0 +extern const Word16 ivas_fine_gain_pred_sqrt_bw[]; // Q11 +extern const Word16 Mean_isf_wb[]; // Q2.56 +extern const Word16 lsp_shb_prev_tbl_fx[]; // Q15 +extern const Word16 lsp_shb_prev_tbl_swb_tbe_enc_fx[]; // Q15 +extern const Word16 ivas_lsp_shb_prev_tbl_fx[]; // Q15 extern const Word16 tab_ari_qnew[4][4]; // enhancer.c diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 238478b1a..04b6ba187 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -930,7 +930,7 @@ static void Calc_st_filt_tbe_ivas_enc_fx( { L_g0 = L_mac0( L_g0, 1, abs_s( h[i] ) ); } - g0 = extract_h( L_shl_sat( L_g0, 14 ) ); + g0 = extract_h( L_shl( L_g0, 14 ) ); /* Scale signal i of 1/A(gamma1) */ IF( GT_16( g0, 1024 ) ) diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c index b65d41403..99e99bef7 100644 --- a/lib_enc/cng_enc_fx.c +++ b/lib_enc/cng_enc_fx.c @@ -1305,19 +1305,19 @@ void CNG_enc_ivas_fx( move16(); BREAK; case L_FRAME32k: - inv_frame_len = ONE_BY_L_FRAME48k_Q31; + inv_frame_len = ONE_BY_L_FRAME32k_Q31; move16(); BREAK; case L_FRAME16k: - inv_frame_len = ONE_BY_L_FRAME48k_Q31; + inv_frame_len = ONE_BY_L_FRAME16k_Q31; move16(); BREAK; case L_FRAME8k: - inv_frame_len = ONE_BY_L_FRAME48k_Q31; + inv_frame_len = ONE_BY_L_FRAME8k_Q31; move16(); BREAK; case L_FRAME4k: - inv_frame_len = ONE_BY_L_FRAME48k_Q31; + inv_frame_len = ONE_BY_L_FRAME4k_Q31; move16(); BREAK; default: diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index ba8ee5aa8..9b4f15dc5 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -21,7 +21,6 @@ #define ENVSHBRES_ACORR_MIN 40 /* minimum lag for calculating autocorrelation function on SHB residual TD envelope */ #define ENVSHBRES_ACORR_MAX 80 /* maximum lag for calculating autocorrelation function on SHB residual TD envelope */ - /*-----------------------------------------------------------------* * Local functions *-----------------------------------------------------------------*/ @@ -551,7 +550,7 @@ void InitSWBencBuffer_ivas_fx( FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->prev_lsp_shb_fx[i] = lsp_shb_prev_tbl_fx[i]; + hBWE_TD->prev_lsp_shb_fx[i] = lsp_shb_prev_tbl_swb_tbe_enc_fx[i]; move16(); } @@ -3109,14 +3108,7 @@ void swb_tbe_enc_ivas_fx( } } - /* stab_check = a2lsp( lsf_shb, lpc_shb, LPC_SHB_ORDER ); - stab_check missing */ - /* LPC to LSP conversion */ - /* LPC: Q12, LSP: Q15 */ - E_LPC_a_lsp_conversion( lpc_shb_fx, lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); - - /* LSP to LSF conversion */ - /* LSP: Q15, LSF: Q15 */ - E_LPC_lsp_lsf_conversion( lsp_shb_fx, lsf_shb_fx, LPC_SHB_ORDER ); + /* stab_check = a2lsp( lsf_shb, lpc_shb, LPC_SHB_ORDER ); */ test(); test(); @@ -3124,8 +3116,8 @@ void swb_tbe_enc_ivas_fx( { FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - // hBWE_TD->prev_lsp_shb_fx[i] = i / 20.0f; - hBWE_TD->prev_lsp_shb_fx[i] = lsp_shb_prev_tbl_fx[i]; + // hBWE_TD->prev_lsp_shb_fx[i] = i / 20.0f; // This value in float enc is lsf. + hBWE_TD->prev_lsp_shb_fx[i] = lsp_shb_prev_tbl_swb_tbe_enc_fx[i]; // lsf converted to lsp as fixed enc stores lsp. move16(); } } @@ -3135,6 +3127,14 @@ void swb_tbe_enc_ivas_fx( // mvr2r( hBWE_TD->prev_lsp_shb, lsf_shb, LPC_SHB_ORDER ); // } + /* LPC to LSP conversion */ + /* LPC: Q12, LSP: Q15 */ + E_LPC_a_lsp_conversion( lpc_shb_fx, lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); + + /* LSP to LSF conversion */ + /* LSP: Q15, LSF: Q15 */ + E_LPC_lsp_lsf_conversion( lsp_shb_fx, lsf_shb_fx, LPC_SHB_ORDER ); + Copy( lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); Copy( lsf_shb_fx, lsf_shb_orig_fx, LPC_SHB_ORDER ); -- GitLab