From 9014e450daa9f28cd26cc022a5e96ff7ebe0d7b8 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 21 Jan 2025 15:20:19 +0530 Subject: [PATCH 1/2] Q-documentation updates, MSAN fixes and bug-fixes --- Workspace_msvc/lib_enc.vcxproj | 12 +- Workspace_msvc/lib_enc.vcxproj.filters | 29 +- lib_com/ivas_cnst.h | 1 + lib_dec/hq_core_dec_fx.c | 3 + lib_dec/ivas_stereo_dft_dec_fx.c | 26 + lib_enc/igf_enc.c | 5 +- lib_enc/ivas_cpe_enc.c | 19 +- lib_enc/ivas_stereo_classifier.c | 50 +- lib_enc/ivas_stereo_dft_enc.c | 6 +- lib_enc/ivas_stereo_eclvq_enc.c | 65 ++- lib_enc/ivas_stereo_ica_enc.c | 8 +- lib_enc/spec_center.c | 42 -- lib_enc/spec_flatness.c | 42 -- lib_enc/speech_music_classif.c | 46 -- lib_enc/stat_noise_uv_enc.c | 41 -- lib_enc/subband_fft.c | 42 -- lib_enc/swb_bwe_enc.c | 54 -- lib_enc/swb_bwe_enc_hr.c | 42 -- lib_enc/swb_bwe_enc_hr_fx.c | 1 + lib_enc/swb_bwe_enc_lr.c | 44 -- lib_enc/swb_pre_proc.c | 750 ------------------------ lib_enc/swb_pre_proc_fx.c | 758 ++++++++++++++++++++++++- 22 files changed, 893 insertions(+), 1193 deletions(-) delete mode 100644 lib_enc/spec_center.c delete mode 100644 lib_enc/spec_flatness.c delete mode 100644 lib_enc/speech_music_classif.c delete mode 100644 lib_enc/stat_noise_uv_enc.c delete mode 100644 lib_enc/subband_fft.c delete mode 100644 lib_enc/swb_bwe_enc.c delete mode 100644 lib_enc/swb_bwe_enc_hr.c delete mode 100644 lib_enc/swb_bwe_enc_lr.c delete mode 100644 lib_enc/swb_pre_proc.c diff --git a/Workspace_msvc/lib_enc.vcxproj b/Workspace_msvc/lib_enc.vcxproj index 88c7c4098..efa9f4229 100644 --- a/Workspace_msvc/lib_enc.vcxproj +++ b/Workspace_msvc/lib_enc.vcxproj @@ -396,17 +396,7 @@ - - - - - - - - - - @@ -463,4 +453,4 @@ - \ No newline at end of file + diff --git a/Workspace_msvc/lib_enc.vcxproj.filters b/Workspace_msvc/lib_enc.vcxproj.filters index c109732e9..e845aa21d 100644 --- a/Workspace_msvc/lib_enc.vcxproj.filters +++ b/Workspace_msvc/lib_enc.vcxproj.filters @@ -76,12 +76,6 @@ enc_evs_c - - enc_evs_c - - - enc_evs_c - enc_evs_c @@ -274,30 +268,9 @@ enc_all_c - - enc_all_c - - - enc_all_c - - - enc_all_c - - - enc_all_c - - - enc_all_c - - - enc_all_c - enc_all_c - - enc_all_c - enc_all_c @@ -926,4 +899,4 @@ {6cccabbe-510f-43d3-90e1-8ed5ea3837d7} - \ No newline at end of file + diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index b44029945..a7a7ce88a 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -765,6 +765,7 @@ enum #define UNCLR_L_ETOT 3 #define UNCLR_L_RELE 10 +#define ONE_BY_UNCLR_L_RELE_Q31 214748365 #define UNCLR_RC_ORDER 20 #define MAX_UV_CNT 100 diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index daa8804d7..010dd9106 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -649,6 +649,9 @@ void ivas_hq_core_dec_fx( set16_fx( gapsynth_fx, 0, L_FRAME48k ); set16_fx( num_bands_p, 0, MAX_SB_NB ); set16_fx( ynrm, 39, NB_SFM ); /* Initialize to the smallest value */ +#ifdef MSAN_FIX + set16_fx( wtda_audio_16, 0, 2 * L_FRAME48k ); +#endif mean_en_high_fx = 0; move16(); Q_audio = 12; diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 3ee0f8e8c..ac7b36919 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -124,13 +124,25 @@ void stereo_dft_dec_reset_fx( set16_fx( hStereoDft->res_pred_index_previous, 0, STEREO_DFT_BAND_MAX ); +#ifdef MSAN_FIX + FOR( i = 0; i < STEREO_DFT_BAND_MAX * 2; i++ ) + { + hStereoDft->res_gains_ind_fx[0][i] = 1006632960; /* 15.0f in Q26 */ + move32(); + } +#else FOR( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) { hStereoDft->res_gains_ind_fx[0][i] = 1006632960; /* 15.0f in Q26 */ move32(); } +#endif +#ifdef MSAN_FIX + set32_fx( hStereoDft->res_gains_ind_fx[1], 0, STEREO_DFT_BAND_MAX * 2 ); +#else set32_fx( hStereoDft->res_gains_ind_fx[1], 0, STEREO_DFT_BAND_MAX ); +#endif /*residual coding*/ set16_fx( hStereoDft->res_cod_mode, hStereoDft->hConfig->res_cod_mode, STEREO_DFT_DEC_DFT_NB ); @@ -249,6 +261,19 @@ void stereo_dft_dec_reset_fx( hStereoDft->ipd_xfade_prev_fx = 0; move32(); +#ifdef MSAN_FIX + FOR( b = 0; b < 2 * IVAS_MAX_NUM_BANDS; b++ ) + { + FOR( i = 0; i < 2; i++ ) + { + FOR( j = 0; j < 4; j++ ) + { + hStereoDft->mixer_mat_smooth_fx[i][j][b] = 0; + move32(); + } + } + } +#else FOR( b = 0; b < hStereoDft->nbands; b++ ) { FOR( i = 0; i < 2; i++ ) @@ -260,6 +285,7 @@ void stereo_dft_dec_reset_fx( } } } +#endif hStereoDft->first_frame = 1; move16(); hStereoDft->g_L_prev_fx = 0; diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index 6b9077129..cfef58018 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -1338,7 +1338,10 @@ static void IGF_CalculateStereoEnvelope_fx( crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ) ); shiftedSFM_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &shiftedSFM_e ); } - shiftedSFM_e = add( shiftedSFM_e, sub( sfm_exp, crest_exp ) ); /* stores resultant exponent for shiftedSFM_fx*/ + IF( shiftedSFM_fx ) + { + shiftedSFM_e = add( shiftedSFM_e, sub( sfm_exp, crest_exp ) ); /* stores resultant exponent for shiftedSFM_fx*/ + } // alpha = min( 320.f / (float) swb_offset[sfb + 1], 1.25f ); temp = BASOP_Util_Divide1616_Scale( 320, swb_offset[sfb + 1], &alpha_e ); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 33ffac914..7eb25452c 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -185,6 +185,7 @@ ivas_error ivas_cpe_enc_fx( set16_zero_fx( old_inp_16k_16fx[i], L_INP ); set_zero_fx( old_inp_16k_fx[i], L_INP ); set16_zero_fx( old_inp_12k8_16fx[i], L_INP_12k8 ); + set_zero_fx( old_inp_12k8_fx[i], L_INP_12k8 ); } #endif /*------------------------------------------------------------------* @@ -832,9 +833,11 @@ ivas_error ivas_cpe_enc_fx( move16(); move16(); stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, sts[0]->input32_fx, &out_start_ind, &out_end_ind, 0, input_Fs, input_Fs, 0, NULL ); + Copy_Scale_sig32_16( sts[0]->input32_fx + out_start_ind, sts[0]->input_fx + out_start_ind, sub( out_end_ind, out_start_ind ), sub( add( Q16, sts[0]->q_inp ), Q15 ) ); // Q15 /* iDFT & resampling to 12.8kHz internal sampling rate */ stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, old_inp_12k8_fx[0] + L_INP_MEM, &out_12k8_start_ind[0], &out_12k8_end_ind[0], 0, input_Fs, INT_FS_12k8, 0, NULL ); + Copy_Scale_sig_32_16( old_inp_12k8_fx[0], old_inp_12k8_16fx[0], L_INP_12k8, -Q16 ); // Q-1 /* iDFT & resampling to 16kHz internal sampling rate for M channel */ IF( EQ_32( input_Fs, internal_Fs ) ) @@ -849,6 +852,7 @@ ivas_error ivas_cpe_enc_fx( { stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, old_inp_16k_fx[0] + L_INP_MEM, &out_16k_start_ind, &out_16k_end_ind, 0, input_Fs, internal_Fs, 0, NULL ); } + Copy_Scale_sig32_16( old_inp_16k_fx[0], old_inp_16k_16fx[0], L_INP, 0 ); // Q15->Q-1 /* DFT Stereo: iDFT of residual signal at 8kHz sampling rate */ test(); @@ -859,18 +863,9 @@ ivas_error ivas_cpe_enc_fx( /* update old input signal buffer */ Copy_Scale_sig_32_16( old_inp_12k8_fx[1] + L_FRAME8k, sts[1]->old_inp_12k8_fx, L_INP_MEM, 0 - 15 ); // Q0 - } - Copy_Scale_sig32_16( sts[0]->input32_fx + out_start_ind, sts[0]->input_fx + out_start_ind, sub( out_end_ind, out_start_ind ), sub( add( Q16, sts[0]->q_inp ), Q15 ) ); // Q15 - - Copy_Scale_sig32_16( old_inp_16k_fx[0], old_inp_16k_16fx[0], L_INP, 0 ); // Q15->Q-1 - /*local fix2flt*/ - /*fix2flt: dft_synthesize*/ - Copy_Scale_sig_32_16( old_inp_12k8_fx[0] + L_INP_MEM + out_12k8_start_ind[0], old_inp_12k8_16fx[0] + L_INP_MEM + out_12k8_start_ind[0], out_12k8_end_ind[0] - out_12k8_start_ind[0], -Q16 ); // Q-1 - if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET] ) - { sts[1]->exp_old_inp_12k8 = Q15; move16(); - Copy_Scale_sig_32_16( old_inp_12k8_fx[1] + L_INP_MEM + out_12k8_start_ind[1], old_inp_12k8_16fx[1] + L_INP_MEM + out_12k8_start_ind[1], out_12k8_end_ind[1] - out_12k8_start_ind[1], -Q16 ); // Q-1 + Copy_Scale_sig_32_16( old_inp_12k8_fx[1], old_inp_12k8_16fx[1], L_INP_12k8, -Q16 ); // Q-1 } /* no iDFT at input sampling rate for Side channel -> reset the buffer */ @@ -1141,7 +1136,7 @@ ivas_error ivas_cpe_enc_fx( test(); IF( !( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && ( EQ_32( sts[0]->core_brate, SID_2k40 ) || sts[0]->core_brate == FRAME_NO_DATA ) ) ) { - Word16 max_bits = extract_l( L_sub( Mpy_32_32_r( hCPE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ), Mult_32_16( sts[0]->bits_frame_nominal, 26214 /* 0.8f in Q15 */ ) ) ); + Word16 max_bits = extract_l( W_extract_h( W_sub( W_mult_32_32( hCPE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ), W_mult_32_32( L_deposit_l( sts[0]->bits_frame_nominal ), 1717986918 /* 0.8f in Q31 */ ) ) ) ); test(); IF( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) { @@ -1154,7 +1149,7 @@ ivas_error ivas_cpe_enc_fx( FOR( Word16 i = 0; i < CPE_CHANNELS; i++ ) { - Copy_Scale_sig_16_32( old_inp_12k8_16fx[i], old_inp_12k8_fx[i], L_INP_12k8, Q16 + Q1 ); + Copy_Scale_sig_16_32_no_sat( old_inp_12k8_16fx[i], old_inp_12k8_fx[i], L_INP_12k8, Q16 + Q1 ); } stereo_dft_enc_res_fx( hCPE->hStereoDft, old_inp_12k8_fx[1] + L_INP_MEM - STEREO_DFT_OVL_8k, hCPE->hMetaData, &nb_bits, max_bits ); } diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index 941d55cba..e840a0b80 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -496,12 +496,38 @@ void stereo_classifier_features_ivas_fx( move32(); move16(); /* update Etot_up and Etot_dn based on aEn */ + exp = norm_l( hStereoClassif->ave_ener_L_fx ); + if ( sub( hStereoClassif->ave_ener_L_fx_e, exp ) < 0 ) + { + exp = hStereoClassif->ave_ener_L_fx_e; + move16(); + } + hStereoClassif->ave_ener_L_fx = L_shl( hStereoClassif->ave_ener_L_fx, exp ); + move32(); + hStereoClassif->ave_ener_L_fx_e = sub( hStereoClassif->ave_ener_L_fx_e, exp ); + move16(); + exp = norm_l( hStereoClassif->ave_ener_R_fx ); + if ( sub( hStereoClassif->ave_ener_R_fx_e, exp ) < 0 ) + { + exp = hStereoClassif->ave_ener_R_fx_e; + move16(); + } + hStereoClassif->ave_ener_R_fx = L_shl( hStereoClassif->ave_ener_R_fx, exp ); + move32(); + hStereoClassif->ave_ener_R_fx_e = sub( hStereoClassif->ave_ener_R_fx_e, exp ); + move16(); ener_l_fx = Mpy_32_16_1( BASOP_Util_Log10( L_add( L_shr( hStereoClassif->ave_ener_L_fx, 1 ), L_shr( ONE_IN_Q30, hStereoClassif->ave_ener_L_fx_e ) ), hStereoClassif->ave_ener_L_fx_e + 1 ), 10 << 11 ); /*q21*/ ener_r_fx = Mpy_32_16_1( BASOP_Util_Log10( L_add( L_shr( hStereoClassif->ave_ener_R_fx, 1 ), L_shr( ONE_IN_Q30, hStereoClassif->ave_ener_R_fx_e ) ), hStereoClassif->ave_ener_R_fx_e + 1 ), 10 << 11 ); /*q21*/ ener_e = 10; move16(); + + /*scaling Etot_buf_fx,Etot_up_fx and Etot_dn_fx to exponent ener_e*/ + exp = L_norm_arr( hStereoClassif->Etot_buf_fx, 3 ); + exp = s_min( exp, L_norm_arr( &hStereoClassif->Etot_up_fx, 1 ) ); + exp = s_min( exp, L_norm_arr( &hStereoClassif->Etot_dn_fx, 1 ) ); + Copy32( &hStereoClassif->Etot_buf_fx[0], &hStereoClassif->Etot_buf_fx[1], UNCLR_L_ETOT - 1 ); - IF( GE_16( hStereoClassif->e_Etot_buf_fx, ener_e ) ) + IF( GE_16( sub( hStereoClassif->e_Etot_buf_fx, exp ), ener_e ) ) { hStereoClassif->Etot_buf_fx[0] = L_shl( L_max( 0, L_max( ener_l_fx, ener_r_fx ) ), sub( ener_e, hStereoClassif->e_Etot_buf_fx ) ); /*scaling from q25 to 31-e_Etot_buf_fx*/ move32(); @@ -883,7 +909,16 @@ void unclr_classifier_td_fx( score = Mpy_32_32( score, hStereoClassif->relE_0_1_fx ); // Q31 /* rising edge detection on relE */ - relE_ST = Mean32( hStereoClassif->relE_buf_fx, UNCLR_L_RELE ); // Q31 + Word32 L_tmp = 0; + move32(); + Word16 L_tmp_e = 0; + move16(); + FOR( i = 0; i < UNCLR_L_RELE; i++ ) + { + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_e, hStereoClassif->relE_buf_fx[i], 0, &L_tmp_e ); + } + relE_ST = L_shl( Mpy_32_32( L_tmp, ONE_BY_UNCLR_L_RELE_Q31 ), L_tmp_e ); // Q31 + IF( hStereoClassif->relE_0_1_fx > relE_ST ) { rc_filter_fx( hStereoClassif->relE_0_1_fx, hStereoClassif->unclr_relE_0_1_LT_fx, UNCLR_RC_ORDER, RC_FACT_UP_Q31 ); @@ -985,7 +1020,16 @@ void unclr_classifier_dft_fx( /* rising edge detector on relE */ // relE_ST = mean(hStereoClassif->relE_buf, UNCLR_L_RELE); - relE_ST = Mean32( hStereoClassif->relE_buf_fx, UNCLR_L_RELE ); // Q31 + Word32 L_tmp = 0; + move32(); + Word16 L_tmp_e = 0; + move16(); + FOR( i = 0; i < UNCLR_L_RELE; i++ ) + { + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_e, hStereoClassif->relE_buf_fx[i], 0, &L_tmp_e ); + } + relE_ST = L_shl( Mpy_32_32( L_tmp, ONE_BY_UNCLR_L_RELE_Q31 ), L_tmp_e ); // Q31 + IF( GT_32( hStereoClassif->relE_0_1_fx, relE_ST ) ) { // rc_filter(hStereoClassif->relE_0_1, hStereoClassif->unclr_relE_0_1_LT, UNCLR_RC_ORDER, RC_FACT_UP); diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index a7a3d1bbe..10bfbacd8 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -886,7 +886,7 @@ void stereo_dft_enc_update_fx( // hStereoDft->res_cod_line_max = (int16_t) ( 0.5f + ( hStereoDft->band_limits[hStereoDft->res_cod_band_max] - 1 ) * 2.f * hStereoDft->N / (float) ( hStereoDft->NFFT ) ); Word32 tmp = L_shl( L_mult0( sub( hStereoDft->band_limits[hStereoDft->res_cod_band_max], 1 ), hStereoDft->N ), 1 ); Word16 exp; - tmp = BASOP_Util_Divide3232_Scale_cadence( tmp, hStereoDft->N, &exp ); + tmp = BASOP_Util_Divide3232_Scale_cadence( tmp, hStereoDft->NFFT, &exp ); hStereoDft->res_cod_line_max = extract_l( L_shr( tmp, sub( 31, exp ) ) ); move16(); // hStereoDft->res_cod_line_max = 8 * (hStereoDft->res_cod_line_max / 8); @@ -1632,7 +1632,7 @@ void stereo_dft_enc_process_fx( // hStereoDft->res_cod_line_max = (int16_t) ( 0.5f + ( hStereoDft->band_limits[hStereoDft->res_cod_band_max] - 1 ) * 2.f * input_frame / (float) ( hStereoDft->NFFT ) ); tmp_32fx = L_shl( L_mult0( sub( hStereoDft->band_limits[hStereoDft->res_cod_band_max], 1 ), input_frame ), 1 ); tmp_32fx = BASOP_Util_Divide3216_Scale( tmp_32fx, hStereoDft->NFFT, &tmp_e ); - hStereoDft->res_cod_line_max = extract_l( L_shr_r( tmp_32fx, sub( 31, tmp_e ) ) ); + hStereoDft->res_cod_line_max = extract_l( L_shr_r( tmp_32fx, sub( -1, tmp_e ) ) ); // 15 - (31 - 15 + tmp_e) = -1 - tmp_e move16(); // hStereoDft->res_cod_line_max = 8 * (hStereoDft->res_cod_line_max / 8); hStereoDft->res_cod_line_max = shl( shr( hStereoDft->res_cod_line_max, 3 ), 3 ); @@ -2769,7 +2769,7 @@ void stereo_dft_enc_res_fx( // in_phase_ratio = check_bounds(in_phase_ratio, 0, 1); // res_cod_gain[b] = in_phase_ratio * STEREO_DFT_RES_COD_SNR_MIN + ( 1 - in_phase_ratio ) * STEREO_DFT_RES_COD_SNR_MAX; - res_cod_gain[b] = L_add( Mpy_32_32( in_phase_ratio, STEREO_DFT_RES_COD_SNR_MIN_Q25 ), Mpy_32_32( L_sub( MAX_32, in_phase_ratio ), STEREO_DFT_RES_COD_SNR_MAX ) ); // Q25 + res_cod_gain[b] = L_add( Mpy_32_32( in_phase_ratio, STEREO_DFT_RES_COD_SNR_MIN_Q25 ), Mpy_32_32( L_sub( MAX_32, in_phase_ratio ), STEREO_DFT_RES_COD_SNR_MAX_Q25 ) ); // Q25 move32(); /*get the maximum through bands*/ diff --git a/lib_enc/ivas_stereo_eclvq_enc.c b/lib_enc/ivas_stereo_eclvq_enc.c index d108e3add..b8ac48298 100644 --- a/lib_enc/ivas_stereo_eclvq_enc.c +++ b/lib_enc/ivas_stereo_eclvq_enc.c @@ -80,13 +80,25 @@ void ECSQ_quantize_vector_fx( Word16 inv_global_gain_e; // inv_global_gain = 1.0f / global_gain; - inv_global_gain = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q15, global_gain, &inv_global_gain_e ); - inv_global_gain = L_shl( inv_global_gain, inv_global_gain_e ); // Q31 - FOR( i = 0; i < N; ++i ) + IF( EQ_32( global_gain, ONE_IN_Q15 ) ) { - // output[i] = (int16_t) round_f( input[i] * inv_global_gain ); - output[i] = extract_l( L_shr_r( Mpy_32_32( input[i], inv_global_gain ), sub( 31, input_e ) ) ); - move16(); + FOR( i = 0; i < N; ++i ) + { + // output[i] = (int16_t) round_f( input[i] * inv_global_gain ); + output[i] = extract_l( L_shr_r( input[i], sub( 31, input_e ) ) ); + move16(); + } + } + ELSE + { + inv_global_gain = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q15, global_gain, &inv_global_gain_e ); + inv_global_gain = L_shl( inv_global_gain, inv_global_gain_e ); // Q31 + FOR( i = 0; i < N; ++i ) + { + // output[i] = (int16_t) round_f( input[i] * inv_global_gain ); + output[i] = extract_l( L_shr_r( Mpy_32_32( input[i], inv_global_gain ), sub( 31, input_e ) ) ); + move16(); + } } return; @@ -107,6 +119,7 @@ Word32 ECSQ_compute_optimal_gain_fx( // Q15 Word16 i; Word32 sum_sq_output; Word32 sum_input_output; + Word16 sum_input_output_e; Word32 optimal_global_gain; Word16 optimal_global_gain_e; @@ -114,12 +127,14 @@ Word32 ECSQ_compute_optimal_gain_fx( // Q15 move32(); sum_input_output = 0; move32(); + sum_input_output_e = 0; + move16(); FOR( i = 0; i < N; ++i ) { // sum_sq_output += (float) output[i] * (float) output[i]; - sum_sq_output = L_add( sum_sq_output, L_shl( L_mult0( output[i], output[i] ), 15 ) ); // Q15 + sum_sq_output = L_add( sum_sq_output, L_mult0( output[i], output[i] ) ); // sum_input_output += input[i] * (float) output[i]; - sum_input_output = L_add( sum_input_output, L_shr( W_extract_l( W_mult0_32_32( input[i], output[i] ) ), sub( 16, input_e ) ) ); // Q15 + sum_input_output = BASOP_Util_Add_Mant32Exp( sum_input_output, sum_input_output_e, W_extract_l( W_mult0_32_32( input[i], output[i] ) ), input_e, &sum_input_output_e ); } optimal_global_gain = 0; @@ -127,8 +142,8 @@ Word32 ECSQ_compute_optimal_gain_fx( // Q15 IF( sum_sq_output != 0 ) { // optimal_global_gain = sum_input_output / sum_sq_output; - optimal_global_gain = BASOP_Util_Divide3232_Scale_cadence( sum_input_output, sum_sq_output, &optimal_global_gain_e ); - optimal_global_gain = L_shr( optimal_global_gain, sub( 16, optimal_global_gain_e ) ); // Q15 + optimal_global_gain = BASOP_Util_Divide3232_Scale_cadence( sum_input_output, sum_sq_output, &optimal_global_gain_e ); // 31 - ( sum_input_output_e - 31 + optimal_global_gain_e ) = 62 - ( sum_input_output_e + optimal_global_gain_e ) + optimal_global_gain = L_shr( optimal_global_gain, sub( sub( 62, add( sum_input_output_e, optimal_global_gain_e ) ), 15 ) ); // Q15 } return optimal_global_gain; @@ -435,8 +450,7 @@ static Word16 get_best_param_fx( /* the best Laplace integer parameter is floor(log2(avg_abs_sum) + log2(offset)) */ // param = (int16_t) floor( log_base2( *avg_abs_sum * offset ) ); - param = sub( 31, norm_l( L_sub( L_shr( Mpy_32_16_1( *avg_abs_sum, offset ), 10 - 1 ), 1 ) ) ); - // sub( 31, norm_l( L_sub( n, 1 ) ) ) + param = extract_l( L_shr( L_add( BASOP_Util_Log2( Mpy_32_16_1( *avg_abs_sum, offset ) ), 738197504 /* (31-(10+14-15)) <<25 */ ), 25 ) ); /* limit param value to the available exponent range */ param = s_max( ECSQ_ALL_ZERO_PARAM + 1, param ); @@ -767,6 +781,8 @@ Word32 ECSQ_encode_target_SNR_fx( // const Word32 global_gain_step = 1165018877; // powf( 10.0f, ECLVQ_INV_GLOBAL_GAIN_FACTOR ) in Q30 Word32 L_tmp1; Word16 L_tmp1_e; + Word64 W_tmp1; + Word16 shift; // max_bits_fixpt = max_bits * 1024; /* max_bits_fixpt is in 22Q10 fixed-point representation */ max_bits_fixpt = L_shl( max_bits, 10 ); /* max_bits_fixpt is in 22Q10 fixed-point representation */ @@ -787,10 +803,24 @@ Word32 ECSQ_encode_target_SNR_fx( move32(); sum_squared_e = 0; move16(); + FOR( i = 0; i < N; ++i ) { // sum_squared += input[i] * input[i]; - sum_squared = BASOP_Util_Add_Mant32Exp( sum_squared, sum_squared_e, Mpy_32_32( input[i], input[i] ), shl( input_e, 1 ), &sum_squared_e ); + W_tmp1 = W_mult0_32_32( input[i], input[i] ); // 2(31-input_e) + IF( W_tmp1 == 0 ) + { + shift = 32; + move16(); + } + ELSE + { + shift = W_norm( W_tmp1 ); + } + shift = sub( 32, shift ); + L_tmp1 = W_extract_l( W_shr( W_tmp1, shift ) ); // 2(31-input_e) - shift = 62 - 2input_e - shift + L_tmp1_e = sub( add( shl( input_e, 1 ), shift ), 31 ); // 31 - (62 - 2input_e - shift) = 2input_e + shift - 31 + sum_squared = BASOP_Util_Add_Mant32Exp( sum_squared, sum_squared_e, L_tmp1, L_tmp1_e, &sum_squared_e ); } // if ( sum_squared < 0.25f ) /* all the values in the input vector will always be quantized to zero */ @@ -830,6 +860,7 @@ Word32 ECSQ_encode_target_SNR_fx( // global_gain = sqrtf( target_sum_squared_error / ( 0.0833f * (float) N ) ); global_gain = BASOP_Util_Divide3232_Scale_cadence( target_sum_squared_error, L_mult0( 5459 /*0.0833f in Q16*/, N ), &global_gain_e ); global_gain_e = add( global_gain_e, sub( target_sum_squared_error_e, 15 ) ); + global_gain = Sqrt32( global_gain, &global_gain_e ); global_gain = L_shr( global_gain, sub( 16, global_gain_e ) ); // Q15 /* quantize the estimated global_gain */ global_gain_index = ECSQ_quantize_gain_fx( global_gain ); @@ -856,7 +887,13 @@ Word32 ECSQ_encode_target_SNR_fx( // adjust_global_gain_index = (int16_t) ceil( adjust_size / ( 1024.0f * N * log_base2( global_gain_step ) ) ); adjust_global_gain_index = BASOP_Util_Divide3232_Scale_cadence( adjust_size, N, &tmp_e ); adjust_global_gain_index = Mpy_32_32( adjust_global_gain_index, 17816838 /*/ ( 1024.0f * log_base2( global_gain_step ) )*/ ); - adjust_global_gain_index = extract_l( L_shr( L_add( adjust_global_gain_index, L_shl( 1, sub( 31, tmp_e ) ) ), sub( 31, tmp_e ) ) ); + IF( NE_32( adjust_global_gain_index, L_shl( L_shr( adjust_global_gain_index, sub( 31, tmp_e ) ), sub( 31, tmp_e ) ) ) ) + { + adjust_global_gain_index = BASOP_Util_Add_Mant32Exp( adjust_global_gain_index, tmp_e, ONE_IN_Q30, 1, &tmp_e ); + } + + adjust_global_gain_index = extract_l( L_shr( adjust_global_gain_index, sub( 31, tmp_e ) ) ); + global_gain_index = s_min( add( global_gain_index, (Word16) adjust_global_gain_index ), 126 ); global_gain = ECSQ_dequantize_gain_fx( global_gain_index ); // Q15 diff --git a/lib_enc/ivas_stereo_ica_enc.c b/lib_enc/ivas_stereo_ica_enc.c index f7cf971ef..3f4696a06 100644 --- a/lib_enc/ivas_stereo_ica_enc.c +++ b/lib_enc/ivas_stereo_ica_enc.c @@ -935,6 +935,8 @@ static void corrStatsEst_fx( alpha_reg_fx = BASOP_Util_Add_Mant32Exp( Y_hat_fx, Y_hat_exp, L_negate( Mpy_32_32( X_hat_fx, beta_reg_fx ) ), add( X_hat_exp, beta_reg_exp ), &alpha_reg_exp ); /* Q31-alpha_reg_exp */ reg_prv_corr_fx = BASOP_Util_Add_Mant32Exp( alpha_reg_fx, alpha_reg_exp, Mpy_32_32( beta_reg_fx, L_shl( MAX_DELAYREGLEN, 27 ) ), add( 4, beta_reg_exp ), ®_prv_corr_exp ); /* Q31-reg_prv_corr_exp */ + reg_prv_corr_fx = L_shr( reg_prv_corr_fx, 1 ); + reg_prv_corr_exp = add( reg_prv_corr_exp, 1 ); IF( LE_16( TRUNC_FX( reg_prv_corr_fx, reg_prv_corr_exp ), -L_NCSHIFT_DS ) ) { reg_prv_corr_fx = -L_NCSHIFT_DS + 1; @@ -1127,7 +1129,9 @@ static void corrStatsEst_fx( test(); IF( vad_flag1 == 0 || vad_flag2 == 0 ) { - corrLagStats[0] = TRUNC_FX( hStereoTCA->delay_0_mem_fx[MAX_DELAYREGLEN - 1], hStereoTCA->delay_0_mem_exp ); /* Q0 */ + Word32 tmp_delay = L_shr( hStereoTCA->delay_0_mem_fx[MAX_DELAYREGLEN - 1], 1 ); + Word16 tmp_delay_e = add( hStereoTCA->delay_0_mem_exp, 1 ); + corrLagStats[0] = TRUNC_FX( tmp_delay, tmp_delay_e ); /* Q0 */ move32(); } @@ -2355,7 +2359,7 @@ static void unclr_calc_corr_features_fx( m_corrL_corrR = L_sub( L_max( L_abs( L_shl( ic_Lm, sub( exp1, s_max( exp1, exp2 ) ) ) ), L_abs( L_shl( ic_Rm, sub( exp2, s_max( exp1, exp2 ) ) ) ) ), L_min( L_abs( L_shl( ic_Lm, sub( exp1, s_max( exp1, exp2 ) ) ) ), L_abs( L_shl( ic_Rm, sub( exp2, s_max( exp1, exp2 ) ) ) ) ) ); // s_max(exp1, exp2) - inp1 = BASOP_Util_Add_Mant32Exp( corrL, corrL_exp, corrR, corrR_exp, &exp ); /* Q31-exp */ + inp1 = BASOP_Util_Add_Mant32Exp( corrL, corrL_exp, L_negate( corrR ), corrR_exp, &exp ); /* Q31-exp */ IF( inp1 ) { d_corrL_corrR = BASOP_Util_Log10( L_abs( inp1 ), exp ); // Q25 diff --git a/lib_enc/spec_center.c b/lib_enc/spec_center.c deleted file mode 100644 index 5cd8e2875..000000000 --- a/lib_enc/spec_center.c +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include "options.h" -#include "prot.h" -#include "rom_enc.h" -#include "cnst.h" -#include "wmc_auto.h" diff --git a/lib_enc/spec_flatness.c b/lib_enc/spec_flatness.c deleted file mode 100644 index 68731d8f1..000000000 --- a/lib_enc/spec_flatness.c +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include -#include "options.h" -#include -#include "prot.h" -#include "wmc_auto.h" diff --git a/lib_enc/speech_music_classif.c b/lib_enc/speech_music_classif.c deleted file mode 100644 index 514f654cb..000000000 --- a/lib_enc/speech_music_classif.c +++ /dev/null @@ -1,46 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include -#include "options.h" -#include -#include "cnst.h" -#include "prot.h" -#include "ivas_prot.h" -#include "rom_enc.h" -#include "rom_com.h" /* Common static table prototypes */ -#include "wmc_auto.h" diff --git a/lib_enc/stat_noise_uv_enc.c b/lib_enc/stat_noise_uv_enc.c deleted file mode 100644 index fc894ba6c..000000000 --- a/lib_enc/stat_noise_uv_enc.c +++ /dev/null @@ -1,41 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include "options.h" -#include "prot.h" -#include "rom_com.h" -#include "wmc_auto.h" diff --git a/lib_enc/subband_fft.c b/lib_enc/subband_fft.c deleted file mode 100644 index 8d4adb219..000000000 --- a/lib_enc/subband_fft.c +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include "options.h" -#include -#include "prot.h" -#include "rom_enc.h" -#include "wmc_auto.h" diff --git a/lib_enc/swb_bwe_enc.c b/lib_enc/swb_bwe_enc.c deleted file mode 100644 index f63322811..000000000 --- a/lib_enc/swb_bwe_enc.c +++ /dev/null @@ -1,54 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include "options.h" -#include -#include "cnst.h" -#include "prot.h" -#include "rom_com.h" -#include "rom_enc.h" -#include "basop_util.h" -#include "basop_proto_func.h" -#include "wmc_auto.h" -#include "prot_fx.h" - - -/*-------------------------------------------------------------------* - * fd_bwe_enc_init() - * - * Initialize FD BWE state structure at the encoder - *-------------------------------------------------------------------*/ diff --git a/lib_enc/swb_bwe_enc_hr.c b/lib_enc/swb_bwe_enc_hr.c deleted file mode 100644 index 8e752f0ac..000000000 --- a/lib_enc/swb_bwe_enc_hr.c +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include "options.h" -#include -#include "prot.h" -#include "rom_com.h" -#include "wmc_auto.h" diff --git a/lib_enc/swb_bwe_enc_hr_fx.c b/lib_enc/swb_bwe_enc_hr_fx.c index 094ad37fa..95d434d6a 100644 --- a/lib_enc/swb_bwe_enc_hr_fx.c +++ b/lib_enc/swb_bwe_enc_hr_fx.c @@ -786,6 +786,7 @@ void swb_bwe_enc_hr_fx( L_tmp = L_shr( L_tmp, temp2 ); t_audio_fx[i] = round_fx( L_tmp ); #endif + move16(); } set16_fx( nq2, 0, Nsv ); diff --git a/lib_enc/swb_bwe_enc_lr.c b/lib_enc/swb_bwe_enc_lr.c deleted file mode 100644 index 5bd24db09..000000000 --- a/lib_enc/swb_bwe_enc_lr.c +++ /dev/null @@ -1,44 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include "options.h" -#include -#include "cnst.h" -#include "prot.h" -#include "rom_com.h" -#include "stat_com.h" -#include "wmc_auto.h" diff --git a/lib_enc/swb_pre_proc.c b/lib_enc/swb_pre_proc.c deleted file mode 100644 index 2f76fa5f4..000000000 --- a/lib_enc/swb_pre_proc.c +++ /dev/null @@ -1,750 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include "options.h" -#include -#include "cnst.h" -#include "prot.h" -#include "rom_com.h" -#include "rom_enc.h" -#include "wmc_auto.h" -#include "ivas_prot.h" -#include "ivas_rom_enc.h" -#include "ivas_prot_fx.h" -#include "prot_fx.h" -#include "prot_fx_enc.h" - - -/*-------------------------------------------------------------------* - * swb_pre_proc() - * - * - Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB target signal - * for SWB TBE or SWB BWE coding - * - Common SWB TBE and SWB BWE pre-processing - *-------------------------------------------------------------------*/ - -/*full implementation pending*/ -void swb_pre_proc_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - Word16 *new_swb_speech, /* o : original input signal at 32kHz - Q0 */ - Word32 *new_swb_speech_fx, /* o : original input signal at 32kHz - Q - q_reImBuffer */ - Word16 *shb_speech, /* o : SHB target signal (6-14kHz) at 16kHz- Q(Q_shb_spch) */ - Word16 *Q_shb_spch, - Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real buffer Q - q_reImbuffer */ - Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag buffer Q - q_reImbuffer */ - Word16 q_reImBuffer, /* i : scale data of real and imag CLDFB buffers */ - CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ -) -{ - Word16 Sample_Delay_SWB_BWE, inner_frame, delay; - TD_BWE_ENC_HANDLE hBWE_TD; - FD_BWE_ENC_HANDLE hBWE_FD; - Word32 inner_Fs, input_Fs; - Word16 old_input_fx[NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k]; // fixed counterpart - Word32 old_input_fx_32[NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k]; // fixed counterpart - Word16 spchTmp[L_FRAME32k], spchTmp2[L_FRAME32k]; - Word16 i, j, L_resamp; - Word16 startB, endB; - Word32 *realBufferFlipped[CLDFB_NO_COL_MAX]; - Word32 *imagBufferFlipped[CLDFB_NO_COL_MAX]; - Word32 realBufferTmp[CLDFB_NO_COL_MAX][20]; - Word32 imagBufferTmp[CLDFB_NO_COL_MAX][20]; - Word32 shb_speech_fx_32[L_FRAME16k]; - Word16 ts, nB, uB; - Word32 v, t, regression; - Word16 t_16; - const Word32 *thr, *regV; - Word32 lbEner; - Word16 exp_lbEner = 0; - Word16 Sample_Delay_SWB_BWE32k, lMemRecalc32k, dft_ovl32k; - Word32 one_by_50_Q31 = 42949673; - - lMemRecalc32k = NS2SA_FX2( 32000, L_MEM_RECALC_NS ); - move16(); // exp_lbEner - move16(); // lMemRecalc32k - move32(); // one_by_50_Q31 - - /* initialization */ - hBWE_TD = st->hBWE_TD; - hBWE_FD = st->hBWE_FD; - input_Fs = st->input_Fs; - - FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ ) - { - set32_fx( realBufferTmp[j], 0, 20 ); - set32_fx( imagBufferTmp[j], 0, 20 ); - realBufferFlipped[j] = realBufferTmp[j]; - imagBufferFlipped[j] = imagBufferTmp[j]; - } - - set16_fx( old_input_fx, 0, NS2SA_FX2( 48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k ); - - IF( EQ_32( st->input_Fs, 32000 ) ) - { - IF( st->element_mode > EVS_MONO ) - { - Sample_Delay_SWB_BWE = NS2SA_FX2( 32000, DELAY_FD_BWE_ENC_12k8_NS ); - move16(); - IF( EQ_16( st->L_frame, L_FRAME16k ) ) - { - Sample_Delay_SWB_BWE = NS2SA_FX2( 32000, DELAY_FD_BWE_ENC_16k_NS ); - move16(); - } - - Copy( st->input_fx - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); - Copy( st->input_fx - L_FRAME32k, hBWE_FD->old_fdbwe_speech_fx, L_FRAME32k ); - - test(); - test(); - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && GE_16( st->bwidth, SWB ) ) - { - Copy( st->input_fx - hCPE->hStereoTCA->lMemRecalc, hBWE_FD->L_old_wtda_swb_fx + L_FRAME32k - sub( hCPE->hStereoTCA->lMemRecalc, Sample_Delay_SWB_BWE ), sub( hCPE->hStereoTCA->lMemRecalc, Sample_Delay_SWB_BWE ) ); - } - ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) && GE_16( st->bwidth, SWB ) ) - { - Copy( st->input_fx - hCPE->hStereoDft->dft_ovl, hBWE_FD->L_old_wtda_swb_fx + L_FRAME32k - sub( hCPE->hStereoDft->dft_ovl, Sample_Delay_SWB_BWE ), sub( hCPE->hStereoDft->dft_ovl, Sample_Delay_SWB_BWE ) ); - } - } - - Copy( st->input_fx, new_swb_speech, L_FRAME32k ); - - test(); - test(); - IF( NE_16( st->last_extl, SWB_BWE ) && NE_16( st->last_extl, FB_BWE ) && NE_16( st->extl, SWB_BWE_HIGHRATE ) ) - { - Sample_Delay_SWB_BWE = NS2SA_FX2( 32000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); - move16(); - test(); - IF( st->element_mode > EVS_MONO && EQ_16( st->L_frame, L_FRAME16k ) ) - { - Sample_Delay_SWB_BWE = NS2SA_FX2( 32000, DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS ); - move16(); - } - IF( st->element_mode > EVS_MONO ) - { - Sample_Delay_SWB_BWE = sub( Sample_Delay_SWB_BWE, NS2SA_FX2( 32000, DELAY_FIR_RESAMPL_NS ) ); - } - - Copy( hBWE_FD->old_fdbwe_speech_fx, &old_input_fx[Sample_Delay_SWB_BWE], L_FRAME32k ); - - set16_fx( old_input_fx, 0, Sample_Delay_SWB_BWE ); - Copy( hBWE_FD->old_fdbwe_speech_fx + L_FRAME32k - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); - IF( NE_16( st->extl, WB_BWE ) ) - { - Copy( old_input_fx, hBWE_FD->L_old_wtda_swb_fx, L_FRAME32k ); - } - } - - test(); - IF( NE_16( st->extl, SWB_BWE ) && NE_16( st->extl, FB_BWE ) ) - { - Copy( st->input_fx, hBWE_FD->old_fdbwe_speech_fx, L_FRAME32k ); - } - } - ELSE /* 48 kHz */ - { - - Sample_Delay_SWB_BWE32k = NS2SA_FX2( 32000, DELAY_FD_BWE_ENC_12k8_NS ); - move16(); - Sample_Delay_SWB_BWE = NS2SA_FX2( 48000, DELAY_FD_BWE_ENC_12k8_NS ); - move16(); - IF( EQ_16( st->L_frame, L_FRAME16k ) ) - { - Sample_Delay_SWB_BWE32k = NS2SA_FX2( 32000, DELAY_FD_BWE_ENC_16k_NS ); - move16(); - Sample_Delay_SWB_BWE = NS2SA_FX2( 48000, DELAY_FD_BWE_ENC_16k_NS ); - move16(); - } - - dft_ovl32k = 0; - move16(); - IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) - { - dft_ovl32k = (Word16) ( STEREO_DFT_OVL_MAX * 32000 / 48000 ); - move16(); - } - - IF( EQ_16( st->codec_mode, MODE1 ) ) - { - IF( st->element_mode > EVS_MONO ) - { - - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) - { - } - ELSE IF( EQ_16( st->bwidth, FB ) ) - { - Copy( st->input_fx - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); - } - - Copy( st->input_fx - L_FRAME48k, hBWE_FD->old_fdbwe_speech_fx, L_FRAME48k ); - - test(); - test(); - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && GE_16( st->bwidth, SWB ) ) - { - IF( EQ_16( st->bwidth, SWB ) ) - { - /* buffers hBWE_FD->old_input[] and hBWE_FD->old_wtda_swb[] need to be at 32 kHz (inner) sampling rate */ - - decimate_2_over_3_allpass_fx( st->input_fx - hCPE->hStereoTCA->lMemRecalc, hCPE->hStereoTCA->lMemRecalc, spchTmp, hBWE_TD->dec_2_over_3_mem_fx, - allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx ); - - Copy( spchTmp, hBWE_FD->L_old_wtda_swb_fx + L_FRAME32k - sub( lMemRecalc32k, Sample_Delay_SWB_BWE32k ), sub( lMemRecalc32k, Sample_Delay_SWB_BWE32k ) ); - Copy( spchTmp + lMemRecalc32k - Sample_Delay_SWB_BWE32k, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE32k ); - } - ELSE /* FB_BWE */ - { - Copy( st->input_fx - hCPE->hStereoTCA->lMemRecalc, hBWE_FD->L_old_wtda_swb_fx + L_FRAME48k - sub( hCPE->hStereoTCA->lMemRecalc, Sample_Delay_SWB_BWE ), sub( hCPE->hStereoTCA->lMemRecalc, Sample_Delay_SWB_BWE ) ); - Copy( st->input_fx - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); - } - } - ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) && GE_16( st->bwidth, SWB ) ) - { - IF( EQ_16( st->bwidth, SWB ) ) - { - lerp( st->input_fx - hCPE->hStereoDft->dft_ovl, spchTmp, dft_ovl32k - Sample_Delay_SWB_BWE32k, hCPE->hStereoDft->dft_ovl - Sample_Delay_SWB_BWE ); - - Copy( spchTmp, hBWE_FD->L_old_wtda_swb_fx + L_FRAME32k - ( dft_ovl32k - Sample_Delay_SWB_BWE32k ), dft_ovl32k - Sample_Delay_SWB_BWE32k ); - } - ELSE - { - Copy( st->input_fx - hCPE->hStereoDft->dft_ovl, hBWE_FD->L_old_wtda_swb_fx + L_FRAME48k - ( hCPE->hStereoDft->dft_ovl - Sample_Delay_SWB_BWE ), hCPE->hStereoDft->dft_ovl - Sample_Delay_SWB_BWE ); - } - } - } - - test(); - test(); - test(); - test(); - IF( ( NE_16( st->extl, SWB_BWE ) && NE_16( st->extl, FB_BWE ) && ( st->core == ACELP_CORE ) ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && ( st->core != ACELP_CORE ) ) /*resampling not needed for MDCT cores*/ ) - { - /* move the resampling out of the TDBWE path as new_swb_speech is not needed for TDBWE. */ - Copy( st->input_fx, hBWE_FD->old_fdbwe_speech_fx, L_FRAME48k ); - } - ELSE - { - test(); - IF( NE_16( st->last_extl, SWB_BWE ) && NE_16( st->last_extl, FB_BWE ) ) - { - /* resample 48 kHz to 32kHz */ - IF( EQ_16( st->last_bwidth, FB ) ) - { - inner_frame = L_FRAME48k; - move16(); - inner_Fs = 48000; - move32(); - Copy( hBWE_FD->old_fdbwe_speech_fx, new_swb_speech, L_FRAME48k ); - } - ELSE - { - inner_frame = L_FRAME32k; - move16(); - inner_Fs = 32000; - move32(); - - IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) - { - decimate_2_over_3_allpass_fx( hBWE_FD->old_fdbwe_speech_fx, L_FRAME48k, new_swb_speech, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx ); - } - ELSE - { - lerp( hBWE_FD->old_fdbwe_speech_fx, new_swb_speech, inner_frame, L_FRAME48k ); - } - - test(); - IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) && st->idchan == 0 ) - { - FOR( i = 0; i < STEREO_DFT_OVL_32k; i++ ) - { - hCPE->hStereoDft->output_mem_dmx_32k_fx[i] = L_shr( Mpy_32_16_1( hCPE->hStereoDft->win_32k_fx[STEREO_DFT_OVL_32k - 1 - i], new_swb_speech[( ( inner_frame + i ) - STEREO_DFT_OVL_32k )] ), 1 ); // Q15 - move32(); - } - } - } - - Sample_Delay_SWB_BWE = NS2SA_FX2( inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); - move16(); - test(); - IF( st->element_mode > EVS_MONO && EQ_16( st->L_frame, L_FRAME16k ) ) - { - Sample_Delay_SWB_BWE = NS2SA_FX2( inner_Fs, DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS ); - move16(); - } - IF( st->element_mode > EVS_MONO ) - { - Sample_Delay_SWB_BWE = sub( Sample_Delay_SWB_BWE, NS2SA_FX2( inner_Fs, DELAY_FIR_RESAMPL_NS ) ); - } - - Copy( new_swb_speech, &old_input_fx[Sample_Delay_SWB_BWE], inner_frame ); - set16_fx( old_input_fx, 0, Sample_Delay_SWB_BWE ); - Copy( new_swb_speech + inner_frame - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); - Copy( old_input_fx, hBWE_FD->L_old_wtda_swb_fx, inner_frame ); - } - - /* resample 48 kHz to 32kHz */ - IF( EQ_16( st->bwidth, FB ) ) - { - Copy( st->input_fx, new_swb_speech, L_FRAME48k ); - } - ELSE - { - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) - { - Word16 dec_2_over_3_mem_tmp[L_FILT_2OVER3], dec_2_over_3_mem_lp_tmp[L_FILT_2OVER3_LP]; - - decimate_2_over_3_allpass_fx( st->input_fx, L_FRAME48k - hCPE->hStereoTCA->lMemRecalc, new_swb_speech, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx ); - - Copy( hBWE_TD->dec_2_over_3_mem_fx, dec_2_over_3_mem_tmp, L_FILT_2OVER3 ); - Copy( hBWE_TD->dec_2_over_3_mem_lp_fx, dec_2_over_3_mem_lp_tmp, L_FILT_2OVER3_LP ); - - decimate_2_over_3_allpass_fx( st->input_fx + L_FRAME48k - hCPE->hStereoTCA->lMemRecalc, hCPE->hStereoTCA->lMemRecalc, new_swb_speech + L_FRAME32k - lMemRecalc32k, dec_2_over_3_mem_tmp, allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, dec_2_over_3_mem_lp_tmp ); - } - ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) - { - decimate_2_over_3_allpass_fx( st->input_fx, L_FRAME48k, new_swb_speech, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx ); - } - ELSE /* IVAS_CPE_DFT */ - { - Word16 out_start_ind, out_end_ind; - stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, new_swb_speech_fx, &out_start_ind, &out_end_ind, st->idchan, input_Fs, 32000, 0, NULL ); - Copy_Scale_sig32_16( new_swb_speech_fx - STEREO_DFT_OVL_MAX, new_swb_speech - STEREO_DFT_OVL_MAX, L_FRAME48k + STEREO_DFT_OVL_MAX, add( q_reImBuffer, 1 ) ); // Q0 - Copy( new_swb_speech - Sample_Delay_SWB_BWE32k, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE32k ); // Q0 - } - } - } - } - ELSE - { - /* resample 48 kHz to 32kHz */ - IF( EQ_16( st->bwidth, FB ) ) - { - Copy( st->input_fx, new_swb_speech, L_FRAME48k ); - } - ELSE - { - decimate_2_over_3_allpass_fx( st->input_fx, L_FRAME48k, new_swb_speech, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx ); - } - } - } - - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( st->core == ACELP_CORE ) && NE_16( st->extl, SWB_BWE_HIGHRATE ) && NE_16( st->extl, FB_BWE_HIGHRATE ) ) || - ( ( EQ_32( st->total_brate, ACELP_9k60 ) || st->rf_mode ) && EQ_16( st->bwidth, SWB ) && ( st->element_mode == EVS_MONO ) ) ) - { - Word32 CldfbHB_fx = 0; // fixed counterpart - Word16 CldfbHB_fx_e = 0; // fixed counterpart -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; -#endif - Word16 realQ_neg1, imagQ_neg1, exp = 0, Cldfbtemp1; - move32(); - move16(); - move16(); - - IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) - { - Word16 out_start_ind, out_end_ind; - Word16 exp_icbweRefEner_fx; - Copy_Scale_sig_16_32( (const Word16 *) &old_input_fx[0], &old_input_fx_32[0], NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k, Q15 ); // Q15 - CldfbHB_fx = stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, old_input_fx_32 + STEREO_DFT_OVL_16k, &out_start_ind, &out_end_ind, st->idchan, input_Fs, 16000, st->L_frame, &CldfbHB_fx_e ); - Copy_Scale_sig_32_16( (const Word32 *) &old_input_fx_32[0], &old_input_fx[0], NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k, -Q15 ); // Q0 - - /* delay corresponding to CLDFB delay */ - Copy( old_input_fx + STEREO_DFT_OVL_16k - 20, shb_speech, L_FRAME16k ); - Copy( old_input_fx, hBWE_TD->old_speech_shb_fx + L_LOOK_16k + L_SUBFR16k - ( STEREO_DFT_OVL_16k - 20 ), STEREO_DFT_OVL_16k - 20 ); - Copy( old_input_fx, hCPE->hStereoICBWE->mem_shb_speech_ref_fx, STEREO_DFT_OVL_16k - 20 ); // Q0 - hCPE->hStereoICBWE->mem_shb_speech_ref_e = 15; - move16(); - - IF( LE_32( CldfbHB_fx, 0 ) ) - { - CldfbHB_fx = EPSILON_FX; - move32(); - } - CldfbHB_fx = L_shl( CldfbHB_fx, exp ); /* CldfbHB_ener = CldfbHB_fl*2^(exp) */ - Cldfbtemp1 = Log2_norm_lc( CldfbHB_fx ); /* Log2_norm_lc(t) = 2^15*(log2(t/2^30)) */ - Cldfbtemp1 = sub( shr( Cldfbtemp1, 6 ), shl( add( sub( Q31 - Q30, CldfbHB_fx_e ), exp ), 9 ) ); - CldfbHB_fx = L_mult( Cldfbtemp1, 9864 ); /* Q9 + Q15 + Q1 = Q25 */ - CldfbHB_fx = Mpy_32_16_1( L_sub( CldfbHB_fx, 1 << Q25 ), 11611 /* 0.1 * 0.221462 in Q19 */ ); - /* Resulting Q = Q25 + Q19 - Q15 = Q29 */ - hBWE_TD->cldfbHBLT = mac_r( CldfbHB_fx, 29491 /*0.9 Q15*/, hBWE_TD->cldfbHBLT ); /* cldfbHBLT is in Q13 */ - move16(); - - exp_lbEner = hCPE->hStereoDft->lbEner_fx_e; - move32(); - lbEner = Mpy_32_16_1( Sqrt32( hCPE->hStereoDft->lbEner_fx, &exp_lbEner ), 1638 /* 0.05 in Q15 */ ); - exp_icbweRefEner_fx = hCPE->hStereoDft->icbweRefEner_fx_e; - move16(); - hCPE->hStereoICBWE->icbweRefEner_fx = Mpy_32_16_1( Sqrt32( hCPE->hStereoDft->icbweRefEner_fx, &exp_icbweRefEner_fx ), 1638 /* 0.05 in Q15 */ ); - move32(); - hCPE->hStereoICBWE->icbweRefEner_fx_e = exp_icbweRefEner_fx; - move16(); - // lbEner = 0.05f * (float) sqrt( hCPE->hStereoDft->lbEner ); - thr = icbwe_thr_DFT_fx; - regV = icbwe_regressionValuesDFT_fx; - } - ELSE - { - IF( EQ_16( st->L_frame, L_FRAME ) ) - { - startB = 34; - move16(); - endB = 14; - move16(); - FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) - { - uB = 0; - move16(); - FOR( nB = startB; nB > endB; nB-- ) - { - realBufferFlipped[ts][uB] = realBuffer[ts][nB]; - move32(); - if ( s_and( ts, 1 ) != 0 ) - { - realBufferFlipped[ts][uB] = L_negate( realBufferFlipped[ts][uB] ); - move32(); - } - imagBufferFlipped[ts][uB] = imagBuffer[ts][nB]; - move32(); - if ( s_and( ts, 1 ) == 0 ) - { - imagBufferFlipped[ts][uB] = L_negate( imagBufferFlipped[ts][uB] ); - move32(); - } - uB = add( uB, 1 ); /* uB ++ */ - } - } - } - ELSE - { - startB = 39; - move16(); - endB = 19; - move16(); - FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) - { - uB = 0; - move16(); - FOR( nB = startB; nB > endB; nB-- ) - { - realBufferFlipped[ts][uB] = L_negate( realBuffer[ts][nB] ); - move32(); - imagBufferFlipped[ts][uB] = imagBuffer[ts][nB]; - move32(); - uB = add( uB, 1 ); /* uB ++ */ - } - } - } - - FOR( nB = 0; nB < 10; nB++ ) - { - FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) - { - realQ_neg1 = extract_l( L_shr( realBufferFlipped[ts][nB], 16 ) ); - imagQ_neg1 = extract_l( L_shr( imagBufferFlipped[ts][nB], 16 ) ); /* Q(-1), headroom needed */ - -#ifdef BASOP_NOGLOB - CldfbHB_fx = L_mac0_o( CldfbHB_fx, realQ_neg1, realQ_neg1, &Overflow ); - CldfbHB_fx = L_mac0_o( CldfbHB_fx, imagQ_neg1, imagQ_neg1, &Overflow ); /* Q(-2) */ -#else - CldfbHB_fx = L_mac0( CldfbHB_fx, realQ_neg1, realQ_neg1 ); - CldfbHB_fx = L_mac0( CldfbHB_fx, imagQ_neg1, imagQ_neg1 ); /* Q(-2) */ -#endif - } - } - CldfbHB_fx_e = sub( Q31, shl( sub( q_reImBuffer, Q16 ), 1 ) ); - exp = norm_l( CldfbHB_fx ); - CldfbHB_fx = L_shl( CldfbHB_fx, exp ); /* CldfbHB_ener = CldfbHB_fl*2^(exp) */ - Cldfbtemp1 = Log2_norm_lc( CldfbHB_fx ); /* Log2_norm_lc(t) = 2^15*(log2(t/2^30)) */ - Cldfbtemp1 = sub( shr( Cldfbtemp1, 6 ), shl( add( sub( Q31 - Q30, CldfbHB_fx_e ), exp ), 9 ) ); - CldfbHB_fx = L_mult( Cldfbtemp1, 9864 ); /* Q9 + Q15 + Q1 = Q25 */ - CldfbHB_fx = Mpy_32_16_1( L_sub( CldfbHB_fx, 1 << Q25 ), 11611 /* 0.1 * 0.221462 in Q19 */ ); - /* Resulting Q = Q25 + Q19 - Q15 = Q29 */ - hBWE_TD->cldfbHBLT = mac_r( CldfbHB_fx, 29491 /*0.9 Q15*/, hBWE_TD->cldfbHBLT ); /* cldfbHBLT is in Q13 */ - move32(); - - IF( CldfbHB_fx == 0 ) - { - CldfbHB_fx = EPSILLON_FX; - move32(); - } - - test(); - IF( GE_16( st->element_mode, IVAS_CPE_DFT ) && hCPE->hStereoICBWE != NULL ) - { - Word32 icbweRefEner_fx = EPSILON_FX; - Word16 exp_icbweRefEner_fx = 0; - - move32(); - move16(); - FOR( nB = 20; nB < 40; nB++ ) - { - FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) - { - realQ_neg1 = extract_l( L_shr( realBuffer[ts][nB], 16 ) ); - imagQ_neg1 = extract_l( L_shr( imagBuffer[ts][nB], 16 ) ); /* Q(-1), headroom needed */ - icbweRefEner_fx = L_mac0_o( icbweRefEner_fx, realQ_neg1, realQ_neg1, &Overflow ); - icbweRefEner_fx = L_mac0_o( icbweRefEner_fx, imagQ_neg1, imagQ_neg1, &Overflow ); /* Q(-2) */ - } - } - exp_icbweRefEner_fx = sub( Q31, shl( sub( q_reImBuffer, Q16 ), 1 ) ); - hCPE->hStereoICBWE->icbweRefEner_fx = Mpy_32_16_1( Sqrt32( icbweRefEner_fx, &exp_icbweRefEner_fx ), 1638 /* 0.05 in Q15 */ ); - move32(); - hCPE->hStereoICBWE->icbweRefEner_fx_e = exp_icbweRefEner_fx; - move16(); - } - - lbEner = EPSILON_FX; - move32(); - FOR( nB = 0; nB < 20; nB++ ) - { - FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) - { - realQ_neg1 = extract_l( L_shr( realBuffer[ts][nB], 16 ) ); - imagQ_neg1 = extract_l( L_shr( imagBuffer[ts][nB], 16 ) ); /* Q(-1), headroom needed */ - - lbEner = L_mac0_o( lbEner, realQ_neg1, realQ_neg1, &Overflow ); - lbEner = L_mac0_o( lbEner, imagQ_neg1, imagQ_neg1, &Overflow ); /* Q(-2) */ - } - } - exp_lbEner = sub( Q31, shl( sub( q_reImBuffer, Q16 ), 1 ) ); - lbEner = Mpy_32_16_1( Sqrt32( lbEner, &exp_lbEner ), 1638 /* 0.05 in Q15 */ ); - thr = icbwe_thr_TDM_fx; - regV = icbwe_regressionValuesTDM_fx; - - cldfbSynthesis_ivas_fx( realBufferFlipped, imagBufferFlipped, shb_speech_fx_32, -1, st->cldfbSynTd ); - Copy_Scale_sig_32_16( shb_speech_fx_32, shb_speech, L_FRAME16k, negate( sub( q_reImBuffer, 1 ) ) ); - *Q_shb_spch = 0; - move16(); - } - - IF( GE_16( st->element_mode, IVAS_CPE_DFT ) && hCPE->hStereoICBWE != NULL ) - { - Word16 exp_t; - hCPE->hStereoICBWE->MSFlag = 0; /* Init the multi-source flag */ - move16(); - v = Mpy_32_16_1( sum16_fx( st->voicing_fx, 3 ), 10923 /* 0.33333 in Q15 */ ); - - // t = log10f( ( hCPE->hStereoICBWE->icbweRefEner + 1e-6f ) / ( lbEner + 1e-6f ) ); - t = L_deposit_h( BASOP_Util_Divide3232_Scale( L_add( hCPE->hStereoICBWE->icbweRefEner_fx, EPSILON_FX ), L_add( lbEner, EPSILON_FX ), &exp_t ) ); - exp_t = add( exp_t, sub( hCPE->hStereoICBWE->icbweRefEner_fx_e, exp_lbEner ) ); - exp = norm_l( t ); - t = L_shl( t, exp ); - t_16 = Log2_norm_lc( t ); /* Log2_norm_lc(t) = 2^15*(log2(t/2^30)) */ - t_16 = sub( shr( t_16, 6 ), shl( add( sub( Q31 - Q30, exp_t ), exp ), 9 ) ); - t = L_mult( t_16, 9864 ); /* Q9 + Q15 + Q1 = Q25 */ - /* Three Level Decision Tree to calculate a regression value first */ - IF( LT_32( t, thr[0] ) ) /* level 1 */ - { - IF( LT_32( t, thr[1] ) ) /* level 2 */ - { - IF( LT_32( v, thr[3] ) ) - { - regression = regV[0]; /* level 3 */ - move32(); - } - ELSE - { - regression = regV[1]; - move32(); - } - } - ELSE - { - IF( LT_32( v, thr[4] ) ) - { - regression = regV[2]; /* level 3 */ - move32(); - } - ELSE - { - regression = regV[3]; - move32(); - } - } - } - ELSE - { - IF( LT_32( t, thr[2] ) ) /* level 2 */ - { - IF( LT_32( v, thr[5] ) ) - { - regression = regV[4]; /* level 3 */ - move32(); - } - ELSE - { - regression = regV[5]; - move32(); - } - } - ELSE - { - IF( LT_32( v, thr[6] ) ) - { - regression = regV[6]; /* level 3 */ - move32(); - } - ELSE - { - regression = regV[7]; - move32(); - } - } - } - - test(); - test(); - /* Convert the regression to a hard decision (classification) */ - IF( GT_32( regression, 1696512081 /* 0.79f in Q31*/ ) && !( LT_16( st->bwidth, SWB ) || hCPE->hCoreCoder[0]->vad_flag == 0 ) ) - { - hCPE->hStereoICBWE->MSFlag = 1; - move16(); - } - } - - test(); - test(); - IF( NE_16( st->extl, WB_TBE ) && NE_16( st->extl, SWB_TBE ) && NE_16( st->extl, FB_TBE ) ) - { - /* Update the previous superwideband speech buffer in case of a SWB_BWE frame - this code is in swb_tbe_enc */ - delay = L_LOOK_16k + L_SUBFR16k; - move16(); - Copy( shb_speech + sub( L_FRAME16k, delay ), hBWE_TD->old_speech_shb_fx, delay ); - } - } - ELSE - { - test(); - test(); - IF( ( EQ_16( st->bwidth, FB ) || st->core == ACELP_CORE ) && ( st->element_mode == EVS_MONO ) ) - { - InitSWBencBufferStates_fx( st->hBWE_TD, shb_speech ); - } - ELSE - { - IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) - { - IF( EQ_16( st->L_frame, L_FRAME ) ) - { - L_resamp = 560; /* 6.4 kHz core -> 6 - 14 kHz SHB target. 20 ms is 560 samples in 28 kHz sample rate */ - move16(); - } - ELSE - { - L_resamp = 620; /* 8 kHz core -> 7.5 - 15.5 kHz SHB target. 20 ms is 620 samples in 31 kHz sample rate */ - move16(); - } - - /* Dirty downsampling to match Nyquist to upper frequency limit of target */ - lerp( st->input_fx, new_swb_speech, L_resamp, (int16_t) Mpy_32_32( input_Fs, one_by_50_Q31 ) ); - - /* flip the spectrum */ - Copy( new_swb_speech, spchTmp, L_resamp ); - FOR( i = 0; i < L_resamp; i = i + 2 ) - { - spchTmp[i] = negate( spchTmp[i] ); - move16(); - } - - /* Dirty upsampling to match Nyquist/2 to lower frequency limit of target (reversed spectrum)*/ - lerp( spchTmp, spchTmp2, L_FRAME32k, L_resamp ); - Copy( spchTmp2, spchTmp, L_FRAME32k ); - } - ELSE - { - /* flip the spectrum */ - Copy( new_swb_speech, spchTmp, L_FRAME32k ); - - FOR( i = 0; i < L_FRAME32k; i = i + 2 ) - { - spchTmp[i] = negate( spchTmp[i] ); - move16(); - } - } - - Decimate_allpass_steep_fx( spchTmp, hBWE_TD->state_ana_filt_shb_fx, L_FRAME32k, shb_speech ); - - Copy( shb_speech + L_FRAME16k - ( L_LOOK_16k + L_SUBFR16k ), hBWE_TD->old_speech_shb_fx, L_LOOK_16k + L_SUBFR16k ); - - /*Compute the past overlap for potential next iDFTs SHB*/ - IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) - { - FOR( i = 0; i < STEREO_DFT_OVL_16k; i++ ) - { - hCPE->hStereoDft->output_mem_dmx_16k_shb_fx[i] = L_mult0( shb_speech[20 + i], mult_r( hCPE->hStereoDft->win_ana_16k_fx[STEREO_DFT_OVL_16k - 1 - i], hCPE->hStereoDft->win_ana_16k_fx[STEREO_DFT_OVL_16k - 1 - i] ) ); // Q15 - move32(); - } - } - } - - IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) - { - /* Reset CLDFB synthesis buffer */ - set32_fx( st->cldfbSynTd->cldfb_state_fx, 0, st->cldfbSynTd->p_filter_length ); - } - ELSE - { - hCPE->hStereoDft->flip_sign = negate( hCPE->hStereoDft->flip_sign ); /* Make sure sign is updated even if DFT SHB target is not generated */ - move16(); - } - } - - /* Memory reset to compensate for 0.9375 ms offset when transitioning from IO to SWB */ - /* When switching from n >1 to n = 1, we keep the enc/dec delay as 8.75/3.25 and below code not needed; - only when n = 1 start, it will be 9.6875/2.3125 in that case this reset is needed for IO->BWE.*/ - test(); - IF( EQ_16( st->last_extl, -1 ) && ( st->element_mode == EVS_MONO ) ) - { - delay = NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ); - move16(); - FOR( i = 0; i < delay; i++ ) - { - shb_speech[i] = mult_r( mult_r( i, 983 /*0.03f Q15*/ ), shb_speech[2 * delay - 1 - i] ); - move16(); - } - } - - return; -} diff --git a/lib_enc/swb_pre_proc_fx.c b/lib_enc/swb_pre_proc_fx.c index 79ca9555d..623ad7b6d 100644 --- a/lib_enc/swb_pre_proc_fx.c +++ b/lib_enc/swb_pre_proc_fx.c @@ -9,9 +9,12 @@ #include "rom_com_fx.h" #include "rom_com.h" #include "stl.h" -#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ +#include "ivas_prot.h" /* Function prototypes */ +#include "ivas_prot_fx.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" +#include "ivas_rom_enc.h" #include @@ -52,8 +55,11 @@ void wb_pre_proc_fx( Word16 temp_buf[320]; Word16 Q_wb_sp, i, max_wb; Word16 fSwitchFromIO = 0; + move16(); Word32 temp1 = 0; + move32(); Word32 temp2 = 0; + move32(); SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; @@ -93,7 +99,7 @@ void wb_pre_proc_fx( temp2 = L_mac0( temp2, temp_buf[i - 1], temp_buf[i] ); } - if ( temp2 < Mult_32_16( temp1, 31129 /*0.95f*/ ) ) + IF( temp2 < Mult_32_16( temp1, 31129 /*0.95f*/ ) ) { Q_wb_sp = sub( Q_wb_sp, 3 ); /* leave 3 bit headroom */ } @@ -107,15 +113,17 @@ void wb_pre_proc_fx( IF( EQ_16( st_fx->extl, WB_BWE ) || EQ_16( st_fx->extl, WB_TBE ) || st_fx->igf != 0 ) { ramp_flag = 0; + move16(); test(); test(); test(); test(); - IF( ( NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, WB_BWE ) && st_fx->igf == 0 ) || - ( st_fx->igf != 0 && fSwitchFromIO != 0 ) ) + if ( ( NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, WB_BWE ) && st_fx->igf == 0 ) || + ( st_fx->igf != 0 && fSwitchFromIO != 0 ) ) { ramp_flag = 1; + move16(); } IF( !hSC_VBR->ppp_mode ) @@ -235,15 +243,15 @@ void wb_pre_proc_ivas_fx( test(); test(); test(); - IF( ( EQ_32( st_fx->last_total_brate, ACELP_6k60 ) ) || - ( EQ_32( st_fx->last_total_brate, ACELP_8k85 ) ) || - ( EQ_32( st_fx->last_total_brate, ACELP_12k65 ) ) || - ( EQ_32( st_fx->last_total_brate, ACELP_14k25 ) ) || - ( EQ_32( st_fx->last_total_brate, ACELP_15k85 ) ) || - ( EQ_32( st_fx->last_total_brate, ACELP_18k25 ) ) || - ( EQ_32( st_fx->last_total_brate, ACELP_19k85 ) ) || - ( EQ_32( st_fx->last_total_brate, ACELP_23k05 ) ) || - ( EQ_32( st_fx->last_total_brate, ACELP_23k85 ) ) ) + if ( ( EQ_32( st_fx->last_total_brate, ACELP_6k60 ) ) || + ( EQ_32( st_fx->last_total_brate, ACELP_8k85 ) ) || + ( EQ_32( st_fx->last_total_brate, ACELP_12k65 ) ) || + ( EQ_32( st_fx->last_total_brate, ACELP_14k25 ) ) || + ( EQ_32( st_fx->last_total_brate, ACELP_15k85 ) ) || + ( EQ_32( st_fx->last_total_brate, ACELP_18k25 ) ) || + ( EQ_32( st_fx->last_total_brate, ACELP_19k85 ) ) || + ( EQ_32( st_fx->last_total_brate, ACELP_23k05 ) ) || + ( EQ_32( st_fx->last_total_brate, ACELP_23k85 ) ) ) { fSwitchFromIO = 1; move16(); @@ -337,7 +345,9 @@ void wb_pre_proc_ivas_fx( ELSE IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { Word16 l_recalc_16k = L_MEM_RECALC_16K + L_FILT16k + 1; /* Note: "+1" is used because L_FILT16k is not divisible by 4 */ + move16(); Word16 l_recalc_4k = ( L_MEM_RECALC_16K + L_FILT16k + 1 ) / 4; + move16(); Sample_Delay_WB_BWE = NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS ); IF( EQ_16( last_element_mode, IVAS_CPE_DFT ) ) @@ -517,6 +527,7 @@ void swb_pre_proc_fx( Word32 CldfbHB_ener; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif Word16 realQ_neg1, imagQ_neg1, exp, Cldfbtemp1; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; @@ -587,6 +598,8 @@ void swb_pre_proc_fx( decimate_2_over_3_allpass_fx( hBWE_FD->old_fdbwe_speech_fx, L_FRAME48k, new_swb_speech_fx, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx ); } + move16(); + move16(); Sample_Delay_SWB_BWE = NS2SA_FX2( inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); Copy( new_swb_speech_fx, &old_input_fx[Sample_Delay_SWB_BWE], inner_frame ); @@ -628,27 +641,33 @@ void swb_pre_proc_fx( test(); test(); test(); - IF( ( EQ_16( st_fx->core, ACELP_CORE ) && NE_16( st_fx->extl, SWB_BWE_HIGHRATE ) && NE_16( st_fx->extl, FB_BWE_HIGHRATE ) ) || ( ( EQ_32( st_fx->total_brate, 9600 ) || st_fx->rf_mode != 0 ) && EQ_16( st_fx->bwidth, SWB ) ) ) + IF( ( st_fx->core == ACELP_CORE && NE_16( st_fx->extl, SWB_BWE_HIGHRATE ) && NE_16( st_fx->extl, FB_BWE_HIGHRATE ) ) || ( ( EQ_32( st_fx->total_brate, 9600 ) || st_fx->rf_mode != 0 ) && EQ_16( st_fx->bwidth, SWB ) ) ) { IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { startB = 34; + move16(); endB = 14; + move16(); FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) { uB = 0; + move16(); FOR( nB = startB; nB > endB; nB-- ) { - move16(); realBufferFlipped[ts][uB] = realBuffer[ts][nB]; + move32(); if ( s_and( ts, 1 ) != 0 ) { realBufferFlipped[ts][uB] = L_negate( realBufferFlipped[ts][uB] ); + move32(); } imagBufferFlipped[ts][uB] = imagBuffer[ts][nB]; + move32(); if ( s_and( ts, 1 ) == 0 ) { imagBufferFlipped[ts][uB] = L_negate( imagBufferFlipped[ts][uB] ); + move32(); } uB = add( uB, 1 ); /* uB ++ */ } @@ -657,14 +676,19 @@ void swb_pre_proc_fx( ELSE { startB = 39; + move16(); endB = 19; + move16(); FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) { uB = 0; + move16(); FOR( nB = startB; nB > endB; nB-- ) { realBufferFlipped[ts][uB] = L_negate( realBuffer[ts][nB] ); + move32(); imagBufferFlipped[ts][uB] = imagBuffer[ts][nB]; + move32(); uB = add( uB, 1 ); /* uB ++ */ } } @@ -673,6 +697,7 @@ void swb_pre_proc_fx( /* Highband energy computation for gain shape control in case of bandwidth switching fix*/ { CldfbHB_ener = 0; + move32(); FOR( nB = 0; nB < 10; nB++ ) { FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) @@ -700,6 +725,7 @@ void swb_pre_proc_fx( cldfbSynthesisFiltering( st_fx->cldfbSynTd, realBufferFlipped, imagBufferFlipped, cldfbScale, shb_speech_fx, 0, CLDFB_NO_COL_MAX, cldfbWorkBuffer ); *Q_shb_spch = 0; /*shb_speech_fx : Q0*/ + move16(); test(); test(); @@ -712,6 +738,7 @@ void swb_pre_proc_fx( } ELSE { + test(); IF( EQ_16( st_fx->bwidth, FB ) || EQ_16( st_fx->core, ACELP_CORE ) ) { set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); @@ -725,6 +752,7 @@ void swb_pre_proc_fx( FOR( i = 0; i < L_FRAME32k; i = i + 2 ) { spchTmp_fx[i] = negate( spchTmp_fx[i] ); + move16(); } Decimate_allpass_steep_fx( spchTmp_fx, hBWE_TD->state_ana_filt_shb_fx, L_FRAME32k, shb_speech_fx ); @@ -740,6 +768,704 @@ void swb_pre_proc_fx( FOR( i = 0; i < delay; i++ ) { shb_speech_fx[i] = mult_r( mult_r( i, 983 /*0.03f Q15*/ ), shb_speech_fx[2 * delay - 1 - i] ); + move16(); + } + } + + return; +} + +/*-------------------------------------------------------------------* + * swb_pre_proc() + * + * - Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB target signal + * for SWB TBE or SWB BWE coding + * - Common SWB TBE and SWB BWE pre-processing + *-------------------------------------------------------------------*/ + +/*full implementation pending*/ +void swb_pre_proc_ivas_fx( + Encoder_State *st, /* i/o: encoder state structure */ + Word16 *new_swb_speech, /* o : original input signal at 32kHz - Q0 */ + Word32 *new_swb_speech_fx, /* o : original input signal at 32kHz - Q - q_reImBuffer */ + Word16 *shb_speech, /* o : SHB target signal (6-14kHz) at 16kHz- Q(Q_shb_spch) */ + Word16 *Q_shb_spch, + Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real buffer Q - q_reImbuffer */ + Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag buffer Q - q_reImbuffer */ + Word16 q_reImBuffer, /* i : scale data of real and imag CLDFB buffers */ + CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ +) +{ + Word16 Sample_Delay_SWB_BWE, inner_frame, delay; + TD_BWE_ENC_HANDLE hBWE_TD; + FD_BWE_ENC_HANDLE hBWE_FD; + Word32 inner_Fs, input_Fs; + Word16 old_input_fx[NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k]; // fixed counterpart + Word32 old_input_fx_32[NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k]; // fixed counterpart + Word16 spchTmp[L_FRAME32k], spchTmp2[L_FRAME32k]; + Word16 i, j, L_resamp; + Word16 startB, endB; + Word32 *realBufferFlipped[CLDFB_NO_COL_MAX]; + Word32 *imagBufferFlipped[CLDFB_NO_COL_MAX]; + Word32 realBufferTmp[CLDFB_NO_COL_MAX][20]; + Word32 imagBufferTmp[CLDFB_NO_COL_MAX][20]; + Word32 shb_speech_fx_32[L_FRAME16k]; + Word16 ts, nB, uB; + Word32 v, t, regression; + Word16 t_16; + const Word32 *thr, *regV; + Word32 lbEner; + Word16 exp_lbEner = 0; + Word16 Sample_Delay_SWB_BWE32k, lMemRecalc32k, dft_ovl32k; + Word32 one_by_50_Q31 = 42949673; + + lMemRecalc32k = NS2SA_FX2( 32000, L_MEM_RECALC_NS ); + move16(); // exp_lbEner + move16(); // lMemRecalc32k + move32(); // one_by_50_Q31 + + /* initialization */ + hBWE_TD = st->hBWE_TD; + hBWE_FD = st->hBWE_FD; + input_Fs = st->input_Fs; + + FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ ) + { + set32_fx( realBufferTmp[j], 0, 20 ); + set32_fx( imagBufferTmp[j], 0, 20 ); + realBufferFlipped[j] = realBufferTmp[j]; + imagBufferFlipped[j] = imagBufferTmp[j]; + } + + set16_fx( old_input_fx, 0, NS2SA_FX2( 48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k ); + + IF( EQ_32( st->input_Fs, 32000 ) ) + { + IF( st->element_mode > EVS_MONO ) + { + Sample_Delay_SWB_BWE = NS2SA_FX2( 32000, DELAY_FD_BWE_ENC_12k8_NS ); + IF( EQ_16( st->L_frame, L_FRAME16k ) ) + { + Sample_Delay_SWB_BWE = NS2SA_FX2( 32000, DELAY_FD_BWE_ENC_16k_NS ); + } + + Copy( st->input_fx - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); + Copy( st->input_fx - L_FRAME32k, hBWE_FD->old_fdbwe_speech_fx, L_FRAME32k ); + + test(); + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && GE_16( st->bwidth, SWB ) ) + { + Copy( st->input_fx - hCPE->hStereoTCA->lMemRecalc, hBWE_FD->L_old_wtda_swb_fx + L_FRAME32k - sub( hCPE->hStereoTCA->lMemRecalc, Sample_Delay_SWB_BWE ), sub( hCPE->hStereoTCA->lMemRecalc, Sample_Delay_SWB_BWE ) ); + } + ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) && GE_16( st->bwidth, SWB ) ) + { + Copy( st->input_fx - hCPE->hStereoDft->dft_ovl, hBWE_FD->L_old_wtda_swb_fx + L_FRAME32k - sub( hCPE->hStereoDft->dft_ovl, Sample_Delay_SWB_BWE ), sub( hCPE->hStereoDft->dft_ovl, Sample_Delay_SWB_BWE ) ); + } + } + + Copy( st->input_fx, new_swb_speech, L_FRAME32k ); + + test(); + test(); + IF( NE_16( st->last_extl, SWB_BWE ) && NE_16( st->last_extl, FB_BWE ) && NE_16( st->extl, SWB_BWE_HIGHRATE ) ) + { + Sample_Delay_SWB_BWE = NS2SA_FX2( 32000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); + test(); + IF( st->element_mode > EVS_MONO && EQ_16( st->L_frame, L_FRAME16k ) ) + { + Sample_Delay_SWB_BWE = NS2SA_FX2( 32000, DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS ); + } + IF( st->element_mode > EVS_MONO ) + { + Sample_Delay_SWB_BWE = sub( Sample_Delay_SWB_BWE, NS2SA_FX2( 32000, DELAY_FIR_RESAMPL_NS ) ); + } + + Copy( hBWE_FD->old_fdbwe_speech_fx, &old_input_fx[Sample_Delay_SWB_BWE], L_FRAME32k ); + + set16_fx( old_input_fx, 0, Sample_Delay_SWB_BWE ); + Copy( hBWE_FD->old_fdbwe_speech_fx + L_FRAME32k - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); + IF( NE_16( st->extl, WB_BWE ) ) + { + Copy( old_input_fx, hBWE_FD->L_old_wtda_swb_fx, L_FRAME32k ); + } + } + + test(); + IF( NE_16( st->extl, SWB_BWE ) && NE_16( st->extl, FB_BWE ) ) + { + Copy( st->input_fx, hBWE_FD->old_fdbwe_speech_fx, L_FRAME32k ); + } + } + ELSE /* 48 kHz */ + { + + Sample_Delay_SWB_BWE32k = NS2SA_FX2( 32000, DELAY_FD_BWE_ENC_12k8_NS ); + move16(); + Sample_Delay_SWB_BWE = NS2SA_FX2( 48000, DELAY_FD_BWE_ENC_12k8_NS ); + move16(); + IF( EQ_16( st->L_frame, L_FRAME16k ) ) + { + Sample_Delay_SWB_BWE32k = NS2SA_FX2( 32000, DELAY_FD_BWE_ENC_16k_NS ); + move16(); + Sample_Delay_SWB_BWE = NS2SA_FX2( 48000, DELAY_FD_BWE_ENC_16k_NS ); + move16(); + } + + dft_ovl32k = 0; + move16(); + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) + { + dft_ovl32k = (Word16) ( STEREO_DFT_OVL_MAX * 32000 / 48000 ); + move16(); + } + + IF( EQ_16( st->codec_mode, MODE1 ) ) + { + IF( st->element_mode > EVS_MONO ) + { + + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) + { + } + ELSE IF( EQ_16( st->bwidth, FB ) ) + { + Copy( st->input_fx - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); + } + + Copy( st->input_fx - L_FRAME48k, hBWE_FD->old_fdbwe_speech_fx, L_FRAME48k ); + + test(); + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && GE_16( st->bwidth, SWB ) ) + { + IF( EQ_16( st->bwidth, SWB ) ) + { + /* buffers hBWE_FD->old_input[] and hBWE_FD->old_wtda_swb[] need to be at 32 kHz (inner) sampling rate */ + + decimate_2_over_3_allpass_fx( st->input_fx - hCPE->hStereoTCA->lMemRecalc, hCPE->hStereoTCA->lMemRecalc, spchTmp, hBWE_TD->dec_2_over_3_mem_fx, + allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx ); + + Copy( spchTmp, hBWE_FD->L_old_wtda_swb_fx + L_FRAME32k - sub( lMemRecalc32k, Sample_Delay_SWB_BWE32k ), sub( lMemRecalc32k, Sample_Delay_SWB_BWE32k ) ); + Copy( spchTmp + lMemRecalc32k - Sample_Delay_SWB_BWE32k, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE32k ); + } + ELSE /* FB_BWE */ + { + Copy( st->input_fx - hCPE->hStereoTCA->lMemRecalc, hBWE_FD->L_old_wtda_swb_fx + L_FRAME48k - sub( hCPE->hStereoTCA->lMemRecalc, Sample_Delay_SWB_BWE ), sub( hCPE->hStereoTCA->lMemRecalc, Sample_Delay_SWB_BWE ) ); + Copy( st->input_fx - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); + } + } + ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) && GE_16( st->bwidth, SWB ) ) + { + IF( EQ_16( st->bwidth, SWB ) ) + { + lerp( st->input_fx - hCPE->hStereoDft->dft_ovl, spchTmp, dft_ovl32k - Sample_Delay_SWB_BWE32k, hCPE->hStereoDft->dft_ovl - Sample_Delay_SWB_BWE ); + + Copy( spchTmp, hBWE_FD->L_old_wtda_swb_fx + L_FRAME32k - ( dft_ovl32k - Sample_Delay_SWB_BWE32k ), dft_ovl32k - Sample_Delay_SWB_BWE32k ); + } + ELSE + { + Copy( st->input_fx - hCPE->hStereoDft->dft_ovl, hBWE_FD->L_old_wtda_swb_fx + L_FRAME48k - ( hCPE->hStereoDft->dft_ovl - Sample_Delay_SWB_BWE ), hCPE->hStereoDft->dft_ovl - Sample_Delay_SWB_BWE ); + } + } + } + + test(); + test(); + test(); + test(); + IF( ( NE_16( st->extl, SWB_BWE ) && NE_16( st->extl, FB_BWE ) && ( st->core == ACELP_CORE ) ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && ( st->core != ACELP_CORE ) ) /*resampling not needed for MDCT cores*/ ) + { + /* move the resampling out of the TDBWE path as new_swb_speech is not needed for TDBWE. */ + Copy( st->input_fx, hBWE_FD->old_fdbwe_speech_fx, L_FRAME48k ); + } + ELSE + { + test(); + IF( NE_16( st->last_extl, SWB_BWE ) && NE_16( st->last_extl, FB_BWE ) ) + { + /* resample 48 kHz to 32kHz */ + IF( EQ_16( st->last_bwidth, FB ) ) + { + inner_frame = L_FRAME48k; + move16(); + inner_Fs = 48000; + move32(); + Copy( hBWE_FD->old_fdbwe_speech_fx, new_swb_speech, L_FRAME48k ); + } + ELSE + { + inner_frame = L_FRAME32k; + move16(); + inner_Fs = 32000; + move32(); + + IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) + { + decimate_2_over_3_allpass_fx( hBWE_FD->old_fdbwe_speech_fx, L_FRAME48k, new_swb_speech, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx ); + } + ELSE + { + lerp( hBWE_FD->old_fdbwe_speech_fx, new_swb_speech, inner_frame, L_FRAME48k ); + } + + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) && st->idchan == 0 ) + { + FOR( i = 0; i < STEREO_DFT_OVL_32k; i++ ) + { + hCPE->hStereoDft->output_mem_dmx_32k_fx[i] = L_shr( Mpy_32_16_1( hCPE->hStereoDft->win_32k_fx[STEREO_DFT_OVL_32k - 1 - i], new_swb_speech[( ( inner_frame + i ) - STEREO_DFT_OVL_32k )] ), 1 ); // Q15 + move32(); + } + } + } + + Sample_Delay_SWB_BWE = NS2SA_FX2( inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); + move16(); + test(); + IF( st->element_mode > EVS_MONO && EQ_16( st->L_frame, L_FRAME16k ) ) + { + Sample_Delay_SWB_BWE = NS2SA_FX2( inner_Fs, DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS ); + move16(); + } + IF( st->element_mode > EVS_MONO ) + { + Sample_Delay_SWB_BWE = sub( Sample_Delay_SWB_BWE, NS2SA_FX2( inner_Fs, DELAY_FIR_RESAMPL_NS ) ); + } + + Copy( new_swb_speech, &old_input_fx[Sample_Delay_SWB_BWE], inner_frame ); + set16_fx( old_input_fx, 0, Sample_Delay_SWB_BWE ); + Copy( new_swb_speech + inner_frame - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); + Copy( old_input_fx, hBWE_FD->L_old_wtda_swb_fx, inner_frame ); + } + + /* resample 48 kHz to 32kHz */ + IF( EQ_16( st->bwidth, FB ) ) + { + Copy( st->input_fx, new_swb_speech, L_FRAME48k ); + } + ELSE + { + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) + { + Word16 dec_2_over_3_mem_tmp[L_FILT_2OVER3], dec_2_over_3_mem_lp_tmp[L_FILT_2OVER3_LP]; + + decimate_2_over_3_allpass_fx( st->input_fx, L_FRAME48k - hCPE->hStereoTCA->lMemRecalc, new_swb_speech, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx ); + + Copy( hBWE_TD->dec_2_over_3_mem_fx, dec_2_over_3_mem_tmp, L_FILT_2OVER3 ); + Copy( hBWE_TD->dec_2_over_3_mem_lp_fx, dec_2_over_3_mem_lp_tmp, L_FILT_2OVER3_LP ); + + decimate_2_over_3_allpass_fx( st->input_fx + L_FRAME48k - hCPE->hStereoTCA->lMemRecalc, hCPE->hStereoTCA->lMemRecalc, new_swb_speech + L_FRAME32k - lMemRecalc32k, dec_2_over_3_mem_tmp, allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, dec_2_over_3_mem_lp_tmp ); + } + ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) + { + decimate_2_over_3_allpass_fx( st->input_fx, L_FRAME48k, new_swb_speech, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx ); + } + ELSE /* IVAS_CPE_DFT */ + { + Word16 out_start_ind, out_end_ind; + stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, new_swb_speech_fx, &out_start_ind, &out_end_ind, st->idchan, input_Fs, 32000, 0, NULL ); + Copy_Scale_sig32_16( new_swb_speech_fx - STEREO_DFT_OVL_MAX, new_swb_speech - STEREO_DFT_OVL_MAX, L_FRAME48k + STEREO_DFT_OVL_MAX, add( q_reImBuffer, 1 ) ); // Q0 + Copy( new_swb_speech - Sample_Delay_SWB_BWE32k, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE32k ); // Q0 + } + } + } + } + ELSE + { + /* resample 48 kHz to 32kHz */ + IF( EQ_16( st->bwidth, FB ) ) + { + Copy( st->input_fx, new_swb_speech, L_FRAME48k ); + } + ELSE + { + decimate_2_over_3_allpass_fx( st->input_fx, L_FRAME48k, new_swb_speech, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx ); + } + } + } + + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( st->core == ACELP_CORE ) && NE_16( st->extl, SWB_BWE_HIGHRATE ) && NE_16( st->extl, FB_BWE_HIGHRATE ) ) || + ( ( EQ_32( st->total_brate, ACELP_9k60 ) || st->rf_mode ) && EQ_16( st->bwidth, SWB ) && ( st->element_mode == EVS_MONO ) ) ) + { + Word32 CldfbHB_fx = 0; // fixed counterpart + Word16 CldfbHB_fx_e = 0; // fixed counterpart +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; + move16(); +#endif + Word16 realQ_neg1, imagQ_neg1, exp = 0, Cldfbtemp1; + move32(); + move16(); + move16(); + + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) + { + Word16 out_start_ind, out_end_ind; + Word16 exp_icbweRefEner_fx; + Copy_Scale_sig_16_32( (const Word16 *) &old_input_fx[0], &old_input_fx_32[0], NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k, Q15 ); // Q15 + CldfbHB_fx = stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, old_input_fx_32 + STEREO_DFT_OVL_16k, &out_start_ind, &out_end_ind, st->idchan, input_Fs, 16000, st->L_frame, &CldfbHB_fx_e ); + Copy_Scale_sig_32_16( (const Word32 *) &old_input_fx_32[0], &old_input_fx[0], NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k, -Q15 ); // Q0 + + /* delay corresponding to CLDFB delay */ + Copy( old_input_fx + STEREO_DFT_OVL_16k - 20, shb_speech, L_FRAME16k ); + Copy( old_input_fx, hBWE_TD->old_speech_shb_fx + L_LOOK_16k + L_SUBFR16k - ( STEREO_DFT_OVL_16k - 20 ), STEREO_DFT_OVL_16k - 20 ); + Copy( old_input_fx, hCPE->hStereoICBWE->mem_shb_speech_ref_fx, STEREO_DFT_OVL_16k - 20 ); // Q0 + hCPE->hStereoICBWE->mem_shb_speech_ref_e = 15; + move16(); + + IF( LE_32( CldfbHB_fx, 0 ) ) + { + CldfbHB_fx = EPSILON_FX; + move32(); + } + CldfbHB_fx = L_shl( CldfbHB_fx, exp ); /* CldfbHB_ener = CldfbHB_fl*2^(exp) */ + Cldfbtemp1 = Log2_norm_lc( CldfbHB_fx ); /* Log2_norm_lc(t) = 2^15*(log2(t/2^30)) */ + Cldfbtemp1 = sub( shr( Cldfbtemp1, 6 ), shl( add( sub( Q31 - Q30, CldfbHB_fx_e ), exp ), 9 ) ); + CldfbHB_fx = L_mult( Cldfbtemp1, 9864 ); /* Q9 + Q15 + Q1 = Q25 */ + CldfbHB_fx = Mpy_32_16_1( L_sub( CldfbHB_fx, 1 << Q25 ), 11611 /* 0.1 * 0.221462 in Q19 */ ); + /* Resulting Q = Q25 + Q19 - Q15 = Q29 */ + hBWE_TD->cldfbHBLT = mac_r( CldfbHB_fx, 29491 /*0.9 Q15*/, hBWE_TD->cldfbHBLT ); /* cldfbHBLT is in Q13 */ + move16(); + + exp_lbEner = hCPE->hStereoDft->lbEner_fx_e; + move32(); + lbEner = Mpy_32_16_1( Sqrt32( hCPE->hStereoDft->lbEner_fx, &exp_lbEner ), 1638 /* 0.05 in Q15 */ ); + exp_icbweRefEner_fx = hCPE->hStereoDft->icbweRefEner_fx_e; + move16(); + hCPE->hStereoICBWE->icbweRefEner_fx = Mpy_32_16_1( Sqrt32( hCPE->hStereoDft->icbweRefEner_fx, &exp_icbweRefEner_fx ), 1638 /* 0.05 in Q15 */ ); + move32(); + hCPE->hStereoICBWE->icbweRefEner_fx_e = exp_icbweRefEner_fx; + move16(); + // lbEner = 0.05f * (float) sqrt( hCPE->hStereoDft->lbEner ); + thr = icbwe_thr_DFT_fx; + regV = icbwe_regressionValuesDFT_fx; + } + ELSE + { + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + startB = 34; + move16(); + endB = 14; + move16(); + FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) + { + uB = 0; + move16(); + FOR( nB = startB; nB > endB; nB-- ) + { + realBufferFlipped[ts][uB] = realBuffer[ts][nB]; + move32(); + if ( s_and( ts, 1 ) != 0 ) + { + realBufferFlipped[ts][uB] = L_negate( realBufferFlipped[ts][uB] ); + move32(); + } + imagBufferFlipped[ts][uB] = imagBuffer[ts][nB]; + move32(); + if ( s_and( ts, 1 ) == 0 ) + { + imagBufferFlipped[ts][uB] = L_negate( imagBufferFlipped[ts][uB] ); + move32(); + } + uB = add( uB, 1 ); /* uB ++ */ + } + } + } + ELSE + { + startB = 39; + move16(); + endB = 19; + move16(); + FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) + { + uB = 0; + move16(); + FOR( nB = startB; nB > endB; nB-- ) + { + realBufferFlipped[ts][uB] = L_negate( realBuffer[ts][nB] ); + move32(); + imagBufferFlipped[ts][uB] = imagBuffer[ts][nB]; + move32(); + uB = add( uB, 1 ); /* uB ++ */ + } + } + } + + FOR( nB = 0; nB < 10; nB++ ) + { + FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) + { + realQ_neg1 = extract_l( L_shr( realBufferFlipped[ts][nB], 16 ) ); + imagQ_neg1 = extract_l( L_shr( imagBufferFlipped[ts][nB], 16 ) ); /* Q(-1), headroom needed */ + +#ifdef BASOP_NOGLOB + CldfbHB_fx = L_mac0_o( CldfbHB_fx, realQ_neg1, realQ_neg1, &Overflow ); + CldfbHB_fx = L_mac0_o( CldfbHB_fx, imagQ_neg1, imagQ_neg1, &Overflow ); /* Q(-2) */ +#else + CldfbHB_fx = L_mac0( CldfbHB_fx, realQ_neg1, realQ_neg1 ); + CldfbHB_fx = L_mac0( CldfbHB_fx, imagQ_neg1, imagQ_neg1 ); /* Q(-2) */ +#endif + } + } + CldfbHB_fx_e = sub( Q31, shl( sub( q_reImBuffer, Q16 ), 1 ) ); + exp = norm_l( CldfbHB_fx ); + CldfbHB_fx = L_shl( CldfbHB_fx, exp ); /* CldfbHB_ener = CldfbHB_fl*2^(exp) */ + Cldfbtemp1 = Log2_norm_lc( CldfbHB_fx ); /* Log2_norm_lc(t) = 2^15*(log2(t/2^30)) */ + Cldfbtemp1 = sub( shr( Cldfbtemp1, 6 ), shl( add( sub( Q31 - Q30, CldfbHB_fx_e ), exp ), 9 ) ); + CldfbHB_fx = L_mult( Cldfbtemp1, 9864 ); /* Q9 + Q15 + Q1 = Q25 */ + CldfbHB_fx = Mpy_32_16_1( L_sub( CldfbHB_fx, 1 << Q25 ), 11611 /* 0.1 * 0.221462 in Q19 */ ); + /* Resulting Q = Q25 + Q19 - Q15 = Q29 */ + hBWE_TD->cldfbHBLT = mac_r( CldfbHB_fx, 29491 /*0.9 Q15*/, hBWE_TD->cldfbHBLT ); /* cldfbHBLT is in Q13 */ + move32(); + + IF( CldfbHB_fx == 0 ) + { + CldfbHB_fx = EPSILLON_FX; + move32(); + } + + test(); + IF( GE_16( st->element_mode, IVAS_CPE_DFT ) && hCPE->hStereoICBWE != NULL ) + { + Word32 icbweRefEner_fx = EPSILON_FX; + Word16 exp_icbweRefEner_fx = 0; + + move32(); + move16(); + FOR( nB = 20; nB < 40; nB++ ) + { + FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) + { + realQ_neg1 = extract_l( L_shr( realBuffer[ts][nB], 16 ) ); + imagQ_neg1 = extract_l( L_shr( imagBuffer[ts][nB], 16 ) ); /* Q(-1), headroom needed */ + icbweRefEner_fx = L_mac0_o( icbweRefEner_fx, realQ_neg1, realQ_neg1, &Overflow ); + icbweRefEner_fx = L_mac0_o( icbweRefEner_fx, imagQ_neg1, imagQ_neg1, &Overflow ); /* Q(-2) */ + } + } + exp_icbweRefEner_fx = sub( Q31, shl( sub( q_reImBuffer, Q16 ), 1 ) ); + hCPE->hStereoICBWE->icbweRefEner_fx = Mpy_32_16_1( Sqrt32( icbweRefEner_fx, &exp_icbweRefEner_fx ), 1638 /* 0.05 in Q15 */ ); + move32(); + hCPE->hStereoICBWE->icbweRefEner_fx_e = exp_icbweRefEner_fx; + move16(); + } + + lbEner = EPSILON_FX; + move32(); + FOR( nB = 0; nB < 20; nB++ ) + { + FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) + { + realQ_neg1 = extract_l( L_shr( realBuffer[ts][nB], 16 ) ); + imagQ_neg1 = extract_l( L_shr( imagBuffer[ts][nB], 16 ) ); /* Q(-1), headroom needed */ + + lbEner = L_mac0_o( lbEner, realQ_neg1, realQ_neg1, &Overflow ); + lbEner = L_mac0_o( lbEner, imagQ_neg1, imagQ_neg1, &Overflow ); /* Q(-2) */ + } + } + exp_lbEner = sub( Q31, shl( sub( q_reImBuffer, Q16 ), 1 ) ); + lbEner = Mpy_32_16_1( Sqrt32( lbEner, &exp_lbEner ), 1638 /* 0.05 in Q15 */ ); + thr = icbwe_thr_TDM_fx; + regV = icbwe_regressionValuesTDM_fx; + + cldfbSynthesis_ivas_fx( realBufferFlipped, imagBufferFlipped, shb_speech_fx_32, -1, st->cldfbSynTd ); + Copy_Scale_sig_32_16( shb_speech_fx_32, shb_speech, L_FRAME16k, negate( sub( q_reImBuffer, 1 ) ) ); + *Q_shb_spch = 0; + move16(); + } + + IF( GE_16( st->element_mode, IVAS_CPE_DFT ) && hCPE->hStereoICBWE != NULL ) + { + Word16 exp_t; + hCPE->hStereoICBWE->MSFlag = 0; /* Init the multi-source flag */ + move16(); + v = Mpy_32_16_1( sum16_fx( st->voicing_fx, 3 ), 10923 /* 0.33333 in Q15 */ ); + + // t = log10f( ( hCPE->hStereoICBWE->icbweRefEner + 1e-6f ) / ( lbEner + 1e-6f ) ); + t = L_deposit_h( BASOP_Util_Divide3232_Scale( L_add( hCPE->hStereoICBWE->icbweRefEner_fx, EPSILON_FX ), L_add( lbEner, EPSILON_FX ), &exp_t ) ); + exp_t = add( exp_t, sub( hCPE->hStereoICBWE->icbweRefEner_fx_e, exp_lbEner ) ); + exp = norm_l( t ); + t = L_shl( t, exp ); + t_16 = Log2_norm_lc( t ); /* Log2_norm_lc(t) = 2^15*(log2(t/2^30)) */ + t_16 = sub( shr( t_16, 6 ), shl( add( sub( Q31 - Q30, exp_t ), exp ), 9 ) ); + t = L_mult( t_16, 9864 ); /* Q9 + Q15 + Q1 = Q25 */ + /* Three Level Decision Tree to calculate a regression value first */ + IF( LT_32( t, thr[0] ) ) /* level 1 */ + { + IF( LT_32( t, thr[1] ) ) /* level 2 */ + { + IF( LT_32( v, thr[3] ) ) + { + regression = regV[0]; /* level 3 */ + move32(); + } + ELSE + { + regression = regV[1]; + move32(); + } + } + ELSE + { + IF( LT_32( v, thr[4] ) ) + { + regression = regV[2]; /* level 3 */ + move32(); + } + ELSE + { + regression = regV[3]; + move32(); + } + } + } + ELSE + { + IF( LT_32( t, thr[2] ) ) /* level 2 */ + { + IF( LT_32( v, thr[5] ) ) + { + regression = regV[4]; /* level 3 */ + move32(); + } + ELSE + { + regression = regV[5]; + move32(); + } + } + ELSE + { + IF( LT_32( v, thr[6] ) ) + { + regression = regV[6]; /* level 3 */ + move32(); + } + ELSE + { + regression = regV[7]; + move32(); + } + } + } + + test(); + test(); + /* Convert the regression to a hard decision (classification) */ + IF( GT_32( regression, 1696512081 /* 0.79f in Q31*/ ) && !( LT_16( st->bwidth, SWB ) || hCPE->hCoreCoder[0]->vad_flag == 0 ) ) + { + hCPE->hStereoICBWE->MSFlag = 1; + move16(); + } + } + + test(); + test(); + IF( NE_16( st->extl, WB_TBE ) && NE_16( st->extl, SWB_TBE ) && NE_16( st->extl, FB_TBE ) ) + { + /* Update the previous superwideband speech buffer in case of a SWB_BWE frame - this code is in swb_tbe_enc */ + delay = L_LOOK_16k + L_SUBFR16k; + move16(); + Copy( shb_speech + sub( L_FRAME16k, delay ), hBWE_TD->old_speech_shb_fx, delay ); + } + } + ELSE + { + test(); + test(); + IF( ( EQ_16( st->bwidth, FB ) || st->core == ACELP_CORE ) && ( st->element_mode == EVS_MONO ) ) + { + InitSWBencBufferStates_fx( st->hBWE_TD, shb_speech ); + } + ELSE + { + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) + { + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + L_resamp = 560; /* 6.4 kHz core -> 6 - 14 kHz SHB target. 20 ms is 560 samples in 28 kHz sample rate */ + move16(); + } + ELSE + { + L_resamp = 620; /* 8 kHz core -> 7.5 - 15.5 kHz SHB target. 20 ms is 620 samples in 31 kHz sample rate */ + move16(); + } + + /* Dirty downsampling to match Nyquist to upper frequency limit of target */ + lerp( st->input_fx, new_swb_speech, L_resamp, (int16_t) Mpy_32_32( input_Fs, one_by_50_Q31 ) ); + + /* flip the spectrum */ + Copy( new_swb_speech, spchTmp, L_resamp ); + FOR( i = 0; i < L_resamp; i = i + 2 ) + { + spchTmp[i] = negate( spchTmp[i] ); + move16(); + } + + /* Dirty upsampling to match Nyquist/2 to lower frequency limit of target (reversed spectrum)*/ + lerp( spchTmp, spchTmp2, L_FRAME32k, L_resamp ); + Copy( spchTmp2, spchTmp, L_FRAME32k ); + } + ELSE + { + /* flip the spectrum */ + Copy( new_swb_speech, spchTmp, L_FRAME32k ); + + FOR( i = 0; i < L_FRAME32k; i = i + 2 ) + { + spchTmp[i] = negate( spchTmp[i] ); + move16(); + } + } + + Decimate_allpass_steep_fx( spchTmp, hBWE_TD->state_ana_filt_shb_fx, L_FRAME32k, shb_speech ); + + Copy( shb_speech + L_FRAME16k - ( L_LOOK_16k + L_SUBFR16k ), hBWE_TD->old_speech_shb_fx, L_LOOK_16k + L_SUBFR16k ); + + /*Compute the past overlap for potential next iDFTs SHB*/ + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) + { + FOR( i = 0; i < STEREO_DFT_OVL_16k; i++ ) + { + hCPE->hStereoDft->output_mem_dmx_16k_shb_fx[i] = L_mult0( shb_speech[20 + i], mult_r( hCPE->hStereoDft->win_ana_16k_fx[STEREO_DFT_OVL_16k - 1 - i], hCPE->hStereoDft->win_ana_16k_fx[STEREO_DFT_OVL_16k - 1 - i] ) ); // Q15 + move32(); + } + } + } + + IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) + { + /* Reset CLDFB synthesis buffer */ + set32_fx( st->cldfbSynTd->cldfb_state_fx, 0, st->cldfbSynTd->p_filter_length ); + } + ELSE + { + hCPE->hStereoDft->flip_sign = negate( hCPE->hStereoDft->flip_sign ); /* Make sure sign is updated even if DFT SHB target is not generated */ + move16(); + } + } + + /* Memory reset to compensate for 0.9375 ms offset when transitioning from IO to SWB */ + /* When switching from n >1 to n = 1, we keep the enc/dec delay as 8.75/3.25 and below code not needed; + only when n = 1 start, it will be 9.6875/2.3125 in that case this reset is needed for IO->BWE.*/ + test(); + IF( EQ_16( st->last_extl, -1 ) && ( st->element_mode == EVS_MONO ) ) + { + delay = NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ); + move16(); + FOR( i = 0; i < delay; i++ ) + { + shb_speech[i] = mult_r( mult_r( i, 983 /*0.03f Q15*/ ), shb_speech[2 * delay - 1 - i] ); + move16(); } } -- GitLab From a7465f11b391b1de2c95e106fea2b0f83138861a Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 21 Jan 2025 17:10:00 +0530 Subject: [PATCH 2/2] MSAN fix and ltv crash fix --- lib_dec/tonalMDCTconcealment.c | 5 ++++- lib_enc/swb_bwe_enc_fx.c | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib_dec/tonalMDCTconcealment.c b/lib_dec/tonalMDCTconcealment.c index c865dbe74..0ac877450 100644 --- a/lib_dec/tonalMDCTconcealment.c +++ b/lib_dec/tonalMDCTconcealment.c @@ -345,6 +345,10 @@ void TonalMdctConceal_whiten_noise_shape_ivas_fx( psychParams = st->hTonalMDCTConc->psychParams; hFdCngCom = st->hFdCngDec->hFdCngCom; +#ifdef MSAN_FIX + set32_fx( whitenend_noise_shape, 0, L_FRAME16k ); +#endif + IF( EQ_32( whitening_mode, ON_FIRST_LOST_FRAME ) ) { IF( GT_16( st->core, TCX_20_CORE ) ) @@ -377,7 +381,6 @@ void TonalMdctConceal_whiten_noise_shape_ivas_fx( noiseLevelPtr_exp = hFdCngCom->cngNoiseLevelExp; move16(); - set32_fx( whitenend_noise_shape, 0, start_idx ); FOR( Word16 j = start_idx; j < stop_idx; j++ ) { whitenend_noise_shape[j] = L_shr( *noiseLevelPtr, 3 ); diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index 355246ec8..155b7298f 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -1469,11 +1469,12 @@ static void vqWithCand_w_fx( { #ifdef BASOP_NOGLOB dist = sub_sat( x[0], *p_E_ROM_dico++ ); /*Q8 */ + L_dist = L_mult_sat( dist, dist ); /*Q17 */ #else dist = sub( x[0], *p_E_ROM_dico++ ); /*Q8 */ + L_dist = L_mult( dist, dist ); /*Q17 */ #endif - L_dist = L_mult( dist, dist ); /*Q17 */ - L_dist = L_shr( L_dist, 12 ); /*Q5 */ + L_dist = L_shr( L_dist, 12 ); /*Q5 */ FOR( j = 1; j < dim; j++ ) { -- GitLab