diff --git a/lib_com/fft_fx.c b/lib_com/fft_fx.c index d6710ebd0f6f1102f8e66f4aa6a91de374cec3a2..ba895d83c85f9b0f71100e94f7616a59e0d6fa94 100644 --- a/lib_com/fft_fx.c +++ b/lib_com/fft_fx.c @@ -7257,7 +7257,7 @@ Word16 find_guarded_bits_fx( Word32 n ) } } -Word16 L_norm_arr( Word32 *arr, Word16 size ) +Word16 L_norm_arr( const Word32 *arr, Word16 size ) { Word16 q = 31; move16(); diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index be9ea3a80f5e10808c5b3cc89bc1b051314aab2e..b554072343587a06c5f450f124676b3763827869 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -69,10 +69,10 @@ void stereo_dmx_evs_enc( /*! r: number of channels to be analysed */ -void copy_encoder_config( +void copy_encoder_config_ivas_fx( Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ Encoder_State *st, /* o : encoder state structure */ - const int16_t flag_all /* i : flag 1==update all, 0=partial update */ + const Word16 flag_all /* i : flag 1==update all, 0=partial update Q0*/ ); @@ -200,94 +200,94 @@ ivas_error pre_proc_front_ivas( ivas_error pre_proc_front_ivas_fx( SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const Word32 element_brate, /* i : SCE/CPE element bitrate */ - const Word16 nb_bits_metadata, /* i : number of metadata bits */ - const Word16 input_frame, /* i : frame length */ - const Word16 n, /* i : channel number */ - Word16 old_inp_12k8_fx[], /* o : (Q-1) buffer of old input signal */ - Word16 old_inp_16k_fx[], /* o : buffer of old input signal @16kHz Q-1 */ - Word32 *ener_fx, /* o : residual energy from Levinson-Durbin Q_r */ - Word16 *relE_fx, /* o : frame relative energy Q8 */ - Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */ - Word32 epsP_fx[M + 1], /* o : LP prediction errors */ + const Word32 element_brate, /* i : SCE/CPE element bitrate Q0*/ + const Word16 nb_bits_metadata, /* i : number of metadata bits Q0*/ + const Word16 input_frame, /* i : frame length Q0*/ + const Word16 n, /* i : channel number Q0*/ + Word16 old_inp_12k8_fx[], /* o : buffer of old input signal Q_new-1*/ + Word16 old_inp_16k_fx[], /* o : buffer of old input signal @16kHz Q_new-1*/ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q*/ + Word16 *relE_fx, /* o : frame relative energy Q8*/ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes Q12*/ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes Q12*/ + Word32 epsP_fx[M + 1], /* o : LP prediction errors epsP_fx_q*/ Word16 *epsP_fx_q, - Word16 lsp_new_fx[M], /* o : LSPs at the end of the frame Q15 */ - Word16 lsp_mid_fx[M], /* o : LSPs in the middle of the frame Q15 */ - Word16 *vad_hover_flag, /* o : VAD hangover flag */ - Word16 *attack_flag, /* o : flag signaling attack */ - Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer Q(q_re_im_buf) */ - Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer Q(q_re_im_buf) */ - Word16 *q_re_im_buf, /* i/o: Q-factor of real and imag buffer */ - Word16 old_wsp[], /* o : weighted input signal buffer q_old_wsp*/ + Word16 lsp_new_fx[M], /* o : LSPs at the end of the frame Q15*/ + Word16 lsp_mid_fx[M], /* o : LSPs in the middle of the frame Q15*/ + Word16 *vad_hover_flag, /* o : VAD hangover flag Q0*/ + Word16 *attack_flag, /* o : flag signaling attack Q0*/ + Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer Q(q_re_im_buf)*/ + Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer Q(q_re_im_buf)*/ + Word16 *q_re_im_buf, /* i/o: Q-factor of real and imag buffer */ + Word16 old_wsp_fx[], /* o : weighted input signal buffer q_old_wsp*/ Word16 *q_old_wsp, - Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6 */ - Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15 */ - Word16 *loc_harm, /* o : harmonicity flag */ - Word16 *cor_map_sum_fx, /* o : speech/music clasif. parameter Q8 */ - Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO */ - Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ - Word16 *enerBuffer_fx_exp, /* o : energy buffer */ - Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer */ - Word16 *fft_buff_fx_q, /* o : FFT buffer */ - const Word16 tdm_A_PCh_fx[M + 1], /* i : unq. LP coeff. of primary channel Q12 */ - const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15 */ - const Word16 currFlatness_fx, /* i : flatness parameter Q7 */ - const Word16 tdm_ratio_idx, /* i : Current Ratio_L index */ - Word32 fr_bands_LR_fx[][2 * NB_BANDS], /* i : energy in frequency bands (fr_bands_LR_fx_q) */ + Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6*/ + Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15*/ + Word16 *loc_harm, /* o : harmonicity flag Q0*/ + Word16 *cor_map_sum_fx, /* o : speech/music clasif. parameter Q8*/ + Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO Q0*/ + Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer enerBuffer_fx_exp*/ + Word16 *enerBuffer_fx_exp, /* o : energy buffer */ + Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer fft_buff_fx_q*/ + Word16 *fft_buff_fx_q, /* o : FFT buffer */ + const Word16 tdm_A_PCh_fx[M + 1], /* i : unq. LP coeff. of primary channel Q12*/ + const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15*/ + const Word16 currFlatness_fx, /* i : flatness parameter Q7*/ + const Word16 tdm_ratio_idx, /* i : Current Ratio_L index Q0*/ + Word32 fr_bands_LR_fx[][2 * NB_BANDS], /* i : energy in frequency bands (fr_bands_LR_fx_q) fr_bands_LR_fx_q*/ Word16 fr_bands_LR_fx_q[CPE_CHANNELS], - const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/ - Word32 lf_E_LR_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels (lf_E_LR_fx_q) */ + const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/ + Word32 lf_E_LR_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels (lf_E_LR_fx_q)*/ Word16 lf_E_LR_fx_q, - const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels */ - Word32 band_energies_LR_fx[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN (band_energies_LR_fx_q) */ + const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels Q0*/ + Word32 band_energies_LR_fx[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN (band_energies_LR_fx_q)*/ Word16 band_energies_LR_fx_q, - const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */ - const Word16 front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */ - const Word16 force_front_vad, /* i : flag to force VAD decision */ - const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX */ + const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ + const Word16 front_vad_flag, /* i : front-VAD flag to overwrite VAD decision Q0*/ + const Word16 force_front_vad, /* i : flag to force VAD decision Q0*/ + const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision Q0*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word32 ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX Q0*/ Word16 *Q_new #ifdef DEBUG_MODE_INFO , const Word16 ch_idx #endif ); -ivas_error pre_proc_ivas( +ivas_error pre_proc_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ - const Word16 last_element_mode, /* i : last element mode */ - const Word32 element_brate, /* i : element bitrate */ - const Word32 last_element_brate, /* i : last element bitrate */ - const Word16 input_frame, /* i : frame length */ - Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal */ - Word16 old_inp_16k_fx[], /* i/o: buffer of old input signal @ 16kHz */ - Word16 **inp_fx, /* o : ptr. to inp. signal in the current frame*/ - Word32 *ener_fx, /* o : residual energy from Levinson-Durbin Q6 */ - Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ - Word32 epsP_fx[M + 1], /* i : LP prediction errors epsP_fx_q */ - Word16 *epsP_fx_q, /* i : LP prediction errors */ - Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ - Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame */ - Word16 *new_inp_resamp16k_fx, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - Word16 *Voicing_flag, /* o : voicing flag for HQ FEC */ - Word16 old_wsp_fx[], /* i : weighted input signal buffer */ + const Word16 last_element_mode, /* i : last element mode Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + const Word32 last_element_brate, /* i : last element bitrate Q0*/ + const Word16 input_frame, /* i : frame length Q0*/ + Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal Q_new-1 */ + Word16 old_inp_16k_fx[], /* i/o: buffer of old input signal @ 16kHz Q_new-1 */ + Word16 **inp_fx, /* o : ptr. to inp. signal in the current frame Q_new*/ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q*/ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes Q12*/ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes Q14*/ + Word32 epsP_fx[M + 1], /* i : LP prediction errors epsP_fx_q*/ + Word16 *epsP_fx_q, /* i : LP prediction errors */ + Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame Q15*/ + Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame Q15*/ + Word16 *new_inp_resamp16k_fx, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE Q_new-1*/ + Word16 *Voicing_flag, /* o : voicing flag for HQ FEC Q0*/ + Word16 old_wsp_fx[], /* i : weighted input signal buffer e_old_wsp*/ Word16 e_old_wsp, - const Word16 loc_harm, /* i : harmonicity flag */ - const Word16 vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const Word16 vad_hover_flag, /* i : VAD hangover flag */ - const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */ - Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], + const Word16 loc_harm, /* i : harmonicity flag Q0*/ + const Word16 vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO Q0*/ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ + const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ + Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* e_enerBuffer */ Word16 e_enerBuffer, - Word16 fft_buff_fx[2 * L_FFT], - Word16 cor_map_sum_fx, // Q8 + Word16 fft_buff_fx[2 * L_FFT], /* Qx */ + Word16 cor_map_sum_fx, /* Q8 */ Word16 *Q_new ); /*! r: number of clipped samples */ -void ivas_initialize_handles_enc( +void ivas_initialize_handles_enc_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); @@ -295,16 +295,16 @@ ivas_error ivas_init_encoder( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); -void ivas_destroy_enc( +void ivas_destroy_enc_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); -ivas_error ivas_initialize_MD_bstr_enc( +ivas_error ivas_initialize_MD_bstr_enc_fx( BSTR_ENC_HANDLE *hBstr, /* o : encoder MD bitstream handle */ Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); -void ivas_destroy_MD_bstr_enc( +void ivas_destroy_MD_bstr_enc_fx( BSTR_ENC_HANDLE *hMetaData /* i/o: encoder MD bitstream handle */ ); @@ -3347,11 +3347,11 @@ void pca_dec_s3( ); -void ivas_huffman_encode( +void ivas_huffman_encode_fx( ivas_huffman_cfg_t *huff_cfg, - int16_t in, - int16_t *hcode, - int16_t *hlen + Word16 in, + Word16 *hcode, + Word16 *hlen ); diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 8726e13d858aa397459be85c6d65f0c2e0c37e08..3a22c5c721726926b0ade11621d4e478342ebbec 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3444,17 +3444,18 @@ ivas_error ivas_param_mc_enc_reconfig_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); -Word16 ivas_arith_encode_cmplx_cell_array( +Word16 ivas_arith_encode_cmplx_cell_array_fx( ivas_arith_t *pArith_re, ivas_arith_t *pArith_re_diff, - const Word16 *pDo_diff, - const Word16 nB, - Word16 *pSymbol_re, - Word16 *pSymbol_old_re, + const Word16 *pDo_diff, /* Q0 */ + const Word16 nB, /* Q0 */ + Word16 *pSymbol_re, /* Q0 */ + Word16 *pSymbol_old_re, /* Q0 */ ivas_cell_dim_t *pCell_dims, BSTR_ENC_HANDLE hMetaData, - const Word16 any_diff, - const Word16 wc_strat_arith ); + const Word16 any_diff, /* Q0 */ + const Word16 wc_strat_arith /* Q0 */ +); ivas_error stereo_dmx_evs_init_encoder_fx( STEREO_DMX_EVS_ENC_HANDLE *hStereoDmxEVS_out, /* o : Stereo downmix for EVS encoder handle */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 7bca00410939f8cf110f6209a55da52efac96156..0e528f9f3af42a04ec8a3ad612476421a8a7528d 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -4577,7 +4577,7 @@ void DoRTFTn_fx_ivas( Word16 find_guarded_bits_fx( Word32 n ); -Word16 L_norm_arr( Word32 *arr, Word16 size ); +Word16 L_norm_arr( const Word32 *arr, Word16 size ); Word16 norm_arr( Word16 *arr, Word16 size ); Word16 get_min_scalefactor( Word32 x, Word32 y ); diff --git a/lib_com/tools.c b/lib_com/tools.c index f757239f38f38da77ad373ff14f22007e7b9a2e7..7810edb94f46fdf91511d68701e6439f91ae67b6 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -281,13 +281,18 @@ Word32 sum2_32_exp_fx( Word16 gb /* i : guard bits */ ) { - Word16 i, s; + Word16 i, s, norm; Word64 W_tmp; W_tmp = 0; Word64 var_a = 0; move64(); move64(); + + norm = L_norm_arr( vec, lvec ); + + gb = sub( gb, norm ); + FOR( i = 0; i < lvec; i++ ) { var_a = W_mult0_32_32( vec[i], vec[i] ); // 2x diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 66561361eae82f8fb59ba6945bedd7fc3d432ef6..ea0468587fe90c936f4a5f3acc203d2befc2b087 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -32,7 +32,7 @@ void HBAutocorrelation_fx( TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 left_overlap_mode, /* input: overlap mode of left window half */ Word16 right_overlap_mode, /* input: overlap mode of right window half */ - Word16 speech[], /* input: speech[-LFAC..L_frame+LFAC] */ + Word16 speech[], /* input: speech[-LFAC..L_frame+LFAC] Qx*/ Word16 L_frame, /* input: frame length */ Word32 *r, /* output: autocorrelations vector */ Word16 m /* input : order of LP filter */ @@ -45,6 +45,7 @@ void HBAutocorrelation_fx( #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /*-----------------------------------------------------------* @@ -64,7 +65,7 @@ void HBAutocorrelation_fx( move16(); L_sum = L_deposit_l( 0 ); Overflow = 0; - move16(); + move32(); FOR( i = 0; i < len; i += 1 ) { /* Test Addition */ @@ -76,7 +77,7 @@ void HBAutocorrelation_fx( IF( Overflow ) { Overflow = 0; - move16(); + move32(); shift = 1; move16(); L_tmp = L_msu0( 0, y[i], y[i] ); @@ -91,7 +92,7 @@ void HBAutocorrelation_fx( #else L_sum = L_sub( L_sum, L_tmp ); #endif - FOR( j = add( i, 1 ); j < len; j++ ) + FOR( j = i + 1; j < len; j++ ) { L_tmp = L_msu0( 0, y[j], y[j] ); L_tmp = L_shr( L_tmp, shift ); @@ -105,7 +106,7 @@ void HBAutocorrelation_fx( IF( Overflow ) { Overflow = 0; - move16(); + move32(); shift = add( shift, 1 ); L_tmp = L_shr( L_tmp, 1 ); #ifdef BASOP_NOGLOB /* Critical Overflow */ @@ -652,17 +653,19 @@ void TNSAnalysis_fx( TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 L_frame, /* input: frame length */ Word16 L_spec, - Word16 tcxMode, /* input: TCX mode for the frame/subframe - TCX20 | TCX10 | TCX 5 (meaning 2 x TCX 5) */ - Word8 isAfterACELP, /* input: Flag indicating if the last frame was ACELP. For the second TCX subframe it should be 0 */ - Word32 spectrum[], /* input: MDCT spectrum */ - STnsData *pTnsData, /* output: Tns data */ - Word8 *pfUseTns, /* output: Flag indicating if TNS is used */ - Word16 *predictionGain ) + Word16 tcxMode, /* input: TCX mode for the frame/subframe - TCX20 | TCX10 | TCX 5 (meaning 2 x TCX 5) */ + Word8 isAfterACELP, /* input: Flag indicating if the last frame was ACELP. For the second TCX subframe it should be 0 */ + Word32 spectrum[], /* input: MDCT spectrum Qx*/ + STnsData *pTnsData, /* output: Tns data */ + Word8 *pfUseTns, /* output: Flag indicating if TNS is used */ + Word16 *predictionGain /*Q7*/ +) { Word32 buff[8]; Word16 tmp = 0; /* initialization only to avoid compiler warning, not counted */ Word16 tmp2 = 0; /* initialization only to avoid compiler warning, not counted */ - + move16(); + move16(); /* Init TNS */ *pfUseTns = 0; @@ -670,8 +673,7 @@ void TNSAnalysis_fx( IF( hTcxCfg->fIsTNSAllowed != 0 ) { - hTcxCfg->pCurrentTnsConfig = &hTcxCfg->tnsConfig[sub( tcxMode, TCX_20 ) == 0][isAfterACELP]; - test(); + hTcxCfg->pCurrentTnsConfig = &hTcxCfg->tnsConfig[( tcxMode - TCX_20 ) == 0][isAfterACELP]; L_spec = hTcxCfg->pCurrentTnsConfig->iFilterBorders[0]; move16(); @@ -756,8 +758,7 @@ void TNSAnalysis_ivas_fx( IF( hTcxCfg->fIsTNSAllowed != 0 ) { - hTcxCfg->pCurrentTnsConfig = &hTcxCfg->tnsConfig[sub( transform_type, TCX_20 ) == 0][isAfterACELP]; - test(); + hTcxCfg->pCurrentTnsConfig = &hTcxCfg->tnsConfig[( transform_type - TCX_20 ) == 0][isAfterACELP]; L_spec = hTcxCfg->pCurrentTnsConfig->iFilterBorders[0]; move16(); @@ -818,8 +819,8 @@ void TNSAnalysis_ivas_fx( void ShapeSpectrum_fx( TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ - Word16 A[], /* input: quantized coefficients NxAz_q[M+1] */ - Word16 gainlpc[], /* output: MDCT gains for the previous frame */ + Word16 A[], /* input: quantized coefficients NxAz_q[M+1] Q = 14 - norm(A[0])*/ + Word16 gainlpc[], /* output: MDCT gains for the previous frame Q(15-gainlpc_e)*/ Word16 gainlpc_e[], /* output: MDCT gains exponents */ Word16 L_frame_glob, /* input: frame length */ Word16 L_spec, @@ -834,6 +835,8 @@ void ShapeSpectrum_fx( Word16 gainlpc_noinv_e[FDNS_NPTS]; Word16 i; Word32 max_low_pre = 0, max_high_pre = 0; + move32(); + move32(); TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; /*-----------------------------------------------------------* @@ -875,6 +878,7 @@ void ShapeSpectrum_fx( IF( st->enablePlcWaveadjust ) { hTcxCfg->SFM2 = SFM_Cal_fx( spectrum, s_min( 200, L_frame ) ); + move32(); } test(); @@ -897,7 +901,7 @@ void ShapeSpectrum_fx( max_high_pre = 0; move32(); - for ( i = 0; i < L_spec - L_frame; i++ ) + FOR( i = 0; i < L_spec - L_frame; i++ ) { Word32 tmp = L_abs( spectrum[L_frame + i] ); if ( GT_32( tmp, max_high_pre ) ) @@ -925,6 +929,8 @@ void ShapeSpectrum_fx( /* reduce the peaks in the IGF region, to make life of the core-coder easier... */ test(); + test(); + test(); IF( ( EQ_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->bwidth, SWB ) ) || ( EQ_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->bwidth, SWB ) ) ) { @@ -967,7 +973,7 @@ void ShapeSpectrum_fx( max_low1 = 0; move32(); - FOR( i = 0; i < sub( L_frame, sf_width ); i++ ) + FOR( i = 0; i < ( L_frame - sf_width ); i++ ) { Word32 tmp = L_abs( spectrum[L_frame - sf_width - 1 - i] ); if ( GT_32( tmp, max_low1 ) ) @@ -975,7 +981,7 @@ void ShapeSpectrum_fx( max_low1 = tmp; move32(); } - if ( tmp > max_low2 ) + if ( GT_32( tmp, max_low2 ) ) { dist_low = add( sf_width, i ); } @@ -987,10 +993,10 @@ void ShapeSpectrum_fx( move32(); dist_high = 0; move16(); - FOR( i = 0; i < sub( L_spec, L_frame ); i++ ) + FOR( i = 0; i < ( L_spec - L_frame ); i++ ) { Word32 tmp = L_abs( spectrum[L_frame + i] ); - if ( GT_32( tmp, max_high ) ) + IF( GT_32( tmp, max_high ) ) { max_high = tmp; move32(); @@ -1036,6 +1042,7 @@ void ShapeSpectrum_fx( FOR( i = 0; i < sub( L_spec, L_frame ); i++ ) { spectrum[L_frame + i] = Mpy_32_16_1( spectrum[L_frame + i], fac ); + move32(); } } } @@ -1052,11 +1059,11 @@ void ShapeSpectrum_fx( void ShapeSpectrum_ivas_fx( TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 A[], /* input: quantized coefficients NxAz_q[M+1], Q = 14 - norm(A[0]) */ - Word16 gainlpc[], /* output: MDCT gains for the previous frame */ + Word16 gainlpc[], /* output: MDCT gains for the previous frame Q(15-gainlpc_e)*/ Word16 gainlpc_e[], /* output: MDCT gains exponents */ Word16 L_frame_glob, /* input: frame length */ Word16 L_spec, - Word32 spectrum[], /* i/o: MDCT spectrum */ + Word32 spectrum[], /* i/o: MDCT spectrum Q(31-spectrum_e) */ Word16 *spectrum_e, /* i/o: MDCT spectrum exponent */ Word8 pfUseTns, /* output: Flag indicating if TNS is used */ Encoder_State *st, @@ -1105,7 +1112,7 @@ void ShapeSpectrum_ivas_fx( { L_frame = add( L_frame, hTcxCfg->tcx_offset ); L_spec = add( L_spec, shr( hTcxCfg->tcx_coded_lines, 2 ) ); - IF( hTcxCfg->lfacNext < 0 ) + if ( hTcxCfg->lfacNext < 0 ) { L_frame = sub( L_frame, hTcxCfg->lfacNext ); move16(); @@ -1167,11 +1174,11 @@ void ShapeSpectrum_ivas_fx( test(); IF( NE_16( len, L_spec ) && LT_16( add( q_spectrum, 1 ), sub( 31, *spectrum_e ) ) ) { - scale_sig32( spectrum + len, sub( L_spec, len ), sub( add( q_spectrum, 1 ), sub( 31, *spectrum_e ) ) ); + scale_sig32( spectrum + len, sub( L_spec, len ), sub( add( q_spectrum, 1 ), sub( 31, *spectrum_e ) ) ); // Q31 } ELSE IF( NE_16( len, L_spec ) && GT_16( add( q_spectrum, 1 ), sub( 31, *spectrum_e ) ) ) { - scale_sig32( spectrum, len, sub( sub( 31, *spectrum_e ), add( q_spectrum, 1 ) ) ); + scale_sig32( spectrum, len, sub( sub( 31, *spectrum_e ), add( q_spectrum, 1 ) ) ); // Q(30-specturm_e) q_spectrum = sub( 31 - 1, *spectrum_e ); } @@ -1253,7 +1260,7 @@ void ShapeSpectrum_ivas_fx( max_low1 = tmp; move32(); } - IF( GT_32( tmp, max_low2 ) ) + if ( GT_32( tmp, max_low2 ) ) { dist_low = add( sf_width, i ); } @@ -1265,10 +1272,10 @@ void ShapeSpectrum_ivas_fx( move32(); dist_high = 0; move16(); - FOR( i = 0; i < sub( L_spec, L_frame ); i++ ) + FOR( i = 0; i < ( L_spec - L_frame ); i++ ) { Word32 tmp = L_abs( spectrum[L_frame + i] ); - if ( GT_32( tmp, max_high ) ) + IF( GT_32( tmp, max_high ) ) { max_high = tmp; move32(); @@ -1532,15 +1539,15 @@ static Word16 GetTransWidth_ivas_fx( static void EstimateTCXNoiseLevel_ivas_fx( Encoder_State *st, /* i : encoder state handle */ - Word32 x_orig[], /* i : shaped MDCT spectrum */ + Word32 x_orig[], /* i : shaped MDCT spectrum Q(31-x_orig_e) */ Word16 x_orig_e, /* i : shaped MDCT spectrum exponent */ Word32 spectrum[], /* i/o: quantized MDCT spectrum */ - const Word16 gain_tcx, /* i : global gain */ + const Word16 gain_tcx, /* i : global gain Q(15-gain_tcx_e) */ const Word16 gain_tcx_e, /* i : global gain exponent */ const Word16 L_frame, /* i : frame length */ const Word16 noiseFillingBorder, /* i : noise filling border */ const Word16 hm_active, /* i : flag indicating if the harmonic model is active */ - Word16 *fac_ns, /* o : noise filling level, Q15 */ + Word16 *fac_ns, /* o : noise filling level, fac_ns_q */ Word16 *fac_ns_q /* o : quantized noise filling level, Q0 */ ) { @@ -1634,7 +1641,7 @@ void QuantizeSpectrum_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 A_fx[], /* i : quantized coefficients NxAz_q[M+1], Q = 14 - norm_s(A_fx[0]) */ const Word16 Aqind[], /* i : frame-independent quantized coefficients (M+1) */ - Word16 gainlpc_fx[], /* i : MDCT gains of the previous frame */ + Word16 gainlpc_fx[], /* i : MDCT gains of the previous frame Q(15-gainlpc_e) */ Word16 gainlpc_e[], /* i : exponents of MDCT gains of the previous frame */ Word16 synth[], /* o : synthesis buffer, Q0 */ const Word16 nb_bits, /* i : bit budget */ @@ -1719,8 +1726,8 @@ void QuantizeSpectrum_ivas_fx( void EstimateStereoTCXNoiseLevel_fx( Encoder_State **sts, /* i : state handle */ - Word32 *q_spectrum[CPE_CHANNELS][NB_DIV], /* i : quantized MDCT spectrum */ - Word16 gain_tcx[][NB_DIV], /* i : global gain */ + Word32 *q_spectrum[CPE_CHANNELS][NB_DIV], /* i : quantized MDCT spectrum Qx */ + Word16 gain_tcx[][NB_DIV], /* i : global gain Q(15-gain_tcx_e) */ Word16 gain_tcx_e[][NB_DIV], /* i : global gain exponent */ Word16 L_frame[][NB_DIV], /* i : frame length */ Word16 noiseFillingBorder[][NB_DIV], /* i : noise filling border */ @@ -1754,9 +1761,9 @@ void EstimateStereoTCXNoiseLevel_fx( move16(); } - if ( ignore_chan[ch] ) + IF( ignore_chan[ch] ) { - continue; + CONTINUE; } IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && !MCT_flag ) @@ -1823,8 +1830,8 @@ void EstimateStereoTCXNoiseLevel_fx( test(); IF( L_tmp != 0 || L_tmp1 != 0 ) { - scale_sig32( hTcxEnc->spectrum_fx[n], L_frame[ch][n], -Q1 ); - scale_sig32( combined_q_spectrum, L_frame[ch][n], -Q1 ); + scale_sig32( hTcxEnc->spectrum_fx[n], L_frame[ch][n], -Q1 ); // Q(31-(spectrum_e+1) + scale_sig32( combined_q_spectrum, L_frame[ch][n], -Q1 ); // Q(31-(spectrum_e+1) hTcxEnc->spectrum_e[n] = add( hTcxEnc->spectrum_e[n], Q1 ); move16(); } @@ -1854,6 +1861,7 @@ void EstimateStereoTCXNoiseLevel_fx( ELSE { hTcxEnc->noiseLevelMemory_cnt = sub( -1, hTcxEnc->noiseLevelMemory_cnt ); + move16(); } } ELSE @@ -1873,7 +1881,7 @@ void QuantizeSpectrum_fx( TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 A[], /* input: quantized coefficients NxAz_q[M+1] */ Word16 Aqind[], /* input: frame-independent quantized coefficients (M+1) */ - Word16 gainlpc[], /* input: MDCT gains of the previous frame */ + Word16 gainlpc[], /* input: MDCT gains of the previous frame Q(15-gainlpc_e)*/ Word16 gainlpc_e[], /* input: MDCT gains exponents */ Word16 synth[], Word16 L_frame_glob, /* input: frame length */ @@ -1881,7 +1889,7 @@ void QuantizeSpectrum_fx( Word16 L_spec, Word16 nb_bits, /*input: bit budget*/ Word8 tcxonly, /*input: only TCX flag*/ - Word32 spectrum[], /* i/o: MDCT spectrum, input is shaped MDCT spectrum */ + Word32 spectrum[], /* i/o: MDCT spectrum, input is shaped MDCT spectrum Q(31-spectrum_e) */ Word16 *spectrum_e, /* i/o: MDCT spectrum exponent */ STnsData *pTnsData, /* input: Tns data */ Word8 fUseTns, /* input: Flag indicating if TNS is used */ @@ -2099,6 +2107,7 @@ void QuantizeSpectrum_fx( FOR( i = st->hIGFEnc->infoStopLine; i < L_frameTCX; i++ ) { spectrum[i] = L_deposit_l( 0 ); + move32(); } /*-----------------------------------------------------------* @@ -2309,6 +2318,7 @@ void QuantizeSpectrum_fx( #else /* BASOP_NOGLOB */ hTcxEnc->tcx_target_bits_fac = shl( mult( hTcxEnc->tcx_target_bits_fac, tmp1 ), tmp2 ); #endif /* BASOP_NOGLOB */ + move16(); BASOP_SATURATE_WARNING_ON_EVS if ( GT_16( hTcxEnc->tcx_target_bits_fac, 0x5000 ) ) @@ -2541,7 +2551,7 @@ void QuantizeSpectrum_fx( tmp8 = 1; move16(); - if ( EQ_16( st->last_core, ACELP_CORE ) ) + if ( st->last_core == ACELP_CORE ) { tmp8 = 0; move16(); @@ -2610,7 +2620,7 @@ void QuantizeSpectrum_fx( /*-----------------------------------------------------------* * Quantize TCX gain * *-----------------------------------------------------------*/ - + test(); IF( GE_32( st->total_brate, ACELP_13k20 ) && st->rf_mode == 0 ) { QuantizeGain( L_spec, &gain_tcx, &gain_tcx_e, &prm[0] ); @@ -2707,6 +2717,7 @@ void QuantizeSpectrum_fx( { /* noise filling start bin */ i = shr( L_frame, 3 ); + test(); IF( GE_32( st->total_brate, ACELP_13k20 ) && st->rf_mode == 0 ) { i = idiv1616U( L_frame, 6 ); @@ -2748,6 +2759,7 @@ void QuantizeSpectrum_fx( IF( EQ_16( prm[NOISE_FILL_RANGES], 1 ) ) { hTcxEnc->noiseLevelMemory_cnt = add( 1, abs_s( hTcxEnc->noiseLevelMemory_cnt ) ); /* update counter */ + move16(); } ELSE { @@ -2768,6 +2780,7 @@ void QuantizeSpectrum_fx( tmp1 = sub( -1, hTcxEnc->noiseLevelMemory_cnt ); } hTcxEnc->noiseLevelMemory_cnt = tmp1; + move16(); } ELSE { @@ -2802,6 +2815,7 @@ void QuantizeSpectrum_fx( * Noise Filling. * *-----------------------------------------------------------*/ + test(); /* Replication of ACELP formant enhancement for low rates */ IF( LT_32( st->total_brate, ACELP_13k20 ) || st->rf_mode != 0 ) { @@ -2812,6 +2826,7 @@ void QuantizeSpectrum_fx( { tmp1 = 0; move16(); + test(); if ( GE_32( st->total_brate, ACELP_13k20 ) && st->rf_mode == 0 ) { tmp1 = 1; @@ -2826,7 +2841,7 @@ void QuantizeSpectrum_fx( tcx_noise_filling( spectrum, *spectrum_e, nf_seed /* seed */, i, noiseFillingSize, noiseTransWidth, L_frame, hTcxEnc->noiseTiltFactor, fac_ns, NULL, st->element_mode ); } - + test(); IF( LT_32( st->total_brate, ACELP_13k20 ) || st->rf_mode != 0 ) { /* partially recompute global gain (energy part), taking noise filling and formant enhancement into account */ @@ -2861,14 +2876,14 @@ void QuantizeSpectrum_fx( /*-----------------------------------------------------------* * Apply gain * *-----------------------------------------------------------*/ - IF( EQ_16( st->hTcxCfg->coder_type, INACTIVE ) ) + IF( st->hTcxCfg->coder_type == INACTIVE ) { gain_tcx = mult_r( gain_tcx, hTcxCfg->na_scale ); } FOR( i = 0; i < L_spec; i++ ) { - spectrum[i] = Mpy_32_16_1( spectrum[i], gain_tcx ); + spectrum[i] = Mpy_32_16_1( spectrum[i], gain_tcx ); // Q(31-(spectrum_e+gain_tcx_e)) move32(); } *spectrum_e = add( *spectrum_e, gain_tcx_e ); @@ -2908,8 +2923,6 @@ void QuantizeSpectrum_fx( IF( hTcxCfg->fIsTNSAllowed != 0 ) { - test(); - test(); test(); SetTnsConfig( hTcxCfg, sub( L_frame_glob, st->L_frame ) == 0, ( st->last_core == ACELP_CORE ) && ( frame_cnt == 0 ) ); @@ -2943,7 +2956,7 @@ void QuantizeSpectrum_fx( s = getScaleFactor32( spectrum, L_frame ); FOR( i = 0; i < L_frame; i++ ) { - spectrum[i] = L_shl( spectrum[i], s ); + spectrum[i] = L_shl( spectrum[i], s ); // Q(31-(spectrum_e-s)) move32(); } *spectrum_e = sub( *spectrum_e, s ); @@ -3127,7 +3140,6 @@ void QuantizeSpectrum_fx( 0 ); - move16(); tmpP16 = xn_buf16 + add( sub( L_win, shr( L_ola, 1 ) ), shr( overlap, 1 ) ); tcx_windowing_synthesis_past_frame( tmpP16, @@ -3156,7 +3168,7 @@ void QuantizeSpectrum_fx( L_win ); /* extra folding-out on left side of win, for perfect reconstruction */ - FOR( w = shr( overlap, 1 ); w < overlap; w++ ) + FOR( w = overlap / 2; w < overlap; w++ ) { xn_buf16[overlap - 1 - w] = negate( xn_buf16[w] ); move16(); @@ -3558,9 +3570,9 @@ static Word16 DecideTonalSideInfo_fx( void QuantizeTCXSpectrum_fx( Encoder_State *st, /* i : state handle */ const Word16 frame_cnt, /* i : frame counter in the super_frame Q0 */ - Word32 *x_orig_fx, /* i : shaped MDCT spectrum */ + Word32 *x_orig_fx, /* i : shaped MDCT spectrum Q(31-x_orig_e)*/ Word16 x_orig_e, /* i : exp of shaped MDCT spectrum */ - Word16 *gainlpc_fx, /* i : FDNS gains */ + Word16 *gainlpc_fx, /* i : FDNS gains Q(15-gainlpc_e)*/ Word16 *gainlpc_e, /* i : exp of FDNS gains */ const Word16 *Aqind, /* i : frame-independent quantized coefficients (M+1) Q0 */ const Word16 tnsSize, /* i : number of tns parameters put into prm Q0 */ @@ -3571,15 +3583,15 @@ void QuantizeTCXSpectrum_fx( Word16 *pL_spec, /* o : length of the coded spectrum Q0 */ Word16 *ptcx_offset, /* o : folding point offset relative to the end of the previous frame Q0 */ Word16 *pnoiseFillingBorder, /* o : noise filling border Q0 */ - Word32 spectrum_fx[], /* o : quantized MDCT spectrum */ + Word32 spectrum_fx[], /* o : quantized MDCT spectrum Q(31-spectrum_e)*/ Word16 *spectrum_e, /* o : exp of quantized MDCT spectrum */ CONTEXT_HM_CONFIG *hm_cfg, /* o : Context-based harmonic model configuration */ Word16 *hm_active, /* o : flag indicating if the harmonic model is active */ Word16 lf_deemph_fact_fx[], /* o : low frequency deemphasis factors Q14*/ Word16 *nf_seed, /* o : noise filling random seed Q0*/ - Word32 *ener_fx, /* o : energy of the quantized spectrum */ + Word32 *ener_fx, /* o : energy of the quantized spectrum Q(31-ener_e) */ Word16 *ener_e, /* o : exp of energy of the quantized spectrum */ - Word16 *gain_tcx_fx, /* o : global gain */ + Word16 *gain_tcx_fx, /* o : global gain Q(15-gain_tcx_e) */ Word16 *gain_tcx_e, /* o : exp of global gain */ Word16 prm[] /* o : tcx parameters Q0 */ ) @@ -3704,6 +3716,7 @@ void QuantizeTCXSpectrum_fx( IF( EQ_16( st->core, TCX_20_CORE ) ) { L_frame_glob = st->L_frame; + move16(); } ELSE { @@ -3947,12 +3960,12 @@ void QuantizeTCXSpectrum_fx( #endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS - if ( GT_16( hTcxEnc->tcx_target_bits_fac, 20480 ) ) + if ( GT_16( hTcxEnc->tcx_target_bits_fac, 20480 /*1.25 in Q14*/ ) ) { hTcxEnc->tcx_target_bits_fac = 20480; move16(); } - if ( LT_16( hTcxEnc->tcx_target_bits_fac, 12288 ) ) + if ( LT_16( hTcxEnc->tcx_target_bits_fac, 12288 /*.75 in Q14*/ ) ) { hTcxEnc->tcx_target_bits_fac = 12288; move16(); @@ -4215,8 +4228,10 @@ void QuantizeTCXSpectrum_fx( FOR( i = 0; i < L_spec; i++ ) { spectrum_fx[i] = (Word32) sqQ[i]; + move32(); /* noise filling seed */ *nf_seed = (Word16) L_add( *nf_seed, L_mult0( abs_s( sqQ[i] ), shl( i, 1 ) ) ); + move16(); } tmp32 = L_deposit_l( 0 ); @@ -4321,6 +4336,7 @@ void QuantizeTCXSpectrum_fx( { calculate_hangover_attenuation_gain_ivas_fx( st, &att_fx, vad_hover_flag ); *gain_tcx_fx = mult( *gain_tcx_fx, att_fx ); + move16(); } /*-----------------------------------------------------------* @@ -4404,13 +4420,13 @@ void coder_tcx_fx( TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 A[], /* input: quantized coefficients NxAz_q[M+1] */ Word16 Aqind[], /* input: frame-independent quantized coefficients (M+1) */ - Word16 synth[], - Word16 L_frame_glob, /* input: frame length */ + Word16 synth[], /*Qx*/ + Word16 L_frame_glob, /* input: frame length */ Word16 L_frameTCX_glob, Word16 L_spec, Word16 nb_bits, /*input: bit budget*/ Word8 tcxonly, /*input: only TCX flag*/ - Word32 spectrum[], /* i/o: MDCT spectrum */ + Word32 spectrum[], /* i/o: MDCT spectrum Q(31-spectrum_e)*/ Word16 *spectrum_e, /* i/o: MDCT spectrum exponent */ Word16 prm[], /* output: tcx parameters */ Encoder_State *st, @@ -4506,6 +4522,7 @@ void coder_tcx_fx( /* DCT */ edct_fx( tmp_buf, spectrum, L_frame, &Q ); *spectrum_e = sub( 31, Q ); + move16(); } @@ -4544,8 +4561,7 @@ void coder_tcx_fx( powerSpec, &powerSpec_e ); IF( hTcxCfg->fIsTNSAllowed != 0 ) { - test(); - test(); + SetTnsConfig( hTcxCfg, sub( L_frame_glob, st->L_frame ) == 0, st->last_core == 0 ); TNSAnalysis_fx( hTcxCfg, L_frame, L_spec, TCX_20, st->last_core == 0, spectrum, hTcxEnc->tnsData, hTcxEnc->fUseTns, &st->hIGFEnc->tns_predictionGain ); @@ -4598,6 +4614,7 @@ void coder_tcx_fx( #ifndef MSAN_FIX hLPDmem->nbits = add( hLPDmem->nbits, add( tnsBits, ltpBits ) ); + move16(); #endif } @@ -4676,18 +4693,18 @@ void InternalTCXDecoder_fx( const Word16 tcx_offset, /* i : folding point offset relative to the end of the previous frame */ const Word16 noiseFillingBorder, /* i : noise filling border */ const Word32 *x_quant_fx, /* i : quantized spectrum, exponent same as spectrum_e */ - const Word32 ener_fx, /* i : energy of the quantized spectrum */ + const Word32 ener_fx, /* i : energy of the quantized spectrum Q(31-ener_e) */ const Word16 ener_e, /* i : exponent of energy of the quantized spectrum */ Word16 lf_deemph_fact_fx[], /* i/o: low frequency deemphasis factors */ const Word16 fac_ns_fx, /* i : noise filling level, Q15 */ const Word16 nf_seed, /* i : noise filling random seed, Q0 */ const Word16 *A_fx, /* i : LPC representation of the FDNS gains, Q = 14 - norm_s(A_fx[0]) */ - Word16 gainlpc_fx[], /* i/o: FDNS gains */ + Word16 gainlpc_fx[], /* i/o: FDNS gains Q(15-gainlpc_e) */ Word16 gainlpc_e[], /* i/o: FDNS gains exponents */ const Word16 hm_active, /* i : flag indicating if the harmonic model is active */ - Word16 gain_tcx_fx, /* i/o: global gain / quantized global gain */ + Word16 gain_tcx_fx, /* i/o: global gain / quantized global gain Q(15-gain_tcx_e) */ Word16 *gain_tcx_e, /* i/o: global gain / quantized global gain exponent */ - Word32 spectrum_fx[], /* o : dequantized spectrum */ + Word32 spectrum_fx[], /* o : dequantized spectrum Q(31-spectrum_e) */ Word16 *spectrum_e, /* o : exponent of dequantized spectrum */ Word16 synth[], /* o : time domain signal */ Word16 *gain_tcx_q /* o : quantized global gain (at low bitrates), Q0 */ @@ -4767,7 +4784,7 @@ void InternalTCXDecoder_fx( tmp2 = add( tmp2, sub( ener_e, add( shl( sub( *spectrum_e, s ), 1 ), 1 ) ) ); tmp1 = Sqrt16( tmp1, &tmp2 ); - gain_tcx_fx = mult( gain_tcx_fx, tmp1 ); + gain_tcx_fx = mult( gain_tcx_fx, tmp1 ); // Q(15-(gain_tcx_e+tmp2)) *gain_tcx_e = add( *gain_tcx_e, tmp2 ); move16(); @@ -4792,11 +4809,11 @@ void InternalTCXDecoder_fx( test(); IF( NE_16( len, L_frame ) && LT_16( q_spec, sub( 31, *spectrum_e ) ) ) { - scale_sig32( spectrum_fx + len, sub( L_frame, len ), sub( q_spec, sub( 15, *spectrum_e ) ) ); + scale_sig32( spectrum_fx + len, sub( L_frame, len ), sub( q_spec, sub( 15, *spectrum_e ) ) ); // q_spec } ELSE IF( NE_16( len, L_frame ) && GT_16( q_spec, sub( 31, *spectrum_e ) ) ) { - scale_sig32( spectrum_fx, len, sub( sub( 15, *spectrum_e ), q_spec ) ); + scale_sig32( spectrum_fx, len, sub( sub( 15, *spectrum_e ), q_spec ) ); // Q(31-spectrum_e) q_spec = sub( 31, *spectrum_e ); } *spectrum_e = sub( 31, q_spec ); @@ -4810,7 +4827,7 @@ void InternalTCXDecoder_fx( * Apply gain * *-----------------------------------------------------------*/ - IF( EQ_16( st->hTcxCfg->coder_type, INACTIVE ) ) + IF( st->hTcxCfg->coder_type == INACTIVE ) { gain_tcx_fx = mult_r( gain_tcx_fx, st->hTcxCfg->na_scale ); } @@ -5089,7 +5106,6 @@ void InternalTCXDecoder_fx( 0 ); - move16(); tmpP16 = xn_buf16 + add( sub( L_win, shr( L_ola, 1 ) ), shr( overlap, 1 ) ); tcx_windowing_synthesis_past_frame( tmpP16, @@ -5432,7 +5448,7 @@ void InternalTCXDecoder_fx( st->hTcxCfg->tcx_curr_overlap_mode ); /* If current overlap mode = FULL_OVERLAP -> ALDO_WINDOW */ - IF( EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) + IF( st->hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) { FOR( i = 0; i < nz; i++ ) { diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 667bd89ae5263b104e00fb15f8027537d0b1cd69..a691405329f4a1b880546efa9ec988965d03ddac 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -250,9 +250,9 @@ ivas_error ivas_core_enc_fx( } IF( EQ_32( ivas_format, SBA_FORMAT ) ) { - IF( NE_32( ( error = pre_proc_ivas( st, last_element_mode, element_brate, last_element_brate, input_frame, old_inp_12k8_fx[n] /* i: -1, o: Q_new - 1 */, old_inp_16k_fx[n] /* i: -1, o: Q_new - 1 */, - &inp_fx[n], &ener_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], new_inp_resamp16k_fx[n], &Voicing_flag[n], old_wsp_fx[n], e_old_wsp[n], loc_harm[n], - vad_flag_dtx[n], MCT_flag, vad_hover_flag[n], flag_16k_smc, enerBuffer_fx[n], enerBuffer_fx_exp[n], fft_buff_fx[n], cor_map_sum_fx[n], &Q_new[n] ) ), + IF( NE_32( ( error = pre_proc_ivas_fx( st, last_element_mode, element_brate, last_element_brate, input_frame, old_inp_12k8_fx[n] /* i: -1, o: Q_new - 1 */, old_inp_16k_fx[n] /* i: -1, o: Q_new - 1 */, + &inp_fx[n], &ener_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], new_inp_resamp16k_fx[n], &Voicing_flag[n], old_wsp_fx[n], e_old_wsp[n], loc_harm[n], + vad_flag_dtx[n], MCT_flag, vad_hover_flag[n], flag_16k_smc, enerBuffer_fx[n], enerBuffer_fx_exp[n], fft_buff_fx[n], cor_map_sum_fx[n], &Q_new[n] ) ), IVAS_ERR_OK ) ) { return error; @@ -260,9 +260,9 @@ ivas_error ivas_core_enc_fx( } ELSE { - IF( NE_32( ( error = pre_proc_ivas( st, last_element_mode, element_brate, element_brate, input_frame, old_inp_12k8_fx[n] /* i: -1, o: Q_new - 1 */, old_inp_16k_fx[n] /* i: -1, o: Q_new - 1 */, - &inp_fx[n], &ener_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], new_inp_resamp16k_fx[n], &Voicing_flag[n], old_wsp_fx[n], e_old_wsp[n], loc_harm[n], - vad_flag_dtx[n], MCT_flag, vad_hover_flag[n], flag_16k_smc, enerBuffer_fx[n], enerBuffer_fx_exp[n], fft_buff_fx[n], cor_map_sum_fx[n], &Q_new[n] ) ), + IF( NE_32( ( error = pre_proc_ivas_fx( st, last_element_mode, element_brate, element_brate, input_frame, old_inp_12k8_fx[n] /* i: -1, o: Q_new - 1 */, old_inp_16k_fx[n] /* i: -1, o: Q_new - 1 */, + &inp_fx[n], &ener_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], new_inp_resamp16k_fx[n], &Voicing_flag[n], old_wsp_fx[n], e_old_wsp[n], loc_harm[n], + vad_flag_dtx[n], MCT_flag, vad_hover_flag[n], flag_16k_smc, enerBuffer_fx[n], enerBuffer_fx_exp[n], fft_buff_fx[n], cor_map_sum_fx[n], &Q_new[n] ) ), IVAS_ERR_OK ) ) { return error; diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index e1f138a84b4f8219a235de75b0a1da43cc672d27..8c2c31adb023e7ded5165a82b24593b48b56e3dd 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -45,40 +45,40 @@ #include "basop_util.h" /*-------------------------------------------------------------------* - * pre_proc_ivas() + * pre_proc_ivas_fx() * * Pre-processing (Selection of internal Fs, classification, SC VBR decision, * Decision matrix, Preprocessing at other Fs, core switching decision, ...) *--------------------------------------------------------------------*/ -ivas_error pre_proc_ivas( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 last_element_mode, /* i : last element mode */ - const Word32 element_brate, /* i : element bitrate */ - const Word32 last_element_brate, /* i : last element bitrate */ - const Word16 input_frame, /* i : frame length */ - Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal Q_new-1 */ - Word16 old_inp_16k_fx[], /* i/o: buffer of old input signal @ 16kHz Q_new-1 */ - Word16 **inp_fx, /* o : ptr. to inp. signal in the current frame*/ - Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q */ - Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ - Word32 epsP_fx[M + 1], /* i : LP prediction errors epsP_fx_q */ - Word16 *epsP_fx_q, /* i : LP prediction errors */ - Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ - Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame */ - Word16 *new_inp_resamp16k_fx, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - Word16 *Voicing_flag, /* o : voicing flag for HQ FEC */ - Word16 old_wsp_fx[], /* i : weighted input signal buffer */ +ivas_error pre_proc_ivas_fx( + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 last_element_mode, /* i : last element mode Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + const Word32 last_element_brate, /* i : last element bitrate Q0*/ + const Word16 input_frame, /* i : frame length Q0*/ + Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal Q_new-1 */ + Word16 old_inp_16k_fx[], /* i/o: buffer of old input signal @ 16kHz Q_new-1 */ + Word16 **inp_fx, /* o : ptr. to inp. signal in the current frame Q_new*/ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q*/ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes Q12*/ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes Q14*/ + Word32 epsP_fx[M + 1], /* i : LP prediction errors epsP_fx_q*/ + Word16 *epsP_fx_q, /* i : LP prediction errors */ + Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame Q15*/ + Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame Q15*/ + Word16 *new_inp_resamp16k_fx, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE Q_new-1*/ + Word16 *Voicing_flag, /* o : voicing flag for HQ FEC Q0*/ + Word16 old_wsp_fx[], /* i : weighted input signal buffer e_old_wsp*/ Word16 e_old_wsp, - const Word16 loc_harm, /* i : harmonicity flag */ - const Word16 vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const Word16 vad_hover_flag, /* i : VAD hangover flag */ - const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */ - Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], + const Word16 loc_harm, /* i : harmonicity flag Q0*/ + const Word16 vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO Q0*/ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ + const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ + Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* e_enerBuffer */ Word16 e_enerBuffer, - Word16 fft_buff_fx[2 * L_FFT], - Word16 cor_map_sum_fx, // Q8 + Word16 fft_buff_fx[2 * L_FFT], /* Qx */ + Word16 cor_map_sum_fx, /* Q8 */ Word16 *Q_new ) { Word16 L_look, element_mode, lMemRecalc_12k8; @@ -138,13 +138,13 @@ ivas_error pre_proc_ivas( IF( st->core_brate == FRAME_NO_DATA ) { /* prevent "L_frame" changes in CNG segments */ - st->L_frame = st->last_L_frame; + st->L_frame = st->last_L_frame; /* Q0 */ move16(); } ELSE IF( EQ_32( st->core_brate, SID_2k40 ) && GE_16( st->bwidth, WB ) && st->hDtxEnc->first_CNG && ( st->hTdCngEnc != NULL && LT_16( st->hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) ) ) { /* prevent "L_frame" changes in SID frame after short segment of active frames */ - st->L_frame = st->hDtxEnc->last_CNG_L_frame; + st->L_frame = st->hDtxEnc->last_CNG_L_frame; /* Q0 */ move16(); } ELSE IF( ( ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && GE_32( st->element_brate, IVAS_64k ) && GE_16( st->bwidth, SWB ) ) || ( EQ_16( element_mode, IVAS_SCE ) && GT_32( st->total_brate, MAX_ACELP_BRATE ) && GE_16( st->bwidth, SWB ) ) ) && NE_32( st->core_brate, SID_2k40 ) ) @@ -191,7 +191,7 @@ ivas_error pre_proc_ivas( if ( st->ini_frame == 0 ) { /* avoid switching of internal ACELP Fs in the very first frame */ - st->last_L_frame = st->L_frame; + st->last_L_frame = st->L_frame; /* Q0 */ move16(); } @@ -217,9 +217,9 @@ ivas_error pre_proc_ivas( move16(); } - st->sr_core = L_mult0( st->L_frame, FRAMES_PER_SEC ); - st->encoderLookahead_enc = NS2SA_FX2( st->sr_core, ACELP_LOOK_NS ); - st->encoderPastSamples_enc = shr( ( imult1616( st->L_frame, 9 ) ), 4 ); + st->sr_core = L_mult0( st->L_frame, FRAMES_PER_SEC ); /* Q0 */ + st->encoderLookahead_enc = NS2SA_FX2( st->sr_core, ACELP_LOOK_NS ); /* Q0 */ + st->encoderPastSamples_enc = shr( ( imult1616( st->L_frame, 9 ) ), 4 ); /* Q0 */ move32(); move16(); move16(); @@ -248,7 +248,7 @@ ivas_error pre_proc_ivas( test(); test(); /* enforce TRANSITION frames */ - IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) && NE_16( st->last_L_frame, st->L_frame ) && NE_32( st->core_brate, FRAME_NO_DATA ) && NE_32( st->core_brate, SID_2k40 ) && NE_32( st->last_core_brate, FRAME_NO_DATA ) && NE_32( st->last_core_brate, SID_2k40 ) && NE_16( st->coder_type_raw, VOICED ) ) + IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) && NE_16( st->last_L_frame, st->L_frame ) && st->core_brate != FRAME_NO_DATA && NE_32( st->core_brate, SID_2k40 ) && st->last_core_brate != FRAME_NO_DATA && NE_32( st->last_core_brate, SID_2k40 ) && NE_16( st->coder_type_raw, VOICED ) ) { /* enforce TC frame in case of ACELP@12k8 <-> ACELP@16k core switching */ st->coder_type = TRANSITION; @@ -298,10 +298,11 @@ ivas_error pre_proc_ivas( st->mdct_sw_enable = MODE1; move16(); move16(); + test(); test(); test(); - IF( ( LE_32( st->total_brate, MIN_BRATE_GSC_NOISY_FLAG ) || LT_16( st->bwidth, SWB ) || st->flag_ACELP16k ) && st->GSC_IVAS_mode == 0 ) + if ( ( LE_32( st->total_brate, MIN_BRATE_GSC_NOISY_FLAG ) || LT_16( st->bwidth, SWB ) || st->flag_ACELP16k ) && st->GSC_IVAS_mode == 0 ) { st->GSC_noisy_speech = 0; move16(); @@ -311,7 +312,7 @@ ivas_error pre_proc_ivas( ivas_decision_matrix_enc_fx( st, element_brate, fft_buff_fx, enerBuffer_fx, e_enerBuffer, last_element_mode ); test(); test(); - IF( EQ_16( st->L_frame, L_FRAME16k ) && ( EQ_16( st->coder_type, VOICED ) || EQ_16( st->coder_type, UNVOICED ) ) ) /* VOICED and UNVOICED are not supported in ACELP@16k */ + if ( EQ_16( st->L_frame, L_FRAME16k ) && ( EQ_16( st->coder_type, VOICED ) || EQ_16( st->coder_type, UNVOICED ) ) ) /* VOICED and UNVOICED are not supported in ACELP@16k */ { st->coder_type = GENERIC; move16(); @@ -323,22 +324,22 @@ ivas_error pre_proc_ivas( st->Nb_ACELP_frames = 0; move16(); /* Configure TCX with the same bitrate as given when (re-)initializing TCX */ - total_brate_tmp = st->total_brate; + total_brate_tmp = st->total_brate; /* Q0 */ move32(); - st->total_brate = L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ); + st->total_brate = L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ); /* Q0 */ move32(); - SetModeIndex_ivas_fx( st, st->last_bits_frame_nominal * FRAMES_PER_SEC, last_element_mode, MCT_flag ); + SetModeIndex_ivas_fx( st, imult3216( st->last_bits_frame_nominal, FRAMES_PER_SEC ), last_element_mode, MCT_flag ); - st->sr_core = getCoreSamplerateMode2( element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format ); + st->sr_core = getCoreSamplerateMode2( element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format ); /* Q0 */ move16(); - st->total_brate = total_brate_tmp; + st->total_brate = total_brate_tmp; /* Q0 */ move32(); - st->L_frame = extract_l( Mpy_32_32( st->sr_core, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + st->L_frame = extract_l( Mpy_32_32( st->sr_core, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /* Q0 */ move16(); - st->encoderLookahead_enc = NS2SA_FX2( st->sr_core, ACELP_LOOK_NS ); - st->encoderPastSamples_enc = shr( ( imult1616( st->L_frame, 9 ) ), 4 ); + st->encoderLookahead_enc = NS2SA_FX2( st->sr_core, ACELP_LOOK_NS ); /* Q0 */ + st->encoderPastSamples_enc = shr( ( imult1616( st->L_frame, 9 ) ), 4 ); /* Q0 */ move16(); move16(); @@ -393,7 +394,7 @@ ivas_error pre_proc_ivas( test(); test(); - IF( NE_16( st->extl, -1 ) && NE_16( st->extl, IGF_BWE ) && EQ_16( st->igf, 1 ) ) + if ( NE_16( st->extl, -1 ) && NE_16( st->extl, IGF_BWE ) && EQ_16( st->igf, 1 ) ) { st->igf = 0; move16(); @@ -409,12 +410,12 @@ ivas_error pre_proc_ivas( test(); IF( EQ_16( loc_harm, 1 ) && GT_16( cor_map_sum_fx, 50 << 8 ) && EQ_16( st->clas, VOICED_CLAS ) && EQ_16( st->coder_type, GENERIC ) ) { - st->last_harm_flag_acelp = add( st->last_harm_flag_acelp, 1 ); + st->last_harm_flag_acelp = add( st->last_harm_flag_acelp, 1 ); /* Q0 */ move16(); IF( GT_16( st->last_harm_flag_acelp, 10 ) ) { - st->last_harm_flag_acelp = 10; + st->last_harm_flag_acelp = 10; /* Q0 */ move16(); } } @@ -430,22 +431,22 @@ ivas_error pre_proc_ivas( IF( EQ_16( st->coder_type, AUDIO ) ) { - st->audio_frame_cnt = add( st->audio_frame_cnt, AUDIO_COUNTER_STEP ); + st->audio_frame_cnt = add( st->audio_frame_cnt, AUDIO_COUNTER_STEP ); /* Q0 */ move16(); } - ELSE IF( NE_16( st->coder_type, INACTIVE ) ) + ELSE IF( st->coder_type != INACTIVE ) { - st->audio_frame_cnt = sub( st->audio_frame_cnt, 1 ); + st->audio_frame_cnt = sub( st->audio_frame_cnt, 1 ); /* Q0 */ move16(); } - IF( GT_16( st->audio_frame_cnt, AUDIO_COUNTER_MAX ) ) + if ( GT_16( st->audio_frame_cnt, AUDIO_COUNTER_MAX ) ) { - st->audio_frame_cnt = AUDIO_COUNTER_MAX; + st->audio_frame_cnt = AUDIO_COUNTER_MAX; /* Q0 */ move16(); } - IF( st->audio_frame_cnt < 0 ) + if ( st->audio_frame_cnt < 0 ) { st->audio_frame_cnt = 0; move16(); @@ -478,7 +479,7 @@ ivas_error pre_proc_ivas( /* channel-aware mode - due to lack of signaling bit, sharpFlag is 1 always in RF mode */ test(); test(); - IF( st->rf_mode && ( EQ_16( st->coder_type, VOICED ) || EQ_16( st->coder_type, GENERIC ) ) ) + if ( st->rf_mode && ( EQ_16( st->coder_type, VOICED ) || EQ_16( st->coder_type, GENERIC ) ) ) { st->sharpFlag = 1; move16(); @@ -491,7 +492,7 @@ ivas_error pre_proc_ivas( st->sharpFlag = 0; move16(); test(); - IF( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, VOICED ) ) + if ( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, VOICED ) ) { st->sharpFlag = 1; move16(); @@ -528,7 +529,7 @@ ivas_error pre_proc_ivas( sr_core_tmp = L_max( INT_FS_16k, st->sr_core ); } - L_look = NS2SA( sr_core_tmp, ACELP_LOOK_NS ); /* lookahead at other sampling rate (16kHz, 25.6kHz, 32kHz) */ + L_look = NS2SA( sr_core_tmp, ACELP_LOOK_NS ); /* lookahead at other sampling rate (16kHz, 25.6kHz, 32kHz) Q0*/ move16(); inp_16k_fx = old_inp_16k_fx + L_INP_MEM - L_look; @@ -541,34 +542,35 @@ ivas_error pre_proc_ivas( inp_16k_fx = old_inp_16k_fx + L_INP_MEM - L_look; Word16 shift = getScaleFactor16( st->old_inp_12k8_fx, L_INP_MEM ); - Scale_sig( st->old_inp_12k8_fx, L_INP_MEM, shift ); + Scale_sig( st->old_inp_12k8_fx, L_INP_MEM, shift ); /* exp(st->exp_old_inp_12k8 - shift) */ st->exp_old_inp_12k8 = sub( st->exp_old_inp_12k8, shift ); move16(); - Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( Q_old_inp_16k, sub( Q15, st->exp_old_inp_16k ) ) ); + Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( Q_old_inp_16k, sub( Q15, st->exp_old_inp_16k ) ) ); /* Q15 - st->exp_old_inp_16k */ st->exp_old_inp_16k = sub( Q15, Q_old_inp_16k ); move16(); IF( st->hBWE_FD != NULL ) { - Scale_sig( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, sub( -1, st->Q_old_wtda ) ); - st->Q_old_wtda = -1; // This reset needs to be looked into + Scale_sig( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, sub( -1, st->Q_old_wtda ) ); /* -1Q */ + st->Q_old_wtda = -1; // This reset needs to be looked into move16(); } - st->mem_preemph_enc = shl( st->mem_preemph_enc, sub( Q_old_inp_16k, sub( Q15, st->exp_mem_preemph_enc ) ) ); + st->mem_preemph_enc = shl( st->mem_preemph_enc, sub( Q_old_inp_16k, sub( Q15, st->exp_mem_preemph_enc ) ) ); /* Q15 - Q_old_inp_16k */ move16(); st->exp_mem_preemph_enc = sub( Q15, Q_old_inp_16k ); move16(); - Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_speech_enc ) ) ); + Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_speech_enc ) ) ); /* Q15 - Q_old_inp_16k */ st->exp_buf_speech_enc = sub( Q15, Q_old_inp_16k ); move16(); - Scale_sig( st->buf_speech_enc_pe, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_speech_enc_pe ) ) ); + Scale_sig( st->buf_speech_enc_pe, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_speech_enc_pe ) ) ); /* Q15 - Q_old_inp_16k */ st->exp_buf_speech_enc_pe = sub( Q15, Q_old_inp_16k ); move16(); Scale_sig( st->input_fx, input_frame, sub( -1, st->q_inp ) ); st->q_inp = -1; - Scale_sig( st->buf_wspeech_enc, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_wspeech_enc ) ) ); + move16(); + Scale_sig( st->buf_wspeech_enc, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_wspeech_enc ) ) ); /* Q15 - Q_old_inp_16k */ st->exp_buf_wspeech_enc = sub( Q15, Q_old_inp_16k ); move16(); Word16 Q_old_inp_128k = *Q_new; @@ -579,7 +581,7 @@ ivas_error pre_proc_ivas( A_fx, Aw_fx, epsP_fx, lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, Q_new, 0 ); - IF( NE_32( error, IVAS_ERR_OK ) ) + IF( error != IVAS_ERR_OK ) { return error; } @@ -596,15 +598,15 @@ ivas_error pre_proc_ivas( test(); IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { - Copy( st->buf_speech_enc + L_FRAME32k - STEREO_DFT_OVL_12k8, st->buf_speech_enc + st->L_frame - STEREO_DFT_OVL_12k8, STEREO_DFT_OVL_12k8 ); + Copy( st->buf_speech_enc + L_FRAME32k - STEREO_DFT_OVL_12k8, st->buf_speech_enc + st->L_frame - STEREO_DFT_OVL_12k8, STEREO_DFT_OVL_12k8 ); /* Q_new - 1 */ } ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) { - Copy( st->buf_speech_enc + L_FRAME32k - lMemRecalc_12k8 - L_FILT, st->buf_speech_enc + st->L_frame - lMemRecalc_12k8 - L_FILT, lMemRecalc_12k8 + L_FILT ); + Copy( st->buf_speech_enc + L_FRAME32k - lMemRecalc_12k8 - L_FILT, st->buf_speech_enc + st->L_frame - lMemRecalc_12k8 - L_FILT, lMemRecalc_12k8 + L_FILT ); /* Q_new - 1 */ } ELSE IF( EQ_16( element_mode, IVAS_SCE ) ) { - Copy( st->buf_speech_enc + L_FRAME32k - L_FILT, st->buf_speech_enc + st->L_frame - L_FILT, L_FILT ); + Copy( st->buf_speech_enc + L_FRAME32k - L_FILT, st->buf_speech_enc + st->L_frame - L_FILT, L_FILT ); /* Q_new - 1 */ } IF( st->tcxonly == 0 ) @@ -615,7 +617,7 @@ ivas_error pre_proc_ivas( IF( flag_16k_smc ) { - Copy( st->buf_speech_enc + L_FRAME16k, new_inp_resamp16k_fx, L_FRAME16k ); + Copy( st->buf_speech_enc + L_FRAME16k, new_inp_resamp16k_fx, L_FRAME16k ); /* Q_new - 1 */ } /*-----------------------------------------------------------------* @@ -623,14 +625,14 @@ ivas_error pre_proc_ivas( *-----------------------------------------------------------------*/ /* update old weighted speech buffer - for OL pitch analysis */ - Copy( &old_wsp_fx[L_FRAME], st->old_wsp_fx, L_WSP_MEM ); + Copy( &old_wsp_fx[L_FRAME], st->old_wsp_fx, L_WSP_MEM ); /* exp(e_old_wsp) */ st->exp_old_wsp = e_old_wsp; move16(); /* set the pointer of the current frame for the ACELP core */ IF( EQ_16( st->L_frame, L_FRAME ) ) { - *inp_fx = inp_12k8_fx; + *inp_fx = inp_12k8_fx; /* Q_old_inp_128k */ *Q_new = Q_old_inp_128k; move16(); } @@ -650,7 +652,7 @@ ivas_error pre_proc_ivas( test(); IF( st->hTdCngEnc != NULL && st->Opt_DTX_ON && vad_hover_flag ) { - st->hTdCngEnc->burst_ho_cnt = add( st->hTdCngEnc->burst_ho_cnt, 1 ); + st->hTdCngEnc->burst_ho_cnt = add( st->hTdCngEnc->burst_ho_cnt, 1 ); /* Q0 */ move16(); if ( GT_16( st->hTdCngEnc->burst_ho_cnt, HO_HIST_SIZE ) ) { @@ -676,22 +678,23 @@ ivas_error pre_proc_ivas( *--------------------------------------------------------------------*/ ivas_error ivas_compute_core_buffers_fx( Encoder_State *st, /* i/o: encoder state structure */ - Word16 **inp16k_out_fx, /* o : ptr. to inp. signal in the current frame */ - Word16 *old_inp_16k_fx, /* i/o: buffer of old input signal @ 16kHz */ - Word16 new_inp_resamp16k_out_fx[], /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - const Word16 input_frame, /* i : frame length */ - const Word16 last_element_mode, /* i : last element mode */ - const Word32 sr_core, /* i : core-coder sampling rate */ - Word32 *ener_fx, /* o : residual energy from Levinson-Durbin Q_r */ - Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ - Word32 epsP_fx[M + 1], /* i/o: LP prediction errors */ - Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ - Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame */ + Word16 **inp16k_out_fx, /* o : ptr. to inp. signal in the current frame Q_new-1*/ + Word16 *old_inp_16k_fx, /* i/o: buffer of old input signal @ 16kHz Q_new-1*/ + Word16 new_inp_resamp16k_out_fx[], /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE Q_old_inp_16k*/ + const Word16 input_frame, /* i : frame length Q0*/ + const Word16 last_element_mode, /* i : last element mode Q0*/ + const Word32 sr_core, /* i : core-coder sampling rate Q0*/ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin Q_r*/ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes Q14*/ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes Q14*/ + Word32 epsP_fx[M + 1], /* i/o: LP prediction errors Q_r*/ + Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame Q15*/ + Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame Q15*/ Word16 Q_old_inp_16k, Word16 Q_r[2], Word16 *Q_new, - Word16 downscale_buf_speech_enc_pe ) + Word16 downscale_buf_speech_enc_pe /* Q0 */ +) { Word16 *inp_16k_fx, *new_inp_16k_fx; Word16 delay, element_mode; @@ -718,11 +721,11 @@ ivas_error ivas_compute_core_buffers_fx( #endif set16_fx( epsP_h, 0, M + 1 ); set16_fx( epsP_l, 0, M + 1 ); - signal_in_fx = st->input_fx; + signal_in_fx = st->input_fx; /* st->q_inp */ - input_Fs = st->input_Fs; + input_Fs = st->input_Fs; /* Q0 */ move32(); - element_mode = st->element_mode; + element_mode = st->element_mode; /* Q0 */ move16(); lMemRecalc_16k = 0; @@ -766,15 +769,15 @@ ivas_error ivas_compute_core_buffers_fx( IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { - Copy( st->old_inp_16k_fx, old_inp_16k_fx, L_INP_MEM - STEREO_DFT_OVL_16k ); + Copy( st->old_inp_16k_fx, old_inp_16k_fx, L_INP_MEM - STEREO_DFT_OVL_16k ); /* Q_new - 1 */ } ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) ) { - Copy( st->old_inp_16k_fx, old_inp_16k_fx, L_INP_MEM - L_MEM_RECALC_16K - L_FILT16k ); + Copy( st->old_inp_16k_fx, old_inp_16k_fx, L_INP_MEM - L_MEM_RECALC_16K - L_FILT16k ); /* Q_new - 1 */ } ELSE { - Copy( st->old_inp_16k_fx, old_inp_16k_fx, L_INP_MEM - L_FILT16k ); + Copy( st->old_inp_16k_fx, old_inp_16k_fx, L_INP_MEM - L_FILT16k ); /* Q_new - 1 */ } /*---------------------------------------------------------------* @@ -790,18 +793,18 @@ ivas_error ivas_compute_core_buffers_fx( delay = NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ); move16(); Copy( st->mem_decim16k_fx + delay, new_inp_16k_fx, delay ); - Copy( signal_in_fx, new_inp_16k_fx + delay, input_frame ); - Copy( signal_in_fx + input_frame - shl( delay, 1 ), st->mem_decim16k_fx, shl( delay, 1 ) ); + Copy( signal_in_fx, new_inp_16k_fx + delay, input_frame ); /* st->q_inp */ + Copy( signal_in_fx + input_frame - shl( delay, 1 ), st->mem_decim16k_fx, shl( delay, 1 ) ); /* st->q_inp */ } ELSE IF( EQ_32( input_Fs, 32000 ) || EQ_32( input_Fs, 48000 ) ) { - size_modified = modify_Fs_ivas_fx( signal_in_fx, input_frame, input_Fs, new_inp_16k_fx, sr_core, st->mem_decim16k_fx, 0, &Q_tmp, &mem_decim16k_size ); - Scale_sig( new_inp_16k_fx, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ + size_modified = modify_Fs_ivas_fx( signal_in_fx, input_frame, input_Fs, new_inp_16k_fx, sr_core, st->mem_decim16k_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ + Scale_sig( new_inp_16k_fx, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ - Copy( st->mem_decim16k_fx, mem_decim16k_dummy_fx, 2 * L_FILT_MAX ); + Copy( st->mem_decim16k_fx, mem_decim16k_dummy_fx, 2 * L_FILT_MAX ); /* Q(-1) */ set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); - size_modified = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_16k_fx + NS2SA( sr_core, FRAME_SIZE_NS ), sr_core, mem_decim16k_dummy_fx, 0, &Q_tmp, &mem_decim16k_size ); - Scale_sig( new_inp_16k_fx + NS2SA( sr_core, FRAME_SIZE_NS ), size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ + size_modified = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_16k_fx + NS2SA( sr_core, FRAME_SIZE_NS ), sr_core, mem_decim16k_dummy_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ + Scale_sig( new_inp_16k_fx + NS2SA( sr_core, FRAME_SIZE_NS ), size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ } } ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) ) @@ -812,9 +815,9 @@ ivas_error ivas_compute_core_buffers_fx( /* no resampling needed, only delay adjustment to account for the FIR resampling delay */ delay = NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ); move16(); - Copy( st->mem_decim16k_fx + delay, new_inp_16k_fx - sub( lMemRecalc, add( delay, L_FILT16k ) ), delay ); - Copy( signal_in_fx - lMemRecalc, new_inp_16k_fx - add( lMemRecalc, L_FILT16k ), add( input_frame, lMemRecalc ) ); - Copy( signal_in_fx + sub( sub( input_frame, lMemRecalc ), shl( delay, 1 ) ), st->mem_decim16k_fx, shl( delay, 1 ) ); + Copy( st->mem_decim16k_fx + delay, new_inp_16k_fx - sub( lMemRecalc, add( delay, L_FILT16k ) ), delay ); /* Q(-1) */ + Copy( signal_in_fx - lMemRecalc, new_inp_16k_fx - add( lMemRecalc, L_FILT16k ), add( input_frame, lMemRecalc ) ); /* st->q_inp */ + Copy( signal_in_fx + sub( sub( input_frame, lMemRecalc ), shl( delay, 1 ) ), st->mem_decim16k_fx, shl( delay, 1 ) ); /* st->q_inp */ } ELSE IF( EQ_32( input_Fs, 32000 ) || EQ_32( input_Fs, 48000 ) ) { @@ -826,30 +829,30 @@ ivas_error ivas_compute_core_buffers_fx( Word16 length_16k = NS2SA_FX2( INT_FS_16k, L_MEM_RECALC_SCH_NS - DELAY_FIR_RESAMPL_NS ); move16(); - Copy( signal_in_fx - lMemRecalc - length_inp - 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim16k_fx, 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ); - size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_16k_fx - lMemRecalc_16k - length_16k, sr_core, st->mem_decim16k_fx, 0, &Q_tmp, &mem_decim16k_size ); - Scale_sig( new_inp_16k_fx - lMemRecalc_16k - length_16k, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ + Copy( signal_in_fx - lMemRecalc - length_inp - 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim16k_fx, 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ); /* st->q_inp */ + size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_16k_fx - lMemRecalc_16k - length_16k, sr_core, st->mem_decim16k_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ + Scale_sig( new_inp_16k_fx - lMemRecalc_16k - length_16k, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ } - size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc, input_frame, input_Fs, new_inp_16k_fx - ( lMemRecalc * sr_core ) / st->input_Fs, sr_core, st->mem_decim16k_fx, 0, &Q_tmp, &mem_decim16k_size ); - Scale_sig( new_inp_16k_fx - ( lMemRecalc * sr_core ) / st->input_Fs, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ + size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc, input_frame, input_Fs, new_inp_16k_fx - ( lMemRecalc * sr_core ) / st->input_Fs, sr_core, st->mem_decim16k_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ + Scale_sig( new_inp_16k_fx - ( lMemRecalc * sr_core ) / st->input_Fs, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ Copy( st->mem_decim16k_fx, mem_decim16k_dummy_fx, 2 * L_FILT_MAX ); IF( lMemRecalc > 0 ) { - size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc + input_frame, lMemRecalc, input_Fs, new_inp_16k_fx + NS2SA( sr_core, FRAME_SIZE_NS ) - ( lMemRecalc * sr_core ) / st->input_Fs, sr_core, mem_decim16k_dummy_fx, 0, &Q_tmp, &mem_decim16k_size ); - Scale_sig( new_inp_16k_fx + NS2SA( sr_core, FRAME_SIZE_NS ) - ( lMemRecalc * sr_core ) / st->input_Fs, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ + size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc + input_frame, lMemRecalc, input_Fs, new_inp_16k_fx + NS2SA( sr_core, FRAME_SIZE_NS ) - ( lMemRecalc * sr_core ) / st->input_Fs, sr_core, mem_decim16k_dummy_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ + Scale_sig( new_inp_16k_fx + NS2SA( sr_core, FRAME_SIZE_NS ) - ( lMemRecalc * sr_core ) / st->input_Fs, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ } set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); - size_modified = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_16k_fx + NS2SA( sr_core, FRAME_SIZE_NS ), sr_core, mem_decim16k_dummy_fx, 0, &Q_tmp, &mem_decim16k_size ); - Scale_sig( new_inp_16k_fx + NS2SA( sr_core, FRAME_SIZE_NS ), size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ + size_modified = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_16k_fx + NS2SA( sr_core, FRAME_SIZE_NS ), sr_core, mem_decim16k_dummy_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ + Scale_sig( new_inp_16k_fx + NS2SA( sr_core, FRAME_SIZE_NS ), size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ } } ELSE IF( st->idchan == 0 ) { /* update the FIR resampling filter memory, needed for switching to time-domain (FIR) resampling */ - Copy( signal_in_fx + input_frame - NS2SA( input_Fs, L_MEM_RECALC_NS ) - 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim16k_fx, 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ); + Copy( signal_in_fx + input_frame - NS2SA( input_Fs, L_MEM_RECALC_NS ) - 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim16k_fx, 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ); /* st->q_inp */ } /*------------------------------------------------* @@ -865,12 +868,12 @@ ivas_error ivas_compute_core_buffers_fx( IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { /* save input resampled at 16kHz, non-preemphasised.*/ - Copy( new_inp_16k_fx, new_inp_resamp16k_fx, L_FRAME16k ); + Copy( new_inp_16k_fx, new_inp_resamp16k_fx, L_FRAME16k ); /* Q_old_inp_16k */ IF( EQ_16( st->bwidth, WB ) ) { - Copy_Scale_sig( new_inp_16k_fx - delay, st->hBWE_FD->old_input_wb_fx, delay, -( Q_old_inp_16k + 1 ) ); /* Scaling to Q(-1) */ - Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k, st->hBWE_FD->L_old_wtda_swb_fx + L_FRAME16k - STEREO_DFT_OVL_16k + delay, STEREO_DFT_OVL_16k - delay ); /* Check Q here once. Q should be Q_old_wtda */ + Copy_Scale_sig( new_inp_16k_fx - delay, st->hBWE_FD->old_input_wb_fx, delay, negate( add( Q_old_inp_16k, 1 ) ) ); /* Scaling to Q(-1) */ + Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k, st->hBWE_FD->L_old_wtda_swb_fx + L_FRAME16k - STEREO_DFT_OVL_16k + delay, sub( STEREO_DFT_OVL_16k, delay ) ); /* Check Q here once. Q should be Q_old_wtda */ } } ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) ) @@ -881,18 +884,18 @@ ivas_error ivas_compute_core_buffers_fx( test(); IF( EQ_16( st->bwidth, WB ) && st->hBWE_FD != NULL ) { - Copy_Scale_sig( new_inp_16k_fx + L_FILT16k - delay, st->hBWE_FD->old_input_wb_fx, delay, -( Q_old_inp_16k + 1 ) ); /* Scaling to Q(-1) */ - Copy( new_inp_16k_fx - L_MEM_RECALC_16K, st->hBWE_FD->L_old_wtda_swb_fx + L_FRAME16k - L_MEM_RECALC_16K - L_FILT16k + delay, L_MEM_RECALC_16K + L_FILT16k - delay ); /* Check Q here once. Q should be Q_old_wtda */ + Copy_Scale_sig( new_inp_16k_fx + L_FILT16k - delay, st->hBWE_FD->old_input_wb_fx, delay, negate( add( Q_old_inp_16k, 1 ) ) ); /* Scaling to Q(-1) */ + Copy( new_inp_16k_fx - L_MEM_RECALC_16K, st->hBWE_FD->L_old_wtda_swb_fx + L_FRAME16k - L_MEM_RECALC_16K - L_FILT16k + delay, sub( L_MEM_RECALC_16K + L_FILT16k, delay ) ); /* Check Q here once. Q should be Q_old_wtda */ } } ELSE IF( element_mode == IVAS_SCE ) { /* save input resampled at 16kHz, non-preemphasised */ - Copy( new_inp_16k_fx + L_FILT16k, new_inp_resamp16k_fx, L_FRAME16k ); + Copy( new_inp_16k_fx + L_FILT16k, new_inp_resamp16k_fx, L_FRAME16k ); /* Q_old_inp_16k */ IF( EQ_16( st->bwidth, WB ) ) { - Copy_Scale_sig( new_inp_16k_fx, st->hBWE_FD->old_input_wb_fx + delay - L_FILT16k, L_FILT16k, -( Q_old_inp_16k + 1 ) ); /* Scaling to Q(-1) */ + Copy_Scale_sig( new_inp_16k_fx, st->hBWE_FD->old_input_wb_fx + delay - L_FILT16k, L_FILT16k, negate( add( Q_old_inp_16k, 1 ) ) ); /* Scaling to Q(-1) */ /* all buffer st->hBWE_FD->old_wtda_swb is correct and does not need to be updated */ } } @@ -912,7 +915,7 @@ ivas_error ivas_compute_core_buffers_fx( test(); if ( st->tcxonly == 0 && !( ( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) ) { - st->mem_preemph_enc = new_inp_16k_fx[L_frame_tmp - 1]; + st->mem_preemph_enc = new_inp_16k_fx[L_frame_tmp - 1]; /* Q(-1) */ move16(); } @@ -924,7 +927,7 @@ ivas_error ivas_compute_core_buffers_fx( set32_fx( sig_out, 0, 960 ); test(); test(); - if ( ( ( EQ_16( st->bwidth, NB ) ) || ( EQ_16( st->max_bwidth, NB ) ) ) && ( GT_32( st->input_Fs, 8000 ) ) ) + if ( ( ( st->bwidth == NB ) || ( st->max_bwidth == NB ) ) && ( GT_32( st->input_Fs, 8000 ) ) ) { headroom = add( headroom, 1 ); } @@ -934,24 +937,24 @@ ivas_error ivas_compute_core_buffers_fx( { IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { - Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, st->inp_16k_mem_stereo_sw_fx, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); /* update for TD/DFT stereo switching */ + Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, st->inp_16k_mem_stereo_sw_fx, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); /* update for TD/DFT stereo switching Q(-1) */ - st->mem_preemph16k_fx = st->mem_preemph16k_DFT_fx; + st->mem_preemph16k_fx = st->mem_preemph16k_DFT_fx; /* Q(-1) */ move16(); - st->mem_preemph16k_DFT_fx = old_inp_16k_fx[L_INP_MEM - STEREO_DFT_OVL_16k + L_FRAME16k - 1]; + st->mem_preemph16k_DFT_fx = old_inp_16k_fx[L_INP_MEM - STEREO_DFT_OVL_16k + L_FRAME16k - 1]; /* Q_new - 1 */ move16(); IF( EQ_16( st->L_frame, L_FRAME16k ) ) { - Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k, st->buf_speech_enc + L_FRAME16k - STEREO_DFT_OVL_16k, L_FRAME16k + STEREO_DFT_OVL_16k ); + Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k, st->buf_speech_enc + L_FRAME16k - STEREO_DFT_OVL_16k, L_FRAME16k + STEREO_DFT_OVL_16k ); /* Q(-1) */ } // PREEMPH_FX(new_inp_16k_fx - STEREO_DFT_OVL_16k, PREEMPH_FAC_16k, L_FRAME16k, &(st->mem_preemph16k_fx)); - PREEMPH_32FX( new_inp_16k_fx - STEREO_DFT_OVL_16k, sig_out, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); + PREEMPH_32FX( new_inp_16k_fx - STEREO_DFT_OVL_16k, sig_out, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); /* Q(-1) */ tmp_fx = st->mem_preemph16k_fx; move16(); // PREEMPH_FX(new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k, &tmp_fx); - PREEMPH_32FX( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, sig_out + L_FRAME16k, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k, &tmp_fx ); + PREEMPH_32FX( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, sig_out + L_FRAME16k, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k, &tmp_fx ); /* Q(-1) */ preemp_start_idx = new_inp_16k_fx - STEREO_DFT_OVL_16k; move16(); preemp_len = STEREO_DFT_OVL_16k + L_FRAME16k; @@ -963,16 +966,16 @@ ivas_error ivas_compute_core_buffers_fx( { st->mem_preemph16k_fx = st->mem_preemph16k_DFT_fx; move16(); - Copy( st->inp_16k_mem_stereo_sw_fx, new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); + Copy( st->inp_16k_mem_stereo_sw_fx, new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); /* Q(-1) */ // PREEMPH_FX(new_inp_16k_fx - L_MEM_RECALC_16K - (STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k), PREEMPH_FAC_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k, &st->mem_preemph16k_fx); - PREEMPH_32FX( new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), sig_out, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k, &st->mem_preemph16k_fx ); + PREEMPH_32FX( new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), sig_out, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k, &st->mem_preemph16k_fx ); /* Q(-1) */ preemp_start_idx = new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); move16(); preemp_len = STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k; move16(); } - st->mem_preemph16k_DFT_fx = old_inp_16k_fx[L_INP_MEM - STEREO_DFT_OVL_16k + L_FRAME16k - 1]; + st->mem_preemph16k_DFT_fx = old_inp_16k_fx[L_INP_MEM - STEREO_DFT_OVL_16k + L_FRAME16k - 1]; /* Q_new - 1 */ move16(); /* preemphasise past segment of input signal when switching from MDCT stereo */ @@ -982,7 +985,7 @@ ivas_error ivas_compute_core_buffers_fx( move16(); // PREEMPH_FX(new_inp_16k_fx - lMemRecalc_16k - length_16k, PREEMPH_FAC, length_16k, &st->mem_preemph16k_fx); - PREEMPH_32FX( new_inp_16k_fx - lMemRecalc_16k - length_16k, sig_out, PREEMPH_FAC, length_16k, &st->mem_preemph16k_fx ); + PREEMPH_32FX( new_inp_16k_fx - lMemRecalc_16k - length_16k, sig_out, PREEMPH_FAC, length_16k, &st->mem_preemph16k_fx ); /* Q(-1) */ preemp_start_idx = new_inp_16k_fx - lMemRecalc_16k - length_16k; preemp_len = length_16k; move16(); @@ -990,14 +993,14 @@ ivas_error ivas_compute_core_buffers_fx( IF( EQ_16( st->L_frame, L_FRAME16k ) ) { - Copy( new_inp_16k_fx - lMemRecalc_16k, st->buf_speech_enc + sub( L_FRAME16k - L_FILT16k, lMemRecalc_16k ), add( lMemRecalc_16k, L_FRAME16k + L_FILT16k ) ); + Copy( new_inp_16k_fx - lMemRecalc_16k, st->buf_speech_enc + sub( L_FRAME16k - L_FILT16k, lMemRecalc_16k ), add( lMemRecalc_16k, L_FRAME16k + L_FILT16k ) ); /* Q_new - 1 */ } // PREEMPH_FX(new_inp_16k_fx - lMemRecalc_16k, PREEMPH_FAC_16k, L_FRAME16k, &(st->mem_preemph16k_fx)); - PREEMPH_32FX( new_inp_16k_fx - lMemRecalc_16k, sig_out + preemp_len, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); + PREEMPH_32FX( new_inp_16k_fx - lMemRecalc_16k, sig_out + preemp_len, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); /* Q(-1) */ tmp_fx = st->mem_preemph16k_fx; move16(); // PREEMPH_FX(new_inp_16k_fx - lMemRecalc_16k + L_FRAME16k, PREEMPH_FAC_16k, lMemRecalc_16k + L_FILT16k, &tmp_fx); - PREEMPH_32FX( new_inp_16k_fx - lMemRecalc_16k + L_FRAME16k, sig_out + preemp_len + L_FRAME16k, PREEMPH_FAC_16k, lMemRecalc_16k + L_FILT16k, &tmp_fx ); + PREEMPH_32FX( new_inp_16k_fx - lMemRecalc_16k + L_FRAME16k, sig_out + preemp_len + L_FRAME16k, PREEMPH_FAC_16k, lMemRecalc_16k + L_FILT16k, &tmp_fx ); /* Q(-1) */ IF( preemp_start_idx && preemp_len ) { preemp_len = add( preemp_len, add( L_FRAME16k + L_FILT16k, lMemRecalc_16k ) ); @@ -1013,11 +1016,11 @@ ivas_error ivas_compute_core_buffers_fx( ELSE IF( EQ_16( element_mode, IVAS_SCE ) ) { // PREEMPH_FX(new_inp_16k_fx, PREEMPH_FAC_16k, L_FRAME16k, &(st->mem_preemph16k_fx)); - PREEMPH_32FX( new_inp_16k_fx, sig_out, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); + PREEMPH_32FX( new_inp_16k_fx, sig_out, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); /* Q(-1) */ tmp_fx = st->mem_preemph16k_fx; move16(); // PREEMPH_FX(new_inp_16k_fx + L_FRAME16k, PREEMPH_FAC_16k, L_FILT16k, &tmp_fx); - PREEMPH_32FX( new_inp_16k_fx + L_FRAME16k, sig_out + L_FRAME16k, PREEMPH_FAC_16k, L_FILT16k, &tmp_fx ); + PREEMPH_32FX( new_inp_16k_fx + L_FRAME16k, sig_out + L_FRAME16k, PREEMPH_FAC_16k, L_FILT16k, &tmp_fx ); /* Q(-1) */ preemp_start_idx = new_inp_16k_fx; preemp_len = L_FRAME16k + L_FILT16k; move16(); @@ -1057,12 +1060,12 @@ ivas_error ivas_compute_core_buffers_fx( { IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { - st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - STEREO_DFT_OVL_16k - 1]; + st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - STEREO_DFT_OVL_16k - 1]; /* Q_new - 1 */ move16(); } ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) ) { - st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - lMemRecalc_16k - 1]; + st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - lMemRecalc_16k - 1]; /* Q_new - 1 */ move16(); } ELSE IF( EQ_16( element_mode, IVAS_CPE_MDCT ) ) @@ -1072,10 +1075,10 @@ ivas_error ivas_compute_core_buffers_fx( } ELSE /* SCE */ { - st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - 1]; + st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - 1]; /* Q_new - 1 */ move16(); } - st->mem_preemph16k_DFT_fx = st->mem_preemph16k_fx; + st->mem_preemph16k_DFT_fx = st->mem_preemph16k_fx; /* Q_new - 1 */ move16(); } @@ -1119,7 +1122,7 @@ ivas_error ivas_compute_core_buffers_fx( IF( EQ_16( st->last_L_frame, L_FRAME ) ) { /* this is just an approximation, but it is sufficient */ - Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); + Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /* Q15 */ } IF( Q_new ) @@ -1171,7 +1174,7 @@ ivas_error ivas_compute_core_buffers_fx( IF( inp16k_out_fx != NULL ) { - *inp16k_out_fx = inp_16k_fx; + *inp16k_out_fx = inp_16k_fx; /* Q_new - 1 */ } IF( new_inp_resamp16k_out_fx != NULL ) diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index cbff81a81183d9fbd47c5501e65df326d382d822..20f2be0cfd5a168ea7e440c1c7d58d7e7ce4d9ab 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -84,57 +84,57 @@ static Word16 get_zero_flag( Word32 arr[], Word16 len ) } ivas_error pre_proc_front_ivas_fx( - SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const Word32 element_brate, /* i : SCE/CPE element bitrate */ - const Word16 nb_bits_metadata, /* i : number of metadata bits */ - const Word16 input_frame, /* i : frame length */ - const Word16 n, /* i : channel number */ - Word16 old_inp_12k8_fx[], /* o : buffer of old input signal Q_new-1 */ - Word16 old_inp_16k_fx[], /* o : buffer of old input signal @16kHz Q_new-1 */ - Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q */ - Word16 *relE_fx, /* o : frame relative energy Q8 */ - Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes Q12 */ - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes Q12 */ - Word32 epsP_fx[M + 1], /* o : LP prediction errors */ + SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word32 element_brate, /* i : SCE/CPE element bitrate Q0*/ + const Word16 nb_bits_metadata, /* i : number of metadata bits Q0*/ + const Word16 input_frame, /* i : frame length Q0*/ + const Word16 n, /* i : channel number Q0*/ + Word16 old_inp_12k8_fx[], /* o : buffer of old input signal Q_new-1*/ + Word16 old_inp_16k_fx[], /* o : buffer of old input signal @16kHz Q_new-1*/ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q*/ + Word16 *relE_fx, /* o : frame relative energy Q8*/ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes Q12*/ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes Q12*/ + Word32 epsP_fx[M + 1], /* o : LP prediction errors epsP_fx_q*/ Word16 *epsP_fx_q, - Word16 lsp_new_fx[M], /* o : LSPs at the end of the frame Q15 */ - Word16 lsp_mid_fx[M], /* o : LSPs in the middle of the frame Q15 */ - Word16 *vad_hover_flag, /* o : VAD hangover flag */ - Word16 *attack_flag, /* o : flag signaling attack */ - Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer Q(q_re_im_buf) */ - Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer Q(q_re_im_buf) */ - Word16 *q_re_im_buf, /* i/o: Q-factor of real and imag buffer */ - Word16 old_wsp_fx[], /* o : weighted input signal buffer q_old_wsp*/ + Word16 lsp_new_fx[M], /* o : LSPs at the end of the frame Q15*/ + Word16 lsp_mid_fx[M], /* o : LSPs in the middle of the frame Q15*/ + Word16 *vad_hover_flag, /* o : VAD hangover flag Q0*/ + Word16 *attack_flag, /* o : flag signaling attack Q0*/ + Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer Q(q_re_im_buf)*/ + Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer Q(q_re_im_buf)*/ + Word16 *q_re_im_buf, /* i/o: Q-factor of real and imag buffer */ + Word16 old_wsp_fx[], /* o : weighted input signal buffer q_old_wsp*/ Word16 *q_old_wsp, - Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6 */ - Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15 */ - Word16 *loc_harm, /* o : harmonicity flag */ - Word16 *cor_map_sum_fx, /* o : speech/music clasif. parameter Q8 */ - Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO */ - Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ - Word16 *enerBuffer_fx_exp, /* o : energy buffer */ - Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer */ - Word16 *fft_buff_fx_q, /* o : FFT buffer */ - const Word16 tdm_A_PCh_fx[M + 1], /* i : unq. LP coeff. of primary channel Q12 */ - const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15 */ - const Word16 currFlatness_fx, /* i : flatness parameter Q7 */ - const Word16 tdm_ratio_idx, /* i : Current Ratio_L index */ - Word32 fr_bands_LR_fx[][2 * NB_BANDS], /* i : energy in frequency bands (fr_bands_LR_fx_q[]) */ + Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6*/ + Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15*/ + Word16 *loc_harm, /* o : harmonicity flag Q0*/ + Word16 *cor_map_sum_fx, /* o : speech/music clasif. parameter Q8*/ + Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO Q0*/ + Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer enerBuffer_fx_exp*/ + Word16 *enerBuffer_fx_exp, /* o : energy buffer */ + Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer fft_buff_fx_q*/ + Word16 *fft_buff_fx_q, /* o : FFT buffer */ + const Word16 tdm_A_PCh_fx[M + 1], /* i : unq. LP coeff. of primary channel Q12*/ + const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15*/ + const Word16 currFlatness_fx, /* i : flatness parameter Q7*/ + const Word16 tdm_ratio_idx, /* i : Current Ratio_L index Q0*/ + Word32 fr_bands_LR_fx[][2 * NB_BANDS], /* i : energy in frequency bands (fr_bands_LR_fx_q) fr_bands_LR_fx_q*/ Word16 fr_bands_LR_fx_q[CPE_CHANNELS], - const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/ - Word32 lf_E_LR_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels (lf_E_LR_fx_q) */ + const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/ + Word32 lf_E_LR_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels (lf_E_LR_fx_q)*/ Word16 lf_E_LR_fx_q, - const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels */ - Word32 band_energies_LR_fx[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN (band_energies_LR_fx_q) */ + const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels Q0*/ + Word32 band_energies_LR_fx[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN (band_energies_LR_fx_q)*/ Word16 band_energies_LR_fx_q, - const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */ - const Word16 front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */ - const Word16 force_front_vad, /* i : flag to force VAD decision */ - const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX */ + const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ + const Word16 front_vad_flag, /* i : front-VAD flag to overwrite VAD decision Q0*/ + const Word16 force_front_vad, /* i : flag to force VAD decision Q0*/ + const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision Q0*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word32 ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX Q0*/ Word16 *Q_new #ifdef DEBUG_MODE_INFO , @@ -153,21 +153,21 @@ ivas_error pre_proc_front_ivas_fx( } Word16 old_inp_12k8_e; Word16 shift = getScaleFactor16( st->old_inp_12k8_fx, 240 ); - Scale_sig( st->old_inp_12k8_fx, 240, shift ); + Scale_sig( st->old_inp_12k8_fx, 240, shift ); /* exp(st->exp_old_inp_12k8 - shift) */ st->exp_old_inp_12k8 = sub( st->exp_old_inp_12k8, shift ); move16(); shift = getScaleFactor16( old_inp_12k8_fx, 496 ); - Scale_sig( old_inp_12k8_fx, 496, shift ); + Scale_sig( old_inp_12k8_fx, 496, shift ); /* exp(16 - shift) */ old_inp_12k8_e = sub( Q16, shift ); IF( GT_16( old_inp_12k8_e, st->exp_old_inp_12k8 ) ) { - Scale_sig( st->old_inp_12k8_fx, 240, sub( st->exp_old_inp_12k8, old_inp_12k8_e ) ); + Scale_sig( st->old_inp_12k8_fx, 240, sub( st->exp_old_inp_12k8, old_inp_12k8_e ) ); /* exp(old_inp_12k8_e) */ st->exp_old_inp_12k8 = old_inp_12k8_e; move16(); } ELSE { - Scale_sig( old_inp_12k8_fx, 496, sub( old_inp_12k8_e, st->exp_old_inp_12k8 ) ); + Scale_sig( old_inp_12k8_fx, 496, sub( old_inp_12k8_e, st->exp_old_inp_12k8 ) ); /* exp(st->exp_old_inp_12k8) */ old_inp_12k8_e = st->exp_old_inp_12k8; move16(); } @@ -259,14 +259,14 @@ ivas_error pre_proc_front_ivas_fx( IF( hSCE != NULL ) { - Copy_Scale_sig_16_32( hSCE->hCoreCoder[n]->input_fx, hSCE->hCoreCoder[n]->input32_fx, input_frame, sub( Q11, hSCE->hCoreCoder[n]->q_inp ) ); - Copy_Scale_sig_16_32( hSCE->hCoreCoder[n]->input_fx - input_frame, hSCE->hCoreCoder[n]->input32_fx - input_frame, input_frame, sub( Q11, hSCE->hCoreCoder[n]->q_old_inp ) ); + Copy_Scale_sig_16_32( hSCE->hCoreCoder[n]->input_fx, hSCE->hCoreCoder[n]->input32_fx, input_frame, sub( Q11, hSCE->hCoreCoder[n]->q_inp ) ); /* Q11 */ + Copy_Scale_sig_16_32( hSCE->hCoreCoder[n]->input_fx - input_frame, hSCE->hCoreCoder[n]->input32_fx - input_frame, input_frame, sub( Q11, hSCE->hCoreCoder[n]->q_old_inp ) ); /* Q11 */ hSCE->hCoreCoder[n]->q_inp32 = Q11; move16(); - Scale_sig( hSCE->hCoreCoder[n]->input_fx, input_frame, sub( -1, hSCE->hCoreCoder[n]->q_inp ) ); + Scale_sig( hSCE->hCoreCoder[n]->input_fx, input_frame, sub( -1, hSCE->hCoreCoder[n]->q_inp ) ); /* Q(-1) */ hSCE->hCoreCoder[n]->q_inp = -1; move16(); - Scale_sig( hSCE->hCoreCoder[n]->old_input_signal_fx, input_frame, sub( -1, hSCE->hCoreCoder[n]->q_old_inp ) ); + Scale_sig( hSCE->hCoreCoder[n]->old_input_signal_fx, input_frame, sub( -1, hSCE->hCoreCoder[n]->q_old_inp ) ); /* Q(-1) */ hSCE->hCoreCoder[n]->q_old_inp = -1; move16(); @@ -277,14 +277,14 @@ ivas_error pre_proc_front_ivas_fx( } ELSE { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[n]->input_fx, hCPE->hCoreCoder[n]->input32_fx, input_frame, sub( Q11, hCPE->hCoreCoder[n]->q_inp ) ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[n]->input_fx - input_frame, hCPE->hCoreCoder[n]->input32_fx - input_frame, input_frame, sub( Q11, hCPE->hCoreCoder[n]->q_old_inp ) ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[n]->input_fx, hCPE->hCoreCoder[n]->input32_fx, input_frame, sub( Q11, hCPE->hCoreCoder[n]->q_inp ) ); /* Q11 */ + Copy_Scale_sig_16_32( hCPE->hCoreCoder[n]->input_fx - input_frame, hCPE->hCoreCoder[n]->input32_fx - input_frame, input_frame, sub( Q11, hCPE->hCoreCoder[n]->q_old_inp ) ); /* Q11 */ hCPE->hCoreCoder[n]->q_inp32 = Q11; move16(); - Scale_sig( hCPE->hCoreCoder[n]->input_fx, input_frame, sub( -1, hCPE->hCoreCoder[n]->q_inp ) ); + Scale_sig( hCPE->hCoreCoder[n]->input_fx, input_frame, sub( -1, hCPE->hCoreCoder[n]->q_inp ) ); /* Q(-1) */ hCPE->hCoreCoder[n]->q_inp = -1; move16(); - Scale_sig( hCPE->hCoreCoder[n]->old_input_signal_fx, input_frame, sub( -1, hCPE->hCoreCoder[n]->q_old_inp ) ); + Scale_sig( hCPE->hCoreCoder[n]->old_input_signal_fx, input_frame, sub( -1, hCPE->hCoreCoder[n]->q_old_inp ) ); /* Q(-1) */ hCPE->hCoreCoder[n]->q_old_inp = -1; move16(); #ifdef DEBUG_MODE_INFO @@ -345,7 +345,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); IF( st->cldfbAnaEnc != NULL ) { - scale_sig32( st->cldfbAnaEnc->cldfb_state_fx, sub( sub( st->cldfbAnaEnc->p_filter_length, st->cldfbAnaEnc->no_channels ), st->cldfbAnaEnc->zeros ), sub( Q11, st->cldfbAnaEnc->Q_cldfb_state ) ); + scale_sig32( st->cldfbAnaEnc->cldfb_state_fx, sub( sub( st->cldfbAnaEnc->p_filter_length, st->cldfbAnaEnc->no_channels ), st->cldfbAnaEnc->zeros ), sub( Q11, st->cldfbAnaEnc->Q_cldfb_state ) ); /* Q11 */ st->cldfbAnaEnc->Q_cldfb_state = Q11; move16(); } @@ -356,10 +356,10 @@ ivas_error pre_proc_front_ivas_fx( #ifndef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING signal_in = hSCE->hCoreCoder[n]->input; #endif - signal_in_fx = hSCE->hCoreCoder[n]->input_fx; - signal32_in_fx = hSCE->hCoreCoder[n]->input32_fx; + signal_in_fx = hSCE->hCoreCoder[n]->input_fx; /* hSCE->hCoreCoder[n]->q_inp */ + signal32_in_fx = hSCE->hCoreCoder[n]->input32_fx; /* hSCE->hCoreCoder[n]->q_inp32 */ element_mode = IVAS_SCE; - last_element_brate = hSCE->last_element_brate; + last_element_brate = hSCE->last_element_brate; /* Q0 */ hStereoClassif = NULL; lr_vad_enabled = 0; move16(); @@ -372,10 +372,10 @@ ivas_error pre_proc_front_ivas_fx( #ifndef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING signal_in = hCPE->hCoreCoder[n]->input; #endif - signal_in_fx = hCPE->hCoreCoder[n]->input_fx; - signal32_in_fx = hCPE->hCoreCoder[n]->input32_fx; + signal_in_fx = hCPE->hCoreCoder[n]->input_fx; /* hSCE->hCoreCoder[n]->q_inp */ + signal32_in_fx = hCPE->hCoreCoder[n]->input32_fx; /* hSCE->hCoreCoder[n]->q_inp32 */ element_mode = hCPE->element_mode; - last_element_brate = hCPE->last_element_brate; + last_element_brate = hCPE->last_element_brate; /* Q0 */ hStereoClassif = hCPE->hStereoClassif; lr_vad_enabled = 0; move16(); @@ -399,13 +399,13 @@ ivas_error pre_proc_front_ivas_fx( IF( hCPE->hStereoTD != NULL ) { - tdm_SM_last_clas = &hCPE->hStereoTD->tdm_SM_last_clas[n]; - Copy( hCPE->hStereoTD->tdm_SM_last_clas, hCPE->hStereoTD->tdm_SM_last2_clas, CPE_CHANNELS ); + tdm_SM_last_clas = &hCPE->hStereoTD->tdm_SM_last_clas[n]; /* Q0 */ + Copy( hCPE->hStereoTD->tdm_SM_last_clas, hCPE->hStereoTD->tdm_SM_last2_clas, CPE_CHANNELS ); /* Q0 */ } IF( hCPE->hStereoDft != NULL ) { - res_cod_SNR_M_fx = hCPE->hStereoDft->res_cod_SNR_M_fx; + res_cod_SNR_M_fx = hCPE->hStereoDft->res_cod_SNR_M_fx; /* Q(31 - res_cod_SNR_M_fx_e[]) */ } } @@ -420,7 +420,7 @@ ivas_error pre_proc_front_ivas_fx( lMemRecalc_12k8 = NS2SA_FX2( INT_FS_12k8, L_MEM_RECALC_NS ); } - input_Fs = st->input_Fs; + input_Fs = st->input_Fs; /* Q0 */ move32(); localVAD_HE_SAD = 0; @@ -468,9 +468,9 @@ ivas_error pre_proc_front_ivas_fx( L_look = L_LOOK_12k8; /* lookahead at 12.8kHz */ move16(); - Scale_sig( old_inp_12k8_fx, L_INP_12k8, sub( Q_to_be_looked_into, sub( Q15, old_inp_12k8_e ) ) ); + Scale_sig( old_inp_12k8_fx, L_INP_12k8, sub( Q_to_be_looked_into, sub( Q15, old_inp_12k8_e ) ) ); /* Q_to_be_looked_into*/ old_inp_12k8_e = sub( Q15, Q_to_be_looked_into ); - Scale_sig( st->old_inp_12k8_fx, 240, sub( Q_to_be_looked_into, sub( Q15, st->exp_old_inp_12k8 ) ) ); + Scale_sig( st->old_inp_12k8_fx, 240, sub( Q_to_be_looked_into, sub( Q15, st->exp_old_inp_12k8 ) ) ); /* Q_to_be_looked_into */ st->exp_old_inp_12k8 = sub( Q15, Q_to_be_looked_into ); move16(); new_inp_12k8_fx = old_inp_12k8_fx + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ @@ -483,26 +483,26 @@ ivas_error pre_proc_front_ivas_fx( IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { - Copy( st->old_inp_12k8_fx, old_inp_12k8_fx, L_INP_MEM - STEREO_DFT_OVL_12k8 ); + Copy( st->old_inp_12k8_fx, old_inp_12k8_fx, L_INP_MEM - STEREO_DFT_OVL_12k8 ); /* exp(st->exp_old_inp_12k8) */ } ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) ) { - Copy( st->old_inp_12k8_fx, old_inp_12k8_fx, sub( L_INP_MEM - L_FILT, lMemRecalc_12k8 ) ); + Copy( st->old_inp_12k8_fx, old_inp_12k8_fx, sub( L_INP_MEM - L_FILT, lMemRecalc_12k8 ) ); /* exp(st->exp_old_inp_12k8) */ } ELSE { - Copy( st->old_inp_12k8_fx, old_inp_12k8_fx, L_INP_MEM - L_FILT ); + Copy( st->old_inp_12k8_fx, old_inp_12k8_fx, L_INP_MEM - L_FILT ); /* exp(st->exp_old_inp_12k8) */ } - Copy( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); + Copy( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); /* exp(st->exp_old_wsp) */ *q_old_wsp = sub( Q15, st->exp_old_wsp ); move16(); wsp_fx = old_wsp_fx + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ - st->rf_mode = st->Opt_RF_ON; + st->rf_mode = st->Opt_RF_ON; /* Q0 */ move16(); - last_core_orig = st->last_core; + last_core_orig = st->last_core; /* Q0 */ move16(); /*--------------------------------------------------------------* @@ -545,13 +545,13 @@ ivas_error pre_proc_front_ivas_fx( test(); IF( EQ_16( element_mode, IVAS_SCE ) ) { - new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx, input_frame, input_Fs, new_inp_12k8_fx, INT_FS_12k8, st->mem_decim_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); - Scale_sig( new_inp_12k8_fx, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to Q_to_be_looked_into*/ + new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx, input_frame, input_Fs, new_inp_12k8_fx, INT_FS_12k8, st->mem_decim_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); /* Q0 */ + Scale_sig( new_inp_12k8_fx, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to Q_to_be_looked_into*/ - Copy( st->mem_decim_fx, mem_decim_dummy_fx, 2 * L_FILT_MAX ); + Copy( st->mem_decim_fx, mem_decim_dummy_fx, 2 * L_FILT_MAX ); /* Q(-1) */ set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); - new_inp_out_size = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8_fx + L_FRAME, INT_FS_12k8, mem_decim_dummy_fx, 0, &Q_new_inp, &mem_decim_size ); - Scale_sig( new_inp_12k8_fx + L_FRAME, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to Q_to_be_looked_into*/ + new_inp_out_size = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8_fx + L_FRAME, INT_FS_12k8, mem_decim_dummy_fx, 0, &Q_new_inp, &mem_decim_size ); /* Q0 */ + Scale_sig( new_inp_12k8_fx + L_FRAME, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to Q_to_be_looked_into*/ } ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) { @@ -562,30 +562,30 @@ ivas_error pre_proc_front_ivas_fx( Word16 length_inp = NS2SA_FX2( input_Fs, L_MEM_RECALC_SCH_NS ); Word16 length_12k8 = NS2SA_FX2( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); - new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, INT_FS_12k8, st->mem_decim_fx, 0, &Q_new_inp, &mem_decim_size ); - Scale_sig( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to Q_to_be_looked_into*/ + new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, INT_FS_12k8, st->mem_decim_fx, 0, &Q_new_inp, &mem_decim_size ); /* Q0 */ + Scale_sig( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to Q_to_be_looked_into*/ } - new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc, input_frame, input_Fs, new_inp_12k8_fx - lMemRecalc_12k8, INT_FS_12k8, st->mem_decim_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); - Copy( st->mem_decim_fx, mem_decim_dummy_fx, 2 * L_FILT_MAX ); - Scale_sig( new_inp_12k8_fx - lMemRecalc_12k8, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to Q_to_be_looked_into*/ + new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc, input_frame, input_Fs, new_inp_12k8_fx - lMemRecalc_12k8, INT_FS_12k8, st->mem_decim_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); /* Q0 */ + Copy( st->mem_decim_fx, mem_decim_dummy_fx, 2 * L_FILT_MAX ); /* Q(-1) */ + Scale_sig( new_inp_12k8_fx - lMemRecalc_12k8, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to Q_to_be_looked_into*/ IF( lMemRecalc > 0 ) { - new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx + sub( input_frame, lMemRecalc ), lMemRecalc, input_Fs, new_inp_12k8_fx + sub( L_FRAME, lMemRecalc_12k8 ), INT_FS_12k8, mem_decim_dummy_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); - Scale_sig( new_inp_12k8_fx + sub( L_FRAME, lMemRecalc_12k8 ), new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to Q_to_be_looked_into*/ + new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx + sub( input_frame, lMemRecalc ), lMemRecalc, input_Fs, new_inp_12k8_fx + sub( L_FRAME, lMemRecalc_12k8 ), INT_FS_12k8, mem_decim_dummy_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); /* Q0 */ + Scale_sig( new_inp_12k8_fx + L_FRAME - lMemRecalc_12k8, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to Q_to_be_looked_into*/ } set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); - new_inp_out_size = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8_fx + L_FRAME, INT_FS_12k8, mem_decim_dummy_fx, 0, &Q_new_inp, &mem_decim_size ); - Scale_sig( new_inp_12k8_fx + L_FRAME, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to Q_to_be_looked_into*/ + new_inp_out_size = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8_fx + L_FRAME, INT_FS_12k8, mem_decim_dummy_fx, 0, &Q_new_inp, &mem_decim_size ); /* Q0 */ + Scale_sig( new_inp_12k8_fx + L_FRAME, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to Q_to_be_looked_into*/ } ELSE /* DFT stereo */ { /* update the FIR resampling filter memory, needed for switching to time-domain (FIR) resampling */ - Copy( signal_in_fx + sub( input_frame, add( NS2SA_FX2( input_Fs, L_MEM_RECALC_NS ), 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ) ), st->mem_decim_fx, 2 * NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ) ); + Copy( signal_in_fx + sub( input_frame, add( NS2SA_FX2( input_Fs, L_MEM_RECALC_NS ), 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ) ), st->mem_decim_fx, 2 * NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ) ); /* hSCE->hCoreCoder[n]->q_inp */ } - Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( -1, sub( 15, st->exp_buf_speech_enc ) ) ); + Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( -1, sub( 15, st->exp_buf_speech_enc ) ) ); /* Q(-1) */ st->exp_buf_speech_enc = 16; move16(); @@ -593,15 +593,15 @@ ivas_error pre_proc_front_ivas_fx( test(); IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { - Copy( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, st->buf_speech_enc + L_FRAME32k - STEREO_DFT_OVL_12k8, L_FRAME + STEREO_DFT_OVL_12k8 ); + Copy( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, st->buf_speech_enc + L_FRAME32k - STEREO_DFT_OVL_12k8, L_FRAME + STEREO_DFT_OVL_12k8 ); /* Q_to_be_looked_into */ } ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) { - Copy( new_inp_12k8_fx - lMemRecalc_12k8, st->buf_speech_enc + L_FRAME32k - lMemRecalc_12k8 - L_FILT, add( L_FRAME + L_FILT, lMemRecalc_12k8 ) ); + Copy( new_inp_12k8_fx - lMemRecalc_12k8, st->buf_speech_enc + L_FRAME32k - lMemRecalc_12k8 - L_FILT, add( L_FRAME + L_FILT, lMemRecalc_12k8 ) ); /* Q_to_be_looked_into */ } ELSE { - Copy( new_inp_12k8_fx, st->buf_speech_enc + L_FRAME32k, L_FRAME ); + Copy( new_inp_12k8_fx, st->buf_speech_enc + L_FRAME32k, L_FRAME ); /* Q_to_be_looked_into */ } /*------------------------------------------------------------------* @@ -617,7 +617,7 @@ ivas_error pre_proc_front_ivas_fx( test(); test(); - IF( ( st->bwidth == NB || st->max_bwidth == NB ) && GT_32( st->input_Fs, 8000 ) ) + if ( ( st->bwidth == NB || st->max_bwidth == NB ) && GT_32( st->input_Fs, 8000 ) ) { headroom = add( headroom, 1 ); } @@ -625,11 +625,11 @@ ivas_error pre_proc_front_ivas_fx( test(); IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { - Copy( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw_fx, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); /* memory for TD/DFT stereo switching */ + Copy( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw_fx, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); /* memory for TD/DFT stereo switching Q_to_be_looked_into*/ - st->mem_preemph_fx = st->mem_preemph_DFT_fx; + st->mem_preemph_fx = st->mem_preemph_DFT_fx; /* Q(-1) */ move16(); - st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; + st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* Q_new - 1 */ move16(); // PREEMPH_FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); @@ -652,7 +652,7 @@ ivas_error pre_proc_front_ivas_fx( { st->mem_preemph_fx = st->mem_preemph_DFT_fx; move16(); - Copy( st->inp_12k8_mem_stereo_sw_fx, new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); + Copy( st->inp_12k8_mem_stereo_sw_fx, new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); /* Q(-1) */ // PREEMPH_FX( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), PREEMPH_FAC, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph_fx ); PREEMPH_32FX( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), sig_out, PREEMPH_FAC, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph_fx ); preemp_start_idx = new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); @@ -661,7 +661,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); } - st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* == inp_12k8[L_FRAME-1] */ + st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* == inp_12k8[L_FRAME-1] Q_new - 1 */ move16(); } @@ -680,7 +680,7 @@ ivas_error pre_proc_front_ivas_fx( // PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); PREEMPH_32FX( new_inp_12k8_fx - lMemRecalc_12k8, sig_out + preemp_len, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); - dummy_fx = st->mem_preemph_fx; + dummy_fx = st->mem_preemph_fx; /* Q(-1) */ move16(); // PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8 + L_FRAME, PREEMPH_FAC, lMemRecalc_12k8 + L_FILT, &dummy_fx ); PREEMPH_32FX( new_inp_12k8_fx - lMemRecalc_12k8 + L_FRAME, sig_out + preemp_len + L_FRAME, PREEMPH_FAC, lMemRecalc_12k8 + L_FILT, &dummy_fx ); @@ -688,13 +688,13 @@ ivas_error pre_proc_front_ivas_fx( test(); IF( preemp_start_idx && preemp_len ) { - preemp_len = add( preemp_len, add( L_FRAME + L_FILT, lMemRecalc_12k8 ) ); + preemp_len = add( preemp_len, add( L_FRAME + L_FILT, lMemRecalc_12k8 ) ); /* Q0 */ move16(); } ELSE { preemp_start_idx = new_inp_12k8_fx - lMemRecalc_12k8; - preemp_len = add( L_FRAME + L_FILT, lMemRecalc_12k8 ); + preemp_len = add( L_FRAME + L_FILT, lMemRecalc_12k8 ); /* Q) */ move16(); } } @@ -738,9 +738,9 @@ ivas_error pre_proc_front_ivas_fx( st->Q_max[i] = shift; move16(); - Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, *Q_new ); + Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, *Q_new ); /* Q_to_be_looked_into + Q_new */ - Scale_sig( old_inp_12k8_fx, (Word16) ( preemp_start_idx - old_inp_12k8_fx ), *Q_new ); + Scale_sig( old_inp_12k8_fx, (Word16) ( preemp_start_idx - old_inp_12k8_fx ), *Q_new ); /* Q(-1) */ *Q_new = add( *Q_new, Q_to_be_looked_into ); move16(); @@ -775,10 +775,10 @@ ivas_error pre_proc_front_ivas_fx( } ELSE { - hStereoClassif->silence_flag = sub( hStereoClassif->silence_flag, 1 ); + hStereoClassif->silence_flag = sub( hStereoClassif->silence_flag, 1 ); /* Q0 */ move16(); } - hStereoClassif->silence_flag = s_max( 0, hStereoClassif->silence_flag ); + hStereoClassif->silence_flag = s_max( 0, hStereoClassif->silence_flag ); /* Q0 */ move16(); } @@ -828,8 +828,8 @@ ivas_error pre_proc_front_ivas_fx( IF( EQ_16( force_front_vad, 1 ) || EQ_16( front_vad_flag, 1 ) ) { /* overwrite VAD decision with front-VAD decision if external VAD is set to 1*/ - st->vad_flag = front_vad_flag; - st->localVAD = front_vad_flag; + st->vad_flag = front_vad_flag; /* Q0 */ + st->localVAD = front_vad_flag; /* Q0 */ move16(); move16(); } @@ -838,7 +838,7 @@ ivas_error pre_proc_front_ivas_fx( test(); IF( ( hCPE != NULL && !( lr_vad_enabled && st->idchan == 0 ) ) || hSCE != NULL ) { - *vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, sub( st->lp_speech_fx, st->lp_noise_fx ), 0, vad_hover_flag, NULL, NULL ); + *vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, sub( st->lp_speech_fx, st->lp_noise_fx ), 0, vad_hover_flag, NULL, NULL ); /* Q0 */ move16(); } ELSE @@ -846,14 +846,14 @@ ivas_error pre_proc_front_ivas_fx( /* This only applies to st->idchan==0 now */ /* Add down mix stereo activity to LR vad_flag_dtx */ test(); - *vad_flag_dtx = *vad_flag_dtx || st->vad_flag; + *vad_flag_dtx = *vad_flag_dtx || st->vad_flag; /* Q0 */ move16(); /* Determine hangover flag status based on LR localVAD and downmix localVAD */ test(); test(); - *vad_hover_flag = *vad_flag_dtx && !( LR_localVAD || st->localVAD ); + *vad_hover_flag = *vad_flag_dtx && !( LR_localVAD || st->localVAD ); /* Q0 */ move16(); } @@ -861,7 +861,7 @@ ivas_error pre_proc_front_ivas_fx( if ( EQ_16( force_front_vad, 1 ) || EQ_16( front_vad_dtx_flag, 1 ) ) { /* overwrite VAD decision with front-VAD decision if external VAD is set to 1*/ - *vad_flag_dtx = front_vad_dtx_flag; + *vad_flag_dtx = front_vad_dtx_flag; /* Q0 */ move16(); } @@ -897,7 +897,7 @@ ivas_error pre_proc_front_ivas_fx( test(); if ( EQ_16( st->idchan, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( st->tdm_LRTD_flag, 1 ) && GE_16( st->bits_frame_channel, IVAS_16k4 / FRAMES_PER_SEC ) ) { - st->bwidth = hCPE->hCoreCoder[0]->bwidth; + st->bwidth = hCPE->hCoreCoder[0]->bwidth; /* Q0 */ move16(); } @@ -946,13 +946,13 @@ ivas_error pre_proc_front_ivas_fx( move16(); 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 ); + corr_shiftL_fx = correlation_shift_fx( hCPE->hFrontVad[0]->hNoiseEst->totalNoise_fx ); // Q15 + corr_shiftR_fx = correlation_shift_fx( hCPE->hFrontVad[1]->hNoiseEst->totalNoise_fx ); // Q15 } - *relE_fx = sub( Etot_fx, st->lp_speech_fx ); + *relE_fx = sub( Etot_fx, st->lp_speech_fx ); // Q8 move16(); - corr_shift_fx = correlation_shift_fx( st->hNoiseEst->totalNoise_fx ); + corr_shift_fx = correlation_shift_fx( st->hNoiseEst->totalNoise_fx ); /* Q15 */ /*----------------------------------------------------------------* * FD-CNG Noise Estimator @@ -981,7 +981,7 @@ ivas_error pre_proc_front_ivas_fx( st->hFdCngEnc->msPeriodog_fx_exp_fft = sub( 31, normmsPeriodog_fx ); move16(); move16(); - Scale_sig32( st->hFdCngEnc->msPeriodog_fx, NPART, normmsPeriodog_fx ); + Scale_sig32( st->hFdCngEnc->msPeriodog_fx, NPART, normmsPeriodog_fx ); /* exp(st->hFdCngEnc->msPeriodog_fx_exp - normmsPeriodog_fx) */ st->hFdCngEnc->msPeriodog_fx_exp = sub( st->hFdCngEnc->msPeriodog_fx_exp, normmsPeriodog_fx ); Word16 msNoiseEst_Q = Q31; move16(); @@ -991,7 +991,7 @@ ivas_error pre_proc_front_ivas_fx( { msNoiseEst_Q = getScaleFactor32( st->hFdCngEnc->msNoiseEst_fx, NPART ); } - Scale_sig32( st->hFdCngEnc->msNoiseEst_old_fx, NPART, msNoiseEst_Q ); + Scale_sig32( st->hFdCngEnc->msNoiseEst_old_fx, NPART, msNoiseEst_Q ); /* exp(st->hFdCngEnc->msNoiseEst_old_fx_exp - msNoiseEst_Q) */ st->hFdCngEnc->msNoiseEst_fx_exp = sub( st->hFdCngEnc->msNoiseEst_old_fx_exp, msNoiseEst_Q ); move16(); perform_noise_estimation_enc_ivas_fx( band_energies_LR_fx, sub( Q31, band_energies_LR_fx_q ), enerBuffer_fx, *enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE ); @@ -1005,7 +1005,7 @@ ivas_error pre_proc_front_ivas_fx( scale_sig32( band_energies_fx, 2 * NB_BANDS, shift ); q_band_energies = add( q_band_energies, shift ); - zero_flag = get_zero_flag( st->hFdCngEnc->msPeriodog_fx, NPART ); + zero_flag = get_zero_flag( st->hFdCngEnc->msPeriodog_fx, NPART ); /* Q0 */ IF( zero_flag ) { normmsPeriodog_fx = getScaleFactor32( st->hFdCngEnc->msPeriodog_fx, NPART ); @@ -1014,20 +1014,20 @@ ivas_error pre_proc_front_ivas_fx( st->hFdCngEnc->msPeriodog_fx_exp_fft = sub( 31, normmsPeriodog_fx ); move16(); move16(); - Scale_sig32( st->hFdCngEnc->msPeriodog_fx, NPART, normmsPeriodog_fx ); - st->hFdCngEnc->msPeriodog_fx_exp = st->hFdCngEnc->msPeriodog_fx_exp - normmsPeriodog_fx; + Scale_sig32( st->hFdCngEnc->msPeriodog_fx, NPART, normmsPeriodog_fx ); /* exp(st->hFdCngEnc->msPeriodog_fx_exp - normmsPeriodog_fx)*/ + st->hFdCngEnc->msPeriodog_fx_exp = sub( st->hFdCngEnc->msPeriodog_fx_exp, normmsPeriodog_fx ); move16(); Word16 msNoiseEst_Q = Q31; move16(); - zero_flag = get_zero_flag( st->hFdCngEnc->msNoiseEst_fx, NPART ); + zero_flag = get_zero_flag( st->hFdCngEnc->msNoiseEst_fx, NPART ); /* Q0 */ IF( zero_flag ) { msNoiseEst_Q = getScaleFactor32( st->hFdCngEnc->msNoiseEst_fx, NPART ); } - Scale_sig32( st->hFdCngEnc->msNoiseEst_old_fx, NPART, msNoiseEst_Q ); - st->hFdCngEnc->msNoiseEst_fx_exp = st->hFdCngEnc->msNoiseEst_old_fx_exp - msNoiseEst_Q; + Scale_sig32( st->hFdCngEnc->msNoiseEst_old_fx, NPART, msNoiseEst_Q ); /* exp(st->hFdCngEnc->msNoiseEst_old_fx_exp - msNoiseEst_Q) */ + st->hFdCngEnc->msNoiseEst_fx_exp = sub( st->hFdCngEnc->msNoiseEst_old_fx_exp, msNoiseEst_Q ); move16(); - zero_flag = get_zero_flag( st->hFdCngEnc->hFdCngCom->periodog, PERIODOGLEN ); + zero_flag = get_zero_flag( st->hFdCngEnc->hFdCngCom->periodog, PERIODOGLEN ); /* Q0 */ Word16 normmsperiodog = 31; move16(); IF( zero_flag ) @@ -1069,7 +1069,7 @@ ivas_error pre_proc_front_ivas_fx( IF( hCPE != NULL && hCPE->hStereoDft != NULL && EQ_32( st->core_brate, SID_2k40 ) ) { /* Add another period of expected xcorr updates */ - hCPE->hStereoDft->expectedNumUpdates = add( hCPE->hStereoDft->expectedNumUpdates, st->hDtxEnc->max_SID ); + hCPE->hStereoDft->expectedNumUpdates = add( hCPE->hStereoDft->expectedNumUpdates, st->hDtxEnc->max_SID ); /* Q0 */ move16(); } @@ -1085,17 +1085,17 @@ ivas_error pre_proc_front_ivas_fx( IF( EQ_16( element_mode, IVAS_SCE ) ) { - total_brate = st->total_brate; + total_brate = st->total_brate; /* Q0 */ move32(); } ELSE { - total_brate = imult3216( FRAMES_PER_SEC, st->bits_frame_nominal ); + total_brate = imult3216( FRAMES_PER_SEC, st->bits_frame_nominal ); /* Q0 */ } configureFdCngEnc_ivas_fx( st->hFdCngEnc, s_max( st->input_bwidth, WB ), total_brate ); IF( hCPE != NULL ) { - st->hFdCngEnc->hFdCngCom->CngBitrate = L_sub( hCPE->element_brate, 1 ); + st->hFdCngEnc->hFdCngCom->CngBitrate = L_sub( hCPE->element_brate, 1 ); /* Q0 */ move32(); } } @@ -1110,29 +1110,29 @@ ivas_error pre_proc_front_ivas_fx( IF( zero_flag ) { msPeriodog_fx_Q = getScaleFactor32( st->hFdCngEnc->msPeriodog_fx, NPART ); - scale_sig32( st->hFdCngEnc->msPeriodog_fx, NPART, msPeriodog_fx_Q ); + scale_sig32( st->hFdCngEnc->msPeriodog_fx, NPART, msPeriodog_fx_Q ); /* exp(st->hFdCngEnc->msPeriodog_fx_exp - msPeriodog_fx_Q) */ st->hFdCngEnc->msPeriodog_fx_exp = sub( st->hFdCngEnc->msPeriodog_fx_exp, msPeriodog_fx_Q ); move16(); } Word16 energy_ho_fx_Q = Q31; move16(); - zero_flag = get_zero_flag( st->hFdCngEnc->energy_ho_fx, NPART ); + zero_flag = get_zero_flag( st->hFdCngEnc->energy_ho_fx, NPART ); /* Q0 */ IF( zero_flag ) { energy_ho_fx_Q = getScaleFactor32( st->hFdCngEnc->energy_ho_fx, NPART ); - scale_sig32( st->hFdCngEnc->energy_ho_fx, NPART, energy_ho_fx_Q ); + scale_sig32( st->hFdCngEnc->energy_ho_fx, NPART, energy_ho_fx_Q ); /* exp(st->hFdCngEnc->energy_ho_fx_exp - energy_ho_fx_Q) */ st->hFdCngEnc->energy_ho_fx_exp = sub( st->hFdCngEnc->energy_ho_fx_exp, energy_ho_fx_Q ); move16(); } Word16 msNoiseEst_old_Q = Q31; move16(); - zero_flag = get_zero_flag( st->hFdCngEnc->msNoiseEst_old_fx, NPART ); + zero_flag = get_zero_flag( st->hFdCngEnc->msNoiseEst_old_fx, NPART ); /* Q0 */ IF( zero_flag ) { msNoiseEst_old_Q = getScaleFactor32( st->hFdCngEnc->msNoiseEst_old_fx, NPART ); - scale_sig32( st->hFdCngEnc->msNoiseEst_old_fx, NPART, msNoiseEst_old_Q ); + scale_sig32( st->hFdCngEnc->msNoiseEst_old_fx, NPART, msNoiseEst_old_Q ); /* exp(st->hFdCngEnc->msNoiseEst_old_fx_exp - msNoiseEst_old_Q) */ st->hFdCngEnc->msNoiseEst_old_fx_exp = sub( st->hFdCngEnc->msNoiseEst_old_fx_exp, msNoiseEst_old_Q ); move16(); } @@ -1156,13 +1156,13 @@ ivas_error pre_proc_front_ivas_fx( Q_new_loc = *Q_new; move16(); - alw_pitch_lag_12k8[0] = st->old_pitch_la; + alw_pitch_lag_12k8[0] = st->old_pitch_la; /* Q0 */ move16(); - alw_pitch_lag_12k8[1] = st->old_pitch_la; + alw_pitch_lag_12k8[1] = st->old_pitch_la; /* Q0 */ move16(); - alw_voicing_fx[0] = st->voicing_fx[2]; + alw_voicing_fx[0] = st->voicing_fx[2]; /* Q15 */ move16(); - alw_voicing_fx[1] = st->voicing_fx[2]; + alw_voicing_fx[1] = st->voicing_fx[2]; /* Q15 */ move16(); i = 0; @@ -1189,9 +1189,9 @@ ivas_error pre_proc_front_ivas_fx( lsp2lsf_fx( lsp_new_fx, lsf_new_fx, M, INT_FS_12k8 ); - stab_fac_fx = lsf_stab_fx( lsf_new_fx, st->lsf_old1_fx, 0, L_FRAME ); + stab_fac_fx = lsf_stab_fx( lsf_new_fx, st->lsf_old1_fx, 0, L_FRAME ); /* Q15 */ - Copy( lsf_new_fx, st->lsf_old1_fx, M ); + Copy( lsf_new_fx, st->lsf_old1_fx, M ); /* Q2.56 */ test(); IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) @@ -1201,8 +1201,8 @@ ivas_error pre_proc_front_ivas_fx( * to reuse the primary channel LP coefficients in the secondary channel *----------------------------------------------------------------*/ Word32 speech_buff[L_FRAME + M]; - Copy_Scale_sig_16_32( inp_12k8_fx - M, speech_buff, L_FRAME + M, Q12 ); - hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison_fx( hCPE->hStereoTD, hCPE->hStereoClassif, st, &speech_buff[0], tdm_A_PCh_fx, A_fx, M, tdm_lsp_new_PCh_fx, lsp_new_fx, L_FRAME, L_sub( element_brate, imult3216( FRAMES_PER_SEC, nb_bits_metadata ) ), add( *Q_new, 12 ) ); + Copy_Scale_sig_16_32( inp_12k8_fx - M, speech_buff, L_FRAME + M, Q12 ); /* Q_new + 12 */ + hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison_fx( hCPE->hStereoTD, hCPE->hStereoClassif, st, &speech_buff[0], tdm_A_PCh_fx, A_fx, M, tdm_lsp_new_PCh_fx, lsp_new_fx, L_FRAME, L_sub( element_brate, imult3216( FRAMES_PER_SEC, nb_bits_metadata ) ), add( *Q_new, 12 ) ); /* Q0 */ move16(); } @@ -1213,7 +1213,7 @@ ivas_error pre_proc_front_ivas_fx( * 1/4 pitch precision improvement *----------------------------------------------------------------*/ - st->mem_wsp_fx = shl( st->mem_wsp_fx, sub( *Q_new, st->mem_wsp_q ) ); + st->mem_wsp_fx = shl( st->mem_wsp_fx, sub( *Q_new, st->mem_wsp_q ) ); /* Q_new */ st->mem_wsp_q = *Q_new; move16(); move16(); @@ -1249,20 +1249,22 @@ ivas_error pre_proc_front_ivas_fx( shift = s_min( shift, add( norm_arr( st->old_wsp2_fx, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ), st->Q_old_wsp2 ) ); scale_sig( old_wsp_fx, L_WSP_MEM, sub( shift, *q_old_wsp ) ); scale_sig( wsp_fx, L_WSP - L_WSP_MEM, sub( shift, Q_wsp ) ); + *q_old_wsp = shift; move16(); Q_wsp = shift; move16(); - scale_sig( st->mem_decim2_fx, 3, sub( Q_wsp, st->Q_old_wsp2 ) ); // Q( mem_decim ) = Q( old_wsp2 ) - scale_sig( st->old_wsp2_fx, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM, sub( Q_wsp, st->Q_old_wsp2 ) ); + scale_sig( st->mem_decim2_fx, 3, sub( Q_wsp, st->Q_old_wsp2 ) ); // Q( mem_decim ) = Q( old_wsp2 ) + scale_sig( st->old_wsp2_fx, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM, sub( Q_wsp, st->Q_old_wsp2 ) ); // Q_wsp + st->Q_old_wsp2 = Q_wsp; move16(); pitch_ol_ivas_fx( st->pitch, st->voicing_fx, &st->old_pitch, &st->old_corr_fx, corr_shift_fx, &st->old_thres_fx, &st->delta_pit, st->old_wsp2_fx, wsp_fx, st->mem_decim2_fx, *relE_fx, st->clas, st->input_bwidth, st->Opt_SC_VBR, Q_wsp ); /* Updates for adaptive lag window memory */ - st->old_pitch_la = st->pitch[2]; + st->old_pitch_la = st->pitch[2]; /* Q0 */ move16(); /*Scaling to avoid 0 values*/ @@ -1286,6 +1288,7 @@ ivas_error pre_proc_front_ivas_fx( shift = sub( norm_arr( old_wsp_fx, L_WSP ), 3 ); scale_sig( old_wsp_fx, L_WSP, shift ); + *q_old_wsp = add( *q_old_wsp, shift ); move16(); Q_wsp = *q_old_wsp; @@ -1404,7 +1407,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); } - Copy_Scale_sig_32_16( st->Bin_E_fx, st->lgBin_E_fx, L_FFT / 2, sub( Q7, st->q_Bin_E ) ); + Copy_Scale_sig_32_16( st->Bin_E_fx, st->lgBin_E_fx, L_FFT / 2, sub( Q7, st->q_Bin_E ) ); /* Q7 */ /* Detection of very short stable pitch period */ StableHighPitchDetect_ivas_fx( &flag_spitch, st->pitch, st->voicing_fx, wsp_fx, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, *q_old_wsp, st->lgBin_E_fx ); @@ -1450,12 +1453,11 @@ ivas_error pre_proc_front_ivas_fx( noise_est_ivas_fx( st, old_pitch1, tmpN_fx, epsP_h, epsP_l, Etot_fx, *relE_fx, corr_shift_fx, tmpE_fx, fr_bands_fx, cor_map_sum_fx, &ncharX_fx, &sp_div_fx, &q_sp_div, &non_staX_fx, loc_harm, lf_E_fx, &st->hNoiseEst->harm_cor_cnt, st->hNoiseEst->Etot_l_lp_fx, st->hNoiseEst->Etot_v_h2_fx, &st->hNoiseEst->bg_cnt, st->lgBin_E_fx, sub( q_fr_bands, QSCALE ), L_shl( E_MIN_IVAS_FX, sub( q_fr_bands, Q19 ) ), &dummy_fx, S_map_fx, hStereoClassif, NULL, st->ini_frame ); - test(); IF( lr_vad_enabled && st->idchan == 0 ) { /* Run noise_est for Left and Right channel */ - *loc_harmLR_fx = *loc_harm; + *loc_harmLR_fx = *loc_harm; /* Q0 */ noise_est_ivas_fx( st, old_pitch1, tmpN_LR_fx[0], epsP_h, epsP_l, Etot_LR_fx[0], sub( Etot_LR_fx[0], hCPE->hFrontVad[0]->lp_speech_fx ), corr_shiftL_fx, tmpE_LR_fx[0], fr_bands_LR_fx[0], &cor_map_sum_LR_fx[0], &ncharX_LR_fx, &sp_div_LR_fx, &q_sp_div_LR, &non_staX_LR_fx, loc_harmLR_fx, lf_E_LR_fx[0], &hCPE->hFrontVad[0]->hNoiseEst->harm_cor_cnt, hCPE->hFrontVad[0]->hNoiseEst->Etot_l_lp_fx, hCPE->hFrontVad[0]->hNoiseEst->Etot_v_h2_fx, &hCPE->hFrontVad[0]->hNoiseEst->bg_cnt, st->lgBin_E_fx, sub( q_fr_bands, QSCALE ), L_shl( E_MIN_IVAS_FX, sub( q_fr_bands, Q19 ) ), &dummy_fx, S_map_LR_fx, NULL, hCPE->hFrontVad[0], hCPE->hFrontVad[0]->ini_frame ); @@ -1481,7 +1483,7 @@ ivas_error pre_proc_front_ivas_fx( find_tilt_ivas_fx( fr_bands_fx, st->hNoiseEst->bckr_fx, ee_fx, st->pitch, st->voicing_fx, lf_E_fx, corr_shift_fx, st->input_bwidth, st->max_band, hp_E_fx, MODE1, q_fr_bands, &( st->bckr_tilt_lt ), st->Opt_SC_VBR ); - st->coder_type = find_uv_ivas_fx( st, pitch_fr_fx, voicing_fr_fx, inp_12k8_fx, ee_fx, &dE1X_fx, corr_shift_fx, *relE_fx, Etot_fx, hp_E_fx, &flag_spitch, last_core_orig, hStereoClassif, *Q_new /*q_inp_12k8*/, q_fr_bands ); + st->coder_type = find_uv_ivas_fx( st, pitch_fr_fx, voicing_fr_fx, inp_12k8_fx, ee_fx, &dE1X_fx, corr_shift_fx, *relE_fx, Etot_fx, hp_E_fx, &flag_spitch, last_core_orig, hStereoClassif, *Q_new /*q_inp_12k8*/, q_fr_bands ); // Q0 Copy_Scale_sig_16_32( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) ); @@ -1499,13 +1501,14 @@ ivas_error pre_proc_front_ivas_fx( * TC frame selection *-----------------------------------------------------------------*/ - st->clas = signal_clas_fx( st, inp_12k8_fx, ee_fx, *relE_fx, L_look, tdm_SM_last_clas ); + st->clas = signal_clas_fx( st, inp_12k8_fx, ee_fx, *relE_fx, L_look, tdm_SM_last_clas ); /* Q0 */ + move16(); select_TC_fx( MODE1, st->tc_cnt, &st->coder_type, st->localVAD ); if ( st->Opt_SC_VBR ) { - st->hSC_VBR->Local_VAD = st->localVAD; + st->hSC_VBR->Local_VAD = st->localVAD; /* Q0 */ move16(); } @@ -1517,10 +1520,10 @@ ivas_error pre_proc_front_ivas_fx( Word16 max_e_Etot; max_e_Etot = s_max( hStereoClassif->e_Etot_buf_fx, s_max( hStereoClassif->Etot_up_e, hStereoClassif->Etot_dn_e ) ); - scale_sig32( hStereoClassif->Etot_buf_fx, 3, sub( hStereoClassif->e_Etot_buf_fx, max_e_Etot ) ); - hStereoClassif->Etot_up_fx = L_shr( hStereoClassif->Etot_up_fx, sub( max_e_Etot, hStereoClassif->Etot_up_e ) ); + scale_sig32( hStereoClassif->Etot_buf_fx, 3, sub( hStereoClassif->e_Etot_buf_fx, max_e_Etot ) ); /* exp(max_e_Etot) */ + hStereoClassif->Etot_up_fx = L_shr( hStereoClassif->Etot_up_fx, sub( max_e_Etot, hStereoClassif->Etot_up_e ) ); /* exp(max_e_Etot) */ move32(); - hStereoClassif->Etot_dn_fx = L_shr( hStereoClassif->Etot_dn_fx, sub( max_e_Etot, hStereoClassif->Etot_dn_e ) ); + hStereoClassif->Etot_dn_fx = L_shr( hStereoClassif->Etot_dn_fx, sub( max_e_Etot, hStereoClassif->Etot_dn_e ) ); /* exp(max_e_Etot) */ move32(); hStereoClassif->Etot_up_e = hStereoClassif->Etot_dn_e = hStereoClassif->e_Etot_buf_fx = max_e_Etot; move16(); @@ -1540,7 +1543,7 @@ ivas_error pre_proc_front_ivas_fx( scale_sig32( PS_fx, 128, shift ); Qfact_PS = add( Qfact_PS, shift ); - smc_dec = ivas_smc_gmm_fx( st, hStereoClassif, localVAD_HE_SAD, Etot_fx, lsp_new_fx, *cor_map_sum_fx /*Q8*/, epsP_fx, PS_fx, non_staX_fx, *relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, *epsP_fx_q, hSpMusClas->past_PS_Q ); + smc_dec = ivas_smc_gmm_fx( st, hStereoClassif, localVAD_HE_SAD, Etot_fx, lsp_new_fx, *cor_map_sum_fx /*Q8*/, epsP_fx, PS_fx, non_staX_fx, *relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, *epsP_fx_q, hSpMusClas->past_PS_Q ); /* Q0 */ #ifdef DEBUGGING if ( st->idchan == 0 ) @@ -1565,7 +1568,7 @@ ivas_error pre_proc_front_ivas_fx( ivas_long_enr_fx( st, Etot_fx, localVAD_HE_SAD, high_lpn_flag, NULL, 1, NULL, NULL ); - Copy32( fr_bands_fx + NB_BANDS, st->hNoiseEst->enrO_fx, NB_BANDS ); + Copy32( fr_bands_fx + NB_BANDS, st->hNoiseEst->enrO_fx, NB_BANDS ); /* fr_bands_fx_q */ st->hNoiseEst->q_enrO = fr_bands_fx_q; move16(); @@ -1574,10 +1577,10 @@ ivas_error pre_proc_front_ivas_fx( { ivas_long_enr_fx( st, -1, localVAD_HE_SAD, high_lpn_flag, hCPE->hFrontVad, CPE_CHANNELS, localVAD_HE_SAD_LR, Etot_LR_fx ); - Copy32( fr_bands_LR_fx[0] + NB_BANDS, hCPE->hFrontVad[0]->hNoiseEst->enrO_fx, NB_BANDS ); + Copy32( fr_bands_LR_fx[0] + NB_BANDS, hCPE->hFrontVad[0]->hNoiseEst->enrO_fx, NB_BANDS ); // fr_bands_LR_fx_q hCPE->hFrontVad[0]->hNoiseEst->q_enrO = fr_bands_LR_fx_q[0]; move16(); - Copy32( fr_bands_LR_fx[1] + NB_BANDS, hCPE->hFrontVad[1]->hNoiseEst->enrO_fx, NB_BANDS ); + Copy32( fr_bands_LR_fx[1] + NB_BANDS, hCPE->hFrontVad[1]->hNoiseEst->enrO_fx, NB_BANDS ); // fr_bands_LR_fx_q hCPE->hFrontVad[1]->hNoiseEst->q_enrO = fr_bands_LR_fx_q[1]; move16(); } @@ -1624,14 +1627,14 @@ ivas_error pre_proc_front_ivas_fx( test(); test(); test(); - IF( EQ_32( ivas_format, SBA_FORMAT ) && NE_32( st->core_brate, FRAME_NO_DATA ) && EQ_32( st->last_core_brate, FRAME_NO_DATA ) && st->sba_br_sw_while_no_data ) + IF( EQ_32( ivas_format, SBA_FORMAT ) && st->core_brate != FRAME_NO_DATA && st->last_core_brate == FRAME_NO_DATA && st->sba_br_sw_while_no_data ) { SetModeIndex_ivas_fx( st, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), element_mode, MCT_flag ); st->sba_br_sw_while_no_data = 0; move16(); } - ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) && EQ_32( st->core_brate, FRAME_NO_DATA ) && NE_32( element_brate, last_element_brate ) ) + ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) && st->core_brate == FRAME_NO_DATA && NE_32( element_brate, last_element_brate ) ) { st->sba_br_sw_while_no_data = 1; move16(); @@ -1639,12 +1642,12 @@ ivas_error pre_proc_front_ivas_fx( IF( flag_16k_smc ) { - Scale_sig( st->input_fx, input_frame, sub( -1, st->q_inp ) ); + Scale_sig( st->input_fx, input_frame, sub( -1, st->q_inp ) ); /* Q(-1) */ st->q_inp = -1; move16(); } /* these are for ivas_acelp_tcx20_switching_fx */ - Scale_sig32( st->hTcxEnc->spectrum_long_fx, N_MAX, sub( st->hTcxEnc->spectrum_long_e, 16 ) ); + Scale_sig32( st->hTcxEnc->spectrum_long_fx, N_MAX, sub( st->hTcxEnc->spectrum_long_e, 16 ) ); /* Q(-1) */ st->hTcxEnc->spectrum_long_e = 16; move16(); st->hTcxEnc->spectrum_e[0] = 16; @@ -1656,27 +1659,27 @@ ivas_error pre_proc_front_ivas_fx( Word16 Q_old_inp_16k = -1; move16(); - Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( Q_old_inp_16k, sub( Q15, st->exp_old_inp_16k ) ) ); + Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( Q_old_inp_16k, sub( Q15, st->exp_old_inp_16k ) ) ); /* Q15 - Q_old_inp_16k */ st->exp_old_inp_16k = sub( Q15, Q_old_inp_16k ); move16(); IF( st->hBWE_FD != NULL ) { - Scale_sig( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, sub( -1, st->Q_old_wtda ) ); - st->Q_old_wtda = -1; // This reset needs to be looked into + Scale_sig( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, sub( -1, st->Q_old_wtda ) ); /* Q(-1) */ + st->Q_old_wtda = -1; // This reset needs to be looked into move16(); } - st->mem_preemph_enc = shl( st->mem_preemph_enc, sub( Q_old_inp_16k, sub( Q15, st->exp_mem_preemph_enc ) ) ); + st->mem_preemph_enc = shl( st->mem_preemph_enc, sub( Q_old_inp_16k, sub( Q15, st->exp_mem_preemph_enc ) ) ); /* Q15 - Q_old_inp_16k */ move16(); st->exp_mem_preemph_enc = sub( Q15, Q_old_inp_16k ); move16(); - Scale_sig( st->buf_wspeech_enc, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_wspeech_enc ) ) ); + Scale_sig( st->buf_wspeech_enc, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_wspeech_enc ) ) ); /* Q15 - Q_old_inp_16k */ st->exp_buf_wspeech_enc = sub( Q15, Q_old_inp_16k ); move16(); - Scale_sig( st->buf_speech_enc_pe, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_speech_enc_pe ) ) ); + Scale_sig( st->buf_speech_enc_pe, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_speech_enc_pe ) ) ); /* Q15 - Q_old_inp_16k */ st->exp_buf_speech_enc_pe = sub( Q15, Q_old_inp_16k ); move16(); - Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_speech_enc ) ) ); + Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_speech_enc ) ) ); /* Q15 - Q_old_inp_16k */ st->exp_buf_speech_enc = sub( Q15, Q_old_inp_16k ); move16(); @@ -1687,7 +1690,7 @@ ivas_error pre_proc_front_ivas_fx( A_fx, Aw_fx, epsP_fx, lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, Q_new, 1 ); - IF( error != IVAS_ERR_OK ) + IF( NE_32( error, IVAS_ERR_OK ) ) { return error; } @@ -1699,21 +1702,21 @@ ivas_error pre_proc_front_ivas_fx( *Q_new = add( *Q_new, Q_to_be_looked_into ); // actual Q_new move16(); - Scale_sig( old_inp_12k8_fx, L_INP_12k8, sub( *Q_new, Q_old_inp_12k8 ) ); + Scale_sig( old_inp_12k8_fx, L_INP_12k8, sub( *Q_new, Q_old_inp_12k8 ) ); /* Q_new */ - Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( 0, sub( Q15, st->exp_buf_speech_enc ) ) ); + Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( 0, sub( Q15, st->exp_buf_speech_enc ) ) ); /* Q0 */ st->exp_buf_speech_enc = Q15; move16(); - smc_dec = ivas_acelp_tcx20_switching_fx( st, st->speech_enc, 0, st->wspeech_enc, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, flag_16k_smc ); + smc_dec = ivas_acelp_tcx20_switching_fx( st, st->speech_enc, 0, st->wspeech_enc, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, flag_16k_smc ); /* Q0 */ } ELSE { - Scale_sig( old_wsp_fx, L_WSP, sub( *Q_new, *q_old_wsp ) ); + Scale_sig( old_wsp_fx, L_WSP, sub( *Q_new, *q_old_wsp ) ); /* Q_new */ *q_old_wsp = *Q_new; move16(); Q_wsp = *Q_new; move16(); - smc_dec = ivas_acelp_tcx20_switching_fx( st, inp_12k8_fx, *Q_new, wsp_fx, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, flag_16k_smc ); + smc_dec = ivas_acelp_tcx20_switching_fx( st, inp_12k8_fx, *Q_new, wsp_fx, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, flag_16k_smc ); /* Q0 */ } } /* Switch to ACELP for non-harmonic transient signals */ @@ -1741,7 +1744,7 @@ ivas_error pre_proc_front_ivas_fx( } } - Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( *Q_new, Q_SCALE - 2 ), st->q_Bin_E ) ); + Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( *Q_new, Q_SCALE - 2 ), st->q_Bin_E ) ); /* Q_new + Q_SCALE - 2 */ st->q_Bin_E = add( *Q_new, Q_SCALE - 2 ); move16(); /* 2nd stage speech/music classification (ACELP/GSC/TCX core selection) */ @@ -1756,7 +1759,7 @@ ivas_error pre_proc_front_ivas_fx( test(); if ( st->Opt_DTX_ON && NE_16( element_mode, IVAS_CPE_DFT ) ) { - st->vad_flag = *vad_flag_dtx; + st->vad_flag = *vad_flag_dtx; /* Q0 */ move16(); } @@ -1764,7 +1767,7 @@ ivas_error pre_proc_front_ivas_fx( * Update old input signal buffer *-----------------------------------------------------------------*/ shift = getScaleFactor16( &old_inp_12k8_fx[L_FRAME], L_INP_MEM ); - Copy_Scale_sig( &old_inp_12k8_fx[L_FRAME], st->old_inp_12k8_fx, L_INP_MEM, shift ); + Copy_Scale_sig( &old_inp_12k8_fx[L_FRAME], st->old_inp_12k8_fx, L_INP_MEM, shift ); /* Q_new + shift */ st->exp_old_inp_12k8 = sub( Q15, add( *Q_new, shift ) ); move16(); @@ -1849,9 +1852,9 @@ static void calculate_energy_buffer_fx( *--------------------------------------------------------------------*/ static void calculate_energy_buffer_ivas_fx( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ - Word32 enerBuffer_dft_fx[], /* o : energy buffer() */ - const Word16 no_channels, /* i : no. of used CLDFB channels */ - const Word32 input_Fs, /* i : input sampling rate */ + Word32 enerBuffer_dft_fx[], /* o : energy buffer() exp(enerBuffer_dft_e)*/ + const Word16 no_channels, /* i : no. of used CLDFB channels Q0*/ + const Word32 input_Fs, /* i : input sampling rate Q0*/ Word16 *enerBuffer_dft_e ) { Word16 i, j; @@ -1863,13 +1866,14 @@ static void calculate_energy_buffer_ivas_fx( Word16 norm_nrg_DMX_fx; Word64 max_abs_nrg_DMX_fx; Flag overflow = 0; + move32(); max_abs_nrg_DMX_fx = 0; move64(); Word16 temp_q1 = sub( norm_l( input_Fs ), 1 ); Word16 temp_q2 = norm_s( hCPE->hStereoDft->NFFT ); - band_res_dft_fx = div_l( L_shl( input_Fs, temp_q1 ), shl( hCPE->hStereoDft->NFFT, temp_q2 ) ); + band_res_dft_fx = div_l( L_shl( input_Fs, temp_q1 ), shl( hCPE->hStereoDft->NFFT, temp_q2 ) ); /* Q0 */ /* chan_width_f = 24000.f / CLDFB_NO_CHANNELS_MAX; */ chan_width_f_fx = 24000 / CLDFB_NO_CHANNELS_MAX; move16(); diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index 8271f1526295cb544b4830d5d989e684d330ad73..887dc12139735af0647c28cebd5c7ea8df8be0cc 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -48,11 +48,11 @@ /* Some float operations are still pending */ ivas_error ivas_corecoder_enc_reconfig_fx( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 nSCE_old, /* i : number of SCEs in previous frame */ - const Word16 nCPE_old, /* i : number of CPEs in previous frame */ - const Word16 nchan_transport_old, /* i : number of TCs in previous frame */ - const Word32 brate_SCE, /* i : bitrate to be set for the SCEs */ - const Word32 brate_CPE, /* i : bitrate to be set for the CPEs */ + const Word16 nSCE_old, /* i : number of SCEs in previous frame Q0*/ + const Word16 nCPE_old, /* i : number of CPEs in previous frame Q0*/ + const Word16 nchan_transport_old, /* i : number of TCs in previous frame Q0*/ + const Word32 brate_SCE, /* i : bitrate to be set for the SCEs Q0*/ + const Word32 brate_CPE, /* i : bitrate to be set for the CPEs Q0*/ const MC_MODE last_mc_mode /* i : switching between MC modes: last mode */ ) { @@ -81,22 +81,22 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move32(); set16_fx( q_input_buff, Q31, MCT_MAX_BLOCKS ); - input_frame = idiv1616U( extract_l( L_shr( hEncoderConfig->input_Fs, 1 ) ), FRAMES_PER_SEC / 2 ); - len_inp_memory = input_frame; + input_frame = idiv1616U( extract_l( L_shr( hEncoderConfig->input_Fs, 1 ) ), FRAMES_PER_SEC / 2 ); /* Q0 */ + len_inp_memory = input_frame; /* Q0 */ move16(); IF( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) ) { - len_inp_memory = add( len_inp_memory, NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS ) ); + len_inp_memory = add( len_inp_memory, NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS ) ); /* Q0 */ } - nchan_transport_old_real = nchan_transport_old; + nchan_transport_old_real = nchan_transport_old; /* Q0 */ move16(); - nchan_transport_real = st_ivas->nchan_transport; + nchan_transport_real = st_ivas->nchan_transport; /* Q0 */ move16(); IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - nchan_transport_real = add( nchan_transport_real, st_ivas->hEncoderConfig->nchan_ism ); + nchan_transport_real = add( nchan_transport_real, st_ivas->hEncoderConfig->nchan_ism ); /* Q0 */ } /*-----------------------------------------------------------------* @@ -110,15 +110,15 @@ ivas_error ivas_corecoder_enc_reconfig_fx( FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { copy_encoder_config_fx( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); - st_ivas->hSCE[sce_id]->element_brate = brate_SCE; + st_ivas->hSCE[sce_id]->element_brate = brate_SCE; /* Q0 */ move32(); - st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() Q0*/ move32(); } FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; + st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; /* Q0 */ move32(); /* prepare bitstream buffers */ @@ -133,14 +133,14 @@ ivas_error ivas_corecoder_enc_reconfig_fx( tmp = 0; move16(); } - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = L_shr( st_ivas->hCPE[cpe_id]->element_brate, tmp ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = L_shr( st_ivas->hCPE[cpe_id]->element_brate, tmp ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() Q0*/ move32(); } } IF( GT_16( st_ivas->nCPE, 1 ) ) { - IF( NE_32( ( error = mct_enc_reconfigure_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) ) + IF( ( error = mct_enc_reconfigure_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -153,13 +153,13 @@ ivas_error ivas_corecoder_enc_reconfig_fx( test(); IF( EQ_16( hEncoderConfig->ivas_format, MC_FORMAT ) && EQ_16( last_mc_mode, MC_MODE_MCMASA ) ) { - nchan_transport_old_real = add( nSCE_old, i_mult( CPE_CHANNELS, nCPE_old ) ); + nchan_transport_old_real = add( nSCE_old, i_mult( CPE_CHANNELS, nCPE_old ) ); /* Q0 */ } test(); IF( EQ_16( hEncoderConfig->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { - nchan_transport_real = add( st_ivas->nSCE, i_mult( CPE_CHANNELS, st_ivas->nCPE ) ); + nchan_transport_real = add( st_ivas->nSCE, i_mult( CPE_CHANNELS, st_ivas->nCPE ) ); /* Q0 */ } /* something in transport changes */ @@ -176,7 +176,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( } /* save bitstream information */ - nb_bits_tot = hBstr->nb_bits_tot; + nb_bits_tot = hBstr->nb_bits_tot; /* Q0 */ move16(); i = 0; move16(); @@ -188,13 +188,13 @@ ivas_error ivas_corecoder_enc_reconfig_fx( { IF( hBstr->ind_list[i].nb_bits > 0 ) { - temp_ind_list[i].id = hBstr->ind_list[i].id; + temp_ind_list[i].id = hBstr->ind_list[i].id; /* Q0 */ move16(); - temp_ind_list[i].value = hBstr->ind_list[i].value; + temp_ind_list[i].value = hBstr->ind_list[i].value; /* Q0 */ move16(); - temp_ind_list[i].nb_bits = hBstr->ind_list[i].nb_bits; + temp_ind_list[i].nb_bits = hBstr->ind_list[i].nb_bits; /* Q0 */ move16(); - hBstr->ind_list[i].nb_bits = -1; + hBstr->ind_list[i].nb_bits = -1; /* Q0 */ move16(); } @@ -203,7 +203,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( hBstr->nb_ind_tot = 0; move16(); - nb_bits = add( nb_bits, temp_ind_list[i].nb_bits ); + nb_bits = add( nb_bits, temp_ind_list[i].nb_bits ); /* Q0 */ i = add( i, 1 ); test(); } @@ -224,12 +224,12 @@ ivas_error ivas_corecoder_enc_reconfig_fx( FOR( k = 0; k < nSCE_old; k++ ) { shift = getScaleFactor16( st_ivas->hSCE[k]->hCoreCoder[0]->old_input_signal_fx, input_frame ); - Scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->old_input_signal_fx, input_frame, shift ); + Scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->old_input_signal_fx, input_frame, shift ); /* st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp + shift */ st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp = add( st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp, shift ); move16(); q_com_sce = s_min( q_com_sce, st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp ); shift = getScaleFactor16( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ) ); - Scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); + Scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); /* st_ivas->hSCE[k]->hCoreCoder[0]->q_inp + shift */ st_ivas->hSCE[k]->hCoreCoder[0]->q_inp = add( st_ivas->hSCE[k]->hCoreCoder[0]->q_inp, shift ); move16(); q_com_sce = s_min( q_com_sce, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp ); @@ -244,12 +244,12 @@ ivas_error ivas_corecoder_enc_reconfig_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { shift = getScaleFactor16( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->old_input_signal_fx, input_frame ); - Scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->old_input_signal_fx, input_frame, shift ); + Scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->old_input_signal_fx, input_frame, shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp + shift */ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp = add( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp, shift ); move16(); q_com_cpe = s_min( q_com_cpe, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp ); shift = getScaleFactor16( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ) ); - Scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); + Scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp = add( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp, shift ); move16(); q_com_cpe = s_min( q_com_cpe, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp ); @@ -261,13 +261,13 @@ ivas_error ivas_corecoder_enc_reconfig_fx( { FOR( k = 0; k < nSCE_old; k++ ) { - Scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->old_input_signal_fx, input_frame, sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp ) ); + Scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->old_input_signal_fx, input_frame, sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp ) ); /* q_com */ st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp = q_com; move16(); - Scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp ) ); + Scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp ) ); /* q_com */ st_ivas->hSCE[k]->hCoreCoder[0]->q_inp = q_com; move16(); - Copy_Scale_sig_16_32( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff_fx, st_ivas->hSCE[k]->hCoreCoder[0]->input_buff32_fx, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) + L_FRAME48k, Q6 ); + Copy_Scale_sig_16_32( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff_fx, st_ivas->hSCE[k]->hCoreCoder[0]->input_buff32_fx, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) + L_FRAME48k, Q6 ); /* Q6 + q_com */ st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32 = add( Q6, q_com ); move16(); } @@ -279,13 +279,13 @@ ivas_error ivas_corecoder_enc_reconfig_fx( { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - Scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->old_input_signal_fx, input_frame, sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp ) ); + Scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->old_input_signal_fx, input_frame, sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp ) ); /* q_com */ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp = q_com; move16(); - Scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp ) ); + Scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp ) ); /* q_com */ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp = q_com; move16(); - Copy_Scale_sig_16_32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff_fx, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) + L_FRAME48k, Q6 ); + Copy_Scale_sig_16_32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff_fx, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) + L_FRAME48k, Q6 ); /* Q6 + q_com */ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32 = add( Q6, q_com ); move16(); } @@ -302,7 +302,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( IF( nSCE_old > 0 ) { set32_fx( input_buff_fx[0], 0, len_inp_memory ); - Copy32( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff32_fx, input_buff_fx[0], len_inp_memory ); + Copy32( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff32_fx, input_buff_fx[0], len_inp_memory ); /* st_ivas->hSCE[0]->hCoreCoder[0]->q_inp32 */ q_input_buff[0] = st_ivas->hSCE[0]->hCoreCoder[0]->q_inp32; move16(); } @@ -312,7 +312,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( set32_fx( input_buff_fx[n + 1], 0, len_inp_memory ); IF( nCPE_old > 0 ) { - Copy32( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff32_fx, input_buff_fx[n + 1], len_inp_memory ); + Copy32( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff32_fx, input_buff_fx[n + 1], len_inp_memory ); /* st_ivas->hCPE[0]->hCoreCoder[n]->q_inp32 */ q_input_buff[n + 1] = st_ivas->hCPE[0]->hCoreCoder[n]->q_inp32; move16(); } @@ -326,7 +326,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( } ELSE { - n_CoreCoder_existing = s_min( nchan_transport_real, nchan_transport_old_real ); + n_CoreCoder_existing = s_min( nchan_transport_real, nchan_transport_old_real ); /* Q0 */ } /* destroy superfluous core-coder elements */ @@ -335,7 +335,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( /* save input audio buffers */ IF( GT_16( n_CoreCoder_existing, sce_id ) ) { - Copy32( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff32_fx, input_buff_fx[sce_id], len_inp_memory ); + Copy32( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff32_fx, input_buff_fx[sce_id], len_inp_memory ); /* st_ivas->hSCE[sce_id]->hCoreCoder[0]->q_inp32 */ q_input_buff[sce_id] = st_ivas->hSCE[sce_id]->hCoreCoder[0]->q_inp32; move16(); } @@ -350,7 +350,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( { IF( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n ) { - Copy32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, input_buff_fx[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory ); + Copy32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, input_buff_fx[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32 */ q_input_buff[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n] = st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32; move16(); } @@ -380,17 +380,17 @@ ivas_error ivas_corecoder_enc_reconfig_fx( FOR( sce_id = 0; sce_id < nSCE_existing; sce_id++ ) { copy_encoder_config_fx( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); - st_ivas->hSCE[sce_id]->element_brate = brate_SCE; + st_ivas->hSCE[sce_id]->element_brate = brate_SCE; /* Q0 */ move32(); - st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() Q0*/ move32(); - ivas_destroy_MD_bstr_enc( &( st_ivas->hSCE[sce_id]->hMetaData ) ); + ivas_destroy_MD_bstr_enc_fx( &( st_ivas->hSCE[sce_id]->hMetaData ) ); } FOR( sce_id = nSCE_existing; sce_id < st_ivas->nSCE; sce_id++ ) { - IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, brate_SCE ) ), IVAS_ERR_OK ) ) + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK ) { return error; } @@ -399,7 +399,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( test(); IF( GT_16( n_CoreCoder_existing, sce_id ) && NE_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { - Copy32( input_buff_fx[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff32_fx, len_inp_memory ); + Copy32( input_buff_fx[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff32_fx, len_inp_memory ); /* q_input_buff[sce_id] */ st_ivas->hSCE[sce_id]->hCoreCoder[0]->q_inp32 = q_input_buff[sce_id]; move16(); } @@ -413,7 +413,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( IF( st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData == NULL ) { - IF( NE_32( ( error = ivas_initialize_MD_bstr_enc( &( st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_initialize_MD_bstr_enc_fx( &( st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -426,7 +426,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( FOR( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) { - st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; + st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; /* Q0 */ move32(); /* allocate buffer of indices */ @@ -435,7 +435,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( copy_encoder_config_fx( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); IF( GT_16( st_ivas->nCPE, 1 ) ) { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate; + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate; /* Q0 */ } ELSE { @@ -459,13 +459,13 @@ ivas_error ivas_corecoder_enc_reconfig_fx( FOR( cpe_id = nCPE_existing; cpe_id < st_ivas->nCPE; cpe_id++ ) { test(); - IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && st_ivas->hMcMasa->separateChannelEnabled ) + if ( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && st_ivas->hMcMasa->separateChannelEnabled ) { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; move16(); } - IF( NE_32( ( error = create_cpe_enc_fx( st_ivas, cpe_id, brate_CPE ) ), IVAS_ERR_OK ) ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK ) { return error; } @@ -476,7 +476,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( IF( GT_16( n_CoreCoder_existing, add( i_mult( cpe_id, CPE_CHANNELS ), n ) ) ) { - Copy32( input_buff_fx[n], st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, len_inp_memory ); + Copy32( input_buff_fx[n], st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, len_inp_memory ); /* q_input_buff */ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32 = q_input_buff[n]; move16(); } @@ -513,21 +513,21 @@ ivas_error ivas_corecoder_enc_reconfig_fx( { IF( temp_ind_list[i].nb_bits > 0 ) { - st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id; + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id; /* Q0 */ move16(); - st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].value = temp_ind_list[i].value; + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].value = temp_ind_list[i].value; /* Q0 */ move16(); - st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].nb_bits = temp_ind_list[i].nb_bits; + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].nb_bits = temp_ind_list[i].nb_bits; /* Q0 */ move16(); } - nb_bits = add( nb_bits, temp_ind_list[i].nb_bits ); + nb_bits = add( nb_bits, temp_ind_list[i].nb_bits ); /* Q0 */ i = add( i, 1 ); test(); } - st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot = i; + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot = i; /* Q0 */ move16(); - st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot; + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot; /* Q0 */ move16(); } ELSE IF( st_ivas->nCPE > 0 ) @@ -537,21 +537,21 @@ ivas_error ivas_corecoder_enc_reconfig_fx( { IF( temp_ind_list[i].nb_bits > 0 ) { - st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id; + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id; /* Q0 */ move16(); - st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].value = temp_ind_list[i].value; + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].value = temp_ind_list[i].value; /* Q0 */ move16(); - st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].nb_bits = temp_ind_list[i].nb_bits; + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].nb_bits = temp_ind_list[i].nb_bits; /* Q0 */ move16(); } - nb_bits = add( nb_bits, temp_ind_list[i].nb_bits ); + nb_bits = add( nb_bits, temp_ind_list[i].nb_bits ); /* Q0 */ i = add( i, 1 ); test(); } - st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->nb_ind_tot = i; + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->nb_ind_tot = i; /* Q0 */ move16(); - st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot; + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot; /* Q0 */ move16(); } @@ -561,7 +561,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( /* restore modified transport signal */ IF( st_ivas->nSCE ) { - Copy32( input_buff_fx[0], st_ivas->hSCE[0]->hCoreCoder[0]->input_buff32_fx, len_inp_memory ); + Copy32( input_buff_fx[0], st_ivas->hSCE[0]->hCoreCoder[0]->input_buff32_fx, len_inp_memory ); /* q_input_buff */ st_ivas->hSCE[0]->hCoreCoder[0]->q_inp32 = q_input_buff[0]; move16(); } @@ -570,7 +570,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - Copy32( input_buff_fx[n + 1], st_ivas->hCPE[0]->hCoreCoder[n]->input_buff32_fx, len_inp_memory ); + Copy32( input_buff_fx[n + 1], st_ivas->hCPE[0]->hCoreCoder[n]->input_buff32_fx, len_inp_memory ); /* q_input_buff */ st_ivas->hCPE[0]->hCoreCoder[n]->q_inp32 = q_input_buff[n + 1]; move16(); } @@ -628,31 +628,31 @@ ivas_error ivas_corecoder_enc_reconfig_fx( /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */ FOR( n = 0; n < CPE_CHANNELS; n++ ) { - st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; + st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; /* Q0 */ move32(); - st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = extract_l( Mpy_32_32( st_ivas->hCPE[0]->element_brate, 42949673 ) /* 1/50 in Q31*/ ); + st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = extract_l( Mpy_32_32( st_ivas->hCPE[0]->element_brate, 42949673 ) /* 1/50 in Q31*/ ); /* Q0 */ move16(); st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent_fx( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC, st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, - st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ); + st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ); /* Q0 */ move16(); - IF( NE_32( ( error = IGF_Reconfig( &st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc, st_ivas->hCPE[0]->hCoreCoder[n]->igf, 1, st_ivas->hCPE[0]->element_brate, st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ) ), IVAS_ERR_OK ) ) + IF( ( error = IGF_Reconfig( &st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc, st_ivas->hCPE[0]->hCoreCoder[n]->igf, 1, st_ivas->hCPE[0]->element_brate, st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ) ) != IVAS_ERR_OK ) { return error; } } } - IF( NE_32( ( error = create_mct_enc_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } ELSE IF( st_ivas->hMCT != NULL && GT_16( st_ivas->nCPE, 1 ) ) { - IF( NE_32( ( error = mct_enc_reconfigure_fx( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ), IVAS_ERR_OK ) ) + IF( ( error = mct_enc_reconfigure_fx( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ) != IVAS_ERR_OK ) { return error; } @@ -663,7 +663,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( { IF( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData == NULL ) { - IF( NE_32( ( error = ivas_initialize_MD_bstr_enc( &( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_initialize_MD_bstr_enc_fx( &( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -673,7 +673,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( FOR( cpe_id = 0; cpe_id < st_ivas->nCPE - 1; cpe_id++ ) { - ivas_destroy_MD_bstr_enc( &( st_ivas->hCPE[cpe_id]->hMetaData ) ); + ivas_destroy_MD_bstr_enc_fx( &( st_ivas->hCPE[cpe_id]->hMetaData ) ); } } @@ -689,7 +689,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handle */ FOR( n = 0; n < CPE_CHANNELS; n++ ) { - st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; + st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; /* Q0 */ move32(); st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = extract_l( Mpy_32_32( st_ivas->hCPE[0]->element_brate, 42949673 ) ) /* 1/50 in Q31*/; // ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); move16(); @@ -697,11 +697,11 @@ ivas_error ivas_corecoder_enc_reconfig_fx( st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent_fx( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, L_mult0( st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal, FRAMES_PER_SEC ), st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, - st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ); + st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ); /* Q0 */ move16(); - IF( NE_32( ( error = IGF_Reconfig( &st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc, st_ivas->hCPE[0]->hCoreCoder[n]->igf, 1, st_ivas->hCPE[0]->element_brate, st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ) ), IVAS_ERR_OK ) ) + IF( ( error = IGF_Reconfig( &st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc, st_ivas->hCPE[0]->hCoreCoder[n]->igf, 1, st_ivas->hCPE[0]->element_brate, st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 3a6ff508ddf4c651ae30ddb978c5b6401d7ec714..11dde0745d1362dfcaa0a2272b793b8ebeb71e3e 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -61,13 +61,13 @@ static void stereo_mode_combined_format_enc_fx( const Encoder_Struct *st_ivas, C * Channel Pair Element (CPE) encoding routine *-------------------------------------------------------------------*/ ivas_error ivas_cpe_enc_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 cpe_id, /* i : CPE # identifier */ - Word32 data_fx_ch0[], /* i : input signal for channel 0 Q(q_data_fx) */ - Word32 data_fx_ch1[], /* i : input signal for channel 1 Q(q_data_fx) */ - Word16 q_data_fx, /* i : Q-factor of input signal for both channels */ - const Word16 input_frame, /* i : input frame length per channel */ - const Word16 nb_bits_metadata, /* i : number of metadata bits */ + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 cpe_id, /* i : CPE # identifier Q0*/ + Word32 data_fx_ch0[], /* i : input signal for channel 0 Q(q_data_fx)*/ + Word32 data_fx_ch1[], /* i : input signal for channel 1 Q(q_data_fx)*/ + Word16 q_data_fx, /* i : Q-factor of input signal for both channels */ + const Word16 input_frame, /* i : input frame length per channel Q0*/ + const Word16 nb_bits_metadata, /* i : number of metadata bits Q0*/ Word16 Q_new_out[] ) { CPE_ENC_HANDLE hCPE; @@ -81,6 +81,7 @@ ivas_error ivas_cpe_enc_fx( Word16 fft_buff_fx[CPE_CHANNELS][2 * L_FFT]; /* FFT buffer */ Word16 fft_buff_fx_q[CPE_CHANNELS]; /* FFT buffer */ Word16 fft_buff_fx_final_q = MAX_16; + move16(); Word32 ener_fx[CPE_CHANNELS]; /* residual energy from Levinson-Durbin Q6 */ Word16 relE_fx[CPE_CHANNELS]; /* frame relative energy Q8 */ Word16 A_fx[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes Q12 */ @@ -189,16 +190,24 @@ ivas_error ivas_cpe_enc_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { - sts[n]->idchan = n; - sts[n]->core = -1; - sts[n]->core_brate = -1; /* updated in dtx() */ - sts[n]->max_bwidth = max_bwidth; + sts[n]->idchan = n; /* Q0 */ + sts[n]->core = -1; /* Q0 */ + sts[n]->core_brate = -1; /* updated in dtx() Q0*/ + sts[n]->max_bwidth = max_bwidth; /* Q0 */ + move32(); + move16(); + move16(); + move16(); + IF( st_ivas->hMCT == NULL ) /*already updated before CPE call*/ { - sts[n]->input_bwidth = sts[n]->last_input_bwidth; /* updated in BWD */ - sts[n]->bwidth = sts[n]->last_bwidth; /* updated in BWD */ + sts[n]->input_bwidth = sts[n]->last_input_bwidth; /* updated in BWD Q0*/ + sts[n]->bwidth = sts[n]->last_bwidth; /* updated in BWD Q0*/ + move16(); + move16(); } sts[n]->rate_switching_reset = 0; + move16(); #ifdef DEBUGGING sts[n]->force = hEncoderConfig->force; @@ -249,7 +258,7 @@ ivas_error ivas_cpe_enc_fx( test(); IF( sts[0]->ini_frame > 0 && st_ivas->hMCT == NULL ) { - hCPE->element_mode = select_stereo_mode( hCPE, ivas_format ); + hCPE->element_mode = select_stereo_mode( hCPE, ivas_format ); /* Q0 */ } stereo_mode_combined_format_enc_fx( st_ivas, hCPE ); @@ -264,13 +273,11 @@ ivas_error ivas_cpe_enc_fx( #ifdef MSAN_FIX set32_fx( band_energies_LR_fx, 0, 2 * NB_BANDS ); #endif -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { Q_buffer[n] = 15; move16(); } -#endif test(); IF( hCPE->hFrontVad[0] != NULL && NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { @@ -291,31 +298,35 @@ ivas_error ivas_cpe_enc_fx( return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( hCPE->hFrontVad[0] != NULL && hCPE->element_mode != IVAS_CPE_MDCT ) + IF( hCPE->hFrontVad[0] != NULL && NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { // Scale_sig( hCPE->hFrontVad[n]->buffer_12k8_fx + 384, 3 * L_FRAME / 2 - 384, sub( Q_buffer[n], hCPE->hFrontVad[n]->q_buffer_12k8 ) ); hCPE->hFrontVad[n]->q_buffer_12k8 = Q_buffer[n]; + move16(); } } -#endif sts[0]->element_mode = hCPE->element_mode; sts[1]->element_mode = hCPE->element_mode; + move16(); + move16(); n_CoreChannels = 2; - if ( hCPE->element_mode == IVAS_CPE_DFT ) + move16(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { n_CoreChannels = 1; /* in DFT stereo, only M channel is coded */ + move16(); sts[1]->vad_flag = 0; + move16(); } /*----------------------------------------------------------------* * dynamically allocate data structures depending on the actual stereo mode *----------------------------------------------------------------*/ - IF( NE_32( ( error = stereo_memory_enc_fx( hCPE, input_Fs, max_bwidth, ivas_format, st_ivas->nchan_transport ) ), IVAS_ERR_OK ) ) + IF( ( error = stereo_memory_enc_fx( hCPE, input_Fs, max_bwidth, ivas_format, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) { return error; } @@ -325,27 +336,27 @@ ivas_error ivas_cpe_enc_fx( * Set TD stereo parameters *----------------------------------------------------------------*/ - Copy_Scale_sig_16_32( sts[1]->input_fx, sts[1]->input32_fx, input_frame, sub( Q11, sts[1]->q_inp ) ); - Copy_Scale_sig_16_32( sts[0]->input_fx, sts[0]->input32_fx, input_frame, sub( Q11, sts[0]->q_inp ) ); + Copy_Scale_sig_16_32( sts[1]->input_fx, sts[1]->input32_fx, input_frame, sub( Q11, sts[1]->q_inp ) ); /* Q11 */ + Copy_Scale_sig_16_32( sts[0]->input_fx, sts[0]->input32_fx, input_frame, sub( Q11, sts[0]->q_inp ) ); /* Q11 */ Word16 shift = getScaleFactor32( sts[1]->input32_fx, input_frame ); - scale_sig32( sts[1]->input32_fx, input_frame, shift ); + scale_sig32( sts[1]->input32_fx, input_frame, shift ); /* Q11 + shift */ sts[1]->q_inp32 = add( Q11, shift ); move16(); shift = getScaleFactor32( sts[0]->input32_fx, input_frame ); - scale_sig32( sts[0]->input32_fx, input_frame, shift ); + scale_sig32( sts[0]->input32_fx, input_frame, shift ); /* Q11 + shift */ sts[0]->q_inp32 = add( Q11, shift ); move16(); Q_inp = s_min( Q_inp, s_min( sts[0]->q_inp32, sts[1]->q_inp32 ) ); - scale_sig32( sts[0]->input32_fx, input_frame, sub( Q_inp, sts[0]->q_inp32 ) ); - scale_sig32( sts[1]->input32_fx, input_frame, sub( Q_inp, sts[1]->q_inp32 ) ); + scale_sig32( sts[0]->input32_fx, input_frame, sub( Q_inp, sts[0]->q_inp32 ) ); /* Q_inp */ + scale_sig32( sts[1]->input32_fx, input_frame, sub( Q_inp, sts[1]->q_inp32 ) ); /* Q_inp */ sts[1]->q_inp32 = sts[0]->q_inp32 = Q_inp; move16(); move16(); - IF( NE_32( ( error = stereo_set_tdm_fx( hCPE, input_frame, Q_inp ) ), IVAS_ERR_OK ) ) + IF( ( error = stereo_set_tdm_fx( hCPE, input_frame, Q_inp ) ) != IVAS_ERR_OK ) { return error; } @@ -355,36 +366,39 @@ ivas_error ivas_cpe_enc_fx( * Resets/updates in case of stereo switching *----------------------------------------------------------------*/ shift = getScaleFactor16( sts[1]->old_input_signal_fx, input_frame ); - Scale_sig( sts[1]->old_input_signal_fx, input_frame, shift ); + Scale_sig( sts[1]->old_input_signal_fx, input_frame, shift ); /* sts[1]->q_old_inp + shift */ sts[1]->q_old_inp = add( sts[1]->q_old_inp, shift ); move16(); shift = getScaleFactor16( sts[1]->input_fx, input_frame ); - Scale_sig( sts[1]->input_fx, input_frame, shift ); + Scale_sig( sts[1]->input_fx, input_frame, shift ); /* sts[1]->q_inp + shift */ sts[1]->q_inp = add( sts[1]->q_inp, shift ); move16(); shift = getScaleFactor16( sts[0]->old_input_signal_fx, input_frame ); - Scale_sig( sts[0]->old_input_signal_fx, input_frame, shift ); + Scale_sig( sts[0]->old_input_signal_fx, input_frame, shift ); /* sts[1]->q_old_inp + shift */ sts[0]->q_old_inp = add( sts[0]->q_old_inp, shift ); move16(); shift = getScaleFactor16( sts[0]->input_fx, input_frame ); - Scale_sig( sts[0]->input_fx, input_frame, shift ); + Scale_sig( sts[0]->input_fx, input_frame, shift ); /* sts[1]->q_inp, shift */ sts[0]->q_inp = add( sts[0]->q_inp, shift ); move16(); Word16 q_inp = s_min( s_min( sts[0]->q_inp, sts[0]->q_old_inp ), s_min( sts[1]->q_inp, sts[1]->q_old_inp ) ); - Scale_sig( sts[1]->input_fx, input_frame, sub( q_inp, sts[1]->q_inp ) ); - Scale_sig( sts[1]->old_input_signal_fx, input_frame, sub( q_inp, sts[1]->q_old_inp ) ); + Scale_sig( sts[1]->input_fx, input_frame, sub( q_inp, sts[1]->q_inp ) ); /* q_inp */ + Scale_sig( sts[1]->old_input_signal_fx, input_frame, sub( q_inp, sts[1]->q_old_inp ) ); /* q_inp */ sts[1]->q_inp = q_inp; sts[1]->q_old_inp = q_inp; - Scale_sig( sts[0]->input_fx, input_frame, sub( q_inp, sts[0]->q_inp ) ); - Scale_sig( sts[0]->old_input_signal_fx, input_frame, sub( q_inp, sts[0]->q_old_inp ) ); + move16(); + move16(); + + Scale_sig( sts[0]->input_fx, input_frame, sub( q_inp, sts[0]->q_inp ) ); /* q_inp */ + Scale_sig( sts[0]->old_input_signal_fx, input_frame, sub( q_inp, sts[0]->q_old_inp ) ); /* q_inp */ sts[0]->q_inp = q_inp; move16(); sts[0]->q_old_inp = q_inp; move16(); - Scale_sig( sts[0]->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( q_inp, sub( Q15, sts[0]->exp_buf_speech_enc ) ) ); + Scale_sig( sts[0]->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( q_inp, sub( Q15, sts[0]->exp_buf_speech_enc ) ) ); // q_inp sts[0]->exp_buf_speech_enc = sub( Q15, q_inp ); move16(); stereo_switching_enc_fx( hCPE, sts[0]->old_input_signal_fx, input_frame, q_inp ); @@ -393,10 +407,10 @@ ivas_error ivas_cpe_enc_fx( * Temporal inter-channel alignment, stereo adjustment *----------------------------------------------------------------*/ - Copy_Scale_sig_16_32( sts[0]->input_buff_fx, sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), Q6 ); + Copy_Scale_sig_16_32( sts[0]->input_buff_fx, sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), Q6 ); /* Q6 + sts[0]->q_inp */ sts[0]->q_inp32 = add( Q6, sts[0]->q_inp ); move16(); - Copy_Scale_sig_16_32( sts[1]->input_buff_fx, sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), Q6 ); + Copy_Scale_sig_16_32( sts[1]->input_buff_fx, sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), Q6 ); /* Q6 + sts[0]->q_inp */ sts[1]->q_inp32 = add( Q6, sts[1]->q_inp ); move16(); @@ -404,8 +418,8 @@ ivas_error ivas_cpe_enc_fx( shift = s_min( 0, sub( add( L_norm_arr( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), sts[0]->q_inp32 ), 16 ) ); shift = s_min( shift, sub( add( L_norm_arr( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), sts[0]->q_inp32 ), 16 ) ); - Copy_Scale_sig32_16( sts[0]->input_buff32_fx, sts[0]->input_buff_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( add( Q16, shift ), sts[0]->q_inp32 ) ); - Copy_Scale_sig32_16( sts[1]->input_buff32_fx, sts[1]->input_buff_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( add( Q16, shift ), sts[1]->q_inp32 ) ); + Copy_Scale_sig32_16( sts[0]->input_buff32_fx, sts[0]->input_buff_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( add( Q16, shift ), sts[0]->q_inp32 ) ); // shift + Copy_Scale_sig32_16( sts[1]->input_buff32_fx, sts[1]->input_buff_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( add( Q16, shift ), sts[1]->q_inp32 ) ); // shift sts[0]->q_inp = sts[1]->q_inp = sts[0]->q_old_inp = sts[1]->q_old_inp = shift; move16(); @@ -418,14 +432,14 @@ ivas_error ivas_cpe_enc_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { - Copy( sts[n]->input_fx, orig_input_fx[n], input_frame ); - Scale_sig( orig_input_fx[n], input_frame, sub( -1, sts[n]->q_inp ) ); + Copy( sts[n]->input_fx, orig_input_fx[n], input_frame ); /* sts->q_inp */ + Scale_sig( orig_input_fx[n], input_frame, sub( -1, sts[n]->q_inp ) ); // Q(-1) Q_orig_inp[n] = -1; move16(); IF( hCPE->hStereoICBWE != NULL ) { - hCPE->hStereoICBWE->dataChan_fx[n] = &orig_input_fx[n][0]; + hCPE->hStereoICBWE->dataChan_fx[n] = &orig_input_fx[n][0]; // Q_orig_inp hCPE->hStereoICBWE->q_dataChan_fx = Q_orig_inp[n]; move16(); } @@ -484,23 +498,32 @@ ivas_error ivas_cpe_enc_fx( IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && ( NE_32( hCPE->element_brate, hCPE->last_element_brate ) || NE_16( hCPE->last_element_mode, hCPE->element_mode ) || sts[0]->ini_frame == 0 || ( NE_32( ivas_total_brate, st_ivas->hEncoderConfig->last_ivas_total_brate ) ) || LE_32( sts[0]->last_core_brate, SID_2k40 ) ) ) /* If the last frame was SID or NO_DATA, we need to run stereo_dft_config here since VAD decision is not known yet */ { + STEREO_DFT_CONFIG_DATA_HANDLE hConfig; + IF( hCPE->hStereoDft == NULL ) + { + hConfig = NULL; + } + ELSE + { + hConfig = hCPE->hStereoDft->hConfig; + } IF( st_ivas->hQMetaData != NULL ) { test(); /* No Basop - st_ivas->ism_mode != ISM_MODE_NONE as comparison with 0 */ IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) && st_ivas->ism_mode != ISM_MODE_NONE ) { - stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, 35 /* 0.70f * FRAMES_PER_SEC */ ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + stereo_dft_config_fx( hConfig, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, 35 /* 0.70f * FRAMES_PER_SEC */ ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } ELSE { - stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + stereo_dft_config_fx( hConfig, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } } ELSE { /* note; "bits_frame_nominal" needed in TD stereo as well */ - stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + stereo_dft_config_fx( hConfig, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } } @@ -508,8 +531,8 @@ ivas_error ivas_cpe_enc_fx( { IF( hCPE->hStereoTD->tdm_LRTD_flag ) { - sts[0]->bits_frame_nominal = (int16_t) ( ( hCPE->element_brate >> 1 ) / FRAMES_PER_SEC ); - sts[1]->bits_frame_nominal = (int16_t) ( ( hCPE->element_brate >> 1 ) / FRAMES_PER_SEC ); + sts[0]->bits_frame_nominal = extract_l( Mult_32_32( L_shr( hCPE->element_brate, 1 ), ONE_BY_FRAMES_PER_SEC_Q31 ) ); /* Q0 */ + sts[1]->bits_frame_nominal = extract_l( Mult_32_32( L_shr( hCPE->element_brate, 1 ), ONE_BY_FRAMES_PER_SEC_Q31 ) ); /* Q0 */ } ELSE { @@ -517,50 +540,75 @@ ivas_error ivas_cpe_enc_fx( } } - if ( hCPE->element_mode == IVAS_CPE_MDCT ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { /* compute bit-rate surplus per channel in combined format coding */ - int32_t brate_surplus[CPE_CHANNELS]; - if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + Word32 brate_surplus[CPE_CHANNELS]; + test(); + test(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - brate_surplus[0] = ( ( hCPE->brate_surplus / FRAMES_PER_SEC ) >> 1 ) * FRAMES_PER_SEC; - brate_surplus[1] = hCPE->brate_surplus - brate_surplus[0]; + brate_surplus[0] = imult3216( L_shr( Mpy_32_32_r( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ), 1 ), FRAMES_PER_SEC ); /* Q0 */ + brate_surplus[1] = L_sub( hCPE->brate_surplus, brate_surplus[0] ); /* Q0 */ + move32(); + move32(); } /* this is just for initialization, the true values of "total_brate" and "bits_frame_channel" are set later */ - for ( n = 0; n < n_CoreChannels; n++ ) + FOR( n = 0; n < n_CoreChannels; n++ ) { - if ( st_ivas->hMCT ) + IF( st_ivas->hMCT ) { - int16_t lfe_bits; - lfe_bits = ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCT ? st_ivas->hLFE->lfe_bits : 0 ); - sts[n]->total_brate = hCPE->element_brate; - sts[n]->bits_frame_nominal = (int16_t) ( hCPE->element_brate / FRAMES_PER_SEC ); - sts[n]->bits_frame_channel = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC - lfe_bits - nb_bits_metadata ) / st_ivas->hMCT->nchan_out_woLFE ); + Word16 lfe_bits; + test(); + IF( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) ) + { + lfe_bits = st_ivas->hLFE->lfe_bits; + move16(); + } + ELSE + { + lfe_bits = 0; + move16(); + } + sts[n]->total_brate = hCPE->element_brate; /* Q0 */ + sts[n]->bits_frame_nominal = extract_l( Mpy_32_32_r( hCPE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /* Q0 */ + sts[n]->bits_frame_channel = ( idiv1616( sub( sub( extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ), lfe_bits ), nb_bits_metadata ), st_ivas->hMCT->nchan_out_woLFE ) ); /* Q0 */ + move32(); + move16(); + move16(); } - else + ELSE { - sts[n]->bits_frame_nominal = (int16_t) ( hCPE->element_brate / FRAMES_PER_SEC ); - sts[n]->bits_frame_channel = (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) / n_CoreChannels ); - sts[n]->total_brate = hCPE->element_brate / n_CoreChannels; + sts[n]->bits_frame_nominal = extract_l( Mpy_32_32_r( hCPE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /* Q0 */ + sts[n]->bits_frame_channel = idiv1616( extract_l( Mpy_32_32_r( hCPE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ), n_CoreChannels ); /* Q0 */ + sts[n]->total_brate = L_shl( div_l( hCPE->element_brate, n_CoreChannels ), 1 ); /* Q0 */ + move32(); + move16(); + move16(); /* subtract bit-rate for combined format coding */ - if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - sts[n]->bits_frame_channel += (int16_t) ( brate_surplus[n] / FRAMES_PER_SEC ); - sts[n]->total_brate += brate_surplus[n]; + sts[n]->bits_frame_channel = add( sts[n]->bits_frame_channel, extract_l( Mpy_32_32_r( brate_surplus[n], ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); /* Q0 */ + sts[n]->total_brate = L_add( sts[n]->total_brate, brate_surplus[n] ); /* Q0 */ + move32(); + move16(); } } } /* reconfiguration in case of bitrate switching */ - if ( hCPE->element_brate != hCPE->last_element_brate && st_ivas->hMCT == NULL ) + IF( NE_32( hCPE->element_brate, hCPE->last_element_brate ) && st_ivas->hMCT == NULL ) { #ifdef DEBUGGING hCPE->hStereoMdct->mdct_stereo_mode_cmdl = hEncoderConfig->mdct_stereo_mode_cmdl; #endif initMdctStereoEncData_fx( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, max_bwidth, 0, NULL, 0 ); - hCPE->hStereoMdct->isSBAStereoMode = ( ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); + test(); + test(); + hCPE->hStereoMdct->isSBAStereoMode = ( ( EQ_16( ivas_format, SBA_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) && ( EQ_16( st_ivas->nchan_transport, 2 ) ) ); /* Q0 */ + move16(); } } @@ -569,54 +617,53 @@ ivas_error ivas_cpe_enc_fx( * Stereo down-mix *----------------------------------------------------------------*/ // printf("\n%f %f ", hCPE->hStereoClassif->is_speech, hCPE->hCoreCoder[0]->hSpMusClas->past_dlp[0]); - if ( hCPE->element_mode == IVAS_CPE_DFT ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* flt2fix: to be removed */ #ifndef MSAN_FIX hCPE->hStereoClassif->xtalk_score_fx = floatToFixed( hCPE->hStereoClassif->xtalk_score, 31 ); #endif // !MSAN_FIX /*flt2fix: dft_synthesize*/ - if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET] ) + test(); + if ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET] ) { sts[1]->exp_old_inp_12k8 = Q15; move16(); } - /*flt2fix end*/ -#endif Word16 temp = getScaleFactor32( hCPE->hStereoDft->Spd_L_smooth_fx, STEREO_DFT_N_32k_ENC / 2 ); - scale_sig32( hCPE->hStereoDft->Spd_L_smooth_fx, STEREO_DFT_N_32k_ENC / 2, temp ); + scale_sig32( hCPE->hStereoDft->Spd_L_smooth_fx, STEREO_DFT_N_32k_ENC / 2, temp ); /* exp(hCPE->hStereoDft->Spd_L_smooth_fx_e - temp)*/ hCPE->hStereoDft->Spd_L_smooth_fx_e = sub( hCPE->hStereoDft->Spd_L_smooth_fx_e, temp ); + move16(); temp = getScaleFactor32( hCPE->hStereoDft->Spd_R_smooth_fx, STEREO_DFT_N_32k_ENC / 2 ); - scale_sig32( hCPE->hStereoDft->Spd_R_smooth_fx, STEREO_DFT_N_32k_ENC / 2, temp ); + scale_sig32( hCPE->hStereoDft->Spd_R_smooth_fx, STEREO_DFT_N_32k_ENC / 2, temp ); /* exp(hCPE->hStereoDft->Spd_R_smooth_fx_e - temp) */ hCPE->hStereoDft->Spd_R_smooth_fx_e = sub( hCPE->hStereoDft->Spd_R_smooth_fx_e, temp ); + move16(); shift = getScaleFactor16( sts[1]->old_input_signal_fx, input_frame ); - Scale_sig( sts[1]->old_input_signal_fx, input_frame, shift ); + Scale_sig( sts[1]->old_input_signal_fx, input_frame, shift ); /* sts[1]->q_old_inp + shift */ sts[1]->q_old_inp = add( sts[1]->q_old_inp, shift ); move16(); shift = getScaleFactor16( sts[1]->input_fx, input_frame ); - Scale_sig( sts[1]->input_fx, input_frame, shift ); + Scale_sig( sts[1]->input_fx, input_frame, shift ); /* sts[1]->q_inp + shift */ sts[1]->q_inp = add( sts[1]->q_inp, shift ); move16(); - Scale_sig( sts[1]->input_fx, input_frame, sub( s_min( sts[1]->q_inp, sts[1]->q_old_inp ), sts[1]->q_inp ) ); - Scale_sig( sts[1]->old_input_signal_fx, input_frame, sub( s_min( sts[1]->q_old_inp, sts[1]->q_inp ), sts[1]->q_old_inp ) ); + Scale_sig( sts[1]->input_fx, input_frame, sub( s_min( sts[1]->q_inp, sts[1]->q_old_inp ), sts[1]->q_inp ) ); /* min( sts[1]->q_inp, sts[1]->q_old_inp) */ + Scale_sig( sts[1]->old_input_signal_fx, input_frame, sub( s_min( sts[1]->q_old_inp, sts[1]->q_inp ), sts[1]->q_old_inp ) ); /* min( sts[1]->q_old_inp, sts[1]->q_inp) */ sts[1]->q_inp = s_min( sts[1]->q_inp, sts[1]->q_old_inp ); move16(); sts[1]->q_old_inp = sts[1]->q_inp; move16(); shift = getScaleFactor16( sts[0]->old_input_signal_fx, input_frame ); - Scale_sig( sts[0]->old_input_signal_fx, input_frame, shift ); + Scale_sig( sts[0]->old_input_signal_fx, input_frame, shift ); /* sts[0]->q_old_inp + shift */ sts[0]->q_old_inp = add( sts[0]->q_old_inp, shift ); move16(); shift = getScaleFactor16( sts[0]->input_fx, input_frame ); - Scale_sig( sts[0]->input_fx, input_frame, shift ); + Scale_sig( sts[0]->input_fx, input_frame, shift ); /* sts[0]->q_inp + shift */ sts[0]->q_inp = add( sts[0]->q_inp, shift ); move16(); - Scale_sig( sts[0]->input_fx, input_frame, sub( s_min( sts[0]->q_inp, sts[0]->q_old_inp ), sts[0]->q_inp ) ); - Scale_sig( sts[0]->old_input_signal_fx, input_frame, sub( s_min( sts[0]->q_old_inp, sts[0]->q_inp ), sts[0]->q_old_inp ) ); + Scale_sig( sts[0]->input_fx, input_frame, sub( s_min( sts[0]->q_inp, sts[0]->q_old_inp ), sts[0]->q_inp ) ); /* min( sts[1]->q_inp, sts[1]->q_old_inp) */ + Scale_sig( sts[0]->old_input_signal_fx, input_frame, sub( s_min( sts[0]->q_old_inp, sts[0]->q_inp ), sts[0]->q_old_inp ) ); /* min( sts[1]->q_old_inp, sts[1]->q_inp) */ sts[0]->q_inp = s_min( sts[0]->q_inp, sts[0]->q_old_inp ); move16(); sts[0]->q_old_inp = sts[0]->q_inp; @@ -629,7 +676,7 @@ ivas_error ivas_cpe_enc_fx( stereo_dft_enc_analyze_fx( sts, CPE_CHANNELS, input_frame, hCPE->hStereoDft, NULL, hCPE->hStereoDft->DFT_fx, hCPE->hStereoDft->DFT_fx_e, hCPE->input_mem_fx, hCPE->q_input_mem ); - sts[0]->total_brate = L_mult0( add( sts[0]->bits_frame_nominal, 10 ), FRAMES_PER_SEC ); /* add small overhead; st[0]->total_brate used in coder_type_modif() */ + sts[0]->total_brate = L_mult0( add( sts[0]->bits_frame_nominal, 10 ), FRAMES_PER_SEC ); /* add small overhead; st[0]->total_brate used in coder_type_modif() Q0*/ /* Update DFT Stereo memories */ stereo_dft_enc_update_fx( hCPE->hStereoDft, sts[0]->max_bwidth ); @@ -637,26 +684,26 @@ ivas_error ivas_cpe_enc_fx( /* DFT stereo processing */ stereo_dft_enc_process_fx( hCPE, vad_flag_dtx, vad_hover_flag, input_frame ); } - else if ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) + ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { - Scale_sig( sts[0]->input_fx, input_frame, negate( sts[0]->q_inp ) ); + Scale_sig( sts[0]->input_fx, input_frame, negate( sts[0]->q_inp ) ); /* Q0 */ sts[0]->q_inp = 0; move16(); - Scale_sig( sts[1]->input_fx, input_frame, negate( sts[1]->q_inp ) ); + Scale_sig( sts[1]->input_fx, input_frame, negate( sts[1]->q_inp ) ); /* Q0 */ sts[1]->q_inp = 0; move16(); /* Determine the energy ratio between the 2 channels */ tdm_ratio_idx = stereo_tdm_ener_analysis_fx( ivas_format, - hCPE, input_frame, &tdm_SM_or_LRTD_Pri, &tdm_ratio_idx_SM ); + hCPE, input_frame, &tdm_SM_or_LRTD_Pri, &tdm_ratio_idx_SM ); /* Q0 */ /* Compute the downmix signal based on the ratio index */ Word16 tdm_SM_flag; IF( hCPE->hStereoTD->tdm_LRTD_flag == 0 ) { - tdm_SM_flag = tdm_SM_or_LRTD_Pri; + tdm_SM_flag = tdm_SM_or_LRTD_Pri; /* Q0 */ move16(); } ELSE @@ -668,64 +715,64 @@ ivas_error ivas_cpe_enc_fx( /* signal the bitrate for BW selection in the SCh */ sts[0]->bits_frame_channel = 0; - sts[1]->bits_frame_channel = extract_l( Mpy_32_32( hCPE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, extract_l( Mpy_32_32( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); + sts[1]->bits_frame_channel = extract_l( Mpy_32_32_r( hCPE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /* Q0 */ + sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, extract_l( Mpy_32_32_r( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); /* Q0 */ move16(); move16(); move16(); - IF( st_ivas->hQMetaData != NULL ) + if ( st_ivas->hQMetaData != NULL ) { - sts[1]->bits_frame_channel = sub( sts[1]->bits_frame_channel, st_ivas->hQMetaData->metadata_max_bits ); + sts[1]->bits_frame_channel = sub( sts[1]->bits_frame_channel, st_ivas->hQMetaData->metadata_max_bits ); /* Q0 */ move16(); } - Etot_last_fx[0] = sts[0]->hNoiseEst->Etot_last_fx; - Etot_last_fx[1] = sts[1]->hNoiseEst->Etot_last_fx; + Etot_last_fx[0] = sts[0]->hNoiseEst->Etot_last_fx; /* Q8 */ + Etot_last_fx[1] = sts[1]->hNoiseEst->Etot_last_fx; /* Q8 */ move16(); move16(); } - else if ( hCPE->element_mode == IVAS_CPE_MDCT ) + ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( hCPE->hStereoMdct != NULL && hCPE->hStereoMdct->hItd != NULL ) + test(); + IF( hCPE->hStereoMdct != NULL && hCPE->hStereoMdct->hItd != NULL ) { - if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET] ) + test(); + if ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET] ) { sts[1]->exp_old_inp_12k8 = Q15; move16(); } } -#endif test(); IF( hCPE->hStereoMdct != NULL && hCPE->hStereoMdct->hItd != NULL ) { shift = getScaleFactor16( sts[1]->old_input_signal_fx, input_frame ); - Scale_sig( sts[1]->old_input_signal_fx, input_frame, shift ); + Scale_sig( sts[1]->old_input_signal_fx, input_frame, shift ); /* sts[1]->q_old_inp + shift */ sts[1]->q_old_inp = add( sts[1]->q_old_inp, shift ); move16(); shift = getScaleFactor16( sts[1]->input_fx, input_frame ); - Scale_sig( sts[1]->input_fx, input_frame, shift ); + Scale_sig( sts[1]->input_fx, input_frame, shift ); /* sts[1]->q_inp + shift */ sts[1]->q_inp = add( sts[1]->q_inp, shift ); move16(); - Scale_sig( sts[1]->input_fx, input_frame, sub( s_min( sts[1]->q_inp, sts[1]->q_old_inp ), sts[1]->q_inp ) ); - Scale_sig( sts[1]->old_input_signal_fx, input_frame, sub( s_min( sts[1]->q_old_inp, sts[1]->q_inp ), sts[1]->q_old_inp ) ); + Scale_sig( sts[1]->input_fx, input_frame, sub( s_min( sts[1]->q_inp, sts[1]->q_old_inp ), sts[1]->q_inp ) ); /* min( sts[1]->q_inp, sts[1]->q_old_inp ) */ + Scale_sig( sts[1]->old_input_signal_fx, input_frame, sub( s_min( sts[1]->q_old_inp, sts[1]->q_inp ), sts[1]->q_old_inp ) ); /* min( sts[1]->q_inp, sts[1]->q_old_inp ) */ sts[1]->q_inp = s_min( sts[1]->q_inp, sts[1]->q_old_inp ); move16(); sts[1]->q_old_inp = sts[1]->q_inp; move16(); shift = getScaleFactor16( sts[0]->old_input_signal_fx, input_frame ); - Scale_sig( sts[0]->old_input_signal_fx, input_frame, shift ); + Scale_sig( sts[0]->old_input_signal_fx, input_frame, shift ); /* sts[0]->q_old_inp + shift*/ sts[0]->q_old_inp = add( sts[0]->q_old_inp, shift ); move16(); shift = getScaleFactor16( sts[0]->input_fx, input_frame ); - Scale_sig( sts[0]->input_fx, input_frame, shift ); + Scale_sig( sts[0]->input_fx, input_frame, shift ); /* sts[0]->q_inp + shift */ sts[0]->q_inp = add( sts[0]->q_inp, shift ); move16(); move16(); - Scale_sig( sts[0]->input_fx, input_frame, sub( s_min( sts[0]->q_inp, sts[0]->q_old_inp ), sts[0]->q_inp ) ); - Scale_sig( sts[0]->old_input_signal_fx, input_frame, sub( s_min( sts[0]->q_old_inp, sts[0]->q_inp ), sts[0]->q_old_inp ) ); + Scale_sig( sts[0]->input_fx, input_frame, sub( s_min( sts[0]->q_inp, sts[0]->q_old_inp ), sts[0]->q_inp ) ); /* min( sts[0]->q_inp, sts[0]->q_old_inp ) */ + Scale_sig( sts[0]->old_input_signal_fx, input_frame, sub( s_min( sts[0]->q_old_inp, sts[0]->q_inp ), sts[0]->q_old_inp ) ); /* min( sts[0]->q_inp, sts[0]->q_old_inp ) */ sts[0]->q_inp = s_min( sts[0]->q_inp, sts[0]->q_old_inp ); move16(); sts[0]->q_old_inp = sts[0]->q_inp; @@ -739,11 +786,19 @@ ivas_error ivas_cpe_enc_fx( * DFT stereo: iDFT and resampling on both channels *----------------------------------------------------------------*/ - if ( hCPE->element_mode == IVAS_CPE_DFT ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - int32_t internal_Fs; + Word32 internal_Fs; - internal_Fs = getTcxonly_ivas_fx( IVAS_CPE_MDCT, sts[0]->bits_frame_nominal * FRAMES_PER_SEC, 0, sts[0]->is_ism_format ) == 0 ? INT_FS_16k : max( INT_FS_16k, sts[0]->sr_core ); + IF( getTcxonly_ivas_fx( IVAS_CPE_MDCT, imult1616( sts[0]->bits_frame_nominal, FRAMES_PER_SEC ), 0, sts[0]->is_ism_format ) == 0 ) + { + internal_Fs = INT_FS_16k; + move32(); + } + ELSE + { + internal_Fs = max( INT_FS_16k, sts[0]->sr_core ); + } /* iDFT at input sampling rate */ Word16 out_start_ind, out_end_ind; @@ -759,9 +814,11 @@ ivas_error ivas_cpe_enc_fx( /* iDFT & resampling to 16kHz internal sampling rate for M channel */ IF( EQ_32( input_Fs, internal_Fs ) ) { - Copy32( sts[0]->input32_fx - STEREO_DFT_OVL_16k, old_inp_16k_fx[0] + L_INP_MEM - STEREO_DFT_OVL_16k, input_frame + STEREO_DFT_OVL_16k ); + Copy32( sts[0]->input32_fx - STEREO_DFT_OVL_16k, old_inp_16k_fx[0] + L_INP_MEM - STEREO_DFT_OVL_16k, add( input_frame, STEREO_DFT_OVL_16k ) ); /* Q_inp */ out_16k_start_ind = -STEREO_DFT_OVL_16k; - out_16k_end_ind = out_16k_start_ind + input_frame + STEREO_DFT_OVL_16k; + out_16k_end_ind = add( out_16k_start_ind, add( input_frame, STEREO_DFT_OVL_16k ) ); + move16(); + move16(); } ELSE { @@ -781,7 +838,6 @@ ivas_error ivas_cpe_enc_fx( Copy_Scale_sig32_16( sts[0]->input32_fx + out_start_ind, sts[0]->input_fx + out_start_ind, sub( out_end_ind, out_start_ind ), sub( add( Q16, sts[0]->q_inp ), Q15 ) ); // Q15 Copy_Scale_sig32_16( old_inp_16k_fx[0], old_inp_16k_16fx[0], L_INP, 0 ); // Q15->Q-1 -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS /*local fix2flt*/ /*fix2flt: dft_synthesize*/ Copy_Scale_sig_32_16( old_inp_12k8_fx[0] + L_INP_MEM + out_12k8_start_ind[0], old_inp_12k8_16fx[0] + L_INP_MEM + out_12k8_start_ind[0], out_12k8_end_ind[0] - out_12k8_start_ind[0], -Q16 ); // Q-1 @@ -791,8 +847,7 @@ ivas_error ivas_cpe_enc_fx( move16(); Copy_Scale_sig_32_16( old_inp_12k8_fx[1] + L_INP_MEM + out_12k8_start_ind[1], old_inp_12k8_16fx[1] + L_INP_MEM + out_12k8_start_ind[1], out_12k8_end_ind[1] - out_12k8_start_ind[1], -Q16 ); // Q-1 } - /*fix2flt end*/ -#endif + /* no iDFT at input sampling rate for Side channel -> reset the buffer */ set16_fx( sts[1]->input_fx, 0, input_frame ); sts[1]->q_inp = Q15; @@ -816,11 +871,20 @@ ivas_error ivas_cpe_enc_fx( set16_fx( old_wsp_fx[n], 0, L_WSP ); q_old_wsp = Q15; move16(); + Word16 front_vad_flag; + IF( st_ivas->hSpar != NULL ) + { + front_vad_flag = st_ivas->hSpar->front_vad_flag; + } + ELSE + { + front_vad_flag = 0; + } error = pre_proc_front_ivas_fx( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8_16fx[n], old_inp_16k_16fx[n], &ener_fx[n], &relE_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], &vad_hover_flag[n], &attack_flag[n], realBuffer_fx[n], imagBuffer_fx[n], &q_re_im_buf[n], old_wsp_fx[n], &q_old_wsp, pitch_fr_fx[n], voicing_fr_fx[n], &loc_harm[n], &cor_map_sum_fx[n], &vad_flag_dtx[n], enerBuffer_fx[n], &enerBuffer_fx_exp[n], fft_buff_fx[n], &fft_buff_fx_q[n], A_fx[0], lsp_new_fx[0], currFlatness_fx[n], tdm_ratio_idx, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, q_lf_E[n], localVAD_HE_SAD, - band_energies_LR_fx, q_band_energies_LR, 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, st_ivas->hMCT != NULL, ivas_total_brate, &Q_new[n] + band_energies_LR_fx, q_band_energies_LR, 0, front_vad_flag, 0, 0, ivas_format, st_ivas->hMCT != NULL, ivas_total_brate, &Q_new[n] #ifdef DEBUG_MODE_INFO , ( st_ivas->nSCE + ( cpe_id * CPE_CHANNELS ) + n ) @@ -828,7 +892,7 @@ ivas_error ivas_cpe_enc_fx( ); e_old_wsp[n] = sub( Q15, q_old_wsp ); move16(); - if ( error != IVAS_ERR_OK ) + IF( error != IVAS_ERR_OK ) { return error; } @@ -842,33 +906,39 @@ ivas_error ivas_cpe_enc_fx( fft_buff_fx_final_q = sub( fft_buff_fx_final_q, 2 ); // headroom FOR( n = 0; n < n_CoreChannels; n++ ) { - Scale_sig( fft_buff_fx[n], 2 * L_FFT, sub( fft_buff_fx_final_q, fft_buff_fx_q[n] ) ); + Scale_sig( fft_buff_fx[n], 2 * L_FFT, sub( fft_buff_fx_final_q, fft_buff_fx_q[n] ) ); /* fft_buff_fx_final_q */ } /* sanity check -> DTX not supported for more than one SCEs/CPEs */ - if ( st_ivas->nSCE + st_ivas->nCPE > 1 ) + IF( GT_16( add( st_ivas->nSCE, st_ivas->nCPE ), 1 ) ) { - if ( sts[0]->core_brate == SID_2k40 || sts[0]->core_brate == FRAME_NO_DATA ) + test(); + IF( EQ_32( sts[0]->core_brate, SID_2k40 ) || sts[0]->core_brate == FRAME_NO_DATA ) { - sts[0]->core_brate = -1; - sts[0]->total_brate = hCPE->element_brate; + sts[0]->core_brate = -1; /* Q0 */ + sts[0]->total_brate = hCPE->element_brate; /* Q0 */ + move32(); + move32(); } } /*----------------------------------------------------------------* * Stereo DTX updates *----------------------------------------------------------------*/ - - if ( ivas_format == MASA_FORMAT && nb_bits_metadata > 0 && hCPE->hCoreCoder[0]->Opt_DTX_ON ) + test(); + test(); + IF( EQ_16( ivas_format, MASA_FORMAT ) && nb_bits_metadata > 0 && hCPE->hCoreCoder[0]->Opt_DTX_ON ) { - if ( hCPE->element_mode == IVAS_CPE_DFT || hCPE->element_mode == IVAS_CPE_TD ) + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { reset_metadata_spatial_fx( ivas_format, hCPE->hMetaData, hCPE->element_brate, &tmp, sts[0]->core_brate, nb_bits_metadata ); } } /* MDCT stereo DTX: active/inactive frame decision; compute FD CNG coherence */ - if ( hCPE->element_mode == IVAS_CPE_MDCT && hEncoderConfig->Opt_DTX_ON ) + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && hEncoderConfig->Opt_DTX_ON ) { stereoFdCngCoherence_fx( sts, hCPE->last_element_mode, fft_buff_fx, sub( 15, fft_buff_fx_final_q ) /*fft exp*/ ); @@ -895,27 +965,36 @@ ivas_error ivas_cpe_enc_fx( IF( ( NE_32( hCPE->last_element_brate, hCPE->element_brate ) || NE_16( hCPE->element_mode, hCPE->last_element_mode ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && NE_16( sts[0]->bits_frame_nominal, last_bits_frame_nominal ) ) || NE_16( sts[n]->last_bwidth, sts[n]->bwidth ) ) && ( n == 0 || EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) ) { Word16 igf; - igf = getIgfPresent_fx( sts[n]->element_mode, L_mult0( sts[n]->bits_frame_nominal, FRAMES_PER_SEC ), sts[n]->max_bwidth, sts[n]->rf_mode ); - IF( NE_32( ( error = IGF_Reconfig_fx( &sts[n]->hIGFEnc, igf, 0, L_mult0( sts[n]->bits_frame_nominal, FRAMES_PER_SEC ), sts[n]->max_bwidth, sts[n]->element_mode, sts[n]->rf_mode ) ), IVAS_ERR_OK ) ) + igf = getIgfPresent_fx( sts[n]->element_mode, L_mult0( sts[n]->bits_frame_nominal, FRAMES_PER_SEC ), sts[n]->max_bwidth, sts[n]->rf_mode ); /* Q0 */ + IF( ( error = IGF_Reconfig_fx( &sts[n]->hIGFEnc, igf, 0, L_mult0( sts[n]->bits_frame_nominal, FRAMES_PER_SEC ), sts[n]->max_bwidth, sts[n]->element_mode, sts[n]->rf_mode ) ) != IVAS_ERR_OK ) { return error; } } } - if ( hCPE->element_mode == IVAS_CPE_MDCT && st_ivas->hMCT == NULL ) + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && st_ivas->hMCT == NULL ) { /* set coded BW for MDCT stereo */ set_bw_stereo_fx( hCPE ); /* reconfiguration of MDCT stereo */ - if ( sts[0]->bwidth != sts[0]->last_bwidth || ( ( hCPE->last_element_brate != hCPE->element_brate || hCPE->last_element_mode != hCPE->element_mode ) && sts[0]->bwidth != sts[0]->max_bwidth ) ) + test(); + test(); + test(); + IF( sts[0]->bwidth != sts[0]->last_bwidth || ( ( hCPE->last_element_brate != hCPE->element_brate || hCPE->last_element_mode != hCPE->element_mode ) && sts[0]->bwidth != sts[0]->max_bwidth ) ) { initMdctStereoEncData_fx( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, sts[0]->bwidth, 0, NULL, 0 ); - hCPE->hStereoMdct->isSBAStereoMode = ( ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); - if ( hCPE->element_brate <= MAX_MDCT_ITD_BRATE && ivas_format == STEREO_FORMAT ) + test(); + test(); + test(); + hCPE->hStereoMdct->isSBAStereoMode = ( ( EQ_16( ivas_format, SBA_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) && ( EQ_16( st_ivas->nchan_transport, 2 ) ) ); /* Q0 */ + + test(); + IF( LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) && EQ_16( ivas_format, STEREO_FORMAT ) ) { - IF( NE_32( ( error = initMdctItdHandling_fx( hCPE->hStereoMdct, input_Fs ) ), IVAS_ERR_OK ) ) + IF( ( error = initMdctItdHandling_fx( hCPE->hStereoMdct, input_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -924,20 +1003,24 @@ ivas_error ivas_cpe_enc_fx( } /* set ACELP@12k8 / ACELP@16k flag for flexible ACELP core */ - for ( n = 0; n < n_CoreChannels; n++ ) + FOR( n = 0; n < n_CoreChannels; n++ ) { - if ( ( sts[0]->core_brate == SID_2k40 || sts[0]->core_brate == FRAME_NO_DATA ) && hCPE->element_mode == IVAS_CPE_DFT ) + test(); + test(); + IF( ( EQ_32( sts[0]->core_brate, SID_2k40 ) || sts[0]->core_brate == FRAME_NO_DATA ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - sts[n]->flag_ACELP16k = set_ACELP_flag_IVAS( hCPE->element_mode, hCPE->element_brate, sts[n]->core_brate, n, sts[0]->tdm_LRTD_flag, sts[n]->bwidth, sts[n]->cng_type ); + sts[n]->flag_ACELP16k = set_ACELP_flag_IVAS( hCPE->element_mode, hCPE->element_brate, sts[n]->core_brate, n, sts[0]->tdm_LRTD_flag, sts[n]->bwidth, sts[n]->cng_type ); /* Q0 */ + move16(); } - else + ELSE { - sts[n]->flag_ACELP16k = set_ACELP_flag_IVAS( hCPE->element_mode, hCPE->element_brate, sts[n]->total_brate, n, sts[0]->tdm_LRTD_flag, sts[n]->bwidth, sts[n]->cng_type ); + sts[n]->flag_ACELP16k = set_ACELP_flag_IVAS( hCPE->element_mode, hCPE->element_brate, sts[n]->total_brate, n, sts[0]->tdm_LRTD_flag, sts[n]->bwidth, sts[n]->cng_type ); /* Q0 */ + move16(); } } /* configure TD stereo encoder */ - if ( hCPE->element_mode == IVAS_CPE_TD ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { tdm_ol_pitch_comparison_fx( hCPE, pitch_fr_fx, voicing_fr_fx ); tdm_configure_enc_fx( ivas_format, st_ivas->ism_mode, hCPE, Etot_last_fx, tdm_SM_or_LRTD_Pri, tdm_ratio_idx, tdm_ratio_idx_SM, attack_flag[0], nb_bits_metadata ); @@ -981,7 +1064,7 @@ ivas_error ivas_cpe_enc_fx( IF( hEncoderConfig->Opt_DTX_ON ) { test(); - IF( EQ_32( sts[0]->core_brate, SID_2k40 ) || EQ_32( sts[0]->core_brate, FRAME_NO_DATA ) ) + IF( EQ_32( sts[0]->core_brate, SID_2k40 ) || sts[0]->core_brate == FRAME_NO_DATA ) { /* Reconfigure DFT Stereo for inactive frames */ IF( EQ_32( sts[0]->core_brate, SID_2k40 ) ) @@ -1002,7 +1085,7 @@ ivas_error ivas_cpe_enc_fx( } /* Write stereo bitstream */ - cpe_brate = st_ivas->hCPE[0]->element_brate; + cpe_brate = st_ivas->hCPE[0]->element_brate; /* Q0 */ move16(); /* DFT stereo side bits */ @@ -1013,14 +1096,14 @@ ivas_error ivas_cpe_enc_fx( test(); test(); test(); - IF( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && LT_32( cpe_brate, MASA_STEREO_MIN_BITRATE ) && NE_32( sts[0]->core_brate, SID_2k40 ) && NE_32( sts[0]->core_brate, FRAME_NO_DATA ) ) + IF( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && LT_32( cpe_brate, MASA_STEREO_MIN_BITRATE ) && NE_32( sts[0]->core_brate, SID_2k40 ) && sts[0]->core_brate != FRAME_NO_DATA ) { nb_bits = 0; /* Only mono downmix is transmitted in this case */ move16(); } - ELSE IF( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && ( EQ_32( sts[0]->core_brate, SID_2k40 ) || EQ_32( sts[0]->core_brate, FRAME_NO_DATA ) ) ) + ELSE IF( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && ( EQ_32( sts[0]->core_brate, SID_2k40 ) || sts[0]->core_brate == FRAME_NO_DATA ) ) { - nb_bits = hCPE->hMetaData->nb_bits_tot; + nb_bits = hCPE->hMetaData->nb_bits_tot; /* Q0 */ move16(); } ELSE @@ -1029,15 +1112,18 @@ ivas_error ivas_cpe_enc_fx( } /* Residual coding in MDCT domain */ - if ( !( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && ( sts[0]->core_brate == SID_2k40 || sts[0]->core_brate == FRAME_NO_DATA ) ) ) + test(); + test(); + IF( !( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && ( EQ_32( sts[0]->core_brate, SID_2k40 ) || sts[0]->core_brate == FRAME_NO_DATA ) ) ) { - int16_t max_bits = (int16_t) ( hCPE->element_brate / FRAMES_PER_SEC - 0.8f * sts[0]->bits_frame_nominal ); - if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) + Word16 max_bits = extract_l( L_sub( Mpy_32_32_r( hCPE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ), Mult_32_16( sts[0]->bits_frame_nominal, 26214 /* 0.8f in Q15 */ ) ) ); + test(); + IF( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) { - max_bits -= nb_bits_metadata; - if ( hCPE->brate_surplus < 0 ) + max_bits = sub( max_bits, nb_bits_metadata ); + IF( hCPE->brate_surplus < 0 ) { - max_bits += (int16_t) ( hCPE->brate_surplus / FRAMES_PER_SEC ); + max_bits = add( max_bits, extract_l( Mpy_32_32_r( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); } } @@ -1048,23 +1134,29 @@ ivas_error ivas_cpe_enc_fx( stereo_dft_enc_res_fx( hCPE->hStereoDft, old_inp_12k8_fx[1] + L_INP_MEM - STEREO_DFT_OVL_8k, hCPE->hMetaData, &nb_bits, max_bits ); } - if ( sts[0]->core_brate == FRAME_NO_DATA || sts[0]->core_brate == SID_2k40 ) + IF( sts[0]->core_brate == FRAME_NO_DATA || EQ_32( sts[0]->core_brate, SID_2k40 ) ) { assert( ( nb_bits <= ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS ) ) && "Stereo DFT CNG: bit budget is violated" ); } - else + ELSE { /* Flexible total bitrate in M channel */ - sts[0]->total_brate = hCPE->element_brate - ( nb_bits * FRAMES_PER_SEC ); + sts[0]->total_brate = L_sub( hCPE->element_brate, L_deposit_l( imult1616( nb_bits, FRAMES_PER_SEC ) ) ); + move32(); } /* subtract metadata bitbudget */ - sts[0]->total_brate -= ( nb_bits_metadata * FRAMES_PER_SEC ); + sts[0]->total_brate = L_sub( sts[0]->total_brate, L_deposit_l( imult1616( nb_bits_metadata, FRAMES_PER_SEC ) ) ); + move32(); /* subtract bit-rate for combined format coding */ - if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) + test(); + test(); + test(); + if ( EQ_16( ivas_format, MASA_ISM_FORMAT ) && ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) { - sts[0]->total_brate += hCPE->brate_surplus; + sts[0]->total_brate = L_add( sts[0]->total_brate, hCPE->brate_surplus ); + move32(); } } @@ -1075,7 +1167,7 @@ ivas_error ivas_cpe_enc_fx( FOR( n = 0; n < n_CoreChannels; n++ ) { - Scale_sig( old_wsp_fx[n], L_WSP, sub( e_old_wsp[n], Q16 ) ); + Scale_sig( old_wsp_fx[n], L_WSP, sub( e_old_wsp[n], Q16 ) ); /* exp(16) */ e_old_wsp[n] = 16; move16(); } @@ -1088,49 +1180,57 @@ ivas_error ivas_cpe_enc_fx( * Common updates *----------------------------------------------------------------*/ - hCPE->last_element_brate = hCPE->element_brate; - hCPE->last_element_mode = hCPE->element_mode; + hCPE->last_element_brate = hCPE->element_brate; /* Q0 */ + move32(); + hCPE->last_element_mode = hCPE->element_mode; /* Q0 */ + move16(); - if ( ivas_format == MASA_ISM_FORMAT ) + if ( EQ_16( ivas_format, MASA_ISM_FORMAT ) ) { - hCPE->element_brate = element_brate_ref; + hCPE->element_brate = element_brate_ref; /* Q0 */ + move32(); } - if ( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->hStereoMdct != NULL && hCPE->hStereoMdct->hItd != NULL ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && hCPE->hStereoMdct != NULL && hCPE->hStereoMdct->hItd != NULL ) { /* update input samples buffer */ - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { - Copy( orig_input_fx[n], sts[n]->old_input_signal_fx, input_frame ); + Copy( orig_input_fx[n], sts[n]->old_input_signal_fx, input_frame ); /* Q_orig_inp */ sts[n]->q_old_inp = Q_orig_inp[n]; move16(); } } - else if ( hCPE->element_mode == IVAS_CPE_DFT ) + ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - Copy( sts[0]->input_fx, sts[0]->old_input_signal_fx, input_frame ); + Copy( sts[0]->input_fx, sts[0]->old_input_signal_fx, input_frame ); /* sts[n]->q_inp */ sts[0]->q_old_inp = sts[0]->q_inp; + move16(); } - else if ( st_ivas->hMCT == NULL ) /* note: in MCT, input buffers are updated later in ivas_mct_enc() */ + ELSE IF( st_ivas->hMCT == NULL ) /* note: in MCT, input buffers are updated later in ivas_mct_enc() */ { /* update input samples buffer */ - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { - Copy( sts[n]->input_fx, sts[n]->old_input_signal_fx, input_frame ); + Copy( sts[n]->input_fx, sts[n]->old_input_signal_fx, input_frame ); /* sts[n]->q_inp */ sts[n]->q_old_inp = sts[n]->q_inp; + move16(); } } - if ( hCPE->hFrontVad[0] != NULL ) + IF( hCPE->hFrontVad[0] != NULL ) { - hCPE->hFrontVad[0]->ini_frame++; - hCPE->hFrontVad[0]->ini_frame = min( hCPE->hFrontVad[0]->ini_frame, MAX_FRAME_COUNTER ); + hCPE->hFrontVad[0]->ini_frame = add( hCPE->hFrontVad[0]->ini_frame, 1 ); + hCPE->hFrontVad[0]->ini_frame = s_min( hCPE->hFrontVad[0]->ini_frame, MAX_FRAME_COUNTER ); + move16(); + move16(); } /* Store previous attack detection flag */ - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { - sts[n]->hTranDet->transientDetector.prev_bIsAttackPresent = sts[n]->hTranDet->transientDetector.bIsAttackPresent; + sts[n]->hTranDet->transientDetector.prev_bIsAttackPresent = sts[n]->hTranDet->transientDetector.bIsAttackPresent; /* Q0 */ + move16(); } IF( Q_new_out ) @@ -1157,8 +1257,8 @@ ivas_error ivas_cpe_enc_fx( *-------------------------------------------------------------------------*/ ivas_error create_cpe_enc_fx( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 cpe_id, /* i : CPE # identifier */ - const Word32 element_brate /* i : element bitrate */ + const Word16 cpe_id, /* i : CPE # identifier Q0*/ + const Word32 element_brate /* i : element bitrate Q0*/ ) { Word16 n; @@ -1175,11 +1275,11 @@ ivas_error create_cpe_enc_fx( ivas_format = hEncoderConfig->ivas_format; move16(); - element_mode_init = hEncoderConfig->element_mode_init; + element_mode_init = hEncoderConfig->element_mode_init; /* Q0 */ move16(); - input_Fs = hEncoderConfig->input_Fs; + input_Fs = hEncoderConfig->input_Fs; /* Q0 */ move16(); - max_bwidth = hEncoderConfig->max_bwidth; + max_bwidth = hEncoderConfig->max_bwidth; /* Q0 */ move16(); /*-----------------------------------------------------------------* @@ -1195,15 +1295,15 @@ ivas_error create_cpe_enc_fx( * Initialization - general parameters *-----------------------------------------------------------------*/ - hCPE->cpe_id = cpe_id; + hCPE->cpe_id = cpe_id; /* Q0 */ move16(); - hCPE->element_brate = element_brate; + hCPE->element_brate = element_brate; /* Q0 */ move16(); - hCPE->last_element_brate = hCPE->element_brate; + hCPE->last_element_brate = hCPE->element_brate; /* Q0 */ move16(); - hCPE->element_mode = element_mode_init; + hCPE->element_mode = element_mode_init; /* Q0 */ move16(); - hCPE->last_element_mode = element_mode_init; + hCPE->last_element_mode = element_mode_init; /* Q0 */ move16(); hCPE->hStereoDft = NULL; @@ -1264,7 +1364,7 @@ ivas_error create_cpe_enc_fx( IF( EQ_16( cpe_id, sub( st_ivas->nCPE, 1 ) ) ) { - IF( NE_32( ( error = ivas_initialize_MD_bstr_enc( &( hCPE->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_initialize_MD_bstr_enc_fx( &( hCPE->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1285,12 +1385,12 @@ ivas_error create_cpe_enc_fx( IF( GT_16( st_ivas->nCPE, 1 ) ) { - st->total_brate = hCPE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + st->total_brate = hCPE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() Q0*/ move32(); } ELSE { - st->total_brate = L_shr( hCPE->element_brate, 1 ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + st->total_brate = L_shr( hCPE->element_brate, 1 ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() Q0*/ move32(); } st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; @@ -1302,7 +1402,8 @@ ivas_error create_cpe_enc_fx( IF( st->hFdCngEnc != NULL ) { - st->hFdCngEnc->hFdCngCom->CngBitrate = L_sub( hCPE->element_brate, 1 ); + st->hFdCngEnc->hFdCngCom->CngBitrate = L_sub( hCPE->element_brate, 1 ); /* Q0 */ + move32(); } hCPE->hCoreCoder[n] = st; @@ -1338,7 +1439,7 @@ ivas_error create_cpe_enc_fx( { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - IF( NE_32( ( error = front_vad_create_fx( &( hCPE->hFrontVad[n] ), hEncoderConfig ) ), IVAS_ERR_OK ) ) + IF( ( error = front_vad_create_fx( &( hCPE->hFrontVad[n] ), hEncoderConfig ) ) != IVAS_ERR_OK ) { return error; } @@ -1358,7 +1459,7 @@ ivas_error create_cpe_enc_fx( IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - IF( NE_32( ( error = stereo_dft_enc_create_fx( &( hCPE->hStereoDft ), input_Fs, max_bwidth ) ), IVAS_ERR_OK ) ) + IF( ( error = stereo_dft_enc_create_fx( &( hCPE->hStereoDft ), input_Fs, max_bwidth ) ) != IVAS_ERR_OK ) { return error; } @@ -1398,7 +1499,7 @@ ivas_error create_cpe_enc_fx( IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { - if ( ( hCPE->hStereoTD = (STEREO_TD_ENC_DATA_HANDLE) malloc( sizeof( STEREO_TD_ENC_DATA ) ) ) == NULL ) + IF( ( hCPE->hStereoTD = (STEREO_TD_ENC_DATA_HANDLE) malloc( sizeof( STEREO_TD_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD Stereo\n" ) ); } @@ -1409,6 +1510,7 @@ ivas_error create_cpe_enc_fx( * MDCT stereo initialization *-----------------------------------------------------------------*/ + test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( st_ivas->nCPE, 1 ) ) { IF( ( hCPE->hStereoMdct = (STEREO_MDCT_ENC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL ) @@ -1435,12 +1537,17 @@ ivas_error create_cpe_enc_fx( #endif initMdctStereoEncData_fx( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, max_bwidth, 0, NULL, 1 ); + + test(); + test(); hCPE->hStereoMdct->isSBAStereoMode = ( ( EQ_16( ivas_format, SBA_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) && EQ_16( st_ivas->nchan_transport, 2 ) ); + move16(); + test(); test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && LE_32( element_brate, MAX_MDCT_ITD_BRATE ) && EQ_16( ivas_format, STEREO_FORMAT ) ) { - IF( NE_32( ( error = initMdctItdHandling_fx( hCPE->hStereoMdct, input_Fs ) ), IVAS_ERR_OK ) ) + IF( ( error = initMdctItdHandling_fx( hCPE->hStereoMdct, input_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -1479,7 +1586,7 @@ void destroy_cpe_enc( } } - ivas_destroy_MD_bstr_enc( &( hCPE->hMetaData ) ); + ivas_destroy_MD_bstr_enc_fx( &( hCPE->hMetaData ) ); FOR( n = 0; n < CPE_CHANNELS; n++ ) { @@ -1561,7 +1668,7 @@ static void stereo_mode_combined_format_enc_fx( IF( EQ_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { - element_brate_ref = hCPE->element_brate; + element_brate_ref = hCPE->element_brate; /* Q0 */ move32(); test(); @@ -1579,9 +1686,9 @@ static void stereo_mode_combined_format_enc_fx( } ELSE { - st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt = add( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt, 1 ); + st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt = add( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt, 1 ); /* Q0 */ move16(); - st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt = s_min( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt, OMASA_STEREO_SW_CNT_MAX ); + st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt = s_min( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt, OMASA_STEREO_SW_CNT_MAX ); /* Q0 */ move16(); } @@ -1591,7 +1698,7 @@ static void stereo_mode_combined_format_enc_fx( move16(); hCPE->element_brate = IVAS_64k; move32(); - hCPE->brate_surplus = L_sub( hCPE->brate_surplus, L_sub( hCPE->element_brate, element_brate_ref ) ); + hCPE->brate_surplus = L_sub( hCPE->brate_surplus, L_sub( hCPE->element_brate, element_brate_ref ) ); /* Q0 */ move32(); } @@ -1606,6 +1713,5 @@ static void stereo_mode_combined_format_enc_fx( } } } - return; } diff --git a/lib_enc/ivas_decision_matrix_enc.c b/lib_enc/ivas_decision_matrix_enc.c index 84939b6024d105b136501dddd94932b742ef7c7d..0ecafc6c3fdb42a50ac19a840dff857d14def364 100644 --- a/lib_enc/ivas_decision_matrix_enc.c +++ b/lib_enc/ivas_decision_matrix_enc.c @@ -74,11 +74,11 @@ void ivas_decision_matrix_enc_fx( Encoder_State *st, /* i : encoder state structure */ - const Word32 element_brate, /* i : element bitrate */ - const Word16 fft_buff[], /* i : FFT buffer */ - const Word32 enerBuffer[], /* i : energy buffer */ + const Word32 element_brate, /* i : element bitrate Q0*/ + const Word16 fft_buff[], /* i : FFT buffer Qx*/ + const Word32 enerBuffer[], /* i : energy buffer enerBuffer_exp*/ Word16 enerBuffer_exp, - const Word16 last_element_mode /* i : last element mode */ + const Word16 last_element_mode /* i : last element mode Q0*/ ) { Word32 icbwe_brate; @@ -96,7 +96,7 @@ void ivas_decision_matrix_enc_fx( st->extl_brate = 0; move16(); - IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + if ( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { st->igf = 0; move16(); @@ -106,13 +106,13 @@ void ivas_decision_matrix_enc_fx( test(); /* SID and FRAME_NO_DATA frames */ - IF( st->Opt_DTX_ON && ( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) ) + IF( st->Opt_DTX_ON && ( EQ_32( st->core_brate, SID_2k40 ) || st->core_brate == FRAME_NO_DATA ) ) { st->core = ACELP_CORE; move16(); test(); - IF( GE_32( st->input_Fs, 32000 ) || GE_16( st->bwidth, SWB ) ) + if ( GE_32( st->input_Fs, 32000 ) || GE_16( st->bwidth, SWB ) ) { st->extl = SWB_CNG; move16(); @@ -195,7 +195,7 @@ void ivas_decision_matrix_enc_fx( ELSE { /* select TCX core or HQ core using bits_frame_nominal to match the TCX configuration bitrate */ - st->core = mdct_classifier_ivas_fx( st, fft_buff, enerBuffer, enerBuffer_exp, ( st->bits_frame_nominal * FRAMES_PER_SEC ) ); + st->core = mdct_classifier_ivas_fx( st, fft_buff, enerBuffer, enerBuffer_exp, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ) ); /* Q0 */ move16(); } } @@ -208,14 +208,14 @@ void ivas_decision_matrix_enc_fx( test(); /* do not allow TD stereo ACELP core -> DFT stereo TCX core switching as it is on the WC complexity path */ - IF( ( ( EQ_16( st->last_core, ACELP_CORE ) && EQ_16( last_element_mode, IVAS_CPE_TD ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) || ( EQ_16( st->tdm_LRTD_flag, 1 ) && LE_32( st->total_brate, IVAS_16k4 ) ) ) && EQ_16( st->core, TCX_20_CORE ) && LE_32( st->total_brate, MAX_ACELP_BRATE ) ) /* Override TCX in case of LRTD && primary channel has low bitrate*/ + if ( ( ( st->last_core == ACELP_CORE && EQ_16( last_element_mode, IVAS_CPE_TD ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) || ( EQ_16( st->tdm_LRTD_flag, 1 ) && LE_32( st->total_brate, IVAS_16k4 ) ) ) && EQ_16( st->core, TCX_20_CORE ) && LE_32( st->total_brate, MAX_ACELP_BRATE ) ) /* Override TCX in case of LRTD && primary channel has low bitrate*/ { st->core = ACELP_CORE; move16(); } test(); - IF( st->is_ism_format && st->tcxonly ) + if ( st->is_ism_format && st->tcxonly ) { st->core = TCX_20_CORE; move16(); @@ -276,7 +276,7 @@ void ivas_decision_matrix_enc_fx( move16(); move16(); - IF( st->low_rate_mode ) + if ( st->low_rate_mode ) { st->coder_type = INACTIVE; move16(); @@ -288,7 +288,7 @@ void ivas_decision_matrix_enc_fx( test(); test(); test(); - IF( st->is_ism_format && st->flag_ACELP16k && !st->low_rate_mode && EQ_16( st->core, ACELP_CORE ) && LT_32( st->total_brate, add( ACELP_16k_LOW_LIMIT, FB_TBE_1k8 ) ) ) + if ( st->is_ism_format && st->flag_ACELP16k && !st->low_rate_mode && st->core == ACELP_CORE && LT_32( st->total_brate, add( ACELP_16k_LOW_LIMIT, FB_TBE_1k8 ) ) ) { st->core = TCX_20_CORE; move16(); @@ -298,15 +298,15 @@ void ivas_decision_matrix_enc_fx( * Select ACELP and GSC extension layer *---------------------------------------------------------------------*/ - IF( EQ_16( st->core, ACELP_CORE ) ) + IF( st->core == ACELP_CORE ) { /* WB */ + test(); IF( EQ_16( st->bwidth, WB ) ) { test(); test(); test(); - test(); IF( LT_32( st->total_brate, MIN_BRATE_WB_BWE ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) ) { st->extl = WB_BWE; @@ -316,7 +316,7 @@ void ivas_decision_matrix_enc_fx( { test(); test(); - IF( ( EQ_16( st->sp_aud_decision1, 1 ) && st->sp_aud_decision2 == 0 ) || EQ_16( st->coder_type, INACTIVE ) ) + IF( ( EQ_16( st->sp_aud_decision1, 1 ) && st->sp_aud_decision2 == 0 ) || st->coder_type == INACTIVE ) { st->extl = WB_BWE; move16(); @@ -361,7 +361,7 @@ void ivas_decision_matrix_enc_fx( test(); test(); test(); - IF( ( ( ( EQ_16( st->sp_aud_decision1, 1 ) && st->sp_aud_decision2 == 0 ) || EQ_16( st->coder_type, INACTIVE ) ) && !st->GSC_noisy_speech ) /* Note: SWB BWE is not used for GSC noisy speech */ ) + IF( ( ( ( EQ_16( st->sp_aud_decision1, 1 ) && st->sp_aud_decision2 == 0 ) || st->coder_type == INACTIVE ) && !st->GSC_noisy_speech ) /* Note: SWB BWE is not used for GSC noisy speech */ ) { st->extl = SWB_BWE; move16(); @@ -423,7 +423,7 @@ void ivas_decision_matrix_enc_fx( test(); test(); - IF( GE_32( st->total_brate, MIN_BRATE_SWB_TBE_2k80 ) && st->flag_ACELP16k && EQ_16( st->element_mode, IVAS_SCE ) ) + if ( GE_32( st->total_brate, MIN_BRATE_SWB_TBE_2k80 ) && st->flag_ACELP16k && EQ_16( st->element_mode, IVAS_SCE ) ) { st->extl_brate = FB_TBE_3k0; move32(); @@ -448,7 +448,7 @@ void ivas_decision_matrix_enc_fx( icbwe_brate = STEREO_BITS_ICBWE * FRAMES_PER_SEC; move32(); - IF( st->flag_ACELP16k == 0 ) + if ( st->flag_ACELP16k == 0 ) { icbwe_brate = ( STEREO_BITS_ICBWE - STEREO_ICBWE_SPBITS ) * FRAMES_PER_SEC; move32(); @@ -459,7 +459,7 @@ void ivas_decision_matrix_enc_fx( icbwe_brate = STEREO_BITS_ICBWE_DFT * FRAMES_PER_SEC; move32(); - IF( st->flag_ACELP16k == 0 ) + if ( st->flag_ACELP16k == 0 ) { icbwe_brate = ( STEREO_BITS_ICBWE_DFT - STEREO_ICBWE_SPBITS ) * FRAMES_PER_SEC; move32(); @@ -471,9 +471,9 @@ void ivas_decision_matrix_enc_fx( test(); test(); test(); - if ( GE_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( st->core, ACELP_CORE ) && ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) + if ( GE_16( st->element_mode, IVAS_CPE_DFT ) && st->core == ACELP_CORE && ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) { - icbwe_brate = L_add( icbwe_brate, STEREO_ICBWE_MSFLAG_BITS * FRAMES_PER_SEC ); + icbwe_brate = L_add( icbwe_brate, STEREO_ICBWE_MSFLAG_BITS * FRAMES_PER_SEC ); /* Q0 */ move32(); } } @@ -481,19 +481,19 @@ void ivas_decision_matrix_enc_fx( /* set core bitrate */ - st->core_brate = L_sub( L_sub( st->total_brate, st->extl_brate ), icbwe_brate ); + st->core_brate = L_sub( L_sub( st->total_brate, st->extl_brate ), icbwe_brate ); /* Q0 */ move32(); IF( st->ini_frame == 0 ) { /* avoid core switching in the very first frame */ - st->last_core = st->core; + st->last_core = st->core; /* Q0 */ move16(); - st->last_core_brate = st->core_brate; + st->last_core_brate = st->core_brate; /* Q0 */ move32(); - st->last_extl = st->extl; + st->last_extl = st->extl; /* Q0 */ move16(); } @@ -504,7 +504,7 @@ void ivas_decision_matrix_enc_fx( st->inactive_coder_type_flag = 0; /* AVQ by default */ move16(); - IF( LE_32( st->total_brate, MAX_GSC_INACTIVE_BRATE ) ) + if ( LE_32( st->total_brate, MAX_GSC_INACTIVE_BRATE ) ) { st->inactive_coder_type_flag = 1; /* GSC */ move16(); @@ -520,11 +520,11 @@ void ivas_decision_matrix_enc_fx( *---------------------------------------------------------------------*/ void ivas_signaling_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const Word32 element_brate, /* i : element bitrate */ - const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel */ - const Word16 tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag in TD stereo */ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel Q0*/ + const Word16 tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag in TD stereo Q0*/ ) { Word16 ind; @@ -559,7 +559,7 @@ void ivas_signaling_enc_fx( test(); IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && !MCT_flag ) /* note: in MCT, the MDCT stereo is used exclusively */ { - ind = sub( st->element_mode, IVAS_CPE_DFT ); + ind = sub( st->element_mode, IVAS_CPE_DFT ); /* Q0 */ push_indice( hBstr, IND_SMODE, ind, NBITS_ELEMENT_MODE ); } @@ -579,7 +579,7 @@ void ivas_signaling_enc_fx( ( LT_32( element_brate, MIN_BRATE_FB_ISM ) && st->is_ism_format ) ) { /* WB and SWB are supported */ - ind = sub( st->bwidth, WB ); + ind = sub( st->bwidth, WB ); /* Q0 */ push_indice( hBstr, IND_BWIDTH, ind, 1 ); } ELSE @@ -597,7 +597,7 @@ void ivas_signaling_enc_fx( test(); IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || GE_32( st->total_brate, STEREO_TCX_MIN_RATE ) ) { - IF( EQ_16( st->core, ACELP_CORE ) ) + IF( st->core == ACELP_CORE ) { push_indice( hBstr, IND_CORE, 0, 1 ); } @@ -611,7 +611,7 @@ void ivas_signaling_enc_fx( * Write core dependent signaling *--------------------------------------------------------------------------*/ - IF( EQ_16( st->core, ACELP_CORE ) ) + IF( st->core == ACELP_CORE ) { /* write coder type */ push_indice( hBstr, IND_ACELP_SIGNALLING, st->coder_type, 3 ); diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 0b2ac1c366de4184f180c7f28d8578e06924e465..58a916858f789a241ff886158dd6951e3e79d27b 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -88,7 +88,7 @@ ivas_error ivas_dirac_enc_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC Config\n" ) ); } - hDirAC->firstrun_sector_params = 1; + hDirAC->firstrun_sector_params = 1; /* Q0 */ move16(); set32_fx( hDirAC->sec_I_vec_smth_x_fx[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); @@ -107,7 +107,7 @@ ivas_error ivas_dirac_enc_open_fx( st_ivas->hDirAC = hDirAC; - IF( NE_32( ( error = ivas_dirac_config_fx( (void *) st_ivas, ENC ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_dirac_config_fx( (void *) st_ivas, ENC ) ) != IVAS_ERR_OK ) { return error; } @@ -118,7 +118,7 @@ ivas_error ivas_dirac_enc_open_fx( FOR( i = 0; i < DIRAC_MAX_NBANDS + 1; i++ ) { /* adapt band grouping to from CLDFB to MDFT bands */ - hDirAC->band_grouping[i] = imult1616( hDirAC->band_grouping[i], CLDFB_TO_MDFT_FAC ); + hDirAC->band_grouping[i] = imult1616( hDirAC->band_grouping[i], CLDFB_TO_MDFT_FAC ); /* Q0 */ move16(); } dirac_slot_ns = DIRAC_SLOT_ENC_NS; @@ -145,7 +145,7 @@ ivas_error ivas_dirac_enc_open_fx( Word16 tmp_e = 0; move16(); - Word16 tmp = BASOP_Util_Divide3232_Scale( (Word32) DIRAC_NO_COL_AVG_DIFF_NS, dirac_slot_ns, &tmp_e ); + Word16 tmp = BASOP_Util_Divide3232_Scale( (Word32) DIRAC_NO_COL_AVG_DIFF_NS, dirac_slot_ns, &tmp_e ); /* exp(tmp_e) */ hDirAC->no_col_avg_diff = shr( tmp, sub( 15, tmp_e ) ); move16(); @@ -194,7 +194,7 @@ ivas_error ivas_dirac_enc_open_fx( move16(); st_ivas->hDirAC = hDirAC; - st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; /* Q0 */ move16(); return error; @@ -251,7 +251,7 @@ ivas_error ivas_dirac_enc_reconfigure( *------------------------------------------------------------------------*/ void ivas_dirac_enc_close_fx( DIRAC_ENC_HANDLE *hDirAC_out, /* i/o: encoder DirAC handle */ - const Word32 input_Fs /* i : input sampling rate */ + const Word32 input_Fs /* i : input sampling rate Q0*/ ) { Word16 i, j; @@ -320,14 +320,14 @@ ivas_error ivas_dirac_enc_fx( DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ - Word32 *data_f_fx[], /* i/o: SBA channels Qx */ - Word32 **pp_fr_real_fx, /* o : real freq domain values pp_fr_q */ - Word32 **pp_fr_imag_fx, /* o : imag freq domain values pp_fr_q */ + Word32 *data_f_fx[], /* i/o: SBA channels Qx*/ + Word32 **pp_fr_real_fx, /* o : real freq domain values pp_fr_q*/ + Word32 **pp_fr_imag_fx, /* o : imag freq domain values pp_fr_q*/ Word16 pp_fr_q, - const Word16 input_frame, /* i : input frame length Q0 */ - const Word16 dtx_vad, /* i : DTX vad flag Q0 */ - const IVAS_FORMAT ivas_format, /* i : ivas format */ - const Word16 hodirac_flag /* i : hodirac flag Q0 */ + const Word16 input_frame, /* i : input frame length Q0*/ + const Word16 dtx_vad, /* i : DTX vad flag Q0*/ + const IVAS_FORMAT ivas_format, /* i : ivas format */ + const Word16 hodirac_flag /* i : hodirac flag Q0*/ ) { Word16 orig_dirac_bands; @@ -336,14 +336,24 @@ ivas_error ivas_dirac_enc_fx( ivas_error error; push_wmops( "ivas_dirac_enc" ); - Word16 nchan_fb_in = hodirac_flag ? HOA2_CHANNELS : FOA_CHANNELS; - move16(); + Word16 nchan_fb_in; + + if ( hodirac_flag ) + { + nchan_fb_in = HOA2_CHANNELS; + move16(); + } + else + { + nchan_fb_in = FOA_CHANNELS; + move16(); + } ivas_dirac_param_est_enc_fx( hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, data_f_fx, pp_fr_real_fx, pp_fr_imag_fx, pp_fr_q, input_frame, ivas_format, hodirac_flag, nchan_fb_in, &( hDirAC->mono_frame_count ), &( hQMetaData->dirac_mono_flag ) ); IF( hQMetaData->q_direction->cfg.nbands > 0 ) { - orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands; + orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands; /* Q0 */ move16(); IF( EQ_16( dtx_vad, 1 ) ) @@ -386,7 +396,7 @@ ivas_error ivas_dirac_enc_fx( } } - IF( NE_32( ( error = ivas_qmetadata_enc_encode_fx( hMetaData, hQMetaData, hodirac_flag ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_qmetadata_enc_encode_fx( hMetaData, hQMetaData, hodirac_flag ) ) != IVAS_ERR_OK ) { return error; } @@ -411,15 +421,15 @@ ivas_error ivas_dirac_enc_fx( { ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( hQMetaData->q_direction[0].band_data[j].azimuth_fx[i], hQMetaData->q_direction[0].band_data[j].elevation_fx[i], &dir_fx[0] ); - Word32 vecLen_fx = Mpy_32_32( hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[i] /*Q30*/, hDirAC->buffer_energy_fx[i * orig_dirac_bands + j] ); - avg_dir_fx[0] = L_add( avg_dir_fx[0], Mpy_32_32( dir_fx[0], vecLen_fx ) ); // Q30 + hDirAC->buffer_energy_q[i * orig_dirac_bands + j] - 1 - 31 - avg_dir_fx[1] = L_add( avg_dir_fx[1], Mpy_32_32( dir_fx[1], vecLen_fx ) ); // Q30 + hDirAC->buffer_energy_q[i * orig_dirac_bands + j] - 1 - 31 - avg_dir_fx[2] = L_add( avg_dir_fx[2], Mpy_32_32( dir_fx[2], vecLen_fx ) ); // Q30 + hDirAC->buffer_energy_q[i * orig_dirac_bands + j] - 1 - 31 + Word32 vecLen_fx = Mpy_32_32( hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[i] /*Q30*/, hDirAC->buffer_energy_fx[i * orig_dirac_bands + j] ); /* hDirAC->buffer_energy_q[i * orig_dirac_bands + j] - 1 */ + avg_dir_fx[0] = L_add( avg_dir_fx[0], Mpy_32_32( dir_fx[0], vecLen_fx ) ); // Q30 + hDirAC->buffer_energy_q[i * orig_dirac_bands + j] - 1 - 31 + avg_dir_fx[1] = L_add( avg_dir_fx[1], Mpy_32_32( dir_fx[1], vecLen_fx ) ); // Q30 + hDirAC->buffer_energy_q[i * orig_dirac_bands + j] - 1 - 31 + avg_dir_fx[2] = L_add( avg_dir_fx[2], Mpy_32_32( dir_fx[2], vecLen_fx ) ); // Q30 + hDirAC->buffer_energy_q[i * orig_dirac_bands + j] - 1 - 31 move32(); move32(); move32(); avg_dir_e = sub( 31, ( sub( add( Q30, hDirAC->buffer_energy_q[i * orig_dirac_bands + j] ), 1 - 31 ) ) ); - energySum_fx = BASOP_Util_Add_Mant32Exp( energySum_fx, energySum_e, hDirAC->buffer_energy_fx[i * orig_dirac_bands + j], sub( 31, hDirAC->buffer_energy_q[i * orig_dirac_bands + j] ), &energySum_e ); + energySum_fx = BASOP_Util_Add_Mant32Exp( energySum_fx, energySum_e, hDirAC->buffer_energy_fx[i * orig_dirac_bands + j], sub( 31, hDirAC->buffer_energy_q[i * orig_dirac_bands + j] ), &energySum_e ); /* exp(energySum_e) */ } Word16 x = getScaleFactor32( avg_dir_fx, 3 ); @@ -437,16 +447,16 @@ ivas_error ivas_dirac_enc_fx( move16(); Word16 denom_e = 0; move16(); - Word32 denom = BASOP_Util_Add_Mant32Exp( energySum_fx, energySum_e, EPSILON_FX_M, EPSILON_FX_E, &denom_e ); + Word32 denom = BASOP_Util_Add_Mant32Exp( energySum_fx, energySum_e, EPSILON_FX_M, EPSILON_FX_E, &denom_e ); /* exp(denom_e) */ - er_tmp = BASOP_Util_Divide3232_Scale( tmp, denom, &er_tmp_e ); + er_tmp = BASOP_Util_Divide3232_Scale( tmp, denom, &er_tmp_e ); /* exp(er_tmp_e) */ er_tmp_e = add( er_tmp_e, sub( tmp_e, denom_e ) ); er_tmp = shr( er_tmp, sub( 1, ( er_tmp_e ) ) ); // Q14 - hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[i] = L_deposit_h( er_tmp ); // Q30 - hQMetaData->q_direction[0].band_data[1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i]; - hQMetaData->q_direction[0].band_data[1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i]; - hQMetaData->q_direction[0].band_data[1].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio_fx[i]; + hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[i] = L_deposit_h( er_tmp ); // Q30 + hQMetaData->q_direction[0].band_data[1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i]; // Q22 + hQMetaData->q_direction[0].band_data[1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i]; // Q22 + hQMetaData->q_direction[0].band_data[1].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio_fx[i]; // Q30 move32(); move32(); move32(); @@ -465,19 +475,20 @@ ivas_error ivas_dirac_enc_fx( IF( EQ_16( dtx_vad, 1 ) ) { len = hQMetaData->q_direction[0].cfg.nblocks; + move16(); } ELSE { len = 1; + move16(); } - move16(); FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) { FOR( i_ts = 0; i_ts < len; i_ts++ ) { - hQMetaData->q_direction->band_data[b].azimuth_fx[i_ts] = hQMetaData->q_direction->band_data[b].q_azimuth_fx[i_ts]; - hQMetaData->q_direction->band_data[b].elevation_fx[i_ts] = hQMetaData->q_direction->band_data[b].q_elevation_fx[i_ts]; - hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]] ); + hQMetaData->q_direction->band_data[b].azimuth_fx[i_ts] = hQMetaData->q_direction->band_data[b].q_azimuth_fx[i_ts]; // Q22 + hQMetaData->q_direction->band_data[b].elevation_fx[i_ts] = hQMetaData->q_direction->band_data[b].q_elevation_fx[i_ts]; // Q22 + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]] ); // Q30 move32(); move32(); move32(); @@ -488,9 +499,9 @@ ivas_error ivas_dirac_enc_fx( { FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[1].azimuth_fx[0]; - hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[1].elevation_fx[0]; - hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio_fx[0]; + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[1].azimuth_fx[0]; // Q22 + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[1].elevation_fx[0]; // Q22 + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio_fx[0]; // Q30 move32(); move32(); move32(); @@ -500,16 +511,16 @@ ivas_error ivas_dirac_enc_fx( { FOR( j = sub( orig_dirac_bands, 2 ); j >= 0; j-- ) { - hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0]; - hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = hQMetaData->q_direction[0].band_data[0].elevation_fx[0]; - hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[0]; + hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0]; // Q22 + hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = hQMetaData->q_direction[0].band_data[0].elevation_fx[0]; // Q22 + hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[0]; // Q30 move32(); move32(); move32(); } } - hQMetaData->q_direction->cfg.nbands = orig_dirac_bands; + hQMetaData->q_direction->cfg.nbands = orig_dirac_bands; /* Q0 */ move16(); } } @@ -527,12 +538,12 @@ ivas_error ivas_dirac_enc_fx( *-------------------------------------------------------------------------*/ static Word16 ivas_dirac_get_mono_flag_fx( - const Word16 *band_grouping, /* i : Band grouping for estimation */ - Word32 Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal */ - Word32 Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal */ - Word16 e_Cldfb, /* i : Exponent of cldfb buffer */ - const Word16 nchan_ana, /* i : number of analysis channels */ - Word16 *mono_frame_count ) /* i/o: current number of mono frames count */ + const Word16 *band_grouping, /* i : Band grouping for estimation Q0*/ + Word32 Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal e_Cldfb*/ + Word32 Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal e_Cldfb*/ + Word16 e_Cldfb, /* i : Exponent of cldfb buffer */ + const Word16 nchan_ana, /* i : number of analysis channels Q0*/ + Word16 *mono_frame_count ) /* i/o: current number of mono frames count Q0*/ { Word16 brange[2]; Word16 i, j, ch_idx; @@ -560,8 +571,8 @@ static Word16 ivas_dirac_get_mono_flag_fx( move32(); move32(); - brange[0] = band_grouping[i]; - brange[1] = band_grouping[i + 1]; + brange[0] = band_grouping[i]; /* Q0 */ + brange[1] = band_grouping[i + 1]; /* Q0 */ move16(); move16(); @@ -577,10 +588,10 @@ static Word16 ivas_dirac_get_mono_flag_fx( /* Loop over the W channel bins to calculate the power in the band */ FOR( j = brange[0]; j < brange[1]; j++ ) { - acc = W_mac_32_32( acc, Cldfb_RealBuffer[0][j], Cldfb_RealBuffer[0][j] ); - acc = W_mac_32_32( acc, Cldfb_ImagBuffer[0][j], Cldfb_ImagBuffer[0][j] ); + acc = W_mac_32_32( acc, Cldfb_RealBuffer[0][j], Cldfb_RealBuffer[0][j] ); /* exp(2 * e_Cldfb) */ + acc = W_mac_32_32( acc, Cldfb_ImagBuffer[0][j], Cldfb_ImagBuffer[0][j] ); /* exp(2 * e_Cldfb) */ shift1 = W_norm( acc ); - W_band_power = W_extract_h( W_shl( acc, shift1 ) ); + W_band_power = W_extract_h( W_shl( acc, shift1 ) ); /* exp(2 * e_Cldfb - shift1) */ W_band_power_e = sub( imult1616( (Word16) 2, e_Cldfb ), shift1 ); } @@ -590,10 +601,10 @@ static Word16 ivas_dirac_get_mono_flag_fx( /* abs()^2 */ FOR( j = brange[0]; j < brange[1]; j++ ) { - acc1 = W_mac_32_32( acc1, Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ); - acc1 = W_mac_32_32( acc1, Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ); + acc1 = W_mac_32_32( acc1, Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ); /* exp(2 * e_Cldfb) */ + acc1 = W_mac_32_32( acc1, Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ); /* exp(2 * e_Cldfb) */ shift2 = W_norm( acc1 ); - other_ch_band_power = W_extract_h( W_shl( acc1, shift2 ) ); + other_ch_band_power = W_extract_h( W_shl( acc1, shift2 ) ); /* exp(2 * e_Cldfb - shift2) */ other_ch_band_power_e = sub( imult1616( (Word16) 2, e_Cldfb ), shift2 ); } } @@ -612,7 +623,7 @@ static Word16 ivas_dirac_get_mono_flag_fx( { Word16 tmp_div_e = 0; move16(); - Word16 tmp_div = BASOP_Util_Divide3232_Scale( W_band_power, DIRAC_MONO_NORM_FACTOR_M, &tmp_div_e ); + Word16 tmp_div = BASOP_Util_Divide3232_Scale( W_band_power, DIRAC_MONO_NORM_FACTOR_M, &tmp_div_e ); /* exp(tmp_div_e) */ tmp_div_e = add( tmp_div_e, sub( W_band_power_e, DIRAC_MONO_NORM_FACTOR_E ) ); Word16 W_band_power_norm_e = 0; move16(); @@ -687,7 +698,7 @@ static Word16 ivas_dirac_get_mono_flag_fx( { IF( LT_16( *mono_frame_count, DIRAC_MONO_FRAME_THRESH ) ) { - *mono_frame_count = add( *mono_frame_count, 1 ); + *mono_frame_count = add( *mono_frame_count, 1 ); /* Q0 */ move16(); } } @@ -720,18 +731,18 @@ static Word16 ivas_dirac_get_mono_flag_fx( void computeReferencePower_enc_fx_dirac( const Word16 *band_grouping, /* i : Band grouping for estimation */ - Word32 Cldfb_RealBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal */ - Word32 Cldfb_ImagBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal */ + Word32 Cldfb_RealBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal e_Cldfb*/ + Word32 Cldfb_ImagBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal e_Cldfb*/ Word16 e_Cldfb, /* i : exponent of Cldfb buffer */ - Word32 *reference_power, /* o : Estimated power */ + Word32 *reference_power, /* o : Estimated power e_reference*/ Word16 *e_reference, /* o : exponent of reference_power */ - const Word16 enc_param_start_band, /* i : first band to process */ - const Word16 num_freq_bands, /* i : Number of frequency bands */ + const Word16 enc_param_start_band, /* i : first band to process Q0*/ + const Word16 num_freq_bands, /* i : Number of frequency bands Q0*/ const IVAS_FORMAT ivas_format, /* i : ivas_format */ - Word16 ref_power_w, /* i : use 0 if hodirac is enabled */ - const Word16 nchan_ana, /* i : number of analysis channels */ - Word16 *mono_frame_count, /* i/o: Mono Frame Count */ - Word16 *dirac_mono_flag /* i/o: Mono Flag */ + Word16 ref_power_w, /* i : use 0 if hodirac is enabled Q0*/ + const Word16 nchan_ana, /* i : number of analysis channels Q0*/ + Word16 *mono_frame_count, /* i/o: Mono Frame Count Q0*/ + Word16 *dirac_mono_flag /* i/o: Mono Flag Q0*/ ) { Word16 brange[2]; @@ -745,7 +756,7 @@ void computeReferencePower_enc_fx_dirac( IF( dirac_mono_flag != NULL ) { - *dirac_mono_flag = ivas_dirac_get_mono_flag_fx( band_grouping, Cldfb_RealBuffer, Cldfb_ImagBuffer, e_Cldfb, nchan_ana, mono_frame_count ); + *dirac_mono_flag = ivas_dirac_get_mono_flag_fx( band_grouping, Cldfb_RealBuffer, Cldfb_ImagBuffer, e_Cldfb, nchan_ana, mono_frame_count ); /* Q0 */ move16(); } #ifdef FIX_1127_IMPROVE_SBA_MLD @@ -779,8 +790,8 @@ void computeReferencePower_enc_fx_dirac( FOR( j = brange[0]; j < brange[1]; j++ ) { #ifdef FIX_1127_IMPROVE_SBA_MLD - reference_power_W[i] = W_add( reference_power_W[i], W_shr( W_mult_32_32( Cldfb_RealBuffer[0][j], Cldfb_RealBuffer[0][j] ), gb ) ); - reference_power_W[i] = W_add( reference_power_W[i], W_shr( W_mult_32_32( Cldfb_ImagBuffer[0][j], Cldfb_ImagBuffer[0][j] ), gb ) ); + reference_power_W[i] = W_add( reference_power_W[i], W_shr( W_mult_32_32( Cldfb_RealBuffer[0][j], Cldfb_RealBuffer[0][j] ), gb ) ); /* exp(2 * e_Cldfb) */ + reference_power_W[i] = W_add( reference_power_W[i], W_shr( W_mult_32_32( Cldfb_ImagBuffer[0][j], Cldfb_ImagBuffer[0][j] ), gb ) ); /* exp(2 * e_Cldfb) */ #else reference_power_W[i] = W_mac_32_32( reference_power_W[i], Cldfb_RealBuffer[0][j], Cldfb_RealBuffer[0][j] ); reference_power_W[i] = W_mac_32_32( reference_power_W[i], Cldfb_ImagBuffer[0][j], Cldfb_ImagBuffer[0][j] ); @@ -789,7 +800,7 @@ void computeReferencePower_enc_fx_dirac( move64(); move64(); } - reference_power_temp[i] = W_add( reference_power_temp[i], reference_power_W[i] ); + reference_power_temp[i] = W_add( reference_power_temp[i], reference_power_W[i] ); /* exp(2 * e_Cldfb) */ move64(); FOR( ch_idx = 1; ch_idx < nchan_ana; ch_idx++ ) @@ -798,8 +809,8 @@ void computeReferencePower_enc_fx_dirac( FOR( j = brange[0]; j < brange[1]; j++ ) { #ifdef FIX_1127_IMPROVE_SBA_MLD - reference_power_temp[i] = W_add( reference_power_temp[i], W_shr( W_mult_32_32( Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ), gb ) ); - reference_power_temp[i] = W_add( reference_power_temp[i], W_shr( W_mult_32_32( Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ), gb ) ); + reference_power_temp[i] = W_add( reference_power_temp[i], W_shr( W_mult_32_32( Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ), gb ) ); /* exp(2 * e_Cldfb) */ + reference_power_temp[i] = W_add( reference_power_temp[i], W_shr( W_mult_32_32( Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ), gb ) ); /* exp(2 * e_Cldfb) */ #else reference_power_temp[i] = W_mac_32_32( reference_power_temp[i], Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ); reference_power_temp[i] = W_mac_32_32( reference_power_temp[i], Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ); @@ -813,7 +824,7 @@ void computeReferencePower_enc_fx_dirac( FOR( i = 0; i < num_freq_bands; i++ ) { - reference_power_temp[i] = W_shr( reference_power_temp[i], 1 ); + reference_power_temp[i] = W_shr( reference_power_temp[i], 1 ); /* exp(2 * e_Cldfb + 1) */ move64(); } @@ -824,7 +835,7 @@ void computeReferencePower_enc_fx_dirac( { IF( BASOP_Util_Cmp_Mant32Exp( W_extract_h( reference_power_temp[i] ), e_reference_temp, W_extract_h( reference_power_W[i] ), e_reference_W ) < 0 ) { - reference_power_temp[i] = reference_power_W[i]; + reference_power_temp[i] = reference_power_W[i]; /* exp(2 * e_Cldfb + 1 ) */ move64(); } } @@ -852,15 +863,15 @@ void computeReferencePower_enc_fx_dirac( } void computeReferencePower_enc_fx( - const Word16 *band_grouping, /* i : Band grouping for estimation */ - Word32 Cldfb_RealBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal */ - Word32 Cldfb_ImagBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal */ - Word32 *reference_power, /* o : Estimated power */ - const Word16 enc_param_start_band, /* i : first band to process */ - const Word16 num_freq_bands, /* i : Number of frequency bands */ + const Word16 *band_grouping, /* i : Band grouping for estimation Q0*/ + Word32 Cldfb_RealBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal inp_q*/ + Word32 Cldfb_ImagBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal inp_q*/ + Word32 *reference_power, /* o : Estimated power ref_exp*/ + const Word16 enc_param_start_band, /* i : first band to process Q0*/ + const Word16 num_freq_bands, /* i : Number of frequency bands Q0*/ const IVAS_FORMAT ivas_format, /* i : ivas_format */ - Word16 ref_power_w, /* i : use 0 if hodirac is enabled */ - const Word16 nchan_ana, /* i : number of analysis channels */ + Word16 ref_power_w, /* i : use 0 if hodirac is enabled Q0*/ + const Word16 nchan_ana, /* i : number of analysis channels Q0*/ Word16 inp_q, /* i : q of cld buffers */ Word16 *ref_exp /* i : output q */ ) @@ -874,9 +885,9 @@ void computeReferencePower_enc_fx( Word64 reference_power_W[DIRAC_MAX_NBANDS]; FOR( i = 0; i < num_freq_bands; i++ ) { - brange[0] = band_grouping[i + enc_param_start_band]; + brange[0] = band_grouping[i + enc_param_start_band]; /* Q0 */ move16(); - brange[1] = band_grouping[i + enc_param_start_band + 1]; + brange[1] = band_grouping[i + enc_param_start_band + 1]; /* Q0 */ move16(); reference_power[i] = 0; move32(); @@ -916,7 +927,7 @@ void computeReferencePower_enc_fx( { IF( LT_64( reference_power_tmp[i], reference_power_W[i] ) ) { - reference_power_tmp[i] = reference_power_W[i]; + reference_power_tmp[i] = reference_power_W[i]; // 2*inp_q + 1 move64(); } } @@ -946,17 +957,18 @@ void computeReferencePower_enc_fx( void ivas_dirac_param_est_enc_fx( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, - const UWord8 useLowerRes, - Word32 *data_f_fx[], - Word32 **pp_fr_real_fx, - Word32 **pp_fr_imag_fx, + const UWord8 useLowerRes, /* Q0 */ + Word32 *data_f_fx[], /* Qx */ + Word32 **pp_fr_real_fx, /* pp_fr_q */ + Word32 **pp_fr_imag_fx, /* pp_fr_q */ Word16 pp_fr_q, - const Word16 input_frame, + const Word16 input_frame, /* Q0 */ const IVAS_FORMAT ivas_format, - const Word16 hodirac_flag, - const Word16 nchan_fb_in, - Word16 *mono_frame_count, - Word16 *dirac_mono_flag ) + const Word16 hodirac_flag, /* Q0 */ + const Word16 nchan_fb_in, /* Q0 */ + Word16 *mono_frame_count, /* Q0 */ + Word16 *dirac_mono_flag /* Q0 */ +) { Word16 i, j, k, d, ts, index, l_ts, num_freq_bands; Word16 band_m_idx, block_m_idx; @@ -995,7 +1007,7 @@ void ivas_dirac_param_est_enc_fx( Word16 ene_secs_exp[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; push_wmops( "dirac_enc_param_est" ); - num_freq_bands = hDirAC->hConfig->nbands; + num_freq_bands = hDirAC->hConfig->nbands; /* Q0 */ move16(); /* Initialization */ @@ -1012,7 +1024,7 @@ void ivas_dirac_param_est_enc_fx( diffuseness_vector_q = 0; move16(); - l_ts = idiv1616( input_frame, MAX_PARAM_SPATIAL_SUBFRAMES ); + l_ts = idiv1616( input_frame, MAX_PARAM_SPATIAL_SUBFRAMES ); /* Q0 */ IF( useLowerRes ) { q_direction->cfg.nblocks = 1; @@ -1054,9 +1066,9 @@ void ivas_dirac_param_est_enc_fx( /* do processing over all CLDFB time slots */ FOR( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ ) { - mrange[0] = hDirAC->block_grouping[block_m_idx]; + mrange[0] = hDirAC->block_grouping[block_m_idx]; /* Q0 */ move16(); - mrange[1] = hDirAC->block_grouping[add( block_m_idx, 1 )]; + mrange[1] = hDirAC->block_grouping[block_m_idx + 1]; move16(); set32_fx( renormalization_factor_fx, EPSILON_FX, hDirAC->hConfig->nbands ); @@ -1085,8 +1097,8 @@ void ivas_dirac_param_est_enc_fx( { FOR( i = 0; i < nchan_fb_in; i++ ) { - Copy32( &pp_fr_real_fx[i][imult1616( ts, l_ts )], Cldfb_RealBuffer_fx[i], l_ts ); - Copy32( &pp_fr_imag_fx[i][imult1616( ts, l_ts )], Cldfb_ImagBuffer_fx[i], l_ts ); + Copy32( &pp_fr_real_fx[i][ts * l_ts], Cldfb_RealBuffer_fx[i], l_ts ); /* pp_fr_q */ + Copy32( &pp_fr_imag_fx[i][ts * l_ts], Cldfb_ImagBuffer_fx[i], l_ts ); /* pp_fr_q */ } cldfb_q = pp_fr_q; move16(); @@ -1094,7 +1106,7 @@ void ivas_dirac_param_est_enc_fx( Word16 ref_power_w = 1; move16(); - IF( hodirac_flag ) + if ( hodirac_flag ) { ref_power_w = 0; move16(); @@ -1156,22 +1168,21 @@ void ivas_dirac_param_est_enc_fx( } /* fill buffers of length "averaging_length" time slots for intensity and energy */ - hDirAC->index_buffer_intensity = add( ( hDirAC->index_buffer_intensity % hDirAC->no_col_avg_diff ), 1 ); /* averaging_length = 32 */ + hDirAC->index_buffer_intensity = add( ( hDirAC->index_buffer_intensity % hDirAC->no_col_avg_diff ), 1 ); /* averaging_length = 32 Q0*/ move16(); - index = hDirAC->index_buffer_intensity; + index = hDirAC->index_buffer_intensity; /* Q0 */ move16(); FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { /* only real part needed */ - Copy32( intensity_real_fx[i], &( hDirAC->buffer_intensity_real_fx[i][index - 1][0] ), num_freq_bands ); + Copy32( intensity_real_fx[i], &( hDirAC->buffer_intensity_real_fx[i][index - 1][0] ), num_freq_bands ); /* intensity_real_q */ #ifdef NONBE_IMPROVE_DIRAC_INTENSITY_PREC Copy( intensity_real_q, &hDirAC->buffer_intensity_real_q[i][index - 1][0], num_freq_bands ); #else - set16_fx( &hDirAC->buffer_intensity_real_q[i][index - 1][0], intensity_real_q, num_freq_bands ); #endif } - Copy32( reference_power_fx[ts], &( hDirAC->buffer_energy_fx[( index - 1 ) * num_freq_bands] ), num_freq_bands ); + Copy32( reference_power_fx[ts], &( hDirAC->buffer_energy_fx[( index - 1 ) * num_freq_bands] ), num_freq_bands ); /* exp(reference_power_exp) */ set16_fx( &hDirAC->buffer_energy_q[( index - 1 ) * num_freq_bands], sub( 31, reference_power_exp ), num_freq_bands ); Word16 buffer_intensity_real_single_q; @@ -1193,7 +1204,7 @@ void ivas_dirac_param_est_enc_fx( { FOR( k = 0; k < num_freq_bands; k++ ) { - hDirAC->buffer_intensity_real_fx[i][j][k] = L_shl( hDirAC->buffer_intensity_real_fx[i][j][k], sub( buffer_intensity_real_single_q, hDirAC->buffer_intensity_real_q[i][j][k] ) ); + hDirAC->buffer_intensity_real_fx[i][j][k] = L_shl( hDirAC->buffer_intensity_real_fx[i][j][k], sub( buffer_intensity_real_single_q, hDirAC->buffer_intensity_real_q[i][j][k] ) ); /* buffer_intensity_real_single_q */ move32(); hDirAC->buffer_intensity_real_q[i][j][k] = buffer_intensity_real_single_q; move16(); @@ -1207,7 +1218,7 @@ void ivas_dirac_param_est_enc_fx( minimum_fx( hDirAC->buffer_energy_q, buffer_len, &buffer_energy_single_q ); FOR( i = 0; i < buffer_len; i++ ) { - hDirAC->buffer_energy_fx[i] = L_shl( hDirAC->buffer_energy_fx[i], sub( buffer_energy_single_q, hDirAC->buffer_energy_q[i] ) ); + hDirAC->buffer_energy_fx[i] = L_shl( hDirAC->buffer_energy_fx[i], sub( buffer_energy_single_q, hDirAC->buffer_energy_q[i] ) ); /* buffer_energy_single_q */ move32(); hDirAC->buffer_energy_q[i] = buffer_energy_single_q; move16(); @@ -1248,9 +1259,9 @@ void ivas_dirac_param_est_enc_fx( { Word32 tmp_diff = L_shr( diffuseness_vector_fx[band_m_idx], sub( diffuseness_vector_q, 30 ) ); // diffueseness_vector_q -> Q30 hDirAC->diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx], - Mpy_32_32( reference_power_fx[ts][band_m_idx], tmp_diff ), add( reference_power_exp, 1 ), &hDirAC->diffuseness_m_exp[band_m_idx] ); + Mpy_32_32( reference_power_fx[ts][band_m_idx], tmp_diff ), add( reference_power_exp, 1 ), &hDirAC->diffuseness_m_exp[band_m_idx] ); /* exp(hDirAC->diffuseness_m_exp) */ move32(); - renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_exp[band_m_idx], reference_power_fx[ts][band_m_idx], reference_power_exp, &renormalization_factor_diff_exp[band_m_idx] ); + renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_exp[band_m_idx], reference_power_fx[ts][band_m_idx], reference_power_exp, &renormalization_factor_diff_exp[band_m_idx] ); /* exp(renormalization_factor_diff_exp) */ move32(); } } @@ -1261,19 +1272,19 @@ void ivas_dirac_param_est_enc_fx( Word32 tmp_diff = L_shr( diffuseness_vector_fx[band_m_idx], sub( diffuseness_vector_q, 30 ) ); // diffueseness_vector_q -> Q30 norm_tmp_fx = Mpy_32_32( reference_power_fx[ts][band_m_idx], L_sub( ONE_IN_Q30, tmp_diff ) ); - hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ), gbits ) ); + hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ), gbits ) ); /* norm_tmp_exp + ( 31 - direction_vector_q ) + gbits */ move32(); - hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ), gbits ) ); + hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ), gbits ) ); /* norm_tmp_exp + ( 31 - direction_vector_q ) + gbits */ move32(); - hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ), gbits ) ); + hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ), gbits ) ); /* norm_tmp_exp + ( 31 - direction_vector_q ) + gbits */ move32(); - renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], L_shr( norm_tmp_fx, gbits ) ); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], L_shr( norm_tmp_fx, gbits ) ); /* exp(norm_tmp_exp + gbits) */ move32(); hDirAC->diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx], - Mpy_32_32( reference_power_fx[ts][band_m_idx], tmp_diff ), add( reference_power_exp, 1 ), &hDirAC->diffuseness_m_exp[band_m_idx] ); + Mpy_32_32( reference_power_fx[ts][band_m_idx], tmp_diff ), add( reference_power_exp, 1 ), &hDirAC->diffuseness_m_exp[band_m_idx] ); /* exp(hDirAC->diffuseness_m_exp) */ move32(); renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_exp[band_m_idx], - reference_power_fx[ts][band_m_idx], reference_power_exp, &renormalization_factor_diff_exp[band_m_idx] ); + reference_power_fx[ts][band_m_idx], reference_power_exp, &renormalization_factor_diff_exp[band_m_idx] ); /* exp(renormalization_factor_diff_exp) */ move32(); } norm_tmp_exp = add( reference_power_exp, 1 ); @@ -1289,11 +1300,11 @@ void ivas_dirac_param_est_enc_fx( { renormalization_factor_fx[band_m_idx] = EPSILON_FX; move32(); - renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] ) ); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] ) ); /* norm_tmp_exp + ( 31 - direction_vector_q ) + gbits */ move32(); - renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] ) ); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] ) ); /* norm_tmp_exp + ( 31 - direction_vector_q ) + gbits */ move32(); - renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] ) ); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] ) ); /* norm_tmp_exp + ( 31 - direction_vector_q ) + gbits */ move32(); renormalization_factor_exp = shl( hDirAC->direction_vector_m_exp[block_m_idx], 1 ); // 2 * direction_vector_m_exp renormalization_factor_fx[band_m_idx] = Sqrt32( renormalization_factor_fx[band_m_idx], &renormalization_factor_exp ); @@ -1306,21 +1317,21 @@ void ivas_dirac_param_est_enc_fx( tmp32 = hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx]; move32(); - tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); /* exp(tmp_e + ( hDirAC->direction_vector_m_exp[block_m_idx] - renormalization_factor_exp)) */ tmp_e = add( tmp_e, sub( hDirAC->direction_vector_m_exp[block_m_idx], renormalization_factor_exp ) ); hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_shr( tmp32, sub( 1, tmp_e ) ); // Q30 move32(); - tmp32 = hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx]; + tmp32 = hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx]; // Q30 move32(); - tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); /* exp(tmp_e + ( hDirAC->direction_vector_m_exp[block_m_idx] - renormalization_factor_exp)) */ tmp_e = add( tmp_e, sub( hDirAC->direction_vector_m_exp[block_m_idx], renormalization_factor_exp ) ); hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_shr( tmp32, sub( 1, tmp_e ) ); // Q30 move32(); - tmp32 = hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx]; + tmp32 = hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx]; // Q30 move32(); - tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); /* exp(tmp_e + ( hDirAC->direction_vector_m_exp[block_m_idx] - renormalization_factor_exp)) */ tmp_e = add( tmp_e, sub( hDirAC->direction_vector_m_exp[block_m_idx], renormalization_factor_exp ) ); hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_shr( tmp32, sub( 1, tmp_e ) ); // Q30 move32(); @@ -1375,9 +1386,9 @@ void ivas_dirac_param_est_enc_fx( q_direction[1].band_data[band_m_idx].elevation_fx[block_m_idx] = L_shr( ele_secs_fx[num_freq_bands + band_m_idx], 1 ); // Q23 -> Q22 move32(); - L_tmp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, Q1, L_negate( diff_secs_fx[band_m_idx] ), diff_secs_exp[band_m_idx], &e_tmp ); - L_tmp1 = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, Q1, L_negate( diff_secs_fx[num_freq_bands + band_m_idx] ), diff_secs_exp[num_freq_bands + band_m_idx], &e_tmp1 ); - L_tmp1 = BASOP_Util_Add_Mant32Exp( L_tmp, e_tmp, L_tmp1, e_tmp1, &e_tmp1 ); + L_tmp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, Q1, L_negate( diff_secs_fx[band_m_idx] ), diff_secs_exp[band_m_idx], &e_tmp ); /* exp(e_tmp) */ + L_tmp1 = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, Q1, L_negate( diff_secs_fx[num_freq_bands + band_m_idx] ), diff_secs_exp[num_freq_bands + band_m_idx], &e_tmp1 ); /* exp(e_tmp1) */ + L_tmp1 = BASOP_Util_Add_Mant32Exp( L_tmp, e_tmp, L_tmp1, e_tmp1, &e_tmp1 ); /* exp(e_tmp1) */ IF( L_tmp1 == 0 ) { q_direction[1].band_data[band_m_idx].energy_ratio_fx[block_m_idx] = L_shl( div_l( L_tmp, EPSILON_FX ), Q30 - Q15 ); // Q30 @@ -1385,7 +1396,7 @@ void ivas_dirac_param_est_enc_fx( } ELSE { - L_tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( L_tmp, L_add( L_tmp1, EPSILON_FX ), &exp_diff ) ); + L_tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( L_tmp, L_add( L_tmp1, EPSILON_FX ), &exp_diff ) ); /* exp(exp_diff) */ exp_diff = add( exp_diff, sub( e_tmp, e_tmp1 ) ); q_direction[1].band_data[band_m_idx].energy_ratio_fx[block_m_idx] = L_shl( L_tmp, sub( exp_diff, Q1 ) ); // Q30 move32(); @@ -1400,7 +1411,7 @@ void ivas_dirac_param_est_enc_fx( IF( GT_32( renormalization_factor_diff_fx[band_m_idx], EPSILON_FX ) ) { Word16 tmp_e; - hDirAC->diffuseness_m_fx[band_m_idx] = L_deposit_h( BASOP_Util_Divide3232_Scale( hDirAC->diffuseness_m_fx[band_m_idx], renormalization_factor_diff_fx[band_m_idx], &tmp_e ) ); + hDirAC->diffuseness_m_fx[band_m_idx] = L_deposit_h( BASOP_Util_Divide3232_Scale( hDirAC->diffuseness_m_fx[band_m_idx], renormalization_factor_diff_fx[band_m_idx], &tmp_e ) ); /* exp(tmp_e) */ move32(); tmp_e = add( tmp_e, sub( hDirAC->diffuseness_m_exp[band_m_idx], renormalization_factor_diff_exp[band_m_idx] ) ); hDirAC->diffuseness_m_fx[band_m_idx] = L_shr( hDirAC->diffuseness_m_fx[band_m_idx], sub( 1, tmp_e ) ); // to Q30 @@ -1440,11 +1451,11 @@ void ivas_dirac_param_est_enc_fx( *------------------------------------------------------------------------*/ static void computeIntensityVector_enc_fx( const DIRAC_ENC_HANDLE hDirAC, - Word32 Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], - Word32 Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], - const Word16 enc_param_start_band, /* i : first band to process */ - const Word16 num_frequency_bands, - Word32 intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS] + Word32 Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* q_cldfb */ + Word32 Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* q_cldfb */ + const Word16 enc_param_start_band, /* i : first band to process Q0*/ + const Word16 num_frequency_bands, /* Q0 */ + Word32 intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS] /* q_intensity_real */ #ifdef NONBE_IMPROVE_DIRAC_INTENSITY_PREC , Word16 q_cldfb, @@ -1464,9 +1475,9 @@ static void computeIntensityVector_enc_fx( #endif FOR( i = 0; i < num_frequency_bands; i++ ) { - brange[0] = hDirAC->band_grouping[i + enc_param_start_band]; + brange[0] = hDirAC->band_grouping[i + enc_param_start_band]; /* Q0 */ move16(); - brange[1] = hDirAC->band_grouping[i + enc_param_start_band + 1]; + brange[1] = hDirAC->band_grouping[i + enc_param_start_band + 1]; /* Q0 */ move16(); #ifdef NONBE_IMPROVE_DIRAC_INTENSITY_PREC Word16 num_bins = sub( brange[1], brange[0] ); @@ -1493,16 +1504,16 @@ static void computeIntensityVector_enc_fx( move32(); #ifdef NONBE_IMPROVE_DIRAC_INTENSITY_PREC Word64 t1, t2, t3; - t1 = W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[3][j], real ), Cldfb_ImagBuffer[3][j], img ); - t2 = W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[1][j], real ), Cldfb_ImagBuffer[1][j], img ); - t3 = W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[2][j], real ), Cldfb_ImagBuffer[2][j], img ); + t1 = W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[3][j], real ), Cldfb_ImagBuffer[3][j], img ); /* 2 * q_cldfb + 1 */ + t2 = W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[1][j], real ), Cldfb_ImagBuffer[1][j], img ); /* 2 * q_cldfb + 1 */ + t3 = W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[2][j], real ), Cldfb_ImagBuffer[2][j], img ); /* 2 * q_cldfb + 1 */ t1 = W_shr( t1, gb ); t2 = W_shr( t2, gb ); t3 = W_shr( t3, gb ); /* Intensity is XYZ order, audio is WYZX order. */ - tmp_1 = W_add( tmp_1, t1 ); - tmp_2 = W_add( tmp_2, t2 ); - tmp_3 = W_add( tmp_3, t3 ); + tmp_1 = W_add( tmp_1, t1 ); /* 2 * q_cldfb + 1 */ + tmp_2 = W_add( tmp_2, t2 ); /* 2 * q_cldfb + 1 */ + tmp_3 = W_add( tmp_3, t3 ); /* 2 * q_cldfb + 1 */ #else /* Intensity is XYZ order, audio is WYZX order. */ tmp_1 = W_add( tmp_1, W_add( W_mult_32_32( Cldfb_RealBuffer[3][j], real ), W_mult_32_32( Cldfb_ImagBuffer[3][j], img ) ) ); @@ -1513,12 +1524,11 @@ static void computeIntensityVector_enc_fx( #ifdef NONBE_IMPROVE_DIRAC_INTENSITY_PREC norm = s_min( W_norm( tmp_1 ), W_norm( tmp_2 ) ); norm = s_min( norm, W_norm( tmp_3 ) ); - intensity_real[0][i] = W_extract_h( W_shl( tmp_1, norm ) ); // output Q= 2* input_q + 1-gb+norm - 32 - move32(); - intensity_real[1][i] = W_extract_h( W_shl( tmp_2, norm ) ); // output Q= 2* input_q + 1-gb+norm - 32 + intensity_real[0][i] = W_extract_h( W_shl( tmp_1, norm ) ); // shift_value - (gb - norm) move32(); - intensity_real[2][i] = W_extract_h( W_shl( tmp_3, norm ) ); // output Q= 2* input_q + 1-gb+norm - 32 + intensity_real[1][i] = W_extract_h( W_shl( tmp_2, norm ) ); // shift_value - (gb - norm) move32(); + intensity_real[2][i] = W_extract_h( W_shl( tmp_3, norm ) ); // shift_value - (gb - norm) q_intensity_real[i] = sub( shift_value, sub( gb, norm ) ); move16(); #else @@ -1541,11 +1551,11 @@ static void computeIntensityVector_enc_fx( * *------------------------------------------------------------------------*/ void computeDiffuseness_mdft_fx( - Word32 **buffer_intensity[DIRAC_NUM_DIMS], - const Word32 *buffer_energy, - const Word16 num_freq_bands, - const UWord16 no_col_avg_diff, - Word32 *diffuseness, + Word32 **buffer_intensity[DIRAC_NUM_DIMS], /* q_factor_intensity */ + const Word32 *buffer_energy, /* q_factor_energy */ + const Word16 num_freq_bands, /* Q0 */ + const UWord16 no_col_avg_diff, /* Q0 */ + Word32 *diffuseness, /* q_diffuseness */ Word16 *q_factor_intensity, Word16 *q_factor_energy, Word16 *q_diffuseness /*Ouput Q*/ @@ -1581,7 +1591,7 @@ void computeDiffuseness_mdft_fx( FOR( k = 0; k < num_freq_bands; k++ ) { - energy_slow[k] = BASOP_Util_Add_Mant32Exp( energy_slow[k], energy_slow_e[k], p_tmp_c[k], sub( 31, tmp_q ), &energy_slow_e[k] ); + energy_slow[k] = BASOP_Util_Add_Mant32Exp( energy_slow[k], energy_slow_e[k], p_tmp_c[k], sub( 31, tmp_q ), &energy_slow_e[k] ); /* exp(energy_slow_e)*/ move32(); } @@ -1591,7 +1601,7 @@ void computeDiffuseness_mdft_fx( p_tmp = buffer_intensity[j][i]; FOR( k = 0; k < num_freq_bands; k++ ) { - intensity_slow[j * num_freq_bands + k] = BASOP_Util_Add_Mant32Exp( intensity_slow[j * num_freq_bands + k], intensity_slow_e[j * num_freq_bands + k], p_tmp[k], sub( 31, q_factor_intensity[i] ), &intensity_slow_e[j * num_freq_bands + k] ); + intensity_slow[j * num_freq_bands + k] = BASOP_Util_Add_Mant32Exp( intensity_slow[j * num_freq_bands + k], intensity_slow_e[j * num_freq_bands + k], p_tmp[k], sub( 31, q_factor_intensity[i] ), &intensity_slow_e[j * num_freq_bands + k] ); /* exp(intensity_slow_e) */ move32(); } } @@ -1605,10 +1615,10 @@ void computeDiffuseness_mdft_fx( FOR( k = 0; k < num_freq_bands; k++ ) { - p_tmp[k] = Mpy_32_32( p_tmp[k], p_tmp[k] ); + p_tmp[k] = Mpy_32_32( p_tmp[k], p_tmp[k] ); /* 2 * (31-p_tmp_e) - 31 */ move32(); tmp_q = sub( shl( sub( 31, p_tmp_e[k] ), 1 ), 31 ); - intensity_slow_abs[k] = BASOP_Util_Add_Mant32Exp( intensity_slow_abs[k], intensity_slow_abs_e[k], p_tmp[k], sub( 31, tmp_q ), &intensity_slow_abs_e[k] ); + intensity_slow_abs[k] = BASOP_Util_Add_Mant32Exp( intensity_slow_abs[k], intensity_slow_abs_e[k], p_tmp[k], sub( 31, tmp_q ), &intensity_slow_abs_e[k] ); /* exp(intensity_slow_abs_e) */ move32(); } } @@ -1621,7 +1631,7 @@ void computeDiffuseness_mdft_fx( { tmp = Sqrt32( p_tmp[i], &intensity_slow_abs_e[i] ); - tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp, L_add( energy_slow[i], EPSILLON_FX ), &tmp_q ) ); + tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp, L_add( energy_slow[i], EPSILLON_FX ), &tmp_q ) ); /* exp(tmp_q) */ tmp_q = add( tmp_q, sub( intensity_slow_abs_e[i], energy_slow_e[i] ) ); tmp = L_shl_sat( tmp, tmp_q ); tmp = L_sub( ONE_IN_Q31, tmp ); diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index e7c693329c743eb8615ed833e1d4bcba14f4e619..95cafd8ff37212c36822565bdd641c9296d56731 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -52,9 +52,9 @@ * Principal IVAS encoder routine *-------------------------------------------------------------------*/ ivas_error ivas_enc_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 *data, /* i : input signal Q0 */ - const Word16 n_samples /* i : number of input samples */ + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 *data, /* i : input signal Q0*/ + const Word16 n_samples /* i : number of input samples Q0*/ ) { Word16 i, n, input_frame, n_samples_chan, nchan_inp /*, scale*/; @@ -77,10 +77,10 @@ ivas_error ivas_enc_fx( hEncoderConfig = st_ivas->hEncoderConfig; - input_Fs = hEncoderConfig->input_Fs; + input_Fs = hEncoderConfig->input_Fs; /* Q0 */ ivas_format = hEncoderConfig->ivas_format; - nchan_inp = hEncoderConfig->nchan_inp; - ivas_total_brate = hEncoderConfig->ivas_total_brate; + nchan_inp = hEncoderConfig->nchan_inp; /* Q0 */ + ivas_total_brate = hEncoderConfig->ivas_total_brate; /* Q0 */ move32(); move32(); move16(); @@ -89,12 +89,12 @@ ivas_error ivas_enc_fx( input_frame = extract_l( Mpy_32_16_1( input_Fs, INV_FRAME_PER_SEC_Q15 ) ); IF( NE_16( nchan_inp, 1 ) ) { - n_samples_chan = div_l( L_deposit_l( n_samples ), nchan_inp ); - n_samples_chan = shl( n_samples_chan, 1 ); + n_samples_chan = div_l( L_deposit_l( n_samples ), nchan_inp ); /* Q0 */ + n_samples_chan = shl( n_samples_chan, 1 ); /* Q0 */ } ELSE { - n_samples_chan = n_samples; + n_samples_chan = n_samples; /* Q0 */ move16(); } set16_fx( nb_bits_metadata, 0, MAX_SCE + 1 ); @@ -108,7 +108,7 @@ ivas_error ivas_enc_fx( data_fx[n] = st_ivas->p_data_fx[n]; IF( data_fx[n] ) { - Scale_sig32( data_fx[n], input_frame, sub( Q11, st_ivas->q_data_fx ) ); + Scale_sig32( data_fx[n], input_frame, sub( Q11, st_ivas->q_data_fx ) ); // Q11 } } st_ivas->q_data_fx = Q11; @@ -122,7 +122,7 @@ ivas_error ivas_enc_fx( data_fx[n][i] = L_mult0( data[i * nchan_inp + n], shl( 1, st_ivas->q_data_fx ) ); move32(); } - n++; + n = add( n, 1 ); } IF( LT_16( n_samples_chan, input_frame ) ) @@ -135,14 +135,14 @@ ivas_error ivas_enc_fx( IF( EQ_32( ivas_format, SBA_FORMAT ) ) { - IF( NE_32( ( error = ivas_sba_enc_reconfigure( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_sba_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { - IF( NE_32( ( error = ivas_osba_enc_reconfig( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_osba_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -180,9 +180,9 @@ ivas_error ivas_enc_fx( test(); IF( EQ_32( ivas_format, STEREO_FORMAT ) ) { - st_ivas->hCPE[0]->element_brate = ivas_total_brate; + st_ivas->hCPE[0]->element_brate = ivas_total_brate; /* Q0 */ move32(); - IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, 0 /* no metadata */, NULL ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, 0 /* no metadata */, NULL ) ) != IVAS_ERR_OK ) { return error; } @@ -190,7 +190,7 @@ ivas_error ivas_enc_fx( ELSE IF( EQ_32( ivas_format, ISM_FORMAT ) ) { /* select ISM format mode; reconfigure the ISM format encoder */ - IF( NE_32( ( error = ivas_ism_enc_config( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_ism_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -203,7 +203,7 @@ ivas_error ivas_enc_fx( ivas_param_ism_stereo_dmx_fx( st_ivas, data_fx, input_frame ); /* Core coding of Stereo DMX */ - IF( NE_32( ( error = ivas_ism_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata, 0 ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_ism_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -211,7 +211,7 @@ ivas_error ivas_enc_fx( ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) ) { /* Analysis, decision about bitrates per channel & core coding */ - IF( NE_32( ( error = ivas_ism_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata, 0 ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_ism_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -241,25 +241,25 @@ ivas_error ivas_enc_fx( { ivas_masa_estimate_energy_fx( st_ivas->hMasa, data_fx, input_frame, st_ivas->nchan_transport, st_ivas->q_data_fx ); /* energy-estimation uses TF-resolution: 4x24 */ - IF( NE_32( ( error = ivas_masa_enc_config_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_masa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } IF( EQ_16( st_ivas->nchan_transport, 2 ) ) { - IF( NE_32( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->hCPE[0]->element_mode, - ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ), - IVAS_ERR_OK ) ) + IF( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->hCPE[0]->element_mode, + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != + IVAS_ERR_OK ) { return error; } } ELSE { - IF( NE_32( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, -1, - ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ), - IVAS_ERR_OK ) ) + IF( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, -1, + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != + IVAS_ERR_OK ) { return error; } @@ -267,7 +267,7 @@ ivas_error ivas_enc_fx( } ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) ) { - IF( NE_32( ( error = ivas_spar_enc_fx( st_ivas, data_fx, input_frame, nb_bits_metadata, hMetaData ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_spar_enc_fx( st_ivas, data_fx, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) { return error; } @@ -281,21 +281,21 @@ ivas_error ivas_enc_fx( /* core-coding of transport channels */ IF( EQ_16( st_ivas->nSCE, 1 ) ) { - IF( NE_32( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[0], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[0], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0], NULL ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0], NULL ) ) != IVAS_ERR_OK ) { return error; } } ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) /* FOA/HOA format */ { - IF( NE_32( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } @@ -316,18 +316,18 @@ ivas_error ivas_enc_fx( IF( EQ_16( sub( st_ivas->hEncoderConfig->nchan_inp, hEncoderConfig->nchan_ism ), 1 ) ) { v_multc_fixed( data_fx[hEncoderConfig->nchan_ism], L_deposit_h( INV_SQRT2_FX_Q15 ) /* Q31 */, data_fx[hEncoderConfig->nchan_ism], input_frame ); - Copy32( data_fx[hEncoderConfig->nchan_ism], data_fx[hEncoderConfig->nchan_ism + 1], input_frame ); + Copy32( data_fx[hEncoderConfig->nchan_ism], data_fx[hEncoderConfig->nchan_ism + 1], input_frame ); /* st_ivas->q_data_fx */ } /* Estimate TF-tile energy for the input MASA stream */ ivas_masa_estimate_energy_fx( st_ivas->hMasa, &( data_fx[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport, st_ivas->q_data_fx ); - IF( NE_32( ( error = ivas_omasa_enc_config_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_omasa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); + set16_fx( nb_bits_metadata, 0, MAX_SCE + 1 ); idx_separated_object = 0; move16(); @@ -341,6 +341,7 @@ ivas_error ivas_enc_fx( /* Scaling data_fx */ { Word16 norm_data_in = MAX16B; + move16(); FOR( i = 0; i < hEncoderConfig->nchan_ism + st_ivas->nchan_transport; i++ ) { norm_data_in = s_min( norm_data_in, L_norm_arr( data_fx[i], input_frame ) ); @@ -348,7 +349,7 @@ ivas_error ivas_enc_fx( norm_data_in = sub( norm_data_in, 7 ); /*guard bit is 4->to handle overflow in cldfbAnalysis*/ FOR( i = 0; i < hEncoderConfig->nchan_ism + st_ivas->nchan_transport; i++ ) { - scale_sig32( data_fx[i], input_frame, norm_data_in ); + scale_sig32( data_fx[i], input_frame, norm_data_in ); /* st_ivas->q_data_fx + norm_data_in */ } st_ivas->q_data_fx = add( st_ivas->q_data_fx, norm_data_in ); move16(); @@ -380,14 +381,14 @@ ivas_error ivas_enc_fx( } ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - flag_omasa_ener_brate = ivas_omasa_ener_brate_fx( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_fx, input_frame, sub( 31, st_ivas->q_data_fx ) ); + flag_omasa_ener_brate = ivas_omasa_ener_brate_fx( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_fx, input_frame, sub( 31, st_ivas->q_data_fx ) ); /* Q0 */ /* Analysis, decision about bitrates per channel & core coding */ IF( NE_32( ( error = ivas_ism_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ), IVAS_ERR_OK ) ) { return error; } - n = st_ivas->hEncoderConfig->nchan_ism; + n = st_ivas->hEncoderConfig->nchan_ism; /* Q0 */ move16(); } @@ -401,7 +402,19 @@ ivas_error ivas_enc_fx( } /* Encode MASA parameters and write MASA metadata bitstream */ - IF( NE_32( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, + Word16 element_mode; + if ( st_ivas->nchan_transport == 2 ) + { + element_mode = st_ivas->hCPE[0]->element_mode; + move16(); + } + else + { + element_mode = -1; + move16(); + } + + IF( NE_32( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, element_mode, st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp, flag_omasa_ener_brate ) ), IVAS_ERR_OK ) ) { @@ -433,11 +446,11 @@ ivas_error ivas_enc_fx( IF( st_ivas->ism_mode == ISM_MODE_NONE ) { - nchan = imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ); + nchan = imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ); /* Q0 */ } ELSE { - nchan = hEncoderConfig->nchan_ism; + nchan = hEncoderConfig->nchan_ism; /* Q0 */ move16(); } FOR( n = 0; n < nchan; n++ ) @@ -462,27 +475,27 @@ ivas_error ivas_enc_fx( } /* SBA metadata encoding and SBA metadata bitstream writing */ - IF( NE_32( ( error = ivas_spar_enc_fx( st_ivas, data_fx, input_frame, nb_bits_metadata, hMetaData ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_spar_enc_fx( st_ivas, data_fx, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) { return error; } - hEncoderConfig->sba_planar = planar_sba_orig; + hEncoderConfig->sba_planar = planar_sba_orig; /* Q0 */ move16(); } ELSE { - n = hEncoderConfig->nchan_ism; + n = hEncoderConfig->nchan_ism; /* Q0 */ move16(); hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; - 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 ) ) + IF( ( 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; } /* SBA metadata encoding and SBA metadata bitstream writing */ - IF( NE_32( ( error = ivas_spar_enc_fx( st_ivas, &data_fx[n], input_frame, nb_bits_metadata, hMetaData ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_spar_enc_fx( st_ivas, &data_fx[n], input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) { return error; } @@ -494,21 +507,21 @@ ivas_error ivas_enc_fx( /* core-coding of transport channels */ IF( EQ_16( st_ivas->nSCE, 1 ) ) { - IF( NE_32( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[0], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[0], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0], NULL ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0], NULL ) ) != IVAS_ERR_OK ) { return error; } } ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) /* FOA/HOA format */ { - IF( NE_32( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } @@ -517,7 +530,7 @@ ivas_error ivas_enc_fx( ELSE IF( EQ_32( ivas_format, MC_FORMAT ) ) { /* select MC format mode; write MC LS setup; reconfigure the MC format encoder */ - IF( NE_32( ( error = ivas_mc_enc_config_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_mc_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -574,7 +587,7 @@ ivas_error ivas_enc_fx( ivas_lfe_enc_fx( st_ivas->hLFE, data_fx[LFE_CHANNEL], st_ivas->q_data_fx, input_frame, st_ivas->hLFE->hBstr ); - IF( NE_32( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } @@ -586,14 +599,14 @@ ivas_error ivas_enc_fx( IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot, NULL ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot, NULL ) ) != IVAS_ERR_OK ) { return error; } } ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) { - IF( NE_32( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } @@ -628,23 +641,23 @@ ivas_error ivas_enc_fx( scale_sig32( st_ivas->hQMetaData->q_direction[0].band_data[i].energy_ratio_fx, MAX_PARAM_SPATIAL_SUBFRAMES, -1 ); // Q31 -> Q30 } - IF( NE_32( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1, - ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ), - IVAS_ERR_OK ) ) + IF( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1, + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != + IVAS_ERR_OK ) { return error; } IF( st_ivas->hMcMasa->separateChannelEnabled ) { - IF( NE_32( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[2], st_ivas->q_data_fx, input_frame, 0 ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[2], st_ivas->q_data_fx, input_frame, 0 ) ) != IVAS_ERR_OK ) { return error; } st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot; - IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot, NULL ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot, NULL ) ) != IVAS_ERR_OK ) { return error; } @@ -653,14 +666,14 @@ ivas_error ivas_enc_fx( { IF( EQ_16( st_ivas->nSCE, 1 ) ) { - IF( NE_32( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[0], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[0], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } } ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot, NULL ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot, NULL ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_enc_cov_handler.c b/lib_enc/ivas_enc_cov_handler.c index cf42f8cc89beccfe7ef532296592e76bac70d6ae..7f08778781cb9a3d5d14867f087b6751b8aaa312 100644 --- a/lib_enc/ivas_enc_cov_handler.c +++ b/lib_enc/ivas_enc_cov_handler.c @@ -62,12 +62,12 @@ static void ivas_band_cov_fx( Word32 **ppIn_FR_real, Word32 **ppIn_FR_imag, Word *------------------------------------------------------------------------*/ ivas_error ivas_spar_covar_enc_open_fx( - ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ - ivas_filterbank_t *pFb, /* i/o: FB handle */ - const Word32 input_Fs, /* i : input sampling rate */ - const Word16 nchan_inp, /* i : number of input channels */ - const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC*/ - const Word32 ivas_total_brate /* i : IVAS total bitrate */ + ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ + ivas_filterbank_t *pFb, /* i/o: FB handle */ + const Word32 input_Fs, /* i : input sampling rate Q0*/ + const Word16 nchan_inp, /* i : number of input channels Q0*/ + const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC */ + const Word32 ivas_total_brate /* i : IVAS total bitrate Q0*/ ) { ivas_enc_cov_handler_state_t *hCovState; @@ -92,7 +92,7 @@ ivas_error ivas_spar_covar_enc_open_fx( { cov_smooth_cfg.max_update_rate_fx = ONE_IN_Q31; // Q31 move32(); - cov_smooth_cfg.min_pool_size = 20; + cov_smooth_cfg.min_pool_size = 20; // Q0 move16(); } @@ -111,7 +111,7 @@ ivas_error ivas_spar_covar_enc_open_fx( return error; } - hCovState->num_bins = extract_l( Mpy_32_32( input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + hCovState->num_bins = extract_l( Mpy_32_32( input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /* Q0 */ hCovState->prior_dtx_present = 0; move16(); @@ -133,7 +133,7 @@ ivas_error ivas_spar_covar_enc_open_fx( void ivas_spar_covar_enc_close_fx( ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ - const Word16 nchan_inp /* i : number of input channels */ + const Word16 nchan_inp /* i : number of input channels Q0*/ ) { ivas_enc_cov_handler_state_t *hCovState; @@ -165,14 +165,15 @@ void ivas_spar_covar_enc_close_fx( static Word16 ivas_spar_get_activeW_flag_fx( ivas_enc_cov_handler_state_t *hCovEnc, - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /* q_cov_real */ + Word32 *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /* q_cov_real */ Word16 *q_cov_real[IVAS_SPAR_MAX_CH], - const Word16 dtx_vad, - const Word16 nchan_inp, - const Word16 nchan_transport, - Word16 *res_ind, - const Word16 *dmx_order ) + const Word16 dtx_vad, /* Q0 */ + const Word16 nchan_inp, /* Q0 */ + const Word16 nchan_transport, /* Q0 */ + Word16 *res_ind, /* Q0 */ + const Word16 *dmx_order /* Q0 */ +) { Word16 b, ch, num_bands, num_chs, activeW_flag; Word32 bb_var[FOA_CHANNELS], sm_fact, side_ch_var, en_ratio; @@ -182,8 +183,8 @@ static Word16 ivas_spar_get_activeW_flag_fx( Word32 L_tmp, L_tmp1; Word16 exp_diff, q_com, guard_bits; - num_chs = s_min( nchan_inp, FOA_CHANNELS ); - num_bands = ivas_get_num_bands_from_bw_idx( SPAR_CONFIG_BW ); + num_chs = s_min( nchan_inp, FOA_CHANNELS ); /* Q0 */ + num_bands = ivas_get_num_bands_from_bw_idx( SPAR_CONFIG_BW ); /* Q0 */ set_zero_fx( bb_var, FOA_CHANNELS ); set_s( q_bb_var, Q31, FOA_CHANNELS ); @@ -225,7 +226,7 @@ static Word16 ivas_spar_get_activeW_flag_fx( q_shift = Q31; move16(); q_shift = W_norm( bb_var_64bit[ch] ); - bb_var[ch] = W_extract_l( W_shl_nosat( bb_var_64bit[ch], sub( q_shift, 32 ) ) ); + bb_var[ch] = W_extract_l( W_shl_nosat( bb_var_64bit[ch], sub( q_shift, 32 ) ) ); /* q_bb_var[ch] + sub( q_shift, 32 ) */ move32(); q_bb_var[ch] = add( q_bb_var[ch], sub( q_shift, 32 ) ); move16(); @@ -294,7 +295,7 @@ static Word16 ivas_spar_get_activeW_flag_fx( { Word16 max_idx; Word32 max_val; - max_idx = nchan_transport; + max_idx = nchan_transport; /* Q0 */ move16(); max_val = hCovEnc->bb_var_lt_fx[max_idx]; // q_bb_var[max_idx] move32(); @@ -306,12 +307,12 @@ static Word16 ivas_spar_get_activeW_flag_fx( move32(); } } - *res_ind = max_idx; + *res_ind = max_idx; /* Q0 */ move16(); } ELSE IF( EQ_16( nchan_transport, 3 ) ) { - *res_ind = dmx_order[nchan_transport]; + *res_ind = dmx_order[nchan_transport]; /* Q0 */ move16(); } } @@ -328,25 +329,26 @@ return activeW_flag; void ivas_enc_cov_handler_process_fx( ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ - Word32 **ppIn_FR_real, - Word32 **ppIn_FR_imag, + Word32 **ppIn_FR_real, /* q_ppIn_FR */ + Word32 **ppIn_FR_imag, /* q_ppIn_FR */ Word16 q_ppIn_FR, - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /* q_cov_real */ Word16 *q_cov_real[IVAS_SPAR_MAX_CH], - Word32 *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /* q_cov_dtx_real */ Word16 *q_cov_dtx_real[IVAS_SPAR_MAX_CH], - ivas_filterbank_t *pFb, /* i/o: FB handle */ - const Word16 start_band, - const Word16 end_band, - const Word16 num_ch, - const Word16 dtx_vad, - const Word16 transient_det[2], - const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH], - Word16 *res_ind, - const Word16 *remix_order, - Word16 *dyn_active_w_flag, - const Word16 nchan_transport, - const Word16 is_sba ) + ivas_filterbank_t *pFb, /* i/o: FB handle */ + const Word16 start_band, /* Q0 */ + const Word16 end_band, /* Q0 */ + const Word16 num_ch, /* Q0 */ + const Word16 dtx_vad, /* Q0 */ + const Word16 transient_det[2], /* Q0 */ + const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH], /* Q0 */ + Word16 *res_ind, /* Q0 */ + const Word16 *remix_order, /* Q0 */ + Word16 *dyn_active_w_flag, /* Q0 */ + const Word16 nchan_transport, /* Q0 */ + const Word16 is_sba /* Q0 */ +) { Word16 i, j; Word16 dtx_cov_flag; @@ -410,7 +412,7 @@ void ivas_enc_cov_handler_process_fx( move16(); IF( GT_16( nchan_transport, 1 ) && LE_16( nchan_transport, sub( FOA_CHANNELS, 1 ) ) ) { - *dyn_active_w_flag = ivas_spar_get_activeW_flag_fx( hCovEnc, cov_real, cov_real, q_cov_real, dtx_vad, num_ch, nchan_transport, res_ind, remix_order ); + *dyn_active_w_flag = ivas_spar_get_activeW_flag_fx( hCovEnc, cov_real, cov_real, q_cov_real, dtx_vad, num_ch, nchan_transport, res_ind, remix_order ); /* Q0 */ } ELSE { @@ -423,7 +425,7 @@ void ivas_enc_cov_handler_process_fx( { FOR( j = 0; j < num_ch; j++ ) { - Copy32( cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); + Copy32( cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); /* q_cov_real */ q_cov_dtx_real[i][j] = q_cov_real[i][j]; move16(); } @@ -437,13 +439,13 @@ void ivas_enc_cov_handler_process_fx( { FOR( j = 0; j < num_ch; j++ ) { - Copy32( cov_real[i][j], hCovEnc->pCov_dtx_state->pPrior_cov_real_fx[i][j], pFb->filterbank_num_bands ); + Copy32( cov_real[i][j], hCovEnc->pCov_dtx_state->pPrior_cov_real_fx[i][j], pFb->filterbank_num_bands ); /* q_cov_real */ FOR( k = 0; k < pFb->filterbank_num_bands; k++ ) { hCovEnc->pCov_dtx_state->q_prior_cov_real_per_band[i][j][k] = hCovEnc->pCov_state->q_cov_real_per_band[i][j][k]; move16(); } - Copy32( cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); + Copy32( cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); /* q_cov_real */ Copy( hCovEnc->pCov_state->q_cov_real_per_band[i][j], hCovEnc->pCov_dtx_state->q_cov_real_per_band[i][j], pFb->filterbank_num_bands ); } } @@ -472,7 +474,7 @@ void ivas_enc_cov_handler_process_fx( { FOR( j = 0; j < num_ch; j++ ) { - Copy32( hCovEnc->pCov_dtx_state->pPrior_cov_real_fx[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); + Copy32( hCovEnc->pCov_dtx_state->pPrior_cov_real_fx[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); /* q_cov_real */ FOR( k = 0; k < pFb->filterbank_num_bands; k++ ) { hCovEnc->pCov_dtx_state->q_cov_real_per_band[i][j][k] = hCovEnc->pCov_dtx_state->q_prior_cov_real_per_band[i][j][k]; @@ -491,20 +493,21 @@ void ivas_enc_cov_handler_process_fx( static void ivas_band_cov_fx( - Word32 **ppIn_FR_real, - Word32 **ppIn_FR_imag, + Word32 **ppIn_FR_real, /* q_In_FR */ + Word32 **ppIn_FR_imag, /* q_In_FR */ Word16 q_In_FR, - const Word16 num_chans, - const Word16 num_bins, - Word16 stride, - Word32 **pFb_bin_to_band, - const Word16 *pFb_start_bin_per_band, - const Word16 *pFb_active_bins_per_band, - const Word16 start_band, - const Word16 end_band, - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + const Word16 num_chans, /* Q0 */ + const Word16 num_bins, /* Q0 */ + Word16 stride, /* Q0 */ + Word32 **pFb_bin_to_band, /* Q22 */ + const Word16 *pFb_start_bin_per_band, /* Q0 */ + const Word16 *pFb_active_bins_per_band, /* Q0 */ + const Word16 start_band, /* Q0 */ + const Word16 end_band, /* Q0 */ + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /* q_cov_real */ Word16 *q_cov_real[IVAS_SPAR_MAX_CH], - const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH] ) + const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH] /* Q0 */ +) { Word16 i, j, k; Word32 pV_re[L_FRAME48k]; @@ -517,8 +520,8 @@ static void ivas_band_cov_fx( { FOR( j = i; j < num_chans; j++ ) { - Word16 i1 = HOA_md_ind[i]; - Word16 j1 = HOA_md_ind[j]; + Word16 i1 = HOA_md_ind[i]; /* Q0 */ + Word16 j1 = HOA_md_ind[j]; /* Q0 */ move16(); move16(); @@ -559,11 +562,11 @@ static void ivas_band_cov_fx( temp = 0; move64(); - num_blocks = idiv1616( num_bins, stride ); + num_blocks = idiv1616( num_bins, stride ); /* Q0 */ move16(); - start_bin = pFb_start_bin_per_band[k]; + start_bin = pFb_start_bin_per_band[k]; /* Q0 */ move16(); - active_bins = pFb_active_bins_per_band[k]; + active_bins = pFb_active_bins_per_band[k]; /* Q0 */ move16(); FOR( blk = 0; blk < num_blocks; blk++ ) @@ -599,7 +602,7 @@ static void ivas_band_cov_fx( } FOR( k = start_band; k < end_band; k++ ) { - cov_real[i][j][k] = W_extract_l( W_shl_nosat( cov_real_64bit[i][j][k], sub( q_shift, 32 ) ) ); + cov_real[i][j][k] = W_extract_l( W_shl_nosat( cov_real_64bit[i][j][k], sub( q_shift, 32 ) ) ); /* q_cov_real[i][j] + q_shift - 32 */ move32(); } q_cov_real[i][j] = add( q_cov_real[i][j], sub( q_shift, 32 ) ); diff --git a/lib_enc/ivas_entropy_coder.c b/lib_enc/ivas_entropy_coder.c index 9949aab631b0a61d79d957f54ed71601fc9fdf6e..da4826776567c8b471c1c3ffaa35ace99882d301 100644 --- a/lib_enc/ivas_entropy_coder.c +++ b/lib_enc/ivas_entropy_coder.c @@ -51,18 +51,19 @@ *-----------------------------------------------------------------------------------------*/ static ivas_error ivas_get_dyn_freq_model_fx( - Word16 *pInput, - const Word16 length, - Word16 *model_index, + Word16 *pInput, /* Q0 */ + const Word16 length, /* Q0 */ + Word16 *model_index, /* Q0 */ ivas_arith_t *pArith, - Word16 **ppCum_freq ) + Word16 **ppCum_freq /* Q0 */ +) { Word32 curr_dist[IVAS_MAX_QUANT_LEVELS]; Word16 i, n[IVAS_MAX_QUANT_LEVELS + 1], model_idx; Word32 curr_bps, curr_bps_min, curr_bps_new; Word16 range = pArith->range; Word16 m; - Word16 offset = negate( pArith->vals[0] ); + Word16 offset = negate( pArith->vals[0] ); /* Q0 */ ivas_error error; error = IVAS_ERR_OK; move32(); @@ -75,7 +76,7 @@ static ivas_error ivas_get_dyn_freq_model_fx( FOR( i = 0; i < length; i++ ) { - n[pInput[i] + offset] = add( n[pInput[i] + offset], 1 ); + n[pInput[i] + offset] = add( n[pInput[i] + offset], 1 ); /* Q0 */ move16(); } @@ -85,7 +86,7 @@ static ivas_error ivas_get_dyn_freq_model_fx( { curr_dist[i] = L_deposit_l( n[i] ); move32(); - curr_bps = L_sub( curr_bps, curr_dist[i] * pArith->saved_dist_arr[0][i] ); + curr_bps = L_sub( curr_bps, W_extract_l( W_mult0_32_32( curr_dist[i], pArith->saved_dist_arr[0][i] ) ) ); } curr_bps_min = curr_bps; move32(); @@ -104,7 +105,7 @@ static ivas_error ivas_get_dyn_freq_model_fx( move32(); FOR( i = 0; i < range; i++ ) { - curr_bps_new = L_sub( curr_bps_new, ( curr_dist[i] * pArith->saved_dist_arr[m + 1][i] ) ); + curr_bps_new = L_sub( curr_bps_new, W_extract_l( W_mult0_32_32( curr_dist[i], pArith->saved_dist_arr[m + 1][i] ) ) ); } #ifdef DEBUGGING { @@ -123,32 +124,34 @@ static ivas_error ivas_get_dyn_freq_model_fx( IF( LT_32( curr_bps_min, curr_bps ) ) { - *ppCum_freq = pArith->cum_freq[model_idx + 1]; - model_idx = add( model_idx, 1 ); + *ppCum_freq = pArith->cum_freq[model_idx + 1]; /* Q0 */ + model_idx = add( model_idx, 1 ); /* Q0 */ } ELSE { model_idx = 0; - *ppCum_freq = pArith->cum_freq[0]; + move16(); + *ppCum_freq = pArith->cum_freq[0]; /* Q0 */ } - *model_index = model_idx; + *model_index = model_idx; /* Q0 */ move16(); return error; } /*-----------------------------------------------------------------------------------------* - * Function ivas_arith_encode_array() + * Function ivas_arith_encode_array_fx() * * Arith encoding of an array of symbols *-----------------------------------------------------------------------------------------*/ -static Word16 ivas_arith_encode_array( - Word16 *pInput, +static Word16 ivas_arith_encode_array_fx( + Word16 *pInput, /* Q0 */ ivas_arith_t *pArith, BSTR_ENC_HANDLE hMetaData, - const Word16 in_len, - const Word16 wc_strat_arith ) + const Word16 in_len, /* Q0 */ + const Word16 wc_strat_arith /* Q0 */ +) { Word16 model_index, i, ind; Word16 *pCum_freq = NULL; @@ -168,14 +171,14 @@ static Word16 ivas_arith_encode_array( } ELSE { - pCum_freq = pArith->cum_freq[0]; + pCum_freq = pArith->cum_freq[0]; /* Q0 */ } ari_start_encoding_14bits( &as ); FOR( i = 0; i < in_len; i++ ) { - ind = sub( pInput[i], pArith->vals[0] ); + ind = sub( pInput[i], pArith->vals[0] ); /* Q0 */ ivas_ari_encode_14bits_ext_fx( hMetaData, &as, ind, (const UWord16 *) pCum_freq ); IF( GT_16( hMetaData->nb_bits_tot, wc_strat_arith ) ) { @@ -195,18 +198,19 @@ static Word16 ivas_arith_encode_array( /*-----------------------------------------------------------------------------------------* - * Function ivas_arithCoder_encode_array_diff() + * Function ivas_arithCoder_encode_array_diff_fx() * * Differential arith encoding *-----------------------------------------------------------------------------------------*/ -static Word16 ivas_arithCoder_encode_array_diff( +static Word16 ivas_arithCoder_encode_array_diff_fx( ivas_arith_t *pArith_diff, - Word16 *pIn_new, - Word16 *pIn_old_scratch, - const Word16 length, + Word16 *pIn_new, /* Q0 */ + Word16 *pIn_old_scratch, /* Q0 */ + const Word16 length, /* Q0 */ BSTR_ENC_HANDLE hMetaData, - const Word16 wc_strat_arith ) + const Word16 wc_strat_arith /* Q0 */ +) { Word16 n; Word16 arith_result; @@ -215,13 +219,13 @@ static Word16 ivas_arithCoder_encode_array_diff( { FOR( n = 0; n < length; n++ ) { - pIn_old_scratch[n] = sub( pIn_new[n], pIn_old_scratch[n] ); + pIn_old_scratch[n] = sub( pIn_new[n], pIn_old_scratch[n] ); /* Q0 */ move16(); } ivas_wrap_arround_fx( pIn_old_scratch, pArith_diff->vals[0], pArith_diff->vals[pArith_diff->range - 1], length ); - arith_result = ivas_arith_encode_array( pIn_old_scratch, pArith_diff, hMetaData, length, wc_strat_arith ); + arith_result = ivas_arith_encode_array_fx( pIn_old_scratch, pArith_diff, hMetaData, length, wc_strat_arith ); /* Q0 */ IF( arith_result < 0 ) { return -1; @@ -233,27 +237,28 @@ static Word16 ivas_arithCoder_encode_array_diff( /*-----------------------------------------------------------------------------------------* - * Function ivas_huffman_encode() + * Function ivas_huffman_encode_fx() * * ivas_huffman_encode *-----------------------------------------------------------------------------------------*/ -void ivas_huffman_encode( +void ivas_huffman_encode_fx( ivas_huffman_cfg_t *huff_cfg, - Word16 in, - Word16 *hcode, - Word16 *hlen ) + Word16 in, /* Q0 */ + Word16 *hcode, /* Q0 */ + Word16 *hlen /* Q0 */ +) { Word16 min_sym_val; const Word16 *codebook; - min_sym_val = huff_cfg->codebook[0]; + min_sym_val = huff_cfg->codebook[0]; /* Q0 */ move16(); - codebook = &huff_cfg->codebook[3 * ( in - min_sym_val )]; - *hlen = codebook[1]; + codebook = &huff_cfg->codebook[3 * ( in - min_sym_val )]; /* Q0 */ + *hlen = codebook[1]; /* Q0 */ move16(); - *hcode = codebook[2]; + *hcode = codebook[2]; /* Q0 */ move16(); return; @@ -261,17 +266,17 @@ void ivas_huffman_encode( /*-----------------------------------------------------------------------------------------* - * Function arith_encode_cell_array() + * Function arith_encode_cell_array_fx() * * Arithmetic encode a cell array *-----------------------------------------------------------------------------------------*/ -static Word16 arith_encode_cell_array( +static Word16 arith_encode_cell_array_fx( ivas_cell_dim_t *pCell_dims, BSTR_ENC_HANDLE hMetaData, - const Word16 nB, + const Word16 nB, /* Q0 */ ivas_arith_t *pArith, - Word16 *pSymbol, + Word16 *pSymbol, /* Q0 */ const Word16 wc_strat_arith ) { Word16 total_symbol_len = 0; @@ -281,7 +286,7 @@ static Word16 arith_encode_cell_array( FOR( i = 0; i < nB; i++ ) { - total_symbol_len = add( total_symbol_len, imult1616( pCell_dims[i].dim1, pCell_dims[i].dim2 ) ); + total_symbol_len = add( total_symbol_len, imult1616( pCell_dims[i].dim1, pCell_dims[i].dim2 ) ); /* Q0 */ } assert( LE_16( total_symbol_len, ( IVAS_MAX_INPUT_LEN ) ) ); @@ -290,7 +295,7 @@ static Word16 arith_encode_cell_array( { IF( GT_16( pArith->range, 1 ) ) { - arith_result = ivas_arith_encode_array( pSymbol, pArith, hMetaData, total_symbol_len, wc_strat_arith ); + arith_result = ivas_arith_encode_array_fx( pSymbol, pArith, hMetaData, total_symbol_len, wc_strat_arith ); /* Q0 */ IF( arith_result < 0 ) { return -1; @@ -303,19 +308,20 @@ static Word16 arith_encode_cell_array( /*-----------------------------------------------------------------------------------------* - * Function arith_encode_cell_array_diff() + * Function arith_encode_cell_array_diff_fx() * * Arithmetic encode a cell array - differential *-----------------------------------------------------------------------------------------*/ -static Word16 arith_encode_cell_array_diff( +static Word16 arith_encode_cell_array_diff_fx( const ivas_cell_dim_t *pCell_dims, BSTR_ENC_HANDLE hMetaData, - Word16 nB, + Word16 nB, /* Q0 */ ivas_arith_t *pArith_diff, - Word16 *pSymbol_old, - Word16 *pSymbol, - const Word16 wc_strat_arith ) + Word16 *pSymbol_old, /* Q0 */ + Word16 *pSymbol, /* Q0 */ + const Word16 wc_strat_arith /* Q0 */ +) { Word16 i, total_symbol_len; Word16 arith_result; @@ -324,7 +330,7 @@ static Word16 arith_encode_cell_array_diff( move16(); FOR( i = 0; i < nB; i++ ) { - total_symbol_len = add( total_symbol_len, ( imult1616( pCell_dims[i].dim1, pCell_dims[i].dim2 ) ) ); + total_symbol_len = add( total_symbol_len, ( imult1616( pCell_dims[i].dim1, pCell_dims[i].dim2 ) ) ); /* Q0 */ } assert( LE_16( total_symbol_len, ( IVAS_MAX_INPUT_LEN ) ) ); @@ -333,7 +339,7 @@ static Word16 arith_encode_cell_array_diff( { IF( GT_16( pArith_diff->range, 1 ) ) { - arith_result = ivas_arithCoder_encode_array_diff( pArith_diff, pSymbol, pSymbol_old, total_symbol_len, hMetaData, wc_strat_arith ); + arith_result = ivas_arithCoder_encode_array_diff_fx( pArith_diff, pSymbol, pSymbol_old, total_symbol_len, hMetaData, wc_strat_arith ); /* Q0 */ IF( arith_result < 0 ) { return -1; @@ -346,22 +352,23 @@ static Word16 arith_encode_cell_array_diff( /*-----------------------------------------------------------------------------------------* - * Function ivas_arith_encode_cmplx_cell_array() + * Function ivas_arith_encode_cmplx_cell_array_fx() * * Arithmetic encode a cell array *-----------------------------------------------------------------------------------------*/ -Word16 ivas_arith_encode_cmplx_cell_array( +Word16 ivas_arith_encode_cmplx_cell_array_fx( ivas_arith_t *pArith_re, ivas_arith_t *pArith_re_diff, - const Word16 *pDo_diff, - const Word16 nB, - Word16 *pSymbol_re, - Word16 *pSymbol_old_re, + const Word16 *pDo_diff, /* Q0 */ + const Word16 nB, /* Q0 */ + Word16 *pSymbol_re, /* Q0 */ + Word16 *pSymbol_old_re, /* Q0 */ ivas_cell_dim_t *pCell_dims, BSTR_ENC_HANDLE hMetaData, - const Word16 any_diff, - const Word16 wc_strat_arith ) + const Word16 any_diff, /* Q0 */ + const Word16 wc_strat_arith /* Q0 */ +) { Word16 input_old[IVAS_MAX_INPUT_LEN]; Word16 input_new[IVAS_MAX_INPUT_LEN]; @@ -381,19 +388,19 @@ Word16 ivas_arith_encode_cmplx_cell_array( move16(); FOR( i = 0; i < nB; i++ ) { - len = ( imult1616( pCell_dims[i].dim1, pCell_dims[i].dim2 ) ); + len = ( imult1616( pCell_dims[i].dim1, pCell_dims[i].dim2 ) ); /* Q0 */ move16(); IF( pDo_diff[i] != 0 ) { FOR( j = 0; j < len; j++ ) { - input_old[idx] = pSymbol_old_re[total_len + j]; - input_new[idx++] = pSymbol_re[total_len + j]; + input_old[idx] = pSymbol_old_re[total_len + j]; /* Q0 */ + input_new[idx++] = pSymbol_re[total_len + j]; /* Q0 */ move16(); move16(); } - cell_dim_diff[i].dim1 = pCell_dims[i].dim1; - cell_dim_diff[i].dim2 = pCell_dims[i].dim2; + cell_dim_diff[i].dim1 = pCell_dims[i].dim1; /* Q0 */ + cell_dim_diff[i].dim2 = pCell_dims[i].dim2; /* Q0 */ cell_dim[i].dim1 = 0; cell_dim[i].dim2 = 0; move16(); @@ -405,28 +412,28 @@ Word16 ivas_arith_encode_cmplx_cell_array( { FOR( j = 0; j < len; j++ ) { - input[idx1++] = pSymbol_re[total_len + j]; + input[idx1++] = pSymbol_re[total_len + j]; /* Q0 */ move16(); } cell_dim_diff[i].dim1 = 0; cell_dim_diff[i].dim2 = 0; - cell_dim[i].dim1 = pCell_dims[i].dim1; - cell_dim[i].dim2 = pCell_dims[i].dim2; + cell_dim[i].dim1 = pCell_dims[i].dim1; /* Q0 */ + cell_dim[i].dim2 = pCell_dims[i].dim2; /* Q0 */ move16(); move16(); move16(); move16(); } - total_len = add( total_len, len ); + total_len = add( total_len, len ); /* Q0 */ } - arith_result = arith_encode_cell_array( cell_dim, hMetaData, nB, pArith_re, input, wc_strat_arith ); + arith_result = arith_encode_cell_array_fx( cell_dim, hMetaData, nB, pArith_re, input, wc_strat_arith ); /* Q0 */ IF( arith_result < 0 ) { return -1; } - arith_result = arith_encode_cell_array_diff( cell_dim_diff, hMetaData, nB, pArith_re_diff, input_old, input_new, wc_strat_arith ); + arith_result = arith_encode_cell_array_diff_fx( cell_dim_diff, hMetaData, nB, pArith_re_diff, input_old, input_new, wc_strat_arith ); /* Q0 */ move16(); IF( arith_result < 0 ) { @@ -435,7 +442,7 @@ Word16 ivas_arith_encode_cmplx_cell_array( } ELSE { - arith_result = arith_encode_cell_array( pCell_dims, hMetaData, nB, pArith_re, pSymbol_re, wc_strat_arith ); + arith_result = arith_encode_cell_array_fx( pCell_dims, hMetaData, nB, pArith_re, pSymbol_re, wc_strat_arith ); /* Q0 */ IF( arith_result < 0 ) { return -1; diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index f1c6cb24a06a09caeac5783811c63f2352278687..023b9fa59b72e7cb023a38f0937677bc526dc58d 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -52,25 +52,25 @@ * Standalone front-VAD module *-----------------------------------------------------------------------------------------*/ ivas_error front_vad_fx( - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure, nullable */ - Encoder_State *st, /* i/o: encoder state structure */ - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - FRONT_VAD_ENC_HANDLE *hFrontVads, /* i/o: FrontVad handles */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const Word16 input_frame, /* i : frame length */ - Word16 vad_flag_dtx[], /* o : HE-SAD flag with additional DTX HO */ - Word32 fr_bands_fx[][2 * NB_BANDS], /* o : energy in frequency bands q_fr_bands_fx */ - Word16 q_fr_bands[], /* o : Q of fr_bands_fx Q0 */ - Word16 Etot_LR_fx[], /* o : total energy Left & Right channel Q8 */ - Word32 lf_E_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels q_lf_E */ - Word16 q_lf_E[], /* o : Q of lf_E_fx */ - Word16 localVAD_HE_SAD[], /* o : HE-SAD flag without hangover, LR channels */ - Word16 vad_hover_flag[], /* o : VAD hangover flag */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure, nullable */ + Encoder_State *st, /* i/o: encoder state structure */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + FRONT_VAD_ENC_HANDLE *hFrontVads, /* i/o: FrontVad handles */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 input_frame, /* i : frame length Q0*/ + Word16 vad_flag_dtx[], /* o : HE-SAD flag with additional DTX HO Q0*/ + Word32 fr_bands_fx[][2 * NB_BANDS], /* o : energy in frequency bands q_fr_bands_fx*/ + Word16 q_fr_bands[], /* o : Q of fr_bands_fx */ + Word16 Etot_LR_fx[], /* o : total energy Left & Right channel Q8*/ + Word32 lf_E_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels q_lf_E*/ + Word16 q_lf_E[], /* o : Q of lf_E_fx */ + Word16 localVAD_HE_SAD[], /* o : HE-SAD flag without hangover, LR channels Q0*/ + Word16 vad_hover_flag[], /* o : VAD hangover flag Q0*/ Word32 band_energies_LR_fx[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN q_band_energies_LR */ - Word16 *q_band_energies_LR, /* o : Q of band_energies_LR_fx */ - Word32 *PS_out_fx, /* o : energy spectrum q_PS_out */ - Word16 *q_PS_out, /* o : Q of PS_out_fx Q0 */ - Word16 *Bin_E_out_fx, /* o : log-energy spectrum of the current frame Q7 */ + Word16 *q_band_energies_LR, /* o : Q of band_energies_LR_fx */ + Word32 *PS_out_fx, /* o : energy spectrum q_PS_out*/ + Word16 *q_PS_out, /* o : Q of PS_out_fx Q0*/ + Word16 *Bin_E_out_fx, /* o : log-energy spectrum of the current frame Q7*/ Word16 Q_inp, Word16 *Q_buffer, Word16 Q_add, @@ -94,6 +94,8 @@ ivas_error front_vad_fx( Word16 Qband, mem_decim_size; error = IVAS_ERR_OK; push_wmops( "front_vad" ); + move16(); + move16(); Q_new = 0; move16(); @@ -101,16 +103,17 @@ ivas_error front_vad_fx( lgBin_E_fx = NULL; if ( st != NULL ) { - lgBin_E_fx = &st->lgBin_E_fx[0]; + lgBin_E_fx = &st->lgBin_E_fx[0]; /* Q8 */ move16(); } IF( hCPE != NULL ) { n_chan = CPE_CHANNELS; + move16(); sts = &hCPE->hCoreCoder[0]; - element_mode = hCPE->element_mode; + element_mode = hCPE->element_mode; /* Q0 */ move16(); - last_element_mode = hCPE->last_element_mode; + last_element_mode = hCPE->last_element_mode; /* Q0 */ move16(); } ELSE IF( st != NULL ) @@ -199,8 +202,8 @@ ivas_error front_vad_fx( { FOR( n = 0; n < n_chan; n++ ) { - scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, 20, sub( add( Q_new_old, QSCALE ), Q11 ) ); - scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, 20, sub( add( Q_new_old, QSCALE ), Q11 ) ); + scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, 20, sub( add( Q_new_old, QSCALE ), Q11 ) ); /* Q_new_old + QSCALE */ + scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, 20, sub( add( Q_new_old, QSCALE ), Q11 ) ); /* Q_new_old + QSCALE */ hFrontVads[n]->lp_speech_fx = shr( hFrontVads[n]->lp_speech_fx, 1 ); move16(); } @@ -222,7 +225,7 @@ ivas_error front_vad_fx( modify_Fs_fx( sts[n]->input_fx, input_frame, sts[0]->input_Fs, hFrontVad->buffer_12k8_fx + L_FFT / 2, INT_FS_12k8, hFrontVad->mem_decim_fx, ( sts[0]->max_bwidth == NB ), &Qband, &mem_decim_size ); /* Preemphasis */ - hFrontVad->mem_preemph_fx = shl( hFrontVad->mem_preemph_fx, sub( add( Q_inp, Qband ), hFrontVad->q_mem_preemph_fx ) ); + hFrontVad->mem_preemph_fx = shl( hFrontVad->mem_preemph_fx, sub( add( Q_inp, Qband ), hFrontVad->q_mem_preemph_fx ) ); /* Q_inp + Qband */ move16(); hFrontVad->q_mem_preemph_fx = add( Q_inp, Qband ); move16(); @@ -230,8 +233,8 @@ ivas_error front_vad_fx( PREEMPH_FX( hFrontVad->buffer_12k8_fx + L_FFT / 2, PREEMPH_FAC, L_FRAME, &hFrontVad->mem_preemph_fx ); Q_new = add( sub( Q_inp, Qband ), Q_add ); - Scale_sig( hFrontVad->buffer_12k8_fx, L_FFT / 2, Q_new - Q_buffer[n] ); - Scale_sig( hFrontVad->buffer_12k8_fx + L_FFT / 2, 384 - L_FFT / 2, Q_new - add( Q_inp, Qband ) ); + Scale_sig( hFrontVad->buffer_12k8_fx, L_FFT / 2, sub( Q_new, Q_buffer[n] ) ); /* Q_new */ + Scale_sig( hFrontVad->buffer_12k8_fx + L_FFT / 2, 384 - L_FFT / 2, sub( Q_new, add( Q_inp, Qband ) ) ); /* Q_new */ Q_buffer[n] = Q_new; move16(); @@ -266,52 +269,52 @@ ivas_error front_vad_fx( Q_new_old = Q_new; move16(); - Word32 Etot_fx = L_deposit_h( Etot_LR_fx[n] ); + Word32 Etot_fx = L_deposit_h( Etot_LR_fx[n] ); /* Q24 */ noise_est_pre_32fx( Etot_fx, hFrontVads[0]->ini_frame, hFrontVad->hNoiseEst, 0, 0, 0 ); /* wb_vad */ Word16 scale = getScaleFactor32( hFrontVads[n]->hNoiseEst->bckr_fx, NB_BANDS ); - scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, NB_BANDS, scale ); + scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, NB_BANDS, scale ); // hFrontVads[n]->hNoiseEst->q_bckr + scale hFrontVads[n]->hNoiseEst->q_bckr = add( hFrontVads[n]->hNoiseEst->q_bckr, scale ); move16(); scale = getScaleFactor32( hFrontVads[n]->hNoiseEst->enrO_fx, NB_BANDS ); - scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, NB_BANDS, scale ); + scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, NB_BANDS, scale ); // hFrontVads[n]->hNoiseEst->q_enrO + scale hFrontVads[n]->hNoiseEst->q_enrO = add( hFrontVads[n]->hNoiseEst->q_enrO, scale ); move16(); scale = s_min( q_fr_bands[n], s_min( hFrontVads[n]->hNoiseEst->q_bckr, hFrontVads[n]->hNoiseEst->q_enrO ) ); - scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, NB_BANDS, sub( scale, hFrontVads[n]->hNoiseEst->q_bckr ) ); + scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, NB_BANDS, sub( scale, hFrontVads[n]->hNoiseEst->q_bckr ) ); // scale hFrontVads[n]->hNoiseEst->q_bckr = scale; move16(); - scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, NB_BANDS, sub( scale, hFrontVads[n]->hNoiseEst->q_enrO ) ); + scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, NB_BANDS, sub( scale, hFrontVads[n]->hNoiseEst->q_enrO ) ); // scale hFrontVads[n]->hNoiseEst->q_enrO = scale; move16(); - scale_sig32( fr_bands_fx[n], 2 * NB_BANDS, sub( scale, q_fr_bands[n] ) ); + scale_sig32( fr_bands_fx[n], 2 * NB_BANDS, sub( scale, q_fr_bands[n] ) ); // scale q_fr_bands[n] = scale; move16(); hFrontVad->hVAD->vad_flag = wb_vad_ivas_fx( sts[n], fr_bands_fx[n], q_fr_bands[n], &dummy, &dummy, &dummy, &snr_sum_he_fx, &localVAD_HE_SAD[n], &dummy_short, hFrontVad->hVAD, hFrontVad->hNoiseEst, - hFrontVad->lp_speech_fx, hFrontVad->lp_noise_fx ); + hFrontVad->lp_speech_fx, hFrontVad->lp_noise_fx ); // Q0 test(); test(); if ( n == 0 && GT_16( n_chan, 1 ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) { - sts[1]->last_coder_type = sts[0]->last_coder_type; + sts[1]->last_coder_type = sts[0]->last_coder_type; /* Q0 */ move16(); } - vad_flag_dtx[n] = ivas_dtx_hangover_addition_fx( sts[n], hFrontVad->hVAD->vad_flag, hFrontVad->lp_speech_fx - hFrontVad->lp_noise_fx, 0 /* <- no cldfb addition */, &vad_hover_flag[n], hFrontVad->hVAD, hFrontVad->hNoiseEst, &hFrontVads[n]->rem_dtx_ho ); + vad_flag_dtx[n] = ivas_dtx_hangover_addition_fx( sts[n], hFrontVad->hVAD->vad_flag, sub( hFrontVad->lp_speech_fx, hFrontVad->lp_noise_fx ), 0 /* <- no cldfb addition */, &vad_hover_flag[n], hFrontVad->hVAD, hFrontVad->hNoiseEst, &hFrontVads[n]->rem_dtx_ho ); /* Q0 */ move16(); if ( EQ_16( n_chan, 1 ) ) { - sts[n]->vad_flag = hFrontVad->hVAD->vad_flag; + sts[n]->vad_flag = hFrontVad->hVAD->vad_flag; /* Q0 */ move16(); } } @@ -491,10 +494,10 @@ void front_vad_destroy_fx( * Standalone front-VAD module for SPAR *-----------------------------------------------------------------------------------------*/ ivas_error front_vad_spar_fx( - SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder structure */ - const Word32 *omni_in, /* i : omnidirectional input signal Q11 */ - ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : encoder configuration handle */ - const Word16 input_frame /* i : input frame length */ + SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder structure */ + const Word32 *omni_in, /* i : omnidirectional input signal Q11*/ + ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : encoder configuration handle */ + const Word16 input_frame /* i : input frame length Q0*/ ) { FRONT_VAD_ENC_HANDLE hFrontVad; @@ -570,8 +573,8 @@ ivas_error front_vad_spar_fx( Word16 Q_bands = Q9; move16(); - Scale_sig32( hFrontVad->hNoiseEst->ave_enr_fx, NB_BANDS, ( Q_bands + QSCALE ) - hFrontVad->hNoiseEst->ave_enr_q ); - Scale_sig32( hFrontVad->hNoiseEst->ave_enr2_fx, NB_BANDS, ( Q_bands + QSCALE ) - hFrontVad->hNoiseEst->ave_enr_q ); + Scale_sig32( hFrontVad->hNoiseEst->ave_enr_fx, NB_BANDS, ( Q_bands + QSCALE ) - hFrontVad->hNoiseEst->ave_enr_q ); /* Q_bands + QSCALE */ + Scale_sig32( hFrontVad->hNoiseEst->ave_enr2_fx, NB_BANDS, ( Q_bands + QSCALE ) - hFrontVad->hNoiseEst->ave_enr_q ); /* Q_bands + QSCALE */ hFrontVad->hNoiseEst->ave_enr_q = ( Q_bands + QSCALE ); move16(); Word16 tmp1; @@ -584,8 +587,8 @@ ivas_error front_vad_spar_fx( MVR2R_WORD16( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); wsp_fx = old_wsp_fx + L_WSP_MEM; - st->core_brate = -1; /* updated in dtx() */ - st->input_bwidth = st->last_input_bwidth; + st->core_brate = -1; /* updated in dtx() */ + st->input_bwidth = st->last_input_bwidth; /* Q0 */ move32(); move16(); @@ -594,7 +597,7 @@ ivas_error front_vad_spar_fx( *-----------------------------------------------------------------*/ st->input_fx = input_fx; - Copy_Scale_sig32_16( omni_in, st->input_fx, input_frame, Q16 - Q11 ); + Copy_Scale_sig32_16( omni_in, st->input_fx, input_frame, Q16 - Q11 ); /* Q16 */ delay_signal( st->input_fx, input_frame, hFrontVad->delay_buf_fx, hFrontVad->delay_samples ); /* Scaling only if the omni_in buffer contains non-zero values */ @@ -618,7 +621,7 @@ ivas_error front_vad_spar_fx( } IF( tmp != 0 ) { - Scale_sig( st->input_fx, input_frame, s ); + Scale_sig( st->input_fx, input_frame, s ); /* s */ } Q_inp = s; move16(); @@ -630,14 +633,14 @@ ivas_error front_vad_spar_fx( Word16 Q_new_old = add( sub( Q_inp, Qband ), Q_add ); 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 ) ); + Scale_sig32( hFrontVad->hNoiseEst->enrO_fx, 20, sub( add( Q_new_old, QSCALE + 2 ), hFrontVad->hNoiseEst->q_enrO ) ); // 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(); - Scale_sig( hFrontVad->mem_decim_fx, 2 * L_FILT_MAX, sub( Q_inp, hFrontVad->q_mem_decim ) ); + Scale_sig( hFrontVad->mem_decim_fx, 2 * L_FILT_MAX, sub( Q_inp, hFrontVad->q_mem_decim ) ); /* Q_inp */ hFrontVad->q_mem_decim = Q_inp; move16(); Word16 q_band_energies; @@ -662,16 +665,16 @@ 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( add( Q_bands, QSCALE ), hFrontVad->hNoiseEst->q_bckr ) ); + Scale_sig32( hFrontVad->hNoiseEst->bckr_fx, 20, sub( add( Q_bands, QSCALE ), hFrontVad->hNoiseEst->q_bckr ) ); /* Q_bands + QSCALE */ 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 ); + corr_shift_fx = correlation_shift_fx( hFrontVad->hNoiseEst->totalNoise_fx ); /* Q15 */ dtx_ivas_fx( st, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8_fx, Q_inp_12k8 ); /* linear prediction analysis */ - alw_pitch_lag_12k8[0] = st->old_pitch_la; - alw_pitch_lag_12k8[1] = st->old_pitch_la; + alw_pitch_lag_12k8[0] = st->old_pitch_la; /* Q0 */ + alw_pitch_lag_12k8[1] = st->old_pitch_la; /* Q0 */ alw_voicing_fx[0] = st->voicing_fx[2]; alw_voicing_fx[1] = st->voicing_fx[2]; move16(); @@ -681,8 +684,8 @@ ivas_error front_vad_spar_fx( Word16 Q_r[2] = { 0 }; move16(); move16(); - Scale_sig( hFrontVad->mem_decim_fx, 2 * L_FILT_MAX, sub( s_min( Q_inp_12k8, hFrontVad->q_mem_decim ), hFrontVad->q_mem_decim ) ); - Scale_sig( inp_12k8_fx, 3 * L_FRAME / 2, sub( s_min( Q_inp_12k8, hFrontVad->q_mem_decim ), Q_inp_12k8 ) ); + Scale_sig( hFrontVad->mem_decim_fx, 2 * L_FILT_MAX, sub( s_min( Q_inp_12k8, hFrontVad->q_mem_decim ), hFrontVad->q_mem_decim ) ); /* min( hFrontVad->q_mem_decim, hFrontVad->q_buffer_12k8 */ + Scale_sig( inp_12k8_fx, 3 * L_FRAME / 2, sub( s_min( Q_inp_12k8, hFrontVad->q_mem_decim ), Q_inp_12k8 ) ); /* min( hFrontVad->q_mem_decim, hFrontVad->q_buffer_12k8 */ Q_inp_12k8 = s_min( hFrontVad->q_mem_decim, hFrontVad->q_buffer_12k8 ); hFrontVad->q_mem_decim = Q_inp_12k8; move16(); @@ -699,7 +702,7 @@ ivas_error front_vad_spar_fx( relE_fx = sub( Etot_fx[0], st->lp_speech_fx ); Scale_sig( A_fx, ( L_FRAME / L_SUBFR ) * ( M + 1 ), -2 ); // Q12 - st->mem_wsp_fx = (Word16) shl_sat( st->mem_wsp_fx, Q_inp_12k8 - st->mem_wsp_q ); + st->mem_wsp_fx = (Word16) shl_sat( st->mem_wsp_fx, Q_inp_12k8 - st->mem_wsp_q ); /* Q_inp_12k8 */ st->mem_wsp_q = Q_inp_12k8; move16(); ivas_find_wsp_fx( L_FRAME, L_SUBFR, NB_SUBFR, A_fx, Aw_fx, inp_12k8_fx, TILT_FAC_FX, wsp_fx, &st->mem_wsp_fx, GAMMA1, L_LOOK_12k8 ); @@ -712,19 +715,29 @@ ivas_error front_vad_spar_fx( old_pitch = st->pitch[1]; move16(); - Scale_sig( wsp_fx, 368, sub( Q8, Q_inp_12k8 ) ); + Scale_sig( wsp_fx, 368, sub( Q8, Q_inp_12k8 ) ); // Q8 pitch_ol_ivas_fx( st->pitch, st->voicing_fx, &st->old_pitch, &st->old_corr_fx, corr_shift_fx, &st->old_thres_fx, &st->delta_pit, st->old_wsp2_fx, wsp_fx, st->mem_decim2_fx, relE_fx, st->clas, st->input_bwidth, st->Opt_SC_VBR, Q8 ); + /* Updates for adaptive lag window memory */ - st->old_pitch_la = st->pitch[2]; + st->old_pitch_la = st->pitch[2]; /* Q0 */ move16(); - Scale_sig( wsp_fx, 368, Q9 - Q8 ); + Scale_sig( wsp_fx, 368, Q9 - Q8 ); /* Q9 */ StableHighPitchDetect_ivas_fx( &flag_spitch, st->pitch, st->voicing_fx, wsp_fx, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, Q12, st->lgBin_E_fx ); IF( st->hSpMusClas != NULL ) { Word16 dummy_int; + Word16 *cor_strong_limit; dummy_int = 0; move16(); - loc_harm = multi_harm_fx( st->lgBin_E_fx, hFrontVad->hNoiseEst->old_S_fx, hFrontVad->hNoiseEst->cor_map_fx, &hFrontVad->hNoiseEst->multi_harm_limit_fx, st->total_brate, st->bwidth, ( st->hGSCEnc != NULL ) ? &st->hGSCEnc->cor_strong_limit : &dummy_int, &st->hSpMusClas->mean_avr_dyn_fx, &st->hSpMusClas->last_sw_dyn_fx, &cor_map_sum_fx, &dummy_fx, S_map_fx ); + if ( st->hGSCEnc != NULL ) + { + cor_strong_limit = &st->hGSCEnc->cor_strong_limit; + } + else + { + cor_strong_limit = &dummy_int; + } + loc_harm = multi_harm_fx( st->lgBin_E_fx, hFrontVad->hNoiseEst->old_S_fx, hFrontVad->hNoiseEst->cor_map_fx, &hFrontVad->hNoiseEst->multi_harm_limit_fx, st->total_brate, st->bwidth, cor_strong_limit, &st->hSpMusClas->mean_avr_dyn_fx, &st->hSpMusClas->last_sw_dyn_fx, &cor_map_sum_fx, &dummy_fx, S_map_fx ); /* Q0 */ } scale = getScaleFactor32( epsP_fx, M + 1 ); Q_esp = add( Q_r[0], scale ); @@ -735,6 +748,7 @@ ivas_error front_vad_spar_fx( } Q_bands = Q9; move16(); + Scale_sig32( lf_E_fx[0], 148, sub( add( Q_bands, QSCALE - 2 ), q_lf_E[0] ) ); // Q_bands+QSCALE-2 q_lf_E[0] = add( Q_bands, QSCALE - 2 ); move16(); @@ -757,10 +771,10 @@ ivas_error front_vad_spar_fx( ivas_long_enr_fx( st, -1, localVAD_HE_SAD[0], high_lpn_flag, &hFrontVad, 1, localVAD_HE_SAD, Etot_fx ); /* increase ini_frame counter */ - hFrontVad->ini_frame = min( add( hFrontVad->ini_frame, 1 ), MAX_FRAME_COUNTER ); - st->ini_frame = hFrontVad->ini_frame; + hFrontVad->ini_frame = s_min( add( hFrontVad->ini_frame, 1 ), MAX_FRAME_COUNTER ); /* Q0 */ + st->ini_frame = hFrontVad->ini_frame; /* Q0 */ move16(); - hSpar->front_vad_flag = st->vad_flag; + hSpar->front_vad_flag = st->vad_flag; /* Q0 */ move16(); hSpar->front_vad_dtx_flag = 1; move16(); diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 16052d5e5cba7cac8664a16311eac76c56172a7b..d6a3597bd2d7c7d39407372215c3d01408ab3d2c 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -78,7 +78,7 @@ void ivas_write_format_fx( ind = 4; move16(); - nBits = add( nBits, extra_bits ); + nBits = add( nBits, extra_bits ); /* Q0 */ } BREAK; case MC_FORMAT: @@ -89,26 +89,26 @@ void ivas_write_format_fx( ind = 6; move16(); - nBits = add( nBits, extra_bits ); + nBits = add( nBits, extra_bits ); /* Q0 */ BREAK; case MASA_FORMAT: ind = 7; move16(); - nBits = add( nBits, extra_bits ); + nBits = add( nBits, extra_bits ); /* Q0 */ BREAK; case MASA_ISM_FORMAT: IF( st_ivas->ism_mode == ISM_MODE_NONE ) { ind = 7; /* send MASA format */ move16(); - nBits = add( nBits, extra_bits ); + nBits = add( nBits, extra_bits ); /* Q0 */ } ELSE { ind = 10; move16(); - nBits = add( nBits, add( extra_bits, IVAS_COMBINED_FORMAT_SIGNALLING_BITS ) ); + nBits = add( nBits, add( extra_bits, IVAS_COMBINED_FORMAT_SIGNALLING_BITS ) ); /* Q0 */ } BREAK; case SBA_ISM_FORMAT: @@ -116,13 +116,13 @@ void ivas_write_format_fx( { ind = 6; /* send SBA format */ move16(); - nBits = add( nBits, extra_bits ); + nBits = add( nBits, extra_bits ); /* Q0 */ } ELSE { ind = 11; /* 1011 */ move16(); - nBits = add( nBits, add( extra_bits, IVAS_COMBINED_FORMAT_SIGNALLING_BITS ) ); + nBits = add( nBits, add( extra_bits, IVAS_COMBINED_FORMAT_SIGNALLING_BITS ) ); /* Q0 */ } BREAK; default: @@ -150,7 +150,7 @@ void ivas_write_format_fx( void ivas_write_format_sid_fx( const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 element_mode, /* i : element bitrate */ + const Word16 element_mode, /* i : element bitrate Q0*/ BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ) { @@ -234,78 +234,91 @@ Word16 getNumChanAnalysis_fx( { Word16 n; - n = add( st_ivas->nSCE, CPE_CHANNELS * st_ivas->nCPE ); + n = add( st_ivas->nSCE, CPE_CHANNELS * st_ivas->nCPE ); /* Q0 */ test(); test(); test(); test(); IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, SBA_FORMAT ) ) { - n = imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ); + n = imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ); /* Q0 */ } ELSE IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MC_FORMAT ) && ( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) || EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) ) { - n = st_ivas->hEncoderConfig->nchan_inp; + n = st_ivas->hEncoderConfig->nchan_inp; /* Q0 */ move16(); } ELSE IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { - n = st_ivas->hEncoderConfig->nchan_inp; + n = st_ivas->hEncoderConfig->nchan_inp; /* Q0 */ move16(); } ELSE IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { - n = st_ivas->hEncoderConfig->nchan_inp; + n = st_ivas->hEncoderConfig->nchan_inp; /* Q0 */ move16(); } ELSE IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { - n = st_ivas->hEncoderConfig->nchan_inp; + n = st_ivas->hEncoderConfig->nchan_inp; /* Q0 */ move16(); } ELSE IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) { - n = add( st_ivas->hEncoderConfig->nchan_ism, imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ) ); + n = add( st_ivas->hEncoderConfig->nchan_ism, imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ) ); /* Q0 */ } return n; } /*-------------------------------------------------------------------* - * copy_encoder_config() + * copy_encoder_config_ivas_fx() * * Copy configuration structrue to the state structrure *-------------------------------------------------------------------*/ -void copy_encoder_config( - Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ - Encoder_State *st, /* o : encoder state structure */ - const Word16 flag_all /* i : flag 1==update all, 0=partial update*/ +void copy_encoder_config_ivas_fx( + Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ + Encoder_State *st, /* o : encoder state structure */ + const Word16 flag_all /* i : flag 1==update all, 0=partial update Q0*/ ) { - if ( flag_all ) + IF( flag_all ) { - st->input_Fs = st_ivas->hEncoderConfig->input_Fs; + st->input_Fs = st_ivas->hEncoderConfig->input_Fs; /* Q0 */ + move32(); - st->last_codec_mode = st_ivas->last_codec_mode; - st->last_total_brate = st_ivas->hEncoderConfig->last_ivas_total_brate; + st->last_codec_mode = st_ivas->last_codec_mode; /* Q0 */ + move16(); + st->last_total_brate = st_ivas->hEncoderConfig->last_ivas_total_brate; /* Q0 */ + move32(); - st->Opt_DTX_ON = st_ivas->hEncoderConfig->Opt_DTX_ON; + st->Opt_DTX_ON = st_ivas->hEncoderConfig->Opt_DTX_ON; /* Q0 */ + move16(); - st->last_Opt_SC_VBR = st_ivas->hEncoderConfig->last_Opt_SC_VBR; + st->last_Opt_SC_VBR = st_ivas->hEncoderConfig->last_Opt_SC_VBR; /* Q0 */ + move16(); } - st->Opt_AMR_WB = st_ivas->hEncoderConfig->Opt_AMR_WB; - st->Opt_SC_VBR = st_ivas->hEncoderConfig->Opt_SC_VBR; + st->Opt_AMR_WB = st_ivas->hEncoderConfig->Opt_AMR_WB; /* Q0 */ + st->Opt_SC_VBR = st_ivas->hEncoderConfig->Opt_SC_VBR; /* Q0 */ + move16(); + move16(); - st->codec_mode = st_ivas->codec_mode; - st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth; + st->codec_mode = st_ivas->codec_mode; /* Q0 */ + st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth; /* Q0 */ + move16(); + move16(); - st->Opt_RF_ON = st_ivas->hEncoderConfig->Opt_RF_ON; - st->rf_fec_offset = st_ivas->hEncoderConfig->rf_fec_offset; - st->rf_fec_indicator = st_ivas->hEncoderConfig->rf_fec_indicator; + st->Opt_RF_ON = st_ivas->hEncoderConfig->Opt_RF_ON; /* Q0 */ + st->rf_fec_offset = st_ivas->hEncoderConfig->rf_fec_offset; /* Q0 */ + st->rf_fec_indicator = st_ivas->hEncoderConfig->rf_fec_indicator; /* Q0 */ + move16(); + move16(); + move16(); - st->element_mode = st_ivas->hEncoderConfig->element_mode_init; + st->element_mode = st_ivas->hEncoderConfig->element_mode_init; /* Q0 */ + move16(); return; } @@ -316,62 +329,62 @@ void copy_encoder_config( *-------------------------------------------------------------------*/ void copy_encoder_config_fx( - Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ - Encoder_State *st_fx, /* o : encoder state structure */ - const Word16 flag_all /* i : flag 1==update all, 0=partial update*/ + Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ + Encoder_State *st_fx, /* o : encoder state structure */ + const Word16 flag_all /* i : flag 1==update all, 0=partial update Q0*/ ) { IF( flag_all ) { - st_fx->input_Fs = st_ivas->hEncoderConfig->input_Fs; + st_fx->input_Fs = st_ivas->hEncoderConfig->input_Fs; /* Q0 */ move32(); - st_fx->last_codec_mode = st_ivas->last_codec_mode; + st_fx->last_codec_mode = st_ivas->last_codec_mode; /* Q0 */ move16(); - st_fx->last_total_brate = st_ivas->hEncoderConfig->last_ivas_total_brate; + st_fx->last_total_brate = st_ivas->hEncoderConfig->last_ivas_total_brate; /* Q0 */ move32(); - st_fx->Opt_DTX_ON = st_ivas->hEncoderConfig->Opt_DTX_ON; + st_fx->Opt_DTX_ON = st_ivas->hEncoderConfig->Opt_DTX_ON; /* Q0 */ move16(); - st_fx->last_Opt_SC_VBR = st_ivas->hEncoderConfig->last_Opt_SC_VBR; + st_fx->last_Opt_SC_VBR = st_ivas->hEncoderConfig->last_Opt_SC_VBR; /* Q0 */ move16(); } - st_fx->Opt_AMR_WB = st_ivas->hEncoderConfig->Opt_AMR_WB; + st_fx->Opt_AMR_WB = st_ivas->hEncoderConfig->Opt_AMR_WB; /* Q0 */ move16(); - st_fx->Opt_SC_VBR = st_ivas->hEncoderConfig->Opt_SC_VBR; + st_fx->Opt_SC_VBR = st_ivas->hEncoderConfig->Opt_SC_VBR; /* Q0 */ move16(); - st_fx->codec_mode = st_ivas->codec_mode; + st_fx->codec_mode = st_ivas->codec_mode; /* Q0 */ move16(); - st_fx->max_bwidth = st_ivas->hEncoderConfig->max_bwidth; + st_fx->max_bwidth = st_ivas->hEncoderConfig->max_bwidth; /* Q0 */ move16(); - st_fx->Opt_RF_ON = st_ivas->hEncoderConfig->Opt_RF_ON; + st_fx->Opt_RF_ON = st_ivas->hEncoderConfig->Opt_RF_ON; /* Q0 */ move16(); - st_fx->rf_fec_offset = st_ivas->hEncoderConfig->rf_fec_offset; + st_fx->rf_fec_offset = st_ivas->hEncoderConfig->rf_fec_offset; /* Q0 */ move16(); - st_fx->rf_fec_indicator = st_ivas->hEncoderConfig->rf_fec_indicator; + st_fx->rf_fec_indicator = st_ivas->hEncoderConfig->rf_fec_indicator; /* Q0 */ move16(); #ifdef DEBUGGING st_fx->force = st_ivas->hEncoderConfig->force; #endif - st_fx->element_mode = st_ivas->hEncoderConfig->element_mode_init; + st_fx->element_mode = st_ivas->hEncoderConfig->element_mode_init; /* Q0 */ move16(); return; } /*------------------------------------------------------------------------- - * ivas_initialize_handles_enc() + * ivas_initialize_handles_enc_fx() * * NULL initialization of handles *-------------------------------------------------------------------------*/ -void ivas_initialize_handles_enc( +void ivas_initialize_handles_enc_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { @@ -466,38 +479,48 @@ ivas_error ivas_init_encoder( hEncoderConfig = st_ivas->hEncoderConfig; ivas_format = hEncoderConfig->ivas_format; - input_Fs = hEncoderConfig->input_Fs; - ivas_total_brate = hEncoderConfig->ivas_total_brate; + input_Fs = hEncoderConfig->input_Fs; /* Q0 */ + ivas_total_brate = hEncoderConfig->ivas_total_brate; /* Q0 */ + move32(); + move32(); - hEncoderConfig->last_ivas_total_brate = ivas_total_brate; + hEncoderConfig->last_ivas_total_brate = ivas_total_brate; /* Q0 */ + move32(); - if ( ivas_format != MONO_FORMAT ) + if ( NE_32( ivas_format, MONO_FORMAT ) ) { /* In IVAS, ensure that minimum coded bandwidth is WB */ - hEncoderConfig->max_bwidth = max( hEncoderConfig->max_bwidth, WB ); + hEncoderConfig->max_bwidth = max( hEncoderConfig->max_bwidth, WB ); /* Q0 */ + move16(); } st_ivas->ism_mode = ISM_MODE_NONE; st_ivas->mc_mode = MC_MODE_NONE; + move32(); + move32(); st_ivas->nchan_transport = -1; + move16(); /*-----------------------------------------------------------------* * Allocate floating-point input audio buffers *-----------------------------------------------------------------*/ - nchan_inp_buff = hEncoderConfig->nchan_inp; - if ( ivas_format == MONO_FORMAT ) + nchan_inp_buff = hEncoderConfig->nchan_inp; /* Q0 */ + move16(); + + IF( EQ_32( ivas_format, MONO_FORMAT ) ) { nchan_inp_buff = 0; + move16(); } - else if ( ivas_format == MASA_ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { - if ( hEncoderConfig->nchan_inp - hEncoderConfig->nchan_ism == 1 ) /* mono is duplicated in monoMASA */ + if ( EQ_32( sub( hEncoderConfig->nchan_inp, hEncoderConfig->nchan_ism ), 1 ) ) /* mono is duplicated in monoMASA */ { - nchan_inp_buff++; + nchan_inp_buff = add( nchan_inp_buff, 1 ); } - nchan_inp_buff++; /* for *data_separated_object */ + nchan_inp_buff = add( nchan_inp_buff, 1 ); /* for *data_separated_object */ } FOR( n = 0; n < nchan_inp_buff; n++ ) @@ -520,10 +543,11 @@ ivas_error ivas_init_encoder( *-----------------------------------------------------------------*/ /* set the maximum allowed number of indices in the list */ - st_ivas->ivas_max_num_indices = get_ivas_max_num_indices_fx( ivas_format, ivas_total_brate ); + st_ivas->ivas_max_num_indices = get_ivas_max_num_indices_fx( ivas_format, ivas_total_brate ); /* Q0 */ + move16(); /* allocate buffer of indices */ - if ( ( st_ivas->ind_list = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices * sizeof( Indice ) ) ) == NULL ) + IF( ( st_ivas->ind_list = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices * sizeof( Indice ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of indices!\n" ) ); } @@ -532,15 +556,17 @@ ivas_error ivas_init_encoder( for ( i = 0; i < st_ivas->ivas_max_num_indices; i++ ) { st_ivas->ind_list[i].nb_bits = -1; + move16(); } /* set the maximum allowed number of metadata indices in the list */ - st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata_fx( st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate ); + st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata_fx( st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate ); /* Q0 */ + move16(); /* allocate buffer of metadata indices */ - if ( st_ivas->ivas_max_num_indices_metadata > 0 ) + IF( st_ivas->ivas_max_num_indices_metadata > 0 ) { - if ( ( st_ivas->ind_list_metadata = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices_metadata * sizeof( Indice ) ) ) == NULL ) + IF( ( st_ivas->ind_list_metadata = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices_metadata * sizeof( Indice ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of metadata indices!\n" ) ); } @@ -549,9 +575,10 @@ ivas_error ivas_init_encoder( for ( i = 0; i < st_ivas->ivas_max_num_indices_metadata; i++ ) { st_ivas->ind_list_metadata[i].nb_bits = -1; + move16(); } } - else + ELSE { st_ivas->ind_list_metadata = NULL; } @@ -560,7 +587,7 @@ ivas_error ivas_init_encoder( * Allocate and initialize SCE/CPE and other handles *-----------------------------------------------------------------*/ - if ( ivas_format == MONO_FORMAT ) + IF( EQ_32( ivas_format, MONO_FORMAT ) ) { st_ivas->nSCE = 1; /* in mono, there is always only one SCE */ move16(); @@ -572,87 +599,92 @@ ivas_error ivas_init_encoder( move16(); test(); - IF( NE_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) ) + IF( st_ivas->hEncoderConfig->element_mode_init != EVS_MONO ) { - IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, ivas_total_brate ) ) != IVAS_ERR_OK ) { return error; } } ELSE { - IF( NE_32( ( error = create_evs_sce_enc( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) + IF( ( error = create_evs_sce_enc( st_ivas, sce_id, ivas_total_brate ) ) != IVAS_ERR_OK ) { return error; } } /* prepare stereo downmix for EVS */ - if ( hEncoderConfig->stereo_dmx_evs == 1 ) + IF( EQ_16( hEncoderConfig->stereo_dmx_evs, 1 ) ) { - if ( ( error = stereo_dmx_evs_init_encoder_fx( &( st_ivas->hStereoDmxEVS ), input_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = stereo_dmx_evs_init_encoder_fx( &( st_ivas->hStereoDmxEVS ), input_Fs ) ) != IVAS_ERR_OK ) { return error; } } } - else if ( ivas_format == STEREO_FORMAT ) + ELSE IF( EQ_32( ivas_format, STEREO_FORMAT ) ) { st_ivas->nSCE = 0; st_ivas->nCPE = 1; /* in stereo, there is always only one CPE */ st_ivas->nchan_transport = CPE_CHANNELS; cpe_id = 0; + move16(); + move16(); + move16(); + move16(); - if ( ( error = create_cpe_enc_fx( st_ivas, cpe_id, ivas_total_brate ) ) != IVAS_ERR_OK ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, ivas_total_brate ) ) != IVAS_ERR_OK ) { return error; } } - else if ( ivas_format == ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, ISM_FORMAT ) ) { st_ivas->ism_mode = ivas_ism_mode_select( hEncoderConfig->nchan_inp, ivas_total_brate ); - if ( ( error = ivas_ism_metadata_enc_create_fx( 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; } - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - if ( ( error = create_sce_enc_fx( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) { return error; } } - if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { - if ( ( error = ivas_param_ism_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_param_ism_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } - if ( st_ivas->hEncoderConfig->Opt_DTX_ON ) + IF( st_ivas->hEncoderConfig->Opt_DTX_ON ) { - if ( ( error = ivas_ism_dtx_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_dtx_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } } - else if ( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT ) + ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, MASA_FORMAT ) ) { IF( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { return error; } - if ( ivas_format == SBA_FORMAT ) + IF( EQ_32( ivas_format, SBA_FORMAT ) ) { - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); /* Q0 */ + move16(); - if ( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -662,74 +694,82 @@ ivas_error ivas_init_encoder( return error; } } - else + ELSE { - st_ivas->nchan_transport = hEncoderConfig->nchan_inp; + st_ivas->nchan_transport = hEncoderConfig->nchan_inp; /* Q0 */ + move16(); - if ( ( error = ivas_masa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_masa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { IF( ( error = create_sce_enc_fx( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) { return error; } - if ( ivas_format == SBA_FORMAT && st_ivas->hEncoderConfig->Opt_DTX_ON ) + if ( EQ_32( ivas_format, SBA_FORMAT ) && st_ivas->hEncoderConfig->Opt_DTX_ON ) { st_ivas->hSCE[sce_id]->hCoreCoder[0]->dtx_sce_sba = 1; + move16(); } } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - if ( ( error = create_cpe_enc_fx( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) { return error; } - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { if ( hEncoderConfig->Opt_DTX_ON ) { st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1; + move16(); } } } - if ( st_ivas->nCPE > 1 ) + IF( GT_16( st_ivas->nCPE, 1 ) ) { - if ( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } } - else if ( ivas_format == MASA_ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { Word32 ism_total_brate; Word16 k; - st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, hEncoderConfig->nchan_ism ); + st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, hEncoderConfig->nchan_ism ); /* Q0 */ move32(); st_ivas->nchan_transport = 2; + move16(); - if ( ( error = ivas_ism_metadata_enc_create_fx( 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; } k = 0; - while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] ) + move16(); + while ( k < SIZE_IVAS_BRATE_TBL && NE_32( ivas_total_brate, ivas_brate_tbl[k] ) ) { k++; } ism_total_brate = 0; + move32(); FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { ism_total_brate = L_add( ism_total_brate, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); @@ -743,43 +783,45 @@ ivas_error ivas_init_encoder( { return error; } - if ( ( error = ivas_masa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_masa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - if ( ( error = ivas_omasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_omasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } - if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) + if ( GE_32( L_sub( ivas_total_brate, ism_total_brate ), MIN_BRATE_MDCT_STEREO ) ) { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + move16(); } else { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; + move16(); } - if ( ( error = create_cpe_enc_fx( st_ivas, 0, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) + IF( ( error = create_cpe_enc_fx( st_ivas, 0, L_sub( ivas_total_brate, ism_total_brate ) ) ) != IVAS_ERR_OK ) { return error; } } - else if ( ivas_format == SBA_ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { st_ivas->ism_mode = ISM_MODE_NONE; - if ( ivas_total_brate >= IVAS_256k ) + if ( GE_32( ivas_total_brate, IVAS_256k ) ) { st_ivas->ism_mode = ISM_SBA_MODE_DISC; } - if ( ( error = ivas_ism_metadata_enc_create_fx( 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; } @@ -791,8 +833,9 @@ ivas_error ivas_init_encoder( } st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); + move16(); - if ( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -802,7 +845,7 @@ ivas_error ivas_init_encoder( return error; } - if ( st_ivas->ism_mode == ISM_MODE_NONE ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_NONE ) ) { /* allocate and initialize SBA core-coders */ IF( EQ_16( st_ivas->nchan_transport, 1 ) ) @@ -813,132 +856,148 @@ ivas_error ivas_init_encoder( } } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - if ( ( error = create_cpe_enc_fx( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) { return error; } } - if ( st_ivas->nCPE > 1 ) + IF( GT_16( st_ivas->nCPE, 1 ) ) { - if ( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } } - else + ELSE { /* allocate and initialize MCT core coder */ - st_ivas->nCPE += ( st_ivas->hEncoderConfig->nchan_ism + 1 ) >> 1; + st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->hEncoderConfig->nchan_ism, 1 ), 1 ) ); - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - if ( ( error = create_cpe_enc_fx( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) { return error; } } - if ( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } - if ( ( error = ivas_osba_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_osba_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } - else if ( ivas_format == MC_FORMAT ) + ELSE IF( EQ_32( ivas_format, MC_FORMAT ) ) { - st_ivas->mc_mode = ivas_mc_mode_select_fx( hEncoderConfig->mc_input_setup, ivas_total_brate ); + st_ivas->mc_mode = ivas_mc_mode_select_fx( hEncoderConfig->mc_input_setup, ivas_total_brate ); /* Q0 */ - if ( ( error = ivas_create_lfe_lpf_enc_fx( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_create_lfe_lpf_enc_fx( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) { return error; } - if ( st_ivas->mc_mode == MC_MODE_MCT ) + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { st_ivas->nSCE = 0; - st_ivas->nCPE = hEncoderConfig->nchan_inp / CPE_CHANNELS; + st_ivas->nCPE = idiv1616( hEncoderConfig->nchan_inp, CPE_CHANNELS ); /* Q0 */ + move16(); + move16(); - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - if ( ( error = create_cpe_enc_fx( st_ivas, cpe_id, ( ivas_total_brate / ( hEncoderConfig->nchan_inp - 1 ) * CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, sub( hEncoderConfig->nchan_inp, 1 ), &res_dec, &res_frac, 0 ); + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) { return error; } } - if ( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - if ( ( error = ivas_create_lfe_enc_fx( &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; } - st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels_fx( st_ivas->hEncoderConfig->mc_input_setup ); + st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels_fx( st_ivas->hEncoderConfig->mc_input_setup ); /* Q0 */ + move16(); } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { st_ivas->nSCE = 0; st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS / 2; st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; + move16(); + move16(); + move16(); - if ( ( error = ivas_mc_paramupmix_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mc_paramupmix_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - if ( ( error = create_cpe_enc_fx( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nCPE, &res_dec, &res_frac, 0 ); + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, res_dec ) ) != IVAS_ERR_OK ) { return error; } } - if ( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - if ( ( error = ivas_create_lfe_enc_fx( &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; } } - else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { - if ( ( error = ivas_param_mc_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_param_mc_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - if ( ( error = create_cpe_enc_fx( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nCPE + st_ivas->nSCE ) ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nCPE, st_ivas->nSCE ), &res_dec, &res_frac, 0 ); + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, res_dec ) ) != IVAS_ERR_OK ) { return error; } } - if ( st_ivas->nCPE > 1 ) + IF( GT_16( st_ivas->nCPE, 1 ) ) { - if ( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } } - else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { Word32 brate_sce, brate_cpe; @@ -949,11 +1008,11 @@ ivas_error ivas_init_encoder( return error; } - if ( ( error = ivas_masa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_masa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - if ( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -968,11 +1027,12 @@ ivas_error ivas_init_encoder( } } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + move16(); - if ( ( error = create_cpe_enc_fx( st_ivas, cpe_id, brate_cpe ) ) != IVAS_ERR_OK ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, brate_cpe ) ) != IVAS_ERR_OK ) { return error; } @@ -985,7 +1045,8 @@ ivas_error ivas_init_encoder( *-----------------------------------------------------------------*/ /* set number of input channels used for analysis/coding */ - n = getNumChanAnalysis_fx( st_ivas ); + n = getNumChanAnalysis_fx( st_ivas ); /* Q0 */ + move16(); IF( n > 0 ) { @@ -1029,18 +1090,18 @@ ivas_error ivas_init_encoder_fx( hEncoderConfig = st_ivas->hEncoderConfig; ivas_format = hEncoderConfig->ivas_format; move32(); - input_Fs = hEncoderConfig->input_Fs; + input_Fs = hEncoderConfig->input_Fs; /* Q0 */ move32(); - ivas_total_brate = hEncoderConfig->ivas_total_brate; + ivas_total_brate = hEncoderConfig->ivas_total_brate; /* Q0 */ move32(); - hEncoderConfig->last_ivas_total_brate = ivas_total_brate; + hEncoderConfig->last_ivas_total_brate = ivas_total_brate; /* Q0 */ move32(); IF( NE_16( ivas_format, MONO_FORMAT ) ) { /* In IVAS, ensure that minimum coded bandwidth is WB */ - hEncoderConfig->max_bwidth = extract_l( L_max( hEncoderConfig->max_bwidth, WB ) ); + hEncoderConfig->max_bwidth = extract_l( L_max( hEncoderConfig->max_bwidth, WB ) ); /* Q0 */ move16(); } st_ivas->ism_mode = ISM_MODE_NONE; @@ -1055,7 +1116,7 @@ ivas_error ivas_init_encoder_fx( * Allocate floating-point input audio buffers *-----------------------------------------------------------------*/ - nchan_inp_buff = hEncoderConfig->nchan_inp; + nchan_inp_buff = hEncoderConfig->nchan_inp; /* Q0 */ move16(); IF( EQ_16( ivas_format, MONO_FORMAT ) ) { @@ -1066,10 +1127,10 @@ ivas_error ivas_init_encoder_fx( { IF( EQ_16( sub( hEncoderConfig->nchan_inp, hEncoderConfig->nchan_ism ), 1 ) ) /* mono is duplicated in monoMASA */ { - nchan_inp_buff = add( nchan_inp_buff, 1 ); + nchan_inp_buff = add( nchan_inp_buff, 1 ); /* Q0 */ } - nchan_inp_buff = add( nchan_inp_buff, 1 ); /* for *data_separated_object */ + nchan_inp_buff = add( nchan_inp_buff, 1 ); /* for *data_separated_object Q0*/ } FOR( n = 0; n < nchan_inp_buff; n++ ) @@ -1091,7 +1152,7 @@ ivas_error ivas_init_encoder_fx( *-----------------------------------------------------------------*/ /* set the maximum allowed number of indices in the list */ - st_ivas->ivas_max_num_indices = get_ivas_max_num_indices_fx( ivas_format, ivas_total_brate ); + st_ivas->ivas_max_num_indices = get_ivas_max_num_indices_fx( ivas_format, ivas_total_brate ); /* Q0 */ move16(); /* allocate buffer of indices */ @@ -1108,7 +1169,7 @@ ivas_error ivas_init_encoder_fx( } /* set the maximum allowed number of metadata indices in the list */ - st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata_fx( st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate ); + st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata_fx( st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate ); /* Q0 */ move16(); /* allocate buffer of metadata indices */ IF( st_ivas->ivas_max_num_indices_metadata > 0 ) @@ -1134,7 +1195,7 @@ ivas_error ivas_init_encoder_fx( * Allocate and initialize SCE/CPE and other handles *-----------------------------------------------------------------*/ test(); - IF( EQ_16( ivas_format, MONO_FORMAT ) ) + IF( EQ_32( ivas_format, MONO_FORMAT ) ) { st_ivas->nSCE = 1; /* in mono, there is always only one SCE */ move16(); @@ -1146,16 +1207,16 @@ ivas_error ivas_init_encoder_fx( move16(); test(); - IF( EQ_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) ) + IF( st_ivas->hEncoderConfig->element_mode_init == EVS_MONO ) { - IF( NE_32( ( error = create_evs_sce_enc( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) + IF( ( error = create_evs_sce_enc( st_ivas, sce_id, ivas_total_brate ) ) != IVAS_ERR_OK ) { return error; } } ELSE { - IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, ivas_total_brate ) ) != IVAS_ERR_OK ) { return error; } @@ -1164,13 +1225,13 @@ ivas_error ivas_init_encoder_fx( /* prepare stereo downmix for EVS */ IF( EQ_16( hEncoderConfig->stereo_dmx_evs, 1 ) ) { - IF( NE_32( ( error = stereo_dmx_evs_init_encoder_fx( &( st_ivas->hStereoDmxEVS ), input_Fs ) ), IVAS_ERR_OK ) ) + IF( ( error = stereo_dmx_evs_init_encoder_fx( &( st_ivas->hStereoDmxEVS ), input_Fs ) ) != IVAS_ERR_OK ) { return error; } } } - ELSE IF( ivas_format == STEREO_FORMAT ) + ELSE IF( EQ_32( ivas_format, STEREO_FORMAT ) ) { st_ivas->nSCE = 0; move16(); @@ -1181,24 +1242,24 @@ ivas_error ivas_init_encoder_fx( cpe_id = 0; move16(); - IF( NE_32( ( error = create_cpe_enc_fx( st_ivas, cpe_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, ivas_total_brate ) ) != IVAS_ERR_OK ) { return error; } } ELSE IF( EQ_32( ivas_format, ISM_FORMAT ) ) { - st_ivas->ism_mode = ivas_ism_mode_select( hEncoderConfig->nchan_inp, ivas_total_brate ); + st_ivas->ism_mode = ivas_ism_mode_select( hEncoderConfig->nchan_inp, ivas_total_brate ); /* Q0 */ move32(); - IF( NE_32( ( error = ivas_ism_metadata_enc_create_fx( 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; } FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, element_brate_tmp[sce_id] ) ), IVAS_ERR_OK ) ) + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) { return error; } @@ -1206,7 +1267,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_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_param_ism_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1214,7 +1275,7 @@ ivas_error ivas_init_encoder_fx( IF( st_ivas->hEncoderConfig->Opt_DTX_ON ) { - IF( NE_32( ( error = ivas_ism_dtx_open( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_ism_dtx_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1222,31 +1283,31 @@ ivas_error ivas_init_encoder_fx( } ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, MASA_FORMAT ) ) { - IF( NE_32( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { return error; } IF( EQ_32( ivas_format, SBA_FORMAT ) ) { - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); /* Q0 */ move16(); - IF( NE_32( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) { return error; } - IF( NE_32( ( error = ivas_dirac_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_dirac_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } ELSE { - st_ivas->nchan_transport = hEncoderConfig->nchan_inp; + st_ivas->nchan_transport = hEncoderConfig->nchan_inp; /* Q0 */ move16(); - IF( NE_32( ( error = ivas_masa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_masa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1256,7 +1317,7 @@ ivas_error ivas_init_encoder_fx( { Word32 res_dec, res_frac; iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); - IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, res_dec ) ), IVAS_ERR_OK ) ) + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, res_dec ) ) != IVAS_ERR_OK ) { return error; } @@ -1272,7 +1333,7 @@ ivas_error ivas_init_encoder_fx( { Word32 res_dec, res_frac; iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); - IF( NE_32( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ), IVAS_ERR_OK ) ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) { return error; } @@ -1289,7 +1350,7 @@ ivas_error ivas_init_encoder_fx( IF( st_ivas->nCPE > 1 ) { - IF( NE_32( ( error = create_mct_enc_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1300,12 +1361,12 @@ ivas_error ivas_init_encoder_fx( Word32 ism_total_brate; Word16 k; - st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, hEncoderConfig->nchan_ism ); + st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, hEncoderConfig->nchan_ism ); /* Q0 */ move32(); st_ivas->nchan_transport = 2; move16(); - IF( NE_32( ( error = ivas_ism_metadata_enc_create_fx( 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; } @@ -1315,32 +1376,32 @@ ivas_error ivas_init_encoder_fx( test(); WHILE( LT_16( k, SIZE_IVAS_BRATE_TBL ) && NE_32( ivas_total_brate, ivas_brate_tbl[k] ) ) { - k = add( k, 1 ); + k++; } ism_total_brate = 0; move32(); FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - ism_total_brate = L_add( ism_total_brate, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); - IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, sep_object_brate[k - 2][st_ivas->nSCE - 1] ) ), IVAS_ERR_OK ) ) + ism_total_brate = L_add( ism_total_brate, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); /* Q0 */ + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, sep_object_brate[k - 2][st_ivas->nSCE - 1] ) ) != IVAS_ERR_OK ) { return error; } } - IF( NE_32( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { return error; } - IF( NE_32( ( error = ivas_masa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_masa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - IF( NE_32( ( error = ivas_omasa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_omasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1357,7 +1418,7 @@ ivas_error ivas_init_encoder_fx( move16(); } - IF( NE_32( ( error = create_cpe_enc_fx( st_ivas, 0, L_sub( ivas_total_brate, ism_total_brate ) ) ), IVAS_ERR_OK ) ) + IF( ( error = create_cpe_enc_fx( st_ivas, 0, L_sub( ivas_total_brate, ism_total_brate ) ) ) != IVAS_ERR_OK ) { return error; } @@ -1373,25 +1434,25 @@ ivas_error ivas_init_encoder_fx( move32(); } - IF( NE_32( ( error = ivas_ism_metadata_enc_create_fx( 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; } /* allocate and initialize SBA handles */ - IF( NE_32( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { return error; } - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); /* Q0 */ - IF( NE_32( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) { return error; } - IF( NE_32( ( error = ivas_dirac_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_dirac_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1401,7 +1462,7 @@ ivas_error ivas_init_encoder_fx( /* allocate and initialize SBA core-coders */ IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { - IF( NE_32( ( error = create_sce_enc_fx( st_ivas, 0, ivas_total_brate ) ), IVAS_ERR_OK ) ) + IF( ( error = create_sce_enc_fx( st_ivas, 0, ivas_total_brate ) ) != IVAS_ERR_OK ) { return error; } @@ -1411,7 +1472,7 @@ ivas_error ivas_init_encoder_fx( { Word32 res_dec, res_frac; iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); - IF( NE_32( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ), IVAS_ERR_OK ) ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) { return error; } @@ -1419,7 +1480,7 @@ ivas_error ivas_init_encoder_fx( IF( GT_16( st_ivas->nCPE, 1 ) ) { - IF( NE_32( ( error = create_mct_enc_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1428,34 +1489,34 @@ ivas_error ivas_init_encoder_fx( ELSE { /* allocate and initialize MCT core coder */ - st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->hEncoderConfig->nchan_ism, 1 ), 1 ) ); + st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->hEncoderConfig->nchan_ism, 1 ), 1 ) ); /* Q0 */ FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { Word32 res_dec, res_frac; iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); - IF( NE_32( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ), IVAS_ERR_OK ) ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) { return error; } } - IF( NE_32( ( error = create_mct_enc_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } - IF( NE_32( ( error = ivas_osba_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_osba_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } ELSE IF( EQ_32( ivas_format, MC_FORMAT ) ) { - st_ivas->mc_mode = ivas_mc_mode_select_fx( hEncoderConfig->mc_input_setup, ivas_total_brate ); + st_ivas->mc_mode = ivas_mc_mode_select_fx( hEncoderConfig->mc_input_setup, ivas_total_brate ); /* Q0 */ move32(); - IF( NE_32( ( error = ivas_create_lfe_lpf_enc_fx( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_create_lfe_lpf_enc_fx( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -1464,30 +1525,30 @@ ivas_error ivas_init_encoder_fx( { st_ivas->nSCE = 0; move16(); - st_ivas->nCPE = idiv1616( hEncoderConfig->nchan_inp, CPE_CHANNELS ); + st_ivas->nCPE = idiv1616( hEncoderConfig->nchan_inp, CPE_CHANNELS ); /* Q0 */ move16(); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { Word32 res_dec, res_frac; iDiv_and_mod_32( ivas_total_brate, sub( hEncoderConfig->nchan_inp, 1 ), &res_dec, &res_frac, 0 ); - IF( NE_32( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ), IVAS_ERR_OK ) ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) { return error; } } - IF( NE_32( ( error = create_mct_enc_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - IF( NE_32( ( error = ivas_create_lfe_enc_fx( &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; } - st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels_fx( st_ivas->hEncoderConfig->mc_input_setup ); + st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels_fx( st_ivas->hEncoderConfig->mc_input_setup ); /* Q0 */ move16(); } ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) @@ -1499,7 +1560,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_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_mc_paramupmix_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1508,32 +1569,32 @@ ivas_error ivas_init_encoder_fx( { Word32 res_dec, res_frac; iDiv_and_mod_32( ivas_total_brate, st_ivas->nCPE, &res_dec, &res_frac, 0 ); - IF( NE_32( ( error = create_cpe_enc_fx( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, res_dec ) ) != IVAS_ERR_OK ) { return error; } } - IF( NE_32( ( error = create_mct_enc_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - IF( NE_32( ( error = ivas_create_lfe_enc_fx( &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; } } - ELSE IF( st_ivas->mc_mode == MC_MODE_PARAMMC ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { - IF( NE_32( ( error = ivas_param_mc_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_param_mc_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - IF( NE_32( ( error = create_cpe_enc_fx( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nCPE + st_ivas->nSCE ) ) ), IVAS_ERR_OK ) ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nCPE + st_ivas->nSCE ) ) ) != IVAS_ERR_OK ) { return error; } @@ -1541,7 +1602,7 @@ ivas_error ivas_init_encoder_fx( IF( GT_16( st_ivas->nCPE, 1 ) ) { - IF( NE_32( ( error = create_mct_enc_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1553,17 +1614,17 @@ ivas_error ivas_init_encoder_fx( ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( hEncoderConfig->element_mode_init ), ivas_total_brate ); - IF( NE_32( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { return error; } - IF( NE_32( ( error = ivas_masa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_masa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - IF( NE_32( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1571,7 +1632,7 @@ ivas_error ivas_init_encoder_fx( FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, brate_sce ) ), IVAS_ERR_OK ) ) + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) { return error; } @@ -1579,10 +1640,10 @@ ivas_error ivas_init_encoder_fx( FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; /* Q0 */ move16(); - IF( NE_32( ( error = create_cpe_enc_fx( st_ivas, cpe_id, brate_cpe ) ), IVAS_ERR_OK ) ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, brate_cpe ) ) != IVAS_ERR_OK ) { return error; } @@ -1932,16 +1993,17 @@ void destroy_evs_core_enc_fx( /*------------------------------------------------------------------------- - * ivas_destroy_enc() + * ivas_destroy_enc_fx() * * Close IVAS encoder handles *-------------------------------------------------------------------------*/ -void ivas_destroy_enc( +void ivas_destroy_enc_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { Word16 i, n, nchan_inp; nchan_inp = st_ivas->hEncoderConfig->nchan_inp; + move16(); /* SCE handles */ for ( i = 0; i < MAX_SCE; i++ ) @@ -1966,7 +2028,7 @@ void ivas_destroy_enc( /* HP20 filter handles */ if ( st_ivas->mem_hp20_in_fx != NULL ) { - n = getNumChanAnalysis_fx( st_ivas ); + n = getNumChanAnalysis_fx( st_ivas ); /* Q0 */ for ( i = 0; i < n; i++ ) { @@ -2030,27 +2092,27 @@ void ivas_destroy_enc( stereo_dmx_evs_close_encoder_fx( &( st_ivas->hStereoDmxEVS ) ); /* Encoder configuration handle */ - if ( st_ivas->hEncoderConfig != NULL ) + IF( st_ivas->hEncoderConfig != NULL ) { free( st_ivas->hEncoderConfig ); st_ivas->hEncoderConfig = NULL; } /* Buffer of indices */ - if ( st_ivas->ind_list != NULL ) + IF( st_ivas->ind_list != NULL ) { free( st_ivas->ind_list ); } - if ( st_ivas->ind_list_metadata != NULL ) + IF( st_ivas->ind_list_metadata != NULL ) { free( st_ivas->ind_list_metadata ); } /* floating-point input audio buffers */ - for ( n = 0; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) + FOR( n = 0; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) { - if ( st_ivas->p_data_fx[n] != NULL ) + IF( st_ivas->p_data_fx[n] != NULL ) { free( st_ivas->p_data_fx[n] ); st_ivas->p_data_fx[n] = NULL; @@ -2064,12 +2126,12 @@ void ivas_destroy_enc( } /*------------------------------------------------------------------------- - * ivas_initialize_MD_bstr_enc() + * ivas_initialize_MD_bstr_enc_fx() * * Allocate and initialize SCE/CPE MD bitstream handle *-------------------------------------------------------------------------*/ -ivas_error ivas_initialize_MD_bstr_enc( +ivas_error ivas_initialize_MD_bstr_enc_fx( BSTR_ENC_HANDLE *hMetaData_out, /* o : encoder MD bitstream handle */ Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) @@ -2084,7 +2146,7 @@ ivas_error ivas_initialize_MD_bstr_enc( /* set pointer to the buffer of metadata indices */ hMetaData->ind_list = st_ivas->ind_list_metadata; hMetaData->ivas_ind_list_zero = &st_ivas->ind_list_metadata; - hMetaData->ivas_max_num_indices = &st_ivas->ivas_max_num_indices_metadata; + hMetaData->ivas_max_num_indices = &st_ivas->ivas_max_num_indices_metadata; /* Q0 */ hMetaData->st_ivas = st_ivas; reset_indices_enc( hMetaData, st_ivas->ivas_max_num_indices_metadata ); @@ -2096,12 +2158,12 @@ ivas_error ivas_initialize_MD_bstr_enc( /*------------------------------------------------------------------------- - * ivas_destroy_MD_bstr_enc() + * ivas_destroy_MD_bstr_enc_fx() * * Destroy SCE/CPE MD bitstream handle *-------------------------------------------------------------------------*/ -void ivas_destroy_MD_bstr_enc( +void ivas_destroy_MD_bstr_enc_fx( BSTR_ENC_HANDLE *hMetaData /* i/o: encoder MD bitstream handle */ ) { diff --git a/lib_enc/ivas_ism_dtx_enc.c b/lib_enc/ivas_ism_dtx_enc.c index 791404a11104208056aa91fb8bc18c7e6e609904..68325273e092f1c9608c867abaef91c9e31f293c 100644 --- a/lib_enc/ivas_ism_dtx_enc.c +++ b/lib_enc/ivas_ism_dtx_enc.c @@ -108,13 +108,13 @@ ivas_error ivas_ism_dtx_open( Word16 ivas_ism_dtx_enc_fx( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word16 nchan_ism, /* i : number of objects */ - const Word16 nchan_transport, /* i : number of transport channels */ - Word16 vad_flag[MAX_NUM_OBJECTS], /* i : VAD flag */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + const Word16 nchan_ism, /* i : number of objects Q0*/ + const Word16 nchan_transport, /* i : number of transport channels Q0*/ + Word16 vad_flag[MAX_NUM_OBJECTS], /* i : VAD flag Q0*/ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - Word16 md_diff_flag[], /* o : metadata differential flag */ - Word16 *sid_flag /* o : indication of SID frame */ + Word16 md_diff_flag[], /* o : metadata differential flag Q0*/ + Word16 *sid_flag /* o : indication of SID frame Q0*/ ) { Word16 ch, dtx_flag; @@ -139,7 +139,7 @@ Word16 ivas_ism_dtx_enc_fx( move16(); FOR( ch = 0; ch < nchan_transport; ch++ ) { - dtx_flag = s_and( dtx_flag, !vad_flag[ch] ); + dtx_flag = s_and( dtx_flag, !vad_flag[ch] ); /* Q0 */ } /* compute global ISM based on long-term background noise */ @@ -222,33 +222,33 @@ Word16 ivas_ism_dtx_enc_fx( } /* estimate SID metadata bit-budget */ - nBits = add( nBits, 1 ); /* number of objects */ - nBits = add( nBits, 1 ); /* SID metadata flag */ + nBits = add( nBits, 1 ); /* number of objects Q0*/ + nBits = add( nBits, 1 ); /* SID metadata flag Q0*/ IF( EQ_16( md_diff_flag[ch], 1 ) ) { - nBits = add( nBits, nBits_azimuth ); - nBits = add( nBits, nBits_elevation ); + nBits = add( nBits, nBits_azimuth ); /* Q0 */ + nBits = add( nBits, nBits_elevation ); /* Q0 */ } } /* calculate maximum available MD bit-budget */ nBits_MD_max = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC; move16(); - nBits_MD_max = sub( nBits_MD_max, SID_FORMAT_NBITS ); + nBits_MD_max = sub( nBits_MD_max, SID_FORMAT_NBITS ); /* Q0 */ if ( GT_16( nchan_transport, 1 ) ) { - nBits_MD_max = sub( nBits_MD_max, nBits_sce_id ); + nBits_MD_max = sub( nBits_MD_max, nBits_sce_id ); /* Q0 */ } FOR( ch = 0; ch < nchan_transport - 1; ch++ ) { - nBits_MD_max = sub( nBits_MD_max, nBits_coh ); /* coherence */ + nBits_MD_max = sub( nBits_MD_max, nBits_coh ); /* coherence Q0*/ } if ( GT_16( nchan_ism, 3 ) ) { - nBits_MD_max = sub( nBits_MD_max, 1 ); /* ism_mode flag */ + nBits_MD_max = sub( nBits_MD_max, 1 ); /* ism_mode flag Q0*/ } /* too many metadata bits -> switch to active coding */ @@ -308,12 +308,12 @@ Word16 ivas_ism_dtx_enc_fx( } /* * update the global SID counter */ - hISMDTX->cnt_SID_ISM = add( hISMDTX->cnt_SID_ISM, 1 ); + hISMDTX->cnt_SID_ISM = add( hISMDTX->cnt_SID_ISM, 1 ); /* Q0 */ move16(); IF( GE_16( hISMDTX->cnt_SID_ISM, hSCE[0]->hCoreCoder[0]->hDtxEnc->max_SID ) ) { /* adaptive SID update interval */ - hSCE[0]->hCoreCoder[0]->hDtxEnc->max_SID = hSCE[0]->hCoreCoder[0]->hDtxEnc->interval_SID; + hSCE[0]->hCoreCoder[0]->hDtxEnc->max_SID = hSCE[0]->hCoreCoder[0]->hDtxEnc->interval_SID; /* Q0 */ hISMDTX->cnt_SID_ISM = 0; move16(); move16(); @@ -326,7 +326,7 @@ Word16 ivas_ism_dtx_enc_fx( move32(); } - IF( EQ_16( hISMDTX->cnt_SID_ISM, 0 ) ) + IF( hISMDTX->cnt_SID_ISM == 0 ) { hSCE[hISMDTX->sce_id_dtx]->hCoreCoder[0]->core_brate = SID_2k40; *sid_flag = 1; @@ -336,7 +336,7 @@ Word16 ivas_ism_dtx_enc_fx( } test(); - IF( EQ_16( dtx_flag, 1 ) && EQ_16( *sid_flag, 0 ) ) + IF( EQ_16( dtx_flag, 1 ) && *sid_flag == 0 ) { set16_fx( md_diff_flag, 0, nchan_transport ); } @@ -352,8 +352,8 @@ Word16 ivas_ism_dtx_enc_fx( void ivas_ism_get_sce_id_dtx_fx( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ - const Word16 nchan_transport, /* i : number of transport channels */ - const Word16 input_frame /* i : input frame length per channel */ + const Word16 nchan_transport, /* i : number of transport channels Q0*/ + const Word16 input_frame /* i : input frame length per channel Q0*/ ) { Word32 tmp_energy[MAX_NUM_OBJECTS]; @@ -380,7 +380,7 @@ void ivas_ism_get_sce_id_dtx_fx( { FOR( i = 0; i < ( PARAM_ISM_HYS_BUF_SIZE - 1 ); i++ ) { - hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][i] = hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][i + 1]; + hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][i] = hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][i + 1]; /* exp(hISMDTX->long_term_energy_stereo_dmx_enc_e) */ move32(); } long_term_energy_stereo_dmx_enc_e[j] = 20; @@ -404,10 +404,10 @@ void ivas_ism_get_sce_id_dtx_fx( { FOR( i = 0; i < PARAM_ISM_HYS_BUF_SIZE - 1; i++ ) { - hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][i] = L_shr( hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][i], max_exp - hISMDTX->long_term_energy_stereo_dmx_enc_e ); + hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][i] = L_shr( hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][i], max_exp - hISMDTX->long_term_energy_stereo_dmx_enc_e ); /* exp(max_exp) */ move32(); } - hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][PARAM_ISM_HYS_BUF_SIZE - 1] = L_shr( hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][PARAM_ISM_HYS_BUF_SIZE - 1], max_exp - long_term_energy_stereo_dmx_enc_e[j] ); + hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][PARAM_ISM_HYS_BUF_SIZE - 1] = L_shr( hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][PARAM_ISM_HYS_BUF_SIZE - 1], max_exp - long_term_energy_stereo_dmx_enc_e[j] ); /* exp(max_exp) */ move32(); } hISMDTX->long_term_energy_stereo_dmx_enc_e = max_exp; @@ -433,10 +433,10 @@ void ivas_ism_get_sce_id_dtx_fx( * *-------------------------------------------------------------------*/ void ivas_ism_coh_estim_dtx_enc_fx( - ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ - SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ - const Word16 nchan_transport, /* i : number of transport channels */ - const Word16 input_frame /* i : input frame length */ + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word16 nchan_transport, /* i : number of transport channels Q0*/ + const Word16 input_frame /* i : input frame length Q0*/ ) { Encoder_State *st, *st_id0; @@ -465,7 +465,7 @@ void ivas_ism_coh_estim_dtx_enc_fx( norm_inp = norm_l( st_id0->input32_fx[i] ); scaled_inp = L_shl( st_id0->input32_fx[i], norm_inp ); tot_exp = shl( sub( 20, norm_inp ), 1 ); - acorr_ene_fx[hISMDTX->sce_id_dtx] = BASOP_Util_Add_Mant32Exp( acorr_ene_fx[hISMDTX->sce_id_dtx], acorr_ene_e[hISMDTX->sce_id_dtx], Mult_32_32( scaled_inp, scaled_inp ), tot_exp, &acorr_ene_e[hISMDTX->sce_id_dtx] ); + acorr_ene_fx[hISMDTX->sce_id_dtx] = BASOP_Util_Add_Mant32Exp( acorr_ene_fx[hISMDTX->sce_id_dtx], acorr_ene_e[hISMDTX->sce_id_dtx], Mult_32_32( scaled_inp, scaled_inp ), tot_exp, &acorr_ene_e[hISMDTX->sce_id_dtx] ); /* exp(acorr_ene_e) */ move32(); } @@ -473,7 +473,7 @@ void ivas_ism_coh_estim_dtx_enc_fx( { IF( EQ_16( sce_id, hISMDTX->sce_id_dtx ) ) { - hISMDTX->coh_fx[sce_id] = 32767; + hISMDTX->coh_fx[sce_id] = 32767; /* 1 in Q15 */ move16(); continue; } @@ -492,14 +492,14 @@ void ivas_ism_coh_estim_dtx_enc_fx( norm_inp = norm_l( st->input32_fx[i] ); scaled_inp = L_shl( st->input32_fx[i], norm_inp ); tot_exp = shl( sub( 20, norm_inp ), 1 ); - acorr_ene_fx[sce_id] = BASOP_Util_Add_Mant32Exp( acorr_ene_fx[sce_id], acorr_ene_e[sce_id], Mult_32_32( scaled_inp, scaled_inp ), tot_exp, &acorr_ene_e[sce_id] ); + acorr_ene_fx[sce_id] = BASOP_Util_Add_Mant32Exp( acorr_ene_fx[sce_id], acorr_ene_e[sce_id], Mult_32_32( scaled_inp, scaled_inp ), tot_exp, &acorr_ene_e[sce_id] ); /* exp(acorr_ene_e) */ move32(); - xcorr_ene_fx = BASOP_Util_Add_Mant32Exp( xcorr_ene_fx, xcorr_ene_e, Mult_32_32( scaled_inp, scaled_inp ), tot_exp, &xcorr_ene_e ); + xcorr_ene_fx = BASOP_Util_Add_Mant32Exp( xcorr_ene_fx, xcorr_ene_e, Mult_32_32( scaled_inp, scaled_inp ), tot_exp, &xcorr_ene_e ); /* exp(xcorr_ene_e) */ } Word16 coh_e; Word16 temp_e = acorr_ene_e[hISMDTX->sce_id_dtx] + acorr_ene_e[sce_id]; Word32 temp = Sqrt32( L_add( Mult_32_32( acorr_ene_fx[hISMDTX->sce_id_dtx], acorr_ene_fx[sce_id] ), EPSILON_FX ), &temp_e ); /*fabsf( xcorr_ene ) / ( sqrtf( ( acorr_ene[hISMDTX->sce_id_dtx] * acorr_ene[sce_id] ) + EPSILON ) );*/ - hISMDTX->coh_fx[sce_id] = BASOP_Util_Divide3232_Scale( L_abs( xcorr_ene_fx ), temp, &coh_e ); + hISMDTX->coh_fx[sce_id] = BASOP_Util_Divide3232_Scale( L_abs( xcorr_ene_fx ), temp, &coh_e ); /* coh_e + (xcorr_ene_e - temp_e) */ move16(); coh_e = add( coh_e, sub( xcorr_ene_e, temp_e ) ); IF( coh_e < 0 ) @@ -509,7 +509,7 @@ void ivas_ism_coh_estim_dtx_enc_fx( coh_e = 0; } /* ensure value of coherence is between [0,1] */ - hISMDTX->coh_fx[sce_id] = check_bounds_s_fx( hISMDTX->coh_fx[sce_id], 0, shl_sat( 1, 15 - coh_e ) ); + hISMDTX->coh_fx[sce_id] = check_bounds_s_fx( hISMDTX->coh_fx[sce_id], 0, shl_sat( 1, 15 - coh_e ) ); /* Q0 */ hISMDTX->coh_fx[sce_id] = shl_sat( hISMDTX->coh_fx[sce_id], coh_e ); move16(); move16(); diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 11f1d4cb9fd022a85b0c1e39f0433c159b4440e5..6f8fb2b9f8b544950c3e55e3a7fc7d2c62e4a0bc 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -51,12 +51,12 @@ * ISM CoreCoders encoding routine *-------------------------------------------------------------------*/ ivas_error ivas_ism_enc_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - Word32 *data[], /* i : input signal [channels][samples] Q(q_data) */ - Word16 q_data, /* i : Q-factor of input signal */ - const Word16 input_frame, /* i : input frame length per channel */ - Word16 *nb_bits_metadata, /* i : number of metadata bits */ - const Word16 flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + Word32 *data[], /* i : input signal [channels][samples] Q(q_data)*/ + Word16 q_data, /* i : Q-factor of input signal */ + const Word16 input_frame, /* i : input frame length per channel Q0*/ + Word16 *nb_bits_metadata, /* i : number of metadata bits Q0*/ + const Word16 flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag Q0*/ ) { SCE_ENC_HANDLE hSCE; @@ -138,7 +138,7 @@ ivas_error ivas_ism_enc_fx( move16(); set16_fx( md_diff_flag, 1, nchan_ism ); - nchan_transport_ism = st_ivas->nchan_transport; + nchan_transport_ism = st_ivas->nchan_transport; /* Q0 */ move16(); IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { @@ -149,7 +149,7 @@ ivas_error ivas_ism_enc_fx( } ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - nchan_transport_ism = st_ivas->hEncoderConfig->nchan_ism; + nchan_transport_ism = st_ivas->hEncoderConfig->nchan_ism; /* Q0 */ move16(); } FOR( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ ) @@ -249,7 +249,7 @@ ivas_error ivas_ism_enc_fx( ); e_old_wsp[sce_id][0] = sub( Q15, q_old_wsp ); move16(); - IF( NE_32( error, IVAS_ERR_OK ) ) + IF( error != IVAS_ERR_OK ) { return error; } @@ -261,7 +261,7 @@ ivas_error ivas_ism_enc_fx( } ELSE { - vad_flag[sce_id] = st->vad_flag; + vad_flag[sce_id] = st->vad_flag; /* Q0 */ move16(); } } @@ -276,7 +276,7 @@ ivas_error ivas_ism_enc_fx( test(); IF( st_ivas->hSCE[j] && st_ivas->hSCE[j]->hCoreCoder[0] ) { - Copy_Scale_sig_16_32( st_ivas->hSCE[j]->hCoreCoder[0]->input_fx, st_ivas->hSCE[j]->hCoreCoder[0]->input32_fx, input_frame, sub( Q11, st_ivas->hSCE[j]->hCoreCoder[0]->q_inp ) ); + Copy_Scale_sig_16_32( st_ivas->hSCE[j]->hCoreCoder[0]->input_fx, st_ivas->hSCE[j]->hCoreCoder[0]->input32_fx, input_frame, sub( Q11, st_ivas->hSCE[j]->hCoreCoder[0]->q_inp ) ); /* Q11 */ st_ivas->hSCE[j]->hCoreCoder[0]->q_inp32 = Q11; move16(); } @@ -286,7 +286,7 @@ ivas_error ivas_ism_enc_fx( { ivas_ism_get_sce_id_dtx_fx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame ); - dtx_flag = ivas_ism_dtx_enc_fx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, st_ivas->nchan_transport, vad_flag, st_ivas->hIsmMetaData, md_diff_flag, &sid_flag ); + dtx_flag = ivas_ism_dtx_enc_fx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, st_ivas->nchan_transport, vad_flag, st_ivas->hIsmMetaData, md_diff_flag, &sid_flag ); /* Q0 */ IF( sid_flag ) { @@ -300,10 +300,10 @@ ivas_error ivas_ism_enc_fx( * Metadata quantization and encoding *-----------------------------------------------------------------*/ - IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { ivas_param_ism_compute_noisy_speech_flag_fx( st_ivas ); - flag_noisy_speech = st_ivas->hParamIsm->flag_noisy_speech; + flag_noisy_speech = st_ivas->hParamIsm->flag_noisy_speech; // Q0 move16(); } @@ -313,7 +313,7 @@ ivas_error ivas_ism_enc_fx( } ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { - 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 ) ) + IF( ( 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; } @@ -327,28 +327,49 @@ ivas_error ivas_ism_enc_fx( move16(); FOR( i = 0; i < st_ivas->nSCE; i++ ) { - ism_total_brate = L_add( ism_total_brate, st_ivas->hSCE[i]->element_brate ); + ism_total_brate = L_add( ism_total_brate, st_ivas->hSCE[i]->element_brate ); /* Q0 */ } } ELSE { - ism_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + ism_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; /* Q0 */ move32(); } - ism_total_brate_ref = ism_total_brate; + ism_total_brate_ref = ism_total_brate; /* Q0 */ move32(); - 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 ) ) + Word16 lp_noise_CPE_fx; + if ( st_ivas->hMasa != NULL ) + { + lp_noise_CPE_fx = st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx; + move16(); + } + else + { + lp_noise_CPE_fx = 0; + move16(); + } + + Word16 *omasa_stereo_sw_cnt; + if ( st_ivas->hMasa != NULL ) + { + omasa_stereo_sw_cnt = &( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt ); + } + else + { + omasa_stereo_sw_cnt = NULL; + } + IF( ( 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, lp_noise_CPE_fx, flag_omasa_ener_brate, omasa_stereo_sw_cnt, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ) != + IVAS_ERR_OK ) { return error; } IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { - st_ivas->hCPE[0]->brate_surplus = L_sub( ism_total_brate_ref, ism_total_brate ); + st_ivas->hCPE[0]->brate_surplus = L_sub( ism_total_brate_ref, ism_total_brate ); /* Q0 */ move32(); } } @@ -403,7 +424,7 @@ ivas_error ivas_ism_enc_fx( { Word16 igf; igf = getIgfPresent_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->max_bwidth, st->rf_mode ); - IF( NE_32( ( error = IGF_Reconfig_fx( &st->hIGFEnc, igf, 0, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->max_bwidth, st->element_mode, st->rf_mode ) ), IVAS_ERR_OK ) ) + IF( ( error = IGF_Reconfig_fx( &st->hIGFEnc, igf, 0, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->max_bwidth, st->element_mode, st->rf_mode ) ) != IVAS_ERR_OK ) { return error; } @@ -423,7 +444,7 @@ ivas_error ivas_ism_enc_fx( } ELSE { - st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->total_brate, 0, 0, -1, -1 ); + st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->total_brate, 0, 0, -1, -1 ); /* Q0 */ move16(); } @@ -437,7 +458,7 @@ ivas_error ivas_ism_enc_fx( test(); IF( !dtx_flag || ( dtx_flag && EQ_16( sce_id, st_ivas->hISMDTX->sce_id_dtx ) ) ) { - Scale_sig( old_wsp_fx[sce_id][0], L_WSP, sub( e_old_wsp[sce_id][0], Q16 ) ); + Scale_sig( old_wsp_fx[sce_id][0], L_WSP, sub( e_old_wsp[sce_id][0], Q16 ) ); /* exp(16) */ e_old_wsp[sce_id][0] = 16; move16(); IF( NE_32( ( error = ivas_core_enc_fx( hSCE, NULL, NULL, 1, old_inp_12k8_fx[sce_id], old_inp_16k_fx[sce_id], Q_new[sce_id], ener_fx[sce_id], A_fx[sce_id], Aw_fx[sce_id], epsP_fx[sce_id], epsP_fx_q[sce_id], lsp_new_fx[sce_id], lsp_mid_fx[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer_fx[sce_id], imagBuffer_fx[sce_id], &q_re_im_buf[sce_id], old_wsp_fx[sce_id], e_old_wsp[sce_id], loc_harm[sce_id], cor_map_sum_fx[sce_id], vad_flag_dtx[sce_id], enerBuffer_fx[sce_id], enerBuffer_fx_exp[sce_id], fft_buff_fx[sce_id], 0, ISM_FORMAT, 0 ) ), IVAS_ERR_OK ) ) @@ -452,15 +473,15 @@ ivas_error ivas_ism_enc_fx( /* update input samples buffer */ - Copy( st->input_fx, st->old_input_signal_fx, input_frame ); + Copy( st->input_fx, st->old_input_signal_fx, input_frame ); /* st->q_inp */ st->q_old_inp = st->q_inp; move16(); - hSCE->last_element_brate = hSCE->element_brate; + hSCE->last_element_brate = hSCE->element_brate; /* Q0 */ move32(); /* Store previous attack detection flag */ - st->hTranDet->transientDetector.prev_bIsAttackPresent = st->hTranDet->transientDetector.bIsAttackPresent; + st->hTranDet->transientDetector.prev_bIsAttackPresent = st->hTranDet->transientDetector.bIsAttackPresent; /* Q0 */ move16(); prev_st = st; @@ -472,9 +493,9 @@ ivas_error ivas_ism_enc_fx( { IF( NE_16( sce_id, st_ivas->hISMDTX->sce_id_dtx ) ) { - st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_core = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->last_core; - st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_core_brate = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->core_brate; - st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_L_frame = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->last_L_frame; + st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_core = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->last_core; /* Q0 */ + st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_core_brate = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->core_brate; /* Q0 */ + st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_L_frame = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->last_L_frame; /* Q0 */ move16(); move32(); move16(); @@ -509,7 +530,7 @@ ivas_error ivas_ism_enc_config( move16(); /* select ISM format mode */ - st_ivas->ism_mode = ivas_ism_mode_select( st_ivas->hEncoderConfig->nchan_inp, st_ivas->hEncoderConfig->ivas_total_brate ); + st_ivas->ism_mode = ivas_ism_mode_select( st_ivas->hEncoderConfig->nchan_inp, st_ivas->hEncoderConfig->ivas_total_brate ); /* Q0 */ move16(); /* ISM bit-rate switching */ @@ -518,7 +539,7 @@ ivas_error ivas_ism_enc_config( { Word32 element_brate_tmp[MAX_NUM_OBJECTS]; - nchan_transport_old = st_ivas->nchan_transport; + nchan_transport_old = st_ivas->nchan_transport; /* Q0 */ move16(); /* Reset and Initialize */ @@ -528,25 +549,25 @@ ivas_error ivas_ism_enc_config( } ELSE { - st_ivas->nchan_transport = st_ivas->hEncoderConfig->nchan_inp; + st_ivas->nchan_transport = st_ivas->hEncoderConfig->nchan_inp; /* Q0 */ } move16(); - nCPE_old = st_ivas->nCPE; + nCPE_old = st_ivas->nCPE; /* Q0 */ move16(); - nSCE_old = st_ivas->nSCE; + nSCE_old = st_ivas->nSCE; /* Q0 */ move16(); - st_ivas->nSCE = st_ivas->nchan_transport; + st_ivas->nSCE = st_ivas->nchan_transport; /* Q0 */ move16(); st_ivas->nCPE = 0; move16(); - IF( NE_32( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hEncoderConfig->nchan_inp, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hEncoderConfig->nchan_inp, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) { return error; } - IF( NE_32( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport, imult3216( ( st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport ), CPE_CHANNELS ), MC_MODE_NONE ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport, imult3216( ( st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport ), CPE_CHANNELS ), MC_MODE_NONE ) ) != IVAS_ERR_OK ) { return error; } @@ -555,7 +576,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_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( ( error = ivas_param_ism_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index f55be64697f53e17723c8f4741841c4991919189..d43ed74385f381091a49b835836edf37ec8461fd 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -430,7 +430,7 @@ ivas_error create_sce_enc_fx( test(); IF( NE_16( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) && EQ_16( sce_id, sub( st_ivas->nSCE, 1 ) ) ) { - IF( ( error = ivas_initialize_MD_bstr_enc( &( hSCE->hMetaData ), st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_initialize_MD_bstr_enc_fx( &( hSCE->hMetaData ), st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -521,7 +521,7 @@ ivas_error create_evs_sce_enc( test(); IF( NE_32( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) && EQ_16( sce_id, sub( st_ivas->nSCE, 1 ) ) ) { - IF( NE_32( ( error = ivas_initialize_MD_bstr_enc( &( hSCE->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_initialize_MD_bstr_enc_fx( &( hSCE->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -643,7 +643,7 @@ void destroy_sce_enc( } } - ivas_destroy_MD_bstr_enc( &( hSCE->hMetaData ) ); + ivas_destroy_MD_bstr_enc_fx( &( hSCE->hMetaData ) ); free( hSCE ); diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 21c876f565ee698627fd695c125579d7b356bf1d..ca209c66bfb548ad08aef2ebf26a63df125b16b7 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -1231,7 +1231,7 @@ static Word16 ivas_get_huffman_coded_bs_fx( FOR( j = pred_offset; j < pred_coeff_dim; j++ ) { - ivas_huffman_encode( &hMdEnc->huff_coeffs.pred_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j], &code, &len ); + ivas_huffman_encode_fx( &hMdEnc->huff_coeffs.pred_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j], &code, &len ); IF( GT_16( ( add( hMetaData->nb_bits_tot, len ) ), hMdEnc->spar_md_cfg.max_bits_per_blk ) ) { return -1; @@ -1242,7 +1242,7 @@ static Word16 ivas_get_huffman_coded_bs_fx( Word16 n = imult1616( ndec, sub( ndm, 1 ) ); FOR( j = 0; j < n; j++ ) { - ivas_huffman_encode( &hMdEnc->huff_coeffs.drct_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].drct_index_re[j], &code, &len ); + ivas_huffman_encode_fx( &hMdEnc->huff_coeffs.drct_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].drct_index_re[j], &code, &len ); IF( GT_16( ( add( hMetaData->nb_bits_tot, len ) ), hMdEnc->spar_md_cfg.max_bits_per_blk ) ) { return -1; @@ -1252,7 +1252,7 @@ static Word16 ivas_get_huffman_coded_bs_fx( FOR( j = 0; j < ndec; j++ ) { - ivas_huffman_encode( &hMdEnc->huff_coeffs.decd_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].decd_index_re[j], &code, &len ); + ivas_huffman_encode_fx( &hMdEnc->huff_coeffs.decd_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].decd_index_re[j], &code, &len ); IF( GT_16( ( add( hMetaData->nb_bits_tot, len ) ), hMdEnc->spar_md_cfg.max_bits_per_blk ) ) { return -1; @@ -1393,8 +1393,8 @@ static Word16 ivas_get_arith_coded_bs_fx( ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, nB, symbol_arr_old_re, pred_cell_dims, PRED_COEFF ); } - arith_result = ivas_arith_encode_cmplx_cell_array( &hMdEnc->arith_coeffs.pred_arith_re[qsi], &hMdEnc->arith_coeffs.pred_arith_re_diff[qsi], pDo_diff, nB, - symbol_arr_re, symbol_arr_old_re, pred_cell_dims, hMetaData, any_diff, hMdEnc->spar_md_cfg.max_bits_per_blk ); + arith_result = ivas_arith_encode_cmplx_cell_array_fx( &hMdEnc->arith_coeffs.pred_arith_re[qsi], &hMdEnc->arith_coeffs.pred_arith_re_diff[qsi], pDo_diff, nB, + symbol_arr_re, symbol_arr_old_re, pred_cell_dims, hMetaData, any_diff, hMdEnc->spar_md_cfg.max_bits_per_blk ); move16(); IF( arith_result < 0 ) { @@ -1431,8 +1431,8 @@ static Word16 ivas_get_arith_coded_bs_fx( } - arith_result = ivas_arith_encode_cmplx_cell_array( &hMdEnc->arith_coeffs.drct_arith_re[qsi], &hMdEnc->arith_coeffs.drct_arith_re_diff[qsi], pDo_diff, nB, - symbol_arr_re, symbol_arr_old_re, drct_cell_dims, hMetaData, any_diff, hMdEnc->spar_md_cfg.max_bits_per_blk ); + arith_result = ivas_arith_encode_cmplx_cell_array_fx( &hMdEnc->arith_coeffs.drct_arith_re[qsi], &hMdEnc->arith_coeffs.drct_arith_re_diff[qsi], pDo_diff, nB, + symbol_arr_re, symbol_arr_old_re, drct_cell_dims, hMetaData, any_diff, hMdEnc->spar_md_cfg.max_bits_per_blk ); move16(); IF( arith_result < 0 ) @@ -1447,8 +1447,8 @@ static Word16 ivas_get_arith_coded_bs_fx( ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, nB, symbol_arr_old_re, decd_cell_dims, DECD_COEFF ); } - arith_result = ivas_arith_encode_cmplx_cell_array( &hMdEnc->arith_coeffs.decd_arith_re[qsi], &hMdEnc->arith_coeffs.decd_arith_re_diff[qsi], pDo_diff, nB, - symbol_arr_re, symbol_arr_old_re, decd_cell_dims, hMetaData, any_diff, hMdEnc->spar_md_cfg.max_bits_per_blk ); + arith_result = ivas_arith_encode_cmplx_cell_array_fx( &hMdEnc->arith_coeffs.decd_arith_re[qsi], &hMdEnc->arith_coeffs.decd_arith_re_diff[qsi], pDo_diff, nB, + symbol_arr_re, symbol_arr_old_re, decd_cell_dims, hMetaData, any_diff, hMdEnc->spar_md_cfg.max_bits_per_blk ); move16(); IF( arith_result < 0 ) diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index aa1b6e32b7157d3cf1b90a91f3b9f0d4e2cf6e84..281e131f7390017a89e5b9cdf8fbac510946f70b 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -150,7 +150,7 @@ ivas_error IVAS_ENC_Open( init_encoder_config( st_ivas->hEncoderConfig ); /* initialize pointers to handles to NULL */ - ivas_initialize_handles_enc( st_ivas ); + ivas_initialize_handles_enc_fx( st_ivas ); st_ivas->ind_list = NULL; st_ivas->ind_list_metadata = NULL; @@ -216,7 +216,7 @@ ivas_error IVAS_ENC_Open_fx( init_encoder_config( st_ivas->hEncoderConfig ); /* initialize pointers to handles to NULL */ - ivas_initialize_handles_enc( st_ivas ); + ivas_initialize_handles_enc_fx( st_ivas ); st_ivas->ind_list = NULL; st_ivas->ind_list_metadata = NULL; @@ -246,7 +246,7 @@ void IVAS_ENC_Close( if ( ( *phIvasEnc )->isConfigured ) { - ivas_destroy_enc( ( *phIvasEnc )->st_ivas ); + ivas_destroy_enc_fx( ( *phIvasEnc )->st_ivas ); } else { diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 4e0b45e46aff6c27a7535ffe048f2b1a9134eb49..8a0c0b82933b1dca2ddb7053b878e1840b1f97b7 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -4714,9 +4714,9 @@ ivas_error init_encoder_fx( ); void copy_encoder_config_fx( - Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ - Encoder_State *st, /* o : encoder state structure */ - const Word16 flag_all /* i : flag 1==update all, 0=partial update*/ + Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ + Encoder_State *st, /* o : encoder state structure */ + const Word16 flag_all /* i : flag 1==update all, 0=partial update Q0*/ ); void destroy_encoder_fx(