From 57df6e89239fc012ee75782591b8003027791cf0 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 29 Apr 2024 09:28:08 +0530 Subject: [PATCH 1/2] mc_dec_reconfig conversions and float cleanup --- lib_com/cldfb.c | 45 +- lib_com/ivas_prot.h | 10 + lib_dec/LD_music_post_filter.c | 38 + lib_dec/core_dec_init.c | 34 +- lib_dec/hq_core_dec.c | 76 +- lib_dec/igf_dec.c | 22 +- lib_dec/ivas_corecoder_dec_reconfig.c | 4 +- lib_dec/ivas_mc_param_dec.c | 698 +++++- lib_dec/ivas_mct_dec.c | 2982 ++++++++++++++----------- lib_dec/ivas_sba_rendering_internal.c | 58 + lib_dec/ivas_spar_md_dec.c | 122 +- lib_dec/swb_tbe_dec.c | 81 +- lib_rend/ivas_crend.c | 6 + lib_rend/ivas_stat_rend.h | 2 + 14 files changed, 2866 insertions(+), 1312 deletions(-) diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index f8b27dd61..8859370e3 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -1614,7 +1614,7 @@ void configureCldfb_ivas_fx( * * open and configures a CLDFB handle *--------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED ivas_error openCldfb_ivas( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ CLDFB_TYPE type, /* i : analysis or synthesis */ @@ -1667,7 +1667,50 @@ ivas_error openCldfb_ivas( return IVAS_ERR_OK; } +#else +ivas_error openCldfb_ivas( + HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ + CLDFB_TYPE type, /* i : analysis or synthesis */ + const int32_t sampling_rate, /* i : sampling rate */ + CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ +) +{ + HANDLE_CLDFB_FILTER_BANK hs; + int16_t buf_len; + + if ((hs = (HANDLE_CLDFB_FILTER_BANK)malloc(sizeof(CLDFB_FILTER_BANK))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB"); + } + + hs->type = type; + hs->prototype = prototype; + configureCldfb_ivas(hs, sampling_rate); + hs->memory_flt = NULL; + hs->memory_length = 0; + + if (type == CLDFB_ANALYSIS) + { + buf_len = hs->p_filter_length - hs->no_channels; + } + else + { + buf_len = hs->p_filter_length; + } + + if ((hs->cldfb_state = (float *)malloc(buf_len * sizeof(float))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB"); + } + + set_f(hs->cldfb_state, 0.0f, buf_len); + + *h_cldfb = hs; + + return IVAS_ERR_OK; +} +#endif #ifdef IVAS_FLOAT_FIXED ivas_error openCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index ddaddc3e1..7bf923004 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4630,6 +4630,11 @@ void ivas_param_mc_enc( float *data_f[], /* i/o: input/transport MC data */ const int16_t input_frame /* i : input frame length */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_param_mc_dec_open_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); +#endif // IVAS_FLOAT_FIXED ivas_error ivas_param_mc_dec_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ @@ -4644,6 +4649,11 @@ ivas_error ivas_param_mc_dec_reconfig_fx( ivas_error ivas_param_mc_dec_reconfig( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); +#ifdef IVAS_FLOAT_FIXED +void ivas_param_mc_dec_close_fx( + PARAM_MC_DEC_HANDLE *hParamMC_out /* i/o: Parametric MC decoder handle */ +); +#endif // IVAS_FLOAT_FIXED void ivas_param_mc_dec_close( PARAM_MC_DEC_HANDLE *hParamMC /* i/o: Parametric MC decoder handle */ diff --git a/lib_dec/LD_music_post_filter.c b/lib_dec/LD_music_post_filter.c index d6a64ad79..a17dcdfb6 100644 --- a/lib_dec/LD_music_post_filter.c +++ b/lib_dec/LD_music_post_filter.c @@ -727,6 +727,7 @@ void Post_music_postP( * * Initialize LD music postfilter state structure *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void music_postfilt_init_flt( MUSIC_POSTFILT_HANDLE hMusicPF /* i/o: LD music postfilter handle */ @@ -801,3 +802,40 @@ void music_postfilt_init_flt( #endif return; } +#else + void music_postfilt_init_flt( + MUSIC_POSTFILT_HANDLE hMusicPF /* i/o: LD music postfilter handle */ + ) + { + int16_t i; + + set_f(hMusicPF->dct_post_old_exc, 0, DCT_L_POST - OFFSET2); + + hMusicPF->LDm_enh_min_ns_gain = (float)pow(10.0f, -12 / 20.0f); + hMusicPF->LDm_last_music_flag = 0; + set_f(hMusicPF->LDm_lt_diff_etot, 0, MAX_LT); + hMusicPF->LDm_thres[0] = TH_0_MIN; + hMusicPF->LDm_thres[1] = TH_1_MIN; + hMusicPF->LDm_thres[2] = TH_2_MIN; + hMusicPF->LDm_thres[3] = TH_3_MIN; + hMusicPF->LDm_nb_thr_1 = 0; + hMusicPF->LDm_nb_thr_3 = 0; + hMusicPF->LDm_mem_etot = 0.0f; + + for (i = 0; i < VOIC_BINS_HR; i++) + { + hMusicPF->LDm_enh_lp_gbin[i] = 1.0f; + hMusicPF->LDm_enh_lf_EO[i] = 0.01f; + } + + for (i = 0; i < MBANDS_GN_LD; i++) + { + hMusicPF->LDm_bckr_noise[i] = E_MIN; + } + + set_f(hMusicPF->filt_lfE, 1.0f, DCT_L_POST); + hMusicPF->last_nonfull_music = 0; + + return; + } +#endif \ No newline at end of file diff --git a/lib_dec/core_dec_init.c b/lib_dec/core_dec_init.c index 112074bcc..458f82feb 100644 --- a/lib_dec/core_dec_init.c +++ b/lib_dec/core_dec_init.c @@ -1449,7 +1449,7 @@ void open_decoder_LPD( * * Initialization TCX-LTP handle *-----------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void tcxltp_dec_init( TCX_LTP_DEC_HANDLE hTcxLtpDec, const int16_t ini_frame, @@ -1489,7 +1489,39 @@ void tcxltp_dec_init( return; } +#else +void tcxltp_dec_init( + TCX_LTP_DEC_HANDLE hTcxLtpDec, + const int16_t ini_frame, + const int16_t last_codec_mode, + const int16_t element_mode, + const int16_t pit_max, + const int32_t sr_core) +{ + hTcxLtpDec->tcxltp_gain_float = 0.0f; + + hTcxLtpDec->tcxltp = getTcxLtp(sr_core); + + if (ini_frame == 0 || (last_codec_mode == MODE1 && element_mode == EVS_MONO)) + { + hTcxLtpDec->tcxltp_pitch_int = pit_max; + hTcxLtpDec->tcxltp_pitch_fr = 0; + + if (ini_frame == 0) + { + set_f(hTcxLtpDec->tcxltp_mem_in_float, 0.0f, TCXLTP_MAX_DELAY); + set_f(hTcxLtpDec->tcxltp_mem_out_float, 0.0f, L_FRAME48k); + hTcxLtpDec->tcxltp_pitch_int_post_prev = 0; + hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0; + hTcxLtpDec->tcxltp_gain_post_prev_float = 0.f; + hTcxLtpDec->tcxltp_filt_idx_prev = -1; + } + } + + return; +} +#endif /*-----------------------------------------------------------------------* * reset_tcx_overl_buf() * diff --git a/lib_dec/hq_core_dec.c b/lib_dec/hq_core_dec.c index 5c4b16a56..839d6b299 100644 --- a/lib_dec/hq_core_dec.c +++ b/lib_dec/hq_core_dec.c @@ -649,7 +649,7 @@ void hq_core_dec( * * Initialize HQ core state structure *-------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void HQ_core_dec_init_flt( HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ ) @@ -745,6 +745,80 @@ void HQ_core_dec_init_flt( return; } +#else +void HQ_core_dec_init_flt( + HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ +) +{ + + set_f(hHQ_core->old_out, 0, L_FRAME48k); + set_f(hHQ_core->old_outLB, 0, L_FRAME32k); + set_s(hHQ_core->old_is_transient, 0, 3); + + hHQ_core->oldHqVoicing = 0; + + set_f(hHQ_core->prev_noise_level, 0.0f, 2); + hHQ_core->prev_R = 0; + set_f(hHQ_core->prev_coeff_out, 0, L_HQ_WB_BWE); + set_s(hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM); + + /* HQ GENERIC */ + hHQ_core->hq_generic_seed = RANDOM_INITSEED; + + hHQ_core->mem_norm[0] = 31; + set_s(hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1); + hHQ_core->mem_env_delta = 0; + hHQ_core->no_att_hangover = 0; + hHQ_core->energy_lt = 300.0f; + + hHQ_core->HqVoicing = 0; + set_f(hHQ_core->fer_samples, 0, L_FRAME48k); + set_f(hHQ_core->prev_env, 0, SFM_N_WB); + set_f(hHQ_core->prev_normq, 0, SFM_N_WB); + hHQ_core->prev_hqswb_clas = HQ_NORMAL; + + set_f(hHQ_core->last_ni_gain, 0, BANDS_MAX); + set_f(hHQ_core->last_env, 0, BANDS_MAX); + hHQ_core->last_max_pos_pulse = 0; + hHQ_core->prev_frm_hfe2 = 0; + hHQ_core->prev_stab_hfe2 = 0; + hHQ_core->prev_ni_ratio = 0.5f; + set_f(hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS); + + + /*----------------------------------------------------------------------------------* + * HQ FEC + *----------------------------------------------------------------------------------*/ + + set_f(hHQ_core->X_sav, 0.0f, PH_ECU_SPEC_SIZE); + hHQ_core->num_p = 0; + hHQ_core->ph_ecu_active = 0; + hHQ_core->ni_seed_forfec = 0; + hHQ_core->last_fec = 0; + hHQ_core->ph_ecu_HqVoicing = 0; + set_f(hHQ_core->oldgapsynth, 0.0f, L_FRAME48k); + hHQ_core->env_stab = 0.75f; + hHQ_core->mem_norm_hqfec[0] = 31; + set_s(hHQ_core->mem_norm_hqfec + 1, 39, SFM_N_ENV_STAB - 1); + hHQ_core->mem_env_delta_hqfec = 0; + hHQ_core->env_stab_plc = 0.0f; + set_f(hHQ_core->env_stab_state_p, 1.0f / NUM_ENV_STAB_PLC_STATES, NUM_ENV_STAB_PLC_STATES); + hHQ_core->envstabplc_hocnt = 0; + + set_f(hHQ_core->mag_chg_1st, 1.0f, LGW_MAX); + set_f(hHQ_core->Xavg, 0.0f, LGW_MAX); + hHQ_core->beta_mute = BETA_MUTE_FAC_INI_FLT; + + hHQ_core->time_offs = 0; + hHQ_core->ber_occured_in_pvq = 0; + + hHQ_core->last_hq_core_type = -1; + + reset_preecho_dec(hHQ_core); + + return; +} +#endif #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* diff --git a/lib_dec/igf_dec.c b/lib_dec/igf_dec.c index 621ea8546..c9251d4d6 100644 --- a/lib_dec/igf_dec.c +++ b/lib_dec/igf_dec.c @@ -1603,7 +1603,7 @@ void IGFDecRestoreTCX10SubFrameData_flt( * * Initialize IGF decoder parameters *-----------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void init_igf_dec_flt( IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: IGF decoder handle */ ) @@ -1625,8 +1625,24 @@ void init_igf_dec_flt( #endif return; } - - +#else +void init_igf_dec_flt( + IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: IGF decoder handle */ +) +{ + set_c((int8_t *)(hIGFDec->infoTCXNoiseBuf), 0, IGF_START_MX); + set_f(hIGFDec->igfData.pSpecFlatBuf, 0, IGF_START_MX); + hIGFDec->igfData.igfInfo.nfSeedBuf[0] = 9733; + hIGFDec->igfData.igfInfo.nfSeedBuf[1] = 9733; + hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0]; + hIGFDec->igfData.pSpecFlat_float = &hIGFDec->igfData.pSpecFlatBuf[0]; + hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; + hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0]; + hIGFDec->virtualSpec_float = &hIGFDec->virtualSpecBuf[0]; + + return; +} +#endif /*-----------------------------------------------------------------------* * get_igf_startline_flt() * diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index 67f65d1af..c916a9dd9 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -974,7 +974,7 @@ ivas_error ivas_cldfb_dec_reconfig_fx( /* resample CLDFB analysis instances */ FOR( i = 0; i < min( numCldfbAnalyses, numCldfbAnalyses_old ); i++ ) { - IF( EQ_32( L_mult0( extract_l(L_mult0( st_ivas->cldfbAnaDec[i]->no_channels, st_ivas->cldfbAnaDec[i]->no_col )), FRAMES_PER_SEC ), hDecoderConfig->output_Fs ) ) + IF( NE_32( L_mult0( extract_l(L_mult0( st_ivas->cldfbAnaDec[i]->no_channels, st_ivas->cldfbAnaDec[i]->no_col )), FRAMES_PER_SEC ), hDecoderConfig->output_Fs ) ) { resampleCldfb_ivas_fx( st_ivas->cldfbAnaDec[i], hDecoderConfig->output_Fs ); } @@ -1027,7 +1027,7 @@ ivas_error ivas_cldfb_dec_reconfig_fx( FOR( i = 0; i < st_ivas->cldfbAnaDec[0]->cldfb_state_length; i++ ) st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i], 16 ); // Scaling down from 27 to 11 FOR( i = 0; i < st_ivas->cldfbSynDec[0]->cldfb_state_length; i++ ) - st_ivas->cldfbSynDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbSynDec[0]->cldfb_state_fx[i], 21- Q_cldfbSynDec); // Scaling down from 21 to Q_cldfbSynDec + st_ivas->cldfbSynDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbSynDec[0]->cldfb_state_fx[i], 21- 11); // Scaling down from 21 to 11 } return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 09d03335f..4b28d4b99 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -79,6 +79,7 @@ typedef struct parameter_band_mapping_struct *-----------------------------------------------------------------------*/ 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_fx( PARAM_MC_DEC_HANDLE hParamMC, const Word16 nchan_in, const Word16 nchan_out ); static void param_mc_protoSignalComputation( float *RealBuffer, float *ImagBuffer, float *proto_frame_f, const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, const int16_t num_freq_bands ); #ifdef IVAS_FLOAT_FIXED @@ -131,7 +132,7 @@ static void ivas_param_mc_bs_decode_parameter_values( uint16_t bit_buffer[], int #ifdef IVAS_FLOAT_FIXED static void ivas_param_mc_bs_decode_parameter_values_fx(UWord16 bit_buffer[], Word16 *bit_pos, const Word16 max_bits, Word16 *BER_detect, HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC, HANDLE_PARAM_MC_PARAMETER_CODING_INFO hParamCodingInfo, const Word16 map_size_wo_lfe, const Word16 map_size, const Word16 num_lfe_bands, const Word16 band_step, const Word16 num_param_bands, Word16 *value_buffer); static void ivas_param_mc_dequantize_cov_fx(PARAM_MC_DEC_HANDLE hParamMC, Word16 *ild_q_fx, Word16 *icc_q_fx, const Word16 param_band_index, const Word16 nY_cov, const PARAM_MC_SYNTHESIS_CONF synth_conf, const Word16 nY_int, const Word16 nX, Word32 *Cx_state_fx, Word16 Cx_state_e, Word32 *Cproto_fx, Word16 Cproto_e, Word32 *Cy_state_fx, Word16 *Cy_state_e); -static ivas_error param_mc_get_diff_proto_info_fx(const Word32 *proto_mtx, const UWord16 nchan_transport, const UWord16 nchan_out_cov, PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info); +static ivas_error param_mc_get_diff_proto_info_fx(const Word32 *proto_mtx, const UWord16 nchan_transport, const UWord16 nchan_out_cov, PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info, Word16 Q_proto_mtx); static void param_mc_update_mixing_matrices_fx( PARAM_MC_DEC_HANDLE hParamMC, Word32 *mixing_matrix[], Word16 *mixing_matrix_fx, Word32 *mixing_matrix_res[], Word16 *mixing_matrix_res_exp, const UWord16 nX, const UWord16 nY ); #endif @@ -140,7 +141,452 @@ static void param_mc_update_mixing_matrices_fx( PARAM_MC_DEC_HANDLE hParamMC, Wo * * Open Parametric MC decoder handle *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_param_mc_dec_open_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + Word16 k, nchan_transport; + PARAM_MC_DEC_HANDLE hParamMC; +#ifndef FIX_901_PARAMMC_DEAD_CODE + IVAS_OUTPUT_SETUP hTransportSetup; +#endif + Word16 nchan_out_transport; + Word16 nchan_out_cov; + Word32 proto_matrix_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; + Word32 proto_mtx_norm_fx; + Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX]; + Word16 max_param_band_residual; + UWord16 config_index; + MC_LS_SETUP mc_ls_setup; + AUDIO_CONFIG output_config; + Word32 output_Fs, ivas_total_brate; + ivas_error error; + + error = IVAS_ERR_OK; + + /*-----------------------------------------------------------------* + * prepare library opening + *-----------------------------------------------------------------*/ + + if ( ( hParamMC = (PARAM_MC_DEC_HANDLE) malloc( sizeof( PARAM_MC_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + + if ( ( hParamMC->hMetadataPMC = (HANDLE_IVAS_PARAM_MC_METADATA) malloc( sizeof( IVAS_PARAM_MC_METADATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC metadata \n" ) ); + } + + output_Fs = st_ivas->hDecoderConfig->output_Fs; + output_config = st_ivas->hDecoderConfig->output_config; + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; +#ifndef FIX_901_PARAMMC_DEAD_CODE + hTransportSetup = st_ivas->hTransSetup; +#endif + mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); + nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; + hParamMC->hoa_encoder_fx = NULL; +#if 1/*TODO: To be removed later(floating pointer initialization)*/ + hParamMC->hoa_encoder = NULL; +#endif + + /* determine the synthesis config */ + if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD || st_ivas->transport_config == output_config ) + { + hParamMC->synthesis_conf = PARAM_MC_SYNTH_DIRECT; + } + else if ( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) + { + hParamMC->synthesis_conf = PARAM_MC_SYNTH_MONO_STEREO; + } + else if ( st_ivas->transport_config != output_config ) + { + if ( ( output_config != IVAS_AUDIO_CONFIG_LS_CUSTOM && nchan_out_transport > audioCfg2channels( output_config ) ) || ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && nchan_out_transport > st_ivas->hOutSetup.nchan_out_woLFE ) ) + { + hParamMC->synthesis_conf = PARAM_MC_SYNTH_LS_CONV_COV; + /* need to reset the intern config */ + st_ivas->intern_config = output_config; + ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); + if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + { + st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->hLsSetupCustom->num_spk; +#if 1/*TODO: To be removed later*/ + st_ivas->hIntSetup.ls_azimuth = st_ivas->hLsSetupCustom->ls_azimuth; + st_ivas->hIntSetup.ls_elevation = st_ivas->hLsSetupCustom->ls_elevation; +#endif + st_ivas->hIntSetup.ls_azimuth_fx = st_ivas->hLsSetupCustom->ls_azimuth_fx; + st_ivas->hIntSetup.ls_elevation_fx = st_ivas->hLsSetupCustom->ls_elevation_fx; + } + } + else + { + hParamMC->synthesis_conf = PARAM_MC_SYNTH_LS_CONV_CLDFB; + } + } + +#if 1/*TODO: To be removed later*/ + hParamMC->ls_conv_dmx_matrix = NULL; +#endif + hParamMC->ls_conv_dmx_matrix_fx = NULL; + + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + { + nchan_out_cov = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; + } + else + { + nchan_out_cov = nchan_out_transport; + } + + st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_ls_setup ); + config_index = ivas_param_mc_get_configuration_index( mc_ls_setup, ivas_total_brate ); + nchan_transport = st_ivas->nchan_transport; + + switch ( nchan_transport ) + { + case 4: + case 3: + st_ivas->nCPE = 2; + st_ivas->nSCE = 0; + st_ivas->element_mode_init = IVAS_CPE_MDCT; + break; + case 2: + st_ivas->nCPE = 1; + st_ivas->nSCE = 0; + st_ivas->element_mode_init = IVAS_CPE_MDCT; + + break; + } + + /*-----------------------------------------------------------------* + * set input parameters + *-----------------------------------------------------------------*/ + + hParamMC->slot_size = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX; + set_s( hParamMC->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); + set_s( hParamMC->subframe_nbslots, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); + hParamMC->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; + + hParamMC->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); + hParamMC->max_band_energy_compensation = hParamMC->num_freq_bands; +#ifndef FIX_901_PARAMMC_DEAD_CODE + ivas_param_mc_metadata_open( mc_ls_setup, hTransportSetup.index_lfe[0], ivas_total_brate, hParamMC->hMetadataPMC ); +#else + ivas_param_mc_metadata_open( mc_ls_setup, ivas_total_brate, hParamMC->hMetadataPMC ); +#endif + + /* init arrays for quantized parameters */ + + if ( ( hParamMC->icc_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( Word16 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + if ( ( hParamMC->icld_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( Word16 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + set16_fx( hParamMC->icld_q_fx, PARAM_MC_DEFAULT_MIN_ILD_FX, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); + set16_fx( hParamMC->icc_q_fx, 0, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); + +#if 1/*TODO: To be removed later(floating point initialization)*/ + if ( ( hParamMC->icc_q = (float *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + if ( ( hParamMC->icld_q = (float *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } +#endif + + param_mc_set_num_synth_bands( output_Fs, hParamMC ); + + /* Band Grouping */ + if ( hParamMC->hMetadataPMC->num_parameter_bands == 20 ) + { + mvs2s( param_mc_band_grouping_20, hParamMC->band_grouping, 20 + 1 ); + } + else if ( hParamMC->hMetadataPMC->num_parameter_bands == 14 ) + { + mvs2s( param_mc_band_grouping_14, hParamMC->band_grouping, 14 + 1 ); + } + else if ( hParamMC->hMetadataPMC->num_parameter_bands == 10 ) + { + mvs2s( param_mc_band_grouping_10, hParamMC->band_grouping, 10 + 1 ); + } + else + { + assert( 0 && "nbands must be 20, 14, or 10!" ); + } + + /* set max parameter band for abs cov */ + k = 0; + while ( hParamMC->band_grouping[k] <= PARAM_MC_MAX_BAND_ABS_COV_DEC ) + { + hParamMC->max_param_band_abs_cov = ( k++ ); + } + + /*-----------------------------------------------------------------* + * open sub-modules + *-----------------------------------------------------------------*/ + + /* prototype signal computation */ + + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_CLDFB || hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + { + if ( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */ + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + { +#if 1/*TODO: To be removed later (floating point malloc)*/ + if ( ( hParamMC->ls_conv_dmx_matrix = (float *) malloc( nchan_out_transport * nchan_out_cov * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } +#endif + IF( ( hParamMC->ls_conv_dmx_matrix_fx = (Word32 *) malloc( nchan_out_transport * nchan_out_cov * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + + for ( k = 0; k < nchan_out_transport; k++ ) + { + Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov], nchan_out_cov );/*Q30*/ + } + + /* convert ParamMC parameter bands to SFB */ + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + { + st_ivas->hLsSetUpConversion->sfbCnt = hParamMC->num_param_bands_synth; + for ( k = 0; k <= hParamMC->num_param_bands_synth; k++ ) + { + st_ivas->hLsSetUpConversion->sfbOffset[k] = PARAM_MC_BAND_TO_MDCT_BAND_RATIO * hParamMC->band_grouping[k]; + } + } + else + { + /* close the ls conversion handle immediately, it was only needed to get the DMX matrix in case of DMX in the covariance domain */ + ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); + } + } + } + if ( ( hParamMC->proto_matrix_int_fx = (Word32 *) malloc( nchan_out_transport * nchan_transport * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, hParamMC->proto_matrix_int_fx, nchan_transport * nchan_out_transport );/*Q31*/ + + if ( ( hParamMC->proto_matrix_int = (float *) malloc( nchan_out_transport * nchan_transport * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + { + Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_transport * nchan_out_cov, -4 ); /*Q.26*/ + matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0, ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0, proto_matrix_fx );/*Q.26*/ + Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_transport * nchan_out_cov, 4 ); /*Q.26*/ + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + { + proto_mtx_norm_fx = ONE_IN_Q26;/*Q26*/ + for ( k = 0; k < nchan_transport * nchan_out_cov; k++ ) + { + proto_mtx_norm_fx = L_max(L_abs(proto_mtx_norm_fx), L_abs( proto_matrix_fx[k] ) );/*Q.26*/ + } + proto_mtx_norm_fx = divide3232(ONE_IN_Q26 , proto_mtx_norm_fx);/*Q15*/ + + /* transfer flattened proto_matrix to 2D in hLsSetupConversion->dmxMtx */ + for ( k = 0; k < nchan_transport; k++ ) + { + for ( int16_t i = 0; i < nchan_out_cov; i++ ) + { + st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl(Mult_32_16(proto_matrix_fx[k * nchan_out_cov + i] , extract_l(proto_mtx_norm_fx)),4);/*Q.30*/ + } + } + } + } + else + { + Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, nchan_out_transport * nchan_transport );/*Q.31*/ + Scale_sig32( proto_matrix_fx, nchan_out_transport * nchan_transport, -5);/*Scaling down to 26*/ + } + + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + { + hParamMC->num_outputs_diff = 0; + hParamMC->diff_proto_info = NULL; + hParamMC->h_output_synthesis_params.use_onset_filters = 0; + hParamMC->max_band_decorr = 0; + hParamMC->h_freq_domain_decorr_ap_params = NULL; + hParamMC->h_freq_domain_decorr_ap_state = NULL; + } + else + { + hParamMC->num_outputs_diff = nchan_out_cov; + if ( ( hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + + if ( ( error = param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info ,Q26) ) != IVAS_ERR_OK ) + { + return error; + } + + /* decorrelation */ + hParamMC->h_freq_domain_decorr_ap_params = NULL; + hParamMC->h_freq_domain_decorr_ap_state = NULL; + + ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); + + IF( ( error = ivas_dirac_dec_decorr_open_fx( &( hParamMC->h_freq_domain_decorr_ap_params ), &( hParamMC->h_freq_domain_decorr_ap_state ), hParamMC->num_freq_bands, hParamMC->num_outputs_diff, hParamMC->diff_proto_info->num_protos_diff, + DIRAC_SYNTHESIS_COV_MC_LS, frequency_axis_fx, nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + + hParamMC->h_output_synthesis_params.use_onset_filters = 0; + hParamMC->max_band_decorr = hParamMC->h_freq_domain_decorr_ap_params->max_band_decorr; + } + hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->hMetadataPMC->nbands_coded]; + max_param_band_residual = 0; + + for ( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- ) + { + if ( hParamMC->band_grouping[k] <= hParamMC->max_band_decorr ) + { + max_param_band_residual = k; + assert( hParamMC->band_grouping[k] == hParamMC->max_band_decorr ); + break; + } + } + + /* output synthesis */ + if ( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ) != IVAS_ERR_OK ) + { + return error; + } + + ivas_param_mc_dec_compute_interpolator_fx( 0, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hParamMC->h_output_synthesis_params.interpolator_fx ); + + /* Head or external rotation */ + if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) + { +#if 1/*TODO : To be removed later*/ + IF ( ( hParamMC->hoa_encoder = (float *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } +#endif + IF ( ( hParamMC->hoa_encoder_fx = (Word32 *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof(Word32) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + compute_hoa_encoder_mtx_fx( st_ivas->hTransSetup.ls_azimuth_fx, st_ivas->hTransSetup.ls_elevation_fx, hParamMC->hoa_encoder_fx, st_ivas->hTransSetup.nchan_out_woLFE, HEAD_ROTATION_HOA_ORDER ); + } + + /*-----------------------------------------------------------------* + * memory allocation + *-----------------------------------------------------------------*/ + + IF ( GT_16(hParamMC->max_band_decorr , 0) ) + { +#if 1/*TODO: To be removed later(floating point malloc)*/ + IF ( ( hParamMC->proto_frame_f = (float *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + IF ( ( hParamMC->proto_frame_dec_f = (float *) malloc( 2 * nchan_out_cov * hParamMC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } +#endif + IF ( ( hParamMC->proto_frame_f_fx = (Word32 *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + IF ( ( hParamMC->proto_frame_dec_f_fx = (Word32 *) malloc( 2 * nchan_out_cov * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + } + ELSE + { +#if 1/*TODO: To be removed later*/ + hParamMC->proto_frame_f = NULL; + hParamMC->proto_frame_dec_f = NULL; +#endif + hParamMC->proto_frame_f_fx = NULL; + hParamMC->proto_frame_dec_f_fx = NULL; + } + + ivas_param_mc_dec_init_fx( hParamMC, nchan_transport, nchan_out_cov ); + + IF ( hParamMC->synthesis_conf != PARAM_MC_SYNTH_MONO_STEREO ) + { + Word16 n_cldfb_slots; + + n_cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS; + IF ( st_ivas->hDecoderConfig->Opt_tsm ) + { + n_cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS; + } + + IF( ( hParamMC->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); + } + set32_fx( hParamMC->Cldfb_RealBuffer_tc_fx, 0, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); + IF( ( hParamMC->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); + } + set32_fx( hParamMC->Cldfb_ImagBuffer_tc_fx, 0, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); + +#if 1/*TODO: To be removed later(floating point malloc)*/ + if ( ( hParamMC->Cldfb_RealBuffer_tc = (float *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); + } + set_zero( hParamMC->Cldfb_RealBuffer_tc, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); + if ( ( hParamMC->Cldfb_ImagBuffer_tc = (float *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); + } + set_zero( hParamMC->Cldfb_ImagBuffer_tc, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); +#endif + + IF ( st_ivas->hTcBuffer == NULL ) + { + IF ( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, 0, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + ELSE + { + hParamMC->Cldfb_RealBuffer_tc_fx = NULL; + hParamMC->Cldfb_ImagBuffer_tc_fx = NULL; +#if 1/*TODO: To be removed later*/ + hParamMC->Cldfb_RealBuffer_tc = NULL; + hParamMC->Cldfb_ImagBuffer_tc = NULL; +#endif + } + + hParamMC->subframes_rendered = 0; + hParamMC->slots_rendered = 0; + st_ivas->hParamMC = hParamMC; + return error; +} +#endif ivas_error ivas_param_mc_dec_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) @@ -489,12 +935,12 @@ ivas_error ivas_param_mc_dec_open( /* output synthesis */ #ifdef IVAS_FLOAT_FIXED - floatToFixed_arrL( proto_matrix, proto_matrix_fx, Q30, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS ); + floatToFixed_arrL( proto_matrix, proto_matrix_fx, Q26, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS ); if ( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ) != IVAS_ERR_OK ) { return error; } - fixedToFloat_arrL( hParamMC->h_output_synthesis_params.proto_matrix_fx, hParamMC->h_output_synthesis_params.proto_matrix, 30, nchan_transport * nchan_out_cov ); + fixedToFloat_arrL( hParamMC->h_output_synthesis_params.proto_matrix_fx, hParamMC->h_output_synthesis_params.proto_matrix, Q26, nchan_transport * nchan_out_cov ); #else if ( ( error = ivas_dirac_dec_output_synthesis_cov_open( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix ) ) != IVAS_ERR_OK ) @@ -966,7 +1412,6 @@ ivas_error ivas_param_mc_dec_reconfig_fx( FOR ( k = 0; k < nchan_out_transport; k++ ) { Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov], nchan_out_cov ); - Scale_sig32( &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov],nchan_out_cov,1 ); } } /* convert ParamMC parameter bands to SFB */ @@ -1001,26 +1446,27 @@ ivas_error ivas_param_mc_dec_reconfig_fx( IF ( EQ_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_LS_CONV_COV) || EQ_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_MONO_STEREO) ) { + Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_transport * nchan_out_cov, -4 ); matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0, ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0, - proto_matrix_fx ); + proto_matrix_fx /*Q26*/); + Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_transport * nchan_out_cov, 4 ); IF ( EQ_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_MONO_STEREO) ) { - proto_mtx_norm_fx = MAX_32; + proto_mtx_norm_fx = ONE_IN_Q26; FOR ( k = 0; k < nchan_transport * nchan_out_cov; k++ ) { proto_mtx_norm_fx = L_max(L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); } - proto_mtx_norm_fx = divide3232(1 , proto_mtx_norm_fx);/*Q15*/ + proto_mtx_norm_fx = divide3232(ONE_IN_Q26 , proto_mtx_norm_fx);/*Q15*/ /* transfer flattened proto_matrix to 2D in hLsSetupConversion->dmxMtx */ FOR ( k = 0; k < nchan_transport; k++ ) { FOR ( Word16 i = 0; i < nchan_out_cov; i++ ) { - st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shr(Mpy_32_16_1(proto_matrix_fx[k * nchan_out_cov + i] , (Word16)proto_mtx_norm_fx),1); - st_ivas->hLsSetUpConversion->dmxMtx[k][i] = fixedToFloat( st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i], Q30 ); + st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl(Mpy_32_16_1(proto_matrix_fx[k * nchan_out_cov + i] , (Word16)proto_mtx_norm_fx),4); } } } @@ -1028,6 +1474,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( ELSE { Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, nchan_out_transport * nchan_transport ); + Scale_sig32( proto_matrix_fx, nchan_out_transport * nchan_transport, -5 ); } IF ( NE_16(nchan_transport_old , nchan_transport) && NE_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_MONO_STEREO) ) @@ -1081,7 +1528,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - IF ( ( param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info ) ) != IVAS_ERR_OK ) + IF ( ( param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info ,Q26) ) != IVAS_ERR_OK ) { return error; } @@ -1852,7 +2299,173 @@ int16_t param_mc_get_num_cldfb_syntheses( * * Close Parametric MC memories *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_param_mc_dec_close_fx( + PARAM_MC_DEC_HANDLE *hParamMC_out /* i/o: Parametric MC decoder handle */ +) +{ + UWord16 i; + PARAM_MC_DEC_HANDLE hParamMC; + + IF( hParamMC_out == NULL || *hParamMC_out == NULL ) + { + return; + } + + hParamMC = *hParamMC_out; + + /* close sub-modules */ + ivas_dirac_dec_output_synthesis_cov_close_fx( &hParamMC->h_output_synthesis_params, &hParamMC->h_output_synthesis_cov_state ); + + IF( hParamMC->h_freq_domain_decorr_ap_params != NULL || hParamMC->h_freq_domain_decorr_ap_state != NULL ) + { + ivas_dirac_dec_decorr_close( &hParamMC->h_freq_domain_decorr_ap_params, &hParamMC->h_freq_domain_decorr_ap_state ); + } + + /* parameter decoding */ + IF( hParamMC->hMetadataPMC != NULL ) + { +#ifndef FIX_901_PARAMMC_DEAD_CODE + ivas_param_mc_metadata_close( hParamMC->hMetadataPMC ); +#endif + free( hParamMC->hMetadataPMC ); + hParamMC->hMetadataPMC = NULL; + } + IF( hParamMC->icc_q_fx != NULL ) + { + free( hParamMC->icc_q_fx ); + hParamMC->icc_q_fx = NULL; + } + + IF( hParamMC->icld_q_fx != NULL ) + { + free( hParamMC->icld_q_fx ); + hParamMC->icld_q_fx = NULL; + } + /* diffuse prototype info */ + IF( hParamMC->diff_proto_info ) + { + FOR( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) + { + free( hParamMC->diff_proto_info->source_chan_idx[i] ); + hParamMC->diff_proto_info->source_chan_idx[i] = NULL; + + free( hParamMC->diff_proto_info->proto_fac_fx[i] ); + hParamMC->diff_proto_info->proto_fac_fx[i] = NULL; + } + + free( hParamMC->diff_proto_info->source_chan_idx ); + hParamMC->diff_proto_info->source_chan_idx = NULL; + + free( hParamMC->diff_proto_info->proto_fac_fx ); + hParamMC->diff_proto_info->proto_fac_fx = NULL; + + free( hParamMC->diff_proto_info->proto_index_diff ); + hParamMC->diff_proto_info->proto_index_diff = NULL; + + free( hParamMC->diff_proto_info->num_source_chan_diff ); + hParamMC->diff_proto_info->num_source_chan_diff = NULL; + + free( hParamMC->diff_proto_info ); + hParamMC->diff_proto_info = NULL; + } + /* States */ + /* free prototype signal buffers */ + IF( hParamMC->proto_frame_f_fx != NULL ) + { + free( hParamMC->proto_frame_f_fx ); + hParamMC->proto_frame_f_fx = NULL; + } + + IF( hParamMC->proto_frame_dec_f_fx != NULL ) + { + free( hParamMC->proto_frame_dec_f_fx); + hParamMC->proto_frame_dec_f_fx = NULL; + } + + IF( hParamMC->ls_conv_dmx_matrix_fx != NULL ) + { + free( hParamMC->ls_conv_dmx_matrix_fx ); + hParamMC->ls_conv_dmx_matrix_fx = NULL; + } + + IF( hParamMC->proto_matrix_int_fx != NULL ) + { + free( hParamMC->proto_matrix_int_fx ); + hParamMC->proto_matrix_int_fx = NULL; + } + + IF( hParamMC->hoa_encoder_fx != NULL ) + { + free( hParamMC->hoa_encoder_fx ); + hParamMC->hoa_encoder_fx = NULL; + } + IF( hParamMC->Cldfb_RealBuffer_tc_fx != NULL ) + { + free( hParamMC->Cldfb_RealBuffer_tc_fx ); + hParamMC->Cldfb_RealBuffer_tc_fx = NULL; + } + IF( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL ) + { + free( hParamMC->Cldfb_ImagBuffer_tc_fx ); + hParamMC->Cldfb_ImagBuffer_tc_fx = NULL; + } +#if 1 /*TODO: To be removed later(Floating point memory dealloc)------------------------------- */ + + IF( hParamMC->icc_q != NULL ) + { + free( hParamMC->icc_q ); + hParamMC->icc_q = NULL; + } + + IF( hParamMC->icld_q != NULL ) + { + free( hParamMC->icld_q ); + hParamMC->icld_q = NULL; + } + IF( hParamMC->diff_proto_info ) + { + FOR( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) + { + free( hParamMC->diff_proto_info->proto_fac[i] ); + hParamMC->diff_proto_info->proto_fac[i] = NULL; + } + free( hParamMC->diff_proto_info->proto_fac ); + hParamMC->diff_proto_info->proto_fac = NULL; + } + IF( hParamMC->proto_frame_f != NULL ) + { + free( hParamMC->proto_frame_f ); + hParamMC->proto_frame_f = NULL; + } + IF( hParamMC->proto_frame_dec_f != NULL ) + { + free( hParamMC->proto_frame_dec_f ); + hParamMC->proto_frame_dec_f = NULL; + } + IF( hParamMC->ls_conv_dmx_matrix != NULL ) + { + free( hParamMC->ls_conv_dmx_matrix ); + hParamMC->ls_conv_dmx_matrix = NULL; + } + IF( hParamMC->Cldfb_RealBuffer_tc != NULL ) + { + free( hParamMC->Cldfb_RealBuffer_tc ); + hParamMC->Cldfb_RealBuffer_tc = NULL; + } + IF( hParamMC->Cldfb_ImagBuffer_tc != NULL ) + { + free( hParamMC->Cldfb_ImagBuffer_tc ); + hParamMC->Cldfb_ImagBuffer_tc = NULL; + } +#endif /***********************************ends here************************************************/ + + free( *hParamMC_out ); + *hParamMC_out = NULL; + return; +} +#endif void ivas_param_mc_dec_close( PARAM_MC_DEC_HANDLE *hParamMC_out /* i/o: Parametric MC decoder handle */ ) @@ -1978,7 +2591,6 @@ void ivas_param_mc_dec_close( return; } - /*------------------------------------------------------------------------- * ivas_param_mc_dec_read_BS() * @@ -3519,7 +4131,65 @@ void ivas_param_mc_dec( * * Parametric MC decoding initialization *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void ivas_param_mc_dec_init_fx( + PARAM_MC_DEC_HANDLE hParamMC, /* i/o: decoder DirAC handle */ + const Word16 nchan_transport, /* i : number of input (transport) channels */ + const Word16 nchan_cov ) /* i : number of cov synthesis channels */ +{ + Word16 k; + UWord16 max_param_band_residual; + Word16 len; + + /*-----------------------------------------------------------------* + * init sub-modules + *-----------------------------------------------------------------*/ + + /* decorrelation */ + IF ( GT_16(hParamMC->max_band_decorr , 0) ) + { + len = hParamMC->diff_proto_info->num_protos_diff * hParamMC->h_freq_domain_decorr_ap_params->h_onset_detection_power_params.max_band_decorr; + + /* init onsetDetectionPower */ + set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx, len ); + set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx, len ); +#if 1/*Floating point intialization: to be removed later*/ + set_zero( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1, len ); + set_zero( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2, len ); +#endif + } + + max_param_band_residual = 0; + + /* output synthesis */ + FOR ( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- ) + { + IF ( LE_16(hParamMC->band_grouping[k] , hParamMC->max_band_decorr) ) + { + max_param_band_residual = k; + break; + } + } + + ivas_dirac_dec_output_synthesis_cov_init_fx( &( hParamMC->h_output_synthesis_cov_state ), nchan_transport, nchan_cov, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual ); + + /*-----------------------------------------------------------------* + * init proto frames + *-----------------------------------------------------------------*/ + + IF ( GT_16(hParamMC->max_band_decorr , 0) ) + { +#if 1/*TODO: To be removed later*/ + set_zero( hParamMC->proto_frame_f, 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands ); + set_zero( hParamMC->proto_frame_dec_f, 2 * nchan_cov * hParamMC->num_freq_bands ); +#endif + set_zero_fx( hParamMC->proto_frame_f_fx, 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands ); + set32_fx( hParamMC->proto_frame_dec_f_fx, 0, 2 * nchan_cov * hParamMC->num_freq_bands ); + } + return; +} +#endif // IVAS_FLOAT_FIXED static void ivas_param_mc_dec_init( PARAM_MC_DEC_HANDLE hParamMC, /* i/o: decoder DirAC handle */ const int16_t nchan_transport, /* i : number of input (transport) channels */ @@ -5629,8 +6299,8 @@ static ivas_error param_mc_get_diff_proto_info_fx( const Word32 *proto_mtx, /* i : protoype matrix for the synthesis */ const UWord16 nchan_transport, /* i : number of transport channels */ const UWord16 nchan_out_cov, /* i : number if output channels of the covariance synthesis */ - PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info /* o : generated diffuse prototype info */ -) + PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info, /* o : generated diffuse prototype info */ + Word16 Q_proto_mtx ) { #if FLT_ENABLE float proto_fac[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; @@ -5698,7 +6368,7 @@ static ivas_error param_mc_get_diff_proto_info_fx( #if FLT_ENABLE if ( diff < 0.1f ) #else - if ( LT_64( diff_fx * 10, 2147483648 ) ) + if ( LT_64( diff_fx * 10, L_shl_sat(1, Q_proto_mtx)) ) #endif { found = 1; diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 47bb00816..b6366c95c 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -64,74 +64,295 @@ static ivas_error ivas_mc_dec_reconfig( Decoder_Struct *st_ivas, uint16_t *nSamp #ifndef IVAS_FLOAT_FIXED ivas_error ivas_mct_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float *output[], /* o : output synthesis signal */ + const int16_t output_frame, /* i : output frame length per channel */ + const int16_t nb_bits_metadata /* i : number of metadata bits */ +) +{ + int16_t n, nCPE, cpe_id; + MCT_DEC_HANDLE hMCT; + CPE_DEC_HANDLE hCPE; + float *x[CPE_CHANNELS][NB_DIV]; + int16_t param[MCT_MAX_BLOCKS][CPE_CHANNELS][DEC_NPRM_DIV * NB_DIV]; + int16_t param_lpc[MCT_MAX_BLOCKS][CPE_CHANNELS][NPRM_LPC_NEW]; + int16_t p_param[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + int16_t nTnsBitsTCX10[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + float Aq[MCT_MAX_BLOCKS][CPE_CHANNELS][(NB_SUBFR16k + 1) * (M + 1)]; + int16_t fUseTns[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + STnsData tnsData[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + Decoder_State **sts; + float synth[CPE_CHANNELS][L_FRAME_PLUS]; + float output_lfe_ch[L_FRAME48k]; + int32_t ivas_total_brate; + ivas_error error; + + push_wmops("ivas_mct_dec"); + + error = IVAS_ERR_OK; + nCPE = st_ivas->nCPE; + hMCT = st_ivas->hMCT; + + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + + if (st_ivas->ivas_format == MC_FORMAT && (st_ivas->mc_mode == MC_MODE_MCT || st_ivas->mc_mode == MC_MODE_PARAMUPMIX)) + { + /* save LFE channel */ + mvr2r(output[LFE_CHANNEL], output_lfe_ch, output_frame); + } + + if (st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCT && !st_ivas->bfi) + { + /* get the number of channels from the signalled MC LS setup */ + n = ivas_mc_ls_setup_get_num_channels(ivas_mc_map_output_config_to_mc_ls_setup(st_ivas->transport_config)); + + if (n != st_ivas->nchan_transport) + { + /* IVAS_fmToDo: more work needed for switching the number of transport channels */ + return IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "Error: wrong number of transport channels signalled in MC format!"); + } + } + + for (cpe_id = 0; cpe_id < nCPE; cpe_id++) + { + /*initialize param_lpc buffer*/ + for (n = 0; n < CPE_CHANNELS; n++) + { + set_s(param_lpc[cpe_id][n], 0, NPRM_LPC_NEW); + } + + if ((error = ivas_cpe_dec(st_ivas, cpe_id, output, output_frame, 0)) != IVAS_ERR_OK) + { + return error; + } + + if (cpe_id == 0) + { + st_ivas->hCPE[0]->hCoreCoder[0]->total_brate = ivas_total_brate; /* set high enough to read the whole side-info; total_brate is rewritten later in ivas_mdct_core_invQ() */ + } + + if (!st_ivas->bfi) + { + ivas_mdct_dec_side_bits_frame_channel(st_ivas->hCPE[cpe_id], param_lpc[cpe_id], p_param[cpe_id], st_ivas->hCPE[0]->hCoreCoder[0], nTnsBitsTCX10[cpe_id], param[cpe_id], 1, + ((cpe_id + 1) * CPE_CHANNELS > hMCT->nchan_out_woLFE)); + + st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect; + st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect; + } + } + + /* MCT side bits decoder */ + ivas_mct_side_bits(hMCT, st_ivas->hCPE, nCPE, st_ivas->hCPE[0]->hCoreCoder[0], st_ivas->bfi, st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream, ivas_total_brate, nb_bits_metadata); + + for (cpe_id = 0; cpe_id < nCPE; cpe_id++) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect |= st_ivas->BER_detect; + st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect |= st_ivas->BER_detect; + + for (n = 0; n < CPE_CHANNELS; n++) + { + x[n][0] = output[n + cpe_id * CPE_CHANNELS]; + x[n][1] = output[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); + set_zero(x[n][0], L_FRAME48k / 2); + set_zero(x[n][1], L_FRAME48k / 2); + } + + ivas_mdct_core_invQ(st_ivas->hCPE[cpe_id], nTnsBitsTCX10[cpe_id], p_param[cpe_id], param_lpc[cpe_id], param[cpe_id], + fUseTns[cpe_id], tnsData[cpe_id], x, x, Aq[cpe_id], NULL, 1); + + st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect; + st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect; + } + + /* MCT core decoder */ + ivas_mct_core_dec(hMCT, st_ivas->hCPE, nCPE, output); + + /* for sba to stereo output disable any further processing for TCs > 2 as it is not needed*/ + if (st_ivas->sba_dirac_stereo_flag && st_ivas->ivas_format != SBA_ISM_FORMAT) + { + for (cpe_id = 1; cpe_id < nCPE; cpe_id++) + { + for (n = 0; n < CPE_CHANNELS; n++) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + } + } + } + + /* MCT reconstruction and CoreCoder updates */ + for (cpe_id = 0; cpe_id < nCPE; cpe_id++) + { + hCPE = st_ivas->hCPE[cpe_id]; + + for (n = 0; n < CPE_CHANNELS; n++) + { + x[n][0] = output[n + cpe_id * CPE_CHANNELS]; + x[n][1] = output[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); + } + + ivas_mdct_core_tns_ns(hCPE, fUseTns[cpe_id], tnsData[cpe_id], x, Aq[cpe_id], 1); + } + + if (st_ivas->renderer_type == RENDERER_MC) + { + /* Equalization in MDCT Domain */ + ivas_ls_setup_conversion_process_mdct(st_ivas, output); + } + + else if (st_ivas->renderer_type == RENDERER_MC_PARAMMC && (st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO)) + { + float *x_all[MAX_CICP_CHANNELS][NB_DIV]; + + for (cpe_id = 0; cpe_id < nCPE; cpe_id++) + { + for (n = 0; n < CPE_CHANNELS; n++) + { + x_all[n + cpe_id * CPE_CHANNELS][0] = output[n + cpe_id * CPE_CHANNELS]; + x_all[n + cpe_id * CPE_CHANNELS][1] = output[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); + } + } + + ivas_ls_setup_conversion_process_mdct_param_mc(st_ivas, x_all); + } + + for (cpe_id = 0; cpe_id < nCPE; cpe_id++) + { + hCPE = st_ivas->hCPE[cpe_id]; + sts = hCPE->hCoreCoder; + + for (n = 0; n < CPE_CHANNELS; n++) + { + x[n][0] = output[n + cpe_id * CPE_CHANNELS]; + x[n][1] = output[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); + } + + ivas_mdct_core_reconstruct(hCPE, x, synth, fUseTns[cpe_id], 1); + + /*----------------------------------------------------------------* + * CoreCoder Post-processing and updates + *----------------------------------------------------------------*/ + + for (n = 0; n < CPE_CHANNELS; n++) + { + if (st_ivas->sba_dirac_stereo_flag && (st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2)) + { + ivas_post_proc(NULL, hCPE, n, synth[n], NULL, output_frame, 1); + } + + /* Postprocessing for ACELP/MDCT core switching and synchronization */ + if ((error = core_switching_post_dec(sts[n], synth[n], output[cpe_id * CPE_CHANNELS + n], hCPE->output_mem[1], st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, (st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2) ? st_ivas->sba_dirac_stereo_flag : 0, -1, hCPE->last_element_mode)) != IVAS_ERR_OK) + { + return error; + } + + /* final output of synthesis signal */ + mvr2r(synth[n], output[cpe_id * CPE_CHANNELS + n], output_frame); + + /* Save synthesis for HQ FEC */ + save_synthesis_hq_fec(sts[n], output[cpe_id * CPE_CHANNELS + n], output_frame, hCPE); + + /* CoreCoder common updates */ + updt_dec_common(sts[n], NORMAL_HQ_CORE, -1, output[cpe_id * CPE_CHANNELS + n]); + + } /* n_channels loop */ + + + /* synthesis synchronization between stereo modes */ + if (!st_ivas->sba_dirac_stereo_flag || (st_ivas->ivas_format == SBA_ISM_FORMAT && cpe_id < nCPE - 2)) + { + synchro_synthesis(ivas_total_brate, hCPE, output + cpe_id * CPE_CHANNELS, output_frame, 0); + } + + } + + /* move channels after LFE to correct output for multi-channel MCT */ + if (st_ivas->ivas_format == MC_FORMAT && (st_ivas->mc_mode == MC_MODE_MCT || st_ivas->mc_mode == MC_MODE_PARAMUPMIX)) + { + float tmp[L_FRAME48k]; + + /*save center channel output*/ + mvr2r(output[hMCT->nchan_out_woLFE - 1], tmp, output_frame); + + for (n = hMCT->nchan_out_woLFE - 1; n >= LFE_CHANNEL; n--) + { + mvr2r(output[n - 1], output[n + 1], output_frame); + } + mvr2r(tmp, output[LFE_CHANNEL - 1], output_frame); + + /* save LFE channel */ + mvr2r(output_lfe_ch, output[LFE_CHANNEL], output_frame); + } + + + pop_wmops(); + return error; +} +#else +ivas_error ivas_mct_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - float *output[], /* o : output synthesis signal */ - const int16_t output_frame, /* i : output frame length per channel */ - const int16_t nb_bits_metadata /* i : number of metadata bits */ + Word32 *output_fx[], /* o : output synthesis signal */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ ) { - int16_t n, nCPE, cpe_id; + Word16 ch, nCPE, cpe_id; MCT_DEC_HANDLE hMCT; CPE_DEC_HANDLE hCPE; - float *x[CPE_CHANNELS][NB_DIV]; - int16_t param[MCT_MAX_BLOCKS][CPE_CHANNELS][DEC_NPRM_DIV * NB_DIV]; - int16_t param_lpc[MCT_MAX_BLOCKS][CPE_CHANNELS][NPRM_LPC_NEW]; - int16_t p_param[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; - int16_t nTnsBitsTCX10[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; - float Aq[MCT_MAX_BLOCKS][CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; - int16_t fUseTns[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + Word16 param[MCT_MAX_BLOCKS][CPE_CHANNELS][DEC_NPRM_DIV * NB_DIV]; + Word16 param_lpc[MCT_MAX_BLOCKS][CPE_CHANNELS][NPRM_LPC_NEW]; + Word16 p_param[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + Word16 nTnsBitsTCX10[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + Word16 fUseTns[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; STnsData tnsData[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + Word16 Aq_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; + Word32 output_lfe_ch_fx[L_FRAME48k]; + Word16 q_output = 11; + Word16 n, k, l, i, j; + + Word32 *x_fx[CPE_CHANNELS][NB_DIV]; + Word16 x_e[MAX_CICP_CHANNELS][NB_DIV]; + Word16 x_len[CPE_CHANNELS][NB_DIV] = { 0 }; Decoder_State **sts; - float synth[CPE_CHANNELS][L_FRAME_PLUS]; - float output_lfe_ch[L_FRAME48k]; + Word16 synth_fx[CPE_CHANNELS][L_FRAME_PLUS]; int32_t ivas_total_brate; ivas_error error; -#ifdef IVAS_FLOAT_FIXED - /* TODO: Temporary fix to avoid garbage values while calculating its q-factor - when not initialised. */ - set_zero((float *)Aq, MCT_MAX_BLOCKS*CPE_CHANNELS*(NB_SUBFR16k + 1) * (M + 1)); -#endif - push_wmops( "ivas_mct_dec" ); error = IVAS_ERR_OK; nCPE = st_ivas->nCPE; + move16(); hMCT = st_ivas->hMCT; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + move32(); - if ( st_ivas->ivas_format == MC_FORMAT && ( st_ivas->mc_mode == MC_MODE_MCT || st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) ) + IF ( EQ_16(st_ivas->ivas_format, MC_FORMAT) && ( EQ_16(st_ivas->mc_mode, MC_MODE_MCT) || EQ_16(st_ivas->mc_mode, MC_MODE_PARAMUPMIX) ) ) { /* save LFE channel */ - mvr2r( output[LFE_CHANNEL], output_lfe_ch, output_frame ); + mvl2l( output_fx[LFE_CHANNEL], output_lfe_ch_fx, output_frame ); } - if ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCT && !st_ivas->bfi ) + IF ( EQ_16(st_ivas->ivas_format, MC_FORMAT) && EQ_16(st_ivas->mc_mode, MC_MODE_MCT) && EQ_16(st_ivas->bfi, 0) ) { /* get the number of channels from the signalled MC LS setup */ n = ivas_mc_ls_setup_get_num_channels( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ) ); - if ( n != st_ivas->nchan_transport ) + IF ( NE_16(n, st_ivas->nchan_transport) ) { /* IVAS_fmToDo: more work needed for switching the number of transport channels */ return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: wrong number of transport channels signalled in MC format!" ); } } - for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + FOR ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { /*initialize param_lpc buffer*/ - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR ( n = 0; n < CPE_CHANNELS; n++ ) { set_s( param_lpc[cpe_id][n], 0, NPRM_LPC_NEW ); } -#ifdef IVAS_FLOAT_FIXED - Word32 *output_fx[2]; - Word16 q_output = 11; - output_fx[0] = malloc( sizeof( Word32 ) * L_FRAME48k ); - output_fx[1] = malloc( sizeof( Word32 ) * L_FRAME48k ); set32_fx( &output_fx[0][0], 0, L_FRAME48k ); set32_fx( &output_fx[1][0], 0, L_FRAME48k ); @@ -140,1649 +361,1837 @@ ivas_error ivas_mct_dec( return error; } - for ( int k = 0; k < L_FRAME48k; k++ ) - { - output[0][k] = (float) output_fx[0][k] / ( 1 << q_output ); - output[1][k] = (float) output_fx[1][k] / ( 1 << q_output ); - } - free( output_fx[0] ); - free( output_fx[1] ); -#else - if ( ( error = ivas_cpe_dec( st_ivas, cpe_id, output, output_frame, 0 ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif // IVAS_FLOAT_FIXED - - if ( cpe_id == 0 ) + IF ( EQ_16(cpe_id, 0) ) { st_ivas->hCPE[0]->hCoreCoder[0]->total_brate = ivas_total_brate; /* set high enough to read the whole side-info; total_brate is rewritten later in ivas_mdct_core_invQ() */ + move32(); } - if ( !st_ivas->bfi ) + IF ( EQ_16(st_ivas->bfi, 0) ) { - ivas_mdct_dec_side_bits_frame_channel( st_ivas->hCPE[cpe_id], param_lpc[cpe_id], p_param[cpe_id], st_ivas->hCPE[0]->hCoreCoder[0], nTnsBitsTCX10[cpe_id], param[cpe_id], 1, - ( ( cpe_id + 1 ) * CPE_CHANNELS > hMCT->nchan_out_woLFE ) ); + ivas_mdct_dec_side_bits_frame_channel_fx( st_ivas->hCPE[cpe_id], param_lpc[cpe_id], p_param[cpe_id], st_ivas->hCPE[0]->hCoreCoder[0], nTnsBitsTCX10[cpe_id], param[cpe_id], 1, + (Word16) GT_16( i_mult(add( cpe_id, 1 ), CPE_CHANNELS ), hMCT->nchan_out_woLFE ) ); - st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect; - st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect; + st_ivas->BER_detect = s_or(st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect); + test(); + st_ivas->BER_detect = s_or(st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect); + test(); } } /* MCT side bits decoder */ - ivas_mct_side_bits( hMCT, st_ivas->hCPE, nCPE, st_ivas->hCPE[0]->hCoreCoder[0], st_ivas->bfi, st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream, ivas_total_brate, nb_bits_metadata ); + ivas_mct_side_bits_fx( hMCT, st_ivas->hCPE, nCPE, st_ivas->hCPE[0]->hCoreCoder[0], st_ivas->bfi, st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream, ivas_total_brate, nb_bits_metadata ); - for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + FOR ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { - st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect |= st_ivas->BER_detect; - st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect |= st_ivas->BER_detect; - - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - x[n][0] = output[n + cpe_id * CPE_CHANNELS]; - x[n][1] = output[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); - set_zero( x[n][0], L_FRAME48k / 2 ); - set_zero( x[n][1], L_FRAME48k / 2 ); - } - -#ifdef IVAS_FLOAT_FIXED -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - hCPE = st_ivas->hCPE[cpe_id]; - sts = hCPE->hCoreCoder; - - Word16 Aq_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; - Word16 ch, k, l, i, j; - - Word32 *x_fx[CPE_CHANNELS][NB_DIV]; - Word16 x_e[CPE_CHANNELS][NB_DIV]; - Word16 x_len[CPE_CHANNELS][NB_DIV] = { 0 }; + st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect = s_or(st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect, st_ivas->BER_detect); + test(); + st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect = s_or(st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect, st_ivas->BER_detect); + test(); - FOR( i = 0; i < CPE_CHANNELS; ++i ) + FOR ( n = 0; n < CPE_CHANNELS; n++ ) { - x_fx[i][0] = malloc( L_FRAME48k * sizeof( Word32 ) ); - x_fx[i][1] = x_fx[i][0] + L_FRAME48k / 2; - floatToFixed_arrL( x[i][0], x_fx[i][0], 0, L_FRAME48k / 2 ); - floatToFixed_arrL( x[i][1], x_fx[i][1], 0, L_FRAME48k / 2 ); - - FOR( j = 0; j < NB_DIV; ++j ) - { - x_e[i][j] = 31; - } + x_fx[n][0] = output_fx[n + cpe_id * CPE_CHANNELS]; + x_e[n][0] = 20; + x_fx[n][1] = output_fx[n + cpe_id * CPE_CHANNELS] + shr( L_FRAME48k, 1 ); + x_e[n][1] = 20; + move16(); + move16(); + + set32_fx( x_fx[n][0], 0, shr(L_FRAME48k, 1) ); + set32_fx( x_fx[n][1], 0, shr(L_FRAME48k, 1) ); } - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) - { - sts[ch]->gamma = float_to_fix16( sts[ch]->gamma_float, Q15 ); - sts[ch]->preemph_fac = float_to_fix16( sts[ch]->preemph_fac_float, Q15 ); - sts[ch]->Mode2_lp_gainp = float_to_fix( sts[ch]->lp_gainp, Q16 ); - sts[ch]->hTcxLtpDec->tcxltp_gain = float_to_fix16( sts[ch]->hTcxLtpDec->tcxltp_gain_float, Q15 ); - sts[ch]->inv_gamma = float_to_fix16( 1 / sts[ch]->gamma_float, Q14 ); - f2me_16( sts[ch]->last_gain_syn_deemph_float, &sts[ch]->last_gain_syn_deemph, &sts[ch]->last_gain_syn_deemph_e ); - f2me_16( sts[ch]->last_concealed_gain_syn_deemph_float, &sts[ch]->last_concealed_gain_syn_deemph, &sts[ch]->last_concealed_gain_syn_deemph_e ); - f2me_16( sts[ch]->hTcxDec->old_gaintcx_bfi_float, &sts[ch]->hTcxDec->old_gaintcx_bfi, &sts[ch]->hTcxDec->old_gaintcx_bfi_e ); - floatToFixed_arr( Aq[cpe_id][ch], Aq_fx[cpe_id][ch], Q12, ( NB_SUBFR16k + 1 ) * ( M + 1 ) ); - - sts[ch]->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16( sts[ch]->hTcxDec->tcxltp_last_gain_unmodified_float, Q15 ); - sts[ch]->old_fpitch = float_to_fix( sts[ch]->old_fpitch_float, Q16 ); - //sts[ch]->hTonalMDCTConc->lastPitchLag = float_to_fix( sts[ch]->hTonalMDCTConc->lastPitchLag_float, Q16 ); - // u8bit to 16bit - FOR( l = 0; l < IGF_START_MX; l++ ) - { - sts[ch]->hIGFDec->infoTCXNoise_evs[l] = (Word16) sts[ch]->hIGFDec->infoTCXNoise[l]; - } - FOR( l = 0; l < N_LTP_GAIN_MEMS; l++ ) - { - sts[ch]->hTcxDec->ltpGainMemory_fx[l] = float_to_fix16( sts[ch]->hTcxDec->ltpGainMemory[l], Q15 ); - } - sts[ch]->hTcxDec->cummulative_damping_tcx = float_to_fix16( sts[ch]->hTcxDec->cummulative_damping_tcx_float, Q15 ); - } - } - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - IF( sts[ch]->rate_switching_reset ) - { - floatToFixed_arr( sts[ch]->lsp_old, sts[ch]->lsp_old_fx, Q15, M ); - } - } -#endif ivas_mdct_core_invQ_fx( st_ivas->hCPE[cpe_id], nTnsBitsTCX10[cpe_id], p_param[cpe_id], param_lpc[cpe_id], param[cpe_id], fUseTns[cpe_id], tnsData[cpe_id], x_fx, x_e, x_fx, x_e, x_len, Aq_fx[cpe_id], NULL, 1 ); -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - IF( sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) - { - me2f_buf( x_fx[ch][0], x_e[ch][0], x[ch][0], sts[ch]->hTcxCfg->tcx_coded_lines ); - sts[ch]->hTcxDec->damping_float = fix16_to_float( sts[ch]->hTcxDec->damping, Q14 ); - sts[ch]->hTcxDec->gainHelper_float = me2f_16( sts[ch]->hTcxDec->gainHelper, sts[ch]->hTcxDec->gainHelper_e ); - sts[ch]->hTcxDec->stepCompensate_float = me2f_16( sts[ch]->hTcxDec->stepCompensate, sts[ch]->hTcxDec->stepCompensate_e ); - } - IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) - { - sts[ch]->lp_gainp = fix_to_float( sts[ch]->Mode2_lp_gainp, Q16 ); - //sts[ch]->hTonalMDCTConc->lastPitchLag_float = fix_to_float( sts[ch]->hTonalMDCTConc->lastPitchLag, Q16 ); - sts[ch]->hTonalMDCTConc->nFramesLost_float = fix16_to_float( sts[ch]->hTonalMDCTConc->nFramesLost, Q1 ); - sts[ch]->hTcxDec->damping_float = fix16_to_float( sts[ch]->hTcxDec->damping, Q14 ); - sts[ch]->hTcxDec->stepCompensate_float = me2f_16( sts[ch]->hTcxDec->stepCompensate, sts[ch]->hTcxDec->stepCompensate_e ); - sts[ch]->hTcxDec->gainHelper_float = me2f_16( sts[ch]->hTcxDec->gainHelper, sts[ch]->hTcxDec->gainHelper_e ); - sts[ch]->last_concealed_gain_syn_deemph_float = me2f_16( sts[ch]->last_concealed_gain_syn_deemph, sts[ch]->last_concealed_gain_syn_deemph_e ); - sts[ch]->last_gain_syn_deemph_float = me2f_16( sts[ch]->last_gain_syn_deemph, sts[ch]->last_gain_syn_deemph_e ); - sts[ch]->hTcxDec->old_gaintcx_bfi_float = me2f_16( sts[ch]->hTcxDec->old_gaintcx_bfi, sts[ch]->hTcxDec->old_gaintcx_bfi_e ); - fixedToFloat_arr( Aq_fx[cpe_id][ch], Aq[cpe_id][ch], Q12, ( NB_SUBFR16k + 1 ) * ( M + 1 ) ); - // 16bit to u8bit - FOR( Word16 l = 0; l < IGF_START_MX; l++ ) - { - sts[ch]->hIGFDec->infoTCXNoise[l] = (uint8_t) sts[ch]->hIGFDec->infoTCXNoise_evs[l]; - } - FOR( Word16 l = 0; l < N_LTP_GAIN_MEMS; l++ ) - { - sts[ch]->hTcxDec->ltpGainMemory[l] = fix16_to_float( sts[ch]->hTcxDec->ltpGainMemory_fx[l], Q15 ); - } - Word16 subFrames = ( sts[ch]->core == TCX_10_CORE ) ? NB_DIV : 1; - FOR( k = 0; k < subFrames; ++k ) - { - me2f_buf( x_fx[ch][k], x_e[ch][k], x[ch][k], x_len[ch][k] ); - // To be made into Q11 - // me2f_buf(x_fx[ch][k], x_e[ch][k], x[ch][k], L_FRAME48k / 2); - } - IF( !sts[0]->bfi || ( sts[0]->bfi && sts[ch]->core != ACELP_CORE ) ) - { - me2f_buf( sts[ch]->hIGFDec->virtualSpec, sts[ch]->hIGFDec->virtualSpec_e, sts[ch]->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); - } - sts[ch]->hTcxDec->cummulative_damping_tcx_float = fix16_to_float( sts[ch]->hTcxDec->cummulative_damping_tcx, Q15 ); - } - } - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + FOR(ch = 0; ch < CPE_CHANNELS; ch++) { - IF( sts[ch]->rate_switching_reset ) + Word16 subFrames = (st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->core == TCX_10_CORE) ? NB_DIV : 1; + FOR(k = 0; k < subFrames; ++k) { - Word16 old_Aq_12_8_e = norm_s( sts[ch]->old_Aq_12_8_fx[0] ); - fixedToFloat_arr( sts[ch]->old_Aq_12_8_fx, sts[ch]->old_Aq_12_8, ( 15 - old_Aq_12_8_e ), M + 1 ); + Scale_sig32(x_fx[ch][k], shr(L_FRAME48k, subFrames - 1), sub(x_e[ch][k], 20)); } } - - FOR( i = 0; i < CPE_CHANNELS; ++i ) - { - free( x_fx[i][0] ); - } - -#endif -#else - ivas_mdct_core_invQ( st_ivas->hCPE[cpe_id], nTnsBitsTCX10[cpe_id], p_param[cpe_id], param_lpc[cpe_id], param[cpe_id], - fUseTns[cpe_id], tnsData[cpe_id], x, x, Aq[cpe_id], NULL, 1 ); -#endif - - st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect; - st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect; - } - - /* MCT core decoder */ -#ifdef IVAS_FLOAT_FIXED -#if 1 - Word32 *signal_out_fx[MAX_TRANSPORT_CHANNELS]; - Decoder_State *st, *sts_tmp[MAX_TRANSPORT_CHANNELS]; - int i = 0; - for (cpe_id = 0; cpe_id < nCPE; cpe_id++) - { - for (int ch = 0; ch < CPE_CHANNELS; ch++) - { - sts_tmp[i] = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]; - i++; - } + + st_ivas->BER_detect = s_or(st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect); + test(); + st_ivas->BER_detect = s_or(st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect); + test(); } - i = 0; - for (int ch = 0; ch < hMCT->nchan_out_woLFE; ch++) - { - if (sts_tmp[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE) - { - continue; - } - i++; - } - for (int i = 0; i < hMCT->nchan_out_woLFE; ++i) - { - signal_out_fx[i] = malloc(L_FRAME48k * sizeof(Word32)); - floatToFixed_arrL(output[i], signal_out_fx[i], Q12, L_FRAME48k); - } + /* MCT core decoder */ Word16 q_x[MAX_TRANSPORT_CHANNELS]; set16_fx(q_x, Q12, MAX_TRANSPORT_CHANNELS); -#endif - - ivas_mct_core_dec(hMCT, st_ivas->hCPE, nCPE, signal_out_fx, q_x); - - for (int ch = 0; ch < hMCT->nchan_out_woLFE; ch++) + // Scaling output buffer to q_x + FOR ( i = 0; i < hMCT->nchan_out_woLFE; ++i) { - fixedToFloat_arrL(signal_out_fx[ch], output[ch], q_x[ch], L_FRAME48k); - free(signal_out_fx[ch]); + Scale_sig32(output_fx[i], L_FRAME48k, sub(q_x[i], Q11) ); } - /*for (int ch = 0; ch < hMCT->nchan_out_woLFE; ch++) - { - dbgwrite_txt(output[ch] , L_FRAME48k, "Fixed_code_mct_core.txt", NULL); - for (int k = 0; k < L_FRAME48k; k++) - { - k = k; - } - }*/ -#if 1 - if (sts_tmp[0]->igf) + ivas_mct_core_dec(hMCT, st_ivas->hCPE, nCPE, output_fx, q_x); + // Scaling output buffer back to Q11 + FOR ( i = 0; i < hMCT->nchan_out_woLFE; ++i) { - if (!hMCT->currBlockDataCnt) - { - for (int ch = 0; ch < hMCT->nchan_out_woLFE; ch++) - { - st = sts_tmp[ch]; - - IF(st->igf) - { - me2f_buf(st->hIGFDec->virtualSpec, st->hIGFDec->virtualSpec_e, st->hIGFDec->virtualSpec_float, (N_MAX_TCX - IGF_START_MN)); - FOR(Word16 l = 0; l < IGF_START_MX; l++) - { - st->hIGFDec->infoTCXNoise[l] = (uint8_t)st->hIGFDec->infoTCXNoise_evs[l]; - } - } - } - } + Scale_sig32(output_fx[i], L_FRAME48k, sub(Q11, q_x[i]) ); } -#endif -#else - ivas_mct_core_dec( hMCT, st_ivas->hCPE, nCPE, output ); - /*for (int ch = 0; ch < hMCT->nchan_out_woLFE; ch++) - { - dbgwrite_txt(output[ch], L_FRAME48k, "Float_code_mct_core.txt", NULL); - }*/ -#endif + /* for sba to stereo output disable any further processing for TCs > 2 as it is not needed*/ - if ( st_ivas->sba_dirac_stereo_flag && st_ivas->ivas_format != SBA_ISM_FORMAT ) + IF ( NE_16(st_ivas->sba_dirac_stereo_flag, 0) && NE_16(st_ivas->ivas_format, SBA_ISM_FORMAT) ) { - for ( cpe_id = 1; cpe_id < nCPE; cpe_id++ ) + FOR ( cpe_id = 1; cpe_id < nCPE; cpe_id++ ) { - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR ( n = 0; n < CPE_CHANNELS; n++ ) { st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; } } } + Word32 Aq_fx_32[6][2][102]; /* MCT reconstruction and CoreCoder updates */ - for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + FOR(cpe_id = 0; cpe_id < nCPE; cpe_id++) { hCPE = st_ivas->hCPE[cpe_id]; - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR(n = 0; n < CPE_CHANNELS; n++) { - x[n][0] = output[n + cpe_id * CPE_CHANNELS]; - x[n][1] = output[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); + Copy_Scale_sig_16_32(Aq_fx[cpe_id][n], Aq_fx_32[cpe_id][n], 102, sub(Q16, Q12)); + x_fx[n][0] = output_fx[n + cpe_id * CPE_CHANNELS]; + x_fx[n][1] = output_fx[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); + x_e[n][0] = 20; + move16(); + x_e[n][1] = 20; + move16(); } - ivas_mdct_core_tns_ns( hCPE, fUseTns[cpe_id], tnsData[cpe_id], x, Aq[cpe_id], 1 ); - } + ivas_mdct_core_tns_ns_fx(hCPE, fUseTns[cpe_id], tnsData[cpe_id], x_fx, Aq_fx_32[cpe_id], 1, x_e); - if ( st_ivas->renderer_type == RENDERER_MC ) - { - /* Equalization in MDCT Domain */ -#ifdef IVAS_FLOAT_FIXED - Word32 *output_fx[MAX_TRANSPORT_CHANNELS]; - for ( int i = 0; i < st_ivas->nchan_transport; ++i ) - { - output_fx[i] = malloc( L_FRAME48k * sizeof( Word32 ) ); - floatToFixed_arrL( output[i], output_fx[i], Q11, L_FRAME48k ); - } - ivas_ls_setup_conversion_process_mdct_fx( st_ivas, output_fx); - for ( int i = 0; i < st_ivas->nchan_transport; ++i ) + FOR(Word16 ind = 0; ind < 2; ind++) { - fixedToFloat_arrL( output_fx[i], output[i], Q11, L_FRAME48k ); - free(output_fx[i]); + Word16 nSubFrames = EQ_16(hCPE->hCoreCoder[ind]->core, TCX_20_CORE) ? 1 : NB_DIV; + Scale_sig32(x_fx[ind][0], shr(L_FRAME48k, sub(nSubFrames, 1)), sub(x_e[ind][0], 20)); + IF(nSubFrames == 2) { + Scale_sig32(x_fx[ind][1], shr(L_FRAME48k, 1), sub(x_e[ind][1], 20)); + } } -#else - ivas_ls_setup_conversion_process_mdct( st_ivas, output ); -#endif } - else if ( st_ivas->renderer_type == RENDERER_MC_PARAMMC && ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO ) ) - { - float *x_all[MAX_CICP_CHANNELS][NB_DIV]; - - for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) - { - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - x_all[n + cpe_id * CPE_CHANNELS][0] = output[n + cpe_id * CPE_CHANNELS]; - x_all[n + cpe_id * CPE_CHANNELS][1] = output[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); - } - } -#ifdef IVAS_FLOAT_FIXED - Word32 **output_fx; + IF ( EQ_16(st_ivas->renderer_type, RENDERER_MC) ) + { + /* Equalization in MDCT Domain */ + ivas_ls_setup_conversion_process_mdct_fx( st_ivas, output_fx); + } + ELSE IF(EQ_16(st_ivas->renderer_type, RENDERER_MC_PARAMMC) && (EQ_16(st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO) || EQ_16(st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO))) + { Word16 x_all_e[MAX_CICP_CHANNELS][NB_DIV] = { 0 }; Word32 *x_all_fx[MAX_CICP_CHANNELS][NB_DIV]; - IF( ( output_fx = (Word32 **) malloc( MAX_CICP_CHANNELS * sizeof( Word32 * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + FOR(cpe_id = 0; cpe_id < nCPE; cpe_id++) { - FOR( n = 0; n < CPE_CHANNELS; n++ ) + FOR(n = 0; n < CPE_CHANNELS; n++) { - IF( ( output_fx[n + cpe_id * CPE_CHANNELS] = (Word32 *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) ); - } - f2me_buf( output[n + cpe_id * CPE_CHANNELS], output_fx[n + cpe_id * CPE_CHANNELS], &x_all_e[n + cpe_id * CPE_CHANNELS][0], 960 ); - Scale_sig32( output_fx[n + cpe_id * CPE_CHANNELS], L_FRAME48k, -1 ); /*Scaling the signal down by 1 because of overflow*/ - x_all_e[n + cpe_id * CPE_CHANNELS][0]++; x_all_fx[n + cpe_id * CPE_CHANNELS][0] = output_fx[n + cpe_id * CPE_CHANNELS]; - x_all_fx[n + cpe_id * CPE_CHANNELS][1] = output_fx[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); - x_all_e[n + cpe_id * CPE_CHANNELS][1] = x_all_e[n + cpe_id * CPE_CHANNELS][0]; - } - } - f2me_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt ); - f2me_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt ); - PARAM_MC_DEC_HANDLE hParamMC; - hParamMC = st_ivas->hParamMC; - floatToFixed_arr16( hParamMC->icld_q, hParamMC->icld_q_fx, 8, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); - floatToFixed_arr32( hParamMC->ls_conv_dmx_matrix, hParamMC->ls_conv_dmx_matrix_fx, 15, st_ivas->hDecoderConfig->nchan_out * ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) ); - FOR(Word16 chOutIdx = 0; chOutIdx < st_ivas->hDecoderConfig->nchan_out; chOutIdx++) - { - FOR(Word16 chInIdx = 0; chInIdx < st_ivas->nchan_transport; chInIdx++) - { - st_ivas->hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx] = float_to_fix(st_ivas->hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx], 30); /*Q30*/ - } - } - ivas_ls_setup_conversion_process_mdct_param_mc_fx( st_ivas, x_all_fx, x_all_e ); - FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) - { - FOR( n = 0; n < CPE_CHANNELS; n++ ) - { - me2f_buf( &x_all_fx[n + cpe_id * CPE_CHANNELS][0][0], x_all_e[n + cpe_id * CPE_CHANNELS][0], &x_all[n + cpe_id * CPE_CHANNELS][0][0], L_FRAME48k / 2 ); - me2f_buf( &x_all_fx[n + cpe_id * CPE_CHANNELS][1][0], x_all_e[n + cpe_id * CPE_CHANNELS][1], &x_all[n + cpe_id * CPE_CHANNELS][1][0], L_FRAME48k / 2 ); + x_all_fx[n + cpe_id * CPE_CHANNELS][1] = output_fx[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); + x_all_e[n + cpe_id * CPE_CHANNELS][1] = 20; + move16(); + x_all_e[n + cpe_id * CPE_CHANNELS][0] = 20; + move16(); } } - me2f_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt ); - me2f_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt ); - FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + ivas_ls_setup_conversion_process_mdct_param_mc_fx(st_ivas, x_all_fx, x_all_e); + + FOR(cpe_id = 0; cpe_id < nCPE; cpe_id++) { - FOR( n = 0; n < CPE_CHANNELS; n++ ) + FOR(n = 0; n < CPE_CHANNELS; n++) { - free( output_fx[n + cpe_id * CPE_CHANNELS] ); + Scale_sig32(x_all_fx[n + cpe_id * CPE_CHANNELS][0], shr(L_FRAME48k, 1), sub(x_all_e[n + cpe_id * CPE_CHANNELS][0], 20)); + Scale_sig32(x_all_fx[n + cpe_id * CPE_CHANNELS][1], shr(L_FRAME48k, 1), sub(x_all_e[n + cpe_id * CPE_CHANNELS][1], 20)); } } -#else - ivas_ls_setup_conversion_process_mdct_param_mc( st_ivas, x_all ); -#endif // + } - for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + FOR ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { hCPE = st_ivas->hCPE[cpe_id]; sts = hCPE->hCoreCoder; - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR ( n = 0; n < CPE_CHANNELS; n++ ) + { + x_fx[n][0] = output_fx[n + cpe_id * CPE_CHANNELS]; + x_fx[n][1] = output_fx[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); + } + FOR(n = 0; n < CPE_CHANNELS; n++) { - x[n][0] = output[n + cpe_id * CPE_CHANNELS]; - x[n][1] = output[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); + IF(NE_16(hCPE->hCoreCoder[n]->Q_syn, 0)) + { + Scale_sig(hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, hCPE->hCoreCoder[n]->Q_syn); + } + if ( sts[n]->hTcxDec && sts[n]->hTcxDec->conCngLevelBackgroundTrace_e < 0 ) + { + sts[n]->hTcxDec->conCngLevelBackgroundTrace_e = 0; + } } + + Copy_Scale_sig_16_32(hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, M + 1, (28 - norm_s(hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0] - 1))); + Copy_Scale_sig_16_32(hCPE->hCoreCoder[1]->old_Aq_12_8_fx, hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32, M + 1, (28 - norm_s(hCPE->hCoreCoder[1]->old_Aq_12_8_fx[0] - 1))); + ivas_mdct_core_reconstruct_fx( hCPE, x_fx, synth_fx, fUseTns[cpe_id], 1, q_output, 15 ); + + FOR(n = 0; n < CPE_CHANNELS; n++) + { + IF(NE_16(hCPE->hCoreCoder[n]->Q_syn, 0)) + { + Scale_sig(hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, negate(hCPE->hCoreCoder[n]->Q_syn)); + } + IF(hCPE->hCoreCoder[n]->hBPF) + { + hCPE->hCoreCoder[n]->hBPF->pst_mem_deemp_err_fx = extract_l( L_shr( hCPE->hCoreCoder[n]->mem_error, sub(Q16, hCPE->hCoreCoder[n]->Q_syn2 - 1) ) ); + Scale_sig(hCPE->hCoreCoder[n]->hBPF->pst_old_syn_fx, NBPSF_PIT_MAX, hCPE->hCoreCoder[n]->Q_syn2 - 1); + } + IF(hCPE->hCoreCoder[n]->hTcxDec) + { + //Scale_sig(hCPE->hCoreCoder[n]->hTcxDec->synth_history_fx, NS2SA(hCPE->hCoreCoder[n]->output_Fs, PH_ECU_MEM_NS), negate(hCPE->hCoreCoder[n]->Q_syn)); + } + IF(hCPE->hCoreCoder[n]->hHQ_core) + { + Scale_sig(hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, negate(hCPE->hCoreCoder[n]->Q_syn)); + } - ivas_mdct_core_reconstruct( hCPE, x, synth, fUseTns[cpe_id], 1 ); + } + /*----------------------------------------------------------------* * CoreCoder Post-processing and updates *----------------------------------------------------------------*/ + Word32 synth_fx_32[CPE_CHANNELS][L_FRAME48k]; - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR ( n = 0; n < CPE_CHANNELS; n++ ) { - if ( st_ivas->sba_dirac_stereo_flag && ( st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2 ) ) + IF ( NE_16(st_ivas->sba_dirac_stereo_flag, 0) && ( NE_16(st_ivas->ivas_format, SBA_ISM_FORMAT) || GE_16(cpe_id, sub(nCPE, 2)) ) ) { - ivas_post_proc( NULL, hCPE, n, synth[n], NULL, output_frame, 1 ); + + Copy_Scale_sig_16_32(synth_fx[n], synth_fx_32[n], L_FRAME48k, sub(Q11, 0)); + Copy_Scale_sig_16_32(hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, hCPE->hCoreCoder[n]->hHQ_core->oldOut_fx, output_frame, Q11); + ivas_post_proc_fx( NULL, hCPE, n, synth_fx_32[n], NULL, output_frame, 1 ); + Copy_Scale_sig_32_16(synth_fx_32[n], synth_fx[n], L_FRAME48k, sub(0, Q11)); + } /* Postprocessing for ACELP/MDCT core switching and synchronization */ - if ( ( error = core_switching_post_dec( sts[n], synth[n], output[cpe_id * CPE_CHANNELS + n], hCPE->output_mem[1], st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, ( st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2 ) ? st_ivas->sba_dirac_stereo_flag : 0, -1, hCPE->last_element_mode ) ) != IVAS_ERR_OK ) + Word16 output_mem_fx[L_FRAME48k]; + IF( hCPE->output_mem_fx[1] != NULL ) { - return error; + Copy_Scale_sig_32_16( hCPE->output_mem_fx[1], output_mem_fx, NS2SA( sts[n]->output_Fs, 3125000 ), sub(0, Q11) ); } - - /* final output of synthesis signal */ - mvr2r( synth[n], output[cpe_id * CPE_CHANNELS + n], output_frame ); - - /* Save synthesis for HQ FEC */ -#ifdef IVAS_FLOAT_FIXED - Word32 exp_max = 0, i; - Word32 output_fx[L_FRAME48k]; - if ( ( sts[n]->codec_mode == MODE1 && sts[n]->hTcxDec != NULL ) && ( ( sts[n]->core == ACELP_CORE && !( sts[n]->bfi == 1 && sts[n]->con_tcx == 1 ) ) || sts[n]->core == HQ_CORE ) ) + ELSE { - double max_prev_synth_buffer = 0.0f, max_old_out = 0.0f, max_delay_buf_out = 0.0f, max_ouput = 0.0f, max_synth_history = 0.0f; - Word32 exp_prev_synth_buffer = 0, exp_old_out = 0, exp_delay_buf_out = 0, exp_ouput = 0, exp_synth_history = 0; - - /*Find maximum values for all the buffers*/ - for ( i = 0; i < NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); i++ ) - { - max_prev_synth_buffer = max( max_prev_synth_buffer, fabs( sts[n]->prev_synth_buffer[i] ) ); - } - if ( (Word16) max_prev_synth_buffer != 0 ) - { - frexp( max_prev_synth_buffer, &exp_prev_synth_buffer ); - } - - for ( i = NS2SA( sts[n]->output_Fs, N_ZERO_MDCT_NS ); i < NS2SA( sts[n]->output_Fs, N_ZERO_MDCT_NS ) + NS2SA( sts[n]->output_Fs, PH_ECU_LOOKAHEAD_NS ); i++ ) - { - max_old_out = max( max_old_out, fabs( sts[n]->hHQ_core->old_out[i] ) ); - } - if ( (Word16) max_old_out != 0 ) - { - frexp( max_old_out, &exp_old_out ); - } - - for ( i = 0; i < NS2SA( sts[n]->output_Fs, DELAY_CLDFB_NS ); i++ ) - { - max_delay_buf_out = max( max_delay_buf_out, fabs( sts[n]->delay_buf_out[i] ) ); - } - if ( (Word16) max_delay_buf_out != 0 ) - { - frexp( max_delay_buf_out, &exp_delay_buf_out ); - } - - for ( i = 0; i < output_frame; i++ ) - { - max_ouput = max( max_ouput, fabs( output[cpe_id * CPE_CHANNELS + n][i] ) ); - } - if ( (Word16) max_ouput != 0 ) - { - frexp( max_ouput, &exp_ouput ); - } - - for ( i = output_frame; i < 2 * output_frame - NS2SA( sts[n]->output_Fs, DELAY_CLDFB_NS ) + NS2SA( sts[n]->output_Fs, PH_ECU_MEM_NS ); i++ ) - { - max_synth_history = max( max_synth_history, fabs( sts[n]->hTcxDec->synth_history[i] ) ); - } - - if ( (Word16) max_synth_history != 0 ) - { - frexp( max_synth_history, &exp_synth_history ); - } - - /*Find a commen maximum exp*/ - exp_max = max( exp_synth_history, exp_ouput ); - exp_max = max( exp_max, exp_prev_synth_buffer ); - exp_max = max( exp_max, exp_old_out ); - exp_max = max( exp_max, exp_delay_buf_out ); - - for ( i = 0; i < NS2SA( sts[n]->output_Fs, DELAY_CLDFB_NS ); i++ ) - { - f2fix_16( &sts[n]->delay_buf_out[i], &sts[n]->delay_buf_out_fx[i], exp_max ); - } - for ( i = NS2SA( sts[n]->output_Fs, N_ZERO_MDCT_NS ); i < NS2SA( sts[n]->output_Fs, PH_ECU_LOOKAHEAD_NS ); i++ ) - { - f2fix_16( &sts[n]->hHQ_core->old_out[i], &sts[n]->hHQ_core->old_out_fx[i], exp_max ); - } - for ( i = 0; i < NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); i++ ) - { - f2fix_16( &sts[n]->prev_synth_buffer[i], &sts[n]->prev_synth_buffer_fx[i], exp_max ); - } - for ( i = output_frame; i < 2 * output_frame - NS2SA( sts[n]->output_Fs, DELAY_CLDFB_NS ) + NS2SA( sts[n]->output_Fs, PH_ECU_MEM_NS ); i++ ) - { - f2fix_16( &sts[n]->hTcxDec->synth_history[i], &sts[n]->hTcxDec->synth_history_fx[i], exp_max ); - } - for ( i = 0; i < output_frame; i++ ) - { - f2fix( &output[cpe_id * CPE_CHANNELS + n][i], &output_fx[i], exp_max ); - } + set16_fx( output_mem_fx, 0, NS2SA( sts[n]->output_Fs, 3125000 ) ); } + + Word16 Q_synth = 0; - save_synthesis_hq_fec_fx( sts[n], output_fx, output_frame, hCPE ); - save_synthesis_hq_fec(sts[n], output[cpe_id * CPE_CHANNELS + n], output_frame, hCPE); - if ( ( sts[n]->codec_mode == MODE1 && sts[n]->hTcxDec != NULL ) && ( ( sts[n]->core == ACELP_CORE && !( sts[n]->bfi == 1 && sts[n]->con_tcx == 1 ) ) || sts[n]->core == HQ_CORE ) ) + IF ( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx[n], output_fx[cpe_id * CPE_CHANNELS + n], output_mem_fx, st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, ( st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2 ) ? st_ivas->sba_dirac_stereo_flag : 0, -1, hCPE->last_element_mode, &Q_synth ) ) != IVAS_ERR_OK ) { - /*dumps*/ - float track = 0; - for ( i = 0; i < 2 * output_frame; i++ ) - { - fix2f_16( &sts[n]->hTcxDec->synth_history_fx[i], &track, exp_max ); - fix2f_16( &sts[n]->hTcxDec->synth_history_fx[i], &sts[n]->hTcxDec->synth_history[i], exp_max ); -#ifdef DUMPS_ENABLED - dbgwrite_txt( &track, 1, "Fixed_code_synth_history_fx.txt", NULL ); - dbgwrite_txt( &sts[n]->hTcxDec->synth_history[i], 1, "Float_code_synth_history_fx.txt", NULL ); -#endif - } + return error; } -#else - save_synthesis_hq_fec( sts[n], output[cpe_id * CPE_CHANNELS + n], output_frame, hCPE ); -#endif + Copy_Scale_sig_16_32(synth_fx[n], output_fx[cpe_id * CPE_CHANNELS + n], output_frame, sub(Q11, Q_synth)); + + /* Save synthesis for HQ FEC */ + Word32 output_fx_[L_FRAME48k]; + mvl2l(output_fx[cpe_id * CPE_CHANNELS + n], output_fx_, L_FRAME48k); + Scale_sig32(output_fx_, L_FRAME48k, sub(Q16, Q11)); + Copy_Scale_sig32_16(sts[n]->prev_synth_buffer32_fx, sts[n]->prev_synth_buffer_fx, NS2SA(48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS), -11); + sts[n]->q_prev_synth_buffer_fx = 0; + + save_synthesis_hq_fec_fx( sts[n], output_fx_, output_frame, hCPE ); + /* CoreCoder common updates */ - updt_dec_common( sts[n], NORMAL_HQ_CORE, -1, output[cpe_id * CPE_CHANNELS + n] ); + ivas_updt_dec_common_fx( hCPE->hCoreCoder[n], NORMAL_HQ_CORE, -1, output_fx[cpe_id * CPE_CHANNELS + n], 11 ); } /* n_channels loop */ + FOR(n = 0; n < 2; n++) { + IF(hCPE->hCoreCoder[n]) + { + Copy_Scale_sig_16_32(hCPE->hCoreCoder[n]->delay_buf_out_fx, hCPE->hCoreCoder[n]->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP, Q11); + } + } /* synthesis synchronization between stereo modes */ - if ( !st_ivas->sba_dirac_stereo_flag || ( st_ivas->ivas_format == SBA_ISM_FORMAT && cpe_id < nCPE - 2 ) ) + IF ( EQ_16(st_ivas->sba_dirac_stereo_flag, 0) || ( EQ_16(st_ivas->ivas_format, SBA_ISM_FORMAT) && LE_16(cpe_id, sub(nCPE, 2)) ) ) { -#ifdef IVAS_FLOAT_FIXED - synchro_synthesis_fixed( ivas_total_brate, hCPE, output + cpe_id * CPE_CHANNELS, output_frame, 0 ); -#else - synchro_synthesis( ivas_total_brate, hCPE, output + cpe_id * CPE_CHANNELS, output_frame, 0 ); -#endif - - //Todo use below once input is fixed not done due to complication in pointer - //synchro_synthesis_fixed_clean( ivas_total_brate, hCPE, output + cpe_id * CPE_CHANNELS, output_frame, 0 ); + synchro_synthesis_fx( ivas_total_brate, hCPE, output_fx + cpe_id * CPE_CHANNELS, output_frame, 0 ); } - } /* move channels after LFE to correct output for multi-channel MCT */ - if ( st_ivas->ivas_format == MC_FORMAT && ( st_ivas->mc_mode == MC_MODE_MCT || st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) ) + IF ( EQ_16(st_ivas->ivas_format, MC_FORMAT) && ( EQ_16(st_ivas->mc_mode, MC_MODE_MCT) || EQ_16(st_ivas->mc_mode, MC_MODE_PARAMUPMIX) ) ) { - float tmp[L_FRAME48k]; + Word32 tmp[L_FRAME48k]; /*save center channel output*/ - mvr2r( output[hMCT->nchan_out_woLFE - 1], tmp, output_frame ); + mvl2l( output_fx[hMCT->nchan_out_woLFE - 1], tmp, output_frame ); - for ( n = hMCT->nchan_out_woLFE - 1; n >= LFE_CHANNEL; n-- ) + FOR ( n = hMCT->nchan_out_woLFE - 1; n >= LFE_CHANNEL; n-- ) { - mvr2r( output[n - 1], output[n + 1], output_frame ); + mvl2l( output_fx[n - 1], output_fx[n + 1], output_frame ); } - mvr2r( tmp, output[LFE_CHANNEL - 1], output_frame ); + mvl2l( tmp, output_fx[LFE_CHANNEL - 1], output_frame ); /* save LFE channel */ - mvr2r( output_lfe_ch, output[LFE_CHANNEL], output_frame ); + mvl2l( output_lfe_ch_fx, output_fx[LFE_CHANNEL], output_frame ); } - pop_wmops(); return error; + } -#else -ivas_error ivas_mct_dec_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_fx[], /* o : output synthesis signal */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 nb_bits_metadata /* i : number of metadata bits */ +#endif + + +/*------------------------------------------------------------------------- + * create_mct_dec() + * + * Create, allocate and initialize IVAS decoder MCT handle + *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error create_mct_dec_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { - Word16 ch, nCPE, cpe_id; MCT_DEC_HANDLE hMCT; - CPE_DEC_HANDLE hCPE; - Word16 param[MCT_MAX_BLOCKS][CPE_CHANNELS][DEC_NPRM_DIV * NB_DIV]; - Word16 param_lpc[MCT_MAX_BLOCKS][CPE_CHANNELS][NPRM_LPC_NEW]; - Word16 p_param[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; - Word16 nTnsBitsTCX10[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; - Word16 fUseTns[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; - STnsData tnsData[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; - Word16 Aq_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; - Word32 output_lfe_ch_fx[L_FRAME48k]; - Word16 q_output = 11; - Word16 n, k, l, i, j; - - Word32 *x_fx[CPE_CHANNELS][NB_DIV]; - Word16 x_e[MAX_CICP_CHANNELS][NB_DIV]; - Word16 x_len[CPE_CHANNELS][NB_DIV] = { 0 }; - Decoder_State **sts; - Word16 synth_fx[CPE_CHANNELS][L_FRAME_PLUS]; - int32_t ivas_total_brate; - ivas_error error; - - push_wmops( "ivas_mct_dec" ); - - error = IVAS_ERR_OK; - nCPE = st_ivas->nCPE; - move16(); - hMCT = st_ivas->hMCT; + Word16 n; + Word32 cp_bitrate; + Word16 max_blocks; + Word16 cpe_id; - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - move32(); + /*--------------------------------------------------------- --------* + * Allocate MCT handle + *-----------------------------------------------------------------*/ - IF ( EQ_16(st_ivas->ivas_format, MC_FORMAT) && ( EQ_16(st_ivas->mc_mode, MC_MODE_MCT) || EQ_16(st_ivas->mc_mode, MC_MODE_PARAMUPMIX) ) ) + IF( ( hMCT = (MCT_DEC_HANDLE) malloc( sizeof( MCT_DEC_DATA ) ) ) == NULL ) { - /* save LFE channel */ - mvl2l( output_fx[LFE_CHANNEL], output_lfe_ch_fx, output_frame ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CPE\n" ) ); } - IF ( EQ_16(st_ivas->ivas_format, MC_FORMAT) && EQ_16(st_ivas->mc_mode, MC_MODE_MCT) && EQ_16(st_ivas->bfi, 0) ) - { - /* get the number of channels from the signalled MC LS setup */ - n = ivas_mc_ls_setup_get_num_channels( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ) ); - - IF ( NE_16(n, st_ivas->nchan_transport) ) - { - /* IVAS_fmToDo: more work needed for switching the number of transport channels */ - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: wrong number of transport channels signalled in MC format!" ); - } - } + /*-----------------------------------------------------------------* + * Allocate MCT BlockData handles + *-----------------------------------------------------------------*/ - FOR ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + /* Determine active channels */ + IF( ( EQ_16(st_ivas->ivas_format , MC_FORMAT) && EQ_16(st_ivas->mc_mode , MC_MODE_PARAMMC) ) || EQ_16(st_ivas->ivas_format , SBA_FORMAT) || EQ_16(st_ivas->ivas_format , SBA_ISM_FORMAT) ) { - /*initialize param_lpc buffer*/ - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + hMCT->nchan_out_woLFE = st_ivas->nchan_transport; + IF( EQ_16(st_ivas->ism_mode , ISM_SBA_MODE_DISC) ) { - set_s( param_lpc[cpe_id][n], 0, NPRM_LPC_NEW ); + hMCT->nchan_out_woLFE = add(hMCT->nchan_out_woLFE,st_ivas->nchan_ism); } + } + ELSE IF( EQ_16(st_ivas->mc_mode , MC_MODE_MCT) ) + { + hMCT->nchan_out_woLFE = sub(st_ivas->nchan_transport , st_ivas->hTransSetup.num_lfe); + } + ELSE IF( EQ_16(st_ivas->ivas_format , MC_FORMAT) && EQ_16(st_ivas->mc_mode , MC_MODE_PARAMUPMIX) ) + { + hMCT->nchan_out_woLFE = sub(st_ivas->nchan_transport , st_ivas->hTransSetup.num_lfe); + } + ELSE + { + assert( !"IVAS format currently not supported for MCT" ); + } - set32_fx( &output_fx[0][0], 0, L_FRAME48k ); - set32_fx( &output_fx[1][0], 0, L_FRAME48k ); + cp_bitrate = L_shl( Mult_32_16( st_ivas->hDecoderConfig->ivas_total_brate, div_s( 1, hMCT->nchan_out_woLFE ) ), 1 ); - IF( ( error = ivas_cpe_dec_fx( st_ivas, cpe_id, &output_fx[0], output_frame, 0, &q_output ) ) != IVAS_ERR_OK ) - { - return error; - } + IF( EQ_16(st_ivas->ism_mode , ISM_SBA_MODE_DISC) ) + { + cp_bitrate = L_shl( Mult_32_16( st_ivas->hDecoderConfig->ivas_total_brate, div_s( 1, st_ivas->nchan_transport ) ), 1 ); + } - IF ( EQ_16(cpe_id, 0) ) + /* indicate LFE for appropriate core-coder channel */ + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) { - st_ivas->hCPE[0]->hCoreCoder[0]->total_brate = ivas_total_brate; /* set high enough to read the whole side-info; total_brate is rewritten later in ivas_mdct_core_invQ() */ - move32(); + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; } + } - IF ( EQ_16(st_ivas->bfi, 0) ) - { - ivas_mdct_dec_side_bits_frame_channel_fx( st_ivas->hCPE[cpe_id], param_lpc[cpe_id], p_param[cpe_id], st_ivas->hCPE[0]->hCoreCoder[0], nTnsBitsTCX10[cpe_id], param[cpe_id], 1, - (Word16) GT_16( i_mult(add( cpe_id, 1 ), CPE_CHANNELS ), hMCT->nchan_out_woLFE ) ); - - st_ivas->BER_detect = s_or(st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect); - test(); - st_ivas->BER_detect = s_or(st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect); - test(); - } + /* in case we have an uneven number of transport channels, indicate last channel ID as inactive */ + IF( hMCT->nchan_out_woLFE % 2 ) + { + st_ivas->hCPE[st_ivas->nCPE - 1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; } - /* MCT side bits decoder */ - ivas_mct_side_bits_fx( hMCT, st_ivas->hCPE, nCPE, st_ivas->hCPE[0]->hCoreCoder[0], st_ivas->bfi, st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream, ivas_total_brate, nb_bits_metadata ); + /*Initialize MCT block data */ + max_blocks = shr(hMCT->nchan_out_woLFE , 1); - FOR ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + FOR( n = 0; n < max_blocks; n++ ) { - st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect = s_or(st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect, st_ivas->BER_detect); - test(); - st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect = s_or(st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect, st_ivas->BER_detect); - test(); - - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + IF( ( hMCT->hBlockData[n] = (MCT_DEC_BLOCK_DATA_HANDLE) malloc( sizeof( MCT_DEC_BLOCK_DATA ) ) ) == NULL ) { - x_fx[n][0] = output_fx[n + cpe_id * CPE_CHANNELS]; - x_e[n][0] = 20; - x_fx[n][1] = output_fx[n + cpe_id * CPE_CHANNELS] + shr( L_FRAME48k, 1 ); - x_e[n][1] = 20; - move16(); - move16(); - - set32_fx( x_fx[n][0], 0, shr(L_FRAME48k, 1) ); - set32_fx( x_fx[n][1], 0, shr(L_FRAME48k, 1) ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MCT block data structure\n" ) ); } - ivas_mdct_core_invQ_fx( st_ivas->hCPE[cpe_id], nTnsBitsTCX10[cpe_id], p_param[cpe_id], param_lpc[cpe_id], param[cpe_id], - fUseTns[cpe_id], tnsData[cpe_id], x_fx, x_e, x_fx, x_e, x_len, Aq_fx[cpe_id], NULL, 1 ); + /*Initialize all parameters to zero*/ + hMCT->hBlockData[n]->ch1 = 0; + hMCT->hBlockData[n]->ch2 = 0; - FOR(ch = 0; ch < CPE_CHANNELS; ch++) + /*-----------------------------------------------------------------* + * MDCT stereo initialization + *-----------------------------------------------------------------*/ + + IF( ( hMCT->hBlockData[n]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) { - Word16 subFrames = (st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->core == TCX_10_CORE) ? NB_DIV : 1; - FOR(k = 0; k < subFrames; ++k) - { - Scale_sig32(x_fx[ch][k], shr(L_FRAME48k, subFrames - 1), sub(x_e[ch][k], 20)); - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); } - - st_ivas->BER_detect = s_or(st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect); - test(); - st_ivas->BER_detect = s_or(st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect); - test(); - } - - /* MCT core decoder */ - Word16 q_x[MAX_TRANSPORT_CHANNELS]; - set16_fx(q_x, Q12, MAX_TRANSPORT_CHANNELS); - // Scaling output buffer to q_x - FOR ( i = 0; i < hMCT->nchan_out_woLFE; ++i) + initMdctStereoDecData_fx( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, SWB ); + hMCT->hBlockData[n]->hStereoMdct->use_itd = 0; + hMCT->hBlockData[n]->hStereoMdct->reverse_dmx = 0; + hMCT->hBlockData[n]->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; + } + FOR( ; n < MCT_MAX_BLOCKS; n++ ) { - Scale_sig32(output_fx[i], L_FRAME48k, sub(q_x[i], Q11) ); + hMCT->hBlockData[n] = NULL; } - ivas_mct_core_dec(hMCT, st_ivas->hCPE, nCPE, output_fx, q_x); - // Scaling output buffer back to Q11 - FOR ( i = 0; i < hMCT->nchan_out_woLFE; ++i) + + /*-----------------------------------------------------------------* + * Initializations + *-----------------------------------------------------------------*/ + + hMCT->currBlockDataCnt = 0; + + /*Initialize bits required to signal channel-pair index*/ + // hMCT->bitsChannelPairIndex = max( 1, (Word16) ( floorf( ( logf( (float) hMCT->nchan_out_woLFE * ( hMCT->nchan_out_woLFE - 1 ) / 2 - 1 ) * INV_LOG_2 ) ) + 1 ) ); + hMCT->bitsChannelPairIndex = s_max( 1, floor_log_2( (Word32) hMCT->nchan_out_woLFE * ( (Word32) hMCT->nchan_out_woLFE - 1 ) / 2 - 1 )+ 1 ); + + set16_fx( hMCT->chBitRatios, 0, MCT_MAX_CHANNELS ); + set16_fx( hMCT->lowE_ch, 0, MCT_MAX_CHANNELS ); + + st_ivas->hMCT = hMCT; + + return IVAS_ERR_OK; +} +#endif // IVAS_FLOAT_FIXED + +ivas_error create_mct_dec( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + MCT_DEC_HANDLE hMCT; + int16_t n; + int32_t cp_bitrate; + int16_t max_blocks; + int16_t cpe_id; + + /*--------------------------------------------------------- --------* + * Allocate MCT handle + *-----------------------------------------------------------------*/ + + if ( ( hMCT = (MCT_DEC_HANDLE) malloc( sizeof( MCT_DEC_DATA ) ) ) == NULL ) { - Scale_sig32(output_fx[i], L_FRAME48k, sub(Q11, q_x[i]) ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CPE\n" ) ); } - - /* for sba to stereo output disable any further processing for TCs > 2 as it is not needed*/ - IF ( NE_16(st_ivas->sba_dirac_stereo_flag, 0) && NE_16(st_ivas->ivas_format, SBA_ISM_FORMAT) ) + /*-----------------------------------------------------------------* + * Allocate MCT BlockData handles + *-----------------------------------------------------------------*/ + + /* Determine active channels */ + if ( ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMMC ) || st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) { - FOR ( cpe_id = 1; cpe_id < nCPE; cpe_id++ ) + hMCT->nchan_out_woLFE = st_ivas->nchan_transport; + if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) { - FOR ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; - } + hMCT->nchan_out_woLFE += st_ivas->nchan_ism; } } - - Word32 Aq_fx_32[6][2][102]; - /* MCT reconstruction and CoreCoder updates */ - FOR(cpe_id = 0; cpe_id < nCPE; cpe_id++) + else if ( st_ivas->mc_mode == MC_MODE_MCT ) { - hCPE = st_ivas->hCPE[cpe_id]; + hMCT->nchan_out_woLFE = st_ivas->nchan_transport - st_ivas->hTransSetup.num_lfe; + } + else if ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + { + hMCT->nchan_out_woLFE = st_ivas->nchan_transport - st_ivas->hTransSetup.num_lfe; + } + else + { + assert( !"IVAS format currently not supported for MCT" ); + } - FOR(n = 0; n < CPE_CHANNELS; n++) - { - Copy_Scale_sig_16_32(Aq_fx[cpe_id][n], Aq_fx_32[cpe_id][n], 102, sub(Q16, Q12)); - x_fx[n][0] = output_fx[n + cpe_id * CPE_CHANNELS]; - x_fx[n][1] = output_fx[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); - x_e[n][0] = 20; - move16(); - x_e[n][1] = 20; - move16(); - } + cp_bitrate = st_ivas->hDecoderConfig->ivas_total_brate / hMCT->nchan_out_woLFE * CPE_CHANNELS; - ivas_mdct_core_tns_ns_fx(hCPE, fUseTns[cpe_id], tnsData[cpe_id], x_fx, Aq_fx_32[cpe_id], 1, x_e); + if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + { + cp_bitrate = st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport * CPE_CHANNELS; + } - FOR(Word16 ind = 0; ind < 2; ind++) + /* indicate LFE for appropriate core-coder channel */ + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + for ( n = 0; n < CPE_CHANNELS; n++ ) { - Word16 nSubFrames = EQ_16(hCPE->hCoreCoder[ind]->core, TCX_20_CORE) ? 1 : NB_DIV; - Scale_sig32(x_fx[ind][0], shr(L_FRAME48k, sub(nSubFrames, 1)), sub(x_e[ind][0], 20)); - IF(nSubFrames == 2) { - Scale_sig32(x_fx[ind][1], shr(L_FRAME48k, 1), sub(x_e[ind][1], 20)); - } + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; } } - - IF ( EQ_16(st_ivas->renderer_type, RENDERER_MC) ) + /* in case we have an uneven number of transport channels, indicate last channel ID as inactive */ + if ( hMCT->nchan_out_woLFE % 2 ) { - /* Equalization in MDCT Domain */ - ivas_ls_setup_conversion_process_mdct_fx( st_ivas, output_fx); + st_ivas->hCPE[st_ivas->nCPE - 1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; } - ELSE IF(EQ_16(st_ivas->renderer_type, RENDERER_MC_PARAMMC) && (EQ_16(st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO) || EQ_16(st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO))) + + /*Initialize MCT block data */ + max_blocks = hMCT->nchan_out_woLFE / 2; + + for ( n = 0; n < max_blocks; n++ ) { - Word16 x_all_e[MAX_CICP_CHANNELS][NB_DIV] = { 0 }; - Word32 *x_all_fx[MAX_CICP_CHANNELS][NB_DIV]; - FOR(cpe_id = 0; cpe_id < nCPE; cpe_id++) + if ( ( hMCT->hBlockData[n] = (MCT_DEC_BLOCK_DATA_HANDLE) malloc( sizeof( MCT_DEC_BLOCK_DATA ) ) ) == NULL ) { - FOR(n = 0; n < CPE_CHANNELS; n++) - { - x_all_fx[n + cpe_id * CPE_CHANNELS][0] = output_fx[n + cpe_id * CPE_CHANNELS]; - x_all_fx[n + cpe_id * CPE_CHANNELS][1] = output_fx[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); - x_all_e[n + cpe_id * CPE_CHANNELS][1] = 20; - move16(); - x_all_e[n + cpe_id * CPE_CHANNELS][0] = 20; - move16(); - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MCT block data structure\n" ) ); } - ivas_ls_setup_conversion_process_mdct_param_mc_fx(st_ivas, x_all_fx, x_all_e); + /*Initialize all parameters to zero*/ + hMCT->hBlockData[n]->ch1 = 0; + hMCT->hBlockData[n]->ch2 = 0; - FOR(cpe_id = 0; cpe_id < nCPE; cpe_id++) + /*-----------------------------------------------------------------* + * MDCT stereo initialization + *-----------------------------------------------------------------*/ + + if ( ( hMCT->hBlockData[n]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) { - FOR(n = 0; n < CPE_CHANNELS; n++) - { - Scale_sig32(x_all_fx[n + cpe_id * CPE_CHANNELS][0], shr(L_FRAME48k, 1), sub(x_all_e[n + cpe_id * CPE_CHANNELS][0], 20)); - Scale_sig32(x_all_fx[n + cpe_id * CPE_CHANNELS][1], shr(L_FRAME48k, 1), sub(x_all_e[n + cpe_id * CPE_CHANNELS][1], 20)); - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); } +#ifndef IVAS_FLOAT_FIXED + initMdctStereoDecData( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, SWB ); +#else + initMdctStereoDecData_fx( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, SWB ); +#endif + hMCT->hBlockData[n]->hStereoMdct->use_itd = 0; + hMCT->hBlockData[n]->hStereoMdct->reverse_dmx = 0; +#ifndef IVAS_FLOAT_FIXED + hMCT->hBlockData[n]->hStereoMdct->smooth_ratio = 1.f; +#else + hMCT->hBlockData[n]->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; +#endif } - - FOR ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + for ( ; n < MCT_MAX_BLOCKS; n++ ) { - hCPE = st_ivas->hCPE[cpe_id]; - sts = hCPE->hCoreCoder; - - FOR ( n = 0; n < CPE_CHANNELS; n++ ) - { - x_fx[n][0] = output_fx[n + cpe_id * CPE_CHANNELS]; - x_fx[n][1] = output_fx[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); - } - FOR(n = 0; n < CPE_CHANNELS; n++) - { - IF(NE_16(hCPE->hCoreCoder[n]->Q_syn, 0)) - { - Scale_sig(hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, hCPE->hCoreCoder[n]->Q_syn); - } - if ( sts[n]->hTcxDec && sts[n]->hTcxDec->conCngLevelBackgroundTrace_e < 0 ) - { - sts[n]->hTcxDec->conCngLevelBackgroundTrace_e = 0; - } - } - - Copy_Scale_sig_16_32(hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, M + 1, (28 - norm_s(hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0] - 1))); - Copy_Scale_sig_16_32(hCPE->hCoreCoder[1]->old_Aq_12_8_fx, hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32, M + 1, (28 - norm_s(hCPE->hCoreCoder[1]->old_Aq_12_8_fx[0] - 1))); - ivas_mdct_core_reconstruct_fx( hCPE, x_fx, synth_fx, fUseTns[cpe_id], 1, q_output, 15 ); - - FOR(n = 0; n < CPE_CHANNELS; n++) - { - IF(NE_16(hCPE->hCoreCoder[n]->Q_syn, 0)) - { - Scale_sig(hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, negate(hCPE->hCoreCoder[n]->Q_syn)); - } - IF(hCPE->hCoreCoder[n]->hBPF) - { - hCPE->hCoreCoder[n]->hBPF->pst_mem_deemp_err_fx = extract_l( L_shr( hCPE->hCoreCoder[n]->mem_error, sub(Q16, hCPE->hCoreCoder[n]->Q_syn2 - 1) ) ); - Scale_sig(hCPE->hCoreCoder[n]->hBPF->pst_old_syn_fx, NBPSF_PIT_MAX, hCPE->hCoreCoder[n]->Q_syn2 - 1); - } - IF(hCPE->hCoreCoder[n]->hTcxDec) - { - //Scale_sig(hCPE->hCoreCoder[n]->hTcxDec->synth_history_fx, NS2SA(hCPE->hCoreCoder[n]->output_Fs, PH_ECU_MEM_NS), negate(hCPE->hCoreCoder[n]->Q_syn)); - } - IF(hCPE->hCoreCoder[n]->hHQ_core) - { - Scale_sig(hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, negate(hCPE->hCoreCoder[n]->Q_syn)); - } - - } - - - /*----------------------------------------------------------------* - * CoreCoder Post-processing and updates - *----------------------------------------------------------------*/ - Word32 synth_fx_32[CPE_CHANNELS][L_FRAME48k]; - - FOR ( n = 0; n < CPE_CHANNELS; n++ ) - { - IF ( NE_16(st_ivas->sba_dirac_stereo_flag, 0) && ( NE_16(st_ivas->ivas_format, SBA_ISM_FORMAT) || GE_16(cpe_id, sub(nCPE, 2)) ) ) - { - - Copy_Scale_sig_16_32(synth_fx[n], synth_fx_32[n], L_FRAME48k, sub(Q11, 0)); - Copy_Scale_sig_16_32(hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, hCPE->hCoreCoder[n]->hHQ_core->oldOut_fx, output_frame, Q11); - ivas_post_proc_fx( NULL, hCPE, n, synth_fx_32[n], NULL, output_frame, 1 ); - Copy_Scale_sig_32_16(synth_fx_32[n], synth_fx[n], L_FRAME48k, sub(0, Q11)); - - } - - /* Postprocessing for ACELP/MDCT core switching and synchronization */ - Word16 output_mem_fx[L_FRAME48k]; - IF( hCPE->output_mem_fx[1] != NULL ) - { - Copy_Scale_sig_32_16( hCPE->output_mem_fx[1], output_mem_fx, NS2SA( sts[n]->output_Fs, 3125000 ), sub(0, Q11) ); - } - ELSE - { - set16_fx( output_mem_fx, 0, NS2SA( sts[n]->output_Fs, 3125000 ) ); - } - - Word16 Q_synth = 0; - - IF ( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx[n], output_fx[cpe_id * CPE_CHANNELS + n], output_mem_fx, st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, ( st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2 ) ? st_ivas->sba_dirac_stereo_flag : 0, -1, hCPE->last_element_mode, &Q_synth ) ) != IVAS_ERR_OK ) - { - return error; - } - - Copy_Scale_sig_16_32(synth_fx[n], output_fx[cpe_id * CPE_CHANNELS + n], output_frame, sub(Q11, Q_synth)); - - /* Save synthesis for HQ FEC */ - Word32 output_fx_[L_FRAME48k]; - mvl2l(output_fx[cpe_id * CPE_CHANNELS + n], output_fx_, L_FRAME48k); - Scale_sig32(output_fx_, L_FRAME48k, sub(Q16, Q11)); - Copy_Scale_sig32_16(sts[n]->prev_synth_buffer32_fx, sts[n]->prev_synth_buffer_fx, NS2SA(48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS), -11); - sts[n]->q_prev_synth_buffer_fx = 0; - - save_synthesis_hq_fec_fx( sts[n], output_fx_, output_frame, hCPE ); - - /* CoreCoder common updates */ - ivas_updt_dec_common_fx( hCPE->hCoreCoder[n], NORMAL_HQ_CORE, -1, output_fx[cpe_id * CPE_CHANNELS + n], 11 ); - - } /* n_channels loop */ - - FOR(n = 0; n < 2; n++) { - IF(hCPE->hCoreCoder[n]) - { - Copy_Scale_sig_16_32(hCPE->hCoreCoder[n]->delay_buf_out_fx, hCPE->hCoreCoder[n]->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP, Q11); - } - } - - /* synthesis synchronization between stereo modes */ - IF ( EQ_16(st_ivas->sba_dirac_stereo_flag, 0) || ( EQ_16(st_ivas->ivas_format, SBA_ISM_FORMAT) && LE_16(cpe_id, sub(nCPE, 2)) ) ) - { - synchro_synthesis_fx( ivas_total_brate, hCPE, output_fx + cpe_id * CPE_CHANNELS, output_frame, 0 ); - } + hMCT->hBlockData[n] = NULL; } - /* move channels after LFE to correct output for multi-channel MCT */ - IF ( EQ_16(st_ivas->ivas_format, MC_FORMAT) && ( EQ_16(st_ivas->mc_mode, MC_MODE_MCT) || EQ_16(st_ivas->mc_mode, MC_MODE_PARAMUPMIX) ) ) - { - Word32 tmp[L_FRAME48k]; + /*-----------------------------------------------------------------* + * Initializations + *-----------------------------------------------------------------*/ - /*save center channel output*/ - mvl2l( output_fx[hMCT->nchan_out_woLFE - 1], tmp, output_frame ); + hMCT->currBlockDataCnt = 0; - FOR ( n = hMCT->nchan_out_woLFE - 1; n >= LFE_CHANNEL; n-- ) - { - mvl2l( output_fx[n - 1], output_fx[n + 1], output_frame ); - } - mvl2l( tmp, output_fx[LFE_CHANNEL - 1], output_frame ); + /*Initialize bits required to signal channel-pair index*/ + hMCT->bitsChannelPairIndex = max( 1, (int16_t) ( floorf( ( logf( (float) hMCT->nchan_out_woLFE * ( hMCT->nchan_out_woLFE - 1 ) / 2 - 1 ) * INV_LOG_2 ) ) + 1 ) ); - /* save LFE channel */ - mvl2l( output_lfe_ch_fx, output_fx[LFE_CHANNEL], output_frame ); - } + set_s( hMCT->chBitRatios, 0, MCT_MAX_CHANNELS ); + set_s( hMCT->lowE_ch, 0, MCT_MAX_CHANNELS ); - pop_wmops(); - return error; + st_ivas->hMCT = hMCT; + return IVAS_ERR_OK; } -#endif /*------------------------------------------------------------------------- - * create_mct_dec() + * mct_dec_reconfigure() * - * Create, allocate and initialize IVAS decoder MCT handle + * Reconfigure IVAS decoder MCT handle *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED -ivas_error create_mct_dec_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +ivas_error mct_dec_reconfigure_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const UWord16 b_nchan_change /* i : flag indicating different channel count */ ) { MCT_DEC_HANDLE hMCT; - Word16 n; - Word32 cp_bitrate; - Word16 max_blocks; - Word16 cpe_id; - - /*--------------------------------------------------------- --------* - * Allocate MCT handle - *-----------------------------------------------------------------*/ + Decoder_State *st; + Word16 n, cpe_id, max_blocks; + Word32 cp_bitrate, L_tmp; + Word16 tmp_exp, tmp; - IF( ( hMCT = (MCT_DEC_HANDLE) malloc( sizeof( MCT_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CPE\n" ) ); - } + hMCT = st_ivas->hMCT; /*-----------------------------------------------------------------* - * Allocate MCT BlockData handles - *-----------------------------------------------------------------*/ - - /* Determine active channels */ - IF( ( EQ_16(st_ivas->ivas_format , MC_FORMAT) && EQ_16(st_ivas->mc_mode , MC_MODE_PARAMMC) ) || EQ_16(st_ivas->ivas_format , SBA_FORMAT) || EQ_16(st_ivas->ivas_format , SBA_ISM_FORMAT) ) + * Allocate and initialize MCT BlockData handles + *-----------------------------------------------------------------*/ + IF ( b_nchan_change ) { - hMCT->nchan_out_woLFE = st_ivas->nchan_transport; - IF( EQ_16(st_ivas->ism_mode , ISM_SBA_MODE_DISC) ) + /* Determine active channels */ + test(); test(); test(); test(); + IF ( ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) || EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - hMCT->nchan_out_woLFE = add(hMCT->nchan_out_woLFE,st_ivas->nchan_ism); + hMCT->nchan_out_woLFE = st_ivas->nchan_transport; + move16(); + IF ( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + hMCT->nchan_out_woLFE = add( hMCT->nchan_out_woLFE, st_ivas->nchan_ism ); + } + } + ELSE IF ( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) + { + hMCT->nchan_out_woLFE = sub( st_ivas->nchan_transport, st_ivas->hTransSetup.num_lfe ); + } + ELSE IF ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) + { + hMCT->nchan_out_woLFE = sub( st_ivas->nchan_transport, st_ivas->hTransSetup.num_lfe ); + } + ELSE + { + assert( !"IVAS format currently not supported for MCT" ); } - } - ELSE IF( EQ_16(st_ivas->mc_mode , MC_MODE_MCT) ) - { - hMCT->nchan_out_woLFE = sub(st_ivas->nchan_transport , st_ivas->hTransSetup.num_lfe); - } - ELSE IF( EQ_16(st_ivas->ivas_format , MC_FORMAT) && EQ_16(st_ivas->mc_mode , MC_MODE_PARAMUPMIX) ) - { - hMCT->nchan_out_woLFE = sub(st_ivas->nchan_transport , st_ivas->hTransSetup.num_lfe); - } - ELSE - { - assert( !"IVAS format currently not supported for MCT" ); - } - - cp_bitrate = L_shl( Mult_32_16( st_ivas->hDecoderConfig->ivas_total_brate, div_s( 1, hMCT->nchan_out_woLFE ) ), 1 ); - - IF( EQ_16(st_ivas->ism_mode , ISM_SBA_MODE_DISC) ) - { - cp_bitrate = L_shl( Mult_32_16( st_ivas->hDecoderConfig->ivas_total_brate, div_s( 1, st_ivas->nchan_transport ) ), 1 ); } /* indicate LFE for appropriate core-coder channel */ - FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - FOR( n = 0; n < CPE_CHANNELS; n++ ) + FOR ( n = 0; n < CPE_CHANNELS; n++ ) { st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; } } /* in case we have an uneven number of transport channels, indicate last channel ID as inactive */ - IF( hMCT->nchan_out_woLFE % 2 ) + IF ( hMCT->nchan_out_woLFE % 2 ) { st_ivas->hCPE[st_ivas->nCPE - 1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; } - /*Initialize MCT block data */ - max_blocks = shr(hMCT->nchan_out_woLFE , 1); + tmp = BASOP_Util_Divide3216_Scale(st_ivas->hDecoderConfig->ivas_total_brate, hMCT->nchan_out_woLFE, &tmp_exp ); + cp_bitrate = L_shl( tmp, tmp_exp + 2 ); - FOR( n = 0; n < max_blocks; n++ ) + IF ( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - IF( ( hMCT->hBlockData[n] = (MCT_DEC_BLOCK_DATA_HANDLE) malloc( sizeof( MCT_DEC_BLOCK_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MCT block data structure\n" ) ); - } + tmp = BASOP_Util_Divide3216_Scale(st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, &tmp_exp); + cp_bitrate = L_shl(tmp, tmp_exp + 2); + } - /*Initialize all parameters to zero*/ - hMCT->hBlockData[n]->ch1 = 0; - hMCT->hBlockData[n]->ch2 = 0; + /* set correct nominal bitrates and igf config already here, otherwise we + * run into a number of problems */ + FOR ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + st_ivas->hCPE[cpe_id]->element_brate = cp_bitrate; + move32(); + FOR ( n = 0; n < CPE_CHANNELS; n++ ) + { + st = st_ivas->hCPE[cpe_id]->hCoreCoder[n]; - /*-----------------------------------------------------------------* - * MDCT stereo initialization - *-----------------------------------------------------------------*/ + st->total_brate = st_ivas->hCPE[cpe_id]->element_brate; + move32(); - IF( ( hMCT->hBlockData[n]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) + IF ( NE_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + { + tmp = BASOP_Util_Divide3232_Scale( st_ivas->hCPE[cpe_id]->element_brate, FRAMES_PER_SEC, &tmp_exp ); + st->bits_frame_nominal = shr( tmp, 15 - tmp_exp ); + st->igf = getIgfPresent_fx(st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->bwidth, st->rf_flag); // no floating point so directly pluggable + + IF(st->igf) + { + IGFDecSetMode_ivas_fx(st->hIGFDec, st_ivas->hCPE[cpe_id]->element_brate, st->bwidth, st->element_mode, -1, -1, st->rf_flag); + } + } + } + } + + /*Initialize MCT block data */ + tmp = BASOP_Util_Divide1616_Scale(hMCT->nchan_out_woLFE, CPE_CHANNELS, &tmp_exp); + max_blocks = shr( tmp, 15 - tmp_exp ); + + FOR ( n = 0; n < max_blocks; n++ ) + { + IF ( b_nchan_change ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); + IF ( hMCT->hBlockData[n] == NULL ) + { + IF ( ( hMCT->hBlockData[n] = (MCT_DEC_BLOCK_DATA_HANDLE) malloc( sizeof( MCT_BLOCK_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MCT block data structure\n" ) ); + } + + /*Initialize all parameters to zero*/ + hMCT->hBlockData[n]->ch1 = 0; + move16(); + hMCT->hBlockData[n]->ch2 = 0; + move16(); + + /* MDCT stereo initialization */ + IF ( ( hMCT->hBlockData[n]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); + } + } } - initMdctStereoDecData_fx( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, SWB ); + initMdctStereoDecData_fx( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, st_ivas->hCPE[0]->hCoreCoder[0]->bwidth ); + hMCT->hBlockData[n]->hStereoMdct->use_itd = 0; - hMCT->hBlockData[n]->hStereoMdct->reverse_dmx = 0; - hMCT->hBlockData[n]->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; + move16(); } - FOR( ; n < MCT_MAX_BLOCKS; n++ ) + + FOR ( ; n < MCT_MAX_BLOCKS; n++ ) { - hMCT->hBlockData[n] = NULL; + /* deallocate no longer needed blocks */ + IF ( hMCT->hBlockData[n] != NULL ) + { + IF ( hMCT->hBlockData[n]->hStereoMdct != NULL ) + { + free( hMCT->hBlockData[n]->hStereoMdct ); + hMCT->hBlockData[n]->hStereoMdct = NULL; + } + + free( hMCT->hBlockData[n] ); + hMCT->hBlockData[n] = NULL; + } } /*-----------------------------------------------------------------* - * Initializations - *-----------------------------------------------------------------*/ + * Initializations + *-----------------------------------------------------------------*/ - hMCT->currBlockDataCnt = 0; + IF ( b_nchan_change ) + { + hMCT->currBlockDataCnt = 0; + move16(); - /*Initialize bits required to signal channel-pair index*/ - // hMCT->bitsChannelPairIndex = max( 1, (Word16) ( floorf( ( logf( (float) hMCT->nchan_out_woLFE * ( hMCT->nchan_out_woLFE - 1 ) / 2 - 1 ) * INV_LOG_2 ) ) + 1 ) ); - hMCT->bitsChannelPairIndex = s_max( 1, floor_log_2( (Word32) hMCT->nchan_out_woLFE * ( (Word32) hMCT->nchan_out_woLFE - 1 ) / 2 - 1 )+ 1 ); + /*Initialize bits required to signal channel-pair index*/ - set16_fx( hMCT->chBitRatios, 0, MCT_MAX_CHANNELS ); - set16_fx( hMCT->lowE_ch, 0, MCT_MAX_CHANNELS ); + Word32 log_tmp; + L_tmp = L_sub( L_shr( L_mult0( hMCT->nchan_out_woLFE, sub(hMCT->nchan_out_woLFE, 1) ), 1 ), 1 ); + tmp_exp = norm_l(L_tmp); + L_tmp = L_shl(L_tmp, tmp_exp); + log_tmp = BASOP_Util_Log2(L_tmp); // ( 31 - tmp_exp ) + log_tmp = L_add(log_tmp, L_shl((Q31 - tmp_exp), Q25)); // Q25 + // scale down from Q25 to Q0 - st_ivas->hMCT = hMCT; + tmp = extract_l(L_shr(log_tmp, Q25)); + tmp = add(tmp, 1); + hMCT->bitsChannelPairIndex = s_max(1, tmp); + + set_s( hMCT->chBitRatios, 0, MCT_MAX_CHANNELS ); + set_s( hMCT->lowE_ch, 0, MCT_MAX_CHANNELS ); + } return IVAS_ERR_OK; } -#endif // IVAS_FLOAT_FIXED - -ivas_error create_mct_dec( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#else +ivas_error mct_dec_reconfigure( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const uint16_t b_nchan_change /* i : flag indicating different channel count */ ) { MCT_DEC_HANDLE hMCT; - int16_t n; + Decoder_State *st; + int16_t n, cpe_id, max_blocks; int32_t cp_bitrate; - int16_t max_blocks; - int16_t cpe_id; - /*--------------------------------------------------------- --------* - * Allocate MCT handle + hMCT = st_ivas->hMCT; + + /*-----------------------------------------------------------------* + * Allocate and initialize MCT BlockData handles *-----------------------------------------------------------------*/ - if ( ( hMCT = (MCT_DEC_HANDLE) malloc( sizeof( MCT_DEC_DATA ) ) ) == NULL ) + if ( b_nchan_change ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CPE\n" ) ); + /* Determine active channels */ + if ( ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMMC ) || st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) + { + hMCT->nchan_out_woLFE = st_ivas->nchan_transport; + if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + { + hMCT->nchan_out_woLFE += st_ivas->nchan_ism; + } + } + else if ( st_ivas->mc_mode == MC_MODE_MCT ) + { + hMCT->nchan_out_woLFE = st_ivas->nchan_transport - st_ivas->hTransSetup.num_lfe; + } + else if ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + { + hMCT->nchan_out_woLFE = st_ivas->nchan_transport - st_ivas->hTransSetup.num_lfe; + } + else + { + assert( !"IVAS format currently not supported for MCT" ); + } + } + + /* indicate LFE for appropriate core-coder channel */ + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + } + } + + /* in case we have an uneven number of transport channels, indicate last channel ID as inactive */ + if ( hMCT->nchan_out_woLFE % 2 ) + { + st_ivas->hCPE[st_ivas->nCPE - 1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + } + + cp_bitrate = st_ivas->hDecoderConfig->ivas_total_brate / hMCT->nchan_out_woLFE * CPE_CHANNELS; + if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + { + cp_bitrate = st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport * CPE_CHANNELS; + } + + /* set correct nominal bitrates and igf config already here, otherwise we + * run into a number of problems */ + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + st_ivas->hCPE[cpe_id]->element_brate = cp_bitrate; + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st = st_ivas->hCPE[cpe_id]->hCoreCoder[n]; + + st->total_brate = st_ivas->hCPE[cpe_id]->element_brate; + + if ( st->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) + { + st->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[cpe_id]->element_brate / FRAMES_PER_SEC ); + st->igf = getIgfPresent( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->bwidth, st->rf_flag ); + if ( st->igf ) + { + IGFDecSetMode_flt( st->hIGFDec, st_ivas->hCPE[cpe_id]->element_brate, st->bwidth, st->element_mode, -1, -1, st->rf_flag ); + } + } + } + } + + /*Initialize MCT block data */ + max_blocks = hMCT->nchan_out_woLFE / CPE_CHANNELS; + + for ( n = 0; n < max_blocks; n++ ) + { + if ( b_nchan_change ) + { + if ( hMCT->hBlockData[n] == NULL ) + { + if ( ( hMCT->hBlockData[n] = (MCT_DEC_BLOCK_DATA_HANDLE) malloc( sizeof( MCT_BLOCK_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MCT block data structure\n" ) ); + } + + /*Initialize all parameters to zero*/ + hMCT->hBlockData[n]->ch1 = 0; + hMCT->hBlockData[n]->ch2 = 0; + + /* MDCT stereo initialization */ + if ( ( hMCT->hBlockData[n]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); + } + } + } + + initMdctStereoDecData( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, st_ivas->hCPE[0]->hCoreCoder[0]->bwidth ); + hMCT->hBlockData[n]->hStereoMdct->use_itd = 0; + } + + for ( ; n < MCT_MAX_BLOCKS; n++ ) + { + /* deallocate no longer needed blocks */ + if ( hMCT->hBlockData[n] != NULL ) + { + if ( hMCT->hBlockData[n]->hStereoMdct != NULL ) + { + free( hMCT->hBlockData[n]->hStereoMdct ); + hMCT->hBlockData[n]->hStereoMdct = NULL; + } + + free( hMCT->hBlockData[n] ); + hMCT->hBlockData[n] = NULL; + } + } + + /*-----------------------------------------------------------------* + * Initializations + *-----------------------------------------------------------------*/ + + if ( b_nchan_change ) + { + hMCT->currBlockDataCnt = 0; + + /*Initialize bits required to signal channel-pair index*/ + hMCT->bitsChannelPairIndex = max( 1, (int16_t) ( floorf( ( logf( (float) hMCT->nchan_out_woLFE * ( hMCT->nchan_out_woLFE - 1 ) / 2 - 1 ) * INV_LOG_2 ) ) + 1 ) ); + + set_s( hMCT->chBitRatios, 0, MCT_MAX_CHANNELS ); + set_s( hMCT->lowE_ch, 0, MCT_MAX_CHANNELS ); + } + + return IVAS_ERR_OK; +} +#endif + + +/*------------------------------------------------------------------------- + * create_mct_dec_close() + * + * Close IVAS decoder MCT handle + *-------------------------------------------------------------------------*/ + +void ivas_mct_dec_close( + MCT_DEC_HANDLE *hMCT /* i/o: MCT decoder structure */ +) +#ifdef IVAS_FLOAT_FIXED +{ + Word16 n, maxBlocks; + + IF ( hMCT == NULL || *hMCT == NULL ) + { + return; + } + + maxBlocks = shr( ( *hMCT )->nchan_out_woLFE, 1 ); + + FOR ( n = 0; n < maxBlocks; n++ ) + { + IF ( ( *hMCT )->hBlockData[n] != NULL ) + { + IF ( ( *hMCT )->hBlockData[n]->hStereoMdct != NULL ) + { + free( ( *hMCT )->hBlockData[n]->hStereoMdct ); + ( *hMCT )->hBlockData[n]->hStereoMdct = NULL; + } + + free( ( *hMCT )->hBlockData[n] ); + ( *hMCT )->hBlockData[n] = NULL; + } + } + + free( *hMCT ); + *hMCT = NULL; + + return; +} +#else +{ + Word16 n, maxBlocks; + + IF ( hMCT == NULL || *hMCT == NULL ) + { + return; + } + + maxBlocks = ( *hMCT )->nchan_out_woLFE / 2; + + FOR ( n = 0; n < maxBlocks; n++ ) + { + IF ( ( *hMCT )->hBlockData[n] != NULL ) + { + IF ( ( *hMCT )->hBlockData[n]->hStereoMdct != NULL ) + { + free( ( *hMCT )->hBlockData[n]->hStereoMdct ); + ( *hMCT )->hBlockData[n]->hStereoMdct = NULL; + } + + free( ( *hMCT )->hBlockData[n] ); + ( *hMCT )->hBlockData[n] = NULL; + } + } + + free( *hMCT ); + *hMCT = NULL; + + return; +} +#endif + + +/*------------------------------------------------------------------------- + * ivas_mc_dec_config() + * + * - read transported MC LS setup + * - select MC format mode + * - reconfigure the MC format decoder + *-------------------------------------------------------------------------*/ + +/*! r : MC format mode */ +ivas_error ivas_mc_dec_config( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t idx, /* i : LS config. index */ + uint16_t *nSamplesRendered, /* o : samples flushed from last frame (JBM) */ + int16_t *data /* o : output synthesis signal */ +) +{ + AUDIO_CONFIG signaled_config; + MC_MODE last_mc_mode; + ivas_error error; + + /* store last frame MC mode */ + last_mc_mode = st_ivas->mc_mode; + + if ( !st_ivas->bfi ) + { + /* set transported MC LS setup */ + signaled_config = ivas_mc_map_ls_setup_to_output_config( idx ); + + if ( st_ivas->ini_frame == 0 ) + { + st_ivas->transport_config = signaled_config; + } + + /* select MC format mode */ + st_ivas->mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( signaled_config ), st_ivas->hDecoderConfig->ivas_total_brate ); + + /* MC format switching */ + if ( st_ivas->ini_frame != 0 ) + { + if ( st_ivas->hDecoderConfig->last_ivas_total_brate != st_ivas->hDecoderConfig->ivas_total_brate || st_ivas->transport_config != signaled_config || last_mc_mode != st_ivas->mc_mode ) + { +#ifdef IVAS_FLOAT_FIXED +#if 1 /*TODO: To be removed(Float to fixed conversion)*/ + DECODER_TC_BUFFER_HANDLE hTcBuffer; + hTcBuffer = st_ivas->hTcBuffer; + IF( st_ivas->hCombinedOrientationData ) + FOR( Word16 ind1 = 0; ind1 < 3; ind1++ ) + { + FOR( Word16 ind2 = 0; ind2 < 3; ind2++ ) + { + st_ivas->hCombinedOrientationData->Rmat_fx[0][ind1][ind2] = (Word32) ( st_ivas->hCombinedOrientationData->Rmat[0][ind1][ind2] * ( 1 << 15 ) ); + } + } + SPAR_DEC_HANDLE hSpar; + hSpar = st_ivas->hSpar; + Word16 nchan_transport_old = st_ivas->nchan_transport; + uint16_t nchan_internal; + Word32 ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + DECODER_CONFIG_HANDLE hDecoderConfig; + hDecoderConfig = st_ivas->hDecoderConfig; + + Word16 n_tc; + n_tc = st_ivas->hTcBuffer->nchan_transport_internal; + for ( int ch = 0; ch < n_tc; ch++ ) + { + floatToFixed_arrL( st_ivas->hTcBuffer->tc[ch], st_ivas->hTcBuffer->tc_fx[ch], Q11, L_FRAME48k ); + } + Word16 cx_e = 0, cy_e = 0, mmo_e = 0, mmro_e = 0; + PARAM_MC_DEC_HANDLE hParamMC; + hParamMC = st_ivas->hParamMC; + Word16 nchan_out_transport, nchan_out_cov; + MC_LS_SETUP mc_ls_setup; + Word16 nchan_transport; + if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + { + mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); + nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_ls_setup ); + nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; + if ( st_ivas->hParamMC ) + { + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + { + nchan_out_cov = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; + } + else + { + nchan_out_cov = nchan_out_transport; + } + floatToFixed_arr( hParamMC->icc_q, hParamMC->icc_q_fx, Q15, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); + floatToFixed_arr( hParamMC->icld_q, hParamMC->icld_q_fx, Q8, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); + Word32 max_cx_old_fx, max_cy_old_fx, max_mix_matrix_old_fx, max_mix_matrix_res_old_fx; + float max_cx_old = hParamMC->h_output_synthesis_cov_state.cx_old[0][0], max_cy_old = hParamMC->h_output_synthesis_cov_state.cy_old[0][0], max_mix_matrix_old = hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[0][0], max_mix_matrix_res_old = hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[0][0]; + for ( int i = 0; i < hParamMC->hMetadataPMC->num_parameter_bands; i++ ) + { + if ( hParamMC->h_output_synthesis_cov_state.cx_old[i] ) + { + for ( int j = 0; j < nchan_transport_old * nchan_transport_old; j++ ) + max_cx_old = max( max_cx_old, hParamMC->h_output_synthesis_cov_state.cx_old[i][j] ); + for ( int j = 0; j < nchan_out_cov * nchan_out_cov; j++ ) + max_cy_old = max( max_cy_old, hParamMC->h_output_synthesis_cov_state.cy_old[i][j] ); + for ( int j = 0; j < nchan_transport_old * nchan_out_cov; j++ ) + max_mix_matrix_old = max( max_mix_matrix_old, hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[i][j] ); + } + } + IF(st_ivas->hParamMC->ls_conv_dmx_matrix_fx ) + floatToFixed_arr32( st_ivas->hParamMC->ls_conv_dmx_matrix, st_ivas->hParamMC->ls_conv_dmx_matrix_fx, Q30, st_ivas->hDecoderConfig->nchan_out * ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) ); + for ( int i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) + { + if ( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[i] ) + { + for ( int j = 0; j < nchan_out_cov * nchan_out_cov; j++ ) + max_mix_matrix_res_old = max( max_mix_matrix_res_old, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[i][j] ); + } + } + f2me( max_cx_old, &max_cx_old_fx, &cx_e ); + f2me( max_cy_old, &max_cy_old_fx, &cy_e ); + f2me( max_mix_matrix_old, &max_mix_matrix_old_fx, &mmo_e ); + f2me( max_mix_matrix_res_old, &max_mix_matrix_res_old_fx, &mmro_e ); + if ( mmo_e < 0 ) + mmo_e = 0; + if ( mmro_e < 0 ) + mmro_e = 0; + for ( int i = 0; i < hParamMC->hMetadataPMC->num_parameter_bands; i++ ) + { + if ( hParamMC->h_output_synthesis_cov_state.cx_old[i] ) + { + + floatToFixed_arrL( hParamMC->h_output_synthesis_cov_state.cx_old[i], hParamMC->h_output_synthesis_cov_state.cx_old_fx[i], 31 - cx_e, nchan_transport_old * nchan_transport_old ); + floatToFixed_arrL( hParamMC->h_output_synthesis_cov_state.cy_old[i], hParamMC->h_output_synthesis_cov_state.cy_old_fx[i], 31 - cy_e, nchan_out_cov * nchan_out_cov ); + floatToFixed_arrL( hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[i], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[i], 31 - mmo_e, nchan_transport_old * nchan_out_cov ); + } + } + for ( int i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) + { + if ( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[i] ) + { + floatToFixed_arrL( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[i], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[i], 31 - mmro_e, nchan_out_cov * nchan_out_cov ); + } + } + floatToFixed_arrL( hParamMC->proto_matrix_int, hParamMC->proto_matrix_int_fx, Q31, nchan_out_transport * nchan_transport ); + FOR( Word16 i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) + { + if ( hParamMC->diff_proto_info ) + floatToFixed_arrL( hParamMC->diff_proto_info->proto_fac[i], hParamMC->diff_proto_info->proto_fac_fx[i], Q26, hParamMC->diff_proto_info->num_source_chan_diff[i] ); + } + } + } +#endif + if ( ( error = ivas_mc_dec_reconfig( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + { + return error; + } +#if 1 + if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + { + PARAM_MC_DEC_HANDLE hParamMC; + hParamMC = st_ivas->hParamMC; + mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); + st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_ls_setup ); + nchan_transport = st_ivas->nchan_transport; + nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + { + nchan_out_cov = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; + } + else + { + nchan_out_cov = nchan_out_transport; + } + if ( hParamMC ) + { + if ( st_ivas->hLsSetUpConversion ) + { + for ( Word16 k = 0; k < nchan_transport; k++ ) + { + for ( int16_t i = 0; i < nchan_out_cov; i++ ) + { + st_ivas->hLsSetUpConversion->dmxMtx[k][i] = fixedToFloat( st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i], Q30 ); + } + } + } + fixedToFloat_arr( hParamMC->icc_q_fx, hParamMC->icc_q, Q15, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); + fixedToFloat_arr( hParamMC->icld_q_fx, hParamMC->icld_q, Q8, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); + fixedToFloat_arrL( hParamMC->h_output_synthesis_params.proto_matrix_fx, hParamMC->h_output_synthesis_params.proto_matrix, 26, nchan_transport * nchan_out_cov ); + IF( hParamMC->diff_proto_info ) + FOR( Word16 i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) + { + + fixedToFloat_arrL( hParamMC->diff_proto_info->proto_fac_fx[i], hParamMC->diff_proto_info->proto_fac[i], 26, hParamMC->diff_proto_info->num_source_chan_diff[i] ); + } + fixedToFloat_arrL( hParamMC->proto_matrix_int_fx, hParamMC->proto_matrix_int, Q31, nchan_out_transport * nchan_transport ); + IF(st_ivas->hParamMC->ls_conv_dmx_matrix_fx ) + fixedToFloat_arrL( st_ivas->hParamMC->ls_conv_dmx_matrix_fx, st_ivas->hParamMC->ls_conv_dmx_matrix, Q30, st_ivas->hDecoderConfig->nchan_out * ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) ); + if ( last_mc_mode == MC_MODE_PARAMMC ) + { + for ( int i = 0; i < hParamMC->hMetadataPMC->num_parameter_bands; i++ ) + { + if ( hParamMC->h_output_synthesis_cov_state.cx_old[i] ) + { + fixedToFloat_arrL( hParamMC->h_output_synthesis_cov_state.cx_old_fx[i], hParamMC->h_output_synthesis_cov_state.cx_old[i], 31 - cx_e, nchan_transport_old * nchan_transport_old ); + fixedToFloat_arrL( hParamMC->h_output_synthesis_cov_state.cy_old_fx[i], hParamMC->h_output_synthesis_cov_state.cy_old[i], 31 - cy_e, nchan_out_cov * nchan_out_cov ); + fixedToFloat_arrL( hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[i], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[i], 31 - mmo_e, nchan_transport_old * nchan_out_cov ); + } + } + for ( int i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) + { + if ( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[i] ) + { + fixedToFloat_arrL( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[i], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[i], 31 - mmro_e, nchan_out_cov * nchan_out_cov ); + } + } + } + } + } +#endif +#else + if ( ( error = ivas_mc_dec_reconfig( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif // IVAS_FLOAT_FIXED + } + } + + st_ivas->transport_config = signaled_config; } - /*-----------------------------------------------------------------* - * Allocate MCT BlockData handles - *-----------------------------------------------------------------*/ + return IVAS_ERR_OK; +} + + +/*------------------------------------------------------------------------- + * ivas_mc_dec_reconfig() + * + * reconfigure the MC format decoder + *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static ivas_error ivas_mc_dec_reconfig( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + UWord16 *nSamplesRendered, /* o : number of samples flushed from the last frame (JBM) */ + Word16 *data /* o : output synthesis signal */ +) +{ + Word16 nchan_transport_old, nSCE_old, nCPE_old, sba_dirac_stereo_flag_old, nchan_hp20_old; + Word16 numCldfbAnalyses_old, numCldfbSyntheses_old; + Word32 new_brate_SCE, new_brate_CPE, ivas_total_brate; + RENDERER_TYPE renderer_type_old; + Decoder_State *st; + ivas_error error; + MC_MODE mc_mode, last_mc_mode; + TC_BUFFER_MODE tc_buffer_mode_new; + Word16 tc_nchan_tc_new; + Word16 tc_nchan_allocate_new; + Word16 tc_granularity_new; + AUDIO_CONFIG intern_config_old; + IVAS_OUTPUT_SETUP hIntSetupOld; + Word16 nchan_out_buff_old, nchan_out_buff; + + error = IVAS_ERR_OK; + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + nchan_transport_old = st_ivas->nchan_transport; + nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); + last_mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */ + + /* temporally set the current mc_mode back to the previous one to make sure the following call to + ivas_init_dec_get_num_cldfb_instances() returns the correct counts */ + mc_mode = st_ivas->mc_mode; + st_ivas->mc_mode = last_mc_mode; + ivas_init_dec_get_num_cldfb_instances_ivas_fx( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); + + st_ivas->mc_mode = mc_mode; - /* Determine active channels */ - if ( ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMMC ) || st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) - { - hMCT->nchan_out_woLFE = st_ivas->nchan_transport; - if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) - { - hMCT->nchan_out_woLFE += st_ivas->nchan_ism; - } - } - else if ( st_ivas->mc_mode == MC_MODE_MCT ) - { - hMCT->nchan_out_woLFE = st_ivas->nchan_transport - st_ivas->hTransSetup.num_lfe; - } - else if ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + nSCE_old = st_ivas->nSCE; + nCPE_old = st_ivas->nCPE; + sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; + + /* special handling needed for the hp20 buffers for McMASA */ + IF ( EQ_16(last_mc_mode , MC_MODE_MCMASA) ) { - hMCT->nchan_out_woLFE = st_ivas->nchan_transport - st_ivas->hTransSetup.num_lfe; + nchan_hp20_old = getNumChanSynthesis( st_ivas ); } - else + ELSE { - assert( !"IVAS format currently not supported for MCT" ); + nchan_hp20_old = nchan_transport_old; } + st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); - cp_bitrate = st_ivas->hDecoderConfig->ivas_total_brate / hMCT->nchan_out_woLFE * CPE_CHANNELS; + /* save old IntSetup, might be needed for JBM flushing...*/ + intern_config_old = st_ivas->intern_config; + hIntSetupOld = st_ivas->hIntSetup; + tc_granularity_new = 1; - if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) - { - cp_bitrate = st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport * CPE_CHANNELS; - } + /* renderer might have changed, reselect */ + renderer_type_old = st_ivas->renderer_type; + ivas_renderer_select( st_ivas ); - /* indicate LFE for appropriate core-coder channel */ - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + /* side effect of the renderer selection can be a changed internal config */ + ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); + + /* transfer subframe info from DirAC or ParamMC to central tc buffer */ + IF ( EQ_16(last_mc_mode , MC_MODE_PARAMMC) ) { - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; - } + st_ivas->hTcBuffer->nb_subframes = st_ivas->hParamMC->nb_subframes; + st_ivas->hTcBuffer->subframes_rendered = st_ivas->hParamMC->subframes_rendered; + st_ivas->hTcBuffer->num_slots = st_ivas->hParamMC->num_slots; + st_ivas->hTcBuffer->slots_rendered = st_ivas->hParamMC->slots_rendered; + Copy( st_ivas->hParamMC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } - - /* in case we have an uneven number of transport channels, indicate last channel ID as inactive */ - if ( hMCT->nchan_out_woLFE % 2 ) + ELSE IF ( EQ_16(last_mc_mode , MC_MODE_MCMASA) && st_ivas->hSpatParamRendCom != NULL ) { - st_ivas->hCPE[st_ivas->nCPE - 1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes; + st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; + st_ivas->hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots; + st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; + Copy( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } - /*Initialize MCT block data */ - max_blocks = hMCT->nchan_out_woLFE / 2; - - for ( n = 0; n < max_blocks; n++ ) + /* JBM: when granularity goes down (e.g. MCT with CREND -> ParamMC with binaural fastconv + render what still fits in the new granularity */ + tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ); + IF ( LT_16(tc_granularity_new , st_ivas->hTcBuffer->n_samples_granularity) ) { - if ( ( hMCT->hBlockData[n] = (MCT_DEC_BLOCK_DATA_HANDLE) malloc( sizeof( MCT_DEC_BLOCK_DATA ) ) ) == NULL ) + IF ( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, last_mc_mode, ISM_MODE_NONE, nSamplesRendered, data ) ) != IVAS_ERR_OK ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MCT block data structure\n" ) ); + return error; } - - /*Initialize all parameters to zero*/ - hMCT->hBlockData[n]->ch1 = 0; - hMCT->hBlockData[n]->ch2 = 0; - - /*-----------------------------------------------------------------* - * MDCT stereo initialization - *-----------------------------------------------------------------*/ - - if ( ( hMCT->hBlockData[n]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) + } + /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ + ELSE IF ( GT_16(tc_granularity_new , st_ivas->hTcBuffer->n_samples_granularity) ) + { + IF ( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); + return error; } - -#ifndef IVAS_FLOAT_FIXED - initMdctStereoDecData( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, SWB ); -#else - initMdctStereoDecData_fx( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, SWB ); -#endif - hMCT->hBlockData[n]->hStereoMdct->use_itd = 0; - hMCT->hBlockData[n]->hStereoMdct->reverse_dmx = 0; -#ifndef IVAS_FLOAT_FIXED - hMCT->hBlockData[n]->hStereoMdct->smooth_ratio = 1.f; -#else - hMCT->hBlockData[n]->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; -#endif } - for ( ; n < MCT_MAX_BLOCKS; n++ ) + IF ( EQ_16(st_ivas->mc_mode , MC_MODE_MCT) ) { - hMCT->hBlockData[n] = NULL; - } - - /*-----------------------------------------------------------------* - * Initializations - *-----------------------------------------------------------------*/ - - hMCT->currBlockDataCnt = 0; - - /*Initialize bits required to signal channel-pair index*/ - hMCT->bitsChannelPairIndex = max( 1, (int16_t) ( floorf( ( logf( (float) hMCT->nchan_out_woLFE * ( hMCT->nchan_out_woLFE - 1 ) / 2 - 1 ) * INV_LOG_2 ) ) + 1 ) ); - - set_s( hMCT->chBitRatios, 0, MCT_MAX_CHANNELS ); - set_s( hMCT->lowE_ch, 0, MCT_MAX_CHANNELS ); - - st_ivas->hMCT = hMCT; + st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ) ); + st_ivas->nSCE = 0; + st_ivas->nCPE = st_ivas->nchan_transport / 2; - return IVAS_ERR_OK; -} + IF ( NE_16(last_mc_mode , MC_MODE_MCT) ) + { + /*De-allocate handles for other MC modes*/ + IF ( st_ivas->hParamMC != NULL ) + { + ivas_param_mc_dec_close_fx( &st_ivas->hParamMC ); + /* remove ls conversion if it was allocated by ParamMC */ + ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); + } -/*------------------------------------------------------------------------- - * mct_dec_reconfigure() - * - * Reconfigure IVAS decoder MCT handle - *-------------------------------------------------------------------------*/ + IF ( EQ_16(last_mc_mode , MC_MODE_PARAMUPMIX) ) + { + ivas_mc_paramupmix_dec_close( &( st_ivas->hMCParamUpmix ) ); + ivas_ls_setup_conversion_close_fx( &( st_ivas->hLsSetUpConversion ) ); + } -#ifdef IVAS_FLOAT_FIXED -ivas_error mct_dec_reconfigure_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const UWord16 b_nchan_change /* i : flag indicating different channel count */ -) -{ - MCT_DEC_HANDLE hMCT; - Decoder_State *st; - Word16 n, cpe_id, max_blocks; - Word32 cp_bitrate, L_tmp; - Word16 tmp_exp, tmp; + /* De-allocate McMasa-related handles */ + ivas_masa_dec_close_fx( &( st_ivas->hMasa ) ); - hMCT = st_ivas->hMCT; + ivas_qmetadata_close( &st_ivas->hQMetaData ); + IF ( st_ivas->hDirAC != NULL ) + { + ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) ); + ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) ); + ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) ); + vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); + } - /*-----------------------------------------------------------------* - * Allocate and initialize MCT BlockData handles - *-----------------------------------------------------------------*/ - IF ( b_nchan_change ) - { - /* Determine active channels */ - test(); test(); test(); test(); - IF ( ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) || EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) - { - hMCT->nchan_out_woLFE = st_ivas->nchan_transport; - move16(); - IF ( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + /* init LS conversion if the renderer type asks for it */ + IF ( EQ_16(st_ivas->renderer_type , RENDERER_MC) && st_ivas->hLsSetUpConversion == NULL ) { - hMCT->nchan_out_woLFE = add( hMCT->nchan_out_woLFE, st_ivas->nchan_ism ); + if ( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } } - ELSE IF ( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) - { - hMCT->nchan_out_woLFE = sub( st_ivas->nchan_transport, st_ivas->hTransSetup.num_lfe ); - } - ELSE IF ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) - { - hMCT->nchan_out_woLFE = sub( st_ivas->nchan_transport, st_ivas->hTransSetup.num_lfe ); - } - ELSE - { - assert( !"IVAS format currently not supported for MCT" ); - } } - - /* indicate LFE for appropriate core-coder channel */ - FOR ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + ELSE IF ( EQ_16(st_ivas->mc_mode , MC_MODE_PARAMUPMIX) ) { - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + st_ivas->nSCE = 0; + st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS / 2; + st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; + + IF ( NE_16(last_mc_mode , MC_MODE_PARAMUPMIX) ) { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; - } - } + /*De-allocate handles for other MC modes*/ + IF ( st_ivas->hParamMC != NULL ) + { + ivas_param_mc_dec_close_fx( &st_ivas->hParamMC ); - /* in case we have an uneven number of transport channels, indicate last channel ID as inactive */ - IF ( hMCT->nchan_out_woLFE % 2 ) - { - st_ivas->hCPE[st_ivas->nCPE - 1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; - } + /* remove ls conversion if it was allocated by ParamMC */ + ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); + } - tmp = BASOP_Util_Divide3216_Scale(st_ivas->hDecoderConfig->ivas_total_brate, hMCT->nchan_out_woLFE, &tmp_exp ); - cp_bitrate = L_shl( tmp, tmp_exp + 2 ); + ivas_masa_dec_close_fx( &( st_ivas->hMasa ) ); + ivas_qmetadata_close( &st_ivas->hQMetaData ); - IF ( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) - { - tmp = BASOP_Util_Divide3216_Scale(st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, &tmp_exp); - cp_bitrate = L_shl(tmp, tmp_exp + 2); - } + /* init LS conversion if the renderer type asks for it */ + IF ( ( EQ_16(st_ivas->renderer_type , RENDERER_MC) ) && st_ivas->hLsSetUpConversion == NULL ) + { + IF ( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } - /* set correct nominal bitrates and igf config already here, otherwise we - * run into a number of problems */ - FOR ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + IF ( ( error = ivas_mc_paramupmix_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + ELSE IF ( EQ_16(st_ivas->mc_mode , MC_MODE_PARAMMC) ) { - st_ivas->hCPE[cpe_id]->element_brate = cp_bitrate; - move32(); - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + IF ( NE_16(last_mc_mode , MC_MODE_PARAMMC) ) { - st = st_ivas->hCPE[cpe_id]->hCoreCoder[n]; - - st->total_brate = st_ivas->hCPE[cpe_id]->element_brate; - move32(); + /* remove old ls conversion for MCT if open, gets reopened correctly within ivas_param_mc_dec_open when needed */ + IF ( EQ_16(renderer_type_old , RENDERER_MC) && st_ivas->hLsSetUpConversion != NULL ) + { + ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); + } - IF ( NE_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + IF ( ( error = ivas_param_mc_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { - tmp = BASOP_Util_Divide3232_Scale( st_ivas->hCPE[cpe_id]->element_brate, FRAMES_PER_SEC, &tmp_exp ); - st->bits_frame_nominal = shr( tmp, 15 - tmp_exp ); - st->igf = getIgfPresent_fx(st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->bwidth, st->rf_flag); // no floating point so directly pluggable + return error; + } - IF(st->igf) - { - IGFDecSetMode_ivas_fx(st->hIGFDec, st_ivas->hCPE[cpe_id]->element_brate, st->bwidth, st->element_mode, -1, -1, st->rf_flag); - } + } + ELSE + { + IF ( ( error = ivas_param_mc_dec_reconfig_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; } } - } - /*Initialize MCT block data */ - tmp = BASOP_Util_Divide1616_Scale(hMCT->nchan_out_woLFE, CPE_CHANNELS, &tmp_exp); - max_blocks = shr( tmp, 15 - tmp_exp ); + /* De-allocate McMasa-related handles */ + ivas_masa_dec_close_fx( &( st_ivas->hMasa ) ); + ivas_qmetadata_close( &st_ivas->hQMetaData ); + + IF ( st_ivas->hDirAC != NULL ) + { + ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) ); + ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) ); + ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) ); + vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); + } - FOR ( n = 0; n < max_blocks; n++ ) - { - IF ( b_nchan_change ) + IF ( EQ_16(last_mc_mode , MC_MODE_MCT) ) { - IF ( hMCT->hBlockData[n] == NULL ) + IF ( st_ivas->hMCT != NULL && LE_16(st_ivas->nchan_transport , CPE_CHANNELS) ) { - IF ( ( hMCT->hBlockData[n] = (MCT_DEC_BLOCK_DATA_HANDLE) malloc( sizeof( MCT_BLOCK_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MCT block data structure\n" ) ); - } - - /*Initialize all parameters to zero*/ - hMCT->hBlockData[n]->ch1 = 0; - move16(); - hMCT->hBlockData[n]->ch2 = 0; - move16(); - - /* MDCT stereo initialization */ - IF ( ( hMCT->hBlockData[n]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); - } + ivas_mct_dec_close( &st_ivas->hMCT ); } } + ELSE IF ( EQ_16(last_mc_mode , MC_MODE_PARAMUPMIX) ) + { + ivas_mc_paramupmix_dec_close( &( st_ivas->hMCParamUpmix ) ); + } - initMdctStereoDecData_fx( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, st_ivas->hCPE[0]->hCoreCoder[0]->bwidth ); - - hMCT->hBlockData[n]->hStereoMdct->use_itd = 0; - move16(); + /* LFE handle */ + ivas_lfe_dec_close_fx( &( st_ivas->hLFE ) ); } - - FOR ( ; n < MCT_MAX_BLOCKS; n++ ) + ELSE IF ( EQ_16(st_ivas->mc_mode , MC_MODE_MCMASA) ) { - /* deallocate no longer needed blocks */ - IF ( hMCT->hBlockData[n] != NULL ) + ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); + + IF ( NE_16(last_mc_mode , MC_MODE_MCMASA) ) { - IF ( hMCT->hBlockData[n]->hStereoMdct != NULL ) + IF ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { - free( hMCT->hBlockData[n]->hStereoMdct ); - hMCT->hBlockData[n]->hStereoMdct = NULL; + return error; } - - free( hMCT->hBlockData[n] ); - hMCT->hBlockData[n] = NULL; } - } - /*-----------------------------------------------------------------* - * Initializations - *-----------------------------------------------------------------*/ + IF ( ( error = ivas_mcmasa_dec_reconfig( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } - IF ( b_nchan_change ) - { - hMCT->currBlockDataCnt = 0; - move16(); + /* LS conversion */ + IF ( st_ivas->hLsSetUpConversion != NULL ) + { + ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); + } - /*Initialize bits required to signal channel-pair index*/ + ivas_mc_paramupmix_dec_close( &( st_ivas->hMCParamUpmix ) ); - Word32 log_tmp; - L_tmp = L_sub( L_shr( L_mult0( hMCT->nchan_out_woLFE, sub(hMCT->nchan_out_woLFE, 1) ), 1 ), 1 ); - tmp_exp = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, tmp_exp); - log_tmp = BASOP_Util_Log2(L_tmp); // ( 31 - tmp_exp ) - log_tmp = L_add(log_tmp, L_shl((Q31 - tmp_exp), Q25)); // Q25 - // scale down from Q25 to Q0 + IF ( st_ivas->hParamMC != NULL ) + { + ivas_param_mc_dec_close_fx( &st_ivas->hParamMC ); + st_ivas->hParamMC = NULL; + } - tmp = extract_l(L_shr(log_tmp, Q25)); - tmp = add(tmp, 1); - hMCT->bitsChannelPairIndex = s_max(1, tmp); + IF ( EQ_16(last_mc_mode , MC_MODE_MCT) ) + { + ivas_mct_dec_close( &st_ivas->hMCT ); + } - set_s( hMCT->chBitRatios, 0, MCT_MAX_CHANNELS ); - set_s( hMCT->lowE_ch, 0, MCT_MAX_CHANNELS ); + /* LFE handle */ + ivas_lfe_dec_close_fx( &( st_ivas->hLFE ) ); } - return IVAS_ERR_OK; -} -#else -ivas_error mct_dec_reconfigure( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const uint16_t b_nchan_change /* i : flag indicating different channel count */ -) -{ - MCT_DEC_HANDLE hMCT; - Decoder_State *st; - int16_t n, cpe_id, max_blocks; - int32_t cp_bitrate; - - hMCT = st_ivas->hMCT; + IF ( NE_16(st_ivas->mc_mode , MC_MODE_MCMASA) ) + { + IF ( EQ_16(st_ivas->nchan_transport , 1) ) + { + st_ivas->element_mode_init = IVAS_SCE; + } + ELSE + { + st_ivas->element_mode_init = IVAS_CPE_MDCT; + } + } /*-----------------------------------------------------------------* - * Allocate and initialize MCT BlockData handles + * Reconfigure core coder *-----------------------------------------------------------------*/ - if ( b_nchan_change ) + /* special case: MCT->ParamMC with more than 2 TC, CPE 1 stays, but has the wrong mct_chan_mode in channel 1 + and might have IGF static memory not allocated and the bit stream index list not set, + set correct mct_chan_mode and init missing static mem (IGF, HQ) and some config (TNS) do it here since it is _very_ MC specific */ + IF ( EQ_16(last_mc_mode , MC_MODE_MCT) && EQ_16(st_ivas->mc_mode , MC_MODE_PARAMMC) && GT_16(st_ivas->nchan_transport , CPE_CHANNELS) ) { - /* Determine active channels */ - if ( ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMMC ) || st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) + st = st_ivas->hCPE[1]->hCoreCoder[1]; + + IF ( st_ivas->nchan_transport == 3 ) { - hMCT->nchan_out_woLFE = st_ivas->nchan_transport; - if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) - { - hMCT->nchan_out_woLFE += st_ivas->nchan_ism; - } + st->mct_chan_mode = MCT_CHAN_MODE_IGNORE; } - else if ( st_ivas->mc_mode == MC_MODE_MCT ) + ELSE { - hMCT->nchan_out_woLFE = st_ivas->nchan_transport - st_ivas->hTransSetup.num_lfe; + st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; } - else if ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + + IF ( st->hIGFDec == NULL ) { - hMCT->nchan_out_woLFE = st_ivas->nchan_transport - st_ivas->hTransSetup.num_lfe; + IF ( ( st->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for IGF\n" ) ); + } + + st->igf = 0; + init_igf_dec( st->hIGFDec ); +#if 1 /*TODO: To be removed later(floating point initialization)*/ +#if ( defined EVS_FLOAT ) || !( defined IVAS_FLOAT_FIXED ) + st->hIGFDec->virtualSpec_float = &st->hIGFDec->virtualSpecBuf[0]; + st->hIGFDec->igfData.pSpecFlat_float = &st->hIGFDec->igfData.pSpecFlatBuf[0]; + set_f( st->hIGFDec->igfData.pSpecFlatBuf, 0, IGF_START_MX ); +#endif + FOR( Word16 l = 0; l < IGF_START_MX; l++ ) + st->hIGFDec->infoTCXNoiseBuf[l] = (uint8_t) st->hIGFDec->infoTCXNoise_evs[l]; +#endif } - else + + IF ( st->hHQ_core == NULL ) { - assert( !"IVAS format currently not supported for MCT" ); + IF ( ( st->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) ); + } + + /* HQ core initialization */ +#if 1/*TODO: To be removed later*/ + HQ_core_dec_init_flt( st->hHQ_core ); +#endif + HQ_core_dec_init_fx( st->hHQ_core ); } - } - /* indicate LFE for appropriate core-coder channel */ - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) - { - for ( n = 0; n < CPE_CHANNELS; n++ ) + /* check if we have a doubly used hTxcCfg, if so, allocate a distint one for the old MCT LFE channel */ + IF ( st->hTcxCfg == st_ivas->hCPE[1]->hCoreCoder[0]->hTcxCfg ) { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + IF ( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); + } } - } - /* in case we have an uneven number of transport channels, indicate last channel ID as inactive */ - if ( hMCT->nchan_out_woLFE % 2 ) + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( ivas_total_brate, st->igf, st->element_mode ); + } + IF ( EQ_16(st_ivas->mc_mode , MC_MODE_MCMASA) ) { - st_ivas->hCPE[st_ivas->nCPE - 1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + uint8_t separateChannelEnabled; + int16_t separateChannelIndex; + ivas_mcmasa_set_separate_channel_mode_fx( &separateChannelEnabled, &separateChannelIndex, ivas_total_brate ); + ivas_mcmasa_split_brate_fx( separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &new_brate_SCE, &new_brate_CPE ); } - - cp_bitrate = st_ivas->hDecoderConfig->ivas_total_brate / hMCT->nchan_out_woLFE * CPE_CHANNELS; - if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + ELSE IF ( EQ_16(st_ivas->mc_mode , MC_MODE_MCT) ) { - cp_bitrate = st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport * CPE_CHANNELS; + new_brate_SCE = 0; + new_brate_CPE = ( ivas_total_brate / ( st_ivas->nchan_transport - 1 ) ) * CPE_CHANNELS; } - - /* set correct nominal bitrates and igf config already here, otherwise we - * run into a number of problems */ - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + ELSE IF ( EQ_16(st_ivas->mc_mode , MC_MODE_PARAMUPMIX) ) { - st_ivas->hCPE[cpe_id]->element_brate = cp_bitrate; - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st = st_ivas->hCPE[cpe_id]->hCoreCoder[n]; - - st->total_brate = st_ivas->hCPE[cpe_id]->element_brate; - - if ( st->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) - { - st->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[cpe_id]->element_brate / FRAMES_PER_SEC ); - st->igf = getIgfPresent( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->bwidth, st->rf_flag ); - if ( st->igf ) - { - IGFDecSetMode_flt( st->hIGFDec, st_ivas->hCPE[cpe_id]->element_brate, st->bwidth, st->element_mode, -1, -1, st->rf_flag ); - } - } - } + new_brate_SCE = 0; + new_brate_CPE = ( ivas_total_brate / ( st_ivas->nchan_transport - 1 ) ) * CPE_CHANNELS; + } + ELSE + { + new_brate_SCE = 0; /* ivas_total_brate / st_ivas->nchan_transport;*/ + new_brate_CPE = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; } - /*Initialize MCT block data */ - max_blocks = hMCT->nchan_out_woLFE / CPE_CHANNELS; - - for ( n = 0; n < max_blocks; n++ ) + IF( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, new_brate_SCE, new_brate_CPE ) ) != IVAS_ERR_OK ) { - if ( b_nchan_change ) + return error; + } + IF ( EQ_16(last_mc_mode , MC_MODE_MCT) && EQ_16(st_ivas->mc_mode , MC_MODE_PARAMMC) && GT_16(st_ivas->nchan_transport , CPE_CHANNELS) ) + { + st = st_ivas->hCPE[1]->hCoreCoder[1]; + + /* TCX-LTP */ + IF ( st->hTcxLtpDec == NULL ) { - if ( hMCT->hBlockData[n] == NULL ) + IF ( ( st->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) { - if ( ( hMCT->hBlockData[n] = (MCT_DEC_BLOCK_DATA_HANDLE) malloc( sizeof( MCT_BLOCK_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MCT block data structure\n" ) ); - } - - /*Initialize all parameters to zero*/ - hMCT->hBlockData[n]->ch1 = 0; - hMCT->hBlockData[n]->ch2 = 0; - - /* MDCT stereo initialization */ - if ( ( hMCT->hBlockData[n]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n" ) ); } + tcxltp_dec_init_fx( st->hTcxLtpDec, 0, st->last_codec_mode, st->element_mode, st->pit_max, st->sr_core ); } + } - initMdctStereoDecData( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, st_ivas->hCPE[0]->hCoreCoder[0]->bwidth ); - hMCT->hBlockData[n]->hStereoMdct->use_itd = 0; + /*-----------------------------------------------------------------* + * re-configure HP20 memories + *-----------------------------------------------------------------*/ + IF ( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) + { + return error; + } +#if 1/*TODO: To be removed later*/ + /*To be removed later: Contains memory allocations for floating point buffers*/ + IF ( ( error = ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) + { + return error; } +#endif + /*-----------------------------------------------------------------* + * Allocate the LFE handle that is coded separately after the allocation of the core coders + *-----------------------------------------------------------------*/ - for ( ; n < MCT_MAX_BLOCKS; n++ ) + IF ( ( EQ_16(st_ivas->mc_mode , MC_MODE_MCT) || EQ_16(st_ivas->mc_mode , MC_MODE_PARAMUPMIX) ) && st_ivas->hLFE == NULL ) { - /* deallocate no longer needed blocks */ - if ( hMCT->hBlockData[n] != NULL ) + Word32 binauralization_delay_ns = st_ivas->binaural_latency_ns; + IF ( st_ivas->hBinRenderer != NULL ) { - if ( hMCT->hBlockData[n]->hStereoMdct != NULL ) + IF ( st_ivas->hBinRenderer->render_lfe ) { - free( hMCT->hBlockData[n]->hStereoMdct ); - hMCT->hBlockData[n]->hStereoMdct = NULL; + /* Account for filterbank delay */ + binauralization_delay_ns += IVAS_FB_DEC_DELAY_NS; + } + else + { + binauralization_delay_ns = 0; } + } - free( hMCT->hBlockData[n] ); - hMCT->hBlockData[n] = NULL; + IF( ( error = ivas_create_lfe_dec_fx( &st_ivas->hLFE, st_ivas->hDecoderConfig->output_Fs, binauralization_delay_ns ) ) != IVAS_ERR_OK ) + { + return error; } + + set32_fx( st_ivas->hLFE->prevsynth_buf_fx, 0, LFE_PLC_BUFLEN ); + set32_fx( st_ivas->hLFE->prior_out_buffer_fx, 0, L_FRAME48k ); } /*-----------------------------------------------------------------* - * Initializations + * Reconfigure renderers *-----------------------------------------------------------------*/ - if ( b_nchan_change ) + IF ( EQ_16(st_ivas->mc_mode , MC_MODE_MCMASA) ) { - hMCT->currBlockDataCnt = 0; - - /*Initialize bits required to signal channel-pair index*/ - hMCT->bitsChannelPairIndex = max( 1, (int16_t) ( floorf( ( logf( (float) hMCT->nchan_out_woLFE * ( hMCT->nchan_out_woLFE - 1 ) / 2 - 1 ) * INV_LOG_2 ) ) + 1 ) ); - - set_s( hMCT->chBitRatios, 0, MCT_MAX_CHANNELS ); - set_s( hMCT->lowE_ch, 0, MCT_MAX_CHANNELS ); + IF ( ( NE_16(st_ivas->renderer_type , RENDERER_DISABLE) ) && ( NE_16(st_ivas->renderer_type , RENDERER_MCMASA_MONO_STEREO) ) ) + { + IF ( st_ivas->hDirAC != NULL ) + { + /* reconfigure existing DirAC dec */ + IF ( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE + { + /* init a new DirAC dec */ + IF ( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + ELSE IF ( EQ_16(st_ivas->renderer_type , RENDERER_DISABLE) && st_ivas->hDirAC != NULL ) + { + ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) ); + ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) ); + ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) ); + vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); + } } - return IVAS_ERR_OK; -} -#endif - - -/*------------------------------------------------------------------------- - * create_mct_dec_close() - * - * Close IVAS decoder MCT handle - *-------------------------------------------------------------------------*/ - -void ivas_mct_dec_close( - MCT_DEC_HANDLE *hMCT /* i/o: MCT decoder structure */ -) -#ifdef IVAS_FLOAT_FIXED -{ - Word16 n, maxBlocks; - - IF ( hMCT == NULL || *hMCT == NULL ) + IF ( NE_16(renderer_type_old , st_ivas->renderer_type) ) { - return; - } + AUDIO_CONFIG output_config; - maxBlocks = shr( ( *hMCT )->nchan_out_woLFE, 1 ); + output_config = st_ivas->hDecoderConfig->output_config; - FOR ( n = 0; n < maxBlocks; n++ ) - { - IF ( ( *hMCT )->hBlockData[n] != NULL ) + /* binaural renderers*/ + IF ( EQ_16(output_config , IVAS_AUDIO_CONFIG_BINAURAL) || EQ_16(output_config , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR) || EQ_16(output_config , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB) ) { - IF ( ( *hMCT )->hBlockData[n]->hStereoMdct != NULL ) + /* remove unneeded binaural renderers */ + IF ( st_ivas->hBinRenderer != NULL && ( NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_FASTCONV) && NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_FASTCONV_ROOM) ) ) { - free( ( *hMCT )->hBlockData[n]->hStereoMdct ); - ( *hMCT )->hBlockData[n]->hStereoMdct = NULL; + ivas_binRenderer_close( &st_ivas->hBinRenderer ); } - free( ( *hMCT )->hBlockData[n] ); - ( *hMCT )->hBlockData[n] = NULL; - } - } - - free( *hMCT ); - *hMCT = NULL; + IF ( ( st_ivas->hCrendWrapper != NULL ) && ( st_ivas->hCrendWrapper->hCrend != NULL ) && ( NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_MIXER_CONV) && NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_MIXER_CONV_ROOM) && ( NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_OBJECTS_TD) || NE_16(st_ivas->hIntSetup.output_config , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB) ) ) ) + { - return; -} -#else -{ - Word16 n, maxBlocks; + ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) ); + } - IF ( hMCT == NULL || *hMCT == NULL ) - { - return; - } + IF ( st_ivas->hBinRendererTd != NULL && ( NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_OBJECTS_TD) ) ) + { + ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); + st_ivas->hHrtfTD = NULL; + } - maxBlocks = ( *hMCT )->nchan_out_woLFE / 2; + IF ( st_ivas->hDiracDecBin != NULL ) + { + IF ( NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_PARAMETRIC) && NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_PARAMETRIC_ROOM) && NE_16(st_ivas->renderer_type , RENDERER_STEREO_PARAMETRIC) ) + { + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); + } + } - FOR ( n = 0; n < maxBlocks; n++ ) - { - IF ( ( *hMCT )->hBlockData[n] != NULL ) - { - IF ( ( *hMCT )->hBlockData[n]->hStereoMdct != NULL ) + /* init necessary new renderers */ + IF ( st_ivas->hBinRenderer == NULL && ( EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_FASTCONV) || EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_FASTCONV_ROOM) ) ) { - free( ( *hMCT )->hBlockData[n]->hStereoMdct ); - ( *hMCT )->hBlockData[n]->hStereoMdct = NULL; + IF ( ( error = ivas_binRenderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } + ELSE IF ( st_ivas->hBinRendererTd == NULL && EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_OBJECTS_TD) ) + { + IF( ( error = ivas_td_binaural_open_fx( st_ivas, st_ivas->hBinRendererTd->SrcInd, &st_ivas->hBinRendererTd->num_src ) ) != IVAS_ERR_OK ) + { + return error; + } + IF ( EQ_16(st_ivas->hIntSetup.output_config , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB) ) + { + IF ( ( error = ivas_rend_initCrendWrapper( &st_ivas->hCrendWrapper ) ) != IVAS_ERR_OK ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Wrapper\n" ); + } - free( ( *hMCT )->hBlockData[n] ); - ( *hMCT )->hBlockData[n] = NULL; + st_ivas->hCrendWrapper->hCrend = NULL; + st_ivas->hCrendWrapper->hHrtfCrend = NULL; + IF ( ( st_ivas->hCrendWrapper->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend\n" ); + } + } + } + ELSE IF ( st_ivas->hCrendWrapper == NULL && ( EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_MIXER_CONV) || EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_MIXER_CONV_ROOM) ) ) + { + IF ( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hDecoderConfig->output_config, st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns; + } + } + /* mono/stereo */ + ELSE IF ( EQ_16(output_config , IVAS_AUDIO_CONFIG_MONO) || EQ_16(output_config , IVAS_AUDIO_CONFIG_STEREO) ) + { + /* nothing should happen here... */ + } + /* LS */ + ELSE IF ( EQ_16(output_config , IVAS_AUDIO_CONFIG_5_1) || EQ_16(output_config , IVAS_AUDIO_CONFIG_5_1_2) || EQ_16(output_config , IVAS_AUDIO_CONFIG_5_1_4) || EQ_16(output_config , IVAS_AUDIO_CONFIG_7_1) || EQ_16(output_config , IVAS_AUDIO_CONFIG_7_1_4) || EQ_16(output_config , IVAS_AUDIO_CONFIG_LS_CUSTOM) ) + { } } + /*-----------------------------------------------------------------* + * CLDFB instances + *-----------------------------------------------------------------*/ - free( *hMCT ); - *hMCT = NULL; - - return; -} -#endif - - -/*------------------------------------------------------------------------- - * ivas_mc_dec_config() - * - * - read transported MC LS setup - * - select MC format mode - * - reconfigure the MC format decoder - *-------------------------------------------------------------------------*/ - -/*! r : MC format mode */ -ivas_error ivas_mc_dec_config( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const int16_t idx, /* i : LS config. index */ - uint16_t *nSamplesRendered, /* o : samples flushed from last frame (JBM) */ - int16_t *data /* o : output synthesis signal */ -) -{ - AUDIO_CONFIG signaled_config; - MC_MODE last_mc_mode; - ivas_error error; + IF ( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ,Q11) ) != IVAS_ERR_OK ) + { + return error; + } - /* store last frame MC mode */ - last_mc_mode = st_ivas->mc_mode; + /*-----------------------------------------------------------------* + * JBM TC buffers + *-----------------------------------------------------------------*/ - if ( !st_ivas->bfi ) { - /* set transported MC LS setup */ - signaled_config = ivas_mc_map_ls_setup_to_output_config( idx ); + Word16 tc_nchan_full_new; + DECODER_TC_BUFFER_HANDLE hTcBuffer; - if ( st_ivas->ini_frame == 0 ) + hTcBuffer = st_ivas->hTcBuffer; + tc_buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas ); + tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); + tc_nchan_allocate_new = tc_nchan_tc_new; + tc_nchan_full_new = tc_nchan_tc_new; + + IF ( EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_PARAMETRIC) || EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_PARAMETRIC_ROOM) || EQ_16(st_ivas->renderer_type , RENDERER_STEREO_PARAMETRIC) ) { - st_ivas->transport_config = signaled_config; + tc_nchan_allocate_new = 2 * BINAURAL_CHANNELS; + tc_nchan_full_new = tc_nchan_allocate_new; } - /* select MC format mode */ - st_ivas->mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( signaled_config ), st_ivas->hDecoderConfig->ivas_total_brate ); - - /* MC format switching */ - if ( st_ivas->ini_frame != 0 ) + IF ( EQ_16(st_ivas->mc_mode , MC_MODE_PARAMMC) && NE_16(st_ivas->hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_MONO) && NE_16(st_ivas->hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_STEREO) ) { - if ( st_ivas->hDecoderConfig->last_ivas_total_brate != st_ivas->hDecoderConfig->ivas_total_brate || st_ivas->transport_config != signaled_config || last_mc_mode != st_ivas->mc_mode ) + tc_nchan_full_new = 0; + } + ELSE IF ( EQ_16(st_ivas->mc_mode , MC_MODE_PARAMUPMIX) ) + { + tc_nchan_allocate_new = MC_PARAMUPMIX_MAX_INPUT_CHANS; + tc_buffer_mode_new = TC_BUFFER_MODE_RENDERER; + IF ( EQ_16(st_ivas->hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_STEREO) || EQ_16(st_ivas->hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_MONO) ) { - if ( ( error = ivas_mc_dec_reconfig( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) - - { - return error; - } + tc_buffer_mode_new = TC_BUFFER_MODE_BUFFER; + tc_nchan_tc_new = st_ivas->hDecoderConfig->nchan_out; + tc_nchan_allocate_new = tc_nchan_tc_new; } + tc_nchan_full_new = tc_nchan_allocate_new; } - st_ivas->transport_config = signaled_config; + /* reconfigure buffer */ + IF ( NE_16(hTcBuffer->tc_buffer_mode , tc_buffer_mode_new) || NE_16(hTcBuffer->nchan_transport_jbm , tc_nchan_tc_new) || + NE_16(hTcBuffer->nchan_buffer_full , tc_nchan_full_new) || NE_16(hTcBuffer->nchan_transport_internal , tc_nchan_allocate_new) || + NE_16(tc_granularity_new , hTcBuffer->n_samples_granularity) ) + { + IF ( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ) != IVAS_ERR_OK ) + { + return error; + } + } + /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ + IF ( st_ivas->hSpatParamRendCom != NULL ) + { + st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; + st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + } + ELSE IF ( st_ivas->hParamMC != NULL ) + { + st_ivas->hParamMC->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + st_ivas->hParamMC->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + st_ivas->hParamMC->num_slots = st_ivas->hTcBuffer->num_slots; + st_ivas->hParamMC->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hParamMC->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + } } - return IVAS_ERR_OK; -} + /*-----------------------------------------------------------------* + * floating-point output audio buffers + *-----------------------------------------------------------------*/ -/*------------------------------------------------------------------------- - * ivas_mc_dec_reconfig() - * - * reconfigure the MC format decoder - *-------------------------------------------------------------------------*/ + nchan_out_buff = ivas_get_nchan_buffers_dec_ivas_fx( st_ivas, -1, -1 ); + + IF( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + { + return error; + } +#if 1/*TODO: To be removed later*/ + if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif + return error; +} +#else static ivas_error ivas_mc_dec_reconfig( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -3046,3 +3455,4 @@ static ivas_error ivas_mc_dec_reconfig( return error; } +#endif // IVAS_FLOAT_FIXED diff --git a/lib_dec/ivas_sba_rendering_internal.c b/lib_dec/ivas_sba_rendering_internal.c index 3829a9213..ec9da41ac 100644 --- a/lib_dec/ivas_sba_rendering_internal.c +++ b/lib_dec/ivas_sba_rendering_internal.c @@ -903,6 +903,8 @@ void ivas_sba_mix_matrix_determiner_fx( } #endif // IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED + void ivas_sba_mix_matrix_determiner( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ float *output[], /* i/o: transport/output audio channels */ @@ -1092,4 +1094,60 @@ void ivas_sba_mix_matrix_determiner( return; } +#else + +void ivas_sba_mix_matrix_determiner( + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + float *output[], /* i/o: transport/output audio channels */ + const int16_t bfi, /* i : BFI flag */ + const int16_t nchan_remapped, /* i : num channels after remapping of TCs */ + const int16_t output_frame, /* i : output frame length */ + const int16_t num_md_sub_frames /* i : number of subframes in mixing matrix*/ +) +{ + int16_t i, ch; + float temp; + int16_t num_bands_out, nchan_transport, nchan_out; + + /* Convert numeric range */ + for (ch = 0; ch < nchan_remapped; ch++) + { + for (i = 0; i < output_frame; i++) + { + temp = output[ch][i]; + temp = floorf(temp + 0.5f); + + if (temp > MAX16B_FLT) + { + temp = MAX16B_FLT; + } + else if (temp < (-1.0f * PCM16_TO_FLT_FAC)) + { + temp = (-1.0f * PCM16_TO_FLT_FAC); + } + temp *= (1.0f / PCM16_TO_FLT_FAC); + output[ch][i] = temp; + } + } + + /* 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 (i = 0; i < output_frame; i++) + { + output[ch][i] = output[ch][i] * PCM16_TO_FLT_FAC; + } + } + + /* Mixing matrix determiner */ + num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; + ivas_spar_dec_gen_umx_mat(hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames); + return; +} +#endif diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 2bd011811..695c72ec4 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -1208,7 +1208,7 @@ static void ivas_dec_mono_sba_handling( * * SPAR Meta Data decoder process *-----------------------------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void ivas_spar_md_dec_process( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling */ @@ -1360,7 +1360,127 @@ void ivas_spar_md_dec_process( return; } +#else +void ivas_spar_md_dec_process( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling */ + const int16_t num_bands_out, /* i : number of output bands */ + const int16_t sba_order /* i : Ambisonic (SBA) order */ +) +{ + int16_t j, k, b, bw, dtx_vad, nB, i_ts; + ivas_spar_md_dec_state_t *hMdDec; + int16_t num_md_chs; + int16_t num_md_sub_frames; + int16_t dyn_active_w_flag; + int16_t active_w_vlbr; + + hMdDec = st_ivas->hSpar->hMdDec; + + active_w_vlbr = (st_ivas->hDecoderConfig->ivas_total_brate < IVAS_24k4) ? 1 : 0; + + num_md_chs = ivas_sba_get_nchan_metadata(sba_order, st_ivas->hDecoderConfig->ivas_total_brate); + + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes(sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate); + + if (hMdDec->spar_md_cfg.nchan_transport > 1 && hMdDec->spar_md_cfg.nchan_transport <= 3) + { + hMdDec->spar_md.res_ind = 0; + dyn_active_w_flag = get_next_indice(st0, 1); + if (dyn_active_w_flag == 1) + { + if (hMdDec->spar_md_cfg.nchan_transport == 2) + { + hMdDec->spar_md.res_ind = get_next_indice(st0, 1); + hMdDec->spar_md.res_ind += hMdDec->spar_md_cfg.nchan_transport; + } + else if (hMdDec->spar_md_cfg.nchan_transport == 3) + { + hMdDec->spar_md.res_ind = remix_order_set[hMdDec->spar_md_cfg.remix_unmix_order][hMdDec->spar_md_cfg.nchan_transport]; + } + } + } + else + { + dyn_active_w_flag = 0; + if (hMdDec->spar_md_cfg.nchan_transport == FOA_CHANNELS) + { + get_next_indice(st0, 1); + } + } + + ivas_spar_dec_parse_md_bs(hMdDec, st0, &nB, &bw, &dtx_vad, st_ivas->hDecoderConfig->ivas_total_brate, + st_ivas->hQMetaData->sba_inactive_mode + ); + assert(nB == hMdDec->spar_md.num_bands); + assert(bw == 1); + ivas_spar_md_fill_invalid_bandcoeffs( + hMdDec->spar_md.band_coeffs, + hMdDec->band_coeffs_prev, + &hMdDec->valid_bands[0], + &hMdDec->base_band_coeffs_age[0], + &hMdDec->first_valid_frame, + nB); + + ivas_dec_mono_sba_handling(st_ivas); + + /* SPAR to DirAC conversion */ + if (hMdDec->spar_hoa_dirac2spar_md_flag == 1) + { + ivas_spar_to_dirac(st_ivas, hMdDec, dtx_vad, num_bands_out, bw, dyn_active_w_flag); + } + + /* set correct number of bands*/ + nB = IVAS_MAX_NUM_BANDS; + + /* expand DirAC MD to all time slots */ + for (i_ts = 1; i_ts < num_md_sub_frames; i_ts++) + { + for (b = 0; b < hMdDec->spar_md.num_bands; b++) + { + for (j = 0; j < IVAS_SPAR_MAX_CH - 1; j++) + { + hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[j] = hMdDec->spar_md.band_coeffs[b].pred_re[j]; + } + + for (j = 0; j < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; j++) + { + for (k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++) + { + hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re[j][k] = hMdDec->spar_md.band_coeffs[b].C_re[j][k]; + } + } + + for (j = 0; j < IVAS_SPAR_MAX_CH - 1; j++) + { + hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re[j] = hMdDec->spar_md.band_coeffs[b].P_re[j]; + } + } + } + + ivas_get_spar_matrices(hMdDec, num_bands_out, num_md_sub_frames, bw, dtx_vad, nB, num_md_chs, active_w_vlbr, dyn_active_w_flag); + +#ifdef DEBUG_SPAR_DIRAC_WRITE_OUT_PRED_PARS + { + static FILE *fid = 0; + int16_t band = 9; + if (!fid) + { + fid = fopen("pred_coeffs_dec.txt", "wt"); + } + fprintf(fid, "%.6f\n", hMdDec->mixer_mat[1][0][band]); + } +#endif + ivas_spar_md_fill_invalid_bands(&hMdDec->spar_coeffs, &hMdDec->spar_coeffs_prev, &hMdDec->valid_bands[0], &hMdDec->base_band_age[0], num_bands_out, num_md_chs, num_md_sub_frames); + + + hMdDec->dtx_md_smoothing_cntr = 1; + + return; +} + +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_spar_chk_zero_coefs() * diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index d930ea19a..c427203d2 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -3346,7 +3346,7 @@ void swb_tbe_dec( else { /* individual sqrt to avoid infinite (nan) value due to acelp_core_dec changes */ - scale = (float) (sqrt( curr_pow ) /sqrt( prev_pow )); + scale = (float)sqrt(curr_pow / prev_pow); } for ( i = 0; i < L_SHB_LAHEAD; i++ ) @@ -4744,12 +4744,13 @@ void TBEreset_dec( * * Initialize TD BWE state structure at the decoder *-------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void td_bwe_dec_init( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ const int16_t extl, /* i : BWE extension layer */ const int32_t output_Fs /* i : output sampling rate */ ) + { int16_t i; @@ -4885,4 +4886,78 @@ void td_bwe_dec_init( #endif return; -} \ No newline at end of file +} + +#else + +void td_bwe_dec_init( + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + const int16_t extl, /* i : BWE extension layer */ + const int32_t output_Fs /* i : output sampling rate */ +) +{ + int16_t i; + + /* init. SHB buffers */; + set_f(hBWE_TD->old_bwe_exc, 0.0f, (PIT16k_MAX * 2)); + hBWE_TD->bwe_seed[0] = 23; /* 1; */ + hBWE_TD->bwe_seed[1] = 59; /* 10000; */ + set_f(hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET); + hBWE_TD->bwe_non_lin_prev_scale = 0; + + set_f(hBWE_TD->genSHBsynth_Hilbert_Mem, 0.0f, HILBERT_MEM_SIZE); + set_f(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 0.0f, 2 * ALLPASSSECTIONS_STEEP); + + hBWE_TD->syn_dm_phase = 0; + hBWE_TD->prev_fbbwe_ratio = 1.0f; + hBWE_TD->prev_wb_bwe_frame_pow = 0.001f; + hBWE_TD->prev_swb_bwe_frame_pow = 0.001f; + + /* reset SHB buffers */ + ResetSHBbuffer_Dec(hBWE_TD, extl); + + if (output_Fs == 48000) + { + set_f(hBWE_TD->fbbwe_hpf_mem[0], 0, 4); + set_f(hBWE_TD->fbbwe_hpf_mem[1], 0, 4); + set_f(hBWE_TD->fbbwe_hpf_mem[2], 0, 4); + set_f(hBWE_TD->fbbwe_hpf_mem[3], 0, 4); + } + + set_f(hBWE_TD->mem_resamp_HB, 0, INTERP_3_1_MEM_LEN); + set_f(hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1); + + hBWE_TD->tilt_mem = 0.0f; + set_f(hBWE_TD->prev_lsf_diff, 0.5f, LPC_SHB_ORDER - 2); + hBWE_TD->prev_tilt_para = 0.0f; + set_f(hBWE_TD->cur_sub_Aq, 0.0f, M + 1); + set_f(hBWE_TD->int_3_over_2_tbemem_dec, 0.0f, INTERP_3_2_MEM_LEN); + + /* TD BWE post-processing */ + hBWE_TD->ptr_mem_stp_swb = hBWE_TD->mem_stp_swb + LPC_SHB_ORDER - 1; + set_f(hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER); + + for (i = 0; i < LPC_SHB_ORDER; i++) + { + hBWE_TD->swb_lsp_prev_interp[i] = (float)cos((float)i * EVS_PI / (float) 10.0f); + } + + hBWE_TD->prev1_shb_ener_sf = 1.0f; + hBWE_TD->prev2_shb_ener_sf = 1.0f; + hBWE_TD->prev3_shb_ener_sf = 1.0f; + hBWE_TD->prev_res_shb_gshape = 0.125f; + hBWE_TD->prev_mixFactors = 0.5f; + hBWE_TD->prev_GainShape = 0.0f; + set_f(hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER); + hBWE_TD->fb_tbe_demph = 0.0f; + + set_f(hBWE_TD->old_hb_synth, 0, L_FRAME48k); + + hBWE_TD->GainFrame_prevfrm = 0.0f; + + hBWE_TD->prev_ener = 0.0f; + + return; +} + +#endif \ No newline at end of file diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index ef7b6f36a..9dec7e9d4 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -2960,6 +2960,12 @@ void ivas_rend_closeCrend( hCrend->lfe_delay_line = NULL; } + if ( hCrend->lfe_delay_line_fx != NULL ) + { + free( hCrend->lfe_delay_line_fx); + hCrend->lfe_delay_line_fx = NULL; + } + if ( hCrend->freq_buffer_re_diffuse != NULL ) { free( hCrend->freq_buffer_re_diffuse ); diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index f8e577f69..2ff4360b9 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1806,6 +1806,8 @@ typedef struct ivas_binaural_td_rendering_struct TDREND_SRC_t *Sources[MAX_NUM_TDREND_CHANNELS]; #ifdef IVAS_FLOAT_FIXED + Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; + Word16 num_src; Word16 Gain_fx; /* Q14 */ #endif // IVAS_FLOAT_FIXED -- GitLab From 34c3758855007534bea5d2db6345b89fe5bd1743 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 29 Apr 2024 13:41:15 +0530 Subject: [PATCH 2/2] revert mc_dec_reconfig changes and ivas_sba_linear_renderer integration --- lib_com/ivas_prot.h | 10 - lib_dec/ivas_corecoder_dec_reconfig.c | 4 +- lib_dec/ivas_jbm_dec.c | 21 +- lib_dec/ivas_mc_param_dec.c | 698 +-------------------- lib_dec/ivas_mct_dec.c | 839 +------------------------- lib_dec/ivas_stereo_dft_dec.c | 129 ++++ lib_rend/ivas_crend.c | 6 - lib_rend/ivas_stat_rend.h | 2 - 8 files changed, 174 insertions(+), 1535 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 7bf923004..ddaddc3e1 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4630,11 +4630,6 @@ void ivas_param_mc_enc( float *data_f[], /* i/o: input/transport MC data */ const int16_t input_frame /* i : input frame length */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_param_mc_dec_open_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -); -#endif // IVAS_FLOAT_FIXED ivas_error ivas_param_mc_dec_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ @@ -4649,11 +4644,6 @@ ivas_error ivas_param_mc_dec_reconfig_fx( ivas_error ivas_param_mc_dec_reconfig( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_param_mc_dec_close_fx( - PARAM_MC_DEC_HANDLE *hParamMC_out /* i/o: Parametric MC decoder handle */ -); -#endif // IVAS_FLOAT_FIXED void ivas_param_mc_dec_close( PARAM_MC_DEC_HANDLE *hParamMC /* i/o: Parametric MC decoder handle */ diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index c916a9dd9..67f65d1af 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -974,7 +974,7 @@ ivas_error ivas_cldfb_dec_reconfig_fx( /* resample CLDFB analysis instances */ FOR( i = 0; i < min( numCldfbAnalyses, numCldfbAnalyses_old ); i++ ) { - IF( NE_32( L_mult0( extract_l(L_mult0( st_ivas->cldfbAnaDec[i]->no_channels, st_ivas->cldfbAnaDec[i]->no_col )), FRAMES_PER_SEC ), hDecoderConfig->output_Fs ) ) + IF( EQ_32( L_mult0( extract_l(L_mult0( st_ivas->cldfbAnaDec[i]->no_channels, st_ivas->cldfbAnaDec[i]->no_col )), FRAMES_PER_SEC ), hDecoderConfig->output_Fs ) ) { resampleCldfb_ivas_fx( st_ivas->cldfbAnaDec[i], hDecoderConfig->output_Fs ); } @@ -1027,7 +1027,7 @@ ivas_error ivas_cldfb_dec_reconfig_fx( FOR( i = 0; i < st_ivas->cldfbAnaDec[0]->cldfb_state_length; i++ ) st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i], 16 ); // Scaling down from 27 to 11 FOR( i = 0; i < st_ivas->cldfbSynDec[0]->cldfb_state_length; i++ ) - st_ivas->cldfbSynDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbSynDec[0]->cldfb_state_fx[i], 21- 11); // Scaling down from 21 to 11 + st_ivas->cldfbSynDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbSynDec[0]->cldfb_state_fx[i], 21- Q_cldfbSynDec); // Scaling down from 21 to Q_cldfbSynDec } return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 3b06fadda..32aa6f4a4 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -3298,6 +3298,7 @@ ivas_error ivas_jbm_dec_tc( st_ivas->hCPE[0]->element_brate = ivas_total_brate; } + /* core-decoding of transport channels */ if ( st_ivas->nSCE == 1 ) { @@ -5772,11 +5773,29 @@ ivas_error ivas_jbm_dec_render( { mvr2r( st_ivas->hTcBuffer->tc[n] + st_ivas->hTcBuffer->n_samples_rendered, p_output[n], *nSamplesRendered ); } - +#ifdef IVAS_FLOAT_FIXED +#if 1//To Be removed + for ( n = 0; n < st_ivas->p_out_len; n++ ) + { + floatToFixed_arr32( p_output[n], p_output_fx[n], Q11, 960 ); + } +#endif + IF ( ( error = ivas_sba_linear_renderer_fx( p_output_fx, *nSamplesRendered, nchan_remapped, 0, output_config, st_ivas->hOutSetup ) ) != IVAS_ERR_OK ) + { + return error; + } +#if 1//To Be removed + for ( n = 0; n < st_ivas->p_out_len; n++ ) + { + fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); + } +#endif +#else if ( ( error = ivas_sba_linear_renderer( p_output, *nSamplesRendered, nchan_remapped, 0, output_config, st_ivas->hOutSetup ) ) != IVAS_ERR_OK ) { return error; } +#endif } else if ( st_ivas->renderer_type == RENDERER_DIRAC ) { diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 4b28d4b99..09d03335f 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -79,7 +79,6 @@ typedef struct parameter_band_mapping_struct *-----------------------------------------------------------------------*/ 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_fx( PARAM_MC_DEC_HANDLE hParamMC, const Word16 nchan_in, const Word16 nchan_out ); static void param_mc_protoSignalComputation( float *RealBuffer, float *ImagBuffer, float *proto_frame_f, const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, const int16_t num_freq_bands ); #ifdef IVAS_FLOAT_FIXED @@ -132,7 +131,7 @@ static void ivas_param_mc_bs_decode_parameter_values( uint16_t bit_buffer[], int #ifdef IVAS_FLOAT_FIXED static void ivas_param_mc_bs_decode_parameter_values_fx(UWord16 bit_buffer[], Word16 *bit_pos, const Word16 max_bits, Word16 *BER_detect, HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC, HANDLE_PARAM_MC_PARAMETER_CODING_INFO hParamCodingInfo, const Word16 map_size_wo_lfe, const Word16 map_size, const Word16 num_lfe_bands, const Word16 band_step, const Word16 num_param_bands, Word16 *value_buffer); static void ivas_param_mc_dequantize_cov_fx(PARAM_MC_DEC_HANDLE hParamMC, Word16 *ild_q_fx, Word16 *icc_q_fx, const Word16 param_band_index, const Word16 nY_cov, const PARAM_MC_SYNTHESIS_CONF synth_conf, const Word16 nY_int, const Word16 nX, Word32 *Cx_state_fx, Word16 Cx_state_e, Word32 *Cproto_fx, Word16 Cproto_e, Word32 *Cy_state_fx, Word16 *Cy_state_e); -static ivas_error param_mc_get_diff_proto_info_fx(const Word32 *proto_mtx, const UWord16 nchan_transport, const UWord16 nchan_out_cov, PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info, Word16 Q_proto_mtx); +static ivas_error param_mc_get_diff_proto_info_fx(const Word32 *proto_mtx, const UWord16 nchan_transport, const UWord16 nchan_out_cov, PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info); static void param_mc_update_mixing_matrices_fx( PARAM_MC_DEC_HANDLE hParamMC, Word32 *mixing_matrix[], Word16 *mixing_matrix_fx, Word32 *mixing_matrix_res[], Word16 *mixing_matrix_res_exp, const UWord16 nX, const UWord16 nY ); #endif @@ -141,452 +140,7 @@ static void param_mc_update_mixing_matrices_fx( PARAM_MC_DEC_HANDLE hParamMC, Wo * * Open Parametric MC decoder handle *-------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_param_mc_dec_open_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -) -{ - Word16 k, nchan_transport; - PARAM_MC_DEC_HANDLE hParamMC; -#ifndef FIX_901_PARAMMC_DEAD_CODE - IVAS_OUTPUT_SETUP hTransportSetup; -#endif - Word16 nchan_out_transport; - Word16 nchan_out_cov; - Word32 proto_matrix_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; - Word32 proto_mtx_norm_fx; - Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX]; - Word16 max_param_band_residual; - UWord16 config_index; - MC_LS_SETUP mc_ls_setup; - AUDIO_CONFIG output_config; - Word32 output_Fs, ivas_total_brate; - ivas_error error; - - error = IVAS_ERR_OK; - - /*-----------------------------------------------------------------* - * prepare library opening - *-----------------------------------------------------------------*/ - - if ( ( hParamMC = (PARAM_MC_DEC_HANDLE) malloc( sizeof( PARAM_MC_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); - } - - if ( ( hParamMC->hMetadataPMC = (HANDLE_IVAS_PARAM_MC_METADATA) malloc( sizeof( IVAS_PARAM_MC_METADATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC metadata \n" ) ); - } - - output_Fs = st_ivas->hDecoderConfig->output_Fs; - output_config = st_ivas->hDecoderConfig->output_config; - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; -#ifndef FIX_901_PARAMMC_DEAD_CODE - hTransportSetup = st_ivas->hTransSetup; -#endif - mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); - nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; - hParamMC->hoa_encoder_fx = NULL; -#if 1/*TODO: To be removed later(floating pointer initialization)*/ - hParamMC->hoa_encoder = NULL; -#endif - - /* determine the synthesis config */ - if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD || st_ivas->transport_config == output_config ) - { - hParamMC->synthesis_conf = PARAM_MC_SYNTH_DIRECT; - } - else if ( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) - { - hParamMC->synthesis_conf = PARAM_MC_SYNTH_MONO_STEREO; - } - else if ( st_ivas->transport_config != output_config ) - { - if ( ( output_config != IVAS_AUDIO_CONFIG_LS_CUSTOM && nchan_out_transport > audioCfg2channels( output_config ) ) || ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && nchan_out_transport > st_ivas->hOutSetup.nchan_out_woLFE ) ) - { - hParamMC->synthesis_conf = PARAM_MC_SYNTH_LS_CONV_COV; - /* need to reset the intern config */ - st_ivas->intern_config = output_config; - ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); - if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) - { - st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->hLsSetupCustom->num_spk; -#if 1/*TODO: To be removed later*/ - st_ivas->hIntSetup.ls_azimuth = st_ivas->hLsSetupCustom->ls_azimuth; - st_ivas->hIntSetup.ls_elevation = st_ivas->hLsSetupCustom->ls_elevation; -#endif - st_ivas->hIntSetup.ls_azimuth_fx = st_ivas->hLsSetupCustom->ls_azimuth_fx; - st_ivas->hIntSetup.ls_elevation_fx = st_ivas->hLsSetupCustom->ls_elevation_fx; - } - } - else - { - hParamMC->synthesis_conf = PARAM_MC_SYNTH_LS_CONV_CLDFB; - } - } - -#if 1/*TODO: To be removed later*/ - hParamMC->ls_conv_dmx_matrix = NULL; -#endif - hParamMC->ls_conv_dmx_matrix_fx = NULL; - - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) - { - nchan_out_cov = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; - } - else - { - nchan_out_cov = nchan_out_transport; - } - - st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_ls_setup ); - config_index = ivas_param_mc_get_configuration_index( mc_ls_setup, ivas_total_brate ); - nchan_transport = st_ivas->nchan_transport; - - switch ( nchan_transport ) - { - case 4: - case 3: - st_ivas->nCPE = 2; - st_ivas->nSCE = 0; - st_ivas->element_mode_init = IVAS_CPE_MDCT; - break; - case 2: - st_ivas->nCPE = 1; - st_ivas->nSCE = 0; - st_ivas->element_mode_init = IVAS_CPE_MDCT; - - break; - } - - /*-----------------------------------------------------------------* - * set input parameters - *-----------------------------------------------------------------*/ - - hParamMC->slot_size = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX; - set_s( hParamMC->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); - set_s( hParamMC->subframe_nbslots, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); - hParamMC->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; - - hParamMC->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); - hParamMC->max_band_energy_compensation = hParamMC->num_freq_bands; -#ifndef FIX_901_PARAMMC_DEAD_CODE - ivas_param_mc_metadata_open( mc_ls_setup, hTransportSetup.index_lfe[0], ivas_total_brate, hParamMC->hMetadataPMC ); -#else - ivas_param_mc_metadata_open( mc_ls_setup, ivas_total_brate, hParamMC->hMetadataPMC ); -#endif - - /* init arrays for quantized parameters */ - - if ( ( hParamMC->icc_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( Word16 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); - } - if ( ( hParamMC->icld_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( Word16 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); - } - set16_fx( hParamMC->icld_q_fx, PARAM_MC_DEFAULT_MIN_ILD_FX, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); - set16_fx( hParamMC->icc_q_fx, 0, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); - -#if 1/*TODO: To be removed later(floating point initialization)*/ - if ( ( hParamMC->icc_q = (float *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); - } - if ( ( hParamMC->icld_q = (float *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); - } -#endif - - param_mc_set_num_synth_bands( output_Fs, hParamMC ); - - /* Band Grouping */ - if ( hParamMC->hMetadataPMC->num_parameter_bands == 20 ) - { - mvs2s( param_mc_band_grouping_20, hParamMC->band_grouping, 20 + 1 ); - } - else if ( hParamMC->hMetadataPMC->num_parameter_bands == 14 ) - { - mvs2s( param_mc_band_grouping_14, hParamMC->band_grouping, 14 + 1 ); - } - else if ( hParamMC->hMetadataPMC->num_parameter_bands == 10 ) - { - mvs2s( param_mc_band_grouping_10, hParamMC->band_grouping, 10 + 1 ); - } - else - { - assert( 0 && "nbands must be 20, 14, or 10!" ); - } - - /* set max parameter band for abs cov */ - k = 0; - while ( hParamMC->band_grouping[k] <= PARAM_MC_MAX_BAND_ABS_COV_DEC ) - { - hParamMC->max_param_band_abs_cov = ( k++ ); - } - - /*-----------------------------------------------------------------* - * open sub-modules - *-----------------------------------------------------------------*/ - - /* prototype signal computation */ - - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_CLDFB || hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) - { - if ( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - - /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */ - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) - { -#if 1/*TODO: To be removed later (floating point malloc)*/ - if ( ( hParamMC->ls_conv_dmx_matrix = (float *) malloc( nchan_out_transport * nchan_out_cov * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); - } -#endif - IF( ( hParamMC->ls_conv_dmx_matrix_fx = (Word32 *) malloc( nchan_out_transport * nchan_out_cov * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); - } - - for ( k = 0; k < nchan_out_transport; k++ ) - { - Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov], nchan_out_cov );/*Q30*/ - } - - /* convert ParamMC parameter bands to SFB */ - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) - { - st_ivas->hLsSetUpConversion->sfbCnt = hParamMC->num_param_bands_synth; - for ( k = 0; k <= hParamMC->num_param_bands_synth; k++ ) - { - st_ivas->hLsSetUpConversion->sfbOffset[k] = PARAM_MC_BAND_TO_MDCT_BAND_RATIO * hParamMC->band_grouping[k]; - } - } - else - { - /* close the ls conversion handle immediately, it was only needed to get the DMX matrix in case of DMX in the covariance domain */ - ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); - } - } - } - if ( ( hParamMC->proto_matrix_int_fx = (Word32 *) malloc( nchan_out_transport * nchan_transport * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); - } - Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, hParamMC->proto_matrix_int_fx, nchan_transport * nchan_out_transport );/*Q31*/ - - if ( ( hParamMC->proto_matrix_int = (float *) malloc( nchan_out_transport * nchan_transport * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); - } - - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) - { - Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_transport * nchan_out_cov, -4 ); /*Q.26*/ - matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0, ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0, proto_matrix_fx );/*Q.26*/ - Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_transport * nchan_out_cov, 4 ); /*Q.26*/ - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) - { - proto_mtx_norm_fx = ONE_IN_Q26;/*Q26*/ - for ( k = 0; k < nchan_transport * nchan_out_cov; k++ ) - { - proto_mtx_norm_fx = L_max(L_abs(proto_mtx_norm_fx), L_abs( proto_matrix_fx[k] ) );/*Q.26*/ - } - proto_mtx_norm_fx = divide3232(ONE_IN_Q26 , proto_mtx_norm_fx);/*Q15*/ - - /* transfer flattened proto_matrix to 2D in hLsSetupConversion->dmxMtx */ - for ( k = 0; k < nchan_transport; k++ ) - { - for ( int16_t i = 0; i < nchan_out_cov; i++ ) - { - st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl(Mult_32_16(proto_matrix_fx[k * nchan_out_cov + i] , extract_l(proto_mtx_norm_fx)),4);/*Q.30*/ - } - } - } - } - else - { - Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, nchan_out_transport * nchan_transport );/*Q.31*/ - Scale_sig32( proto_matrix_fx, nchan_out_transport * nchan_transport, -5);/*Scaling down to 26*/ - } - - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) - { - hParamMC->num_outputs_diff = 0; - hParamMC->diff_proto_info = NULL; - hParamMC->h_output_synthesis_params.use_onset_filters = 0; - hParamMC->max_band_decorr = 0; - hParamMC->h_freq_domain_decorr_ap_params = NULL; - hParamMC->h_freq_domain_decorr_ap_state = NULL; - } - else - { - hParamMC->num_outputs_diff = nchan_out_cov; - if ( ( hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); - } - - if ( ( error = param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info ,Q26) ) != IVAS_ERR_OK ) - { - return error; - } - - /* decorrelation */ - hParamMC->h_freq_domain_decorr_ap_params = NULL; - hParamMC->h_freq_domain_decorr_ap_state = NULL; - - ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); - - IF( ( error = ivas_dirac_dec_decorr_open_fx( &( hParamMC->h_freq_domain_decorr_ap_params ), &( hParamMC->h_freq_domain_decorr_ap_state ), hParamMC->num_freq_bands, hParamMC->num_outputs_diff, hParamMC->diff_proto_info->num_protos_diff, - DIRAC_SYNTHESIS_COV_MC_LS, frequency_axis_fx, nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) - { - return error; - } - - hParamMC->h_output_synthesis_params.use_onset_filters = 0; - hParamMC->max_band_decorr = hParamMC->h_freq_domain_decorr_ap_params->max_band_decorr; - } - hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->hMetadataPMC->nbands_coded]; - max_param_band_residual = 0; - - for ( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- ) - { - if ( hParamMC->band_grouping[k] <= hParamMC->max_band_decorr ) - { - max_param_band_residual = k; - assert( hParamMC->band_grouping[k] == hParamMC->max_band_decorr ); - break; - } - } - - /* output synthesis */ - if ( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ) != IVAS_ERR_OK ) - { - return error; - } - - ivas_param_mc_dec_compute_interpolator_fx( 0, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hParamMC->h_output_synthesis_params.interpolator_fx ); - - /* Head or external rotation */ - if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) - { -#if 1/*TODO : To be removed later*/ - IF ( ( hParamMC->hoa_encoder = (float *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); - } -#endif - IF ( ( hParamMC->hoa_encoder_fx = (Word32 *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof(Word32) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); - } - compute_hoa_encoder_mtx_fx( st_ivas->hTransSetup.ls_azimuth_fx, st_ivas->hTransSetup.ls_elevation_fx, hParamMC->hoa_encoder_fx, st_ivas->hTransSetup.nchan_out_woLFE, HEAD_ROTATION_HOA_ORDER ); - } - - /*-----------------------------------------------------------------* - * memory allocation - *-----------------------------------------------------------------*/ - - IF ( GT_16(hParamMC->max_band_decorr , 0) ) - { -#if 1/*TODO: To be removed later(floating point malloc)*/ - IF ( ( hParamMC->proto_frame_f = (float *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); - } - IF ( ( hParamMC->proto_frame_dec_f = (float *) malloc( 2 * nchan_out_cov * hParamMC->num_freq_bands * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); - } -#endif - IF ( ( hParamMC->proto_frame_f_fx = (Word32 *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); - } - IF ( ( hParamMC->proto_frame_dec_f_fx = (Word32 *) malloc( 2 * nchan_out_cov * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); - } - } - ELSE - { -#if 1/*TODO: To be removed later*/ - hParamMC->proto_frame_f = NULL; - hParamMC->proto_frame_dec_f = NULL; -#endif - hParamMC->proto_frame_f_fx = NULL; - hParamMC->proto_frame_dec_f_fx = NULL; - } - - ivas_param_mc_dec_init_fx( hParamMC, nchan_transport, nchan_out_cov ); - - IF ( hParamMC->synthesis_conf != PARAM_MC_SYNTH_MONO_STEREO ) - { - Word16 n_cldfb_slots; - - n_cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS; - IF ( st_ivas->hDecoderConfig->Opt_tsm ) - { - n_cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS; - } - - IF( ( hParamMC->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); - } - set32_fx( hParamMC->Cldfb_RealBuffer_tc_fx, 0, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); - IF( ( hParamMC->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); - } - set32_fx( hParamMC->Cldfb_ImagBuffer_tc_fx, 0, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); - -#if 1/*TODO: To be removed later(floating point malloc)*/ - if ( ( hParamMC->Cldfb_RealBuffer_tc = (float *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); - } - set_zero( hParamMC->Cldfb_RealBuffer_tc, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); - if ( ( hParamMC->Cldfb_ImagBuffer_tc = (float *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); - } - set_zero( hParamMC->Cldfb_ImagBuffer_tc, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); -#endif - - IF ( st_ivas->hTcBuffer == NULL ) - { - IF ( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, 0, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) - { - return error; - } - } - } - ELSE - { - hParamMC->Cldfb_RealBuffer_tc_fx = NULL; - hParamMC->Cldfb_ImagBuffer_tc_fx = NULL; -#if 1/*TODO: To be removed later*/ - hParamMC->Cldfb_RealBuffer_tc = NULL; - hParamMC->Cldfb_ImagBuffer_tc = NULL; -#endif - } - - hParamMC->subframes_rendered = 0; - hParamMC->slots_rendered = 0; - st_ivas->hParamMC = hParamMC; - return error; -} -#endif ivas_error ivas_param_mc_dec_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) @@ -935,12 +489,12 @@ ivas_error ivas_param_mc_dec_open( /* output synthesis */ #ifdef IVAS_FLOAT_FIXED - floatToFixed_arrL( proto_matrix, proto_matrix_fx, Q26, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS ); + floatToFixed_arrL( proto_matrix, proto_matrix_fx, Q30, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS ); if ( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ) != IVAS_ERR_OK ) { return error; } - fixedToFloat_arrL( hParamMC->h_output_synthesis_params.proto_matrix_fx, hParamMC->h_output_synthesis_params.proto_matrix, Q26, nchan_transport * nchan_out_cov ); + fixedToFloat_arrL( hParamMC->h_output_synthesis_params.proto_matrix_fx, hParamMC->h_output_synthesis_params.proto_matrix, 30, nchan_transport * nchan_out_cov ); #else if ( ( error = ivas_dirac_dec_output_synthesis_cov_open( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix ) ) != IVAS_ERR_OK ) @@ -1412,6 +966,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( FOR ( k = 0; k < nchan_out_transport; k++ ) { Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov], nchan_out_cov ); + Scale_sig32( &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov],nchan_out_cov,1 ); } } /* convert ParamMC parameter bands to SFB */ @@ -1446,27 +1001,26 @@ ivas_error ivas_param_mc_dec_reconfig_fx( IF ( EQ_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_LS_CONV_COV) || EQ_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_MONO_STEREO) ) { - Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_transport * nchan_out_cov, -4 ); matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0, ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0, - proto_matrix_fx /*Q26*/); - Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_transport * nchan_out_cov, 4 ); + proto_matrix_fx ); IF ( EQ_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_MONO_STEREO) ) { - proto_mtx_norm_fx = ONE_IN_Q26; + proto_mtx_norm_fx = MAX_32; FOR ( k = 0; k < nchan_transport * nchan_out_cov; k++ ) { proto_mtx_norm_fx = L_max(L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); } - proto_mtx_norm_fx = divide3232(ONE_IN_Q26 , proto_mtx_norm_fx);/*Q15*/ + proto_mtx_norm_fx = divide3232(1 , proto_mtx_norm_fx);/*Q15*/ /* transfer flattened proto_matrix to 2D in hLsSetupConversion->dmxMtx */ FOR ( k = 0; k < nchan_transport; k++ ) { FOR ( Word16 i = 0; i < nchan_out_cov; i++ ) { - st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl(Mpy_32_16_1(proto_matrix_fx[k * nchan_out_cov + i] , (Word16)proto_mtx_norm_fx),4); + st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shr(Mpy_32_16_1(proto_matrix_fx[k * nchan_out_cov + i] , (Word16)proto_mtx_norm_fx),1); + st_ivas->hLsSetUpConversion->dmxMtx[k][i] = fixedToFloat( st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i], Q30 ); } } } @@ -1474,7 +1028,6 @@ ivas_error ivas_param_mc_dec_reconfig_fx( ELSE { Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, nchan_out_transport * nchan_transport ); - Scale_sig32( proto_matrix_fx, nchan_out_transport * nchan_transport, -5 ); } IF ( NE_16(nchan_transport_old , nchan_transport) && NE_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_MONO_STEREO) ) @@ -1528,7 +1081,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - IF ( ( param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info ,Q26) ) != IVAS_ERR_OK ) + IF ( ( param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info ) ) != IVAS_ERR_OK ) { return error; } @@ -2299,173 +1852,7 @@ int16_t param_mc_get_num_cldfb_syntheses( * * Close Parametric MC memories *------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -void ivas_param_mc_dec_close_fx( - PARAM_MC_DEC_HANDLE *hParamMC_out /* i/o: Parametric MC decoder handle */ -) -{ - UWord16 i; - PARAM_MC_DEC_HANDLE hParamMC; - - IF( hParamMC_out == NULL || *hParamMC_out == NULL ) - { - return; - } - - hParamMC = *hParamMC_out; - - /* close sub-modules */ - ivas_dirac_dec_output_synthesis_cov_close_fx( &hParamMC->h_output_synthesis_params, &hParamMC->h_output_synthesis_cov_state ); - - IF( hParamMC->h_freq_domain_decorr_ap_params != NULL || hParamMC->h_freq_domain_decorr_ap_state != NULL ) - { - ivas_dirac_dec_decorr_close( &hParamMC->h_freq_domain_decorr_ap_params, &hParamMC->h_freq_domain_decorr_ap_state ); - } - - /* parameter decoding */ - IF( hParamMC->hMetadataPMC != NULL ) - { -#ifndef FIX_901_PARAMMC_DEAD_CODE - ivas_param_mc_metadata_close( hParamMC->hMetadataPMC ); -#endif - free( hParamMC->hMetadataPMC ); - hParamMC->hMetadataPMC = NULL; - } - IF( hParamMC->icc_q_fx != NULL ) - { - free( hParamMC->icc_q_fx ); - hParamMC->icc_q_fx = NULL; - } - - IF( hParamMC->icld_q_fx != NULL ) - { - free( hParamMC->icld_q_fx ); - hParamMC->icld_q_fx = NULL; - } - /* diffuse prototype info */ - IF( hParamMC->diff_proto_info ) - { - FOR( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) - { - free( hParamMC->diff_proto_info->source_chan_idx[i] ); - hParamMC->diff_proto_info->source_chan_idx[i] = NULL; - - free( hParamMC->diff_proto_info->proto_fac_fx[i] ); - hParamMC->diff_proto_info->proto_fac_fx[i] = NULL; - } - - free( hParamMC->diff_proto_info->source_chan_idx ); - hParamMC->diff_proto_info->source_chan_idx = NULL; - - free( hParamMC->diff_proto_info->proto_fac_fx ); - hParamMC->diff_proto_info->proto_fac_fx = NULL; - - free( hParamMC->diff_proto_info->proto_index_diff ); - hParamMC->diff_proto_info->proto_index_diff = NULL; - - free( hParamMC->diff_proto_info->num_source_chan_diff ); - hParamMC->diff_proto_info->num_source_chan_diff = NULL; - - free( hParamMC->diff_proto_info ); - hParamMC->diff_proto_info = NULL; - } - /* States */ - /* free prototype signal buffers */ - IF( hParamMC->proto_frame_f_fx != NULL ) - { - free( hParamMC->proto_frame_f_fx ); - hParamMC->proto_frame_f_fx = NULL; - } - - IF( hParamMC->proto_frame_dec_f_fx != NULL ) - { - free( hParamMC->proto_frame_dec_f_fx); - hParamMC->proto_frame_dec_f_fx = NULL; - } - - IF( hParamMC->ls_conv_dmx_matrix_fx != NULL ) - { - free( hParamMC->ls_conv_dmx_matrix_fx ); - hParamMC->ls_conv_dmx_matrix_fx = NULL; - } - - IF( hParamMC->proto_matrix_int_fx != NULL ) - { - free( hParamMC->proto_matrix_int_fx ); - hParamMC->proto_matrix_int_fx = NULL; - } - - IF( hParamMC->hoa_encoder_fx != NULL ) - { - free( hParamMC->hoa_encoder_fx ); - hParamMC->hoa_encoder_fx = NULL; - } - IF( hParamMC->Cldfb_RealBuffer_tc_fx != NULL ) - { - free( hParamMC->Cldfb_RealBuffer_tc_fx ); - hParamMC->Cldfb_RealBuffer_tc_fx = NULL; - } - IF( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL ) - { - free( hParamMC->Cldfb_ImagBuffer_tc_fx ); - hParamMC->Cldfb_ImagBuffer_tc_fx = NULL; - } -#if 1 /*TODO: To be removed later(Floating point memory dealloc)------------------------------- */ - - IF( hParamMC->icc_q != NULL ) - { - free( hParamMC->icc_q ); - hParamMC->icc_q = NULL; - } - - IF( hParamMC->icld_q != NULL ) - { - free( hParamMC->icld_q ); - hParamMC->icld_q = NULL; - } - IF( hParamMC->diff_proto_info ) - { - FOR( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) - { - free( hParamMC->diff_proto_info->proto_fac[i] ); - hParamMC->diff_proto_info->proto_fac[i] = NULL; - } - free( hParamMC->diff_proto_info->proto_fac ); - hParamMC->diff_proto_info->proto_fac = NULL; - } - IF( hParamMC->proto_frame_f != NULL ) - { - free( hParamMC->proto_frame_f ); - hParamMC->proto_frame_f = NULL; - } - IF( hParamMC->proto_frame_dec_f != NULL ) - { - free( hParamMC->proto_frame_dec_f ); - hParamMC->proto_frame_dec_f = NULL; - } - IF( hParamMC->ls_conv_dmx_matrix != NULL ) - { - free( hParamMC->ls_conv_dmx_matrix ); - hParamMC->ls_conv_dmx_matrix = NULL; - } - IF( hParamMC->Cldfb_RealBuffer_tc != NULL ) - { - free( hParamMC->Cldfb_RealBuffer_tc ); - hParamMC->Cldfb_RealBuffer_tc = NULL; - } - IF( hParamMC->Cldfb_ImagBuffer_tc != NULL ) - { - free( hParamMC->Cldfb_ImagBuffer_tc ); - hParamMC->Cldfb_ImagBuffer_tc = NULL; - } -#endif /***********************************ends here************************************************/ - - free( *hParamMC_out ); - *hParamMC_out = NULL; - return; -} -#endif void ivas_param_mc_dec_close( PARAM_MC_DEC_HANDLE *hParamMC_out /* i/o: Parametric MC decoder handle */ ) @@ -2591,6 +1978,7 @@ void ivas_param_mc_dec_close( return; } + /*------------------------------------------------------------------------- * ivas_param_mc_dec_read_BS() * @@ -4131,65 +3519,7 @@ void ivas_param_mc_dec( * * Parametric MC decoding initialization *------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -static void ivas_param_mc_dec_init_fx( - PARAM_MC_DEC_HANDLE hParamMC, /* i/o: decoder DirAC handle */ - const Word16 nchan_transport, /* i : number of input (transport) channels */ - const Word16 nchan_cov ) /* i : number of cov synthesis channels */ -{ - Word16 k; - UWord16 max_param_band_residual; - Word16 len; - - /*-----------------------------------------------------------------* - * init sub-modules - *-----------------------------------------------------------------*/ - - /* decorrelation */ - IF ( GT_16(hParamMC->max_band_decorr , 0) ) - { - len = hParamMC->diff_proto_info->num_protos_diff * hParamMC->h_freq_domain_decorr_ap_params->h_onset_detection_power_params.max_band_decorr; - - /* init onsetDetectionPower */ - set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx, len ); - set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx, len ); -#if 1/*Floating point intialization: to be removed later*/ - set_zero( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1, len ); - set_zero( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2, len ); -#endif - } - - max_param_band_residual = 0; - - /* output synthesis */ - FOR ( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- ) - { - IF ( LE_16(hParamMC->band_grouping[k] , hParamMC->max_band_decorr) ) - { - max_param_band_residual = k; - break; - } - } - - ivas_dirac_dec_output_synthesis_cov_init_fx( &( hParamMC->h_output_synthesis_cov_state ), nchan_transport, nchan_cov, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual ); - - /*-----------------------------------------------------------------* - * init proto frames - *-----------------------------------------------------------------*/ - - IF ( GT_16(hParamMC->max_band_decorr , 0) ) - { -#if 1/*TODO: To be removed later*/ - set_zero( hParamMC->proto_frame_f, 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands ); - set_zero( hParamMC->proto_frame_dec_f, 2 * nchan_cov * hParamMC->num_freq_bands ); -#endif - set_zero_fx( hParamMC->proto_frame_f_fx, 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands ); - set32_fx( hParamMC->proto_frame_dec_f_fx, 0, 2 * nchan_cov * hParamMC->num_freq_bands ); - } - return; -} -#endif // IVAS_FLOAT_FIXED static void ivas_param_mc_dec_init( PARAM_MC_DEC_HANDLE hParamMC, /* i/o: decoder DirAC handle */ const int16_t nchan_transport, /* i : number of input (transport) channels */ @@ -6299,8 +5629,8 @@ static ivas_error param_mc_get_diff_proto_info_fx( const Word32 *proto_mtx, /* i : protoype matrix for the synthesis */ const UWord16 nchan_transport, /* i : number of transport channels */ const UWord16 nchan_out_cov, /* i : number if output channels of the covariance synthesis */ - PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info, /* o : generated diffuse prototype info */ - Word16 Q_proto_mtx ) + PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info /* o : generated diffuse prototype info */ +) { #if FLT_ENABLE float proto_fac[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; @@ -6368,7 +5698,7 @@ static ivas_error param_mc_get_diff_proto_info_fx( #if FLT_ENABLE if ( diff < 0.1f ) #else - if ( LT_64( diff_fx * 10, L_shl_sat(1, Q_proto_mtx)) ) + if ( LT_64( diff_fx * 10, 2147483648 ) ) #endif { found = 1; diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index b6366c95c..29294304c 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -1352,846 +1352,26 @@ ivas_error ivas_mc_dec_config( { if ( st_ivas->hDecoderConfig->last_ivas_total_brate != st_ivas->hDecoderConfig->ivas_total_brate || st_ivas->transport_config != signaled_config || last_mc_mode != st_ivas->mc_mode ) { -#ifdef IVAS_FLOAT_FIXED -#if 1 /*TODO: To be removed(Float to fixed conversion)*/ - DECODER_TC_BUFFER_HANDLE hTcBuffer; - hTcBuffer = st_ivas->hTcBuffer; - IF( st_ivas->hCombinedOrientationData ) - FOR( Word16 ind1 = 0; ind1 < 3; ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < 3; ind2++ ) - { - st_ivas->hCombinedOrientationData->Rmat_fx[0][ind1][ind2] = (Word32) ( st_ivas->hCombinedOrientationData->Rmat[0][ind1][ind2] * ( 1 << 15 ) ); - } - } - SPAR_DEC_HANDLE hSpar; - hSpar = st_ivas->hSpar; - Word16 nchan_transport_old = st_ivas->nchan_transport; - uint16_t nchan_internal; - Word32 ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); - DECODER_CONFIG_HANDLE hDecoderConfig; - hDecoderConfig = st_ivas->hDecoderConfig; - - Word16 n_tc; - n_tc = st_ivas->hTcBuffer->nchan_transport_internal; - for ( int ch = 0; ch < n_tc; ch++ ) - { - floatToFixed_arrL( st_ivas->hTcBuffer->tc[ch], st_ivas->hTcBuffer->tc_fx[ch], Q11, L_FRAME48k ); - } - Word16 cx_e = 0, cy_e = 0, mmo_e = 0, mmro_e = 0; - PARAM_MC_DEC_HANDLE hParamMC; - hParamMC = st_ivas->hParamMC; - Word16 nchan_out_transport, nchan_out_cov; - MC_LS_SETUP mc_ls_setup; - Word16 nchan_transport; - if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) - { - mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); - nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_ls_setup ); - nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; - if ( st_ivas->hParamMC ) - { - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) - { - nchan_out_cov = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; - } - else - { - nchan_out_cov = nchan_out_transport; - } - floatToFixed_arr( hParamMC->icc_q, hParamMC->icc_q_fx, Q15, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); - floatToFixed_arr( hParamMC->icld_q, hParamMC->icld_q_fx, Q8, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); - Word32 max_cx_old_fx, max_cy_old_fx, max_mix_matrix_old_fx, max_mix_matrix_res_old_fx; - float max_cx_old = hParamMC->h_output_synthesis_cov_state.cx_old[0][0], max_cy_old = hParamMC->h_output_synthesis_cov_state.cy_old[0][0], max_mix_matrix_old = hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[0][0], max_mix_matrix_res_old = hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[0][0]; - for ( int i = 0; i < hParamMC->hMetadataPMC->num_parameter_bands; i++ ) - { - if ( hParamMC->h_output_synthesis_cov_state.cx_old[i] ) - { - for ( int j = 0; j < nchan_transport_old * nchan_transport_old; j++ ) - max_cx_old = max( max_cx_old, hParamMC->h_output_synthesis_cov_state.cx_old[i][j] ); - for ( int j = 0; j < nchan_out_cov * nchan_out_cov; j++ ) - max_cy_old = max( max_cy_old, hParamMC->h_output_synthesis_cov_state.cy_old[i][j] ); - for ( int j = 0; j < nchan_transport_old * nchan_out_cov; j++ ) - max_mix_matrix_old = max( max_mix_matrix_old, hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[i][j] ); - } - } - IF(st_ivas->hParamMC->ls_conv_dmx_matrix_fx ) - floatToFixed_arr32( st_ivas->hParamMC->ls_conv_dmx_matrix, st_ivas->hParamMC->ls_conv_dmx_matrix_fx, Q30, st_ivas->hDecoderConfig->nchan_out * ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) ); - for ( int i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) - { - if ( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[i] ) - { - for ( int j = 0; j < nchan_out_cov * nchan_out_cov; j++ ) - max_mix_matrix_res_old = max( max_mix_matrix_res_old, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[i][j] ); - } - } - f2me( max_cx_old, &max_cx_old_fx, &cx_e ); - f2me( max_cy_old, &max_cy_old_fx, &cy_e ); - f2me( max_mix_matrix_old, &max_mix_matrix_old_fx, &mmo_e ); - f2me( max_mix_matrix_res_old, &max_mix_matrix_res_old_fx, &mmro_e ); - if ( mmo_e < 0 ) - mmo_e = 0; - if ( mmro_e < 0 ) - mmro_e = 0; - for ( int i = 0; i < hParamMC->hMetadataPMC->num_parameter_bands; i++ ) - { - if ( hParamMC->h_output_synthesis_cov_state.cx_old[i] ) - { - - floatToFixed_arrL( hParamMC->h_output_synthesis_cov_state.cx_old[i], hParamMC->h_output_synthesis_cov_state.cx_old_fx[i], 31 - cx_e, nchan_transport_old * nchan_transport_old ); - floatToFixed_arrL( hParamMC->h_output_synthesis_cov_state.cy_old[i], hParamMC->h_output_synthesis_cov_state.cy_old_fx[i], 31 - cy_e, nchan_out_cov * nchan_out_cov ); - floatToFixed_arrL( hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[i], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[i], 31 - mmo_e, nchan_transport_old * nchan_out_cov ); - } - } - for ( int i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) - { - if ( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[i] ) - { - floatToFixed_arrL( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[i], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[i], 31 - mmro_e, nchan_out_cov * nchan_out_cov ); - } - } - floatToFixed_arrL( hParamMC->proto_matrix_int, hParamMC->proto_matrix_int_fx, Q31, nchan_out_transport * nchan_transport ); - FOR( Word16 i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) - { - if ( hParamMC->diff_proto_info ) - floatToFixed_arrL( hParamMC->diff_proto_info->proto_fac[i], hParamMC->diff_proto_info->proto_fac_fx[i], Q26, hParamMC->diff_proto_info->num_source_chan_diff[i] ); - } - } - } -#endif - if ( ( error = ivas_mc_dec_reconfig( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) - { - return error; - } -#if 1 - if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) - { - PARAM_MC_DEC_HANDLE hParamMC; - hParamMC = st_ivas->hParamMC; - mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); - st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_ls_setup ); - nchan_transport = st_ivas->nchan_transport; - nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) - { - nchan_out_cov = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; - } - else - { - nchan_out_cov = nchan_out_transport; - } - if ( hParamMC ) - { - if ( st_ivas->hLsSetUpConversion ) - { - for ( Word16 k = 0; k < nchan_transport; k++ ) - { - for ( int16_t i = 0; i < nchan_out_cov; i++ ) - { - st_ivas->hLsSetUpConversion->dmxMtx[k][i] = fixedToFloat( st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i], Q30 ); - } - } - } - fixedToFloat_arr( hParamMC->icc_q_fx, hParamMC->icc_q, Q15, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); - fixedToFloat_arr( hParamMC->icld_q_fx, hParamMC->icld_q, Q8, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); - fixedToFloat_arrL( hParamMC->h_output_synthesis_params.proto_matrix_fx, hParamMC->h_output_synthesis_params.proto_matrix, 26, nchan_transport * nchan_out_cov ); - IF( hParamMC->diff_proto_info ) - FOR( Word16 i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) - { - - fixedToFloat_arrL( hParamMC->diff_proto_info->proto_fac_fx[i], hParamMC->diff_proto_info->proto_fac[i], 26, hParamMC->diff_proto_info->num_source_chan_diff[i] ); - } - fixedToFloat_arrL( hParamMC->proto_matrix_int_fx, hParamMC->proto_matrix_int, Q31, nchan_out_transport * nchan_transport ); - IF(st_ivas->hParamMC->ls_conv_dmx_matrix_fx ) - fixedToFloat_arrL( st_ivas->hParamMC->ls_conv_dmx_matrix_fx, st_ivas->hParamMC->ls_conv_dmx_matrix, Q30, st_ivas->hDecoderConfig->nchan_out * ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) ); - if ( last_mc_mode == MC_MODE_PARAMMC ) - { - for ( int i = 0; i < hParamMC->hMetadataPMC->num_parameter_bands; i++ ) - { - if ( hParamMC->h_output_synthesis_cov_state.cx_old[i] ) - { - fixedToFloat_arrL( hParamMC->h_output_synthesis_cov_state.cx_old_fx[i], hParamMC->h_output_synthesis_cov_state.cx_old[i], 31 - cx_e, nchan_transport_old * nchan_transport_old ); - fixedToFloat_arrL( hParamMC->h_output_synthesis_cov_state.cy_old_fx[i], hParamMC->h_output_synthesis_cov_state.cy_old[i], 31 - cy_e, nchan_out_cov * nchan_out_cov ); - fixedToFloat_arrL( hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[i], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[i], 31 - mmo_e, nchan_transport_old * nchan_out_cov ); - } - } - for ( int i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) - { - if ( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[i] ) - { - fixedToFloat_arrL( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[i], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[i], 31 - mmro_e, nchan_out_cov * nchan_out_cov ); - } - } - } - } - } -#endif -#else - if ( ( error = ivas_mc_dec_reconfig( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif // IVAS_FLOAT_FIXED - } - } - - st_ivas->transport_config = signaled_config; - } - - return IVAS_ERR_OK; -} - - -/*------------------------------------------------------------------------- - * ivas_mc_dec_reconfig() - * - * reconfigure the MC format decoder - *-------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -static ivas_error ivas_mc_dec_reconfig( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - UWord16 *nSamplesRendered, /* o : number of samples flushed from the last frame (JBM) */ - Word16 *data /* o : output synthesis signal */ -) -{ - Word16 nchan_transport_old, nSCE_old, nCPE_old, sba_dirac_stereo_flag_old, nchan_hp20_old; - Word16 numCldfbAnalyses_old, numCldfbSyntheses_old; - Word32 new_brate_SCE, new_brate_CPE, ivas_total_brate; - RENDERER_TYPE renderer_type_old; - Decoder_State *st; - ivas_error error; - MC_MODE mc_mode, last_mc_mode; - TC_BUFFER_MODE tc_buffer_mode_new; - Word16 tc_nchan_tc_new; - Word16 tc_nchan_allocate_new; - Word16 tc_granularity_new; - AUDIO_CONFIG intern_config_old; - IVAS_OUTPUT_SETUP hIntSetupOld; - Word16 nchan_out_buff_old, nchan_out_buff; - - error = IVAS_ERR_OK; - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - nchan_transport_old = st_ivas->nchan_transport; - nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); - last_mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */ - - /* temporally set the current mc_mode back to the previous one to make sure the following call to - ivas_init_dec_get_num_cldfb_instances() returns the correct counts */ - mc_mode = st_ivas->mc_mode; - st_ivas->mc_mode = last_mc_mode; - ivas_init_dec_get_num_cldfb_instances_ivas_fx( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); - - st_ivas->mc_mode = mc_mode; - - nSCE_old = st_ivas->nSCE; - nCPE_old = st_ivas->nCPE; - sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; - - /* special handling needed for the hp20 buffers for McMASA */ - IF ( EQ_16(last_mc_mode , MC_MODE_MCMASA) ) - { - nchan_hp20_old = getNumChanSynthesis( st_ivas ); - } - ELSE - { - nchan_hp20_old = nchan_transport_old; - } - st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); - - /* save old IntSetup, might be needed for JBM flushing...*/ - intern_config_old = st_ivas->intern_config; - hIntSetupOld = st_ivas->hIntSetup; - tc_granularity_new = 1; - - /* renderer might have changed, reselect */ - renderer_type_old = st_ivas->renderer_type; - ivas_renderer_select( st_ivas ); - - /* side effect of the renderer selection can be a changed internal config */ - ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); - - /* transfer subframe info from DirAC or ParamMC to central tc buffer */ - IF ( EQ_16(last_mc_mode , MC_MODE_PARAMMC) ) - { - st_ivas->hTcBuffer->nb_subframes = st_ivas->hParamMC->nb_subframes; - st_ivas->hTcBuffer->subframes_rendered = st_ivas->hParamMC->subframes_rendered; - st_ivas->hTcBuffer->num_slots = st_ivas->hParamMC->num_slots; - st_ivas->hTcBuffer->slots_rendered = st_ivas->hParamMC->slots_rendered; - Copy( st_ivas->hParamMC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); - } - ELSE IF ( EQ_16(last_mc_mode , MC_MODE_MCMASA) && st_ivas->hSpatParamRendCom != NULL ) - { - st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes; - st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; - st_ivas->hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots; - st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; - Copy( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); - } - - /* JBM: when granularity goes down (e.g. MCT with CREND -> ParamMC with binaural fastconv - render what still fits in the new granularity */ - tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ); - IF ( LT_16(tc_granularity_new , st_ivas->hTcBuffer->n_samples_granularity) ) - { - IF ( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, last_mc_mode, ISM_MODE_NONE, nSamplesRendered, data ) ) != IVAS_ERR_OK ) - { - return error; - } - } - /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ - ELSE IF ( GT_16(tc_granularity_new , st_ivas->hTcBuffer->n_samples_granularity) ) - { - IF ( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } - IF ( EQ_16(st_ivas->mc_mode , MC_MODE_MCT) ) - { - st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ) ); - st_ivas->nSCE = 0; - st_ivas->nCPE = st_ivas->nchan_transport / 2; - - IF ( NE_16(last_mc_mode , MC_MODE_MCT) ) - { - /*De-allocate handles for other MC modes*/ - IF ( st_ivas->hParamMC != NULL ) - { - ivas_param_mc_dec_close_fx( &st_ivas->hParamMC ); - - /* remove ls conversion if it was allocated by ParamMC */ - ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); - } - - IF ( EQ_16(last_mc_mode , MC_MODE_PARAMUPMIX) ) - { - ivas_mc_paramupmix_dec_close( &( st_ivas->hMCParamUpmix ) ); - ivas_ls_setup_conversion_close_fx( &( st_ivas->hLsSetUpConversion ) ); - } - - /* De-allocate McMasa-related handles */ - ivas_masa_dec_close_fx( &( st_ivas->hMasa ) ); - - ivas_qmetadata_close( &st_ivas->hQMetaData ); - IF ( st_ivas->hDirAC != NULL ) - { - ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) ); - ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) ); - ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) ); - vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); - } - - /* init LS conversion if the renderer type asks for it */ - IF ( EQ_16(st_ivas->renderer_type , RENDERER_MC) && st_ivas->hLsSetUpConversion == NULL ) - { - if ( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } - } - } - ELSE IF ( EQ_16(st_ivas->mc_mode , MC_MODE_PARAMUPMIX) ) - { - st_ivas->nSCE = 0; - st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS / 2; - st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; - - IF ( NE_16(last_mc_mode , MC_MODE_PARAMUPMIX) ) - { - /*De-allocate handles for other MC modes*/ - IF ( st_ivas->hParamMC != NULL ) - { - ivas_param_mc_dec_close_fx( &st_ivas->hParamMC ); - - /* remove ls conversion if it was allocated by ParamMC */ - ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); - } - - ivas_masa_dec_close_fx( &( st_ivas->hMasa ) ); - ivas_qmetadata_close( &st_ivas->hQMetaData ); - - /* init LS conversion if the renderer type asks for it */ - IF ( ( EQ_16(st_ivas->renderer_type , RENDERER_MC) ) && st_ivas->hLsSetUpConversion == NULL ) - { - IF ( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - IF ( ( error = ivas_mc_paramupmix_dec_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } - } - ELSE IF ( EQ_16(st_ivas->mc_mode , MC_MODE_PARAMMC) ) - { - IF ( NE_16(last_mc_mode , MC_MODE_PARAMMC) ) - { - /* remove old ls conversion for MCT if open, gets reopened correctly within ivas_param_mc_dec_open when needed */ - IF ( EQ_16(renderer_type_old , RENDERER_MC) && st_ivas->hLsSetUpConversion != NULL ) - { - ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); - } - - IF ( ( error = ivas_param_mc_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - - } - ELSE - { - IF ( ( error = ivas_param_mc_dec_reconfig_fx( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - /* De-allocate McMasa-related handles */ - ivas_masa_dec_close_fx( &( st_ivas->hMasa ) ); - ivas_qmetadata_close( &st_ivas->hQMetaData ); - - IF ( st_ivas->hDirAC != NULL ) - { - ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) ); - ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) ); - ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) ); - vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); - } - - IF ( EQ_16(last_mc_mode , MC_MODE_MCT) ) - { - IF ( st_ivas->hMCT != NULL && LE_16(st_ivas->nchan_transport , CPE_CHANNELS) ) - { - ivas_mct_dec_close( &st_ivas->hMCT ); - } - } - ELSE IF ( EQ_16(last_mc_mode , MC_MODE_PARAMUPMIX) ) - { - ivas_mc_paramupmix_dec_close( &( st_ivas->hMCParamUpmix ) ); - } - - /* LFE handle */ - ivas_lfe_dec_close_fx( &( st_ivas->hLFE ) ); - } - ELSE IF ( EQ_16(st_ivas->mc_mode , MC_MODE_MCMASA) ) - { - ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); - - IF ( NE_16(last_mc_mode , MC_MODE_MCMASA) ) - { - IF ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - IF ( ( error = ivas_mcmasa_dec_reconfig( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - - /* LS conversion */ - IF ( st_ivas->hLsSetUpConversion != NULL ) - { - ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); - } - - ivas_mc_paramupmix_dec_close( &( st_ivas->hMCParamUpmix ) ); - - IF ( st_ivas->hParamMC != NULL ) - { - ivas_param_mc_dec_close_fx( &st_ivas->hParamMC ); - st_ivas->hParamMC = NULL; - } - - IF ( EQ_16(last_mc_mode , MC_MODE_MCT) ) - { - ivas_mct_dec_close( &st_ivas->hMCT ); - } - - /* LFE handle */ - ivas_lfe_dec_close_fx( &( st_ivas->hLFE ) ); - } - - IF ( NE_16(st_ivas->mc_mode , MC_MODE_MCMASA) ) - { - IF ( EQ_16(st_ivas->nchan_transport , 1) ) - { - st_ivas->element_mode_init = IVAS_SCE; - } - ELSE - { - st_ivas->element_mode_init = IVAS_CPE_MDCT; - } - } - - /*-----------------------------------------------------------------* - * Reconfigure core coder - *-----------------------------------------------------------------*/ - - /* special case: MCT->ParamMC with more than 2 TC, CPE 1 stays, but has the wrong mct_chan_mode in channel 1 - and might have IGF static memory not allocated and the bit stream index list not set, - set correct mct_chan_mode and init missing static mem (IGF, HQ) and some config (TNS) do it here since it is _very_ MC specific */ - IF ( EQ_16(last_mc_mode , MC_MODE_MCT) && EQ_16(st_ivas->mc_mode , MC_MODE_PARAMMC) && GT_16(st_ivas->nchan_transport , CPE_CHANNELS) ) - { - st = st_ivas->hCPE[1]->hCoreCoder[1]; - - IF ( st_ivas->nchan_transport == 3 ) - { - st->mct_chan_mode = MCT_CHAN_MODE_IGNORE; - } - ELSE - { - st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; - } - - IF ( st->hIGFDec == NULL ) - { - IF ( ( st->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for IGF\n" ) ); - } - - st->igf = 0; - init_igf_dec( st->hIGFDec ); -#if 1 /*TODO: To be removed later(floating point initialization)*/ -#if ( defined EVS_FLOAT ) || !( defined IVAS_FLOAT_FIXED ) - st->hIGFDec->virtualSpec_float = &st->hIGFDec->virtualSpecBuf[0]; - st->hIGFDec->igfData.pSpecFlat_float = &st->hIGFDec->igfData.pSpecFlatBuf[0]; - set_f( st->hIGFDec->igfData.pSpecFlatBuf, 0, IGF_START_MX ); -#endif - FOR( Word16 l = 0; l < IGF_START_MX; l++ ) - st->hIGFDec->infoTCXNoiseBuf[l] = (uint8_t) st->hIGFDec->infoTCXNoise_evs[l]; -#endif - } - - IF ( st->hHQ_core == NULL ) - { - IF ( ( st->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) ); - } - - /* HQ core initialization */ -#if 1/*TODO: To be removed later*/ - HQ_core_dec_init_flt( st->hHQ_core ); -#endif - HQ_core_dec_init_fx( st->hHQ_core ); - } - - /* check if we have a doubly used hTxcCfg, if so, allocate a distint one for the old MCT LFE channel */ - IF ( st->hTcxCfg == st_ivas->hCPE[1]->hCoreCoder[0]->hTcxCfg ) - { - IF ( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); - } - } - - st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( ivas_total_brate, st->igf, st->element_mode ); - } - IF ( EQ_16(st_ivas->mc_mode , MC_MODE_MCMASA) ) - { - uint8_t separateChannelEnabled; - int16_t separateChannelIndex; - ivas_mcmasa_set_separate_channel_mode_fx( &separateChannelEnabled, &separateChannelIndex, ivas_total_brate ); - ivas_mcmasa_split_brate_fx( separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &new_brate_SCE, &new_brate_CPE ); - } - ELSE IF ( EQ_16(st_ivas->mc_mode , MC_MODE_MCT) ) - { - new_brate_SCE = 0; - new_brate_CPE = ( ivas_total_brate / ( st_ivas->nchan_transport - 1 ) ) * CPE_CHANNELS; - } - ELSE IF ( EQ_16(st_ivas->mc_mode , MC_MODE_PARAMUPMIX) ) - { - new_brate_SCE = 0; - new_brate_CPE = ( ivas_total_brate / ( st_ivas->nchan_transport - 1 ) ) * CPE_CHANNELS; - } - ELSE - { - new_brate_SCE = 0; /* ivas_total_brate / st_ivas->nchan_transport;*/ - new_brate_CPE = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; - } - - IF( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, new_brate_SCE, new_brate_CPE ) ) != IVAS_ERR_OK ) - { - return error; - } - IF ( EQ_16(last_mc_mode , MC_MODE_MCT) && EQ_16(st_ivas->mc_mode , MC_MODE_PARAMMC) && GT_16(st_ivas->nchan_transport , CPE_CHANNELS) ) - { - st = st_ivas->hCPE[1]->hCoreCoder[1]; - - /* TCX-LTP */ - IF ( st->hTcxLtpDec == NULL ) - { - IF ( ( st->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n" ) ); - } - tcxltp_dec_init_fx( st->hTcxLtpDec, 0, st->last_codec_mode, st->element_mode, st->pit_max, st->sr_core ); - } - } - - /*-----------------------------------------------------------------* - * re-configure HP20 memories - *-----------------------------------------------------------------*/ - IF ( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) - { - return error; - } -#if 1/*TODO: To be removed later*/ - /*To be removed later: Contains memory allocations for floating point buffers*/ - IF ( ( error = ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif - /*-----------------------------------------------------------------* - * Allocate the LFE handle that is coded separately after the allocation of the core coders - *-----------------------------------------------------------------*/ - - IF ( ( EQ_16(st_ivas->mc_mode , MC_MODE_MCT) || EQ_16(st_ivas->mc_mode , MC_MODE_PARAMUPMIX) ) && st_ivas->hLFE == NULL ) - { - Word32 binauralization_delay_ns = st_ivas->binaural_latency_ns; - IF ( st_ivas->hBinRenderer != NULL ) - { - IF ( st_ivas->hBinRenderer->render_lfe ) - { - /* Account for filterbank delay */ - binauralization_delay_ns += IVAS_FB_DEC_DELAY_NS; - } - else - { - binauralization_delay_ns = 0; - } - } - - IF( ( error = ivas_create_lfe_dec_fx( &st_ivas->hLFE, st_ivas->hDecoderConfig->output_Fs, binauralization_delay_ns ) ) != IVAS_ERR_OK ) - { - return error; - } - - set32_fx( st_ivas->hLFE->prevsynth_buf_fx, 0, LFE_PLC_BUFLEN ); - set32_fx( st_ivas->hLFE->prior_out_buffer_fx, 0, L_FRAME48k ); - } - - /*-----------------------------------------------------------------* - * Reconfigure renderers - *-----------------------------------------------------------------*/ - - IF ( EQ_16(st_ivas->mc_mode , MC_MODE_MCMASA) ) - { - IF ( ( NE_16(st_ivas->renderer_type , RENDERER_DISABLE) ) && ( NE_16(st_ivas->renderer_type , RENDERER_MCMASA_MONO_STEREO) ) ) - { - IF ( st_ivas->hDirAC != NULL ) - { - /* reconfigure existing DirAC dec */ - IF ( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) - { - return error; - } - } - ELSE - { - /* init a new DirAC dec */ - IF ( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) - { - return error; - } - } - } - ELSE IF ( EQ_16(st_ivas->renderer_type , RENDERER_DISABLE) && st_ivas->hDirAC != NULL ) - { - ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) ); - ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) ); - ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) ); - vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); - } - } - - IF ( NE_16(renderer_type_old , st_ivas->renderer_type) ) - { - AUDIO_CONFIG output_config; - - output_config = st_ivas->hDecoderConfig->output_config; - - /* binaural renderers*/ - IF ( EQ_16(output_config , IVAS_AUDIO_CONFIG_BINAURAL) || EQ_16(output_config , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR) || EQ_16(output_config , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB) ) - { - /* remove unneeded binaural renderers */ - IF ( st_ivas->hBinRenderer != NULL && ( NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_FASTCONV) && NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_FASTCONV_ROOM) ) ) - { - ivas_binRenderer_close( &st_ivas->hBinRenderer ); - } - - IF ( ( st_ivas->hCrendWrapper != NULL ) && ( st_ivas->hCrendWrapper->hCrend != NULL ) && ( NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_MIXER_CONV) && NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_MIXER_CONV_ROOM) && ( NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_OBJECTS_TD) || NE_16(st_ivas->hIntSetup.output_config , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB) ) ) ) - { - - ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) ); - } - - IF ( st_ivas->hBinRendererTd != NULL && ( NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_OBJECTS_TD) ) ) - { - ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); - st_ivas->hHrtfTD = NULL; - } - - IF ( st_ivas->hDiracDecBin != NULL ) - { - IF ( NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_PARAMETRIC) && NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_PARAMETRIC_ROOM) && NE_16(st_ivas->renderer_type , RENDERER_STEREO_PARAMETRIC) ) - { - ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); - } - } - - /* init necessary new renderers */ - IF ( st_ivas->hBinRenderer == NULL && ( EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_FASTCONV) || EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_FASTCONV_ROOM) ) ) - { - IF ( ( error = ivas_binRenderer_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } - ELSE IF ( st_ivas->hBinRendererTd == NULL && EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_OBJECTS_TD) ) - { - IF( ( error = ivas_td_binaural_open_fx( st_ivas, st_ivas->hBinRendererTd->SrcInd, &st_ivas->hBinRendererTd->num_src ) ) != IVAS_ERR_OK ) - { - return error; - } - IF ( EQ_16(st_ivas->hIntSetup.output_config , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB) ) - { - IF ( ( error = ivas_rend_initCrendWrapper( &st_ivas->hCrendWrapper ) ) != IVAS_ERR_OK ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Wrapper\n" ); - } + if ( ( error = ivas_mc_dec_reconfig( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) - st_ivas->hCrendWrapper->hCrend = NULL; - st_ivas->hCrendWrapper->hHrtfCrend = NULL; - IF ( ( st_ivas->hCrendWrapper->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend\n" ); - } - } - } - ELSE IF ( st_ivas->hCrendWrapper == NULL && ( EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_MIXER_CONV) || EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_MIXER_CONV_ROOM) ) ) - { - IF ( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hDecoderConfig->output_config, st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) { return error; } - st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns; - } - } - /* mono/stereo */ - ELSE IF ( EQ_16(output_config , IVAS_AUDIO_CONFIG_MONO) || EQ_16(output_config , IVAS_AUDIO_CONFIG_STEREO) ) - { - /* nothing should happen here... */ - } - /* LS */ - ELSE IF ( EQ_16(output_config , IVAS_AUDIO_CONFIG_5_1) || EQ_16(output_config , IVAS_AUDIO_CONFIG_5_1_2) || EQ_16(output_config , IVAS_AUDIO_CONFIG_5_1_4) || EQ_16(output_config , IVAS_AUDIO_CONFIG_7_1) || EQ_16(output_config , IVAS_AUDIO_CONFIG_7_1_4) || EQ_16(output_config , IVAS_AUDIO_CONFIG_LS_CUSTOM) ) - { - } - } - /*-----------------------------------------------------------------* - * CLDFB instances - *-----------------------------------------------------------------*/ - - IF ( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ,Q11) ) != IVAS_ERR_OK ) - { - return error; - } - - /*-----------------------------------------------------------------* - * JBM TC buffers - *-----------------------------------------------------------------*/ - - { - Word16 tc_nchan_full_new; - DECODER_TC_BUFFER_HANDLE hTcBuffer; - - hTcBuffer = st_ivas->hTcBuffer; - tc_buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas ); - tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); - tc_nchan_allocate_new = tc_nchan_tc_new; - tc_nchan_full_new = tc_nchan_tc_new; - - IF ( EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_PARAMETRIC) || EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_PARAMETRIC_ROOM) || EQ_16(st_ivas->renderer_type , RENDERER_STEREO_PARAMETRIC) ) - { - tc_nchan_allocate_new = 2 * BINAURAL_CHANNELS; - tc_nchan_full_new = tc_nchan_allocate_new; - } - - IF ( EQ_16(st_ivas->mc_mode , MC_MODE_PARAMMC) && NE_16(st_ivas->hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_MONO) && NE_16(st_ivas->hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_STEREO) ) - { - tc_nchan_full_new = 0; - } - ELSE IF ( EQ_16(st_ivas->mc_mode , MC_MODE_PARAMUPMIX) ) - { - tc_nchan_allocate_new = MC_PARAMUPMIX_MAX_INPUT_CHANS; - tc_buffer_mode_new = TC_BUFFER_MODE_RENDERER; - IF ( EQ_16(st_ivas->hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_STEREO) || EQ_16(st_ivas->hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_MONO) ) - { - tc_buffer_mode_new = TC_BUFFER_MODE_BUFFER; - tc_nchan_tc_new = st_ivas->hDecoderConfig->nchan_out; - tc_nchan_allocate_new = tc_nchan_tc_new; } - tc_nchan_full_new = tc_nchan_allocate_new; } - /* reconfigure buffer */ - IF ( NE_16(hTcBuffer->tc_buffer_mode , tc_buffer_mode_new) || NE_16(hTcBuffer->nchan_transport_jbm , tc_nchan_tc_new) || - NE_16(hTcBuffer->nchan_buffer_full , tc_nchan_full_new) || NE_16(hTcBuffer->nchan_transport_internal , tc_nchan_allocate_new) || - NE_16(tc_granularity_new , hTcBuffer->n_samples_granularity) ) - { - IF ( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ) != IVAS_ERR_OK ) - { - return error; - } - } - /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ - IF ( st_ivas->hSpatParamRendCom != NULL ) - { - st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; - st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; - st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; - st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; - Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); - } - ELSE IF ( st_ivas->hParamMC != NULL ) - { - st_ivas->hParamMC->nb_subframes = st_ivas->hTcBuffer->nb_subframes; - st_ivas->hParamMC->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; - st_ivas->hParamMC->num_slots = st_ivas->hTcBuffer->num_slots; - st_ivas->hParamMC->slots_rendered = st_ivas->hTcBuffer->slots_rendered; - Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hParamMC->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); - } + st_ivas->transport_config = signaled_config; } + return IVAS_ERR_OK; +} - /*-----------------------------------------------------------------* - * floating-point output audio buffers - *-----------------------------------------------------------------*/ - - nchan_out_buff = ivas_get_nchan_buffers_dec_ivas_fx( st_ivas, -1, -1 ); - IF( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) - { - return error; - } -#if 1/*TODO: To be removed later*/ - if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif - return error; -} -#else +/*------------------------------------------------------------------------- + * ivas_mc_dec_reconfig() + * + * reconfigure the MC format decoder + *-------------------------------------------------------------------------*/ static ivas_error ivas_mc_dec_reconfig( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -3455,4 +2635,3 @@ static ivas_error ivas_mc_dec_reconfig( return error; } -#endif // IVAS_FLOAT_FIXED diff --git a/lib_dec/ivas_stereo_dft_dec.c b/lib_dec/ivas_stereo_dft_dec.c index d0381d674..d178c08fc 100644 --- a/lib_dec/ivas_stereo_dft_dec.c +++ b/lib_dec/ivas_stereo_dft_dec.c @@ -546,6 +546,7 @@ void stereo_dft_dec_open( * Reset DFT stereo memories *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void stereo_dft_dec_reset( STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i/o: decoder DFT stereo handle */ ) @@ -847,7 +848,135 @@ void stereo_dft_dec_reset( return; } +#else + +void stereo_dft_dec_reset( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i/o: decoder DFT stereo handle */ +) +{ + int16_t i; + int16_t j, b; + + /*Configuration*/ + set_s( hStereoDft->prm_res, hStereoDft->hConfig->prm_res, STEREO_DFT_DEC_DFT_NB ); + + /* SIDE_GAIN */ + set_s( hStereoDft->side_gain_index, 15, STEREO_DFT_BAND_MAX ); + set_s( hStereoDft->side_gain_index_previous, 15, STEREO_DFT_BAND_MAX ); + + /*residual prediction*/ + set_s( hStereoDft->res_pred_mode, hStereoDft->hConfig->res_pred_mode, STEREO_DFT_DEC_DFT_NB ); + for ( i = 0; i < STEREO_DFT_PAST_MAX; i++ ) + { + set_zero( hStereoDft->DFT_past_DMX[i], STEREO_DFT32MS_N_32k ); + set_zero( hStereoDft->past_res_pred_gain[i], STEREO_DFT_BAND_MAX ); + } + + hStereoDft->past_DMX_pos = 0; + + set_s( hStereoDft->res_pred_index_previous, 0, STEREO_DFT_BAND_MAX ); + + for ( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) + { + hStereoDft->res_gains_ind[0][i] = 15.f; + } + + set_zero( hStereoDft->res_gains_ind[1], STEREO_DFT_BAND_MAX ); + + /*residual coding*/ + set_s( hStereoDft->res_cod_mode, hStereoDft->hConfig->res_cod_mode, STEREO_DFT_DEC_DFT_NB ); + hStereoDft->res_cod_band_max = dft_band_res_cod[hStereoDft->hConfig->band_res][hStereoDft->hConfig->res_cod_mode]; + set_zero( hStereoDft->res_cod_mem, STEREO_DFT_OVL_8k ); + + hStereoDft->res_pred_band_min = max( STEREO_DFT_RES_PRED_BAND_MIN, hStereoDft->res_cod_band_max ); + + hStereoDft->stab_fac_smooth_res = 0.f; + bass_psfilter_init( hStereoDft->hBpf ); + + tcxltp_dec_init( hStereoDft->hTcxLtpDec, 0, MODE1, IVAS_CPE_DFT, PIT_MAX, 12800 ); + + hStereoDft->reverb_flag = 0; + + hStereoDft->bpf_error_signal_last = 0.0f; + hStereoDft->bpf_error_ratio_mem = 1.0f; + hStereoDft->res_hb_nrg_mem = 0.0f; + + /*reset parameters*/ + set_zero( hStereoDft->side_gain, STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX ); + set_zero( hStereoDft->gipd, STEREO_DFT_DEC_DFT_NB ); + set_zero( hStereoDft->itd, STEREO_DFT_DEC_DFT_NB ); + set_zero( hStereoDft->res_pred_gain, STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX ); + + hStereoDft->wasTransient = 0; + hStereoDft->attackPresent = 0; + + hStereoDft->lt_pred_gain = 0.0f; + hStereoDft->lt_pred_gain_variation = 0.0f; + hStereoDft->lt_var_mean_ratio = STEREO_DFT_RES_RATIO_LIMIT; + hStereoDft->stefi_short_gain = 1.0f; + hStereoDft->stefi_long_gain = 0.0f; + + set_zero( hStereoDft->g_state, STEREO_DFT_BAND_MAX ); + + init_basic_allpass( &hStereoDft->ap1, dft_ap_gains[0], dft_ap_delays[0] ); + init_basic_allpass( &hStereoDft->ap2, dft_ap_gains[1], dft_ap_delays[1] ); + init_basic_allpass( &hStereoDft->ap3, dft_ap_gains[2], dft_ap_delays[2] ); + + set_zero( hStereoDft->ap_delay_mem, NS2SA( 16000, DELAY_BWE_TOTAL_NS ) ); + set_zero( hStereoDft->ap_fade_mem, STEREO_DFT_ALLPASS_FADELEN_16k ); + hStereoDft->ap_wasTransient = 0; + set_zero( hStereoDft->smooth_dmx_nrg, STEREO_DFT_BAND_MAX ); + set_zero( hStereoDft->smooth_res_nrg, STEREO_DFT_BAND_MAX ); + + set_s( hStereoDft->core_hist, ACELP_CORE, STEREO_DFT_CORE_HIST_MAX ); + + set_zero( hStereoDft->hb_stefi_sig, L_FRAME48k + NS2SA( 48000, STEREO_DFT_TD_STEFI_DELAY_NS ) ); + set_zero( hStereoDft->hb_nrg, STEREO_DFT_CORE_HIST_MAX ); + set_zero( hStereoDft->td_gain, STEREO_DFT_CORE_HIST_MAX ); + + /* PLC parameters */ + set_zero( hStereoDft->res_mem, STEREO_DFT_RES_BW_MAX ); + hStereoDft->time_offs = 0; + hStereoDft->past_dmx_nrg = 0; + hStereoDft->sg_mean = 0.0f; + hStereoDft->sg_mem_corrupt = 0; + hStereoDft->recovery_flg = 0; + for ( i = 0; i < SBA_DIRAC_STEREO_NUM_BANDS; i++ ) + { + set_zero( hStereoDft->smooth_buf[i], SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + set_zero( hStereoDft->smooth_fac[0], SBA_DIRAC_STEREO_NUM_BANDS ); + set_zero( hStereoDft->smooth_fac[1], SBA_DIRAC_STEREO_NUM_BANDS ); + + hStereoDft->itd_xfade_target = 0.0f; + hStereoDft->itd_xfade_step = 0.0f; + hStereoDft->itd_xfade_counter = 0; + hStereoDft->itd_xfade_prev = 0.0f; + hStereoDft->last_active_element_brate = 0; + hStereoDft->ipd_xfade_target = 0.0f; + hStereoDft->ipd_xfade_step = 0.0f; + hStereoDft->ipd_xfade_counter = 0; + hStereoDft->ipd_xfade_prev = 0.0f; + + for ( b = 0; b < hStereoDft->nbands; b++ ) + { + for ( i = 0; i < 2; i++ ) + { + for ( j = 0; j < 4; j++ ) + { + hStereoDft->mixer_mat_smooth[i][j][b] = 0.0f; + } + } + } + hStereoDft->first_frame = 1; + hStereoDft->g_L_prev = 0.f; + hStereoDft->g_R_prev = 0.f; + + return; +} + +#endif /*------------------------------------------------------------------------- * stereo_dft_dec_update() * diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 9dec7e9d4..ef7b6f36a 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -2960,12 +2960,6 @@ void ivas_rend_closeCrend( hCrend->lfe_delay_line = NULL; } - if ( hCrend->lfe_delay_line_fx != NULL ) - { - free( hCrend->lfe_delay_line_fx); - hCrend->lfe_delay_line_fx = NULL; - } - if ( hCrend->freq_buffer_re_diffuse != NULL ) { free( hCrend->freq_buffer_re_diffuse ); diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 2ff4360b9..f8e577f69 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1806,8 +1806,6 @@ typedef struct ivas_binaural_td_rendering_struct TDREND_SRC_t *Sources[MAX_NUM_TDREND_CHANNELS]; #ifdef IVAS_FLOAT_FIXED - Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; - Word16 num_src; Word16 Gain_fx; /* Q14 */ #endif // IVAS_FLOAT_FIXED -- GitLab