From 2db4f9f05c3e3fb5c500f3e565d10e155072207d Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 17 Jul 2024 21:54:40 +0530 Subject: [PATCH 1/2] ASAN and MSAN fixes, LTV crash fix for -10dB stereo stream [x] ASAN error fixes [x] MSAN error fixes [x] Fix for ltv-Stereo downmix to bit-exact EVS at 13200 kbps, 32kHz in, 32kHz out crash for -10dB stream --- lib_com/hq2_bit_alloc_fx.c | 12 ++++++++++++ lib_com/ivas_prot.h | 14 +++++++------- lib_dec/ivas_sba_rendering_internal.c | 5 +++-- lib_enc/init_enc.c | 3 +++ lib_enc/ivas_core_pre_proc_front.c | 9 +++++---- lib_enc/ivas_mc_paramupmix_enc.c | 4 ++++ lib_enc/speech_music_classif.c | 5 +++-- 7 files changed, 37 insertions(+), 15 deletions(-) diff --git a/lib_com/hq2_bit_alloc_fx.c b/lib_com/hq2_bit_alloc_fx.c index 1f5a146c0..c43b11ae5 100644 --- a/lib_com/hq2_bit_alloc_fx.c +++ b/lib_com/hq2_bit_alloc_fx.c @@ -312,6 +312,12 @@ void hq2_bit_alloc_har_fx( Word16 exp_shift; +#ifdef BASOP_NOGLOB + Flag Overflow; + Overflow = 0; + move32(); +#endif + L_THR1 = L_shl( L_deposit_l( THR1 ), SWB_BWE_LR_QRk ); L_THR2 = L_shl( L_deposit_l( THR2 ), SWB_BWE_LR_QRk ); L_THR3 = L_shl( L_deposit_l( THR3 ), SWB_BWE_LR_QRk ); @@ -566,7 +572,13 @@ void hq2_bit_alloc_har_fx( L_temp = Mult_32_16( L_Ravg_sub[GRP_SB - 1], sub( GRP_SB, 1 ) ); /* Qbe+0+1 */ L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); /* Qbe+1+QIpb+1 */ +#ifdef BASOP_NOGLOB + lf_hf_ge_r_fx = round_fx_o( L_shl_o( L_temp, sub( 15 + 16, sub( add( SWB_BWE_LR_Qbe, QIns ), 30 ) ), &Overflow ), &Overflow ); + Overflow = 0; /* reset BASOP Overflow */ + move32(); +#else lf_hf_ge_r_fx = round_fx( L_shl( L_temp, sub( 15 + 16, sub( add( SWB_BWE_LR_Qbe, QIns ), 30 ) ) ) ); +#endif exp_normn = norm_s( norm_sum_fx ); exp_normn = sub( exp_normn, 1 ); diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 5dcff25ea..e476e3a49 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5521,13 +5521,13 @@ ivas_error ivas_sba_linear_renderer( ); #ifdef IVAS_FLOAT_FIXED void ivas_sba_mix_matrix_determiner_fx( - SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - Word32 *output_fx[], /* i/o: transport/output audio channels */ - const Word16 bfi, /* i : BFI flag */ - const Word16 nchan_remapped, /* i : num channels after remapping of TCs */ - const Word16 output_frame, /* i : output frame length */ - const Word16 num_md_sub_frames, /* i : number of subframes in mixing matrix */ - const Word16 Q_p_Output /* i : number of subframes in mixing matrix */ + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + Word32 *output_fx[], /* i/o: transport/output audio channels */ + const Word16 bfi, /* i : BFI flag */ + const Word16 nchan_remapped, /* i : num channels after remapping of TCs */ + const Word16 output_frame, /* i : output frame length */ + const Word16 num_md_sub_frames, /* i : number of subframes in mixing matrix*/ + const Word16 Q_output /* i : Q of transport/output audio channels */ ); #endif // IVAS_FLOAT_FIXED diff --git a/lib_dec/ivas_sba_rendering_internal.c b/lib_dec/ivas_sba_rendering_internal.c index e925bd3e6..19113a09a 100644 --- a/lib_dec/ivas_sba_rendering_internal.c +++ b/lib_dec/ivas_sba_rendering_internal.c @@ -861,7 +861,7 @@ void ivas_sba_mix_matrix_determiner_fx( const Word16 nchan_remapped, /* i : num channels after remapping of TCs */ const Word16 output_frame, /* i : output frame length */ const Word16 num_md_sub_frames, /* i : number of subframes in mixing matrix*/ - const Word16 Q_output /* i : number of subframes in mixing matrix*/ + const Word16 Q_output /* i : Q of transport/output audio channels */ ) { Word16 i, ch; @@ -899,6 +899,7 @@ void ivas_sba_mix_matrix_determiner_fx( nchan_out = nchan_transport; move16(); ivas_agc_dec_process_fx( hSpar->hAgcDec, ( output_fx ), ( output_fx ), nchan_transport, output_frame ); + Q_p_output = sub( Q_p_output, 3 ); #ifdef DUMPS_ENABLED dbgwrite_txt( &output[0][0], output_frame, "fix_ivas_agc_dec_process_output.txt", NULL ); #endif // DUMPS_ENABLED @@ -908,7 +909,7 @@ void ivas_sba_mix_matrix_determiner_fx( { FOR( i = 0; i < output_frame; i++ ) { - output_fx[ch][i] = Mult_32_32( L_shl_sat( output_fx[ch][i], sub( 18, Q_p_output ) ), L_shl_sat( PCM16_TO_FLT_FAC_FX, 16 ) ); /*Q-0*/ + output_fx[ch][i] = Mult_32_32( L_shl_sat( output_fx[ch][i], sub( 15, Q_p_output ) ), L_shl_sat( PCM16_TO_FLT_FAC_FX, 16 ) ); /* Q0 */ } } diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index f0e08363a..44b398a89 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -490,6 +490,9 @@ ivas_error init_encoder( st->lp_speech = 45.0f; /* Initialize the long-term active speech level in dB */ st->lp_noise = 0.0f; +#ifdef IVAS_FLOAT_FIXED + st->lp_noise_fx = 0; +#endif st->flag_noisy_speech_snr = 0; st->fd_cng_reset_flag = 0; st->cng_type = -1; diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index acf656866..344d03098 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -920,7 +920,7 @@ ivas_error pre_proc_front_ivas_fx( float sp_div, PS[128]; /* speech/music clasif. parameters */ int16_t L_look; /* length of look-ahead */ #if 1 - float snr_sum_he; /* HE SAD parameters */ + float snr_sum_he; /* HE SAD parameters */ #endif float mem_decim_dummy[2 * L_FILT_MAX]; /* dummy decimation filter memory */ float temp1F_icatdmResampBuf[L_FILT_MAX]; /* temp buffers for ICA TDM resamplers */ @@ -962,8 +962,8 @@ ivas_error pre_proc_front_ivas_fx( Word16 *temp1F_icatdmResampBuf_fx; Word16 *old_inp_12k8_fx; Word16 *old_inp_16k_fx; - Word16 *mem_decim_dummy_fx; /* dummy decimation filter memory */ - Word32 Etot_fx; /* total energy */ + Word16 *mem_decim_dummy_fx; /* dummy decimation filter memory */ + Word32 Etot_fx; /* total energy */ #if 0 Word32 fr_bands_fx[2 * NB_BANDS]; /* energy in frequency bands */ Word16 Q_new; @@ -1354,7 +1354,7 @@ ivas_error pre_proc_front_ivas_fx( { mvr2r( new_inp_12k8, st->buf_speech_enc_flt + L_FRAME32k, L_FRAME ); } -#ifndef MSAN_FIX /*To be enabled when updations related to new_inp_12k8_fx is enabled */ +#ifndef MSAN_FIX/*To be enabled when updations related to new_inp_12k8_fx is enabled */ #if 1 IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { @@ -1730,6 +1730,7 @@ ivas_error pre_proc_front_ivas_fx( st->lt_mean_NB_fx = (Word16) st->lt_mean_NB * ( 1 << 11 ); st->lt_mean_WB_fx = (Word16) st->lt_mean_WB * ( 1 << 11 ); st->lt_mean_SWB_fx = (Word16) st->lt_mean_SWB * ( 1 << 11 ); + st->lp_noise_fx = (Word16) st->lp_noise * ( 1 << 8 ); //have taken Q8 as above one functions uses Q8 #endif bw_detect_fx( st, st->input_fx, NULL, enerBuffer_fx, sf_energySum, ivas_format, 0 ); diff --git a/lib_enc/ivas_mc_paramupmix_enc.c b/lib_enc/ivas_mc_paramupmix_enc.c index ea0fd5bfb..9c3d0bfb1 100644 --- a/lib_enc/ivas_mc_paramupmix_enc.c +++ b/lib_enc/ivas_mc_paramupmix_enc.c @@ -859,7 +859,11 @@ static void ivas_mc_paramupmix_param_est_enc( } set_s( q_ppIn_FR, Q31, MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH ); +#ifdef MSAN_FIX + FOR( i = 0; i < MC_PARAMUPMIX_NCH; i++ ) +#else FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH; i++ ) +#endif { q_ppIn_FR[i] = L_get_q_buf1( pp_in_fr_real[i], input_frame ); q_ppIn_FR[i] = min( q_ppIn_FR[i], L_get_q_buf1( pp_in_fr_imag[i], input_frame ) ); diff --git a/lib_enc/speech_music_classif.c b/lib_enc/speech_music_classif.c index 8f536dbd5..8ff7d2545 100644 --- a/lib_enc/speech_music_classif.c +++ b/lib_enc/speech_music_classif.c @@ -126,6 +126,7 @@ void speech_music_clas_init( hSpMusClas->dlp_var_LT_fx = 0; #ifdef MSAN_FIX hSpMusClas->dlp_mean_LT_fx = 0; + set16_fx( hSpMusClas->past_dlp_fx, 0, HANG_LEN - 1 ); #endif // MSAN_FIX #endif hSpMusClas->dlp_mean_LT = 0.0f; @@ -135,8 +136,8 @@ void speech_music_clas_init( { hSpMusClas->prev_FV[i] = 0.5f * hout_intervals[2 * i] + 0.5f * hout_intervals[2 * i + 1]; #ifdef IVAS_FLOAT_FIXED - hSpMusClas->prev_FV_fx[i] = (Word32) ( hSpMusClas->prev_FV[i] * ONE_IN_Q20 ); -#endif + hSpMusClas->prev_FV_fx[i] =( Word32)( hSpMusClas->prev_FV[i] * ONE_IN_Q20 ); + #endif } for ( i = 0; i < NB_BANDS_SPMUS; i++ ) -- GitLab From cda92559b6c5c1012724cf35323b5b3faa6dc3bc Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 17 Jul 2024 22:02:32 +0530 Subject: [PATCH 2/2] Clang formatting changes --- lib_enc/ivas_core_pre_proc_front.c | 10 +++++----- lib_enc/speech_music_classif.c | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 344d03098..616d5cc15 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -920,7 +920,7 @@ ivas_error pre_proc_front_ivas_fx( float sp_div, PS[128]; /* speech/music clasif. parameters */ int16_t L_look; /* length of look-ahead */ #if 1 - float snr_sum_he; /* HE SAD parameters */ + float snr_sum_he; /* HE SAD parameters */ #endif float mem_decim_dummy[2 * L_FILT_MAX]; /* dummy decimation filter memory */ float temp1F_icatdmResampBuf[L_FILT_MAX]; /* temp buffers for ICA TDM resamplers */ @@ -962,8 +962,8 @@ ivas_error pre_proc_front_ivas_fx( Word16 *temp1F_icatdmResampBuf_fx; Word16 *old_inp_12k8_fx; Word16 *old_inp_16k_fx; - Word16 *mem_decim_dummy_fx; /* dummy decimation filter memory */ - Word32 Etot_fx; /* total energy */ + Word16 *mem_decim_dummy_fx; /* dummy decimation filter memory */ + Word32 Etot_fx; /* total energy */ #if 0 Word32 fr_bands_fx[2 * NB_BANDS]; /* energy in frequency bands */ Word16 Q_new; @@ -1354,7 +1354,7 @@ ivas_error pre_proc_front_ivas_fx( { mvr2r( new_inp_12k8, st->buf_speech_enc_flt + L_FRAME32k, L_FRAME ); } -#ifndef MSAN_FIX/*To be enabled when updations related to new_inp_12k8_fx is enabled */ +#ifndef MSAN_FIX /*To be enabled when updations related to new_inp_12k8_fx is enabled */ #if 1 IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { @@ -1730,7 +1730,7 @@ ivas_error pre_proc_front_ivas_fx( st->lt_mean_NB_fx = (Word16) st->lt_mean_NB * ( 1 << 11 ); st->lt_mean_WB_fx = (Word16) st->lt_mean_WB * ( 1 << 11 ); st->lt_mean_SWB_fx = (Word16) st->lt_mean_SWB * ( 1 << 11 ); - st->lp_noise_fx = (Word16) st->lp_noise * ( 1 << 8 ); //have taken Q8 as above one functions uses Q8 + st->lp_noise_fx = (Word16) st->lp_noise * ( 1 << 8 ); // have taken Q8 as above one functions uses Q8 #endif bw_detect_fx( st, st->input_fx, NULL, enerBuffer_fx, sf_energySum, ivas_format, 0 ); diff --git a/lib_enc/speech_music_classif.c b/lib_enc/speech_music_classif.c index 8ff7d2545..e41e50052 100644 --- a/lib_enc/speech_music_classif.c +++ b/lib_enc/speech_music_classif.c @@ -136,8 +136,8 @@ void speech_music_clas_init( { hSpMusClas->prev_FV[i] = 0.5f * hout_intervals[2 * i] + 0.5f * hout_intervals[2 * i + 1]; #ifdef IVAS_FLOAT_FIXED - hSpMusClas->prev_FV_fx[i] =( Word32)( hSpMusClas->prev_FV[i] * ONE_IN_Q20 ); - #endif + hSpMusClas->prev_FV_fx[i] = (Word32) ( hSpMusClas->prev_FV[i] * ONE_IN_Q20 ); +#endif } for ( i = 0; i < NB_BANDS_SPMUS; i++ ) -- GitLab