From 3596358ea07a128091456bc53d3b969371161ec3 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 6 Dec 2022 11:37:45 +0100 Subject: [PATCH 1/5] Issue 231: define SPAR covariance buffers in stack instead of inter-frame heap; under COVARIANCE_MEMORY_OPT --- lib_com/options.h | 4 +- lib_enc/ivas_spar_encoder.c | 136 +++++++++++++++++++++++++++++++++++- lib_enc/ivas_spar_md_enc.c | 9 ++- lib_enc/ivas_stat_enc.h | 2 + 4 files changed, 146 insertions(+), 5 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 0ec45254f9..a3cc817f54 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -175,7 +175,9 @@ #define FIX_GET_DELAY_RETURN /* Issue 223: change return data type in function get_delay() */ #define NTT_REDUC_COMP_POC /* Contribution : Complexity reduction of phase spectrum in stereo downmix*/ -#define FIX_ISM_INACTIVE_BITS /* fix bitbudget distribution in inactive frames in ISM format */ +//#define FIX_ISM_INACTIVE_BITS /* fix bitbudget distribution in inactive frames in ISM format */ + +#define COVARIANCE_MEMORY_OPT /* Issue 231: define SPAR covariance buffers in stack instead of inter-frame heap */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index b08eeb5e4b..0dd5346e84 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -325,6 +325,120 @@ ivas_error ivas_spar_enc( } +#ifdef COVARIANCE_MEMORY_OPT +/*-------------------------------------------------------------------* + * ivas_spar_cov_md_process() + * + * Process call for SPAR covariance and MD encoder + *-------------------------------------------------------------------*/ + +static void ivas_spar_cov_md_process( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + BSTR_ENC_HANDLE hMetaData, + const int16_t nchan_inp, + const int16_t sba_order, + float *ppIn_FR_real[IVAS_SPAR_MAX_CH], + float *ppIn_FR_imag[IVAS_SPAR_MAX_CH], + const int16_t transient_det, + const int16_t dtx_vad ) +{ + int16_t i, j, i_ts, b, table_idx; + float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + float cov_real_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + float cov_dtx_real_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + ENCODER_CONFIG_HANDLE hEncoderConfig = st_ivas->hEncoderConfig; + SPAR_ENC_HANDLE hSpar = st_ivas->hSpar; + IVAS_QMETADATA_HANDLE hQMetaData = st_ivas->hQMetaData; + + /*-----------------------------------------------------------------------------------------* + * Covariance process + *-----------------------------------------------------------------------------------------*/ + + for ( i = 0; i < nchan_inp; i++ ) + { + for ( j = 0; j < nchan_inp; j++ ) + { + cov_real[i][j] = cov_real_buf[i][j]; + cov_dtx_real[i][j] = cov_dtx_real_buf[i][j]; + } + } + + ivas_enc_cov_handler_process( hSpar->hCovEnc, ppIn_FR_real, ppIn_FR_imag, cov_real, cov_dtx_real, hSpar->hFbMixer->pFb, 0, hSpar->hFbMixer->pFb->filterbank_num_bands, nchan_inp, dtx_vad, transient_det ); + + /*-----------------------------------------------------------------------------------------* + * Set SPAR bitrates + *-----------------------------------------------------------------------------------------*/ + + table_idx = ivas_get_spar_table_idx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); + + if ( hSpar->hMdEnc->table_idx != table_idx ) + { + hSpar->hMdEnc->table_idx = table_idx; + ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, ( hSpar->hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND ); + } + + /*-----------------------------------------------------------------------------------------* + * MetaData encoder + *-----------------------------------------------------------------------------------------*/ + + if ( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) + { + ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order ); + } + + { + float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + float diffuseness[IVAS_MAX_NUM_BANDS]; + float Wscale_d[IVAS_MAX_NUM_BANDS]; + int16_t d_start_band, d_end_band; + int16_t dirac_band_idx; + + d_start_band = hSpar->enc_param_start_band; + d_end_band = IVAS_MAX_NUM_BANDS; + + for ( b = d_start_band; b < d_end_band; b++ ) + { + dirac_band_idx = hSpar->dirac_to_spar_md_bands[b] - d_start_band; + for ( i_ts = 0; i_ts < hQMetaData->q_direction->cfg.nblocks; i_ts++ ) + { + azi_dirac[b][i_ts] = hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[i_ts]; + ele_dirac[b][i_ts] = hQMetaData->q_direction->band_data[dirac_band_idx].elevation[i_ts]; + } + diffuseness[b] = 1.0f - hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0]; + } + + if ( d_start_band >= 6 && dtx_vad == 1 ) + { + mvr2r( hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_quant_re, hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_re, IVAS_SPAR_MAX_CH - 1 ); + } + + for ( b = d_start_band; b < d_end_band; b++ ) + { + Wscale_d[b] = 1.0f; + for ( i = 1; i < nchan_inp; i++ ) + { + Wscale_d[b] += cov_real[i][i][b] / max( EPSILON, cov_real[0][0][b] ); + } + Wscale_d[b] = Wscale_d[b] / ( 1.0f + (float) sba_order ); /*DirAC normalized signal variance sums to 1 + order*/ + Wscale_d[b] = sqrtf( Wscale_d[b] ); + Wscale_d[b] = min( 2.0f, max( Wscale_d[b], 1.0f ) ); + } + + ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, 1, hSpar->hMdEnc->mixer_mat, &hSpar->hMdEnc->spar_md, &hSpar->hMdEnc->spar_md_cfg, d_start_band, d_end_band, ( hSpar->hMdEnc->spar_hoa_md_flag ) ? 1 : sba_order, dtx_vad, Wscale_d ); + } + + if ( hSpar->hMdEnc->spar_hoa_md_flag ) + { + ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order ); + } + + return; +} +#endif + + /*-----------------------------------------------------------------------------------------* * Function ivas_spar_enc_process() * @@ -343,10 +457,13 @@ static ivas_error ivas_spar_enc_process( float *p_pcm_tmp[IVAS_SPAR_MAX_CH]; int16_t i, j, b, i_ts, input_frame, transient_det, dtx_vad; int32_t ivas_total_brate, input_Fs; +#ifdef COVARIANCE_MEMORY_OPT + int16_t nchan_inp, sba_order; +#else float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - int16_t nchan_inp, nchan_transport, sba_order; int16_t table_idx; +#endif int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; ivas_error error; const int16_t *order; @@ -523,6 +640,9 @@ static ivas_error ivas_spar_enc_process( } } +#ifdef COVARIANCE_MEMORY_OPT + ivas_spar_cov_md_process( st_ivas, hMetaData, nchan_inp, sba_order, ppIn_FR_real, ppIn_FR_imag, transient_det, dtx_vad ); +#else /*-----------------------------------------------------------------------------------------* * Covariance process *-----------------------------------------------------------------------------------------*/ @@ -531,8 +651,13 @@ static ivas_error ivas_spar_enc_process( { for ( j = 0; j < nchan_inp; j++ ) { +#ifdef COVARIANCE_MEMORY_OPT + cov_real[i][j] = cov_real_buf[i][j]; + cov_dtx_real[i][j] = cov_dtx_real_buf[i][j]; +#else cov_real[i][j] = hSpar->hMdEnc->cov_real[i][j]; cov_dtx_real[i][j] = hSpar->hMdEnc->cov_dtx_real[i][j]; +#endif } } @@ -607,12 +732,17 @@ static ivas_error ivas_spar_enc_process( { ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order ); } +#endif /*-----------------------------------------------------------------------------------------* * FB mixer *-----------------------------------------------------------------------------------------*/ +#ifdef COVARIANCE_MEMORY_OPT + ivas_fb_mixer_get_in_out_mapping( hSpar->hFbMixer->fb_cfg, st_ivas->nchan_transport, ENC, remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order], in_out_mixer_map ); +#else ivas_fb_mixer_get_in_out_mapping( hSpar->hFbMixer->fb_cfg, nchan_transport, ENC, remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order], in_out_mixer_map ); +#endif #ifdef DEBUG_SBA_MD_DUMP { @@ -765,7 +895,11 @@ static ivas_error ivas_spar_enc_process( order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; +#ifdef COVARIANCE_MEMORY_OPT + for ( j = 0; j < st_ivas->nchan_transport; j++ ) +#else for ( j = 0; j < nchan_transport; j++ ) +#endif { mvr2r( p_pcm_tmp[j], data_f[order[j]], input_frame ); } diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 09c766b581..24d42b2369 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -147,6 +147,7 @@ ivas_error ivas_spar_md_enc_open( } } +#ifndef COVARIANCE_MEMORY_OPT if ( ( hMdEnc->cov_real = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR cov real matrix" ); @@ -184,7 +185,7 @@ ivas_error ivas_spar_md_enc_open( } } } - +#endif if ( ( hMdEnc->mixer_mat_local = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); @@ -249,6 +250,7 @@ void ivas_spar_md_enc_close( count_free( hMdEnc->mixer_mat ); } +#ifndef COVARIANCE_MEMORY_OPT if ( hMdEnc->cov_real != NULL ) { for ( i = 0; i < num_channels; i++ ) @@ -276,7 +278,7 @@ void ivas_spar_md_enc_close( } count_free( hMdEnc->cov_dtx_real ); } - +#endif if ( hMdEnc->mixer_mat_local != NULL ) { for ( i = 0; i < num_channels; i++ ) @@ -363,6 +365,7 @@ static ivas_error ivas_spar_md_enc_init( } } +#ifndef COVARIANCE_MEMORY_OPT for ( i = 0; i < num_channels; i++ ) { for ( j = 0; j < num_channels; j++ ) @@ -374,7 +377,7 @@ static ivas_error ivas_spar_md_enc_init( } } } - +#endif ivas_clear_band_coeffs( hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdEnc->spar_md.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdEnc->spar_md_prior.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 0644fcd918..50a4bdbb65 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -638,8 +638,10 @@ typedef struct ivas_spar_md_enc_state_t int16_t num_decorr; float ***mixer_mat; +#ifndef COVARIANCE_MEMORY_OPT float ***cov_real; float ***cov_dtx_real; +#endif float ***mixer_mat_local; ivas_spar_md_com_cfg spar_md_cfg; ivas_arith_coeffs_t arith_coeffs; -- GitLab From 857ec60588aefc5c54adf9ba151ee204544a2a93 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 6 Dec 2022 11:38:53 +0100 Subject: [PATCH 2/5] merge from main --- lib_com/options.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index a0f3493559..b75ba0e983 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -175,14 +175,13 @@ #define FIX_GET_DELAY_RETURN /* Issue 223: change return data type in function get_delay() */ #define NTT_REDUC_COMP_POC /* NTT Contribution 10: Complexity reduction of phase spectrum in stereo downmix*/ #define FIX_ISM_DECODER_PRINTOUT /* Issue 229: fix ISM decoder printout */ +#define FIX_ITD_CNG /* Eri: Fix for CNG ITD */ //#define FIX_ISM_INACTIVE_BITS /* fix bitbudget distribution in inactive frames in ISM format */ #define COVARIANCE_MEMORY_OPT /* Issue 231: define SPAR covariance buffers in stack instead of inter-frame heap */ -#define FIX_ITD_CNG /* Eri: Fix for CNG ITD */ - /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ #endif -- GitLab From 43747a1f8487b5987f6f9188437d254b35262b34 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 21 Jun 2023 08:12:48 +0200 Subject: [PATCH 3/5] remove obsolete define --- lib_com/options.h | 1 - 1 file changed, 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 543bc7e451..b4773b1615 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -150,7 +150,6 @@ #ifdef IND_LIST_DYN #define FIX_545_ASSERT /* VA: fix issue 545, replace assert() with warning message when hitting memory limit in the buffer of indices */ #endif -#define FIX_ITD_CNG /* Eri: Fix for CNG ITD */ #define FIX_383_CLEAN_UP /* Dlb : Clean up of unused functions */ #define FIX_532_ISM_MD_INACTIVE /* VA: issue 532: improve MD coding in ISM inactive frames */ -- GitLab From f28f44873430429f69e09581c825dc2603d4dc53 Mon Sep 17 00:00:00 2001 From: rtyag Date: Thu, 20 Jul 2023 15:26:23 +1000 Subject: [PATCH 4/5] merge issue fix in options.h --- lib_com/options.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 675ef76c62..9a0f6f3067 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -179,7 +179,9 @@ #define FIX_570_SF_EXT_ORIENTATION #define FIX_593_STL_INCLUDE /* FhG: Issue 593: correct include of stl.h in lib_enc/ivas_stereo_eclvq_enc.c */ #define FIX_583_CLANG_TRANS_DET /* FhG: Issue 583: clang left shift on ramp_up_flag in transient detector */ -#define COVARIANCE_MEMORY_OPT /* Issue 231: define SPAR covariance buffers in stack instead of inter-frame heap */ +#define FIX_280_PLANAR_CP /* Dlb : fix issue 28 : remove planarCP=1 related code*/ +#define CODE_CLEAN_UP_DIRAC /* Dlb : code clean up*/ +#define COVARIANCE_MEMORY_OPT /* Dlb : Issue 231: define SPAR covariance buffers in stack instead of inter-frame heap */ #define NONBE_FIX_589_JBM_TC_OFFSETS /* FhG: issue 589: wrong offset into the TC buffers is used in some rendering paths in the JBM main rendering function */ #define FIX_MEM_REALLOC_IND_LIST /* VA: issue 601: failure of the automatic memory re-allocation mechanism when ind_list[] buffer is depleted in MASA mode with 2 TC*/ #define FIX_581_CLANG_OFFSET_TO_NULL /* FhG: issue 581: fix CLANG error about applying an offset to a NULL pointer */ @@ -204,7 +206,6 @@ #define CR_FIX_585_MASA_2TC_DTX_EXT /* Nokia: issue 585: fixes transition artifacts in MASA 2TC DTX by applying correct condition */ - /* ##################### End NON-BE CR switches ########################### */ -- GitLab From 75ff4837bef721a992df10b1632d25885a0a41d3 Mon Sep 17 00:00:00 2001 From: rtyag Date: Thu, 20 Jul 2023 15:59:00 +1000 Subject: [PATCH 5/5] dummy commit --- lib_dec/ivas_spar_md_dec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 6d7e58829e..a4ee09adc1 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -598,6 +598,7 @@ ivas_error ivas_spar_md_dec_init( { set_zero( hMdDec->smooth_buf[i], 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); } + for ( i = 0; i < IVAS_SPAR_MAX_CH; i++ ) { for ( j = 0; j < IVAS_SPAR_MAX_CH; j++ ) -- GitLab