From 32a86b0a772053fe1a8baffca888413d1c1524bc Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 8 Jul 2024 21:46:16 +0530 Subject: [PATCH 1/2] Integrated ivas_enc_cov_handler_process_fx function in MC path --- lib_com/ivas_cov_smooth.c | 91 ++--- lib_com/ivas_prot.h | 30 +- lib_com/ivas_prot_fx.h | 5 + lib_com/ivas_stat_com.h | 18 +- lib_com/ivas_tools.c | 67 +--- lib_enc/ivas_enc.c | 578 +++++++++++++++++++++++++++++-- lib_enc/ivas_enc_cov_handler.c | 139 ++++++-- lib_enc/ivas_init_enc.c | 273 ++++++++++++++- lib_enc/ivas_lfe_enc.c | 118 ++++++- lib_enc/ivas_mc_paramupmix_enc.c | 113 ++++++ lib_enc/ivas_osba_enc.c | 268 +++++++++++++- lib_enc/ivas_sba_enc.c | 247 ++++++++++++- lib_enc/ivas_spar_encoder.c | 18 + lib_enc/ivas_stat_enc.h | 14 +- 14 files changed, 1772 insertions(+), 207 deletions(-) diff --git a/lib_com/ivas_cov_smooth.c b/lib_com/ivas_cov_smooth.c index b7f195b9c..c1d35c45e 100644 --- a/lib_com/ivas_cov_smooth.c +++ b/lib_com/ivas_cov_smooth.c @@ -206,7 +206,6 @@ static void ivas_set_up_cov_smoothing_fx( Word16 active_bins = pFb->fb_bin_to_band.pFb_active_bins_per_band[j]; update_factor = ivas_calculate_update_factor_fx( pFb->fb_bin_to_band.pFb_bin_to_band_fx[j], active_bins ); ivas_calculate_smoothning_factor_fx( &hCovState->pSmoothing_factor_fx[j], update_factor, min_pool_size, max_update_rate, smooth_mode, ivas_total_brate, j ); - hCovState->pSmoothing_factor[j] = fixedToFloat( hCovState->pSmoothing_factor_fx[j], Q31 ); } } ELSE @@ -217,7 +216,6 @@ static void ivas_set_up_cov_smoothing_fx( Word16 active_bins = pFb->fb_bin_to_band.p_short_stride_num_bins_per_band[j]; update_factor = ivas_calculate_update_factor_fx( p_bin_to_band, active_bins ); ivas_calculate_smoothning_factor_fx( &hCovState->pSmoothing_factor_fx[j], update_factor, min_pool_size, max_update_rate, smooth_mode, ivas_total_brate, j ); - hCovState->pSmoothing_factor[j] = fixedToFloat( hCovState->pSmoothing_factor_fx[j], Q31 ); } } @@ -270,78 +268,65 @@ static void ivas_set_up_cov_smoothing( #endif +#ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- - * ivas_spar_covar_smooth_enc_open() + * ivas_spar_covar_smooth_enc_open_fx() * * Allocate and initialize SPAR Covar. smoothing handle *------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_spar_covar_smooth_enc_open( +ivas_error ivas_spar_covar_smooth_enc_open_fx( ivas_cov_smooth_state_t **hCovState_out, /* i/o: SPAR Covar. smoothing handle */ const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i : SPAR config. handle */ ivas_filterbank_t *pFb, /* i/o: FB handle */ - const int16_t nchan_inp, /* i : number of input channels */ + const Word16 nchan_inp, /* i : number of input channels */ const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ ) { ivas_cov_smooth_state_t *hCovState; - int16_t i, j; + Word16 i, j; - if ( ( hCovState = (ivas_cov_smooth_state_t *) malloc( sizeof( ivas_cov_smooth_state_t ) ) ) == NULL ) + IF( ( hCovState = (ivas_cov_smooth_state_t *) malloc( sizeof( ivas_cov_smooth_state_t ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" ); } -#ifdef IVAS_FLOAT_FIXED IF( ( hCovState->pSmoothing_factor_fx = (Word32 *) malloc( sizeof( Word32 ) * cov_smooth_cfg->max_bands ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" ); } -#endif - if ( ( hCovState->pSmoothing_factor = (float *) malloc( sizeof( float ) * cov_smooth_cfg->max_bands ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" ); - } - for ( i = 0; i < nchan_inp; i++ ) + FOR( i = 0; i < nchan_inp; i++ ) { - for ( j = 0; j < nchan_inp; j++ ) + FOR( j = 0; j < nchan_inp; j++ ) { - if ( ( hCovState->pPrior_cov_real[i][j] = (float *) malloc( sizeof( float ) * cov_smooth_cfg->max_bands ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" ); - } - set_zero( hCovState->pPrior_cov_real[i][j], cov_smooth_cfg->max_bands ); -#ifdef IVAS_FLOAT_FIXED - if ( ( hCovState->pPrior_cov_real_fx[i][j] = (Word32 *) malloc( sizeof( Word32 ) * cov_smooth_cfg->max_bands ) ) == NULL ) + IF( ( hCovState->pPrior_cov_real_fx[i][j] = (Word32 *) malloc( sizeof( Word32 ) * cov_smooth_cfg->max_bands ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); } set_zero_fx( hCovState->pPrior_cov_real_fx[i][j], cov_smooth_cfg->max_bands ); -#endif -#ifdef IVAS_FLOAT_FIXED - if ( ( hCovState->q_cov_real_per_band[i][j] = (Word16 *) malloc( sizeof( Word16 ) * cov_smooth_cfg->max_bands ) ) == NULL ) + IF( ( hCovState->q_cov_real_per_band[i][j] = (Word16 *) malloc( sizeof( Word16 ) * cov_smooth_cfg->max_bands ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); } set_s( hCovState->q_cov_real_per_band[i][j], Q31, cov_smooth_cfg->max_bands ); -#endif } } -#ifdef IVAS_FLOAT_FIXED ivas_set_up_cov_smoothing_fx( hCovState, pFb, cov_smooth_cfg->max_update_rate_fx, cov_smooth_cfg->min_pool_size, smooth_mode, ivas_total_brate ); -#else - ivas_set_up_cov_smoothing( hCovState, pFb, cov_smooth_cfg->max_update_rate, cov_smooth_cfg->min_pool_size, smooth_mode, ivas_total_brate ); -#endif *hCovState_out = hCovState; return IVAS_ERR_OK; } #else +/*------------------------------------------------------------------------- + * ivas_spar_covar_smooth_enc_open() + * + * Allocate and initialize SPAR Covar. smoothing handle + *------------------------------------------------------------------------*/ + ivas_error ivas_spar_covar_smooth_enc_open( ivas_cov_smooth_state_t **hCovState_out, /* i/o: SPAR Covar. smoothing handle */ const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i : SPAR config. handle */ @@ -384,46 +369,36 @@ ivas_error ivas_spar_covar_smooth_enc_open( } #endif +#ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- - * ivas_spar_covar_smooth_enc_close() + * ivas_spar_covar_smooth_enc_close_fx() * * Deallocate SPAR Covar. smoothing handle *------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -void ivas_spar_covar_smooth_enc_close( +void ivas_spar_covar_smooth_enc_close_fx( ivas_cov_smooth_state_t **hCovState_out, /* i/o: SPAR Covar. smoothing handle */ - const int16_t nchan_inp /* i : number of input channels */ + const Word16 nchan_inp /* i : number of input channels */ ) { ivas_cov_smooth_state_t *hCovState; - int16_t i, j; + Word16 i, j; hCovState = *hCovState_out; - if ( hCovState != NULL ) + IF( hCovState != NULL ) { -#ifdef IVAS_FLOAT_FIXED free( hCovState->pSmoothing_factor_fx ); hCovState->pSmoothing_factor_fx = NULL; -#endif - free( hCovState->pSmoothing_factor ); - hCovState->pSmoothing_factor = NULL; - for ( i = 0; i < nchan_inp; i++ ) + FOR( i = 0; i < nchan_inp; i++ ) { - for ( j = 0; j < nchan_inp; j++ ) + FOR( j = 0; j < nchan_inp; j++ ) { - free( hCovState->pPrior_cov_real[i][j] ); - hCovState->pPrior_cov_real[i][j] = NULL; -#ifdef IVAS_FLOAT_FIXED free( hCovState->pPrior_cov_real_fx[i][j] ); hCovState->pPrior_cov_real_fx[i][j] = NULL; -#endif -#ifdef IVAS_FLOAT_FIXED free( hCovState->q_cov_real_per_band[i][j] ); hCovState->q_cov_real_per_band[i][j] = NULL; -#endif } } @@ -434,6 +409,12 @@ void ivas_spar_covar_smooth_enc_close( return; } #else +/*------------------------------------------------------------------------- + * ivas_spar_covar_smooth_enc_close() + * + * Deallocate SPAR Covar. smoothing handle + *------------------------------------------------------------------------*/ + void ivas_spar_covar_smooth_enc_close( ivas_cov_smooth_state_t **hCovState_out, /* i/o: SPAR Covar. smoothing handle */ const int16_t nchan_inp /* i : number of input channels */ @@ -597,9 +578,7 @@ static void ivas_compute_smooth_cov_fx( return; } -#endif - - +#else /*-----------------------------------------------------------------------------------------* * Function ivas_compute_smooth_cov() * @@ -691,6 +670,7 @@ static void ivas_compute_smooth_cov( return; } +#endif #ifdef IVAS_FLOAT_FIXED @@ -728,9 +708,7 @@ void ivas_cov_smooth_process_fx( return; } -#endif - - +#else /*-----------------------------------------------------------------------------------------* * Function ivas_cov_smooth_process() * @@ -763,3 +741,4 @@ void ivas_cov_smooth_process( return; } +#endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 85556a4f4..6b6e1c39c 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5860,6 +5860,21 @@ void ivas_spar_dec_gen_umx_mat( const int16_t num_md_sub_frames ); +#ifdef IVAS_FLOAT_FIXED +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 */ +); + +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 */ +); +#else /* Covariance module */ ivas_error ivas_spar_covar_enc_open( ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ @@ -5874,6 +5889,7 @@ void ivas_spar_covar_enc_close( ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ const int16_t nchan_inp /* i : number of input channels */ ); +#endif #ifdef IVAS_FLOAT_FIXED void ivas_enc_cov_handler_process_fx( @@ -5898,8 +5914,7 @@ void ivas_enc_cov_handler_process_fx( const Word16 nchan_transport, const Word16 is_sba ); -#endif - +#else void ivas_enc_cov_handler_process( ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ float **ppIn_FR_real, @@ -5919,8 +5934,9 @@ void ivas_enc_cov_handler_process( const int16_t nchan_transport, const int16_t is_sba ); +#endif -#ifdef IVAS_FLOAT_FIXED_ +#ifdef IVAS_FLOAT_FIXED ivas_error ivas_spar_covar_smooth_enc_open_fx( ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. smoothing handle */ const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i : SPAR config. handle */ @@ -5934,8 +5950,7 @@ void ivas_spar_covar_smooth_enc_close_fx( ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. encoder handle */ const Word16 nchan_inp /* i : number of input channels */ ); -#endif - +#else ivas_error ivas_spar_covar_smooth_enc_open( ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. smoothing handle */ const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i : SPAR config. handle */ @@ -5949,6 +5964,7 @@ void ivas_spar_covar_smooth_enc_close( ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. encoder handle */ const int16_t nchan_inp /* i : number of input channels */ ); +#endif #ifdef IVAS_FLOAT_FIXED void ivas_cov_smooth_process_fx( @@ -5961,8 +5977,7 @@ void ivas_cov_smooth_process_fx( const Word16 transient_det[2], Word16 *q_cov[IVAS_SPAR_MAX_CH] ); -#endif - +#else void ivas_cov_smooth_process( ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */ float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -5972,6 +5987,7 @@ void ivas_cov_smooth_process( const int16_t num_ch, const int16_t transient_det[2] ); +#endif /* Transient detector module */ ivas_error ivas_transient_det_open( diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 14d5b40cf..66921d415 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2393,6 +2393,11 @@ Word16 ism_quant_meta_fx( const Word16 cbsize /* i : codebook size */ ); +/*! r: number of channels to be analysed */ +Word16 getNumChanAnalysis_fx( + Encoder_Struct *st_ivas /* i : IVAS encoder structure */ +); + ivas_error ivas_limiter_open_fx( IVAS_LIMITER_HANDLE *hLimiter_out, /* o : limiter struct handle */ const Word16 max_num_channels, /* i : maximum number of I/O channels to be processed */ diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 78227e56b..1a2542ed4 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -367,24 +367,28 @@ typedef struct ivas_agc_com_state_t /* Covariance structures */ typedef struct ivas_cov_smooth_state_t { - float *pPrior_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - int16_t prior_bank_idx; - float *pSmoothing_factor; - int16_t num_bins; #ifdef IVAS_FLOAT_FIXED Word32 *pPrior_cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - Word16 *q_cov_real[IVAS_SPAR_MAX_CH]; Word16 *q_cov_real_per_band[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; +#else + float *pPrior_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; +#endif + int16_t prior_bank_idx; +#ifdef IVAS_FLOAT_FIXED Word32 *pSmoothing_factor_fx; /* Q31 */ +#else + float *pSmoothing_factor; #endif + int16_t num_bins; } ivas_cov_smooth_state_t; typedef struct ivas_cov_smooth_cfg_t { - float max_update_rate; #ifdef IVAS_FLOAT_FIXED Word32 max_update_rate_fx; /* Q31 */ +#else + float max_update_rate; #endif int16_t min_pool_size; int16_t max_bands; @@ -595,7 +599,7 @@ typedef struct ivas_masa_qmetadata_frame_struct #ifndef IVAS_FLOAT_FIXED float dir_comp_ratio; #else - Word16 dir_comp_ratio_fx; /* Q15 */ + Word16 dir_comp_ratio_fx; /* Q15 */ #endif uint8_t is_masa_ivas_format; diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index e42efb441..0e24db967 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -2555,64 +2555,21 @@ void lls_interp_n_fx( { Word16 i; const Word16 n_i_fx[11] = { 0, 2048, 4096, 6144, 8192, 10240, 12288, 14336, 16384, 18432, 20480 }; // Q11 - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); + move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); const Word16 one_by_n_fx[11] = { 0, 32767, 16384, 10911, 8192, 6553, 5459, 4681, 4096, 3640, 3276 }; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); + move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); const Word16 sum_i_fx[12] = { 0, 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55 }; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); + move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); // 1.0f/ ( N * sum_ii[N] - sum_i[N] * sum_i[N] ) const Word32 res_table[12] = { 0, 0, 0, 357913952, 107374184, 42949672, 20452226, 10956549, 6391320, 3976821, 2603010, 385 }; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); + move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); Word32 sum_x_fx, sum_ix_fx, slope_fx, offset_fx; Word16 dot_exp = 0, sum_ix_q = 0; - move16(); - move16(); + move16(); move16(); Word32 num; assert( N > 0 && LE_16( N, 10 ) ); @@ -3045,8 +3002,8 @@ Word16 is_SIDrate( test(); test(); if ( EQ_32( ivas_total_brate, SID_1k75 ) || - EQ_32( ivas_total_brate, SID_2k40 ) || - EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) + EQ_32( ivas_total_brate, SID_2k40 ) || + EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { sid_rate_flag = 1; move16(); @@ -3416,9 +3373,9 @@ Word16 ceil_log_2( *-------------------------------------------------------------------*/ Word64 var_32_fx( - const Word32 *x, /* i : input vector */ - const Word16 len, /* i : length of inputvector */ - Word16 q /* q : q-factor for the array */ + const Word32 *x, /* i : input vector */ + const Word16 len, /* i : length of inputvector */ + Word16 q /* q : q-factor for the array */ ) { @@ -3434,7 +3391,7 @@ Word64 var_32_fx( mean = W_add( mean, x[i] ); } - mean = mean / len; /* NOTE: No BASOP for 64 bit division */ + mean = mean / len; /* NOTE: No BASOP for 64 bit division */ FOR( int i = 0; i < len; i++ ) { @@ -3443,7 +3400,7 @@ Word64 var_32_fx( var = W_shl( var, sub( 31, q ) ); - var = var / len; /* NOTE: No BASOP for 64 bit division */ + var = var / len; /* NOTE: No BASOP for 64 bit division */ return var; } diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 23dee7bc6..e983df322 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -40,13 +40,18 @@ #include "ivas_prot.h" #include "ivas_rom_com.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx1.h" +#include "prot_fx2.h" +#include "ivas_prot_fx.h" +#endif /*-------------------------------------------------------------------* * ivas_enc() * * Principal IVAS encoder routine *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t *data, /* i : input signal */ @@ -433,71 +438,571 @@ ivas_error ivas_enc( { st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; -#ifdef IVAS_FLOAT_FIXED - Word16 q_data_lfe_ch; - Word32 data_lfe_ch_fx[L_FRAME48k]; - float max_val = 0; + ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); + } - for ( int ii = 0; ii < input_frame; ii++ ) + if ( st_ivas->mc_mode == MC_MODE_MCT ) + { + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, 0 ) ) != IVAS_ERR_OK ) { - if ( max_val < (float) fabs( data_f[LFE_CHANNEL][ii] ) ) - max_val = (float) fabs( data_f[LFE_CHANNEL][ii] ); + return error; } + } + else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + { + /* encode MC ParamUpmix parameters and write bitstream */ + ivas_mc_paramupmix_enc( st_ivas, hMetaData, data_f, input_frame ); - if ( (Word32) max_val == 0 ) - q_data_lfe_ch = 31; - else - q_data_lfe_ch = norm_l( (Word32) max_val ); + st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; + + ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); + + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + { + /* encode Parametric MC parameters and write bitstream */ + ivas_param_mc_enc( st_ivas, hMetaData, data_f, input_frame ); + + if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + { + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->nCPE > 1 ) + { + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + { + if ( st_ivas->hMcMasa->separateChannelEnabled ) + { + hMetaData = st_ivas->hCPE[0]->hMetaData; /* Metadata is always with CPE in the case of separated channel */ + } + ivas_mcmasa_enc( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport, nchan_inp ); - for ( int ii = 0; ii < input_frame; ii++ ) + if ( ( error = ivas_masa_encode( 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 ) { - data_lfe_ch_fx[ii] = (Word32) ( data_f[LFE_CHANNEL][ii] * ( 1 << q_data_lfe_ch ) ); + return error; } - ivas_lfe_enc_fx( st_ivas->hLFE, data_lfe_ch_fx, q_data_lfe_ch, input_frame, st_ivas->hLFE->hBstr ); + if ( st_ivas->hMcMasa->separateChannelEnabled ) + { + if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[2], 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 ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + if ( st_ivas->nSCE == 1 ) + { + if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + { + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + } + } + + /*----------------------------------------------------------------* + * Common updates + *----------------------------------------------------------------*/ + + hEncoderConfig->last_ivas_total_brate = ivas_total_brate; + + + pop_wmops(); + return error; +} #else - ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); -#endif // IVAS_FLOAT_FIXED +ivas_error ivas_enc( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 *data, /* i : input signal */ + const Word16 n_samples /* i : number of input samples */ +) +{ + Word16 i, n, input_frame, n_samples_chan, nchan_inp /*, scale*/; + Word32 input_Fs; + IVAS_FORMAT ivas_format; + ENCODER_CONFIG_HANDLE hEncoderConfig; + BSTR_ENC_HANDLE hMetaData; + Word16 nb_bits_metadata[MAX_SCE + 1]; + float *data_f[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; + Word32 *data_fx[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; + Word32 ivas_total_brate; + ivas_error error; + error = IVAS_ERR_OK; + move32(); + + push_wmops( "ivas_enc" ); + + /*------------------------------------------------------------------* + * Initialization - general + *-----------------------------------------------------------------*/ + + hEncoderConfig = st_ivas->hEncoderConfig; + + input_Fs = hEncoderConfig->input_Fs; + ivas_format = hEncoderConfig->ivas_format; + nchan_inp = hEncoderConfig->nchan_inp; + ivas_total_brate = hEncoderConfig->ivas_total_brate; + move32(); + move32(); + move16(); + move32(); + + 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 ); + } + ELSE + { + n_samples_chan = n_samples; + move16(); + } + set16_fx( nb_bits_metadata, 0, MAX_SCE + 1 ); + + /*----------------------------------------------------------------* + * convert 'Word16' input data to 'Word32' in Q11 format + *----------------------------------------------------------------*/ + + FOR( n = 0; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) + { + data_f[n] = st_ivas->p_data_f[n]; // float initialization to be removed + data_fx[n] = st_ivas->p_data_fx[n]; + } + + st_ivas->q_data_fx = 11; // Q-factor of the input buffer + move16(); + n = 0; + move16(); + WHILE( LT_16( n, nchan_inp ) ) + { + FOR( i = 0; i < n_samples_chan; i++ ) + { + data_f[n][i] = (float) data[i * nchan_inp + n]; // float initialization to be removed + data_fx[n][i] = L_mult0( data[add( imult1616( i, nchan_inp ), n )], shl( 1, st_ivas->q_data_fx ) ); + move32(); } + n = add( n, 1 ); + } - if ( st_ivas->mc_mode == MC_MODE_MCT ) + IF( LT_16( n_samples_chan, input_frame ) ) + { + FOR( n = 0; n < nchan_inp; n++ ) { - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, 0 ) ) != IVAS_ERR_OK ) + set_f( data_f[n] + n_samples_chan, 0.0f, input_frame - n_samples_chan ); // float initialization to be removed + set32_fx( data_fx[n] + n_samples_chan, 0, sub( input_frame, n_samples_chan ) ); + } + } + + IF( EQ_32( ivas_format, SBA_FORMAT ) ) + { + IF( ( error = ivas_sba_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) ) + { + IF( ( error = ivas_osba_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /*----------------------------------------------------------------* + * HP filtering + *----------------------------------------------------------------*/ + + n = getNumChanAnalysis_fx( st_ivas ); + + /* bypass EVS coding in float precision, emulating EVS encoder/decoder delay */ + FOR( i = 0; i < n; i++ ) + { + test(); + test(); + IF( ( EQ_32( ivas_format, SBA_FORMAT ) ) && !( GT_16( st_ivas->sba_analysis_order, 1 ) ) ) + { + hp20_flt( data_f[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); +#if 0 // To be enabled, precision loss observed + hp20_fix32( data_fx[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs ); +#endif + } + ELSE IF( !( EQ_32( ivas_format, MC_FORMAT ) && EQ_16( i, LFE_CHANNEL ) ) ) + { + hp20_flt( data_f[i], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); // To be removed +#if 0 // To be enabled, precision loss observed + hp20_fix32( data_fx[i], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs ); +#endif + } + } + +#if 0 /* Fixed to float conversion To be removed */ + for ( i = 0; i < n; i++ ) + { + fixedToFloat_arrL( data_fx[i], data_f[i], st_ivas->q_data_fx, input_frame ); + } +#endif // 1 + + + /*----------------------------------------------------------------* + * write IVAS format signaling + *----------------------------------------------------------------*/ + + ivas_write_format( st_ivas ); + + /*----------------------------------------------------------------* + * Encoding + *----------------------------------------------------------------*/ + + if ( ivas_format == STEREO_FORMAT ) + { + st_ivas->hCPE[0]->element_brate = ivas_total_brate; + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, 0 /* no metadata */ ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( ivas_format == ISM_FORMAT ) + { + /* select ISM format mode; reconfigure the ISM format encoder */ + if ( ( error = ivas_ism_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + { + ivas_param_ism_enc( st_ivas, data_f, input_frame ); + + /* Stereo DMX generation */ + ivas_param_ism_stereo_dmx( st_ivas, data_f, input_frame ); + + /* Core coding of Stereo DMX */ + if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + else if ( st_ivas->ism_mode == ISM_MODE_DISC ) { - /* encode MC ParamUpmix parameters and write bitstream */ - ivas_mc_paramupmix_enc( st_ivas, hMetaData, data_f, input_frame ); + /* Analysis, decision about bitrates per channel & core coding */ + if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else if ( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT ) + { + /* MASA configuration */ + if ( ivas_format == MASA_FORMAT ) + { + ivas_masa_enc_reconfigure( st_ivas ); + } - st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; + /* SBA/MASA metadata encoding and SBA/MASA metadata bitstream writing */ + hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; -#ifdef IVAS_FLOAT_FIXED - Word16 q_data_lfe_ch; - Word32 data_lfe_ch_fx[L_FRAME48k]; - float max_val = 0; + if ( st_ivas->hQMetaData != NULL && ivas_format == MASA_FORMAT ) + { + ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */ + + if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_masa_encode( 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->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( ivas_format == SBA_FORMAT ) + { + if ( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ivas_format == SBA_FORMAT ) + { + ivas_sba_getTCs( data_f, st_ivas, input_frame ); + } - for ( int ii = 0; ii < input_frame; ii++ ) + /* core-coding of transport channels */ + if ( st_ivas->nSCE == 1 ) + { + if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + { + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { - if ( max_val < (float) fabs( data_f[LFE_CHANNEL][ii] ) ) - max_val = (float) fabs( data_f[LFE_CHANNEL][ii] ); + return error; } + } + else if ( st_ivas->nCPE > 1 ) /* FOA/HOA format */ + { + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else if ( ivas_format == MASA_ISM_FORMAT ) + { + float *data_separated_object; + + int16_t idx_separated_object; + int16_t flag_omasa_ener_brate; - if ( (Word32) max_val == 0 ) - q_data_lfe_ch = 31; + flag_omasa_ener_brate = 0; + + /* Stereo transport is used also with monoMASA, duplicate mono if monoMASA */ + if ( ( st_ivas->hEncoderConfig->nchan_inp - hEncoderConfig->nchan_ism ) == 1 ) + { + v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame ); + mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); + } + + /* Estimate TF-tile energy for the input MASA stream */ + ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); + + if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); + idx_separated_object = 0; + + data_separated_object = data_f[hEncoderConfig->nchan_ism + CPE_CHANNELS]; + + /* put audio object data in SCE's */ + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + /* Estimate MASA parameters for the objects */ + ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object ); + } + + /* Encode ISMs transport channels */ + n = 0; + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + { + if ( ( error = ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */ + { + return error; + } + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + if ( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1], 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + flag_omasa_ener_brate = ivas_omasa_ener_brate( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_f, input_frame ); + + /* Analysis, decision about bitrates per channel & core coding */ + if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) + { + return error; + } + n = st_ivas->hEncoderConfig->nchan_ism; + } + + hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + + if ( st_ivas->nSCE > 0 ) + { + /* update pointer to the buffer of indices (ISM indices were alredy written) */ + hMetaData->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->nb_ind_tot; + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->nb_ind_tot; + } + + /* Encode MASA parameters and write MASA metadata bitstream */ + if ( ( error = ivas_masa_encode( 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, + 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 ) + { + return error; + } + + /* Configuration of combined-format bit-budget distribution */ + ivas_set_surplus_brate_enc( st_ivas ); + + /* Encode MASA transport channels */ + if ( ( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( ivas_format == SBA_ISM_FORMAT ) + { + int16_t planar_sba_orig; + planar_sba_orig = hEncoderConfig->sba_planar; + + /* Analyze objects and determine needed audio signals */ + ivas_osba_enc( st_ivas->hOSba, st_ivas->hIsmMetaData, data_f, input_frame, hEncoderConfig->nchan_ism, st_ivas->ism_mode, st_ivas->sba_analysis_order, hEncoderConfig->input_Fs, hEncoderConfig->sba_planar ); + + if ( st_ivas->ism_mode == ISM_MODE_NONE ) + { + /*once SBA and ISM are combined into SBA signal then disable planar flag*/ + hEncoderConfig->sba_planar = 0; + if ( st_ivas->nchan_transport == 1 ) + { + hMetaData = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData; + } else - q_data_lfe_ch = norm_l( (Word32) max_val ); + { + hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + } + + /* SBA metadata encoding and SBA metadata bitstream writing */ + if ( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + { + return error; + } + + hEncoderConfig->sba_planar = planar_sba_orig; + } + else + { + n = hEncoderConfig->nchan_ism; + hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + + if ( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* SBA metadata encoding and SBA metadata bitstream writing */ + if ( ( error = ivas_spar_enc( st_ivas, &data_f[n], input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* get SBA TCs */ + ivas_sba_getTCs( &data_f[n], st_ivas, input_frame ); + } + /* core-coding of transport channels */ + if ( st_ivas->nSCE == 1 ) + { + if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + { + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->nCPE > 1 ) /* FOA/HOA format */ + { + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else if ( EQ_32( ivas_format, MC_FORMAT ) ) + { + /* select MC format mode; write MC LS setup; reconfigure the MC format encoder */ + if ( ( error = ivas_mc_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } - for ( int ii = 0; ii < input_frame; ii++ ) + // hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + IF( st_ivas->nSCE > 0 ) + { + hMetaData = st_ivas->hSCE[sub( st_ivas->nSCE, 1 )]->hMetaData; + } + ELSE + { + hMetaData = st_ivas->hCPE[sub( st_ivas->nCPE, 1 )]->hMetaData; + } + + /* LFE low pass filter */ + ivas_lfe_lpf_enc_apply( st_ivas->hLfeLpf, data_f[LFE_CHANNEL], input_frame ); + + /* LFE channel encoder */ + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) + { + IF( st_ivas->nSCE > 0 ) + { + st_ivas->hLFE->hBstr = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr; + } + ELSE { - data_lfe_ch_fx[ii] = (Word32) ( data_f[LFE_CHANNEL][ii] * ( 1 << q_data_lfe_ch ) ); + st_ivas->hLFE->hBstr = st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; } - ivas_lfe_enc_fx( st_ivas->hLFE, data_lfe_ch_fx, q_data_lfe_ch, input_frame, st_ivas->hLFE->hBstr ); +#if 1 // To be removed + floatToFixed_arr32( data_f[LFE_CHANNEL], data_fx[LFE_CHANNEL], st_ivas->q_data_fx, input_frame ); +#endif + ivas_lfe_enc_fx( st_ivas->hLFE, data_fx[LFE_CHANNEL], st_ivas->q_data_fx, input_frame, st_ivas->hLFE->hBstr ); + } + + if ( st_ivas->mc_mode == MC_MODE_MCT ) + { + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + { + /* encode MC ParamUpmix parameters and write bitstream */ + ivas_mc_paramupmix_enc( st_ivas, hMetaData, data_f, input_frame ); + + st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; + +#ifdef IVAS_FLOAT_FIXED + floatToFixed_arr32( data_f[LFE_CHANNEL], data_fx[LFE_CHANNEL], st_ivas->q_data_fx, input_frame ); + + ivas_lfe_enc_fx( st_ivas->hLFE, data_fx[LFE_CHANNEL], st_ivas->q_data_fx, input_frame, st_ivas->hLFE->hBstr ); #else ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); #endif // IVAS_FLOAT_FIXED @@ -586,3 +1091,4 @@ ivas_error ivas_enc( pop_wmops(); return error; } +#endif diff --git a/lib_enc/ivas_enc_cov_handler.c b/lib_enc/ivas_enc_cov_handler.c index cda2b4676..804470189 100644 --- a/lib_enc/ivas_enc_cov_handler.c +++ b/lib_enc/ivas_enc_cov_handler.c @@ -44,13 +44,14 @@ * Local constants *------------------------------------------------------------------------------------------*/ -#define MIN_POOL_SIZE 24 -#define MAX_UPDATE_RATE 0.8f -#define MIN_POOL_SIZE_DTX 40 -#define MAX_UPDATE_RATE_DTX 0.4f +#define MIN_POOL_SIZE 24 +#define MIN_POOL_SIZE_DTX 40 #ifdef IVAS_FLOAT_FIXED #define MAX_UPDATE_RATE_Q31 ( 1717986944 ) #define MAX_UPDATE_RATE_DTX_Q31 ( 858993472 ) +#else +#define MAX_UPDATE_RATE 0.8f +#define MAX_UPDATE_RATE_DTX 0.4f #endif @@ -60,9 +61,80 @@ #ifdef IVAS_FLOAT_FIXED static void ivas_band_cov_fx( Word32 **ppIn_FR_real, Word32 **ppIn_FR_imag, 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], Word16 *q_cov_real[IVAS_SPAR_MAX_CH], const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH] ); -#endif +#else static void ivas_band_cov( float **ppIn_FR_real, float **ppIn_FR_imag, const int16_t num_chans, const int16_t num_bins, int16_t stride, float **pFb_bin_to_band, const int16_t *pFb_start_bin_per_band, const int16_t *pFb_active_bins_per_band, const int16_t start_band, const int16_t end_band, float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] ); +#endif +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * ivas_spar_covar_enc_open_fx() + * + * Allocate and initialize SPAR Covar. encoder handle + *------------------------------------------------------------------------*/ + +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 *hCovState; + ivas_cov_smooth_cfg_t cov_smooth_cfg; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + + IF( ( hCovState = (ivas_enc_cov_handler_state_t *) malloc( sizeof( ivas_enc_cov_handler_state_t ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" ); + } + + cov_smooth_cfg.max_bands = IVAS_MAX_NUM_BANDS; + move16(); + cov_smooth_cfg.max_update_rate_fx = MAX_UPDATE_RATE_Q31; + move32(); + cov_smooth_cfg.min_pool_size = MIN_POOL_SIZE; + move16(); + IF( EQ_32( smooth_mode, COV_SMOOTH_MC ) ) + { + cov_smooth_cfg.max_update_rate_fx = ONE_IN_Q31; // Q31 + move32(); + cov_smooth_cfg.min_pool_size = 20; + move16(); + } + + IF( NE_32( ( error = ivas_spar_covar_smooth_enc_open_fx( &hCovState->pCov_state, &cov_smooth_cfg, pFb, nchan_inp, smooth_mode, ivas_total_brate ) ), IVAS_ERR_OK ) ) + { + return error; + } + + cov_smooth_cfg.max_update_rate_fx = MAX_UPDATE_RATE_DTX_Q31; + move32(); + cov_smooth_cfg.min_pool_size = MIN_POOL_SIZE_DTX; + move16(); + + IF( NE_32( ( error = ivas_spar_covar_smooth_enc_open_fx( &hCovState->pCov_dtx_state, &cov_smooth_cfg, pFb, nchan_inp, smooth_mode, ivas_total_brate ) ), IVAS_ERR_OK ) ) + { + return error; + } + + hCovState->num_bins = extract_l( Mpy_32_32( input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + hCovState->prior_dtx_present = 0; + move16(); + + set_zero_fx( hCovState->bb_var_lt_fx, FOA_CHANNELS ); + hCovState->prior_var_flag = -1; + move16(); + + *hCovEnc = hCovState; + + return error; +} +#else /*------------------------------------------------------------------------- * ivas_spar_covar_enc_open() * @@ -90,16 +162,10 @@ ivas_error ivas_spar_covar_enc_open( } cov_smooth_cfg.max_bands = IVAS_MAX_NUM_BANDS; -#ifdef IVAS_FLOAT_FIXED - cov_smooth_cfg.max_update_rate_fx = MAX_UPDATE_RATE_Q31; -#endif cov_smooth_cfg.max_update_rate = MAX_UPDATE_RATE; cov_smooth_cfg.min_pool_size = MIN_POOL_SIZE; if ( smooth_mode == COV_SMOOTH_MC ) { -#ifdef IVAS_FLOAT_FIXED - cov_smooth_cfg.max_update_rate_fx = ONE_IN_Q31; // Q31 -#endif cov_smooth_cfg.max_update_rate = 1.0f; cov_smooth_cfg.min_pool_size = 20; } @@ -109,9 +175,6 @@ ivas_error ivas_spar_covar_enc_open( return error; } -#ifdef IVAS_FLOAT_FIXED - cov_smooth_cfg.max_update_rate_fx = MAX_UPDATE_RATE_DTX_Q31; -#endif cov_smooth_cfg.max_update_rate = MAX_UPDATE_RATE_DTX; cov_smooth_cfg.min_pool_size = MIN_POOL_SIZE_DTX; @@ -130,8 +193,41 @@ ivas_error ivas_spar_covar_enc_open( return error; } +#endif +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * ivas_spar_covar_enc_close_fx() + * + * Deallocate SPAR Covar. encoder handle + *------------------------------------------------------------------------*/ + +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 */ +) +{ + ivas_enc_cov_handler_state_t *hCovState; + + test(); + IF( hCovEnc == NULL || *hCovEnc == NULL ) + { + return; + } + + hCovState = *hCovEnc; + + ivas_spar_covar_smooth_enc_close_fx( &hCovState->pCov_state, nchan_inp ); + + ivas_spar_covar_smooth_enc_close_fx( &hCovState->pCov_dtx_state, nchan_inp ); + + free( *hCovEnc ); + *hCovEnc = NULL; + + return; +} +#else /*------------------------------------------------------------------------- * ivas_spar_covar_enc_close() * @@ -161,6 +257,7 @@ void ivas_spar_covar_enc_close( return; } +#endif #ifdef IVAS_FLOAT_FIXED @@ -325,9 +422,7 @@ ELSE IF( EQ_16( nchan_transport, 3 ) ) return activeW_flag; } -#endif - - +#else /*-----------------------------------------------------------------------------------------* * Function ivas_spar_get_activeW_flag() * @@ -438,6 +533,7 @@ static int16_t ivas_spar_get_activeW_flag( return activeW_flag; } +#endif #ifdef IVAS_FLOAT_FIXED @@ -599,8 +695,7 @@ void ivas_enc_cov_handler_process_fx( return; } -#endif - +#else /*-----------------------------------------------------------------------------------------* * Function ivas_enc_cov_handler_process() * @@ -707,6 +802,7 @@ void ivas_enc_cov_handler_process( return; } +#endif #ifdef IVAS_FLOAT_FIXED @@ -843,9 +939,7 @@ static void ivas_band_cov_fx( return; } -#endif - - +#else static void ivas_band_cov( float **ppIn_FR_real, float **ppIn_FR_imag, @@ -914,3 +1008,4 @@ static void ivas_band_cov( return; } +#endif diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 1daf86b23..4bdf08e1a 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -42,6 +42,7 @@ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #include "prot_fx_enc.h" +#include "prot_fx1.h" #endif @@ -240,6 +241,50 @@ int16_t getNumChanAnalysis( return n; } +#ifdef IVAS_FLOAT_FIXED +Word16 getNumChanAnalysis_fx( + Encoder_Struct *st_ivas /* i : IVAS encoder structure */ +) +{ + Word16 n; + + n = add( st_ivas->nSCE, CPE_CHANNELS * st_ivas->nCPE ); + 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 ) ); + } + 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; + 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; + 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; + move16(); + } + ELSE IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) + { + n = st_ivas->hEncoderConfig->nchan_inp; + 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 ) ) ); + } + + return n; +} +#endif /*-------------------------------------------------------------------* * copy_encoder_config() @@ -461,7 +506,20 @@ ivas_error ivas_init_encoder( { st_ivas->p_data_f[n] = NULL; } - +#ifdef IVAS_FLOAT_FIXED + FOR( n = 0; n < nchan_inp_buff; n++ ) + { + /* note: these are intra-frame heap memories */ + IF( ( st_ivas->p_data_fx[n] = (Word32 *) malloc( Mpy_32_16_1( input_Fs, INV_FRAME_PER_SEC_Q15 ) * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point input audio buffer!\n" ) ); + } + } + FOR( ; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) + { + st_ivas->p_data_fx[n] = NULL; + } +#endif /*-----------------------------------------------------------------* * Allocate and initialize buffer of indices *-----------------------------------------------------------------*/ @@ -976,7 +1034,29 @@ ivas_error ivas_init_encoder( set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); } +#ifdef IVAS_FLOAT_FIXED + IF( n > 0 ) + { + IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + } + ELSE + { + st_ivas->mem_hp20_in_fx = NULL; + } + + FOR( i = 0; i < n; i++ ) + { + IF( ( st_ivas->mem_hp20_in_fx[i] = (Word32 *) malloc( ( L_HP20_MEM + 2 ) * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + set32_fx( st_ivas->mem_hp20_in_fx[i], 0, L_HP20_MEM + 2 ); + } +#endif return error; } #ifdef IVAS_FLOAT_FIXED @@ -1030,7 +1110,7 @@ ivas_error ivas_init_encoder_fx( nchan_inp_buff++; /* for *data_separated_object */ } - +#if 1 /* To be removed */ FOR( n = 0; n < nchan_inp_buff; n++ ) { /* note: these are intra-frame heap memories */ @@ -1043,6 +1123,20 @@ ivas_error ivas_init_encoder_fx( { st_ivas->p_data_f[n] = NULL; } +#endif + FOR( n = 0; n < nchan_inp_buff; n++ ) + { + /* note: these are intra-frame heap memories */ + IF( ( st_ivas->p_data_fx[n] = (Word32 *) malloc( Mpy_32_16_1( input_Fs, INV_FRAME_PER_SEC_Q15 ) * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point input audio buffer!\n" ) ); + } + } + FOR( ; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) + { + st_ivas->p_data_fx[n] = NULL; + } + /*-----------------------------------------------------------------* * Allocate and initialize buffer of indices @@ -1535,8 +1629,8 @@ ivas_error ivas_init_encoder_fx( *-----------------------------------------------------------------*/ /* set number of input channels used for analysis/coding */ - n = getNumChanAnalysis( st_ivas ); - + n = getNumChanAnalysis_fx( st_ivas ); +#if 1 // To be removed if ( n > 0 ) { if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) @@ -1558,6 +1652,29 @@ ivas_error ivas_init_encoder_fx( set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); } +#endif + /*Fixed point init*/ + IF( n > 0 ) + { + IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + } + ELSE + { + st_ivas->mem_hp20_in_fx = NULL; + } + + FOR( i = 0; i < n; i++ ) + { + IF( ( st_ivas->mem_hp20_in_fx[i] = (Word32 *) malloc( ( L_HP20_MEM + 2 ) * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + set32_fx( st_ivas->mem_hp20_in_fx[i], 0, L_HP20_MEM + 2 ); + } return error; } @@ -1723,7 +1840,154 @@ void destroy_core_enc( * * Close IVAS encoder handles *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_destroy_enc( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + int16_t i, n, nchan_inp; + nchan_inp = st_ivas->hEncoderConfig->nchan_inp; + + /* SCE handles */ + for ( i = 0; i < MAX_SCE; i++ ) + { + if ( st_ivas->hSCE[i] != NULL ) + { + destroy_sce_enc( st_ivas->hSCE[i] ); + st_ivas->hSCE[i] = NULL; + } + } + + /* CPE handles */ + for ( i = 0; i < MAX_CPE; i++ ) + { + if ( st_ivas->hCPE[i] != NULL ) + { + destroy_cpe_enc( st_ivas->hCPE[i] ); + st_ivas->hCPE[i] = NULL; + } + } + /* HP20 filter handles */ + if ( st_ivas->mem_hp20_in != NULL ) + { + n = getNumChanAnalysis_fx( st_ivas ); + + for ( i = 0; i < n; i++ ) + { + free( st_ivas->mem_hp20_in_fx[i] ); + st_ivas->mem_hp20_in_fx[i] = NULL; + } + free( st_ivas->mem_hp20_in_fx ); + st_ivas->mem_hp20_in_fx = NULL; + } + if ( st_ivas->mem_hp20_in != NULL ) + { + n = getNumChanAnalysis_fx( st_ivas ); + + for ( i = 0; i < n; i++ ) + { + free( st_ivas->mem_hp20_in[i] ); + st_ivas->mem_hp20_in[i] = NULL; + } + free( st_ivas->mem_hp20_in ); + st_ivas->mem_hp20_in = NULL; + } + + /* ISM metadata handles */ + ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 ); + + /* ISM DTX Handle */ + if ( st_ivas->hISMDTX != NULL ) + { + free( st_ivas->hISMDTX ); + st_ivas->hISMDTX = NULL; + } + + /* Q Metadata handle */ + ivas_qmetadata_close( &( st_ivas->hQMetaData ) ); + + /* DirAC handle */ + ivas_dirac_enc_close( &( st_ivas->hDirAC ), st_ivas->hEncoderConfig->input_Fs ); + + /* ParamISM handle */ + ivas_param_ism_enc_close( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs ); + + /* SPAR handle */ + ivas_spar_enc_close( &( st_ivas->hSpar ), st_ivas->hEncoderConfig->input_Fs, nchan_inp, 0 ); + + /* MASA handle */ + ivas_masa_enc_close( &( st_ivas->hMasa ) ); + + /* MCT handle */ + ivas_mct_enc_close( &( st_ivas->hMCT ) ); + + /* LFE handle */ + ivas_lfe_enc_close( &( st_ivas->hLFE ) ); + + /* LFE low pass filter state */ + ivas_lfe_lpf_enc_close( &( st_ivas->hLfeLpf ) ); + + /* Param-Upmix MC handle */ + ivas_mc_paramupmix_enc_close( &( st_ivas->hMCParamUpmix ), st_ivas->hEncoderConfig->input_Fs ); + + /* Parametric MC handle */ + ivas_param_mc_enc_close( &( st_ivas->hParamMC ), st_ivas->hEncoderConfig->input_Fs ); + + /* Multi-channel MASA handle */ + ivas_mcmasa_enc_close( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); + + /* OMASA handle */ + ivas_omasa_enc_close( &( st_ivas->hOMasa ) ); + + /* OSBA handle */ + ivas_osba_enc_close( &( st_ivas->hOSba ) ); + + /* Stereo downmix for EVS encoder handle */ + stereo_dmx_evs_close_encoder( &( st_ivas->hStereoDmxEVS ) ); + + /* Encoder configuration handle */ + if ( st_ivas->hEncoderConfig != NULL ) + { + free( st_ivas->hEncoderConfig ); + st_ivas->hEncoderConfig = NULL; + } + + /* Buffer of indices */ + if ( st_ivas->ind_list != NULL ) + { + free( st_ivas->ind_list ); + } + + 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++ ) + { + if ( st_ivas->p_data_f[n] != NULL ) + { + free( st_ivas->p_data_f[n] ); + st_ivas->p_data_f[n] = NULL; + } + } + for ( n = 0; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) + { + if ( st_ivas->p_data_fx[n] != NULL ) + { + free( st_ivas->p_data_fx[n] ); + st_ivas->p_data_fx[n] = NULL; + } + } + + /* main IVAS handle */ + free( st_ivas ); + + return; +} +#else void ivas_destroy_enc( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) @@ -1850,6 +2114,7 @@ void ivas_destroy_enc( return; } +#endif /*------------------------------------------------------------------------- * ivas_initialize_MD_bstr_enc() diff --git a/lib_enc/ivas_lfe_enc.c b/lib_enc/ivas_lfe_enc.c index 26829a6d7..f4923cafd 100644 --- a/lib_enc/ivas_lfe_enc.c +++ b/lib_enc/ivas_lfe_enc.c @@ -94,7 +94,7 @@ static void ivas_lfe_arith_coding( * * LFE quatization block, calls arithmetic coding block inside *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void ivas_lfe_enc_quant( LFE_ENC_HANDLE hLFE, float *pLfe_dct, @@ -319,7 +319,7 @@ static void ivas_lfe_enc_quant( } -#ifdef IVAS_FLOAT_FIXED +#else static void ivas_lfe_enc_quant_fx( LFE_ENC_HANDLE hLFE, @@ -626,7 +626,7 @@ static void ivas_lfe_enc_quant_fx( * * LFE channel encoder *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_lfe_enc( LFE_ENC_HANDLE hLFE, /* i/o: LFE encoder handle */ float data_lfe_ch[], /* i : input LFE signal */ @@ -669,7 +669,7 @@ void ivas_lfe_enc( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_lfe_enc_fx( LFE_ENC_HANDLE hLFE, /* i/o: LFE encoder handle */ @@ -779,7 +779,85 @@ void ivas_lfe_enc_fx( * * Create, allocate and initialize IVAS encoder LFE handle *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_create_lfe_enc( + LFE_ENC_HANDLE *hLFE_out, /* o : IVAS LFE encoder structure */ + const Word32 input_Fs /* i : input sampling rate */ +) +{ + Word16 input_frame; + LFE_ENC_HANDLE hLFE; + Word16 i, j; + + input_frame = extract_l( Mpy_32_16_1( input_Fs, INV_FRAME_PER_SEC_Q15 ) ); + + /*-----------------------------------------------------------------* + * Allocate LFE handle + *-----------------------------------------------------------------*/ + + IF ( ( hLFE = (LFE_ENC_HANDLE) malloc( sizeof( LFE_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE\n" ) ); + } + + /* initializations */ + hLFE->lfe_bits = 0; + move16(); + hLFE->pWindow_state = NULL; + hLFE->hBstr = NULL; + + /*-----------------------------------------------------------------* + * Input memory buffer: allocate and initialize + *-----------------------------------------------------------------*/ + + IF( ( hLFE->old_wtda_audio_fx = (Word32 *) malloc( sizeof( hLFE->old_wtda_audio_fx[0] ) * NS2SA( input_Fs, IVAS_LFE_FADE_NS ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE memory\n" ) ); + } + + set32_fx( hLFE->old_wtda_audio_fx, 0, NS2SA( input_Fs, IVAS_LFE_FADE_NS ) ); + hLFE->q_old_wtda_audio = 31; + move16(); + + /*-----------------------------------------------------------------* + * LFE Window: allocate and initialize + *-----------------------------------------------------------------*/ + + IF ( ( hLFE->pWindow_state = (LFE_WINDOW_HANDLE) malloc( sizeof( LFE_WINDOW_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE window structure\n" ) ); + } + + ivas_lfe_window_init_fx( hLFE->pWindow_state, input_Fs, input_frame ); + + /* Initialization for entropy coding */ + hLFE->cum_freq_models[0][0] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg1; + hLFE->cum_freq_models[0][1] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg2; + hLFE->cum_freq_models[0][2] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg3; + hLFE->cum_freq_models[0][3] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg4; + hLFE->cum_freq_models[1][0] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg1; + hLFE->cum_freq_models[1][1] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg2; + hLFE->cum_freq_models[1][2] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg3; + hLFE->cum_freq_models[1][3] = &ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg4; + + /* Initialization base2 bits for each subgroup for no entropy coding */ + FOR ( i = 0; i < IVAS_MAX_NUM_QUANT_STRATS; i++ ) + { + FOR( j = 0; j < IVAS_MAX_NUM_DCT_COEF_GROUPS; j++ ) + { + // hLFE->lfe_enc_indices_coeffs_tbl[i][j] = + // (int16_t) ceilf( log2f( (float) ( ivas_lfe_num_ele_in_coder_models[i][j] + 1 ) ) ); + hLFE->lfe_enc_indices_coeffs_tbl[i][j] = + floor_log_2( add( ivas_lfe_num_ele_in_coder_models[i][j], 1 ) ); + move16(); + } + } + + *hLFE_out = hLFE; + return IVAS_ERR_OK; +} +#else ivas_error ivas_create_lfe_enc( LFE_ENC_HANDLE *hLFE_out, /* o : IVAS LFE encoder structure */ const int32_t input_Fs /* i : input sampling rate */ @@ -866,14 +944,42 @@ ivas_error ivas_create_lfe_enc( return IVAS_ERR_OK; } - +#endif /*------------------------------------------------------------------------- * ivas_lfe_enc_close() * * Destroy IVAS cncoder LFE handle *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_lfe_enc_close( + LFE_ENC_HANDLE *hLFE /* i/o: LFE encoder handle */ +) +{ + test(); + IF( hLFE == NULL || *hLFE == NULL ) + { + return; + } + + IF( ( *hLFE )->old_wtda_audio_fx != NULL ) + { + free( ( *hLFE )->old_wtda_audio_fx ); + ( *hLFE )->old_wtda_audio_fx = NULL; + } + IF( ( *hLFE )->pWindow_state ) + { + free( ( *hLFE )->pWindow_state ); + ( *hLFE )->pWindow_state = NULL; + } + + free( ( *hLFE ) ); + ( *hLFE ) = NULL; + + return; +} +#else void ivas_lfe_enc_close( LFE_ENC_HANDLE *hLFE /* i/o: LFE encoder handle */ ) @@ -908,7 +1014,7 @@ void ivas_lfe_enc_close( return; } - +#endif /*------------------------------------------------------------------------- * ivas_create_lfe_lpf_enc() diff --git a/lib_enc/ivas_mc_paramupmix_enc.c b/lib_enc/ivas_mc_paramupmix_enc.c index db20e7bc2..ea0fd5bfb 100644 --- a/lib_enc/ivas_mc_paramupmix_enc.c +++ b/lib_enc/ivas_mc_paramupmix_enc.c @@ -40,6 +40,7 @@ #include "ivas_prot.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "prot_fx2.h" #endif #include "ivas_cnst.h" #include "ivas_rom_com.h" @@ -52,7 +53,11 @@ static void ivas_mc_paramupmix_dmx( MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, float *data_f[], const int16_t input_frame ); +#ifdef IVAS_FLOAT_FIXED +static ivas_error ivas_mc_paramupmix_param_est_enc( MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, float *input_frame_t[], const int16_t input_frame, float alphas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS], float betas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS] ); +#else static void ivas_mc_paramupmix_param_est_enc( MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, float *input_frame_t[], const int16_t input_frame, float alphas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS], float betas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS] ); +#endif static void get_huff_table( const PAR_TYPE par_type, HUFF_TAB *df0, HUFF_TAB *df ); @@ -197,10 +202,17 @@ ivas_error ivas_mc_paramupmix_enc_open( for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { /* Covariance handle */ +#ifdef IVAS_FLOAT_FIXED + IF( NE_32( ( error = ivas_spar_covar_enc_open_fx( &( hMCParamUpmix->hCovEnc[i] ), hMCParamUpmix->hFbMixer->pFb, input_Fs, MC_PARAMUPMIX_NCH + 1, COV_SMOOTH_MC, st_ivas->hEncoderConfig->ivas_total_brate ) ), IVAS_ERR_OK ) ) + { + return error; + } +#else if ( ( error = ivas_spar_covar_enc_open( &( hMCParamUpmix->hCovEnc[i] ), hMCParamUpmix->hFbMixer->pFb, input_Fs, MC_PARAMUPMIX_NCH + 1, COV_SMOOTH_MC, st_ivas->hEncoderConfig->ivas_total_brate ) ) != IVAS_ERR_OK ) { return error; } +#endif } for ( b = 0; b < MC_PARAMUPMIX_COMBINATIONS; b++ ) @@ -333,7 +345,11 @@ void ivas_mc_paramupmix_enc_close( /* Covariance handle */ if ( ( *hMCParamUpmix )->hCovEnc[i] != NULL ) { +#ifdef IVAS_FLOAT_FIXED + ivas_spar_covar_enc_close_fx( &( *hMCParamUpmix )->hCovEnc[i], ( MC_PARAMUPMIX_NCH + 1 ) ); +#else ivas_spar_covar_enc_close( &( *hMCParamUpmix )->hCovEnc[i], ( MC_PARAMUPMIX_NCH + 1 ) ); +#endif } } @@ -664,12 +680,21 @@ static void ivas_mc_paramupmix_dmx( * estimate the input and down mix covariances *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static ivas_error ivas_mc_paramupmix_param_est_enc( + MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, /* i/o: MC Param-Upmix encoder handle */ + float *data_f[], /* i : Input frame in the time domain */ + const int16_t input_frame, /* i : Input frame length */ + float alphas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS], + float betas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS] ) +#else static void ivas_mc_paramupmix_param_est_enc( MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, /* i/o: MC Param-Upmix encoder handle */ float *data_f[], /* i : Input frame in the time domain */ const int16_t input_frame, /* i : Input frame length */ float alphas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS], float betas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS] ) +#endif { float *pcm_in[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; float fr_realbuffer[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH][L_FRAME48k]; @@ -679,8 +704,19 @@ static void ivas_mc_paramupmix_param_est_enc( float *p_fr_imagbuffer[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; float *pp_in_fr_real[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; float *pp_in_fr_imag[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; +#ifdef IVAS_FLOAT_FIXED + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word32 *cov_dtx_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word16 *q_cov_real[IVAS_SPAR_MAX_CH]; + Word16 *q_cov_dtx_real[IVAS_SPAR_MAX_CH]; + Word32 cov_real_buf_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + Word32 cov_dtx_real_buf_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + Word32 *pp_in_fr_real_fx[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH], *pp_in_fr_imag_fx[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; + Word16 q_ppIn_FR[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; +#else float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; +#endif float rxx, rxy, ryy, cmat, rxxest, drxx, wetaux; int16_t l_ts; int16_t b, i, j, ts, bnd; @@ -785,12 +821,85 @@ static void ivas_mc_paramupmix_param_est_enc( { for ( j = 0; j < MC_PARAMUPMIX_NCH; j++ ) { +#ifdef IVAS_FLOAT_FIXED + cov_real_fx[i][j] = cov_real_buf_fx[i][j]; + cov_dtx_real_fx[i][j] = cov_dtx_real_buf_fx[i][j]; +#else cov_real[i][j] = hMCParamUpmix->cov_real[b][i][j]; cov_dtx_real[i][j] = hMCParamUpmix->cov_dtx_real[b][i][j]; +#endif + } +#ifdef IVAS_FLOAT_FIXED + IF( ( q_cov_real[i] = (Word16 *) malloc( sizeof( Word16 ) * MC_PARAMUPMIX_NCH ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); + } + set_s( q_cov_real[i], Q31, MC_PARAMUPMIX_NCH ); + IF( ( q_cov_dtx_real[i] = (Word16 *) malloc( sizeof( Word16 ) * MC_PARAMUPMIX_NCH ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); } + set_s( q_cov_dtx_real[i], Q31, MC_PARAMUPMIX_NCH ); +#endif + } + +#ifdef IVAS_FLOAT_FIXED + FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH; i++ ) + { + IF( ( pp_in_fr_real_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * input_frame ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR encoder Fixed" ); + } + set_zero_fx( pp_in_fr_real_fx[i], input_frame ); + IF( ( pp_in_fr_imag_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * input_frame ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR encoder Fixed" ); + } + set_zero_fx( pp_in_fr_imag_fx[i], input_frame ); + } + set_s( q_ppIn_FR, Q31, MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH ); + + FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH; i++ ) + { + q_ppIn_FR[i] = L_get_q_buf1( pp_in_fr_real[i], input_frame ); + q_ppIn_FR[i] = min( q_ppIn_FR[i], L_get_q_buf1( pp_in_fr_imag[i], input_frame ) ); + floatToFixed_arrL( pp_in_fr_real[i], pp_in_fr_real_fx[i], q_ppIn_FR[i], input_frame ); + floatToFixed_arrL( pp_in_fr_imag[i], pp_in_fr_imag_fx[i], q_ppIn_FR[i], input_frame ); } +#endif +#ifdef IVAS_FLOAT_FIXED + ivas_enc_cov_handler_process_fx( hMCParamUpmix->hCovEnc[b], pp_in_fr_real_fx, pp_in_fr_imag_fx, q_ppIn_FR, cov_real_fx, q_cov_real, cov_dtx_real_fx, q_cov_dtx_real, hMCParamUpmix->hFbMixer->pFb, 0, hMCParamUpmix->hFbMixer->pFb->filterbank_num_bands, MC_PARAMUPMIX_NCH, 0 /*dtx_vad*/, transient_det[b], HOA_md_ind, NULL, NULL, NULL, 0, 0 ); +#else ivas_enc_cov_handler_process( hMCParamUpmix->hCovEnc[b], pp_in_fr_real, pp_in_fr_imag, cov_real, cov_dtx_real, hMCParamUpmix->hFbMixer->pFb, 0, hMCParamUpmix->hFbMixer->pFb->filterbank_num_bands, MC_PARAMUPMIX_NCH, 0 /*dtx_vad*/, transient_det[b], HOA_md_ind, NULL, NULL, NULL, 0, 0 ); +#endif + +#ifdef IVAS_FLOAT_FIXED + FOR( i = 0; i < MC_PARAMUPMIX_NCH; i++ ) + { + FOR( j = 0; j < MC_PARAMUPMIX_NCH; j++ ) + { + FOR( k = 0; k < hMCParamUpmix->hFbMixer->pFb->filterbank_num_bands; k++ ) + { + hMCParamUpmix->cov_real[b][i][j][k] = me2f( cov_real_fx[i][j][k], sub( Q31, hMCParamUpmix->hCovEnc[b]->pCov_state->q_cov_real_per_band[i][j][k] ) ); + hMCParamUpmix->cov_dtx_real[b][i][j][k] = me2f( cov_dtx_real_fx[i][j][k], sub( Q31, hMCParamUpmix->hCovEnc[b]->pCov_dtx_state->q_cov_real_per_band[i][j][k] ) ); + } + } + free( q_cov_real[i] ); + q_cov_real[i] = NULL; + free( q_cov_dtx_real[i] ); + q_cov_dtx_real[i] = NULL; + } + // Note: No need to convert pp_in_fr_real_fx and pp_in_fr_imag_fx back to float as they are not used after ivas_mc_paramupmix_param_est_enc() + + FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH; i++ ) + { + free( pp_in_fr_real_fx[i] ); + pp_in_fr_real_fx[i] = NULL; + free( pp_in_fr_imag_fx[i] ); + pp_in_fr_imag_fx[i] = NULL; + } +#endif } maxbands = hMCParamUpmix->hFbMixer->pFb->filterbank_num_bands; @@ -824,5 +933,9 @@ static void ivas_mc_paramupmix_param_est_enc( } } +#ifdef IVAS_FLOAT_FIXED + return IVAS_ERR_OK; +#else return; +#endif } diff --git a/lib_enc/ivas_osba_enc.c b/lib_enc/ivas_osba_enc.c index 296dbce5c..5389d11d2 100644 --- a/lib_enc/ivas_osba_enc.c +++ b/lib_enc/ivas_osba_enc.c @@ -42,6 +42,8 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "prot_fx1.h" +#include "prot_fx2.h" #endif @@ -170,7 +172,264 @@ void ivas_osba_enc_close( * * oSBA encoder reconfiguration *--------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_osba_enc_reconfig( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + + Word16 n, nSCE_old, nCPE_old, nchan_transport_old; + ISM_MODE old_ism_mode; + Word32 ivas_total_brate; + ivas_error error; + ENCODER_CONFIG_HANDLE hEncoderConfig; + + error = IVAS_ERR_OK; move32(); + hEncoderConfig = st_ivas->hEncoderConfig; + ivas_total_brate = hEncoderConfig->ivas_total_brate; move32(); + + IF ( NE_32(ivas_total_brate, hEncoderConfig->last_ivas_total_brate) ) + { + DIRAC_ENC_HANDLE hDirAC = st_ivas->hDirAC; + SPAR_ENC_HANDLE hSpar; + int16_t analysis_order_old; + int16_t spar_reconfig_flag; + int16_t nbands_old; + int16_t ndir_old; + + spar_reconfig_flag = 0;move16(); + old_ism_mode = st_ivas->ism_mode;move32(); + IF ( GE_32(ivas_total_brate, IVAS_256k) ) + { + st_ivas->ism_mode = ISM_SBA_MODE_DISC;move32(); + } + ELSE + { + st_ivas->ism_mode = ISM_MODE_NONE;move32(); + } + nchan_transport_old = st_ivas->nchan_transport; + nCPE_old = st_ivas->nCPE; + nSCE_old = st_ivas->nSCE; + move16(); + move16(); + move16(); + + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, hEncoderConfig->sba_order ); + move16(); + analysis_order_old = ivas_sba_get_analysis_order_fx( hEncoderConfig->last_ivas_total_brate, hEncoderConfig->sba_order ); + + nbands_old = st_ivas->hQMetaData->q_direction->cfg.nbands; + move16(); + ndir_old = st_ivas->hQMetaData->no_directions; + move16(); + + test(); + IF ( NE_16( analysis_order_old, st_ivas->sba_analysis_order ) || NE_32( old_ism_mode, st_ivas->ism_mode ) ) + { + Word16 i, n_old; + Word32 **old_mem_hp20_in_fx; + + n_old = add(st_ivas->hEncoderConfig->nchan_ism, imult1616(add( analysis_order_old, 1 ), add( analysis_order_old, 1 ))); + n = add(st_ivas->hEncoderConfig->nchan_ism, imult1616(add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ))); +#if 1 // To be removed + float **old_mem_hp20_in; + + if ( n > n_old ) + { + /* save old mem_hp_20 pointer */ + old_mem_hp20_in = st_ivas->mem_hp20_in; + st_ivas->mem_hp20_in = NULL; + + if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + for ( i = 0; i < n_old; i++ ) + { + st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; + old_mem_hp20_in[i] = NULL; + } + /* create additional hp20 memories */ + for ( ; i < n; i++ ) + { + if ( ( st_ivas->mem_hp20_in[i] = (float *) malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); + } + + free( old_mem_hp20_in ); + old_mem_hp20_in = NULL; + } + else if ( n < n_old ) + { + /* save old mem_hp_20 pointer */ + old_mem_hp20_in = st_ivas->mem_hp20_in; + st_ivas->mem_hp20_in = NULL; + + if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + for ( i = 0; i < n; i++ ) + { + st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; + old_mem_hp20_in[i] = NULL; + } + /* remove superfluous hp20 memories */ + for ( ; i < n_old; i++ ) + { + free( old_mem_hp20_in[i] ); + old_mem_hp20_in[i] = NULL; + } + + free( old_mem_hp20_in ); + old_mem_hp20_in = NULL; + } +#endif + IF( GT_16( n, n_old ) ) + { + /* save old mem_hp_20 pointer */ + old_mem_hp20_in_fx = st_ivas->mem_hp20_in_fx; + st_ivas->mem_hp20_in_fx = NULL; + + IF ( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + FOR ( i = 0; i < n_old; i++ ) + { + st_ivas->mem_hp20_in_fx[i] = old_mem_hp20_in_fx[i]; + old_mem_hp20_in_fx[i] = NULL; + } + /* create additional hp20 memories */ + FOR ( ; i < n; i++ ) + { + IF ( ( st_ivas->mem_hp20_in_fx[i] = (Word32 *) malloc( (L_HP20_MEM+2) * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + set32_fx( st_ivas->mem_hp20_in_fx[i], 0, L_HP20_MEM + 2 ); + } + + free( old_mem_hp20_in_fx ); + old_mem_hp20_in_fx = NULL; + } + ELSE IF ( LT_16(n, n_old) ) + { + /* save old mem_hp_20 pointer */ + old_mem_hp20_in_fx = st_ivas->mem_hp20_in_fx; + st_ivas->mem_hp20_in_fx = NULL; + + IF ( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + FOR ( i = 0; i < n; i++ ) + { + st_ivas->mem_hp20_in_fx[i] = old_mem_hp20_in_fx[i]; + old_mem_hp20_in_fx[i] = NULL; + } + /* remove superfluous hp20 memories */ + FOR ( ; i < n_old; i++ ) + { + free( old_mem_hp20_in_fx[i] ); + old_mem_hp20_in_fx[i] = NULL; + } + + free( old_mem_hp20_in_fx ); + old_mem_hp20_in_fx = NULL; + } + + } + + ivas_spar_config( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); + + hSpar = st_ivas->hSpar; + + if ( st_ivas->nchan_transport == 1 ) + { + hEncoderConfig->element_mode_init = IVAS_SCE; + } + else + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + if ( nchan_transport_old != st_ivas->nchan_transport || ( ivas_total_brate < IVAS_512k && hEncoderConfig->last_ivas_total_brate >= IVAS_512k ) || ( ivas_total_brate >= IVAS_512k && hEncoderConfig->last_ivas_total_brate < IVAS_512k ) ) + { + /* FB mixer handle */ + if ( hDirAC->hFbMixer != NULL ) + { + ivas_FB_mixer_close( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs, 0 ); + hDirAC->hFbMixer = NULL; + } + spar_reconfig_flag = 1; + ivas_spar_enc_close( &( st_ivas->hSpar ), hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); + + if ( ( error = ivas_spar_enc_open( st_ivas, spar_reconfig_flag ) ) != IVAS_ERR_OK ) + { + return error; + } + } + st_ivas->hSpar->spar_reconfig_flag = spar_reconfig_flag; + if ( ( error = ivas_dirac_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + if ( st_ivas->hQMetaData->q_direction->cfg.nbands != nbands_old || st_ivas->hQMetaData->no_directions != ndir_old ) + { + int16_t dir, j, i; + IVAS_QDIRECTION *q_direction = st_ivas->hQMetaData->q_direction; + for ( dir = 0; dir < st_ivas->hQMetaData->no_directions; dir++ ) + { + for ( j = 0; j < q_direction[dir].cfg.nbands; j++ ) + { + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + q_direction[dir].band_data[j].energy_ratio_index[i] = 0; + q_direction[dir].band_data[j].energy_ratio_index_mod[i] = 0; + } + } + } + } + hSpar->enc_param_start_band = hDirAC->hConfig->enc_param_start_band; + + /*-----------------------------------------------------------------* + * Allocate, initialize, and configure SCE/CPE/MCT handles + *-----------------------------------------------------------------*/ + + if ( old_ism_mode == ISM_MODE_NONE && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + { + st_ivas->nCPE += ( st_ivas->hEncoderConfig->nchan_ism + 1 ) >> 1; + } + else if ( old_ism_mode == ISM_SBA_MODE_DISC && st_ivas->ism_mode == ISM_MODE_NONE ) + { + nchan_transport_old += st_ivas->hEncoderConfig->nchan_ism; + } + else if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + { + st_ivas->nCPE += ( st_ivas->hEncoderConfig->nchan_ism + 1 ) >> 1; + nCPE_old = st_ivas->nCPE; + nchan_transport_old = st_ivas->nchan_transport; + nchan_transport_old += st_ivas->hEncoderConfig->nchan_ism; + } + + if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, ivas_total_brate / st_ivas->nchan_transport, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + return error; +} +#else ivas_error ivas_osba_enc_reconfig( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) @@ -208,13 +467,10 @@ ivas_error ivas_osba_enc_reconfig( nchan_transport_old = st_ivas->nchan_transport; nCPE_old = st_ivas->nCPE; nSCE_old = st_ivas->nSCE; -#ifndef IVAS_FLOAT_FIXED + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, hEncoderConfig->sba_order ); analysis_order_old = ivas_sba_get_analysis_order( hEncoderConfig->last_ivas_total_brate, hEncoderConfig->sba_order ); -#else - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, hEncoderConfig->sba_order ); - analysis_order_old = ivas_sba_get_analysis_order_fx( hEncoderConfig->last_ivas_total_brate, hEncoderConfig->sba_order ); -#endif + nbands_old = st_ivas->hQMetaData->q_direction->cfg.nbands; ndir_old = st_ivas->hQMetaData->no_directions; @@ -363,7 +619,7 @@ ivas_error ivas_osba_enc_reconfig( return error; } - +#endif /*--------------------------------------------------------------------------* * ivas_osba_enc() diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index cbd9c869d..2ebcdba1e 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -43,6 +43,8 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "prot_fx1.h" +#include "prot_fx2.h" #endif @@ -87,7 +89,244 @@ void ivas_sba_getTCs( * * Reconfigure IVAS SBA encoder *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +/* To be renamed as ivas_sba_enc_reconfigure_fx later */ +ivas_error ivas_sba_enc_reconfigure( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + Word16 n, nSCE_old, nCPE_old, nchan_transport_old; + Word32 ivas_total_brate; + ivas_error error; + ENCODER_CONFIG_HANDLE hEncoderConfig; + + error = IVAS_ERR_OK; + move32(); + hEncoderConfig = st_ivas->hEncoderConfig; + ivas_total_brate = hEncoderConfig->ivas_total_brate; + move32(); + + IF( NE_32( ivas_total_brate, hEncoderConfig->last_ivas_total_brate ) ) + { + DIRAC_ENC_HANDLE hDirAC = st_ivas->hDirAC; + SPAR_ENC_HANDLE hSpar; + Word16 analysis_order_old; + Word16 spar_reconfig_flag; + Word16 nbands_old; + Word16 ndir_old; + + spar_reconfig_flag = 0; + nchan_transport_old = st_ivas->nchan_transport; + nCPE_old = st_ivas->nCPE; + nSCE_old = st_ivas->nSCE; + move16(); + move16(); + move16(); + move16(); + + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, hEncoderConfig->sba_order ); + move16(); + analysis_order_old = ivas_sba_get_analysis_order_fx( hEncoderConfig->last_ivas_total_brate, hEncoderConfig->sba_order ); + + nbands_old = st_ivas->hQMetaData->q_direction->cfg.nbands; + move16(); + ndir_old = st_ivas->hQMetaData->no_directions; + move16(); + + IF( NE_16( analysis_order_old, st_ivas->sba_analysis_order ) ) + { + Word16 i, n_old; + Word32 **old_mem_hp20_in_fx; + + n_old = imult1616( add( analysis_order_old, 1 ), add( analysis_order_old, 1 ) ); + n = imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ); +#if 1 // To be removed + float **old_mem_hp20_in; + + if ( n > n_old ) + { + /* save old mem_hp_20 pointer */ + old_mem_hp20_in = st_ivas->mem_hp20_in; + st_ivas->mem_hp20_in = NULL; + + if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + for ( i = 0; i < n_old; i++ ) + { + st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; + old_mem_hp20_in[i] = NULL; + } + /* create additional hp20 memories */ + for ( ; i < n; i++ ) + { + if ( ( st_ivas->mem_hp20_in[i] = (float *) malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); + } + + free( old_mem_hp20_in ); + old_mem_hp20_in = NULL; + } + else if ( n < n_old ) + { + /* save old mem_hp_20 pointer */ + old_mem_hp20_in = st_ivas->mem_hp20_in; + st_ivas->mem_hp20_in = NULL; + + if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + for ( i = 0; i < n; i++ ) + { + st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; + old_mem_hp20_in[i] = NULL; + } + /* remove superfluous hp20 memories */ + for ( ; i < n_old; i++ ) + { + free( old_mem_hp20_in[i] ); + old_mem_hp20_in[i] = NULL; + } + + free( old_mem_hp20_in ); + old_mem_hp20_in = NULL; + } +#endif + IF( GT_16( n, n_old ) ) + { + /* save old mem_hp_20 pointer */ + old_mem_hp20_in_fx = st_ivas->mem_hp20_in_fx; + st_ivas->mem_hp20_in_fx = NULL; + + IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + FOR( i = 0; i < n_old; i++ ) + { + st_ivas->mem_hp20_in_fx[i] = old_mem_hp20_in_fx[i]; + old_mem_hp20_in_fx[i] = NULL; + } + /* create additional hp20 memories */ + FOR( ; i < n; i++ ) + { + IF( ( st_ivas->mem_hp20_in_fx[i] = (Word32 *) malloc( ( L_HP20_MEM + 2 ) * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + set32_fx( st_ivas->mem_hp20_in_fx[i], 0, L_HP20_MEM + 2 ); + } + + free( old_mem_hp20_in_fx ); + old_mem_hp20_in_fx = NULL; + } + ELSE IF( LT_16( n, n_old ) ) + { + /* save old mem_hp_20 pointer */ + old_mem_hp20_in_fx = st_ivas->mem_hp20_in_fx; + st_ivas->mem_hp20_in_fx = NULL; + + IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + FOR( i = 0; i < n; i++ ) + { + st_ivas->mem_hp20_in_fx[i] = old_mem_hp20_in_fx[i]; + old_mem_hp20_in_fx[i] = NULL; + } + /* remove superfluous hp20 memories */ + FOR( ; i < n_old; i++ ) + { + free( old_mem_hp20_in_fx[i] ); + old_mem_hp20_in_fx[i] = NULL; + } + + free( old_mem_hp20_in_fx ); + old_mem_hp20_in_fx = NULL; + } + } + + ivas_spar_config( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); + + hSpar = st_ivas->hSpar; + + if ( st_ivas->nchan_transport == 1 ) + { + hEncoderConfig->element_mode_init = IVAS_SCE; + } + else + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + + if ( nchan_transport_old != st_ivas->nchan_transport || ( ivas_total_brate < IVAS_512k && hEncoderConfig->last_ivas_total_brate >= IVAS_512k ) || ( ivas_total_brate >= IVAS_512k && hEncoderConfig->last_ivas_total_brate < IVAS_512k ) ) + { + /* FB mixer handle */ + if ( hDirAC->hFbMixer != NULL ) + { + ivas_FB_mixer_close( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs, 0 ); + hDirAC->hFbMixer = NULL; + } + spar_reconfig_flag = 1; + ivas_spar_enc_close( &( st_ivas->hSpar ), hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); + + if ( ( error = ivas_spar_enc_open( st_ivas, spar_reconfig_flag ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + st_ivas->hSpar->spar_reconfig_flag = spar_reconfig_flag; + + if ( ( error = ivas_dirac_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( st_ivas->hQMetaData->q_direction->cfg.nbands != nbands_old || st_ivas->hQMetaData->no_directions != ndir_old ) + { + int16_t dir, j, i; + IVAS_QDIRECTION *q_direction = st_ivas->hQMetaData->q_direction; + for ( dir = 0; dir < st_ivas->hQMetaData->no_directions; dir++ ) + { + for ( j = 0; j < q_direction[dir].cfg.nbands; j++ ) + { + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + q_direction[dir].band_data[j].energy_ratio_index[i] = 0; + q_direction[dir].band_data[j].energy_ratio_index_mod[i] = 0; + } + } + } + } + hSpar->enc_param_start_band = hDirAC->hConfig->enc_param_start_band; + + /*-----------------------------------------------------------------* + * Allocate, initialize, and configure SCE/CPE/MCT handles + *-----------------------------------------------------------------*/ + + if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, ivas_total_brate / st_ivas->nchan_transport, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + return error; +} +#else ivas_error ivas_sba_enc_reconfigure( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) @@ -114,13 +353,10 @@ ivas_error ivas_sba_enc_reconfigure( nchan_transport_old = st_ivas->nchan_transport; nCPE_old = st_ivas->nCPE; nSCE_old = st_ivas->nSCE; -#ifndef IVAS_FLOAT_FIXED + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, hEncoderConfig->sba_order ); analysis_order_old = ivas_sba_get_analysis_order( hEncoderConfig->last_ivas_total_brate, hEncoderConfig->sba_order ); -#else - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, hEncoderConfig->sba_order ); - analysis_order_old = ivas_sba_get_analysis_order_fx( hEncoderConfig->last_ivas_total_brate, hEncoderConfig->sba_order ); -#endif + nbands_old = st_ivas->hQMetaData->q_direction->cfg.nbands; ndir_old = st_ivas->hQMetaData->no_directions; @@ -257,3 +493,4 @@ ivas_error ivas_sba_enc_reconfigure( return error; } +#endif diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 238a9ff7b..b1e9ad53a 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -150,10 +150,17 @@ ivas_error ivas_spar_enc_open( } /* Covariance handle */ +#ifdef IVAS_FLOAT_FIXED + IF( NE_32( ( error = ivas_spar_covar_enc_open_fx( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, input_Fs, nchan_inp, COV_SMOOTH_SPAR, hEncoderConfig->ivas_total_brate ) ), IVAS_ERR_OK ) ) + { + return error; + } +#else if ( ( error = ivas_spar_covar_enc_open( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, input_Fs, nchan_inp, COV_SMOOTH_SPAR, hEncoderConfig->ivas_total_brate ) ) != IVAS_ERR_OK ) { return error; } +#endif if ( !spar_reconfig_flag ) { @@ -344,10 +351,17 @@ ivas_error ivas_spar_enc_open_fx( } /* Covariance handle */ +#ifdef IVAS_FLOAT_FIXED + IF( NE_32( ( error = ivas_spar_covar_enc_open_fx( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, input_Fs, nchan_inp, COV_SMOOTH_SPAR, hEncoderConfig->ivas_total_brate ) ), IVAS_ERR_OK ) ) + { + return error; + } +#else IF( ( error = ivas_spar_covar_enc_open( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, input_Fs, nchan_inp, COV_SMOOTH_SPAR, hEncoderConfig->ivas_total_brate ) ) != IVAS_ERR_OK ) { return error; } +#endif IF( !spar_reconfig_flag ) { @@ -494,7 +508,11 @@ void ivas_spar_enc_close( ivas_spar_md_enc_close( &( *hSpar )->hMdEnc ); /* Covar. State handle */ +#ifdef IVAS_FLOAT_FIXED + ivas_spar_covar_enc_close_fx( &( *hSpar )->hCovEnc, num_chans ); +#else ivas_spar_covar_enc_close( &( *hSpar )->hCovEnc, num_chans ); +#endif /* FB mixer handle */ ivas_FB_mixer_close( &( *hSpar )->hFbMixer, input_Fs, spar_reconfig_flag ); diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 3e9ec271f..37aebacef 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -855,10 +855,11 @@ typedef struct ivas_enc_cov_handler_state_t ivas_cov_smooth_state_t *pCov_dtx_state; int16_t num_bins; int16_t prior_dtx_present; - float bb_var_lt[FOA_CHANNELS]; int16_t prior_var_flag; #ifdef IVAS_FLOAT_FIXED Word32 bb_var_lt_fx[FOA_CHANNELS]; +#else + float bb_var_lt[FOA_CHANNELS]; #endif } ivas_enc_cov_handler_state_t; @@ -1351,8 +1352,9 @@ typedef struct ivas_lfe_enc_data_structure const uint16_t *cum_freq_models[IVAS_MAX_NUM_QUANT_STRATS][IVAS_MAX_NUM_DCT_COEF_GROUPS]; int16_t lfe_enc_indices_coeffs_tbl[IVAS_MAX_NUM_QUANT_STRATS][IVAS_MAX_NUM_DCT_COEF_GROUPS]; int16_t lfe_bits; +#ifndef IVAS_FLOAT_FIXED float *old_wtda_audio; -#ifdef IVAS_FLOAT_FIXED +#else Word32 *old_wtda_audio_fx; Word16 q_old_wtda_audio; #endif // IVAS_FLOAT_FIXED @@ -1414,7 +1416,10 @@ typedef struct ENCODER_CONFIG_HANDLE hEncoderConfig; /* Encoder configuration structure */ float *p_data_f[MAX_INPUT_CHANNELS+MAX_NUM_OBJECTS]; /* floating-point input audio buffers */ - +#ifdef IVAS_FLOAT_FIXED + Word32 *p_data_fx[MAX_INPUT_CHANNELS+MAX_NUM_OBJECTS]; /* fixed-point input audio buffers */ + Word16 q_data_fx; /* Q-factor of fixed-point input audio buffers */ +#endif Indice *ind_list; /* List of indices */ Word16 ivas_max_num_indices; /* Maximum allowed number of indices in the list */ Indice *ind_list_metadata; /* List of indices for metadata */ @@ -1426,6 +1431,9 @@ typedef struct Word16 codec_mode; /* Mode1 or Mode2 of core codec */ Word16 last_codec_mode; /* previous frame Mode 1 or 2 */ float **mem_hp20_in; /* input signals HP filter memories */ +#ifdef IVAS_FLOAT_FIXED + Word32 **mem_hp20_in_fx; /* input signals HP filter memories */ +#endif /* core-encoder modules */ Word16 nSCE; /* number of total SCEs */ -- GitLab From e51b4cdcb6505a1d8c39b2d64ed1fe692ff82ad4 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 8 Jul 2024 21:49:43 +0530 Subject: [PATCH 2/2] Clang formatting changes --- lib_com/ivas_stat_com.h | 2 +- lib_com/ivas_tools.c | 67 +++++++++++++++++++++++++++++++++-------- lib_enc/ivas_lfe_enc.c | 8 ++--- lib_enc/ivas_osba_enc.c | 45 +++++++++++++++------------ 4 files changed, 85 insertions(+), 37 deletions(-) diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 1a2542ed4..8a042ca26 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -599,7 +599,7 @@ typedef struct ivas_masa_qmetadata_frame_struct #ifndef IVAS_FLOAT_FIXED float dir_comp_ratio; #else - Word16 dir_comp_ratio_fx; /* Q15 */ + Word16 dir_comp_ratio_fx; /* Q15 */ #endif uint8_t is_masa_ivas_format; diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 0e24db967..e42efb441 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -2555,21 +2555,64 @@ void lls_interp_n_fx( { Word16 i; const Word16 n_i_fx[11] = { 0, 2048, 4096, 6144, 8192, 10240, 12288, 14336, 16384, 18432, 20480 }; // Q11 - move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); const Word16 one_by_n_fx[11] = { 0, 32767, 16384, 10911, 8192, 6553, 5459, 4681, 4096, 3640, 3276 }; - move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); const Word16 sum_i_fx[12] = { 0, 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55 }; - move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); // 1.0f/ ( N * sum_ii[N] - sum_i[N] * sum_i[N] ) const Word32 res_table[12] = { 0, 0, 0, 357913952, 107374184, 42949672, 20452226, 10956549, 6391320, 3976821, 2603010, 385 }; - move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); Word32 sum_x_fx, sum_ix_fx, slope_fx, offset_fx; Word16 dot_exp = 0, sum_ix_q = 0; - move16(); move16(); + move16(); + move16(); Word32 num; assert( N > 0 && LE_16( N, 10 ) ); @@ -3002,8 +3045,8 @@ Word16 is_SIDrate( test(); test(); if ( EQ_32( ivas_total_brate, SID_1k75 ) || - EQ_32( ivas_total_brate, SID_2k40 ) || - EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) + EQ_32( ivas_total_brate, SID_2k40 ) || + EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { sid_rate_flag = 1; move16(); @@ -3373,9 +3416,9 @@ Word16 ceil_log_2( *-------------------------------------------------------------------*/ Word64 var_32_fx( - const Word32 *x, /* i : input vector */ - const Word16 len, /* i : length of inputvector */ - Word16 q /* q : q-factor for the array */ + const Word32 *x, /* i : input vector */ + const Word16 len, /* i : length of inputvector */ + Word16 q /* q : q-factor for the array */ ) { @@ -3391,7 +3434,7 @@ Word64 var_32_fx( mean = W_add( mean, x[i] ); } - mean = mean / len; /* NOTE: No BASOP for 64 bit division */ + mean = mean / len; /* NOTE: No BASOP for 64 bit division */ FOR( int i = 0; i < len; i++ ) { @@ -3400,7 +3443,7 @@ Word64 var_32_fx( var = W_shl( var, sub( 31, q ) ); - var = var / len; /* NOTE: No BASOP for 64 bit division */ + var = var / len; /* NOTE: No BASOP for 64 bit division */ return var; } diff --git a/lib_enc/ivas_lfe_enc.c b/lib_enc/ivas_lfe_enc.c index f4923cafd..8d0f57495 100644 --- a/lib_enc/ivas_lfe_enc.c +++ b/lib_enc/ivas_lfe_enc.c @@ -782,7 +782,7 @@ void ivas_lfe_enc_fx( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_create_lfe_enc( LFE_ENC_HANDLE *hLFE_out, /* o : IVAS LFE encoder structure */ - const Word32 input_Fs /* i : input sampling rate */ + const Word32 input_Fs /* i : input sampling rate */ ) { Word16 input_frame; @@ -795,7 +795,7 @@ ivas_error ivas_create_lfe_enc( * Allocate LFE handle *-----------------------------------------------------------------*/ - IF ( ( hLFE = (LFE_ENC_HANDLE) malloc( sizeof( LFE_ENC_DATA ) ) ) == NULL ) + IF( ( hLFE = (LFE_ENC_HANDLE) malloc( sizeof( LFE_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE\n" ) ); } @@ -823,7 +823,7 @@ ivas_error ivas_create_lfe_enc( * LFE Window: allocate and initialize *-----------------------------------------------------------------*/ - IF ( ( hLFE->pWindow_state = (LFE_WINDOW_HANDLE) malloc( sizeof( LFE_WINDOW_DATA ) ) ) == NULL ) + IF( ( hLFE->pWindow_state = (LFE_WINDOW_HANDLE) malloc( sizeof( LFE_WINDOW_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE window structure\n" ) ); } @@ -841,7 +841,7 @@ ivas_error ivas_create_lfe_enc( hLFE->cum_freq_models[1][3] = &ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg4; /* Initialization base2 bits for each subgroup for no entropy coding */ - FOR ( i = 0; i < IVAS_MAX_NUM_QUANT_STRATS; i++ ) + FOR( i = 0; i < IVAS_MAX_NUM_QUANT_STRATS; i++ ) { FOR( j = 0; j < IVAS_MAX_NUM_DCT_COEF_GROUPS; j++ ) { diff --git a/lib_enc/ivas_osba_enc.c b/lib_enc/ivas_osba_enc.c index 5389d11d2..5a8fcfa78 100644 --- a/lib_enc/ivas_osba_enc.c +++ b/lib_enc/ivas_osba_enc.c @@ -184,11 +184,13 @@ ivas_error ivas_osba_enc_reconfig( ivas_error error; ENCODER_CONFIG_HANDLE hEncoderConfig; - error = IVAS_ERR_OK; move32(); + error = IVAS_ERR_OK; + move32(); hEncoderConfig = st_ivas->hEncoderConfig; - ivas_total_brate = hEncoderConfig->ivas_total_brate; move32(); + ivas_total_brate = hEncoderConfig->ivas_total_brate; + move32(); - IF ( NE_32(ivas_total_brate, hEncoderConfig->last_ivas_total_brate) ) + IF( NE_32( ivas_total_brate, hEncoderConfig->last_ivas_total_brate ) ) { DIRAC_ENC_HANDLE hDirAC = st_ivas->hDirAC; SPAR_ENC_HANDLE hSpar; @@ -197,15 +199,19 @@ ivas_error ivas_osba_enc_reconfig( int16_t nbands_old; int16_t ndir_old; - spar_reconfig_flag = 0;move16(); - old_ism_mode = st_ivas->ism_mode;move32(); - IF ( GE_32(ivas_total_brate, IVAS_256k) ) + spar_reconfig_flag = 0; + move16(); + old_ism_mode = st_ivas->ism_mode; + move32(); + IF( GE_32( ivas_total_brate, IVAS_256k ) ) { - st_ivas->ism_mode = ISM_SBA_MODE_DISC;move32(); + st_ivas->ism_mode = ISM_SBA_MODE_DISC; + move32(); } ELSE { - st_ivas->ism_mode = ISM_MODE_NONE;move32(); + st_ivas->ism_mode = ISM_MODE_NONE; + move32(); } nchan_transport_old = st_ivas->nchan_transport; nCPE_old = st_ivas->nCPE; @@ -224,13 +230,13 @@ ivas_error ivas_osba_enc_reconfig( move16(); test(); - IF ( NE_16( analysis_order_old, st_ivas->sba_analysis_order ) || NE_32( old_ism_mode, st_ivas->ism_mode ) ) + IF( NE_16( analysis_order_old, st_ivas->sba_analysis_order ) || NE_32( old_ism_mode, st_ivas->ism_mode ) ) { Word16 i, n_old; Word32 **old_mem_hp20_in_fx; - n_old = add(st_ivas->hEncoderConfig->nchan_ism, imult1616(add( analysis_order_old, 1 ), add( analysis_order_old, 1 ))); - n = add(st_ivas->hEncoderConfig->nchan_ism, imult1616(add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ))); + n_old = add( st_ivas->hEncoderConfig->nchan_ism, imult1616( add( analysis_order_old, 1 ), add( analysis_order_old, 1 ) ) ); + n = add( st_ivas->hEncoderConfig->nchan_ism, imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ) ); #if 1 // To be removed float **old_mem_hp20_in; @@ -297,20 +303,20 @@ ivas_error ivas_osba_enc_reconfig( old_mem_hp20_in_fx = st_ivas->mem_hp20_in_fx; st_ivas->mem_hp20_in_fx = NULL; - IF ( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) + IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } - FOR ( i = 0; i < n_old; i++ ) + FOR( i = 0; i < n_old; i++ ) { st_ivas->mem_hp20_in_fx[i] = old_mem_hp20_in_fx[i]; old_mem_hp20_in_fx[i] = NULL; } /* create additional hp20 memories */ - FOR ( ; i < n; i++ ) + FOR( ; i < n; i++ ) { - IF ( ( st_ivas->mem_hp20_in_fx[i] = (Word32 *) malloc( (L_HP20_MEM+2) * sizeof( Word32 ) ) ) == NULL ) + IF( ( st_ivas->mem_hp20_in_fx[i] = (Word32 *) malloc( ( L_HP20_MEM + 2 ) * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } @@ -321,24 +327,24 @@ ivas_error ivas_osba_enc_reconfig( free( old_mem_hp20_in_fx ); old_mem_hp20_in_fx = NULL; } - ELSE IF ( LT_16(n, n_old) ) + ELSE IF( LT_16( n, n_old ) ) { /* save old mem_hp_20 pointer */ old_mem_hp20_in_fx = st_ivas->mem_hp20_in_fx; st_ivas->mem_hp20_in_fx = NULL; - IF ( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) + IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } - FOR ( i = 0; i < n; i++ ) + FOR( i = 0; i < n; i++ ) { st_ivas->mem_hp20_in_fx[i] = old_mem_hp20_in_fx[i]; old_mem_hp20_in_fx[i] = NULL; } /* remove superfluous hp20 memories */ - FOR ( ; i < n_old; i++ ) + FOR( ; i < n_old; i++ ) { free( old_mem_hp20_in_fx[i] ); old_mem_hp20_in_fx[i] = NULL; @@ -347,7 +353,6 @@ ivas_error ivas_osba_enc_reconfig( free( old_mem_hp20_in_fx ); old_mem_hp20_in_fx = NULL; } - } ivas_spar_config( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); -- GitLab