From 1865cf3ddd7ae5267320e8979a956e1ba23cccca Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Tue, 22 Nov 2022 08:45:07 +0100 Subject: [PATCH 1/2] reduce the memory consumption of DirAC and the hDirAC_mem handle for certain bit rates and output configurations, under define FIX_158_DIRAC_MEM, active, self_test BE --- lib_com/options.h | 1 + lib_dec/ivas_dirac_dec.c | 121 +++++++++++++++++++++++++++++++++------ lib_dec/ivas_stat_dec.h | 4 ++ 3 files changed, 110 insertions(+), 16 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index c2ef6ee92d..6837dd2d0d 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -157,6 +157,7 @@ #define FIX_IGF_NOISE_REPETITION /* Issue 182: fix repetition of same noise in IGF */ #define FIX_126_MDFT_FB_STATIC_MEM /* Issue 126: reduce static mem consumption of the MDFT FB for non-SBA formats */ #define FIX_I214_CLIPPING_STANDALONE_REND /* Issue 214: TD standalone renderer does not handle clipping */ +#define FIX_158_DIRAC_MEM /* Issue 158: Reduce memory consumption in the hDirac_mem handle */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index d7feb33256..298bcc4a0b 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -49,8 +49,11 @@ /*-----------------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------------*/ - +#ifdef FIX_158_DIRAC_MEM +static void ivas_dirac_alloc_mem( DIRAC_DEC_HANDLE hDirAC, const RENDERER_TYPE renderer_type, DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem ); +#else static void ivas_dirac_alloc_mem( DIRAC_DEC_HANDLE hDirAC, DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem ); +#endif static void ivas_dirac_free_mem( DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem ); @@ -714,6 +717,13 @@ ivas_error ivas_dirac_dec_config( } } + +#ifdef FIX_158_DIRAC_MEM + if ( flag_config == DIRAC_OPEN ) + { + hDirAC->buffer_energy = NULL; + } +#endif if ( ( flag_config == DIRAC_OPEN && hDirAC->hConfig->dec_param_estim == TRUE ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->hConfig->dec_param_estim == TRUE && dec_param_estim_old == FALSE ) ) ) { hDirAC->index_buffer_intensity = 0; @@ -726,7 +736,12 @@ ivas_error ivas_dirac_dec_config( set_f( hDirAC->buffer_intensity_real[i][j], 0.0f, CLDFB_NO_CHANNELS_MAX ); } } - +#ifdef FIX_158_DIRAC_MEM + if ( hDirAC->buffer_energy == NULL ) + { + hDirAC->buffer_energy = (float *) count_malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); + } +#endif set_f( hDirAC->buffer_energy, 0.0f, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); } else if ( ( flag_config == DIRAC_OPEN && hDirAC->hConfig->dec_param_estim == FALSE ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->hConfig->dec_param_estim == FALSE && dec_param_estim_old == TRUE ) ) ) @@ -742,6 +757,13 @@ ivas_error ivas_dirac_dec_config( hDirAC->buffer_intensity_real[i][j] = NULL; } } +#ifdef FIX_158_DIRAC_MEM + if ( hDirAC->buffer_energy != NULL ) + { + count_free( hDirAC->buffer_energy ); + hDirAC->buffer_energy = NULL; + } +#endif } /* output synthesis */ @@ -752,7 +774,11 @@ ivas_error ivas_dirac_dec_config( { ivas_dirac_free_mem( &( hDirAC->stack_mem ) ); } +#ifdef FIX_158_DIRAC_MEM + ivas_dirac_alloc_mem( hDirAC, st_ivas->renderer_type, &( hDirAC->stack_mem ) ); +#else ivas_dirac_alloc_mem( hDirAC, &( hDirAC->stack_mem ) ); +#endif mvs2s( DirAC_block_grouping, hDirAC->block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); @@ -935,6 +961,13 @@ void ivas_dirac_dec_close( } } } +#ifdef FIX_158_DIRAC_MEM + if ( hDirAC->buffer_energy != NULL ) + { + count_free( hDirAC->buffer_energy ); + hDirAC->buffer_energy = NULL; + } +#endif for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) { @@ -1091,6 +1124,9 @@ void ivas_dirac_dec_close( static void ivas_dirac_alloc_mem( DIRAC_DEC_HANDLE hDirAC, +#ifdef FIX_158_DIRAC_MEM + const RENDERER_TYPE renderer_type, +#endif DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem ) { int16_t num_freq_bands, num_freq_bands_diff, size; @@ -1113,6 +1149,9 @@ static void ivas_dirac_alloc_mem( hDirAC_mem->proto_power_diff_smooth = NULL; hDirAC_mem->direct_responses_square = NULL; hDirAC_mem->frame_dec_f = NULL; +#ifdef FIX_158_DIRAC_MEM + hDirAC_mem->proto_diffuse_buffer_f = NULL; +#endif if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { hDirAC_mem->cy_auto_dir_smooth = (float *) malloc( sizeof( float ) * size ); @@ -1123,8 +1162,14 @@ static void ivas_dirac_alloc_mem( set_zero( hDirAC_mem->proto_power_diff_smooth, size ); hDirAC_mem->direct_responses_square = (float *) malloc( sizeof( float ) * size ); set_zero( hDirAC_mem->direct_responses_square, size ); - - hDirAC_mem->frame_dec_f = (float *) malloc( sizeof( float ) * 2 * num_outputs_diff * num_freq_bands ); +#ifdef FIX_158_DIRAC_MEM + if ( hDirAC->proto_signal_decorr_on && ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) ) + { +#endif + hDirAC_mem->frame_dec_f = (float *) malloc( sizeof( float ) * 2 * num_outputs_diff * num_freq_bands ); +#ifdef FIX_158_DIRAC_MEM + } +#endif } hDirAC->h_output_synthesis_psd_state.proto_power_smooth = hDirAC_mem->proto_power_smooth; hDirAC->h_output_synthesis_psd_state.proto_power_diff_smooth = hDirAC_mem->proto_power_diff_smooth; @@ -1153,21 +1198,44 @@ static void ivas_dirac_alloc_mem( hDirAC->h_output_synthesis_psd_state.direct_responses = hDirAC_mem->direct_responses; /* Prototypes */ - hDirAC_mem->proto_direct_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_protos_dir * num_freq_bands ); - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) +#ifdef FIX_158_DIRAC_MEM + hDirAC_mem->proto_direct_buffer_f = NULL; + hDirAC_mem->proto_diffuse_buffer_f = NULL; + if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) { - hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * size ); - } - else - { - hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_outputs_diff * num_freq_bands ); +#endif + hDirAC_mem->proto_direct_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_protos_dir * num_freq_bands ); +#ifdef FIX_158_DIRAC_MEM + if ( hDirAC->proto_signal_decorr_on ) + { +#endif + if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) + { + hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * size ); + } + else + { + hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_outputs_diff * num_freq_bands ); + } +#ifdef FIX_158_DIRAC_MEM + } } +#endif hDirAC->h_output_synthesis_psd_state.proto_direct_buffer_f = hDirAC_mem->proto_direct_buffer_f; hDirAC->h_output_synthesis_psd_state.proto_diffuse_buffer_f = hDirAC_mem->proto_diffuse_buffer_f; /* Gains/power factors*/ - hDirAC_mem->direct_power_factor = (float *) malloc( sizeof( float ) * num_freq_bands ); - hDirAC_mem->diffuse_power_factor = (float *) malloc( sizeof( float ) * num_freq_bands ); +#ifdef FIX_158_DIRAC_MEM + hDirAC_mem->direct_power_factor = NULL; + hDirAC_mem->diffuse_power_factor = NULL; + if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) + { +#endif + hDirAC_mem->direct_power_factor = (float *) malloc( sizeof( float ) * num_freq_bands ); + hDirAC_mem->diffuse_power_factor = (float *) malloc( sizeof( float ) * num_freq_bands ); +#ifdef FIX_158_DIRAC_MEM + } +#endif hDirAC->h_output_synthesis_psd_state.direct_power_factor = hDirAC_mem->direct_power_factor; hDirAC->h_output_synthesis_psd_state.diffuse_power_factor = hDirAC_mem->diffuse_power_factor; @@ -1175,8 +1243,20 @@ static void ivas_dirac_alloc_mem( hDirAC_mem->onset_filter = NULL; if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ); - hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands ); +#ifdef FIX_158_DIRAC_MEM + if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) + { +#endif + hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ); +#ifdef FIX_158_DIRAC_MEM + if ( hDirAC->proto_signal_decorr_on ) + { +#endif + hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands ); +#ifdef FIX_158_DIRAC_MEM + } + } +#endif } else { @@ -1184,11 +1264,20 @@ static void ivas_dirac_alloc_mem( { hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 5 * num_freq_bands ); } +#ifndef FIX_158_DIRAC_MEM else { hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * num_freq_bands ); } - hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ); +#endif +#ifdef FIX_158_DIRAC_MEM + if ( hDirAC->proto_signal_decorr_on ) + { +#endif + hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ); +#ifdef FIX_158_DIRAC_MEM + } +#endif } return; diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 50369fab6d..2393a41f2f 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -663,7 +663,11 @@ typedef struct ivas_dirac_dec_data_structure /*Parameter estimation*/ int16_t index_buffer_intensity; float *buffer_intensity_real[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; +#ifdef FIX_158_DIRAC_MEM + float *buffer_energy; +#else float buffer_energy[DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX]; +#endif /*Decoder parameters */ /*Prototypes*/ -- GitLab From ec3b686a07e9f8de0a2ea5a36da9bc392878440b Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 22 Nov 2022 12:22:07 +0100 Subject: [PATCH 2/2] remove doubled initialization --- lib_dec/ivas_dirac_dec.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 298bcc4a0b..f8c19d0c10 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1149,9 +1149,6 @@ static void ivas_dirac_alloc_mem( hDirAC_mem->proto_power_diff_smooth = NULL; hDirAC_mem->direct_responses_square = NULL; hDirAC_mem->frame_dec_f = NULL; -#ifdef FIX_158_DIRAC_MEM - hDirAC_mem->proto_diffuse_buffer_f = NULL; -#endif if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { hDirAC_mem->cy_auto_dir_smooth = (float *) malloc( sizeof( float ) * size ); -- GitLab