diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 7d84adbb12c971c785f1f08baeff0bd98035fb9b..684462b41b8ba1404ded09145d847ec45a7ccf60 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -907,6 +907,9 @@ typedef enum { DIRAC_OPEN, /* initialize to default value */ DIRAC_RECONFIGURE /* HOA3 */ +#ifdef SBA_BITRATE_SWITCHING // VE2FhG: TBV - just dirty patch for the moment + ,DIRAC_RECONFIGURE_MODE /* HOA3 */ +#endif } DIRAC_CONFIG_FLAG; diff --git a/lib_com/ivas_cov_smooth.c b/lib_com/ivas_cov_smooth.c index 00158712871c6b35dcbbb73aa274f4d0ae4c057d..3ebd1ba3f709bbaac567db889de63dfed9c11fc0 100644 --- a/lib_com/ivas_cov_smooth.c +++ b/lib_com/ivas_cov_smooth.c @@ -180,7 +180,7 @@ static void ivas_compute_smooth_cov( const int16_t end_band #ifdef SBA_SPAR_HARM , - const int16_t num_ch, + const int16_t nchan, const int16_t transient_det #endif ) @@ -188,7 +188,7 @@ static void ivas_compute_smooth_cov( int16_t i, j, k; int16_t prev_idx = hCovState->prior_bank_idx; #ifndef SBA_SPAR_HARM - int16_t num_ch = pIn_buf->num_ch; + int16_t nchan = pIn_buf->nchan; #endif float factor = 0; @@ -200,7 +200,7 @@ static void ivas_compute_smooth_cov( if ( prev_idx == -1 || pIn_buf->reset_cov == 1 ) #endif { - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { for ( k = start_band; k < end_band; k++ ) { @@ -210,9 +210,9 @@ static void ivas_compute_smooth_cov( } else if ( prev_idx == 0 ) { - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( i == j ) { @@ -253,26 +253,26 @@ void ivas_cov_smooth_process( const int16_t end_band #ifdef SBA_SPAR_HARM , - const int16_t num_ch, + const int16_t nchan, const int16_t transient_det #endif ) { int16_t i, j; #ifndef SBA_SPAR_HARM - int16_t num_ch = pIn_buf->num_ch; + int16_t nchan = pIn_buf->nchan; #endif int16_t num_bands = end_band - start_band; #ifdef SBA_SPAR_HARM - ivas_compute_smooth_cov( hCovState, pFb, cov_real, hCovState->pPrior_cov_real, 1e-20f, start_band, end_band, num_ch, transient_det ); + ivas_compute_smooth_cov( hCovState, pFb, cov_real, hCovState->pPrior_cov_real, 1e-20f, start_band, end_band, nchan, transient_det ); #else ivas_compute_smooth_cov( hCovState, pIn_buf, pFb, pIn_buf->cov_real, hCovState->pPrior_cov_real, 1e-20f, start_band, end_band ); #endif - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { #ifdef SBA_SPAR_HARM mvr2r( &cov_real[i][j][start_band], &hCovState->pPrior_cov_real[i][j][start_band], num_bands ); diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 53ad90d01ff0bbb9ba48dc8a647bdb06e362c70f..8419fea31f86907a4e9a7171aa974cf95dcd5dba 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -102,8 +102,8 @@ ivas_error ivas_fb_set_cfg( IVAS_FB_CFG **pFb_cfg_out, /* o : FB config. handle */ const int16_t ivas_format, /* i : IVAS format */ const SBA_MODE sba_mode, /* i : SBA mode */ - const int16_t num_in_chans, /* i : number of FB input channels */ - const int16_t num_out_chans, /* i : number of FB output channels*/ + const int16_t nchan_inp, /* i : number of FB input channels */ + const int16_t nchan_out, /* i : number of FB output channels*/ const int16_t active_w_mixing, /* i : active_w_mixing flag */ const int32_t sampling_rate /* i : sampling rate */ ) @@ -115,8 +115,8 @@ ivas_error ivas_fb_set_cfg( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer config" ); } - pFb_cfg->num_in_chans = num_in_chans; - pFb_cfg->num_out_chans = num_out_chans; + pFb_cfg->nchan_inp = nchan_inp; + pFb_cfg->nchan_out = nchan_out; pFb_cfg->pcm_offset = 0; /* note: in SPAR decoder, this parameter is overwritten later */ pFb_cfg->active_w_mixing = active_w_mixing; @@ -179,7 +179,7 @@ ivas_error ivas_FB_mixer_open( { IVAS_FB_MIXER_HANDLE hFbMixer; int16_t i, j, frame_len, num_bands; - int16_t num_chs_alloc; + int16_t nchan_alloc; ivas_error error; error = IVAS_ERR_OK; @@ -198,20 +198,20 @@ ivas_error ivas_FB_mixer_open( if ( fb_cfg->active_w_mixing == -1 ) { - num_chs_alloc = 0; + nchan_alloc = 0; } else if ( fb_cfg->active_w_mixing ) { - num_chs_alloc = fb_cfg->num_in_chans; + nchan_alloc = fb_cfg->nchan_inp; } else { - num_chs_alloc = fb_cfg->num_out_chans; + nchan_alloc = fb_cfg->nchan_out; } - for ( i = 0; i < num_chs_alloc; i++ ) + for ( i = 0; i < nchan_alloc; i++ ) { - if ( fb_cfg->num_out_chans == 0 ) + if ( fb_cfg->nchan_out == 0 ) { hFbMixer->ppFilterbank_inFR_re[i] = NULL; hFbMixer->ppFilterbank_inFR_im[i] = NULL; @@ -234,13 +234,13 @@ ivas_error ivas_FB_mixer_open( if ( fb_cfg->active_w_mixing == -1 ) { - num_chs_alloc = 0; + nchan_alloc = 0; } else { - num_chs_alloc = fb_cfg->num_in_chans; + nchan_alloc = fb_cfg->nchan_inp; } - for ( i = 0; i < num_chs_alloc; i++ ) + for ( i = 0; i < nchan_alloc; i++ ) { if ( ( hFbMixer->ppFilterbank_prior_input[i] = (float *) count_malloc( sizeof( float ) * fb_cfg->prior_input_length ) ) == NULL ) { @@ -249,17 +249,17 @@ ivas_error ivas_FB_mixer_open( set_f( hFbMixer->ppFilterbank_prior_input[i], 0, fb_cfg->prior_input_length ); } - if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) ) + if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->nchan_out > 0 ) ) { float *pTemp_mem; - if ( ( pTemp_mem = (float *) count_malloc( sizeof( float ) * fb_cfg->num_out_chans * fb_cfg->num_in_chans * IVAS_MAX_NUM_BANDS ) ) == NULL ) + if ( ( pTemp_mem = (float *) count_malloc( sizeof( float ) * fb_cfg->nchan_out * fb_cfg->nchan_inp * IVAS_MAX_NUM_BANDS ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer" ); } - for ( i = 0; i < fb_cfg->num_out_chans; i++ ) + for ( i = 0; i < fb_cfg->nchan_out; i++ ) { - for ( j = 0; j < fb_cfg->num_in_chans; j++ ) + for ( j = 0; j < fb_cfg->nchan_inp; j++ ) { hFbMixer->prior_mixer[i][j] = pTemp_mem; pTemp_mem += IVAS_MAX_NUM_BANDS; @@ -268,7 +268,7 @@ ivas_error ivas_FB_mixer_open( } } - if ( fb_cfg->num_out_chans > 0 ) + if ( fb_cfg->nchan_out > 0 ) { const int16_t *pActive_bins_per_band, *pActive_bins_per_band_abs, *pStart_offset, *pStart_offset_abs; @@ -372,18 +372,18 @@ void ivas_FB_mixer_close( } else if ( fb_cfg->active_w_mixing ) { - num_chs_alloc = fb_cfg->num_in_chans; + num_chs_alloc = fb_cfg->nchan_inp; } else { - num_chs_alloc = fb_cfg->num_out_chans; + num_chs_alloc = fb_cfg->nchan_out; } if ( hFbMixer != NULL ) { for ( i = 0; i < num_chs_alloc; i++ ) { - if ( fb_cfg->num_out_chans > 0 ) + if ( fb_cfg->nchan_out > 0 ) { j = fb_cfg->remix_order[i]; @@ -401,7 +401,7 @@ void ivas_FB_mixer_close( } else { - num_chs_alloc = fb_cfg->num_in_chans; + num_chs_alloc = fb_cfg->nchan_inp; } for ( i = 0; i < num_chs_alloc; i++ ) { @@ -409,13 +409,13 @@ void ivas_FB_mixer_close( hFbMixer->ppFilterbank_prior_input[i] = NULL; } - if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) ) + if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->nchan_out > 0 ) ) { count_free( hFbMixer->prior_mixer[0][0] ); hFbMixer->prior_mixer[0][0] = NULL; } - if ( fb_cfg->num_out_chans > 0 ) + if ( fb_cfg->nchan_out > 0 ) { num_bands = hFbMixer->pFb->filterbank_num_bands; @@ -483,14 +483,14 @@ void ivas_fb_mixer_pcm_ingest( if ( fb_cfg->active_w_mixing ) { - num_chs_ingest = fb_cfg->num_in_chans; + num_chs_ingest = fb_cfg->nchan_inp; } else { - num_chs_ingest = fb_cfg->num_out_chans; + num_chs_ingest = fb_cfg->nchan_out; } - for ( i = 0; i < fb_cfg->num_in_chans; i++ ) + for ( i = 0; i < fb_cfg->nchan_inp; i++ ) { mvr2r( &hFbMixer->ppFilterbank_prior_input[i][fb_cfg->prior_input_length - frame_len], ppOut_pcm[i], frame_len ); mvr2r( pcm_in[i], &ppOut_pcm[i][frame_len], frame_len ); @@ -519,7 +519,7 @@ void ivas_fb_mixer_update_prior_input( { int16_t i; - for ( i = 0; i < hFbMixer->fb_cfg->num_in_chans; i++ ) + for ( i = 0; i < hFbMixer->fb_cfg->nchan_inp; i++ ) { mvr2r( &hFbMixer->ppFilterbank_prior_input[i][length], hFbMixer->ppFilterbank_prior_input[i], hFbMixer->fb_cfg->prior_input_length - length ); mvr2r( pcm_in[i], &hFbMixer->ppFilterbank_prior_input[i][hFbMixer->fb_cfg->prior_input_length - length], length ); @@ -556,7 +556,7 @@ void ivas_fb_mixer_get_windowed_fr( rev_offset = (int16_t) ( 2 * mdft_len - hFbMixer->ana_window_offset ); set_zero( fr_in_block, offset ); - for ( ch_idx = 0; ch_idx < hFbMixer->fb_cfg->num_in_chans; ch_idx++ ) + for ( ch_idx = 0; ch_idx < hFbMixer->fb_cfg->nchan_inp; ch_idx++ ) { mvr2r( &hFbMixer->ppFilterbank_prior_input[ch_idx][offset + hFbMixer->fb_cfg->windowed_fr_offset], &fr_in_block[offset], n_old_samples - offset ); mvr2r( pcm_in[ch_idx], &fr_in_block[n_old_samples], n_new_samples ); @@ -657,7 +657,7 @@ void ivas_fb_mixer_process( pMdft_out[0] = Mdft_out_0; pMdft_out[1] = Mdft_out_1; - for ( ch = ( hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) + for ( ch = ( hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hFbMixer->fb_cfg->nchan_out; ch++ ) { /* Run a loop of 2 to calculate current frame's filterbank output and prev frame's output */ for ( hist = 0; hist < 2; hist++ ) @@ -665,7 +665,7 @@ void ivas_fb_mixer_process( set_zero( pOut_fr_re, frame_len ); set_zero( pOut_fr_im, frame_len ); - for ( j = 0; j < hFbMixer->fb_cfg->num_in_chans; j++ ) + for ( j = 0; j < hFbMixer->fb_cfg->nchan_inp; j++ ) { if ( in_out_mixer_map[ch][j] != 0 ) { @@ -739,9 +739,9 @@ void ivas_fb_mixer_get_in_out_mapping( { if ( fb_cfg->active_w_mixing ) { - for ( i = 0; i < fb_cfg->num_out_chans; i++ ) + for ( i = 0; i < fb_cfg->nchan_out; i++ ) { - for ( j = 0; j < fb_cfg->num_in_chans; j++ ) + for ( j = 0; j < fb_cfg->nchan_inp; j++ ) { in_out_mixer_map[i][j] = 1; } @@ -750,7 +750,7 @@ void ivas_fb_mixer_get_in_out_mapping( else { in_out_mixer_map[0][0] = 1; /* W depends on only W input*/ - for ( i = 1; i < fb_cfg->num_out_chans; i++ ) + for ( i = 1; i < fb_cfg->nchan_out; i++ ) { in_out_mixer_map[i][0] = 1; in_out_mixer_map[i][order[i]] = 1; @@ -768,7 +768,7 @@ void ivas_fb_mixer_get_in_out_mapping( if ( nchan_transport == 1 ) { /* no cross predicitons in 1 ch dmx*/ - for ( i = nchan_transport; i < fb_cfg->num_out_chans; i++ ) + for ( i = nchan_transport; i < fb_cfg->nchan_out; i++ ) { in_out_mixer_map[order[i]][0] = 1; in_out_mixer_map[order[i]][i] = 1; @@ -777,7 +777,7 @@ void ivas_fb_mixer_get_in_out_mapping( else { /* handle the cross predictions and decorrelation*/ - for ( i = nchan_transport; i < fb_cfg->num_out_chans; i++ ) + for ( i = nchan_transport; i < fb_cfg->nchan_out; i++ ) { for ( j = 0; j < nchan_transport; j++ ) { @@ -820,8 +820,8 @@ static int16_t ivas_calculate_abs_fr( float short_stride_nrg = 0.0f; float cldfb_nrg = 0.0f; int16_t short_stride = pFb->fb_bin_to_band.short_stride; - const int16_t num_bins_per_short_stride_bin = ( const int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / short_stride ); - const int16_t num_bins_per_cldfb_band = ( const int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / pFb->fb_bin_to_band.num_cldfb_bands ); + const int16_t num_bins_per_short_stride_bin = (const int16_t) ( ( sampling_rate / FRAMES_PER_SEC ) / short_stride ); + const int16_t num_bins_per_cldfb_band = (const int16_t) ( ( sampling_rate / FRAMES_PER_SEC ) / pFb->fb_bin_to_band.num_cldfb_bands ); float short_stride_max_per_spar_band = 1e-9f; /*loop over all stored Filter Bank Response MDFT coefficients*/ @@ -1038,11 +1038,11 @@ static ivas_error ivas_filterbank_setup( error = IVAS_ERR_OK; - set_s( hFbMixer->first_frame, 1, pCfg->num_out_chans ); - set_s( hFbMixer->first_frame + pCfg->num_out_chans, 0, IVAS_SPAR_MAX_CH - pCfg->num_out_chans ); + set_s( hFbMixer->first_frame, 1, pCfg->nchan_out ); + set_s( hFbMixer->first_frame + pCfg->nchan_out, 0, IVAS_SPAR_MAX_CH - pCfg->nchan_out ); - if ( pCfg->num_out_chans > 0 ) + if ( pCfg->nchan_out > 0 ) { hFbMixer->pFb->filterbank_num_bands = ivas_get_num_bands( sampling_rate ); @@ -1078,7 +1078,7 @@ static ivas_error ivas_filterbank_setup( return error; } - if ( pCfg->num_out_chans > 0 ) + if ( pCfg->nchan_out > 0 ) { ivas_filterbank_t *pFb = hFbMixer->pFb; int16_t offset = 0; diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index ff23fb7ebf04df04dc9b29e02c882ee1404fcbf8..401366a9f00c2a5e4dd60a69c47325676f8490ed 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -654,7 +654,7 @@ MC_LS_SETUP ivas_mc_map_output_config_to_mc_ls_setup( /*! r: limiter struct handle */ IVAS_LIMITER_HANDLE ivas_limiter_open( - const int16_t num_channels, /* i : number of I/O channels */ + const int16_t nchan, /* i : number of I/O channels */ const int32_t sampling_rate /* i : sampling rate for processing */ ); @@ -666,7 +666,7 @@ void ivas_limiter_dec ( IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ float output[MAX_OUTPUT_CHANNELS][L_FRAME48k], /* i/o: input/output buffer */ - const int16_t num_channels, /* i : number of channels to be processed */ + const int16_t nchan, /* i : number of channels to be processed */ const int16_t output_frame, /* i : number of samples per channel in the buffer */ const int16_t BER_detect /* i : BER detect flag */ ); @@ -3113,9 +3113,9 @@ void ivas_sba_getTCs( ); ivas_error ivas_sba_linear_renderer( - float output_f[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ + float output[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ const int16_t output_frame, /* i : output frame length per channel */ - const int16_t nchan_in, /* i : number of input ambisonics channels */ + const int16_t nchan_inp, /* i : number of input ambisonics channels */ const AUDIO_CONFIG output_config, /* i : output audio configuration */ const IVAS_OUTPUT_SETUP output_setup, /* i : output format setup */ const float hoa_dec_mtx[] /* i : HOA decoding mtx */ @@ -3311,7 +3311,7 @@ void computeDiffuseness( ); void ivas_dirac_dec_onset_detection_open( - const int16_t num_channels, + const int16_t nchan, const int16_t num_freq_bands, const int16_t max_band_decorr, DIRAC_ONSET_DETECTION_PARAMS *ph_dirac_onset_detection_params, @@ -3340,7 +3340,7 @@ void ivas_dirac_dec_decorr_open( void ivas_dirac_dec_decorr_process( const int16_t num_freq_bands, - int16_t num_channels, + int16_t nchan, const int16_t num_protos_diff, const DIRAC_SYNTHESIS_CONFIG synthesisConf, const int16_t nchan_transport, /* i : number of transport channels */ @@ -3635,14 +3635,14 @@ void ivas_dirac_dec_output_synthesis_cov_open( const int16_t interp_length, /* i : length for interpolating the mixing matrices in time slots */ const int16_t num_param_bands, /* i : number of parameter bands */ const int16_t num_param_bands_residual, /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ - const int16_t nchan_in, /* i : number of input (transport) channels */ + const int16_t nchan_inp, /* i : number of input (transport) channels */ const int16_t nchan_out, /* i : number of output channels */ const float *proto_matrix /* i : the prototype (upmix) matrix (only used if mode == 1) */ ); void ivas_dirac_dec_output_synthesis_cov_init( DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: pointer to the state of the covariance synthesis */ - const int16_t nchan_in, /* i : number of input (tranport) channels */ + const int16_t nchan_inp, /* i : number of input (tranport) channels */ const int16_t nchan_out, /* i : number of output channels */ const int16_t n_param_bands, /* i : number of total parameter bands */ const int16_t n_param_bands_res /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ @@ -3659,7 +3659,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot( float cx[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (real part) */ float cx_imag[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (imaginary part) */ PARAM_MC_DEC_HANDLE hParamMC, /* i : handle to Parametric MC state */ - const int16_t nchan_in, /* i : number of input channels */ + const int16_t nchan_inp, /* i : number of input channels */ const int16_t idx_slot /* i : index of the slot to be added to the input covariance */ ); @@ -3907,6 +3907,14 @@ void ivas_spar_md_enc_close( ivas_spar_md_enc_state_t **hMdEnc /* i/o: SPAR MD encoder handle */ ); +#ifdef SBA_BITRATE_SWITCHING +ivas_error ivas_spar_md_enc_init( + ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + const int16_t sba_order /* i : Ambisonic (SBA) order */ +); +#endif + ivas_error ivas_spar_md_enc_process( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ @@ -3934,7 +3942,7 @@ void ivas_compute_spar_params( const int16_t start_band, const int16_t end_band, const int16_t dtx_vad, - const int16_t num_ch, + const int16_t nchan, const int16_t bands_bw, const int16_t active_w, ivas_spar_md_com_cfg *hSparCfg, @@ -3959,7 +3967,7 @@ void ivas_calc_c_p_coeffs( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t i_ts, float ***mixer_mat, - const int16_t num_ch, + const int16_t nchan, const int16_t num_dmx, const int16_t band_idx, const int16_t dtx_vad, @@ -3977,7 +3985,7 @@ void ivas_get_spar_md_from_dirac( ivas_spar_md_com_cfg *hSpar_md_cfg, const int16_t start_band, const int16_t end_band, - const int16_t order, + const int16_t sba_order, const int16_t dtx_vad, float Wscale_d[IVAS_MAX_NUM_BANDS] ); @@ -3985,7 +3993,7 @@ void ivas_get_spar_md_from_dirac( ivas_error ivas_spar_md_dec_open( ivas_spar_md_dec_state_t **hMdDec_out, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t num_channels /* i : number of internal channels */ + const int16_t nchan /* i : number of internal channels */ #ifdef SBA_HOA_HBR_IMPROV , const int16_t sba_order /* i : flag to send HOA MD for all bands */ @@ -4000,16 +4008,19 @@ void ivas_spar_get_parameters( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ const int16_t ts, /* i : time slot index */ - const int16_t num_ch_out, /* i : number of channels out */ - const int16_t num_ch_in, /* i : number of channels in */ + const int16_t nchan_out, /* i : number of channels out */ + const int16_t nchan_inp, /* i : number of channels in */ const int16_t num_spar_bands, /* i : number of SPAR bands */ - float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /* o : mixing matrix */ + float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /* o : mixing matrix */ ); ivas_error ivas_spar_md_dec_init( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t num_channels /* i : number of internal channels */ +#if ( defined SBA_BITRATE_SWITCHING && defined SBA_HOA_HBR_IMPROV ) + const int16_t sba_order, /* i : SBA order */ +#endif + const int16_t nchan /* i : number of internal channels */ ); void ivas_spar_md_dec_process( @@ -4106,7 +4117,7 @@ void ivas_cov_smooth_process( const int16_t end_band #ifdef SBA_SPAR_HARM , - const int16_t num_ch, + const int16_t nchan, const int16_t transient_det #endif ); @@ -4598,7 +4609,7 @@ void rotateFrame_shd_cldfb( float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: unrotated HOA3 signal buffer in cldfb domain real part */ float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: unrotated HOA3 signal buffer in cldfb domain imag part */ float Rmat[3][3], /* i : real-space rotation matrix */ - const int16_t nInChannels, /* i : number of channels */ + const int16_t nchan_inp, /* i : number of channels */ const int16_t shd_rot_max_order /* i : split-order rotation method */ ); @@ -5166,8 +5177,8 @@ ivas_error ivas_fb_set_cfg( IVAS_FB_CFG **pFb_cfg_out, /* o : FB config. handle */ const int16_t ivas_format, /* i : IVAS format */ const SBA_MODE sba_mode, /* i : SBA mode */ - const int16_t num_in_chans, /* i : number of FB input channels */ - const int16_t num_out_chans, /* i : number of FB output channels */ + const int16_t nchan_inp, /* i : number of FB input channels */ + const int16_t nchan_out, /* i : number of FB output channels */ const int16_t active_w_mixing, /* i : active_w_mixing flag */ const int32_t sampling_Fs /* i : sampling rate */ ); diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index b5821e4632c2f60be4ca7b67ee6522a5efe7df62..9989a7f55497ab5dbfeb955dd376296dc8d7fca9 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -80,9 +80,9 @@ static void ivas_get_pred_coeffs( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SP static void ivas_reorder_array( float in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], const int16_t in_chans, const int16_t order[IVAS_SPAR_MAX_CH], float ***mixer_mat, const int16_t start_band, const int16_t end_band ); -static void ivas_get_Wscaling_factor( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], float ***mixer_mat, const int16_t start_band, const int16_t end_band, const int16_t dtx_vad, const int16_t num_ch, const int16_t *pNum_dmx, const int16_t bands_bw, const int16_t active_w, float *pWscale ); +static void ivas_get_Wscaling_factor( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], float ***mixer_mat, const int16_t start_band, const int16_t end_band, const int16_t dtx_vad, const int16_t nchan, const int16_t *pNum_dmx, const int16_t bands_bw, const int16_t active_w, float *pWscale ); -static void ivas_calc_post_pred_per_band( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float ***mixer_mat, const int16_t num_ch, const int16_t num_dmx, const int16_t band_idx, float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] ); +static void ivas_calc_post_pred_per_band( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float ***mixer_mat, const int16_t nchan, const int16_t num_dmx, const int16_t band_idx, float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] ); static int16_t ivas_is_mat_inv( float in_re[MAX_MAT_DIM][MAX_MAT_DIM], const int16_t dim ); @@ -641,7 +641,7 @@ static void ivas_get_Wscaling_factor( const int16_t start_band, const int16_t end_band, const int16_t dtx_vad, - const int16_t num_ch, + const int16_t nchan, const int16_t *pNum_dmx, const int16_t bands_bw, const int16_t active_w, @@ -668,11 +668,11 @@ static void ivas_get_Wscaling_factor( { float Gw_sq, g_sq = 0; - ivas_calc_post_pred_per_band( cov_real, mixer_mat, num_ch, pNum_dmx[b * bands_bw], b, postpred_cov_re ); + ivas_calc_post_pred_per_band( cov_real, mixer_mat, nchan, pNum_dmx[b * bands_bw], b, postpred_cov_re ); Gw_sq = cov_real[0][0][b] / max( postpred_cov_re[0][0], IVAS_FLT_EPS ); - for ( ch = 0; ch < num_ch - 1; ch++ ) + for ( ch = 0; ch < nchan - 1; ch++ ) { IVAS_CALCULATE_SQ_ABS_N( pred_coeffs_re[ch][b], abs_val ); @@ -864,7 +864,7 @@ static void ivas_reorder_array( static void ivas_calc_post_pred_per_band( float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float ***mixer_mat, - const int16_t num_ch, + const int16_t nchan, const int16_t num_dmx, const int16_t band_idx, float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] ) @@ -875,29 +875,29 @@ static void ivas_calc_post_pred_per_band( float tmp_re; // NOTE: What is this doing? - if ( num_dmx != num_ch ) + if ( num_dmx != nchan ) { - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; } } } - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - set_zero( postpred_cov_re[i], num_ch ); + set_zero( postpred_cov_re[i], nchan ); } - /* num_ch x num_ch mult */ - for ( i = 0; i < num_ch; i++ ) + /* nchan x nchan mult */ + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { temp_mat[i][j] = 0; - for ( k = 0; k < num_ch; k++ ) + for ( k = 0; k < nchan; k++ ) { IVAS_RMULT_FLOAT( cov_real[i][k][band_idx], dmx_mat_conj[k][j], tmp_re ); temp_mat[i][j] += tmp_re; @@ -905,12 +905,12 @@ static void ivas_calc_post_pred_per_band( } } - /* num_ch x num_ch mult */ - for ( i = 0; i < num_ch; i++ ) + /* nchan x nchan mult */ + for ( i = 0; i < nchan; i++ ) { - for ( j = i; j < num_ch; j++ ) + for ( j = i; j < nchan; j++ ) { - for ( k = 0; k < num_ch; k++ ) + for ( k = 0; k < nchan; k++ ) { IVAS_RMULT_FLOAT( mixer_mat[i][k][band_idx], temp_mat[k][j], tmp_re ); @@ -919,7 +919,7 @@ static void ivas_calc_post_pred_per_band( } } - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { for ( j = 0; j < i; j++ ) { @@ -928,9 +928,9 @@ static void ivas_calc_post_pred_per_band( } #ifdef SPAR_HOA_DBG /*fprintf(stderr, "\n\n Postpred cov: (band %d)\n", band_idx); - for (i = 0; i < num_ch; i++) + for (i = 0; i < nchan; i++) { - for (j = 0; j < num_ch; j++) + for (j = 0; j < nchan; j++) { fprintf(stderr, "%f, ", postpred_cov_re[i][j]); } @@ -953,7 +953,7 @@ static void ivas_calc_p_coeffs_per_band( ivas_spar_md_t *pSparMd, const int16_t i_ts, float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const int16_t num_ch, + const int16_t nchan, const int16_t dtx_vad, const int16_t num_dmx, const int16_t band_idx ) @@ -970,7 +970,7 @@ static void ivas_calc_p_coeffs_per_band( b_ts_idx = band_idx + i_ts * IVAS_MAX_NUM_BANDS; - if ( num_dmx != num_ch ) + if ( num_dmx != nchan ) { set_zero( pSparMd->band_coeffs[b_ts_idx].P_re, IVAS_SPAR_MAX_CH - 1 ); for ( i = 0; i < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; i++ ) @@ -978,9 +978,9 @@ static void ivas_calc_p_coeffs_per_band( set_zero( recon_uu_re[i], IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ); } - for ( i = num_dmx; i < num_ch; i++ ) + for ( i = num_dmx; i < nchan; i++ ) { - for ( j = num_dmx; j < num_ch; j++ ) + for ( j = num_dmx; j < nchan; j++ ) { cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; } @@ -1043,7 +1043,7 @@ static void ivas_calc_p_coeffs_per_band( /* Step 1: Multiply C * cov_dd * C' */ float re1[3], re; - for ( i = 0; i < num_ch - num_dmx; i++ ) + for ( i = 0; i < nchan - num_dmx; i++ ) { set_f( re1, 0, 3 ); for ( m = 0; m < num_dmx - 1; m++ ) @@ -1054,7 +1054,7 @@ static void ivas_calc_p_coeffs_per_band( re1[m] += re; } } - for ( j = 0; j < num_ch - num_dmx; j++ ) + for ( j = 0; j < nchan - num_dmx; j++ ) { for ( m = 0; m < num_dmx - 1; m++ ) { @@ -1065,9 +1065,9 @@ static void ivas_calc_p_coeffs_per_band( } /* Step 2: cov_uu - recon_uu */ - for ( i = 0; i < num_ch - num_dmx; i++ ) + for ( i = 0; i < nchan - num_dmx; i++ ) { - for ( j = 0; j < num_ch - num_dmx; j++ ) + for ( j = 0; j < nchan - num_dmx; j++ ) { cov_uu_re[i][j] -= recon_uu_re[i][j]; } @@ -1084,7 +1084,7 @@ static void ivas_calc_p_coeffs_per_band( trace = 0.0f; - for ( i = num_dmx; i < num_ch; i++ ) + for ( i = num_dmx; i < nchan; i++ ) { float tmp_out; IVAS_CALCULATE_RABS( cov_uu_re[i - num_dmx][i - num_dmx], tmp_out ); @@ -1096,9 +1096,9 @@ static void ivas_calc_p_coeffs_per_band( factor = 1 / factor; /* normalise Hermitian (except for rounding) cov_uu */ - for ( i = num_dmx; i < num_ch; i++ ) + for ( i = num_dmx; i < nchan; i++ ) { - for ( j = num_dmx; j < num_ch; j++ ) + for ( j = num_dmx; j < nchan; j++ ) { if ( i == j ) { @@ -1114,16 +1114,16 @@ static void ivas_calc_p_coeffs_per_band( } /* take sqrt of max of diags and zero */ - for ( i = num_dmx; i < num_ch; i++ ) + for ( i = num_dmx; i < nchan; i++ ) { cov_uu_re[i - num_dmx][i - num_dmx] = sqrtf( max( 0.0f, cov_uu_re[i - num_dmx][i - num_dmx] ) ); /* cov_uu_im[i - num_dmx][i - num_dmx] = 0; */ } /* save into MD struct */ - for ( i = num_dmx; i < num_ch; i++ ) + for ( i = num_dmx; i < nchan; i++ ) { - for ( j = num_dmx; j < num_ch; j++ ) + for ( j = num_dmx; j < nchan; j++ ) { if ( i == j ) { @@ -1147,7 +1147,7 @@ static void ivas_calc_c_coeffs_per_band( ivas_spar_md_t *pSparMd, const int16_t i_ts, float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const int16_t num_ch, + const int16_t nchan, const int16_t num_dmx, const int16_t band_idx, const int16_t dtx_vad ) @@ -1171,7 +1171,7 @@ static void ivas_calc_c_coeffs_per_band( return; } - for ( i = num_dmx; i < num_ch; i++ ) + for ( i = num_dmx; i < nchan; i++ ) { for ( j = 1; j < num_dmx; j++ ) { @@ -1213,7 +1213,7 @@ static void ivas_calc_c_coeffs_per_band( else { ivas_calc_mat_inv( cov_dd_re, num_dmx - 1, cov_dd_re_inv ); - for ( i = 0; i < num_ch - num_dmx; i++ ) + for ( i = 0; i < nchan - num_dmx; i++ ) { for ( j = 0; j < num_dmx - 1; j++ ) { @@ -1243,7 +1243,7 @@ void ivas_calc_c_p_coeffs( float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t i_ts, float ***mixer_mat, - const int16_t num_ch, + const int16_t nchan, const int16_t num_dmx, const int16_t band_idx, const int16_t dtx_vad, @@ -1253,18 +1253,18 @@ void ivas_calc_c_p_coeffs( int16_t i, j; float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - if ( num_dmx != num_ch ) + if ( num_dmx != nchan ) { - ivas_calc_post_pred_per_band( cov_real, mixer_mat, num_ch, num_dmx, band_idx, postpred_cov_re ); + ivas_calc_post_pred_per_band( cov_real, mixer_mat, nchan, num_dmx, band_idx, postpred_cov_re ); if ( num_dmx != 1 ) { - ivas_calc_c_coeffs_per_band( pSparMd, i_ts, postpred_cov_re, num_ch, num_dmx, band_idx, dtx_vad ); + ivas_calc_c_coeffs_per_band( pSparMd, i_ts, postpred_cov_re, nchan, num_dmx, band_idx, dtx_vad ); } if ( planarCP ) { - for ( i = 0; i < num_ch - num_dmx; i++ ) + for ( i = 0; i < nchan - num_dmx; i++ ) { if ( !keep_planar[i] ) { @@ -1278,12 +1278,12 @@ void ivas_calc_c_p_coeffs( if ( compute_p_flag == 1 ) { - ivas_calc_p_coeffs_per_band( pSparMd, i_ts, postpred_cov_re, num_ch, dtx_vad, num_dmx, band_idx ); + ivas_calc_p_coeffs_per_band( pSparMd, i_ts, postpred_cov_re, nchan, dtx_vad, num_dmx, band_idx ); } if ( planarCP ) { - for ( i = num_dmx; i < num_ch; i++ ) + for ( i = num_dmx; i < nchan; i++ ) { if ( !keep_planar[i - num_dmx] ) { @@ -1533,7 +1533,7 @@ void ivas_compute_spar_params( const int16_t start_band, const int16_t end_band, const int16_t dtx_vad, - const int16_t num_ch, + const int16_t nchan, const int16_t bands_bw, const int16_t active_w, ivas_spar_md_com_cfg *hSparCfg, @@ -1544,12 +1544,12 @@ void ivas_compute_spar_params( float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; int16_t b, i, ndm; - ivas_get_pred_coeffs( cov_real, pred_coeffs_re, dm_fv_re, num_ch, start_band, end_band, active_w, dtx_vad, from_dirac ); + ivas_get_pred_coeffs( cov_real, pred_coeffs_re, dm_fv_re, nchan, start_band, end_band, active_w, dtx_vad, from_dirac ); #ifdef SPAR_HOA_DBG /*fprintf(stderr, "\n\n Prediction Coefficients:\n"); - for (i = 0; i < num_ch - 1; i++) + for (i = 0; i < nchan - 1; i++) { for (j = start_band; j < end_band; j++) { @@ -1559,14 +1559,14 @@ void ivas_compute_spar_params( } fprintf(stderr, "\n\n"); */ #endif - ivas_create_fullr_dmx_mat( pred_coeffs_re, dm_fv_re, mixer_mat, num_ch, start_band, end_band, active_w, hSparCfg ); + ivas_create_fullr_dmx_mat( pred_coeffs_re, dm_fv_re, mixer_mat, nchan, start_band, end_band, active_w, hSparCfg ); #ifdef SPAR_HOA_DBG /*fprintf(stderr, "\n\n 1st DMX matrix (band 0):\n"); - for (i = 0; i < num_ch; i++) + for (i = 0; i < nchan; i++) { - for (j = 0; j < num_ch; j++) + for (j = 0; j < nchan; j++) { fprintf(stderr, "%f, ", mixer_mat[i][j][0]); } @@ -1575,18 +1575,18 @@ void ivas_compute_spar_params( fprintf(stderr, "\n\n");*/ #endif - ivas_get_Wscaling_factor( cov_real, pred_coeffs_re, mixer_mat, start_band, end_band, dtx_vad, num_ch, + ivas_get_Wscaling_factor( cov_real, pred_coeffs_re, mixer_mat, start_band, end_band, dtx_vad, nchan, hSparCfg->num_dmx_chans_per_band, bands_bw, active_w, pWscale ); for ( b = start_band; b < end_band; b++ ) { float onebyscale = 1.0f / pWscale[b]; - for ( i = 0; i < num_ch - 1; i++ ) + for ( i = 0; i < nchan - 1; i++ ) { hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[i] = pred_coeffs_re[i][b] * onebyscale; } - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { mixer_mat[0][i][b] *= pWscale[b]; } @@ -1596,20 +1596,20 @@ void ivas_compute_spar_params( { ndm = hSparCfg->num_dmx_chans_per_band[b * bands_bw]; - if ( ndm != num_ch ) + if ( ndm != nchan ) { - ivas_calc_c_p_coeffs( hSparMd, cov_real, i_ts, mixer_mat, num_ch, ndm, b, dtx_vad, 1, 0 ); + ivas_calc_c_p_coeffs( hSparMd, cov_real, i_ts, mixer_mat, nchan, ndm, b, dtx_vad, 1, 0 ); #ifdef SPAR_HOA_DBG /* if (b == 0) */ { fprintf( stdout, "\n\nUnquantised C, P coeffs -- band %d:\n", b ); - for ( int16_t ii = 0; ii < num_ch; ii++ ) + for ( int16_t ii = 0; ii < nchan; ii++ ) { fprintf( stdout, "%f |", hSparMd->band_coeffs[b].pred_re[ii] ); - if ( ii < num_ch - ndm ) + if ( ii < nchan - ndm ) { for ( int16_t jj = 0; jj < ndm - 1; jj++ ) { @@ -1645,11 +1645,11 @@ void ivas_get_spar_md_from_dirac( ivas_spar_md_com_cfg *hSpar_md_cfg, const int16_t start_band, const int16_t end_band, - const int16_t order, + const int16_t sba_order, const int16_t dtx_vad, float Wscale_d[IVAS_MAX_NUM_BANDS] ) { - int16_t num_ch, band, i, j; + int16_t nchan_md, band, i, j; int16_t block, ch; float response_avg[MAX_OUTPUT_CHANNELS]; float response[MAX_PARAM_SPATIAL_SUBFRAMES][MAX_OUTPUT_CHANNELS]; @@ -1661,15 +1661,15 @@ void ivas_get_spar_md_from_dirac( float **ppMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH]; float *pMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; float en_ratio_fac, diff_norm_order1, diff_norm_order2, diff_norm_order3; - int16_t ndm, foa_ch, hoa2_ch; + int16_t ndm, nchan_foa, nchan_md_hoa2; float P_dir_fact[IVAS_SPAR_MAX_CH - 1]; const int16_t *remix_order; remix_order = remix_order_set[hSpar_md_cfg->remix_unmix_order]; - num_ch = 2 * order + 2; - hoa2_ch = 6; - foa_ch = FOA_CHANNELS; + nchan_md = ivas_sba_get_nchan_metadata( sba_order ); + nchan_md_hoa2 = ivas_sba_get_nchan_metadata( 2 ); + nchan_foa = FOA_CHANNELS; diff_norm_order1 = 3.0f; diff_norm_order2 = 5.0f; diff_norm_order3 = 7.0f; @@ -1689,39 +1689,39 @@ void ivas_get_spar_md_from_dirac( int16_t idx; ndm = hSpar_md_cfg->num_dmx_chans_per_band[start_band - 1]; P_norm[0] = 0.0f; - for ( i = 0; i < max( 0, foa_ch - ndm ); i++ ) + for ( i = 0; i < max( 0, nchan_foa - ndm ); i++ ) { P_norm[0] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; } - P_norm[0] *= diff_norm_order1 / min( diff_norm_order1, max( 0, foa_ch - ndm ) ); + P_norm[0] *= diff_norm_order1 / min( diff_norm_order1, max( 0, nchan_foa - ndm ) ); P_norm[1] = 0.0f; - for ( ; i < max( 0, min( num_ch, hoa2_ch ) - ndm ); i++ ) + for ( ; i < max( 0, min( nchan_md, nchan_md_hoa2 ) - ndm ); i++ ) { P_norm[1] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; } - P_norm[1] *= diff_norm_order2 / min( diff_norm_order2, max( 0, min( num_ch, hoa2_ch ) - ndm ) ); + P_norm[1] *= diff_norm_order2 / min( diff_norm_order2, max( 0, min( nchan_md, nchan_md_hoa2 ) - ndm ) ); P_norm[2] = 0.0f; - for ( ; i < num_ch - ndm; i++ ) + for ( ; i < nchan_md - ndm; i++ ) { P_norm[2] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; } - P_norm[2] *= diff_norm_order3 / min( diff_norm_order3, max( 0, num_ch - ndm ) ); + P_norm[2] *= diff_norm_order3 / min( diff_norm_order3, max( 0, nchan_md - ndm ) ); - for ( i = 0; i < max( 0, foa_ch - ndm ); i++ ) + for ( i = 0; i < max( 0, nchan_foa - ndm ); i++ ) { idx = remix_order[i + ndm] - ndm; P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[0] ); } - for ( ; i < max( 0, min( num_ch, hoa2_ch ) - ndm ); i++ ) + for ( ; i < max( 0, min( nchan_md, nchan_md_hoa2 ) - ndm ); i++ ) { idx = remix_order[i + ndm] - ndm; P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[1] ); } - for ( ; i < num_ch - ndm; i++ ) + for ( ; i < nchan_md - ndm; i++ ) { idx = remix_order[i + ndm] - ndm; P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; @@ -1744,24 +1744,24 @@ void ivas_get_spar_md_from_dirac( #endif if ( n_ts > 1 ) { - ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][i_ts], (int16_t) ele_dirac[band][i_ts], response_avg, order ); + ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][i_ts], (int16_t) ele_dirac[band][i_ts], response_avg, sba_order ); } else { for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { - ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][block], (int16_t) ele_dirac[band][block], &( response[block][0] ), order ); + ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][block], (int16_t) ele_dirac[band][block], &( response[block][0] ), sba_order ); } /* average responses in all subframes*/ { float norm; - int16_t num_ch_order, hoa2_ch_order; + int16_t nchan_internal, nchan_hoa2; - num_ch_order = ivas_sba_get_nchan( order, 0 ); - hoa2_ch_order = 9; + nchan_internal = ivas_sba_get_nchan( sba_order, 0 ); + nchan_hoa2 = ivas_sba_get_nchan( 2, 0 ); - for ( ch = 0; ch < num_ch_order; ch++ ) + for ( ch = 0; ch < nchan_internal; ch++ ) { for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { @@ -1772,51 +1772,51 @@ void ivas_get_spar_md_from_dirac( /*normalize 1st order*/ norm = 0.0f; - for ( ch = 1; ch < foa_ch; ch++ ) + for ( ch = 1; ch < nchan_foa; ch++ ) { norm += response_avg[ch] * response_avg[ch]; } norm = max( EPSILON, sqrtf( norm ) ); - for ( ch = 1; ch < foa_ch; ch++ ) + for ( ch = 1; ch < nchan_foa; ch++ ) { response_avg[ch] /= norm; } /*normalize 2nd order*/ norm = 0.0f; - for ( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) + for ( ch = nchan_foa; ch < min( nchan_hoa2, nchan_internal ); ch++ ) { norm += response_avg[ch] * response_avg[ch]; } norm = max( EPSILON, sqrtf( norm ) ); - for ( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) + for ( ch = nchan_foa; ch < min( nchan_hoa2, nchan_internal ); ch++ ) { response_avg[ch] /= norm; } /*normalize 3rd order*/ norm = 0.0f; - for ( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) + for ( ch = nchan_hoa2; ch < nchan_internal; ch++ ) { norm += response_avg[ch] * response_avg[ch]; } norm = max( EPSILON, sqrtf( norm ) ); - for ( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) + for ( ch = nchan_hoa2; ch < nchan_internal; ch++ ) { response_avg[ch] /= norm; } } } - for ( i = FOA_CHANNELS + 1; i < num_ch; i++ ) + for ( i = FOA_CHANNELS + 1; i < nchan_md; i++ ) { response_avg[i] = response_avg[HOA_keep_ind[i]]; } en_ratio_fac = ( 1.0f - diffuseness[band] ); - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan_md; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan_md; j++ ) { if ( i == j ) { @@ -1836,11 +1836,11 @@ void ivas_get_spar_md_from_dirac( } else { - if ( i < foa_ch ) + if ( i < nchan_foa ) { cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order1; } - else if ( i < hoa2_ch ) + else if ( i < nchan_md_hoa2 ) { cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order2; } @@ -1852,11 +1852,11 @@ void ivas_get_spar_md_from_dirac( } else { - if ( i < foa_ch ) + if ( i < nchan_foa ) { cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order1; } - else if ( i < hoa2_ch ) + else if ( i < nchan_md_hoa2 ) { cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order2; } @@ -1875,9 +1875,9 @@ void ivas_get_spar_md_from_dirac( } } - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan_md; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan_md; j++ ) { pCov_real[i][j] = cov_real_dirac[i][j]; } @@ -1893,9 +1893,9 @@ void ivas_get_spar_md_from_dirac( fid = fopen( "cov_real_dirac.txt", "wt" ); } - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan_md; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan_md; j++ ) { for ( k = start_band; k < end_band; k++ ) { @@ -1908,7 +1908,7 @@ void ivas_get_spar_md_from_dirac( #endif ivas_compute_spar_params( pCov_real, dm_fv_re, i_ts, ppMixer_mat, start_band, end_band, dtx_vad, - num_ch, 1, hSpar_md_cfg->active_w, hSpar_md_cfg, hSpar_md, Wscale, 1 ); + nchan_md, 1, hSpar_md_cfg->active_w, hSpar_md_cfg, hSpar_md, Wscale, 1 ); if ( mixer_mat != NULL ) { @@ -1918,15 +1918,15 @@ void ivas_get_spar_md_from_dirac( for ( i = 0; i < ndm; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan_md; j++ ) { mixer_mat[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = ppMixer_mat[i][j][band]; } } - for ( i = ndm; i < num_ch; i++ ) + for ( i = ndm; i < nchan_md; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan_md; j++ ) { mixer_mat[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = 0.0f; } @@ -1934,7 +1934,7 @@ void ivas_get_spar_md_from_dirac( if ( ( ndm == 1 ) && ( Wscale_d != NULL ) ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan_md; j++ ) { mixer_mat[0][j][band + i_ts * IVAS_MAX_NUM_BANDS] *= Wscale_d[band]; } diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 4b2c342f4f5bed4cbb86767f1db5c73d0a8f0c2a..859baaedcec775e21a1eb66c1b0df795bc8d9022 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -355,7 +355,7 @@ typedef struct ivas_cov_smooth_cfg_t typedef struct ivas_cov_smooth_in_buf_t { float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - int16_t num_ch; + int16_t nchan; int16_t reset_cov; } ivas_cov_smooth_in_buf_t; @@ -670,8 +670,8 @@ typedef struct ivas_trans_det_state_t typedef struct ivas_fb_mixer_cfg_t { int16_t fb_latency; - int16_t num_in_chans; - int16_t num_out_chans; + int16_t nchan_inp; + int16_t nchan_out; int16_t pcm_offset; int16_t fade_len; /* this sets the stride length; no delay is introduced */ int16_t prior_input_length; diff --git a/lib_com/options.h b/lib_com/options.h old mode 100644 new mode 100755 index b988fcb581dd99ec968794076c1d2445f96ea7ef..33f0512cf0559cb143c60c97850bb8295745d8b5 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -153,6 +153,7 @@ #define EFAP_FIX_POLY /* Issue 167: fix bug in EFAP polygon selection */ #define SBA_HOA_HBR_IMPROV /* issue 91: Improvements to SBA high bitrate HOA3 coding */ +#define SBA_BITRATE_SWITCHING /* Issue 114: suppport bitrate switching in SBA - CORECODER_BITRATE_SWITCHING must be defined */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_com/tools.c b/lib_com/tools.c index 3e6e56d5a0aed488b98d1e843612187b7f137b69..fb2ea7689c21a151585e920c4b3acd2986f4d228 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -1447,7 +1447,7 @@ void polezero_filter( } #define WMC_TOOL_MAN - +// VE: define complexity macros here static float fleft_shift( float input, const int16_t shift ) { return ( input * (float) pow( 2.0, (double) shift ) ); diff --git a/lib_debug/mem_count.c b/lib_debug/mem_count.c index b12639ae3fcb3e100477cab505ba97e378bc1e7a..5d1da67eb7c483d5ca883ae6e60e3fe0a676854f 100644 --- a/lib_debug/mem_count.c +++ b/lib_debug/mem_count.c @@ -93,7 +93,11 @@ typedef INT64 int64_t; /* This is the maximum number of allocations for which to keep information. It can be increased if required. */ +#ifdef SBA_BITRATE_SWITCHING +#define MAX_INFO_RECORDS 6000 +#else #define MAX_INFO_RECORDS 3000 +#endif /* This is the length after which the function name will be truncated when the summary is printed. */ diff --git a/lib_dec/ACcontextMapping_dec.c b/lib_dec/ACcontextMapping_dec.c index 10fb36974167250244b60cb2f307bec755591a98..3308eb38b9c4b13241503df4b89a109028e437a8 100644 --- a/lib_dec/ACcontextMapping_dec.c +++ b/lib_dec/ACcontextMapping_dec.c @@ -633,8 +633,8 @@ int16_t RCcontextMapping_decode2_no_mem_s17_LCS( /* Update bitstream pointer */ st->next_bit_pos = start_bit_pos + bits_tups + rc_uni_dec_virtual_finish( &rc_st_dec ); - /* Confirm that there is no overflow */ #ifdef DEBUGGING + /* Confirm that there is no overflow */ assert( st->next_bit_pos - start_bit_pos + rest_bits <= 0 ); #endif diff --git a/lib_dec/ivas_binauralRenderer.c b/lib_dec/ivas_binauralRenderer.c index 45108a92faf37767b05a8bf481c28771e33ba406..a5254401a178d87413f4830489eb39f5d4a0ecea 100644 --- a/lib_dec/ivas_binauralRenderer.c +++ b/lib_dec/ivas_binauralRenderer.c @@ -66,7 +66,7 @@ static void ivas_binRenderer_filterModule( for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - for ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) + for ( chIdx = 0; chIdx < hBinRenderer->nchan_inp; chIdx++ ) { filterStatesLeftRealPtr = (float *) &( hBinRenderer->hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx][0] ); filterStatesLeftImagPtr = (float *) &( hBinRenderer->hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx][0] ); @@ -140,11 +140,11 @@ static ivas_error ivas_binRenderer_convModuleOpen( if ( !isLoudspeaker ) { - hBinRenderer->nInChannels = 16; + hBinRenderer->nchan_inp = 16; } else { - hBinRenderer->nInChannels = ( audioCfg2channels( input_config ) - isLoudspeaker ); // TODO maybe an audioCfg2channels_woLFE() function? Works as long as only 1 LFE is present + hBinRenderer->nchan_inp = ( audioCfg2channels( input_config ) - isLoudspeaker ); // TODO maybe an audioCfg2channels_woLFE() function? Works as long as only 1 LFE is present } if ( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM && hRenderConfig->roomAcoustics.use_brir ) @@ -209,22 +209,22 @@ static ivas_error ivas_binRenderer_convModuleOpen( for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - if ( ( hBinRenConvModule->filterTapsLeftReal[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsLeftReal[bandIdx] = (float **) count_malloc( hBinRenderer->nchan_inp * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsLeftImag[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsLeftImag[bandIdx] = (float **) count_malloc( hBinRenderer->nchan_inp * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsRightReal[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsRightReal[bandIdx] = (float **) count_malloc( hBinRenderer->nchan_inp * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsRightImag[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsRightImag[bandIdx] = (float **) count_malloc( hBinRenderer->nchan_inp * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } @@ -242,17 +242,17 @@ static ivas_error ivas_binRenderer_convModuleOpen( for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - if ( ( hBinRenConvModule->filterStatesLeftReal[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterStatesLeftReal[bandIdx] = (float **) count_malloc( hBinRenderer->nchan_inp * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterStatesLeftImag[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterStatesLeftImag[bandIdx] = (float **) count_malloc( hBinRenderer->nchan_inp * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - for ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) + for ( chIdx = 0; chIdx < hBinRenderer->nchan_inp; chIdx++ ) { if ( ( hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx] = (float *) count_malloc( hBinRenConvModule->numTapsArray[bandIdx] * sizeof( float ) ) ) == NULL ) { @@ -269,7 +269,7 @@ static ivas_error ivas_binRenderer_convModuleOpen( /* set memories */ for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - for ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) + for ( chIdx = 0; chIdx < hBinRenderer->nchan_inp; chIdx++ ) { int16_t tmp = 0; @@ -369,7 +369,7 @@ static void ivas_binaural_obtain_DMX( float realDMX[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float imagDMX[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX] ) { - int16_t chIdx, bandIdx, k; + int16_t ch_in, bandIdx, k; // ToDo: hBinRenderer->ivas_format is never set to ISM_FORMAT -> TBV if ( hBinRenderer->ivas_format == MC_FORMAT || hBinRenderer->ivas_format == ISM_FORMAT ) @@ -377,34 +377,34 @@ static void ivas_binaural_obtain_DMX( /* Obtain the downmix */ float P_in[CLDFB_NO_CHANNELS_MAX]; float P_out, factEQ; - int16_t chOutIdx; + int16_t ch_out; float temp1, temp2; for ( k = 0; k < numTimeSlots; k++ ) { - for ( chOutIdx = 0; chOutIdx < BINAURAL_CHANNELS; chOutIdx++ ) + for ( ch_out = 0; ch_out < BINAURAL_CHANNELS; ch_out++ ) { - set_zero( realDMX[chOutIdx][k], CLDFB_NO_CHANNELS_MAX ); - set_zero( imagDMX[chOutIdx][k], CLDFB_NO_CHANNELS_MAX ); + set_zero( realDMX[ch_out][k], CLDFB_NO_CHANNELS_MAX ); + set_zero( imagDMX[ch_out][k], CLDFB_NO_CHANNELS_MAX ); } } - for ( chOutIdx = 0; chOutIdx < BINAURAL_CHANNELS; chOutIdx++ ) + for ( ch_out = 0; ch_out < BINAURAL_CHANNELS; ch_out++ ) { set_zero( P_in, hBinRenderer->conv_band ); - for ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) + for ( ch_in = 0; ch_in < hBinRenderer->nchan_inp; ch_in++ ) { - float dmxConst = hBinRenderer->hReverb->dmxmtx[chOutIdx][chIdx]; + float dmxConst = hBinRenderer->hReverb->dmxmtx[ch_out][ch_in]; for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { for ( k = 0; k < numTimeSlots; k++ ) { - temp1 = RealBuffer[chIdx][k][bandIdx] * dmxConst; - temp2 = ImagBuffer[chIdx][k][bandIdx] * dmxConst; - realDMX[chOutIdx][k][bandIdx] += temp1; - imagDMX[chOutIdx][k][bandIdx] += temp2; + temp1 = RealBuffer[ch_in][k][bandIdx] * dmxConst; + temp2 = ImagBuffer[ch_in][k][bandIdx] * dmxConst; + realDMX[ch_out][k][bandIdx] += temp1; + imagDMX[ch_out][k][bandIdx] += temp2; P_in[bandIdx] += temp1 * temp1 + temp2 * temp2; } @@ -416,8 +416,8 @@ static void ivas_binaural_obtain_DMX( P_out = 0.f; for ( k = 0; k < numTimeSlots; k++ ) { - temp1 = realDMX[chOutIdx][k][bandIdx]; - temp2 = imagDMX[chOutIdx][k][bandIdx]; + temp1 = realDMX[ch_out][k][bandIdx]; + temp2 = imagDMX[ch_out][k][bandIdx]; P_out += temp1 * temp1 + temp2 * temp2; } factEQ = sqrtf( P_in[bandIdx] / ( P_out + 1e-20f ) ); @@ -429,8 +429,8 @@ static void ivas_binaural_obtain_DMX( factEQ = max( min( factEQ, 2.0f ), 0.5f ); for ( k = 0; k < numTimeSlots; k++ ) { - realDMX[chOutIdx][k][bandIdx] *= factEQ; - imagDMX[chOutIdx][k][bandIdx] *= factEQ; + realDMX[ch_out][k][bandIdx] *= factEQ; + imagDMX[ch_out][k][bandIdx] *= factEQ; } } } @@ -452,12 +452,12 @@ static void ivas_binaural_obtain_DMX( set_zero( outRealRightPtr, CLDFB_NO_CHANNELS_MAX ); set_zero( outImagRightPtr, CLDFB_NO_CHANNELS_MAX ); - for ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) + for ( ch_in = 0; ch_in < hBinRenderer->nchan_inp; ch_in++ ) { - float foa_const = hBinRenderer->hReverb->foa_enc[chIdx][1]; + float foa_const = hBinRenderer->hReverb->foa_enc[ch_in][1]; - inRealPtr = (float *) &( RealBuffer[chIdx][k][0] ); - inImagPtr = (float *) &( ImagBuffer[chIdx][k][0] ); + inRealPtr = (float *) &( RealBuffer[ch_in][k][0] ); + inImagPtr = (float *) &( ImagBuffer[ch_in][k][0] ); for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { @@ -519,7 +519,7 @@ ivas_error ivas_binRenderer_open( { hBinRenderer->ivas_format = SBA_FORMAT; } - hBinRenderer->max_band = (int16_t) ( ( BINAURAL_MAXBANDS * st_ivas->hDecoderConfig->output_Fs ) / 48000 ); + hBinRenderer->max_band = ( int16_t )( ( BINAURAL_MAXBANDS * st_ivas->hDecoderConfig->output_Fs ) / 48000 ); convBand = hBinRenderer->max_band; hBinRenderer->timeSlots = MAX_PARAM_SPATIAL_SUBFRAMES; /* Corresponds to 5 msec sound to motion latency */ @@ -552,10 +552,17 @@ ivas_error ivas_binRenderer_open( } ivas_output_init( &out_setup, AUDIO_CONFIG_7_1_4 ); - if ( ( error = ivas_sba_get_hoa_dec_matrix( out_setup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + +#ifdef SBA_BITRATE_SWITCHING + if( st_ivas->hoa_dec_mtx == NULL ) +#endif { - return error; + if ( ( error = ivas_sba_get_hoa_dec_matrix( out_setup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + { + return error; + } } + hBinRenderer->hoa_dec_mtx = st_ivas->hoa_dec_mtx; st_ivas->binaural_latency_ns = (int32_t) ( FASTCONV_BRIR_latency_s * 1000000000.f ); } @@ -588,7 +595,7 @@ ivas_error ivas_binRenderer_open( /* initialize the dmx matrix */ for ( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) { - for ( k = 0; k < hBinRenderer->nInChannels; k++ ) + for ( k = 0; k < hBinRenderer->nchan_inp; k++ ) { hBinRenderer->hReverb->dmxmtx[chIdx][k] = dmxmtx[chIdx][k]; } @@ -679,7 +686,7 @@ static void ivas_binRenderer_convModuleClose( for ( bandIdx = 0; bandIdx < ( *hBinRenderer )->conv_band; bandIdx++ ) { - for ( chIdx = 0; chIdx < ( *hBinRenderer )->nInChannels; chIdx++ ) + for ( chIdx = 0; chIdx < ( *hBinRenderer )->nchan_inp; chIdx++ ) { count_free( hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx] ); hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx] = NULL; @@ -912,9 +919,9 @@ void ivas_binRenderer( } /* HOA decoding to CICP19 if needed*/ - if ( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 && hBinRenderer->nInChannels != 16 ) + if ( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 && hBinRenderer->nchan_inp != 16 ) { - ivas_sba2mc_cldfb( *( hBinRenderer->hInputSetup ), RealBuffer, ImagBuffer, hBinRenderer->nInChannels, hBinRenderer->conv_band, hBinRenderer->hoa_dec_mtx ); + ivas_sba2mc_cldfb( *( hBinRenderer->hInputSetup ), RealBuffer, ImagBuffer, hBinRenderer->nchan_inp, hBinRenderer->conv_band, hBinRenderer->hoa_dec_mtx ); } ivas_binRenderer_filterModule( Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, RealBuffer, ImagBuffer, hBinRenderer ); diff --git a/lib_dec/ivas_binaural_reverb.c b/lib_dec/ivas_binaural_reverb.c index b03c8c005322f630cf0a91005ff99e96d0cd4909..269eff9f7de529aae739719e7e956859021595c6 100644 --- a/lib_dec/ivas_binaural_reverb.c +++ b/lib_dec/ivas_binaural_reverb.c @@ -538,6 +538,9 @@ void ivas_binaural_reverb_close( } count_free( ( *hReverb ) ); +#ifdef SBA_BITRATE_SWITCHING + ( *hReverb ) = NULL; +#endif return; } diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 5d3a5a10f943086dec40888bbf09247b6397af06..fec88a37c6b30bf855465debb00ccb523bf0222a 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -55,7 +55,7 @@ ivas_error ivas_dec( int16_t *data /* o : output synthesis signal */ ) { - int16_t n, output_frame, nchan_out; + int16_t ch, output_frame, nchan_out; Decoder_State *st; /* used for bitstream handling */ float output[MAX_OUTPUT_CHANNELS][L_FRAME48k]; /* 'float' buffer for output synthesis, MAX_OUTPUT_CHANNELS channels */ /* IVAS_fmToDo: buffer can be allocated dynamically based on the actual number of output channels */ int16_t nchan_remapped; @@ -103,9 +103,9 @@ ivas_error ivas_dec( if ( st_ivas->bfi && st_ivas->ini_frame == 0 ) { /* zero output when first frame(s) is lost */ - for ( n = 0; n < nchan_out; n++ ) + for ( ch = 0; ch < nchan_out; ch++ ) { - set_f( output[n], 0.0f, output_frame ); + set_f( output[ch], 0.0f, output_frame ); } #ifdef DEBUG_MODE_INFO @@ -125,9 +125,9 @@ ivas_error ivas_dec( } /* HP filtering */ - for ( n = 0; n < min( nchan_out, st_ivas->nchan_transport ); n++ ) + for ( ch = 0; ch < min( nchan_out, st_ivas->nchan_transport ); ch++ ) { - hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs ); + hp20( output[ch], output_frame, st_ivas->mem_hp20_out[ch], output_Fs ); } /* Rendering */ @@ -148,15 +148,15 @@ ivas_error ivas_dec( ivas_ism_metadata_dec( ivas_total_brate, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, NULL ); } - for ( n = 0; n < st_ivas->nchan_transport; n++ ) + for ( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { - if ( ( error = ivas_sce_dec( st_ivas, n, &output[n], output_frame, nb_bits_metadata[n] ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_sce_dec( st_ivas, ch, &output[ch], output_frame, nb_bits_metadata[ch] ) ) != IVAS_ERR_OK ) { return error; } /* HP filtering */ - hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs ); + hp20( output[ch], output_frame, st_ivas->mem_hp20_out[ch], output_Fs ); } /* Rendering */ @@ -297,9 +297,9 @@ ivas_error ivas_dec( /* HP filtering */ #ifndef DEBUG_SPAR_BYPASS_EVS_CODEC - for ( n = 0; n < nchan_remapped; n++ ) + for ( ch = 0; ch < nchan_remapped; ch++ ) { - hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs ); + hp20( output[ch], output_frame, st_ivas->mem_hp20_out[ch], output_Fs ); } #endif if ( st_ivas->ivas_format == SBA_FORMAT ) @@ -320,9 +320,9 @@ ivas_error ivas_dec( { float gain = 0.8414f; /* Todo: Temporary gain for roughly matching the loudness. To be tuned later together with other outputs. */ - for ( n = 0; n < nchan_remapped; n++ ) + for ( ch = 0; ch < nchan_remapped; ch++ ) { - v_multc( output[n], gain, output[n], output_frame ); + v_multc( output[ch], gain, output[ch], output_frame ); } } @@ -368,11 +368,11 @@ ivas_error ivas_dec( mvr2r( output_lfe_ch, output[LFE_CHANNEL], output_frame ); /* HP filtering */ - for ( n = 0; n < st_ivas->nchan_transport; n++ ) + for ( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { - if ( n != LFE_CHANNEL ) + if ( ch != LFE_CHANNEL ) { - hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs ); + hp20( output[ch], output_frame, st_ivas->mem_hp20_out[ch], output_Fs ); } } @@ -427,9 +427,9 @@ ivas_error ivas_dec( } /* HP filtering */ - for ( n = 0; n < st_ivas->nchan_transport; n++ ) + for ( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { - hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs ); + hp20( output[ch], output_frame, st_ivas->mem_hp20_out[ch], output_Fs ); } /* Rendering */ @@ -464,10 +464,10 @@ ivas_error ivas_dec( } /* Identify the index of the separated channel */ - n = st_ivas->hOutSetup.separateChannelIndex; + ch = st_ivas->hOutSetup.separateChannelIndex; /* Decode the separated channel to output[n] to be combined with the synthesized channels */ - if ( ( error = ivas_sce_dec( st_ivas, 0, &output[n], output_frame, 0 ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_sce_dec( st_ivas, 0, &output[ch], output_frame, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -477,12 +477,12 @@ ivas_error ivas_dec( output_config == AUDIO_CONFIG_5_1_4 || output_config == AUDIO_CONFIG_7_1_4 || output_config == AUDIO_CONFIG_5_1_2 || ( output_config == AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.num_lfe > 0 ) ) { - ivas_lfe_synth_with_filters( st_ivas->hMasa->hMasaLfeSynth, output, output_frame, n, LFE_CHANNEL ); + ivas_lfe_synth_with_filters( st_ivas->hMasa->hMasaLfeSynth, output, output_frame, ch, LFE_CHANNEL ); } else if ( output_config == AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.num_lfe == 0 ) { /* Delay the separated channel to sync with the DirAC rendering */ - delay_signal( output[n], output_frame, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size ); + delay_signal( output[ch], output_frame, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size ); } } else @@ -509,9 +509,9 @@ ivas_error ivas_dec( } /* HP filtering */ - for ( n = 0; n < getNumChanSynthesis( st_ivas ); n++ ) + for ( ch = 0; ch < getNumChanSynthesis( st_ivas ); ch++ ) { - hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs ); + hp20( output[ch], output_frame, st_ivas->mem_hp20_out[ch], output_Fs ); } /* Rendering */ @@ -529,9 +529,9 @@ ivas_error ivas_dec( } else if ( st_ivas->intern_config == AUDIO_CONFIG_5_1 && ( output_config == AUDIO_CONFIG_5_1_2 || output_config == AUDIO_CONFIG_5_1_4 || output_config == AUDIO_CONFIG_7_1 ) ) { - for ( n = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; n < st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; n++ ) + for ( ch = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; ch < st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; ch++ ) { - set_zero( output[n], output_frame ); + set_zero( output[ch], output_frame ); } } } diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index ec9a712065419747d337522d6bc67e2d28a5754a..3388961b0d7e98c13a5ee86eba27ee2df2b7316d 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -56,7 +56,7 @@ static void ivas_dirac_free_mem( DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem ); static void initDiffuseResponses( float *diffuse_response_function, - const int16_t num_channels, + const int16_t nchan, AUDIO_CONFIG output_config, IVAS_OUTPUT_SETUP hOutSetup, const int16_t ambisonics_order, @@ -126,8 +126,12 @@ ivas_error ivas_dirac_dec_open( *-------------------------------------------------------------------------*/ ivas_error ivas_dirac_dec_config( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ +#ifdef SBA_BITRATE_SWITCHING + const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ +#else const DIRAC_CONFIG_FLAG flag_config /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ +#endif ) { DIRAC_DEC_HANDLE hDirAC; @@ -146,6 +150,11 @@ ivas_error ivas_dirac_dec_config( int32_t output_Fs, ivas_total_brate; ivas_error error; int16_t nchan_transport_orig; +#ifdef SBA_BITRATE_SWITCHING + DIRAC_CONFIG_FLAG flag_config; + + flag_config = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; +#endif error = IVAS_ERR_OK; @@ -198,7 +207,7 @@ ivas_error ivas_dirac_dec_config( if ( flag_config == DIRAC_RECONFIGURE && st_ivas->ivas_format == SBA_FORMAT ) { int16_t tmp1, tmp2, tmp3; - ivas_sba_config( st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport_old, st_ivas->sba_planar, &tmp1, &tmp2, &tmp3 ); + ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport_old, st_ivas->sba_planar, &tmp1, &tmp2, &tmp3 ); } /*-----------------------------------------------------------------* @@ -270,6 +279,10 @@ ivas_error ivas_dirac_dec_config( /* band config needed only for SPAR with FOA output */ if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA && st_ivas->sba_mode == SBA_MODE_SPAR ) { +#ifdef SBA_BITRATE_SWITCHING + st_ivas->nchan_transport = nchan_transport_orig; +#endif + return IVAS_ERR_OK; } @@ -653,7 +666,11 @@ ivas_error ivas_dirac_dec_config( } else if ( flag_config == DIRAC_RECONFIGURE && hDirAC->proto_signal_decorr_on && proto_signal_decorr_on_old ) { +#ifdef SBA_BITRATE_SWITCHING + if ( nchan_transport != nchan_transport_old || hDirAC->num_outputs_diff != num_outputs_diff_old || flag_config_inp == DIRAC_RECONFIGURE_MODE ) +#else if ( ( nchan_transport != nchan_transport_old ) || ( hDirAC->num_outputs_diff != num_outputs_diff_old ) ) +#endif { /* close and reopen the decorrelator */ ivas_dirac_dec_decorr_close( &hDirAC->h_freq_domain_decorr_ap_params, &hDirAC->h_freq_domain_decorr_ap_state ); @@ -2343,12 +2360,12 @@ void ivas_dirac_dec( { float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; - int16_t outchannels; + int16_t nchan_out; idx_in = 0; idx_lfe = 0; - outchannels = hDirAC->hOutSetup.nchan_out_woLFE + hDirAC->hOutSetup.num_lfe; + nchan_out = hDirAC->hOutSetup.nchan_out_woLFE + hDirAC->hOutSetup.num_lfe; if ( hDirAC->hOutSetup.separateChannelEnabled && ( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_5_1 || hDirAC->hOutSetup.output_config == AUDIO_CONFIG_7_1 || hDirAC->hOutSetup.output_config == AUDIO_CONFIG_5_1_2 || @@ -2356,7 +2373,7 @@ void ivas_dirac_dec( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_7_1_4 || ( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM && st_ivas->hLsSetupCustom->separate_ch_found ) ) ) { - outchannels++; + nchan_out++; } if ( hDirAC->hOutSetup.separateChannelEnabled && hDirAC->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM ) @@ -2370,7 +2387,7 @@ void ivas_dirac_dec( mvr2r( &( output_f[st_ivas->hOutSetup.separateChannelIndex][subframe_start_sample] ), tmp_separated, num_samples_subframe ); mvr2r( &( output_f[LFE_CHANNEL][subframe_start_sample] ), tmp_lfe, num_samples_subframe ); - for ( ch = 0; ch < outchannels; ch++ ) + for ( ch = 0; ch < nchan_out; ch++ ) { if ( ( hDirAC->hOutSetup.num_lfe > 0 ) && ( hDirAC->hOutSetup.index_lfe[idx_lfe] == ch ) ) { @@ -2411,7 +2428,7 @@ void ivas_dirac_dec( } else { - for ( ch = 0; ch < outchannels; ch++ ) + for ( ch = 0; ch < nchan_out; ch++ ) { if ( ( hDirAC->hOutSetup.num_lfe > 0 ) && ( hDirAC->hOutSetup.index_lfe[idx_lfe] == ch ) ) { @@ -2522,7 +2539,7 @@ void ivas_dirac_dec_get_frequency_axis( static void initDiffuseResponses( float *diffuse_response_function, - const int16_t num_channels, + const int16_t nchan, AUDIO_CONFIG output_config, IVAS_OUTPUT_SETUP hOutSetup, const int16_t ambisonics_order, @@ -2543,7 +2560,7 @@ static void initDiffuseResponses( /* set diffuse response function */ if ( ivas_format == MC_FORMAT && ( transport_config == AUDIO_CONFIG_5_1 || transport_config == AUDIO_CONFIG_7_1 ) && output_config == AUDIO_CONFIG_5_1_4 ) { - num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS; + num_horizontal_speakers = nchan - NUM_ELEVATED_SPEAKERS; mvr2r( diffuse_response_CICP6, diffuse_response_function, num_horizontal_speakers ); set_zero( &diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS ); @@ -2551,30 +2568,30 @@ static void initDiffuseResponses( } else if ( ivas_format == MC_FORMAT && ( transport_config == AUDIO_CONFIG_5_1 || transport_config == AUDIO_CONFIG_7_1 ) && output_config == AUDIO_CONFIG_7_1_4 ) { - num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS; + num_horizontal_speakers = nchan - NUM_ELEVATED_SPEAKERS; set_f( diffuse_response_function, sqrtf( 1.f / ( (float) num_horizontal_speakers ) ), num_horizontal_speakers ); set_zero( &diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS ); *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS; } - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1 && num_channels == 5 ) + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1 && nchan == 5 ) { - mvr2r( diffuse_response_CICP6, diffuse_response_function, num_channels ); + mvr2r( diffuse_response_CICP6, diffuse_response_function, nchan ); } - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1_2 && num_channels == 7 ) + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1_2 && nchan == 7 ) { - mvr2r( diffuse_response_CICP14, diffuse_response_function, num_channels ); + mvr2r( diffuse_response_CICP14, diffuse_response_function, nchan ); } - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_5_1_4 ) && ( num_channels == 9 ) ) + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_5_1_4 ) && ( nchan == 9 ) ) { - mvr2r( diffuse_response_CICP16, diffuse_response_function, num_channels ); + mvr2r( diffuse_response_CICP16, diffuse_response_function, nchan ); } else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_LS_CUSTOM ) ) { if ( transport_config == AUDIO_CONFIG_5_1 || transport_config == AUDIO_CONFIG_7_1 ) { /* Detect loudspeakers with elevation */ - for ( i = 0, num_horizontal_speakers = 0; i < num_channels; i++ ) + for ( i = 0, num_horizontal_speakers = 0; i < nchan; i++ ) { if ( fabsf( hOutSetup.ls_elevation[i] ) <= 5.f ) { @@ -2590,7 +2607,7 @@ static void initDiffuseResponses( /* Diffuse only to horizontal plane if enough loudspeakers */ if ( num_horizontal_speakers > 2 ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { diffuse_response_function[i] *= sqrtf( 1.f / (float) num_horizontal_speakers ); } @@ -2598,17 +2615,17 @@ static void initDiffuseResponses( else { *num_ele_spk_no_diffuse_rendering = 0; - set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels ); + set_f( diffuse_response_function, sqrtf( 1.f / (float) nchan ), nchan ); } } else { - set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels ); + set_f( diffuse_response_function, sqrtf( 1.f / (float) nchan ), nchan ); } } else { - set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels ); + set_f( diffuse_response_function, sqrtf( 1.f / (float) nchan ), nchan ); } } else diff --git a/lib_dec/ivas_dirac_dec_binaural_functions.c b/lib_dec/ivas_dirac_dec_binaural_functions.c index ca9f0a4587a985e94d8fedb4b8372f09fb90fffb..04afb9ce2bb803f3bb5acc265a99f7afc9b9f49a 100644 --- a/lib_dec/ivas_dirac_dec_binaural_functions.c +++ b/lib_dec/ivas_dirac_dec_binaural_functions.c @@ -98,9 +98,21 @@ ivas_error ivas_dirac_dec_init_binaural_data( float binCenterFreq, tmpFloat; ivas_error error; - if ( ( hBinaural = (DIRAC_DEC_BIN_HANDLE) count_malloc( sizeof( DIRAC_DEC_BIN_DATA ) ) ) == NULL ) +#ifdef SBA_BITRATE_SWITCHING // VE2FhG: TBV - Renderer Reconfig. to be reviewed + hBinaural = st_ivas->hDiracDecBin; + + if ( hBinaural == NULL ) +#endif { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC binaural handle " ); + if ( ( hBinaural = (DIRAC_DEC_BIN_HANDLE) count_malloc( sizeof( DIRAC_DEC_BIN_DATA ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC binaural handle " ); + } + +#ifdef SBA_BITRATE_SWITCHING + hBinaural->hTdDecorr = NULL; + hBinaural->hReverb = NULL; +#endif } nBins = st_ivas->hDirAC->num_freq_bands; @@ -189,18 +201,31 @@ ivas_error ivas_dirac_dec_init_binaural_data( { mvr2r( parametricEarlyPartEneCorrection, hBinaural->earlyPartEneCorrection, nBins ); - if ( hBinaural->useSubframeMode ) +#ifdef SBA_BITRATE_SWITCHING + /* reconfiguration needed when Reverb. parameters are changed -> close and open the handle again */ + if ( hBinaural->hReverb != NULL && ( ( hBinaural->hReverb->numBins != nBins ) || + ( hBinaural->useSubframeMode && hBinaural->hReverb->blockSize != CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES ) || + ( !hBinaural->useSubframeMode && hBinaural->hReverb->blockSize != CLDFB_NO_COL_MAX ) ) ) { - if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) != IVAS_ERR_OK ) - { - return error; - } + ivas_binaural_reverb_close( &( hBinaural->hReverb ) ); } - else + + if ( hBinaural->hReverb == NULL ) +#endif { - if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) != IVAS_ERR_OK ) + if ( hBinaural->useSubframeMode ) { - return error; + if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) != IVAS_ERR_OK ) + { + return error; + } } } } @@ -219,7 +244,13 @@ ivas_error ivas_dirac_dec_init_binaural_data( { if ( st_ivas->hDecoderConfig->ivas_total_brate >= IVAS_13k2 && st_ivas->ivas_format == SBA_FORMAT ) { - ivas_spar_td_decorr_dec_open( &( hBinaural->hTdDecorr ), output_Fs, 3, 1 ); +#ifdef SBA_BITRATE_SWITCHING + if ( hBinaural->hTdDecorr == NULL ) +#endif + { + ivas_spar_td_decorr_dec_open( &( hBinaural->hTdDecorr ), output_Fs, 3, 1 ); + } + if ( st_ivas->hDecoderConfig->ivas_total_brate < IVAS_24k4 ) { hBinaural->hTdDecorr->pTrans_det->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR; @@ -236,7 +267,11 @@ ivas_error ivas_dirac_dec_init_binaural_data( } else { +#ifdef SBA_BITRATE_SWITCHING + ivas_spar_td_decorr_dec_close( &( hBinaural->hTdDecorr ) ); +#else hBinaural->hTdDecorr = NULL; +#endif } st_ivas->hDiracDecBin = hBinaural; @@ -574,7 +609,6 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric uint8_t applyLowBitRateEQ; int16_t dirac_read_idx; - hDirAC = st_ivas->hDirAC; h = st_ivas->hDiracDecBin; separateCenterChannelRendering = st_ivas->hOutSetup.separateChannelEnabled; @@ -1159,14 +1193,14 @@ static void ivas_dirac_dec_binaural_process_output( if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) { /* Process second / room effect part of binaural output when needed */ - ivas_binaural_reverb_processFrame( st_ivas->hDiracDecBin->hReverb, numInChannels, inRe, inIm, reverbRe, reverbIm, firstSlot ); + ivas_binaural_reverb_processFrame( h->hReverb, numInChannels, inRe, inIm, reverbRe, reverbIm, firstSlot ); } interpVal = 0.0f; for ( slot = firstSlot; slot < ( firstSlot + numSlots ); slot++ ) { interpVal += 1.0f / (float) numSlots; - if ( !st_ivas->hDiracDecBin->useTdDecorr && max_band_decorr > 0 ) + if ( !h->useTdDecorr && max_band_decorr > 0 ) { ivas_dirac_dec_decorrelate_slot( st_ivas->hDirAC, slot, inRe, inIm, decSlotRe, decSlotIm ); } @@ -1181,7 +1215,7 @@ static void ivas_dirac_dec_binaural_process_output( /* Processing of the first / HRTF part of the binaural output. */ for ( chB = 0; chB < numInChannels; chB++ ) { - if ( st_ivas->hDiracDecBin->useTdDecorr ) + if ( h->useTdDecorr ) { decSlotRePointer = inRe[chB + 2][slot]; decSlotImPointer = inIm[chB + 2][slot]; diff --git a/lib_dec/ivas_dirac_decorr_dec.c b/lib_dec/ivas_dirac_decorr_dec.c index 437bdf8a647911cc20cd13b355e77dea657116b0..c74d5d29aba817de27c0a97a42e4d2e840644d95 100644 --- a/lib_dec/ivas_dirac_decorr_dec.c +++ b/lib_dec/ivas_dirac_decorr_dec.c @@ -292,7 +292,7 @@ void ivas_dirac_dec_decorr_open( void ivas_dirac_dec_decorr_process( const int16_t num_freq_bands, - int16_t num_channels, + int16_t nchan, const int16_t num_protos_diff, const DIRAC_SYNTHESIS_CONFIG synthesisConf, const int16_t nchan_transport, /* i : number of transport channels*/ @@ -355,7 +355,7 @@ void ivas_dirac_dec_decorr_process( if ( synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - num_channels -= nchan_transport; + nchan -= nchan_transport; } @@ -380,8 +380,8 @@ void ivas_dirac_dec_decorr_process( ivas_dirac_dec_onset_detection_process( aux_buffer, onset_filter, num_protos_diff, h_freq_domain_decorr_ap_params->h_onset_detection_power_params, h_freq_domain_decorr_ap_state->h_onset_detection_power_state ); - /* Apply decorrelator if num_channels is greater than 0 */ - if ( num_channels > 0 ) + /* Apply decorrelator if nchan is greater than 0 */ + if ( nchan > 0 ) { /* remove onsets from prototype frame */ for ( ch_idx = 0; ch_idx < num_protos_dir; ch_idx++ ) @@ -403,7 +403,7 @@ void ivas_dirac_dec_decorr_process( phase_coeff_imag = h_freq_domain_decorr_ap_params->phase_coeff_imag; incr_aux = 2 * ( num_freq_bands - max_band_decorr ); - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { /* final phase rotation */ for ( k = 0; k < max_band_decorr; k++ ) @@ -419,9 +419,9 @@ void ivas_dirac_dec_decorr_process( decorr_buffer_len = h_freq_domain_decorr_ap_params->filter_length[0] + h_freq_domain_decorr_ap_params->pre_delay[0] - 1; for ( time_idx = 0; time_idx < ( decorr_buffer_len - 1 ); time_idx++ ) { - mvr2r( &h_freq_domain_decorr_ap_state->decorr_buffer[2 * ( time_idx + 1 ) * max_band_decorr * num_channels], &h_freq_domain_decorr_ap_state->decorr_buffer[2 * (time_idx) *max_band_decorr * num_channels], 2 * max_band_decorr * num_channels ); + mvr2r( &h_freq_domain_decorr_ap_state->decorr_buffer[2 * ( time_idx + 1 ) * max_band_decorr * nchan], &h_freq_domain_decorr_ap_state->decorr_buffer[2 * (time_idx) *max_band_decorr * nchan], 2 * max_band_decorr * nchan ); } - set_zero( &h_freq_domain_decorr_ap_state->decorr_buffer[2 * ( decorr_buffer_len - 1 ) * max_band_decorr * num_channels], 2 * max_band_decorr * num_channels ); + set_zero( &h_freq_domain_decorr_ap_state->decorr_buffer[2 * ( decorr_buffer_len - 1 ) * max_band_decorr * nchan], 2 * max_band_decorr * nchan ); /* calculate all pass */ for ( split_bands_idx = 0; split_bands_idx < h_freq_domain_decorr_ap_params->num_split_frequency_bands; split_bands_idx++ ) @@ -431,15 +431,15 @@ void ivas_dirac_dec_decorr_process( num_bands = k_2 - k_1; filter_length = h_freq_domain_decorr_ap_params->filter_length[split_bands_idx]; pre_delay = h_freq_domain_decorr_ap_params->pre_delay[split_bands_idx]; - decorr_buffer_step = num_channels * max_band_decorr; + decorr_buffer_step = nchan * max_band_decorr; for ( k = 0; k < num_bands; ++k ) { band_idx = k_1 + k; - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { - idx_filter = band_idx * ( h_freq_domain_decorr_ap_params->filter_length[0] * num_channels ) + ch_idx * h_freq_domain_decorr_ap_params->filter_length[0]; + idx_filter = band_idx * ( h_freq_domain_decorr_ap_params->filter_length[0] * nchan ) + ch_idx * h_freq_domain_decorr_ap_params->filter_length[0]; filter_coeff_num_real = &h_freq_domain_decorr_ap_params->filter_coeff_num_real[idx_filter]; filter_coeff_den_real = &h_freq_domain_decorr_ap_params->filter_coeff_den_real[idx_filter]; decorr_buffer_start_ptr = &h_freq_domain_decorr_ap_state->decorr_buffer[2 * ( ch_idx * max_band_decorr + band_idx )]; @@ -486,18 +486,18 @@ void ivas_dirac_dec_decorr_process( /* calculate the power of the decorrelated signal */ - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { v_mult( &frame_dec_f[2 * ch_idx * num_freq_bands], &frame_dec_f[2 * ch_idx * num_freq_bands], &aux_buffer[2 * ch_idx * max_band_decorr], 2 * max_band_decorr ); v_add_inc( &aux_buffer[2 * ch_idx * max_band_decorr], 2, &aux_buffer[2 * ch_idx * max_band_decorr + 1], 2, &aux_buffer[ch_idx * max_band_decorr], 1, max_band_decorr ); } /* smooth energies */ - v_multc( aux_buffer, 1.0f - DIRAC_DUCK_ALPHA, aux_buffer, num_channels * max_band_decorr ); + v_multc( aux_buffer, 1.0f - DIRAC_DUCK_ALPHA, aux_buffer, nchan * max_band_decorr ); - v_multc( h_freq_domain_decorr_ap_state->reverb_energy_smooth, DIRAC_DUCK_ALPHA, h_freq_domain_decorr_ap_state->reverb_energy_smooth, num_channels * max_band_decorr ); + v_multc( h_freq_domain_decorr_ap_state->reverb_energy_smooth, DIRAC_DUCK_ALPHA, h_freq_domain_decorr_ap_state->reverb_energy_smooth, nchan * max_band_decorr ); - v_add( aux_buffer, h_freq_domain_decorr_ap_state->reverb_energy_smooth, h_freq_domain_decorr_ap_state->reverb_energy_smooth, num_channels * max_band_decorr ); + v_add( aux_buffer, h_freq_domain_decorr_ap_state->reverb_energy_smooth, h_freq_domain_decorr_ap_state->reverb_energy_smooth, nchan * max_band_decorr ); v_multc( direct_energy, 1.0f - DIRAC_DUCK_ALPHA, direct_energy, num_protos_dir * max_band_decorr ); @@ -505,7 +505,7 @@ void ivas_dirac_dec_decorr_process( v_add( direct_energy, h_freq_domain_decorr_ap_state->direct_energy_smooth, h_freq_domain_decorr_ap_state->direct_energy_smooth, num_protos_dir * max_band_decorr ); - for ( ch_idx = 0; ch_idx < num_channels; ch_idx++ ) + for ( ch_idx = 0; ch_idx < nchan; ch_idx++ ) { float *frame_dec_f_ptr = &frame_dec_f[ch_idx * 2 * num_freq_bands]; int16_t cur_proto_index = proto_index_dir[ch_idx] * max_band_decorr; @@ -545,7 +545,7 @@ void ivas_dirac_dec_decorr_process( if ( h_freq_domain_decorr_ap_params->add_back_onsets_on == 1 ) { - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { offset = proto_index_dir[ch_idx] * num_freq_bands; @@ -560,7 +560,7 @@ void ivas_dirac_dec_decorr_process( } /* avoid decorrelation above maximum frequency -> set to zero the remaining frequencies*/ - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { /* calc output indices */ idx_in_out = 2 * ( ch_idx * num_freq_bands + h_freq_domain_decorr_ap_params->max_band_decorr ); diff --git a/lib_dec/ivas_dirac_output_synthesis_cov.c b/lib_dec/ivas_dirac_output_synthesis_cov.c index decca3445234054923af2446157b98cd9329c2fc..a26a4695227b3ca3b34e3dd1b5d401945aafd604 100644 --- a/lib_dec/ivas_dirac_output_synthesis_cov.c +++ b/lib_dec/ivas_dirac_output_synthesis_cov.c @@ -65,7 +65,7 @@ void ivas_dirac_dec_output_synthesis_cov_open( const int16_t interp_length, /* i : length for interpolating the mixing matrices in time slots */ const int16_t num_param_bands, /* i : number of parameter bands */ const int16_t num_param_bands_residual, /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ - const int16_t nchan_in, /* i : number of input (transport) channels */ + const int16_t nchan_inp, /* i : number of input (transport) channels */ const int16_t nchan_out, /* i : number of output channels */ const float *proto_matrix /* i : the prototype (upmix) matrix (only used if mode == 1) */ ) @@ -80,18 +80,18 @@ void ivas_dirac_dec_output_synthesis_cov_open( /* buffer length and interpolator */ h_dirac_output_synthesis_params->alpha_synthesis = NULL; - h_dirac_output_synthesis_params->proto_matrix = (float *) count_malloc( nchan_out * nchan_in * sizeof( float ) ); + h_dirac_output_synthesis_params->proto_matrix = (float *) count_malloc( nchan_out * nchan_inp * sizeof( float ) ); /* cov buffers */ for ( idx = 0; idx < num_param_bands; idx++ ) { - h_dirac_output_synthesis_state->cx_old[idx] = (float *) count_malloc( nchan_in * nchan_in * sizeof( float ) ); + h_dirac_output_synthesis_state->cx_old[idx] = (float *) count_malloc( nchan_inp * nchan_inp * sizeof( float ) ); h_dirac_output_synthesis_state->cy_old[idx] = (float *) count_malloc( nchan_out * nchan_out * sizeof( float ) ); - h_dirac_output_synthesis_state->mixing_matrix_old[idx] = (float *) count_malloc( nchan_out * nchan_in * sizeof( float ) ); - set_zero( h_dirac_output_synthesis_state->cx_old[idx], nchan_in * nchan_in ); + h_dirac_output_synthesis_state->mixing_matrix_old[idx] = (float *) count_malloc( nchan_out * nchan_inp * sizeof( float ) ); + set_zero( h_dirac_output_synthesis_state->cx_old[idx], nchan_inp * nchan_inp ); set_zero( h_dirac_output_synthesis_state->cy_old[idx], nchan_out * nchan_out ); - set_zero( h_dirac_output_synthesis_state->mixing_matrix_old[idx], nchan_out * nchan_in ); + set_zero( h_dirac_output_synthesis_state->mixing_matrix_old[idx], nchan_out * nchan_inp ); } for ( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { @@ -120,7 +120,7 @@ void ivas_dirac_dec_output_synthesis_cov_open( h_dirac_output_synthesis_params->interpolator[idx - 1] = (float) idx / (float) interp_length; } - mvr2r( proto_matrix, h_dirac_output_synthesis_params->proto_matrix, nchan_in * nchan_out ); + mvr2r( proto_matrix, h_dirac_output_synthesis_params->proto_matrix, nchan_inp * nchan_out ); return; } @@ -134,7 +134,7 @@ void ivas_dirac_dec_output_synthesis_cov_open( void ivas_dirac_dec_output_synthesis_cov_init( DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: pointer to the state of the covariance synthesis */ - const int16_t nchan_in, /* i : number of input (tranport) channels */ + const int16_t nchan_inp, /* i : number of input (tranport) channels */ const int16_t nchan_out, /* i : number of output channels */ const int16_t n_param_bands, /* i : number of total parameter bands */ const int16_t n_param_bands_res /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ @@ -146,9 +146,9 @@ void ivas_dirac_dec_output_synthesis_cov_init( /* initialize buffers */ for ( idx = 0; idx < n_param_bands; idx++ ) { - set_zero( h_dirac_output_synthesis_state->cx_old[idx], nchan_in * nchan_in ); + set_zero( h_dirac_output_synthesis_state->cx_old[idx], nchan_inp * nchan_inp ); set_zero( h_dirac_output_synthesis_state->cy_old[idx], nchan_out * nchan_out ); - set_zero( h_dirac_output_synthesis_state->mixing_matrix_old[idx], nchan_out * nchan_in ); + set_zero( h_dirac_output_synthesis_state->mixing_matrix_old[idx], nchan_out * nchan_inp ); } for ( idx = 0; idx < n_param_bands_res; idx++ ) @@ -243,7 +243,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot( float cx[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (real part) */ float cx_imag[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (imaginary part) */ PARAM_MC_DEC_HANDLE hParamMC, /* i : handle to Parametric MC state */ - const int16_t nchan_in, /* i : number of input channels */ + const int16_t nchan_inp, /* i : number of input channels */ const int16_t idx_slot /* i : index of the slot to be added to the input covariance */ ) { @@ -268,18 +268,18 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot( for ( band_idx = 0; band_idx < num_bands; band_idx++ ) { int16_t band = brange[0] + band_idx; - for ( ch_idx = 0; ch_idx < nchan_in; ch_idx++ ) + for ( ch_idx = 0; ch_idx < nchan_inp; ch_idx++ ) { real_in_buffer[band_idx + num_bands * ch_idx] = RealBuffer[ch_idx][idx_slot][band]; imag_in_buffer[band_idx + num_bands * ch_idx] = ImagBuffer[ch_idx][idx_slot][band]; } } - cmplx_matrix_square( real_in_buffer, imag_in_buffer, num_bands, nchan_in, real_buffer, imag_buffer ); + cmplx_matrix_square( real_in_buffer, imag_in_buffer, num_bands, nchan_inp, real_buffer, imag_buffer ); - v_add( cx[param_band], real_buffer, cx[param_band], nchan_in * nchan_in ); + v_add( cx[param_band], real_buffer, cx[param_band], nchan_inp * nchan_inp ); - v_add( cx_imag[param_band], imag_buffer, cx_imag[param_band], nchan_in * nchan_in ); + v_add( cx_imag[param_band], imag_buffer, cx_imag[param_band], nchan_inp * nchan_inp ); } return; diff --git a/lib_dec/ivas_dirac_output_synthesis_dec.c b/lib_dec/ivas_dirac_output_synthesis_dec.c index 79c04f824b6f86848acc0df1962ec1e35757d1fe..3cf09b8182efa0e985cff18878aa054c32cf979d 100644 --- a/lib_dec/ivas_dirac_output_synthesis_dec.c +++ b/lib_dec/ivas_dirac_output_synthesis_dec.c @@ -61,15 +61,15 @@ * Local function prototypes *------------------------------------------------------------------------*/ -static void computeTargetPSDs_direct( const int16_t num_channels, const int16_t num_freq_bands, const float *direct_power_factor, const float *reference_power, const float *direct_responses, const float *direct_responses_square, float *cy_auto_dir_smooth, float *cy_cross_dir_smooth ); +static void computeTargetPSDs_direct( const int16_t nchan, const int16_t num_freq_bands, const float *direct_power_factor, const float *reference_power, const float *direct_responses, const float *direct_responses_square, float *cy_auto_dir_smooth, float *cy_cross_dir_smooth ); -static void computeTargetPSDs_direct_subframe( const int16_t num_channels, const int16_t num_freq_bands, const float *direct_power_factor, const float *reference_power, const float *direct_responses, const float *direct_responses_square, float *cy_auto_dir_smooth, float *cy_cross_dir_smooth ); +static void computeTargetPSDs_direct_subframe( const int16_t nchan, const int16_t num_freq_bands, const float *direct_power_factor, const float *reference_power, const float *direct_responses, const float *direct_responses_square, float *cy_auto_dir_smooth, float *cy_cross_dir_smooth ); -static void computeTargetPSDs_diffuse( const int16_t num_channels, const int16_t num_freq_bands, const int16_t start_band, const float *diffuse_power_factor, const float *reference_power, const float *diffuse_responses_square, float *cy_auto_diff_smooth ); +static void computeTargetPSDs_diffuse( const int16_t nchan, const int16_t num_freq_bands, const int16_t start_band, const float *diffuse_power_factor, const float *reference_power, const float *diffuse_responses_square, float *cy_auto_diff_smooth ); -static void computeTargetPSDs_diffuse_subframe( const int16_t num_channels, const int16_t num_freq_bands, const int16_t start_band, const float *diffuse_power_factor, const float *reference_power, const float *diffuse_responses_square, float *cy_auto_diff_smooth ); +static void computeTargetPSDs_diffuse_subframe( const int16_t nchan, const int16_t num_freq_bands, const int16_t start_band, const float *diffuse_power_factor, const float *reference_power, const float *diffuse_responses_square, float *cy_auto_diff_smooth ); -static void computeTargetPSDs_diffuse_with_onsets( const int16_t num_channels, const int16_t num_freq_bands, const int16_t num_decorr_freq_bands, const int16_t *proto_frame_diff_index, const float *diffuse_power_factor, const float *reference_power, const float *diffuse_responses_square, const float *onset_filter, float *cy_auto_diff_smooth ); +static void computeTargetPSDs_diffuse_with_onsets( const int16_t nchan, const int16_t num_freq_bands, const int16_t num_decorr_freq_bands, const int16_t *proto_frame_diff_index, const float *diffuse_power_factor, const float *reference_power, const float *diffuse_responses_square, const float *onset_filter, float *cy_auto_diff_smooth ); static void computeAlphaSynthesis( float *alpha_synthesis, const int16_t averaging_length_ms, const float maxAlpha, int16_t *numAlphas, const int16_t slot_size, const int16_t num_freq_bands, const float *frequency_axis, const int32_t output_Fs ); @@ -1812,7 +1812,7 @@ void ivas_lfe_synth_with_filters( *------------------------------------------------------------------------*/ static void computeTargetPSDs_direct( - const int16_t num_channels, + const int16_t nchan, const int16_t num_freq_bands, const float *direct_power_factor, const float *reference_power, @@ -1831,7 +1831,7 @@ static void computeTargetPSDs_direct( v_mult( direct_power_factor, reference_power, direct_power, num_freq_bands ); /* compute target auto and cross PSDs of current frame (smoothed) */ - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { cur_idx = ch_idx * num_freq_bands; @@ -1847,7 +1847,7 @@ static void computeTargetPSDs_direct( static void computeTargetPSDs_direct_subframe( - const int16_t num_channels, + const int16_t nchan, const int16_t num_freq_bands, const float *direct_power_factor, const float *reference_power, @@ -1865,7 +1865,7 @@ static void computeTargetPSDs_direct_subframe( v_mult( direct_power_factor, reference_power, direct_power, num_freq_bands ); /* compute target auto and cross PSDs of current frame (smoothed) */ - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { cur_idx = ch_idx * num_freq_bands; @@ -1878,7 +1878,7 @@ static void computeTargetPSDs_direct_subframe( static void computeTargetPSDs_diffuse( - const int16_t num_channels, + const int16_t nchan, const int16_t num_freq_bands, const int16_t start_band, const float *diffuse_power_factor, @@ -1896,7 +1896,7 @@ static void computeTargetPSDs_diffuse( v_mult( diffuse_power_factor, reference_power, diffuse_power, num_freq_bands ); /* compute target auto and cross PSDs of current frame (smoothed) */ - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { cur_idx = ch_idx * num_freq_bands; v_multc( &diffuse_power[start_band], diffuse_responses_square[ch_idx], aux_buffer_res, num_freq_bands - start_band ); @@ -1908,7 +1908,7 @@ static void computeTargetPSDs_diffuse( static void computeTargetPSDs_diffuse_subframe( - const int16_t num_channels, + const int16_t nchan, const int16_t num_freq_bands, const int16_t start_band, const float *diffuse_power_factor, @@ -1923,7 +1923,7 @@ static void computeTargetPSDs_diffuse_subframe( v_mult( diffuse_power_factor, reference_power, diffuse_power, num_freq_bands ); /* compute target auto and cross PSDs of current frame (smoothed) */ - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { cur_idx = ch_idx * num_freq_bands; @@ -1935,7 +1935,7 @@ static void computeTargetPSDs_diffuse_subframe( static void computeTargetPSDs_diffuse_with_onsets( - const int16_t num_channels, + const int16_t nchan, const int16_t num_freq_bands, const int16_t num_decorr_freq_bands, const int16_t *proto_frame_diff_index, @@ -1955,7 +1955,7 @@ static void computeTargetPSDs_diffuse_with_onsets( v_mult( diffuse_power_factor, reference_power, diffuse_power, num_decorr_freq_bands ); /* compute target auto and cross PSDs of current frame (smoothed) */ - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { diffuse_response_p4 = diffuse_responses_square[ch_idx] * diffuse_responses_square[ch_idx]; diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index e3849dfbe090ca8d8e305af266eb324b2064b5eb..df05d6b0b1dee6503148db5fde9798090fac1195 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -121,11 +121,11 @@ ivas_error ivas_dec_setup( /* read Ambisonic (SBA) order */ st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1]; st_ivas->sba_order += 2 * st_ivas->bit_stream[num_bits_read]; + num_bits_read += SBA_ORDER_BITS; /* set Ambisonic (SBA) order used for analysis and coding */ st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); - - num_bits_read += SBA_ORDER_BITS; + if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate && ivas_total_brate > IVAS_SID_5k2 ) { if ( ( error = ivas_sba_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) @@ -280,6 +280,7 @@ ivas_error ivas_dec_setup( st->next_bit_pos = num_bits_read; st->total_brate = ACELP_8k00; /* only temporary initialization - this is needed for get_next_indice() in the frame following NO_DATA frame */ } + return error; } @@ -594,7 +595,7 @@ ivas_error ivas_init_decoder( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { - int16_t i, k, n; + int16_t i, n; int16_t sce_id, cpe_id; int16_t numCldfbAnalyses; int16_t numCldfbSyntheses; @@ -755,7 +756,6 @@ ivas_error ivas_init_decoder( } else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT ) { - if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { return error; @@ -797,10 +797,7 @@ ivas_error ivas_init_decoder( return error; } - for ( k = 0; k < DIRAC_MAX_NBANDS; k++ ) - { - st_ivas->hSpar->dirac_to_spar_md_bands[k] = st_ivas->hDirAC->dirac_to_spar_md_bands[k]; - } + mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; } else @@ -1753,7 +1750,7 @@ void ivas_init_dec_get_num_cldfb_instances( case RENDERER_DIRAC: if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { - *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans; + *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->nchan_inp; if ( st_ivas->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC ) { @@ -1761,7 +1758,7 @@ void ivas_init_dec_get_num_cldfb_instances( } else if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA ) { - *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->num_out_chans; + *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->nchan_out; } else { @@ -1811,7 +1808,7 @@ void ivas_init_dec_get_num_cldfb_instances( case RENDERER_BINAURAL_FASTCONV_ROOM: if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { - *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans; + *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->nchan_inp; if ( st_ivas->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC ) { @@ -1819,7 +1816,7 @@ void ivas_init_dec_get_num_cldfb_instances( } else if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA ) { - *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->num_out_chans; + *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->nchan_out; } else { diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index c6c1f99c9c960aab46001c9e640f0ea98c7c1892..03932b51d9b6c952c0db4dda4e3e321ad0066afb 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -285,7 +285,7 @@ static void ivas_param_ism_rendering( const int16_t num_ch_LS, const int16_t nchan_transport ) { - int16_t outchIdx, inchIdx, bin_idx; + int16_t ch_out, ch_inp, bin_idx; float tmp_1, mixing_matrix_smooth; tmp_1 = hDirAC->hParamIsmRendering->interpolator[slot_idx]; @@ -293,15 +293,15 @@ static void ivas_param_ism_rendering( for ( bin_idx = 0; bin_idx < hDirAC->num_freq_bands; bin_idx++ ) { /* smooth the mixing matrix */ - for ( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ ) + for ( ch_out = 0; ch_out < num_ch_LS; ch_out++ ) { - for ( inchIdx = 0; inchIdx < nchan_transport; inchIdx++ ) + for ( ch_inp = 0; ch_inp < nchan_transport; ch_inp++ ) { - mixing_matrix_smooth = tmp_1 * mixing_matrix[bin_idx][outchIdx + inchIdx * num_ch_LS] + - ( 1 - tmp_1 ) * hDirAC->hParamIsmRendering->mixing_matrix_lin_old[bin_idx][outchIdx + inchIdx * num_ch_LS]; + mixing_matrix_smooth = tmp_1 * mixing_matrix[bin_idx][ch_out + ch_inp * num_ch_LS] + + ( 1 - tmp_1 ) * hDirAC->hParamIsmRendering->mixing_matrix_lin_old[bin_idx][ch_out + ch_inp * num_ch_LS]; - Cldfb_RealBuffer[outchIdx][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_RealBuffer_in[inchIdx][slot_idx][bin_idx]; - Cldfb_ImagBuffer[outchIdx][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_ImagBuffer_in[inchIdx][slot_idx][bin_idx]; + Cldfb_RealBuffer[ch_out][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_RealBuffer_in[ch_inp][slot_idx][bin_idx]; + Cldfb_ImagBuffer[ch_out][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_ImagBuffer_in[ch_inp][slot_idx][bin_idx]; } } } @@ -351,10 +351,10 @@ static ivas_error ivas_param_ism_rendering_init( static void ivas_param_ism_update_mixing_matrix( DIRAC_DEC_HANDLE hDirAC, float mixing_matrix[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], - const int16_t nchan_in, + const int16_t nchan_inp, const int16_t nchan_out ) { - int16_t inchIdx, outchIdx, bin_idx, band_idx; + int16_t ch_inp, ch_out, bin_idx, band_idx; int16_t brange[2]; for ( band_idx = 0; band_idx < hDirAC->hParamIsm->nbands; band_idx++ ) @@ -364,11 +364,11 @@ static void ivas_param_ism_update_mixing_matrix( for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ ) { - for ( inchIdx = 0; inchIdx < nchan_in; inchIdx++ ) + for ( ch_inp = 0; ch_inp < nchan_inp; ch_inp++ ) { - for ( outchIdx = 0; outchIdx < nchan_out; outchIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - hDirAC->hParamIsmRendering->mixing_matrix_lin_old[bin_idx][outchIdx + inchIdx * nchan_out] = mixing_matrix[bin_idx][outchIdx + inchIdx * nchan_out]; + hDirAC->hParamIsmRendering->mixing_matrix_lin_old[bin_idx][ch_out + ch_inp * nchan_out] = mixing_matrix[bin_idx][ch_out + ch_inp * nchan_out]; } } } diff --git a/lib_dec/ivas_limiter.c b/lib_dec/ivas_limiter.c index e483318be8c08350ee00ea008baeb48707d92da4..d3dcd8027f5e32e23ad1ed8f5db21a23d07d1433 100644 --- a/lib_dec/ivas_limiter.c +++ b/lib_dec/ivas_limiter.c @@ -125,7 +125,7 @@ IVAS_LIMITER_HANDLE ivas_limiter_open( hLimiter = count_malloc( sizeof( IVAS_LIMITER ) ); hLimiter->max_num_channels = max_num_channels; - hLimiter->num_channels = max_num_channels; + hLimiter->nchan = max_num_channels; hLimiter->channel_ptrs = count_malloc( max_num_channels * sizeof( float * ) ); hLimiter->sampling_rate = sampling_rate; hLimiter->gain = 1.f; @@ -176,11 +176,11 @@ void ivas_limiter_close( *-------------------------------------------------------------------*/ void ivas_limiter_dec( - IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ - float output[MAX_OUTPUT_CHANNELS][L_FRAME48k], /* i/o: input/output buffer */ - const int16_t num_channels, /* i : number of channels to be processed */ - const int16_t output_frame, /* i : number of samples per channel in the buffer */ - const int16_t BER_detect /* i : BER detect flag */ + IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ + float output[MAX_OUTPUT_CHANNELS][L_FRAME48k], /* i/o: input/output buffer */ + const int16_t nchan, /* i : number of channels to be processed */ + const int16_t output_frame, /* i : number of samples per channel in the buffer */ + const int16_t BER_detect /* i : BER detect flag */ ) { int16_t c; @@ -193,11 +193,11 @@ void ivas_limiter_dec( } /* Update number of channels and prepare pointers to the beginning of each of them */ - assert( num_channels <= hLimiter->max_num_channels && "Number of channels must be lower than the maximum set during limiter initialization!" ); - hLimiter->num_channels = min( num_channels, hLimiter->max_num_channels ); + assert( nchan <= hLimiter->max_num_channels && "Number of channels must be lower than the maximum set during limiter initialization!" ); + hLimiter->nchan = min( nchan, hLimiter->max_num_channels ); channels = hLimiter->channel_ptrs; - for ( c = 0; c < num_channels; ++c ) + for ( c = 0; c < nchan; ++c ) { channels[c] = output[c]; } @@ -231,7 +231,7 @@ void limiter_process( float releaseHeuristic; int16_t apply_limiting, apply_strong_limiting; float **output; - int16_t num_channels; + int16_t nchan; int32_t sampling_rate; /* return early if given nonsensical values */ @@ -245,7 +245,7 @@ void limiter_process( gain = hLimiter->gain; output = hLimiter->channel_ptrs; - num_channels = hLimiter->num_channels; + nchan = hLimiter->nchan; sampling_rate = hLimiter->sampling_rate; attack_constant = hLimiter->attack_constant; @@ -257,7 +257,7 @@ void limiter_process( for ( i = 0; i < output_frame; i++ ) { - for ( c = 0; c < num_channels; c++ ) + for ( c = 0; c < nchan; c++ ) { tmp = fabsf( output[c][i] ); if ( tmp > max_val ) @@ -364,7 +364,7 @@ void limiter_process( gain = release_constant * ( gain - frame_gain ) + frame_gain; } - for ( c = 0; c < num_channels; c++ ) + for ( c = 0; c < nchan; c++ ) { sample = &output[c][i]; diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 29e2ce40025443b0b0384dfb80cb7e23733e1478..a6889137f6e374835c530e24dda9f19729288032 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -60,8 +60,7 @@ * Local function prototypes *-----------------------------------------------------------------------*/ -static void ivas_param_mc_dec_init( PARAM_MC_DEC_HANDLE hParamMC, const int16_t nchan_in, const int16_t nchan_out ); - +static void ivas_param_mc_dec_init( PARAM_MC_DEC_HANDLE hParamMC, const int16_t nchan_inp, const int16_t nchan_out ); static void param_mc_protoSignalComputation( float RealBuffer[PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_NSLOTS][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_NSLOTS][CLDFB_NO_CHANNELS_MAX], float *proto_frame_f, const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, const int16_t slot_index, const int16_t num_freq_bands ); diff --git a/lib_dec/ivas_out_setup_conversion.c b/lib_dec/ivas_out_setup_conversion.c index 9ed27e56c3d21f63d1d14675ffcb76bc8c47a52a..10436882cb65111f45eba07836610b4bcbf88b93 100644 --- a/lib_dec/ivas_out_setup_conversion.c +++ b/lib_dec/ivas_out_setup_conversion.c @@ -147,7 +147,7 @@ static void get_custom_ls_conversion_matrix( { int16_t ch_in, ch_in_woLFE; int16_t ch_out, ch_out_woLFE; - int16_t nchan_in, nchan_out; + int16_t nchan_inp, nchan_out; int16_t lfe_in_idx, lfe_out_idx; float dmxCoeff_LFE; @@ -156,7 +156,7 @@ static void get_custom_ls_conversion_matrix( lfe_in_idx = -1; lfe_out_idx = -1; - nchan_in = hTransSetup.nchan_out_woLFE + hTransSetup.num_lfe; + nchan_inp = hTransSetup.nchan_out_woLFE + hTransSetup.num_lfe; nchan_out = hLsSetupCustom->num_spk + hLsSetupCustom->num_lfe; /* The below code will need to be restructured in case additional LFEs must be supported */ @@ -171,7 +171,7 @@ static void get_custom_ls_conversion_matrix( dmxCoeff_LFE = 1.f / hTransSetup.nchan_out_woLFE; - for ( ch_in = 0, ch_in_woLFE = 0; ch_in < nchan_in; ch_in++, ch_in_woLFE++ ) + for ( ch_in = 0, ch_in_woLFE = 0; ch_in < nchan_inp; ch_in++, ch_in_woLFE++ ) { if ( lfe_in_idx == ch_in ) { @@ -218,7 +218,7 @@ static ivas_error get_ls_conversion_matrix( { int16_t i, k; int16_t ch_in, ch_out; - int16_t nchan_in, nchan_out; + int16_t nchan_inp, nchan_out; int16_t index; float value; const LS_CONVERSION_MATRIX *conversion_matrix; @@ -228,7 +228,7 @@ static ivas_error get_ls_conversion_matrix( conversion_matrix = NULL; - nchan_in = audioCfg2channels( input_config ); + nchan_inp = audioCfg2channels( input_config ); nchan_out = audioCfg2channels( output_config ); /* Search the table for a mapping */ @@ -239,7 +239,7 @@ static ivas_error get_ls_conversion_matrix( /* Special handling for MONO and STEREO downmix */ if ( output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO ) { - for ( ch_in = 0, k = 0; ch_in < nchan_in; ch_in++, k++ ) + for ( ch_in = 0, k = 0; ch_in < nchan_inp; ch_in++, k++ ) { /* Skip two rows in the matrix for 5.1.x formats */ if ( ch_in == 6 && ( input_config == AUDIO_CONFIG_5_1_2 || input_config == AUDIO_CONFIG_5_1_4 ) ) @@ -268,7 +268,7 @@ static ivas_error get_ls_conversion_matrix( /* If a mapping is defined with a NULL matrix, 1:1 upmix of input channels */ if ( conversion_matrix == NULL ) { - for ( k = 0; k < nchan_in; k++ ) + for ( k = 0; k < nchan_inp; k++ ) { hLsSetUpConversion->dmxMtx[k][k] = 1.0f; } @@ -307,10 +307,9 @@ ivas_error ivas_ls_setup_conversion_open( ) { LSSETUP_CONVERSION_HANDLE hLsSetUpConversion; - int16_t chIdx, inChannels, outChannels; + int16_t chIdx, nchan_inp, nchan_out; int16_t output_frame; int32_t output_Fs; - int16_t nchan_out; output_Fs = st_ivas->hDecoderConfig->output_Fs; nchan_out = st_ivas->hDecoderConfig->nchan_out; @@ -324,12 +323,11 @@ ivas_error ivas_ls_setup_conversion_open( assert( nchan_out <= MAX_OUTPUT_CHANNELS ); - outChannels = nchan_out; if ( st_ivas->renderer_type == RENDERER_MC_PARAMMC ) { - inChannels = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; + nchan_inp = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; hLsSetUpConversion->sfbCnt = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); - for ( chIdx = 0; chIdx < outChannels; chIdx++ ) + for ( chIdx = 0; chIdx < nchan_out; chIdx++ ) { hLsSetUpConversion->targetEnergyPrev[chIdx] = (float *) count_malloc( ( hLsSetUpConversion->sfbCnt ) * sizeof( float ) ); hLsSetUpConversion->dmxEnergyPrev[chIdx] = (float *) count_malloc( ( hLsSetUpConversion->sfbCnt ) * sizeof( float ) ); @@ -344,7 +342,7 @@ ivas_error ivas_ls_setup_conversion_open( } else { - inChannels = st_ivas->nchan_transport; + nchan_inp = st_ivas->nchan_transport; /*Initialization of MDCT bands with TCX20 resolution */ ivas_lssetupconversion_mdct_init_bands( output_frame, TCX_20_CORE, &hLsSetUpConversion->sfbOffset[0], &hLsSetUpConversion->sfbCnt ); hLsSetUpConversion->targetEnergyPrev[0] = (float *) count_malloc( ( MAX_SFB + 2 ) * sizeof( float ) ); @@ -360,14 +358,14 @@ ivas_error ivas_ls_setup_conversion_open( /* Initialize the DMX conversion matrix */ - for ( chIdx = 0; chIdx < inChannels; chIdx++ ) + for ( chIdx = 0; chIdx < nchan_inp; chIdx++ ) { /* Allocate memory depending on the number of output channels */ - if ( ( hLsSetUpConversion->dmxMtx[chIdx] = (float *) count_malloc( outChannels * sizeof( float ) ) ) == NULL ) + if ( ( hLsSetUpConversion->dmxMtx[chIdx] = (float *) count_malloc( nchan_out * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for temp dmx matrix \n" ) ); } - set_zero( hLsSetUpConversion->dmxMtx[chIdx], outChannels ); + set_zero( hLsSetUpConversion->dmxMtx[chIdx], nchan_out ); } for ( ; chIdx < MAX_CICP_CHANNELS; chIdx++ ) @@ -455,7 +453,7 @@ void ivas_ls_setup_conversion( float output[][L_FRAME48k] /* i/o: LS input/output synthesis signal */ ) { - int16_t chInIdx, chOutIdx, idx; + int16_t ch_in, ch_out, idx; LSSETUP_CONVERSION_HANDLE hLsSetUpConversion; float dmxCoeff, tmpVal; float output_tmp[MAX_OUTPUT_CHANNELS][L_FRAME48k]; @@ -464,12 +462,12 @@ void ivas_ls_setup_conversion( hLsSetUpConversion = st_ivas->hLsSetUpConversion; - for ( chOutIdx = 0; chOutIdx < st_ivas->hDecoderConfig->nchan_out; chOutIdx++ ) + for ( ch_out = 0; ch_out < st_ivas->hDecoderConfig->nchan_out; ch_out++ ) { - set_zero( output_tmp[chOutIdx], output_frame ); - for ( chInIdx = 0; chInIdx < st_ivas->nchan_transport; chInIdx++ ) + set_zero( output_tmp[ch_out], output_frame ); + for ( ch_in = 0; ch_in < st_ivas->nchan_transport; ch_in++ ) { - dmxCoeff = hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx]; + dmxCoeff = hLsSetUpConversion->dmxMtx[ch_in][ch_out]; if ( dmxCoeff == 0.f ) { @@ -479,24 +477,24 @@ void ivas_ls_setup_conversion( { for ( idx = 0; idx < output_frame; idx++ ) { - output_tmp[chOutIdx][idx] += output[chInIdx][idx]; + output_tmp[ch_out][idx] += output[ch_in][idx]; } } else { for ( idx = 0; idx < output_frame; idx++ ) { - tmpVal = dmxCoeff * output[chInIdx][idx]; - output_tmp[chOutIdx][idx] += tmpVal; + tmpVal = dmxCoeff * output[ch_in][idx]; + output_tmp[ch_out][idx] += tmpVal; } } } } /* Copy to output buffer */ - for ( chOutIdx = 0; chOutIdx < st_ivas->hDecoderConfig->nchan_out; chOutIdx++ ) + for ( ch_out = 0; ch_out < st_ivas->hDecoderConfig->nchan_out; ch_out++ ) { - mvr2r( output_tmp[chOutIdx], output[chOutIdx], output_frame ); + mvr2r( output_tmp[ch_out], output[ch_out], output_frame ); } wmops_sub_end(); @@ -517,8 +515,8 @@ void ivas_ls_setup_conversion_process_mdct( ) { /* Declaration of all required variables */ - int16_t i, bandIdx, chInIdx, chOutIdx, cpe_idx, subFrameIdx, binIdx, idx; - int16_t inChannels, outChannels, num_CPE; + int16_t i, bandIdx, ch_in, ch_out, cpe_idx, subFrameIdx, binIdx, idx; + int16_t nchan_in, nchan_out, num_CPE; int16_t transform_type[MAX_CICP_CHANNELS][2]; int16_t frameSize; float targetEnergy[MAX_SFB + 2], dmxEnergy[MAX_SFB + 2]; @@ -538,15 +536,15 @@ void ivas_ls_setup_conversion_process_mdct( wmops_sub_start( "LS_Renderer_MDCT" ); /* Assign all the declared variables */ - inChannels = st_ivas->nchan_transport; - outChannels = st_ivas->hDecoderConfig->nchan_out; + nchan_in = st_ivas->nchan_transport; + nchan_out = st_ivas->hDecoderConfig->nchan_out; num_CPE = st_ivas->nCPE; /* Assign output pointer to variable x */ - for ( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_in; ch_in++ ) { - x[chInIdx][0] = &output[chInIdx][0]; - x[chInIdx][1] = &output[chInIdx][0] + L_FRAME48k / 2; + x[ch_in][0] = &output[ch_in][0]; + x[ch_in][1] = &output[ch_in][0] + L_FRAME48k / 2; } /* Assign all the declared handles*/ @@ -562,11 +560,11 @@ void ivas_ls_setup_conversion_process_mdct( for ( idx = 0; idx < CPE_CHANNELS; idx++ ) { /* get the channel index */ - chInIdx = cpe_idx * CPE_CHANNELS + idx; - assert( chInIdx <= inChannels ); - transform_type[chInIdx][0] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[0]; - transform_type[chInIdx][1] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[1]; - mct_chan_mode[chInIdx] = hCPE[cpe_idx]->hCoreCoder[idx]->mct_chan_mode; + ch_in = cpe_idx * CPE_CHANNELS + idx; + assert( ch_in <= nchan_in ); + transform_type[ch_in][0] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[0]; + transform_type[ch_in][1] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[1]; + mct_chan_mode[ch_in] = hCPE[cpe_idx]->hCoreCoder[idx]->mct_chan_mode; } } @@ -576,17 +574,17 @@ void ivas_ls_setup_conversion_process_mdct( set_zero( targetEnergy, MAX_SFB + 2 ); set_zero( dmxEnergy, MAX_SFB + 2 ); - for ( chOutIdx = 0; chOutIdx < outChannels; chOutIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { /* Step 0: Set the buffers to zero */ set_zero( dmxSignalReal, frameSize ); set_zero( dmxSignalImag, frameSize ); - for ( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_in; ch_in++ ) { - dmxCoeff = hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx]; + dmxCoeff = hLsSetUpConversion->dmxMtx[ch_in][ch_out]; - if ( !( chInIdx == LFE_CHANNEL && st_ivas->hMCT->LFE_off ) && mct_chan_mode[chInIdx] != MCT_CHAN_MODE_IGNORE ) + if ( !( ch_in == LFE_CHANNEL && st_ivas->hMCT->LFE_off ) && mct_chan_mode[ch_in] != MCT_CHAN_MODE_IGNORE ) { /* Step 1: Compute the target energy and DMX signal (possible since we have all signals in TCX20 resolution) */ if ( dmxCoeff ) @@ -595,19 +593,19 @@ void ivas_ls_setup_conversion_process_mdct( /* Convert the signal resolution to TCX20 */ /* initially, set pointers to input; if conversion occurs in (sub)frame, set to convertRes */ - sig[0] = pTmp[0] = x[chInIdx][0]; - sig[1] = pTmp[1] = x[chInIdx][1]; + sig[0] = pTmp[0] = x[ch_in][0]; + sig[1] = pTmp[1] = x[ch_in][1]; /* convert (sub)frames to higher frequency resolution */ - if ( transform_type[chInIdx][0] != TCX_20 ) + if ( transform_type[ch_in][0] != TCX_20 ) { for ( subFrameIdx = 0; subFrameIdx < NB_DIV; subFrameIdx++ ) { - if ( transform_type[chInIdx][subFrameIdx] == TCX_5 ) + if ( transform_type[ch_in][subFrameIdx] == TCX_5 ) { /* subframe is TCX5, but TCX10 or TCX20 in other channel -> convert channel with TCX5 to TCX10 resolution */ pTmp[subFrameIdx] = sig[subFrameIdx] = convertRes + subFrameIdx * frameSize / 2; - convert_coeffs_to_higher_res( x[chInIdx][subFrameIdx], x[chInIdx][subFrameIdx] + frameSize / 4, pTmp[subFrameIdx], frameSize / 4 ); + convert_coeffs_to_higher_res( x[ch_in][subFrameIdx], x[ch_in][subFrameIdx] + frameSize / 4, pTmp[subFrameIdx], frameSize / 4 ); } } @@ -645,7 +643,7 @@ void ivas_ls_setup_conversion_process_mdct( } /* end of band loop */ } } - } /* end of chInIdx loop */ + } /* end of ch_in loop */ for ( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { @@ -677,11 +675,11 @@ void ivas_ls_setup_conversion_process_mdct( } /* Step 4: Perform equalization */ - for ( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_in; ch_in++ ) { - if ( !( chInIdx == LFE_CHANNEL && st_ivas->hMCT->LFE_off ) && mct_chan_mode[chInIdx] != MCT_CHAN_MODE_IGNORE ) + if ( !( ch_in == LFE_CHANNEL && st_ivas->hMCT->LFE_off ) && mct_chan_mode[ch_in] != MCT_CHAN_MODE_IGNORE ) { - if ( transform_type[chInIdx][0] == TCX_20 ) + if ( transform_type[ch_in][0] == TCX_20 ) { /* TCX20 */ for ( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) @@ -693,7 +691,7 @@ void ivas_ls_setup_conversion_process_mdct( ivas_lssetupconversion_computeEQFactor( &targetEnergy[bandIdx], &dmxEnergy[bandIdx], &eqGain ); for ( binIdx = start; binIdx < stop; binIdx++ ) { - x[chInIdx][0][binIdx] *= eqGain; + x[ch_in][0][binIdx] *= eqGain; } } } @@ -710,12 +708,12 @@ void ivas_ls_setup_conversion_process_mdct( for ( subFrameIdx = 0; subFrameIdx < NB_DIV; subFrameIdx++ ) { - if ( transform_type[chInIdx][subFrameIdx] == TCX_10 ) + if ( transform_type[ch_in][subFrameIdx] == TCX_10 ) { /* TCX10 */ for ( binIdx = start; binIdx < stop; binIdx++ ) { - x[chInIdx][subFrameIdx][binIdx] *= eqGain; + x[ch_in][subFrameIdx][binIdx] *= eqGain; } } else @@ -726,8 +724,8 @@ void ivas_ls_setup_conversion_process_mdct( for ( binIdx = start_tcx5; binIdx < stop_tcx5; binIdx++ ) { - x[chInIdx][subFrameIdx][binIdx] *= eqGain; - x[chInIdx][subFrameIdx][binIdx + ( frameSize >> 2 )] *= eqGain; + x[ch_in][subFrameIdx][binIdx] *= eqGain; + x[ch_in][subFrameIdx][binIdx + ( frameSize >> 2 )] *= eqGain; } } } @@ -756,7 +754,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( int16_t i; int16_t idx; int16_t nchan_transport, nchan_out, nchan_transport_format; - int16_t chInIdx, chOutIdx, cpe_idx, subFrameIdx, binIdx; + int16_t ch_in, ch_out, cpe_idx, subFrameIdx, binIdx; int16_t band, bandIdx, num_bands; int16_t num_CPE; @@ -819,11 +817,11 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( for ( idx = 0; idx < CPE_CHANNELS; idx++ ) { /* get the channel index */ - chInIdx = cpe_idx * CPE_CHANNELS + idx; - assert( chInIdx <= nchan_transport ); - transform_type[chInIdx][0] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[0]; - transform_type[chInIdx][1] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[1]; - mct_chan_mode[chInIdx] = hCPE[cpe_idx]->hCoreCoder[idx]->mct_chan_mode; + ch_in = cpe_idx * CPE_CHANNELS + idx; + assert( ch_in <= nchan_transport ); + transform_type[ch_in][0] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[0]; + transform_type[ch_in][1] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[1]; + mct_chan_mode[ch_in] = hCPE[cpe_idx]->hCoreCoder[idx]->mct_chan_mode; } } @@ -833,43 +831,43 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( set_zero( targetEnergy, MAX_SFB + 2 ); set_zero( dmxEnergy, MAX_SFB + 2 ); - for ( chInIdx = 0; chInIdx < nchan_transport; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_transport; ch_in++ ) { - if ( mct_chan_mode[chInIdx] != MCT_CHAN_MODE_IGNORE ) + if ( mct_chan_mode[ch_in] != MCT_CHAN_MODE_IGNORE ) { /* initially, set pointers to input; if conversion occurs in (sub)frame, set to convertRes */ - sig[chInIdx][0] = pTmp[0] = x[chInIdx][0]; - sig[chInIdx][1] = pTmp[1] = x[chInIdx][1]; + sig[ch_in][0] = pTmp[0] = x[ch_in][0]; + sig[ch_in][1] = pTmp[1] = x[ch_in][1]; /* convert (sub)frames to higher frequency resolution */ - if ( transform_type[chInIdx][0] != TCX_20 ) + if ( transform_type[ch_in][0] != TCX_20 ) { for ( subFrameIdx = 0; subFrameIdx < NB_DIV; subFrameIdx++ ) { - if ( transform_type[chInIdx][subFrameIdx] == TCX_5 ) + if ( transform_type[ch_in][subFrameIdx] == TCX_5 ) { /* subframe is TCX5, but TCX10 or TCX20 in other channel -> convert channel with TCX5 to TCX10 resolution */ - pTmp[subFrameIdx] = sig[chInIdx][subFrameIdx] = convertRes[chInIdx] + subFrameIdx * frameSize / 2; - convert_coeffs_to_higher_res( x[chInIdx][subFrameIdx], x[chInIdx][subFrameIdx] + frameSize / 4, pTmp[subFrameIdx], frameSize / 4 ); + pTmp[subFrameIdx] = sig[ch_in][subFrameIdx] = convertRes[ch_in] + subFrameIdx * frameSize / 2; + convert_coeffs_to_higher_res( x[ch_in][subFrameIdx], x[ch_in][subFrameIdx] + frameSize / 4, pTmp[subFrameIdx], frameSize / 4 ); } } /* convert channel with TCX10 to TCX20 resolution */ - sig[chInIdx][0] = convertRes[chInIdx]; - convert_coeffs_to_higher_res( pTmp[0], pTmp[1], sig[chInIdx][0], frameSize / 2 ); + sig[ch_in][0] = convertRes[ch_in]; + convert_coeffs_to_higher_res( pTmp[0], pTmp[1], sig[ch_in][0], frameSize / 2 ); } } } /* precalculate MDST estimate */ - for ( chInIdx = 0; chInIdx < nchan_transport; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_transport; ch_in++ ) { - if ( mct_chan_mode[chInIdx] != MCT_CHAN_MODE_IGNORE ) + if ( mct_chan_mode[ch_in] != MCT_CHAN_MODE_IGNORE ) { - mdst[chInIdx][0] = mdst[chInIdx][frameSize - 1] = 0.f; + mdst[ch_in][0] = mdst[ch_in][frameSize - 1] = 0.f; for ( i = 1; i < frameSize - 1; i++ ) { - mdst[chInIdx][i] = sig[chInIdx][0][i + 1] - sig[chInIdx][0][i - 1]; + mdst[ch_in][i] = sig[ch_in][0][i + 1] - sig[ch_in][0][i - 1]; } } } @@ -925,48 +923,48 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( /* Step 1.2, get target channel energies for the transported format as in ivas_param_mc_get_mono_stereo_mixing_matrices(), Nrqq calculation */ ild_q = hParamMC->icld_q + bandIdx * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe; - for ( chInIdx = 0; chInIdx < nchan_transport_format; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_transport_format; ch_in++ ) { float ref_ener = 0.0f; int16_t ref_channel_cnt; int16_t ref_channel_idx; - for ( ref_channel_cnt = 0; ref_channel_cnt < hParamMC->hMetadataPMC->ild_mapping_conf->num_ref_channels[chInIdx]; ref_channel_cnt++ ) + for ( ref_channel_cnt = 0; ref_channel_cnt < hParamMC->hMetadataPMC->ild_mapping_conf->num_ref_channels[ch_in]; ref_channel_cnt++ ) { - ref_channel_idx = hParamMC->hMetadataPMC->ild_mapping_conf->ref_channel_idx[chInIdx][ref_channel_cnt]; + ref_channel_idx = hParamMC->hMetadataPMC->ild_mapping_conf->ref_channel_idx[ch_in][ref_channel_cnt]; ref_ener += cx[bandIdx][ref_channel_idx + ref_channel_idx * nchan_transport]; } - Nrqq[hParamMC->hMetadataPMC->ild_mapping_conf->ild_index[chInIdx]] = powf( 10.0f, ild_q[chInIdx] / 10.0f ) * hParamMC->hMetadataPMC->ild_factors[chInIdx] * ref_ener; + Nrqq[hParamMC->hMetadataPMC->ild_mapping_conf->ild_index[ch_in]] = powf( 10.0f, ild_q[ch_in] / 10.0f ) * hParamMC->hMetadataPMC->ild_factors[ch_in] * ref_ener; } /* Step 1.3 get target Cy like in ivas_param_mc_get_mono_stereo_mixing_matrices() (with dmx matrix from CICPX to MONO/STEREO saved in hParamMC) */ - for ( chOutIdx = 0; chOutIdx < nchan_out; chOutIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { for ( i = 0; i < nchan_transport_format; i++ ) { - target_ch_ener[chOutIdx] += hParamMC->ls_conv_dmx_matrix[chOutIdx + i * nchan_out] * Nrqq[i]; + target_ch_ener[ch_out] += hParamMC->ls_conv_dmx_matrix[ch_out + i * nchan_out] * Nrqq[i]; } - cy[chOutIdx + nchan_out * chOutIdx] = target_ch_ener[chOutIdx]; + cy[ch_out + nchan_out * ch_out] = target_ch_ener[ch_out]; } /* Step 1.4 final target energy for the band would then be the sum over the diagonal of Cy*/ - for ( chOutIdx = 0; chOutIdx < nchan_out; chOutIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - targetEnergy[bandIdx] += cy[chOutIdx + nchan_out * chOutIdx]; + targetEnergy[bandIdx] += cy[ch_out + nchan_out * ch_out]; } /* Step 2: Calculate DMX ener */ start = hLsSetUpConversion->sfbOffset[bandIdx]; stop = hLsSetUpConversion->sfbOffset[bandIdx + 1]; - for ( chOutIdx = 0; chOutIdx < nchan_out; chOutIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - for ( chInIdx = 0; chInIdx < nchan_transport; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_transport; ch_in++ ) { - if ( mct_chan_mode[chInIdx] != MCT_CHAN_MODE_IGNORE ) + if ( mct_chan_mode[ch_in] != MCT_CHAN_MODE_IGNORE ) { - dmxCoeff = hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx]; + dmxCoeff = hLsSetUpConversion->dmxMtx[ch_in][ch_out]; /* Step 1: Compute the target energy and DMX signal (possible since we have all signals in TCX20 resolution) */ if ( dmxCoeff ) @@ -974,10 +972,10 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( /* Loop over all the bins in the band */ for ( binIdx = start; binIdx < stop; binIdx++ ) { - tmpDMXSig = dmxCoeff * sig[chInIdx][0][binIdx]; + tmpDMXSig = dmxCoeff * sig[ch_in][0][binIdx]; dmxSignalReal[binIdx] += tmpDMXSig; - tmpDMXSig = dmxCoeff * mdst[chInIdx][binIdx]; + tmpDMXSig = dmxCoeff * mdst[ch_in][binIdx]; dmxSignalImag[binIdx] += tmpDMXSig; } } @@ -1008,11 +1006,11 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( } /* Step 4: Perform equalization */ - for ( chInIdx = 0; chInIdx < nchan_transport; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_transport; ch_in++ ) { - if ( mct_chan_mode[chInIdx] != MCT_CHAN_MODE_IGNORE ) + if ( mct_chan_mode[ch_in] != MCT_CHAN_MODE_IGNORE ) { - if ( transform_type[chInIdx][0] == TCX_20 ) + if ( transform_type[ch_in][0] == TCX_20 ) { /*TCX20*/ for ( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) @@ -1024,7 +1022,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( ivas_lssetupconversion_computeEQFactor( &targetEnergy[bandIdx], &dmxEnergy[bandIdx], &eqGain ); for ( binIdx = start; binIdx < stop; binIdx++ ) { - x[chInIdx][0][binIdx] *= eqGain; + x[ch_in][0][binIdx] *= eqGain; } } } @@ -1041,12 +1039,12 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( for ( subFrameIdx = 0; subFrameIdx < NB_DIV; subFrameIdx++ ) { - if ( transform_type[chInIdx][subFrameIdx] == TCX_10 ) + if ( transform_type[ch_in][subFrameIdx] == TCX_10 ) { /*TCX10*/ for ( binIdx = start; binIdx < stop; binIdx++ ) { - x[chInIdx][subFrameIdx][binIdx] *= eqGain; + x[ch_in][subFrameIdx][binIdx] *= eqGain; } } else @@ -1056,12 +1054,12 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( stop_tcx5 = ( stop + 1 ) / 2; for ( binIdx = start_tcx5; binIdx < stop_tcx5; binIdx++ ) { - x[chInIdx][subFrameIdx][binIdx] *= eqGain; + x[ch_in][subFrameIdx][binIdx] *= eqGain; } for ( binIdx = start_tcx5; binIdx < stop_tcx5; binIdx++ ) { - x[chInIdx][subFrameIdx][binIdx + ( frameSize >> 2 )] *= eqGain; + x[ch_in][subFrameIdx][binIdx + ( frameSize >> 2 )] *= eqGain; } } } @@ -1086,8 +1084,8 @@ void ivas_lssetupconversion_process_param_mc( int16_t channel_active[MAX_CICP_CHANNELS] /* i : bitmap indicating which output channels are active */ ) { - int16_t slotIdx, chOutIdx, chInIdx, bandIdx; - int16_t inChannels, outChannels; + int16_t slotIdx, ch_in, ch_out, bandIdx; + int16_t nchan_in, nchan_out; float targetEnergy[MAX_CICP_CHANNELS][CLDFB_NO_CHANNELS_MAX]; float dmxEnergy[MAX_CICP_CHANNELS][CLDFB_NO_CHANNELS_MAX]; float tmpDMXSig, dmxCoeff, tmpReal, tmpImag; @@ -1099,101 +1097,101 @@ void ivas_lssetupconversion_process_param_mc( wmops_sub_start( "LS_Renderer_Process_Param_MC" ); /* inits */ - inChannels = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; - outChannels = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; + nchan_in = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; + nchan_out = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; hLsSetUpConversion = st_ivas->hLsSetUpConversion; EQ = 0.0f; - set_s( channel_active, 0, outChannels ); + set_s( channel_active, 0, nchan_out ); /* Loop over each time slots and compute dmx for each time slot */ for ( slotIdx = 0; slotIdx < st_ivas->hParamMC->subframe_nbslots; slotIdx++ ) { /* copy buffers */ - for ( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_in; ch_in++ ) { - mvr2r( Cldfb_RealBuffer_InOut[chInIdx][slotIdx], Cldfb_RealBuffer_tmp[chInIdx], CLDFB_NO_CHANNELS_MAX ); - mvr2r( Cldfb_ImagBuffer_InOut[chInIdx][slotIdx], Cldfb_ImagBuffer_tmp[chInIdx], CLDFB_NO_CHANNELS_MAX ); + mvr2r( Cldfb_RealBuffer_InOut[ch_in][slotIdx], Cldfb_RealBuffer_tmp[ch_in], CLDFB_NO_CHANNELS_MAX ); + mvr2r( Cldfb_ImagBuffer_InOut[ch_in][slotIdx], Cldfb_ImagBuffer_tmp[ch_in], CLDFB_NO_CHANNELS_MAX ); } /* set the buffers to zero */ - for ( chOutIdx = 0; chOutIdx < outChannels; chOutIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - set_f( Cldfb_RealBuffer_InOut[chOutIdx][slotIdx], 0.0f, CLDFB_NO_CHANNELS_MAX ); - set_f( Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx], 0.0f, CLDFB_NO_CHANNELS_MAX ); + set_f( Cldfb_RealBuffer_InOut[ch_out][slotIdx], 0.0f, CLDFB_NO_CHANNELS_MAX ); + set_f( Cldfb_ImagBuffer_InOut[ch_out][slotIdx], 0.0f, CLDFB_NO_CHANNELS_MAX ); - set_f( dmxEnergy[chOutIdx], 0.0f, CLDFB_NO_CHANNELS_MAX ); - set_f( targetEnergy[chOutIdx], 0.0f, CLDFB_NO_CHANNELS_MAX ); + set_f( dmxEnergy[ch_out], 0.0f, CLDFB_NO_CHANNELS_MAX ); + set_f( targetEnergy[ch_out], 0.0f, CLDFB_NO_CHANNELS_MAX ); } /* Compute the target energy and DMX signal */ - for ( chOutIdx = 0; chOutIdx < outChannels; chOutIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - for ( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_in; ch_in++ ) { - dmxCoeff = hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx]; + dmxCoeff = hLsSetUpConversion->dmxMtx[ch_in][ch_out]; if ( dmxCoeff == 0.0f ) { continue; } else { - channel_active[chOutIdx] |= 1; + channel_active[ch_out] |= 1; for ( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - tmpDMXSig = dmxCoeff * Cldfb_RealBuffer_tmp[chInIdx][bandIdx]; - Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx] += tmpDMXSig; - targetEnergy[chOutIdx][bandIdx] += tmpDMXSig * tmpDMXSig; + tmpDMXSig = dmxCoeff * Cldfb_RealBuffer_tmp[ch_in][bandIdx]; + Cldfb_RealBuffer_InOut[ch_out][slotIdx][bandIdx] += tmpDMXSig; + targetEnergy[ch_out][bandIdx] += tmpDMXSig * tmpDMXSig; - tmpDMXSig = dmxCoeff * Cldfb_ImagBuffer_tmp[chInIdx][bandIdx]; - Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx][bandIdx] += tmpDMXSig; - targetEnergy[chOutIdx][bandIdx] += tmpDMXSig * tmpDMXSig; + tmpDMXSig = dmxCoeff * Cldfb_ImagBuffer_tmp[ch_in][bandIdx]; + Cldfb_ImagBuffer_InOut[ch_out][slotIdx][bandIdx] += tmpDMXSig; + targetEnergy[ch_out][bandIdx] += tmpDMXSig * tmpDMXSig; } } } } /* Compute the DMX energy */ - for ( chOutIdx = 0; chOutIdx < outChannels; chOutIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - if ( channel_active[chOutIdx] ) + if ( channel_active[ch_out] ) { for ( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - tmpReal = Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx]; - tmpImag = Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx][bandIdx]; + tmpReal = Cldfb_RealBuffer_InOut[ch_out][slotIdx][bandIdx]; + tmpImag = Cldfb_ImagBuffer_InOut[ch_out][slotIdx][bandIdx]; - dmxEnergy[chOutIdx][bandIdx] = tmpReal * tmpReal + tmpImag * tmpImag; + dmxEnergy[ch_out][bandIdx] = tmpReal * tmpReal + tmpImag * tmpImag; } } } /* Peform energy smoothing */ - for ( chOutIdx = 0; chOutIdx < outChannels; chOutIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - if ( channel_active[chOutIdx] ) + if ( channel_active[ch_out] ) { for ( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - targetEnergy[chOutIdx][bandIdx] = LS_OUT_CONV_SMOOTHING_FACTOR * targetEnergy[chOutIdx][bandIdx] + ( 1 - LS_OUT_CONV_SMOOTHING_FACTOR ) * hLsSetUpConversion->targetEnergyPrev[chOutIdx][bandIdx]; - dmxEnergy[chOutIdx][bandIdx] = LS_OUT_CONV_SMOOTHING_FACTOR * dmxEnergy[chOutIdx][bandIdx] + ( 1 - LS_OUT_CONV_SMOOTHING_FACTOR ) * hLsSetUpConversion->dmxEnergyPrev[chOutIdx][bandIdx]; - hLsSetUpConversion->targetEnergyPrev[chOutIdx][bandIdx] = targetEnergy[chOutIdx][bandIdx]; - hLsSetUpConversion->dmxEnergyPrev[chOutIdx][bandIdx] = dmxEnergy[chOutIdx][bandIdx]; + targetEnergy[ch_out][bandIdx] = LS_OUT_CONV_SMOOTHING_FACTOR * targetEnergy[ch_out][bandIdx] + ( 1 - LS_OUT_CONV_SMOOTHING_FACTOR ) * hLsSetUpConversion->targetEnergyPrev[ch_out][bandIdx]; + dmxEnergy[ch_out][bandIdx] = LS_OUT_CONV_SMOOTHING_FACTOR * dmxEnergy[ch_out][bandIdx] + ( 1 - LS_OUT_CONV_SMOOTHING_FACTOR ) * hLsSetUpConversion->dmxEnergyPrev[ch_out][bandIdx]; + hLsSetUpConversion->targetEnergyPrev[ch_out][bandIdx] = targetEnergy[ch_out][bandIdx]; + hLsSetUpConversion->dmxEnergyPrev[ch_out][bandIdx] = dmxEnergy[ch_out][bandIdx]; } } } /* Compute and perform equalization */ - for ( chOutIdx = 0; chOutIdx < outChannels; chOutIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - if ( channel_active[chOutIdx] ) + if ( channel_active[ch_out] ) { for ( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - ivas_lssetupconversion_computeEQFactor( &targetEnergy[chOutIdx][bandIdx], &dmxEnergy[chOutIdx][bandIdx], &EQ ); - Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx] *= EQ; - Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx][bandIdx] *= EQ; + ivas_lssetupconversion_computeEQFactor( &targetEnergy[ch_out][bandIdx], &dmxEnergy[ch_out][bandIdx], &EQ ); + Cldfb_RealBuffer_InOut[ch_out][slotIdx][bandIdx] *= EQ; + Cldfb_ImagBuffer_InOut[ch_out][slotIdx][bandIdx] *= EQ; } } } diff --git a/lib_dec/ivas_rom_dec.c b/lib_dec/ivas_rom_dec.c index 39918776e676d4c1a6ec8dd6b22aff5ef07df2c2..421ec619d34062700a5318f0ad96c55a7ec50e12 100644 --- a/lib_dec/ivas_rom_dec.c +++ b/lib_dec/ivas_rom_dec.c @@ -516,7 +516,7 @@ const int16_t sba_map_tc[8] = * LS Renderer ROM tables *----------------------------------------------------------------------------------*/ - /* All matrices are stored with dimensions nchan_in x nchan_out */ + /* All matrices are stored with dimensions nchan_inp x nchan_out */ /* Downmix matrices */ const float ls_conversion_cicpX_mono[12][1] = { diff --git a/lib_dec/ivas_rotation.c b/lib_dec/ivas_rotation.c index 77809d8270e9e2b30a50800b5052fc2b696d827b..9e6cbca8c12cb240a85612e74832372ab0519d91 100644 --- a/lib_dec/ivas_rotation.c +++ b/lib_dec/ivas_rotation.c @@ -559,7 +559,7 @@ void rotateFrame_shd_cldfb( float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: unrotated HOA3 signal buffer in cldfb domain real part */ float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: unrotated HOA3 signal buffer in cldfb domain imag part */ float Rmat[3][3], /* i : real-space rotation matrix */ - const int16_t nInChannels, /* i : number of channels */ + const int16_t nchan_inp, /* i : number of channels */ const int16_t shd_rot_max_order /* i : split-order rotation method */ ) { @@ -571,7 +571,7 @@ void rotateFrame_shd_cldfb( float realRot[2 * HEADROT_ORDER + 1], imagRot[2 * HEADROT_ORDER + 1]; float SHrotmat[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; - assert( nInChannels == HEADROT_SHMAT_DIM && "Number of channels must be 16!" ); + assert( nchan_inp == HEADROT_SHMAT_DIM && "Number of channels must be 16!" ); /* initialize rotation matrices with zeros */ for ( i = 0; i < HEADROT_SHMAT_DIM; i++ ) @@ -618,18 +618,18 @@ void rotateFrame_shd_cldfb( } /* unoptimized code for reference (full matrix multiplication) - for (n = 0; n < nInChannels; n++) + for (n = 0; n < nchan_inp; n++) { realRot[n] = 0.f; imagRot[n] = 0.f; - for (m = 0; m < nInChannels; m++) + for (m = 0; m < nchan_inp; m++) { realRot[n] += SHrotmat[n][m] * Cldfb_RealBuffer[m][i][iBand]; imagRot[n] += SHrotmat[n][m] * Cldfb_ImagBuffer[m][i][iBand]; } } - for (n = 0; n < nInChannels; n++) + for (n = 0; n < nchan_inp; n++) { Cldfb_RealBuffer[n][i][iBand] = realRot[n]; Cldfb_ImagBuffer[n][i][iBand] = imagRot[n]; @@ -666,14 +666,13 @@ void rotateFrame_sd_cldfb( float imagRot[MAX_CICP_CHANNELS - 1][MAX_PARAM_SPATIAL_SUBFRAMES * CLDFB_NO_CHANNELS_MAX]; float *p_realRot, *p_imagRot; float *p_real, *p_imag; - int16_t nInChannels; - int16_t isPlanar; + int16_t nchan_inp, isPlanar; wmops_sub_start( "rotateFrame_sd_cldfb" ); - nInChannels = hOutputSetup->nchan_out_woLFE; + nchan_inp = hOutputSetup->nchan_out_woLFE; isPlanar = 1; - for ( n = 0; n < nInChannels; n++ ) + for ( n = 0; n < nchan_inp; n++ ) { if ( hOutputSetup->ls_elevation[n] != 0 ) { @@ -686,7 +685,7 @@ void rotateFrame_sd_cldfb( QuatToRotMat( hHeadTrackData->Quaternions[hHeadTrackData->num_quaternions++], Rmat ); /* rotation of Euler angles */ - for ( n = 0; n < nInChannels; n++ ) + for ( n = 0; n < nchan_inp; n++ ) { rotateAziEle( hOutputSetup->ls_azimuth[n], hOutputSetup->ls_elevation[n], &azimuth, &elevation, Rmat, isPlanar ); if ( hEFAPdata != NULL && ( hOutputSetup->ls_azimuth[n] != azimuth || hOutputSetup->ls_elevation[n] != elevation ) ) @@ -695,17 +694,17 @@ void rotateFrame_sd_cldfb( } else { - set_zero( gains[n], nInChannels ); + set_zero( gains[n], nchan_inp ); gains[n][n] = 1.0f; } } /* Apply panning gains by mtx multiplication*/ - for ( n = 0; n < nInChannels; n++ ) + for ( n = 0; n < nchan_inp; n++ ) { set_zero( realRot[n], MAX_PARAM_SPATIAL_SUBFRAMES * nb_band ); set_zero( imagRot[n], MAX_PARAM_SPATIAL_SUBFRAMES * nb_band ); - for ( m = 0; m < nInChannels; m++ ) + for ( m = 0; m < nchan_inp; m++ ) { g1 = gains[m][n]; p_realRot = realRot[n]; @@ -728,7 +727,7 @@ void rotateFrame_sd_cldfb( } } - for ( n = 0; n < nInChannels; n++ ) + for ( n = 0; n < nchan_inp; n++ ) { p_realRot = realRot[n]; p_imagRot = imagRot[n]; diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 2180cb79a31b039e4ee6bde871dc6068b9fa5a86..6e493b7b51f669c5d35532ab7fe2b72a04a07f40 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -37,6 +37,9 @@ #include "ivas_cnst.h" #include "prot.h" #include "ivas_prot.h" +#ifdef SBA_BITRATE_SWITCHING +#include "ivas_rom_com.h" +#endif #include "ivas_rom_dec.h" #ifdef DEBUGGING #include "debug.h" @@ -77,7 +80,7 @@ void ivas_mc2sba( assert( ( sba_order <= 3 ) && "Only order up to 3 is supported!" ); /* Init*/ - sba_num_chans = ( sba_order + 1 ) * ( sba_order + 1 ); + sba_num_chans = ivas_sba_get_nchan( sba_order, 0 ); for ( j = 0; j < sba_num_chans; j++ ) { set_zero( buffer_tmp[j], output_frame ); @@ -297,7 +300,7 @@ void ivas_ism2sba( assert( hIsmRendererData != NULL && "hIsmRendererData not allocated!" ); /* Init*/ - sba_num_chans = ( sba_order + 1 ) * ( sba_order + 1 ); + sba_num_chans = ivas_sba_get_nchan( sba_order, 0 ); for ( j = 0; j < sba_num_chans; j++ ) { set_zero( buffer_tmp[j], output_frame ); @@ -348,31 +351,47 @@ ivas_error ivas_sba_dec_reconfigure( ) { #ifdef CORECODER_BITRATE_SWITCHING - int16_t i; - int16_t nchan_transport, nchan_transport_old; - int16_t nSCE_old, nCPE_old, nchan_hp20_old; + int16_t i, nSCE_old, nCPE_old, nchan_transport_old, nchan_hp20_old; #else int16_t i, n, sce_id, cpe_id; int16_t nchan_transport, nchan_transport_old; int16_t nSCE_old, nCPE_old; +#endif +#ifdef SBA_BITRATE_SWITCHING + int16_t output_frame; + SBA_MODE sba_mode_old; #endif AUDIO_CONFIG intern_config_old; int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses, numCldfbSyntheses_old; int16_t sba_dirac_stereo_flag_old; int32_t ivas_total_brate, last_ivas_total_brate; + DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; error = IVAS_ERR_OK; - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; + hDecoderConfig = st_ivas->hDecoderConfig; + ivas_total_brate = hDecoderConfig->ivas_total_brate; + last_ivas_total_brate = hDecoderConfig->last_ivas_total_brate; + +#ifdef SBA_BITRATE_SWITCHING + output_frame = (int16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); +#endif /*-----------------------------------------------------------------* - * Allocate, initalize, and configure SBA and rendering handles + * Set SBA high-level parameters + * Save old SBA high-level parameters *-----------------------------------------------------------------*/ +#ifdef SBA_BITRATE_SWITCHING + sba_mode_old = ivas_sba_mode_select( last_ivas_total_brate ); + + st_ivas->sba_mode = sba_mode_old; +#endif ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); +#ifndef SBA_BITRATE_SWITCHING numCldfbAnalyses = 0; +#endif #ifdef CORECODER_BITRATE_SWITCHING nchan_hp20_old = getNumChanSynthesis( st_ivas ); @@ -385,9 +404,176 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); - ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); +#ifdef SBA_BITRATE_SWITCHING + st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); + + + /*-----------------------------------------------------------------* + * Allocate, initalize, and configure SBA handles + *-----------------------------------------------------------------*/ + + if ( st_ivas->sba_mode != SBA_MODE_SPAR ) + { + ivas_spar_dec_close( st_ivas->hSpar, hDecoderConfig->output_Fs ); + st_ivas->hSpar = NULL; + + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) + { + return error; + } + + st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); + } + else + { + int16_t sba_order_internal, nchan_internal; + DIRAC_DEC_HANDLE hDirAC = st_ivas->hDirAC; + SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; + + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + nchan_internal = ivas_sba_get_nchan_metadata( sba_order_internal ); + + if ( hSpar != NULL && nchan_transport_old != ivas_get_sba_num_TCs( ivas_total_brate, sba_order_internal ) ) + { + + // VE: dirty patch -> reconfiguration of SPAR modules should be used instead !! + IVAS_FB_CFG *fb_cfg; + int16_t active_w_mixing; - st_ivas->nchan_transport = nchan_transport; + /* MD handle */ + ivas_spar_md_dec_close( &hSpar->hMdDec ); + + if ( ( error = ivas_spar_md_dec_open( &hSpar->hMdDec, st_ivas->hDecoderConfig, nchan_internal +#ifdef SBA_HOA_HBR_IMPROV + , + sba_order_internal +#endif + ) ) != IVAS_ERR_OK ) + { + return error; + } + hSpar->hMdDec->td_decorr_flag = 1; + hSpar->hMdDec->table_idx = -1; + + /* TD decorr. */ + ivas_spar_td_decorr_dec_close( &hSpar->hTdDecorr ); + + if ( ( error = ivas_spar_td_decorr_dec_open( &hSpar->hTdDecorr, hDecoderConfig->output_Fs, nchan_internal, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* FB mixer handle */ + ivas_FB_mixer_close( &hSpar->hFbMixer, hDecoderConfig->output_Fs ); + + /* set FB config. */ + active_w_mixing = -1; + if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_SPAR, nchan_internal, nchan_internal, active_w_mixing, hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + fb_cfg->pcm_offset = NS2SA( hDecoderConfig->output_Fs, DELAY_FB_1_NS + IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ); + fb_cfg->remix_order = remix_order_set[hSpar->hMdDec->spar_md_cfg.remix_unmix_order]; + + /* FB mixer handle */ + if ( ( error = ivas_FB_mixer_open( &hSpar->hFbMixer, hDecoderConfig->output_Fs, fb_cfg ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* mixer_mat intitialization */ + for ( i = 0; i < nchan_internal; i++ ) + { + for ( int16_t j = 0; j < nchan_internal; j++ ) + { + for ( int16_t b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + { + hSpar->hMdDec->mixer_mat[i][j][b] = 0.0f; + for ( int16_t i_ts = 0; i_ts < ( MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); i_ts++ ) + { + hSpar->hMdDec->mixer_mat_prev[i_ts][i][j][b] = 0.0f; + } + } + } + } + hSpar->i_subframe = 0; + } + + + /* PCA handle */ + if ( hSpar != NULL ) + { + if ( st_ivas->hDecoderConfig->ivas_total_brate == PCA_BRATE && sba_order_internal == 1 ) + { + if ( ( hSpar->hPCA = (PCA_DEC_STATE *) count_malloc( sizeof( PCA_DEC_STATE ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PCA decoder" ); + } + + ivas_pca_dec_init( hSpar->hPCA ); + } + else if ( hSpar->hPCA != NULL ) + { + count_free( st_ivas->hSpar->hPCA ); + hSpar->hPCA = NULL; + } + } + + if ( hSpar == NULL && st_ivas->sba_mode == SBA_MODE_SPAR ) + { + if ( ( error = ivas_spar_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + hSpar = st_ivas->hSpar; + } + + st_ivas->sba_dirac_stereo_flag = 0; + + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); + + if ( hDirAC == NULL && st_ivas->sba_mode == SBA_MODE_DIRAC ) + { + if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + hDirAC = st_ivas->hDirAC; + } + + if ( hDirAC != NULL ) + { + ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE_MODE ); + + mvs2s( hDirAC->dirac_to_spar_md_bands, hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); + hSpar->enc_param_start_band = hDirAC->hConfig->enc_param_start_band; + } + + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( st_ivas->nchan_transport == 1 ) + { + st_ivas->element_mode_init = IVAS_SCE; + } + else + { + st_ivas->element_mode_init = IVAS_CPE_MDCT; + } +#else + + ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); +#endif + + /*-----------------------------------------------------------------* + * Renderer selection + *-----------------------------------------------------------------*/ /* renderer might have changed */ intern_config_old = st_ivas->intern_config; @@ -399,9 +585,103 @@ ivas_error ivas_sba_dec_reconfigure( ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); } +#ifdef SBA_BITRATE_SWITCHING + /*-------------------------------------------------------------------* + * Reallocate and initialize binaural rendering handles + *--------------------------------------------------------------------*/ + + if ( st_ivas->hBinRenderer == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) ) + { + /* open fastconv binaural renderer */ + if ( ( error = ivas_binRenderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->hBinRenderer != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV && st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM ) ) + { + ivas_binRenderer_close( &st_ivas->hBinRenderer ); + } + + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + { + /* open parametric binaural renderer */ + if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->hDiracDecBin != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) ) + { + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); + } +#endif + + /*-----------------------------------------------------------------* + * hDirAC decoder handle configuration + *-----------------------------------------------------------------*/ + +#ifdef SBA_BITRATE_SWITCHING + if ( sba_mode_old != st_ivas->sba_mode ) // VE: TBD - possibly merge with the 'else if' branch below + { + if ( st_ivas->hDirAC != NULL ) + { + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE_MODE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && + ( last_ivas_total_brate > IVAS_SID_5k2 || st_ivas->nchan_transport != nchan_transport_old ) ) + { + if ( st_ivas->hDirAC != NULL ) + { + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else if ( st_ivas->renderer_type == RENDERER_DISABLE || ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->sba_mode != SBA_MODE_SPAR ) ) + { + if ( st_ivas->hDirAC != NULL ) + { + ivas_dirac_dec_close( st_ivas->hDirAC ); + st_ivas->hDirAC = NULL; + } + + if ( st_ivas->hVBAPdata != NULL ) + { + vbap_free_data( &( st_ivas->hVBAPdata ) ); + } + } + + if ( st_ivas->hDirAC != NULL && st_ivas->sba_mode == SBA_MODE_SPAR ) + { + mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); + st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + } + +#else + if ( st_ivas->sba_mode != SBA_MODE_SPAR ) { - st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); + st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) { @@ -413,7 +693,7 @@ ivas_error ivas_sba_dec_reconfigure( int16_t sba_order_internal; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); - ivas_spar_config( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); + ivas_spar_config( hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) { @@ -421,7 +701,7 @@ ivas_error ivas_sba_dec_reconfigure( } } - if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && ( last_ivas_total_brate > IVAS_SID_5k2 || nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) + if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && ( last_ivas_total_brate > IVAS_SID_5k2 || st_ivas->nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) { if ( st_ivas->hDirAC != NULL ) { @@ -451,6 +731,7 @@ ivas_error ivas_sba_dec_reconfigure( vbap_free_data( &( st_ivas->hVBAPdata ) ); } } +#endif /*-----------------------------------------------------------------* * Allocate, initalize, and configure SCE/CPE/MCT handles @@ -718,13 +999,24 @@ ivas_error ivas_sba_dec_reconfigure( /* special case, if there was one transport channel in the previous frame and more than one in the current frame, remove the second CLDFB here, it was for CNA/CNG */ - if ( nchan_transport_old == 1 && numCldfbAnalyses_old == 2 && nchan_transport > 1 ) + if ( nchan_transport_old == 1 && numCldfbAnalyses_old == 2 && st_ivas->nchan_transport > 1 ) { deleteCldfb( &( st_ivas->cldfbAnaDec[1] ) ); st_ivas->cldfbAnaDec[1] = NULL; numCldfbAnalyses_old--; } +#ifdef SBA_BITRATE_SWITCHING + /* resample CLDFB analysis instances */ + for ( i = 0; i < min( numCldfbAnalyses, numCldfbAnalyses_old ); i++ ) + { + if ( ( st_ivas->cldfbAnaDec[i]->no_channels * st_ivas->cldfbAnaDec[i]->no_col ) != output_frame ) + { + resampleCldfb( st_ivas->cldfbAnaDec[i], hDecoderConfig->output_Fs ); + } + } +#endif + /* Analysis*/ if ( numCldfbAnalyses_old > numCldfbAnalyses ) { @@ -740,7 +1032,7 @@ ivas_error ivas_sba_dec_reconfigure( /* create additional CLDFB synthesis instances */ for ( i = numCldfbAnalyses_old; i < numCldfbAnalyses; i++ ) { - if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } @@ -762,13 +1054,21 @@ ivas_error ivas_sba_dec_reconfigure( /* create additional CLDFB synthesis instances */ for ( i = numCldfbSyntheses_old; i < numCldfbSyntheses; i++ ) { - if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } } } +#ifdef SBA_BITRATE_SWITCHING + /* CLDFB Interpolation weights */ + if ( st_ivas->sba_mode == SBA_MODE_SPAR && ( numCldfbAnalyses_old != numCldfbAnalyses || numCldfbSyntheses_old != numCldfbSyntheses || nchan_transport_old != st_ivas->nchan_transport ) ) + { + ivas_spar_get_cldfb_gains( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig ); + } +#endif + #ifndef CORECODER_BITRATE_SWITCHING /*-----------------------------------------------------------------* * Set CNA/CNG flags @@ -813,6 +1113,7 @@ ivas_error ivas_sba_dec_reconfigure( } #endif +#ifndef SBA_BITRATE_SWITCHING /*-------------------------------------------------------------------* * Reallocate and initialize binaural rendering handles *--------------------------------------------------------------------*/ @@ -842,6 +1143,7 @@ ivas_error ivas_sba_dec_reconfigure( { ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); } +#endif return error; } diff --git a/lib_dec/ivas_sba_rendering.c b/lib_dec/ivas_sba_rendering.c index 92e50de5359911616c7ecc66599f03666574f412..5fbfa24e453e0ba0c482069aa03c87e19c08499e 100644 --- a/lib_dec/ivas_sba_rendering.c +++ b/lib_dec/ivas_sba_rendering.c @@ -47,7 +47,7 @@ * Local function prototypes *-----------------------------------------------------------------------*/ -static void ivas_sba_mtx_mult( float output_f[][L_FRAME48k], const int16_t output_frame, const int16_t nchan_in, const IVAS_OUTPUT_SETUP output_setup, const float *mtx_hoa_decoder ); +static void ivas_sba_mtx_mult( float output_f[][L_FRAME48k], const int16_t output_frame, const int16_t nchan_inp, const IVAS_OUTPUT_SETUP output_setup, const float *mtx_hoa_decoder ); /*-------------------------------------------------------------------* @@ -57,9 +57,9 @@ static void ivas_sba_mtx_mult( float output_f[][L_FRAME48k], const int16_t outpu *-------------------------------------------------------------------*/ ivas_error ivas_sba_linear_renderer( - float output_f[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ + float output[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ const int16_t output_frame, /* i : output frame length per channel */ - const int16_t nchan_in, /* i : number of input ambisonics channels */ + const int16_t nchan_inp, /* i : number of input ambisonics channels */ const AUDIO_CONFIG output_config, /* i : output audio configuration */ const IVAS_OUTPUT_SETUP output_setup, /* i : output format setup */ const float hoa_dec_mtx[] /* i : HOA decoding mtx */ @@ -73,13 +73,13 @@ ivas_error ivas_sba_linear_renderer( error = IVAS_ERR_OK; /* Number of channels of HOA depends of transport format which is mixed order xH1V*/ - nchan_hoa = nchan_in; + nchan_hoa = nchan_inp; - if ( nchan_in == 6 ) /*2H1V*/ + if ( nchan_inp == 6 ) /*2H1V*/ { nchan_hoa = 9; } - else if ( nchan_in == 8 ) /*3H1V*/ + else if ( nchan_inp == 8 ) /*3H1V*/ { nchan_hoa = 16; } @@ -88,27 +88,27 @@ ivas_error ivas_sba_linear_renderer( { case AUDIO_CONFIG_MONO: /* If stereo DMX, MONO = W = Cardioids L + R*/ - if ( nchan_in == 2 ) + if ( nchan_inp == 2 ) { for ( i = 0; i < output_frame; i++ ) { - output_f[0][i] += output_f[1][i]; + output[0][i] += output[1][i]; } } /* else: do nothing, MONO = W*/ break; case AUDIO_CONFIG_STEREO: - assert( ( nchan_in >= 2 ) && "Number of input channels must be at least 2 (for W and Y)!\n" ); + assert( ( nchan_inp >= 2 ) && "Number of input channels must be at least 2 (for W and Y)!\n" ); /* Compute L and R cardioids from SB format except if stereo DMX is transmitted already in this format*/ - if ( nchan_in > 2 ) + if ( nchan_inp > 2 ) { /*Build L/R cardioids*/ for ( i = 0; i < output_frame; i++ ) { - dmx_l = 0.5f * ( output_f[0][i] + output_f[1][i] ); /* cardioid_left = 0.5(W + Y) */ - output_f[1][i] = 0.5f * ( output_f[0][i] - output_f[1][i] ); /* cardioid_right = 0.5(W - Y) */ - output_f[0][i] = dmx_l; + dmx_l = 0.5f * ( output[0][i] + output[1][i] ); /* cardioid_left = 0.5(W + Y) */ + output[1][i] = 0.5f * ( output[0][i] - output[1][i] ); /* cardioid_right = 0.5(W - Y) */ + output[0][i] = dmx_l; } } break; @@ -118,14 +118,14 @@ ivas_error ivas_sba_linear_renderer( case AUDIO_CONFIG_5_1_4: case AUDIO_CONFIG_7_1_4: case AUDIO_CONFIG_LS_CUSTOM: - ivas_sba_mtx_mult( output_f, output_frame, nchan_hoa, output_setup, hoa_dec_mtx ); + ivas_sba_mtx_mult( output, output_frame, nchan_hoa, output_setup, hoa_dec_mtx ); break; case AUDIO_CONFIG_FOA: /* Ambisonics output, order: 1 */ case AUDIO_CONFIG_HOA2: /* Ambisonics output, order: 2 */ case AUDIO_CONFIG_HOA3: /* Ambisonics output, order: 3 */ for ( i = nchan_hoa; i < output_setup.nchan_out_woLFE; i++ ) { - set_zero( output_f[i], output_frame ); + set_zero( output[i], output_frame ); } break; default: @@ -145,7 +145,7 @@ ivas_error ivas_sba_linear_renderer( static void ivas_sba_mtx_mult( float output_f[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ const int16_t output_frame, /* i : output frame length per channel */ - const int16_t nchan_in, /* i : Number of ambisonic channels */ + const int16_t nchan_inp, /* i : Number of ambisonic channels */ const IVAS_OUTPUT_SETUP output_setup, /* i : Output configuration */ const float *mtx_hoa_decoder /* i : HOA decoding mtx */ ) @@ -155,14 +155,14 @@ static void ivas_sba_mtx_mult( float input_f[16]; const float *hoa_decoder; - assert( ( nchan_in >= FOA_CHANNELS ) && "Number of input channels must be at least 4 (FOA)!\n" ); + assert( ( nchan_inp >= FOA_CHANNELS ) && "Number of input channels must be at least 4 (FOA)!\n" ); for ( i = 0; i < output_frame; i++ ) { /* init*/ idx_lfe = 0; hoa_decoder = &mtx_hoa_decoder[0]; - for ( k = 0; k < nchan_in; k++ ) + for ( k = 0; k < nchan_inp; k++ ) { input_f[k] = output_f[k][i]; } @@ -183,7 +183,7 @@ static void ivas_sba_mtx_mult( { /*HOA decoding*/ output_f[ch_idx][i] = input_f[0] * hoa_decoder[0]; - for ( k = 1; k < nchan_in; k++ ) + for ( k = 1; k < nchan_inp; k++ ) { output_f[ch_idx][i] += input_f[k] * hoa_decoder[k]; } @@ -208,12 +208,12 @@ void ivas_sba_upmixer_renderer( const int16_t output_frame /* i : output frame length */ ) { - int16_t i, nchan_internal; + int16_t i, nchan; float temp; wmops_sub_start( "ivas_sba_upmixer_renderer" ); - nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order ); + nchan = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order ); if ( st_ivas->nchan_transport >= 3 ) { @@ -227,7 +227,7 @@ void ivas_sba_upmixer_renderer( } /* Upmixer + Renderer */ - ivas_spar_dec_upmixer( st_ivas, output, nchan_internal, output_frame ); + ivas_spar_dec_upmixer( st_ivas, output, nchan, output_frame ); if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC ) { @@ -256,7 +256,7 @@ void ivas_sba_mix_matrix_determiner( { int16_t i, ch; float temp; - int16_t num_bands_out, nchan_transport, nchan_out; + int16_t num_bands_out, nchan_transport; /* Convert numeric range */ for ( ch = 0; ch < nchan_remapped; ch++ ) @@ -281,11 +281,10 @@ void ivas_sba_mix_matrix_determiner( /* AGC */ nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; - nchan_out = nchan_transport; ivas_agc_dec_process( hSpar->hAgcDec, output, output, nchan_transport, output_frame ); /* Convert numeric range back */ - for ( ch = 0; ch < nchan_out; ch++ ) + for ( ch = 0; ch < nchan_transport; ch++ ) { for ( i = 0; i < output_frame; i++ ) { @@ -320,9 +319,9 @@ void ivas_sba_prototype_renderer( DECODER_CONFIG_HANDLE hDecoderConfig; int16_t num_spar_bands, spar_band; int16_t b, ts; - int16_t num_cldfb_bands, numch_in, numch_out; + int16_t num_cldfb_bands, nchan_inp, nchan_out; int16_t cldfb_band; - int16_t out_ch, in_ch; + int16_t ch_out, ch_in; int16_t firstSlot, slotEnd, firstInCh, inChEnd, firstOutCh, outChEnd; int16_t sf_idx; @@ -336,8 +335,8 @@ void ivas_sba_prototype_renderer( slotEnd = ( firstSubframe + nSubframes ) * ( CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES ); num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; - numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; - numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + nchan_inp = hSpar->hFbMixer->fb_cfg->nchan_inp; + nchan_out = hSpar->hFbMixer->fb_cfg->nchan_out; if ( st_ivas->nchan_transport == 1 ) { @@ -358,7 +357,7 @@ void ivas_sba_prototype_renderer( for ( ts = firstSlot; ts < slotEnd; ts++ ) { /* determine SPAR parameters for this time slot */ - ivas_spar_get_parameters( hSpar, hDecoderConfig, ts, numch_out, numch_in, num_spar_bands, mixer_mat ); + ivas_spar_get_parameters( hSpar, hDecoderConfig, ts, nchan_out, nchan_inp, num_spar_bands, mixer_mat ); for ( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ ) { @@ -367,17 +366,17 @@ void ivas_sba_prototype_renderer( float cldfb_par; ivas_fb_bin_to_band_data_t *bin2band = &hSpar->hFbMixer->pFb->fb_bin_to_band; - for ( out_ch = firstOutCh; out_ch < outChEnd; out_ch++ ) + for ( ch_out = firstOutCh; ch_out < outChEnd; ch_out++ ) { - out_re[out_ch] = 0.0f; - out_im[out_ch] = 0.0f; + out_re[ch_out] = 0.0f; + out_im[ch_out] = 0.0f; - for ( in_ch = firstInCh; in_ch < inChEnd; in_ch++ ) + for ( ch_in = firstInCh; ch_in < inChEnd; ch_in++ ) { if ( cldfb_band < CLDFB_PAR_WEIGHT_START_BAND ) /* tuning parameter, depends on how much SPAR Filters overlap for the CLDFB bands */ { spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; - cldfb_par = mixer_mat[out_ch][in_ch][spar_band]; + cldfb_par = mixer_mat[ch_out][ch_in][spar_band]; } else { @@ -385,20 +384,20 @@ void ivas_sba_prototype_renderer( for ( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ - cldfb_par += mixer_mat[out_ch][in_ch][spar_band] * bin2band->pp_cldfb_weights_per_spar_band[cldfb_band][spar_band]; + cldfb_par += mixer_mat[ch_out][ch_in][spar_band] * bin2band->pp_cldfb_weights_per_spar_band[cldfb_band][spar_band]; } } - out_re[out_ch] += inRe[in_ch][ts][cldfb_band] * cldfb_par; - out_im[out_ch] += inIm[in_ch][ts][cldfb_band] * cldfb_par; + out_re[ch_out] += inRe[ch_in][ts][cldfb_band] * cldfb_par; + out_im[ch_out] += inIm[ch_in][ts][cldfb_band] * cldfb_par; } } /*update CLDFB data with the parameter-modified data*/ - for ( out_ch = firstOutCh; out_ch < outChEnd; out_ch++ ) + for ( ch_out = firstOutCh; ch_out < outChEnd; ch_out++ ) { - inRe[out_ch][ts][cldfb_band] = out_re[out_ch]; - inIm[out_ch][ts][cldfb_band] = out_im[out_ch]; + inRe[ch_out][ts][cldfb_band] = out_re[ch_out]; + inIm[ch_out][ts][cldfb_band] = out_im[ch_out]; } } @@ -413,13 +412,13 @@ void ivas_sba_prototype_renderer( mvr2r( hSpar->hMdDec->mixer_mat_prev[3][0][0], hSpar->hMdDec->mixer_mat_prev[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); mvr2r( hSpar->hMdDec->mixer_mat_prev[4][0][0], hSpar->hMdDec->mixer_mat_prev[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - for ( out_ch = 0; out_ch < numch_out; out_ch++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - for ( in_ch = 0; in_ch < numch_in; in_ch++ ) + for ( ch_in = 0; ch_in < nchan_inp; ch_in++ ) { for ( b = 0; b < num_spar_bands; b++ ) { - hSpar->hMdDec->mixer_mat_prev[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][b + sf_idx * IVAS_MAX_NUM_BANDS]; + hSpar->hMdDec->mixer_mat_prev[4][ch_out][ch_in][b] = hSpar->hMdDec->mixer_mat[ch_out][ch_in][b + sf_idx * IVAS_MAX_NUM_BANDS]; } } } diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index 97ee2e83369b3a6c061237d40808e638f23bb288..3956325ff5ce6fce7fa990f92de32a2ff4e40863 100644 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -276,7 +276,7 @@ ivas_error ivas_sce_dec( dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "element_brate", 0, sce_id, DEC ) ); dbgwrite( &st->element_mode, sizeof( int16_t ), 1, output_frame, fname( debug_dir, "element_mode", 0, sce_id, DEC ) ); - dbgwrite( output, sizeof( float ), output_frame, 1, fname( debug_dir, "output.sce", 0, sce_id, DEC ) ); + dbgwrite( output[0], sizeof( float ), output_frame, 1, fname( debug_dir, "output.sce", 0, sce_id, DEC ) ); tmpF = 0; dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.cpe", 0, sce_id, DEC ) ); dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.mct", 0, sce_id, DEC ) ); diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 7a0590e6c1d1f9e9d083647ea7ab0ce8732b52e3..9e5dc2ec4a8da3349464eb0972a98df3558f2e3d 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -50,7 +50,7 @@ * Local function prototypes *--------------------------------------------------------------------*/ -static void ivas_spar_dec_MD( Decoder_Struct *st_ivas, Decoder_State *st0 ); +static ivas_error ivas_spar_dec_MD( Decoder_Struct *st_ivas, Decoder_State *st0 ); /*------------------------------------------------------------------------- @@ -65,14 +65,14 @@ ivas_error ivas_spar_dec_open( { SPAR_DEC_HANDLE hSpar; ivas_error error; - int16_t sba_order_internal, num_channels_internal; + int16_t sba_order_internal, nchan_internal; IVAS_FB_CFG *fb_cfg; int16_t i, j, b, active_w_mixing; int32_t output_Fs; error = IVAS_ERR_OK; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); - num_channels_internal = ivas_sba_get_nchan_metadata( sba_order_internal ); + nchan_internal = ivas_sba_get_nchan_metadata( sba_order_internal ); /* SPAR decoder handle */ if ( ( hSpar = (SPAR_DEC_HANDLE) count_malloc( sizeof( SPAR_DEC_DATA ) ) ) == NULL ) @@ -83,13 +83,13 @@ ivas_error ivas_spar_dec_open( output_Fs = st_ivas->hDecoderConfig->output_Fs; /* TD decorr. */ - if ( ( error = ivas_spar_td_decorr_dec_open( &hSpar->hTdDecorr, output_Fs, num_channels_internal, 1 ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_td_decorr_dec_open( &hSpar->hTdDecorr, output_Fs, nchan_internal, 1 ) ) != IVAS_ERR_OK ) { return error; } /* MD handle */ - if ( ( error = ivas_spar_md_dec_open( &hSpar->hMdDec, st_ivas->hDecoderConfig, num_channels_internal + if ( ( error = ivas_spar_md_dec_open( &hSpar->hMdDec, st_ivas->hDecoderConfig, nchan_internal #ifdef SBA_HOA_HBR_IMPROV , sba_order_internal @@ -103,7 +103,7 @@ ivas_error ivas_spar_dec_open( /* set FB config. */ active_w_mixing = -1; - if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_SPAR, num_channels_internal, num_channels_internal, active_w_mixing, output_Fs ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_SPAR, nchan_internal, nchan_internal, active_w_mixing, output_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -135,9 +135,9 @@ ivas_error ivas_spar_dec_open( } /* mixer_mat intitialization */ - for ( i = 0; i < num_channels_internal; i++ ) + for ( i = 0; i < nchan_internal; i++ ) { - for ( j = 0; j < num_channels_internal; j++ ) + for ( j = 0; j < nchan_internal; j++ ) { for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) { @@ -263,7 +263,7 @@ ivas_error ivas_spar_dec( st0->bits_frame = min( MAX_BITS_METADATA, last_bit_pos + 1 ); st0->total_brate = hDecoderConfig->ivas_total_brate; /* to avoid BER detect */ - ivas_spar_dec_MD( st_ivas, st0 ); + error = ivas_spar_dec_MD( st_ivas, st0 ); *nb_bits_read = st0->next_bit_pos + nb_bits_read_orig; st0->bit_stream = bit_stream_orig; @@ -622,18 +622,23 @@ int16_t ivas_is_res_channel( * IVAS SPAR MD decoder *-------------------------------------------------------------------*/ -static void ivas_spar_dec_MD( +static ivas_error ivas_spar_dec_MD( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ Decoder_State *st0 /* i/o: decoder state structure - for bitstream handling*/ ) { - int16_t num_channels, table_idx, num_bands_out, bfi, sba_order; + int16_t nchan, table_idx, num_bands_out, bfi, sba_order; int32_t ivas_total_brate; - DECODER_CONFIG_HANDLE hDecoderConfig = st_ivas->hDecoderConfig; - SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; + DECODER_CONFIG_HANDLE hDecoderConfig; + SPAR_DEC_HANDLE hSpar; + ivas_error error; wmops_sub_start( "ivas_spar_dec_MD" ); + hDecoderConfig = st_ivas->hDecoderConfig; + hSpar = st_ivas->hSpar; + error = IVAS_ERR_OK; + /*---------------------------------------------------------------------* * Initialization *---------------------------------------------------------------------*/ @@ -641,7 +646,7 @@ static void ivas_spar_dec_MD( sba_order = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); bfi = st_ivas->bfi; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - num_channels = ivas_sba_get_nchan_metadata( sba_order ); + nchan = ivas_sba_get_nchan_metadata( sba_order ); num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; if ( ivas_total_brate > FRAME_NO_DATA && !bfi ) @@ -666,7 +671,14 @@ static void ivas_spar_dec_MD( hSpar->hMdDec->table_idx = table_idx; hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[table_idx].td_ducking; - ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, num_channels ); +#if ( defined SBA_BITRATE_SWITCHING && defined SBA_HOA_HBR_IMPROV ) + if ( ( error = ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, sba_order, nchan ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, nchan ) ) != IVAS_ERR_OK ) +#endif + { + return error; + } } } @@ -684,6 +696,13 @@ static void ivas_spar_dec_MD( { ivas_pca_read_bits( st0, hSpar->hPCA ); } +#ifdef SBA_BITRATE_SWITCHING + else if ( ivas_total_brate == PCA_BRATE && sba_order == 1 ) + { + /* skip PCA bypass bit */ + get_next_indice( st0, 1 ); + } +#endif /*---------------------------------------------------------------------* * Read AGC bits @@ -720,7 +739,7 @@ static void ivas_spar_dec_MD( } wmops_sub_end(); - return; + return error; } @@ -791,12 +810,12 @@ void ivas_spar_get_parameters( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ const int16_t ts, - const int16_t num_ch_out, - const int16_t num_ch_in, + const int16_t nchan_out, + const int16_t nchan_inp, const int16_t num_spar_bands, - float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] ) + float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] ) { - int16_t spar_band, out_ch, in_ch; + int16_t spar_band, ch_out, ch_in; float weight, weight_20ms; int16_t ts0, ts1, split_band; @@ -810,30 +829,30 @@ void ivas_spar_get_parameters( for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) { - for ( out_ch = 0; out_ch < num_ch_out; out_ch++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - for ( in_ch = 0; in_ch < num_ch_in; in_ch++ ) + for ( ch_in = 0; ch_in < nchan_inp; ch_in++ ) { if ( split_band < IVAS_MAX_NUM_BANDS /* 20ms cross-fade for Transport channels in all frequency bands */ - && ( 0 == ivas_is_res_channel( out_ch, hSpar->hMdDec->spar_md_cfg.nchan_transport ) ) /* sub-frame processing for missing channels in all frequency bands*/ + && ( 0 == ivas_is_res_channel( ch_out, hSpar->hMdDec->spar_md_cfg.nchan_transport ) ) /* sub-frame processing for missing channels in all frequency bands*/ ) { if ( hSpar->i_subframe > 3 ) { - par_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight ) * hSpar->hMdDec->mixer_mat_prev[ts0][out_ch][in_ch][spar_band] + - weight * hSpar->hMdDec->mixer_mat_prev[ts1][out_ch][in_ch][spar_band]; + mixer_mat[ch_out][ch_in][spar_band] = ( 1.0f - weight ) * hSpar->hMdDec->mixer_mat_prev[ts0][ch_out][ch_in][spar_band] + + weight * hSpar->hMdDec->mixer_mat_prev[ts1][ch_out][ch_in][spar_band]; } else { - par_mat[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; + mixer_mat[ch_out][ch_in][spar_band] = hSpar->hMdDec->mixer_mat[ch_out][ch_in][spar_band]; } } else { /* 20ms Transport channel reconstruction with matching encoder/decoder processing */ int16_t prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */ - par_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight_20ms ) * hSpar->hMdDec->mixer_mat_prev[prev_idx][out_ch][in_ch][spar_band] + weight_20ms * hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; + mixer_mat[ch_out][ch_in][spar_band] = ( 1.0f - weight_20ms ) * hSpar->hMdDec->mixer_mat_prev[prev_idx][ch_out][ch_in][spar_band] + weight_20ms * hSpar->hMdDec->mixer_mat[ch_out][ch_in][spar_band]; } } } @@ -851,26 +870,26 @@ void ivas_spar_get_parameters( static void ivas_spar_get_skip_mat( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - const int16_t num_ch_out, - const int16_t num_ch_in, + const int16_t nchan_out, + const int16_t nchan_inp, const int16_t num_spar_bands, int16_t skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] ) { - int16_t spar_band, out_ch, in_ch; + int16_t spar_band, ch_out, ch_in; int16_t i_ts, skip_flag; - for ( out_ch = 0; out_ch < num_ch_out; out_ch++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - for ( in_ch = 0; in_ch < num_ch_in; in_ch++ ) + for ( ch_in = 0; ch_in < nchan_inp; ch_in++ ) { - skip_mat[out_ch][in_ch] = 1; + skip_mat[ch_out][ch_in] = 1; skip_flag = 1; for ( i_ts = 0; i_ts < MAX_PARAM_SPATIAL_SUBFRAMES; i_ts++ ) { for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) { - if ( hSpar->hMdDec->mixer_mat_prev[1 + i_ts][out_ch][in_ch][spar_band] != 0.0f || hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band + i_ts * MAX_PARAM_SPATIAL_SUBFRAMES] != 0.0f ) + if ( hSpar->hMdDec->mixer_mat_prev[1 + i_ts][ch_out][ch_in][spar_band] != 0.0f || hSpar->hMdDec->mixer_mat[ch_out][ch_in][spar_band + i_ts * MAX_PARAM_SPATIAL_SUBFRAMES] != 0.0f ) { skip_flag = 0; break; @@ -879,7 +898,7 @@ static void ivas_spar_get_skip_mat( if ( skip_flag == 0 ) { - skip_mat[out_ch][in_ch] = 0; + skip_mat[ch_out][ch_in] = 0; break; } } @@ -903,14 +922,13 @@ void ivas_spar_dec_upmixer( const int16_t output_frame /* i : output frame length */ ) { - int16_t cldfb_band, num_cldfb_bands, numch_in, numch_out; + int16_t nchan_inp, nchan_out, nchan_transport, nchan_ingest; + int16_t cldfb_band, num_cldfb_bands; float *cldfb_in_ts_re[MAX_OUTPUT_CHANNELS][CLDFB_NO_COL_MAX]; float *cldfb_in_ts_im[MAX_OUTPUT_CHANNELS][CLDFB_NO_COL_MAX]; - int16_t i, b, ts, out_ch, in_ch; - int16_t num_spar_bands, spar_band, nchan_transport; - int16_t num_in_ingest, num_bands_out, split_band; + int16_t i, b, ts, ch_out, ch_in; + int16_t num_spar_bands, spar_band, num_bands_out, split_band; float Pcm_tmp[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - int16_t numch_out_dirac; float *pPcm_tmp[MAX_OUTPUT_CHANNELS]; float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; int16_t b_skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; @@ -922,11 +940,11 @@ void ivas_spar_dec_upmixer( hSpar = st_ivas->hSpar; hDecoderConfig = st_ivas->hDecoderConfig; num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; - nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; // VE: == st_ivas->nchan_transport num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; - numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; - numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + nchan_inp = hSpar->hFbMixer->fb_cfg->nchan_inp; + nchan_out = hSpar->hFbMixer->fb_cfg->nchan_out; #ifdef DEBUG_SPAR_BYPASS_EVS_CODEC /* by-pass core-coder */ @@ -957,9 +975,9 @@ void ivas_spar_dec_upmixer( } for ( smp = 0; smp < L_FRAME48k; smp++ ) { - for ( in_ch = 0; in_ch < nchan_transport; in_ch++ ) + for ( ch_in = 0; ch_in < nchan_transport; ch_in++ ) { - fread( &output[in_ch][smp], sizeof( float ), 1, fid_enc ); + fread( &output[ch_in][smp], sizeof( float ), 1, fid_enc ); } } } @@ -982,11 +1000,11 @@ void ivas_spar_dec_upmixer( if ( hSpar->hMdDec->td_decorr_flag ) { - num_in_ingest = nchan_internal; + nchan_ingest = nchan_internal; } else { - num_in_ingest = nchan_transport; + nchan_ingest = nchan_transport; } for ( i = 0; i < nchan_internal; i++ ) @@ -998,19 +1016,18 @@ void ivas_spar_dec_upmixer( * PCA decoder *---------------------------------------------------------------------*/ #ifdef DEBUG_SBA_AUDIO_DUMP - hSpar->pca_ingest_channels = num_in_ingest; + hSpar->pca_ingest_channels = nchan_ingest; #endif if ( hSpar->hPCA != NULL ) { - ivas_pca_dec( hSpar->hPCA, output_frame, num_in_ingest, hDecoderConfig->ivas_total_brate, hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, output ); + ivas_pca_dec( hSpar->hPCA, output_frame, nchan_ingest, hDecoderConfig->ivas_total_brate, hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, output ); #ifdef DEBUG_SBA_AUDIO_DUMP /* Dump audio signal after ivas_pca_dec */ - ivas_spar_dump_signal_wav( output_frame, NULL, output, num_in_ingest, spar_foa_dec_wav[2], "ivas_pca_dec()" ); + ivas_spar_dump_signal_wav( output_frame, NULL, output, nchan_ingest, spar_foa_dec_wav[2], "ivas_pca_dec()" ); #endif } - /*---------------------------------------------------------------------* * TD decorrelation *---------------------------------------------------------------------*/ @@ -1024,11 +1041,11 @@ void ivas_spar_dec_upmixer( mvr2r( pPcm_tmp[hSpar->hTdDecorr->num_apd_outputs - 1 - i], output[nchan_internal - 1 - i], output_frame ); } - hSpar->hFbMixer->fb_cfg->num_in_chans = num_in_ingest; + hSpar->hFbMixer->fb_cfg->nchan_inp = nchan_inp; // VE2DB: this is the same for the else branch below -> call it only once? } else { - hSpar->hFbMixer->fb_cfg->num_in_chans = num_in_ingest; + hSpar->hFbMixer->fb_cfg->nchan_inp = nchan_inp; } /*---------------------------------------------------------------------* @@ -1036,26 +1053,26 @@ void ivas_spar_dec_upmixer( *---------------------------------------------------------------------*/ /* set-up pointers */ - if ( st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) + if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) { /* at this point, output channels are used as intermediate procesing buffers */ - for ( in_ch = 0; in_ch < MAX_OUTPUT_CHANNELS; in_ch++ ) + for ( ch_in = 0; ch_in < MAX_OUTPUT_CHANNELS; ch_in++ ) { for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { - cldfb_in_ts_re[in_ch][ts] = &Pcm_tmp[in_ch][ts * num_cldfb_bands]; - cldfb_in_ts_im[in_ch][ts] = &Pcm_tmp[in_ch][ts * num_cldfb_bands + 4 * num_cldfb_bands]; + cldfb_in_ts_re[ch_in][ts] = &Pcm_tmp[ch_in][ts * num_cldfb_bands]; + cldfb_in_ts_im[ch_in][ts] = &Pcm_tmp[ch_in][ts * num_cldfb_bands + 4 * num_cldfb_bands]; } } } else { - for ( in_ch = 0; in_ch < numch_in; in_ch++ ) + for ( ch_in = 0; ch_in < nchan_inp; ch_in++ ) { for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { - cldfb_in_ts_re[in_ch][ts] = &Pcm_tmp[in_ch][ts * num_cldfb_bands]; - cldfb_in_ts_im[in_ch][ts] = &Pcm_tmp[in_ch][ts * num_cldfb_bands + 4 * num_cldfb_bands]; + cldfb_in_ts_re[ch_in][ts] = &Pcm_tmp[ch_in][ts * num_cldfb_bands]; + cldfb_in_ts_im[ch_in][ts] = &Pcm_tmp[ch_in][ts * num_cldfb_bands + 4 * num_cldfb_bands]; } } } @@ -1075,30 +1092,28 @@ void ivas_spar_dec_upmixer( /* apply parameters */ /* determine if we can skip certain data */ - ivas_spar_get_skip_mat( hSpar, numch_out, numch_in, num_spar_bands, b_skip_mat ); /* this can be precomputed based on bitrate and format*/ - - numch_out_dirac = st_ivas->hDecoderConfig->nchan_out; + ivas_spar_get_skip_mat( hSpar, nchan_out, nchan_inp, num_spar_bands, b_skip_mat ); /* this can be precomputed based on bitrate and format*/ for ( int16_t i_sf = 0; i_sf < MAX_PARAM_SPATIAL_SUBFRAMES; i_sf++ ) { /* CLDFB analysis of incoming frame */ - for ( in_ch = 0; in_ch < numch_in; in_ch++ ) + for ( ch_in = 0; ch_in < nchan_inp; ch_in++ ) { for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { cldfbAnalysis_ts( - &output[in_ch][( ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES ) * num_cldfb_bands], - cldfb_in_ts_re[in_ch][ts], - cldfb_in_ts_im[in_ch][ts], + &output[ch_in][( ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES ) * num_cldfb_bands], + cldfb_in_ts_re[ch_in][ts], + cldfb_in_ts_im[ch_in][ts], num_cldfb_bands, - st_ivas->cldfbAnaDec[in_ch] ); + st_ivas->cldfbAnaDec[ch_in] ); } } for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { /* determine SPAR parameters for this time slots */ - ivas_spar_get_parameters( hSpar, st_ivas->hDecoderConfig, ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES, numch_out, numch_in, num_spar_bands, mixer_mat ); + ivas_spar_get_parameters( hSpar, hDecoderConfig, ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES, nchan_out, nchan_inp, num_spar_bands, mixer_mat ); for ( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ ) { @@ -1107,21 +1122,21 @@ void ivas_spar_dec_upmixer( float cldfb_par; ivas_fb_bin_to_band_data_t *bin2band = &hSpar->hFbMixer->pFb->fb_bin_to_band; - for ( out_ch = 0; out_ch < numch_out; out_ch++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - out_re[out_ch] = 0.0f; - out_im[out_ch] = 0.0f; + out_re[ch_out] = 0.0f; + out_im[ch_out] = 0.0f; - for ( in_ch = 0; in_ch < numch_in; in_ch++ ) + for ( ch_in = 0; ch_in < nchan_inp; ch_in++ ) { - if ( b_skip_mat[out_ch][in_ch] ) + if ( b_skip_mat[ch_out][ch_in] ) { continue; } else if ( cldfb_band < CLDFB_PAR_WEIGHT_START_BAND ) /* tuning parameter, depends on how much SPAR Filters overlap for the CLDFB bands */ { spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; - cldfb_par = mixer_mat[out_ch][in_ch][spar_band]; + cldfb_par = mixer_mat[ch_out][ch_in][spar_band]; } else { @@ -1129,37 +1144,37 @@ void ivas_spar_dec_upmixer( for ( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ - cldfb_par += mixer_mat[out_ch][in_ch][spar_band] * bin2band->pp_cldfb_weights_per_spar_band[cldfb_band][spar_band]; + cldfb_par += mixer_mat[ch_out][ch_in][spar_band] * bin2band->pp_cldfb_weights_per_spar_band[cldfb_band][spar_band]; } } - out_re[out_ch] += cldfb_in_ts_re[in_ch][ts][cldfb_band] * cldfb_par; - out_im[out_ch] += cldfb_in_ts_im[in_ch][ts][cldfb_band] * cldfb_par; + out_re[ch_out] += cldfb_in_ts_re[ch_in][ts][cldfb_band] * cldfb_par; + out_im[ch_out] += cldfb_in_ts_im[ch_in][ts][cldfb_band] * cldfb_par; } } /*update CLDFB data with the parameter-modified data*/ - for ( out_ch = 0; out_ch < numch_out; out_ch++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - cldfb_in_ts_re[out_ch][ts][cldfb_band] = out_re[out_ch]; - cldfb_in_ts_im[out_ch][ts][cldfb_band] = out_im[out_ch]; + cldfb_in_ts_re[ch_out][ts][cldfb_band] = out_re[ch_out]; + cldfb_in_ts_im[ch_out][ts][cldfb_band] = out_im[ch_out]; } } } - if ( st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) + if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) { ivas_dirac_dec( st_ivas, output, nchan_internal, cldfb_in_ts_re, cldfb_in_ts_im, i_sf ); } if ( st_ivas->hDirAC != NULL ) { - int16_t outchannels, idx_in, idx_lfe, ch; + int16_t nchan, idx_in, idx_lfe, ch; idx_in = 0; idx_lfe = 0; - outchannels = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; - for ( ch = 0; ch < outchannels; ch++ ) + nchan = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; + for ( ch = 0; ch < nchan; ch++ ) { if ( ( st_ivas->hOutSetup.num_lfe > 0 ) && ( st_ivas->hOutSetup.index_lfe[idx_lfe] == ch ) ) { @@ -1172,7 +1187,7 @@ void ivas_spar_dec_upmixer( } else { - if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA || + if ( hDecoderConfig->output_config == AUDIO_CONFIG_FOA || !( st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL || st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL_ROOM ) ) { for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) @@ -1189,26 +1204,26 @@ void ivas_spar_dec_upmixer( } } #ifdef DEBUG_SBA_AUDIO_DUMP - hSpar->numOutChannels = outchannels; + hSpar->numOutChannels = nchan; #endif } else { /* CLDFB to time synthesis (overwrite mixer output) */ - for ( out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + for ( ch_out = 0; ch_out < hDecoderConfig->nchan_out; ch_out++ ) { for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { cldfbSynthesis( - &cldfb_in_ts_re[out_ch][ts], - &cldfb_in_ts_im[out_ch][ts], - &output[out_ch][( ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES ) * num_cldfb_bands], + &cldfb_in_ts_re[ch_out][ts], + &cldfb_in_ts_im[ch_out][ts], + &output[ch_out][( ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES ) * num_cldfb_bands], num_cldfb_bands, - st_ivas->cldfbSynDec[out_ch] ); + st_ivas->cldfbSynDec[ch_out] ); } } #ifdef DEBUG_SBA_AUDIO_DUMP - hSpar->numOutChannels = numch_out_dirac; + hSpar->numOutChannels = nchan; #endif } #ifdef DEBUG_SBA_AUDIO_DUMP @@ -1226,13 +1241,13 @@ void ivas_spar_dec_upmixer( mvr2r( hSpar->hMdDec->mixer_mat_prev[3][0][0], hSpar->hMdDec->mixer_mat_prev[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); mvr2r( hSpar->hMdDec->mixer_mat_prev[4][0][0], hSpar->hMdDec->mixer_mat_prev[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - for ( out_ch = 0; out_ch < numch_out; out_ch++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - for ( in_ch = 0; in_ch < numch_in; in_ch++ ) + for ( ch_in = 0; ch_in < nchan_inp; ch_in++ ) { for ( b = 0; b < num_spar_bands; b++ ) { - hSpar->hMdDec->mixer_mat_prev[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][b + i_sf * IVAS_MAX_NUM_BANDS]; + hSpar->hMdDec->mixer_mat_prev[4][ch_out][ch_in][b] = hSpar->hMdDec->mixer_mat[ch_out][ch_in][b + i_sf * IVAS_MAX_NUM_BANDS]; } } } diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 3d5f03b2087cde099c7f145eb6d8fe0f53cbe6c8..eac82bc20db57c0b3e545b9e07adb9f6e80d55c2 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -73,7 +73,7 @@ static void ivas_fill_band_coeffs_idx( ivas_band_coeffs_ind_t *pBands_idx, const static void ivas_get_band_idx_from_differential( ivas_spar_md_t *pSpar_md, const int16_t q_levels[2], const int16_t one_sided, const int16_t nB, const ivas_coeffs_type_t coeff_type ); -static void ivas_mat_col_rearrange( float in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t order[IVAS_SPAR_MAX_CH], const int16_t i_ts, float ***mixer_mat, const int16_t bands, const int16_t num_ch ); +static void ivas_mat_col_rearrange( float in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t order[IVAS_SPAR_MAX_CH], const int16_t i_ts, float ***mixer_mat, const int16_t bands, const int16_t nchan ); static void ivas_spar_dec_compute_ramp_down_post_matrix( ivas_spar_md_dec_state_t *hMdDec, const int16_t num_bands, const int16_t bfi ); @@ -94,7 +94,7 @@ static void ivas_spar_dec_parse_md_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder static ivas_error ivas_spar_md_dec_matrix_open( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const int16_t num_channels /* i : number of internal channels */ + const int16_t nchan /* i : number of internal channels */ ) { int16_t i, j; @@ -103,17 +103,17 @@ static ivas_error ivas_spar_md_dec_matrix_open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" ); } - if ( ( hMdDec->mixer_mat = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdDec->mixer_mat = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdDec->mixer_mat[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdDec->mixer_mat[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdDec->mixer_mat[i][j] = (float *) count_malloc( MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -122,17 +122,17 @@ static ivas_error ivas_spar_md_dec_matrix_open( } } - if ( ( hMdDec->spar_coeffs.C_re = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.C_re = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdDec->spar_coeffs.C_re[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.C_re[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdDec->spar_coeffs.C_re[i][j] = (float *) count_malloc( MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -141,17 +141,17 @@ static ivas_error ivas_spar_md_dec_matrix_open( } } - if ( ( hMdDec->spar_coeffs.P_re = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.P_re = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdDec->spar_coeffs.P_re[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.P_re[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdDec->spar_coeffs.P_re[i][j] = (float *) count_malloc( MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -160,17 +160,17 @@ static ivas_error ivas_spar_md_dec_matrix_open( } } - if ( ( hMdDec->spar_coeffs_prev.C_re = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_prev.C_re = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdDec->spar_coeffs_prev.C_re[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_prev.C_re[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdDec->spar_coeffs_prev.C_re[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -179,17 +179,17 @@ static ivas_error ivas_spar_md_dec_matrix_open( } } - if ( ( hMdDec->spar_coeffs_prev.P_re = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_prev.P_re = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdDec->spar_coeffs_prev.P_re[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_prev.P_re[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdDec->spar_coeffs_prev.P_re[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -198,17 +198,17 @@ static ivas_error ivas_spar_md_dec_matrix_open( } } - if ( ( hMdDec->spar_coeffs_tar.C_re = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_tar.C_re = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdDec->spar_coeffs_tar.C_re[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_tar.C_re[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdDec->spar_coeffs_tar.C_re[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -217,17 +217,17 @@ static ivas_error ivas_spar_md_dec_matrix_open( } } - if ( ( hMdDec->spar_coeffs_tar.P_re = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_tar.P_re = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdDec->spar_coeffs_tar.P_re[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_tar.P_re[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdDec->spar_coeffs_tar.P_re[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -249,7 +249,7 @@ static ivas_error ivas_spar_md_dec_matrix_open( ivas_error ivas_spar_md_dec_open( ivas_spar_md_dec_state_t **hMdDec_out, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t num_channels /* i : number of internal channels */ + const int16_t nchan /* i : number of internal channels */ #ifdef SBA_HOA_HBR_IMPROV , const int16_t sba_order /* i : SBA order */ @@ -266,17 +266,23 @@ ivas_error ivas_spar_md_dec_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD decoder" ); } - if ( ( error = ivas_spar_md_dec_matrix_open( hMdDec, num_channels ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_md_dec_matrix_open( hMdDec, nchan ) ) != IVAS_ERR_OK ) { return error; } +#ifndef SBA_BITRATE_SWITCHING #ifdef SBA_HOA_HBR_IMPROV hMdDec->spar_hoa_md_flag = ivas_sba_get_spar_hoa_md_flag( sba_order, hDecoderConfig->ivas_total_brate ); +#endif #endif hMdDec->table_idx = 0; /* just to initialize state variables*/ - if ( ( error = ivas_spar_md_dec_init( hMdDec, hDecoderConfig, num_channels ) ) != IVAS_ERR_OK ) +#if ( defined SBA_BITRATE_SWITCHING && defined SBA_HOA_HBR_IMPROV ) + if ( ( error = ivas_spar_md_dec_init( hMdDec, hDecoderConfig, sba_order, nchan ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_spar_md_dec_init( hMdDec, hDecoderConfig, nchan ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -295,7 +301,7 @@ ivas_error ivas_spar_md_dec_open( static void ivas_spar_md_dec_matrix_close( ivas_spar_md_dec_state_t *hMdDecoder, /* i/o: SPAR MD decoder handle */ - const int16_t num_channels /* i : number of internal channels */ + const int16_t nchan /* i : number of internal channels */ ) { int16_t i, j; @@ -307,9 +313,9 @@ static void ivas_spar_md_dec_matrix_close( } if ( hMdDecoder->mixer_mat != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdDecoder->mixer_mat[i][j] ); } @@ -320,9 +326,9 @@ static void ivas_spar_md_dec_matrix_close( if ( hMdDecoder->spar_coeffs.C_re != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdDecoder->spar_coeffs.C_re[i][j] ); } @@ -333,9 +339,9 @@ static void ivas_spar_md_dec_matrix_close( if ( hMdDecoder->spar_coeffs.P_re != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdDecoder->spar_coeffs.P_re[i][j] ); } @@ -346,9 +352,9 @@ static void ivas_spar_md_dec_matrix_close( if ( hMdDecoder->spar_coeffs_prev.C_re != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdDecoder->spar_coeffs_prev.C_re[i][j] ); } @@ -359,9 +365,9 @@ static void ivas_spar_md_dec_matrix_close( if ( hMdDecoder->spar_coeffs_prev.P_re != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdDecoder->spar_coeffs_prev.P_re[i][j] ); } @@ -372,9 +378,9 @@ static void ivas_spar_md_dec_matrix_close( if ( hMdDecoder->spar_coeffs_tar.C_re != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdDecoder->spar_coeffs_tar.C_re[i][j] ); } @@ -385,9 +391,9 @@ static void ivas_spar_md_dec_matrix_close( if ( hMdDecoder->spar_coeffs_tar.P_re != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdDecoder->spar_coeffs_tar.P_re[i][j] ); } @@ -411,12 +417,12 @@ void ivas_spar_md_dec_close( ) { ivas_spar_md_dec_state_t *hMdDecoder; - int16_t num_channels; + int16_t nchan; hMdDecoder = *hMdDec; - num_channels = hMdDecoder->spar_md_cfg.num_umx_chs; + nchan = hMdDecoder->spar_md_cfg.num_umx_chs; - ivas_spar_md_dec_matrix_close( hMdDecoder, num_channels ); + ivas_spar_md_dec_matrix_close( hMdDecoder, nchan ); if ( *hMdDec != NULL ) { @@ -437,13 +443,20 @@ void ivas_spar_md_dec_close( ivas_error ivas_spar_md_dec_init( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t num_channels /* i : number of internal channels */ +#if ( defined SBA_BITRATE_SWITCHING && defined SBA_HOA_HBR_IMPROV ) + const int16_t sba_order, /* i : SBA order */ +#endif + const int16_t nchan /* i : number of internal channels */ ) { int16_t i, j, k; int16_t nchan_transport; float pFC[IVAS_MAX_NUM_BANDS], PR_minmax[2]; +#if ( defined SBA_BITRATE_SWITCHING && defined SBA_HOA_HBR_IMPROV ) + hMdDec->spar_hoa_md_flag = ivas_sba_get_spar_hoa_md_flag( sba_order, hDecoderConfig->ivas_total_brate ); +#endif + hMdDec->spar_md_cfg.gen_bs = 1; // VE2DB : always 1 - can it be removed? #ifdef SBA_HOA_HBR_IMPROV @@ -491,9 +504,9 @@ ivas_error ivas_spar_md_dec_init( hMdDec->spar_plc_num_lost_frames = 0; hMdDec->spar_plc_enable_fadeout_flag = 1; - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -502,9 +515,9 @@ ivas_error ivas_spar_md_dec_init( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -513,9 +526,9 @@ ivas_error ivas_spar_md_dec_init( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -524,9 +537,9 @@ ivas_error ivas_spar_md_dec_init( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -563,7 +576,7 @@ static ivas_error ivas_spar_set_dec_config( const int16_t nchan_transport, float *pFC ) { - int16_t i, j, nchan, dmx_ch; + int16_t i, j, nchan, nchan_dmx; for ( i = 0; i < nchan_transport; i++ ) { @@ -593,15 +606,15 @@ static ivas_error ivas_spar_set_dec_config( hMdDec->spar_md_cfg.num_umx_chs = nchan; - dmx_ch = 0; + nchan_dmx = 0; for ( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) { - dmx_ch = 0; + nchan_dmx = 0; for ( j = 0; j < nchan_transport; j++ ) { if ( pFC[i] < hMdDec->spar_md_cfg.max_freq_per_chan[j] ) { - dmx_ch += 1; + nchan_dmx += 1; } } @@ -609,7 +622,7 @@ static ivas_error ivas_spar_set_dec_config( hMdDec->spar_md_cfg.num_decorr_per_band[i] = nchan - hMdDec->spar_md_cfg.nchan_transport; } - hMdDec->spar_md_cfg.nchan_transport = dmx_ch; + hMdDec->spar_md_cfg.nchan_transport = nchan_dmx; return IVAS_ERR_OK; } @@ -641,17 +654,17 @@ void ivas_spar_md_dec_process( char f_name[100]; int16_t num_bands = nB; int16_t num_subframes = 1, num_block_groups = 1, num_elements = 1, byte_size = sizeof( float ); - int16_t num_ch = 2 * sba_order + 2; + int16_t nchan = 2 * sba_order + 2; for ( b = 0; b < num_bands; b++ ) { sprintf( f_name, "spar_band_pred_coeffs_dec.bin" ); ( b == 0 && frame == 0 ) ? dbgwrite( &num_bands, sizeof( num_bands ), 1, 1, f_name ) : false; - num_elements = num_ch - 1; + num_elements = nchan - 1; ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; - for ( j = 0; j < num_ch - 1; j++ ) + for ( j = 0; j < nchan - 1; j++ ) { dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[j], sizeof( float ), 1, 1, f_name ); } @@ -671,12 +684,12 @@ void ivas_spar_md_dec_process( } sprintf( f_name, "spar_band_P_coeffs_dec.bin" ); ( b == 0 && frame == 0 ) ? dbgwrite( &num_bands, sizeof( num_bands ), 1, 1, f_name ) : false; - num_elements = num_ch - 1; + num_elements = nchan - 1; ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; - for ( j = 0; j < num_ch - 1; j++ ) + for ( j = 0; j < nchan - 1; j++ ) { dbgwrite( &hMdDec->spar_md.band_coeffs[b].P_re[j], sizeof( float ), 1, 1, f_name ); } @@ -773,18 +786,18 @@ void ivas_spar_smooth_md_dtx( const int16_t num_bands_out /* i : number of output bands */ ) { - int16_t j, k, b, dmx_ch; + int16_t j, k, b, nchan_dmx; float ramp, tar, prev, new_val; ramp = (float) hMdDec->dtx_md_smoothing_cntr / IVAS_DEFAULT_DTX_CNG_RAMP; for ( b = 0; b < num_bands_out; b++ ) { - dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; + nchan_dmx = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; for ( j = 1; j < FOA_CHANNELS; j++ ) { - for ( k = dmx_ch; k < FOA_CHANNELS; k++ ) + for ( k = nchan_dmx; k < FOA_CHANNELS; k++ ) { prev = hMdDec->spar_coeffs_prev.P_re[j][k][b]; tar = hMdDec->spar_coeffs_tar.P_re[j][k][b]; @@ -795,7 +808,7 @@ void ivas_spar_smooth_md_dtx( for ( j = 0; j < FOA_CHANNELS; j++ ) { - for ( k = 0; k < dmx_ch; k++ ) + for ( k = 0; k < nchan_dmx; k++ ) { prev = hMdDec->spar_coeffs_prev.C_re[j][k][b]; tar = hMdDec->spar_coeffs_tar.C_re[j][k][b]; @@ -810,12 +823,11 @@ void ivas_spar_smooth_md_dtx( { for ( b = 0; b < num_bands_out; b++ ) { - dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; + nchan_dmx = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; for ( j = 1; j < FOA_CHANNELS; j++ ) { - for ( k = dmx_ch; k < FOA_CHANNELS; k++ ) - + for ( k = nchan_dmx; k < FOA_CHANNELS; k++ ) { hMdDec->spar_coeffs.P_re[j][k][b + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.P_re[j][k][b]; } @@ -823,7 +835,7 @@ void ivas_spar_smooth_md_dtx( for ( j = 0; j < FOA_CHANNELS; j++ ) { - for ( k = 0; k < dmx_ch; k++ ) + for ( k = 0; k < nchan_dmx; k++ ) { hMdDec->spar_coeffs.C_re[j][k][b + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.C_re[j][k][b]; } @@ -849,13 +861,13 @@ void ivas_spar_setup_md_smoothing( ) { /* copy the coeffs */ - int16_t num_channels, i, j, k; + int16_t nchan, i, j, k; - num_channels = hMdDec->spar_md_cfg.num_umx_chs; + nchan = hMdDec->spar_md_cfg.num_umx_chs; - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -864,9 +876,9 @@ void ivas_spar_setup_md_smoothing( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -875,9 +887,9 @@ void ivas_spar_setup_md_smoothing( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -886,9 +898,9 @@ void ivas_spar_setup_md_smoothing( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -912,13 +924,13 @@ void ivas_spar_setup_md_smoothing( void ivas_spar_update_md_hist( ivas_spar_md_dec_state_t *hMdDec ) { - int16_t num_channels, i, j, k; + int16_t nchan, i, j, k; - num_channels = hMdDec->spar_md_cfg.num_umx_chs; + nchan = hMdDec->spar_md_cfg.num_umx_chs; - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -927,9 +939,9 @@ void ivas_spar_update_md_hist( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -938,9 +950,9 @@ void ivas_spar_update_md_hist( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -949,9 +961,9 @@ void ivas_spar_update_md_hist( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -979,12 +991,12 @@ static void ivas_get_spar_matrices( const int16_t nB, const int16_t sba_order ) { - int16_t numch_out, num_bands, dmx_ch, split_band; + int16_t nchan, num_bands, nchan_dmx, split_band; int16_t i, j, k, m, b, i_ts, active_w; const int16_t *order; float active_w_dm_fac, re; - numch_out = ivas_sba_get_nchan_metadata( sba_order ); + nchan = ivas_sba_get_nchan_metadata( sba_order ); num_bands = num_bands_out; order = remix_order_set[hMdDec->spar_md_cfg.remix_unmix_order]; @@ -993,9 +1005,9 @@ static void ivas_get_spar_matrices( if ( split_band >= IVAS_MAX_NUM_BANDS ) { /*store previous 4x4 parameters for linear interpolation to current*/ - for ( i = 0; i < numch_out; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < numch_out; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( b = 0; b < num_bands; b++ ) { @@ -1008,15 +1020,15 @@ static void ivas_get_spar_matrices( #ifdef SPAR_HOA_DBG /*for (b = 0; b < BANDS_12; b++) { - for (i = 0; i < IVAS_SPAR_MAX_CH - 1; i++) + for (i = 0; i < IVAS_SPAR_MAX_CH - 1; i++) + { + hMdDec->spar_md.band_coeffs[b].pred_re[i] = (float)(i + 1)/10; + for (j = 0; j < IVAS_SPAR_MAX_CH - 1; j++) { - hMdDec->spar_md.band_coeffs[b].pred_re[i] = (float)(i + 1)/10; - for (j = 0; j < IVAS_SPAR_MAX_CH - 1; j++) - { - hMdDec->spar_md.band_coeffs[b].C_re[i][j] = (float)(i + j * 20 + 1)/10; - hMdDec->spar_md.band_coeffs[b].P_re[i][j] = (float)(i + j * 20 + 1)/10; - } + hMdDec->spar_md.band_coeffs[b].C_re[i][j] = (float)(i + j * 20 + 1)/10; + hMdDec->spar_md.band_coeffs[b].P_re[i][j] = (float)(i + j * 20 + 1)/10; } + } }*/ #endif @@ -1025,9 +1037,9 @@ static void ivas_get_spar_matrices( for ( i_ts = 0; i_ts < n_ts; i_ts++ ) { - for ( i = 0; i < numch_out; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < numch_out; j++ ) + for ( j = 0; j < nchan; j++ ) { set_zero( &hMdDec->spar_coeffs.C_re[i][j][i_ts * IVAS_MAX_NUM_BANDS], IVAS_MAX_NUM_BANDS ); set_zero( &hMdDec->spar_coeffs.P_re[i][j][i_ts * IVAS_MAX_NUM_BANDS], IVAS_MAX_NUM_BANDS ); @@ -1047,27 +1059,27 @@ static void ivas_get_spar_matrices( float tmp_C2_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; float tmp_dm_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[bw * b]; + nchan_dmx = hMdDec->spar_md_cfg.num_dmx_chans_per_band[bw * b]; - for ( j = 0; j < numch_out; j++ ) + for ( j = 0; j < nchan; j++ ) { - set_zero( tmp_C1_re[j], numch_out ); - set_zero( tmp_C2_re[j], numch_out ); - set_zero( tmp_dm_re[j], numch_out ); + set_zero( tmp_C1_re[j], nchan ); + set_zero( tmp_C2_re[j], nchan ); + set_zero( tmp_dm_re[j], nchan ); tmp_C1_re[j][j] = 1.0f; tmp_C2_re[j][j] = 1.0f; tmp_dm_re[j][j] = 1.0f; } - for ( j = 1; j < numch_out; j++ ) + for ( j = 1; j < nchan; j++ ) { tmp_C1_re[j][0] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[j - 1]; } if ( active_w == 1 ) { - for ( j = 1; j < numch_out; j++ ) + for ( j = 1; j < nchan; j++ ) { tmp_C2_re[0][j] = active_w_dm_fac * -hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[j - 1]; } @@ -1095,7 +1107,7 @@ static void ivas_get_spar_matrices( if ( hMdDec->spar_md_cfg.remix_unmix_order != 3 ) { - ivas_mat_col_rearrange( tmp_dm_re, order, i_ts, hMdDec->mixer_mat, b, numch_out ); + ivas_mat_col_rearrange( tmp_dm_re, order, i_ts, hMdDec->mixer_mat, b, nchan ); } else { @@ -1120,7 +1132,7 @@ static void ivas_get_spar_matrices( { if ( hMdDec->spar_md_cfg.remix_unmix_order != 3 ) { - ivas_mat_col_rearrange( tmp_C1_re, order, i_ts, hMdDec->mixer_mat, b, numch_out ); + ivas_mat_col_rearrange( tmp_C1_re, order, i_ts, hMdDec->mixer_mat, b, nchan ); } else { @@ -1142,63 +1154,62 @@ static void ivas_get_spar_matrices( } } - if ( dmx_ch > 0 ) + if ( nchan_dmx > 0 ) { float tmpC_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; float tmpP_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - for ( j = 0; j < numch_out; j++ ) + for ( j = 0; j < nchan; j++ ) { - set_zero( tmpC_re[j], numch_out ); - set_zero( tmpP_re[j], numch_out ); + set_zero( tmpC_re[j], nchan ); + set_zero( tmpP_re[j], nchan ); } - for ( j = 0; j < numch_out; j++ ) + for ( j = 0; j < nchan; j++ ) { - set_zero( tmpC_re[j], numch_out ); + set_zero( tmpC_re[j], nchan ); } - for ( k = 0; k < dmx_ch; k++ ) + for ( k = 0; k < nchan_dmx; k++ ) { tmpC_re[k][k] = 1; } - for ( j = dmx_ch; j < numch_out; j++ ) + for ( j = nchan_dmx; j < nchan; j++ ) { - for ( k = 1; k < dmx_ch; k++ ) + for ( k = 1; k < nchan_dmx; k++ ) { - tmpC_re[j][k] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re[j - dmx_ch][k - 1]; + tmpC_re[j][k] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re[j - nchan_dmx][k - 1]; } } #ifdef SPAR_HOA_DBG - /*fprintf(stdout, "C matrix1: %d x %d\n\n", numch_out, dmx_ch); - for (j = 0; j < numch_out; j++) + /*fprintf(stdout, "C matrix1: %d x %d\n\n", nchan, nchan_dmx); + for (j = 0; j < nchan; j++) { - for (k = 0; k < dmx_ch; k++) - { - fprintf(stdout, "%f, ", tmpC_re[j][k]); - } - fprintf(stdout, "\n"); - + for (k = 0; k < nchan_dmx; k++) + { + fprintf(stdout, "%f, ", tmpC_re[j][k]); + } + fprintf(stdout, "\n"); } - fprintf(stdout, "Mixer Mat: %d x %d\n\n", numch_out, numch_out); - for ( j = 0; j < numch_out; j++) + fprintf(stdout, "Mixer Mat: %d x %d\n\n", nchan, nchan); + for ( j = 0; j < nchan; j++) { - for (k = 0; k < numch_out; k++) - { - fprintf(stdout, "%f, ", hMdDec->mixer_mat[j][k][0][b]); - } - fprintf(stdout, "\n"); + for (k = 0; k < nchan; k++) + { + fprintf(stdout, "%f, ", hMdDec->mixer_mat[j][k][0][b]); + } + fprintf(stdout, "\n"); }*/ #endif - for ( j = dmx_ch; j < numch_out; j++ ) + for ( j = nchan_dmx; j < nchan; j++ ) { - for ( k = dmx_ch; k < numch_out; k++ ) + for ( k = nchan_dmx; k < nchan; k++ ) { - if ( ( j - dmx_ch ) == ( k - dmx_ch ) ) + if ( ( j - nchan_dmx ) == ( k - nchan_dmx ) ) { - tmpP_re[j][k] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re[k - dmx_ch]; + tmpP_re[j][k] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re[k - nchan_dmx]; } else { @@ -1209,34 +1220,32 @@ static void ivas_get_spar_matrices( #ifdef SPAR_HOA_DBG /*if (b == 0) { - fprintf(stdout, "tmp_P matrix: %d x %d\n\n", numch_out, dmx_ch); - for (j = 0; j < numch_out; j++) + fprintf(stdout, "tmp_P matrix: %d x %d\n\n", nchan, nchan_dmx); + for (j = 0; j < nchan; j++) + { + for (k = 0; k < nchan; k++) { - for (k = 0; k < numch_out; k++) - { - fprintf(stdout, "%f, ", tmpP_re[j][k]); - } - fprintf(stdout, "\n"); - + fprintf(stdout, "%f, ", tmpP_re[j][k]); } - fprintf(stdout, "Mixer Mat: %d x %d\n\n", numch_out, numch_out); - for (j = 0; j < numch_out; j++) + fprintf(stdout, "\n"); + } + fprintf(stdout, "Mixer Mat: %d x %d\n\n", nchan, nchan); + for (j = 0; j < nchan; j++) + { + for (k = 0; k < nchan; k++) { - for (k = 0; k < numch_out; k++) - { - fprintf(stdout, "%f, ", hMdDec->mixer_mat[j][k][0][b]); - } - fprintf(stdout, "\n"); - + fprintf(stdout, "%f, ", hMdDec->mixer_mat[j][k][0][b]); } + fprintf(stdout, "\n"); + } }*/ #endif - for ( j = 1; j < numch_out; j++ ) + for ( j = 1; j < nchan; j++ ) { - for ( k = dmx_ch; k < numch_out; k++ ) + for ( k = nchan_dmx; k < nchan; k++ ) { - for ( m = 0; m < numch_out; m++ ) + for ( m = 0; m < nchan; m++ ) { IVAS_RMULT_FLOAT( hMdDec->mixer_mat[j][m][b + i_ts * IVAS_MAX_NUM_BANDS], tmpP_re[m][k], re ); hMdDec->spar_coeffs.P_re[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] += re; @@ -1244,11 +1253,11 @@ static void ivas_get_spar_matrices( } } - for ( j = 0; j < numch_out; j++ ) + for ( j = 0; j < nchan; j++ ) { - for ( k = 0; k < dmx_ch; k++ ) + for ( k = 0; k < nchan_dmx; k++ ) { - for ( m = 0; m < numch_out; m++ ) + for ( m = 0; m < nchan; m++ ) { IVAS_RMULT_FLOAT( hMdDec->mixer_mat[j][m][b + i_ts * IVAS_MAX_NUM_BANDS], tmpC_re[m][k], re ); hMdDec->spar_coeffs.C_re[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] += re; @@ -1256,15 +1265,14 @@ static void ivas_get_spar_matrices( } } #ifdef SPAR_HOA_DBG - /*fprintf(stdout, "C matrix1: %d x %d\n\n", numch_out, dmx_ch); - for (j = 0; j < numch_out; j++) + /*fprintf(stdout, "C matrix1: %d x %d\n\n", nchan, nchan_dmx); + for (j = 0; j < nchan; j++) { - for (k = 0; k < dmx_ch; k++) + for (k = 0; k < nchan_dmx; k++) { fprintf(stdout, "%f, ", hMdDec->spar_coeffs.C_re[j][k][b]); } fprintf(stdout, "\n"); - }*/ #endif hMdDec->spar_coeffs.C_re[0][0][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] = @@ -1274,27 +1282,25 @@ static void ivas_get_spar_matrices( #ifdef SPAR_HOA_DBG /* for (b = 0; b < 1; b++) { - fprintf(stdout, "C matrix: %d x %d band %d\n\n", numch_out, dmx_ch, b); - for (j = 0; j < numch_out; j++) + fprintf(stdout, "C matrix: %d x %d band %d\n\n", nchan, nchan_dmx, b); + for (j = 0; j < nchan; j++) + { + for (k = 0; k < nchan; k++) { - for (k = 0; k < numch_out; k++) - { - fprintf(stdout, "%f, ", hMdDec->spar_coeffs.C_re[j][k][b]); - } - fprintf(stdout, "\n"); - + fprintf(stdout, "%f, ", hMdDec->spar_coeffs.C_re[j][k][b]); } - fprintf(stdout, "\nP matrix: %d x %d\n\n", numch_out, numch_out); + fprintf(stdout, "\n"); + } + fprintf(stdout, "\nP matrix: %d x %d\n\n", nchan, nchan); - for (j = 0; j < numch_out; j++) + for (j = 0; j < nchan; j++) + { + for (k = 0; k < nchan; k++) { - for (k = 0; k < numch_out; k++) - { - fprintf(stdout, "%f, ", hMdDec->spar_coeffs.P_re[j][k][b]); - } - fprintf(stdout, "\n"); - + fprintf(stdout, "%f, ", hMdDec->spar_coeffs.P_re[j][k][b]); } + fprintf(stdout, "\n"); + } }*/ #endif @@ -1303,18 +1309,18 @@ static void ivas_get_spar_matrices( { for ( b = 0; b < num_bands_out; b = b + bw ) { - dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; - for ( j = 0; j < numch_out; j++ ) + nchan_dmx = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; + for ( j = 0; j < nchan; j++ ) { - for ( k = dmx_ch; k < numch_out; k++ ) + for ( k = nchan_dmx; k < nchan; k++ ) { hMdDec->spar_coeffs.P_re[j][k][( b + 1 ) + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.P_re[j][k][b + i_ts * IVAS_MAX_NUM_BANDS]; } } - for ( j = 0; j < numch_out; j++ ) + for ( j = 0; j < nchan; j++ ) { - for ( k = 0; k < dmx_ch; k++ ) + for ( k = 0; k < nchan_dmx; k++ ) { hMdDec->spar_coeffs.C_re[j][k][( b + 1 ) + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.C_re[j][k][b + i_ts * IVAS_MAX_NUM_BANDS]; } @@ -1339,15 +1345,15 @@ static void ivas_mat_col_rearrange( const int16_t i_ts, float ***mixer_mat, const int16_t bands, - const int16_t num_ch ) + const int16_t nchan ) { int16_t i, j, idx; - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { idx = order[i]; - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { mixer_mat[j][i][bands + i_ts * IVAS_MAX_NUM_BANDS] = in_re[j][idx]; } @@ -1419,7 +1425,7 @@ void ivas_spar_dec_gen_umx_mat( } } } - + #ifdef DEBUG_SBA_MD_DUMP { static FILE *f_mat = 0; @@ -2195,9 +2201,9 @@ static void ivas_spar_md_fill_invalid_bands( int16_t valid_band_idx[IVAS_MAX_NUM_BANDS], idx = -1; int16_t last_valid_band_idx[IVAS_MAX_NUM_BANDS]; float w = 0; - int16_t num_channels; + int16_t nchan; - num_channels = ivas_sba_get_nchan_metadata( sba_order ); + nchan = ivas_sba_get_nchan_metadata( sba_order ); set_s( valid_band_idx, 0, IVAS_MAX_NUM_BANDS ); set_s( last_valid_band_idx, 0, IVAS_MAX_NUM_BANDS ); @@ -2253,9 +2259,9 @@ static void ivas_spar_md_fill_invalid_bands( w = ( (float) ( b - id0 ) ) / ( id1 - id0 ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { pSpar_coeffs->C_re[i][j][b] = ( 1 - w ) * pSpar_coeffs->C_re[i][j][id0] + w * pSpar_coeffs->C_re[i][j][id1]; pSpar_coeffs->P_re[i][j][b] = ( 1 - w ) * pSpar_coeffs->P_re[i][j][id0] + w * pSpar_coeffs->P_re[i][j][id1]; @@ -2266,9 +2272,9 @@ static void ivas_spar_md_fill_invalid_bands( { if ( valid_bands[b] == 0 ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { pSpar_coeffs->C_re[i][j][b] = pSpar_coeffs_prev->C_re[i][j][b]; pSpar_coeffs->P_re[i][j][b] = pSpar_coeffs_prev->P_re[i][j][b]; @@ -2280,9 +2286,9 @@ static void ivas_spar_md_fill_invalid_bands( if ( valid_bands[b] == 0 ) { int16_t i_ts; - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( i_ts = 1; i_ts < MAX_PARAM_SPATIAL_SUBFRAMES; i_ts++ ) { diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 925fa5dfd7267acdcff3b351763d7a47f21b9f39..746315f1b381ff8837ea9fd97307562fd16799ad 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -509,37 +509,37 @@ typedef struct dirac_output_synthesis_params_structure typedef struct dirac_output_synthesis_state_structure { /* only pointer to local buffers */ - float *direct_responses; /* direct responses for DOA of current frame. Size: num_freq_bands*num_channels. */ + float *direct_responses; /* direct responses for DOA of current frame. Size: num_freq_bands*nchan. */ float *direct_responses_square; - float *diffuse_responses_square; /* squared diffuse responses. Size: num_channels. */ + float *diffuse_responses_square; /* squared diffuse responses. Size: nchan. */ /* only pointer to local buffers */ float *direct_power_factor; float *diffuse_power_factor; - float *proto_power_smooth; /* Smoothed power of the prototype signals. Size: num_freq_bands*num_channels. */ - float *proto_power_smooth_prev; /* Smoothed power of the prototype signals of the previous synthesis block. Size: num_freq_bands*num_channels. */ + float *proto_power_smooth; /* Smoothed power of the prototype signals. Size: num_freq_bands*nchan. */ + float *proto_power_smooth_prev; /* Smoothed power of the prototype signals of the previous synthesis block. Size: num_freq_bands*nchan. */ float *proto_power_diff_smooth; float *proto_power_diff_smooth_prev; /* only pointer to local buffers */ - float *proto_direct_buffer_f; /* Buffer for direct sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ - float *proto_diffuse_buffer_f; /* Buffer for diffuse sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ + float *proto_direct_buffer_f; /* Buffer for direct sound prototype signals. Size: 2*num_freq_bands*nchan*buffer_length (complex interleaved). */ + float *proto_diffuse_buffer_f; /* Buffer for diffuse sound prototype signals. Size: 2*num_freq_bands*nchan*buffer_length (complex interleaved). */ /* Output gain memories */ float *gains_dir_prev; /* Direct sound gains of current synthesis block. Size: num_freq_bands*num_channel. */ float *gains_diff_prev; /* Diffuse sound gains of previous synthesis block. Size: num_freq_bands*num_channel. */ /* only pointer to local buffers */ - float *cy_auto_dir_smooth; /* Target auto PSD of direct sound. Size: num_freq_bands*num_channels. */ - float *cy_cross_dir_smooth; /* Target cross PSD of direct sound. Size: num_freq_bands*num_channels. */ - float *cy_auto_diff_smooth; /* Target auto PSD of diffuse sound. Size: num_freq_bands*num_channels. */ + float *cy_auto_dir_smooth; /* Target auto PSD of direct sound. Size: num_freq_bands*nchan. */ + float *cy_cross_dir_smooth; /* Target cross PSD of direct sound. Size: num_freq_bands*nchan. */ + float *cy_auto_diff_smooth; /* Target auto PSD of diffuse sound. Size: num_freq_bands*nchan. */ /* PSD memories */ - float *cy_auto_dir_smooth_prev; /* Target auto PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */ - float *cy_cross_dir_smooth_prev; /* Target cross PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */ - float *cy_auto_diff_smooth_prev; /* Target auto PSD of diffuse sound of previous synthesis block. Size: num_freq_bands*num_channels. */ + float *cy_auto_dir_smooth_prev; /* Target auto PSD of direct sound of previous synthesis block. Size: num_freq_bands*nchan. */ + float *cy_cross_dir_smooth_prev; /* Target cross PSD of direct sound of previous synthesis block. Size: num_freq_bands*nchan. */ + float *cy_auto_diff_smooth_prev; /* Target auto PSD of diffuse sound of previous synthesis block. Size: num_freq_bands*nchan. */ const float *onset_filter; @@ -557,14 +557,14 @@ typedef struct dirac_output_synthesis_cov_state_structure float *diffuse_power_factor; /* only pointer to local buffers */ - float *direct_responses; /* direct responses for DOA of current frame. Size: num_freq_bands*num_channels. */ + float *direct_responses; /* direct responses for DOA of current frame. Size: num_freq_bands*nchan. */ float *direct_responses_square; - float *diffuse_responses_square; /* squared diffuse responses. Size: num_channels. */ + float *diffuse_responses_square; /* squared diffuse responses. Size: nchan. */ /* only pointer to local buffers */ - float *proto_direct_buffer_f; /* Buffer for direct sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ - float *proto_diffuse_buffer_f; /* Buffer for diffuse sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ - float *proto_power; /* Smoothed power of the prototype signals. Size: num_freq_bands*num_channels. */ + float *proto_direct_buffer_f; /* Buffer for direct sound prototype signals. Size: 2*num_freq_bands*nchan*buffer_length (complex interleaved). */ + float *proto_diffuse_buffer_f; /* Buffer for diffuse sound prototype signals. Size: 2*num_freq_bands*nchan*buffer_length (complex interleaved). */ + float *proto_power; /* Smoothed power of the prototype signals. Size: num_freq_bands*nchan. */ float *proto_power_diff; float *cx_old[CLDFB_NO_CHANNELS_MAX]; @@ -873,10 +873,10 @@ typedef struct ivas_spar_dec_lib_t int16_t AGC_flag; ivas_agc_dec_state_t *hAgcDec; PCA_DEC_STATE *hPCA; - int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; + int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; // VE2DB: could only hDirAC->dirac_to_spar_md_bands be used all the time, or it is defined as a pointer here? int16_t enc_param_start_band; int32_t core_nominal_brate; /* Nominal bitrate for core coding */ - int32_t i_subframe; + int32_t i_subframe; // VE2DB: change to int16_t #ifdef DEBUG_SBA_AUDIO_DUMP int16_t numOutChannels; @@ -1327,7 +1327,7 @@ typedef struct ivas_binaural_rendering_struct int16_t max_band; /* band upto which rendering is performed */ int16_t conv_band; /* band upto which convolution in cldfb domain is performed */ int16_t timeSlots; /* number of time slots of binaural renderer */ - int16_t nInChannels; /* number input channels */ + int16_t nchan_inp; /* number input channels */ int8_t render_lfe; /* Flag to render LFE in binaural rendering*/ IVAS_FORMAT ivas_format; /* format; corresponds to st_ivas->ivas_format, unless the signal gets transormed to a different domain for rendering */ @@ -1881,7 +1881,7 @@ typedef struct ivas_lfe_dec_data_structure typedef struct { int16_t max_num_channels; - int16_t num_channels; + int16_t nchan; float **channel_ptrs; int32_t sampling_rate; float gain; diff --git a/lib_dec/ivas_td_decorr.c b/lib_dec/ivas_td_decorr.c index 29b748e4c704dc0f352e0a813e3835db7306f3ce..e1daf78e6031eada43e092313a3aa2e90abf508a 100644 --- a/lib_dec/ivas_td_decorr.c +++ b/lib_dec/ivas_td_decorr.c @@ -91,8 +91,8 @@ const float ivas_three_pow_frac[IVAS_MAX_DECORR_APD_SECTIONS] = { * Local functions declaration *------------------------------------------------------------------------------------------*/ -static int16_t ivas_get_APD_filt_orders( const int16_t num_out_chans, const int32_t output_Fs, int16_t *APD_filt_orders ); -static ivas_error ivas_td_decorr_init( ivas_td_decorr_state_t *hTdDecorr, const int16_t num_out_chans, const int16_t ducking_flag ); +static int16_t ivas_get_APD_filt_orders( const int16_t nchan, const int32_t output_Fs, int16_t *APD_filt_orders ); +static ivas_error ivas_td_decorr_init( ivas_td_decorr_state_t *hTdDecorr, const int16_t nchan, const int16_t ducking_flag ); /*------------------------------------------------------------------------- @@ -109,11 +109,11 @@ ivas_error ivas_spar_td_decorr_dec_open( ) { int16_t i, j, len; - int16_t num_out_chans; + int16_t nchan; ivas_td_decorr_state_t *hCovState; ivas_error error; - num_out_chans = nchan_internal - 1; + nchan = nchan_internal - 1; error = IVAS_ERR_OK; @@ -128,9 +128,9 @@ ivas_error ivas_spar_td_decorr_dec_open( } set_f( hCovState->look_ahead_buf, 0, (int16_t) ( output_Fs * IVAS_DECORR_PARM_LOOKAHEAD_TAU ) ); - hCovState->num_apd_sections = ivas_get_APD_filt_orders( num_out_chans, output_Fs, hCovState->APD_filt_state[0].order ); + hCovState->num_apd_sections = ivas_get_APD_filt_orders( nchan, output_Fs, hCovState->APD_filt_state[0].order ); - for ( j = 0; j < num_out_chans; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( i = 0; i < hCovState->num_apd_sections; i++ ) { @@ -145,7 +145,7 @@ ivas_error ivas_spar_td_decorr_dec_open( } } - ivas_td_decorr_init( hCovState, num_out_chans, ducking_flag ); + ivas_td_decorr_init( hCovState, nchan, ducking_flag ); if ( ducking_flag ) { @@ -213,7 +213,7 @@ void ivas_spar_td_decorr_dec_close( *-----------------------------------------------------------------------------------------*/ static int16_t ivas_get_APD_filt_orders( - const int16_t num_out_chans, + const int16_t nchan, const int32_t output_Fs, int16_t *APD_filt_orders ) { @@ -221,7 +221,7 @@ static int16_t ivas_get_APD_filt_orders( int16_t num_apd_sections = 0; float sum_R, R[IVAS_MAX_DECORR_APD_SECTIONS]; - switch ( num_out_chans ) + switch ( nchan ) { case IVAS_TD_DECORR_OUT_1CH: case IVAS_TD_DECORR_OUT_2CH: @@ -277,13 +277,13 @@ static int16_t ivas_get_APD_filt_orders( static ivas_error ivas_td_decorr_init( ivas_td_decorr_state_t *hTdDecorr, - const int16_t num_out_chans, + const int16_t nchan, const int16_t ducking_flag ) { int16_t i, j; hTdDecorr->ducking_flag = ducking_flag; - hTdDecorr->num_apd_outputs = num_out_chans; + hTdDecorr->num_apd_outputs = nchan; for ( i = 0; i < hTdDecorr->num_apd_outputs; i++ ) { diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c index 3968e38974dba01378f418e4d059f28b74e07a00..659738feb93a9c81d6929cef2a7f17c6ed3f6968 100644 --- a/lib_dec/jbm_pcmdsp_apa.c +++ b/lib_dec/jbm_pcmdsp_apa.c @@ -110,7 +110,7 @@ struct apa_state_t uint16_t bad_frame_count; /* # frames before quality threshold is lowered */ uint16_t good_frame_count; /* # scaled frames */ - uint16_t num_channels; /* number of input/output channels */ + uint16_t nchan; /* number of input/output channels */ }; @@ -186,7 +186,7 @@ void apa_reset( ps->last_pitch = 0; ps->bad_frame_count = 0; ps->good_frame_count = 0; - ps->num_channels = 0; + ps->nchan = 0; return; } @@ -196,7 +196,7 @@ void apa_reset( bool apa_set_rate( apa_state_t *ps, const int32_t output_Fs, - const int16_t num_channels ) + const int16_t nchan ) { /* make sure pointer is valid */ if ( ps == NULL ) @@ -217,7 +217,7 @@ bool apa_set_rate( ps->rate = (uint16_t) output_Fs; /* set number of channels */ - ps->num_channels = num_channels; + ps->nchan = nchan; /* * several other parameters depend on the sampling rate @@ -232,7 +232,7 @@ bool apa_set_rate( /* in the order of a pitch, set to 160 samples at 16 kHz */ /* used for windowing and as the correlation length, i.e., */ /* the size of the template segment. */ - ps->l_seg = ( ps->rate / 100 ) * ps->num_channels; + ps->l_seg = ( ps->rate / 100 ) * ps->nchan; /* init Hann window */ /* Note: l_win < APA_BUF is required, which is assured */ @@ -244,17 +244,17 @@ bool apa_set_rate( /* set frame size */ /* set to 320 samples at 16 kHz */ - ps->l_frm = ( ps->rate / FRAMES_PER_SEC ) * ps->num_channels; + ps->l_frm = ( ps->rate / FRAMES_PER_SEC ) * ps->nchan; /* set minimum pitch */ /* set to 40 samples at 16 kHz */ /* (defines min change in number of samples, i.e., abs(l_in-l_out) >= p_min) */ - ps->p_min = ( ps->rate / 400 ) * ps->num_channels; + ps->p_min = ( ps->rate / 400 ) * ps->nchan; /* set search length */ /* must cover one pitch, set to 200 samples at 16 kHz */ /* (the resulting maximum pitch is then p_min+l_search = 240 samples at 16 kHz) */ - ps->l_search = ( ps->rate / 80 ) * ps->num_channels; + ps->l_search = ( ps->rate / 80 ) * ps->nchan; return 0; } @@ -669,18 +669,18 @@ static void get_scaling_quality( uint16_t i = 0; - for ( i = 0; i < ps->num_channels; i++ ) + for ( i = 0; i < ps->nchan; i++ ) { float energy; offset = 0; - pitch_cn = normalized_cross_correlation_self( signal, pitch + offset, offset, corr_len, ps->num_channels * 2, &pitch_energy ); + pitch_cn = normalized_cross_correlation_self( signal, pitch + offset, offset, corr_len, ps->nchan * 2, &pitch_energy ); if ( pitch_cn > 0.0f ) { /* calculate correlation for double pitch */ if ( 2 * pitch + offset + corr_len <= s_len ) { - double_pitch_cn = normalized_cross_correlation_self( signal, 2 * pitch + offset, offset, corr_len, ps->num_channels * 2, &double_pitch_energy ); + double_pitch_cn = normalized_cross_correlation_self( signal, 2 * pitch + offset, offset, corr_len, ps->nchan * 2, &double_pitch_energy ); } else { @@ -690,7 +690,7 @@ static void get_scaling_quality( /* calculate correlation for three/half pitch */ if ( ( 3 * pitch ) / 2 + offset + corr_len <= s_len ) { - three_halves_pitch_cn = normalized_cross_correlation_self( signal, ( 3 * pitch ) / 2 + offset, offset, corr_len, ps->num_channels * 2, &three_halves_pitch_energy ); + three_halves_pitch_cn = normalized_cross_correlation_self( signal, ( 3 * pitch ) / 2 + offset, offset, corr_len, ps->nchan * 2, &three_halves_pitch_energy ); } else { @@ -700,7 +700,7 @@ static void get_scaling_quality( /* calculate correlation for half pitch */ if ( pitch / 2 + offset + corr_len <= s_len ) { - half_pitch_cn = normalized_cross_correlation_self( signal, pitch / 2 + offset, offset, corr_len, ps->num_channels * 2, &half_pitch_energy ); + half_pitch_cn = normalized_cross_correlation_self( signal, pitch / 2 + offset, offset, corr_len, ps->nchan * 2, &half_pitch_energy ); } else { @@ -820,13 +820,13 @@ static bool logarithmic_search( coeff_max = -FLT_MAX; /* will always be overwritten with result of first correlation */ for ( i = s_start; i < s_start + inlen; i += css ) { - if ( ( wss == 1 ) && ( ps->num_channels == 1 ) ) + if ( ( wss == 1 ) && ( ps->nchan == 1 ) ) { coeff = cross_correlation_self( signal, i + offset, fixed_pos + offset, corr_len ); } else { - coeff = cross_correlation_subsampled_self( signal, i + offset, fixed_pos + offset, corr_len, wss * ps->num_channels ); + coeff = cross_correlation_subsampled_self( signal, i + offset, fixed_pos + offset, corr_len, wss * ps->nchan ); } /* update max corr */ @@ -929,10 +929,10 @@ static bool find_synch( /* pass last pitch to search function as prediction value */ *synch_pos = ps->last_pitch; - logarithmic_search( ps, in, s_start, s_len, offset, fixed_pos, corr_len, ps->wss, ps->css * ps->num_channels, synch_pos ); + logarithmic_search( ps, in, s_start, s_len, offset, fixed_pos, corr_len, ps->wss, ps->css * ps->nchan, synch_pos ); /* assert synch_pos is cleanly divisible by number of channels */ - assert( *synch_pos % ps->num_channels == 0 ); + assert( *synch_pos % ps->nchan == 0 ); *quality = 0; get_scaling_quality( ps, in, l_in, offset, corr_len, (uint16_t) abs( fixed_pos - *synch_pos ), energy, quality ); @@ -1035,7 +1035,7 @@ static bool shrink_frm( frm_in += l_frm; /* set search range */ - s_start = ( ps->p_min / ps->num_channels ) * ps->num_channels; + s_start = ( ps->p_min / ps->nchan ) * ps->nchan; s_end = s_start + ps->l_search; if ( ( s_end + l_seg ) >= l_frm ) { @@ -1055,7 +1055,7 @@ static bool shrink_frm( else { /* set to last valid element (i.e. element[len - 1] but note for stereo last element is last pair of samples) */ - xtract = s_end - ps->num_channels; + xtract = s_end - ps->nchan; } } else @@ -1065,7 +1065,7 @@ static bool shrink_frm( } /* assert synch_pos is cleanly divisible by number of channels */ - assert( xtract % ps->num_channels == 0 ); + assert( xtract % ps->nchan == 0 ); /* set frame overlappable - reset if necessary */ over = 1; @@ -1104,7 +1104,7 @@ static bool shrink_frm( { return 1; } - overlapAdd( frm_in, frm_in + xtract, frm_out, l_seg, ps->num_channels, ps->win + ps->l_halfwin, ps->win ); + overlapAdd( frm_in, frm_in + xtract, frm_out, l_seg, ps->nchan, ps->win + ps->l_halfwin, ps->win ); } else { @@ -1256,7 +1256,7 @@ static bool extend_frm( /* maximum scaling */ energy = -65; quality = 5; - xtract[n] = s_start + ps->num_channels; + xtract[n] = s_start + ps->nchan; } else { @@ -1264,7 +1264,7 @@ static bool extend_frm( findSynchResult = find_synch( ps, frm_in, 2 * l_frm, s_start, s_end - s_start, sync_start, l_seg, l_frm, &energy, &quality, &xtract[n] ); } /* assert synch_pos is cleanly divisible by number of channels */ - assert( xtract[n] % ps->num_channels == 0 ); + assert( xtract[n] % ps->nchan == 0 ); /* test for sufficient quality */ if ( quality < ( ps->targetQuality - ( ps->bad_frame_count * 0.1f ) + ( ps->good_frame_count * 0.2f ) ) ) @@ -1313,7 +1313,7 @@ static bool extend_frm( fadeOut = frm_in + l_frm + xtract[n - 1] + l_seg; fadeIn = frm_in + l_frm + xtract[n]; out = frm_out + ( n - 2 ) * l_seg; - overlapAdd( fadeOut, fadeIn, out, l_seg, ps->num_channels, ps->win + ps->l_halfwin, ps->win ); + overlapAdd( fadeOut, fadeIn, out, l_seg, ps->nchan, ps->win + ps->l_halfwin, ps->win ); } else { diff --git a/lib_dec/jbm_pcmdsp_apa.h b/lib_dec/jbm_pcmdsp_apa.h index 5cf4e7d8b6d4dc97f4694bdae5ac18241fa5411c..5297c799b9fbc7f2e4ccddf662005f87518d7ece 100644 --- a/lib_dec/jbm_pcmdsp_apa.h +++ b/lib_dec/jbm_pcmdsp_apa.h @@ -101,9 +101,9 @@ void apa_reset( apa_state_t *s ); * Will also set a number of other state variables that depend on the sampling rate. * @param[in,out] ps state * @param[in] output_Fs sample rate [Hz] - * @param[in] num_channels number of channels + * @param[in] nchan number of channels * @return 0 on success, 1 on failure */ -bool apa_set_rate( apa_state_t *ps, const int32_t output_Fs, const int16_t num_channels ); +bool apa_set_rate( apa_state_t *ps, const int32_t output_Fs, const int16_t nchan ); /*! Set scaling. * The scale is given in % and will be valid until changed again. diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 857099ed927bdd9976caa750bfdb3c407f0fb15d..9cb48c2f22589036a778344ec100f4ed83226342 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -369,6 +369,7 @@ ivas_error acelp_core_enc( nb_bits = 0; st->acelp_cfg.FEC_mode = 0; uc_two_stage_flag = 0; + if ( !nelp_mode && !ppp_mode ) { config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); @@ -551,7 +552,6 @@ ivas_error acelp_core_enc( return error; } - if ( st->hSC_VBR->bump_up ) /* PPP failed, bump up */ { /* restore memories of LSF quantizer and synthesis filter */ diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 491a9ab3586fa620fb63e12027a890e25baed9c8..25a15981839a6c49ad8a42ea55865a6c9872fb86 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -686,7 +686,7 @@ ivas_error ivas_cpe_enc( } { - float tmpF = ivas_total_brate / 1000.0f; + float tmpF = hCPE->element_brate / 1000.0f; dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "element_brate", 0, cpe_id, ENC ) ); } #endif diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 063ec02d8f29f10222c53f9a468c878267341702..95e6076ddef86995079ad522683cdcf359f82861 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -103,6 +103,7 @@ ivas_error ivas_dirac_enc_open( { return error; } + /* Allocate and initialize FB mixer handle */ if ( ( error = ivas_FB_mixer_open( &( hDirAC->hFbMixer ), input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) { @@ -125,12 +126,19 @@ ivas_error ivas_dirac_enc_open( for ( i = 0; i < DIRAC_MAX_ANA_CHANS; i++ ) { - hDirAC->sba_synchro_buffer[i] = (float *) count_malloc( hDirAC->num_samples_synchro_delay * sizeof( float ) ); + if ( ( st_ivas->hDirAC->sba_synchro_buffer[i] = (float *) count_malloc( st_ivas->hDirAC->num_samples_synchro_delay * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hDirAC synchro buffer\n" ) ); + } set_zero( hDirAC->sba_synchro_buffer[i], hDirAC->num_samples_synchro_delay ); } } else { +#ifdef SBA_BITRATE_SWITCHING + hDirAC->num_samples_synchro_delay = 0; +#endif + for ( i = 0; i < DIRAC_MAX_ANA_CHANS; i++ ) { hDirAC->sba_synchro_buffer[i] = NULL; @@ -340,6 +348,7 @@ void ivas_dirac_enc( SBA_MODE_DIRAC #endif ); + /* encode parameters */ if ( sba_planar || hQMetaData->useLowerRes ) { diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 75ffc5212d31b145d2b447f752d908364fb6efed..71972008d9510575d3d0376ca11ead0268a58caa 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -55,7 +55,7 @@ ivas_error ivas_enc( const int16_t n_samples /* i : number of input samples */ ) { - int16_t i, n, input_frame, n_samples_chan, nchan_inp; + int16_t i, ch, input_frame, n_samples_chan, nchan_inp; int32_t input_Fs; IVAS_FORMAT ivas_format; ENCODER_CONFIG_HANDLE hEncoderConfig; @@ -90,8 +90,8 @@ ivas_error ivas_enc( * convert 'short' input data to 'float' *----------------------------------------------------------------*/ - n = 0; - while ( n < nchan_inp ) + ch = 0; + while ( ch < nchan_inp ) { #ifdef DEBUG_MODE_LFE if ( n == LFE_CHANNEL ) @@ -99,23 +99,23 @@ ivas_error ivas_enc( int16_t tmp[L_FRAME48k]; for ( i = 0; i < n_samples_chan; i++ ) { - tmp[i] = data[i * nchan_inp + n]; + tmp[i] = data[i * nchan_inp + nch]; } dbgwrite( tmp, sizeof( int16_t ), n_samples_chan, 1, "./lfe_chan_in.raw" ); } #endif for ( i = 0; i < n_samples_chan; i++ ) { - data_f[n][i] = (float) data[i * nchan_inp + n]; + data_f[ch][i] = (float) data[i * nchan_inp + ch]; } - n++; + ch++; } if ( n_samples_chan < input_frame ) { - for ( n = 0; n < nchan_inp; n++ ) + for ( ch = 0; ch < nchan_inp; ch++ ) { - set_f( data_f[n] + n_samples_chan, 0.0f, input_frame - n_samples_chan ); + set_f( data_f[ch] + n_samples_chan, 0.0f, input_frame - n_samples_chan ); } } @@ -127,10 +127,10 @@ ivas_error ivas_enc( * HP filtering *----------------------------------------------------------------*/ - n = getNumChanAnalysis( st_ivas ); + ch = getNumChanAnalysis( st_ivas ); #ifndef DEBUG_SPAR_BYPASS_EVS_CODEC /* bypass EVS coding in float precision, emulating EVS encoder/decoder delay */ - for ( i = 0; i < n; i++ ) + for ( i = 0; i < ch; i++ ) { if ( !( ivas_format == MC_FORMAT && i == LFE_CHANNEL ) ) /*TODO: is the HPF needed for LFE channel? */ { @@ -189,7 +189,9 @@ ivas_error ivas_enc( /* SBA/MASA configuration */ if ( ivas_format == SBA_FORMAT ) { +#ifndef SBA_BITRATE_SWITCHING if ( st_ivas->sba_mode == SBA_MODE_DIRAC ) +#endif { if ( ( error = ivas_sba_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) { @@ -232,6 +234,7 @@ ivas_error ivas_enc( 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 ); } + } else if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { @@ -364,6 +367,7 @@ ivas_error ivas_enc( float tmpF = ivas_total_brate / 1000.0f; dbgwrite( &tmpF, sizeof( float ), 1, input_frame, "res/ivas_total_brate" ); } + dbgwrite( &st_ivas->nchan_transport, sizeof( int16_t ), 1, input_frame, "res/nchan_transport" ); #endif wmops_sub_end(); diff --git a/lib_enc/ivas_enc_cov_handler.c b/lib_enc/ivas_enc_cov_handler.c index 907b8c5908b0b2b03423107c664a35d26db229f0..c49154e4a635f44134464f020bc2c80a584035b3 100644 --- a/lib_enc/ivas_enc_cov_handler.c +++ b/lib_enc/ivas_enc_cov_handler.c @@ -156,7 +156,7 @@ void ivas_enc_cov_handler_process( const int16_t end_band #ifdef SBA_SPAR_HARM , - const int16_t num_ch, + const int16_t nchan, const int16_t dtx_vad, const int16_t transient_det #endif @@ -169,15 +169,15 @@ void ivas_enc_cov_handler_process( dtx_cov_flag = ( dtx_vad == 1 ) ? 0 : 1; #else ivas_cov_smooth_in_buf_t pCov_in_buf; - int16_t num_ch = pIn_buf->num_ch; + int16_t nchan = pIn_buf->nchan; - pCov_in_buf.num_ch = num_ch; + pCov_in_buf.nchan = nchan; #endif #ifdef SBA_SPAR_HARM - ivas_band_cov( ppIn_FR_real, ppIn_FR_imag, num_ch, hCovEnc->num_bins, + ivas_band_cov( ppIn_FR_real, ppIn_FR_imag, nchan, hCovEnc->num_bins, #else - ivas_band_cov( pIn_buf->ppIn_FR_real, pIn_buf->ppIn_FR_imag, pIn_buf->num_ch, hCovEnc->num_bins, + ivas_band_cov( pIn_buf->ppIn_FR_real, pIn_buf->ppIn_FR_imag, pIn_buf->nchan, hCovEnc->num_bins, #endif pFb->fb_bin_to_band.short_stride, pFb->fb_bin_to_band.pp_short_stride_bin_to_band, @@ -196,9 +196,9 @@ void ivas_enc_cov_handler_process( fid = fopen( "cov_real.txt", "wt" ); } - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = start_band; k < end_band; k++ ) { @@ -209,9 +209,9 @@ void ivas_enc_cov_handler_process( fprintf( fid, "\n" ); } #endif - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { #ifndef SBA_SPAR_HARM pCov_in_buf.cov_real[i][j] = cov_real[i][j]; @@ -221,7 +221,7 @@ void ivas_enc_cov_handler_process( } #ifdef SBA_SPAR_HARM - ivas_cov_smooth_process( hCovEnc->pCov_state, cov_real, pFb, start_band, end_band, num_ch, transient_det ); + ivas_cov_smooth_process( hCovEnc->pCov_state, cov_real, pFb, start_band, end_band, nchan, transient_det ); #else ivas_cov_smooth_process( hCovEnc->pCov_state, &pCov_in_buf, pFb, start_band, end_band ); #endif @@ -232,9 +232,9 @@ void ivas_enc_cov_handler_process( if ( pIn_buf->dtx_cov_flag == 0 ) #endif { - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { #ifdef SBA_SPAR_HARM mvr2r( cov_real[i][j], hCovEnc->pCov_dtx_state->pPrior_cov_real[i][j], pFb->filterbank_num_bands ); @@ -257,11 +257,11 @@ void ivas_enc_cov_handler_process( #endif { #ifdef SBA_SPAR_HARM - ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, cov_dtx_real, pFb, start_band, end_band, num_ch, transient_det ); + ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, cov_dtx_real, pFb, start_band, end_band, nchan, transient_det ); #else - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { pCov_in_buf.cov_real[i][j] = cov_dtx_real[i][j]; } @@ -277,11 +277,11 @@ void ivas_enc_cov_handler_process( if ( hCovEnc->prior_dtx_present == 0 ) { #ifdef SBA_SPAR_HARM - ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, cov_dtx_real, pFb, start_band, end_band, num_ch, transient_det ); + ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, cov_dtx_real, pFb, start_band, end_band, nchan, transient_det ); #else - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { pCov_in_buf.cov_real[i][j] = cov_dtx_real[i][j]; } @@ -294,9 +294,9 @@ void ivas_enc_cov_handler_process( } else { - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { mvr2r( hCovEnc->pCov_dtx_state->pPrior_cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); } diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index af7a48a80b2b585d3f26fd34f4a5611436ccb60b..396a9a5ecd9fea04803915e599ed32ff1ac5ae90 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -53,19 +53,19 @@ * Local function prototypes *------------------------------------------------------------------------*/ -static void ivas_param_mc_dmx( PARAM_MC_ENC_HANDLE hParamMC, float data_f[][L_FRAME48k], float data_dmx[][L_FRAME48k], const int16_t input_frame, const int16_t nchan_input, const int16_t nchan_transport ); +static void ivas_param_mc_dmx( PARAM_MC_ENC_HANDLE hParamMC, float data_f[][L_FRAME48k], float data_dmx[][L_FRAME48k], const int16_t input_frame, const int16_t nchan_inp, const int16_t nchan_transport ); -static void ivas_param_mc_param_est_enc( PARAM_MC_ENC_HANDLE hParamMC, float input_frame_t[][L_FRAME48k], float Cy_sum[][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], float Cx_sum[][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], const int16_t input_frame, const int16_t nchan_input, const int16_t nchan_transport ); +static void ivas_param_mc_param_est_enc( PARAM_MC_ENC_HANDLE hParamMC, float input_frame_t[][L_FRAME48k], float Cy_sum[][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], float Cx_sum[][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], const int16_t input_frame, const int16_t nchan_inp, const int16_t nchan_transport ); static void ivas_param_mc_parameter_quantizer( const float *x, const int16_t L, const int16_t sz_quantizer, const float *quantizer, int16_t *quant_idx, float *y ); static void ivas_param_mc_transient_detection( PARAM_MC_ENC_HANDLE hParamMC, TRAN_DET_HANDLE hTranDet, int16_t *bAttackPresent, int16_t *attackIdx ); -static void ivas_param_mc_enc_find_icc_map( PARAM_MC_ENC_HANDLE hParamMC, float Cx_sum[][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], float Cy_sum[][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], float ILD_q[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_SZ_ILD_MAP], const int16_t nchan_input, const int16_t nchan_transport ); +static void ivas_param_mc_enc_find_icc_map( PARAM_MC_ENC_HANDLE hParamMC, float Cx_sum[][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], float Cy_sum[][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], float ILD_q[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_SZ_ILD_MAP], const int16_t nchan_inp, const int16_t nchan_transport ); -static void ivas_param_mc_quantize_iccs( PARAM_MC_ENC_HANDLE hParamMC, float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], const int16_t freq_idx, const int16_t nchan_input, int16_t *ICC_idx_out ); +static void ivas_param_mc_quantize_iccs( PARAM_MC_ENC_HANDLE hParamMC, float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], const int16_t freq_idx, const int16_t nchan_inp, int16_t *ICC_idx_out ); -static void ivas_param_mc_quantize_ilds( PARAM_MC_ENC_HANDLE hParamMC, float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], float Cx[PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], const int16_t freq_idx, const int16_t nchan_input, const int16_t nchan_transport, int16_t *ILD_idx_out, float ILD_q[PARAM_MC_SZ_ILD_MAP] ); +static void ivas_param_mc_quantize_ilds( PARAM_MC_ENC_HANDLE hParamMC, float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], float Cx[PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], const int16_t freq_idx, const int16_t nchan_inp, const int16_t nchan_transport, int16_t *ILD_idx_out, float ILD_q[PARAM_MC_SZ_ILD_MAP] ); static void ivas_param_mc_write_bs( const PARAM_MC_ENC_HANDLE hParamMC, int16_t *ILD_idx, int16_t *ICC_idx, uint16_t bit_buffer[PARAM_MC_MAX_BITS], int16_t *bit_pos ); @@ -430,27 +430,28 @@ static void ivas_param_mc_dmx( float data_f[][L_FRAME48k], /* i : Input frame */ float data_dmx[][L_FRAME48k], /* o : Down mixed frame */ const int16_t input_frame, /* i : Input frame length */ - const int16_t nchan_input, /* i : number of input channels */ + const int16_t nchan_inp, /* i : number of input channels */ const int16_t nchan_transport /* i : number of transport channels */ ) { int16_t i; const int16_t *idx; - int16_t dmx_ch; - int16_t inp_ch; + int16_t ch_dmx, ch_inp; const float *p_dmx_fac; + float *dmx_sample; idx = Param_MC_index; for ( i = 0; i < input_frame; i++ ) { p_dmx_fac = hParamMC->dmx_factors; - for ( dmx_ch = 0; dmx_ch < nchan_transport; dmx_ch++ ) + for ( ch_dmx = 0; ch_dmx < nchan_transport; ch_dmx++ ) { - float *dmx_sample = &data_dmx[idx[dmx_ch]][i]; + dmx_sample = &data_dmx[idx[ch_dmx]][i]; *dmx_sample = 0.0f; - for ( inp_ch = 0; inp_ch < nchan_input; inp_ch++ ) + + for ( ch_inp = 0; ch_inp < nchan_inp; ch_inp++ ) { - ( *dmx_sample ) += data_f[idx[inp_ch]][i] * ( *( p_dmx_fac++ ) ); + ( *dmx_sample ) += data_f[idx[ch_inp]][i] * ( *( p_dmx_fac++ ) ); } } } @@ -472,7 +473,7 @@ static void ivas_param_mc_param_est_enc( float Cy_sum[][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], /* o : Covariance matrix for the original frame */ float Cx_sum[][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], /* o : Covariance matrix for the downmixed frame */ const int16_t input_frame, /* i : Input frame length */ - const int16_t nchan_input, /* i : number of input channels */ + const int16_t nchan_inp, /* i : number of input channels */ const int16_t nchan_transport /* i : number of transport channels */ ) { @@ -525,7 +526,7 @@ static void ivas_param_mc_param_est_enc( } /* Copy current frame to memory for delay compensation */ - for ( i = 0; i < nchan_input; i++ ) + for ( i = 0; i < nchan_inp; i++ ) { idx_ls = map_ls[i]; pcm_in[i] = &input_frame_t[idx_ls][0]; @@ -536,7 +537,7 @@ static void ivas_param_mc_param_est_enc( for ( ts = 0; ts < start_ts; ts++ ) { ivas_fb_mixer_update_prior_input( hParamMC->hFbMixer, pcm_in, l_ts ); - for ( i = 0; i < nchan_input; i++ ) + for ( i = 0; i < nchan_inp; i++ ) { pcm_in[i] += l_ts; } @@ -546,7 +547,7 @@ static void ivas_param_mc_param_est_enc( { ivas_fb_mixer_get_windowed_fr( hParamMC->hFbMixer, pcm_in, p_slot_frame_f_real, p_slot_frame_f_imag, l_ts, 2 * l_ts ); ivas_fb_mixer_update_prior_input( hParamMC->hFbMixer, pcm_in, l_ts ); - for ( i = 0; i < nchan_input; i++ ) + for ( i = 0; i < nchan_inp; i++ ) { pcm_in[i] += l_ts; } @@ -566,7 +567,7 @@ static void ivas_param_mc_param_est_enc( { dmx_real[ch_idx1] = 0.0f; dmx_imag[ch_idx1] = 0.0f; - for ( inp_ch = 0; inp_ch < nchan_input; inp_ch++ ) + for ( inp_ch = 0; inp_ch < nchan_inp; inp_ch++ ) { dmx_real[ch_idx1] += slot_frame_f_real[inp_ch][cur_cldfb_band] * ( *p_dmx_fac ); dmx_imag[ch_idx1] += slot_frame_f_imag[inp_ch][cur_cldfb_band] * ( *p_dmx_fac ); @@ -591,9 +592,9 @@ static void ivas_param_mc_param_est_enc( } /* Cy for input channels */ - for ( ch_idx1 = 0; ch_idx1 < nchan_input; ++ch_idx1 ) + for ( ch_idx1 = 0; ch_idx1 < nchan_inp; ++ch_idx1 ) { - for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_input; ++ch_idx2 ) + for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_inp; ++ch_idx2 ) { a = slot_frame_f_real[ch_idx1][cur_cldfb_band]; b = slot_frame_f_imag[ch_idx1][cur_cldfb_band]; @@ -624,7 +625,7 @@ static void ivas_param_mc_param_est_enc( dmx_real[ch_idx1] = 0.0f; dmx_imag[ch_idx1] = 0.0f; - for ( inp_ch = 0; inp_ch < nchan_input; inp_ch++ ) + for ( inp_ch = 0; inp_ch < nchan_inp; inp_ch++ ) { dmx_real[ch_idx1] += slot_frame_f_real[inp_ch][cur_cldfb_band] * ( *p_dmx_fac ); dmx_imag[ch_idx1] += slot_frame_f_imag[inp_ch][cur_cldfb_band] * ( *p_dmx_fac ); @@ -648,9 +649,9 @@ static void ivas_param_mc_param_est_enc( } /* Cy for input channels */ - for ( ch_idx1 = 0; ch_idx1 < nchan_input; ++ch_idx1 ) + for ( ch_idx1 = 0; ch_idx1 < nchan_inp; ++ch_idx1 ) { - for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_input; ++ch_idx2 ) + for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_inp; ++ch_idx2 ) { a = slot_frame_f_real[ch_idx1][cur_cldfb_band]; b = slot_frame_f_imag[ch_idx1][cur_cldfb_band]; @@ -671,7 +672,7 @@ static void ivas_param_mc_param_est_enc( { for ( cur_param_band = PARAM_MC_MAX_BAND_LFE; cur_param_band < hParamMC->max_param_band_abs_cov; cur_param_band++ ) { - for ( ch_idx1 = 0; ch_idx1 < nchan_input; ++ch_idx1 ) + for ( ch_idx1 = 0; ch_idx1 < nchan_inp; ++ch_idx1 ) { Cy_sum[cur_param_band][hParamMC->lfe_index][ch_idx1] = 0.0f; Cy_sum[cur_param_band][ch_idx1][hParamMC->lfe_index] = 0.0f; @@ -682,7 +683,7 @@ static void ivas_param_mc_param_est_enc( for ( ; cur_param_band < num_parameter_bands; cur_param_band++ ) { - for ( ch_idx1 = 0; ch_idx1 < nchan_input; ++ch_idx1 ) + for ( ch_idx1 = 0; ch_idx1 < nchan_inp; ++ch_idx1 ) { Cy_sum[cur_param_band][hParamMC->lfe_index][ch_idx1] = 0.0f; Cy_sum[cur_param_band][ch_idx1][hParamMC->lfe_index] = 0.0f; @@ -704,9 +705,9 @@ static void ivas_param_mc_param_est_enc( } } - for ( ch_idx1 = 0; ch_idx1 < nchan_input; ++ch_idx1 ) + for ( ch_idx1 = 0; ch_idx1 < nchan_inp; ++ch_idx1 ) { - for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_input; ++ch_idx2 ) + for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_inp; ++ch_idx2 ) { Cy_sum[cur_param_band - 1][ch_idx1][ch_idx2] += Cy_sum[cur_param_band][ch_idx1][ch_idx2]; Cy_sum_imag[cur_param_band - 1][ch_idx1][ch_idx2] += Cy_sum_imag[cur_param_band][ch_idx1][ch_idx2]; @@ -726,9 +727,9 @@ static void ivas_param_mc_param_est_enc( } } - for ( ch_idx1 = 0; ch_idx1 < nchan_input; ++ch_idx1 ) + for ( ch_idx1 = 0; ch_idx1 < nchan_inp; ++ch_idx1 ) { - for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_input; ++ch_idx2 ) + for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_inp; ++ch_idx2 ) { Cy_sum[cur_param_band - 1][ch_idx1][ch_idx2] += Cy_sum[cur_param_band][ch_idx1][ch_idx2]; } @@ -756,9 +757,9 @@ static void ivas_param_mc_param_est_enc( } /* Cy for transport channels */ - for ( ch_idx1 = 0; ch_idx1 < nchan_input; ch_idx1++ ) + for ( ch_idx1 = 0; ch_idx1 < nchan_inp; ch_idx1++ ) { - for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_input; ch_idx2++ ) + for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_inp; ch_idx2++ ) { real_part = Cy_sum[cur_param_band][ch_idx1][ch_idx2]; imag_part = Cy_sum_imag[cur_param_band][ch_idx1][ch_idx2]; @@ -794,7 +795,7 @@ static void ivas_param_mc_enc_find_icc_map( float Cx_sum[][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], /* i : Covariance matrix for the downmixed frame */ float Cy_sum[][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], /* i : Covariance matrix for the original frame */ float ILD_q[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_SZ_ILD_MAP], /* i : quantized ILDs */ - const int16_t nchan_input, /* i : number of input channels */ + const int16_t nchan_inp, /* i : number of input channels */ const int16_t nchan_transport /* i : number of transport channels */ ) { @@ -824,7 +825,7 @@ static void ivas_param_mc_enc_find_icc_map( icc_map_size_wo_lfe = hParamMC->hMetadataPMC.icc_mapping_conf->icc_map_size_wo_lfe; icc_map_size = hParamMC->hMetadataPMC.icc_mapping_conf->icc_map_size_lfe; - set_zero( Cy_band, nchan_input * nchan_input ); + set_zero( Cy_band, nchan_inp * nchan_inp ); /* Estimate the target covariance like in the decoder using the * already available qunantised ICLDs */ @@ -842,18 +843,18 @@ static void ivas_param_mc_enc_find_icc_map( } /* get estimated Cy from Cx and proto matrix */ - matrix_product( hParamMC->dmx_factors, nchan_input, nchan_transport, 0, + matrix_product( hParamMC->dmx_factors, nchan_inp, nchan_transport, 0, Cx_band, nchan_transport, nchan_transport, 0, mat_mult_buffer1 ); - matrix_product( mat_mult_buffer1, nchan_input, nchan_transport, 0, - hParamMC->dmx_factors, nchan_input, nchan_transport, 1, + matrix_product( mat_mult_buffer1, nchan_inp, nchan_transport, 0, + hParamMC->dmx_factors, nchan_inp, nchan_transport, 1, Cproto_band ); set_zero( Nrqq, MAX_OUTPUT_CHANNELS ); /*get back Nrg*/ - for ( k = 0; k < nchan_input; k++ ) + for ( k = 0; k < nchan_inp; k++ ) { float ref_ener = 0.0f; int16_t ref_channel_cnt; @@ -868,51 +869,51 @@ static void ivas_param_mc_enc_find_icc_map( } /* apply quantized ICLDs in the estimated covariance */ - for ( k = 0; k < nchan_input; k++ ) + for ( k = 0; k < nchan_inp; k++ ) { - a[k] = sqrtf( Nrqq[k] ) / ( sqrtf( Cproto_band[k + nchan_input * k] ) + EPSILON ); - v_multc( Cproto_band + k * nchan_input, a[k], Cproto_band + k * nchan_input, nchan_input ); + a[k] = sqrtf( Nrqq[k] ) / ( sqrtf( Cproto_band[k + nchan_inp * k] ) + EPSILON ); + v_multc( Cproto_band + k * nchan_inp, a[k], Cproto_band + k * nchan_inp, nchan_inp ); } - for ( k = 0; k < nchan_input; k++ ) + for ( k = 0; k < nchan_inp; k++ ) { int16_t l; float *Cyp = Cproto_band + k; float ap = a[k]; - for ( l = 0; l < nchan_input; l++ ) + for ( l = 0; l < nchan_inp; l++ ) { ( *Cyp ) *= ap; - Cyp += nchan_input; + Cyp += nchan_inp; } } /* transfer Cy_sum band to columnwise matrix */ - for ( ch_idx1 = 0; ch_idx1 < nchan_input; ++ch_idx1 ) + for ( ch_idx1 = 0; ch_idx1 < nchan_inp; ++ch_idx1 ) { - for ( ch_idx2 = 0; ch_idx2 < nchan_input; ++ch_idx2 ) + for ( ch_idx2 = 0; ch_idx2 < nchan_inp; ++ch_idx2 ) { Cy_band[ch_idx1 + nchan_transport * ch_idx2] = Cy_sum[cur_param_band][ch_idx1][ch_idx2]; } } /* apply quantized ICLDs on the input covariance */ - for ( k = 0; k < nchan_input; k++ ) + for ( k = 0; k < nchan_inp; k++ ) { - a[k] = sqrtf( Nrqq[k] ) / ( sqrtf( Cy_band[k + nchan_input * k] ) + EPSILON ); - v_multc( Cy_band + k * nchan_input, a[k], Cy_band + k * nchan_input, nchan_input ); + a[k] = sqrtf( Nrqq[k] ) / ( sqrtf( Cy_band[k + nchan_inp * k] ) + EPSILON ); + v_multc( Cy_band + k * nchan_inp, a[k], Cy_band + k * nchan_inp, nchan_inp ); } - for ( k = 0; k < nchan_input; k++ ) + for ( k = 0; k < nchan_inp; k++ ) { int16_t l; float *Cyp = Cy_band + k; float ap = a[k]; - for ( l = 0; l < nchan_input; l++ ) + for ( l = 0; l < nchan_inp; l++ ) { ( *Cyp ) *= ap; - Cyp += nchan_input; + Cyp += nchan_inp; } } @@ -921,7 +922,7 @@ static void ivas_param_mc_enc_find_icc_map( { int16_t idx0 = hParamMC->hMetadataPMC.icc_map_full[0][map_idx]; int16_t idx1 = hParamMC->hMetadataPMC.icc_map_full[1][map_idx]; - mapped_error[map_idx] += fabsf( Cproto_band[idx0 + idx1 * nchan_input] - Cy_band[idx0 + idx1 * nchan_input] ); + mapped_error[map_idx] += fabsf( Cproto_band[idx0 + idx1 * nchan_inp] - Cy_band[idx0 + idx1 * nchan_inp] ); } } } @@ -1018,7 +1019,7 @@ static void ivas_param_mc_quantize_ilds( float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], /* i : Covariance matrix of the input */ float Cx[PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], /* i : Covariance matrix of the dmx */ const int16_t freq_idx, /* i : frequency index being processed */ - const int16_t nchan_input, /* i : number of input channels */ + const int16_t nchan_inp, /* i : number of input channels */ const int16_t nchan_transport, /* i : number of transport channels */ int16_t *ILD_idx_out, /* o : ILD indices */ float ILD_q[PARAM_MC_SZ_ILD_MAP] /* o : Quanzited ILD matrix */ @@ -1040,7 +1041,7 @@ static void ivas_param_mc_quantize_ilds( set_zero( Nrg, MAX_CICP_CHANNELS ); set_zero( ILD, PARAM_MC_SZ_ILD_MAP ); - Ny = nchan_input; + Ny = nchan_inp; h_ild_mapping = hParamMC->hMetadataPMC.ild_mapping_conf; ild_map_size = hParamMC->hMetadataPMC.ild_mapping_conf->ild_map_size_lfe; @@ -1159,7 +1160,7 @@ static void ivas_param_mc_quantize_iccs( PARAM_MC_ENC_HANDLE hParamMC, /* i/o: Parametric MC encoder handle */ float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], /* i : Covariance matrix of the input */ const int16_t freq_idx, /* i : frequency index being processed */ - const int16_t nchan_input, /* i : number of input channels */ + const int16_t nchan_inp, /* i : number of input channels */ int16_t *ICC_idx_out /* o : quantizer indices */ ) { @@ -1179,7 +1180,7 @@ static void ivas_param_mc_quantize_iccs( set_zero( ICC_vect, PARAM_MC_SZ_ICC_MAP ); set_zero( ICC_vect_q, PARAM_MC_SZ_ICC_MAP ); - Ny = nchan_input; + Ny = nchan_inp; /* Downsampling */ if ( ( hParamMC->hMetadataPMC.bAttackPresent == 0 ) && ( hParamMC->hMetadataPMC.param_frame_idx != hParamMC->hMetadataPMC.coding_band_mapping[freq_idx] ) ) diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 18c3b93fb91f2a1b60806cc9a1cd82e6a20494bd..07825a612b92bf6db81138c4ddcb06914cbdcf91 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -332,6 +332,13 @@ ivas_error mct_enc_reconfigure( hMCT->nchan_out_woLFE = st_ivas->hEncoderConfig->nchan_inp - 1; /* LFE channel is coded separately */ hMCT->num_lfe = TRUE; } +#ifdef SBA_BITRATE_SWITCHING // VE2FhG: TBV + else if ( ivas_format == SBA_FORMAT ) + { + hMCT->nchan_out_woLFE = st_ivas->nchan_transport; + hMCT->num_lfe = FALSE; + } +#else else if ( ivas_format == SBA_FORMAT && st_ivas->hDirAC ) // VE: this condition to be reviewed together with the following one { hMCT->nchan_out_woLFE = ivas_get_sba_num_TCs( ivas_total_brate, st_ivas->sba_analysis_order ); @@ -342,6 +349,7 @@ ivas_error mct_enc_reconfigure( hMCT->nchan_out_woLFE = ivas_sba_get_nchan( st_ivas->sba_analysis_order, st_ivas->hEncoderConfig->sba_planar ); hMCT->num_lfe = FALSE; } +#endif else { assert( !"IVAS format currently not supported for MCT" ); @@ -468,6 +476,14 @@ ivas_error mct_enc_reconfigure( } } +#ifdef SBA_BITRATE_SWITCHING + hMCT->hbr_mct = 0; + if ( st_ivas->sba_mode == SBA_MODE_SPAR && ivas_total_brate >= IVAS_256k ) + { + hMCT->hbr_mct = 1; + } +#endif + return IVAS_ERR_OK; } diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index d4c7c70b2187eff07bbc58daccca0228300699fc..e3bcc251a5afa842861f6d9096faaa6e609c4d6e 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -105,19 +105,25 @@ ivas_error ivas_sba_enc_reconfigure( ) { int16_t nSCE_old, nCPE_old, nchan_transport_old; + #ifndef CORECODER_BITRATE_SWITCHING int16_t n, sce_id, cpe_id; Indice *ind_list_metadata; #endif int32_t ivas_total_brate; + ENCODER_CONFIG_HANDLE hEncoderConfig; ivas_error error; + hEncoderConfig = st_ivas->hEncoderConfig; error = IVAS_ERR_OK; - ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + ivas_total_brate = hEncoderConfig->ivas_total_brate; - if ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) + if ( ivas_total_brate != hEncoderConfig->last_ivas_total_brate ) { + DIRAC_ENC_HANDLE hDirAC = st_ivas->hDirAC; + SPAR_ENC_HANDLE hSpar; + nchan_transport_old = st_ivas->nchan_transport; nCPE_old = st_ivas->nCPE; nSCE_old = st_ivas->nSCE; @@ -125,10 +131,165 @@ ivas_error ivas_sba_enc_reconfigure( ind_list_metadata = NULL; #endif - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, hEncoderConfig->sba_order ); + +#ifdef SBA_BITRATE_SWITCHING + st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); + + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) + { + if ( st_ivas->hSpar == NULL ) + { + if ( ( error = ivas_spar_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + // VE: TBV - populate 'hSpar->hFrontVad' with 'hCoreCoder[0]' instead of resetting it to init-state? + } + + 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 ); + } + else + { + ivas_spar_enc_close( st_ivas->hSpar, hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp ); + st_ivas->hSpar = NULL; + } + + hSpar = st_ivas->hSpar; + + if ( st_ivas->nchan_transport == 1 ) + { + hEncoderConfig->element_mode_init = IVAS_SCE; + } + else + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + + /* FB mixer handle */ + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) + { + // VE: TBV whether 'hFbMixer' can be reused + if ( hDirAC->hFbMixer != NULL ) + { + ivas_FB_mixer_close( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs ); + hDirAC->hFbMixer = NULL; + } + + { + // VE: dirty patch -> reconfiguration of SPAR MD, TD_decorr, FbMixer modules should be used instead !! + + IVAS_FB_CFG *fb_cfg; + int16_t nchan_internal, sba_order_internal; + int16_t table_idx, active_w_mixing; + + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + nchan_internal = ivas_sba_get_nchan_metadata( sba_order_internal ); + + /* Covar. State handle */ + ivas_spar_covar_enc_close( &hSpar->hCovEnc, hSpar->hFbMixer->fb_cfg->nchan_inp ); + + /* MD handle */ + ivas_spar_md_enc_close( &hSpar->hMdEnc ); + + if ( ( error = ivas_spar_md_enc_open( &( hSpar->hMdEnc ), hEncoderConfig, sba_order_internal ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* FB mixer handle */ + ivas_FB_mixer_close( &hSpar->hFbMixer, hEncoderConfig->input_Fs ); - ivas_dirac_enc_reconfigure( st_ivas ); + table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order_internal, SPAR_CONFIG_BW, NULL, NULL ); + active_w_mixing = ivas_spar_br_table_consts[table_idx].active_w; + if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_SPAR, nchan_internal, st_ivas->nchan_transport, active_w_mixing, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + fb_cfg->remix_order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; + if ( ( error = ivas_FB_mixer_open( &( hSpar->hFbMixer ), hEncoderConfig->input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* Covar. State handle */ + if ( ( error = ivas_spar_covar_enc_open( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, hEncoderConfig->input_Fs, nchan_internal ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else + { + if ( hDirAC->hFbMixer == NULL ) + { + IVAS_FB_CFG *fb_cfg; + + if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_DIRAC, DIRAC_MAX_ANA_CHANS, 0, 0, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* Allocate and initialize FB mixer handle */ + if ( ( error = ivas_FB_mixer_open( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + + /* initalize delay for SPAR/DirAC delay synchronization */ + if ( st_ivas->sba_mode == SBA_MODE_DIRAC ) + { + int16_t n; + + if ( hDirAC->num_samples_synchro_delay == 0 ) + { + hDirAC->num_samples_synchro_delay = NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS ); + + for ( n = 0; n < DIRAC_MAX_ANA_CHANS; n++ ) + { + if ( ( hDirAC->sba_synchro_buffer[n] = (float *) count_malloc( hDirAC->num_samples_synchro_delay * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hDirAC synchro buffer\n" ) ); + } + set_zero( hDirAC->sba_synchro_buffer[n], hDirAC->num_samples_synchro_delay ); + } + for ( ; n < DIRAC_MAX_ANA_CHANS; n++ ) + { + hDirAC->sba_synchro_buffer[n] = NULL; + } + } + } + else + { + for ( int16_t n = 0; n < DIRAC_MAX_ANA_CHANS; n++ ) + { + if ( hDirAC->sba_synchro_buffer[n] != NULL ) + { + count_free( hDirAC->sba_synchro_buffer[n] ); + hDirAC->sba_synchro_buffer[n] = NULL; + } + } + hDirAC->num_samples_synchro_delay = 0; + } +#endif + + if ( ( error = ivas_dirac_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + +#ifdef SBA_BITRATE_SWITCHING + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) + { + mvs2s( hDirAC->dirac_to_spar_md_bands, hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); + hSpar->enc_param_start_band = hDirAC->hConfig->enc_param_start_band; + } +#endif #ifdef CORECODER_BITRATE_SWITCHING /*-----------------------------------------------------------------* @@ -137,8 +298,7 @@ ivas_error ivas_sba_enc_reconfigure( ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old ); #else - - if ( hEncoderConfig->nchan_transport == nchan_transport_old ) + if ( st_ivas->nchan_transport == nchan_transport_old ) { for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { @@ -170,11 +330,8 @@ ivas_error ivas_sba_enc_reconfigure( else { Indice *ind_list; - int16_t nb_bits_tot; - int16_t next_ind; - int16_t last_ind; - BSTR_ENC_HANDLE hBstr; - BSTR_ENC_HANDLE hMetaData; + int16_t nb_bits_tot, next_ind, last_ind; + BSTR_ENC_HANDLE hBstr, hMetaData; ind_list = NULL; hBstr = NULL; @@ -236,12 +393,14 @@ ivas_error ivas_sba_enc_reconfigure( { int16_t nSCE_existing; nSCE_existing = min( nSCE_old, st_ivas->nSCE ); + for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ ) { copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ } + for ( sce_id = nSCE_existing; sce_id < st_ivas->nSCE; sce_id++ ) { if ( ( error = create_sce_enc( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) @@ -273,6 +432,7 @@ ivas_error ivas_sba_enc_reconfigure( { int16_t nCPE_existing; nCPE_existing = min( nCPE_old, st_ivas->nCPE ); + for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) { st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; @@ -307,7 +467,7 @@ ivas_error ivas_sba_enc_reconfigure( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->next_ind = next_ind; } - if ( st_ivas->hEncoderConfig->Opt_DTX_ON ) + if ( hEncoderConfig->Opt_DTX_ON ) { st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1; } @@ -411,8 +571,8 @@ ivas_error ivas_sba_enc_reconfigure( st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; } - initMdctStereoEncData( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct, st_ivas->hEncoderConfig->ivas_format, st_ivas->hCPE[st_ivas->nCPE - 1]->element_mode, st_ivas->hCPE[st_ivas->nCPE - 1]->element_brate, st_ivas->hEncoderConfig->max_bwidth, 0, NULL, 1 ); - st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = ( ( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); + initMdctStereoEncData( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct, hEncoderConfig->ivas_format, st_ivas->hCPE[st_ivas->nCPE - 1]->element_mode, st_ivas->hCPE[st_ivas->nCPE - 1]->element_brate, hEncoderConfig->max_bwidth, 0, NULL, 1 ); + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = ( ( hEncoderConfig->ivas_format == SBA_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); } } #endif diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 2592b578f680c36a3af687a072f39b523e391633..856252d9f6135dfdb501170714a7c1ea8db5762a 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -146,7 +146,7 @@ ivas_error ivas_sce_enc( { if ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->hEncoderConfig->ivas_total_brate >= MCMASA_SEPARATE_BRATE ) { - st->bits_frame_nominal = (int16_t) ( hSCE->element_brate / FRAMES_PER_SEC ); + st->bits_frame_nominal = ( int16_t )( hSCE->element_brate / FRAMES_PER_SEC ); } else { @@ -155,11 +155,11 @@ ivas_error ivas_sce_enc( } else if ( st_ivas->hSpar != NULL ) { - st->bits_frame_nominal = (int16_t) ( st_ivas->hSpar->core_nominal_brate / FRAMES_PER_SEC ); + st->bits_frame_nominal = ( int16_t )( st_ivas->hSpar->core_nominal_brate / FRAMES_PER_SEC ); } else { - st->bits_frame_nominal = (int16_t) ( ( hSCE->element_brate / FRAMES_PER_SEC ) - ISM_NB_BITS_METADATA_NOMINAL ); + st->bits_frame_nominal = ( int16_t )( ( hSCE->element_brate / FRAMES_PER_SEC ) - ISM_NB_BITS_METADATA_NOMINAL ); } /* set "total_brate" */ @@ -238,7 +238,7 @@ ivas_error ivas_sce_enc( coder_type_modif( st, relE[0] ); /*----------------------------------------------------------------* - * Encoder + * Core Encoder *----------------------------------------------------------------*/ #ifdef CORECODER_BITRATE_SWITCHING @@ -361,17 +361,19 @@ ivas_error create_sce_enc( *-------------------------------------------------------------------------*/ void destroy_sce_enc( - SCE_ENC_HANDLE hSCE /* i/o: SCE encoder structure */ + SCE_ENC_HANDLE hSCE /* i/o: SCE encoder structure */ ) { Encoder_State *st; - st = hSCE->hCoreCoder[0]; - - if ( st != NULL ) { - destroy_core_enc( st ); - st = NULL; + st = hSCE->hCoreCoder[0]; + + if ( st != NULL ) + { + destroy_core_enc( st ); + st = NULL; + } } if ( hSCE->hMetaData != NULL ) diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index bbf1c332b599ac6a702c8e0843e9f393c6c81b76..134b456aee289c70e555eb81ee7c2155962201d8 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -48,7 +48,7 @@ * Local function prototypes *--------------------------------------------------------------------*/ -static ivas_error ivas_spar_enc_process( Encoder_Struct *st_ivas, const ENCODER_CONFIG_HANDLE hEncoderConfig, BSTR_ENC_HANDLE hMetaData, const int16_t front_vad_flag, float data_f[][L_FRAME48k] ); +static ivas_error ivas_spar_enc_process( Encoder_Struct *st_ivas, BSTR_ENC_HANDLE hMetaData, const int16_t front_vad_flag, float data_f[][L_FRAME48k] ); /*------------------------------------------------------------------------- @@ -98,7 +98,10 @@ ivas_error ivas_spar_enc_open( /* set FB config. */ active_w_mixing = ivas_spar_br_table_consts[table_idx].active_w; - ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_SPAR, nchan_inp, nchan_transport, active_w_mixing, input_Fs ); + if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_SPAR, nchan_inp, nchan_transport, active_w_mixing, input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } fb_cfg->remix_order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; /* FB mixer handle */ @@ -213,7 +216,8 @@ void ivas_spar_enc_close( const int16_t nchan_inp /* i : number of input channels */ ) { - int16_t num_chans; + int16_t nchan; + if ( hSpar != NULL ) { /* core-coder-VAD handle */ @@ -231,14 +235,14 @@ void ivas_spar_enc_close( } - num_chans = hSpar->hFbMixer->fb_cfg->num_in_chans; - assert( num_chans <= nchan_inp ); + nchan = hSpar->hFbMixer->fb_cfg->nchan_inp; + assert( nchan <= nchan_inp ); /* MD handle */ ivas_spar_md_enc_close( &hSpar->hMdEnc ); /* Covar. State handle */ - ivas_spar_covar_enc_close( &hSpar->hCovEnc, num_chans ); + ivas_spar_covar_enc_close( &hSpar->hCovEnc, nchan ); /* FB mixer handle */ ivas_FB_mixer_close( &hSpar->hFbMixer, input_Fs ); @@ -284,6 +288,40 @@ ivas_error ivas_spar_enc( error = IVAS_ERR_OK; hEncoderConfig = st_ivas->hEncoderConfig; +#ifdef SBA_BITRATE_SWITCHING + // VE2DB: can hFbMixer->ppFilterbank_prior_input be replaced by st->input ? + + /* check last sba_mode */ + if ( ivas_sba_mode_select( st_ivas->hEncoderConfig->last_ivas_total_brate ) == SBA_MODE_DIRAC ) + { + Encoder_State *sts[MCT_MAX_BLOCKS]; + + /* initializations */ + for ( int16_t sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + sts[sce_id] = st_ivas->hSCE[sce_id]->hCoreCoder[0]; + } + + for ( int16_t cpe_id = 0, i = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + for ( int16_t ch = 0; ch < CPE_CHANNELS; ch++ ) + { + sts[i] = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]; + i++; + } + } + + /* update FB prior input */ + // VE: last 1ms of 'ppFilterbank_prior_input' is not correct + for ( int16_t i = 0; i < st_ivas->nchan_transport; i++ ) + { + mvr2r( sts[i]->input_buff + NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS ), st_ivas->hSpar->hFbMixer->ppFilterbank_prior_input[i] + st_ivas->hSpar->hFbMixer->fb_cfg->prior_input_length - input_frame, input_frame ); + } + + //VE: TBD - update 'st->input_buff' for SparVAD + } +#endif + /* front VAD */ if ( ( error = front_vad_spar( st_ivas->hSpar, data_f[0], st_ivas->hEncoderConfig, input_frame ) ) != IVAS_ERR_OK ) { @@ -295,7 +333,7 @@ ivas_error ivas_spar_enc( ivas_sba_zero_vert_comp( data_f, st_ivas->sba_analysis_order, hEncoderConfig->sba_planar, input_frame ); } - if ( ( error = ivas_spar_enc_process( st_ivas, hEncoderConfig, hMetaData, st_ivas->hSpar->front_vad_flag, data_f ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_enc_process( st_ivas, hMetaData, st_ivas->hSpar->front_vad_flag, data_f ) ) != IVAS_ERR_OK ) { return error; } @@ -387,11 +425,10 @@ static void ivas_spar_enc_get_windowed_fr( *-----------------------------------------------------------------------------------------*/ static ivas_error ivas_spar_enc_process( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ - const int16_t front_vad_flag, /* i : front-VAD decision */ - float data_f[][L_FRAME48k] /* i/o: input/transport audio channels */ + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ + const int16_t front_vad_flag, /* i : front-VAD decision */ + float data_f[][L_FRAME48k] /* i/o: input/transport audio channels */ ) { float pcm_tmp[IVAS_SPAR_MAX_CH][L_FRAME48k * 2]; @@ -420,6 +457,7 @@ static ivas_error ivas_spar_enc_process( const int16_t *order; SPAR_ENC_HANDLE hSpar = st_ivas->hSpar; IVAS_QMETADATA_HANDLE hQMetaData = st_ivas->hQMetaData; + ENCODER_CONFIG_HANDLE hEncoderConfig = st_ivas->hEncoderConfig; int16_t ts, l_ts, orig_dirac_bands, num_del_samples; float *ppIn_FR_real[IVAS_SPAR_MAX_CH], *ppIn_FR_imag[IVAS_SPAR_MAX_CH]; float w_del_buf[IVAS_FB_1MS_48K_SAMP]; @@ -527,7 +565,7 @@ static ivas_error ivas_spar_enc_process( } #ifndef SBA_SPAR_HARM - cov_in_buf.num_ch = nchan_inp; + cov_in_buf.nchan = nchan_inp; #endif dtx_vad = ( hEncoderConfig->Opt_DTX_ON == 1 ) ? front_vad_flag : 1; @@ -656,7 +694,7 @@ static ivas_error ivas_spar_enc_process( *-----------------------------------------------------------------------------------------*/ #ifndef SBA_SPAR_HARM - cov_in_buf.num_ch = nchan_inp; + cov_in_buf.nchan = nchan_inp; #endif for ( i = 0; i < nchan_inp; i++ ) { @@ -686,13 +724,26 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->table_idx != table_idx ) { hSpar->hMdEnc->table_idx = table_idx; - ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, + +#ifdef SBA_BITRATE_SWITCHING + if ( ivas_total_brate != hEncoderConfig->last_ivas_total_brate ) + { + if ( ( error = ivas_spar_md_enc_init( hSpar->hMdEnc, hEncoderConfig, sba_order ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else +#endif + { + ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, #ifdef SBA_HOA_HBR_IMPROV - ( hSpar->hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND + ( hSpar->hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND #else - SPAR_DIRAC_SPLIT_START_BAND + SPAR_DIRAC_SPLIT_START_BAND #endif - ); + ); + } } #ifdef SBA_SPAR_HARM @@ -839,9 +890,9 @@ static ivas_error ivas_spar_enc_process( if ( f_mat == 0 ) f_mat = fopen( "mixer_mat_enc", "w" ); - for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + for ( i = 0; i < hSpar->hFbMixer->fb_cfg->nchan_out; i++ ) { - for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) + for ( j = 0; j < hSpar->hFbMixer->fb_cfg->nchan_inp; j++ ) { for ( k = 0; k < hSpar->hFbMixer->pFb->filterbank_num_bands; k++ ) { @@ -924,7 +975,7 @@ static ivas_error ivas_spar_enc_process( { if ( hEncoderConfig->Opt_AGC_ON > 0 ) { - ivas_agc_enc_process( hSpar->hAgcEnc, hMetaData, p_pcm_tmp, p_pcm_tmp, hSpar->hFbMixer->fb_cfg->num_out_chans, hEncoderConfig ); + ivas_agc_enc_process( hSpar->hAgcEnc, hMetaData, p_pcm_tmp, p_pcm_tmp, hSpar->hFbMixer->fb_cfg->nchan_out, hEncoderConfig ); } else { diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 2624389cc42606485bc63fb2ee3de587025cccb5..676597d75b11d656e94c1b2ad27842b867807ddd 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -68,7 +68,7 @@ typedef enum ivas_strats_t * Static functions declaration *------------------------------------------------------------------------------------------*/ -static void ivas_band_mixer( float *cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t num_ch, int16_t *num_bands, int16_t red_band_fact ); +static void ivas_band_mixer( float *cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t nchan, int16_t *num_bands, int16_t red_band_fact ); static void ivas_get_band_differential_index( ivas_band_coeffs_ind_t *pBand_idx, const int16_t q_levels[2], const int16_t one_sided, const int16_t nB, const int16_t complex_cov, const int16_t dim, const ivas_coeffs_type_t coeff_type ); @@ -84,16 +84,19 @@ static void ivas_store_prior_coeffs( ivas_spar_md_enc_state_t *hMdEnc, const int static void ivas_write_spar_md_bitstream( ivas_spar_md_enc_state_t *hMdEnc, const int16_t nB, const int16_t bands_bw, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate, const int16_t dtx_silence_mode, const int16_t strat, const int16_t qsi, const int16_t planarCP ); +#ifndef SBA_BITRATE_SWITCHING static ivas_error ivas_spar_md_enc_init( ivas_spar_md_enc_state_t *hMdEnc, const ENCODER_CONFIG_HANDLE hEncoderConfig, const int16_t sba_order ); +#endif static void ivas_spar_quant_pred_coeffs_dtx( ivas_spar_md_t *pSpar_md, const float *pValues, const int16_t ndm, int16_t *pIndex, const int16_t dim1, float *pQuant ); -static void ivas_quant_p_per_band_dtx( float *pP_mat, const int16_t num_dec, const int16_t num_dmx, int16_t *ppIdx_pd, float *pP_out, const int16_t num_ch ); +static void ivas_quant_p_per_band_dtx( float *pP_mat, const int16_t num_dec, const int16_t num_dmx, int16_t *ppIdx_pd, float *pP_out, const int16_t nchan ); + static void ivas_write_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, BSTR_ENC_HANDLE hMetaData, int16_t *num_dmx, int16_t *num_dec, const int16_t num_bands ); -static void ivas_quant_p_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t num_ch ); +static void ivas_quant_p_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t nchan ); static void ivas_quant_c_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t ndec, const int16_t ndm ); -static void ivas_quant_pred_coeffs_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t num_ch ); +static void ivas_quant_pred_coeffs_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t nchan ); /*------------------------------------------------------------------------- @@ -110,7 +113,7 @@ ivas_error ivas_spar_md_enc_open( { ivas_spar_md_enc_state_t *hMdEnc; ivas_error error; - int16_t num_channels, i, j; + int16_t nchan, i, j; error = IVAS_ERR_OK; @@ -119,27 +122,29 @@ ivas_error ivas_spar_md_enc_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD encoder" ); } - num_channels = 2 * sba_order + 2; + nchan = 2 * sba_order + 2; +#ifndef SBA_BITRATE_SWITCHING #ifdef SBA_HOA_HBR_IMPROV hMdEnc->spar_hoa_md_flag = ivas_sba_get_spar_hoa_md_flag( sba_order, hEncoderConfig->ivas_total_brate ); +#endif #endif if ( ( hMdEnc->spar_md.band_coeffs = (ivas_band_coeffs_t *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" ); } - if ( ( hMdEnc->mixer_mat = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdEnc->mixer_mat = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdEnc->mixer_mat[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdEnc->mixer_mat[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdEnc->mixer_mat[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -148,17 +153,17 @@ ivas_error ivas_spar_md_enc_open( } } - if ( ( hMdEnc->cov_real = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdEnc->cov_real = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR cov real matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdEnc->cov_real[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdEnc->cov_real[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR cov real matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdEnc->cov_real[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -167,17 +172,17 @@ ivas_error ivas_spar_md_enc_open( } } - if ( ( hMdEnc->cov_dtx_real = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdEnc->cov_dtx_real = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR cov dtx real matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdEnc->cov_dtx_real[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdEnc->cov_dtx_real[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR cov dtx real matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdEnc->cov_dtx_real[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -186,17 +191,17 @@ ivas_error ivas_spar_md_enc_open( } } - if ( ( hMdEnc->mixer_mat_local = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdEnc->mixer_mat_local = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdEnc->mixer_mat_local[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdEnc->mixer_mat_local[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdEnc->mixer_mat_local[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -226,11 +231,11 @@ void ivas_spar_md_enc_close( ivas_spar_md_enc_state_t **hMdEnc_in /* i/o: SPAR MD encoder handle */ ) { - int16_t num_channels, i, j; + int16_t nchan, i, j; ivas_spar_md_enc_state_t *hMdEnc; hMdEnc = *hMdEnc_in; - num_channels = hMdEnc->num_umx_ch; + nchan = hMdEnc->num_umx_ch; if ( hMdEnc->spar_md.band_coeffs != NULL ) { @@ -239,9 +244,9 @@ void ivas_spar_md_enc_close( } if ( hMdEnc->mixer_mat != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdEnc->mixer_mat[i][j] ); } @@ -252,10 +257,10 @@ void ivas_spar_md_enc_close( if ( hMdEnc->cov_real != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdEnc->cov_real[i][j] ); } @@ -266,10 +271,10 @@ void ivas_spar_md_enc_close( if ( hMdEnc->cov_dtx_real != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdEnc->cov_dtx_real[i][j] ); } @@ -280,10 +285,10 @@ void ivas_spar_md_enc_close( if ( hMdEnc->mixer_mat_local != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdEnc->mixer_mat_local[i][j] ); } @@ -308,7 +313,11 @@ void ivas_spar_md_enc_close( * SPAR MD encoder initialization *-----------------------------------------------------------------------------------------*/ +#ifndef SBA_BITRATE_SWITCHING static ivas_error ivas_spar_md_enc_init( +#else +ivas_error ivas_spar_md_enc_init( +#endif ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ const int16_t sba_order /* i : Ambisonic (SBA) order */ @@ -317,12 +326,18 @@ static ivas_error ivas_spar_md_enc_init( float pFC[IVAS_MAX_NUM_BANDS]; int16_t table_idx; float PR_minmax[2]; - int16_t num_channels, i, j, k; + int16_t nchan, i, j, k; - num_channels = ivas_sba_get_nchan_metadata( sba_order ); + nchan = ivas_sba_get_nchan_metadata( sba_order ); table_idx = ivas_get_spar_table_idx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); +#ifdef SBA_BITRATE_SWITCHING +#ifdef SBA_HOA_HBR_IMPROV + hMdEnc->spar_hoa_md_flag = ivas_sba_get_spar_hoa_md_flag( sba_order, hEncoderConfig->ivas_total_brate ); +#endif +#endif + hMdEnc->spar_md_cfg.gen_bs = 1; ivas_spar_set_bitrate_config( &hMdEnc->spar_md_cfg, table_idx, #ifdef SBA_HOA_HBR_IMPROV @@ -338,7 +353,7 @@ static ivas_error ivas_spar_md_enc_init( pFC[i] = ivas_fb_fcs_12band_1ms[i] * hEncoderConfig->input_Fs * 0.5f; } - ivas_spar_set_enc_config( hMdEnc, hMdEnc->spar_md_cfg.max_freq_per_chan, hMdEnc->spar_md_cfg.nchan_transport, pFC, num_channels ); + ivas_spar_set_enc_config( hMdEnc, hMdEnc->spar_md_cfg.max_freq_per_chan, hMdEnc->spar_md_cfg.nchan_transport, pFC, nchan ); /* if(hMdEnc->spar_md_cfg.quant_strat[0].C.q_levels[0] == 0 || hMdEnc->spar_md_cfg.quant_strat[0].C.q_levels[1] == 0 || hMdEnc->spar_md_cfg.quant_strat[0].PR.q_levels[0] == 0 || hMdEnc->spar_md_cfg.quant_strat[0].PR.q_levels[1] == 0 @@ -372,9 +387,9 @@ static ivas_error ivas_spar_md_enc_init( hMdEnc->spar_md_cfg.prior_strat = START; hMdEnc->spar_md_cfg.prev_quant_idx = -1; - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -383,9 +398,9 @@ static ivas_error ivas_spar_md_enc_init( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -461,7 +476,7 @@ static ivas_error ivas_spar_set_enc_config( static void ivas_band_limit_dmx_matrix( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ - const int16_t num_ch, + const int16_t nchan, const int16_t num_bands, const int16_t bands_bw ) { @@ -471,9 +486,9 @@ static void ivas_band_limit_dmx_matrix( { ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; - for ( i = ndm; i < num_ch; i++ ) + for ( i = ndm; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { hMdEnc->mixer_mat[i][j][b] = 0; } @@ -492,7 +507,7 @@ static void ivas_band_limit_dmx_matrix( static void ivas_band_mixing( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ - const int16_t num_ch, + const int16_t nchan, const int16_t num_bands, const int16_t nchan_transport, const int16_t upmixed_bands ) @@ -504,7 +519,7 @@ static void ivas_band_mixing( for ( i = 0; i < nchan_transport; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = num_bands - 1; k >= 0; k-- ) { @@ -583,7 +598,7 @@ ivas_error ivas_spar_md_enc_process( #ifdef SBA_HOA_HBR_IMPROV float pred_coeffs_re_local[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; #endif - int16_t i, b, qsi, ndm, ndec, num_ch, num_quant_strats; + int16_t i, b, qsi, ndm, ndec, nchan, num_quant_strats; int16_t j, planarCP; #ifdef SBA_SPAR_HARM int16_t k, bwidth, num_bands, num_bands_full, num_bands_bw; @@ -601,7 +616,7 @@ ivas_error ivas_spar_md_enc_process( float Wscale[IVAS_MAX_NUM_BANDS]; num_quant_strats = hMdEnc->spar_md_cfg.num_quant_strats; - num_ch = ivas_sba_get_nchan_metadata( sba_order ); + nchan = ivas_sba_get_nchan_metadata( sba_order ); active_w = hMdEnc->spar_md_cfg.active_w; nchan_transport = hMdEnc->spar_md_cfg.nchan_transport; @@ -677,9 +692,9 @@ ivas_error ivas_spar_md_enc_process( bands_bw = num_bands / nB; #ifdef SBA_SPAR_HARM - ivas_band_mixer( cov_real, num_ch, &num_bands, bands_bw ); + ivas_band_mixer( cov_real, nchan, &num_bands, bands_bw ); #else - ivas_band_mixer( pIn_buf->cov_real, num_ch, &num_bands, bands_bw ); + ivas_band_mixer( pIn_buf->cov_real, nchan, &num_bands, bands_bw ); #endif } else @@ -703,16 +718,16 @@ ivas_error ivas_spar_md_enc_process( #endif #ifdef SBA_SPAR_HARM - ivas_compute_spar_params( cov_real, dm_fv_re, 0, hMdEnc->mixer_mat, 0, nB, dtx_vad, num_ch, + ivas_compute_spar_params( cov_real, dm_fv_re, 0, hMdEnc->mixer_mat, 0, nB, dtx_vad, nchan, bands_bw, active_w, &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale, 0 ); #else - ivas_compute_spar_params( pIn_buf->cov_real, dm_fv_re, 0, hMdEnc->mixer_mat, 0, nB, dtx_vad, num_ch, + ivas_compute_spar_params( pIn_buf->cov_real, dm_fv_re, 0, hMdEnc->mixer_mat, 0, nB, dtx_vad, nchan, bands_bw, active_w, &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale, 0 ); #endif - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( b = 0; b < num_bands; b++ ) { @@ -753,12 +768,12 @@ ivas_error ivas_spar_md_enc_process( { ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; - if ( ndm != num_ch ) + if ( ndm != nchan ) { #ifdef SBA_SPAR_HARM - ivas_calc_c_p_coeffs( &hMdEnc->spar_md, cov_real, 0, hMdEnc->mixer_mat_local, num_ch, ndm, b, dtx_vad, 1, planarCP ); + ivas_calc_c_p_coeffs( &hMdEnc->spar_md, cov_real, 0, hMdEnc->mixer_mat_local, nchan, ndm, b, dtx_vad, 1, planarCP ); #else - ivas_calc_c_p_coeffs( &hMdEnc->spar_md, pIn_buf->cov_real, 0, hMdEnc->mixer_mat_local, num_ch, ndm, b, dtx_vad, 1, planarCP ); + ivas_calc_c_p_coeffs( &hMdEnc->spar_md, pIn_buf->cov_real, 0, hMdEnc->mixer_mat_local, nchan, ndm, b, dtx_vad, 1, planarCP ); #endif } } @@ -770,7 +785,7 @@ ivas_error ivas_spar_md_enc_process( if ( dtx_vad == 1 ) { - if ( ndm != num_ch ) + if ( ndm != nchan ) { #ifdef SPAR_HOA_DBG /* fprintf(stderr, "\n\n P coefficients: band %d\n", b); @@ -810,27 +825,27 @@ ivas_error ivas_spar_md_enc_process( #endif } - ivas_quant_p_per_band( &hMdEnc->spar_md.band_coeffs[b], &hMdEnc->spar_md.band_coeffs_idx[b], &hMdEnc->spar_md_cfg.quant_strat[qsi], num_ch ); + ivas_quant_p_per_band( &hMdEnc->spar_md.band_coeffs[b], &hMdEnc->spar_md.band_coeffs_idx[b], &hMdEnc->spar_md_cfg.quant_strat[qsi], nchan ); } - ivas_quant_pred_coeffs_per_band( &hMdEnc->spar_md.band_coeffs[b], &hMdEnc->spar_md.band_coeffs_idx[b], &hMdEnc->spar_md_cfg.quant_strat[qsi], num_ch ); + ivas_quant_pred_coeffs_per_band( &hMdEnc->spar_md.band_coeffs[b], &hMdEnc->spar_md.band_coeffs_idx[b], &hMdEnc->spar_md_cfg.quant_strat[qsi], nchan ); } else { - if ( ndm != num_ch ) + if ( ndm != nchan ) { - ivas_quant_p_per_band_dtx( hMdEnc->spar_md.band_coeffs[b].P_re, ndec, ndm, &hMdEnc->spar_md.band_coeffs_idx[b].decd_index_re[0], hMdEnc->spar_md.band_coeffs[b].P_quant_re, num_ch ); + ivas_quant_p_per_band_dtx( hMdEnc->spar_md.band_coeffs[b].P_re, ndec, ndm, &hMdEnc->spar_md.band_coeffs_idx[b].decd_index_re[0], hMdEnc->spar_md.band_coeffs[b].P_quant_re, nchan ); } - for ( i = 0; i < num_ch - 1; i++ ) + for ( i = 0; i < nchan - 1; i++ ) { hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i] = 0; } - ivas_spar_quant_pred_coeffs_dtx( &hMdEnc->spar_md, hMdEnc->spar_md.band_coeffs[b].pred_re, ndm, hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re, num_ch - 1, hMdEnc->spar_md.band_coeffs[b].pred_quant_re ); + ivas_spar_quant_pred_coeffs_dtx( &hMdEnc->spar_md, hMdEnc->spar_md.band_coeffs[b].pred_re, ndm, hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re, nchan - 1, hMdEnc->spar_md.band_coeffs[b].pred_quant_re ); } } - for ( i = 0; i < num_ch - 1; i++ ) + for ( i = 0; i < nchan - 1; i++ ) { for ( b = 0; b < num_bands; b++ ) { @@ -856,29 +871,29 @@ ivas_error ivas_spar_md_enc_process( } #endif - ivas_create_fullr_dmx_mat( pred_coeffs_re, dm_fv_re, hMdEnc->mixer_mat, num_ch, 0, num_bands, active_w, &hMdEnc->spar_md_cfg ); + ivas_create_fullr_dmx_mat( pred_coeffs_re, dm_fv_re, hMdEnc->mixer_mat, nchan, 0, num_bands, active_w, &hMdEnc->spar_md_cfg ); for ( b = 0; b < num_bands; b++ ) { ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[b * bands_bw]; - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { hMdEnc->mixer_mat[0][i][b] *= Wscale[b]; } - if ( ( ndm != num_ch ) && ( ndm != 1 ) ) + if ( ( ndm != nchan ) && ( ndm != 1 ) ) { #ifdef SBA_SPAR_HARM - ivas_calc_c_p_coeffs( &hMdEnc->spar_md, cov_real, 0, hMdEnc->mixer_mat, num_ch, ndm, b, dtx_vad, 0, planarCP ); + ivas_calc_c_p_coeffs( &hMdEnc->spar_md, cov_real, 0, hMdEnc->mixer_mat, nchan, ndm, b, dtx_vad, 0, planarCP ); #else - ivas_calc_c_p_coeffs( &hMdEnc->spar_md, pIn_buf->cov_real, 0, hMdEnc->mixer_mat, num_ch, ndm, b, dtx_vad, 0, planarCP ); + ivas_calc_c_p_coeffs( &hMdEnc->spar_md, pIn_buf->cov_real, 0, hMdEnc->mixer_mat, nchan, ndm, b, dtx_vad, 0, planarCP ); #endif #ifdef SPAR_HOA_DBG /*fprintf(stderr, "\n\n C coefficients: band %d\n", b); - for (i = 0; i < num_ch - ndm; i++) + for (i = 0; i < nchan - ndm; i++) { for (j = 0; j < ndm - 1; j++) { @@ -890,7 +905,7 @@ ivas_error ivas_spar_md_enc_process( #endif if ( planarCP ) { - for ( i = 0; i < num_ch - ndm; i++ ) + for ( i = 0; i < nchan - ndm; i++ ) { if ( !keep_planar[i] ) { @@ -903,7 +918,7 @@ ivas_error ivas_spar_md_enc_process( #ifdef SPAR_HOA_DBG /*fprintf(stderr, "\n\n Planar C coefficients: band %d\n", b); - for (i = 0; i < num_ch - ndm; i++) + for (i = 0; i < nchan - ndm; i++) { for (j = 0; j < ndm - 1; j++) { @@ -930,15 +945,15 @@ ivas_error ivas_spar_md_enc_process( } /* band limit downmix matrix */ - ivas_band_limit_dmx_matrix( hMdEnc, num_ch, num_bands, bands_bw ); + ivas_band_limit_dmx_matrix( hMdEnc, nchan, num_bands, bands_bw ); /* band mixing */ if ( bands_bw > 1 ) { #ifdef SBA_SPAR_HARM - ivas_band_mixing( hMdEnc, num_ch, num_bands, nchan_transport, num_bands_full ); + ivas_band_mixing( hMdEnc, nchan, num_bands, nchan_transport, num_bands_full ); #else - ivas_band_mixing( hMdEnc, num_ch, num_bands, nchan_transport, pIn_buf->num_bands ); + ivas_band_mixing( hMdEnc, nchan, num_bands, nchan_transport, pIn_buf->num_bands ); #endif } @@ -999,7 +1014,7 @@ ivas_error ivas_spar_md_enc_process( { b = 0; fprintf( stdout, "\n\nMETADATA PR: band %d, qsi %d\n\n", b, qsi ); - for ( i = 0; i < num_ch - 1; i++ ) + for ( i = 0; i < nchan - 1; i++ ) { fprintf( stdout, "i: %d -- %f\t %d\t %d\n", i, //hMdEnc->spar_md.band_coeffs[b].pred_re[i], hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i], @@ -1020,7 +1035,7 @@ ivas_error ivas_spar_md_enc_process( } } fprintf( stdout, "\n\n METADATA Pd: band %d\n\n", b ); - for ( i = 0; i < num_ch - ndm; i++ ) + for ( i = 0; i < nchan - ndm; i++ ) { fprintf( stdout, "i: %d -- %f\t %d\t %d\n", i, //hMdEnc->spar_md.band_coeffs[b].P_re[i][i], hMdEnc->spar_md.band_coeffs[b].P_quant_re[i][i], @@ -1034,10 +1049,10 @@ ivas_error ivas_spar_md_enc_process( ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; fprintf( stdout, "\n\n Metadata PR (15x1), C(15x15), P(15x15): band %d\n", b ); - for ( i = 0; i < num_ch - 1; i++ ) + for ( i = 0; i < nchan - 1; i++ ) { fprintf( stdout, "i: %d -- %.2f\t|\t", i, hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i] ); - if ( i < num_ch - ndm ) + if ( i < nchan - ndm ) { if ( keep_planar[i] == 1 ) { @@ -1052,7 +1067,7 @@ ivas_error ivas_spar_md_enc_process( fprintf( stdout, "%.2f\t", hMdEnc->spar_md.band_coeffs[b].C_quant_re[i][j] ); } fprintf( stdout, "|\t" ); - for ( j = 0; j < num_ch - ndm; j++ ) + for ( j = 0; j < nchan - ndm; j++ ) { fprintf( stdout, "%.2f\t", hMdEnc->spar_md.band_coeffs[b].P_quant_re[j] ); } @@ -1086,12 +1101,12 @@ ivas_error ivas_spar_md_enc_process( sprintf( f_name, "spar_band_pred_coeffs.bin" ); ( b == 0 && frame == 0 ) ? dbgwrite( &nB, sizeof( nB ), 1, 1, f_name ) : false; - num_elements = num_ch - 1; + num_elements = nchan - 1; ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; - for ( i = 0; i < num_ch - 1; i++ ) + for ( i = 0; i < nchan - 1; i++ ) { dbgwrite( &hMdEnc->spar_md.band_coeffs[b].pred_re[i], sizeof( float ), 1, 1, f_name ); } @@ -1111,23 +1126,23 @@ ivas_error ivas_spar_md_enc_process( } sprintf( f_name, "spar_band_P_coeffs.bin" ); ( b == 0 && frame == 0 ) ? dbgwrite( &nB, sizeof( nB ), 1, 1, f_name ) : false; - num_elements = num_ch - ndm; + num_elements = nchan - ndm; ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; - for ( i = 0; i < num_ch - ndm; i++ ) + for ( i = 0; i < nchan - ndm; i++ ) { dbgwrite( &hMdEnc->spar_md.band_coeffs[b].P_re[i], sizeof( float ), 1, 1, f_name ); } sprintf( f_name, "spar_band_pred_coeffs_quant.bin" ); ( b == 0 && frame == 0 ) ? dbgwrite( &nB, sizeof( nB ), 1, 1, f_name ) : false; - num_elements = num_ch - 1; + num_elements = nchan - 1; ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; - for ( i = 0; i < num_ch - 1; i++ ) + for ( i = 0; i < nchan - 1; i++ ) { dbgwrite( &hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i], sizeof( float ), 1, 1, f_name ); } @@ -1147,12 +1162,12 @@ ivas_error ivas_spar_md_enc_process( } sprintf( f_name, "spar_band_P_coeffs_quant.bin" ); ( b == 0 && frame == 0 ) ? dbgwrite( &nB, sizeof( nB ), 1, 1, f_name ) : false; - num_elements = num_ch - ndm; + num_elements = nchan - ndm; ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; - for ( i = 0; i < num_ch - ndm; i++ ) + for ( i = 0; i < nchan - ndm; i++ ) { dbgwrite( &hMdEnc->spar_md.band_coeffs[b].P_quant_re[i], sizeof( float ), 1, 1, f_name ); } @@ -1187,7 +1202,7 @@ ivas_error ivas_spar_md_enc_process( static void ivas_band_mixer( float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const int16_t num_ch, + const int16_t nchan, int16_t *num_bands, int16_t red_band_fact ) { @@ -1198,9 +1213,9 @@ static void ivas_band_mixer( *num_bands /= red_band_fact; rem_band = orig_band - ( *num_bands * red_band_fact ); - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < *num_bands - 1; k++ ) { @@ -1725,11 +1740,11 @@ static void ivas_quant_p_per_band_dtx( const int16_t num_dmx, int16_t *ppIdx_pd, float *pP_out, - const int16_t num_ch ) + const int16_t nchan ) { int16_t i; - int16_t dim = num_ch - num_dmx; - if ( num_dec == num_ch - 1 ) + int16_t dim = nchan - num_dmx; + if ( num_dec == nchan - 1 ) { for ( i = 0; i < dim; i++ ) { @@ -1746,7 +1761,7 @@ static void ivas_quant_p_per_band_dtx( } for ( i = 0; i < dim; i++ ) { - ivas_quantise_real_values( &pP_mat[i], dtx_pd_real_q_levels[num_ch - num_dec - 1][i], dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &ppIdx_pd[i], &pP_out[i], 1 ); + ivas_quantise_real_values( &pP_mat[i], dtx_pd_real_q_levels[nchan - num_dec - 1][i], dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &ppIdx_pd[i], &pP_out[i], 1 ); } return; } @@ -1875,9 +1890,9 @@ static void ivas_quant_pred_coeffs_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, - const int16_t num_ch ) + const int16_t nchan ) { - ivas_quantise_real_values( pband_coeffs->pred_re, pQs->PR.q_levels[0], pQs->PR.min, pQs->PR.max, pBand_coeffs_idx->pred_index_re, pband_coeffs->pred_quant_re, ( num_ch - 1 ) ); + ivas_quantise_real_values( pband_coeffs->pred_re, pQs->PR.q_levels[0], pQs->PR.min, pQs->PR.max, pBand_coeffs_idx->pred_index_re, pband_coeffs->pred_quant_re, ( nchan - 1 ) ); return; } @@ -1953,7 +1968,7 @@ static void ivas_quant_p_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, - const int16_t num_ch ) + const int16_t nchan ) { #ifdef SPAR_HOA_DBG /*fprintf(stderr, "\n\n P_d:\n"); @@ -1963,6 +1978,6 @@ static void ivas_quant_p_per_band( } fprintf(stderr, "\n\n");*/ #endif - ivas_quantise_real_values( pband_coeffs->P_re, pQs->P_r.q_levels[0], pQs->P_r.min, pQs->P_r.max, pBand_coeffs_idx->decd_index_re, pband_coeffs->P_quant_re, num_ch - 1 ); + ivas_quantise_real_values( pband_coeffs->P_re, pQs->P_r.q_levels[0], pQs->P_r.min, pQs->P_r.max, pBand_coeffs_idx->decd_index_re, pband_coeffs->P_quant_re, nchan - 1 ); return; } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 24e9ebaf76f970921324e039b86c43d1b84441f0..842bdb46b472e04024dc2422897edb2cbe06ea5b 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -634,7 +634,7 @@ typedef struct ivas_enc_cov_handler_in_buf_t { float *ppIn_FR_real[IVAS_SPAR_MAX_CH]; float *ppIn_FR_imag[IVAS_SPAR_MAX_CH]; - int16_t num_ch; + int16_t nchan; int16_t transient_det; int16_t dtx_cov_flag; @@ -692,7 +692,7 @@ typedef struct ivas_spar_enc_lib_t ivas_enc_cov_handler_state_t *hCovEnc; ivas_trans_det_state_t *hTranDet; ivas_agc_enc_state_t *hAgcEnc; - int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; + int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; // VE2DB: could only hDirAC->dirac_to_spar_md_bands be used all the time, or it is defined as a pointer here? int16_t enc_param_start_band; PCA_ENC_STATE *hPCA; int32_t core_nominal_brate; /* Nominal bitrate for core coding */ @@ -867,7 +867,7 @@ typedef struct cpe_enc_data_structure int16_t cpe_id; /* CPE # identifier */ int32_t element_brate; /* CPE element total bitrate in bps */ - int32_t last_element_brate; /* last CPE element total bitrate in bps */ + int32_t last_element_brate; /* last CPE element bitrate in bps */ int16_t element_mode; /* element mode, in CPE it can be IVAS_CPE_DFT, IVAS_CPE_TD or IVAS_CPE_MDCT */ int16_t last_element_mode; /* last element mode */ diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index 6d1e9a32b0d10110079f5ebbce5095092c976766..f9a25f3a880c23e53bda23615e1ceef2bb640e99 100755 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -254,6 +254,7 @@ void stereo_mdct_core_enc( /*--------------------------------------------------------------* * Stereo Processing *---------------------------------------------------------------*/ + if ( !hStereoMdct->isSBAStereoMode ) { stereo_coder_tcx( hStereoMdct, sts, ms_mask, mdst_spectrum, inv_spectrum, inv_mdst_spectrum, 0 ); diff --git a/lib_util/ivas_prerenderer.c b/lib_util/ivas_prerenderer.c index a2c0b4c7104d40f44f9986ff3a944264cd9ff30d..018d8f1dc561003ae9fb07f8afd2399eba90ab21 100644 --- a/lib_util/ivas_prerenderer.c +++ b/lib_util/ivas_prerenderer.c @@ -1715,7 +1715,7 @@ static void ivas_limiter_prerenderer( } channels = hLimiter->channel_ptrs; - num_channels = hLimiter->num_channels; + num_channels = hLimiter->nchan; for ( c = 0; c < num_channels; ++c ) { diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c index d993405b1169dc591fe242b44fe3464af11683dd..ee73254126ba451930a2e950e306cffa55bc9eb1 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c @@ -181,47 +181,47 @@ const char *ivas_crend_map_in_fmt( int16_t ivas_get_num_channels( const int16_t ch_format ) { - int16_t num_channels = 0; + int16_t nchan = 0; switch ( ch_format ) { case MONO_1: - num_channels = 1; + nchan = 1; break; case BIN_2: case STEREO_2: - num_channels = 2; + nchan = 2; break; case FOA_4: - num_channels = FOA_CHANNELS; + nchan = FOA_CHANNELS; break; case MULT_CH_5_1: - num_channels = 6; + nchan = 6; break; case MULT_CH_7_1: - num_channels = 8; + nchan = 8; break; case HOA_9: - num_channels = 9; + nchan = 9; break; case HOA_16: - num_channels = 16; + nchan = 16; break; case OBA: - num_channels = 8; + nchan = 8; break; case MULT_CH_5_1_2: - num_channels = 8; + nchan = 8; break; case MULT_CH_7_1_4: - num_channels = 12; + nchan = 12; break; default: assert( !"Not supported Input format for Common Renderer!" ); break; } - return num_channels; + return nchan; } static ivas_result_t ivas_crend_mixer(