From ba0d3b42b4e3552e8c5e087bfe75f93dd39071f4 Mon Sep 17 00:00:00 2001 From: marc emerit Date: Thu, 11 Dec 2025 16:06:15 +0100 Subject: [PATCH 01/15] ready for testing --- lib_com/options.h | 1 + lib_dec/ivas_init_dec.c | 19 ++- lib_dec/lib_dec.c | 11 +- lib_rend/ivas_crend.c | 2 + lib_rend/ivas_hrtf.c | 226 +++++++++++++++++++++++++++-- lib_rend/ivas_objectRenderer_mix.c | 2 + lib_rend/ivas_prot_rend.h | 52 ++++++- lib_rend/ivas_stat_rend.h | 4 + lib_rend/lib_rend.c | 26 +++- lib_util/hrtf_file_reader.c | 158 +++++++++++++++++++- 10 files changed, 479 insertions(+), 22 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 0e6f20b90c..7cdd5317e5 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -162,6 +162,7 @@ /*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ +#define FIX_2249_MEMORY_LEAK_IN_SBA /* OR : issue 2249 : Memory leak in SBA to BINAURAL_ROOM_REVERB with memory instrumentation */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index a3d954ef2f..ecb9446b0c 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1500,8 +1500,18 @@ ivas_error ivas_init_decoder( if ( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + /* Allocate HRTF statistics */ + if ( ( error = ivas_HRTF_statistics_binary_open( &( st_ivas->hHrtfStatistics ) ) ) != IVAS_ERR_OK ) + { + return error; + } + /* Init HRTF statistics */ + if ( ( error = ivas_HRTF_statistics_init_from_rom( &st_ivas->hHrtfStatistics, output_Fs ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_HRTF_statistics_init( &st_ivas->hHrtfStatistics, output_Fs ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -2990,16 +3000,21 @@ void ivas_destroy_dec( if ( st_ivas->hHrtfTD != NULL ) { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_td_binary_close( &st_ivas->hHrtfTD ); +#else BSplineModelEvalDealloc( &st_ivas->hHrtfTD->ModelParams, &st_ivas->hHrtfTD->ModelEval ); - ivas_HRTF_binary_close( &st_ivas->hHrtfTD ); +#endif } /* CRend binaural renderer handle */ ivas_HRTF_CRend_binary_close( &st_ivas->hHrtfCrend ); +#ifndef FIX_2249_MEMORY_LEAK_IN_SBA /* Fastconv HRTF memories */ ivas_binaural_hrtf_close( &st_ivas->hHrtfFastConv ); +#endif /* Fastconv HRTF filters */ ivas_HRTF_fastconv_binary_close( &st_ivas->hHrtfFastConv ); @@ -3008,7 +3023,7 @@ void ivas_destroy_dec( ivas_HRTF_parambin_binary_close( &st_ivas->hHrtfParambin ); /* HRTF statistics */ - ivas_HRTF_statistics_close( &st_ivas->hHrtfStatistics ); + ivas_HRTF_statistics_binary_close( &st_ivas->hHrtfStatistics ); /* Config. Renderer */ ivas_render_config_close( &( st_ivas->hRenderConfig ) ); diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 8ffb9ba776..223d47bcbb 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -2938,7 +2938,11 @@ ivas_error IVAS_DEC_HRTF_binary_open( /* TD binaural renderer */ if ( ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && st_ivas->hHrtfTD == NULL ) { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + if ( ( error = ivas_HRTF_td_binary_open( &( st_ivas->hHrtfTD ) ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_HRTF_binary_open( &( st_ivas->hHrtfTD ) ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -3008,7 +3012,11 @@ ivas_error IVAS_DEC_HRTF_binary_close( { if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_td_binary_close( &st_ivas->hHrtfTD ); +#else ivas_HRTF_binary_close( &st_ivas->hHrtfTD ); +#endif } if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_CREND || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) @@ -3019,9 +3027,10 @@ ivas_error IVAS_DEC_HRTF_binary_close( if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) { +#ifndef FIX_2249_MEMORY_LEAK_IN_SBA /* Fastconv HRTF memories */ ivas_binaural_hrtf_close( &st_ivas->hHrtfFastConv ); - +#endif /* Fastconv HRTF filters */ ivas_HRTF_fastconv_binary_close( &st_ivas->hHrtfFastConv ); } diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 5341118e3c..b310ab92bc 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -1477,7 +1477,9 @@ void ivas_rend_closeCldfbRend( } ivas_binRenderer_close( &pCldfbRend->hCldfbRend ); +#ifndef FIX_2249_MEMORY_LEAK_IN_SBA ivas_binaural_hrtf_close( &pCldfbRend->hHrtfFastConv ); +#endif ivas_HRTF_fastconv_binary_close( &pCldfbRend->hHrtfFastConv ); return; diff --git a/lib_rend/ivas_hrtf.c b/lib_rend/ivas_hrtf.c index 66c3ca0206..169b77c51e 100644 --- a/lib_rend/ivas_hrtf.c +++ b/lib_rend/ivas_hrtf.c @@ -40,13 +40,17 @@ #include "ivas_rom_binaural_crend_head.h" /*-----------------------------------------------------------------------* - * ivas_HRTF_binary_open() + * ivas_HRTF_td_binary_open() * * Allocate HRTF binary handle for TD renderer *-----------------------------------------------------------------------*/ - +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA +ivas_error ivas_HRTF_td_binary_open( + TDREND_HRFILT_FiltSet_t **hHrtfTD ) +#else ivas_error ivas_HRTF_binary_open( TDREND_HRFILT_FiltSet_t **hHrtfTD ) +#endif { /* Allocate HR filter set for headphones configuration */ *hHrtfTD = (TDREND_HRFILT_FiltSet_t *) malloc( sizeof( TDREND_HRFILT_FiltSet_t ) ); @@ -66,22 +70,79 @@ ivas_error ivas_HRTF_binary_open( * * Close HRTF binary handle for TD renderer *-------------------------------------------------------------------*/ - +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA +void ivas_HRTF_td_binary_close( + TDREND_HRFILT_FiltSet_t **hHrtfTD ) +#else void ivas_HRTF_binary_close( TDREND_HRFILT_FiltSet_t **hHrtfTD ) +#endif { if ( hHrtfTD == NULL || *hHrtfTD == NULL ) { return; } +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + int16_t i; + + if ( ( *hHrtfTD )->ModelParams.modelROM ) + { + BSplineModelEvalDealloc( &( *hHrtfTD )->ModelParams, &( *hHrtfTD )->ModelEval ); + } + else + { + if ( ( *hHrtfTD )->ModelParams.UseItdModel ) + { + free( ( *hHrtfTD )->ModelParamsITD.elevKSeq_dyn ); + free( ( *hHrtfTD )->ModelParamsITD.azimKSeq_dyn ); + free( ( *hHrtfTD )->ModelParamsITD.W_dyn ); + free( ( *hHrtfTD )->ModelParamsITD.azimBsShape_dyn ); + free( ( *hHrtfTD )->ModelParamsITD.elevBsShape_dyn ); + free( ( *hHrtfTD )->ModelParamsITD.azimBsLen_dyn ); + free( ( *hHrtfTD )->ModelParamsITD.azimBsStart_dyn ); + free( ( *hHrtfTD )->ModelParamsITD.elevBsLen_dyn ); + free( ( *hHrtfTD )->ModelParamsITD.elevBsStart_dyn ); + } + free( ( *hHrtfTD )->ModelParams.elevKSeq_dyn ); + free( ( *hHrtfTD )->ModelParams.azim_start_idx_dyn ); + free( ( *hHrtfTD )->ModelParams.azimDim3_dyn ); + free( ( *hHrtfTD )->ModelParams.AlphaL_dyn ); + free( ( *hHrtfTD )->ModelParams.AlphaR_dyn ); + free( ( *hHrtfTD )->ModelParams.azimSegSamples_dyn ); + + free( ( *hHrtfTD )->ModelParams.azimShapeIdx_dyn ); + free( ( *hHrtfTD )->ModelParams.azimShapeSampFactor_dyn ); + free( ( *hHrtfTD )->ModelParams.elevBsLen_dyn ); + free( ( *hHrtfTD )->ModelParams.elevBsStart_dyn ); + free( ( *hHrtfTD )->ModelParams.elevBsShape_dyn ); + + for ( i = 0; i < ( *hHrtfTD )->ModelParams.num_unique_azim_splines; i++ ) + { + free( ( *hHrtfTD )->ModelParams.azimBsShape_dyn[i] ); + } + free( ( *hHrtfTD )->ModelParams.azimBsShape_dyn ); + + free( (void *) ( *hHrtfTD )->ModelParams.azimBsShape ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ + for ( i = 0; i < ( *hHrtfTD )->ModelParams.elevDim3; i++ ) + { + free( ( *hHrtfTD )->ModelParams.azimKSeq[i] ); + } + free( ( *hHrtfTD )->ModelParams.azimKSeq ); + + free( ( *hHrtfTD )->ModelParams.EL_dyn ); + free( ( *hHrtfTD )->ModelParams.ER_dyn ); + + free( ( *hHrtfTD )->ModelEval.hrfModL ); + free( ( *hHrtfTD )->ModelEval.hrfModR ); + } +#endif free( *hHrtfTD ); *hHrtfTD = NULL; return; } - /*-----------------------------------------------------------------------* * ivas_HRTF_CRend_binary_open() * @@ -106,17 +167,45 @@ ivas_error ivas_HRTF_CRend_binary_open( return IVAS_ERR_OK; } - +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA /*-----------------------------------------------------------------------* - * ivas_HRTF_CRend_binary_open_buffers_uint16() + * ivas_HRTF_binary_open_buffers_int16() * * Allocate buffer with dynamic length for HRTF binary Crend handle *-----------------------------------------------------------------------*/ +ivas_error ivas_HRTF_binary_open_buffers_int16( + int16_t **buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +) +{ + *buffer = (int16_t *) malloc( mem_size ); + + if ( *buffer == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" ); + } + + return IVAS_ERR_OK; +} +#endif + +/*-----------------------------------------------------------------------* + * ivas_HRTF_binary_open_buffers_uint16() + * + * Allocate buffer with dynamic length for HRTF binary Crend handle + *-----------------------------------------------------------------------*/ +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA +ivas_error ivas_HRTF_binary_open_buffers_uint16( + uint16_t **buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +) +#else ivas_error ivas_HRTF_CRend_binary_open_buffers_uint16( uint16_t **buffer, /* o : buffer to allocate */ const uint32_t mem_size /* i : size of buffer */ ) +#endif { *buffer = (uint16_t *) malloc( mem_size ); @@ -128,17 +217,22 @@ ivas_error ivas_HRTF_CRend_binary_open_buffers_uint16( return IVAS_ERR_OK; } - /*-----------------------------------------------------------------------* - * ivas_HRTF_CRend_binary_open_buffers_float() + * ivas_HRTF_binary_open_buffers_float() * * Allocate buffer with dynamic length for HRTF binary Crend handle *-----------------------------------------------------------------------*/ - +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA +ivas_error ivas_HRTF_binary_open_buffers_float( + float **buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +) +#else ivas_error ivas_HRTF_CRend_binary_open_buffers_float( float **buffer, /* o : buffer to allocate */ const uint32_t mem_size /* i : size of buffer */ ) +#endif { *buffer = (float *) malloc( mem_size ); @@ -150,6 +244,47 @@ ivas_error ivas_HRTF_CRend_binary_open_buffers_float( return IVAS_ERR_OK; } +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA +/*-----------------------------------------------------------------------* + * ivas_HRTF_binary_open_buffers_float_ptr() + * + * Allocate buffer with dynamic length for HRTF binary Crend handle + *-----------------------------------------------------------------------*/ +ivas_error ivas_HRTF_binary_open_buffers_float_ptr( + float ***buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +) +{ + *buffer = (float **) malloc( mem_size ); + + if ( *buffer == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" ); + } + + return IVAS_ERR_OK; +} +/*-----------------------------------------------------------------------* + * ivas_HRTF_binary_open_buffers_float_ptr() + * + * Allocate buffer with dynamic length for HRTF binary Crend handle + *-----------------------------------------------------------------------*/ +ivas_error ivas_HRTF_binary_open_buffers_float_ptr_const( + const float ***buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +) +{ + *buffer = (const float **) malloc( mem_size ); + + if ( *buffer == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" ); + } + + return IVAS_ERR_OK; +} +#endif + /*-------------------------------------------------------------------* * ivas_HRTF_CRend_binary_close() @@ -242,6 +377,10 @@ void ivas_HRTF_fastconv_binary_close( { return; } +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + /* Fastconv HRTF memories */ + ivas_binaural_hrtf_close( hHrtfFastConv ); +#endif free( *hHrtfFastConv ); *hHrtfFastConv = NULL; @@ -305,7 +444,9 @@ ivas_error ivas_HRTF_statistics_binary_open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for statistics HRTF tables!" ); } - +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + set_c( (int8_t *) ( *hHrtfStatistics ), 0, (int32_t) sizeof( HRTFS_STATISTICS ) ); +#endif return IVAS_ERR_OK; } @@ -315,14 +456,35 @@ ivas_error ivas_HRTF_statistics_binary_open( * * Close HRTF binary handle for statistics handler *-----------------------------------------------------------------------*/ - +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA +void ivas_HRTF_statistics_binary_close( + HRTFS_STATISTICS **hHrtfStatistics ) +#else void ivas_HRTF_statistics_close( HRTFS_STATISTICS **hHrtfStatistics ) +#endif { if ( hHrtfStatistics == NULL || *hHrtfStatistics == NULL ) { return; } +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + if ( ( hHrtfStatistics != NULL ) && ( *hHrtfStatistics != NULL ) && ( ( *hHrtfStatistics )->fromROM == FALSE ) ) + { + if ( ( *hHrtfStatistics )->average_energy_l_dyn != NULL ) + { + free( ( *hHrtfStatistics )->average_energy_l_dyn ); + } + if ( ( *hHrtfStatistics )->average_energy_r_dyn != NULL ) + { + free( ( *hHrtfStatistics )->average_energy_r_dyn ); + } + if ( ( *hHrtfStatistics )->inter_aural_coherence_dyn != NULL ) + { + free( ( *hHrtfStatistics )->inter_aural_coherence_dyn ); + } + } +#endif free( *hHrtfStatistics ); *hHrtfStatistics = NULL; @@ -331,15 +493,52 @@ void ivas_HRTF_statistics_close( } /*-----------------------------------------------------------------------* - * ivas_HRTF_statistics_init() + * ivas_HRTF_statistics_init_from_rom() * * Allocates HRTF statistics handle and initializes from ROM *-----------------------------------------------------------------------*/ - +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA +ivas_error ivas_HRTF_statistics_init_from_rom( + HRTFS_STATISTICS_HANDLE *hHrtfStatistics, + const int32_t sampleRate ) +#else ivas_error ivas_HRTF_statistics_init( HRTFS_STATISTICS_HANDLE *hHrtfStatistics, const int32_t sampleRate ) +#endif { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + if ( hHrtfStatistics == NULL || *hHrtfStatistics != NULL ) + { + /* Tables not initialised */ + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + switch ( sampleRate ) + { + case 48000: + ( *hHrtfStatistics )->average_energy_l = defaultHRIR_left_avg_power_48kHz; + ( *hHrtfStatistics )->average_energy_r = defaultHRIR_right_avg_power_48kHz; + ( *hHrtfStatistics )->inter_aural_coherence = defaultHRIR_coherence_48kHz; + break; + case 32000: + ( *hHrtfStatistics )->average_energy_l = defaultHRIR_left_avg_power_32kHz; + ( *hHrtfStatistics )->average_energy_r = defaultHRIR_right_avg_power_32kHz; + ( *hHrtfStatistics )->inter_aural_coherence = defaultHRIR_coherence_32kHz; + break; + case 16000: + ( *hHrtfStatistics )->average_energy_l = defaultHRIR_left_avg_power_16kHz; + ( *hHrtfStatistics )->average_energy_r = defaultHRIR_right_avg_power_16kHz; + ( *hHrtfStatistics )->inter_aural_coherence = defaultHRIR_coherence_16kHz; + break; + default: + ( *hHrtfStatistics )->average_energy_l = NULL; + ( *hHrtfStatistics )->average_energy_r = NULL; + ( *hHrtfStatistics )->inter_aural_coherence = NULL; + break; + } + ( *hHrtfStatistics )->fromROM = TRUE; +#else HRTFS_STATISTICS *HrtfStatistics; if ( hHrtfStatistics != NULL && *hHrtfStatistics != NULL ) @@ -380,5 +579,6 @@ ivas_error ivas_HRTF_statistics_init( *hHrtfStatistics = HrtfStatistics; +#endif return IVAS_ERR_OK; } diff --git a/lib_rend/ivas_objectRenderer_mix.c b/lib_rend/ivas_objectRenderer_mix.c index 3c63594709..d9120b60c8 100644 --- a/lib_rend/ivas_objectRenderer_mix.c +++ b/lib_rend/ivas_objectRenderer_mix.c @@ -144,6 +144,7 @@ void TDREND_MIX_Dealloc( { BSplineModelEvalDealloc( &hBinRendererTd->HrFiltSet_p->ModelParams, &hBinRendererTd->HrFiltSet_p->ModelEval ); } +#ifndef FIX_2249_MEMORY_LEAK_IN_SBA else { if ( hBinRendererTd->HrFiltSet_p->Elev_p != NULL ) @@ -167,6 +168,7 @@ void TDREND_MIX_Dealloc( hBinRendererTd->HrFiltSet_p->RightFiltSet_p = NULL; } } +#endif if ( hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == 1 ) { diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 2cd33f685e..ce87df82aa 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -554,7 +554,15 @@ void ivas_masa_ext_dirac_render( /*----------------------------------------------------------------------------------* * HRTF *----------------------------------------------------------------------------------*/ +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA +ivas_error ivas_HRTF_td_binary_open( + TDREND_HRFILT_FiltSet_t **hHrtfTD /* i/o: TD renderer HRTF handle */ +); +void ivas_HRTF_td_binary_close( + TDREND_HRFILT_FiltSet_t **hHrtfTD /* i/o: TD renderer HRTF handle */ +); +#else ivas_error ivas_HRTF_binary_open( TDREND_HRFILT_FiltSet_t **hHrtfTD /* i/o: TD renderer HRTF handle */ ); @@ -562,6 +570,7 @@ ivas_error ivas_HRTF_binary_open( void ivas_HRTF_binary_close( TDREND_HRFILT_FiltSet_t **hHrtfTD /* i/o: TD renderer HRTF handle */ ); +#endif ivas_error ivas_HRTF_fastconv_binary_open( HRTFS_FASTCONV **hHrtfFastConv /* i/o: FASTCONV HRTF structure */ @@ -583,28 +592,69 @@ ivas_error ivas_HRTF_CRend_binary_open( HRTFS_CREND_DATA **hHrtfCrend /* i/o: Crend HRTF handle */ ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA +ivas_error ivas_HRTF_binary_open_buffers_uint16( + uint16_t **buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +); + +ivas_error ivas_HRTF_binary_open_buffers_int16( + int16_t **buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +); +#else ivas_error ivas_HRTF_CRend_binary_open_buffers_uint16( uint16_t **buffer, /* o : buffer to allocate */ const uint32_t mem_size /* i : size of buffer */ ); +#endif + +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA +ivas_error ivas_HRTF_binary_open_buffers_float( + float **buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +); +ivas_error ivas_HRTF_binary_open_buffers_float_ptr( + float ***buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +); + +ivas_error ivas_HRTF_binary_open_buffers_float_ptr_const( + const float ***buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +); + +#else ivas_error ivas_HRTF_CRend_binary_open_buffers_float( float **buffer, /* o : buffer to allocate */ const uint32_t mem_size /* i : size of buffer */ ); +#endif void ivas_HRTF_CRend_binary_close( HRTFS_CREND_DATA **hHrtfCrend /* i/o: Crend HRTF handle */ ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA +ivas_error ivas_HRTF_statistics_init_from_rom( + HRTFS_STATISTICS_HANDLE *hHrtfStatistics, /* i/o: HRTF statistics structure */ + const int32_t sampleRate ); /* i : Sample rate */ +#else ivas_error ivas_HRTF_statistics_init( HRTFS_STATISTICS_HANDLE *hHrtfStatistics, /* i/o: HRTF statistics structure */ const int32_t sampleRate /* i : Sample rate */ ); +#endif -void ivas_HRTF_statistics_close( +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA +void ivas_HRTF_statistics_binary_close( + HRTFS_STATISTICS **hHrtfStatistics ); /* i/o: HRTF statistics structure */ +#else + void ivas_HRTF_statistics_close( HRTFS_STATISTICS **hHrtfStatistics /* i/o: HRTF statistics structure */ ); +#endif ivas_error ivas_HRTF_statistics_binary_open( HRTFS_STATISTICS **hHrtfStatistics /* i/o: HRTF statistics structure */ diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index e935c9f9bc..2edcd53c24 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1035,13 +1035,17 @@ typedef struct ivas_hrtf_TDREND_HRFILT_FiltSet_struct int16_t NumPos; int16_t NumElev; float Dist; +#ifndef FIX_2249_MEMORY_LEAK_IN_SBA float *ItdSet_p; +#endif int16_t FiltLength; +#ifndef FIX_2249_MEMORY_LEAK_IN_SBA float *Azim_p; float *Elev_p; float *ItdSetNominal_p; float *LeftFiltSet_p; float *RightFiltSet_p; +#endif ModelParams_t ModelParams; ModelEval_t ModelEval; ModelParamsITD_t ModelParamsITD; diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 9462886b3f..da0d4f746c 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -3239,7 +3239,11 @@ ivas_error IVAS_REND_Open( hIvasRend->hHrtfs.hHrtfStatistics = NULL; if ( asHrtfBinary ) { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + if ( ( error = ivas_HRTF_td_binary_open( &( hIvasRend->hHrtfs.hHrtfTD ) ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_HRTF_binary_open( &( hIvasRend->hHrtfs.hHrtfTD ) ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -3263,7 +3267,18 @@ ivas_error IVAS_REND_Open( if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + /* Allocate HRTF statistics */ + if ( ( error = ivas_HRTF_statistics_binary_open( &( hIvasRend->hHrtfs.hHrtfStatistics ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* Init HRTF statistics */ + if ( ( error = ivas_HRTF_statistics_init_from_rom( &( hIvasRend->hHrtfs.hHrtfStatistics ), hIvasRend->sampleRateOut ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_HRTF_statistics_init( &( hIvasRend->hHrtfs.hHrtfStatistics ), hIvasRend->sampleRateOut ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -8239,16 +8254,25 @@ void IVAS_REND_Close( ivas_external_orientation_close( &hIvasRend->hExternalOrientationData ); ivas_combined_orientation_close( &hIvasRend->hCombinedOrientationData ); +#ifndef FIX_2249_MEMORY_LEAK_IN_SBA /* Fastconv HRTF memories */ ivas_binaural_hrtf_close( &hIvasRend->hHrtfs.hHrtfFastConv ); +#endif /* Parametric binauralizer HRTF filters */ +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_td_binary_close( &( hIvasRend->hHrtfs.hHrtfTD ) ); +#else ivas_HRTF_binary_close( &( hIvasRend->hHrtfs.hHrtfTD ) ); +#endif ivas_HRTF_CRend_binary_close( &( hIvasRend->hHrtfs.hHrtfCrend ) ); ivas_HRTF_fastconv_binary_close( &( hIvasRend->hHrtfs.hHrtfFastConv ) ); ivas_HRTF_parambin_binary_close( &( hIvasRend->hHrtfs.hHrtfParambin ) ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_statistics_binary_close( &( hIvasRend->hHrtfs.hHrtfStatistics ) ); +#else ivas_HRTF_statistics_close( &( hIvasRend->hHrtfs.hHrtfStatistics ) ); - +#endif free( hIvasRend ); *phIvasRend = NULL; diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index e0cb53b09e..3dd5fb7a18 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -296,7 +296,11 @@ static ivas_error TDREND_LoadBSplineBinaryITD( } fread( &modelITD->elevDim3, sizeof( int16_t ), 1, f_hrtf ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_float( &modelITD->elevKSeq_dyn, ( modelITD->elevDim3 - 2 ) * sizeof( float ) ); +#else modelITD->elevKSeq_dyn = (float *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( float ) ); +#endif v_tmp16 = (int16_t *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( int16_t ) ); if ( modelITD->elevKSeq_dyn == NULL || v_tmp16 == NULL ) { @@ -312,7 +316,11 @@ static ivas_error TDREND_LoadBSplineBinaryITD( free( v_tmp16 ); fread( &modelITD->azimDim3, sizeof( int16_t ), 1, f_hrtf ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_float( &modelITD->azimKSeq_dyn, ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( float ) ); +#else modelITD->azimKSeq_dyn = (float *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( float ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ +#endif v_tmp16 = (int16_t *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( int16_t ) ); if ( modelITD->azimKSeq_dyn == NULL || v_tmp16 == NULL ) { @@ -328,7 +336,11 @@ static ivas_error TDREND_LoadBSplineBinaryITD( free( v_tmp16 ); fread( &tmp, sizeof( int16_t ), 1, f_hrtf ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_float( &modelITD->W_dyn, tmp * sizeof( float ) ); +#else modelITD->W_dyn = (float *) malloc( tmp * sizeof( float ) ); +#endif if ( modelITD->W_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -349,13 +361,21 @@ static ivas_error TDREND_LoadBSplineBinaryITD( free( v_tmp16 ); /* azimuth */ +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_int16( &modelITD->azimBsLen_dyn, HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( int16_t ) ); +#else modelITD->azimBsLen_dyn = (int16_t *) malloc( HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( int16_t ) ); +#endif if ( modelITD->azimBsLen_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } fread( modelITD->azimBsLen_dyn, sizeof( int16_t ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_int16( &modelITD->azimBsStart_dyn, HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( int16_t ) ); +#else modelITD->azimBsStart_dyn = (int16_t *) malloc( HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( int16_t ) ); +#endif if ( modelITD->azimBsStart_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -363,7 +383,11 @@ static ivas_error TDREND_LoadBSplineBinaryITD( fread( modelITD->azimBsStart_dyn, sizeof( int16_t ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); fread( &tmp, sizeof( int16_t ), 1, f_hrtf ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_float( &modelITD->azimBsShape_dyn, tmp * sizeof( float ) ); +#else modelITD->azimBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); +#endif v_tmp16 = (int16_t *) malloc( tmp * sizeof( int16_t ) ); if ( modelITD->azimBsShape_dyn == NULL || v_tmp16 == NULL ) { @@ -380,14 +404,22 @@ static ivas_error TDREND_LoadBSplineBinaryITD( fread( &modelITD->azimSegSamples, sizeof( int16_t ), 1, f_hrtf ); - /* elevation */ +/* elevation */ +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_int16( &modelITD->elevBsLen_dyn, HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( int16_t ) ); +#else modelITD->elevBsLen_dyn = (int16_t *) malloc( HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( int16_t ) ); +#endif if ( modelITD->elevBsLen_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } fread( modelITD->elevBsLen_dyn, sizeof( int16_t ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_int16( &modelITD->elevBsStart_dyn, HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( int16_t ) ); +#else modelITD->elevBsStart_dyn = (int16_t *) malloc( HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( int16_t ) ); +#endif if ( modelITD->elevBsStart_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -395,7 +427,11 @@ static ivas_error TDREND_LoadBSplineBinaryITD( fread( modelITD->elevBsStart_dyn, sizeof( int16_t ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); fread( &tmp, sizeof( int16_t ), 1, f_hrtf ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_float( &modelITD->elevBsShape_dyn, tmp * sizeof( float ) ); +#else modelITD->elevBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); +#endif if ( modelITD->elevBsShape_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -494,7 +530,11 @@ static ivas_error TDREND_LoadBSplineBinary( fread( &model->K, sizeof( int16_t ), 1, f_hrtf ); fread( &model->elevDim3, sizeof( int16_t ), 1, f_hrtf ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_float( &model->elevKSeq_dyn, ( model->elevDim3 - 2 ) * sizeof( float ) ); +#else model->elevKSeq_dyn = (float *) malloc( ( model->elevDim3 - 2 ) * sizeof( float ) ); +#endif v_tmp16 = (int16_t *) malloc( ( model->elevDim3 - 2 ) * sizeof( int16_t ) ); if ( model->elevKSeq_dyn == NULL || v_tmp16 == NULL ) @@ -509,10 +549,22 @@ static ivas_error TDREND_LoadBSplineBinary( model->elevKSeq_dyn[j] = v_tmp16[j] * q_scale; } free( v_tmp16 ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_int16( &model->azimDim3_dyn, model->elevDim3 * sizeof( int16_t ) ); +#else model->azimDim3_dyn = (int16_t *) malloc( model->elevDim3 * sizeof( int16_t ) ); +#endif +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_int16( &model->azim_start_idx_dyn, model->elevDim3 * sizeof( int16_t ) ); +#else model->azim_start_idx_dyn = (int16_t *) malloc( model->elevDim3 * sizeof( int16_t ) ); +#endif +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_float_ptr( &model->azimKSeq, model->elevDim3 * sizeof( float * ) ); +#else model->azimKSeq = (float **) malloc( model->elevDim3 * sizeof( float * ) ); +#endif if ( model->azimDim3_dyn == NULL || model->azim_start_idx_dyn == NULL || model->azimKSeq == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -522,7 +574,11 @@ static ivas_error TDREND_LoadBSplineBinary( { fread( &model->azimDim3_dyn[i], sizeof( int16_t ), 1, f_hrtf ); fread( &model->azim_start_idx_dyn[i], sizeof( int16_t ), 1, f_hrtf ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_float( &model->azimKSeq[i], ( model->azimDim3_dyn[i] + 1 ) * sizeof( float ) ); +#else model->azimKSeq[i] = (float *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( float ) ); +#endif v_tmp16 = (int16_t *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( int16_t ) ); if ( model->azimKSeq[i] == NULL || v_tmp16 == NULL ) @@ -539,8 +595,11 @@ static ivas_error TDREND_LoadBSplineBinary( free( v_tmp16 ); } fread( &model->AlphaN, sizeof( int16_t ), 1, f_hrtf ); - +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_float( &model->AlphaL_dyn, model->AlphaN * model->K * sizeof( float ) ); +#else model->AlphaL_dyn = (float *) malloc( model->AlphaN * model->K * sizeof( float ) ); +#endif v_tmp16 = (int16_t *) malloc( model->AlphaN * model->K * sizeof( int16_t ) ); if ( model->AlphaL_dyn == NULL || v_tmp16 == NULL ) @@ -555,7 +614,11 @@ static ivas_error TDREND_LoadBSplineBinary( { model->AlphaL_dyn[j] = v_tmp16[j] * q_scale; /* Q14 */ } +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_float( &model->AlphaR_dyn, model->AlphaN * model->K * sizeof( float ) ); +#else model->AlphaR_dyn = (float *) malloc( model->AlphaN * model->K * sizeof( float ) ); +#endif if ( model->AlphaR_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -571,9 +634,21 @@ static ivas_error TDREND_LoadBSplineBinary( /* azimuth */ fread( &model->num_unique_azim_splines, sizeof( int16_t ), 1, f_hrtf ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_float_ptr_const( &model->azimBsShape, model->num_unique_azim_splines * sizeof( float * ) ); +#else model->azimBsShape = (const float **) malloc( model->num_unique_azim_splines * sizeof( float * ) ); +#endif +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_float_ptr( &model->azimBsShape_dyn, model->num_unique_azim_splines * sizeof( float * ) ); +#else model->azimBsShape_dyn = (float **) malloc( model->num_unique_azim_splines * sizeof( float * ) ); +#endif +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_int16( &model->azimSegSamples_dyn, model->num_unique_azim_splines * sizeof( int16_t ) ); +#else model->azimSegSamples_dyn = (int16_t *) malloc( model->num_unique_azim_splines * sizeof( int16_t ) ); +#endif if ( model->azimBsShape == NULL || model->azimBsShape_dyn == NULL || model->azimSegSamples_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -582,7 +657,11 @@ static ivas_error TDREND_LoadBSplineBinary( for ( i = 0; i < model->num_unique_azim_splines; i++ ) { fread( &tmp, sizeof( int16_t ), 1, f_hrtf ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_float( &model->azimBsShape_dyn[i], tmp * sizeof( float ) ); +#else model->azimBsShape_dyn[i] = (float *) malloc( tmp * sizeof( float ) ); +#endif if ( model->azimBsShape_dyn[i] == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -604,7 +683,11 @@ static ivas_error TDREND_LoadBSplineBinary( free( v_tmp16 ); } +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_int16( &model->azimShapeIdx_dyn, model->elevDim3 * sizeof( int16_t ) ); +#else model->azimShapeIdx_dyn = (int16_t *) malloc( model->elevDim3 * sizeof( int16_t ) ); +#endif if ( model->azimShapeIdx_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -618,13 +701,21 @@ static ivas_error TDREND_LoadBSplineBinary( fread( model->azimShapeSampFactor_dyn, sizeof( int16_t ), model->elevDim3, f_hrtf ); /* elevation */ +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_int16( &model->elevBsLen_dyn, HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( int16_t ) ); +#else model->elevBsLen_dyn = (int16_t *) malloc( HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( int16_t ) ); +#endif if ( model->elevBsLen_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } fread( model->elevBsLen_dyn, sizeof( int16_t ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_int16( &model->elevBsStart_dyn, HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( int16_t ) ); +#else model->elevBsStart_dyn = (int16_t *) malloc( HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( int16_t ) ); +#endif if ( model->elevBsStart_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -633,7 +724,11 @@ static ivas_error TDREND_LoadBSplineBinary( fread( &tmp, sizeof( int16_t ), 1, f_hrtf ); v_tmp16 = (int16_t *) malloc( tmp * sizeof( int16_t ) ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_float( &model->elevBsShape_dyn, tmp * sizeof( float ) ); +#else model->elevBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); +#endif if ( model->elevBsShape_dyn == NULL || v_tmp16 == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -650,7 +745,11 @@ static ivas_error TDREND_LoadBSplineBinary( fread( &model->elevSegSamples, sizeof( int16_t ), 1, f_hrtf ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_float( &model->EL_dyn, model->AlphaN * HRTF_MODEL_N_SECTIONS * sizeof( float ) ); +#else model->EL_dyn = (float *) malloc( model->AlphaN * HRTF_MODEL_N_SECTIONS * sizeof( float ) ); +#endif if ( model->EL_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -664,7 +763,11 @@ static ivas_error TDREND_LoadBSplineBinary( model->EL_dyn[j] = ( (int32_t *) model->EL_dyn )[j] * q_scale; /* Q14 */ } +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_float( &model->ER_dyn, model->AlphaN * HRTF_MODEL_N_SECTIONS * sizeof( float ) ); +#else model->ER_dyn = (float *) malloc( model->AlphaN * HRTF_MODEL_N_SECTIONS * sizeof( float ) ); +#endif if ( model->ER_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -698,8 +801,13 @@ static ivas_error TDREND_LoadBSplineBinary( HRTF_model_precalc( model ); HrFiltSet_p->FiltLength = HrFiltSet_p->ModelParams.K; +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_float( &HrFiltSet_p->ModelEval.hrfModL, model->K * sizeof( float ) ); + ivas_HRTF_binary_open_buffers_float( &HrFiltSet_p->ModelEval.hrfModR, model->K * sizeof( float ) ); +#else HrFiltSet_p->ModelEval.hrfModL = (float *) malloc( model->K * sizeof( float ) ); HrFiltSet_p->ModelEval.hrfModR = (float *) malloc( model->K * sizeof( float ) ); +#endif if ( HrFiltSet_p->ModelEval.hrfModL == NULL || HrFiltSet_p->ModelEval.hrfModR == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -813,9 +921,15 @@ static ivas_error load_reverb_from_binary( if ( is_reverb ) { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_float( &hHrtfStatistics->average_energy_l_dyn, lr_iac_len * sizeof( float ) ); + ivas_HRTF_binary_open_buffers_float( &hHrtfStatistics->average_energy_r_dyn, lr_iac_len * sizeof( float ) ); + ivas_HRTF_binary_open_buffers_float( &hHrtfStatistics->inter_aural_coherence_dyn, lr_iac_len * sizeof( float ) ); +#else hHrtfStatistics->average_energy_l_dyn = (float *) malloc( lr_iac_len * sizeof( float ) ); hHrtfStatistics->average_energy_r_dyn = (float *) malloc( lr_iac_len * sizeof( float ) ); hHrtfStatistics->inter_aural_coherence_dyn = (float *) malloc( lr_iac_len * sizeof( float ) ); +#endif if ( hHrtfStatistics->average_energy_l_dyn == NULL || hHrtfStatistics->average_energy_r_dyn == NULL || hHrtfStatistics->inter_aural_coherence_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -1036,6 +1150,9 @@ void destroy_td_hrtf( IVAS_DEC_HRTF_TD_HANDLE *hHrtf /* i/o: TD rend. HRTF handle */ ) { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_td_binary_close( hHrtf ); +#else int16_t i; if ( ( hHrtf == NULL ) || ( *hHrtf == NULL ) ) @@ -1091,7 +1208,7 @@ void destroy_td_hrtf( } ivas_HRTF_binary_close( hHrtf ); - +#endif return; } @@ -1164,7 +1281,11 @@ static ivas_error create_Crend_HRTF_from_rawdata( { for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + if ( ( error = ivas_HRTF_binary_open_buffers_uint16( &( *hHRTF )->pIndex_frequency_max_dyn[i][j], mem_size ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_HRTF_CRend_binary_open_buffers_uint16( &( *hHRTF )->pIndex_frequency_max_dyn[i][j], mem_size ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -1191,7 +1312,11 @@ static ivas_error create_Crend_HRTF_from_rawdata( for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { mem_size = ( *hHRTF )->num_iterations_diffuse[j] * sizeof( uint16_t ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + if ( ( error = ivas_HRTF_binary_open_buffers_uint16( &( *hHRTF )->pIndex_frequency_max_diffuse_dyn[j], mem_size ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_HRTF_CRend_binary_open_buffers_uint16( &( *hHRTF )->pIndex_frequency_max_diffuse_dyn[j], mem_size ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -1235,7 +1360,11 @@ static ivas_error create_Crend_HRTF_from_rawdata( { for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + if ( ( error = ivas_HRTF_binary_open_buffers_float( &( *hHRTF )->pOut_to_bin_re_dyn[i][j], mem_size_buf ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_HRTF_CRend_binary_open_buffers_float( &( *hHRTF )->pOut_to_bin_re_dyn[i][j], mem_size_buf ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -1262,7 +1391,11 @@ static ivas_error create_Crend_HRTF_from_rawdata( { for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + if ( ( error = ivas_HRTF_binary_open_buffers_float( &( *hHRTF )->pOut_to_bin_im_dyn[i][j], mem_size_buf ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_HRTF_CRend_binary_open_buffers_float( &( *hHRTF )->pOut_to_bin_im_dyn[i][j], mem_size_buf ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -1297,7 +1430,11 @@ static ivas_error create_Crend_HRTF_from_rawdata( /* coeff_diffuse_re : The size depends on pIndex_frequency_max_diffuse */ for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + if ( ( error = ivas_HRTF_binary_open_buffers_float( &( *hHRTF )->pOut_to_bin_diffuse_re_dyn[j], mem_size_buf ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_HRTF_CRend_binary_open_buffers_float( &( *hHRTF )->pOut_to_bin_diffuse_re_dyn[j], mem_size_buf ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -1322,7 +1459,11 @@ static ivas_error create_Crend_HRTF_from_rawdata( /* coeff_diffuse_im : The size depends on pIndex_frequency_max_diffuse */ for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + if ( ( error = ivas_HRTF_binary_open_buffers_float( &( *hHRTF )->pOut_to_bin_diffuse_im_dyn[j], mem_size_buf ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_HRTF_CRend_binary_open_buffers_float( &( *hHRTF )->pOut_to_bin_diffuse_im_dyn[j], mem_size_buf ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -2016,6 +2157,9 @@ void destroy_crend_hrtf( IVAS_DEC_HRTF_CREND_HANDLE *hHrtfCrend /* i/o: Crend HRTF handle */ ) { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_CRend_binary_close( hHrtfCrend ); +#else uint16_t i, j; if ( *hHrtfCrend != NULL && hHrtfCrend != NULL ) @@ -2057,6 +2201,7 @@ void destroy_crend_hrtf( free( *hHrtfCrend ); *hHrtfCrend = NULL; } +#endif return; } @@ -2072,8 +2217,10 @@ void destroy_fastconv_hrtf( IVAS_DEC_HRTF_FASTCONV_HANDLE *hHrtfFastConv /* i/o: FastConv HRTF handle */ ) { +#ifndef FIX_2249_MEMORY_LEAK_IN_SBA /* Fastconv HRTF memories */ ivas_binaural_hrtf_close( hHrtfFastConv ); +#endif /* Fastconv HRTF filters */ ivas_HRTF_fastconv_binary_close( hHrtfFastConv ); @@ -2108,6 +2255,9 @@ void destroy_hrtf_statistics( IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics /* i/o: HRTF statistics handle */ ) { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_statistics_binary_close( hHrtfStatistics ); +#else if ( ( hHrtfStatistics != NULL ) && ( *hHrtfStatistics != NULL ) && ( ( *hHrtfStatistics )->fromROM == FALSE ) ) { if ( ( *hHrtfStatistics )->average_energy_l != NULL ) @@ -2125,6 +2275,6 @@ void destroy_hrtf_statistics( } ivas_HRTF_statistics_close( hHrtfStatistics ); - +#endif return; } -- GitLab From 034573a8390a86508825e4bb450cec68f9deaecb Mon Sep 17 00:00:00 2001 From: marc emerit Date: Thu, 11 Dec 2025 17:21:42 +0100 Subject: [PATCH 02/15] bug fix and fix IVAS_DEC_HRTF_BINARY_WRAPPER --- apps/decoder.c | 41 +++++++++++++++++++++++++++++++++++++++-- lib_rend/ivas_hrtf.c | 2 +- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index f6b55ba00f..9ee831d443 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -159,9 +159,11 @@ typedef struct hrtfFileReader *hrtfReader; char *hrtfFileName; +#ifndef FIX_2249_MEMORY_LEAK_IN_SBA IVAS_DEC_HRTF_TD_HANDLE *hHrtfTD; IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics; +#endif IVAS_BIN_RENDERER_TYPE binaural_renderer; IVAS_BIN_RENDERER_TYPE binaural_renderer_old; @@ -242,8 +244,10 @@ int main( enable_float_exception_trap( FLE_MASK_DENORM | FLE_MASK_UNDERFLOW ); #endif +#ifndef FIX_2249_MEMORY_LEAK_IN_SBA hHrtfBinary.hHrtfTD = NULL; /* just to avoid compilation warning */ hHrtfBinary.hHrtfStatistics = NULL; /* just to avoid compilation warning */ +#endif splitRendBits.bits_buf = splitRendBitsBuf; @@ -849,11 +853,13 @@ cleanup: IVAS_DEC_GetSbaDebugParams( hIvasDec, &numOutChannels, &numTransportChannels, &pca_ingest_channels ); #endif +#ifndef FIX_2249_MEMORY_LEAK_IN_SBA if ( arg.hrtfReaderEnabled ) { destroy_td_hrtf( hHrtfBinary.hHrtfTD ); destroy_hrtf_statistics( hHrtfBinary.hHrtfStatistics ); } +#endif IVAS_DEC_Close( &hIvasDec ); CustomLsReader_close( &hLsCustomReader ); @@ -4146,12 +4152,12 @@ static ivas_error load_hrtf_from_file( /*------------------------------------------------------------------------------------------* * Release HRTF binary data *------------------------------------------------------------------------------------------*/ - +#ifndef FIX_2249_MEMORY_LEAK_IN_SBA if ( !( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && binaural_renderer_sec != IVAS_BIN_RENDERER_TYPE_TDREND && hHrtfBinary->hHrtfTD != NULL ) { destroy_td_hrtf( hHrtfBinary->hHrtfTD ); } - +#endif if ( ( error = IVAS_DEC_HRTF_binary_close( hIvasDec, hHrtfBinary->binaural_renderer_old ) ) != IVAS_ERR_OK ) { return error; @@ -4173,13 +4179,23 @@ static ivas_error load_hrtf_from_file( if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_sec == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) { + +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + IVAS_DEC_HRTF_TD_HANDLE *hHrtfTD = NULL; + if ( ( error = IVAS_DEC_GetHrtfTDrendHandle( hIvasDec, &hHrtfTD ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_DEC_GetHrtfTDrendHandle( hIvasDec, &hHrtfBinary->hHrtfTD ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nIVAS_DEC_GetHrtfTDrendHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); return error; } +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + if ( ( error = load_TDrend_HRTF_binary( *hHrtfTD, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) +#else if ( ( error = load_TDrend_HRTF_binary( *hHrtfBinary->hHrtfTD, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) +#endif { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { @@ -4188,7 +4204,11 @@ static ivas_error load_hrtf_from_file( } else { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + destroy_td_hrtf( hHrtfTD ); +#else destroy_td_hrtf( hHrtfBinary->hHrtfTD ); +#endif } } } @@ -4263,15 +4283,28 @@ static ivas_error load_hrtf_from_file( } } +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + if ( ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND ) && OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) +#else if ( hHrtfBinary->hHrtfStatistics == NULL && ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND ) && OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) +#endif { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics = NULL; + if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfStatistics ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfBinary->hHrtfStatistics ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nIVAS_DEC_GetHrtfStatisticsHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); return error; } +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + if ( ( error = load_reverb_binary( *hHrtfStatistics, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) +#else if ( ( error = load_reverb_binary( *hHrtfBinary->hHrtfStatistics, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) +#endif { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { @@ -4280,7 +4313,11 @@ static ivas_error load_hrtf_from_file( } else { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + destroy_hrtf_statistics( hHrtfStatistics ); +#else destroy_hrtf_statistics( hHrtfBinary->hHrtfStatistics ); +#endif } } } diff --git a/lib_rend/ivas_hrtf.c b/lib_rend/ivas_hrtf.c index 169b77c51e..d2c7d86c55 100644 --- a/lib_rend/ivas_hrtf.c +++ b/lib_rend/ivas_hrtf.c @@ -508,7 +508,7 @@ ivas_error ivas_HRTF_statistics_init( #endif { #ifdef FIX_2249_MEMORY_LEAK_IN_SBA - if ( hHrtfStatistics == NULL || *hHrtfStatistics != NULL ) + if ( hHrtfStatistics == NULL || *hHrtfStatistics == NULL ) { /* Tables not initialised */ return IVAS_ERR_UNEXPECTED_NULL_POINTER; -- GitLab From 7690c562de432190a2c5770103e13866d6f6c2e0 Mon Sep 17 00:00:00 2001 From: marc emerit Date: Fri, 12 Dec 2025 09:01:13 +0100 Subject: [PATCH 03/15] bug fix and missing switch --- apps/renderer.c | 2 ++ lib_dec/ivas_init_dec.c | 4 ++++ lib_rend/lib_rend.c | 9 ++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/renderer.c b/apps/renderer.c index 491433d645..10a9ab9589 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -2082,8 +2082,10 @@ cleanup: RotationFileReader_close( &referenceRotReader ); Vector3PairFileReader_close( &referenceVectorReader ); +#ifndef FIX_2249_MEMORY_LEAK_IN_SBA destroy_td_hrtf( hHrtfTD ); destroy_hrtf_statistics( hHrtfStatistics ); +#endif IVAS_REND_Close( &hIvasRend ); IsmPositionProvider_close( positionProvider ); RenderConfigReader_close( &renderConfigReader ); diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index ecb9446b0c..f0810427af 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -3023,7 +3023,11 @@ void ivas_destroy_dec( ivas_HRTF_parambin_binary_close( &st_ivas->hHrtfParambin ); /* HRTF statistics */ +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA ivas_HRTF_statistics_binary_close( &st_ivas->hHrtfStatistics ); +#else + ivas_HRTF_statistics_close( &st_ivas->hHrtfStatistics ); +#endif /* Config. Renderer */ ivas_render_config_close( &( st_ivas->hRenderConfig ) ); diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index da0d4f746c..f8a89df154 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -3268,10 +3268,13 @@ ivas_error IVAS_REND_Open( if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { #ifdef FIX_2249_MEMORY_LEAK_IN_SBA - /* Allocate HRTF statistics */ - if ( ( error = ivas_HRTF_statistics_binary_open( &( hIvasRend->hHrtfs.hHrtfStatistics ) ) ) != IVAS_ERR_OK ) + if ( hIvasRend->hHrtfs.hHrtfStatistics == NULL ) { - return error; + /* Allocate HRTF statistics */ + if ( ( error = ivas_HRTF_statistics_binary_open( &( hIvasRend->hHrtfs.hHrtfStatistics ) ) ) != IVAS_ERR_OK ) + { + return error; + } } /* Init HRTF statistics */ -- GitLab From 9c8f892078a24ff4110b0b8f32403bba533f6c87 Mon Sep 17 00:00:00 2001 From: marc emerit Date: Fri, 12 Dec 2025 09:19:01 +0100 Subject: [PATCH 04/15] fix clang format --- lib_dec/ivas_init_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index f0810427af..b602846245 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -3023,7 +3023,7 @@ void ivas_destroy_dec( ivas_HRTF_parambin_binary_close( &st_ivas->hHrtfParambin ); /* HRTF statistics */ -#ifdef FIX_2249_MEMORY_LEAK_IN_SBA +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA ivas_HRTF_statistics_binary_close( &st_ivas->hHrtfStatistics ); #else ivas_HRTF_statistics_close( &st_ivas->hHrtfStatistics ); -- GitLab From 06ca0cb5499ac2512665c74fb5343cc631757e46 Mon Sep 17 00:00:00 2001 From: marc emerit Date: Fri, 12 Dec 2025 10:54:27 +0100 Subject: [PATCH 05/15] fix usan error --- apps/decoder.c | 27 ++++++++++++++++----------- lib_dec/ivas_init_dec.c | 10 ++++++---- lib_dec/lib_dec.c | 13 ++++++++++--- lib_dec/lib_dec.h | 5 ++++- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 9ee831d443..836872f43b 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -4291,7 +4291,8 @@ static ivas_error load_hrtf_from_file( { #ifdef FIX_2249_MEMORY_LEAK_IN_SBA IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics = NULL; - if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfStatistics ) ) != IVAS_ERR_OK ) + int16_t initFromRom; + if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfStatistics, &initFromRom ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfBinary->hHrtfStatistics ) ) != IVAS_ERR_OK ) #endif @@ -4299,27 +4300,31 @@ static ivas_error load_hrtf_from_file( fprintf( stderr, "\nIVAS_DEC_GetHrtfStatisticsHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); return error; } - #ifdef FIX_2249_MEMORY_LEAK_IN_SBA - if ( ( error = load_reverb_binary( *hHrtfStatistics, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) + if ( initFromRom ) + { + if ( ( error = load_reverb_binary( *hHrtfStatistics, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) #else if ( ( error = load_reverb_binary( *hHrtfBinary->hHrtfStatistics, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) #endif - { - if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) - { - fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); - return error; - } - else { + if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) + { + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); + return error; + } + else + { #ifdef FIX_2249_MEMORY_LEAK_IN_SBA - destroy_hrtf_statistics( hHrtfStatistics ); + destroy_hrtf_statistics( hHrtfStatistics ); #else destroy_hrtf_statistics( hHrtfBinary->hHrtfStatistics ); #endif + } } +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA } +#endif } return IVAS_ERR_OK; diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index b602846245..8cc2cb3b93 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1501,12 +1501,14 @@ ivas_error ivas_init_decoder( if ( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { #ifdef FIX_2249_MEMORY_LEAK_IN_SBA - /* Allocate HRTF statistics */ - if ( ( error = ivas_HRTF_statistics_binary_open( &( st_ivas->hHrtfStatistics ) ) ) != IVAS_ERR_OK ) + if ( st_ivas->hHrtfStatistics == NULL ) { - return error; + /* Allocate HRTF statistics */ + if ( ( error = ivas_HRTF_statistics_binary_open( &( st_ivas->hHrtfStatistics ) ) ) != IVAS_ERR_OK ) + { + return error; + } } - /* Init HRTF statistics */ if ( ( error = ivas_HRTF_statistics_init_from_rom( &st_ivas->hHrtfStatistics, output_Fs ) ) != IVAS_ERR_OK ) #else diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 223d47bcbb..859f45b385 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -2897,16 +2897,23 @@ ivas_error IVAS_DEC_GetHrtfParamBinHandle( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetHrtfStatisticsHandle( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - IVAS_DEC_HRTF_STATISTICS_HANDLE **hHrtfStatistics /* o : HRTF statistics handle */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_DEC_HRTF_STATISTICS_HANDLE **hHrtfStatistics +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + , /* o : HRTF statistics handle */ + int16_t *intialisedFromRom /* o : int16_t handle */ +#endif ) { - if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfStatistics == NULL ) + if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfStatistics == NULL || intialisedFromRom == NULL ) { return IVAS_ERR_WRONG_PARAMS; } *hHrtfStatistics = &hIvasDec->st_ivas->hHrtfStatistics; +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + *intialisedFromRom = hIvasDec->st_ivas->hHrtfStatistics->fromROM; +#endif return IVAS_ERR_OK; } diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 7ed631b5b9..77a01c07fa 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -462,7 +462,10 @@ ivas_error IVAS_DEC_GetHrtfParamBinHandle( ivas_error IVAS_DEC_GetHrtfStatisticsHandle( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - IVAS_DEC_HRTF_STATISTICS_HANDLE **hHrtfStatistics /* o : HRTF statistics handle */ + IVAS_DEC_HRTF_STATISTICS_HANDLE **hHrtfStatistics, /* o : HRTF statistics handle */ +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + int16_t *intialisedFromRom /* o : int16_t handle */ +#endif ); ivas_error IVAS_DEC_HRTF_binary_open( -- GitLab From a411b197b9b28f889938493fa4cb0418e7d2354b Mon Sep 17 00:00:00 2001 From: marc emerit Date: Fri, 12 Dec 2025 11:27:16 +0100 Subject: [PATCH 06/15] fix missing switch --- lib_dec/lib_dec.c | 4 ++++ lib_dec/lib_dec.h | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 859f45b385..9a1bfe72bb 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -2905,7 +2905,11 @@ ivas_error IVAS_DEC_GetHrtfStatisticsHandle( #endif ) { +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfStatistics == NULL || intialisedFromRom == NULL ) +#else + if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfStatistics == NULL ) +#endif { return IVAS_ERR_WRONG_PARAMS; } diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 77a01c07fa..bcaba7037f 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -462,8 +462,9 @@ ivas_error IVAS_DEC_GetHrtfParamBinHandle( ivas_error IVAS_DEC_GetHrtfStatisticsHandle( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - IVAS_DEC_HRTF_STATISTICS_HANDLE **hHrtfStatistics, /* o : HRTF statistics handle */ + IVAS_DEC_HRTF_STATISTICS_HANDLE **hHrtfStatistics #ifdef FIX_2249_MEMORY_LEAK_IN_SBA +, /* o : HRTF statistics handle */ int16_t *intialisedFromRom /* o : int16_t handle */ #endif ); -- GitLab From 96f1bed062afea490eb79779636f3411ed8ffb20 Mon Sep 17 00:00:00 2001 From: marc emerit Date: Fri, 12 Dec 2025 14:47:14 +0100 Subject: [PATCH 07/15] bug smoke test fix --- lib_util/hrtf_file_reader.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 3dd5fb7a18..c560e44c3b 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -693,7 +693,11 @@ static ivas_error TDREND_LoadBSplineBinary( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } fread( model->azimShapeIdx_dyn, sizeof( int16_t ), model->elevDim3, f_hrtf ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_HRTF_binary_open_buffers_int16( &model->azimShapeSampFactor_dyn, model->elevDim3 * sizeof( int16_t ) ); +#else model->azimShapeSampFactor_dyn = (int16_t *) malloc( model->elevDim3 * sizeof( int16_t ) ); +#endif if ( model->azimShapeSampFactor_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); -- GitLab From e0d9f800ee13df3ae61d8953c56f72525be279a1 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 15 Dec 2025 12:43:53 +0100 Subject: [PATCH 08/15] editorial improvements --- apps/decoder.c | 2 -- lib_dec/ivas_init_dec.c | 1 + lib_rend/ivas_crend.c | 1 + lib_rend/ivas_hrtf.c | 19 +++++++++++++++++++ lib_rend/ivas_prot_rend.h | 3 ++- 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 836872f43b..14f5574279 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -164,7 +164,6 @@ typedef struct IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics; #endif - IVAS_BIN_RENDERER_TYPE binaural_renderer; IVAS_BIN_RENDERER_TYPE binaural_renderer_old; IVAS_BIN_RENDERER_TYPE binaural_renderer_sec; @@ -248,7 +247,6 @@ int main( hHrtfBinary.hHrtfTD = NULL; /* just to avoid compilation warning */ hHrtfBinary.hHrtfStatistics = NULL; /* just to avoid compilation warning */ #endif - splitRendBits.bits_buf = splitRendBitsBuf; /*------------------------------------------------------------------------------------------* diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 8cc2cb3b93..eef85f58ac 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1509,6 +1509,7 @@ ivas_error ivas_init_decoder( return error; } } + /* Init HRTF statistics */ if ( ( error = ivas_HRTF_statistics_init_from_rom( &st_ivas->hHrtfStatistics, output_Fs ) ) != IVAS_ERR_OK ) #else diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index b310ab92bc..854a708ad7 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -1477,6 +1477,7 @@ void ivas_rend_closeCldfbRend( } ivas_binRenderer_close( &pCldfbRend->hCldfbRend ); + #ifndef FIX_2249_MEMORY_LEAK_IN_SBA ivas_binaural_hrtf_close( &pCldfbRend->hHrtfFastConv ); #endif diff --git a/lib_rend/ivas_hrtf.c b/lib_rend/ivas_hrtf.c index d2c7d86c55..4ed6e7f2f5 100644 --- a/lib_rend/ivas_hrtf.c +++ b/lib_rend/ivas_hrtf.c @@ -44,6 +44,7 @@ * * Allocate HRTF binary handle for TD renderer *-----------------------------------------------------------------------*/ + #ifdef FIX_2249_MEMORY_LEAK_IN_SBA ivas_error ivas_HRTF_td_binary_open( TDREND_HRFILT_FiltSet_t **hHrtfTD ) @@ -70,6 +71,7 @@ ivas_error ivas_HRTF_binary_open( * * Close HRTF binary handle for TD renderer *-------------------------------------------------------------------*/ + #ifdef FIX_2249_MEMORY_LEAK_IN_SBA void ivas_HRTF_td_binary_close( TDREND_HRFILT_FiltSet_t **hHrtfTD ) @@ -137,6 +139,7 @@ void ivas_HRTF_binary_close( free( ( *hHrtfTD )->ModelEval.hrfModR ); } #endif + free( *hHrtfTD ); *hHrtfTD = NULL; @@ -168,6 +171,7 @@ ivas_error ivas_HRTF_CRend_binary_open( } #ifdef FIX_2249_MEMORY_LEAK_IN_SBA + /*-----------------------------------------------------------------------* * ivas_HRTF_binary_open_buffers_int16() * @@ -188,6 +192,7 @@ ivas_error ivas_HRTF_binary_open_buffers_int16( return IVAS_ERR_OK; } + #endif /*-----------------------------------------------------------------------* @@ -195,6 +200,7 @@ ivas_error ivas_HRTF_binary_open_buffers_int16( * * Allocate buffer with dynamic length for HRTF binary Crend handle *-----------------------------------------------------------------------*/ + #ifdef FIX_2249_MEMORY_LEAK_IN_SBA ivas_error ivas_HRTF_binary_open_buffers_uint16( uint16_t **buffer, /* o : buffer to allocate */ @@ -217,11 +223,13 @@ ivas_error ivas_HRTF_CRend_binary_open_buffers_uint16( return IVAS_ERR_OK; } + /*-----------------------------------------------------------------------* * ivas_HRTF_binary_open_buffers_float() * * Allocate buffer with dynamic length for HRTF binary Crend handle *-----------------------------------------------------------------------*/ + #ifdef FIX_2249_MEMORY_LEAK_IN_SBA ivas_error ivas_HRTF_binary_open_buffers_float( float **buffer, /* o : buffer to allocate */ @@ -245,11 +253,13 @@ ivas_error ivas_HRTF_CRend_binary_open_buffers_float( } #ifdef FIX_2249_MEMORY_LEAK_IN_SBA + /*-----------------------------------------------------------------------* * ivas_HRTF_binary_open_buffers_float_ptr() * * Allocate buffer with dynamic length for HRTF binary Crend handle *-----------------------------------------------------------------------*/ + ivas_error ivas_HRTF_binary_open_buffers_float_ptr( float ***buffer, /* o : buffer to allocate */ const uint32_t mem_size /* i : size of buffer */ @@ -264,11 +274,14 @@ ivas_error ivas_HRTF_binary_open_buffers_float_ptr( return IVAS_ERR_OK; } + + /*-----------------------------------------------------------------------* * ivas_HRTF_binary_open_buffers_float_ptr() * * Allocate buffer with dynamic length for HRTF binary Crend handle *-----------------------------------------------------------------------*/ + ivas_error ivas_HRTF_binary_open_buffers_float_ptr_const( const float ***buffer, /* o : buffer to allocate */ const uint32_t mem_size /* i : size of buffer */ @@ -377,6 +390,7 @@ void ivas_HRTF_fastconv_binary_close( { return; } + #ifdef FIX_2249_MEMORY_LEAK_IN_SBA /* Fastconv HRTF memories */ ivas_binaural_hrtf_close( hHrtfFastConv ); @@ -444,9 +458,11 @@ ivas_error ivas_HRTF_statistics_binary_open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for statistics HRTF tables!" ); } + #ifdef FIX_2249_MEMORY_LEAK_IN_SBA set_c( (int8_t *) ( *hHrtfStatistics ), 0, (int32_t) sizeof( HRTFS_STATISTICS ) ); #endif + return IVAS_ERR_OK; } @@ -456,6 +472,7 @@ ivas_error ivas_HRTF_statistics_binary_open( * * Close HRTF binary handle for statistics handler *-----------------------------------------------------------------------*/ + #ifdef FIX_2249_MEMORY_LEAK_IN_SBA void ivas_HRTF_statistics_binary_close( HRTFS_STATISTICS **hHrtfStatistics ) @@ -468,6 +485,7 @@ void ivas_HRTF_statistics_close( { return; } + #ifdef FIX_2249_MEMORY_LEAK_IN_SBA if ( ( hHrtfStatistics != NULL ) && ( *hHrtfStatistics != NULL ) && ( ( *hHrtfStatistics )->fromROM == FALSE ) ) { @@ -497,6 +515,7 @@ void ivas_HRTF_statistics_close( * * Allocates HRTF statistics handle and initializes from ROM *-----------------------------------------------------------------------*/ + #ifdef FIX_2249_MEMORY_LEAK_IN_SBA ivas_error ivas_HRTF_statistics_init_from_rom( HRTFS_STATISTICS_HANDLE *hHrtfStatistics, diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index ce87df82aa..dc0862809c 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -554,6 +554,7 @@ void ivas_masa_ext_dirac_render( /*----------------------------------------------------------------------------------* * HRTF *----------------------------------------------------------------------------------*/ + #ifdef FIX_2249_MEMORY_LEAK_IN_SBA ivas_error ivas_HRTF_td_binary_open( TDREND_HRFILT_FiltSet_t **hHrtfTD /* i/o: TD renderer HRTF handle */ @@ -599,7 +600,7 @@ ivas_error ivas_HRTF_binary_open_buffers_uint16( ); ivas_error ivas_HRTF_binary_open_buffers_int16( - int16_t **buffer, /* o : buffer to allocate */ + int16_t **buffer, /* o : buffer to allocate */ const uint32_t mem_size /* i : size of buffer */ ); #else -- GitLab From 09aceded1e04d9f4968582d5b500484c44b4ac40 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 17 Dec 2025 13:20:14 +0100 Subject: [PATCH 09/15] fixes --- apps/decoder.c | 27 ++++------ lib_com/options.h | 1 + lib_dec/ivas_binRenderer_internal.c | 8 ++- lib_dec/ivas_init_dec.c | 13 ++--- lib_dec/lib_dec.c | 15 +----- lib_dec/lib_dec.h | 6 +-- lib_rend/ivas_crend.c | 17 ++++-- lib_rend/ivas_dirac_dec_binaural_functions.c | 10 ++++ lib_rend/ivas_hrtf.c | 6 +++ lib_rend/ivas_objectRenderer_mix.c | 4 ++ lib_rend/ivas_prot_rend.h | 10 +++- lib_rend/ivas_reverb.c | 57 ++++++++++++++++++++ lib_rend/lib_rend.c | 9 ++-- 13 files changed, 128 insertions(+), 55 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 14f5574279..38ce42f00f 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -4289,8 +4289,7 @@ static ivas_error load_hrtf_from_file( { #ifdef FIX_2249_MEMORY_LEAK_IN_SBA IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics = NULL; - int16_t initFromRom; - if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfStatistics, &initFromRom ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfStatistics ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfBinary->hHrtfStatistics ) ) != IVAS_ERR_OK ) #endif @@ -4298,31 +4297,27 @@ static ivas_error load_hrtf_from_file( fprintf( stderr, "\nIVAS_DEC_GetHrtfStatisticsHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); return error; } + #ifdef FIX_2249_MEMORY_LEAK_IN_SBA - if ( initFromRom ) - { - if ( ( error = load_reverb_binary( *hHrtfStatistics, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) + if ( ( error = load_reverb_binary( *hHrtfStatistics, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) #else if ( ( error = load_reverb_binary( *hHrtfBinary->hHrtfStatistics, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) #endif + { + if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) + { + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); + return error; + } + else { - if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) - { - fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); - return error; - } - else - { #ifdef FIX_2249_MEMORY_LEAK_IN_SBA - destroy_hrtf_statistics( hHrtfStatistics ); + destroy_hrtf_statistics( hHrtfStatistics ); #else destroy_hrtf_statistics( hHrtfBinary->hHrtfStatistics ); #endif - } } -#ifdef FIX_2249_MEMORY_LEAK_IN_SBA } -#endif } return IVAS_ERR_OK; diff --git a/lib_com/options.h b/lib_com/options.h index 6bc270ca26..57560f4b44 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -163,6 +163,7 @@ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ #define FIX_2249_MEMORY_LEAK_IN_SBA /* OR : issue 2249 : Memory leak in SBA to BINAURAL_ROOM_REVERB with memory instrumentation */ +#define FIX_2249_HRTF_INIT_HARMONIZATION /* VA: issue 2249: harmonize HRTFs init. between ROM and binary representations */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index 3a0bbfba0f..212afe4e3d 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -504,13 +504,19 @@ static ivas_error ivas_binaural_hrtf_open( /* Initialise tables from ROM */ HRTFS_FASTCONV *HrtfFastConv; +#ifdef FIX_2249_HRTF_INIT_HARMONIZATION + if ( ( error = ivas_HRTF_fastconv_binary_open( &HrtfFastConv ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( HrtfFastConv = (HRTFS_FASTCONV *) malloc( sizeof( HRTFS_FASTCONV ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for FastConv HRTF tables" ); } ivas_init_binaural_hrtf( HrtfFastConv ); - +#endif if ( input_config == IVAS_AUDIO_CONFIG_BINAURAL || renderer_type == RENDERER_BINAURAL_FASTCONV ) { HrtfFastConv->FASTCONV_latency_s = FASTCONV_HRIR_latency_s; diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index eef85f58ac..3067435bbb 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1501,23 +1501,16 @@ ivas_error ivas_init_decoder( if ( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { #ifdef FIX_2249_MEMORY_LEAK_IN_SBA - if ( st_ivas->hHrtfStatistics == NULL ) + if ( ( error = ivas_reverb_HRTF_statistics_open( &( st_ivas->hHrtfStatistics ), output_Fs ) ) != IVAS_ERR_OK ) { - /* Allocate HRTF statistics */ - if ( ( error = ivas_HRTF_statistics_binary_open( &( st_ivas->hHrtfStatistics ) ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } - - /* Init HRTF statistics */ - if ( ( error = ivas_HRTF_statistics_init_from_rom( &st_ivas->hHrtfStatistics, output_Fs ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_HRTF_statistics_init( &st_ivas->hHrtfStatistics, output_Fs ) ) != IVAS_ERR_OK ) -#endif { return error; } +#endif /* Get default reverb values based on format, if custom values were not given */ if ( st_ivas->hDecoderConfig->Opt_RendConfigCustom == 0 ) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 9a1bfe72bb..223d47bcbb 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -2897,27 +2897,16 @@ ivas_error IVAS_DEC_GetHrtfParamBinHandle( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetHrtfStatisticsHandle( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - IVAS_DEC_HRTF_STATISTICS_HANDLE **hHrtfStatistics -#ifdef FIX_2249_MEMORY_LEAK_IN_SBA - , /* o : HRTF statistics handle */ - int16_t *intialisedFromRom /* o : int16_t handle */ -#endif + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_DEC_HRTF_STATISTICS_HANDLE **hHrtfStatistics /* o : HRTF statistics handle */ ) { -#ifdef FIX_2249_MEMORY_LEAK_IN_SBA - if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfStatistics == NULL || intialisedFromRom == NULL ) -#else if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfStatistics == NULL ) -#endif { return IVAS_ERR_WRONG_PARAMS; } *hHrtfStatistics = &hIvasDec->st_ivas->hHrtfStatistics; -#ifdef FIX_2249_MEMORY_LEAK_IN_SBA - *intialisedFromRom = hIvasDec->st_ivas->hHrtfStatistics->fromROM; -#endif return IVAS_ERR_OK; } diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index bcaba7037f..7ed631b5b9 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -462,11 +462,7 @@ ivas_error IVAS_DEC_GetHrtfParamBinHandle( ivas_error IVAS_DEC_GetHrtfStatisticsHandle( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - IVAS_DEC_HRTF_STATISTICS_HANDLE **hHrtfStatistics -#ifdef FIX_2249_MEMORY_LEAK_IN_SBA -, /* o : HRTF statistics handle */ - int16_t *intialisedFromRom /* o : int16_t handle */ -#endif + IVAS_DEC_HRTF_STATISTICS_HANDLE **hHrtfStatistics /* o : HRTF statistics handle */ ); ivas_error IVAS_DEC_HRTF_binary_open( diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 854a708ad7..2e34a38750 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -102,7 +102,7 @@ ivas_error ivas_Crend_hrtf_init( return IVAS_ERR_OK; } - +#ifndef FIX_2249_HRTF_INIT_HARMONIZATION /*------------------------------------------------------------------------- * ivas_hrtf_open() * @@ -138,7 +138,6 @@ static ivas_error ivas_hrtf_open( return IVAS_ERR_OK; } - /*------------------------------------------------------------------------- * ivas_hrtf_close() * @@ -159,7 +158,7 @@ static void ivas_hrtf_close( return; } - +#endif /*------------------------------------------------------------------------- * ivas_rend_initCrend() @@ -206,10 +205,17 @@ static ivas_error ivas_rend_initCrend( else { /* create new handle when HRTF is loaded from ROM, or external renderer is used */ +#ifdef FIX_2249_HRTF_INIT_HARMONIZATION + if ( ( error = ivas_HRTF_CRend_binary_open( &hHrtf ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_hrtf_open( &hHrtf ) ) != IVAS_ERR_OK ) { return error; } +#endif hHrtf->init_from_rom = 1; if ( hHrtfCrend != NULL ) @@ -1362,7 +1368,12 @@ void ivas_rend_closeCrend( if ( ( *pCrend )->hHrtfCrend != NULL && ( *pCrend )->hHrtfCrend->init_from_rom ) { +#ifdef FIX_2249_HRTF_INIT_HARMONIZATION + free( ( *pCrend )->hHrtfCrend ); + ( *pCrend )->hHrtfCrend = NULL; +#else ivas_hrtf_close( &( *pCrend )->hHrtfCrend ); +#endif } for ( pos_idx = 0; pos_idx < MAX_HEAD_ROT_POSES; pos_idx++ ) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index e14414c57e..7e691a0a4a 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -396,6 +396,9 @@ ivas_error ivas_dirac_dec_binaural_copy_hrtfs( ) { int16_t i, j; +#ifdef FIX_2249_HRTF_INIT_HARMONIZATION + ivas_error error; +#endif if ( hHrtfParambin != NULL && *hHrtfParambin != NULL ) { @@ -407,10 +410,17 @@ ivas_error ivas_dirac_dec_binaural_copy_hrtfs( /* Initialise tables from ROM */ HRTFS_PARAMBIN *hrtfParambin; +#ifdef FIX_2249_HRTF_INIT_HARMONIZATION + if ( ( error = ivas_HRTF_parambin_binary_open( &hrtfParambin )) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( hrtfParambin = (HRTFS_PARAMBIN *) malloc( sizeof( HRTFS_PARAMBIN ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for parametric binauralizer HRTF tables" ); } +#endif for ( i = 0; i < BINAURAL_CHANNELS; i++ ) { diff --git a/lib_rend/ivas_hrtf.c b/lib_rend/ivas_hrtf.c index 4ed6e7f2f5..22d0dcb91e 100644 --- a/lib_rend/ivas_hrtf.c +++ b/lib_rend/ivas_hrtf.c @@ -368,7 +368,11 @@ ivas_error ivas_HRTF_fastconv_binary_open( *hHrtfFastConv = (HRTFS_FASTCONV *) malloc( sizeof( HRTFS_FASTCONV ) ); if ( *hHrtfFastConv == NULL ) { +#ifdef FIX_2249_HRTF_INIT_HARMONIZATION + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FastConv HRTF tables!" ); +#else return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FASTCONV HRTF tables!" ); +#endif } ivas_init_binaural_hrtf( *hHrtfFastConv ); @@ -510,6 +514,7 @@ void ivas_HRTF_statistics_close( return; } +#ifndef FIX_2249_MEMORY_LEAK_IN_SBA /*-----------------------------------------------------------------------* * ivas_HRTF_statistics_init_from_rom() * @@ -601,3 +606,4 @@ ivas_error ivas_HRTF_statistics_init( #endif return IVAS_ERR_OK; } +#endif diff --git a/lib_rend/ivas_objectRenderer_mix.c b/lib_rend/ivas_objectRenderer_mix.c index d9120b60c8..230f9f26a4 100644 --- a/lib_rend/ivas_objectRenderer_mix.c +++ b/lib_rend/ivas_objectRenderer_mix.c @@ -224,7 +224,11 @@ ivas_error TDREND_MIX_Init( /* Init HR filter set */ if ( *hHrtfTD == NULL ) { +#ifdef FIX_2249_HRTF_INIT_HARMONIZATION + if ( ( error = ivas_HRTF_td_binary_open( &(hBinRendererTd->HrFiltSet_p )) ) != IVAS_ERR_OK ) +#else if ( ( hBinRendererTd->HrFiltSet_p = (TDREND_HRFILT_FiltSet_t *) malloc( sizeof( TDREND_HRFILT_FiltSet_t ) ) ) == NULL ) +#endif { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); } diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index dc0862809c..00c0bf1ce4 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -637,6 +637,7 @@ void ivas_HRTF_CRend_binary_close( HRTFS_CREND_DATA **hHrtfCrend /* i/o: Crend HRTF handle */ ); +#ifndef FIX_2249_MEMORY_LEAK_IN_SBA #ifdef FIX_2249_MEMORY_LEAK_IN_SBA ivas_error ivas_HRTF_statistics_init_from_rom( HRTFS_STATISTICS_HANDLE *hHrtfStatistics, /* i/o: HRTF statistics structure */ @@ -647,7 +648,7 @@ ivas_error ivas_HRTF_statistics_init( const int32_t sampleRate /* i : Sample rate */ ); #endif - +#endif #ifdef FIX_2249_MEMORY_LEAK_IN_SBA void ivas_HRTF_statistics_binary_close( HRTFS_STATISTICS **hHrtfStatistics ); /* i/o: HRTF statistics structure */ @@ -1015,6 +1016,13 @@ void ivas_binaural_reverb_processSubframe( float outImag[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX] /* o : output CLDFB data imag */ ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA +ivas_error ivas_reverb_HRTF_statistics_open( + HRTFS_STATISTICS_HANDLE *hHrtfStatistics, /* o : HRTF statistics handle */ + const int32_t output_Fs /* i : output sampling rate */ +); + +#endif ivas_error ivas_reverb_open( REVERB_HANDLE *hReverb, /* i/o: Reverberator handle */ const HRTFS_STATISTICS_HANDLE hHrtfStatistics, /* i : HRTF statistics handle */ diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index 3f9e3aef0f..0de176eb7e 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -34,6 +34,9 @@ #include "options.h" #include "prot.h" #include "ivas_prot_rend.h" +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA +#include "ivas_rom_binaural_crend_head.h" +#endif #include "ivas_cnst.h" #ifdef DEBUGGING #include "debug.h" @@ -123,6 +126,60 @@ typedef struct ivas_reverb_params_t static ivas_error calc_jot_t60_coeffs( float *pH_dB, const uint16_t nrFrequencies, float *pFrequencies, float *pCoeffA, float *pCoeffB, const float fNyquist ); +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + +/*------------------------------------------------------------------------- + * ivas_reverb_HRTF_statistics_open() + * + * Open and initialize HRTF statistics handle from ROM tables + *------------------------------------------------------------------------*/ + +ivas_error ivas_reverb_HRTF_statistics_open( + HRTFS_STATISTICS_HANDLE *hHrtfStatistics, /* o : HRTF statistics handle */ + const int32_t output_Fs /* i : output sampling rate */ +) +{ + if ( *hHrtfStatistics != NULL && (*hHrtfStatistics)->fromROM == FALSE ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL, "HRTF statistics allocated but not initialized from binary file!\n" ); + } + + if( ( *hHrtfStatistics = (HRTFS_STATISTICS *) malloc( sizeof( HRTFS_STATISTICS ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for statistics HRTF tables!" ); + } + + /* Init HRTF statistics from ROM */ + switch ( output_Fs ) + { + case 48000: + ( *hHrtfStatistics )->average_energy_l = defaultHRIR_left_avg_power_48kHz; + ( *hHrtfStatistics )->average_energy_r = defaultHRIR_right_avg_power_48kHz; + ( *hHrtfStatistics )->inter_aural_coherence = defaultHRIR_coherence_48kHz; + break; + case 32000: + ( *hHrtfStatistics )->average_energy_l = defaultHRIR_left_avg_power_32kHz; + ( *hHrtfStatistics )->average_energy_r = defaultHRIR_right_avg_power_32kHz; + ( *hHrtfStatistics )->inter_aural_coherence = defaultHRIR_coherence_32kHz; + break; + case 16000: + ( *hHrtfStatistics )->average_energy_l = defaultHRIR_left_avg_power_16kHz; + ( *hHrtfStatistics )->average_energy_r = defaultHRIR_right_avg_power_16kHz; + ( *hHrtfStatistics )->inter_aural_coherence = defaultHRIR_coherence_16kHz; + break; + default: + ( *hHrtfStatistics )->average_energy_l = NULL; + ( *hHrtfStatistics )->average_energy_r = NULL; + ( *hHrtfStatistics )->inter_aural_coherence = NULL; + break; + } + + ( *hHrtfStatistics )->fromROM = TRUE; + + return IVAS_ERR_OK; +} + +#endif /*------------------------------------------------------------------------- * binRend_rand() diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index f8a89df154..dc1b919f66 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -3270,21 +3270,18 @@ ivas_error IVAS_REND_Open( #ifdef FIX_2249_MEMORY_LEAK_IN_SBA if ( hIvasRend->hHrtfs.hHrtfStatistics == NULL ) { - /* Allocate HRTF statistics */ - if ( ( error = ivas_HRTF_statistics_binary_open( &( hIvasRend->hHrtfs.hHrtfStatistics ) ) ) != IVAS_ERR_OK ) + /* Allocate and init HRTF statistics */ + if ( ( error = ivas_reverb_HRTF_statistics_open( &( hIvasRend->hHrtfs.hHrtfStatistics), outputSampleRate ) ) != IVAS_ERR_OK ) { return error; } } - - /* Init HRTF statistics */ - if ( ( error = ivas_HRTF_statistics_init_from_rom( &( hIvasRend->hHrtfs.hHrtfStatistics ), hIvasRend->sampleRateOut ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_HRTF_statistics_init( &( hIvasRend->hHrtfs.hHrtfStatistics ), hIvasRend->sampleRateOut ) ) != IVAS_ERR_OK ) -#endif { return error; } +#endif } return IVAS_ERR_OK; -- GitLab From 262d5d5e38607f4c8b06d1de5f48736922127b29 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 17 Dec 2025 13:28:35 +0100 Subject: [PATCH 10/15] remove FIX_2249_HRTF_INIT_HARMONIZATION --- lib_com/options.h | 1 - lib_dec/ivas_binRenderer_internal.c | 8 +------- lib_rend/ivas_crend.c | 16 ++-------------- lib_rend/ivas_dirac_dec_binaural_functions.c | 10 ---------- lib_rend/ivas_hrtf.c | 7 +++---- lib_rend/ivas_objectRenderer_mix.c | 4 ---- 6 files changed, 6 insertions(+), 40 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 57560f4b44..6bc270ca26 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -163,7 +163,6 @@ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ #define FIX_2249_MEMORY_LEAK_IN_SBA /* OR : issue 2249 : Memory leak in SBA to BINAURAL_ROOM_REVERB with memory instrumentation */ -#define FIX_2249_HRTF_INIT_HARMONIZATION /* VA: issue 2249: harmonize HRTFs init. between ROM and binary representations */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index 212afe4e3d..3a0bbfba0f 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -504,19 +504,13 @@ static ivas_error ivas_binaural_hrtf_open( /* Initialise tables from ROM */ HRTFS_FASTCONV *HrtfFastConv; -#ifdef FIX_2249_HRTF_INIT_HARMONIZATION - if ( ( error = ivas_HRTF_fastconv_binary_open( &HrtfFastConv ) ) != IVAS_ERR_OK ) - { - return error; - } -#else if ( ( HrtfFastConv = (HRTFS_FASTCONV *) malloc( sizeof( HRTFS_FASTCONV ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for FastConv HRTF tables" ); } ivas_init_binaural_hrtf( HrtfFastConv ); -#endif + if ( input_config == IVAS_AUDIO_CONFIG_BINAURAL || renderer_type == RENDERER_BINAURAL_FASTCONV ) { HrtfFastConv->FASTCONV_latency_s = FASTCONV_HRIR_latency_s; diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 2e34a38750..2eef3f723c 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -102,7 +102,7 @@ ivas_error ivas_Crend_hrtf_init( return IVAS_ERR_OK; } -#ifndef FIX_2249_HRTF_INIT_HARMONIZATION + /*------------------------------------------------------------------------- * ivas_hrtf_open() * @@ -158,7 +158,7 @@ static void ivas_hrtf_close( return; } -#endif + /*------------------------------------------------------------------------- * ivas_rend_initCrend() @@ -205,17 +205,10 @@ static ivas_error ivas_rend_initCrend( else { /* create new handle when HRTF is loaded from ROM, or external renderer is used */ -#ifdef FIX_2249_HRTF_INIT_HARMONIZATION - if ( ( error = ivas_HRTF_CRend_binary_open( &hHrtf ) ) != IVAS_ERR_OK ) - { - return error; - } -#else if ( ( error = ivas_hrtf_open( &hHrtf ) ) != IVAS_ERR_OK ) { return error; } -#endif hHrtf->init_from_rom = 1; if ( hHrtfCrend != NULL ) @@ -1368,12 +1361,7 @@ void ivas_rend_closeCrend( if ( ( *pCrend )->hHrtfCrend != NULL && ( *pCrend )->hHrtfCrend->init_from_rom ) { -#ifdef FIX_2249_HRTF_INIT_HARMONIZATION - free( ( *pCrend )->hHrtfCrend ); - ( *pCrend )->hHrtfCrend = NULL; -#else ivas_hrtf_close( &( *pCrend )->hHrtfCrend ); -#endif } for ( pos_idx = 0; pos_idx < MAX_HEAD_ROT_POSES; pos_idx++ ) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 7e691a0a4a..e14414c57e 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -396,9 +396,6 @@ ivas_error ivas_dirac_dec_binaural_copy_hrtfs( ) { int16_t i, j; -#ifdef FIX_2249_HRTF_INIT_HARMONIZATION - ivas_error error; -#endif if ( hHrtfParambin != NULL && *hHrtfParambin != NULL ) { @@ -410,17 +407,10 @@ ivas_error ivas_dirac_dec_binaural_copy_hrtfs( /* Initialise tables from ROM */ HRTFS_PARAMBIN *hrtfParambin; -#ifdef FIX_2249_HRTF_INIT_HARMONIZATION - if ( ( error = ivas_HRTF_parambin_binary_open( &hrtfParambin )) != IVAS_ERR_OK ) - { - return error; - } -#else if ( ( hrtfParambin = (HRTFS_PARAMBIN *) malloc( sizeof( HRTFS_PARAMBIN ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for parametric binauralizer HRTF tables" ); } -#endif for ( i = 0; i < BINAURAL_CHANNELS; i++ ) { diff --git a/lib_rend/ivas_hrtf.c b/lib_rend/ivas_hrtf.c index 22d0dcb91e..ae5fd81529 100644 --- a/lib_rend/ivas_hrtf.c +++ b/lib_rend/ivas_hrtf.c @@ -37,7 +37,10 @@ #include "ivas_error.h" #include "wmc_auto.h" #include "ivas_prot.h" +#ifndef FIX_2249_MEMORY_LEAK_IN_SBA #include "ivas_rom_binaural_crend_head.h" +#endif + /*-----------------------------------------------------------------------* * ivas_HRTF_td_binary_open() @@ -368,11 +371,7 @@ ivas_error ivas_HRTF_fastconv_binary_open( *hHrtfFastConv = (HRTFS_FASTCONV *) malloc( sizeof( HRTFS_FASTCONV ) ); if ( *hHrtfFastConv == NULL ) { -#ifdef FIX_2249_HRTF_INIT_HARMONIZATION - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FastConv HRTF tables!" ); -#else return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FASTCONV HRTF tables!" ); -#endif } ivas_init_binaural_hrtf( *hHrtfFastConv ); diff --git a/lib_rend/ivas_objectRenderer_mix.c b/lib_rend/ivas_objectRenderer_mix.c index 230f9f26a4..d9120b60c8 100644 --- a/lib_rend/ivas_objectRenderer_mix.c +++ b/lib_rend/ivas_objectRenderer_mix.c @@ -224,11 +224,7 @@ ivas_error TDREND_MIX_Init( /* Init HR filter set */ if ( *hHrtfTD == NULL ) { -#ifdef FIX_2249_HRTF_INIT_HARMONIZATION - if ( ( error = ivas_HRTF_td_binary_open( &(hBinRendererTd->HrFiltSet_p )) ) != IVAS_ERR_OK ) -#else if ( ( hBinRendererTd->HrFiltSet_p = (TDREND_HRFILT_FiltSet_t *) malloc( sizeof( TDREND_HRFILT_FiltSet_t ) ) ) == NULL ) -#endif { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); } -- GitLab From 74b80cf52b9e6ea927ca90c08b03520b5aafa390 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 17 Dec 2025 13:39:26 +0100 Subject: [PATCH 11/15] comments --- lib_rend/ivas_hrtf.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib_rend/ivas_hrtf.c b/lib_rend/ivas_hrtf.c index ae5fd81529..46eaf2401c 100644 --- a/lib_rend/ivas_hrtf.c +++ b/lib_rend/ivas_hrtf.c @@ -178,7 +178,7 @@ ivas_error ivas_HRTF_CRend_binary_open( /*-----------------------------------------------------------------------* * ivas_HRTF_binary_open_buffers_int16() * - * Allocate buffer with dynamic length for HRTF binary Crend handle + * Allocate buffer with dynamic length for HRTF binary tables *-----------------------------------------------------------------------*/ ivas_error ivas_HRTF_binary_open_buffers_int16( @@ -201,7 +201,7 @@ ivas_error ivas_HRTF_binary_open_buffers_int16( /*-----------------------------------------------------------------------* * ivas_HRTF_binary_open_buffers_uint16() * - * Allocate buffer with dynamic length for HRTF binary Crend handle + * Allocate buffer with dynamic length for HRTF binary tables *-----------------------------------------------------------------------*/ #ifdef FIX_2249_MEMORY_LEAK_IN_SBA @@ -230,7 +230,7 @@ ivas_error ivas_HRTF_CRend_binary_open_buffers_uint16( /*-----------------------------------------------------------------------* * ivas_HRTF_binary_open_buffers_float() * - * Allocate buffer with dynamic length for HRTF binary Crend handle + * Allocate buffer with dynamic length for HRTF binary tables *-----------------------------------------------------------------------*/ #ifdef FIX_2249_MEMORY_LEAK_IN_SBA @@ -260,7 +260,7 @@ ivas_error ivas_HRTF_CRend_binary_open_buffers_float( /*-----------------------------------------------------------------------* * ivas_HRTF_binary_open_buffers_float_ptr() * - * Allocate buffer with dynamic length for HRTF binary Crend handle + * Allocate buffer with dynamic length for HRTF binary tables *-----------------------------------------------------------------------*/ ivas_error ivas_HRTF_binary_open_buffers_float_ptr( @@ -282,7 +282,7 @@ ivas_error ivas_HRTF_binary_open_buffers_float_ptr( /*-----------------------------------------------------------------------* * ivas_HRTF_binary_open_buffers_float_ptr() * - * Allocate buffer with dynamic length for HRTF binary Crend handle + * Allocate buffer with dynamic length for HRTF binary tables *-----------------------------------------------------------------------*/ ivas_error ivas_HRTF_binary_open_buffers_float_ptr_const( -- GitLab From da45b6e90ac07bb48321342101c632fe4963903d Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 17 Dec 2025 13:55:49 +0100 Subject: [PATCH 12/15] clang-format --- lib_rend/ivas_reverb.c | 6 +++--- lib_rend/lib_rend.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index 0de176eb7e..c98cbcb0d5 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -134,17 +134,17 @@ static ivas_error calc_jot_t60_coeffs( float *pH_dB, const uint16_t nrFrequencie * Open and initialize HRTF statistics handle from ROM tables *------------------------------------------------------------------------*/ -ivas_error ivas_reverb_HRTF_statistics_open( +ivas_error ivas_reverb_HRTF_statistics_open( HRTFS_STATISTICS_HANDLE *hHrtfStatistics, /* o : HRTF statistics handle */ const int32_t output_Fs /* i : output sampling rate */ ) { - if ( *hHrtfStatistics != NULL && (*hHrtfStatistics)->fromROM == FALSE ) + if ( *hHrtfStatistics != NULL && ( *hHrtfStatistics )->fromROM == FALSE ) { return IVAS_ERROR( IVAS_ERR_INTERNAL, "HRTF statistics allocated but not initialized from binary file!\n" ); } - if( ( *hHrtfStatistics = (HRTFS_STATISTICS *) malloc( sizeof( HRTFS_STATISTICS ) ) ) == NULL ) + if ( ( *hHrtfStatistics = (HRTFS_STATISTICS *) malloc( sizeof( HRTFS_STATISTICS ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for statistics HRTF tables!" ); } diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index dc1b919f66..1d22c004ad 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -3271,7 +3271,7 @@ ivas_error IVAS_REND_Open( if ( hIvasRend->hHrtfs.hHrtfStatistics == NULL ) { /* Allocate and init HRTF statistics */ - if ( ( error = ivas_reverb_HRTF_statistics_open( &( hIvasRend->hHrtfs.hHrtfStatistics), outputSampleRate ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_reverb_HRTF_statistics_open( &( hIvasRend->hHrtfs.hHrtfStatistics ), outputSampleRate ) ) != IVAS_ERR_OK ) { return error; } -- GitLab From 2ccfe120e1daaf5d5812c6e81a76f5dcb3d26868 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 17 Dec 2025 15:37:11 +0100 Subject: [PATCH 13/15] fix --- lib_rend/ivas_reverb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index c98cbcb0d5..4db9a4106e 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -139,7 +139,7 @@ ivas_error ivas_reverb_HRTF_statistics_open( const int32_t output_Fs /* i : output sampling rate */ ) { - if ( *hHrtfStatistics != NULL && ( *hHrtfStatistics )->fromROM == FALSE ) + if ( *hHrtfStatistics != NULL && ( *hHrtfStatistics )->fromROM == TRUE ) { return IVAS_ERROR( IVAS_ERR_INTERNAL, "HRTF statistics allocated but not initialized from binary file!\n" ); } -- GitLab From 8e164867effb5e4b4c51ce1cc276d33768739be7 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 17 Dec 2025 16:20:54 +0100 Subject: [PATCH 14/15] fix --- apps/decoder.c | 14 ++++++++++---- lib_dec/ivas_init_dec.c | 9 +++++---- lib_rend/ivas_reverb.c | 10 ++++++++-- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 38ce42f00f..a9fe6155e4 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -4150,6 +4150,7 @@ static ivas_error load_hrtf_from_file( /*------------------------------------------------------------------------------------------* * Release HRTF binary data *------------------------------------------------------------------------------------------*/ + #ifndef FIX_2249_MEMORY_LEAK_IN_SBA if ( !( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && binaural_renderer_sec != IVAS_BIN_RENDERER_TYPE_TDREND && hHrtfBinary->hHrtfTD != NULL ) { @@ -4279,19 +4280,21 @@ static ivas_error load_hrtf_from_file( } } } +#ifndef FIX_2249_MEMORY_LEAK_IN_SBA } +#endif #ifdef FIX_2249_MEMORY_LEAK_IN_SBA if ( ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND ) && OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) #else - if ( hHrtfBinary->hHrtfStatistics == NULL && ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND ) && OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + if ( hHrtfBinary->hHrtfStatistics == NULL && ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND ) && OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) #endif { #ifdef FIX_2249_MEMORY_LEAK_IN_SBA IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics = NULL; if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfStatistics ) ) != IVAS_ERR_OK ) #else - if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfBinary->hHrtfStatistics ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfBinary->hHrtfStatistics ) ) != IVAS_ERR_OK ) #endif { fprintf( stderr, "\nIVAS_DEC_GetHrtfStatisticsHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); @@ -4301,7 +4304,7 @@ static ivas_error load_hrtf_from_file( #ifdef FIX_2249_MEMORY_LEAK_IN_SBA if ( ( error = load_reverb_binary( *hHrtfStatistics, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) #else - if ( ( error = load_reverb_binary( *hHrtfBinary->hHrtfStatistics, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) + if ( ( error = load_reverb_binary( *hHrtfBinary->hHrtfStatistics, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) #endif { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) @@ -4314,11 +4317,14 @@ static ivas_error load_hrtf_from_file( #ifdef FIX_2249_MEMORY_LEAK_IN_SBA destroy_hrtf_statistics( hHrtfStatistics ); #else - destroy_hrtf_statistics( hHrtfBinary->hHrtfStatistics ); + destroy_hrtf_statistics( hHrtfBinary->hHrtfStatistics ); #endif } } } +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA +} +#endif return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 3067435bbb..bb3326de18 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -2989,6 +2989,10 @@ void ivas_destroy_dec( ivas_combined_orientation_close( &st_ivas->hCombinedOrientationData ); /* Time Domain binaural renderer handle */ +#ifdef FIX_2249_MEMORY_LEAK_IN_SBA + ivas_td_binaural_close( &st_ivas->hBinRendererTd ); + ivas_HRTF_td_binary_close( &st_ivas->hHrtfTD ); +#else if ( st_ivas->hBinRendererTd != NULL ) { ivas_td_binaural_close( &st_ivas->hBinRendererTd ); @@ -2996,13 +3000,10 @@ void ivas_destroy_dec( if ( st_ivas->hHrtfTD != NULL ) { -#ifdef FIX_2249_MEMORY_LEAK_IN_SBA - ivas_HRTF_td_binary_close( &st_ivas->hHrtfTD ); -#else BSplineModelEvalDealloc( &st_ivas->hHrtfTD->ModelParams, &st_ivas->hHrtfTD->ModelEval ); ivas_HRTF_binary_close( &st_ivas->hHrtfTD ); -#endif } +#endif /* CRend binaural renderer handle */ ivas_HRTF_CRend_binary_close( &st_ivas->hHrtfCrend ); diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index 4db9a4106e..4197c404a0 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -139,9 +139,15 @@ ivas_error ivas_reverb_HRTF_statistics_open( const int32_t output_Fs /* i : output sampling rate */ ) { - if ( *hHrtfStatistics != NULL && ( *hHrtfStatistics )->fromROM == TRUE ) + if ( *hHrtfStatistics != NULL ) { - return IVAS_ERROR( IVAS_ERR_INTERNAL, "HRTF statistics allocated but not initialized from binary file!\n" ); + if( ( *hHrtfStatistics )->fromROM == TRUE ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL, "HRTF statistics allocated but not initialized from binary file!\n" ); + } + + /* HRTF statistics loaded from binary file */ + return IVAS_ERR_OK; } if ( ( *hHrtfStatistics = (HRTFS_STATISTICS *) malloc( sizeof( HRTFS_STATISTICS ) ) ) == NULL ) -- GitLab From 3772d9cc4dd2473fdb5e5d595d380c0fa755c071 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 17 Dec 2025 16:31:40 +0100 Subject: [PATCH 15/15] clang-format --- apps/decoder.c | 2 +- lib_rend/ivas_reverb.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index a9fe6155e4..28ad8fe7cb 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -4326,7 +4326,7 @@ static ivas_error load_hrtf_from_file( } #endif - return IVAS_ERR_OK; +return IVAS_ERR_OK; } diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index 4197c404a0..c0956405f0 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -141,7 +141,7 @@ ivas_error ivas_reverb_HRTF_statistics_open( { if ( *hHrtfStatistics != NULL ) { - if( ( *hHrtfStatistics )->fromROM == TRUE ) + if ( ( *hHrtfStatistics )->fromROM == TRUE ) { return IVAS_ERROR( IVAS_ERR_INTERNAL, "HRTF statistics allocated but not initialized from binary file!\n" ); } -- GitLab