From 63ea05d0afc81fc394e24a7242ff12e5965b568d Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 26 Dec 2024 15:06:04 +0530 Subject: [PATCH] High MLD fixes, bug fixes and Q-info updates [x] Fix for wrong q of exc buffers [x] bug-fix in attack detection [x] Removed saturations in find_enr_dft_fx and ivas_find_enr1 [x] Q documentation and Basop updation [x] High mld fix for [basop_encoder-Multi-channel 7_1_4 bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, 7_1_4 out] [x] Bug fix related to bckr --- lib_com/cnst.h | 2 - lib_com/fft_fx.c | 20 + lib_com/ivas_prot.h | 37 +- lib_com/ivas_prot_fx.h | 2 +- lib_com/prot_fx.h | 13 +- lib_com/pvq_com_fx.c | 16 +- lib_com/swb_tbe_com_fx.c | 13 +- lib_com/tcx_utils_fx.c | 4 + lib_dec/ivas_stereo_mdct_stereo_dec.c | 15 +- lib_enc/analy_sp_fx.c | 620 ++++++++++++++++++++------ lib_enc/hq_core_enc.c | 8 +- lib_enc/hq_hr_enc.c | 1 + lib_enc/ivas_core_pre_proc_front.c | 39 +- lib_enc/ivas_corecoder_enc_reconfig.c | 7 +- lib_enc/ivas_cpe_enc.c | 10 - lib_enc/ivas_enc.c | 2 +- lib_enc/ivas_front_vad.c | 16 +- lib_enc/ivas_init_enc.c | 76 ++-- lib_enc/ivas_ism_enc.c | 14 +- lib_enc/ivas_ism_metadata_enc.c | 68 +-- lib_enc/ivas_ism_param_enc.c | 42 +- lib_enc/ivas_lfe_enc.c | 24 +- lib_enc/ivas_masa_enc.c | 160 +++---- lib_enc/ivas_mc_param_enc.c | 70 +-- lib_enc/ivas_mc_paramupmix_enc.c | 70 +-- lib_enc/ivas_mcmasa_enc.c | 287 +++++++----- lib_enc/ivas_mct_core_enc.c | 30 +- lib_enc/ivas_mct_enc.c | 186 ++++---- lib_enc/ivas_stat_enc.h | 2 +- lib_enc/ivas_stereo_dft_enc.c | 3 +- lib_enc/ivas_stereo_dft_enc_itd.c | 21 +- lib_enc/ivas_tcx_core_enc.c | 4 +- lib_enc/prot_fx_enc.h | 18 +- lib_enc/speech_music_classif_fx.c | 40 +- lib_enc/stat_enc.h | 5 +- lib_enc/tcx_utils_enc_fx.c | 5 +- 36 files changed, 1192 insertions(+), 758 deletions(-) diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 7e6572382..40cc0e36c 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -747,10 +747,8 @@ enum #define PIT_UP_SAMP6 6 #define PIT_L_INTERPOL6_2 17 #define PIT_FIR_SIZE6_2 ( PIT_UP_SAMP6 * PIT_L_INTERPOL6_2 + 1 ) -#define E_MIN_Q11_FX 7 /* minimum allowable energy in Q11*/ #define E_MIN 0.0035f /* minimum allowable energy */ #define E_MIN_Q11_FX 7 /* minimum allowable energy in Q11*/ -#define E_MIN_Q16_FX 229 /* minimum allowable energy in Q16*/ #define STEP_DELTA 0.0625f /* quantization step for tilt compensation of gaussian cb. excitation */ #define GAMMA_EV 0.92f /* weighting factor for core synthesis error weighting */ #define FORMANT_SHARPENING_NOISE_THRESHOLD 21.0f /* lp_noise level above which formant sharpening is deactivated */ diff --git a/lib_com/fft_fx.c b/lib_com/fft_fx.c index c4237bcc9..d6710ebd0 100644 --- a/lib_com/fft_fx.c +++ b/lib_com/fft_fx.c @@ -7282,6 +7282,26 @@ Word16 L_norm_arr( Word32 *arr, Word16 size ) return q; } +Word16 norm_arr( Word16 *arr, Word16 size ) +{ + Word16 q = 15; + Word16 exp = 0; + move16(); + move16(); + FOR( Word16 i = 0; i < size; i++ ) + { + if ( arr[i] != 0 ) + { + exp = norm_s( arr[i] ); + } + if ( arr[i] != 0 ) + { + q = s_min( q, exp ); + } + } + return q; +} + Word16 get_min_scalefactor( Word32 x, Word32 y ) { #ifndef FIX_1104_OPT_GETMINSCALEFAC diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index c89b5a604..d0517ccce 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -95,7 +95,7 @@ ivas_error create_cpe_enc( const int32_t element_brate /* i : element bitrate */ ); -ivas_error create_mct_enc( +ivas_error create_mct_enc_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); @@ -112,7 +112,7 @@ void destroy_cpe_enc( CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ ); -void ivas_mct_enc_close( +void ivas_mct_enc_close_fx( MCT_ENC_HANDLE *hMCT /* i/o: MCT encoder structure */ ); @@ -775,7 +775,7 @@ Word16 ism_quant_meta_fx( const Word16 cbsize /* i : codebook size */ ); -ivas_error ivas_ism_metadata_enc_create( +ivas_error ivas_ism_metadata_enc_create_fx( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t n_ISms, /* i : number of objects */ int32_t element_brate_tmp[] /* o : element bitrate per object */ @@ -818,11 +818,11 @@ ivas_error ivas_ism_metadata_dec( /*! r: ISM format mode */ -ivas_error ivas_param_ism_enc_open( +ivas_error ivas_param_ism_enc_open_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); -void ivas_param_ism_enc_close( +void ivas_param_ism_enc_close_fx( PARAM_ISM_CONFIG_HANDLE *hParamIsm, /* i/o: ParamISM handle */ const int32_t input_Fs /* i : input sampling_rate */ ); @@ -890,7 +890,7 @@ void ivas_ism_dtx_dec( int16_t *nb_bits_metadata /* o : number of metadata bits */ ); -void ivas_ism_metadata_sid_enc( +void ivas_ism_metadata_sid_enc_fx( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ const int16_t flag_noisy_speech, /* i : noisy speech flag */ const int16_t nchan_ism, /* i : number of objects */ @@ -917,7 +917,7 @@ void ivas_ism_metadata_sid_dec( ); -void ivas_param_ism_compute_noisy_speech_flag( +void ivas_param_ism_compute_noisy_speech_flag_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); @@ -2712,11 +2712,11 @@ void ivas_dirac_dec_get_response( -ivas_error ivas_mc_paramupmix_enc_open( +ivas_error ivas_mc_paramupmix_enc_open_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); -void ivas_mc_paramupmix_enc_close( +void ivas_mc_paramupmix_enc_close_fx( MC_PARAMUPMIX_ENC_HANDLE *hMCParamUpmix, /* i/o: MC Param-Upmix encoder handle */ const int32_t input_Fs /* i : input sampling rate */ ); @@ -3456,11 +3456,11 @@ void generate_gridEq( SPHERICAL_GRID_DATA *data /* o : data structure for grid */ ); -ivas_error ivas_masa_enc_open( +ivas_error ivas_masa_enc_open_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); -void ivas_masa_enc_close( +void ivas_masa_enc_close_fx( MASA_ENCODER_HANDLE *hMasa /* i/o: MASA metadata structure */ ); @@ -3790,10 +3790,11 @@ void ivas_mcmasa_split_brate( void ivas_mcmasa_dmx_modify_fx( - const Word16 n_samples, /* i : input frame length in samples */ - Word32 dmx_fx[][L_FRAME48k + NS2SA(48000, IVAS_FB_ENC_DELAY_NS)], /* i/o: downmix signal to be transformed into another format Qx*/ - const Word16 n_chnls_dmx_old, /* i : number of downmix channels in the old format Q0*/ - const Word16 n_chnls_dmx_new /* i : number of downmix channels in the target format Q0*/ + const Word16 n_samples, /* i : input frame length in samples */ + Word32 dmx_fx[][L_FRAME48k + NS2SA(48000, IVAS_FB_ENC_DELAY_NS)], /* i/o: downmix signal to be transformed into another format Qx*/ + Word16 dmx_Q[], /* i/o : Q of the intput signal which is being transformed*/ + const Word16 n_chnls_dmx_old, /* i : number of downmix channels in the old format Q0 */ + const Word16 n_chnls_dmx_new /* i : number of downmix channels in the target format Q0*/ ); ivas_error ivas_mono_dmx_renderer_open( @@ -3821,7 +3822,7 @@ ivas_error ivas_create_lfe_lpf_enc( const int32_t input_Fs /* i : input sampling rate */ ); -void ivas_lfe_lpf_enc_close( +void ivas_lfe_lpf_enc_close_fx( ivas_filters_process_state_t **hLfeLpf /* i/o: LFE LPF handle */ ); @@ -3836,12 +3837,12 @@ void ivas_lfe_lpf_enc_apply( * LFE Coding prototypes *----------------------------------------------------------------------------------*/ -ivas_error ivas_create_lfe_enc( +ivas_error ivas_create_lfe_enc_fx( LFE_ENC_HANDLE *hLFE, /* o : IVAS LFE encoder structure */ const int32_t input_Fs /* i : input sampling rate */ ); -void ivas_lfe_enc_close( +void ivas_lfe_enc_close_fx( LFE_ENC_HANDLE *hLFE /* i/o: LFE encoder handle */ ); diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index e65ce8b76..7882f0482 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -4127,7 +4127,7 @@ ivas_error ivas_set_ism_metadata_fx( const Word16 non_diegetic_flag /* i : non-diegetic object flag */ ); -ivas_error ivas_ism_metadata_enc( +ivas_error ivas_ism_metadata_enc_fx( Word32 *ism_total_brate, /* i/o: ISM total bitrate */ const Word16 nchan_ism, /* i : number of ISM channels */ const Word16 nchan_transport, /* i : number of transport channels */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 5cd7e90ad..75b01b759 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -4566,6 +4566,7 @@ void DoRTFTn_fx_ivas( Word16 find_guarded_bits_fx( Word32 n ); Word16 L_norm_arr( Word32 *arr, Word16 size ); +Word16 norm_arr( Word16 *arr, Word16 size ); Word16 get_min_scalefactor( Word32 x, Word32 y ); @@ -4951,12 +4952,12 @@ void fine_gain_quant_fx( const Word16 *gopt /* i : Optimal gains Q12 */ ); void fine_gain_quant_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *ord, /* i : Indices for energy order Q0 */ - const Word16 num_sfm, /* i : Number of bands Q0 */ - const Word16 *gain_bits, /* i : Gain adjustment bits per sub band Q0 */ - Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains Q12 */ - const Word16 *gopt /* i : Optimal gains Q12 */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 *ord, /* i : Indices for energy order Q0 */ + const Word16 num_sfm, /* i : Number of bands Q0 */ + const Word16 *gain_bits, /* i : Gain adjustment bits per sub band Q0 */ + Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains i:Q12 / o:Q11 */ + const Word16 *gopt /* i : Optimal gains Q12 */ ); void get_max_pulses_fx( const Word16 *band_start, /* i : Sub band start indices */ diff --git a/lib_com/pvq_com_fx.c b/lib_com/pvq_com_fx.c index 48ee402ef..36fa528b8 100644 --- a/lib_com/pvq_com_fx.c +++ b/lib_com/pvq_com_fx.c @@ -515,12 +515,12 @@ void apply_gain_fx( * Fine gain quantization *--------------------------------------------------------------------------*/ void fine_gain_quant_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *ord, /* i : Indices for energy order Q0 */ - const Word16 num_sfm, /* i : Number of bands Q0 */ - const Word16 *gain_bits, /* i : Gain adjustment bits per sub band Q0 */ - Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains Q11 */ - const Word16 *gopt /* i : Optimal gains Q12 */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 *ord, /* i : Indices for energy order Q0 */ + const Word16 num_sfm, /* i : Number of bands Q0 */ + const Word16 *gain_bits, /* i : Gain adjustment bits per sub band Q0 */ + Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains i:Q12 / o:Q11 */ + const Word16 *gopt /* i : Optimal gains Q12 */ ) { Word16 band; @@ -577,6 +577,10 @@ void fine_gain_quant_ivas_fx( fg_pred[band] = round_fx( L_shl( L_tmp, sub( 15, exp1 ) ) ); /*12+exp1+16-exp1-16=12 - 1-> Q11*/ move16(); } + ELSE + { + fg_pred[band] = shr( fg_pred[band], 1 ); // Q12 -> Q11 To align all the fg_pred indices in same Q. + } } return; diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 494dbebd5..b7c650e9e 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -3377,7 +3377,7 @@ void GenShapedSHBExcitation_ivas_enc_fx( /* calculate pow22 */ /* pow22=0.00001f */ tmp = sub( shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1 ), 31 ); - pow22 = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(*Q_bwe_exc-NOISE_QADJ) */ + Word64 sum = W_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(*Q_bwe_exc-NOISE_QADJ) */ FOR( k = 0; k < L_FRAME16k; k++ ) { /* White_exc16k[k] *= excNoisyEnv[k]; */ @@ -3388,14 +3388,11 @@ void GenShapedSHBExcitation_ivas_enc_fx( /* i: White_exc16k in Q6 */ /* o: White_exc16k in (Q_bwe_exc-NOISE_QADJ) */ /* pow22 += White_exc16k[k] * White_exc16k[k]; */ -#ifdef BASOP_NOGLOB - pow22 = L_mac0_sat( pow22, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_excTmp2-NOISE_QADJ)*/ -#else - pow22 = L_mac0( pow22, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_bwe_exc-NOISE_QADJ)*/ -#endif + sum = W_mac0_16_16( sum, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_excTmp2-NOISE_QADJ)*/ } - /*Q_pow22 = sub( shl(*Q_bwe_exc,1), 18 );*/ - Q_pow22 = shl( sub( Q_excTmp2, NOISE_QADJ ), 1 ); + Q_pow22 = W_norm( sum ); + pow22 = W_extract_h( W_shl( sum, Q_pow22 ) ); // 2*(Q_excTmp2-NOISE_QADJ)+Q_pow22-32 + Q_pow22 = sub( add( Q_pow22, shl( sub( Q_excTmp2, NOISE_QADJ ), 1 ) ), 32 ); Scale_sig( White_exc16k, L_FRAME16k, sub( *Q_bwe_exc, Q_excTmp2 ) ); } diff --git a/lib_com/tcx_utils_fx.c b/lib_com/tcx_utils_fx.c index 64b7defc9..26e29b104 100644 --- a/lib_com/tcx_utils_fx.c +++ b/lib_com/tcx_utils_fx.c @@ -1072,7 +1072,11 @@ void mdct_shaping( FOR( l = 0; l < k; l++ ) { +#ifdef BASOP_NOGLOB + *x = L_shl_o( Mpy_32_16_r( *x, *gains ), *gains_exp, &Overflow ); /*Qx*/ +#else *x = L_shl( Mpy_32_16_r( *x, *gains ), *gains_exp ); /*Qx*/ +#endif move32(); x++; } diff --git a/lib_dec/ivas_stereo_mdct_stereo_dec.c b/lib_dec/ivas_stereo_mdct_stereo_dec.c index 6d4fc967e..44dcda09b 100644 --- a/lib_dec/ivas_stereo_mdct_stereo_dec.c +++ b/lib_dec/ivas_stereo_mdct_stereo_dec.c @@ -720,20 +720,7 @@ static void update_exp( } return; } -static Word16 norm_arr( - Word16 *arr, - Word32 size /* Q0 */ -) -{ - Word16 q = 15; - move16(); - FOR( Word32 i = 0; i < size; i++ ) - IF( arr[i] != 0 ) - { - q = s_min( q, norm_s( arr[i] ) ); - } - return q; -} + void updateBuffersForDmxMdctStereo_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ const Word16 output_frame, /* i : output frame length Q0*/ diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index d2e34b012..8ad417eee 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -19,7 +19,7 @@ static void find_enr( Word16 data[], Word32 band[], Word32 *ptE, Word32 *LEtot, const Word16 min_band, const Word16 max_band, const Word16 Q_new2, const Word32 e_min, Word32 *Bin_E, Word16 BIN_FREQ_FX, Word32 *band_energies ); static void ivas_find_enr( Word16 data[], Word32 band[], Word32 *ptE, Word32 *LEtot, const Word16 min_band, const Word16 max_band, const Word16 Q_new2, const Word32 e_min, Word32 *Bin_E, Word16 BIN_FREQ_FX, Word32 *band_energies ); -static void ivas_find_enr1( Word16 *data, Word16 q_data, Word32 *band, Word32 *ptE, Word32 *LEtot, const Word16 min_band, const Word16 max_band, const Word16 Q_new, const Word32 e_min, Word32 *Bin_E, Word16 BIN_FREQ_FX, Word32 *band_energies ); +static void ivas_find_enr1( Word16 *data, Word16 q_data, Word32 *band, Word16 *q_band, Word32 *ptE, Word16 *q_ptE, Word64 *LEtot, const Word16 min_band, const Word16 max_band, const Word16 Q_new, const Word32 e_min, Word32 *Bin_E, Word16 BIN_FREQ_FX, Word32 *band_energies ); #ifdef IVAS_CODE_CPE static void find_enr_dft( CPE_ENC_HANDLE hCPE, const int32_t input_Fs, float DFT_past_DMX[], float band[], float *ptE, float *Etot, const int16_t min_band, const int16_t max_band, float *Bin_E, float *band_ener ); #endif @@ -413,6 +413,236 @@ static void find_enr_dft_fx( return; } + +static void find_enr_dft_ivas_fx( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word32 input_Fs, /* i : input sampling rate */ + Word32 DFT_past_DMX_fx[], /* i :input DFT_Dmx (Q_inp_dmx ) */ + Word32 band_fx[], /* o : per band energy (*q_band) */ + Word16 *q_band, /* o : Q of per band energy */ + Word32 *ptE_fx, /* o : per bin energy for low frequencies (*q_ptE) */ + Word16 *q_ptE, /* o : Q of per bin energy for low frequencies */ + Word64 *Etot_fx, /* i/o: total energy (Q8) */ + const Word16 min_band, /* i : minimum critical band */ + const Word16 max_band, /* i : maximum critical band */ + Word32 *Bin_E_fx, /* o : Per bin energy (Q7) */ + Word16 *q_Bin_E, /* o : Q of Per bin energy (*q_band) */ + Word32 *band_ener_fx, /* o : per band energy without E_MIN */ + Word16 Q_inp_dmx ) +{ + Word16 i; + Word64 tot_ener; + Word32 freq; + const Word32 *ptR_fx, *ptI_fx; + Word16 norm_val_fx; + Word16 bin_cnt; + Word32 c_fx, s_fx; + Word32 g_fx; + Word32 scaleWin_fx; + Word16 bin_freq; + Word16 temp1, temp2, exp, exp1; + Word16 q_norm_val; + Word32 BinE_fx[STEREO_DFT_N_12k8_ENC / 2]; /* NB_BANDS = 20 (= 6350Hz) = highest band available for SR 12.8 -> bin_cnt = 158 */ + Word32 c_1_fx, s_1_fx, g_1_fx, g_2_fx; + Word64 band_ener; + Word32 BinE, tmp_fx; + Word32 start_freq; + Word32 min_ener; + Word16 shift = 0; + move16(); + + /* One window - 40ms*12.8kHz = 512 samples */ + c_1_fx = 1073741799; // 0.99999998 in Q30, cosf( PI2 / STEREO_DFT_N_12k8_ENC ) + s_1_fx = 229974; // 0.00021418 in Q30, sinf( PI2 / STEREO_DFT_N_12k8_ENC ) + g_1_fx = 1570240043; // 1.4624 in Q30, ( 1.f + 0.68f * 0.68f ) + g_2_fx = 1460288880; // 1.36 in Q30, 2 * 0.68f + move32(); + move32(); + move32(); + move32(); + + bin_cnt = 0; + move16(); + + /* input_Fs / (float) hCPE->hStereoDft->NFFT;*/ /* adaptive frequency bin width */ + bin_freq = BASOP_Util_Divide3216_Scale( input_Fs, hCPE->hStereoDft->NFFT, &exp ); + bin_freq = shl( bin_freq, add( 1, exp ) ); // Q0 + + /* scaleWin = 1 / ( 2 * hCPE->hStereoDft->win_ana_energy ); + scaleWin *= (float) BIN / bin_freq; */ + + temp2 = BASOP_Util_Divide3216_Scale( BIN, bin_freq, &exp ); + temp2 = shl( temp2, add( 1, exp ) ); // Q0 + exp = norm_s( hCPE->hStereoDft->win_ana_energy_fx ); + temp1 = div_s( ONE_IN_Q14, shl( hCPE->hStereoDft->win_ana_energy_fx, exp ) ); // 14-(15+exp-1)+15 = 15+exp + scaleWin_fx = L_mult0( temp1, temp2 ); // 15+exp + + /* scaleWin * 4.0f makes Q of scaleWin_fx from 15+exp to 13+exp + norm_val = scaleWin * 4.0f / ( hCPE->hStereoDft->NFFT * hCPE->hStereoDft->NFFT ); */ + + norm_val_fx = BASOP_Util_Divide3232_Scale( scaleWin_fx, L_mult0( hCPE->hStereoDft->NFFT, hCPE->hStereoDft->NFFT ), &exp1 ); // 13+exp+15-exp1 = 28+exp-exp1 + q_norm_val = add( 28, sub( exp, exp1 ) ); + + ptR_fx = &DFT_past_DMX_fx[2]; /* first real */ + ptI_fx = &DFT_past_DMX_fx[3]; /* first imaginary */ + + c_fx = c_1_fx; // Q30 + s_fx = s_1_fx; // Q30 + move32(); + move32(); + + /* for low frequency bins, save per bin energy for the use in find_tilt() */ + freq = bin_freq; + move32(); + + *q_band = add( shl( Q_inp_dmx, 1 ), sub( q_norm_val, 47 ) ); + move16(); + *q_Bin_E = *q_band; + move16(); + + IF( GT_16( *q_band, 39 ) ) + { + *q_band = 39; + move16(); + shift = sub( *q_band, 39 ); + } + + min_ener = L_shl( 7516193 /* 0.0035 in Q31 */, sub( *q_band, 31 ) ); + + FOR( i = 0; i < NB_BANDS - 1; i++ ) /* up to maximum allowed voiced critical band */ + { + band_ener = 0; + move64(); + start_freq = freq; + move32(); + + /* bins up to crit_band 17 (<= 3700 Hz): + * bin_cnt old (bin_width 50 Hz): 74 (74 * FRAMES_PER_SEC = 3700) + * bin_cnt new (bin_width 40 Hz): 92 (92 * 40 = 3680) + */ + + WHILE( LE_32( freq, crit_bands_fx[i] ) ) + { + g_fx = L_sub( g_1_fx, L_shl( Mpy_32_32( g_2_fx, c_fx ), 1 ) ); // 30 + tmp_fx = Msub_32_32( Mpy_32_32( c_fx, c_1_fx ), s_fx, s_1_fx ); // 29 + s_fx = L_shl( Madd_32_32( Mpy_32_32( s_fx, c_1_fx ), c_fx, s_1_fx ), 1 ); // 30 + c_fx = L_shl( tmp_fx, 1 ); // 30 + + BinE = Madd_32_32( Mpy_32_32( *ptR_fx, *ptR_fx ), *ptI_fx, *ptI_fx ); // 2*Q_inp_dmx-31 + BinE_fx[bin_cnt] = Mpy_32_32( BinE, Mpy_32_16_1( g_fx, norm_val_fx ) ); // (2*Q_inp_dmx-31)+(q_norm_val+30-15)-31 = 2*Q_inp_dmx+q_norm_val-47 = *q_Bin_E + move32(); + + /* + BIN_FREQ_FX = BIN, cnt = ( ( crit_bands_fx[i] - start_freq ) / bin_freq ) + 1 + band[i] = BinE[bin_cnt]; + band[i] *= inv_tbl[cnt]; // normalization per frequency bin + */ + band_ener = W_mac_32_16( band_ener, BinE_fx[bin_cnt], inv_tbl_fx[( ( crit_bands_fx[i] - start_freq ) / bin_freq ) + 1] ); // *q_band+shift+16 + + ptR_fx += 2; + ptI_fx += 2; + freq = L_mac0( freq, bin_freq, 1 ); + bin_cnt = add( bin_cnt, 1 ); + } + + /* normalization per frequency bin */ + band_fx[i] = W_extract_h( W_shl( band_ener, sub( Q16, shift ) ) ); // *q_band + move32(); + + /* per band energy without E_MIN */ + band_ener_fx[i] = band_fx[i]; // *q_band + move32(); + + if ( LT_32( band_fx[i], min_ener ) ) + { + band_fx[i] = min_ener; // *q_band + move32(); + } + } + + /* continue computing the energy per critical band for higher frequencies */ + + /* old version, FFT 256 @ SR12.8 (-> bin_width = 50 Hz): + NB_BANDS = 20 (= 6350Hz) = highest band available for SR 12.8 -> bin_cnt = 127 = L_FFT/2-1*/ + + /* new version: DFT (1200/800/400) @ input SR (48/32/16) (-> bin_width = 40 Hz): + * + */ + /* NB_BANDS = 20 (= 6350Hz) = highest band available for SR 12.8 -> bin_cnt = 158 */ + /* NB_BANDS = 21 (= 7700Hz) = highest band available for SR 16 -> bin_cnt = 192 */ + /* NB_BANDS = 24 (= 15500Hz) = highest band available for SR 32 -> bin_cnt = 387 */ + /* NB_BANDS = 24 (= 15500Hz) = highest band available for SR 48 -> bin_cnt = 387 */ + + FOR( ; i < NB_BANDS; i++ ) + { + band_ener = 0; + move64(); + start_freq = freq; + move32(); + + WHILE( LT_32( freq, 6399 ) ) + { + + g_fx = L_sub( g_1_fx, L_shl( Mpy_32_32( g_2_fx, c_fx ), 1 ) ); // 30 + + BinE = Madd_32_32( Mpy_32_32( *ptR_fx, *ptR_fx ), *ptI_fx, *ptI_fx ); // 2*Q_inp_dmx-31 + BinE_fx[bin_cnt] = Mpy_32_32( BinE, Mpy_32_16_1( g_fx, norm_val_fx ) ); // (2*Q_inp_dmx-31)+(q_norm_val+30-15)-31 = 2*Q_inp_dmx+q_norm_val-47 = *q_Bin_E + move32(); + + /* + BIN_FREQ_FX = BIN, cnt = ( ( 6399 - start_freq ) / bin_freq ) + 1 + band[i] = BinE[bin_cnt]; + band[i] *= inv_tbl[cnt]; // normalization per frequency bin + */ + band_ener = W_mac_32_16( band_ener, BinE_fx[bin_cnt], inv_tbl_fx[( ( 6399 - start_freq ) / bin_freq ) + 1] ); // *q_band+shift + + ptR_fx += 2; + ptI_fx += 2; + freq = L_mac0( freq, bin_freq, 1 ); + bin_cnt = add( bin_cnt, 1 ); + } + + /* normalization per frequency bin */ + band_fx[i] = W_extract_h( W_shl( band_ener, sub( Q16, shift ) ) ); // *q_band + move32(); + + /* per band energy without E_MIN */ + band_ener_fx[i] = band_fx[i]; // *q_band + move32(); + + if ( LT_32( band_fx[i], min_ener ) ) + { + band_fx[i] = min_ener; // *q_band + move32(); + } + } + + /* put bin energies from BinE into Bin_E[L_FFT/2-1] (interpolate 40 Hz bin values to fit into 50 Hz bins) */ + /* Last value of Bin_E is handled outside this function*/ + assert( bin_cnt == ( STEREO_DFT_N_12k8_ENC / 2 - 1 ) ); + BinE_fx[STEREO_DFT_N_12k8_ENC / 2 - 1] = BinE_fx[STEREO_DFT_N_12k8_ENC / 2 - 2]; // // *q_Bin_E + move32(); + + L_lerp_fx( BinE_fx, Bin_E_fx, L_FFT / 2, STEREO_DFT_N_12k8_ENC / 2, q_Bin_E ); + + MVR2R_WORD32( Bin_E_fx, ptE_fx, VOIC_BINS ); // *q_Bin_E + *q_ptE = *q_Bin_E; + move16(); + + /* find the total log energy */ + tot_ener = *Etot_fx; + move64(); + + FOR( i = min_band; i <= max_band; i++ ) + { + tot_ener = W_mac_32_32( tot_ener, band_fx[i], 1 ); // *q_band+1 + } + + *Etot_fx = tot_ener; + move64(); + + return; +} /*-------------------------------------------------------------------* * ivas_analy_sp_fx() * @@ -569,28 +799,36 @@ void ivas_analy_sp_fx_front( const Word32 input_Fs, /* i : input sampling rate */ Word16 *speech, /* i : speech buffer Q_new - preemph_bits */ const Word16 Q_new, /* i : current scaling exp Q0 */ - Word32 *fr_bands, /* o : energy in critical frequency bands Q_new + QSCALE - 2 */ - Word32 *lf_E, /* o : per bin E for first... Q_new + QSCALE - 2 */ + Word32 *fr_bands, /* o : energy in critical frequency bands q_fr_bands */ + Word16 *q_fr_bands, /* o : energy in critical frequency bands Q0 */ + Word32 *lf_E, /* o : per bin E for first... q_lf_E */ + Word16 *q_lf_E, /* o : per bin E for first... Q0 */ Word16 *Etot, /* o : total input energy Q8 */ const Word16 min_band, /* i : minimum critical band Q0 */ const Word16 max_band, /* i : maximum critical band Q0 */ const Word32 e_min_scaled, /* i : minimum energy scaled Q_new + QSCALE - 2 */ Word16 Scale_fac[2], /* o : FFT scales factors (2 values by frame) Q0 */ Word32 *Bin_E, /* o : per-bin energy spectrum Q7 */ + Word16 *q_Bin_E, /* o : per-bin energy spectrum Q7 */ Word32 *Bin_E_old, /* o : per-bin energy spectrum of the previous frame Q7 */ + Word16 *q_Bin_E_old, /* o : per-bin energy spectrum of the previous frame Q7 */ Word32 *PS, /* o : per-bin energy spectrum Q_new + QSCALE - 2 */ + Word16 *q_PS, /* o : per-bin energy spectrum Q_new + QSCALE - 2 */ Word16 *EspecdB, /* o : per-bin log energy spectrum (with f=0) Q7 */ - Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN (Q_new + QSCALE - 2)*/ + Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN (band_energies_exp)*/ + Word16 *band_energies_exp, /* o : exponent of energy in critical frequency bands without minimum noise floor MODE2_E_MIN */ Word16 *fft_buff /* o : FFT coefficients (Q_new + Scale_fac[i_subfr]) */ ) { Word16 *pt; Word16 i_subfr, i; Word32 *pt_bands; - Word32 Ltmp, LEtot; + Word32 Ltmp; Word16 *pt_fft; - Word32 temp32_log; - Word16 max_pfft; + Word16 exp, tmp; + Word64 LEtot; + LEtot = 0; + move64(); /*-----------------------------------------------------------------* * Compute spectrum * find energy per critical frequency band and total energy in dB @@ -598,143 +836,208 @@ void ivas_analy_sp_fx_front( pt_bands = fr_bands; pt_fft = fft_buff; - LEtot = L_deposit_l( 0 ); + IF( NE_16( element_mode, IVAS_CPE_DFT ) ) { - FOR( i_subfr = 0; i_subfr <= 1; i_subfr++ ) + IF( is_zero_arr16( speech + 3 * ( L_SUBFR / 2 ) - L_FFT / 2, L_FFT + 4 * ( L_SUBFR / 2 ) ) ) { - /* set pointer to the beginning of the signal for spectral analysis */ - /* set the pointer for first analysis window */ - pt = speech + 3 * ( L_SUBFR / 2 ) - L_FFT / 2; - IF( i_subfr != 0 ) - { - /* set the pointer for second analysis window */ - pt = speech + 7 * ( L_SUBFR / 2 ) - L_FFT / 2; - } - - /* Clear 1st value of 1st part, copy 1st value of 2nd part */ - pt_fft[0] = 0; + set16_fx( pt_fft, 0, 2 * L_FFT ); + Scale_fac[0] = 0; + Scale_fac[1] = 0; move16(); - pt_fft[L_FFT / 2] = pt[L_FFT / 2]; move16(); - FOR( i = 1; i < L_FFT / 2; i++ ) + set32_fx( Bin_E, 0, L_FFT ); + set32_fx( lf_E, 0, 2 * VOIC_BINS ); + set32_fx( band_energies, 0, 2 * NB_BANDS ); + set32_fx( fr_bands, e_min_scaled, 2 * NB_BANDS ); + + LEtot = W_shl( W_mult_32_16( e_min_scaled, add( sub( max_band, min_band ), 1 ) ), 1 ); // Q_new + QSCALE - 1 + *q_fr_bands = add( Q_new, Q_SCALE - 2 ); + *q_lf_E = *q_fr_bands; + move16(); + move16(); + } + ELSE + { + Word16 scale = norm_arr( speech + 3 * ( L_SUBFR / 2 ) - L_FFT / 2, L_FFT + 4 * ( L_SUBFR / 2 ) ); + scale = sub( scale, LOG2_L_FFT ); // guard_bits + FOR( i_subfr = 0; i_subfr <= 1; i_subfr++ ) { - /* 1st windowed part */ - pt_fft[i] = mult_r( pt[i], sqrt_han_window_fx[i] ); - move16(); + /* set pointer to the beginning of the signal for spectral analysis */ + /* set the pointer for first analysis window */ + pt = speech + 3 * ( L_SUBFR / 2 ) - L_FFT / 2; + if ( i_subfr != 0 ) + { + /* set the pointer for second analysis window */ + pt = speech + 7 * ( L_SUBFR / 2 ) - L_FFT / 2; + } - /* 2nd windowed part */ - pt_fft[L_FFT - i] = mult_r( pt[L_FFT - i], sqrt_han_window_fx[i] ); + /* Clear 1st value of 1st part, copy 1st value of 2nd part */ + pt_fft[0] = 0; + move16(); + pt_fft[L_FFT / 2] = pt[L_FFT / 2]; move16(); - } - maximum_abs_16_fx( pt_fft, L_FFT, &max_pfft ); - IF( max_pfft > 0 ) - { - Scale_fac[i_subfr] = sub( norm_s( max_pfft ), LOG2_L_FFT ); + FOR( i = 1; i < L_FFT / 2; i++ ) + { + /* 1st windowed part */ + pt_fft[i] = mult_r( pt[i], sqrt_han_window_fx[i] ); + move16(); + + /* 2nd windowed part */ + pt_fft[L_FFT - i] = mult_r( pt[L_FFT - i], sqrt_han_window_fx[i] ); + move16(); + } + + Scale_fac[i_subfr] = scale; move16(); - } - Scale_sig( pt_fft, L_FFT, Scale_fac[i_subfr] ); + Scale_sig( pt_fft, L_FFT, Scale_fac[i_subfr] ); - /* compute the spectrum */ - fft_rel_fx( pt_fft, L_FFT, LOG2_L_FFT ); + /* compute the spectrum */ + fft_rel_fx( pt_fft, L_FFT, LOG2_L_FFT ); - /* find energy per critical band */ - ivas_find_enr1( pt_fft, add( Q_new, Scale_fac[i_subfr] ), pt_bands, lf_E + i_subfr * VOIC_BINS, &LEtot, min_band, max_band, - Q_new, e_min_scaled, &Bin_E[i_subfr * L_FFT / 2], BIN, band_energies + i_subfr * NB_BANDS ); + /* find energy per critical band */ + ivas_find_enr1( pt_fft, add( Q_new, Scale_fac[i_subfr] ), pt_bands, q_fr_bands, lf_E + i_subfr * VOIC_BINS, q_lf_E, &LEtot, min_band, max_band, + Q_new, e_min_scaled, &Bin_E[i_subfr * L_FFT / 2], BIN, band_energies + i_subfr * NB_BANDS ); - pt_bands += NB_BANDS; - pt_fft += L_FFT; + pt_bands += NB_BANDS; + pt_fft += L_FFT; + } } + *q_Bin_E = *q_lf_E; + move16(); + /* Average total log energy over both half-frames */ /* *Etot = 10.0f * (float)log10(0.5f * *Etot); */ *Etot = -12800 /* 10.f * logf(0.00001f) in Q8 */; move16(); IF( LEtot != 0 ) { - /* Q of LEtot is Q_new + Q_SCALE - 1, LEtot / 2 can be considered as LEtot in Q_new + Q_SCALE - 1*/ - temp32_log = BASOP_Util_Log10( LEtot, sub( Q31, add( Q_new, QSCALE - Q1 ) ) ); // Q25 - temp32_log = Mpy_32_32( temp32_log, 1342177280 /* 10.f in Q27 */ ); // (Q25, Q27) -> Q21 - *Etot = extract_l( L_shr( temp32_log, Q21 - Q8 ) ); // Q8 + /* Q of LEtot is q_fr_bands+1, LEtot / 2 can be considered as LEtot in q_fr_bands+2 */ + exp = W_norm( LEtot ); + LEtot = W_shl( LEtot, exp ); // q_fr_bands+2+exp + Ltmp = BASOP_Util_Log10( W_extract_h( LEtot ), sub( 61, add( *q_fr_bands, exp ) ) /* 31-(q_fr_bands+2+exp-32) */ ); // Q25 + Ltmp = Mpy_32_32( Ltmp, 1342177280 /* 10.f in Q27 */ ); // (Q25, Q27) -> Q21 + *Etot = extract_h( L_shl( Ltmp, Q24 - Q21 ) ); // Q8 move16(); } } ELSE { - Word16 Qout = add( Q_new, QSCALE - 2 ); - find_enr_dft_fx( hCPE, input_Fs, hCPE->hStereoDft->DFT_fx[0], pt_bands, lf_E, &LEtot, min_band, max_band, Bin_E, band_energies, sub( Q31, hCPE->hStereoDft->DFT_fx_e[0] ), &Qout ); - scale_sig32( lf_E, VOIC_BINS, sub( add( Q_new, QSCALE - 2 ), Qout ) ); - scale_sig32( Bin_E, ( L_FFT / 2 ), sub( add( Q_new, QSCALE - 2 ), Qout ) ); - MVR2R_WORD32( lf_E, lf_E + VOIC_BINS, VOIC_BINS ); - MVR2R_WORD32( Bin_E, Bin_E + ( L_FFT / 2 ), L_FFT / 2 ); - MVR2R_WORD32( band_energies, band_energies + NB_BANDS, NB_BANDS ); - MVR2R_WORD32( pt_bands, pt_bands + NB_BANDS, NB_BANDS ); - - /* *Etot *= 2.f; - *Etot = 10.0f * (float)log10(0.5f * *Etot); - => *Etot = 10.0f * (float)log10(*Etot); - */ + IF( is_zero_arr( hCPE->hStereoDft->DFT_fx[0], STEREO_DFT_N_MAX_ENC ) ) + { + set32_fx( Bin_E, 0, L_FFT ); + set32_fx( lf_E, 0, 2 * VOIC_BINS ); + set32_fx( band_energies, 0, 2 * NB_BANDS ); + set32_fx( fr_bands, e_min_scaled, 2 * NB_BANDS ); + + LEtot = W_shl( W_mult_32_16( e_min_scaled, add( sub( max_band, min_band ), 1 ) ), 1 ); // Q_new + QSCALE - 1 + *q_fr_bands = add( Q_new, Q_SCALE - 2 ); + *q_lf_E = *q_fr_bands; + move16(); + move16(); + } + ELSE + { + exp = sub( getScaleFactor32( hCPE->hStereoDft->DFT_fx[0], STEREO_DFT_N_MAX_ENC ), 1 ); + scale_sig32( hCPE->hStereoDft->DFT_fx[0], STEREO_DFT_N_MAX_ENC, exp ); + hCPE->hStereoDft->DFT_fx_e[0] = sub( hCPE->hStereoDft->DFT_fx_e[0], exp ); + move16(); + find_enr_dft_ivas_fx( hCPE, input_Fs, hCPE->hStereoDft->DFT_fx[0], pt_bands, q_fr_bands, lf_E, q_lf_E, &LEtot, min_band, max_band, Bin_E, q_Bin_E, band_energies, sub( Q31, hCPE->hStereoDft->DFT_fx_e[0] ) ); + MVR2R_WORD32( lf_E, lf_E + VOIC_BINS, VOIC_BINS ); + MVR2R_WORD32( Bin_E, Bin_E + ( L_FFT / 2 ), L_FFT / 2 ); + MVR2R_WORD32( band_energies, band_energies + NB_BANDS, NB_BANDS ); + MVR2R_WORD32( pt_bands, pt_bands + NB_BANDS, NB_BANDS ); + } /* Average total log energy over both half-frames */ *Etot = -12800 /* 10.f * logf(0.00001f) in Q8 */; move16(); IF( LEtot != 0 ) { - temp32_log = BASOP_Util_Log10( LEtot, sub( Q31, add( Q_new, QSCALE - Q2 ) ) ); // Q25 - temp32_log = Mpy_32_32( temp32_log, 1342177280 /* 10.f in Q27 */ ); // (Q25, Q27) -> Q21 - *Etot = extract_l( L_shr( temp32_log, Q21 - Q8 ) ); // Q8 + exp = W_norm( LEtot ); + LEtot = W_shl( LEtot, exp ); // q_fr_bands+exp + Ltmp = BASOP_Util_Log10( W_extract_h( LEtot ), sub( 62, add( *q_fr_bands, exp ) ) /* 31-(q_fr_bands+1+exp-32) */ ); // Q25 + Ltmp = Mpy_32_32( Ltmp, 1342177280 /* 10.f in Q27 */ ); // (Q25, Q27) -> Q21 + *Etot = extract_h( L_shl( Ltmp, Q24 - Q21 ) ); // Q8 move16(); } } + *band_energies_exp = sub( 31, *q_fr_bands ); + move16(); + + exp = sub( getScaleFactor32( fr_bands, 2 * NB_BANDS ), 1 ); + scale_sig32( fr_bands, 2 * NB_BANDS, exp ); + *q_fr_bands = add( *q_fr_bands, exp ); + move16(); + + exp = sub( getScaleFactor32( band_energies, 2 * NB_BANDS ), 1 ); + scale_sig32( band_energies, 2 * NB_BANDS, exp ); + *band_energies_exp = sub( *band_energies_exp, exp ); + move16(); + + *q_Bin_E_old = *q_Bin_E; + move16(); + + /* Per-bin log-energy spectrum */ - Bin_E[L_FFT / 2 - 1] = Bin_E[L_FFT / 2 - 2]; + Bin_E[L_FFT / 2 - 1] = Bin_E[L_FFT / 2 - 2]; // *q_Bin_E move32(); - Bin_E[L_FFT - 1] = Bin_E[L_FFT - 2]; + Bin_E[L_FFT - 1] = Bin_E[L_FFT - 2]; // *q_Bin_E move32(); FOR( i = 0; i < L_FFT / 2; i++ ) { - Bin_E_old[i] = Bin_E[i]; + Bin_E_old[i] = Bin_E[i]; // *q_Bin_E move32(); - /* tmp = (input[i] + input[i+Len]+0.001f)/2.0f */ - // Ltmp = L_max( L_shr( 21474, sub( Q31, add( Q_new, QSCALE ) ) ), L_add( L_shr( Bin_E[i], 1 ), L_shr( Bin_E[i + L_FFT / 2], 1 ) ) ); - Ltmp = L_add( L_shr( Bin_E[i], 1 ), L_shr( Bin_E[i + L_FFT / 2], 1 ) ); // average - if ( Ltmp == 0 ) - { - // Ltmp = L_min( L_shr( 21474, sub( Q31, add( Q_new, QSCALE - 2 ) ) ), 1 ); - Ltmp = L_max( L_shr( 21474, sub( Q31, add( Q_new, QSCALE - 2 ) ) ), 1 ); - if ( EspecdB != NULL ) - { - // temp32_log = L_add( BASOP_Util_Log2( Ltmp ), L_shl( sub( Q31, Q_new + QSCALE ), Q25 ) ); - // EspecdB[i] = -1474; /* log(1e-5) in Q7 */ - EspecdB[i] = -14736; /* log(1e-5) in Q7 */ - move16(); - } + /* PS[i] = ( Bin_E[i] + 1e-5f + Bin_E[i + L_FFT / 2] + 1e-5f ) / 2.0f; */ + PS[i] = W_extract_h( W_mac_32_32( W_mult_32_32( Bin_E[i], ONE_IN_Q30 ), Bin_E[i + L_FFT / 2], ONE_IN_Q30 ) ); // *q_Bin_E + move32(); + + /* Bin_E[i] = (float) ( 10.0f * log( PS[i] ) ); */ + if ( EspecdB != NULL ) + { + EspecdB[i] = -14736; /* ln(1e-5) in Q7 */ + move16(); } - else + + Bin_E[i] = -482887093; /* ln(1e-5) in Q22 */ + move32(); + + IF( PS[i] != 0 ) { + Ltmp = L_add( BASOP_Util_Log2( PS[i] ), L_shl( sub( Q31, *q_Bin_E ), Q25 ) ); + Bin_E[i] = Mpy_32_32( Ltmp, 1860652798 /*10.0*logf(2) in Q28 */ ); // Q22 + move32(); + + tmp = extract_h( L_shl( Bin_E[i], Q23 - Q22 ) ); // Q7 if ( EspecdB != NULL ) { - temp32_log = L_add( BASOP_Util_Log2( Ltmp ), L_shl( sub( Q31, Q_new + QSCALE - 2 ), Q25 ) ); - EspecdB[i] = extract_l( L_shr( Mpy_32_32( temp32_log, 1860652798 ), Q22 - Q7 ) ); /*log(x) = log2(x)*logf(2)*/ - /* 10.0*log((float)tmp) */ - /* 10.0*logf(2) in Q28 = 1860652798 */ - + EspecdB[i] = tmp; // Q7 move16(); } } - if ( PS != NULL ) - { - PS[i] = Ltmp; - move32(); - } } + *q_PS = *q_Bin_E; + move16(); + + exp = L_norm_arr( Bin_E, L_FFT / 2 ); + IF( GE_16( exp, sub( *q_Bin_E, Q22 ) ) ) + { + scale_sig32( Bin_E, L_FFT / 2, sub( *q_Bin_E, Q22 ) ); // *q_Bin_E + } + ELSE + { + scale_sig32( Bin_E + L_FFT / 2, L_FFT / 2, sub( Q22, *q_Bin_E ) ); // Q22 + *q_Bin_E = Q22; + move16(); + } return; } @@ -993,28 +1296,27 @@ static void ivas_find_enr( static void ivas_find_enr1( Word16 data[], /* i : fft result */ Word16 q_data, /* i : Q of fft result */ - Word32 band[], /* o : per band energy Q_new + QSCALE-2 */ - Word32 *ptE, /* o : per bin energy for low frequencies Q_new + QSCALE-2 */ - Word32 *LEtot, /* o : total energy Q_new + QSCALE-2 */ + Word32 band[], /* o : per band energy q_band */ + Word16 *q_band, /* o : Q of per band energy Q0 */ + Word32 *ptE, /* o : per bin energy for low frequencies q_ptE */ + Word16 *q_ptE, /* o : Q of per bin energy for low frequencies Q0 */ + Word64 *LEtot, /* o : total energy q_band+1 */ const Word16 min_band, /* i : minimum critical band Q0 */ const Word16 max_band, /* i : maximum critical band Q0 */ const Word16 Q_new, /* i : scaling factor Q0 */ - const Word32 e_min, /* i : minimum energy scaled Q_new + QSCALE-2 */ - Word32 *Bin_E, /* o : Per bin energy Q_new + QSCALE-2 */ - Word16 BIN_FREQ_FX, /* i : Number of frequency bins */ - Word32 *band_energies /* o : per band energy without MODE2_E_MIN Q_new + QSCALE-2 */ + const Word32 e_min, /* i : minimum energy scaled Q_new+QSCALE-2 */ + Word32 *Bin_E, /* o : Per bin energy q_ptE */ + Word16 BIN_FREQ_FX, /* i : Number of frequency bins Q0 */ + Word32 *band_energies /* o : per band energy without MODE2_E_MIN q_band */ ) { - Word16 i, cnt; + Word16 i; Word16 freq; Word16 *ptR, *ptI; - Word32 Ltmp; Word16 voic_band; - Word32 etot; - Word32 norm_val; - - norm_val = 131072 /* 4.0f / ( L_FFT * L_FFT ) in Q31 */; - move32(); + Word64 etot, band_ener; + Word16 start_freq; + Word32 min_ener; ptR = &data[1]; /* first real */ ptI = &data[L_FFT - 1]; /* first imaginary */ @@ -1028,47 +1330,64 @@ static void ivas_find_enr1( * in NS and find_tilt() *-----------------------------------------------------------------*/ + *q_ptE = add( shl( q_data, 1 ), 14 ); + move16(); + *q_band = add( shl( q_data, 1 ), 14 ); + move16(); + + /* Only used for comparison purpose, so saturation is added. It doesn't effect the outcome */ + min_ener = L_shl( e_min, sub( *q_band, add( Q_new, QSCALE - 2 ) ) ); // *q_band + freq = BIN_FREQ_FX; move16(); FOR( i = 0; i < voic_band; i++ ) /* up to maximum allowed voiced critical band */ { - band[i] = 0; - move32(); - cnt = 0; + band_ener = 0; + move64(); + start_freq = freq; move16(); WHILE( LE_32( freq, crit_bands_fx[i] ) ) { - // *ptE = *ptR * *ptR + *ptI * *ptI; /* energy */ - Word64 te = ( W_add( W_mult0_32_32( *ptR, *ptR ), W_mult0_32_32( *ptI, *ptI ) ) ); // 2 * Qfft - Word16 te_exp = W_norm( te ); - te = W_shl( te, te_exp ); // 2 * Qfft + te_exp - Ltmp = W_extract_h( te ); // 2 * Qfft + te_exp - 32 + /* + *ptE = *ptR * *ptR + *ptI * *ptI; - // *ptE *= norm_val; /* normalization - corresponds to FFT normalization by 2/L_FFT */ - Ltmp = Mpy_32_32( Ltmp, norm_val ); // 2 * Qfft + te_exp - 32 - *ptE = L_shl_sat( Ltmp, sub( add( Q_new, QSCALE - 2 ), add( shl( q_data, Q1 ), sub( te_exp, 32 ) ) ) ); // Q_new + QSCALE - 2 - move32(); + Overflow occurs in the above operation only when ptR and ptI values are equal to -32768. + In that case, energy value will be 2^31 (only one greater than max 32 bit value). + Hence, saturation is added. + + *ptE *= norm_val; + norm_val = 4 / (256 * 256), As the value is in power's of 2, result can be obtained by increasing the Q factor + + Q of energy = 2 * q_data + 14 = *q_ptE + */ - *Bin_E++ = *ptE; // Q_new + QSCALE - 2 + *ptE = L_mac0_sat( L_mult0( *ptR, *ptR ), *ptI, *ptI ); // *q_ptE move32(); - band[i] = L_add_sat( band[i], *ptE++ ); // Q_new + QSCALE - 2 + + *Bin_E++ = *ptE; // *q_ptE move32(); + + /* + BIN_FREQ_FX = BIN, cnt = ( ( crit_bands_fx[i] - start_freq ) / BIN ) + 1 + band[i] += *ptE++; + band[i] *= inv_tbl[cnt]; // normalization per frequency bin + */ + band_ener = W_mac_32_16( band_ener, *ptE, inv_tbl_fx[( ( crit_bands_fx[i] - start_freq ) / BIN ) + 1] ); // *q_ptE+16 ptR++; ptI--; - + ptE++; freq = add( freq, BIN_FREQ_FX ); - cnt = add( cnt, 1 ); } - band[i] = Mpy_32_16_1( band[i], inv_tbl_fx[cnt] ); /* normalization per frequency bin */ // Q_new + QSCALE - 2 + band[i] = W_extract_h( W_shl( band_ener, Q16 ) ); // *q_ptE+16+16-32 = *q_ptE = *q_band move32(); - band_energies[i] = band[i]; /* per band energy without E_MIN */ // Q_new + QSCALE - 2 + band_energies[i] = band[i]; /* per band energy without E_MIN */ // *q_band move32(); - if ( LT_32( band[i], e_min ) ) // Q_new + QSCALE - 2 + if ( LT_32( band[i], min_ener ) ) // *q_band { - band[i] = e_min; // Q_new + QSCALE - 2 + band[i] = min_ener; // *q_band move32(); } } @@ -1081,41 +1400,50 @@ static void ivas_find_enr1( FOR( i = voic_band; i < NB_BANDS; i++ ) { - band[i] = 0; - move32(); - cnt = 0; + band_ener = 0; + move64(); + start_freq = freq; move16(); WHILE( LE_32( freq, crit_bands_fx[i] ) ) { - // *Bin_E = *ptR * *ptR + *ptI * *ptI; - Word64 te = ( W_add( W_mult0_32_32( *ptR, *ptR ), W_mult0_32_32( *ptI, *ptI ) ) ); // 2 * Qfft - Word16 te_exp = W_norm( te ); - te = W_shl( te, te_exp ); // 2 * Qfft + te_exp - Ltmp = W_extract_h( te ); // 2 * Qfft + te_exp - 32 + /* + *Bin_E = *ptR * *ptR + *ptI * *ptI; - // *Bin_E *= norm_val; - Ltmp = Mpy_32_32( Ltmp, norm_val ); // 2 * Qfft + te_exp - 32 - *Bin_E = L_shl_sat( Ltmp, sub( add( Q_new, QSCALE - 2 ), add( shl( q_data, Q1 ), sub( te_exp, 32 ) ) ) ); // Q_new + QSCALE - 2 - move32(); + Overflow occurs in the below operation only when ptR and ptI values are equal to - 32768. + In that case, energy value will be 2 ^ 31 (only one greater than max 32 bit value). + Hence, saturation is added. - band[i] = L_add_sat( band[i], *Bin_E++ ); // Q_new + QSCALE - 2 + *Bin_E *= norm_val; + norm_val = 4 / (256 * 256), As the value is in power's of 2, result can be obtained by increasing the Q factor + + Q of energy = 2 * q_data + 14 = *q_ptE + */ + + *Bin_E = L_mac0_sat( L_mult0( *ptR, *ptR ), *ptI, *ptI ); // 2*q_data+14 = *q_ptE move32(); + + /* + BIN_FREQ_FX = BIN, cnt = ( ( crit_bands_fx[i] - start_freq ) / BIN ) + 1 + band[i] += *ptE++; + band[i] *= inv_tbl[cnt]; // normalization per frequency bin + */ + band_ener = W_mac_32_16( band_ener, *Bin_E, inv_tbl_fx[( ( crit_bands_fx[i] - start_freq ) / BIN ) + 1] ); // q_ptE+16 ptR++; ptI--; + Bin_E++; freq = add( freq, BIN_FREQ_FX ); - cnt = add( cnt, 1 ); } - band[i] = Mpy_32_16_1( band[i], inv_tbl_fx[cnt] ); /* normalization per frequency bin */ // Q_new + QSCALE - 2 + band[i] = W_extract_h( W_shl_nosat( band_ener, Q16 ) ); // *q_ptE+16+16-32 = *q_ptE = *q_band move32(); - band_energies[i] = band[i]; /* per band energy without E_MIN */ // Q_new + QSCALE - 2 + band_energies[i] = band[i]; /* per band energy without E_MIN */ // *q_band move32(); - if ( LT_32( band[i], e_min ) ) // Q_new + QSCALE - 2 + if ( LT_32( band[i], min_ener ) ) // *q_band { - band[i] = e_min; // Q_new + QSCALE - 2 + band[i] = min_ener; // *q_band move32(); } } @@ -1125,14 +1453,14 @@ static void ivas_find_enr1( * Find the total energy over the input bandwidth *-----------------------------------------------------------------*/ - etot = *LEtot; - move32(); + etot = *LEtot; // *q_band + move64(); FOR( i = min_band; i <= max_band; i++ ) { - etot = L_add_sat( etot, band[i] ); // Q_new + QSCALE - 2 + etot = W_mac_32_32( etot, band[i], 1 ); // *q_band+1 } - *LEtot = etot; - move32(); + *LEtot = etot; // *q_band+1 + move64(); return; } diff --git a/lib_enc/hq_core_enc.c b/lib_enc/hq_core_enc.c index 91701fd7f..148ef885e 100644 --- a/lib_enc/hq_core_enc.c +++ b/lib_enc/hq_core_enc.c @@ -68,7 +68,7 @@ void hq_core_enc_ivas_fx( Word16 two_frames_buffer[2 * L_FRAME48k]; Word16 tmp; Word16 Aq_old_fx[M + 1]; - Word16 output_fx[L_FRAME16k]; + Word16 output_fx[L_FRAME48k]; Word16 Q_audio; Word16 out_q = 0, old_q = 0; move16(); @@ -87,7 +87,7 @@ void hq_core_enc_ivas_fx( set32_fx( wtda_audio_fx32, 0, 2 * L_FRAME48k ); st->Nb_ACELP_frames = 0; move16(); - set_zero_fx( t_audio_fx, L_FRAME48k ); + set_zero_fx( t_audio_fx, L_FRAME48k_EXT ); /* set input_frame length */ input_frame = input_frame_orig; @@ -282,7 +282,7 @@ void hq_core_enc_ivas_fx( * Transform-domain encoding *--------------------------------------------------------------------------*/ - scale_sig32( t_audio_fx, L_FRAME48k, sub( Q12, Q_audio ) ); + scale_sig32( t_audio_fx, L_FRAME48k_EXT, sub( Q12, Q_audio ) ); scale_sig32( wtda_audio_fx32, 2 * L_FRAME48k, sub( Q12, Q_audio ) ); Q_audio = 12; move16(); @@ -394,7 +394,7 @@ void hq_core_enc_ivas_fx( { /* Store LB synthesis in case of switch to ACELP */ Copy( output_fx, st->hLPDmem->old_exc, L_FRAME16k ); - st->hLPDmem->q_lpd_old_exc = 15; + st->hLPDmem->q_lpd_old_exc = 0; move16(); } pop_wmops(); diff --git a/lib_enc/hq_hr_enc.c b/lib_enc/hq_hr_enc.c index 07080804e..c72e682e0 100644 --- a/lib_enc/hq_hr_enc.c +++ b/lib_enc/hq_hr_enc.c @@ -265,6 +265,7 @@ void hq_hr_enc_ivas_fx( IF( NE_16( hqswb_clas, HQ_HVQ ) ) { apply_envelope_enc_ivas_fx( t_audio_q_norm, ynrm, num_sfm, sfm_start, sfm_end, t_audio_q_fx ); + scale_sig32( t_audio_q_fx, length, sub( Q12, Q_audio ) ); // Q12 } IF( is_transient ) diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index acaee9dea..e53515637 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -764,33 +764,9 @@ ivas_error pre_proc_front_ivas_fx( Word16 Scale_fac[2] = { 0 }; move16(); move16(); - Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( *Q_new, Q_SCALE - 2 ), st->q_Bin_E ) ); - st->q_Bin_E = add( *Q_new, Q_SCALE - 2 ); - move16(); + Word32 Le_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( *Q_new, QSCALE - 2 ) ) ), 1 ), 1 ); - ivas_analy_sp_fx_front( element_mode, hCPE, input_Fs, inp_12k8_fx /*old_inp_12k8_e*/, *Q_new, fr_bands_fx, lf_E_fx, &Etot_fx, st->min_band, st->max_band, Le_min_scaled, Scale_fac, st->Bin_E_fx, st->Bin_E_old_fx, PS_fx, lgBin_E_fx, band_energies_fx, fft_buff_fx /*, Q_inp_dmx*/ ); - st->q_Bin_E_old = add( *Q_new, Q_SCALE - 2 ); - move16(); - fr_bands_fx_q = add( *Q_new, QSCALE - 2 ); - band_energies_fx_exp = sub( 31, add( *Q_new, QSCALE - 2 ) ); - Word16 tmp_norm = L_norm_arr( fr_bands_fx, 2 * NB_BANDS ); - IF( GE_16( tmp_norm, 2 ) ) - { - scale_sig32( fr_bands_fx, 2 * NB_BANDS, 2 ); - fr_bands_fx_q = add( fr_bands_fx_q, 2 ); - } - tmp_norm = L_norm_arr( band_energies_fx, 2 * NB_BANDS ); - IF( GE_16( tmp_norm, 2 ) ) - { - scale_sig32( band_energies_fx, 2 * NB_BANDS, 2 ); - band_energies_fx_exp = sub( band_energies_fx_exp, 2 ); - } - Qfact_PS = add( *Q_new, QSCALE - 2 ); - q_lf_E_fx = add( *Q_new, QSCALE - 2 ); - IF( lgBin_E_fx != NULL ) - { - Copy_Scale_sig_16_32( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) ); - } + ivas_analy_sp_fx_front( element_mode, hCPE, input_Fs, inp_12k8_fx /*old_inp_12k8_e*/, *Q_new, fr_bands_fx, &fr_bands_fx_q, lf_E_fx, &q_lf_E_fx, &Etot_fx, st->min_band, st->max_band, Le_min_scaled, Scale_fac, st->Bin_E_fx, &st->q_Bin_E, st->Bin_E_old_fx, &st->q_Bin_E_old, PS_fx, &Qfact_PS, lgBin_E_fx, band_energies_fx, &band_energies_fx_exp, fft_buff_fx /*, Q_inp_dmx*/ ); Word16 min_q = MAX_16, fft_q[2]; Word16 i_sbfr; @@ -952,17 +928,18 @@ ivas_error pre_proc_front_ivas_fx( IF( lr_vad_enabled && st->idchan == 0 ) { Scale_sig32( hCPE->hFrontVad[0]->hNoiseEst->bckr_fx, NB_BANDS, sub( add( fr_bands_LR_fx_q, Q_SCALE ), hCPE->hFrontVad[0]->hNoiseEst->q_bckr ) ); + hCPE->hFrontVad[0]->hNoiseEst->q_bckr = add( fr_bands_LR_fx_q, Q_SCALE ); + move16(); Scale_sig32( hCPE->hFrontVad[1]->hNoiseEst->bckr_fx, NB_BANDS, sub( add( fr_bands_LR_fx_q, Q_SCALE ), hCPE->hFrontVad[1]->hNoiseEst->q_bckr ) ); + hCPE->hFrontVad[1]->hNoiseEst->q_bckr = hCPE->hFrontVad[0]->hNoiseEst->q_bckr; + move16(); Word32 Le_min_scaled0, Le_min_scaled1; Le_min_scaled0 = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_bands0, QSCALE ) ) ), 1 ), 1 ); - noise_est_down_fx( fr_bands_LR_fx[0], hCPE->hFrontVad[0]->hNoiseEst->bckr_fx, tmpN_LR_fx[0], tmpE_LR_fx[0], st->min_band, st->max_band, &hCPE->hFrontVad[0]->hNoiseEst->totalNoise_fx, Etot_LR_fx[0], &hCPE->hFrontVad[0]->hNoiseEst->Etot_last_fx, &hCPE->hFrontVad[0]->hNoiseEst->Etot_v_h2_fx, Q_bands0, Le_min_scaled0 ); - hCPE->hFrontVad[0]->hNoiseEst->q_bckr = add( Q_bands0, QSCALE ); - move16(); Le_min_scaled1 = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_bands1, QSCALE ) ) ), 1 ), 1 ); + + noise_est_down_fx( fr_bands_LR_fx[0], hCPE->hFrontVad[0]->hNoiseEst->bckr_fx, tmpN_LR_fx[0], tmpE_LR_fx[0], st->min_band, st->max_band, &hCPE->hFrontVad[0]->hNoiseEst->totalNoise_fx, Etot_LR_fx[0], &hCPE->hFrontVad[0]->hNoiseEst->Etot_last_fx, &hCPE->hFrontVad[0]->hNoiseEst->Etot_v_h2_fx, Q_bands0, Le_min_scaled0 ); noise_est_down_fx( fr_bands_LR_fx[1], hCPE->hFrontVad[1]->hNoiseEst->bckr_fx, tmpN_LR_fx[1], tmpE_LR_fx[1], st->min_band, st->max_band, &hCPE->hFrontVad[1]->hNoiseEst->totalNoise_fx, Etot_LR_fx[1], &hCPE->hFrontVad[1]->hNoiseEst->Etot_last_fx, &hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2_fx, Q_bands1, Le_min_scaled1 ); - hCPE->hFrontVad[1]->hNoiseEst->q_bckr = add( Q_bands1, QSCALE ); - move16(); corr_shiftL_fx = correlation_shift_fx( hCPE->hFrontVad[0]->hNoiseEst->totalNoise_fx ); corr_shiftR_fx = correlation_shift_fx( hCPE->hFrontVad[1]->hNoiseEst->totalNoise_fx ); diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index ea5676d5f..8271f1526 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -318,7 +318,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx( } } - ivas_mcmasa_dmx_modify_fx( len_inp_memory, input_buff_fx, nSCE_old + CPE_CHANNELS * nCPE_old, st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE ); + ivas_mcmasa_dmx_modify_fx( len_inp_memory, input_buff_fx, q_input_buff, nSCE_old + CPE_CHANNELS * nCPE_old, st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE ); + n_CoreCoder_existing = 0; move16(); @@ -360,7 +361,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( test(); IF( LE_16( st_ivas->nCPE, 1 ) && st_ivas->hMCT != NULL ) { - ivas_mct_enc_close( &( st_ivas->hMCT ) ); + ivas_mct_enc_close_fx( &( st_ivas->hMCT ) ); } /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles */ @@ -644,7 +645,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( } } - IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = create_mct_enc_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index bd2f19ade..27f3ddd7c 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -259,20 +259,10 @@ ivas_error ivas_cpe_enc_fx( test(); IF( hCPE->hFrontVad[0] != NULL && NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { - Word16 Qband = -1; - move16(); - Word16 Q_new_old = add( add( sub( Q_inp, Qband ), Q_add ), QSCALE ); - FOR( n = 0; n < CPE_CHANNELS; n++ ) { Q_buffer[n] = hCPE->hFrontVad[n]->q_buffer_12k8; move16(); - Scale_sig32( hCPE->hFrontVad[n]->hNoiseEst->bckr_fx, 20, sub( Q_new_old, hCPE->hFrontVad[n]->hNoiseEst->q_bckr ) ); - hCPE->hFrontVad[n]->hNoiseEst->q_bckr = Q_new_old; - move16(); - Scale_sig32( hCPE->hFrontVad[n]->hNoiseEst->enrO_fx, 20, sub( Q_new_old, hCPE->hFrontVad[n]->hNoiseEst->q_enrO ) ); - hCPE->hFrontVad[n]->hNoiseEst->q_enrO = Q_new_old; - move16(); } } diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 3979326e4..1c715d516 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -473,7 +473,7 @@ ivas_error ivas_enc_fx( move16(); hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; - IF( NE_32( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -256 /* -1.0f in Q8 */, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_ism_metadata_enc_fx( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -256 /* -1.0f in Q8 */, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index f892dca8f..16e1d5008 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -239,8 +239,12 @@ ivas_error front_vad_fx( noise_est_pre_32fx( Etot_fx, hFrontVads[0]->ini_frame, hFrontVad->hNoiseEst, 0, 0, 0 ); /* wb_vad */ - Scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, NB_BANDS, Q_new + QSCALE - ( Q_new_old + QSCALE ) ); - Scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, NB_BANDS, Q_new + QSCALE - ( Q_new_old + QSCALE ) ); + Scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, NB_BANDS, sub( add( Q_new, QSCALE ), hFrontVads[n]->hNoiseEst->q_bckr ) ); + hFrontVads[n]->hNoiseEst->q_bckr = add( Q_new, QSCALE ); + move16(); + Scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, NB_BANDS, sub( add( Q_new, QSCALE ), hFrontVads[n]->hNoiseEst->q_enrO ) ); + hFrontVads[n]->hNoiseEst->q_enrO = add( Q_new, QSCALE ); + move16(); hFrontVad->hVAD->vad_flag = wb_vad_ivas_fx( sts[n], fr_bands_fx[n], &dummy, &dummy, &dummy, &snr_sum_he_fx, &localVAD_HE_SAD[n], &dummy_short, Q_new, hFrontVad->hVAD, hFrontVad->hNoiseEst, hFrontVad->lp_speech_fx, hFrontVad->lp_noise_fx ); test(); @@ -572,7 +576,9 @@ ivas_error front_vad_spar_fx( Scale_sig32( hFrontVad->hNoiseEst->bckr_fx, 20, sub( add( Q_new_old, QSCALE + 2 ), hFrontVad->hNoiseEst->q_bckr ) ); // Q_new_old +QSCALE +2 Scale_sig32( hFrontVad->hNoiseEst->enrO_fx, 20, sub( add( Q_new_old, QSCALE + 2 ), hFrontVad->hNoiseEst->q_enrO ) ); - hFrontVad->hNoiseEst->q_enrO = add( Q_new_old, QSCALE + 2 ); + hFrontVad->hNoiseEst->q_bckr = add( Q_new_old, QSCALE + 2 ); + move16(); + hFrontVad->hNoiseEst->q_enrO = hFrontVad->hNoiseEst->q_bckr; move16(); Word16 Q_buffer = hFrontVad->q_buffer_12k8; move16(); @@ -598,8 +604,8 @@ ivas_error front_vad_spar_fx( Word32 e_min_scaled; e_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_bands, QSCALE ) ) ), 1 ), 1 ); - Scale_sig32( hFrontVad->hNoiseEst->bckr_fx, 20, sub( Q_bands + QSCALE, add( Q_new_old, QSCALE + 2 ) ) ); - hFrontVad->hNoiseEst->q_bckr = Q_bands + QSCALE; + Scale_sig32( hFrontVad->hNoiseEst->bckr_fx, 20, sub( add( Q_bands, QSCALE ), hFrontVad->hNoiseEst->q_bckr ) ); + hFrontVad->hNoiseEst->q_bckr = add( Q_bands, QSCALE ); move16(); noise_est_down_fx( fr_bands_fx[0], hFrontVad->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, &hFrontVad->hNoiseEst->totalNoise_fx, Etot_fx[0], &hFrontVad->hNoiseEst->Etot_last_fx, &hFrontVad->hNoiseEst->Etot_v_h2_fx, Q_bands, e_min_scaled ); corr_shift_fx = correlation_shift_fx( hFrontVad->hNoiseEst->totalNoise_fx ); diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 06e4f7a3a..2a516ea28 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -609,7 +609,7 @@ ivas_error ivas_init_encoder( { st_ivas->ism_mode = ivas_ism_mode_select( hEncoderConfig->nchan_inp, ivas_total_brate ); - if ( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_inp, element_brate_tmp ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_ism_metadata_enc_create_fx( st_ivas, hEncoderConfig->nchan_inp, element_brate_tmp ) ) != IVAS_ERR_OK ) { return error; } @@ -624,7 +624,7 @@ ivas_error ivas_init_encoder( if ( st_ivas->ism_mode == ISM_MODE_PARAM ) { - if ( ( error = ivas_param_ism_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_param_ism_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -663,7 +663,7 @@ ivas_error ivas_init_encoder( { st_ivas->nchan_transport = hEncoderConfig->nchan_inp; - if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_masa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -700,7 +700,7 @@ ivas_error ivas_init_encoder( if ( st_ivas->nCPE > 1 ) { - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -715,7 +715,7 @@ ivas_error ivas_init_encoder( move32(); st_ivas->nchan_transport = 2; - if ( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_ism_metadata_enc_create_fx( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK ) { return error; } @@ -740,7 +740,7 @@ ivas_error ivas_init_encoder( { return error; } - if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_masa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -776,7 +776,7 @@ ivas_error ivas_init_encoder( st_ivas->ism_mode = ISM_SBA_MODE_DISC; } - if ( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_ism_metadata_enc_create_fx( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK ) { return error; } @@ -820,7 +820,7 @@ ivas_error ivas_init_encoder( if ( st_ivas->nCPE > 1 ) { - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -839,7 +839,7 @@ ivas_error ivas_init_encoder( } } - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -871,12 +871,12 @@ ivas_error ivas_init_encoder( } } - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - if ( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_create_lfe_enc_fx( &st_ivas->hLFE, input_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -889,7 +889,7 @@ ivas_error ivas_init_encoder( st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS / 2; st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; - if ( ( error = ivas_mc_paramupmix_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_mc_paramupmix_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -902,12 +902,12 @@ ivas_error ivas_init_encoder( } } - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - if ( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_create_lfe_enc_fx( &st_ivas->hLFE, input_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -929,7 +929,7 @@ ivas_error ivas_init_encoder( if ( st_ivas->nCPE > 1 ) { - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -946,7 +946,7 @@ ivas_error ivas_init_encoder( return error; } - if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_masa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1188,7 +1188,7 @@ ivas_error ivas_init_encoder_fx( st_ivas->ism_mode = ivas_ism_mode_select( hEncoderConfig->nchan_inp, ivas_total_brate ); move32(); - IF( NE_32( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_inp, element_brate_tmp ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_ism_metadata_enc_create_fx( st_ivas, hEncoderConfig->nchan_inp, element_brate_tmp ) ), IVAS_ERR_OK ) ) { return error; } @@ -1203,7 +1203,7 @@ ivas_error ivas_init_encoder_fx( IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { - IF( NE_32( ( error = ivas_param_ism_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_param_ism_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1243,7 +1243,7 @@ ivas_error ivas_init_encoder_fx( st_ivas->nchan_transport = hEncoderConfig->nchan_inp; move16(); - IF( NE_32( ( error = ivas_masa_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_masa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1286,7 +1286,7 @@ ivas_error ivas_init_encoder_fx( IF( st_ivas->nCPE > 1 ) { - IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = create_mct_enc_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1302,7 +1302,7 @@ ivas_error ivas_init_encoder_fx( st_ivas->nchan_transport = 2; move16(); - IF( NE_32( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_ism_metadata_enc_create_fx( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ), IVAS_ERR_OK ) ) { return error; } @@ -1330,7 +1330,7 @@ ivas_error ivas_init_encoder_fx( { return error; } - IF( NE_32( ( error = ivas_masa_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_masa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1370,7 +1370,7 @@ ivas_error ivas_init_encoder_fx( move32(); } - IF( NE_32( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_ism_metadata_enc_create_fx( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ), IVAS_ERR_OK ) ) { return error; } @@ -1416,7 +1416,7 @@ ivas_error ivas_init_encoder_fx( IF( GT_16( st_ivas->nCPE, 1 ) ) { - IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = create_mct_enc_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1437,7 +1437,7 @@ ivas_error ivas_init_encoder_fx( } } - IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = create_mct_enc_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1474,12 +1474,12 @@ ivas_error ivas_init_encoder_fx( } } - IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = create_mct_enc_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - IF( NE_32( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_create_lfe_enc_fx( &st_ivas->hLFE, input_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -1496,7 +1496,7 @@ ivas_error ivas_init_encoder_fx( st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; move16(); - IF( NE_32( ( error = ivas_mc_paramupmix_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_mc_paramupmix_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1511,12 +1511,12 @@ ivas_error ivas_init_encoder_fx( } } - IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = create_mct_enc_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - IF( NE_32( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_create_lfe_enc_fx( &st_ivas->hLFE, input_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -1538,7 +1538,7 @@ ivas_error ivas_init_encoder_fx( IF( GT_16( st_ivas->nCPE, 1 ) ) { - IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = create_mct_enc_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1555,7 +1555,7 @@ ivas_error ivas_init_encoder_fx( return error; } - IF( NE_32( ( error = ivas_masa_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_masa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1991,25 +1991,25 @@ void ivas_destroy_enc( ivas_dirac_enc_close_fx( &( st_ivas->hDirAC ), st_ivas->hEncoderConfig->input_Fs ); /* ParamISM handle */ - ivas_param_ism_enc_close( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs ); + ivas_param_ism_enc_close_fx( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs ); /* SPAR handle */ ivas_spar_enc_close_fx( &( st_ivas->hSpar ), st_ivas->hEncoderConfig->input_Fs, nchan_inp, 0 ); /* MASA handle */ - ivas_masa_enc_close( &( st_ivas->hMasa ) ); + ivas_masa_enc_close_fx( &( st_ivas->hMasa ) ); /* MCT handle */ - ivas_mct_enc_close( &( st_ivas->hMCT ) ); + ivas_mct_enc_close_fx( &( st_ivas->hMCT ) ); /* LFE handle */ - ivas_lfe_enc_close( &( st_ivas->hLFE ) ); + ivas_lfe_enc_close_fx( &( st_ivas->hLFE ) ); /* LFE low pass filter state */ - ivas_lfe_lpf_enc_close( &( st_ivas->hLfeLpf ) ); + ivas_lfe_lpf_enc_close_fx( &( st_ivas->hLfeLpf ) ); /* Param-Upmix MC handle */ - ivas_mc_paramupmix_enc_close( &( st_ivas->hMCParamUpmix ), st_ivas->hEncoderConfig->input_Fs ); + ivas_mc_paramupmix_enc_close_fx( &( st_ivas->hMCParamUpmix ), st_ivas->hEncoderConfig->input_Fs ); /* Parametric MC handle */ ivas_param_mc_enc_close_fx( &( st_ivas->hParamMC ), st_ivas->hEncoderConfig->input_Fs ); diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 1a956f4c5..607740bfe 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -302,18 +302,18 @@ ivas_error ivas_ism_enc_fx( IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { - ivas_param_ism_compute_noisy_speech_flag( st_ivas ); + ivas_param_ism_compute_noisy_speech_flag_fx( st_ivas ); flag_noisy_speech = st_ivas->hParamIsm->flag_noisy_speech; move16(); } IF( dtx_flag ) { - ivas_ism_metadata_sid_enc( st_ivas->hISMDTX, flag_noisy_speech, nchan_ism, st_ivas->nchan_transport, st_ivas->ism_mode, st_ivas->hIsmMetaData, sid_flag, md_diff_flag, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata ); + ivas_ism_metadata_sid_enc_fx( st_ivas->hISMDTX, flag_noisy_speech, nchan_ism, st_ivas->nchan_transport, st_ivas->ism_mode, st_ivas->hIsmMetaData, sid_flag, md_diff_flag, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata ); } ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { - IF( NE_32( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -256 /* -1.0f in Q8 */, 0, NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_ism_metadata_enc_fx( &st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -256 /* -1.0f in Q8 */, 0, NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ), IVAS_ERR_OK ) ) { return error; } @@ -339,8 +339,8 @@ ivas_error ivas_ism_enc_fx( ism_total_brate_ref = ism_total_brate; move32(); - IF( NE_32( ( error = ivas_ism_metadata_enc( &ism_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, - nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx : 0, flag_omasa_ener_brate, st_ivas->hMasa != NULL ? &( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt ) : NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ), + IF( NE_32( ( error = ivas_ism_metadata_enc_fx( &ism_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, + nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx : 0, flag_omasa_ener_brate, st_ivas->hMasa != NULL ? &( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt ) : NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ), IVAS_ERR_OK ) ) { return error; @@ -555,7 +555,7 @@ ivas_error ivas_ism_enc_config( IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) && EQ_16( last_ism_mode, ISM_MODE_DISC ) ) { /* Allocate and Initialize the memory used by ParamISM when switch from Discrete ISM */ - IF( NE_32( ( error = ivas_param_ism_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_param_ism_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -565,7 +565,7 @@ ivas_error ivas_ism_enc_config( IF( EQ_16( st_ivas->ism_mode, ISM_MODE_DISC ) && EQ_16( last_ism_mode, ISM_MODE_PARAM ) ) { /* Deallocate the memory used by ParamISM when switch to Discrete ISM */ - ivas_param_ism_enc_close( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs ); + ivas_param_ism_enc_close_fx( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs ); } } diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index ffd0e1b1d..9bcc34dd8 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -72,9 +72,9 @@ * Local function declarations *-----------------------------------------------------------------------*/ -static void encode_angle_indices( BSTR_ENC_HANDLE hBstr, ISM_METADATA_ANGLE_HANDLE angle, const int16_t last_ism_metadata_flag, const int16_t ini_frame, const int16_t idx_angle1_abs, const int16_t idx_angle2_abs, int16_t *flag_abs_angle1, int16_t *flag_abs_angle2 ); +static void encode_angle_indices_fx( BSTR_ENC_HANDLE hBstr, ISM_METADATA_ANGLE_HANDLE angle, const Word16 last_ism_metadata_flag, const Word16 ini_frame, const Word16 idx_angle1_abs, const Word16 idx_angle2_abs, Word16 *flag_abs_angle1, Word16 *flag_abs_angle2 ); -static void encode_radius( BSTR_ENC_HANDLE hBstr, int16_t *last_radius_idx, int16_t *radius_diff_cnt, const int16_t last_ism_metadata_flag, const int16_t idx_radius_abs, int16_t *flag_abs_radius ); +static void encode_radius_fx( BSTR_ENC_HANDLE hBstr, Word16 *last_radius_idx, Word16 *radius_diff_cnt, const Word16 last_ism_metadata_flag, const Word16 idx_radius_abs, Word16 *flag_abs_radius ); /*-------------------------------------------------------------------------* @@ -102,15 +102,15 @@ ivas_error ivas_set_ism_metadata_fx( move16(); /* save read metadata parameters to the internal codec structure */ - hIsmMeta->azimuth_fx = azimuth; + hIsmMeta->azimuth_fx = azimuth; // Q22 move32(); - hIsmMeta->elevation_fx = elevation; + hIsmMeta->elevation_fx = elevation; // Q22 move32(); - hIsmMeta->radius_fx = radius_meta; + hIsmMeta->radius_fx = radius_meta; // Q9 move16(); - hIsmMeta->yaw_fx = yaw; + hIsmMeta->yaw_fx = yaw; // Q22 move16(); - hIsmMeta->pitch_fx = pitch; + hIsmMeta->pitch_fx = pitch; // Q22 move16(); hIsmMeta->non_diegetic_flag = non_diegetic_flag; move16(); @@ -124,7 +124,7 @@ ivas_error ivas_set_ism_metadata_fx( * Rate importance of particular ISM streams *-------------------------------------------------------------------------*/ -static void rate_ism_importance( +static void rate_ism_importance_fx( const Word16 nchan_transport, /* i : number of transported channels */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ @@ -187,7 +187,7 @@ static void rate_ism_importance( * quantize and encode ISM metadata *-------------------------------------------------------------------------*/ -ivas_error ivas_ism_metadata_enc( +ivas_error ivas_ism_metadata_enc_fx( Word32 *ism_total_brate, /* i/o: ISM total bitrate */ const Word16 nchan_ism, /* i : number of ISM channels */ const Word16 nchan_transport, /* i : number of transport channels */ @@ -334,7 +334,7 @@ ivas_error ivas_ism_metadata_enc( IF( NE_16( ism_mode, ISM_SBA_MODE_DISC ) ) { - rate_ism_importance( nchan_transport, hIsmMeta, hSCE, lowrate_metadata_flag, ism_imp ); + rate_ism_importance_fx( nchan_transport, hIsmMeta, hSCE, lowrate_metadata_flag, ism_imp ); } } @@ -475,18 +475,18 @@ ivas_error ivas_ism_metadata_enc( /* Map azimuth to panning range [-90:90] */ IF( GT_32( hIsmMetaData->azimuth_fx, 377487360 /*90.0f Q22*/ ) ) { - hIsmMetaData->azimuth_fx = L_sub( 754974720 /*180.0f Q22*/, hIsmMetaData->azimuth_fx ); + hIsmMetaData->azimuth_fx = L_sub( 754974720 /*180.0f Q22*/, hIsmMetaData->azimuth_fx ); // Q22 move32(); } IF( LT_32( hIsmMetaData->azimuth_fx, L_negate( 377487360 ) /*-90.0f Q22*/ ) ) { - hIsmMetaData->azimuth_fx = L_sub( L_negate( 754974720 ) /*-180.0f Q22*/, hIsmMetaData->azimuth_fx ); + hIsmMetaData->azimuth_fx = L_sub( L_negate( 754974720 ) /*-180.0f Q22*/, hIsmMetaData->azimuth_fx ); // Q22 move32(); } idx_angle1_abs = ism_quant_meta_fx( hIsmMetaData->azimuth_fx, &valQ_fx, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); - encode_angle_indices( hBstr, &( hIsmMetaData->position_angle ), hIsmMetaData->last_ism_metadata_flag, hSCE[0]->hCoreCoder[0]->ini_frame, idx_angle1_abs, 0, &flag_abs_azimuth[ch], NULL ); + encode_angle_indices_fx( hBstr, &( hIsmMetaData->position_angle ), hIsmMetaData->last_ism_metadata_flag, hSCE[0]->hCoreCoder[0]->ini_frame, idx_angle1_abs, 0, &flag_abs_azimuth[ch], NULL ); } ELSE { @@ -506,7 +506,7 @@ ivas_error ivas_ism_metadata_enc( idx_angle2_abs = hParamIsm->ele_index[ch]; move16(); } - encode_angle_indices( hBstr, &( hIsmMetaData->position_angle ), hIsmMetaData->last_ism_metadata_flag, ini_frame, idx_angle1_abs, idx_angle2_abs, &flag_abs_azimuth[ch], &flag_abs_elevation[ch] ); + encode_angle_indices_fx( hBstr, &( hIsmMetaData->position_angle ), hIsmMetaData->last_ism_metadata_flag, ini_frame, idx_angle1_abs, idx_angle2_abs, &flag_abs_azimuth[ch], &flag_abs_elevation[ch] ); /*----------------------------------------------------------------* * Quantize and encode radius, yaw, and pitch *----------------------------------------------------------------*/ @@ -520,8 +520,8 @@ ivas_error ivas_ism_metadata_enc( idx_radius_abs = usquant_fx( hIsmMetaData->radius_fx, &valQ_fx_tmp, ISM_RADIUS_MIN_Q9, ISM_RADIUS_DELTA_Q8, 1 << ISM_RADIUS_NBITS ); valQ_fx = L_shr( L_deposit_h( valQ_fx_tmp ), 3 ); // Q22 // valQ = fixedToFloat( valQ_fx, Q22 ); - encode_angle_indices( hBstr, &( hIsmMetaData->orientation_angle ), hIsmMetaData->last_ism_metadata_flag, ini_frame, idx_angle1_abs, idx_angle2_abs, &flag_abs_yaw[ch], &flag_abs_pitch[ch] ); - encode_radius( hBstr, &hIsmMetaData->last_radius_idx, &hIsmMetaData->radius_diff_cnt, hIsmMetaData->last_ism_metadata_flag, idx_radius_abs, &flag_abs_radius[ch] ); + encode_angle_indices_fx( hBstr, &( hIsmMetaData->orientation_angle ), hIsmMetaData->last_ism_metadata_flag, ini_frame, idx_angle1_abs, idx_angle2_abs, &flag_abs_yaw[ch], &flag_abs_pitch[ch] ); + encode_radius_fx( hBstr, &hIsmMetaData->last_radius_idx, &hIsmMetaData->radius_diff_cnt, hIsmMetaData->last_ism_metadata_flag, idx_radius_abs, &flag_abs_radius[ch] ); } } @@ -536,11 +536,11 @@ ivas_error ivas_ism_metadata_enc( } /* Updates */ - hIsmMeta[ch]->last_true_azimuth_fx = hIsmMeta[ch]->azimuth_fx; + hIsmMeta[ch]->last_true_azimuth_fx = hIsmMeta[ch]->azimuth_fx; // Q22 move32(); - hIsmMeta[ch]->last_true_elevation_fx = hIsmMeta[ch]->elevation_fx; + hIsmMeta[ch]->last_true_elevation_fx = hIsmMeta[ch]->elevation_fx; // Q22 move32(); - hIsmMeta[ch]->last_true_radius_fx = hIsmMeta[ch]->radius_fx; + hIsmMeta[ch]->last_true_radius_fx = hIsmMeta[ch]->radius_fx; // Q22 move16(); } } @@ -553,7 +553,7 @@ ivas_error ivas_ism_metadata_enc( i = 0; move16(); test(); - WHILE( i == 0 || i < idiv1616( nchan_ism, INTER_OBJECT_PARAM_CHECK ) ) + WHILE( i == 0 || i < ( nchan_ism / INTER_OBJECT_PARAM_CHECK ) ) { Word16 num, abs_num, abs_first, abs_next, pos_zero; Word16 abs_matrice[INTER_OBJECT_PARAM_CHECK * ISM_NUM_PARAM]; @@ -581,7 +581,7 @@ ivas_error ivas_ism_metadata_enc( abs_first = 0; move16(); - WHILE( GT_16( abs_num, 1 ) ) + WHILE( abs_num > 1 ) { /* find first "1" entry */ WHILE( abs_matrice[abs_first] == 0 ) @@ -599,7 +599,7 @@ ivas_error ivas_ism_metadata_enc( /* find "0" position */ pos_zero = 0; move16(); - WHILE( EQ_16( abs_matrice[pos_zero], 1 ) ) + WHILE( abs_matrice[pos_zero] == 1 ) { pos_zero = add( pos_zero, 1 ); } @@ -612,7 +612,7 @@ ivas_error ivas_ism_metadata_enc( move16(); } - IF( abs_next % ISM_NUM_PARAM == 1 ) + IF( EQ_16( abs_next % ISM_NUM_PARAM, 1 ) ) { hIsmMeta[ch]->position_angle.angle2_diff_cnt = sub( abs_num, 1 ); move16(); @@ -869,7 +869,7 @@ ivas_error ivas_ism_metadata_enc( * Create, allocate, initialize and configure IVAS encoder ISM metadata handles *-------------------------------------------------------------------------*/ -ivas_error ivas_ism_metadata_enc_create( +ivas_error ivas_ism_metadata_enc_create_fx( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const Word16 n_ISms, /* i : number of objects */ Word32 element_brate_tmp[] /* o : element bitrate per object */ @@ -976,21 +976,21 @@ ivas_error ivas_ism_metadata_enc_create( ivas_ism_reset_metadata_enc( st_ivas->hIsmMetaData[ch] ); - st_ivas->hIsmMetaData[ch]->last_azimuth_fx = 0; + st_ivas->hIsmMetaData[ch]->last_azimuth_fx = 0; // Q22 move32(); - st_ivas->hIsmMetaData[ch]->last_elevation_fx = 0; + st_ivas->hIsmMetaData[ch]->last_elevation_fx = 0; // Q22 move32(); - st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx = 0; + st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx = 0; // Q22 move32(); - st_ivas->hIsmMetaData[ch]->last_true_elevation_fx = 0; + st_ivas->hIsmMetaData[ch]->last_true_elevation_fx = 0; // Q22 move32(); st_ivas->hIsmMetaData[ch]->ism_md_fec_cnt_enc = 0; move16(); st_ivas->hIsmMetaData[ch]->ism_md_inc_diff_cnt = ISM_MD_INC_DIFF_CNT_MAX; move16(); - st_ivas->hIsmMetaData[ch]->last_true_radius_fx = ONE_IN_Q9; + st_ivas->hIsmMetaData[ch]->last_true_radius_fx = ONE_IN_Q9; // Q9 move16(); } @@ -1028,7 +1028,7 @@ ivas_error ivas_ism_metadata_enc_create( * * Radius index encoding *-------------------------------------------------------------------------*/ -static void encode_radius( +static void encode_radius_fx( BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ Word16 *last_radius_idx, /* i/o: last radius index */ Word16 *radius_diff_cnt, /* i/o: radius diff coding counter */ @@ -1143,7 +1143,7 @@ static void encode_radius( * Encoding of an angle *----------------------------------------------------------------*/ -static void encode_angle_indices( +static void encode_angle_indices_fx( BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ ISM_METADATA_ANGLE_HANDLE angle, /* i/o: angle handle */ const Word16 last_ism_metadata_flag, /* i : last frame ism_metadata_flag */ @@ -1168,8 +1168,8 @@ static void encode_angle_indices( move16(); *flag_abs_angle1 = 0; /* differential coding by default */ test(); - if ( EQ_16( angle->angle1_diff_cnt, ISM_FEC_MAX ) /* make differential encoding in ISM_FEC_MAX consecutive frames at maximum (in order to control the decoding in FEC) */ - || last_ism_metadata_flag == 0 /* If last frame had no metadata coded, do not use differential coding */ + IF( EQ_16( angle->angle1_diff_cnt, ISM_FEC_MAX ) /* make differential encoding in ISM_FEC_MAX consecutive frames at maximum (in order to control the decoding in FEC) */ + || last_ism_metadata_flag == 0 /* If last frame had no metadata coded, do not use differential coding */ ) { *flag_abs_angle1 = 1; @@ -1418,7 +1418,7 @@ static void encode_angle_indices( * Quantize and encode ISM metadata in SID frame *-------------------------------------------------------------------*/ -void ivas_ism_metadata_sid_enc( +void ivas_ism_metadata_sid_enc_fx( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ const Word16 flag_noisy_speech, /* i : noisy speech flag */ const Word16 nchan_ism, /* i : number of objects */ diff --git a/lib_enc/ivas_ism_param_enc.c b/lib_enc/ivas_ism_param_enc.c index 7214e6f2f..3169962f5 100644 --- a/lib_enc/ivas_ism_param_enc.c +++ b/lib_enc/ivas_ism_param_enc.c @@ -180,7 +180,7 @@ static void ivas_param_ism_compute_obj_parameters_fx( tmp1 = W_norm( ref_power_local_frame[0] ); tmp2 = W_norm( ref_power_local_frame[i] ); tmp_ratio = BASOP_Util_Divide3232_Scale( W_extract_h( W_shl( ref_power_local_frame[0], tmp1 ) ), W_extract_h( W_shl( ref_power_local_frame[i], tmp2 ) ), &e_tmp ); // ((Qx + tmp1) - 16) - ((Qx + tmp2) - 16) + 15 - e_tmp = 15 + tmp1 - tmp2 - e_tmp - tmp_ratio = W_shl( tmp_ratio, sub( sub( e_tmp, 1 ), sub( tmp1, tmp2 ) ) ); // Q14 + tmp_ratio = W_shl( tmp_ratio, sub( sub( e_tmp, 1 ), sub( tmp1, tmp2 ) ) ); // Q14 // Q14 test(); IF( GT_64( tmp_ratio, 15974 /* 0.975f in Q14 */ ) && LT_64( tmp_ratio, 16794 /* 1.025f in Q14*/ ) ) @@ -220,7 +220,7 @@ static void ivas_param_ism_enc_quantize_DOA_fx( azi_idx = ism_quant_meta_fx( hIsmMetaData[i]->azimuth_fx, &valQ_fx, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); /*Replace azimuth with quantized values */ - hIsmMetaData[i]->azimuth_fx = valQ_fx; + hIsmMetaData[i]->azimuth_fx = valQ_fx; // Q22 move32(); /* Copy the quantized indices */ @@ -312,17 +312,17 @@ void ivas_param_ism_stereo_dmx_fx( cardioid_right[i] = sub( ONE_IN_Q14 /* 1.0f in Q14 */, cardioid_left[i] ); /* corresponds to: alpha + ( 1 - alpha ) * cosf( tmp + tmp_1 ); */ move16(); /* Loop over all samples */ - FOR( j = 0; j < shr( input_frame, 1 ); j++ ) + FOR( j = 0; j < input_frame >> 1; j++ ) { tmp = data[i][j]; move32(); - tmp = W_extract_l( W_shr( W_mult_32_16( tmp, add( last_cardioid_left, mult0( j, grad ) ) ), 15 ) ); - stereo_dmx[0][j] = L_add( stereo_dmx[0][j], tmp ); /* Qx DMX Left */ + tmp = W_extract_l( W_shr( W_mult_32_16( tmp, add( last_cardioid_left, mult0( j, grad ) ) ), 15 ) ); /* Qx DMX Left */ + stereo_dmx[0][j] = L_add( stereo_dmx[0][j], tmp ); /* Qx DMX Left */ move32(); tmp = data[i][j]; move32(); - tmp = W_extract_l( W_shr( W_mult_32_16( tmp, add( last_cardioid_right, negate( mult0( j, grad ) ) ) ), 15 ) ); - stereo_dmx[1][j] = L_add( stereo_dmx[1][j], tmp ); /* Qx DMX Right */ + tmp = W_extract_l( W_shr( W_mult_32_16( tmp, add( last_cardioid_right, negate( mult0( j, grad ) ) ) ), 15 ) ); /* Qx DMX Right */ + stereo_dmx[1][j] = L_add( stereo_dmx[1][j], tmp ); /* Qx DMX Right */ move32(); ene_data = W_add( ene_data, W_mult_32_32( data[i][j], data[i][j] ) ); /* 2 * Qx + 1 energy of all objects combined */ } @@ -330,13 +330,13 @@ void ivas_param_ism_stereo_dmx_fx( { tmp = data[i][j]; move32(); - tmp = W_extract_l( W_shr( W_mult_32_16( tmp, cardioid_left[i] ), 15 ) ); - stereo_dmx[0][j] = L_add( stereo_dmx[0][j], tmp ); /* Qx DMX Left */ + tmp = W_extract_l( W_shr( W_mult_32_16( tmp, cardioid_left[i] ), 15 ) ); /* Qx DMX Left */ + stereo_dmx[0][j] = L_add( stereo_dmx[0][j], tmp ); /* Qx DMX Left */ move32(); tmp = data[i][j]; move32(); - tmp = W_extract_l( W_shr( W_mult_32_16( tmp, cardioid_right[i] ), 15 ) ); - stereo_dmx[1][j] = L_add( stereo_dmx[1][j], tmp ); /* Qx DMX Right */ + tmp = W_extract_l( W_shr( W_mult_32_16( tmp, cardioid_right[i] ), 15 ) ); /* Qx DMX Right */ + stereo_dmx[1][j] = L_add( stereo_dmx[1][j], tmp ); /* Qx DMX Right */ move32(); ene_data = W_add( ene_data, W_mult_32_32( data[i][j], data[i][j] ) ); /* 2 * Qx + 1 energy of all objects combined */ } @@ -351,18 +351,18 @@ void ivas_param_ism_stereo_dmx_fx( { tmp = data[i][j]; move32(); - tmp = W_extract_l( W_shr( W_mult_32_16( tmp, cardioid_left[i] ), 15 ) ); - stereo_dmx[0][j] = L_add( stereo_dmx[0][j], tmp ); /* Qx DMX Left */ + tmp = W_extract_l( W_shr( W_mult_32_16( tmp, cardioid_left[i] ), 15 ) ); /* Qx DMX Left */ + stereo_dmx[0][j] = L_add( stereo_dmx[0][j], tmp ); /* Qx DMX Left */ move32(); tmp = data[i][j]; move32(); - tmp = W_extract_l( W_shr( W_mult_32_16( tmp, cardioid_right[i] ), 15 ) ); - stereo_dmx[1][j] = L_add( stereo_dmx[1][j], tmp ); /* Qx DMX Right */ + tmp = W_extract_l( W_shr( W_mult_32_16( tmp, cardioid_right[i] ), 15 ) ); /* Qx DMX Right */ + stereo_dmx[1][j] = L_add( stereo_dmx[1][j], tmp ); /* Qx DMX Right */ move32(); ene_data = W_add( ene_data, W_mult_32_32( data[i][j], data[i][j] ) ); /* 2 * Qx + 1 energy of all objects combined */ } } - st_ivas->hParamIsm->last_cardioid_left_fx[i] = cardioid_left[i]; + st_ivas->hParamIsm->last_cardioid_left_fx[i] = cardioid_left[i]; // Q14 move16(); } @@ -389,7 +389,7 @@ void ivas_param_ism_stereo_dmx_fx( tmp_1 = 15 + 1; move16(); - FOR( i = 0; i < shr( input_frame, 1 ); i++ ) + FOR( i = 0; i < input_frame >> 1; i++ ) { stereo_dmx[0][i] = W_extract_l( W_shr( W_mult_32_32( stereo_dmx[0][i], L_add( tmp, mult0( i, grad ) ) ), tmp_1 ) ); // Qx move32(); @@ -437,7 +437,7 @@ void ivas_param_ism_stereo_dmx_fx( * Open Param ISM handle *-------------------------------------------------------------------------*/ -ivas_error ivas_param_ism_enc_open( +ivas_error ivas_param_ism_enc_open_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { @@ -479,7 +479,7 @@ ivas_error ivas_param_ism_enc_open( hParamIsm->nbands = MAX_PARAM_ISM_NBANDS; move16(); - max_bins = extract_l( Mpy_32_32( input_Fs, 10737418 ) ); // (int16_t) ( ( MDFT_FB_BANDS_240 * input_Fs ) / 48000 ); + max_bins = extract_l( Mpy_32_32( input_Fs, 10737418 /*240/48000.Q31*/ ) ); // (int16_t) ( ( MDFT_FB_BANDS_240 * input_Fs ) / 48000 ); FOR( i = 0; i < ( hParamIsm->nbands + 1 ); i++ ) { hParamIsm->band_grouping[i] = CLDFB_TO_MDFT_FAC * Param_ISM_band_grouping[i]; @@ -505,7 +505,7 @@ ivas_error ivas_param_ism_enc_open( * Close Param ISM encoder handle *-------------------------------------------------------------------------*/ -void ivas_param_ism_enc_close( +void ivas_param_ism_enc_close_fx( PARAM_ISM_CONFIG_HANDLE *hParamIsm, /* i/o: ParamISM handle */ const Word32 input_Fs /* i : input sampling_rate */ ) @@ -604,7 +604,7 @@ void ivas_param_ism_enc_fx( * *-------------------------------------------------------------------*/ -void ivas_param_ism_compute_noisy_speech_flag( +void ivas_param_ism_compute_noisy_speech_flag_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { diff --git a/lib_enc/ivas_lfe_enc.c b/lib_enc/ivas_lfe_enc.c index 6a67cd814..e72270e6c 100644 --- a/lib_enc/ivas_lfe_enc.c +++ b/lib_enc/ivas_lfe_enc.c @@ -433,14 +433,14 @@ void ivas_lfe_enc_fx( IF( LT_16( q_data_lfe_ch, hLFE->q_old_wtda_audio ) ) { - Scale_sig32( hLFE->old_wtda_audio_fx, fade_len, sub( q_data_lfe_ch, hLFE->q_old_wtda_audio ) ); + Scale_sig32( hLFE->old_wtda_audio_fx, fade_len, sub( q_data_lfe_ch, hLFE->q_old_wtda_audio ) ); // hLFE->q_old_wtda_audio hLFE->q_old_wtda_audio = q_data_lfe_ch; move16(); } IF( GT_16( q_data_lfe_ch, hLFE->q_old_wtda_audio ) ) { - Scale_sig32( data_lfe_ch, input_frame, sub( hLFE->q_old_wtda_audio, q_data_lfe_ch ) ); + Scale_sig32( data_lfe_ch, input_frame, sub( hLFE->q_old_wtda_audio, q_data_lfe_ch ) ); // hLFE->q_old_wtda_audio; q_data_lfe_ch = hLFE->q_old_wtda_audio; move16(); } @@ -451,7 +451,7 @@ void ivas_lfe_enc_fx( q_out1 = Find_Max_Norm32( wtda_audio_fx, input_frame ); q_out1 = sub( q_out1, find_guarded_bits_fx( dct_len ) ); - Scale_sig32( wtda_audio_fx, input_frame, q_out1 ); + Scale_sig32( wtda_audio_fx, input_frame, q_out1 ); // Q10 + q_out1 q_out1 = add( q_data_lfe_ch, q_out1 ); ivas_mdct_fx( wtda_audio_fx, t_audio_fx, dct_len, &q_out1 ); @@ -464,7 +464,7 @@ void ivas_lfe_enc_fx( /* mdct */ q_out2 = Find_Max_Norm32( wtda_audio_fx, input_frame ); q_out2 = sub( q_out2, find_guarded_bits_fx( dct_len ) ); - Scale_sig32( wtda_audio_fx, input_frame, q_out2 ); + Scale_sig32( wtda_audio_fx, input_frame, q_out2 ); // Q10 + q_out2 q_out2 = add( q_data_lfe_ch, q_out2 ); ivas_mdct_fx( wtda_audio_fx, t_audio_fx, dct_len, &q_out2 ); @@ -479,7 +479,7 @@ void ivas_lfe_enc_fx( q_out2 = add( q_out2, min( q_tmp2, sub( q_out1, q_out2 ) ) ); IF( GT_16( q_out1, q_out2 ) ) { - Scale_sig32( lfe_dct_fx, num_dct_pass_bins, sub( q_out2, q_out1 ) ); + Scale_sig32( lfe_dct_fx, num_dct_pass_bins, sub( q_out2, q_out1 ) ); // q_out2 q_out1 = q_out2; move16(); } @@ -490,7 +490,7 @@ void ivas_lfe_enc_fx( q_out1 = add( q_out1, min( q_tmp1, sub( q_out2, q_out1 ) ) ); IF( LT_16( q_out1, q_out2 ) ) { - Scale_sig32( lfe_dct_fx + num_dct_pass_bins, num_dct_pass_bins, sub( q_out1, q_out2 ) ); + Scale_sig32( lfe_dct_fx + num_dct_pass_bins, num_dct_pass_bins, sub( q_out1, q_out2 ) ); // q_out1 q_out1 = q_out2; move16(); } @@ -507,7 +507,7 @@ void ivas_lfe_enc_fx( * * Create, allocate and initialize IVAS encoder LFE handle *-------------------------------------------------------------------------*/ -ivas_error ivas_create_lfe_enc( +ivas_error ivas_create_lfe_enc_fx( LFE_ENC_HANDLE *hLFE_out, /* o : IVAS LFE encoder structure */ const Word32 input_Fs /* i : input sampling rate */ ) @@ -575,7 +575,7 @@ ivas_error ivas_create_lfe_enc( // hLFE->lfe_enc_indices_coeffs_tbl[i][j] = // (int16_t) ceilf( log2f( (float) ( ivas_lfe_num_ele_in_coder_models[i][j] + 1 ) ) ); hLFE->lfe_enc_indices_coeffs_tbl[i][j] = - floor_log_2( add( ivas_lfe_num_ele_in_coder_models[i][j], 1 ) ); + floor_log_2( add( ivas_lfe_num_ele_in_coder_models[i][j], 1 ) ); // Q0 move16(); } } @@ -590,7 +590,7 @@ ivas_error ivas_create_lfe_enc( * * Destroy IVAS cncoder LFE handle *-------------------------------------------------------------------------*/ -void ivas_lfe_enc_close( +void ivas_lfe_enc_close_fx( LFE_ENC_HANDLE *hLFE /* i/o: LFE encoder handle */ ) { @@ -628,7 +628,7 @@ ivas_error ivas_create_lfe_lpf_enc_fx( const Word32 input_Fs /* i : input sampling rate */ ) { - const Word32 *filt_coeff; + const Word32 *filt_coeff; // 31 - filt_coeff_e const Word16 *filt_coeff_e = NULL; IF( hLfeLpf == NULL ) @@ -657,7 +657,7 @@ ivas_error ivas_create_lfe_lpf_enc_fx( * * Destroy IVAS cncoder LFE low pass filter state *-------------------------------------------------------------------------*/ -void ivas_lfe_lpf_enc_close( +void ivas_lfe_lpf_enc_close_fx( ivas_filters_process_state_t **hLfeLpf /* i/o: LFE LPF handle */ ) { @@ -681,7 +681,7 @@ void ivas_lfe_lpf_enc_close( *-------------------------------------------------------------------------*/ void ivas_lfe_lpf_enc_apply_fx( ivas_filters_process_state_t *hLfeLpf, /* i/o: LFE LPF handle */ - Word32 data_lfe_ch[], /* i/o: LFE signal */ + Word32 data_lfe_ch[], /* i/o: LFE signal Q11*/ const Word16 input_frame /* i : input frame length per channel */ ) { diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index abf709442..d79d83ec9 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -118,7 +118,7 @@ static void masa_metadata_direction_alignment_fx( MASA_ENCODER_HANDLE hMasa ); * * open and initialize MASA encoder *-----------------------------------------------------------------------*/ -ivas_error ivas_masa_enc_open( +ivas_error ivas_masa_enc_open_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ) { @@ -179,16 +179,16 @@ ivas_error ivas_masa_enc_open( Copy( DirAC_block_grouping, hMasa->config.block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); Copy( MASA_band_grouping_24, hMasa->config.band_grouping, MASA_FREQUENCY_BANDS + 1 ); - hMasa->data.onset_detector_1_fx = 0; - hMasa->data.onset_detector_2_fx = 0; + hMasa->data.onset_detector_1_fx = 0; // hMasa->data.q_onset_detector + hMasa->data.onset_detector_2_fx = 0; // hMasa->data.q_onset_detector hMasa->data.q_onset_detector = 0; move32(); move32(); move16(); - set32_fx( hMasa->data.lfeToTotalEnergyRatio_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); + set32_fx( hMasa->data.lfeToTotalEnergyRatio_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); // hMasa->data.lfeToTotalEnergyRatio_e set16_fx( hMasa->data.lfeToTotalEnergyRatio_e, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); - hMasa->data.prevq_lfeToTotalEnergyRatio_fx = 0; + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = 0; // Q31 move32(); hMasa->data.prevq_lfeIndex = 0; @@ -201,10 +201,10 @@ ivas_error ivas_masa_enc_open( move16(); move32(); - set_zero_fx( hMasa->data.dir_align_state.previous_azi_dir1_fx, MASA_FREQUENCY_BANDS ); - set_zero_fx( hMasa->data.dir_align_state.previous_ele_dir1_fx, MASA_FREQUENCY_BANDS ); - set_zero_fx( hMasa->data.dir_align_state.previous_azi_dir2_fx, MASA_FREQUENCY_BANDS ); - set_zero_fx( hMasa->data.dir_align_state.previous_ele_dir2_fx, MASA_FREQUENCY_BANDS ); + set_zero_fx( hMasa->data.dir_align_state.previous_azi_dir1_fx, MASA_FREQUENCY_BANDS ); // Q22 + set_zero_fx( hMasa->data.dir_align_state.previous_ele_dir1_fx, MASA_FREQUENCY_BANDS ); // Q22 + set_zero_fx( hMasa->data.dir_align_state.previous_azi_dir2_fx, MASA_FREQUENCY_BANDS ); // Q22 + set_zero_fx( hMasa->data.dir_align_state.previous_ele_dir2_fx, MASA_FREQUENCY_BANDS ); // Q22 IF( EQ_32( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { @@ -217,7 +217,7 @@ ivas_error ivas_masa_enc_open( FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - set32_fx( hOmasaData->masa_to_total_energy_ratio_fx[i], 0, MASA_FREQUENCY_BANDS ); + set32_fx( hOmasaData->masa_to_total_energy_ratio_fx[i], 0, MASA_FREQUENCY_BANDS ); // Q30 } hOmasaData->lp_noise_CPE_fx = -256; /* -1 in Q8 */ @@ -227,7 +227,7 @@ ivas_error ivas_masa_enc_open( FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - set_zero_fx( hOmasaData->energy_ism_fx[i], MASA_FREQUENCY_BANDS ); + set_zero_fx( hOmasaData->energy_ism_fx[i], MASA_FREQUENCY_BANDS ); // hOmasaData->energy_ism_fx_e set16_fx( hOmasaData->energy_ism_fx_e[i], 0, MASA_FREQUENCY_BANDS ); } @@ -248,7 +248,7 @@ ivas_error ivas_masa_enc_open( * * close MASA encoder *-----------------------------------------------------------------------*/ -void ivas_masa_enc_close( +void ivas_masa_enc_close_fx( MASA_ENCODER_HANDLE *hMasa /* i/o: MASA metadata structure */ ) { @@ -322,7 +322,6 @@ ivas_error ivas_masa_encode_fx( IF( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { /* Create the MASA SID descriptor for the metadata and CPE mode, in order to have the SID frame self-contained. */ - test(); IF( Opt_DTX_ON && hQMetaData != NULL ) { IF( EQ_16( nchan_transport, 2 ) ) /* this is MASA format in CPE only */ @@ -351,9 +350,9 @@ ivas_error ivas_masa_encode_fx( { FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - Copy32( hMasa->masaMetadata.directional_meta[i].azimuth_fx[j], h_orig_metadata[i].azimuth_fx[j], MASA_FREQUENCY_BANDS ); - Copy32( hMasa->masaMetadata.directional_meta[i].elevation_fx[j], h_orig_metadata[i].elevation_fx[j], MASA_FREQUENCY_BANDS ); - Copy32( hMasa->masaMetadata.directional_meta[i].energy_ratio_fx[j], h_orig_metadata[i].energy_ratio_fx[j], MASA_FREQUENCY_BANDS ); + Copy32( hMasa->masaMetadata.directional_meta[i].azimuth_fx[j], h_orig_metadata[i].azimuth_fx[j], MASA_FREQUENCY_BANDS ); // Q22 + Copy32( hMasa->masaMetadata.directional_meta[i].elevation_fx[j], h_orig_metadata[i].elevation_fx[j], MASA_FREQUENCY_BANDS ); // Q22 + Copy32( hMasa->masaMetadata.directional_meta[i].energy_ratio_fx[j], h_orig_metadata[i].energy_ratio_fx[j], MASA_FREQUENCY_BANDS ); // Q30 Copy( (Word16 *) ( hMasa->masaMetadata.directional_meta[i].spherical_index[j] ), (Word16 *) ( h_orig_metadata[i].spherical_index[j] ), MASA_FREQUENCY_BANDS ); } } @@ -384,7 +383,7 @@ ivas_error ivas_masa_encode_fx( { FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - hMasa->data.energy_fx[i][j] = L_shr( hMasa->data.energy_fx[i][j], sub( s, hMasa->data.energy_e[i][j] ) ); + hMasa->data.energy_fx[i][j] = L_shr( hMasa->data.energy_fx[i][j], sub( s, hMasa->data.energy_e[i][j] ) ); // hMasa->data.energy_e[i][j] -> s hMasa->data.energy_e[i][j] = s; move32(); move16(); @@ -700,9 +699,9 @@ ivas_error ivas_masa_encode_fx( { FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - Copy32( h_orig_metadata[i].azimuth_fx[j], hMasa->masaMetadata.directional_meta[i].azimuth_fx[j], MASA_FREQUENCY_BANDS ); - Copy32( h_orig_metadata[i].elevation_fx[j], hMasa->masaMetadata.directional_meta[i].elevation_fx[j], MASA_FREQUENCY_BANDS ); - Copy32( h_orig_metadata[i].energy_ratio_fx[j], hMasa->masaMetadata.directional_meta[i].energy_ratio_fx[j], MASA_FREQUENCY_BANDS ); + Copy32( h_orig_metadata[i].azimuth_fx[j], hMasa->masaMetadata.directional_meta[i].azimuth_fx[j], MASA_FREQUENCY_BANDS ); // Q22 + Copy32( h_orig_metadata[i].elevation_fx[j], hMasa->masaMetadata.directional_meta[i].elevation_fx[j], MASA_FREQUENCY_BANDS ); // Q22 + Copy32( h_orig_metadata[i].energy_ratio_fx[j], hMasa->masaMetadata.directional_meta[i].energy_ratio_fx[j], MASA_FREQUENCY_BANDS ); // Q30 } } @@ -1105,7 +1104,7 @@ ivas_error ivas_masa_enc_config_fx( maxBand = 0; move16(); test(); - WHILE( LE_16( maxBand, MASA_FREQUENCY_BANDS ) && LE_16( MASA_band_grouping_24[maxBand], maxBin ) ) + WHILE( ( maxBand <= MASA_FREQUENCY_BANDS ) && ( MASA_band_grouping_24[maxBand] <= maxBin ) ) { test(); maxBand = (UWord8) add( maxBand, 1 ); @@ -1131,7 +1130,7 @@ ivas_error ivas_masa_enc_config_fx( continueLoop = 1; move16(); test(); - WHILE( GT_16( maxBand, 5 ) && continueLoop ) + WHILE( ( maxBand > 5 ) && continueLoop ) { test(); FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) @@ -1203,7 +1202,8 @@ ivas_error ivas_masa_enc_config_fx( } ELSE { - st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = shr( add( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise_fx, st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise_fx ), 1 ); /*Q8*/ + /* ( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise + st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise ) / CPE_CHANNELS; */ + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = extract_h( L_mac( L_mult( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise_fx, ONE_IN_Q14 ), st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise_fx, ONE_IN_Q14 ) ); /*Q8*/ } move16(); } @@ -1519,7 +1519,7 @@ static void combine_freqbands_and_subframes_fx( } } - if ( i == 0 ) + IF( i == 0 ) { energy[j][k] = energySum; // 31-energySum_e energy_e[j][k] = energySum_e; @@ -1887,7 +1887,7 @@ void ivas_masa_combine_directions_fx( } static void find_n_largest_fx( - const Word32 *input_fx, + const Word32 *input_fx, // Q(31 - exp_input) Word16 exp_input, Word16 *largestIndices, const Word16 numElements, @@ -1900,13 +1900,13 @@ static void find_n_largest_fx( FOR( j = 0; j < numElements; j++ ) { - values[j] = input_fx[j]; + values[j] = input_fx[j]; // Q(31 - exp_input) move32(); } FOR( i = 0; i < numLargest; i++ ) { - largestValue = values[0]; + largestValue = values[0]; // Q(31 - exp_input) move32(); largestIndex = 0; move16(); @@ -1914,7 +1914,7 @@ static void find_n_largest_fx( { IF( GT_32( values[j], largestValue ) ) { - largestValue = values[j]; + largestValue = values[j]; // Q(31 - exp_input) largestIndex = j; move32(); move16(); @@ -1924,12 +1924,12 @@ static void find_n_largest_fx( move16(); IF( exp_input != 0 ) { - values[largestIndex] = L_negate( 1 << ( sub( 31, exp_input ) ) ); + values[largestIndex] = L_negate( 1 << ( sub( 31, exp_input ) ) ); // Q(31 - exp_input) move32(); } ELSE { - values[largestIndex] = 1 << ( sub( 31, exp_input ) ); + values[largestIndex] = 1 << ( sub( 31, exp_input ) ); // Q(31 - exp_input) move32(); } } @@ -1966,9 +1966,9 @@ static void move_metadata_to_qmetadata_fx( { FOR( band = 0; band < numCodingBands; band++ ) { - hQMeta->q_direction[dir].band_data[band].azimuth_fx[sf] = hMeta->directional_meta[dir].azimuth_fx[sf][band]; - hQMeta->q_direction[dir].band_data[band].elevation_fx[sf] = hMeta->directional_meta[dir].elevation_fx[sf][band]; - hQMeta->q_direction[dir].band_data[band].energy_ratio_fx[sf] = hMeta->directional_meta[dir].energy_ratio_fx[sf][band]; + hQMeta->q_direction[dir].band_data[band].azimuth_fx[sf] = hMeta->directional_meta[dir].azimuth_fx[sf][band]; // Q22 + hQMeta->q_direction[dir].band_data[band].elevation_fx[sf] = hMeta->directional_meta[dir].elevation_fx[sf][band]; // Q22 + hQMeta->q_direction[dir].band_data[band].energy_ratio_fx[sf] = hMeta->directional_meta[dir].energy_ratio_fx[sf][band]; // Q30 hQMeta->q_direction[dir].band_data[band].spherical_index[sf] = hMeta->directional_meta[dir].spherical_index[sf][band]; move32(); move32(); @@ -1977,7 +1977,7 @@ static void move_metadata_to_qmetadata_fx( IF( hQMeta->q_direction[dir].coherence_band_data != NULL ) { - hQMeta->q_direction[dir].coherence_band_data[band].spread_coherence[sf] = (UWord8) mult_r( hMeta->directional_meta[dir].spread_coherence_fx[sf][band], UINT8_MAX ); + hQMeta->q_direction[dir].coherence_band_data[band].spread_coherence[sf] = (UWord8) mult_r( hMeta->directional_meta[dir].spread_coherence_fx[sf][band], UINT8_MAX ); // Q15 move16(); } } @@ -1990,7 +1990,7 @@ static void move_metadata_to_qmetadata_fx( { IF( hQMeta->surcoh_band_data != NULL ) { - hQMeta->surcoh_band_data[band].surround_coherence[sf] = (UWord8) mult_r( hMeta->common_meta.surround_coherence_fx[sf][band], UINT8_MAX ); + hQMeta->surcoh_band_data[band].surround_coherence[sf] = (UWord8) mult_r( hMeta->common_meta.surround_coherence_fx[sf][band], UINT8_MAX ); // Q15 move16(); } } @@ -2072,12 +2072,12 @@ static void detect_metadata_composition_fx( { sf = 0; move16(); - WHILE( !dirValid[dir] && LT_16( sf, MAX_PARAM_SPATIAL_SUBFRAMES ) ) + WHILE( !dirValid[dir] && ( sf < MAX_PARAM_SPATIAL_SUBFRAMES ) ) { test(); band = 0; move16(); - WHILE( !dirValid[dir] && LT_16( band, MASA_FREQUENCY_BANDS ) ) + WHILE( !dirValid[dir] && ( band < MASA_FREQUENCY_BANDS ) ) { test(); IF( GE_32( hMeta->directional_meta[dir].energy_ratio_fx[sf][band] /*q30*/, MASA_RATIO_THRESHOLD_FX >> 1 /*q30*/ ) ) @@ -2119,7 +2119,7 @@ static void detect_metadata_composition_fx( } } - IF( *isTwoDir == FALSE ) + if ( *isTwoDir == FALSE ) { /* Further checks will be done with just one direction */ numDir = 1; @@ -2132,9 +2132,10 @@ static void detect_metadata_composition_fx( sf = 1; move16(); move16(); - WHILE( EQ_16( sfSimilar, TRUE ) && LT_16( sf, MAX_PARAM_SPATIAL_SUBFRAMES ) ) + + test(); + WHILE( ( sfSimilar == TRUE ) && ( sf < MAX_PARAM_SPATIAL_SUBFRAMES ) ) { - test(); sfSimilar = are_masa_subframes_similar_fx( hMeta, 0, hMeta, sf ); sf = (Word8) add( sf, 1 ); move16(); @@ -2155,19 +2156,19 @@ static void detect_metadata_composition_fx( /* Check spread coherence */ dir = 0; move16(); - WHILE( cohPresent == FALSE && LT_16( dir, numDir ) ) + test(); + WHILE( cohPresent == FALSE && ( dir < numDir ) ) { - test(); sf = 0; move16(); - WHILE( cohPresent == FALSE && LT_16( sf, nSubFrames ) ) + test(); + WHILE( cohPresent == FALSE && ( sf < nSubFrames ) ) { - test(); band = 0; move16(); - WHILE( cohPresent == FALSE /*has value zero*/ && LT_16( band, MASA_FREQUENCY_BANDS ) ) + test(); + WHILE( cohPresent == FALSE /*has value zero*/ && ( band < MASA_FREQUENCY_BANDS ) ) { - test(); /* Check coherences for presence of coherence */ IF( GT_16( hMeta->directional_meta[dir].spread_coherence_fx[sf][band] /*Q15*/, MASA_COHERENCE_THRESHOLD_FX >> 16 ) ) /*Q15*/ { @@ -2563,7 +2564,7 @@ static void reduce_metadata_further_fx( { FOR( band = 0; band < numCodingBands; band++ ) { - hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[0]; + hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[0]; // Q0 move16(); } } @@ -2582,18 +2583,18 @@ static void reduce_metadata_further_fx( /* Use the selected frequency band to represent all data */ FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - hqmetadata->q_direction[0].band_data[0].azimuth_fx[sf] = hqmetadata->q_direction[0].band_data[selectedBand].azimuth_fx[sf]; - hqmetadata->q_direction[0].band_data[0].elevation_fx[sf] = hqmetadata->q_direction[0].band_data[selectedBand].elevation_fx[sf]; - hqmetadata->q_direction[0].band_data[0].energy_ratio_fx[sf] = hqmetadata->q_direction[0].band_data[selectedBand].energy_ratio_fx[sf]; + hqmetadata->q_direction[0].band_data[0].azimuth_fx[sf] = hqmetadata->q_direction[0].band_data[selectedBand].azimuth_fx[sf]; // Q22 + hqmetadata->q_direction[0].band_data[0].elevation_fx[sf] = hqmetadata->q_direction[0].band_data[selectedBand].elevation_fx[sf]; // Q22 + hqmetadata->q_direction[0].band_data[0].energy_ratio_fx[sf] = hqmetadata->q_direction[0].band_data[selectedBand].energy_ratio_fx[sf]; // Q30 move32(); move32(); move32(); - if ( hqmetadata->q_direction[0].coherence_band_data != NULL ) + IF( hqmetadata->q_direction[0].coherence_band_data != NULL ) { - hqmetadata->q_direction[0].coherence_band_data[0].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[selectedBand].spread_coherence[sf]; + hqmetadata->q_direction[0].coherence_band_data[0].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[selectedBand].spread_coherence[sf]; // Q0 move16(); } - if ( hqmetadata->surcoh_band_data != NULL ) + IF( hqmetadata->surcoh_band_data != NULL ) { hqmetadata->surcoh_band_data[0].surround_coherence[sf] = hqmetadata->surcoh_band_data[selectedBand].surround_coherence[sf]; move16(); @@ -2607,7 +2608,7 @@ static void reduce_metadata_further_fx( { FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[0].spread_coherence[sf]; + hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[0].spread_coherence[sf]; // Q0 move16(); } } @@ -2657,7 +2658,7 @@ static Word16 encode_lfe_to_total_energy_ratio_fx( move16(); /* Determine maximum amount of LFE energy in any subframe */ - maxLFESubFrameEner = 0; + maxLFESubFrameEner = 0; // maxLFESubFrameEner_e move32(); maxLFESubFrameEner_e = 0; move16(); @@ -2665,7 +2666,7 @@ static Word16 encode_lfe_to_total_energy_ratio_fx( { IF( BASOP_Util_Cmp_Mant32Exp( hMasa->data.lfeToTotalEnergyRatio_fx[i], hMasa->data.lfeToTotalEnergyRatio_e[i], maxLFESubFrameEner, maxLFESubFrameEner_e ) > 0 ) { - maxLFESubFrameEner = hMasa->data.lfeToTotalEnergyRatio_fx[i]; + maxLFESubFrameEner = hMasa->data.lfeToTotalEnergyRatio_fx[i]; // hMasa->data.lfeToTotalEnergyRatio_e[i] move32(); maxLFESubFrameEner_e = hMasa->data.lfeToTotalEnergyRatio_e[i]; move16(); @@ -2897,7 +2898,7 @@ void ivas_masa_enc_reconfigure_fx( st_ivas->hCPE[cpe_id]->element_brate = imult3216( tmp_br, 2 ); //( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; move32(); - IF( st_ivas->nCPE > 1 ) + IF( GT_16( st_ivas->nCPE, 1 ) ) { tmp = 1; } @@ -2939,7 +2940,7 @@ void ivas_masa_enc_reconfigure_fx( *-------------------------------------------------------------------*/ static void average_masa_metadata_fx( MASA_METADATA_FRAME *hMeta, - Word32 energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /*i*/ + Word32 energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /*i Q(31 - energy_e) */ Word16 energy_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /*i:stores exponent values for energy_e*/ const SPHERICAL_GRID_DATA *Sph_Grid16, const UWord8 useSphGrid ) @@ -3111,16 +3112,16 @@ static void copy_masa_metadata_subframe_fx( /* directional metadata */ FOR( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ ) { - Copy32( hMetaFrom->directional_meta[dir].azimuth_fx[sfFrom], hMetaTo->directional_meta[dir].azimuth_fx[sfTo], MASA_FREQUENCY_BANDS ); - Copy32( hMetaFrom->directional_meta[dir].elevation_fx[sfFrom], hMetaTo->directional_meta[dir].elevation_fx[sfTo], MASA_FREQUENCY_BANDS ); - Copy32( hMetaFrom->directional_meta[dir].energy_ratio_fx[sfFrom], hMetaTo->directional_meta[dir].energy_ratio_fx[sfTo], MASA_FREQUENCY_BANDS ); - Copy( hMetaFrom->directional_meta[dir].spread_coherence_fx[sfFrom], hMetaTo->directional_meta[dir].spread_coherence_fx[sfTo], MASA_FREQUENCY_BANDS ); + Copy32( hMetaFrom->directional_meta[dir].azimuth_fx[sfFrom], hMetaTo->directional_meta[dir].azimuth_fx[sfTo], MASA_FREQUENCY_BANDS ); // Q22 + Copy32( hMetaFrom->directional_meta[dir].elevation_fx[sfFrom], hMetaTo->directional_meta[dir].elevation_fx[sfTo], MASA_FREQUENCY_BANDS ); // Q22 + Copy32( hMetaFrom->directional_meta[dir].energy_ratio_fx[sfFrom], hMetaTo->directional_meta[dir].energy_ratio_fx[sfTo], MASA_FREQUENCY_BANDS ); // Q30 + Copy( hMetaFrom->directional_meta[dir].spread_coherence_fx[sfFrom], hMetaTo->directional_meta[dir].spread_coherence_fx[sfTo], MASA_FREQUENCY_BANDS ); // Q15 } /* common metadata */ - Copy32( hMetaFrom->common_meta.diffuse_to_total_ratio_fx[sfFrom], hMetaTo->common_meta.diffuse_to_total_ratio_fx[sfTo], MASA_FREQUENCY_BANDS ); - Copy( hMetaFrom->common_meta.surround_coherence_fx[sfFrom], hMetaTo->common_meta.surround_coherence_fx[sfTo], MASA_FREQUENCY_BANDS ); - Copy32( hMetaFrom->common_meta.remainder_to_total_ratio_fx[sfFrom], hMetaTo->common_meta.remainder_to_total_ratio_fx[sfTo], MASA_FREQUENCY_BANDS ); + Copy32( hMetaFrom->common_meta.diffuse_to_total_ratio_fx[sfFrom], hMetaTo->common_meta.diffuse_to_total_ratio_fx[sfTo], MASA_FREQUENCY_BANDS ); // Q30 + Copy( hMetaFrom->common_meta.surround_coherence_fx[sfFrom], hMetaTo->common_meta.surround_coherence_fx[sfTo], MASA_FREQUENCY_BANDS ); // Q15 + Copy32( hMetaFrom->common_meta.remainder_to_total_ratio_fx[sfFrom], hMetaTo->common_meta.remainder_to_total_ratio_fx[sfTo], MASA_FREQUENCY_BANDS ); // Q30 return; } @@ -3209,18 +3210,18 @@ static UWord8 are_masa_subframes_similar_fx( move16(); move16(); - WHILE( EQ_16( sf_differ, FALSE ) && LE_16( dir, num_dir ) ) + WHILE( ( sf_differ == FALSE ) && ( dir <= num_dir ) ) { test(); band_idx = 0; move16(); - WHILE( EQ_16( sf_differ, FALSE ) && LT_16( band_idx, MASA_FREQUENCY_BANDS ) ) + WHILE( ( sf_differ == FALSE ) && ( band_idx < MASA_FREQUENCY_BANDS ) ) { test(); Word32 azi_dif_fx; - azi_dif_fx = L_abs( L_sub( frame1->directional_meta[dir].azimuth_fx[sf1_idx][band_idx], frame2->directional_meta[dir].azimuth_fx[sf2_idx][band_idx] ) ); + azi_dif_fx = L_abs( L_sub( frame1->directional_meta[dir].azimuth_fx[sf1_idx][band_idx], frame2->directional_meta[dir].azimuth_fx[sf2_idx][band_idx] ) ); // Q22 IF( GT_32( azi_dif_fx, 180 << Q22 ) ) - azi_dif_fx = L_sub( 360 << Q22, azi_dif_fx ); + azi_dif_fx = L_sub( 360 << Q22, azi_dif_fx ); // Q22 IF( GT_32( azi_dif_fx, ONE_IN_Q21 /*0.5 in Q22*/ ) ) { @@ -3258,7 +3259,7 @@ static UWord8 are_masa_subframes_similar_fx( } /* check the common metadata */ - WHILE( EQ_16( sf_differ, FALSE ) && LT_16( band_idx, MASA_FREQUENCY_BANDS ) ) + WHILE( ( sf_differ == FALSE ) && ( band_idx < MASA_FREQUENCY_BANDS ) ) { test(); IF( GT_32( L_abs( L_sub( frame1->common_meta.surround_coherence_fx[sf1_idx][band_idx], frame2->common_meta.surround_coherence_fx[sf2_idx][band_idx] ) ), MASA_COHERENCE_TOLERANCE_FX ) ) @@ -3770,19 +3771,19 @@ void ivas_merge_masa_metadata_fx( move16(); IF( EQ_16( band_n_dirs, 2 ) ) { - energyTimesRatioMASA_fx[1] = Mpy_32_32( eneBand_fx, hMeta->directional_meta[1].energy_ratio_fx[sf][band] ); + energyTimesRatioMASA_fx[1] = Mpy_32_32( eneBand_fx, hMeta->directional_meta[1].energy_ratio_fx[sf][band] ); // energyTimesRatioMASA_e energyTimesRatioMASA_e[1] = add( eneBand_e, 1 ); } ELSE { - energyTimesRatioMASA_fx[1] = 0; + energyTimesRatioMASA_fx[1] = 0; // energyTimesRatioMASA_e energyTimesRatioMASA_e[1] = 0; } move32(); move16(); /* target is original MASA diffuseness */ - total_diff_nrg_fx = Mpy_32_32( eneBand_fx, hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] ); + total_diff_nrg_fx = Mpy_32_32( eneBand_fx, hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] ); // total_diff_nrg_e total_diff_nrg_e = add( eneBand_e, 1 ); /* criterion is mean of ISM ratio and new ratio */ @@ -3842,6 +3843,7 @@ void ivas_merge_masa_metadata_fx( ELSE { hMeta->directional_meta[merge_dest].energy_ratio_fx[sf][band] = hOMasaMeta->directional_meta[0].energy_ratio_fx[sf][band]; /*q30*/ + move32(); } /* clip with original ISM dir */ hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_sub( ONE_IN_Q30, hMeta->directional_meta[merge_dest].energy_ratio_fx[sf][band] ); /*q30*/ @@ -3920,7 +3922,7 @@ static void quantize_ratio_ism_vector_ivas_fx( IF( tmp < 0 ) { /* take it out from quantize function */ - Copy( ratio_ism, ratio_ism_loc, idx_sep_object ); + Copy( ratio_ism, ratio_ism_loc, idx_sep_object ); // Q(15 - ratio_ism_e) Copy( &ratio_ism[idx_sep_object + 1], &ratio_ism_loc[idx_sep_object], nchan_ism - idx_sep_object - 1 ); no_ism_loc = sub( nchan_ism, 1 ); } @@ -3980,7 +3982,7 @@ static void quantize_ratio_ism_vector_ivas_fx( move16(); move16(); - WHILE( LT_16( part_idx_sum, max_sum_idx ) ) + WHILE( ( part_idx_sum < max_sum_idx ) ) { best_i = -1; move16(); @@ -4183,7 +4185,7 @@ static Word16 try_differential_fx( b_signif = 0; move16(); - WHILE( LT_16( b_signif, numCodingBands ) && GE_32( masa_to_total_energy_ratio[b_signif], MASA2TOTAL_THR_Q30 ) ) + WHILE( ( b_signif < numCodingBands ) && ( masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR_Q30 ) ) { test(); b_signif = add( b_signif, 1 ); @@ -4471,7 +4473,7 @@ static Word16 encode_ratio_ism_subframe_fx( move16(); move16(); move16(); - WHILE( LT_16( b_signif, numCodingBands ) && GE_32( masa_to_total_energy_ratio[b_signif], MASA2TOTAL_THR_Q30 ) ) + WHILE( ( b_signif < numCodingBands ) && ( masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR_Q30 ) ) { test(); b_signif = add( b_signif, 1 ); @@ -4735,8 +4737,8 @@ static void ivas_encode_masaism_metadata_fx( { FOR( band = 0; band < nbands_work; band++ ) { - energy_ism = 0; /* ISM energy for current subband */ - energy_ism_e = 0; /* ISM energy for current subband */ + energy_ism = 0; /* ISM energy for current subband */ // energy_ism_e + energy_ism_e = 0; /* ISM energy for current subband */ move32(); move16(); FOR( obj = 0; obj < nchan_ism; obj++ ) diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index 26a81c133..ac9992757 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -52,13 +52,13 @@ * Local function prototypes *------------------------------------------------------------------------*/ -static void ivas_param_mc_write_bs( const PARAM_MC_ENC_HANDLE hParamMC, int16_t *ILD_idx, int16_t *ICC_idx, uint16_t bit_buffer[PARAM_MC_MAX_BITS], int16_t *bit_pos ); +static void ivas_param_mc_write_bs_fx( const PARAM_MC_ENC_HANDLE hParamMC, Word16 *ILD_idx, Word16 *ICC_idx, UWord16 bit_buffer[PARAM_MC_MAX_BITS], Word16 *bit_pos ); -static void ivas_param_mc_dec2bin( const int16_t val, const int16_t N, uint16_t bits[PARAM_MC_MAX_BITS] ); +static void ivas_param_mc_dec2bin_fx( const Word16 val, const Word16 N, UWord16 bits[PARAM_MC_MAX_BITS] ); -static void ivas_param_mc_encode_parameter( int16_t *idx_in, HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC, HANDLE_PARAM_MC_PARAMETER_CODING_INFO hParameterCodingInfo, const int16_t nbands, const int16_t band_step, const int16_t map_size_wo_lfe, const int16_t map_size, uint16_t bit_buffer[PARAM_MC_MAX_BITS], int16_t *bit_pos ); +static void ivas_param_mc_encode_parameter_fx( Word16 *idx_in, HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC, HANDLE_PARAM_MC_PARAMETER_CODING_INFO hParameterCodingInfo, const Word16 nbands, const Word16 band_step, const Word16 map_size_wo_lfe, const Word16 map_size, UWord16 bit_buffer[PARAM_MC_MAX_BITS], Word16 *bit_pos ); -static void ivas_param_mc_range_encoder( const int16_t *seq_in, const int16_t num_symbols, const uint16_t *cum_freq, const uint16_t *sym_freq, const uint16_t tot_shift, const int16_t max_nb_bits, uint16_t *bit_buffer, int16_t *bit_pos ); +static void ivas_param_mc_range_encoder_fx( const Word16 *seq_in, const Word16 num_symbols, const UWord16 *cum_freq, const UWord16 *sym_freq, const UWord16 tot_shift, const Word16 max_nb_bits, UWord16 *bit_buffer, Word16 *bit_pos ); #define ATTACKTHRESHOLD_E 4 @@ -147,7 +147,7 @@ ivas_error ivas_param_mc_enc_open_fx( } /* get dmx factors */ - hParamMC->dmx_factors_fx = ivas_param_mc_conf[config_index].dmx_fac_fx; + hParamMC->dmx_factors_fx = ivas_param_mc_conf[config_index].dmx_fac_fx; // Q31 /* set FB config. */ IF( NE_32( ( error = ivas_fb_set_cfg( &fb_cfg, MC_FORMAT, nchan_inp, 0, 0, input_Fs, 0 ) ), IVAS_ERR_OK ) ) @@ -216,12 +216,12 @@ ivas_error ivas_param_mc_enc_open_fx( move16(); /* Init total/dmx ener factors */ - set32_fx( hParamMC->ener_fac_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS ); + set32_fx( hParamMC->ener_fac_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS ); // Q21 /* init previous ILDs */ FOR( i = 0; i < PARAM_MC_MAX_PARAMETER_BANDS; i++ ) { - set32_fx( hParamMC->prev_ilds_fx[i], 0, PARAM_MC_SZ_ILD_MAP ); + set32_fx( hParamMC->prev_ilds_fx[i], 0, PARAM_MC_SZ_ILD_MAP ); // Q21 } st_ivas->hParamMC = hParamMC; @@ -292,7 +292,7 @@ ivas_error ivas_param_mc_enc_reconfig_fx( } /* get dmx factors */ - hParamMC->dmx_factors_fx = ivas_param_mc_conf[config_index].dmx_fac_fx; + hParamMC->dmx_factors_fx = ivas_param_mc_conf[config_index].dmx_fac_fx; // Q31 /* open/init parameter coding */ ivas_param_mc_metadata_open_fx( mc_input_setup, ivas_total_brate, &hParamMC->hMetadataPMC ); @@ -349,7 +349,7 @@ ivas_error ivas_param_mc_enc_reconfig_fx( move16(); /* Init total/dmx ener factors */ - set32_fx( hParamMC->ener_fac_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS ); + set32_fx( hParamMC->ener_fac_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS ); // Q21 return error; @@ -536,7 +536,7 @@ void ivas_param_mc_enc_fx( /* just copy data_dmx generated above, contains already the downmix */ FOR( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { - Copy32( data_dmx_fx[ch], data_f_fx[ch], input_frame ); + Copy32( data_dmx_fx[ch], data_f_fx[ch], input_frame ); // q_data_dmx_fx16 } /* we have to run the transient detector on the second channel of the last CPE if we @@ -547,15 +547,15 @@ void ivas_param_mc_enc_fx( { Word16 cpe_idx = shr( ch, 1 ); - set32_fx( data_f_fx[ch], 0, input_frame ); - set16_fx( data_f_fx16, 0, input_frame ); + set32_fx( data_f_fx[ch], 0, input_frame ); // Q11 + set16_fx( data_f_fx16, 0, input_frame ); // Q11 RunTransientDetection_ivas_fx( data_f_fx16, input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet, 0 ); } } /* write Parametric MC side info bitstream into temporary buffer*/ - ivas_param_mc_write_bs( hParamMC, ILD_idx, ICC_idx, bit_buffer, &bit_pos ); + ivas_param_mc_write_bs_fx( hParamMC, ILD_idx, ICC_idx, bit_buffer, &bit_pos ); /* push the Parametric MC side info from the temporary buffer into the medatdata bitstream*/ push_next_bits( hMetaData, bit_buffer, bit_pos ); @@ -606,7 +606,7 @@ static void ivas_param_mc_dmx_fx( move16(); FOR( inp_ch = 0; inp_ch < nchan_input; inp_ch++ ) { - ( *dmx_sample_fx ) = Madd_32_32( ( *dmx_sample_fx ), data_f_fx[idx[inp_ch]][i], ( *( p_dmx_fac_fx++ ) ) ); + ( *dmx_sample_fx ) = Madd_32_32( ( *dmx_sample_fx ), data_f_fx[idx[inp_ch]][i], ( *( p_dmx_fac_fx++ ) ) ); // Q_x - 11 move16(); } } @@ -626,9 +626,9 @@ static void ivas_param_mc_dmx_fx( static void ivas_param_mc_param_est_enc_fx( PARAM_MC_ENC_HANDLE hParamMC, /* i/o: Parametric MC encoder handle */ Word32 *data_f_fx[], /* i : Input frame in the time domain Q11 */ - Word32 Cy_sum_fx[][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], /* o : Covariance matrix for the original frame */ + Word32 Cy_sum_fx[][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], /* o : Covariance matrix for the original frame Cy_sum_e*/ Word16 Cy_sum_e[][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], /* o : Covariance matrix for the original frame */ - Word32 Cx_sum_fx[][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], /* o : Covariance matrix for the downmixed frame */ + Word32 Cx_sum_fx[][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], /* o : Covariance matrix for the downmixed frame Cx_sum_e*/ Word16 Cx_sum_e[][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], /* o : Covariance matrix for the downmixed frame */ const Word16 input_frame, /* i : Input frame length */ const Word16 nchan_input, /* i : number of input channels */ @@ -1009,7 +1009,7 @@ static void ivas_param_mc_param_est_enc_fx( { ref_channel_idx = h_ild_mapping->ref_channel_idx[k][ref_channel_cnt]; move16(); - ref_ener_fx = BASOP_Util_Add_Mant32Exp( ref_ener_fx, ref_ener_e, Cx_sum_fx[cur_param_band][ref_channel_idx][ref_channel_idx], + ref_ener_fx = BASOP_Util_Add_Mant32Exp( ref_ener_fx, ref_ener_e, Cx_sum_fx[cur_param_band][ref_channel_idx][ref_channel_idx], // ref_ener_e Cx_sum_e[cur_param_band][ref_channel_idx][ref_channel_idx], &ref_ener_e ); ref_ener_e = Cx_sum_e[cur_param_band][ref_channel_idx][ref_channel_idx]; move16(); @@ -1633,8 +1633,8 @@ static void ivas_param_mc_transient_detection_fx( push_wmops( "param_mc_trn_det" ); attackRatioThreshold_fx = hTranDet->transientDetector.attackRatioThreshold; - pSubblockNrg_fx = &hTranDet->subblockEnergies.subblockNrg[hParamMC->transient_detector_delay]; - pAccSubblockNrg_fx = &hTranDet->subblockEnergies.accSubblockNrg[hParamMC->transient_detector_delay]; + pSubblockNrg_fx = &hTranDet->subblockEnergies.subblockNrg[hParamMC->transient_detector_delay]; // Q0 + pAccSubblockNrg_fx = &hTranDet->subblockEnergies.accSubblockNrg[hParamMC->transient_detector_delay]; // Q0 bIsAttackPresent = FALSE; move16(); @@ -1680,7 +1680,7 @@ return; * Write the metadata bitstream *------------------------------------------------------------------------*/ -static void ivas_param_mc_write_bs( +static void ivas_param_mc_write_bs_fx( const PARAM_MC_ENC_HANDLE hParamMC, /* i/o: Parametric MC encoder Handle */ Word16 *ILD_idx, /* i : ILD quantizer indices sequence */ Word16 *ICC_idx, /* i : ICC quantizer indices sequence */ @@ -1762,11 +1762,11 @@ static void ivas_param_mc_write_bs( } } - ivas_param_mc_encode_parameter( ICC_idx, &hParamMC->hMetadataPMC, &hParamMC->hMetadataPMC.icc_coding, - nbands, band_step, icc_map_size_wo_lfe, icc_map_size, bit_buffer, bit_pos ); + ivas_param_mc_encode_parameter_fx( ICC_idx, &hParamMC->hMetadataPMC, &hParamMC->hMetadataPMC.icc_coding, + nbands, band_step, icc_map_size_wo_lfe, icc_map_size, bit_buffer, bit_pos ); - ivas_param_mc_encode_parameter( ILD_idx, &hParamMC->hMetadataPMC, &hParamMC->hMetadataPMC.ild_coding, - nbands, band_step, ild_map_size_wo_lfe, ild_map_size, bit_buffer, bit_pos ); + ivas_param_mc_encode_parameter_fx( ILD_idx, &hParamMC->hMetadataPMC, &hParamMC->hMetadataPMC.ild_coding, + nbands, band_step, ild_map_size_wo_lfe, ild_map_size, bit_buffer, bit_pos ); pop_wmops(); return; @@ -1774,13 +1774,13 @@ static void ivas_param_mc_write_bs( /*------------------------------------------------------------------------- - * ivas_param_mc_encode_parameter() + * ivas_param_mc_encode_parameter_fx() * * (entropy) encode a sequence of parameter indices *------------------------------------------------------------------------*/ -static void ivas_param_mc_encode_parameter( - int16_t *quant_idx, /* i : indices sequence to encode */ +static void ivas_param_mc_encode_parameter_fx( + Word16 *quant_idx, /* i : indices sequence to encode */ HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC, /* i : Parametric MC metadata handle */ HANDLE_PARAM_MC_PARAMETER_CODING_INFO hParameterCodingInfo, /* i : parameter quantization and coding info */ const Word16 nbands, /* i : number of parameter bands to encode */ @@ -1867,10 +1867,10 @@ static void ivas_param_mc_encode_parameter( bit_cnt_uni = sub( i_mult( sz_seq, hParameterCodingInfo->uni_bits ), 1 ); /* -1 for the additional diff/direct signaling bit for the range encoder*/ /* code the direct index sequence */ - ivas_param_mc_range_encoder( seq, sz_seq, hParameterCodingInfo->cum_freq, hParameterCodingInfo->sym_freq, PARAM_MC_RANGE_CODER_TOT_SHIFT, bit_cnt_uni, &tmp_bit_buffer[0], &bit_cnt_range ); + ivas_param_mc_range_encoder_fx( seq, sz_seq, hParameterCodingInfo->cum_freq, hParameterCodingInfo->sym_freq, PARAM_MC_RANGE_CODER_TOT_SHIFT, bit_cnt_uni, &tmp_bit_buffer[0], &bit_cnt_range ); /* Coding the delta index sequence */ - ivas_param_mc_range_encoder( seq_delta, sz_seq, hParameterCodingInfo->cum_freq_delta, hParameterCodingInfo->sym_freq_delta, PARAM_MC_RANGE_CODER_TOT_SHIFT, bit_cnt_uni, &tmp_bit_buffer_diff[0], &bit_cnt_range_diff ); + ivas_param_mc_range_encoder_fx( seq_delta, sz_seq, hParameterCodingInfo->cum_freq_delta, hParameterCodingInfo->sym_freq_delta, PARAM_MC_RANGE_CODER_TOT_SHIFT, bit_cnt_uni, &tmp_bit_buffer_diff[0], &bit_cnt_range_diff ); bit_cnt_range_min = s_min( bit_cnt_range, bit_cnt_range_diff ); @@ -1885,7 +1885,7 @@ static void ivas_param_mc_encode_parameter( FOR( i = 0; i < sz_seq; ++i ) { - ivas_param_mc_dec2bin( seq[i], hParameterCodingInfo->uni_bits, &bit_buffer[*( bit_pos ) + bit_pos_tmp] ); + ivas_param_mc_dec2bin_fx( seq[i], hParameterCodingInfo->uni_bits, &bit_buffer[*( bit_pos ) + bit_pos_tmp] ); bit_pos_tmp = add( bit_pos_tmp, hParameterCodingInfo->uni_bits ); } *bit_pos = add( *bit_pos, bit_pos_tmp ); @@ -1927,7 +1927,7 @@ static void ivas_param_mc_encode_parameter( * Decimal to binary routine *------------------------------------------------------------------------*/ -static void ivas_param_mc_dec2bin( +static void ivas_param_mc_dec2bin_fx( const Word16 val, /* i : value to encode */ const Word16 N, /* i : number of bits for encoding the value */ UWord16 bits[PARAM_MC_MAX_BITS] ) /* o : encoded bits buffer */ @@ -1953,7 +1953,7 @@ static void ivas_param_mc_dec2bin( * Parametric MC Range encoder *-------------------------------------------------------------------*/ -static void ivas_param_mc_range_encoder( +static void ivas_param_mc_range_encoder_fx( const Word16 *seq_in, /* i : input sequence */ const Word16 num_symbols, /* i : Number of symbole to encode */ const UWord16 *cum_freq, /* i : cumulated frequencies */ @@ -1992,10 +1992,10 @@ static void ivas_param_mc_range_encoder( /* Push range coded bits from byte_buffer to bitstream */ /* 1) Push all complete bytes, one byte at a time */ - FOR( i = 0; i < shr( rc_tot_bits, 3 ); ++i ) + FOR( i = 0; i < ( rc_tot_bits >> 3 ); ++i ) { /* use rc_st_enc.byte_buffer */ - bits = &bit_buffer[shl( i, 3 )]; + bits = &bit_buffer[i << 3]; byte = rc_st_enc.byte_buffer[i]; move16(); @@ -2023,7 +2023,7 @@ static void ivas_param_mc_range_encoder( { UWord8 rem_bits = (UWord8) s_and( rc_tot_bits, 7 ); - bits = &bit_buffer[shl( i, 3 )]; + bits = &bit_buffer[( i << 3 )]; byte = rc_st_enc.byte_buffer[i]; move16(); diff --git a/lib_enc/ivas_mc_paramupmix_enc.c b/lib_enc/ivas_mc_paramupmix_enc.c index 7d029ac2e..61f817b2f 100644 --- a/lib_enc/ivas_mc_paramupmix_enc.c +++ b/lib_enc/ivas_mc_paramupmix_enc.c @@ -80,7 +80,7 @@ static void quantize_pars_fx( const Word32 *v_fx, Word16 exp_v, const Word16 nq, void ivas_mc_paramupmix_enc_fx( Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ BSTR_ENC_HANDLE hBStr, /* i/o: IVAS Metadata bitstream handle */ - Word32 *data_fx[], + Word32 *data_fx[], // st_ivas->q_data_fx const Word16 input_frame /* i : input frame length */ ) { @@ -95,8 +95,8 @@ void ivas_mc_paramupmix_enc_fx( bit_pos = 0; /* Parameter estimation */ - Word32 alphas_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; - Word32 betas_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; + Word32 alphas_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; // exp_alphas + Word32 betas_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; // exp_betas Word16 exp_alphas = 31, exp_betas = 31; move16(); move16(); @@ -126,7 +126,7 @@ void ivas_mc_paramupmix_enc_fx( * * Initialize MC ParamUpmix encoder handle *------------------------------------------------------------------------*/ -ivas_error ivas_mc_paramupmix_enc_open( +ivas_error ivas_mc_paramupmix_enc_open_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ) { @@ -270,7 +270,7 @@ ivas_error ivas_mc_paramupmix_enc_open( * * Close MC Param-Upmix encoder handle *------------------------------------------------------------------------*/ -void ivas_mc_paramupmix_enc_close( +void ivas_mc_paramupmix_enc_close_fx( MC_PARAMUPMIX_ENC_HANDLE *hMCParamUpmix, /* i/o: MC Param-Upmix encoder handle */ const Word32 input_Fs /* i : input sampling rate */ ) @@ -465,12 +465,12 @@ static void huffman_encode_fx( } static void quantize_pars_fx( - const Word32 *v_fx, + const Word32 *v_fx, // exp_v Word16 exp_v, const Word16 nq, - const Word32 *data_fx, + const Word32 *data_fx, // Q28 Word32 vq[IVAS_MAX_NUM_BANDS], - Word32 *vdeq_fx, + Word32 *vdeq_fx, // exp_vdeq Word16 *exp_vdeq ) { Word16 iv, iq, iq0, iq1; @@ -480,7 +480,7 @@ static void quantize_pars_fx( iq0 = 0; iq1 = sub( nq, 1 ); - WHILE( GT_16( sub( iq1, iq0 ), 1 ) ) + WHILE( ( iq1 - iq0 ) > 1 ) { iq = shr( add( iq0, iq1 ), 1 ); Word16 cmp_1 = BASOP_Util_Cmp_Mant32Exp( v_fx[iv], exp_v, data_fx[iq], 31 - Q28 ); @@ -527,17 +527,17 @@ static void quantize_pars_fx( } static void quantize_alpha_fx( - const Word32 *alpha_fx, + const Word32 *alpha_fx, // 31 - exp_alpha Word16 exp_alpha, Word16 *pnq, Word32 aq[IVAS_MAX_NUM_BANDS], - Word32 *adeq_fx, + Word32 *adeq_fx, // 31 - exp_adeq Word16 *exp_adeq ) { Word16 nq; const Word32 *data_fx; - nq = ivas_mc_paramupmix_alpha_quant_table_fx.nquant; + nq = ivas_mc_paramupmix_alpha_quant_table_fx.nquant; // Q0 move16(); data_fx = ivas_mc_paramupmix_alpha_quant_table_fx.data; // Q28 @@ -566,13 +566,13 @@ static void quantize_beta_fx( FOR( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ ) { - quant_table_fx = tables_fx[ivas_param_upmx_mx_qmap[aq[iv]]]; + quant_table_fx = tables_fx[ivas_param_upmx_mx_qmap[aq[iv]]]; // Q28 iq0 = 0; move16(); iq1 = sub( quant_table_fx.nquant, 1 ); - WHILE( GT_16( sub( iq1, iq0 ), 1 ) ) + WHILE( ( ( iq1 - iq0 ) > 1 ) ) { iq = shr( add( iq0, iq1 ), 1 ); @@ -604,12 +604,12 @@ static void quantize_beta_fx( IF( EQ_16( cmp_2, negate( 1 ) ) ) { bq[iv] = iq0; - bdeq_fx[iv] = quant_table_fx.data[iq0]; + bdeq_fx[iv] = quant_table_fx.data[iq0]; // Q28 } ELSE { bq[iv] = iq1; - bdeq_fx[iv] = quant_table_fx.data[iq1]; + bdeq_fx[iv] = quant_table_fx.data[iq1]; // Q28 } move16(); move32(); @@ -625,9 +625,9 @@ static void quantize_beta_fx( static void put_ec_data_fx( MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, const Word16 ch, - const Word32 pars_fx[IVAS_MAX_NUM_BANDS], + const Word32 pars_fx[IVAS_MAX_NUM_BANDS], // Q(31 - exp_paras) Word16 exp_paras, - const Word32 alphas_fx[IVAS_MAX_NUM_BANDS], + const Word32 alphas_fx[IVAS_MAX_NUM_BANDS], // Q(31 - exp_alphas) Word16 exp_alphas, const PAR_TYPE parType, UWord16 bit_buffer[MC_PARAMUPMIX_MAX_BITS], @@ -636,8 +636,8 @@ static void put_ec_data_fx( Word16 nq; Word32 alphaQuant[IVAS_MAX_NUM_BANDS]; Word32 betaQuant[IVAS_MAX_NUM_BANDS]; - Word32 alphaDequant_fx[IVAS_MAX_NUM_BANDS]; - Word32 betaDequant_fx[IVAS_MAX_NUM_BANDS]; + Word32 alphaDequant_fx[IVAS_MAX_NUM_BANDS]; // 31 - exp_alphaDequant + Word32 betaDequant_fx[IVAS_MAX_NUM_BANDS]; // 31 - exp_betaDequant Word16 exp_alphaDequant = 31, exp_betaDequant = 31; @@ -760,12 +760,12 @@ static void ivas_mc_paramupmix_dmx_fx( static ivas_error ivas_mc_paramupmix_param_est_enc_fx( MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, /* i/o: MC Param-Upmix encoder handle */ - Word32 *data_f_fx[], + Word32 *data_f_fx[], // Q_data_f Word16 Q_data_f, - const Word16 input_frame, /* i : Input frame length */ - Word32 alphas_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS], + const Word16 input_frame, /* i : Input frame length */ + Word32 alphas_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS], // 31 - exp_alphas Word16 *exp_alphas, - Word32 betas_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS], + Word32 betas_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS], // 31 - exp_betas Word16 *exp_betas ) { @@ -775,11 +775,11 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx( Word32 fr_imagbuffer_fx[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH][L_FRAME48k]; Word32 *p_fr_realbuffer_fx[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; Word32 *p_fr_imagbuffer_fx[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; - Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - Word32 *cov_dtx_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; // q_cov_real + Word32 *cov_dtx_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; // q_cov_dtx_real Word16 *q_cov_real[IVAS_SPAR_MAX_CH]; Word16 *q_cov_dtx_real[IVAS_SPAR_MAX_CH]; - Word32 *pp_in_fr_real_fx[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH], *pp_in_fr_imag_fx[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; + Word32 *pp_in_fr_real_fx[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH], *pp_in_fr_imag_fx[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; // q_ppIn_FR Word16 q_ppIn_FR; Word32 rxy_fx, ryy_fx; @@ -822,8 +822,8 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx( pcm_in_fx[2 * i] = data_f_fx[chan1s[i]]; pcm_in_fx[2 * i + 1] = data_f_fx[chan2s[i]]; - Scale_sig32( pcm_in_fx[2 * i], input_frame, sub( Q14, Q_data_f ) ); - Scale_sig32( pcm_in_fx[2 * i + 1], input_frame, sub( Q14, Q_data_f ) ); + Scale_sig32( pcm_in_fx[2 * i], input_frame, sub( Q14, Q_data_f ) ); // Q14 + Scale_sig32( pcm_in_fx[2 * i + 1], input_frame, sub( Q14, Q_data_f ) ); // Q14 } /*-----------------------------------------------------------------------------------------* @@ -898,10 +898,10 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx( FOR( b = 0; b < MC_PARAMUPMIX_COMBINATIONS; b++ ) { - pp_in_fr_real_fx[0] = p_fr_realbuffer_fx[2 * b]; - pp_in_fr_imag_fx[0] = p_fr_imagbuffer_fx[2 * b]; - pp_in_fr_real_fx[1] = FR_Real_Mid_fx; - pp_in_fr_imag_fx[1] = FR_Imag_Mid_fx; + pp_in_fr_real_fx[0] = p_fr_realbuffer_fx[2 * b]; // q_ppIn_FR + pp_in_fr_imag_fx[0] = p_fr_imagbuffer_fx[2 * b]; // q_ppIn_FR + pp_in_fr_real_fx[1] = FR_Real_Mid_fx; // q_ppIn_FR + pp_in_fr_imag_fx[1] = FR_Imag_Mid_fx; // q_ppIn_FR v_add_fx( pp_in_fr_real_fx[0], p_fr_realbuffer_fx[2 * b + 1], pp_in_fr_real_fx[1], L_FRAME48k ); v_add_fx( pp_in_fr_imag_fx[0], p_fr_imagbuffer_fx[2 * b + 1], pp_in_fr_imag_fx[1], L_FRAME48k ); @@ -910,9 +910,9 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx( { FOR( j = 0; j < MC_PARAMUPMIX_NCH; j++ ) { - cov_real_fx[i][j] = hMCParamUpmix->cov_real_fx[b][i][j]; + cov_real_fx[i][j] = hMCParamUpmix->cov_real_fx[b][i][j]; // q_cov_real move32(); - cov_dtx_real_fx[i][j] = hMCParamUpmix->cov_dtx_real_fx[b][i][j]; + cov_dtx_real_fx[i][j] = hMCParamUpmix->cov_dtx_real_fx[b][i][j]; // q_cov_dtx_real move32(); } IF( ( q_cov_real[i] = (Word16 *) malloc( sizeof( Word16 ) * MC_PARAMUPMIX_NCH ) ) == NULL ) diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index 78d1a3e87..34d43d366 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -191,7 +191,7 @@ ivas_error ivas_mcmasa_enc_open_fx( { IF( GE_32( hMcMasa->band_grouping[i], maxBin ) ) { - hMcMasa->band_grouping[i] = maxBin; + hMcMasa->band_grouping[i] = maxBin; // Q0 move16(); hMcMasa->nbands = i; move16(); @@ -346,7 +346,7 @@ ivas_error ivas_mcmasa_enc_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); } - set_zero_fx( hMcMasa->buffer_intensity_real_fx[i][j], hMcMasa->nbands ); + set_zero_fx( hMcMasa->buffer_intensity_real_fx[i][j], hMcMasa->nbands ); // hMcMasa->buffer_intensity_real_q } } set16_fx( hMcMasa->buffer_intensity_real_q, 31, DIRAC_NO_COL_AVG_DIFF ); @@ -358,7 +358,7 @@ ivas_error ivas_mcmasa_enc_open_fx( FOR( j = 0; j < hMcMasa->no_col_avg_diff; j++ ) { - IF( ( hMcMasa->buffer_intensity_real_vert_fx[j] = (Word32 *) malloc( hMcMasa->nbands * sizeof( Word32 ) ) ) == NULL ) + IF( ( hMcMasa->buffer_intensity_real_vert_fx[j] = (Word32 *) malloc( hMcMasa->nbands * sizeof( Word32 ) ) ) == NULL ) // hMcMasa->buffer_intensity_real_vert_q { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); } @@ -369,7 +369,7 @@ ivas_error ivas_mcmasa_enc_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); } - set_zero_fx( hMcMasa->buffer_energy_fx, imult1616( hMcMasa->nbands, hMcMasa->no_col_avg_diff ) ); + set_zero_fx( hMcMasa->buffer_energy_fx, imult1616( hMcMasa->nbands, hMcMasa->no_col_avg_diff ) ); // hMcMasa->buffer_energy_q set16_fx( hMcMasa->buffer_intensity_real_vert_q, 31, DIRAC_NO_COL_AVG_DIFF ); set16_fx( hMcMasa->buffer_energy_q, 31, DIRAC_NO_COL_AVG_DIFF ); @@ -402,8 +402,8 @@ ivas_error ivas_mcmasa_enc_open_fx( } ELSE IF( EQ_32( st_ivas->hEncoderConfig->mc_input_setup, MC_LS_SETUP_5_1_4 ) ) { - Copy32( ls_azimuth_CICP16_fx, ls_azimuth, sub( nchan_inp, 1 ) ); - Copy32( ls_elevation_CICP16_fx, ls_elevation, sub( nchan_inp, 1 ) ); + Copy32( ls_azimuth_CICP16_fx, ls_azimuth, sub( nchan_inp, 1 ) ); // Q22 + Copy32( ls_elevation_CICP16_fx, ls_elevation, sub( nchan_inp, 1 ) ); // Q22 hMcMasa->numHorizontalChannels = 5; move16(); hMcMasa->isHorizontalSetup = 0; @@ -411,8 +411,8 @@ ivas_error ivas_mcmasa_enc_open_fx( } ELSE { - Copy32( ls_azimuth_CICP19_fx, ls_azimuth, sub( nchan_inp, 1 ) ); - Copy32( ls_elevation_CICP19_fx, ls_elevation, sub( nchan_inp, 1 ) ); + Copy32( ls_azimuth_CICP19_fx, ls_azimuth, sub( nchan_inp, 1 ) ); // Q22 + Copy32( ls_elevation_CICP19_fx, ls_elevation, sub( nchan_inp, 1 ) ); // Q22 hMcMasa->numHorizontalChannels = 7; move16(); hMcMasa->isHorizontalSetup = 0; @@ -421,8 +421,8 @@ ivas_error ivas_mcmasa_enc_open_fx( IF( hMcMasa->separateChannelEnabled ) { - Copy32( &ls_azimuth[hMcMasa->separateChannelIndex + 1], &ls_azimuth[hMcMasa->separateChannelIndex], numAnalysisChannels - hMcMasa->separateChannelIndex ); - Copy32( &ls_elevation[hMcMasa->separateChannelIndex + 1], &ls_elevation[hMcMasa->separateChannelIndex], numAnalysisChannels - hMcMasa->separateChannelIndex ); + Copy32( &ls_azimuth[hMcMasa->separateChannelIndex + 1], &ls_azimuth[hMcMasa->separateChannelIndex], numAnalysisChannels - hMcMasa->separateChannelIndex ); // Q22 + Copy32( &ls_elevation[hMcMasa->separateChannelIndex + 1], &ls_elevation[hMcMasa->separateChannelIndex], numAnalysisChannels - hMcMasa->separateChannelIndex ); // Q22 hMcMasa->numHorizontalChannels = sub( hMcMasa->numHorizontalChannels, 1 ); move16(); } @@ -457,12 +457,12 @@ ivas_error ivas_mcmasa_enc_open_fx( hMcMasa->combineRatios = hMasa->config.mergeRatiosOverSubframes; move16(); - Copy32( ls_azimuth, hMcMasa->ls_azimuth_fx, numAnalysisChannels ); + Copy32( ls_azimuth, hMcMasa->ls_azimuth_fx, numAnalysisChannels ); // Q22 FOR( i = 0; i < hMcMasa->numHorizontalChannels; i++ ) { - left_min = L_shl( 360, 22 ); - right_min = L_negate( L_shl( 360, 22 ) ); + left_min = ( 360 << 22 ); + right_min = -( ( 360 << 22 ) ); FOR( j = 0; j < hMcMasa->numHorizontalChannels; j++ ) { @@ -546,14 +546,14 @@ ivas_error ivas_mcmasa_enc_reconfig_fx( /* bitrate changed, may need to do something */ /* brute-force solution: close McMASA and re-instantiate with new settings */ - ivas_masa_enc_close( &( st_ivas->hMasa ) ); + ivas_masa_enc_close_fx( &( st_ivas->hMasa ) ); ivas_mcmasa_enc_close_fx( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); /* Determine if to separate some channels from the analysis */ ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->hEncoderConfig->element_mode_init ), ivas_total_brate ); - IF( NE_32( ( error = ivas_masa_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_masa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -674,21 +674,21 @@ void ivas_mcmasa_enc_fx( move16(); UWord8 fixedDistance = 0; move16(); - Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 energyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 spreadCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 surroundingCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // Q22 + Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // Q22 + Word32 energyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // Q31 + Word32 spreadCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // Q30 + Word32 surroundingCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // Q31 Word32 separatedChannelSignal[L_FRAME48k]; /* Compute low frequency energy */ computeLfeEnergy_fx( hMcMasa, data_fx, input_frame, q_inp ); /* Sum center and LFE, move surround channels */ - v_add_32( data_fx[2], data_fx[3], data_fx[2], input_frame ); + v_add_32( data_fx[2], data_fx[3], data_fx[2], input_frame ); // q_inp FOR( i = 4; i < nchan_inp; i++ ) { - Copy32( data_fx[i], data_fx[i - 1], input_frame ); + Copy32( data_fx[i], data_fx[i - 1], input_frame ); // q_inp } IF( hMcMasa->separateChannelEnabled ) @@ -698,12 +698,12 @@ void ivas_mcmasa_enc_fx( move16(); /* Separate the identified channel */ - Copy32( data_fx[i], separatedChannelSignal, input_frame ); + Copy32( data_fx[i], separatedChannelSignal, input_frame ); // q_inp /* Move the remaining channels in order to perform the analysis without the separated channel */ FOR( i = ( hMcMasa->separateChannelIndex + 1 ); i < ( nchan_inp - 1 ); i++ ) { - Copy32( data_fx[i], data_fx[i - 1], input_frame ); + Copy32( data_fx[i], data_fx[i - 1], input_frame ); // q_inp } } @@ -713,7 +713,7 @@ void ivas_mcmasa_enc_fx( /* Determine LFE-to-total energy ratio */ FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - hMasa->data.lfeToTotalEnergyRatio_fx[i] = L_deposit_h( BASOP_Util_Divide3232_Scale( hMcMasa->lfeLfEne[i], L_add( EPSILON_FX, hMcMasa->totalLfEne[i] ), &hMasa->data.lfeToTotalEnergyRatio_e[i] ) ); + hMasa->data.lfeToTotalEnergyRatio_fx[i] = L_deposit_h( BASOP_Util_Divide3232_Scale( hMcMasa->lfeLfEne[i], L_add( EPSILON_FX, hMcMasa->totalLfEne[i] ), &hMasa->data.lfeToTotalEnergyRatio_e[i] ) ); // hMasa->data.lfeToTotalEnergyRatio_e[i] hMasa->data.lfeToTotalEnergyRatio_e[i] = add( sub( hMcMasa->lfeLfEne_e[i], hMcMasa->totalLfEne_e[i] ), hMasa->data.lfeToTotalEnergyRatio_e[i] ); move32(); move16(); @@ -735,11 +735,11 @@ void ivas_mcmasa_enc_fx( move16(); } - hQMeta->q_direction[0].band_data[i].azimuth_fx[j] = azimuth_m_values_fx[j][i]; + hQMeta->q_direction[0].band_data[i].azimuth_fx[j] = azimuth_m_values_fx[j][i]; // Q22 move32(); - hQMeta->q_direction[0].band_data[i].elevation_fx[j] = elevation_m_values_fx[j][i]; + hQMeta->q_direction[0].band_data[i].elevation_fx[j] = elevation_m_values_fx[j][i]; // Q22 move32(); - hQMeta->q_direction[0].band_data[i].energy_ratio_fx[j] = energyRatio_fx[k][i]; + hQMeta->q_direction[0].band_data[i].energy_ratio_fx[j] = energyRatio_fx[k][i]; // Q30 move32(); hQMeta->q_direction[0].band_data[i].distance[j] = fixedDistance; move16(); @@ -761,11 +761,11 @@ void ivas_mcmasa_enc_fx( { FOR( j = 0; j < nBlocks; j++ ) { - hQMeta->q_direction[0].band_data[i].azimuth_fx[j] = 0; + hQMeta->q_direction[0].band_data[i].azimuth_fx[j] = 0; // Q22 move32(); - hQMeta->q_direction[0].band_data[i].elevation_fx[j] = 0; + hQMeta->q_direction[0].band_data[i].elevation_fx[j] = 0; // Q22 move32(); - hQMeta->q_direction[0].band_data[i].energy_ratio_fx[j] = 0; + hQMeta->q_direction[0].band_data[i].energy_ratio_fx[j] = 0; // Q30 move32(); hQMeta->q_direction[0].band_data[i].distance[j] = 0; move16(); @@ -805,7 +805,7 @@ void ivas_mcmasa_enc_fx( i = 0; move16(); test(); - WHILE( LT_16( i, nBlocks ) && hQMeta->all_coherence_zero ) + WHILE( ( i < nBlocks ) && hQMeta->all_coherence_zero ) { test(); j = 0; @@ -873,7 +873,7 @@ void ivas_mcmasa_enc_fx( void ivas_mcmasa_param_est_enc_fx( MCMASA_ENC_HANDLE hMcMasa, /* i : McMASA encoder structure */ MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder structure */ - Word32 *data_f[], /* i : Audio frame in MC-format */ + Word32 *data_f[], /* i : Audio frame in MC-format Q(q_inp) */ Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated elevation Q22 */ Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated azimuth Q22 */ Word32 energyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated direct-to-total ratio Q31 */ @@ -904,13 +904,13 @@ void ivas_mcmasa_param_est_enc_fx( Word32 intensity_even_real_fx[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; Word32 direction_vector_fx[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; Word32 diffuseness_vector_fx[MASA_FREQUENCY_BANDS]; - Word32 vertical_diffuseness_vector_fx[MASA_FREQUENCY_BANDS]; - Word32 diffuseness_m_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 vertical_diffuseness_vector_fx[MASA_FREQUENCY_BANDS]; // q_vdv + Word32 diffuseness_m_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // diffuseness_e Word16 diffuseness_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 coherentEnergyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 coherentEnergyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // coherentEnergyRatio_e Word16 coherentEnergyRatio_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word16 band_m_idx, block_m_idx; - Word32 renormalization_factor_diff_fx[MASA_FREQUENCY_BANDS]; + Word32 renormalization_factor_diff_fx[MASA_FREQUENCY_BANDS]; // renormalization_factor_diff_e Word16 renormalization_factor_diff_e[MASA_FREQUENCY_BANDS]; Word32 norm_tmp_fx; Word16 mrange[2], brange[2]; @@ -918,7 +918,7 @@ void ivas_mcmasa_param_est_enc_fx( CovarianceMatrix COVls[MASA_FREQUENCY_BANDS]; Word32 absCOVls_fx[MCMASA_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; Word16 absCOVls_e[MCMASA_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; - Word32 lsEnergy_fx[MCMASA_MAX_ANA_CHANS]; + Word32 lsEnergy_fx[MCMASA_MAX_ANA_CHANS]; // lsEnergy_e Word16 lsEnergy_e[MCMASA_MAX_ANA_CHANS]; Word32 lsEnergySum_fx, maxEne_fx; Word16 lsEnergySum_e = 0, maxEne_e; @@ -929,15 +929,15 @@ void ivas_mcmasa_param_est_enc_fx( Word16 i1, i2, i3; Word32 angleDist_fx, minAngleDist_fx; Word32 currentAzi_fx; - Word32 lsEnergyRelation_fx; + Word32 lsEnergyRelation_fx; // lsEnergyRelation_e Word16 lsEnergyRelation_e; - Word32 tempLsEnergyRelation_fx; + Word32 tempLsEnergyRelation_fx; // tempLsEnergyRelation_e Word16 tempLsEnergyRelation_e; Word32 stereoness_fx, cohwideness_fx, spreadCoh_fx; Word32 stereoRatio_fx, cohPanRatio_fx; Word32 stereoCoh_fx, cohPanCoh_fx, cohRatio_fx; Word16 stereoCoh_e, cohPanCoh_e, spreadCoh_e, stereoness_e; - Word32 renormalization_factor_coh_fx[MASA_FREQUENCY_BANDS]; + Word32 renormalization_factor_coh_fx[MASA_FREQUENCY_BANDS]; // renormalization_factor_coh_e Word16 renormalization_factor_coh_e[MASA_FREQUENCY_BANDS]; Word16 surroundingCoherence_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word16 numAnalysisChannels; @@ -967,24 +967,24 @@ void ivas_mcmasa_param_est_enc_fx( IF( hMcMasa->combineRatios ) { /* Need to initialize renormalization_factors, and variables to be normalized */ - set_zero_fx( renormalization_factor_diff_fx, hMcMasa->nbands ); + set_zero_fx( renormalization_factor_diff_fx, hMcMasa->nbands ); // renormalization_factor_diff_e set16_fx( renormalization_factor_diff_e, 0, hMcMasa->nbands ); - set_zero_fx( &diffuseness_m_fx[0][0], MASA_FREQUENCY_BANDS * MAX_PARAM_SPATIAL_SUBFRAMES ); + set_zero_fx( &diffuseness_m_fx[0][0], MASA_FREQUENCY_BANDS * MAX_PARAM_SPATIAL_SUBFRAMES ); // diffuseness_e set16_fx( &diffuseness_e[0][0], 31, MASA_FREQUENCY_BANDS * MAX_PARAM_SPATIAL_SUBFRAMES ); - set_zero_fx( renormalization_factor_coh_fx, hMcMasa->nbands ); + set_zero_fx( renormalization_factor_coh_fx, hMcMasa->nbands ); // renormalization_factor_coh_e set16_fx( renormalization_factor_coh_e, 31, hMcMasa->nbands ); - set_zero_fx( surroundingCoherence_fx[0], hMcMasa->nbands ); + set_zero_fx( surroundingCoherence_fx[0], hMcMasa->nbands ); // surroundingCoherence_e set16_fx( &surroundingCoherence_e[0][0], 31, MASA_FREQUENCY_BANDS * MAX_PARAM_SPATIAL_SUBFRAMES ); - set_zero_fx( coherentEnergyRatio_fx[0], hMcMasa->nbands ); + set_zero_fx( coherentEnergyRatio_fx[0], hMcMasa->nbands ); // coherentEnergyRatio_e set16_fx( &coherentEnergyRatio_e[0][0], 0, MASA_FREQUENCY_BANDS * MAX_PARAM_SPATIAL_SUBFRAMES ); } /* Copy current frame to memory for delay compensation */ FOR( i = 0; i < numAnalysisChannels; i++ ) { - pcm_in[i] = data_f[i]; - p_Chnl_RealBuffer_fx[i] = &Chnl_RealBuffer_fx[i][0]; - p_Chnl_ImagBuffer_fx[i] = &Chnl_ImagBuffer_fx[i][0]; + pcm_in[i] = data_f[i]; // q_inp + p_Chnl_RealBuffer_fx[i] = &Chnl_RealBuffer_fx[i][0]; // q_inp + p_Chnl_ImagBuffer_fx[i] = &Chnl_ImagBuffer_fx[i][0]; // q_inp } /* initialising energy_fx */ @@ -992,7 +992,7 @@ void ivas_mcmasa_param_est_enc_fx( { FOR( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) { - hMasa->data.energy_fx[block_m_idx][i] = 0; + hMasa->data.energy_fx[block_m_idx][i] = 0; // hMasa->data.energy_e move32(); hMasa->data.energy_e[block_m_idx][i] = 31; move16(); @@ -1024,8 +1024,8 @@ void ivas_mcmasa_param_est_enc_fx( { FOR( j = 0; j < numAnalysisChannels; j++ ) { - set_zero_fx( COVls[i].xr_fx[j], numAnalysisChannels ); - set_zero_fx( COVls[i].xi_fx[j], numAnalysisChannels ); + set_zero_fx( COVls[i].xr_fx[j], numAnalysisChannels ); // COVls[i].xr_e[j] + set_zero_fx( COVls[i].xi_fx[j], numAnalysisChannels ); // COVls[i].xi_e[j] set16_fx( COVls[i].xr_e[j], 0, numAnalysisChannels ); set16_fx( COVls[i].xi_e[j], 0, numAnalysisChannels ); } @@ -1094,21 +1094,21 @@ void ivas_mcmasa_param_est_enc_fx( /* Compute standard FOA */ /* W */ - v_add_32( Chnl_RealBuffer_fx[0], Chnl_RealBuffer_fx[1], Foa_RealBuffer_fx[0], num_freq_bins ); - v_add_32( Chnl_ImagBuffer_fx[0], Chnl_ImagBuffer_fx[1], Foa_ImagBuffer_fx[0], num_freq_bins ); + v_add_32( Chnl_RealBuffer_fx[0], Chnl_RealBuffer_fx[1], Foa_RealBuffer_fx[0], num_freq_bins ); // inp_q + v_add_32( Chnl_ImagBuffer_fx[0], Chnl_ImagBuffer_fx[1], Foa_ImagBuffer_fx[0], num_freq_bins ); // inp_q FOR( i = 2; i < numAnalysisChannels; i++ ) { - v_add_32( Chnl_RealBuffer_fx[i], Foa_RealBuffer_fx[0], Foa_RealBuffer_fx[0], num_freq_bins ); - v_add_32( Chnl_ImagBuffer_fx[i], Foa_ImagBuffer_fx[0], Foa_ImagBuffer_fx[0], num_freq_bins ); + v_add_32( Chnl_RealBuffer_fx[i], Foa_RealBuffer_fx[0], Foa_RealBuffer_fx[0], num_freq_bins ); // inp_q + v_add_32( Chnl_ImagBuffer_fx[i], Foa_ImagBuffer_fx[0], Foa_ImagBuffer_fx[0], num_freq_bins ); // inp_q } /* Y */ - v_multc_fixed( Chnl_RealBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[1][0], Foa_RealBuffer_fx[1], num_freq_bins ); - v_multc_fixed( Chnl_ImagBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[1][0], Foa_ImagBuffer_fx[1], num_freq_bins ); + v_multc_fixed( Chnl_RealBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[1][0], Foa_RealBuffer_fx[1], num_freq_bins ); // inp_q + v_multc_fixed( Chnl_ImagBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[1][0], Foa_ImagBuffer_fx[1], num_freq_bins ); // inp_q FOR( i = 1; i < numAnalysisChannels; i++ ) { - v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[1][i], Foa_RealBuffer_fx[1], num_freq_bins ); - v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[1][i], Foa_ImagBuffer_fx[1], num_freq_bins ); + v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[1][i], Foa_RealBuffer_fx[1], num_freq_bins ); // inp_q + v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[1][i], Foa_ImagBuffer_fx[1], num_freq_bins ); // inp_q } /* Z */ @@ -1120,49 +1120,49 @@ void ivas_mcmasa_param_est_enc_fx( } ELSE { - v_multc_fixed( Chnl_RealBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[2][0], Foa_RealBuffer_fx[2], num_freq_bins ); - v_multc_fixed( Chnl_ImagBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[2][0], Foa_ImagBuffer_fx[2], num_freq_bins ); + v_multc_fixed( Chnl_RealBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[2][0], Foa_RealBuffer_fx[2], num_freq_bins ); // inp_q + v_multc_fixed( Chnl_ImagBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[2][0], Foa_ImagBuffer_fx[2], num_freq_bins ); // inp_q FOR( i = 1; i < numAnalysisChannels; i++ ) { - v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[2][i], Foa_RealBuffer_fx[2], num_freq_bins ); - v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[2][i], Foa_ImagBuffer_fx[2], num_freq_bins ); + v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[2][i], Foa_RealBuffer_fx[2], num_freq_bins ); // inp_q + v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[2][i], Foa_ImagBuffer_fx[2], num_freq_bins ); // inp_q } } /* X */ - v_multc_fixed( Chnl_RealBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[3][0], Foa_RealBuffer_fx[3], num_freq_bins ); - v_multc_fixed( Chnl_ImagBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[3][0], Foa_ImagBuffer_fx[3], num_freq_bins ); + v_multc_fixed( Chnl_RealBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[3][0], Foa_RealBuffer_fx[3], num_freq_bins ); // inp_q + v_multc_fixed( Chnl_ImagBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[3][0], Foa_ImagBuffer_fx[3], num_freq_bins ); // inp_q FOR( i = 1; i < numAnalysisChannels; i++ ) { - v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[3][i], Foa_RealBuffer_fx[3], num_freq_bins ); - v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[3][i], Foa_ImagBuffer_fx[3], num_freq_bins ); + v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[3][i], Foa_RealBuffer_fx[3], num_freq_bins ); // inp_q + v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[3][i], Foa_ImagBuffer_fx[3], num_freq_bins ); // inp_q } /* Compute even FOA */ /* W */ - Copy32( Foa_RealBuffer_fx[0], FoaEven_RealBuffer_fx[0], num_freq_bins ); - Copy32( Foa_ImagBuffer_fx[0], FoaEven_ImagBuffer_fx[0], num_freq_bins ); + Copy32( Foa_RealBuffer_fx[0], FoaEven_RealBuffer_fx[0], num_freq_bins ); // inp_q + Copy32( Foa_ImagBuffer_fx[0], FoaEven_ImagBuffer_fx[0], num_freq_bins ); // inp_q /* Y */ - v_multc_fixed( Chnl_RealBuffer_fx[0], hMcMasa->chnlToFoaEvenMtx_fx[1][0], FoaEven_RealBuffer_fx[1], num_freq_bins ); - v_multc_fixed( Chnl_ImagBuffer_fx[0], hMcMasa->chnlToFoaEvenMtx_fx[1][0], FoaEven_ImagBuffer_fx[1], num_freq_bins ); + v_multc_fixed( Chnl_RealBuffer_fx[0], hMcMasa->chnlToFoaEvenMtx_fx[1][0], FoaEven_RealBuffer_fx[1], num_freq_bins ); // inp_q + v_multc_fixed( Chnl_ImagBuffer_fx[0], hMcMasa->chnlToFoaEvenMtx_fx[1][0], FoaEven_ImagBuffer_fx[1], num_freq_bins ); // inp_q FOR( i = 1; i < numAnalysisChannels; i++ ) { - v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hMcMasa->chnlToFoaEvenMtx_fx[1][i], FoaEven_RealBuffer_fx[1], num_freq_bins ); - v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hMcMasa->chnlToFoaEvenMtx_fx[1][i], FoaEven_ImagBuffer_fx[1], num_freq_bins ); + v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hMcMasa->chnlToFoaEvenMtx_fx[1][i], FoaEven_RealBuffer_fx[1], num_freq_bins ); // inp_q + v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hMcMasa->chnlToFoaEvenMtx_fx[1][i], FoaEven_ImagBuffer_fx[1], num_freq_bins ); // inp_q } /* Z (even setups are handled as horizontal) */ - set_zero_fx( FoaEven_RealBuffer_fx[2], num_freq_bins ); - set_zero_fx( FoaEven_ImagBuffer_fx[2], num_freq_bins ); + set_zero_fx( FoaEven_RealBuffer_fx[2], num_freq_bins ); // inp_q + set_zero_fx( FoaEven_ImagBuffer_fx[2], num_freq_bins ); // inp_q /* X */ - v_multc_fixed( Chnl_RealBuffer_fx[0], hMcMasa->chnlToFoaEvenMtx_fx[3][0], FoaEven_RealBuffer_fx[3], num_freq_bins ); - v_multc_fixed( Chnl_ImagBuffer_fx[0], hMcMasa->chnlToFoaEvenMtx_fx[3][0], FoaEven_ImagBuffer_fx[3], num_freq_bins ); + v_multc_fixed( Chnl_RealBuffer_fx[0], hMcMasa->chnlToFoaEvenMtx_fx[3][0], FoaEven_RealBuffer_fx[3], num_freq_bins ); // inp_q + v_multc_fixed( Chnl_ImagBuffer_fx[0], hMcMasa->chnlToFoaEvenMtx_fx[3][0], FoaEven_ImagBuffer_fx[3], num_freq_bins ); // inp_q FOR( i = 1; i < numAnalysisChannels; i++ ) { - v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hMcMasa->chnlToFoaEvenMtx_fx[3][i], FoaEven_RealBuffer_fx[3], num_freq_bins ); - v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hMcMasa->chnlToFoaEvenMtx_fx[3][i], FoaEven_ImagBuffer_fx[3], num_freq_bins ); + v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hMcMasa->chnlToFoaEvenMtx_fx[3][i], FoaEven_RealBuffer_fx[3], num_freq_bins ); // inp_q + v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hMcMasa->chnlToFoaEvenMtx_fx[3][i], FoaEven_ImagBuffer_fx[3], num_freq_bins ); // inp_q } /* Direction estimation */ @@ -1217,11 +1217,11 @@ void ivas_mcmasa_param_est_enc_fx( FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { /* only real part needed */ - Copy32( intensity_even_real_fx[i], &( hMcMasa->buffer_intensity_real_fx[i][index - 1][0] ), num_freq_bands ); + Copy32( intensity_even_real_fx[i], &( hMcMasa->buffer_intensity_real_fx[i][index - 1][0] ), num_freq_bands ); // hMcMasa->buffer_intensity_real_q } hMcMasa->buffer_intensity_real_q[index - 1] = sub( shl( inp_q, 1 ), 31 ); move16(); - Copy32( reference_power_fx[ts], &( hMcMasa->buffer_energy_fx[( index - 1 ) * num_freq_bands] ), num_freq_bands ); + Copy32( reference_power_fx[ts], &( hMcMasa->buffer_energy_fx[( index - 1 ) * num_freq_bands] ), num_freq_bands ); // ref_e hMcMasa->buffer_energy_q[index - 1] = sub( Q31, ref_e ); move16(); @@ -1361,7 +1361,7 @@ void ivas_mcmasa_param_est_enc_fx( } } } - surrCoh_fx = L_shl( surrCoh_fx, surrCoh_e ); + surrCoh_fx = L_shl( surrCoh_fx, surrCoh_e ); // Q31 surrCoh_e = 0; move16(); surrCoh_fx = Mult_32_32( surrCoh_fx, surrCoh_fx ); @@ -1531,18 +1531,18 @@ void ivas_mcmasa_param_est_enc_fx( tempCoh_fx = BASOP_Util_Add_Mant32Exp( stereoness_fx, stereoness_e, L_negate( L_sub( cohwideness_fx, L_shl( 1, sub( 30, cohPanCoh_e ) ) ) ), cohPanCoh_e, &tempCoh_e ); IF( ( tempCoh_e < 0 ) ) { - tempCoh_fx = L_shl( tempCoh_fx, tempCoh_e ); + tempCoh_fx = L_shl( tempCoh_fx, tempCoh_e ); // Q31 tempCoh_e = 0; move16(); } IF( GT_32( tempCoh_fx, L_shl_sat( 1, sub( 30, tempCoh_e ) ) ) ) { - spreadCoh_fx = tempCoh_fx; + spreadCoh_fx = tempCoh_fx; // tempCoh_e move32(); } ELSE { - spreadCoh_fx = L_shl_sat( 1, sub( 30, tempCoh_e ) ); + spreadCoh_fx = L_shl_sat( 1, sub( 30, tempCoh_e ) ); // Q30 } spreadCoh_e = tempCoh_e; move16(); @@ -1550,14 +1550,14 @@ void ivas_mcmasa_param_est_enc_fx( } IF( ( spreadCoh_e < 0 ) ) { - spreadCoh_fx = L_shl( spreadCoh_fx, spreadCoh_e ); + spreadCoh_fx = L_shl( spreadCoh_fx, spreadCoh_e ); // Q31 spreadCoh_e = 0; move16(); } IF( ( GE_32( spreadCoh_fx, L_shl_sat( 1, sub( 31, spreadCoh_e ) ) ) ) ) { - spreadCoh_fx = L_shl_sat( 1, sub( 31, spreadCoh_e ) ); + spreadCoh_fx = L_shl_sat( 1, sub( 31, spreadCoh_e ) ); // Q31 } IF( ( spreadCoh_fx <= 0 ) ) { @@ -1599,7 +1599,7 @@ void ivas_mcmasa_param_est_enc_fx( IF( GE_32( cohRatio_fx, ONE_IN_Q31 ) ) { - cohRatio_fx = ONE_IN_Q31; + cohRatio_fx = ONE_IN_Q31; // Q31 move32(); } IF( cohRatio_fx <= 0 ) @@ -1734,6 +1734,7 @@ void ivas_mcmasa_param_est_enc_fx( void ivas_mcmasa_dmx_modify_fx( const Word16 n_samples, /* i : input frame length in samples */ Word32 dmx_fx[][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )], /* i/o: downmix signal to be transformed into another format Qx*/ + Word16 dmx_Q[], /* i/o : Q of the intput signal which is being transformed*/ const Word16 n_chnls_dmx_old, /* i : number of downmix channels in the old format Q0 */ const Word16 n_chnls_dmx_new ) /* i : number of downmix channels in the target format Q0*/ { @@ -1749,6 +1750,11 @@ void ivas_mcmasa_dmx_modify_fx( return; } + Word16 Q_min_1_2, Q_min_0_1_2; + + Q_min_1_2 = s_min( dmx_Q[1], dmx_Q[2] ); + Q_min_0_1_2 = s_min( dmx_Q[1], s_min( dmx_Q[2], dmx_Q[0] ) ); + IF( EQ_16( n_chnls_dmx_old, 1 ) ) { /* split mono energy into identical channels */ @@ -1775,14 +1781,24 @@ void ivas_mcmasa_dmx_modify_fx( IF( EQ_16( n_chnls_dmx_new, 1 ) ) { /* sum l and r */ - dmx_fx[0][i] = L_add( dmx_fx[1][i], dmx_fx[2][i] ); + dmx_fx[1][i] = L_shl( dmx_fx[1][i], sub( Q_min_1_2, dmx_Q[1] ) ); + dmx_fx[2][i] = L_shl( dmx_fx[2][i], sub( Q_min_1_2, dmx_Q[2] ) ); + move32(); + move32(); + + dmx_fx[0][i] = L_add( dmx_fx[1][i], dmx_fx[2][i] ); // dmx_q move32(); } ELSE IF( EQ_16( n_chnls_dmx_new, 3 ) ) { + dmx_fx[1][i] = L_shl( dmx_fx[1][i], sub( Q_min_1_2, dmx_Q[1] ) ); + dmx_fx[2][i] = L_shl( dmx_fx[2][i], sub( Q_min_1_2, dmx_Q[2] ) ); + move32(); + move32(); + dmx_fx[0][i] = L_shr( L_add( dmx_fx[1][i], dmx_fx[2][i] ), 1 ); - dmx_fx[1][i] = L_sub( dmx_fx[1][i], dmx_fx[0][i] ); - dmx_fx[2][i] = L_sub( dmx_fx[2][i], dmx_fx[0][i] ); + dmx_fx[1][i] = L_sub( dmx_fx[1][i], dmx_fx[0][i] ); // dmx_q + dmx_fx[2][i] = L_sub( dmx_fx[2][i], dmx_fx[0][i] ); // dmx_q move32(); move32(); move32(); @@ -1796,15 +1812,31 @@ void ivas_mcmasa_dmx_modify_fx( IF( EQ_16( n_chnls_dmx_new, 1 ) ) { /* sum all channels */ + + dmx_fx[0][i] = L_shl( dmx_fx[0][i], sub( Q_min_0_1_2, dmx_Q[1] ) ); + dmx_fx[1][i] = L_shl( dmx_fx[1][i], sub( Q_min_0_1_2, dmx_Q[1] ) ); + dmx_fx[2][i] = L_shl( dmx_fx[2][i], sub( Q_min_0_1_2, dmx_Q[2] ) ); + move32(); + move32(); + move32(); + dmx_fx[0][i] = L_add( L_add( dmx_fx[0][i], dmx_fx[1][i] ), dmx_fx[2][i] ); move32(); } ELSE IF( EQ_16( n_chnls_dmx_new, 2 ) ) { + + dmx_fx[0][i] = L_shl( dmx_fx[0][i], sub( Q_min_0_1_2, dmx_Q[1] ) ); + dmx_fx[1][i] = L_shl( dmx_fx[1][i], sub( Q_min_0_1_2, dmx_Q[1] ) ); + dmx_fx[2][i] = L_shl( dmx_fx[2][i], sub( Q_min_0_1_2, dmx_Q[2] ) ); + move32(); + move32(); + move32(); + /* mix center into sides */ dmx_fx[0][i] = Mpy_32_16_1( dmx_fx[0][i], INV_SQRT2_FX_Q15 ); - dmx_fx[1][i] = L_add( dmx_fx[1][i], dmx_fx[0][i] ); - dmx_fx[2][i] = L_add( dmx_fx[2][i], dmx_fx[0][i] ); + dmx_fx[1][i] = L_add( dmx_fx[1][i], dmx_fx[0][i] ); // dmx_q + dmx_fx[2][i] = L_add( dmx_fx[2][i], dmx_fx[0][i] ); // dmx_q move32(); move32(); move32(); @@ -1812,6 +1844,39 @@ void ivas_mcmasa_dmx_modify_fx( } } + // Q updation for different channels + + IF( EQ_16( n_chnls_dmx_old, 1 ) ) + { + /* split mono energy into identical channels */ + IF( EQ_16( n_chnls_dmx_new, 2 ) ) + { + dmx_Q[1] = dmx_Q[0]; + move16(); + dmx_Q[2] = dmx_Q[0]; + move16(); + } + } + ELSE IF( EQ_16( n_chnls_dmx_old, 2 ) ) + { + dmx_Q[0] = Q_min_1_2; + move16(); + dmx_Q[1] = Q_min_1_2; + move16(); + dmx_Q[2] = Q_min_1_2; + move16(); + } + ELSE IF( EQ_16( n_chnls_dmx_old, 3 ) ) + { + dmx_Q[0] = Q_min_0_1_2; + move16(); + dmx_Q[1] = Q_min_0_1_2; + move16(); + dmx_Q[2] = Q_min_0_1_2; + move16(); + } + + return; } @@ -1822,7 +1887,7 @@ void ivas_mcmasa_dmx_modify_fx( /* Compute downmix */ static void ivas_mcmasa_dmx_fx( MCMASA_ENC_HANDLE hMcMasa, - Word32 *data_fx[], + Word32 *data_fx[], // Q(31 - data_e) Word16 data_e, const Word16 input_frame, const Word16 nchan_transport, @@ -1880,7 +1945,7 @@ static void ivas_mcmasa_dmx_fx( FOR( i = 0; i < input_frame; i++ ) { - data_fx[0][i] = L_add( data_fx[0][i], data_fx[leftIndex][i] ); + data_fx[0][i] = L_add( data_fx[0][i], data_fx[leftIndex][i] ); // data_e move32(); data_fx[1][i] = L_add( data_fx[1][i], data_fx[rightIndex][i] ); move32(); @@ -1893,9 +1958,9 @@ static void ivas_mcmasa_dmx_fx( { dmx_c_fx = W_extract_h( W_mult_32_32( INV_SQRT2_FX, data_fx[2][i] ) ); move32(); - data_fx[0][i] = L_add( dmx_c_fx, data_fx[0][i] ); + data_fx[0][i] = L_add( dmx_c_fx, data_fx[0][i] ); // data_e move32(); - data_fx[1][i] = L_add( dmx_c_fx, data_fx[1][i] ); + data_fx[1][i] = L_add( dmx_c_fx, data_fx[1][i] ); // data_e move32(); } } @@ -1959,10 +2024,10 @@ static void ivas_mcmasa_dmx_fx( FOR( j = 0; j < nchan_transport; j++ ) { - data_fx[j][i] = Mpy_32_32( instEQ_fx, data_fx[j][i] ); + data_fx[j][i] = Mpy_32_32( instEQ_fx, data_fx[j][i] ); // data_e + instEQ_e - 31 move32(); move32(); - data_fx[j][i] = L_shl( data_fx[j][i], instEQ_e ); + data_fx[j][i] = L_shl( data_fx[j][i], instEQ_e ); // data_e + 2*instEQ_e - 31 } } @@ -2143,8 +2208,8 @@ static void computeVerticalDiffuseness_fx( return; } static void computeEvenLayout_fx( - const Word32 *ls_azimuth, - Word32 *ls_azimuth_even, + const Word32 *ls_azimuth, // Q22 + Word32 *ls_azimuth_even, // Q22 const Word16 numChannels ) { Word16 i; @@ -2213,7 +2278,7 @@ static void computeEvenLayout_fx( } static void computeLfeEnergy_fx( MCMASA_ENC_HANDLE hMcMasa, - Word32 *data_fx[], + Word32 *data_fx[], // q_inp const Word16 input_frame, Word16 q_inp ) { @@ -2234,8 +2299,8 @@ static void computeLfeEnergy_fx( IF( hMcMasa->separateChannelEnabled ) { - Copy32( data_fx[lfeChannelIndex], &( hMcMasa->delay_buffer_lfe[0][hMcMasa->num_samples_delay_comp - hMcMasa->offset_comp] ), hMcMasa->offset_comp ); - Copy32( data_fx[separateChannelIndex], &( hMcMasa->delay_buffer_lfe[1][hMcMasa->num_samples_delay_comp - hMcMasa->offset_comp] ), hMcMasa->offset_comp ); + Copy32( data_fx[lfeChannelIndex], &( hMcMasa->delay_buffer_lfe[0][hMcMasa->num_samples_delay_comp - hMcMasa->offset_comp] ), hMcMasa->offset_comp ); // q_inp + Copy32( data_fx[separateChannelIndex], &( hMcMasa->delay_buffer_lfe[1][hMcMasa->num_samples_delay_comp - hMcMasa->offset_comp] ), hMcMasa->offset_comp ); // q_inp } ELSE { @@ -2257,10 +2322,10 @@ static void computeLfeEnergy_fx( Word32 delayedInputSignal[2][L_FRAME48k]; Word32 lowPassSignal[2][L_FRAME48k]; - Copy32( &( hMcMasa->delay_buffer_lfe[0][0] ), &( delayedInputSignal[0][0] ), hMcMasa->num_slots_delay_comp * l_ts ); - Copy32( data_fx[lfeChannelIndex] + hMcMasa->offset_comp, &( delayedInputSignal[0][hMcMasa->num_slots_delay_comp * l_ts] ), ( MDFT_NO_COL_MAX - hMcMasa->num_slots_delay_comp ) * l_ts ); - Copy32( &( hMcMasa->delay_buffer_lfe[1][0] ), &( delayedInputSignal[1][0] ), hMcMasa->num_slots_delay_comp * l_ts ); - Copy32( data_fx[separateChannelIndex] + hMcMasa->offset_comp, &( delayedInputSignal[1][hMcMasa->num_slots_delay_comp * l_ts] ), ( MDFT_NO_COL_MAX - hMcMasa->num_slots_delay_comp ) * l_ts ); + Copy32( &( hMcMasa->delay_buffer_lfe[0][0] ), &( delayedInputSignal[0][0] ), hMcMasa->num_slots_delay_comp * l_ts ); // q_inp + Copy32( data_fx[lfeChannelIndex] + hMcMasa->offset_comp, &( delayedInputSignal[0][hMcMasa->num_slots_delay_comp * l_ts] ), ( MDFT_NO_COL_MAX - hMcMasa->num_slots_delay_comp ) * l_ts ); // q_inp + Copy32( &( hMcMasa->delay_buffer_lfe[1][0] ), &( delayedInputSignal[1][0] ), hMcMasa->num_slots_delay_comp * l_ts ); // q_inp + Copy32( data_fx[separateChannelIndex] + hMcMasa->offset_comp, &( delayedInputSignal[1][hMcMasa->num_slots_delay_comp * l_ts] ), ( MDFT_NO_COL_MAX - hMcMasa->num_slots_delay_comp ) * l_ts ); // q_inp lowpassCoef = L_shl( div_w( 1, (Word32) hMcMasa->ringBufferSize ), Q6 ); // Q.37(31+6) @@ -2347,8 +2412,8 @@ static void computeLfeEnergy_fx( IF( hMcMasa->separateChannelEnabled ) { - Copy32( data_fx[lfeChannelIndex] + ( input_frame - hMcMasa->num_samples_delay_comp + hMcMasa->offset_comp ), &( hMcMasa->delay_buffer_lfe[0][0] ), sub( hMcMasa->num_samples_delay_comp, hMcMasa->offset_comp ) ); - Copy32( data_fx[separateChannelIndex] + ( input_frame - hMcMasa->num_samples_delay_comp + hMcMasa->offset_comp ), &( hMcMasa->delay_buffer_lfe[1][0] ), sub( hMcMasa->num_samples_delay_comp, hMcMasa->offset_comp ) ); + Copy32( data_fx[lfeChannelIndex] + ( input_frame - hMcMasa->num_samples_delay_comp + hMcMasa->offset_comp ), &( hMcMasa->delay_buffer_lfe[0][0] ), sub( hMcMasa->num_samples_delay_comp, hMcMasa->offset_comp ) ); // q_in + Copy32( data_fx[separateChannelIndex] + ( input_frame - hMcMasa->num_samples_delay_comp + hMcMasa->offset_comp ), &( hMcMasa->delay_buffer_lfe[1][0] ), sub( hMcMasa->num_samples_delay_comp, hMcMasa->offset_comp ) ); // q_in } return; diff --git a/lib_enc/ivas_mct_core_enc.c b/lib_enc/ivas_mct_core_enc.c index 6b336708d..c3096d205 100644 --- a/lib_enc/ivas_mct_core_enc.c +++ b/lib_enc/ivas_mct_core_enc.c @@ -78,11 +78,11 @@ static void FindChannelRatio_fx( IF( NE_32( sts[i]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) { // sum_nrg += nrg[i]; - sum_nrg = BASOP_Util_Add_Mant32Exp( sum_nrg, sum_e, nrg[i], nrg_e[i], &sum_e ); + sum_nrg = BASOP_Util_Add_Mant32Exp( sum_nrg, sum_e, nrg[i], nrg_e[i], &sum_e ); // sum_e } } // sum_nrg = 1.0f / max( sum_nrg, EPSILON ); - sum_nrg = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_add_sat( sum_nrg, EPSILON_FX ), &inv_e ); + sum_nrg = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_add_sat( sum_nrg, EPSILON_FX ), &inv_e ); // inv_e inv_e = add( inv_e, sub( 0, sum_e ) ); FOR( i = 0; i < nChannels; i++ ) @@ -137,7 +137,7 @@ static void AdjustChannelRatios_fx( move32(); FOR( i = 0; i < nChannels; i++ ) { - sum_ratio = L_add( sum_ratio, temp_brs[i] ); + sum_ratio = L_add( sum_ratio, temp_brs[i] ); // Q0 } FOR( i = 0; i < nChannels; i++ ) { @@ -145,7 +145,7 @@ static void AdjustChannelRatios_fx( // force_ch_bit_ratios[i] = min( BITRATE_MCT_RATIO_RANGE - 1, max( 1, (uint16_t) ( BITRATE_MCT_RATIO_RANGE * cur_ratio + 0.5f ) ) ); cur_ratio = BASOP_Util_Divide3232_Scale( temp_brs[i], sum_ratio, &cur_ratio_e ); - cur_ratio = shr_r( cur_ratio, sub( 11, cur_ratio_e ) ); + cur_ratio = shr_r( cur_ratio, sub( 11, cur_ratio_e ) ); // Q11 force_ch_bit_ratios[i] = s_min( BITRATE_MCT_RATIO_RANGE - 1, s_max( 1, (UWord16) ( cur_ratio ) ) ); move16(); } @@ -207,8 +207,8 @@ static void AdjustChannelRatios_fx( // cur_ratio = chBitRatios[i] / sum_ratio; // chBitRatios[i] = min( BITRATE_MCT_RATIO_RANGE - 1, max( 1, (uint16_t) ( BITRATE_MCT_RATIO_RANGE * cur_ratio + 0.5f ) ) ); - cur_ratio = div_s( chBitRatios[i], extract_l( sum_ratio ) ); - chBitRatios[i] = s_min( BITRATE_MCT_RATIO_RANGE - 1, s_max( 1, (UWord16) mult_r( BITRATE_MCT_RATIO_RANGE, cur_ratio ) ) ); + cur_ratio = div_s( chBitRatios[i], extract_l( sum_ratio ) ); // Q15 + chBitRatios[i] = s_min( BITRATE_MCT_RATIO_RANGE - 1, s_max( 1, (UWord16) mult_r( BITRATE_MCT_RATIO_RANGE, cur_ratio ) ) ); // Q0 move16(); } @@ -282,8 +282,8 @@ void ivas_mct_core_enc_fx( FOR( ch = 0; ch < nChannels; ch++ ) { set32_fx( inv_spectrum_long_fx[ch], 0, L_FRAME48k ); - set32_fx( powerSpec_fx[ch], 0, L_FRAME48k ); - set32_fx( powerSpecMsInv_long_fx[ch], 0, L_FRAME48k ); + set32_fx( powerSpec_fx[ch], 0, L_FRAME48k ); // tmp_q_powSpec + set32_fx( powerSpecMsInv_long_fx[ch], 0, L_FRAME48k ); // tmp_q_powSpecInv inv_mdst_spectrum_fx[ch][0] = powerSpecMsInv_fx[ch][0] = powerSpecMsInv_long_fx[ch]; inv_mdst_spectrum_fx[ch][1] = powerSpecMsInv_fx[ch][1] = powerSpecMsInv_long_fx[ch] + N_TCX10_MAX; @@ -310,7 +310,7 @@ void ivas_mct_core_enc_fx( mdst_spectrum_fx[i][0] = hMCT->p_mdst_spectrum_long_fx[cpe_id][ch]; mdst_spectrum_fx[i][1] = hMCT->p_mdst_spectrum_long_fx[cpe_id][ch] + N_TCX10_MAX; - orig_spectrum_fx[i][0] = hMCT->p_orig_spectrum_long_fx[cpe_id][ch]; + orig_spectrum_fx[i][0] = hMCT->p_orig_spectrum_long_fx[cpe_id][ch]; // q_origSpec orig_spectrum_fx[i][1] = hMCT->p_orig_spectrum_long_fx[cpe_id][ch] + N_TCX10_MAX; sp_aud_decision0[i] = hCPE[cpe_id]->hCoreCoder[0]->sp_aud_decision0; @@ -436,8 +436,8 @@ void ivas_mct_core_enc_fx( W_tmp = W_mac_32_32( W_mult_32_32( mdst_spectrum_fx[ch][n][i], mdst_spectrum_fx[ch][n][i] ), sts[ch]->hTcxEnc->spectrum_fx[n][i], sts[ch]->hTcxEnc->spectrum_fx[n][i] ); tmp_s = sub( W_norm( W_tmp ), 1 ); W_tmp = W_shl( W_tmp, tmp_s ); - powerSpec_fx[ch][add( i, imult1616( n, L_subframeTCX ) )] = W_extract_h( W_tmp ); - tmp_q_powSpec[add( i, imult1616( n, L_subframeTCX ) )] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 + powerSpec_fx[ch][( i + ( n * L_subframeTCX ) )] = W_extract_h( W_tmp ); + tmp_q_powSpec[( i + ( n * L_subframeTCX ) )] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 move32(); move16(); @@ -501,8 +501,10 @@ void ivas_mct_core_enc_fx( W_tmp = W_mac_32_32( W_mult_32_32( mdst_fx, mdst_fx ), L_shr( sts[ch]->hTcxEnc->spectrum_fx[n][i], 1 ), L_shr( sts[ch]->hTcxEnc->spectrum_fx[n][i], 1 ) ); // Q = 2 * (q_spec - 1) + 1 tmp_s = W_norm( W_tmp ); W_tmp = W_shl( W_tmp, tmp_s ); + powerSpec_fx[ch][i + ( n * L_subframeTCX )] = W_extract_h( W_tmp ); tmp_q_powSpec[i + ( n * L_subframeTCX )] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 33 ); // Q = 2 * (q_spec - 1) + 1 + tmp_s - 32 + move32(); move16(); } @@ -510,8 +512,8 @@ void ivas_mct_core_enc_fx( W_tmp = W_mult_32_32( sts[ch]->hTcxEnc->spectrum_fx[n][L_subframeTCX - 1], sts[ch]->hTcxEnc->spectrum_fx[n][L_subframeTCX - 1] ); tmp_s = sub( W_norm( W_tmp ), 1 ); W_tmp = W_shl( W_tmp, tmp_s ); - powerSpec_fx[ch][add( sub( L_subframeTCX, 1 ), imult1616( n, L_subframeTCX ) )] = W_extract_h( W_tmp ); - tmp_q_powSpec[add( sub( L_subframeTCX, 1 ), imult1616( n, L_subframeTCX ) )] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 + powerSpec_fx[ch][( ( L_subframeTCX - 1 ) + ( n * L_subframeTCX ) )] = W_extract_h( W_tmp ); + tmp_q_powSpec[( ( L_subframeTCX - 1 ) + ( n * L_subframeTCX ) )] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 move32(); move16(); } @@ -543,7 +545,7 @@ void ivas_mct_core_enc_fx( FOR( i = 0; i < L_subframeTCX; i++ ) { powerSpecMsInv_fx[ch][n][i] = L_shr( powerSpecMsInv_fx[ch][n][i], sub( tmp_q_psi[n][i], q_powSpec[ch] ) ); - powerSpec_fx[ch][add( i, imult1616( n, L_subframeTCX ) )] = L_shr( powerSpec_fx[ch][add( i, imult1616( n, L_subframeTCX ) )], sub( tmp_q_powSpec[i], q_powSpec[ch] ) ); + powerSpec_fx[ch][( i + ( n * L_subframeTCX ) )] = L_shr( powerSpec_fx[ch][( i + ( n * L_subframeTCX ) )], sub( tmp_q_powSpec[i], q_powSpec[ch] ) ); move32(); move32(); } diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 98bf7a3a5..a43be5c22 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -58,7 +58,7 @@ static ivas_error ivas_mc_enc_reconfig_fx( Encoder_Struct *st_ivas, const Word16 * Set hMCT handle parameters *-------------------------------------------------------------------*/ -static void set_mct_enc_params( +static void set_mct_enc_params_fx( MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ const Word32 ivas_total_brate, /* i : IVAS total bitrate */ const IVAS_FORMAT ivas_format, /* i : IVAS_format */ @@ -79,7 +79,7 @@ static void set_mct_enc_params( FOR( n = 0; n < MCT_MAX_CHANNELS; n++ ) { - set32_fx( hMCT->lastxCorrMatrix_fx[n], 0, MCT_MAX_CHANNELS ); + set32_fx( hMCT->lastxCorrMatrix_fx[n], 0, MCT_MAX_CHANNELS ); // hMCT->lastxCorrMatrix_e } hMCT->lastxCorrMatrix_e = 0; move16(); @@ -129,7 +129,7 @@ static void map_input_to_cpe_channels_ivas_fx( FOR( n = 0; n < LFE_CHANNEL - 1; n++ ) { - pdata[i] = data[n]; + pdata[i] = data[n]; // Qx i = add( i, 1 ); } test(); @@ -138,7 +138,7 @@ static void map_input_to_cpe_channels_ivas_fx( { FOR( n = LFE_CHANNEL + 1; n < nchan_transport; n++ ) { - pdata[i] = data[n]; + pdata[i] = data[n]; // Qx i = add( i, 1 ); } pdata[i] = data[LFE_CHANNEL - 1]; @@ -147,7 +147,7 @@ static void map_input_to_cpe_channels_ivas_fx( { FOR( ; n < nchan_transport; n++ ) { - pdata[i] = data[n]; + pdata[i] = data[n]; // Qx i = add( i, 1 ); } } @@ -282,29 +282,50 @@ ivas_error ivas_mct_enc_fx( } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // Float to Fixed, to be removed Word16 q_spec = Q31; Word16 q_origSpec = Q31; Word16 q_com = Q31, q_com_spec = Q31; move16(); move16(); + move16(); + move16(); Word16 length, ch, nCPE; - nCPE = ( hMCT->nchan_out_woLFE % 2 ) == 0 ? ( hMCT->nchan_out_woLFE / 2 ) : ( hMCT->nchan_out_woLFE / 2 ) + 1; + IF( ( hMCT->nchan_out_woLFE % 2 ) == 0 ) + { + nCPE = idiv1616( hMCT->nchan_out_woLFE, 2 ); + } + ELSE + { + nCPE = add( idiv1616( hMCT->nchan_out_woLFE, 2 ), 1 ); + } - for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { - for ( ch = 0; ch < CPE_CHANNELS; ch++ ) + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { - if ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + IF( EQ_32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) { - continue; + CONTINUE; } - length = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX / ( ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ); - if ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->last_core == ACELP_CORE ) + + // length = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX / ( ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ); + + IF( EQ_16( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->tcxMode, TCX_20 ) ) { - length += length / 4; + length = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX; + move16(); } - for ( Word16 k = 0; k <= ( ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) + ELSE + { + length = idiv1616( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX, NB_DIV ); // st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX / NB_DIV + } + + IF( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->last_core == ACELP_CORE ) + { + length = add( length, idiv1616( length, 4 ) ); + } + + FOR( Word16 k = 0; k <= ( ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) { IF( hMCT->p_mdst_spectrum_long_fx[cpe_id][ch] ) { @@ -332,7 +353,7 @@ ivas_error ivas_mct_enc_fx( } IF( hMCT->p_orig_spectrum_long_fx[cpe_id][ch] ) { - Scale_sig32( hMCT->p_orig_spectrum_long_fx[cpe_id][ch], L_FRAME48k, sub( q_origSpec, hMCT->q_orig_spectrum_long_fx[cpe_id][ch] ) ); + Scale_sig32( hMCT->p_orig_spectrum_long_fx[cpe_id][ch], L_FRAME48k, sub( q_origSpec, hMCT->q_orig_spectrum_long_fx[cpe_id][ch] ) ); // q_origSpec hMCT->q_orig_spectrum_long_fx[cpe_id][ch] = q_origSpec; move16(); } @@ -340,33 +361,39 @@ ivas_error ivas_mct_enc_fx( } hMCT->q_orig_spectrum_long_com = q_origSpec; move16(); - for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { - for ( ch = 0; ch < CPE_CHANNELS; ch++ ) + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { - length = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX / ( ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ); - if ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->last_core == ACELP_CORE ) + // length = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX / ( ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ); + + IF( EQ_16( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->tcxMode, TCX_20 ) ) { - length += length / 4; + length = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX; + move16(); } - for ( Word16 k = 0; k <= ( ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) + ELSE + { + length = idiv1616( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX, NB_DIV ); // st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX / NB_DIV + } + + IF( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->last_core == ACELP_CORE ) + { + length = add( length, idiv1616( length, 4 ) ); + } + + FOR( Word16 k = 0; k <= ( ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) { - /*if ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum[0] ) - { - floatToFixed_arrL32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum[k], st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_fx[k], q_spec, length ); - st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[0] = sub( Q31, q_spec ); - st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[1] = sub( Q31, q_spec ); - }*/ IF( hMCT->p_mdst_spectrum_long_fx[cpe_id][ch] ) { - Scale_sig32( &hMCT->p_mdst_spectrum_long_fx[cpe_id][ch][k * N_TCX10_MAX], length, sub( q_spec, hMCT->q_mdst_spectrum_long_fx[cpe_id][ch][k] ) ); + Scale_sig32( &hMCT->p_mdst_spectrum_long_fx[cpe_id][ch][k * N_TCX10_MAX], length, sub( q_spec, hMCT->q_mdst_spectrum_long_fx[cpe_id][ch][k] ) ); // q_spec hMCT->q_mdst_spectrum_long_fx[cpe_id][ch][k] = q_spec; move16(); } } } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Encoder_State *sts_tmp[MCT_MAX_CHANNELS]; Encoder_State *st; Word16 i; @@ -387,12 +414,9 @@ ivas_error ivas_mct_enc_fx( i = add( i, 1 ); CONTINUE; } - i++; + i = add( i, 1 ); } } -#endif -#endif // 1 - FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { @@ -417,7 +441,7 @@ ivas_error ivas_mct_enc_fx( { length = idiv1616( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX, NB_DIV ); } - scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_fx, N_MAX, sub( q_spec, sub( 31, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_e ) ) ); + scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_fx, N_MAX, sub( q_spec, sub( 31, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_e ) ) ); // q_spec st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[0] = sub( 31, q_spec ); move16(); @@ -456,10 +480,10 @@ ivas_error ivas_mct_enc_fx( } ELSE { - scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_fx[0], length, sub( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[0], e_spec ) ); - scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_fx[0] + length, sub( N_TCX10_MAX, length ), sub( sub( 31, q_spec ), e_spec ) ); - scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_fx[1], length, sub( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[0], e_spec ) ); - scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_fx[1] + length, sub( N_MAX - N_TCX10_MAX, length ), sub( sub( 31, q_spec ), e_spec ) ); + scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_fx[0], length, sub( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[0], e_spec ) ); // st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[0] + scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_fx[0] + length, sub( N_TCX10_MAX, length ), sub( sub( 31, q_spec ), e_spec ) ); // 31 - q_spec + scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_fx[1], length, sub( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[0], e_spec ) ); // st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[0] + scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_fx[1] + length, sub( N_MAX - N_TCX10_MAX, length ), sub( sub( 31, q_spec ), e_spec ) ); // 31 - q_spec st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_e = e_spec; move16(); } @@ -470,45 +494,54 @@ ivas_error ivas_mct_enc_fx( } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS q_spec = 31; move16(); - for ( ch = 0; ch < hMCT->nchan_out_woLFE; ch++ ) + FOR( ch = 0; ch < hMCT->nchan_out_woLFE; ch++ ) { - length = sts_tmp[ch]->hTcxEnc->L_frameTCX / ( ( sts_tmp[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ); - if ( sts_tmp[ch]->last_core == ACELP_CORE ) + // length = sts_tmp[ch]->hTcxEnc->L_frameTCX / ( ( sts_tmp[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ); + + IF( EQ_16( sts_tmp[ch]->hTcxEnc->tcxMode, TCX_20 ) ) + { + length = sts_tmp[ch]->hTcxEnc->L_frameTCX; + move16(); + } + ELSE { - length += length / 4; + length = idiv1616( sts_tmp[ch]->hTcxEnc->L_frameTCX, NB_DIV ); // st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX / NB_DIV + } + + IF( sts_tmp[ch]->last_core == ACELP_CORE ) + { + length = add( length, idiv1616( length, 4 ) ); } } -#endif + /* Spectrum quantization and coding */ FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { hCPE = st_ivas->hCPE[cpe_id]; - if ( cpe_id > 0 ) + IF( cpe_id > 0 ) { hCPE->hCoreCoder[0]->hBstr->ind_list = st_ivas->hCPE[cpe_id - 1]->hCoreCoder[1]->hBstr->ind_list + st_ivas->hCPE[cpe_id - 1]->hCoreCoder[1]->hBstr->nb_ind_tot; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Encoder_State /**st,*/ **sts; FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { sts = hCPE->hCoreCoder; st = sts[ch]; } -#endif + ivas_mdct_quant_coder_fx( hCPE, hMCT->tnsBits[cpe_id], hMCT->tnsSize[cpe_id], hMCT->p_param[cpe_id], 1 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { sts = hCPE->hCoreCoder; st = sts[ch]; } -#endif + /* update input samples buffer (as done in ivas_cpe_enc() for other than MCT coding) */ FOR( n = 0; n < CPE_CHANNELS; n++ ) { @@ -516,22 +549,21 @@ ivas_error ivas_mct_enc_fx( hCPE->hCoreCoder[n]->q_old_inp = hCPE->hCoreCoder[n]->q_inp; move16(); /* common encoder updates */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + st = hCPE->hCoreCoder[n]; IF( st->hTcxEnc != NULL ) { st->hTcxEnc->exp_buf_speech_ltp = 31; /*Q0*/ } -#endif + updt_enc_common_ivas_fx( st, Q_new_out[cpe_id][n] ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + IF( st->hTcxEnc != NULL ) { - Scale_sig( st->hTcxEnc->buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, st->hTcxEnc->exp_buf_speech_ltp ); + Scale_sig( st->hTcxEnc->buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, st->hTcxEnc->exp_buf_speech_ltp ); // st->hTcxEnc->exp_buf_speech_ltp } -#endif } } @@ -545,7 +577,7 @@ ivas_error ivas_mct_enc_fx( * Create, allocate and initialize IVAS encoder MCT handle *-------------------------------------------------------------------------*/ -ivas_error create_mct_enc( +ivas_error create_mct_enc_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { @@ -677,7 +709,7 @@ ivas_error create_mct_enc( * Initializations *-----------------------------------------------------------------*/ - set_mct_enc_params( hMCT, ivas_total_brate, ivas_format, 1 ); + set_mct_enc_params_fx( hMCT, ivas_total_brate, ivas_format, 1 ); st_ivas->hMCT = hMCT; @@ -869,7 +901,7 @@ ivas_error mct_enc_reconfigure_fx( * Initializations *-----------------------------------------------------------------*/ - set_mct_enc_params( hMCT, ivas_total_brate, ivas_format, b_nchan_change ); + set_mct_enc_params_fx( hMCT, ivas_total_brate, ivas_format, b_nchan_change ); return error; } @@ -881,7 +913,7 @@ ivas_error mct_enc_reconfigure_fx( * Close MCT *-------------------------------------------------------------------------*/ -void ivas_mct_enc_close( +void ivas_mct_enc_close_fx( MCT_ENC_HANDLE *hMCT /* i/o: MCT encoder structure */ ) { @@ -1013,11 +1045,11 @@ static ivas_error ivas_mc_enc_reconfig_fx( IF( st_ivas->hLFE != NULL ) { /* LFE handle */ - ivas_lfe_enc_close( &( st_ivas->hLFE ) ); + ivas_lfe_enc_close_fx( &( st_ivas->hLFE ) ); } /* create LFE handle */ - IF( NE_32( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, st_ivas->hEncoderConfig->input_Fs ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_create_lfe_enc_fx( &st_ivas->hLFE, st_ivas->hEncoderConfig->input_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -1025,12 +1057,12 @@ static ivas_error ivas_mc_enc_reconfig_fx( /*De-allocate handles for other MC modes*/ ivas_param_mc_enc_close_fx( &( st_ivas->hParamMC ), st_ivas->hEncoderConfig->input_Fs ); - ivas_mc_paramupmix_enc_close( &( st_ivas->hMCParamUpmix ), st_ivas->hEncoderConfig->input_Fs ); + ivas_mc_paramupmix_enc_close_fx( &( st_ivas->hMCParamUpmix ), st_ivas->hEncoderConfig->input_Fs ); /* De-allocate McMasa-related handles */ ivas_mcmasa_enc_close_fx( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); - ivas_masa_enc_close( &( st_ivas->hMasa ) ); + ivas_masa_enc_close_fx( &( st_ivas->hMasa ) ); ivas_qmetadata_close_fx( &st_ivas->hQMetaData ); } @@ -1049,11 +1081,11 @@ static ivas_error ivas_mc_enc_reconfig_fx( IF( st_ivas->hLFE != NULL ) { /* LFE handle */ - ivas_lfe_enc_close( &( st_ivas->hLFE ) ); + ivas_lfe_enc_close_fx( &( st_ivas->hLFE ) ); } /* create LFE handle */ - IF( NE_32( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, st_ivas->hEncoderConfig->input_Fs ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_create_lfe_enc_fx( &st_ivas->hLFE, st_ivas->hEncoderConfig->input_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -1061,7 +1093,7 @@ static ivas_error ivas_mc_enc_reconfig_fx( IF( NE_32( last_mc_mode, MC_MODE_PARAMUPMIX ) ) { - IF( NE_32( ( error = ivas_mc_paramupmix_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_mc_paramupmix_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1072,7 +1104,7 @@ static ivas_error ivas_mc_enc_reconfig_fx( /* De-allocate McMasa-related handles */ ivas_mcmasa_enc_close_fx( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); - ivas_masa_enc_close( &( st_ivas->hMasa ) ); + ivas_masa_enc_close_fx( &( st_ivas->hMasa ) ); ivas_qmetadata_close_fx( &st_ivas->hQMetaData ); } @@ -1098,17 +1130,17 @@ static ivas_error ivas_mc_enc_reconfig_fx( IF( st_ivas->hMasa != NULL ) { - ivas_masa_enc_close( &( st_ivas->hMasa ) ); + ivas_masa_enc_close_fx( &( st_ivas->hMasa ) ); st_ivas->hMasa = NULL; } - ivas_mc_paramupmix_enc_close( &( st_ivas->hMCParamUpmix ), st_ivas->hEncoderConfig->input_Fs ); + ivas_mc_paramupmix_enc_close_fx( &( st_ivas->hMCParamUpmix ), st_ivas->hEncoderConfig->input_Fs ); test(); IF( EQ_32( last_mc_mode, MC_MODE_PARAMUPMIX ) && st_ivas->hLFE != NULL ) { /* LFE handle */ - ivas_lfe_enc_close( &( st_ivas->hLFE ) ); + ivas_lfe_enc_close_fx( &( st_ivas->hLFE ) ); } ivas_qmetadata_close_fx( &st_ivas->hQMetaData ); @@ -1117,14 +1149,14 @@ static ivas_error ivas_mc_enc_reconfig_fx( test(); IF( EQ_32( last_mc_mode, MC_MODE_MCT ) && LE_16( st_ivas->nchan_transport, CPE_CHANNELS ) ) { - ivas_mct_enc_close( &( st_ivas->hMCT ) ); + ivas_mct_enc_close_fx( &( st_ivas->hMCT ) ); } test(); IF( EQ_32( last_mc_mode, MC_MODE_MCT ) && st_ivas->hLFE != NULL ) { /* LFE handle */ - ivas_lfe_enc_close( &( st_ivas->hLFE ) ); + ivas_lfe_enc_close_fx( &( st_ivas->hLFE ) ); } } ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) @@ -1138,7 +1170,7 @@ static ivas_error ivas_mc_enc_reconfig_fx( return error; } - IF( NE_32( ( error = ivas_masa_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_masa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1158,21 +1190,21 @@ static ivas_error ivas_mc_enc_reconfig_fx( ivas_param_mc_enc_close_fx( &( st_ivas->hParamMC ), st_ivas->hEncoderConfig->input_Fs ); - ivas_mc_paramupmix_enc_close( &( st_ivas->hMCParamUpmix ), st_ivas->hEncoderConfig->input_Fs ); + ivas_mc_paramupmix_enc_close_fx( &( st_ivas->hMCParamUpmix ), st_ivas->hEncoderConfig->input_Fs ); test(); IF( EQ_32( last_mc_mode, MC_MODE_PARAMUPMIX ) && st_ivas->hLFE != NULL ) { /* LFE handle */ - ivas_lfe_enc_close( &( st_ivas->hLFE ) ); + ivas_lfe_enc_close_fx( &( st_ivas->hLFE ) ); } IF( EQ_32( last_mc_mode, MC_MODE_MCT ) ) { /* LFE handle */ - ivas_lfe_enc_close( &( st_ivas->hLFE ) ); + ivas_lfe_enc_close_fx( &( st_ivas->hLFE ) ); - ivas_mct_enc_close( &( st_ivas->hMCT ) ); + ivas_mct_enc_close_fx( &( st_ivas->hMCT ) ); } } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index e9b06d77d..64338184e 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -87,7 +87,7 @@ typedef struct stereo_itd_data_struct Word16 prev_xcorr_lb_fx_e; Word32 E_band_n_fx[STEREO_DFT_ITD_VAD_BAND_NUM]; /*Q0*/ Word32 xcorr_smooth_fx[STEREO_DFT_N_32k_ENC]; - Word16 xcorr_smooth_fx_e; + Word16 xcorr_smooth_fx_e[STEREO_DFT_N_32k_ENC]; Word32 lp_phat_peak_fx; /* low-pass GCC PHAT peak value */ // Q31 // Word16 q_itd; Word32 deltaItd_fx[STEREO_DFT_ENC_DFT_NB]; // Q16 diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index e2b459765..0acc28a78 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -737,8 +737,7 @@ void stereo_enc_itd_init_fx( set16_fx( hItd->td_itd_32k, 0, STEREO_DFT_ENC_DFT_NB ); set16_fx( hItd->itd_index, 0, STEREO_DFT_ENC_DFT_NB ); set32_fx( hItd->xcorr_smooth_fx, 0, STEREO_DFT_N_32k_ENC ); - hItd->xcorr_smooth_fx_e = 0; - move16(); + set16_fx( hItd->xcorr_smooth_fx_e, 0, STEREO_DFT_N_32k_ENC ); hItd->lp_phat_peak_fx = 0; move32(); hItd->itd_hangover = 0; diff --git a/lib_enc/ivas_stereo_dft_enc_itd.c b/lib_enc/ivas_stereo_dft_enc_itd.c index 45eb643a5..4a4b6466f 100644 --- a/lib_enc/ivas_stereo_dft_enc_itd.c +++ b/lib_enc/ivas_stereo_dft_enc_itd.c @@ -524,10 +524,10 @@ static Word32 calc_mean_E_ratio_fx( FOR( i = band_limits[b]; i < min( band_limits[b + 1], STEREO_DFT_N_32k_ENC / 2 ); i++ ) { // sum_xcorr[0] += hItd->xcorr_smooth[2 * i]; - sum_xcorr[0] = BASOP_Util_Add_Mant32Exp( sum_xcorr[0], sum_xcorr_e[0], hItd->xcorr_smooth_fx[2 * i], hItd->xcorr_smooth_fx_e, &sum_xcorr_e[0] ); + sum_xcorr[0] = BASOP_Util_Add_Mant32Exp( sum_xcorr[0], sum_xcorr_e[0], hItd->xcorr_smooth_fx[2 * i], hItd->xcorr_smooth_fx_e[2 * i], &sum_xcorr_e[0] ); move32(); // sum_xcorr[1] += hItd->xcorr_smooth[2 * i + 1]; - sum_xcorr[1] = BASOP_Util_Add_Mant32Exp( sum_xcorr[1], sum_xcorr_e[1], hItd->xcorr_smooth_fx[2 * i + 1], hItd->xcorr_smooth_fx_e, &sum_xcorr_e[1] ); + sum_xcorr[1] = BASOP_Util_Add_Mant32Exp( sum_xcorr[1], sum_xcorr_e[1], hItd->xcorr_smooth_fx[2 * i + 1], hItd->xcorr_smooth_fx_e[2 * i + 1], &sum_xcorr_e[1] ); move32(); // sum_nrg_L += nrg_L[i]; sum_nrg_L = BASOP_Util_Add_Mant32Exp( sum_nrg_L, sum_nrg_L_e, nrg_L[i], nrg_L_e[i], &sum_nrg_L_e ); @@ -622,8 +622,7 @@ static void resetEstimates_fx( ITD_DATA_HANDLE hItd ) { set32_fx( hItd->xcorr_smooth_fx, 0, STEREO_DFT_N_32k_ENC ); - hItd->xcorr_smooth_fx_e = 0; - move16(); + set16_fx( hItd->xcorr_smooth_fx_e, 0, STEREO_DFT_N_32k_ENC ); set32_fx( hItd->acorr_L_fx, 0, STEREO_DFT_BAND_MAX ); hItd->acorr_L_fx_e = 0; move16(); @@ -1583,7 +1582,7 @@ void stereo_dft_enc_compute_itd_fx( } Word16 xcorr_smooth_fx_tmp_e[STEREO_DFT_N_32k_ENC]; - set16_fx( xcorr_smooth_fx_tmp_e, hItd->xcorr_smooth_fx_e, STEREO_DFT_N_32k_ENC ); + Copy( hItd->xcorr_smooth_fx_e, xcorr_smooth_fx_tmp_e, STEREO_DFT_N_32k_ENC ); hItd->xcorr_smooth_fx[0] = 0; move32(); xcorr_smooth_fx_tmp_e[0] = 0; @@ -1942,17 +1941,7 @@ void stereo_dft_enc_compute_itd_fx( /* RESCALING TO COMMON EXP */ max_exp = MIN_16; move16(); - FOR( i = 0; i < STEREO_DFT_N_32k_ENC; i++ ) - { - max_exp = s_max( max_exp, xcorr_smooth_fx_tmp_e[i] ); - } - hItd->xcorr_smooth_fx_e = max_exp; - move16(); - FOR( i = 0; i < STEREO_DFT_N_32k_ENC; i++ ) - { - hItd->xcorr_smooth_fx[i] = L_shr_r( hItd->xcorr_smooth_fx[i], sub( hItd->xcorr_smooth_fx_e, xcorr_smooth_fx_tmp_e[i] ) ); - move32(); - } + Copy( xcorr_smooth_fx_tmp_e, hItd->xcorr_smooth_fx_e, STEREO_DFT_N_32k_ENC ); max_exp = MIN_16; move16(); FOR( i = 0; i < STEREO_DFT_N_32k_ENC; i++ ) diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index c8709db47..bd64725e3 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -586,6 +586,8 @@ void stereo_tcx_core_enc( Scale_sig( st->hTdCngEnc->cng_exc2_buf, HO_HIST_SIZE * L_FFT, sub( add( shl( Q_new, 1 ), s ), Q_exc ) ); } Q_exc = add( shl( Q_new, 1 ), s ); // 2 * Q_new + s + st->hLPDmem->q_lpd_old_exc = Q_exc; + move16(); IF( st->enableTcxLpc ) { @@ -716,8 +718,6 @@ void stereo_tcx_core_enc( move16(); st->hLPDmem->q_lpd_syn = Q_new; move16(); - st->hLPDmem->q_lpd_old_exc = Q_new; - move16(); IF( st->hTdCngEnc != NULL ) { FOR( Word16 ii = 0; ii < HO_HIST_SIZE; ii++ ) diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 1bc7536b8..d7c0a9bc6 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2186,18 +2186,24 @@ void ivas_analy_sp_fx_front( const Word32 input_Fs, /* i : input sampling rate */ Word16 *speech, /* i : speech buffer Q_new - preemph_bits */ const Word16 Q_new, /* i : current scaling exp Q0 */ - Word32 *fr_bands, /* o : energy in critical frequency bands Q_new + QSCALE */ - Word32 *lf_E, /* o : per bin E for first... Q_new + QSCALE - 2*/ + Word32 *fr_bands, /* o : energy in critical frequency bands q_fr_bands */ + Word16 *q_fr_bands, /* o : Q of energy in critical frequency bands Q0 */ + Word32 *lf_E, /* o : per bin E for first... Q0 */ + Word16 *q_lf_E, /* o : Q of per bin E for first... q_lf_E */ Word16 *Etot, /* o : total input energy Q8 */ const Word16 min_band, /* i : minimum critical band Q0 */ const Word16 max_band, /* i : maximum critical band Q0 */ const Word32 e_min_scaled, /* i : minimum energy scaled Q_new + QSCALE */ Word16 Scale_fac[2], /* o : FFT scales factors (2 values by frame) Q0 */ - Word32 *Bin_E, /* o : per-bin energy spectrum Q7 */ - Word32 *Bin_E_old, /* o : per-bin energy spectrum of the previous frame Q7 */ - Word32 *PS, /* o : per-bin energy spectrum Q_new + QSCALE - 2 */ + Word32 *Bin_E, /* o : per-bin energy spectrum q_Bin_E */ + Word16 *q_Bin_E, /* o : Q of per-bin energy spectrum Q0 */ + Word32 *Bin_E_old, /* o : per-bin energy spectrum of the previous frame q_Bin_E_old */ + Word16 *q_Bin_E_old, /* o : Q of per-bin energy spectrum of the previous frame Q0 */ + Word32 *PS, /* o : per-bin energy spectrum q_PS */ + Word16 *q_PS, /* o : Q of per-bin energy spectrum Q0 */ Word16 *EspecdB, /* o : per-bin log energy spectrum (with f=0) Q7 */ - Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN (Q_new + QSCALE)*/ + Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN (band_energies_exp)*/ + Word16 *band_energies_exp, /* o : exponent of energy in critical frequency bands without minimum noise floor MODE2_E_MIN */ Word16 *fft_buff /* o : FFT coefficients (Q_new + Scale_fac[i_subfr]) */ ); void find_wsp_fx( diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index 6f8fba9f1..fc0278233 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -406,6 +406,9 @@ void speech_music_clas_init_ivas_fx( set32_fx( hSpMusClas->finc_prev_fx, 0, ATT_NSEG ); hSpMusClas->lt_finc_fx = 0; move32(); + hSpMusClas->Q_lt_finc = Q31; + move16(); + hSpMusClas->last_strong_attack = 0; move16(); hSpMusClas->tdm_lt_Etot_fx = 3; /* 0.01f in Q8 */ @@ -2052,12 +2055,25 @@ Word16 ivas_smc_gmm_fx( Word16 sum_PS_e = 0; move32(); move16(); + Word64 sum = W_shl( 21475 /* 1e-5 in Q31 */, sub( Qfact_PS, 30 ) ); // Qfact_PS+1 + move64(); FOR( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) { - sum_PS_fx = BASOP_Util_Add_Mant32Exp( sum_PS_fx, sum_PS_e, PS_fx[i], sub( 31, Qfact_PS ), &sum_PS_e ); // sum_PS_e + sum = W_mac_32_32( sum, PS_fx[i], 1 ); // Qfact_PS+1 + } + IF( sum == 0 ) + { + sum_PS_fx = 1407374884; // 1e-5 in Q47 + move32(); + sum_PS_e = -16; + move16(); + } + ELSE + { + sum_PS_e = W_norm( sum ); + sum_PS_fx = W_extract_h( W_shl( sum, sum_PS_e ) ); // Qfact_PS+1+sum_PS_e-32 + sum_PS_e = sub( 62, add( Qfact_PS, sum_PS_e ) ); // 31-(Qfact_PS+1+sum_PS_e-32) } - sum_PS_e = add( sum_PS_e, 1 ); // to avoid overflow - sum_PS_fx = L_add( L_shr( sum_PS_fx, 1 ), L_shr( 21475 /*1 e-5 q31*/, sum_PS_e ) ); // 31-sum_PS_e FOR( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) { @@ -2281,25 +2297,25 @@ Word16 ivas_smc_gmm_fx( lprob_exp = 0; move16(); lprob_fx = dot_product_cholesky_fixed( fvm_fx, &prec_chol_speech_fx[m * ( N_PCA_COEF * N_PCA_COEF + N_PCA_COEF ) / 2], N_PCA_COEF, fvm_exp, 31 - 28, &lprob_exp ); - ps_fx[m] = L_sub( L_sub( L_add( log_weights_speech_compute[m], log_det_chol_speech_fx[m] ), L_shl( lprob_fx, sub( Q19 - 1, sub( Q31, lprob_exp ) ) ) ), HALF_N_PCA_COEF_LOG_P12_Q19 ); // Q19 + ps_fx[m] = L_sub( L_sub( L_shr( L_add( log_weights_speech_compute[m], log_det_chol_speech_fx[m] ), 1 ), L_shl( lprob_fx, sub( Q18 - 1, sub( Q31, lprob_exp ) ) ) ), HALF_N_PCA_COEF_LOG_P12_Q19 / 2 ); // Q18 move32(); v_sub32_fx( FV_fx, &means_music_fx[m * N_PCA_COEF], fvm_fx, N_PCA_COEF ); lprob_exp = 0; move16(); lprob_fx = dot_product_cholesky_fixed( fvm_fx, &prec_chol_music_fx[m * ( N_PCA_COEF * N_PCA_COEF + N_PCA_COEF ) / 2], N_PCA_COEF, fvm_exp, 31 - 28, &lprob_exp ); - pm_fx[m] = L_sub( L_sub( L_add( log_weights_music_compute[m], log_det_chol_music_fx[m] ), L_shl( lprob_fx, sub( Q19 - 1, sub( Q31, lprob_exp ) ) ) ), HALF_N_PCA_COEF_LOG_P12_Q19 ); // Q19 + pm_fx[m] = L_sub( L_sub( L_shr( L_add( log_weights_music_compute[m], log_det_chol_music_fx[m] ), 1 ), L_shl( lprob_fx, sub( Q18 - 1, sub( Q31, lprob_exp ) ) ) ), HALF_N_PCA_COEF_LOG_P12_Q19 / 2 ); // Q18 move32(); v_sub32_fx( FV_fx, &means_noise_fx[m * N_PCA_COEF], fvm_fx, N_PCA_COEF ); lprob_exp = 0; move16(); lprob_fx = dot_product_cholesky_fixed( fvm_fx, &prec_chol_noise_fx[m * ( N_PCA_COEF * N_PCA_COEF + N_PCA_COEF ) / 2], N_PCA_COEF, fvm_exp, 31 - 28, &lprob_exp ); - pn_fx[m] = L_sub( L_sub( L_add( log_weights_noise_compute[m], log_det_chol_noise_fx[m] ), L_shl( lprob_fx, sub( Q19 - 1, sub( Q31, lprob_exp ) ) ) ), HALF_N_PCA_COEF_LOG_P12_Q19 ); // Q19 + pn_fx[m] = L_sub( L_sub( L_shr( L_add( log_weights_noise_compute[m], log_det_chol_noise_fx[m] ), 1 ), L_shl( lprob_fx, sub( Q18 - 1, sub( Q31, lprob_exp ) ) ) ), HALF_N_PCA_COEF_LOG_P12_Q19 / 2 ); // Q18 move32(); } - lps_fx = logsumexp_fx( ps_fx, sub( 31, Q19 ), N_SMC_MIXTURES ); - lpm_fx = logsumexp_fx( pm_fx, sub( 31, Q19 ), N_SMC_MIXTURES ); - lpn_fx = logsumexp_fx( pn_fx, sub( 31, Q19 ), N_SMC_MIXTURES ); + lps_fx = logsumexp_fx( ps_fx, sub( 31, Q18 ), N_SMC_MIXTURES ); + lpm_fx = logsumexp_fx( pm_fx, sub( 31, Q18 ), N_SMC_MIXTURES ); + lpn_fx = logsumexp_fx( pn_fx, sub( 31, Q18 ), N_SMC_MIXTURES ); *high_lpn_flag = 0; move16(); if ( GT_32( lpn_fx, lps_fx ) && GT_32( lpn_fx, lpm_fx ) ) @@ -3021,6 +3037,12 @@ void ivas_smc_mode_selection_fx( var_cor_calc_ivas_fx( st->old_corr_fx, &hSpMusClas->mold_corr_fx, hSpMusClas->var_cor_t_fx, &hSpMusClas->high_stable_cor ); /* attack detection */ + IF( NE_16( shl( Q_new, 1 ), hSpMusClas->Q_lt_finc ) ) + { + Scale_sig32( &hSpMusClas->lt_finc_fx, 1, sub( shl( Q_new, 1 ), hSpMusClas->Q_lt_finc ) ); + hSpMusClas->Q_lt_finc = shl( Q_new, 1 ); + move16(); + } attack = attack_det_ivas_fx( inp, Q_new, st->clas, st->localVAD, st->coder_type, 0, st->element_mode, st->clas, hSpMusClas->finc_prev_fx, &hSpMusClas->lt_finc_fx, &hSpMusClas->last_strong_attack ); /* tonal detector */ diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 73cb96e15..9503ebaf8 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -640,8 +640,9 @@ typedef struct sp_mus_clas_structure Word16 UV_cnt1; Word16 LT_UV_cnt1_fx; /* Q6 */ - Word32 finc_prev_fx[ATT_NSEG]; /* strong attack detection - previous finc, (Q_new * 2) */ - Word32 lt_finc_fx; /* strong attack detection - long-term finc energy, (Q_new * 2) */ + Word32 finc_prev_fx[ATT_NSEG]; /* strong attack detection - previous finc, (Q_new * 2) */ + Word32 lt_finc_fx; /* strong attack detection - long-term finc energy, Q_lt_finc (Q_new * 2) */ + Word16 Q_lt_finc; Word16 last_strong_attack; /* strong attack detection - last strong attack flag */ Word32 tod_lt_Bin_E_fx[TOD_NSPEC]; /* tonal detector - long-term energy spectrum, Q_tod_lt_Bin_E */ Word16 Q_tod_lt_Bin_E; diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index c85c7236e..a5889e401 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -2705,11 +2705,12 @@ void tcx_encoder_memory_update_ivas_fx( IF( LT_16( L_frame_glob, L_EXC_MEM ) ) { Copy( LPDmem->old_exc + L_frame_glob, LPDmem->old_exc, sub( L_EXC_MEM, L_frame_glob ) ); - Residu3_fx( A, synth, LPDmem->old_exc + sub( L_EXC_MEM, L_frame_glob ), L_frame_glob, 1 ); + Scale_sig( LPDmem->old_exc, sub( L_EXC_MEM, L_frame_glob ), Q_new ); // Q_new->2*Q_new + Residu3_fx( A, synth, LPDmem->old_exc + sub( L_EXC_MEM, L_frame_glob ), L_frame_glob, 1 ); // 2*Q_new } ELSE { - Residu3_fx( A, synth + sub( L_frame_glob, L_EXC_MEM ), LPDmem->old_exc, L_EXC_MEM, 1 ); + Residu3_fx( A, synth + sub( L_frame_glob, L_EXC_MEM ), LPDmem->old_exc, L_EXC_MEM, 1 ); // 2*Q_new } } } -- GitLab