From 3004191cceae8a9839a688dd2bff81a35cc7e9a0 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sun, 19 Jan 2025 17:14:35 +0530 Subject: [PATCH 1/2] ASAN/MSAN fixes for encoder and decoder, win_lpc_hb_wb table added inline with float code --- lib_com/rom_com.c | 19 +++++++++++++++++++ lib_com/rom_com.h | 1 + lib_dec/gs_dec_fx.c | 5 ++++- lib_enc/acelp_core_enc_fx.c | 1 + lib_enc/enc_tran_fx.c | 5 +++++ lib_enc/ivas_stereo_icbwe_enc.c | 4 ++++ lib_enc/ivas_tcx_core_enc.c | 17 +++++++++++++++++ lib_enc/ivas_td_low_rate_enc.c | 4 ++++ lib_enc/swb_tbe_enc_fx.c | 6 ++---- 9 files changed, 57 insertions(+), 5 deletions(-) diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index 612e30bdf..5e61db76e 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -14271,6 +14271,25 @@ const Word16 win_lpc_hb_wb_fx[(L_LOOK_12k8 + L_SUBFR + L_FRAME) * 5 / 32] = 32611, 32698, 32751 }; +const Word16 win_lpc_hb_wb_ivas_fx[(L_LOOK_12k8 + L_SUBFR + L_FRAME) * 5 / 32] = +{//Q15 + 6, 51, 140, 274, + 453, 675, 940, 1247, + 1596, 1985, 2414, 2882, + 3386, 3926, 4499, 5106, + 5743, 6410, 7104, 7823, + 8566, 9331, 10114, 10915, + 11731, 12559, 13398, 14245, + 15099, 15955, 16813, 17669, + 18523, 19370, 20209, 21037, + 21853, 22654, 23437, 24202, + 24945, 25664, 26358, 27025, + 27662, 28269, 28842, 29382, + 29886, 30354, 30783, 31172, + 31521, 31828, 32093, 32315, + 32494, 32628, 32717, 32762 +}; + const Word16 ola_win_shb_switch_fold_fx[L_SUBFR16k] = {//Q15 diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 431c6b704..19447609c 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -612,6 +612,7 @@ extern const Word16 cos_fb_exc_fx[32]; // Q15 extern const Word16 win_lpc_shb_fx[]; // Q15 /* Window for calculating SHB LPC coeffs */ extern const Word16 win_lpc_hb_wb_fx[]; // Q15 +extern const Word16 win_lpc_hb_wb_ivas_fx[]; // Q15 extern const Word16 ola_win_shb_switch_fold_fx[]; // Q15 extern const Word16 win_flatten_fx[]; // Q15 extern const Word16 win_flatten_4k_fx[]; // Q15 diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c index 670b19400..c237bc987 100644 --- a/lib_dec/gs_dec_fx.c +++ b/lib_dec/gs_dec_fx.c @@ -1587,7 +1587,10 @@ void gsc_dec_ivas_fx( { pvq_core_dec_fx( st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); #ifdef MSAN_FIX - Scale_sig( concat_out, s_max( gsc_sfm_end[nb_subbands - 1], 0 ), sub( Q_PVQ_OUT, Q_tmp ) ); /* Q_PVQ_OUT */ + IF( nb_subbands > 0 ) + { + Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); /* Q_PVQ_OUT */ + } #else Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); /* Q_PVQ_OUT */ #endif diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index 9497234a1..62596fa8f 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -867,6 +867,7 @@ ivas_error acelp_core_enc_ivas_fx( Word32 q_env_fx[NUM_ENV_CNG]; #ifdef MSAN_FIX set32_fx( q_env_fx, 0, NUM_ENV_CNG ); + set16_fx( exc2_fx, 0, L_FRAME16k ); #endif Word16 exc3_fx[L_FRAME16k]; Word16 syn1_fx[L_FRAME16k]; diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c index 71e8b9e3b..6f9cb9c6a 100644 --- a/lib_enc/enc_tran_fx.c +++ b/lib_enc/enc_tran_fx.c @@ -508,6 +508,11 @@ Word16 encod_tran_ivas_fx( L_frame_fx = st_fx->L_frame; move16(); + +#ifdef MSAN_FIX + set16_fx( h1, 0, L_SUBFR + ( M + 1 ) ); +#endif + /*------------------------------------------------------------------* * Initializations *------------------------------------------------------------------*/ diff --git a/lib_enc/ivas_stereo_icbwe_enc.c b/lib_enc/ivas_stereo_icbwe_enc.c index f21cf3531..607dc6b92 100644 --- a/lib_enc/ivas_stereo_icbwe_enc.c +++ b/lib_enc/ivas_stereo_icbwe_enc.c @@ -1198,6 +1198,10 @@ void stereo_icBWE_preproc_fx( Word32 gD_fx; Word32 input_Fs; +#ifdef MSAN_FIX + set16_fx( temp_inp_fx, 0, L_FRAME48k ); +#endif + /* initialization */ hStereoTCA = hCPE->hStereoTCA; /* Stereo TCA encoder handle */ hStereoICBWE = hCPE->hStereoICBWE; /* Stereo IC BWE encoder handle */ diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index e8a81147a..8c034e73c 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -810,6 +810,13 @@ Word16 ivas_acelp_tcx20_switching_fx( #ifdef MSAN_FIX set16_fx( window_fx, 0, L_LOOK_16k ); set16_fx( xn_buf_fx, 0, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX ); + FOR( i = 0; i < L_LOOK_16k; i++ ) + { + window_p_fx[i].v.re = 0; + move16(); + window_p_fx[i].v.im = 0; + move16(); + } #endif L_frame_tmp = L_frame; @@ -865,6 +872,15 @@ Word16 ivas_acelp_tcx20_switching_fx( overlap = st->hTcxCfg->tcx_mdct_window_delay; move16(); +#ifdef MSAN_FIX + FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_length / 2; i++ ) + { + window_fx[st->hTcxCfg->tcx_mdct_window_length / 2 - 1 - i] = st->hTcxCfg->tcx_mdct_window[i].v.re; // Q15 + move16(); + window_fx[i] = st->hTcxCfg->tcx_mdct_window[i].v.im; // Q15 + move16(); + } +#else FOR( i = 0; i < L_LOOK_16k / 2; i++ ) { window_fx[L_LOOK_16k / 2 - 1 - i] = st->hTcxCfg->tcx_mdct_window[i].v.re; // Q15 @@ -872,6 +888,7 @@ Word16 ivas_acelp_tcx20_switching_fx( window_fx[i] = st->hTcxCfg->tcx_mdct_window[i].v.im; // Q15 move16(); } +#endif } ELSE { diff --git a/lib_enc/ivas_td_low_rate_enc.c b/lib_enc/ivas_td_low_rate_enc.c index 22ce9b6e9..95762fa29 100644 --- a/lib_enc/ivas_td_low_rate_enc.c +++ b/lib_enc/ivas_td_low_rate_enc.c @@ -222,6 +222,10 @@ void encod_gen_2sbfr( LPD_state_HANDLE hLPDmem = st->hLPDmem; +#ifdef MSAN_FIX + set16_fx( cn, 0, 2 * L_SUBFR ); /* Target vector in residual domain */ +#endif + /*------------------------------------------------------------------* * Initializations *------------------------------------------------------------------*/ diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 0772fc336..f9c56d6e4 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -1208,7 +1208,7 @@ void wb_tbe_enc_fx( tmp = round_fx_o( L_tmp, &Overflow ); /* Q15 */ #else /* BASOP_NOGLOB */ L_tmp = L_shl( L_tmp, add( exp, 10 ) ); - tmp = round_fx( L_tmp ); /* Q15 */ + tmp = round_fx( L_tmp ); /* Q15 */ #endif } @@ -1379,7 +1379,7 @@ void wb_tbe_enc_ivas_fx( } } - autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, ( ( NS2SA( INT_FS_12k8, 5000000L ) + L_SUBFR + L_FRAME ) * 5 / 16 ), win_lpc_hb_wb_fx, 0, 1 ); + autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, ( ( NS2SA( INT_FS_12k8, 5000000L ) + L_SUBFR + L_FRAME ) * 5 / 16 ), win_lpc_hb_wb_ivas_fx, 0, 1 ); E_LPC_lev_dur( R_h, R_l, lpc_wb_temp_fx, LepsP, LPC_SHB_ORDER_WB, NULL ); // Since 0th index will be 1 in floating point buffer, in fixed point one has to take norm of 0th index to identify the Q-factor @@ -1638,14 +1638,12 @@ void wb_tbe_enc_ivas_fx( rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); - Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); FOR( i = 0; i < L_FRAME32k; i++ ) { bwe_exc_extended_16[i + NL_BUFF_OFFSET] = round_fx( L_shl( bwe_exc_extended[i], sc ) ); move16(); } - Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); -- GitLab From 0b241bd0dd6c9ff0c546222efe7296b954a1ee2d Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sun, 19 Jan 2025 17:17:54 +0530 Subject: [PATCH 2/2] Formatting changes --- lib_enc/swb_tbe_enc_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index f9c56d6e4..97587d144 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -1208,7 +1208,7 @@ void wb_tbe_enc_fx( tmp = round_fx_o( L_tmp, &Overflow ); /* Q15 */ #else /* BASOP_NOGLOB */ L_tmp = L_shl( L_tmp, add( exp, 10 ) ); - tmp = round_fx( L_tmp ); /* Q15 */ + tmp = round_fx( L_tmp ); /* Q15 */ #endif } -- GitLab