diff --git a/lib_com/options.h b/lib_com/options.h index 68e801b352a368a5240b03fa358873a31eaceaa9..29d980db05ef534beb08b3257e2e442a428b4e1e 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -160,7 +160,7 @@ #define FIX_I214_CLIPPING_STANDALONE_REND /* Issue 214: TD standalone renderer does not handle clipping */ #define FIX_I218_PARAMISM_NOISY_SPEECH /* Issue 218: Fix noisy speech buffer in ParamISM */ #define FIX_I217_GSC_FLAG_IN_ISM /* Issue 217: fix BER detected in ISM4 due to desynchronized 'GSC_IVAS_mode' parameter */ - +#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 d7feb33256936ed413db192a1156e0f9fad25e21..f8c19d0c10a84a711746a5cf2877d4c4d21ef811 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; @@ -1123,8 +1159,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 +1195,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 ) - { - hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * size ); - } - else +#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 * 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 +1240,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 +1261,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 50369fab6df6656564be67c6b3eac0e0f6087133..2393a41f2f5a831f0f03546264bf605e1a9cf536 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*/