From 147f3eead0d3bfe577db430ef43d6ea18a1ae64f Mon Sep 17 00:00:00 2001 From: Andrea Eichenseer Date: Tue, 5 Sep 2023 17:37:49 +0200 Subject: [PATCH 01/10] Refactoring of ParamISM (issue 768) under switch PARAM_ISM_REFACTOR. --- lib_com/ivas_prot.h | 11 + lib_com/ivas_stat_com.h | 65 +- lib_com/options.h | 2 + lib_dec/ivas_dec.c | 5 + lib_dec/ivas_dirac_dec.c | 2 + lib_dec/ivas_init_dec.c | 4 + lib_dec/ivas_ism_dec.c | 4 + lib_dec/ivas_ism_dtx_dec.c | 12 + lib_dec/ivas_ism_param_dec.c | 1577 ++++++++++++++++++++++++++++++++++ lib_dec/ivas_jbm_dec.c | 10 + lib_dec/ivas_stat_dec.h | 51 ++ lib_enc/ivas_init_enc.c | 4 + lib_enc/ivas_ism_enc.c | 14 + lib_enc/ivas_ism_param_enc.c | 136 +++ lib_enc/ivas_stat_enc.h | 5 + 15 files changed, 1872 insertions(+), 30 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 6893be758d..d8a8d665ab 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1034,10 +1034,17 @@ void ivas_param_ism_enc( const int16_t input_frame /* i : input frame length per channel */ ); +#ifndef PARAM_ISM_REFACTOR void ivas_param_ism_enc_close( DIRAC_ENC_HANDLE *hDirAC, /* i/o: encoder DirAC handle */ const int32_t input_Fs /* i : input sampling_rate */ ); +#else +void ivas_param_ism_enc_close( + PARAM_ISM_CONFIG_HANDLE *hParamIsm, /* i/o: ParamISM handle */ + const int32_t input_Fs /* i : input sampling_rate */ +); +#endif void ivas_ism_metadata_close( ISM_METADATA_HANDLE hIsmMetaData[], /* i/o : object metadata handles */ @@ -1076,7 +1083,11 @@ ivas_error ivas_param_ism_dec_open( ); void ivas_param_ism_dec_close( +#ifndef PARAM_ISM_REFACTOR DIRAC_DEC_HANDLE *hDirAC, /* i/o: decoder DirAC handle */ +#else + PARAM_ISM_DEC_HANDLE *hParamIsmDec, /* i/o: decoder ParamISM handle */ +#endif SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */ const AUDIO_CONFIG output_config /* i : output audio configuration */ ); diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 4e9a7bff9f..1968fb2f80 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -150,36 +150,6 @@ typedef struct } ECSQ_instance; -/*----------------------------------------------------------------------------------* - * PARAMETRIC ISM encoder/decoder (common) structure - *----------------------------------------------------------------------------------*/ - -typedef struct ivas_param_ism_data_structure -{ - int16_t nbands; - int16_t nblocks[MAX_PARAM_ISM_NBANDS]; - int16_t band_grouping[MAX_PARAM_ISM_NBANDS + 1]; - - int16_t azi_index[MAX_NUM_OBJECTS]; - int16_t ele_index[MAX_NUM_OBJECTS]; - - int16_t obj_indices[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS][MAX_PARAM_ISM_WAVE]; - int16_t power_ratios_idx[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS]; - - int16_t last_az_sgn[MAX_NUM_OBJECTS]; - int16_t last_az_diff[MAX_NUM_OBJECTS]; - int16_t last_el_sgn[MAX_NUM_OBJECTS]; - int16_t last_el_diff[MAX_NUM_OBJECTS]; - - int16_t flag_noisy_speech; - int16_t noisy_speech_buffer[PARAM_ISM_HYS_BUF_SIZE]; - int16_t flag_equal_energy; - - float last_dmx_gain; - float last_cardioid_left[MAX_NUM_OBJECTS]; - -} PARAM_ISM_CONFIG_DATA, *PARAM_ISM_CONFIG_HANDLE; - /*----------------------------------------------------------------------------------* * Declaration of DirAC common (encoder & decoder) structure @@ -813,4 +783,39 @@ typedef struct ivas_fb_mixer_state_structure } IVAS_FB_MIXER_DATA, *IVAS_FB_MIXER_HANDLE; +/*----------------------------------------------------------------------------------* + * PARAMETRIC ISM encoder/decoder (common) structure + *----------------------------------------------------------------------------------*/ + +typedef struct ivas_param_ism_data_structure +{ +#ifdef PARAM_ISM_REFACTOR + IVAS_FB_MIXER_HANDLE hFbMixer; + +#endif + int16_t nbands; + int16_t nblocks[MAX_PARAM_ISM_NBANDS]; + int16_t band_grouping[MAX_PARAM_ISM_NBANDS + 1]; + + int16_t azi_index[MAX_NUM_OBJECTS]; + int16_t ele_index[MAX_NUM_OBJECTS]; + + int16_t obj_indices[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS][MAX_PARAM_ISM_WAVE]; + int16_t power_ratios_idx[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS]; + + int16_t last_az_sgn[MAX_NUM_OBJECTS]; + int16_t last_az_diff[MAX_NUM_OBJECTS]; + int16_t last_el_sgn[MAX_NUM_OBJECTS]; + int16_t last_el_diff[MAX_NUM_OBJECTS]; + + int16_t flag_noisy_speech; + int16_t noisy_speech_buffer[PARAM_ISM_HYS_BUF_SIZE]; + int16_t flag_equal_energy; + + float last_dmx_gain; + float last_cardioid_left[MAX_NUM_OBJECTS]; + +} PARAM_ISM_CONFIG_DATA, *PARAM_ISM_CONFIG_HANDLE; + + #endif /* IVAS_STAT_COM */ diff --git a/lib_com/options.h b/lib_com/options.h index 4eac787b42..7cbb1dc559 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -158,6 +158,8 @@ #define OSBA_SPLIT_RENDERING #endif +#define PARAM_ISM_REFACTOR /* FhG: Issue 768: Refactoring to decouple hDirAC and hParamISM */ + /* #################### End BE switches ################################## */ /* #################### Start NON-BE switches ############################ */ diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 8d41109c07..d36794c9a9 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -188,8 +188,13 @@ ivas_error ivas_dec( } else if ( st_ivas->ism_mode == ISM_MODE_PARAM ) { +#ifndef PARAM_ISM_REFACTOR if ( ( error = ivas_ism_metadata_dec( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, st_ivas->hDirAC->hParamIsm, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_ism_metadata_dec( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, st_ivas->hParamIsmDec->hParamIsm, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, + st_ivas->hSCE[0]->hCoreCoder[0] ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index fd94409a02..38a1d1dd13 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -85,8 +85,10 @@ static ivas_error ivas_dirac_dec_config_internal( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC Config\n" ) ); } +#ifndef PARAM_ISM_REFACTOR hDirAC->hParamIsm = NULL; hDirAC->hParamIsmRendering = NULL; +#endif st_ivas->hDirAC = hDirAC; } diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 6a462fcd25..db15e6b8d8 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -2556,7 +2556,11 @@ void ivas_destroy_dec( /* DirAC handle */ if ( st_ivas->ivas_format == ISM_FORMAT ) { +#ifndef PARAM_ISM_REFACTOR ivas_param_ism_dec_close( &( st_ivas->hDirAC ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); +#else + ivas_param_ism_dec_close( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); +#endif } else { diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index d83fd7ff07..17a313edd4 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -177,7 +177,11 @@ static ivas_error ivas_ism_bitrate_switching_dec( if ( st_ivas->ism_mode == ISM_MODE_DISC && last_ism_mode == ISM_MODE_PARAM ) { /* Deallocate the ParamISM struct */ +#ifndef PARAM_ISM_REFACTOR ivas_param_ism_dec_close( &( st_ivas->hDirAC ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); +#else + ivas_param_ism_dec_close( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); +#endif if ( st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL || st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB #ifdef SPLIT_REND_WITH_HEAD_ROT diff --git a/lib_dec/ivas_ism_dtx_dec.c b/lib_dec/ivas_ism_dtx_dec.c index cf5d6311b9..011f6a6608 100644 --- a/lib_dec/ivas_ism_dtx_dec.c +++ b/lib_dec/ivas_ism_dtx_dec.c @@ -116,10 +116,17 @@ ivas_error ivas_ism_dtx_dec( if ( ivas_total_brate == IVAS_SID_5k2 && !st_ivas->bfi ) { +#ifndef PARAM_ISM_REFACTOR if ( st_ivas->hDirAC != NULL ) { st_ivas->hDirAC->hParamIsm->flag_noisy_speech = flag_noisy_speech; } +#else + if ( st_ivas->hParamIsmDec != NULL ) + { + st_ivas->hParamIsmDec->hParamIsm->flag_noisy_speech = flag_noisy_speech; + } +#endif st_ivas->hISMDTX.sce_id_dtx = sce_id_dtx; } @@ -130,8 +137,13 @@ ivas_error ivas_ism_dtx_dec( { for ( ch = 0; ch < nchan_ism; ch++ ) { +#ifndef PARAM_ISM_REFACTOR st_ivas->hDirAC->azimuth_values[ch] = st_ivas->hIsmMetaData[ch]->azimuth; st_ivas->hDirAC->elevation_values[ch] = st_ivas->hIsmMetaData[ch]->elevation; +#else + st_ivas->hParamIsmDec->azimuth_values[ch] = st_ivas->hIsmMetaData[ch]->azimuth; + st_ivas->hParamIsmDec->elevation_values[ch] = st_ivas->hIsmMetaData[ch]->elevation; +#endif } } diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index bf60d8c4d3..635da7972d 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -45,6 +45,7 @@ #include "wmc_auto.h" +#ifndef PARAM_ISM_REFACTOR /*-----------------------------------------------------------------------* * Local function definitions *-----------------------------------------------------------------------*/ @@ -1619,3 +1620,1579 @@ void ivas_param_ism_params_to_masa_param_mapping( return; } + + +#else +/*-----------------------------------------------------------------------* + * Local function definitions + *-----------------------------------------------------------------------*/ + +static void ivas_param_ism_dec_dequant_DOA( + PARAM_ISM_DEC_HANDLE hParamIsmDec, /* i/o: decoder ParamISM handle */ + const int16_t nchan_ism /* i : number of ISM channels */ +) +{ + int16_t i; + PARAM_ISM_CONFIG_HANDLE hParamIsm; + + hParamIsm = hParamIsmDec->hParamIsm; + + assert( nchan_ism <= MAX_NUM_OBJECTS ); + + /* Get the azimuth and elevation values */ + for ( i = 0; i < nchan_ism; i++ ) + { + hParamIsmDec->azimuth_values[i] = ism_dequant_meta( hParamIsm->azi_index[i], ism_azimuth_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_AZIMUTH_NBITS ); + hParamIsmDec->elevation_values[i] = ism_dequant_meta( hParamIsm->ele_index[i], ism_elevation_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_ELEVATION_NBITS ); + } + + return; +} + + +static void ivas_param_ism_dec_dequant_powrat( + PARAM_ISM_DEC_HANDLE hParamIsmDec /* i/o: decoder ParamISM handle */ +) +{ + int16_t band_idx, slot_idx; + PARAM_ISM_CONFIG_HANDLE hParamIsm; + + hParamIsm = hParamIsmDec->hParamIsm; + + /* Get the power ratio values */ + for ( band_idx = 0; band_idx < hParamIsm->nbands; band_idx++ ) + { + for ( slot_idx = 0; slot_idx < hParamIsm->nblocks[band_idx]; slot_idx++ ) + { + hParamIsmDec->power_ratios[band_idx][slot_idx][0] = (float) ( hParamIsm->power_ratios_idx[band_idx][slot_idx] ) / (float) ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) / 2.0f + 0.5f; + hParamIsmDec->power_ratios[band_idx][slot_idx][1] = 1.0f - hParamIsmDec->power_ratios[band_idx][slot_idx][0]; + } + } + + return; +} + +static void ivas_ism_get_interpolator( + const int16_t subframe_nbslots, + float *interpolator ) +{ + int16_t interp_idx = 0; + + for ( interp_idx = 0; interp_idx < subframe_nbslots; interp_idx++ ) + { + interpolator[interp_idx] = (float) ( interp_idx + 1 ) / (float) subframe_nbslots; + } + + return; +} + + +static void ivas_ism_get_proto_matrix( + IVAS_OUTPUT_SETUP hOutSetup, + const int16_t nchan_transport, + float *proto_matrix ) +{ + int16_t idx; + + /* compute proto_matrix */ + switch ( nchan_transport ) + { + case 2: + { + if ( hOutSetup.nchan_out_woLFE ) + { + for ( idx = 0; idx < hOutSetup.nchan_out_woLFE; idx++ ) + { + if ( hOutSetup.ls_azimuth[idx] > 0.0f ) + { + proto_matrix[idx] = 1.0f; + proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 0.0f; + } + else if ( hOutSetup.ls_azimuth[idx] < 0.0f ) + { + proto_matrix[idx] = 0.0f; + proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 1.0f; + } + else + { + proto_matrix[idx] = 0.5f; + proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 0.5f; + } + } + } + else + { + assert( 0 && "Error: number of output channels not supported" ); + } + break; + } + + default: + assert( 0 && "Error: number of transport channels not supported" ); + } + + return; +} + + +static void ivas_param_ism_collect_slot( + PARAM_ISM_DEC_HANDLE hParamIsmDec, /* i/o: decoder ParamISM handle */ + float *Cldfb_RealBuffer_in, + float *Cldfb_ImagBuffer_in, + const int16_t ch, + float ref_power[], + float cx_diag[][PARAM_ISM_MAX_DMX] ) +{ + + int16_t band_idx, bin_idx; + int16_t brange[2]; + float tmp; + + /* loop over parameter bands to collect transport channel energies */ + for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ ) + { + brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx]; + brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1]; + for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ ) + { + tmp = 0.0f; + tmp += ( Cldfb_RealBuffer_in[bin_idx] * Cldfb_RealBuffer_in[bin_idx] ); + tmp += ( Cldfb_ImagBuffer_in[bin_idx] * Cldfb_ImagBuffer_in[bin_idx] ); + cx_diag[bin_idx][ch] += tmp; + ref_power[bin_idx] += tmp; + } + } + + return; +} + + +static void ivas_param_ism_compute_mixing_matrix( + const int16_t nchan_ism, /* i : number of ISM channels */ + PARAM_ISM_DEC_HANDLE hParamIsmDec, /* i/o: decoder ParamISM handle */ + ISM_DTX_DATA_DEC hISMDTX, /* i : ISM DTX handle */ + float direct_response[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN], + const int16_t nchan_transport, + const int16_t nchan_out_woLFE, + float cx_diag[][PARAM_ISM_MAX_DMX], + float ref_power[], + float mixing_matrix[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX] ) +{ + int16_t band_idx, bin_idx; + int16_t i, w, obj_indx; + int16_t brange[2]; + float direct_power[MAX_NUM_OBJECTS]; + float cy_diag[PARAM_ISM_MAX_CHAN]; + float cy_diag_tmp[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN]; + float *dir_res_ptr; + float *proto_matrix; + float response_matrix[PARAM_ISM_MAX_CHAN * MAX_NUM_OBJECTS]; + int16_t num_wave; + + proto_matrix = hParamIsmDec->hParamIsmRendering->proto_matrix; + + assert( ( nchan_ism == 3 ) || ( nchan_ism == 4 ) ); + assert( nchan_transport == 2 ); + + if ( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag ) + { + num_wave = nchan_ism; + } + else + { + num_wave = MAX_PARAM_ISM_WAVE; + } + set_zero( response_matrix, PARAM_ISM_MAX_CHAN * MAX_NUM_OBJECTS ); + + /* loop over parameter bands to compute the mixing matrix */ + for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ ) + { + brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx]; + brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1]; + + /* Compute covaraince matrix from direct response*/ + for ( w = 0; w < num_wave; w++ ) + { + set_zero( cy_diag_tmp[w], nchan_out_woLFE ); + + if ( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag ) + { + dir_res_ptr = direct_response[w]; + } + else + { + obj_indx = hParamIsmDec->hParamIsm->obj_indices[band_idx][0][w]; + dir_res_ptr = direct_response[obj_indx]; + } + mvr2r( dir_res_ptr, response_matrix + w * nchan_out_woLFE, nchan_out_woLFE ); + /* we only need the diagonal of Cy*/ + matrix_product_diag( dir_res_ptr, nchan_out_woLFE, 1, 0, dir_res_ptr, 1, nchan_out_woLFE, 0, cy_diag_tmp[w] ); + } + + for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ ) + { + + set_zero( cy_diag, nchan_out_woLFE ); + for ( w = 0; w < num_wave; w++ ) + { + if ( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag ) + { + direct_power[w] = ( 1.0f / nchan_ism ) * ref_power[bin_idx]; + } + else + { + direct_power[w] = hParamIsmDec->power_ratios[band_idx][0][w] * ref_power[bin_idx]; + } + + if ( direct_power[w] != 0.f ) + { + for ( i = 0; i < nchan_out_woLFE; i++ ) + { + cy_diag[i] += direct_power[w] * cy_diag_tmp[w][i]; + } + } + direct_power[w] = sqrtf( direct_power[w] ); + } + /* Compute mixing matrix */ + computeMixingMatricesISM( nchan_transport, num_wave, nchan_out_woLFE, response_matrix, direct_power, cx_diag[bin_idx], cy_diag, proto_matrix, 1, + PARAM_MC_REG_SX, PARAM_MC_REG_GHAT, mixing_matrix[bin_idx] ); + } + } + + return; +} + + +static void ivas_param_ism_render_slot( + PARAM_ISM_DEC_HANDLE hParamIsmDec, + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, + float *Cldfb_RealBuffer_in[PARAM_ISM_MAX_DMX], + float *Cldfb_ImagBuffer_in[PARAM_ISM_MAX_DMX], + float Cldfb_RealBuffer[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + float Cldfb_ImagBuffer[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + float mixing_matrix[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], + const int16_t interpolator_idx, + const int16_t out_slot_idx, + const int16_t num_ch_LS, + const int16_t nchan_transport ) +{ + int16_t outchIdx, inchIdx, bin_idx; + float tmp_1, mixing_matrix_smooth; + + tmp_1 = hParamIsmDec->hParamIsmRendering->interpolator[interpolator_idx]; + + for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ ) + { + /* smooth the mixing matrix */ + for ( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ ) + { + for ( inchIdx = 0; inchIdx < nchan_transport; inchIdx++ ) + { + mixing_matrix_smooth = tmp_1 * mixing_matrix[bin_idx][outchIdx + inchIdx * num_ch_LS] + + ( 1 - tmp_1 ) * hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old[bin_idx][outchIdx + inchIdx * num_ch_LS]; + + Cldfb_RealBuffer[outchIdx][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_RealBuffer_in[inchIdx][bin_idx]; + Cldfb_ImagBuffer[outchIdx][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_ImagBuffer_in[inchIdx][bin_idx]; + } + } + } + + return; +} + + +static void ivas_param_ism_rendering( + PARAM_ISM_DEC_HANDLE hParamIsmDec, + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, + float Cldfb_RealBuffer_in[PARAM_ISM_MAX_DMX][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + float Cldfb_ImagBuffer_in[PARAM_ISM_MAX_DMX][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + float Cldfb_RealBuffer[PARAM_ISM_MAX_CHAN][4][CLDFB_NO_CHANNELS_MAX], + float Cldfb_ImagBuffer[PARAM_ISM_MAX_CHAN][4][CLDFB_NO_CHANNELS_MAX], + float mixing_matrix[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], + const int16_t out_slot_idx, + const int16_t slot_idx, + const int16_t num_ch_LS, + const int16_t nchan_transport ) +{ + int16_t outchIdx, inchIdx, bin_idx; + float tmp_1, mixing_matrix_smooth; + + tmp_1 = hParamIsmDec->hParamIsmRendering->interpolator[slot_idx]; + + for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ ) + { + /* smooth the mixing matrix */ + for ( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ ) + { + for ( inchIdx = 0; inchIdx < nchan_transport; inchIdx++ ) + { + mixing_matrix_smooth = tmp_1 * mixing_matrix[bin_idx][outchIdx + inchIdx * num_ch_LS] + + ( 1 - tmp_1 ) * hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old[bin_idx][outchIdx + inchIdx * num_ch_LS]; + + Cldfb_RealBuffer[outchIdx][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_RealBuffer_in[inchIdx][slot_idx][bin_idx]; + Cldfb_ImagBuffer[outchIdx][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_ImagBuffer_in[inchIdx][slot_idx][bin_idx]; + } + } + } + + return; +} + + +static ivas_error ivas_param_ism_rendering_init( + PARAM_ISM_RENDERING_HANDLE hParamIsmRendering, + IVAS_OUTPUT_SETUP hOutSetup, + const int16_t nchan_transport, + const int16_t subframe_nbslots, + AUDIO_CONFIG output_config ) +{ + int16_t bin_idx; + + /* initialization of mixing matrix buffer for smoothing */ + for ( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ ) + { + set_zero( hParamIsmRendering->mixing_matrix_lin_old[bin_idx], PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX ); + } + + /* memory allocation for proto matrix and interpolator */ + if ( ( hParamIsmRendering->proto_matrix = (float *) malloc( hOutSetup.nchan_out_woLFE * nchan_transport * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for proto matrix\n" ) ); + } + if ( ( hParamIsmRendering->interpolator = (float *) malloc( subframe_nbslots * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for interpolator\n" ) ); + } + +#ifdef SPLIT_REND_WITH_HEAD_ROT_PARAMBIN + if ( !( output_config == AUDIO_CONFIG_EXTERNAL || output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB || output_config == AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) +#else + if ( !( output_config == AUDIO_CONFIG_EXTERNAL || output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) +#endif + { + /* computation of proto matrix */ + ivas_ism_get_proto_matrix( hOutSetup, nchan_transport, hParamIsmRendering->proto_matrix ); + } + + /* computation of interpolator*/ + ivas_ism_get_interpolator( subframe_nbslots, hParamIsmRendering->interpolator ); + + return IVAS_ERR_OK; +} + + +static void ivas_param_ism_update_mixing_matrix( + PARAM_ISM_DEC_HANDLE hParamIsmDec, + float mixing_matrix[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], + const int16_t nchan_in, + const int16_t nchan_out ) +{ + int16_t inchIdx, outchIdx, bin_idx, band_idx; + int16_t brange[2]; + + for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ ) + { + brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx]; + brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1]; + + for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ ) + { + for ( inchIdx = 0; inchIdx < nchan_in; inchIdx++ ) + { + for ( outchIdx = 0; outchIdx < nchan_out; outchIdx++ ) + { + hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old[bin_idx][outchIdx + inchIdx * nchan_out] = mixing_matrix[bin_idx][outchIdx + inchIdx * nchan_out]; + } + } + } + } + + return; +} + + +/*-------------------------------------------------------------------------* + * ivas_param_ism_dec_open() + * + * Open Param ISM handle + *-------------------------------------------------------------------------*/ + +ivas_error ivas_param_ism_dec_open( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + int16_t i; + PARAM_ISM_DEC_HANDLE hParamIsmDec; + IVAS_OUTPUT_SETUP hOutSetup; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + AUDIO_CONFIG output_config; + int32_t output_Fs; + ivas_error error; + + error = IVAS_ERR_OK; + + push_wmops( "ivas_param_ism_dec_open" ); + + /*-----------------------------------------------------------------* + * prepare library opening + *-----------------------------------------------------------------*/ + + if ( ( hParamIsmDec = (PARAM_ISM_DEC_HANDLE) malloc( sizeof( PARAM_ISM_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM\n" ) ); + } + + if ( ( hSpatParamRendCom = (SPAT_PARAM_REND_COMMON_DATA_HANDLE) malloc( sizeof( SPAT_PARAM_REND_COMMON_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + /* Assign memory to Param Object handle */ + if ( ( hParamIsmDec->hParamIsm = (PARAM_ISM_CONFIG_HANDLE) malloc( sizeof( PARAM_ISM_CONFIG_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM\n" ) ); + } + + if ( ( hParamIsmDec->hParamIsmRendering = (PARAM_ISM_RENDERING_HANDLE) malloc( sizeof( PARAM_ISM_RENDERING_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM Rendering handle\n" ) ); + } + + output_Fs = st_ivas->hDecoderConfig->output_Fs; + output_config = st_ivas->hDecoderConfig->output_config; + + ivas_param_ism_config( hParamIsmDec->hParamIsm, st_ivas->nchan_ism ); + + /*-----------------------------------------------------------------* + * set input parameters + *-----------------------------------------------------------------*/ + + hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); + set_s( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); + set_s( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); + hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; + hSpatParamRendCom->subframes_rendered = 0; + hSpatParamRendCom->slots_rendered = 0; + hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; + hSpatParamRendCom->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); + + hParamIsmDec->hParamIsm->nbands = MAX_PARAM_ISM_NBANDS; + + for ( i = 0; i < ( hParamIsmDec->hParamIsm->nbands + 1 ); i++ ) + { + hParamIsmDec->hParamIsm->band_grouping[i] = Param_ISM_band_grouping[i]; + + if ( hParamIsmDec->hParamIsm->band_grouping[i] > hSpatParamRendCom->num_freq_bands ) + { + hParamIsmDec->hParamIsm->band_grouping[i] = hSpatParamRendCom->num_freq_bands; + } + } + + /*-----------------------------------------------------------------* + * output setup + *-----------------------------------------------------------------*/ + + /* hIntSetup and hOutSetup differs only for Binaural rendering */ + if ( output_config == AUDIO_CONFIG_EXTERNAL ) + { + /* nchan_out is essential for memory initialization for CLDFB Synthesis */ + st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->nchan_ism; + st_ivas->hIntSetup.is_loudspeaker_setup = 1; + } + + hOutSetup = st_ivas->hIntSetup; + + if ( !( output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO ) ) + { + /* Initialize Param ISM Rendering handle */ + if ( st_ivas->hDecoderConfig->Opt_tsm ) + { + if ( ( error = ivas_param_ism_rendering_init( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, MAX_JBM_CLDFB_TIMESLOTS, output_config ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + if ( ( error = ivas_param_ism_rendering_init( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, CLDFB_NO_COL_MAX, output_config ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + +#ifdef SPLIT_REND_WITH_HEAD_ROT_PARAMBIN + if ( !( output_config == AUDIO_CONFIG_EXTERNAL || output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB || + output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO || output_config == AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) +#else + if ( !( output_config == AUDIO_CONFIG_EXTERNAL || output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB || + output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO ) ) +#endif + { + /* Initialize efap handle */ + if ( ( error = efap_init_data( &( st_ivas->hEFAPdata ), hOutSetup.ls_azimuth, hOutSetup.ls_elevation, hOutSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* Azi and Ele values are transmitted once per frame per object */ + set_zero( hParamIsmDec->azimuth_values, MAX_NUM_OBJECTS ); + set_zero( hParamIsmDec->elevation_values, MAX_NUM_OBJECTS ); + + hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; + hSpatParamRendCom->dirac_bs_md_write_idx = 0; + hSpatParamRendCom->dirac_read_idx = 0; + +#ifdef SPLIT_REND_WITH_HEAD_ROT_PARAMBIN + if ( output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB || output_config == AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) +#else + if ( output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) +#endif + { + if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + st_ivas->hISMDTX.dtx_flag = 0; + + st_ivas->hParamIsmDec = hParamIsmDec; + st_ivas->hSpatParamRendCom = hSpatParamRendCom; + + if ( st_ivas->hDecoderConfig->Opt_5ms ) + { + if ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE ) + { + int16_t nchan_transport = st_ivas->nchan_transport; + int16_t nchan_full = 0; + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) + { + nchan_full = nchan_transport; + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL; + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL; + } + else + { + int16_t n_slots_to_alloc; + if ( st_ivas->hDecoderConfig->Opt_tsm == 1 ) + { + n_slots_to_alloc = MAX_JBM_CLDFB_TIMESLOTS; + } + else + { + n_slots_to_alloc = CLDFB_SLOTS_PER_SUBFRAME * MAX_PARAM_SPATIAL_SUBFRAMES; + } + if ( ( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = (float *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) + + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); + } + set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands ); + + if ( ( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = (float *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); + } + set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands ); + } + if ( st_ivas->hTcBuffer == NULL ) + { + if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, nchan_full, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else + { + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL; + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL; + if ( st_ivas->hTcBuffer == NULL ) + { + int16_t nchan_to_allocate = st_ivas->hDecoderConfig->nchan_out; + if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_BUFFER, nchan_to_allocate, nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + } + else + { + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL; + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL; + } + + pop_wmops(); + return error; +} + + +/*-------------------------------------------------------------------------* + * ivas_param_ism_dec_close() + * + * Close Param ISM handle + *-------------------------------------------------------------------------*/ + +void ivas_param_ism_dec_close( + PARAM_ISM_DEC_HANDLE *hParamIsmDec_out, /* i/o: decoder DirAC handle */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */ + AUDIO_CONFIG output_config /* i : output audio configuration */ +) +{ + if ( hParamIsmDec_out != NULL && *hParamIsmDec_out != NULL ) + { + PARAM_ISM_DEC_HANDLE hParamIsmDec; + hParamIsmDec = *hParamIsmDec_out; + + /* Config & CLDFB */ + if ( hParamIsmDec->hParamIsm != NULL ) + { + free( hParamIsmDec->hParamIsm ); + hParamIsmDec->hParamIsm = NULL; + } + + if ( !( output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO ) ) + { + /* Param ISM Rendering */ + if ( hParamIsmDec->hParamIsmRendering->interpolator != NULL ) + { + free( hParamIsmDec->hParamIsmRendering->interpolator ); + hParamIsmDec->hParamIsmRendering->interpolator = NULL; + } + if ( hParamIsmDec->hParamIsmRendering->proto_matrix != NULL ) + { + free( hParamIsmDec->hParamIsmRendering->proto_matrix ); + hParamIsmDec->hParamIsmRendering->proto_matrix = NULL; + } + } + + if ( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc != NULL ) + { + free( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc ); + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL; + } + if ( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc != NULL ) + { + free( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc ); + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL; + } + + if ( hParamIsmDec->hParamIsmRendering != NULL ) + { + free( hParamIsmDec->hParamIsmRendering ); + hParamIsmDec->hParamIsmRendering = NULL; + } + + free( *hParamIsmDec_out ); + *hParamIsmDec_out = NULL; + } + + if ( hSpatParamRendCom_out != NULL && *hSpatParamRendCom_out != NULL ) + { + if ( output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + { + ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 1 ); + ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 2 ); + } + + free( *hSpatParamRendCom_out ); + *hSpatParamRendCom_out = NULL; + } + + return; +} + + +/*-------------------------------------------------------------------------* + * ivas_param_ism_dec() + * + * Param ISM decoder + *-------------------------------------------------------------------------*/ + +void ivas_param_ism_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float *output_f[] /* i/o: synthesized core-coder transport channels/DirAC output*/ +) +{ + int16_t ch, nchan_transport, nchan_out, nchan_out_woLFE, i; + int16_t subframe_idx, slot_idx, index_slot, bin_idx; + int32_t ivas_total_brate; + int16_t output_frame; + float *p_tc[PARAM_ISM_MAX_DMX]; + float ref_power[CLDFB_NO_CHANNELS_MAX]; + float cx_diag[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_DMX]; + /* CLDFB Input Buffers */ + float Cldfb_RealBuffer_in[PARAM_ISM_MAX_DMX][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_ImagBuffer_in[PARAM_ISM_MAX_DMX][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + + /* CLDFB Output Buffers */ + float Cldfb_RealBuffer[PARAM_ISM_MAX_CHAN][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_ImagBuffer[PARAM_ISM_MAX_CHAN][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; + + /* Direct Response/EFAP Gains */ + float direct_response[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN]; + + /* Covariance Rendering */ + float mixing_matrix[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX]; + + PARAM_ISM_DEC_HANDLE hParamIsmDec; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + + IVAS_OUTPUT_SETUP hSetup; + + /* Initialization */ + hParamIsmDec = st_ivas->hParamIsmDec; + assert( hParamIsmDec ); + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + assert( hSpatParamRendCom ); + for ( i = 0; i < PARAM_ISM_MAX_DMX; i++ ) + { + p_tc[i] = output_f[i]; + } + output_frame = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); + + nchan_transport = st_ivas->nchan_transport; + if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) + { + nchan_out = st_ivas->nchan_ism; + nchan_out_woLFE = nchan_out; + st_ivas->hDecoderConfig->nchan_out = nchan_out; + } + else + { + nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; + nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE; + } + + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + + hSetup = st_ivas->hIntSetup; + + push_wmops( "ivas_param_ism_dec" ); + + /* set buffers to zero */ + for ( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ ) + { + set_zero( cx_diag[bin_idx], PARAM_ISM_MAX_DMX ); + } + set_zero( ref_power, CLDFB_NO_CHANNELS_MAX ); + + /* Frame-level Processing */ + /* De-quantization */ + if ( !( ivas_total_brate == IVAS_SID_5k2 || ivas_total_brate == FRAME_NO_DATA ) ) + { + ivas_param_ism_dec_dequant_DOA( hParamIsmDec, st_ivas->nchan_ism ); + ivas_param_ism_dec_dequant_powrat( hParamIsmDec ); + st_ivas->hISMDTX.dtx_flag = 0; + } + else + { + st_ivas->hISMDTX.dtx_flag = 1; + } + + /* obtain the direct response using EFAP */ + if ( !( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) ) + { + for ( i = 0; i < st_ivas->nchan_ism; i++ ) + { + efap_determine_gains( st_ivas->hEFAPdata, direct_response[i], hParamIsmDec->azimuth_values[i], hParamIsmDec->elevation_values[i], EFAP_MODE_EFAP ); + } + } + else + { + int16_t j; + + for ( i = 0; i < st_ivas->nchan_ism; i++ ) + { + for ( j = 0; j < nchan_out_woLFE; j++ ) + { + if ( i == j ) + { + direct_response[i][j] = 1.0f; + } + else + { + direct_response[i][j] = 0.0f; + } + } + } + + for ( j = 0; j < nchan_out_woLFE; j++ ) + { + if ( hParamIsmDec->azimuth_values[j] > 0.0f ) + { + hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 1.0f; + hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 0.0f; + } + else + { + if ( hParamIsmDec->azimuth_values[j] < 0.0f ) + { + hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 0.0f; + hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 1.0f; + } + else /* == 0.0f */ + { + hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 0.5f; + hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 0.5f; + } + } + } + } + ivas_ism_param_dec_tc_gain_ajust( st_ivas, output_frame, output_frame / 2, p_tc ); + for ( ch = 0; ch < nchan_transport; ch++ ) + { + /*-----------------------------------------------------------------* + * CLDFB Analysis + *-----------------------------------------------------------------*/ + for ( slot_idx = 0; slot_idx < CLDFB_NO_COL_MAX; slot_idx++ ) + { + cldfbAnalysis_ts( &( output_f[ch][hSpatParamRendCom->num_freq_bands * slot_idx] ), Cldfb_RealBuffer_in[ch][slot_idx], Cldfb_ImagBuffer_in[ch][slot_idx], hSpatParamRendCom->num_freq_bands, st_ivas->cldfbAnaDec[ch] ); + + ivas_param_ism_collect_slot( hParamIsmDec, Cldfb_RealBuffer_in[ch][slot_idx], Cldfb_ImagBuffer_in[ch][slot_idx], ch, ref_power, cx_diag ); + } + } + + /* Obtain Mixing Matrix on a frame-level */ + for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ ) + { + set_f( mixing_matrix[bin_idx], 0.0f, nchan_transport * nchan_out_woLFE ); + } + + /* Compute mixing matrix */ + ivas_param_ism_compute_mixing_matrix( st_ivas->nchan_ism, hParamIsmDec, st_ivas->hISMDTX, direct_response, nchan_transport, nchan_out_woLFE, cx_diag, ref_power, mixing_matrix ); + /* subframe loop for synthesis*/ + for ( subframe_idx = 0; subframe_idx < hSpatParamRendCom->nb_subframes; subframe_idx++ ) + { + uint16_t slot_idx_start = subframe_idx * hSpatParamRendCom->subframe_nbslots[subframe_idx]; + uint16_t idx_in; + uint16_t idx_lfe; + + /* Set some memories to zero */ + for ( ch = 0; ch < nchan_out_woLFE; ch++ ) + { + for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + set_f( Cldfb_RealBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands ); + set_f( Cldfb_ImagBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands ); + } + } + + for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + index_slot = slot_idx_start + slot_idx; + + /* Compute bandwise rendering to target LS using covariance rendering */ + ivas_param_ism_rendering( hParamIsmDec, hSpatParamRendCom, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, + Cldfb_RealBuffer, Cldfb_ImagBuffer, mixing_matrix, slot_idx, index_slot, + nchan_out_woLFE, nchan_transport ); + } + + /* CLDFB Synthesis */ + idx_in = 0; + idx_lfe = 0; + + for ( ch = 0; ch < nchan_out; ch++ ) + { + if ( ( hSetup.num_lfe > 0 ) && ( hSetup.index_lfe[idx_lfe] == ch ) ) + { + set_zero( &( output_f[ch][slot_idx_start * hSpatParamRendCom->num_freq_bands] ), hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands ); + if ( idx_lfe < ( hSetup.num_lfe - 1 ) ) + { + idx_lfe++; + } + } + else + { + float *RealBuffer[16]; + float *ImagBuffer[16]; + + /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ + for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) + { + RealBuffer[i] = Cldfb_RealBuffer[idx_in][i]; + ImagBuffer[i] = Cldfb_ImagBuffer[idx_in][i]; + } + + cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][slot_idx_start * hSpatParamRendCom->num_freq_bands] ), + hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] ); + + idx_in++; + } + } + } + + /* copy the memories */ + /* store mixing matrix for next subframe */ + ivas_param_ism_update_mixing_matrix( hParamIsmDec, mixing_matrix, nchan_transport, nchan_out_woLFE ); + + /* store MetaData parameters */ + for ( ch = 0; ch < st_ivas->nchan_ism; ch++ ) + { + if ( st_ivas->hParamIsmDec->azimuth_values[ch] > 180.0f ) + { + st_ivas->hIsmMetaData[ch]->azimuth = st_ivas->hParamIsmDec->azimuth_values[ch] - 360.0f; + } + else + { + st_ivas->hIsmMetaData[ch]->azimuth = st_ivas->hParamIsmDec->azimuth_values[ch]; + } + + st_ivas->hIsmMetaData[ch]->elevation = st_ivas->hParamIsmDec->elevation_values[ch]; + } + + pop_wmops(); + + return; +} + + +/*-------------------------------------------------------------------------* + * ivas_ism_dec_digest_tc() + * + * + *-------------------------------------------------------------------------*/ + +void ivas_ism_dec_digest_tc( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + + ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas ); + + if ( st_ivas->renderer_type == RENDERER_TD_PANNING || + 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_MIXER_CONV_ROOM && st_ivas->hDecoderConfig->Opt_Headrotation == 0 ) ) + { + int16_t i, num_objects; + int16_t azimuth, elevation; + + /* we have a full frame interpolator, adapt it */ + /* for BE testing */ + if ( ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ) == st_ivas->hTcBuffer->n_samples_available ) + { + int16_t interpolator_length = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); + if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) + { + st_ivas->hIsmRendererData->interpolator[0] = 0.0f; + for ( i = 1; i < interpolator_length; i++ ) + { + st_ivas->hIsmRendererData->interpolator[i] = st_ivas->hIsmRendererData->interpolator[i - 1] + 1.f / ( interpolator_length - 1 ); + } + } + else + { + for ( i = 0; i < interpolator_length; i++ ) + { + st_ivas->hIsmRendererData->interpolator[i] = (float) i / ( (float) interpolator_length - 1 ); + } + } + } + else + { + ivas_jbm_dec_get_adapted_linear_interpolator( (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ), st_ivas->hTcBuffer->n_samples_available, st_ivas->hIsmRendererData->interpolator ); + } + /* also get the gains here */ + num_objects = st_ivas->nchan_transport; + for ( i = 0; i < num_objects; i++ ) + { + mvr2r( st_ivas->hIsmRendererData->gains[i], st_ivas->hIsmRendererData->prev_gains[i], MAX_OUTPUT_CHANNELS ); + + if ( st_ivas->intern_config == AUDIO_CONFIG_STEREO ) + { + ivas_ism_get_stereo_gains( st_ivas->hIsmMetaData[i]->azimuth, + st_ivas->hIsmMetaData[i]->elevation, + &st_ivas->hIsmRendererData->gains[i][0], + &st_ivas->hIsmRendererData->gains[i][1] ); + } + else + { + // TODO tmu review when #215 is resolved + azimuth = (int16_t) floorf( st_ivas->hIsmMetaData[i]->azimuth + 0.5f ); + elevation = (int16_t) floorf( st_ivas->hIsmMetaData[i]->elevation + 0.5f ); + + if ( ( st_ivas->renderer_type == RENDERER_TD_PANNING || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) && + st_ivas->hCombinedOrientationData == NULL ) + { + if ( st_ivas->hIntSetup.is_planar_setup ) + { + /* If no elevation support in output format, then rendering should be done with zero elevation */ + elevation = 0; + } + + if ( st_ivas->hEFAPdata != NULL ) + { + efap_determine_gains( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains[i], azimuth, elevation, EFAP_MODE_EFAP ); + } + } + else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) + { + /*get HOA gets for direction (ACN/SN3D)*/ + ivas_dirac_dec_get_response( azimuth, elevation, st_ivas->hIsmRendererData->gains[i], st_ivas->hIntSetup.ambisonics_order ); + } + } + } + } + + return; +} + + +/*-------------------------------------------------------------------------* + * ivas_param_ism_dec_digest_tc() + * + * + *-------------------------------------------------------------------------*/ + +void ivas_param_ism_dec_digest_tc( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const uint16_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ + float *transport_channels_f[] /* i : synthesized core-coder transport channels/DirAC output */ +) +{ + int16_t ch, nchan_transport, nchan_out, nchan_out_woLFE, i; + int16_t slot_idx, bin_idx; + int32_t ivas_total_brate; + int16_t output_frame; + float ref_power[CLDFB_NO_CHANNELS_MAX]; + float cx_diag[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_DMX]; + /* Direct Response/EFAP Gains */ + float direct_response[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN]; + PARAM_ISM_DEC_HANDLE hParamIsmDec; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + int16_t fade_len; + + /* Initialization */ + hParamIsmDec = st_ivas->hParamIsmDec; + assert( hParamIsmDec ); + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + assert( hSpatParamRendCom ); + output_frame = nCldfbSlots * hSpatParamRendCom->num_freq_bands; + fade_len = output_frame / 2; + + nchan_transport = st_ivas->nchan_transport; + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + + if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) + { + nchan_out = st_ivas->nchan_ism; + nchan_out_woLFE = nchan_out; + st_ivas->hDecoderConfig->nchan_out = nchan_out; + } + else + { + nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; + nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE; + } + + push_wmops( "ivas_param_ism_dec" ); + + /* general setup */ + ivas_jbm_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hParamIsmDec->hParamIsmRendering->interpolator ); + + ivas_dirac_dec_set_md_map( st_ivas, nCldfbSlots ); + + /* set buffers to zero */ + for ( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ ) + { + set_zero( cx_diag[bin_idx], PARAM_ISM_MAX_DMX ); + } + set_zero( ref_power, CLDFB_NO_CHANNELS_MAX ); + + /* Frame-level Processing */ + /* De-quantization */ + if ( !( ivas_total_brate == IVAS_SID_5k2 || ivas_total_brate == FRAME_NO_DATA ) ) + { + ivas_param_ism_dec_dequant_DOA( hParamIsmDec, st_ivas->nchan_ism ); + ivas_param_ism_dec_dequant_powrat( hParamIsmDec ); + st_ivas->hISMDTX.dtx_flag = 0; + } + else + { + st_ivas->hISMDTX.dtx_flag = 1; + } + + /* obtain the direct response using EFAP */ + if ( !( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) ) + { + for ( i = 0; i < st_ivas->nchan_ism; i++ ) + { + efap_determine_gains( st_ivas->hEFAPdata, direct_response[i], hParamIsmDec->azimuth_values[i], hParamIsmDec->elevation_values[i], EFAP_MODE_EFAP ); + } + } + else + { + int16_t j; + + for ( i = 0; i < st_ivas->nchan_ism; i++ ) + { + for ( j = 0; j < nchan_out_woLFE; j++ ) + { + if ( i == j ) + { + direct_response[i][j] = 1.0f; + } + else + { + direct_response[i][j] = 0.0f; + } + } + } + + for ( j = 0; j < nchan_out_woLFE; j++ ) + { + if ( hParamIsmDec->azimuth_values[j] > 0.0f ) + { + hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 1.0f; + hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 0.0f; + } + else + { + if ( hParamIsmDec->azimuth_values[j] < 0.0f ) + { + hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 0.0f; + hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 1.0f; + } + else /* == 0.0f */ + { + hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 0.5f; + hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 0.5f; + } + } + } + } + if ( st_ivas->hDecoderConfig->Opt_tsm || !st_ivas->hDecoderConfig->Opt_5ms ) + { + /*TODO : FhG to check*/ + ivas_ism_param_dec_tc_gain_ajust( st_ivas, output_frame, fade_len, transport_channels_f ); + } + + for ( ch = 0; ch < nchan_transport; ch++ ) + { + /*-----------------------------------------------------------------* + * CLDFB Analysis + *-----------------------------------------------------------------*/ + for ( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ ) + { + if ( st_ivas->hDecoderConfig->Opt_tsm || !st_ivas->hDecoderConfig->Opt_5ms ) + { + + float RealBuffer[CLDFB_NO_CHANNELS_MAX]; + float ImagBuffer[CLDFB_NO_CHANNELS_MAX]; + + cldfbAnalysis_ts( &( transport_channels_f[ch][hSpatParamRendCom->num_freq_bands * slot_idx] ), RealBuffer, ImagBuffer, hSpatParamRendCom->num_freq_bands, st_ivas->cldfbAnaDec[ch] ); + mvr2r( RealBuffer, &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands ); + mvr2r( ImagBuffer, &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands ); + } + ivas_param_ism_collect_slot( hParamIsmDec, &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], ch, ref_power, cx_diag ); + } + } + + /* Obtain Mixing Matrix on a frame-level */ + for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ ) + { + set_f( hParamIsmDec->hParamIsmRendering->mixing_matrix_lin[bin_idx], 0.0f, nchan_transport * nchan_out_woLFE ); + } + + /* Compute mixing matrix */ + ivas_param_ism_compute_mixing_matrix( st_ivas->nchan_ism, hParamIsmDec, st_ivas->hISMDTX, direct_response, nchan_transport, nchan_out_woLFE, cx_diag, ref_power, hParamIsmDec->hParamIsmRendering->mixing_matrix_lin ); + + pop_wmops(); + + return; +} + + +/*-------------------------------------------------------------------------* + * ivas_ism_param_dec_tc_gain_ajust() + * + * + *-------------------------------------------------------------------------*/ + +void ivas_ism_param_dec_tc_gain_ajust( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const uint16_t nSamples, /* i : number of samples to be compensate */ + const uint16_t nFadeLength, /* i : length of the crossfade in samples */ + float *transport_channels_f[] /* i : synthesized core-coder transport channels/DirAC output */ +) + +{ + int16_t i; + float gain, ene_tc, ene_sum, grad; + float last_gain; + + ene_tc = 0.0f; + ene_sum = 0.0f; + last_gain = st_ivas->hParamIsmDec->hParamIsm->last_dmx_gain; + + + for ( i = 0; i < nSamples; i++ ) + { + ene_tc += transport_channels_f[0][i] * transport_channels_f[0][i] + transport_channels_f[1][i] * transport_channels_f[1][i]; // L*L + R*R + ene_sum += ( transport_channels_f[0][i] + transport_channels_f[1][i] ) * ( transport_channels_f[0][i] + transport_channels_f[1][i] ); // (L+R)*(L+R) + } + gain = sqrtf( ene_tc / ( ene_sum + EPSILON ) ); + if ( st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame > 1 ) + { + /* Smoothing */ + gain = 0.75f * gain + 0.25f * last_gain; + /* 10ms ramp */ + grad = ( gain - last_gain ) / (float) nFadeLength; /* slope between two consecutive gains, 480 samples length */ + for ( i = 0; i < ( nFadeLength ); i++ ) + { + transport_channels_f[0][i] *= ( last_gain + i * grad ); + transport_channels_f[1][i] *= ( last_gain + i * grad ); + } + for ( ; i < nSamples; i++ ) + { + transport_channels_f[0][i] *= gain; + transport_channels_f[1][i] *= gain; + } + } + else + { + for ( i = 0; i < nSamples; i++ ) + { + transport_channels_f[0][i] *= gain; + transport_channels_f[1][i] *= gain; + } + } + st_ivas->hParamIsmDec->hParamIsm->last_dmx_gain = gain; + + return; +} + +/*-------------------------------------------------------------------------* + * ivas_ism_param_dec_render_sf() + * + * + *-------------------------------------------------------------------------*/ + +static void ivas_ism_param_dec_render_sf( + Decoder_Struct *st_ivas, + IVAS_OUTPUT_SETUP hSetup, + const int16_t nchan_transport, + const int16_t nchan_out, + const int16_t nchan_out_woLFE, + float *output_f[] /* o : rendered time signal */ +) +{ + int16_t ch, slot_idx, i, index_slot; + /* CLDFB Output Buffers */ + float Cldfb_RealBuffer[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_ImagBuffer[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + float *Cldfb_RealBuffer_in[PARAM_ISM_MAX_DMX]; + float *Cldfb_ImagBuffer_in[PARAM_ISM_MAX_DMX]; + PARAM_ISM_DEC_HANDLE hParamIsmDec; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + + int16_t slot_idx_start; + int16_t idx_in; + int16_t idx_lfe; + int16_t subframe_idx; + + hParamIsmDec = st_ivas->hParamIsmDec; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + slot_idx_start = hSpatParamRendCom->slots_rendered; + subframe_idx = hSpatParamRendCom->subframes_rendered; + + /* Set some memories to zero */ + for ( ch = 0; ch < nchan_out_woLFE; ch++ ) + { + for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + set_f( Cldfb_RealBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands ); + set_f( Cldfb_ImagBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands ); + } + } + + for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + index_slot = slot_idx_start + slot_idx; + + for ( ch = 0; ch < nchan_transport; ch++ ) + { + Cldfb_RealBuffer_in[ch] = &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc[index_slot * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands]; + Cldfb_ImagBuffer_in[ch] = &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc[index_slot * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands]; + } + + /* Compute bandwise rendering to target LS using covariance rendering */ + ivas_param_ism_render_slot( hParamIsmDec, hSpatParamRendCom, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, + Cldfb_RealBuffer, Cldfb_ImagBuffer, hParamIsmDec->hParamIsmRendering->mixing_matrix_lin, index_slot, slot_idx, + nchan_out_woLFE, nchan_transport ); + } + + /* CLDFB Synthesis */ + idx_in = 0; + idx_lfe = 0; + + for ( ch = 0; ch < nchan_out; ch++ ) + { + if ( ( hSetup.num_lfe > 0 ) && ( hSetup.index_lfe[idx_lfe] == ch ) ) + { + set_zero( output_f[ch], hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands ); + if ( idx_lfe < ( hSetup.num_lfe - 1 ) ) + { + idx_lfe++; + } + } + else + { + float *RealBuffer[16]; + float *ImagBuffer[16]; + + /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ + for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) + { + RealBuffer[i] = Cldfb_RealBuffer[idx_in][i]; + ImagBuffer[i] = Cldfb_ImagBuffer[idx_in][i]; + } + cldfbSynthesis( RealBuffer, ImagBuffer, output_f[ch], + hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] ); + idx_in++; + } + } + + hSpatParamRendCom->slots_rendered += hSpatParamRendCom->subframe_nbslots[subframe_idx]; + hSpatParamRendCom->subframes_rendered++; + + return; +} + + +/*-------------------------------------------------------------------------* + * ivas_param_ism_dec_render() + * + * + *-------------------------------------------------------------------------*/ + +void ivas_param_ism_dec_render( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ + uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */ + uint16_t *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ + float *output_f[] /* o : rendered time signal */ +) +{ + int16_t ch, slots_to_render, first_sf, last_sf, subframe_idx; + uint16_t slot_size, n_samples_sf; + PARAM_ISM_DEC_HANDLE hParamIsmDec; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + IVAS_OUTPUT_SETUP hSetup; + int16_t nchan_transport, nchan_out, nchan_out_woLFE; + float *output_f_local[MAX_OUTPUT_CHANNELS]; + + hParamIsmDec = st_ivas->hParamIsmDec; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + hSetup = st_ivas->hIntSetup; +#ifdef DEBUGGING + assert( hParamIsmDec ); + assert( hSpatParamRendCom ); +#endif + nchan_transport = st_ivas->nchan_transport; + if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) + { + nchan_out = st_ivas->nchan_ism; + nchan_out_woLFE = nchan_out; + st_ivas->hDecoderConfig->nchan_out = nchan_out; + } + else + { + nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; + nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE; + } + slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + + /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ + slots_to_render = min( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered, nSamplesAsked / slot_size ); + *nSamplesRendered = slots_to_render * slot_size; + first_sf = hSpatParamRendCom->subframes_rendered; + last_sf = first_sf; + + while ( slots_to_render > 0 ) + { + slots_to_render -= hSpatParamRendCom->subframe_nbslots[last_sf]; + last_sf++; + } +#ifdef DEBUGGING + assert( slots_to_render == 0 ); +#endif + + for ( ch = 0; ch < nchan_out; ch++ ) + { + output_f_local[ch] = &output_f[ch][0]; + } + + for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) + { + ivas_ism_param_dec_render_sf( st_ivas, hSetup, nchan_transport, nchan_out, nchan_out_woLFE, output_f_local ); + n_samples_sf = hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->slot_size; + for ( ch = 0; ch < nchan_out; ch++ ) + { + output_f_local[ch] += n_samples_sf; + } + } + + if ( hSpatParamRendCom->slots_rendered == hSpatParamRendCom->num_slots ) + { + /* copy the memories */ + /* store mixing matrix for next subframe */ + ivas_param_ism_update_mixing_matrix( hParamIsmDec, hParamIsmDec->hParamIsmRendering->mixing_matrix_lin, nchan_transport, nchan_out_woLFE ); + + /* store MetaData parameters */ + for ( ch = 0; ch < st_ivas->nchan_ism; ch++ ) + { + if ( st_ivas->hParamIsmDec->azimuth_values[ch] > 180.0f ) + { + st_ivas->hIsmMetaData[ch]->azimuth = st_ivas->hParamIsmDec->azimuth_values[ch] - 360.0f; + } + else + { + st_ivas->hIsmMetaData[ch]->azimuth = st_ivas->hParamIsmDec->azimuth_values[ch]; + } + + st_ivas->hIsmMetaData[ch]->elevation = st_ivas->hParamIsmDec->elevation_values[ch]; + } + } + + *nSamplesAvailableNext = ( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered ) * slot_size; + + return; +} + + +/*-------------------------------------------------------------------------* + * ivas_param_ism_params_to_masa_param_mapping() + * + * + *-------------------------------------------------------------------------*/ + +void ivas_param_ism_params_to_masa_param_mapping( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + PARAM_ISM_DEC_HANDLE hParamIsmDec; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + int16_t nBins; + int16_t band_idx, bin_idx, sf_idx; + int16_t brange[2]; + int16_t azimuth[2]; + int16_t elevation[2]; + float power_ratio[2]; + int32_t ivas_total_brate; + + hParamIsmDec = st_ivas->hParamIsmDec; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + nBins = hSpatParamRendCom->num_freq_bands; + + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + + if ( !( ivas_total_brate == IVAS_SID_5k2 || ivas_total_brate == FRAME_NO_DATA ) ) + { + ivas_param_ism_dec_dequant_DOA( hParamIsmDec, st_ivas->nchan_ism ); + ivas_param_ism_dec_dequant_powrat( hParamIsmDec ); + st_ivas->hISMDTX.dtx_flag = 0; + } + else + { + st_ivas->hISMDTX.dtx_flag = 1; + } + + if ( st_ivas->nchan_ism > 1 ) + { + if ( st_ivas->hISMDTX.dtx_flag ) + { + float energy_ratio; + energy_ratio = powf( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence, 2.0f ); + + hSpatParamRendCom->numSimultaneousDirections = 1; + azimuth[0] = (int16_t) roundf( hParamIsmDec->azimuth_values[0] ); + elevation[0] = (int16_t) roundf( hParamIsmDec->elevation_values[0] ); + + for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + { + for ( bin_idx = 0; bin_idx < nBins; bin_idx++ ) + { + hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0]; + hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0]; + + hSpatParamRendCom->energy_ratio1[sf_idx][bin_idx] = energy_ratio; + + hSpatParamRendCom->spreadCoherence[sf_idx][bin_idx] = 0.0f; + hSpatParamRendCom->surroundingCoherence[sf_idx][bin_idx] = 0.0; + } + } + } + else + { + hSpatParamRendCom->numSimultaneousDirections = 2; + for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ ) + { + brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx]; + brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1]; + + azimuth[0] = (int16_t) roundf( hParamIsmDec->azimuth_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] ); + elevation[0] = (int16_t) roundf( hParamIsmDec->elevation_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] ); + power_ratio[0] = hParamIsmDec->power_ratios[band_idx][0][0]; + + azimuth[1] = (int16_t) roundf( hParamIsmDec->azimuth_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]] ); + elevation[1] = (int16_t) roundf( hParamIsmDec->elevation_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]] ); + power_ratio[1] = hParamIsmDec->power_ratios[band_idx][0][1]; + + for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + { + for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ ) + { + hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0]; + hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0]; + hSpatParamRendCom->energy_ratio1[sf_idx][bin_idx] = power_ratio[0]; + hSpatParamRendCom->azimuth2[sf_idx][bin_idx] = azimuth[1]; + hSpatParamRendCom->elevation2[sf_idx][bin_idx] = elevation[1]; + hSpatParamRendCom->energy_ratio2[sf_idx][bin_idx] = power_ratio[1]; + } + } + } + + for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + { + for ( bin_idx = 0; bin_idx < nBins; bin_idx++ ) + { + hSpatParamRendCom->spreadCoherence[sf_idx][bin_idx] = 0.0f; + hSpatParamRendCom->spreadCoherence2[sf_idx][bin_idx] = 0.0f; + hSpatParamRendCom->surroundingCoherence[sf_idx][bin_idx] = 0.0; + } + } + } + } + else + { + hSpatParamRendCom->numSimultaneousDirections = 1; + azimuth[0] = (int16_t) roundf( hParamIsmDec->azimuth_values[0] ); + elevation[0] = (int16_t) roundf( hParamIsmDec->elevation_values[0] ); + + for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + { + for ( bin_idx = 0; bin_idx < nBins; bin_idx++ ) + { + hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0]; + hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0]; + hSpatParamRendCom->energy_ratio1[sf_idx][bin_idx] = 1.0f; + hSpatParamRendCom->spreadCoherence[sf_idx][bin_idx] = 0.0f; + hSpatParamRendCom->surroundingCoherence[sf_idx][bin_idx] = 0.0; + } + } + } + + return; +} +#endif \ No newline at end of file diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 1fe58874a0..fd6f944add 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -152,8 +152,13 @@ ivas_error ivas_jbm_dec_tc( } else if ( st_ivas->ism_mode == ISM_MODE_PARAM ) { +#ifndef PARAM_ISM_REFACTOR if ( ( error = ivas_ism_metadata_dec( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, st_ivas->hDirAC->hParamIsm, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_ism_metadata_dec( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, st_ivas->hParamIsmDec->hParamIsm, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, + st_ivas->hSCE[0]->hCoreCoder[0] ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -2355,8 +2360,13 @@ void ivas_jbm_dec_copy_tc_no_tsm( if ( st_ivas->ivas_format == ISM_FORMAT ) { +#ifndef PARAM_ISM_REFACTOR cldfb_real_buffer = st_ivas->hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc; cldfb_imag_buffer = st_ivas->hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc; +#else + cldfb_real_buffer = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc; + cldfb_imag_buffer = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc; +#endif num_freq_bands = st_ivas->hSpatParamRendCom->num_freq_bands; ivas_ism_param_dec_tc_gain_ajust( st_ivas, output_frame, output_frame / 2, tc ); } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index e70403488d..d5cbc8eff4 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -399,6 +399,7 @@ typedef struct } ISM_DTX_DATA_DEC; +#ifndef PARAM_ISM_REFACTOR /*----------------------------------------------------------------------------------* * DirAC decoder structures *----------------------------------------------------------------------------------*/ @@ -435,6 +436,53 @@ typedef struct ivas_dirac_dec_data_structure IVAS_FB_MIXER_HANDLE hFbMdft; } DIRAC_DEC_DATA, *DIRAC_DEC_HANDLE; +#else +/*----------------------------------------------------------------------------------* + * ParamISM decoder structures + *----------------------------------------------------------------------------------*/ + +typedef struct param_ism_rendering +{ + float *proto_matrix; + float *interpolator; + float mixing_matrix_lin_old[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX]; + float mixing_matrix_lin[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX]; + float *Cldfb_RealBuffer_tc; + float *Cldfb_ImagBuffer_tc; + +} PARAM_ISM_RENDERING_DATA, *PARAM_ISM_RENDERING_HANDLE; + + +typedef struct ivas_param_ism_dec_data_structure +{ + /*Parameter decoding*/ + float azimuth_values[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS]; + float elevation_values[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS]; + float power_ratios[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS][MAX_PARAM_ISM_WAVE]; + + /*sub-modules*/ + PARAM_ISM_CONFIG_HANDLE hParamIsm; /* Parametric ISM common handle */ + PARAM_ISM_RENDERING_HANDLE hParamIsmRendering; /* ParamISM rendering handle */ + +} PARAM_ISM_DEC_DATA, *PARAM_ISM_DEC_HANDLE; + + +/*----------------------------------------------------------------------------------* + * DirAC decoder structures + *----------------------------------------------------------------------------------*/ + +typedef struct ivas_dirac_dec_data_structure +{ + DIRAC_CONFIG_DATA_HANDLE hConfig; + + int16_t band_grouping[IVAS_MAX_NUM_BANDS + 1]; + int16_t dithering_seed; + int16_t spar_to_dirac_write_idx; + + IVAS_FB_MIXER_HANDLE hFbMdft; + +} DIRAC_DEC_DATA, *DIRAC_DEC_HANDLE; +#endif /*----------------------------------------------------------------------------------* @@ -1037,6 +1085,9 @@ typedef struct Decoder_Struct ISM_DTX_DATA_DEC hISMDTX; /* ISM DTX structure */ ISM_RENDERER_HANDLE hIsmRendererData; /* ISM renderer handle */ DIRAC_DEC_HANDLE hDirAC; /* DirAC handle */ +#ifdef PARAM_ISM_REFACTOR + PARAM_ISM_DEC_HANDLE hParamIsmDec; /* ParamISM handle */ +#endif SPAR_DEC_HANDLE hSpar; /* SPAR handle */ IVAS_QMETADATA_HANDLE hQMetaData; /* q_metadata handle */ MCT_DEC_HANDLE hMCT; /* MCT handle */ diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 4a870d5977..6cceae1743 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -1149,7 +1149,11 @@ void ivas_destroy_enc( /* DirAC handle */ if ( ivas_format == ISM_FORMAT ) { +#ifndef PARAM_ISM_REFACTOR ivas_param_ism_enc_close( &( st_ivas->hDirAC ), st_ivas->hEncoderConfig->input_Fs ); +#else + ivas_param_ism_enc_close( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs ); +#endif } else { diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 35878e5848..a15c342adb 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -226,7 +226,11 @@ ivas_error ivas_ism_enc( if ( st_ivas->ism_mode == ISM_MODE_PARAM ) { ivas_param_ism_compute_noisy_speech_flag( st_ivas ); +#ifndef PARAM_ISM_REFACTOR flag_noisy_speech = st_ivas->hDirAC->hParamIsm->flag_noisy_speech; +#else + flag_noisy_speech = st_ivas->hParamIsm->flag_noisy_speech; +#endif } if ( dtx_flag ) @@ -235,9 +239,15 @@ ivas_error ivas_ism_enc( } else if ( st_ivas->ism_mode == ISM_MODE_PARAM ) { +#ifndef PARAM_ISM_REFACTOR ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ); +#else + ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, + nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, + st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ); +#endif } else /* ISM_MODE_DISC */ { @@ -471,7 +481,11 @@ ivas_error ivas_ism_enc_config( if ( st_ivas->ism_mode == ISM_MODE_DISC && last_ism_mode == ISM_MODE_PARAM ) { /* Deallocate the memory used by ParamISM when switch to Discrete ISM */ +#ifndef PARAM_ISM_REFACTOR ivas_param_ism_enc_close( &( st_ivas->hDirAC ), st_ivas->hEncoderConfig->input_Fs ); +#else + ivas_param_ism_enc_close( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs ); +#endif } } diff --git a/lib_enc/ivas_ism_param_enc.c b/lib_enc/ivas_ism_param_enc.c index dbd31953a4..91af2aebe6 100644 --- a/lib_enc/ivas_ism_param_enc.c +++ b/lib_enc/ivas_ism_param_enc.c @@ -235,7 +235,11 @@ void ivas_param_ism_stereo_dmx( dmx_gain = 0; ene_dmx = 0; ene_data = 0; +#ifndef PARAM_ISM_REFACTOR last_dmx_gain = st_ivas->hDirAC->hParamIsm->last_dmx_gain; +#else + last_dmx_gain = st_ivas->hParamIsm->last_dmx_gain; +#endif /* Set the stereo dmx to zero */ set_zero( stereo_dmx[0], L_FRAME48k ); @@ -245,7 +249,11 @@ void ivas_param_ism_stereo_dmx( for ( i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) { hIsmMetaData = st_ivas->hIsmMetaData[i]; +#ifndef PARAM_ISM_REFACTOR last_cardioid_left = st_ivas->hDirAC->hParamIsm->last_cardioid_left[i]; +#else + last_cardioid_left = st_ivas->hParamIsm->last_cardioid_left[i]; +#endif /*Compute the Cardioids for the corresponding object direction */ tmp = hIsmMetaData->azimuth * ( EVS_PI / 180 ); tmp_1 = ( EVS_PI / 2 ) + azi_shift; @@ -288,7 +296,11 @@ void ivas_param_ism_stereo_dmx( ene_data += ( tmp * tmp ); /* energy of all objects combined */ } } +#ifndef PARAM_ISM_REFACTOR st_ivas->hDirAC->hParamIsm->last_cardioid_left[i] = cardioid_left[i]; +#else + st_ivas->hParamIsm->last_cardioid_left[i] = cardioid_left[i]; +#endif } /* Energy compensation */ @@ -322,7 +334,12 @@ void ivas_param_ism_stereo_dmx( stereo_dmx[1][j] *= dmx_gain; } } +#ifndef PARAM_ISM_REFACTOR st_ivas->hDirAC->hParamIsm->last_dmx_gain = dmx_gain; +#else + st_ivas->hParamIsm->last_dmx_gain = dmx_gain; +#endif + /* Copy the stereo dmx to data variable */ mvr2r( stereo_dmx[0], data[0], input_frame ); mvr2r( stereo_dmx[1], data[1], input_frame ); @@ -345,24 +362,37 @@ ivas_error ivas_param_ism_enc_open( { int16_t i; IVAS_FB_CFG *fb_cfg; +#ifndef PARAM_ISM_REFACTOR DIRAC_ENC_HANDLE hDirAC; +#else + PARAM_ISM_CONFIG_HANDLE hParamIsm; +#endif int16_t max_bins; int32_t input_Fs; ivas_error error; error = IVAS_ERR_OK; +#ifndef PARAM_ISM_REFACTOR /* Assign memory to DirAC handle */ if ( ( hDirAC = (DIRAC_ENC_HANDLE) malloc( sizeof( DIRAC_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } +#endif /* Assign memory to Param Object handle */ +#ifndef PARAM_ISM_REFACTOR if ( ( hDirAC->hParamIsm = (PARAM_ISM_CONFIG_HANDLE) malloc( sizeof( PARAM_ISM_CONFIG_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM\n" ) ); } +#else + if ( ( hParamIsm = (PARAM_ISM_CONFIG_HANDLE) malloc( sizeof( PARAM_ISM_CONFIG_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM\n" ) ); + } +#endif input_Fs = st_ivas->hEncoderConfig->input_Fs; @@ -374,29 +404,62 @@ ivas_error ivas_param_ism_enc_open( } /* Allocate and initialize FB mixer handle */ +#ifndef PARAM_ISM_REFACTOR if ( ( error = ivas_FB_mixer_open( &( hDirAC->hFbMixer ), input_Fs, fb_cfg, 0 ) ) != IVAS_ERR_OK ) { return error; } +#else + if ( ( error = ivas_FB_mixer_open( &( hParamIsm->hFbMixer ), input_Fs, fb_cfg, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif +#ifndef PARAM_ISM_REFACTOR ivas_param_ism_config( hDirAC->hParamIsm, st_ivas->hEncoderConfig->nchan_inp ); +#else + ivas_param_ism_config( hParamIsm, st_ivas->hEncoderConfig->nchan_inp ); +#endif /* Assign memories for Band and Block grouping */ +#ifndef PARAM_ISM_REFACTOR hDirAC->hParamIsm->nbands = MAX_PARAM_ISM_NBANDS; +#else + hParamIsm->nbands = MAX_PARAM_ISM_NBANDS; +#endif max_bins = (int16_t) ( ( MDFT_FB_BANDS_240 * input_Fs ) / 48000 ); +#ifndef PARAM_ISM_REFACTOR for ( i = 0; i < ( hDirAC->hParamIsm->nbands + 1 ); i++ ) +#else + for ( i = 0; i < ( hParamIsm->nbands + 1 ); i++ ) +#endif { +#ifndef PARAM_ISM_REFACTOR hDirAC->hParamIsm->band_grouping[i] = CLDFB_TO_MDFT_FAC * Param_ISM_band_grouping[i]; +#else + hParamIsm->band_grouping[i] = CLDFB_TO_MDFT_FAC * Param_ISM_band_grouping[i]; +#endif if ( ( Param_ISM_band_grouping[i] * CLDFB_TO_MDFT_FAC ) > max_bins ) { +#ifndef PARAM_ISM_REFACTOR hDirAC->hParamIsm->band_grouping[i] = max_bins; +#else + hParamIsm->band_grouping[i] = max_bins; +#endif } } +#ifndef PARAM_ISM_REFACTOR set_s( hDirAC->hParamIsm->noisy_speech_buffer, 0, PARAM_ISM_HYS_BUF_SIZE ); st_ivas->hDirAC = hDirAC; +#else + set_s( hParamIsm->noisy_speech_buffer, 0, PARAM_ISM_HYS_BUF_SIZE ); + + st_ivas->hParamIsm = hParamIsm; +#endif return error; } @@ -408,6 +471,7 @@ ivas_error ivas_param_ism_enc_open( * Close Param ISM encoder handle *-------------------------------------------------------------------------*/ +#ifndef PARAM_ISM_REFACTOR void ivas_param_ism_enc_close( DIRAC_ENC_HANDLE *hDirAC, /* i/o: encoder DirAC handle */ const int32_t input_Fs /* i : input sampling_rate */ @@ -431,6 +495,25 @@ void ivas_param_ism_enc_close( return; } +#else +void ivas_param_ism_enc_close( + PARAM_ISM_CONFIG_HANDLE *hParamIsm, /* i/o: ParamISM handle */ + const int32_t input_Fs /* i : input sampling_rate */ +) +{ + if ( hParamIsm == NULL || *hParamIsm == NULL ) + { + return; + } + + ivas_FB_mixer_close( &( *hParamIsm )->hFbMixer, input_Fs, 0 ); + + free( ( *hParamIsm ) ); + ( *hParamIsm ) = NULL; + + return; +} +#endif /*-------------------------------------------------------------------------* @@ -454,12 +537,18 @@ void ivas_param_ism_enc( float *p_fb_RealBuffer[MAX_NUM_OBJECTS]; float *p_fb_ImagBuffer[MAX_NUM_OBJECTS]; float reference_power_obj[MAX_NUM_OBJECTS][PARAM_ISM_MDFT_NO_SLOTS][DIRAC_NO_FB_BANDS_MAX]; +#ifndef PARAM_ISM_REFACTOR DIRAC_ENC_HANDLE hDirAC; +#endif PARAM_ISM_CONFIG_HANDLE hParamIsm; nchan_ism = st_ivas->hEncoderConfig->nchan_ism; +#ifndef PARAM_ISM_REFACTOR hDirAC = st_ivas->hDirAC; hParamIsm = hDirAC->hParamIsm; +#else + hParamIsm = st_ivas->hParamIsm; +#endif push_wmops( "ivas_param_ism_enc" ); @@ -478,9 +567,15 @@ void ivas_param_ism_enc( for ( ts = 0; ts < num_time_slots; ts++ ) { +#ifndef PARAM_ISM_REFACTOR ivas_fb_mixer_get_windowed_fr( hDirAC->hFbMixer, pcm_in, p_fb_RealBuffer, p_fb_ImagBuffer, l_ts, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); ivas_fb_mixer_update_prior_input( hDirAC->hFbMixer, pcm_in, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); +#else + ivas_fb_mixer_get_windowed_fr( hParamIsm->hFbMixer, pcm_in, p_fb_RealBuffer, p_fb_ImagBuffer, l_ts, l_ts, hParamIsm->hFbMixer->fb_cfg->num_in_chans ); + + ivas_fb_mixer_update_prior_input( hParamIsm->hFbMixer, pcm_in, l_ts, hParamIsm->hFbMixer->fb_cfg->num_in_chans ); +#endif for ( i = 0; i < nchan_ism; i++ ) { @@ -515,6 +610,7 @@ void ivas_param_ism_compute_noisy_speech_flag( { int16_t i; +#ifndef PARAM_ISM_REFACTOR /* Move the Noisy speech buffer */ for ( i = 0; i < ( PARAM_ISM_HYS_BUF_SIZE - 1 ); i++ ) { @@ -553,6 +649,46 @@ void ivas_param_ism_compute_noisy_speech_flag( st_ivas->hDirAC->hParamIsm->flag_noisy_speech = st_ivas->hDirAC->hParamIsm->flag_noisy_speech && st_ivas->hDirAC->hParamIsm->noisy_speech_buffer[i]; } } +#else + /* Move the Noisy speech buffer */ + for ( i = 0; i < ( PARAM_ISM_HYS_BUF_SIZE - 1 ); i++ ) + { + st_ivas->hParamIsm->noisy_speech_buffer[i] = st_ivas->hParamIsm->noisy_speech_buffer[i + 1]; + } + + /* Set flag_noisy_speech to 0 for cases where object energies are not roughly equal */ + if ( !st_ivas->hParamIsm->flag_equal_energy ) + { + st_ivas->hParamIsm->noisy_speech_buffer[i] = 0; + st_ivas->hParamIsm->flag_noisy_speech = 0; + } + else + { + /* For the current frame, make a decision based on some core-coder flags */ + if ( st_ivas->hSCE[0]->hCoreCoder[0]->flag_noisy_speech_snr && st_ivas->hSCE[1]->hCoreCoder[0]->flag_noisy_speech_snr ) + { + if ( st_ivas->hSCE[0]->hCoreCoder[0]->vad_flag || st_ivas->hSCE[1]->hCoreCoder[0]->vad_flag ) + { + st_ivas->hParamIsm->noisy_speech_buffer[i] = 0; + } + else + { + st_ivas->hParamIsm->noisy_speech_buffer[i] = 1; + } + } + else + { + st_ivas->hParamIsm->noisy_speech_buffer[i] = 0; + } + + /* Do a decision based on hysteresis */ + st_ivas->hParamIsm->flag_noisy_speech = 1; + for ( i = 0; i < PARAM_ISM_HYS_BUF_SIZE; i++ ) + { + st_ivas->hParamIsm->flag_noisy_speech = st_ivas->hParamIsm->flag_noisy_speech && st_ivas->hParamIsm->noisy_speech_buffer[i]; + } + } +#endif return; } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 05bf62a92a..34acd443da 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -585,7 +585,9 @@ typedef struct front_vad_enc typedef struct ivas_dirac_enc_data_structure { DIRAC_CONFIG_DATA_HANDLE hConfig; +#ifndef PARAM_ISM_REFACTOR PARAM_ISM_CONFIG_HANDLE hParamIsm; /* Parametric ISM handle */ +#endif IVAS_FB_MIXER_HANDLE hFbMixer; @@ -1227,6 +1229,9 @@ typedef struct ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS]; /* ISM metadata handles (storage for one frame of read ISM metadata) */ ISM_DTX_HANDLE hISMDTX; /* ISM DTX handle */ DIRAC_ENC_HANDLE hDirAC; /* DirAC data handle */ +#ifdef PARAM_ISM_REFACTOR + PARAM_ISM_CONFIG_HANDLE hParamIsm; /* Parametric ISM handle */ +#endif SPAR_ENC_HANDLE hSpar; /* SPAR encoder handle */ MASA_ENCODER_HANDLE hMasa; /* MASA encoder data and configuration */ IVAS_QMETADATA_HANDLE hQMetaData; /* Metadata handle for q_metadata parametric spatial coding DirAC/MASA*/ -- GitLab From e656947f1d469e10ff61abcddf61c89e9d67f6a2 Mon Sep 17 00:00:00 2001 From: Andrea Eichenseer Date: Tue, 5 Sep 2023 17:41:22 +0200 Subject: [PATCH 02/10] Clang format. --- lib_dec/ivas_stat_dec.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index d5cbc8eff4..9fe82974df 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -461,8 +461,8 @@ typedef struct ivas_param_ism_dec_data_structure float power_ratios[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS][MAX_PARAM_ISM_WAVE]; /*sub-modules*/ - PARAM_ISM_CONFIG_HANDLE hParamIsm; /* Parametric ISM common handle */ - PARAM_ISM_RENDERING_HANDLE hParamIsmRendering; /* ParamISM rendering handle */ + PARAM_ISM_CONFIG_HANDLE hParamIsm; /* Parametric ISM common handle */ + PARAM_ISM_RENDERING_HANDLE hParamIsmRendering; /* ParamISM rendering handle */ } PARAM_ISM_DEC_DATA, *PARAM_ISM_DEC_HANDLE; -- GitLab From 1d649f7d2fc10c9b47f463906acb0c9be4e19899 Mon Sep 17 00:00:00 2001 From: Andrea Eichenseer Date: Tue, 5 Sep 2023 17:46:58 +0200 Subject: [PATCH 03/10] Newline. --- lib_dec/ivas_ism_param_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 635da7972d..445f779b93 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -3195,4 +3195,4 @@ void ivas_param_ism_params_to_masa_param_mapping( return; } -#endif \ No newline at end of file +#endif -- GitLab From 4c7585501e459656cbafc527783e610d59061e00 Mon Sep 17 00:00:00 2001 From: Andrea Eichenseer Date: Mon, 11 Sep 2023 15:26:35 +0200 Subject: [PATCH 04/10] Some tweaks in handle initialization and closing. --- lib_dec/ivas_init_dec.c | 3 +++ lib_enc/ivas_init_enc.c | 16 ++++++++++++---- lib_enc/ivas_ism_enc.c | 8 ++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 70e8d0ee4b..1878a35ada 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -2412,6 +2412,9 @@ void ivas_initialize_handles_dec( /* spatial coding handles */ st_ivas->hDirAC = NULL; +#ifdef PARAM_ISM_REFACTOR + st_ivas->hParamIsmDec = NULL; +#endif st_ivas->hSpar = NULL; st_ivas->hMasa = NULL; st_ivas->hQMetaData = NULL; diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 6cceae1743..2332f77e0b 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -321,6 +321,10 @@ void ivas_initialize_handles_enc( /* DirAC handle */ st_ivas->hDirAC = NULL; +#ifdef PARAM_ISM_REFACTOR + /* ParamISM handle */ + st_ivas->hParamIsm = NULL; +#endif /* SPAR handle */ st_ivas->hSpar = NULL; @@ -1146,19 +1150,23 @@ void ivas_destroy_enc( /* Q Metadata handle */ ivas_qmetadata_close( &( st_ivas->hQMetaData ) ); +#ifndef PARAM_ISM_REFACTOR /* DirAC handle */ if ( ivas_format == ISM_FORMAT ) { -#ifndef PARAM_ISM_REFACTOR ivas_param_ism_enc_close( &( st_ivas->hDirAC ), st_ivas->hEncoderConfig->input_Fs ); -#else - ivas_param_ism_enc_close( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs ); -#endif } else { ivas_dirac_enc_close( &( st_ivas->hDirAC ), st_ivas->hEncoderConfig->input_Fs ); } +#else + /* DirAC handle */ + ivas_dirac_enc_close( &( st_ivas->hDirAC ), st_ivas->hEncoderConfig->input_Fs ); + + /* ParamISM handle */ + ivas_param_ism_enc_close( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs ); +#endif /* SPAR handle */ ivas_spar_enc_close( &( st_ivas->hSpar ), st_ivas->hEncoderConfig->input_Fs, nchan_inp, 0 ); diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index a15c342adb..e8d765eb0f 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -210,11 +210,19 @@ ivas_error ivas_ism_enc( } #ifdef DEBUG_MODE_PARAM_ISM +#ifndef PARAM_ISM_REFACTOR if ( st_ivas->hDirAC != NULL ) dbgwrite( &( st_ivas->hDirAC->hParamIsm->flag_noisy_speech ), sizeof( int16_t ), 1, 1, "./res/ParamISM_noisy_speech_flag_enc.dat" ); dbgwrite( &( st_ivas->hISMDTX->dtx_flag ), sizeof( int16_t ), 1, 1, "./res/ParamISM_DTX_CNG_flag_enc.dat" ); dbgwrite( &( st_ivas->hISMDTX->sce_id_dtx ), sizeof( int16_t ), 1, input_frame, "./res/sce_id_dtx" ); dbgwrite( &( dtx_flag ), sizeof( int16_t ), 1, input_frame, "./res/dtx_flag" ); +#else + if ( st_ivas->hParamIsmDec != NULL ) + dbgwrite( &( st_ivas->hParamIsmDec->hParamIsm->flag_noisy_speech ), sizeof( int16_t ), 1, 1, "./res/ParamISM_noisy_speech_flag_enc.dat" ); + dbgwrite( &( st_ivas->hISMDTX->dtx_flag ), sizeof( int16_t ), 1, 1, "./res/ParamISM_DTX_CNG_flag_enc.dat" ); + dbgwrite( &( st_ivas->hISMDTX->sce_id_dtx ), sizeof( int16_t ), 1, input_frame, "./res/sce_id_dtx" ); + dbgwrite( &( dtx_flag ), sizeof( int16_t ), 1, input_frame, "./res/dtx_flag" ); +#endif #endif } -- GitLab From 009aa8eea6e07c9439e7dd36c0f603ca52aad8b3 Mon Sep 17 00:00:00 2001 From: Andrea Eichenseer Date: Mon, 11 Sep 2023 16:24:03 +0200 Subject: [PATCH 05/10] Re-add hDirAC to ivas_param_ism_dec_open(): must be initialized for ivas_dirac_dec_set_md_map(). --- lib_dec/ivas_ism_param_dec.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 445f779b93..8f3219b19e 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -2022,6 +2022,7 @@ ivas_error ivas_param_ism_dec_open( ) { int16_t i; + DIRAC_DEC_HANDLE hDirAC; PARAM_ISM_DEC_HANDLE hParamIsmDec; IVAS_OUTPUT_SETUP hOutSetup; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; @@ -2037,6 +2038,11 @@ ivas_error ivas_param_ism_dec_open( * prepare library opening *-----------------------------------------------------------------*/ + if ( ( hDirAC = (DIRAC_DEC_HANDLE) malloc( sizeof( DIRAC_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + if ( ( hParamIsmDec = (PARAM_ISM_DEC_HANDLE) malloc( sizeof( PARAM_ISM_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM\n" ) ); @@ -2068,6 +2074,7 @@ ivas_error ivas_param_ism_dec_open( *-----------------------------------------------------------------*/ hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); + hDirAC->hConfig = NULL; set_s( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); set_s( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; @@ -2143,6 +2150,7 @@ ivas_error ivas_param_ism_dec_open( hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; hSpatParamRendCom->dirac_bs_md_write_idx = 0; hSpatParamRendCom->dirac_read_idx = 0; + hDirAC->spar_to_dirac_write_idx = 0; #ifdef SPLIT_REND_WITH_HEAD_ROT_PARAMBIN if ( output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB || output_config == AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) @@ -2164,6 +2172,7 @@ ivas_error ivas_param_ism_dec_open( st_ivas->hISMDTX.dtx_flag = 0; st_ivas->hParamIsmDec = hParamIsmDec; + st_ivas->hDirAC = hDirAC; st_ivas->hSpatParamRendCom = hSpatParamRendCom; if ( st_ivas->hDecoderConfig->Opt_5ms ) -- GitLab From 8194f1ca4ea4d15b266758578aeee533d8d333d8 Mon Sep 17 00:00:00 2001 From: Andrea Eichenseer Date: Wed, 13 Sep 2023 20:14:15 +0200 Subject: [PATCH 06/10] Fix remaining ASAN/MSAN issue. Still needs a proper fix instead of PARAM_ISM_JBM_HACK. --- lib_com/options.h | 3 +++ lib_dec/ivas_dirac_dec.c | 14 ++++++++++++++ lib_dec/ivas_ism_param_dec.c | 9 --------- lib_enc/ivas_init_enc.c | 2 ++ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 82af067643..249c904245 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -163,6 +163,9 @@ #define FIX_RAM_COUNTING_5MS_RENDERING /* FhG: fix for correct RAM reporting with 5ms rendering */ #define PARAM_ISM_REFACTOR /* FhG: Issue 768: Refactoring to decouple hDirAC and hParamISM */ +#ifdef PARAM_ISM_REFACTOR +#define PARAM_ISM_JBM_HACK /* FhG: To do. hDirAC is not available there; needs proper solution. */ +#endif /* #################### End BE switches ################################## */ diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 38a1d1dd13..36a1c91b9f 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1538,10 +1538,16 @@ void ivas_dirac_dec_set_md_map( DIRAC_DEC_HANDLE hDirAC; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; +#ifndef PARAM_ISM_JBM_HACK hDirAC = st_ivas->hDirAC; +#else + hDirAC = NULL; +#endif hSpatParamRendCom = st_ivas->hSpatParamRendCom; #ifdef DEBUGGING +#ifndef PARAM_ISM_JBM_HACK assert( hDirAC ); +#endif assert( hSpatParamRendCom ); #endif @@ -1568,7 +1574,11 @@ void ivas_dirac_dec_set_md_map( { ivas_jbm_dec_get_md_map_even_spacing( nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } +#ifndef PARAM_ISM_JBM_HACK else if ( hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) +#else + else if ( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) +#endif { ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } @@ -1577,7 +1587,11 @@ void ivas_dirac_dec_set_md_map( ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, hSpatParamRendCom->dirac_read_idx, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } +#ifndef PARAM_ISM_JBM_HACK if ( hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) +#else + if ( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) +#endif { float tmp; int16_t sf_idx, slot_idx, slot_idx_abs; diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 8f3219b19e..445f779b93 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -2022,7 +2022,6 @@ ivas_error ivas_param_ism_dec_open( ) { int16_t i; - DIRAC_DEC_HANDLE hDirAC; PARAM_ISM_DEC_HANDLE hParamIsmDec; IVAS_OUTPUT_SETUP hOutSetup; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; @@ -2038,11 +2037,6 @@ ivas_error ivas_param_ism_dec_open( * prepare library opening *-----------------------------------------------------------------*/ - if ( ( hDirAC = (DIRAC_DEC_HANDLE) malloc( sizeof( DIRAC_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - if ( ( hParamIsmDec = (PARAM_ISM_DEC_HANDLE) malloc( sizeof( PARAM_ISM_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM\n" ) ); @@ -2074,7 +2068,6 @@ ivas_error ivas_param_ism_dec_open( *-----------------------------------------------------------------*/ hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); - hDirAC->hConfig = NULL; set_s( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); set_s( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; @@ -2150,7 +2143,6 @@ ivas_error ivas_param_ism_dec_open( hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; hSpatParamRendCom->dirac_bs_md_write_idx = 0; hSpatParamRendCom->dirac_read_idx = 0; - hDirAC->spar_to_dirac_write_idx = 0; #ifdef SPLIT_REND_WITH_HEAD_ROT_PARAMBIN if ( output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB || output_config == AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) @@ -2172,7 +2164,6 @@ ivas_error ivas_param_ism_dec_open( st_ivas->hISMDTX.dtx_flag = 0; st_ivas->hParamIsmDec = hParamIsmDec; - st_ivas->hDirAC = hDirAC; st_ivas->hSpatParamRendCom = hSpatParamRendCom; if ( st_ivas->hDecoderConfig->Opt_5ms ) diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 2332f77e0b..69f565c0fd 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -1098,9 +1098,11 @@ void ivas_destroy_enc( ) { int16_t i, n, nchan_inp; +#ifndef PARAM_ISM_REFACTOR IVAS_FORMAT ivas_format; ivas_format = st_ivas->hEncoderConfig->ivas_format; +#endif nchan_inp = st_ivas->hEncoderConfig->nchan_inp; /* SCE handles */ -- GitLab From 7e9ee82af2ebd0f7cfd3c35f24b1c282ff44aefb Mon Sep 17 00:00:00 2001 From: Andrea Eichenseer Date: Mon, 18 Sep 2023 15:12:17 +0200 Subject: [PATCH 07/10] Resolve PARAM_ISM_JBM_HACK and merge fixed solution with PARAM_ISM_REFACTOR. --- lib_com/options.h | 4 +--- lib_dec/ivas_dirac_dec.c | 10 +++------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 93af95cf51..e51475223d 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -174,9 +174,7 @@ #define FIX_708_AEID_COMMAND_LINE /* VA: issue 708: improve AEID command-line robustness */ #define PARAM_ISM_REFACTOR /* FhG: Issue 768: Refactoring to decouple hDirAC and hParamISM */ -#ifdef PARAM_ISM_REFACTOR -#define PARAM_ISM_JBM_HACK /* FhG: To do. hDirAC is not available there; needs proper solution. */ -#endif + /* #################### End BE switches ################################## */ /* #################### Start NON-BE switches ############################ */ diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 3dd1b1e51d..36a6fc77fd 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1550,14 +1550,10 @@ void ivas_dirac_dec_set_md_map( DIRAC_DEC_HANDLE hDirAC; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; -#ifndef PARAM_ISM_JBM_HACK hDirAC = st_ivas->hDirAC; -#else - hDirAC = NULL; -#endif hSpatParamRendCom = st_ivas->hSpatParamRendCom; #ifdef DEBUGGING -#ifndef PARAM_ISM_JBM_HACK +#ifndef PARAM_ISM_REFACTOR assert( hDirAC ); #endif assert( hSpatParamRendCom ); @@ -1586,7 +1582,7 @@ void ivas_dirac_dec_set_md_map( { ivas_jbm_dec_get_md_map_even_spacing( nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } -#ifndef PARAM_ISM_JBM_HACK +#ifndef PARAM_ISM_REFACTOR else if ( hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) #else else if ( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) @@ -1599,7 +1595,7 @@ void ivas_dirac_dec_set_md_map( ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, hSpatParamRendCom->dirac_read_idx, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } -#ifndef PARAM_ISM_JBM_HACK +#ifndef PARAM_ISM_REFACTOR if ( hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) #else if ( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) -- GitLab From dd1e1a696d066e05b16fd04433287b46560d0d65 Mon Sep 17 00:00:00 2001 From: Andrea Eichenseer Date: Mon, 18 Sep 2023 15:55:02 +0200 Subject: [PATCH 08/10] Fix merge mistake in ivas_ism_enc.c; manually fix new audio config names in ivas_ism_param_dec.c. --- lib_dec/ivas_ism_param_dec.c | 36 ++++++++++++++++++------------------ lib_enc/ivas_ism_enc.c | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 9646cca728..62bcc415de 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -1965,9 +1965,9 @@ static ivas_error ivas_param_ism_rendering_init( } #ifdef SPLIT_REND_WITH_HEAD_ROT_PARAMBIN - if ( !( output_config == AUDIO_CONFIG_EXTERNAL || output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB || output_config == AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) + if ( !( output_config == IVAS_AUDIO_CONFIG_EXTERNAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) #else - if ( !( output_config == AUDIO_CONFIG_EXTERNAL || output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + if ( !( output_config == IVAS_AUDIO_CONFIG_EXTERNAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) #endif { /* computation of proto matrix */ @@ -2093,7 +2093,7 @@ ivas_error ivas_param_ism_dec_open( *-----------------------------------------------------------------*/ /* hIntSetup and hOutSetup differs only for Binaural rendering */ - if ( output_config == AUDIO_CONFIG_EXTERNAL ) + if ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) { /* nchan_out is essential for memory initialization for CLDFB Synthesis */ st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->nchan_ism; @@ -2102,7 +2102,7 @@ ivas_error ivas_param_ism_dec_open( hOutSetup = st_ivas->hIntSetup; - if ( !( output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO ) ) + if ( !( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) ) { /* Initialize Param ISM Rendering handle */ if ( st_ivas->hDecoderConfig->Opt_tsm ) @@ -2122,11 +2122,11 @@ ivas_error ivas_param_ism_dec_open( } #ifdef SPLIT_REND_WITH_HEAD_ROT_PARAMBIN - if ( !( output_config == AUDIO_CONFIG_EXTERNAL || output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB || - output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO || output_config == AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) + if ( !( output_config == IVAS_AUDIO_CONFIG_EXTERNAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB || + output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) #else - if ( !( output_config == AUDIO_CONFIG_EXTERNAL || output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB || - output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO ) ) + if ( !( output_config == IVAS_AUDIO_CONFIG_EXTERNAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB || + output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) ) #endif { /* Initialize efap handle */ @@ -2145,9 +2145,9 @@ ivas_error ivas_param_ism_dec_open( hSpatParamRendCom->dirac_read_idx = 0; #ifdef SPLIT_REND_WITH_HEAD_ROT_PARAMBIN - if ( output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB || output_config == AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) + if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) #else - if ( output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) #endif { if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK ) @@ -2259,7 +2259,7 @@ void ivas_param_ism_dec_close( hParamIsmDec->hParamIsm = NULL; } - if ( !( output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO ) ) + if ( !( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) ) { /* Param ISM Rendering */ if ( hParamIsmDec->hParamIsmRendering->interpolator != NULL ) @@ -2297,7 +2297,7 @@ void ivas_param_ism_dec_close( if ( hSpatParamRendCom_out != NULL && *hSpatParamRendCom_out != NULL ) { - if ( output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 1 ); ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 2 ); @@ -2360,7 +2360,7 @@ void ivas_param_ism_dec( output_frame = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); nchan_transport = st_ivas->nchan_transport; - if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) { nchan_out = st_ivas->nchan_ism; nchan_out_woLFE = nchan_out; @@ -2399,7 +2399,7 @@ void ivas_param_ism_dec( } /* obtain the direct response using EFAP */ - if ( !( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) ) + if ( !( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) ) { for ( i = 0; i < st_ivas->nchan_ism; i++ ) { @@ -2608,7 +2608,7 @@ void ivas_ism_dec_digest_tc( { mvr2r( st_ivas->hIsmRendererData->gains[i], st_ivas->hIsmRendererData->prev_gains[i], MAX_OUTPUT_CHANNELS ); - if ( st_ivas->intern_config == AUDIO_CONFIG_STEREO ) + if ( st_ivas->intern_config == IVAS_AUDIO_CONFIG_STEREO ) { ivas_ism_get_stereo_gains( st_ivas->hIsmMetaData[i]->azimuth, st_ivas->hIsmMetaData[i]->elevation, @@ -2683,7 +2683,7 @@ void ivas_param_ism_dec_digest_tc( nchan_transport = st_ivas->nchan_transport; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) { nchan_out = st_ivas->nchan_ism; nchan_out_woLFE = nchan_out; @@ -2723,7 +2723,7 @@ void ivas_param_ism_dec_digest_tc( } /* obtain the direct response using EFAP */ - if ( !( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) ) + if ( !( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) ) { for ( i = 0; i < st_ivas->nchan_ism; i++ ) { @@ -3000,7 +3000,7 @@ void ivas_param_ism_dec_render( assert( hSpatParamRendCom ); #endif nchan_transport = st_ivas->nchan_transport; - if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) { nchan_out = st_ivas->nchan_ism; nchan_out_woLFE = nchan_out; diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 84c07acc3f..5c0f8f3824 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -253,7 +253,7 @@ ivas_error ivas_ism_enc( nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, - nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hParamIsmDec->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) + nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) #endif { return error; -- GitLab From f3f6b6253fe349850ec197ba2b7745525ab48da3 Mon Sep 17 00:00:00 2001 From: Andrea Eichenseer Date: Wed, 20 Sep 2023 11:00:31 +0200 Subject: [PATCH 09/10] Missing changes from MR 1074 added to ivas_ism_param_dec.c --- lib_dec/ivas_ism_param_dec.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index d508dac8a0..2a74a420e4 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -1672,6 +1672,7 @@ static void ivas_param_ism_dec_dequant_powrat( return; } + static void ivas_ism_get_interpolator( const int16_t subframe_nbslots, float *interpolator ) @@ -1853,6 +1854,7 @@ static void ivas_param_ism_compute_mixing_matrix( } direct_power[w] = sqrtf( direct_power[w] ); } + /* Compute mixing matrix */ computeMixingMatricesISM( nchan_transport, num_wave, nchan_out_woLFE, response_matrix, direct_power, cx_diag[bin_idx], cy_diag, proto_matrix, 1, PARAM_MC_REG_SX, PARAM_MC_REG_GHAT, mixing_matrix[bin_idx] ); @@ -2447,12 +2449,12 @@ void ivas_param_ism_dec( } } } + ivas_ism_param_dec_tc_gain_ajust( st_ivas, output_frame, output_frame / 2, p_tc ); + for ( ch = 0; ch < nchan_transport; ch++ ) { - /*-----------------------------------------------------------------* - * CLDFB Analysis - *-----------------------------------------------------------------*/ + /* CLDFB Analysis */ for ( slot_idx = 0; slot_idx < CLDFB_NO_COL_MAX; slot_idx++ ) { cldfbAnalysis_ts( &( output_f[ch][hSpatParamRendCom->num_freq_bands * slot_idx] ), Cldfb_RealBuffer_in[ch][slot_idx], Cldfb_ImagBuffer_in[ch][slot_idx], hSpatParamRendCom->num_freq_bands, st_ivas->cldfbAnaDec[ch] ); @@ -2469,6 +2471,7 @@ void ivas_param_ism_dec( /* Compute mixing matrix */ ivas_param_ism_compute_mixing_matrix( st_ivas->nchan_ism, hParamIsmDec, st_ivas->hISMDTX, direct_response, nchan_transport, nchan_out_woLFE, cx_diag, ref_power, mixing_matrix ); + /* subframe loop for synthesis*/ for ( subframe_idx = 0; subframe_idx < hSpatParamRendCom->nb_subframes; subframe_idx++ ) { @@ -2565,7 +2568,6 @@ void ivas_ism_dec_digest_tc( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { - ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas ); if ( st_ivas->renderer_type == RENDERER_TD_PANNING || @@ -2602,6 +2604,7 @@ void ivas_ism_dec_digest_tc( { ivas_jbm_dec_get_adapted_linear_interpolator( (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ), st_ivas->hTcBuffer->n_samples_available, st_ivas->hIsmRendererData->interpolator ); } + /* also get the gains here */ num_objects = st_ivas->nchan_transport; for ( i = 0; i < num_objects; i++ ) @@ -2610,10 +2613,7 @@ void ivas_ism_dec_digest_tc( if ( st_ivas->intern_config == IVAS_AUDIO_CONFIG_STEREO ) { - ivas_ism_get_stereo_gains( st_ivas->hIsmMetaData[i]->azimuth, - st_ivas->hIsmMetaData[i]->elevation, - &st_ivas->hIsmRendererData->gains[i][0], - &st_ivas->hIsmRendererData->gains[i][1] ); + ivas_ism_get_stereo_gains( st_ivas->hIsmMetaData[i]->azimuth, st_ivas->hIsmMetaData[i]->elevation, &st_ivas->hIsmRendererData->gains[i][0], &st_ivas->hIsmRendererData->gains[i][1] ); } else { @@ -2794,6 +2794,7 @@ void ivas_param_ism_dec_digest_tc( mvr2r( RealBuffer, &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands ); mvr2r( ImagBuffer, &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands ); } + ivas_param_ism_collect_slot( hParamIsmDec, &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], ch, ref_power, cx_diag ); } } @@ -2820,10 +2821,10 @@ void ivas_param_ism_dec_digest_tc( *-------------------------------------------------------------------------*/ void ivas_ism_param_dec_tc_gain_ajust( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const uint16_t nSamples, /* i : number of samples to be compensate */ - const uint16_t nFadeLength, /* i : length of the crossfade in samples */ - float *transport_channels_f[] /* i : synthesized core-coder transport channels/DirAC output */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const uint16_t nSamples, /* i : number of samples to be compensate */ + const uint16_t nFadeLength, /* i : length of the crossfade in samples */ + float *transport_channels_f[] /* i : synthesized core-coder transport channels/DirAC output*/ ) { @@ -2835,7 +2836,6 @@ void ivas_ism_param_dec_tc_gain_ajust( ene_sum = 0.0f; last_gain = st_ivas->hParamIsmDec->hParamIsm->last_dmx_gain; - for ( i = 0; i < nSamples; i++ ) { ene_tc += transport_channels_f[0][i] * transport_channels_f[0][i] + transport_channels_f[1][i] * transport_channels_f[1][i]; // L*L + R*R @@ -2867,11 +2867,13 @@ void ivas_ism_param_dec_tc_gain_ajust( transport_channels_f[1][i] *= gain; } } + st_ivas->hParamIsmDec->hParamIsm->last_dmx_gain = gain; return; } + /*-------------------------------------------------------------------------* * ivas_ism_param_dec_render_sf() * @@ -2895,7 +2897,6 @@ static void ivas_ism_param_dec_render_sf( float *Cldfb_ImagBuffer_in[PARAM_ISM_MAX_DMX]; PARAM_ISM_DEC_HANDLE hParamIsmDec; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - int16_t slot_idx_start; int16_t idx_in; int16_t idx_lfe; @@ -2928,8 +2929,7 @@ static void ivas_ism_param_dec_render_sf( /* Compute bandwise rendering to target LS using covariance rendering */ ivas_param_ism_render_slot( hParamIsmDec, hSpatParamRendCom, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, - Cldfb_RealBuffer, Cldfb_ImagBuffer, hParamIsmDec->hParamIsmRendering->mixing_matrix_lin, index_slot, slot_idx, - nchan_out_woLFE, nchan_transport ); + Cldfb_RealBuffer, Cldfb_ImagBuffer, hParamIsmDec->hParamIsmRendering->mixing_matrix_lin, index_slot, slot_idx, nchan_out_woLFE, nchan_transport ); } /* CLDFB Synthesis */ @@ -2957,8 +2957,8 @@ static void ivas_ism_param_dec_render_sf( RealBuffer[i] = Cldfb_RealBuffer[idx_in][i]; ImagBuffer[i] = Cldfb_ImagBuffer[idx_in][i]; } - cldfbSynthesis( RealBuffer, ImagBuffer, output_f[ch], - hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] ); + + cldfbSynthesis( RealBuffer, ImagBuffer, output_f[ch], hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] ); idx_in++; } } -- GitLab From bb75db6b3a05a5b28f19c3320faf946363675c32 Mon Sep 17 00:00:00 2001 From: Andrea Eichenseer Date: Wed, 20 Sep 2023 11:06:04 +0200 Subject: [PATCH 10/10] Clang format. --- lib_dec/ivas_dec.c | 4 ++-- lib_dec/ivas_ism_param_dec.c | 2 +- lib_dec/ivas_jbm_dec.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 68b929d650..01b7fe6e5e 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -62,7 +62,7 @@ ivas_error ivas_dec( ) { int16_t n, output_frame, nchan_out; - Decoder_State *st; /* used for bitstream handling */ + Decoder_State *st; /* used for bitstream handling */ float *p_output[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; /* 'float' buffer for output synthesis */ int16_t nchan_remapped; int16_t nb_bits_metadata[MAX_SCE + 1]; @@ -189,7 +189,7 @@ ivas_error ivas_dec( #ifndef PARAM_ISM_REFACTOR if ( ( error = ivas_ism_metadata_dec( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, st_ivas->hDirAC->hParamIsm, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ) != IVAS_ERR_OK ) #else - if ( ( error = ivas_ism_metadata_dec( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, st_ivas->hParamIsmDec->hParamIsm, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_ism_metadata_dec( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, st_ivas->hParamIsmDec->hParamIsm, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ) != IVAS_ERR_OK ) #endif { return error; diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 2a74a420e4..e867d7b2ac 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -2471,7 +2471,7 @@ void ivas_param_ism_dec( /* Compute mixing matrix */ ivas_param_ism_compute_mixing_matrix( st_ivas->nchan_ism, hParamIsmDec, st_ivas->hISMDTX, direct_response, nchan_transport, nchan_out_woLFE, cx_diag, ref_power, mixing_matrix ); - + /* subframe loop for synthesis*/ for ( subframe_idx = 0; subframe_idx < hSpatParamRendCom->nb_subframes; subframe_idx++ ) { diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index cccd2d1874..6ddb8bb48c 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -71,7 +71,7 @@ ivas_error ivas_jbm_dec_tc( ) { int16_t n, output_frame, nchan_out; - Decoder_State *st; /* used for bitstream handling */ + Decoder_State *st; /* used for bitstream handling */ float *p_output[MAX_TRANSPORT_CHANNELS]; /* 'float' buffer for output synthesis */ float output_f[MAX_TRANSPORT_CHANNELS][L_FRAME48k]; /* TODO: can be allocated dynamically using st_ivas->p_output_f */ int16_t nchan_remapped; @@ -592,7 +592,7 @@ ivas_error ivas_jbm_dec_tc( ivas_mono_stereo_downmix_mcmasa( st_ivas, p_output, output_frame ); } } - } + } /*----------------------------------------------------------------* * Write IVAS transport channels -- GitLab