From 649654943b3b07844d18e2dddb45c68956c23567 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 5 Oct 2022 12:40:29 +0200 Subject: [PATCH 1/8] reduction of static RAM usage in fastconv binaural renderer; under SRAM_REDUCTION_BINRENDERER --- lib_com/options.h | 4 +++- lib_dec/ivas_binauralRenderer.c | 33 +++++++++++++++++++++++++++++++++ lib_dec/ivas_stat_dec.h | 5 +++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 038c9ece53..69718d0a9c 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -58,7 +58,7 @@ #ifdef DEBUGGING -/*#define MEM_COUNT_DETAILS*/ /* RAM counting tool: print per sub-structure details */ +#define MEM_COUNT_DETAILS /* RAM counting tool: print per sub-structure details */ /*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO @@ -156,6 +156,8 @@ #define DRAM_REDUCTION_MCT_IGF /* Issue 121: reduce dynamic RAM consumption in MCT IGF */ +#define SRAM_REDUCTION_BINRENDERER /* reduction of static RAM usage in fastconv binaural renderer */ + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ #endif diff --git a/lib_dec/ivas_binauralRenderer.c b/lib_dec/ivas_binauralRenderer.c index 153e159adc..4ded855668 100644 --- a/lib_dec/ivas_binauralRenderer.c +++ b/lib_dec/ivas_binauralRenderer.c @@ -186,6 +186,24 @@ static ivas_error ivas_binRenderer_convModuleOpen( } } +#ifdef SRAM_REDUCTION_BINRENDERER + for ( int16_t i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( int16_t j = 0; j < MAX_OUTPUT_CHANNELS; j++ ) + { + if ( ( hBinRenConvModule->filterStatesLeftReal[i][j] = (float *) count_malloc( sizeof( float ) * hBinRenConvModule->numTaps ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } + + if ( ( hBinRenConvModule->filterStatesLeftImag[i][j] = (float *) count_malloc( sizeof( float ) * hBinRenConvModule->numTaps ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } + } + } +#endif + for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { for ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) @@ -578,6 +596,21 @@ void ivas_binRenderer_close( if ( ( *hBinRenderer )->hBinRenConvModule != NULL ) { + +#ifdef SRAM_REDUCTION_BINRENDERER + for ( int16_t i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( int16_t j = 0; j < MAX_OUTPUT_CHANNELS; j++ ) + { + count_free( ( *hBinRenderer )->hBinRenConvModule->filterStatesLeftReal[i][j] ); + ( *hBinRenderer )->hBinRenConvModule->filterStatesLeftReal[i][j] = NULL; + + count_free( ( *hBinRenderer )->hBinRenConvModule->filterStatesLeftImag[i][j] ); + ( *hBinRenderer )->hBinRenConvModule->filterStatesLeftImag[i][j] = NULL; + } + } +#endif + count_free( ( *hBinRenderer )->hBinRenConvModule ); ( *hBinRenderer )->hBinRenConvModule = NULL; } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 16af0c47aa..5d12c2f78a 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1308,8 +1308,13 @@ typedef struct ivas_binaural_rendering_conv_module_struct const float *filterTapsRightReal[CLDFB_NO_CHANNELS_MAX][MAX_OUTPUT_CHANNELS]; const float *filterTapsRightImag[CLDFB_NO_CHANNELS_MAX][MAX_OUTPUT_CHANNELS]; +#ifdef SRAM_REDUCTION_BINRENDERER + float *filterStatesLeftReal[BINAURAL_CONVBANDS][MAX_OUTPUT_CHANNELS]; + float *filterStatesLeftImag[BINAURAL_CONVBANDS][MAX_OUTPUT_CHANNELS]; +#else float filterStatesLeftReal[BINAURAL_CONVBANDS][MAX_OUTPUT_CHANNELS][BINAURAL_NTAPS_MAX]; float filterStatesLeftImag[BINAURAL_CONVBANDS][MAX_OUTPUT_CHANNELS][BINAURAL_NTAPS_MAX]; +#endif int16_t numTapsArray[BINAURAL_CONVBANDS]; int16_t numTaps; -- GitLab From 6ece7a81726795064aab9b055b08af9b40e5bc96 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 5 Oct 2022 13:39:09 +0200 Subject: [PATCH 2/8] more memory allocated dynamically --- lib_dec/ivas_binauralRenderer.c | 170 ++++++++++++++++++++++++++++---- lib_dec/ivas_stat_dec.h | 11 ++- 2 files changed, 161 insertions(+), 20 deletions(-) diff --git a/lib_dec/ivas_binauralRenderer.c b/lib_dec/ivas_binauralRenderer.c index 4ded855668..7c33774dbc 100644 --- a/lib_dec/ivas_binauralRenderer.c +++ b/lib_dec/ivas_binauralRenderer.c @@ -187,16 +187,80 @@ static ivas_error ivas_binRenderer_convModuleOpen( } #ifdef SRAM_REDUCTION_BINRENDERER - for ( int16_t i = 0; i < BINAURAL_CONVBANDS; i++ ) + /* allocate memory for filter states */ + if ( ( hBinRenConvModule->filterTapsLeftReal = (float ***) count_malloc( hBinRenderer->conv_band * sizeof( float ) ) ) == NULL ) { - for ( int16_t j = 0; j < MAX_OUTPUT_CHANNELS; j++ ) + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } + + if ( ( hBinRenConvModule->filterTapsLeftImag = (float ***) count_malloc( hBinRenderer->conv_band * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } + + if ( ( hBinRenConvModule->filterTapsRightReal = (float ***) count_malloc( hBinRenderer->conv_band * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } + + if ( ( hBinRenConvModule->filterTapsRightImag = (float ***) count_malloc( hBinRenderer->conv_band * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } + + for ( int16_t i = 0; i < hBinRenderer->conv_band; i++ ) + { + if ( ( hBinRenConvModule->filterTapsLeftReal[i] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } + + if ( ( hBinRenConvModule->filterTapsLeftImag[i] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } + + if ( ( hBinRenConvModule->filterTapsRightReal[i] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) { - if ( ( hBinRenConvModule->filterStatesLeftReal[i][j] = (float *) count_malloc( sizeof( float ) * hBinRenConvModule->numTaps ) ) == NULL ) + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } + + if ( ( hBinRenConvModule->filterTapsRightImag[i] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } + } + + if ( ( hBinRenConvModule->filterStatesLeftReal = (float ***) count_malloc( hBinRenderer->conv_band * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } + + if ( ( hBinRenConvModule->filterStatesLeftImag = (float ***) count_malloc( hBinRenderer->conv_band * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } + + for ( int16_t i = 0; i < hBinRenderer->conv_band; i++ ) + { + if ( ( hBinRenConvModule->filterStatesLeftReal[i] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } + + if ( ( hBinRenConvModule->filterStatesLeftImag[i] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } + + for ( int16_t j = 0; j < hBinRenderer->nInChannels; j++ ) + { + if ( ( hBinRenConvModule->filterStatesLeftReal[i][j] = (float *) count_malloc( hBinRenConvModule->numTaps * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterStatesLeftImag[i][j] = (float *) count_malloc( sizeof( float ) * hBinRenConvModule->numTaps ) ) == NULL ) + if ( ( hBinRenConvModule->filterStatesLeftImag[i][j] = (float *) count_malloc( hBinRenConvModule->numTaps * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } @@ -204,6 +268,7 @@ static ivas_error ivas_binRenderer_convModuleOpen( } #endif + /* set memories */ for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { for ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) @@ -578,6 +643,86 @@ ivas_error ivas_binRenderer_open( return error; } +#ifdef SRAM_REDUCTION_BINRENDERER +/*------------------------------------------------------------------------- + * ivas_binRenderer_convModuleClose() + * + * Close convolution module handle of fastconv binaural renderer + *------------------------------------------------------------------------*/ + +static void ivas_binRenderer_convModuleClose( + BINAURAL_RENDERER_HANDLE *hBinRenderer /* i/o: fastconv binaural renderer handle */ +) +{ + int16_t i, j; + BINRENDERER_CONV_MODULE_HANDLE hBinRenConvModule; + + hBinRenConvModule = ( *hBinRenderer )->hBinRenConvModule; + + if ( hBinRenConvModule == NULL ) + { + return; + } + + for ( i = 0; i < ( *hBinRenderer )->conv_band; i++ ) + { + count_free( (float **) hBinRenConvModule->filterTapsLeftReal[i] ); + hBinRenConvModule->filterTapsLeftReal[i] = NULL; + + count_free( (float **) hBinRenConvModule->filterTapsLeftImag[i] ); + hBinRenConvModule->filterTapsLeftImag[i] = NULL; + + count_free( (float **) hBinRenConvModule->filterTapsRightReal[i] ); + hBinRenConvModule->filterTapsRightReal[i] = NULL; + + count_free( (float **) hBinRenConvModule->filterTapsRightImag[i] ); + hBinRenConvModule->filterTapsRightImag[i] = NULL; + } + + count_free( (float *) hBinRenConvModule->filterTapsLeftReal ); + hBinRenConvModule->filterTapsLeftReal = NULL; + + count_free( (float *) hBinRenConvModule->filterTapsLeftImag ); + hBinRenConvModule->filterTapsLeftImag = NULL; + + count_free( (float *) hBinRenConvModule->filterTapsRightReal ); + hBinRenConvModule->filterTapsRightReal = NULL; + + count_free( (float *) hBinRenConvModule->filterTapsRightImag ); + hBinRenConvModule->filterTapsRightImag = NULL; + + + for ( i = 0; i < ( *hBinRenderer )->conv_band; i++ ) + { + for ( j = 0; j < ( *hBinRenderer )->nInChannels; j++ ) + { + count_free( hBinRenConvModule->filterStatesLeftReal[i][j] ); + hBinRenConvModule->filterStatesLeftReal[i][j] = NULL; + + count_free( hBinRenConvModule->filterStatesLeftImag[i][j] ); + hBinRenConvModule->filterStatesLeftImag[i][j] = NULL; + } + + count_free( hBinRenConvModule->filterStatesLeftReal[i] ); + hBinRenConvModule->filterStatesLeftReal[i] = NULL; + + count_free( hBinRenConvModule->filterStatesLeftImag[i] ); + hBinRenConvModule->filterStatesLeftImag[i] = NULL; + } + + count_free( hBinRenConvModule->filterStatesLeftReal ); + hBinRenConvModule->filterStatesLeftReal = NULL; + + count_free( hBinRenConvModule->filterStatesLeftImag ); + hBinRenConvModule->filterStatesLeftImag = NULL; + + + count_free( ( *hBinRenderer )->hBinRenConvModule ); + ( *hBinRenderer )->hBinRenConvModule = NULL; + + return; +} +#endif /*------------------------------------------------------------------------- * ivas_binRenderer_close() @@ -596,23 +741,12 @@ void ivas_binRenderer_close( if ( ( *hBinRenderer )->hBinRenConvModule != NULL ) { - #ifdef SRAM_REDUCTION_BINRENDERER - for ( int16_t i = 0; i < BINAURAL_CONVBANDS; i++ ) - { - for ( int16_t j = 0; j < MAX_OUTPUT_CHANNELS; j++ ) - { - count_free( ( *hBinRenderer )->hBinRenConvModule->filterStatesLeftReal[i][j] ); - ( *hBinRenderer )->hBinRenConvModule->filterStatesLeftReal[i][j] = NULL; - - count_free( ( *hBinRenderer )->hBinRenConvModule->filterStatesLeftImag[i][j] ); - ( *hBinRenderer )->hBinRenConvModule->filterStatesLeftImag[i][j] = NULL; - } - } -#endif - + ivas_binRenderer_convModuleClose( hBinRenderer ); +#else count_free( ( *hBinRenderer )->hBinRenConvModule ); ( *hBinRenderer )->hBinRenConvModule = NULL; +#endif } if ( ( *hBinRenderer )->hReverb != NULL ) diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 5d12c2f78a..75098de82e 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1303,14 +1303,21 @@ typedef struct ivas_dirac_dec_binaural_data_structure typedef struct ivas_binaural_rendering_conv_module_struct { +#ifdef SRAM_REDUCTION_BINRENDERER + const float ***filterTapsLeftReal; + const float ***filterTapsLeftImag; + const float ***filterTapsRightReal; + const float ***filterTapsRightImag; +#else const float *filterTapsLeftReal[CLDFB_NO_CHANNELS_MAX][MAX_OUTPUT_CHANNELS]; const float *filterTapsLeftImag[CLDFB_NO_CHANNELS_MAX][MAX_OUTPUT_CHANNELS]; const float *filterTapsRightReal[CLDFB_NO_CHANNELS_MAX][MAX_OUTPUT_CHANNELS]; const float *filterTapsRightImag[CLDFB_NO_CHANNELS_MAX][MAX_OUTPUT_CHANNELS]; +#endif #ifdef SRAM_REDUCTION_BINRENDERER - float *filterStatesLeftReal[BINAURAL_CONVBANDS][MAX_OUTPUT_CHANNELS]; - float *filterStatesLeftImag[BINAURAL_CONVBANDS][MAX_OUTPUT_CHANNELS]; + float ***filterStatesLeftReal; + float ***filterStatesLeftImag; #else float filterStatesLeftReal[BINAURAL_CONVBANDS][MAX_OUTPUT_CHANNELS][BINAURAL_NTAPS_MAX]; float filterStatesLeftImag[BINAURAL_CONVBANDS][MAX_OUTPUT_CHANNELS][BINAURAL_NTAPS_MAX]; -- GitLab From 1382ee5d3568d141639a02898ad262cbe0706671 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 5 Oct 2022 13:44:37 +0200 Subject: [PATCH 3/8] disable MEM_COUNT_DETAILS --- lib_com/options.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 00a32f3c78..37831857bf 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -58,7 +58,7 @@ #ifdef DEBUGGING -#define MEM_COUNT_DETAILS /* RAM counting tool: print per sub-structure details */ +/*#define MEM_COUNT_DETAILS*/ /* RAM counting tool: print per sub-structure details */ /*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO @@ -155,9 +155,9 @@ #define HARMONIZE_SBA_NCHAN_TRANSPORT /* harmonize setting of number of transport channels in SBA */ #define DRAM_REDUCTION_MCT_IGF /* Issue 121: reduce dynamic RAM consumption in MCT IGF */ #define FIX_I13_TCX_TNS_ISSUE /* Issue 13: Fix reported artifacts. Bug in TNS with TCX5 */ +#define SRAM_REDUCTION_BINRENDERER /* Issue 145: reduction of static RAM usage in fastconv binaural renderer */ -#define SRAM_REDUCTION_BINRENDERER /* reduction of static RAM usage in fastconv binaural renderer */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ -- GitLab From 974385347feed557eceb1f23d3661c88dc586879 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 5 Oct 2022 14:32:18 +0200 Subject: [PATCH 4/8] fix Linux build errors --- lib_dec/ivas_binauralRenderer.c | 26 +++++++++++++------------- lib_dec/ivas_rom_binauralRenderer.h | 23 +++++++++++++++++++++++ lib_dec/ivas_stat_dec.h | 8 ++++---- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/lib_dec/ivas_binauralRenderer.c b/lib_dec/ivas_binauralRenderer.c index 7c33774dbc..6c4e0ba6f8 100644 --- a/lib_dec/ivas_binauralRenderer.c +++ b/lib_dec/ivas_binauralRenderer.c @@ -666,29 +666,29 @@ static void ivas_binRenderer_convModuleClose( for ( i = 0; i < ( *hBinRenderer )->conv_band; i++ ) { - count_free( (float **) hBinRenConvModule->filterTapsLeftReal[i] ); + count_free( hBinRenConvModule->filterTapsLeftReal[i] ); hBinRenConvModule->filterTapsLeftReal[i] = NULL; - count_free( (float **) hBinRenConvModule->filterTapsLeftImag[i] ); + count_free( hBinRenConvModule->filterTapsLeftImag[i] ); hBinRenConvModule->filterTapsLeftImag[i] = NULL; - count_free( (float **) hBinRenConvModule->filterTapsRightReal[i] ); + count_free( hBinRenConvModule->filterTapsRightReal[i] ); hBinRenConvModule->filterTapsRightReal[i] = NULL; - count_free( (float **) hBinRenConvModule->filterTapsRightImag[i] ); + count_free( hBinRenConvModule->filterTapsRightImag[i] ); hBinRenConvModule->filterTapsRightImag[i] = NULL; } - count_free( (float *) hBinRenConvModule->filterTapsLeftReal ); + count_free( hBinRenConvModule->filterTapsLeftReal ); hBinRenConvModule->filterTapsLeftReal = NULL; - count_free( (float *) hBinRenConvModule->filterTapsLeftImag ); + count_free( hBinRenConvModule->filterTapsLeftImag ); hBinRenConvModule->filterTapsLeftImag = NULL; - count_free( (float *) hBinRenConvModule->filterTapsRightReal ); + count_free( hBinRenConvModule->filterTapsRightReal ); hBinRenConvModule->filterTapsRightReal = NULL; - count_free( (float *) hBinRenConvModule->filterTapsRightImag ); + count_free( hBinRenConvModule->filterTapsRightImag ); hBinRenConvModule->filterTapsRightImag = NULL; @@ -942,10 +942,10 @@ void ivas_binRenderer( /* Obtain the binaural dmx and compute the reverb */ if ( hBinRenderer->hReverb != NULL ) { - float reverbRe[2][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - float reverbIm[2][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - float inRe[2][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - float inIm[2][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + float reverbRe[BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + float reverbIm[BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + float inRe[BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + float inIm[BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; ivas_binaural_obtain_DMX( numTimeSlots, hBinRenderer, RealBuffer, ImagBuffer, inRe, inIm ); @@ -958,7 +958,7 @@ void ivas_binRenderer( } } - ivas_binaural_reverb_processFrame( hBinRenderer->hReverb, 2, inRe, inIm, reverbRe, reverbIm, 0u ); + ivas_binaural_reverb_processFrame( hBinRenderer->hReverb, BINAURAL_CHANNELS, inRe, inIm, reverbRe, reverbIm, 0u ); /* Add the conv module and reverb module output */ for ( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) diff --git a/lib_dec/ivas_rom_binauralRenderer.h b/lib_dec/ivas_rom_binauralRenderer.h index 3bed3c5ec9..ca3a527c4c 100644 --- a/lib_dec/ivas_rom_binauralRenderer.h +++ b/lib_dec/ivas_rom_binauralRenderer.h @@ -44,6 +44,21 @@ /* Binaural rendering data set based on HRIRs */ extern const float FASTCONV_HRIR_latency_s; +#ifdef SRAM_REDUCTION_BINRENDERER +extern float leftHRIRReal_HOA3[BINAURAL_CONVBANDS][16][7]; +extern float leftHRIRImag_HOA3[BINAURAL_CONVBANDS][16][7]; +extern float rightHRIRReal_HOA3[BINAURAL_CONVBANDS][16][7]; +extern float rightHRIRImag_HOA3[BINAURAL_CONVBANDS][16][7]; + +extern float leftHRIRReal[BINAURAL_CONVBANDS][15][7]; +extern float leftHRIRImag[BINAURAL_CONVBANDS][15][7]; +extern float rightHRIRReal[BINAURAL_CONVBANDS][15][7]; +extern float rightHRIRImag[BINAURAL_CONVBANDS][15][7]; + +extern float FASTCONV_HOA3_latency_s; +extern float hrtfShCoeffsRe[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]; +extern float hrtfShCoeffsIm[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]; +#else extern const float leftHRIRReal_HOA3[BINAURAL_CONVBANDS][16][7]; extern const float leftHRIRImag_HOA3[BINAURAL_CONVBANDS][16][7]; extern const float rightHRIRReal_HOA3[BINAURAL_CONVBANDS][16][7]; @@ -57,13 +72,21 @@ extern const float rightHRIRImag[BINAURAL_CONVBANDS][15][7]; extern const float FASTCONV_HOA3_latency_s; extern const float hrtfShCoeffsRe[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]; extern const float hrtfShCoeffsIm[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]; +#endif /* Binaural rendering data set based on BRIRs */ extern const float FASTCONV_BRIR_latency_s; +#ifdef SRAM_REDUCTION_BINRENDERER +extern float leftBRIRReal[BINAURAL_CONVBANDS][15][BINAURAL_NTAPS_MAX]; +extern float leftBRIRImag[BINAURAL_CONVBANDS][15][BINAURAL_NTAPS_MAX]; +extern float rightBRIRReal[BINAURAL_CONVBANDS][15][BINAURAL_NTAPS_MAX]; +extern float rightBRIRImag[BINAURAL_CONVBANDS][15][BINAURAL_NTAPS_MAX]; +#else extern const float leftBRIRReal[BINAURAL_CONVBANDS][15][BINAURAL_NTAPS_MAX]; extern const float leftBRIRImag[BINAURAL_CONVBANDS][15][BINAURAL_NTAPS_MAX]; extern const float rightBRIRReal[BINAURAL_CONVBANDS][15][BINAURAL_NTAPS_MAX]; extern const float rightBRIRImag[BINAURAL_CONVBANDS][15][BINAURAL_NTAPS_MAX]; +#endif /* Reverberation parameters based on BRIRs for fastconv */ extern float fastconvReverberationTimes[CLDFB_NO_CHANNELS_MAX]; diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 75098de82e..dd17424248 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1304,10 +1304,10 @@ typedef struct ivas_dirac_dec_binaural_data_structure typedef struct ivas_binaural_rendering_conv_module_struct { #ifdef SRAM_REDUCTION_BINRENDERER - const float ***filterTapsLeftReal; - const float ***filterTapsLeftImag; - const float ***filterTapsRightReal; - const float ***filterTapsRightImag; + float ***filterTapsLeftReal; + float ***filterTapsLeftImag; + float ***filterTapsRightReal; + float ***filterTapsRightImag; #else const float *filterTapsLeftReal[CLDFB_NO_CHANNELS_MAX][MAX_OUTPUT_CHANNELS]; const float *filterTapsLeftImag[CLDFB_NO_CHANNELS_MAX][MAX_OUTPUT_CHANNELS]; -- GitLab From 2980ce8ad6b6d4bd765e9340712c2ca49f56fe42 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 6 Oct 2022 08:49:18 +0200 Subject: [PATCH 5/8] more savings for BINAURAL_ROOM output --- lib_dec/ivas_binauralRenderer.c | 67 ++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/lib_dec/ivas_binauralRenderer.c b/lib_dec/ivas_binauralRenderer.c index 6c4e0ba6f8..e094152dda 100644 --- a/lib_dec/ivas_binauralRenderer.c +++ b/lib_dec/ivas_binauralRenderer.c @@ -208,24 +208,24 @@ static ivas_error ivas_binRenderer_convModuleOpen( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - for ( int16_t i = 0; i < hBinRenderer->conv_band; i++ ) + for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - if ( ( hBinRenConvModule->filterTapsLeftReal[i] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsLeftReal[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsLeftImag[i] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsLeftImag[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsRightReal[i] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsRightReal[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsRightImag[i] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsRightImag[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } @@ -241,26 +241,26 @@ static ivas_error ivas_binRenderer_convModuleOpen( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - for ( int16_t i = 0; i < hBinRenderer->conv_band; i++ ) + for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - if ( ( hBinRenConvModule->filterStatesLeftReal[i] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterStatesLeftReal[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterStatesLeftImag[i] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterStatesLeftImag[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - for ( int16_t j = 0; j < hBinRenderer->nInChannels; j++ ) + for ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) { - if ( ( hBinRenConvModule->filterStatesLeftReal[i][j] = (float *) count_malloc( hBinRenConvModule->numTaps * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx] = (float *) count_malloc( hBinRenConvModule->numTapsArray[bandIdx] * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterStatesLeftImag[i][j] = (float *) count_malloc( hBinRenConvModule->numTaps * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx] = (float *) count_malloc( hBinRenConvModule->numTapsArray[bandIdx] * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } @@ -308,8 +308,13 @@ static ivas_error ivas_binRenderer_convModuleOpen( if ( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM && hRenderConfig->roomAcoustics.use_brir ) { /* set the memories to zero */ +#ifdef SRAM_REDUCTION_BINRENDERER + set_zero( hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx], hBinRenConvModule->numTapsArray[bandIdx] ); + set_zero( hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx], hBinRenConvModule->numTapsArray[bandIdx] ); +#else set_zero( hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx], hBinRenConvModule->numTaps ); set_zero( hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx], hBinRenConvModule->numTaps ); +#endif if ( isLoudspeaker ) { @@ -654,7 +659,7 @@ static void ivas_binRenderer_convModuleClose( BINAURAL_RENDERER_HANDLE *hBinRenderer /* i/o: fastconv binaural renderer handle */ ) { - int16_t i, j; + int16_t bandIdx, chIdx; BINRENDERER_CONV_MODULE_HANDLE hBinRenConvModule; hBinRenConvModule = ( *hBinRenderer )->hBinRenConvModule; @@ -664,19 +669,19 @@ static void ivas_binRenderer_convModuleClose( return; } - for ( i = 0; i < ( *hBinRenderer )->conv_band; i++ ) + for ( bandIdx = 0; bandIdx < ( *hBinRenderer )->conv_band; bandIdx++ ) { - count_free( hBinRenConvModule->filterTapsLeftReal[i] ); - hBinRenConvModule->filterTapsLeftReal[i] = NULL; + count_free( hBinRenConvModule->filterTapsLeftReal[bandIdx] ); + hBinRenConvModule->filterTapsLeftReal[bandIdx] = NULL; - count_free( hBinRenConvModule->filterTapsLeftImag[i] ); - hBinRenConvModule->filterTapsLeftImag[i] = NULL; + count_free( hBinRenConvModule->filterTapsLeftImag[bandIdx] ); + hBinRenConvModule->filterTapsLeftImag[bandIdx] = NULL; - count_free( hBinRenConvModule->filterTapsRightReal[i] ); - hBinRenConvModule->filterTapsRightReal[i] = NULL; + count_free( hBinRenConvModule->filterTapsRightReal[bandIdx] ); + hBinRenConvModule->filterTapsRightReal[bandIdx] = NULL; - count_free( hBinRenConvModule->filterTapsRightImag[i] ); - hBinRenConvModule->filterTapsRightImag[i] = NULL; + count_free( hBinRenConvModule->filterTapsRightImag[bandIdx] ); + hBinRenConvModule->filterTapsRightImag[bandIdx] = NULL; } count_free( hBinRenConvModule->filterTapsLeftReal ); @@ -692,22 +697,22 @@ static void ivas_binRenderer_convModuleClose( hBinRenConvModule->filterTapsRightImag = NULL; - for ( i = 0; i < ( *hBinRenderer )->conv_band; i++ ) + for ( bandIdx = 0; bandIdx < ( *hBinRenderer )->conv_band; bandIdx++ ) { - for ( j = 0; j < ( *hBinRenderer )->nInChannels; j++ ) + for ( chIdx = 0; chIdx < ( *hBinRenderer )->nInChannels; chIdx++ ) { - count_free( hBinRenConvModule->filterStatesLeftReal[i][j] ); - hBinRenConvModule->filterStatesLeftReal[i][j] = NULL; + count_free( hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx] ); + hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx] = NULL; - count_free( hBinRenConvModule->filterStatesLeftImag[i][j] ); - hBinRenConvModule->filterStatesLeftImag[i][j] = NULL; + count_free( hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx] ); + hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx] = NULL; } - count_free( hBinRenConvModule->filterStatesLeftReal[i] ); - hBinRenConvModule->filterStatesLeftReal[i] = NULL; + count_free( hBinRenConvModule->filterStatesLeftReal[bandIdx] ); + hBinRenConvModule->filterStatesLeftReal[bandIdx] = NULL; - count_free( hBinRenConvModule->filterStatesLeftImag[i] ); - hBinRenConvModule->filterStatesLeftImag[i] = NULL; + count_free( hBinRenConvModule->filterStatesLeftImag[bandIdx] ); + hBinRenConvModule->filterStatesLeftImag[bandIdx] = NULL; } count_free( hBinRenConvModule->filterStatesLeftReal ); -- GitLab From 71e19748daa5d380a52d90b2e63d195a97b347f9 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 6 Oct 2022 10:32:38 +0200 Subject: [PATCH 6/8] reduction of static RAM usage in fastconv binaural *room* renderer; under SRAM_REDUCTION_BINRENDERER_ROOM --- lib_com/ivas_prot.h | 15 +- lib_com/options.h | 2 +- lib_dec/ivas_binauralRenderer.c | 14 ++ lib_dec/ivas_binaural_reverb.c | 146 +++++++++++++++++++- lib_dec/ivas_dirac_dec_binaural_functions.c | 18 +++ 5 files changed, 190 insertions(+), 5 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 60f44e22a3..3fe50e09b1 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3240,12 +3240,23 @@ void ivas_dirac_dec_binaural( const int16_t nchan_transport /* i : number of transport channels */ ); +#ifdef SRAM_REDUCTION_BINRENDERER_ROOM ivas_error ivas_binaural_reverb_open( REVERB_STRUCT_HANDLE *hReverbPr, /* i/o: binaural reverb handle */ const int16_t numBins, /* i : number of CLDFB bins */ - const int16_t numCldfbSlotsPerFrame /* i : number of CLDFB slots per frame, i.e., reverberator block size */ + const int16_t numCldfbSlotsPerFrame, /* i : number of CLDFB slots per frame */ + ivas_roomAcoustics_t *roomAcoustics, /* i/o: room acoustics parameters */ + const AUDIO_CONFIG output_config, /* i : output audio configuration */ + const int32_t sampling_rate, /* i : sampling rate */ + const RENDERER_TYPE renderer_type /* i : renderer type */ ); - +#else +ivas_error ivas_binaural_reverb_open( + REVERB_STRUCT_HANDLE *hReverbPr, /* i/o: binaural reverb handle */ + const int16_t numBins, /* i : number of CLDFB bins */ + const int16_t numCldfbSlotsPerFrame /* i : number of CLDFB slots per frame */ +); +#endif void ivas_binaural_reverb_close( REVERB_STRUCT_HANDLE *hReverb /* i/o: binaural reverb handle */ ); diff --git a/lib_com/options.h b/lib_com/options.h index 37831857bf..1b85a69e77 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -156,7 +156,7 @@ #define DRAM_REDUCTION_MCT_IGF /* Issue 121: reduce dynamic RAM consumption in MCT IGF */ #define FIX_I13_TCX_TNS_ISSUE /* Issue 13: Fix reported artifacts. Bug in TNS with TCX5 */ #define SRAM_REDUCTION_BINRENDERER /* Issue 145: reduction of static RAM usage in fastconv binaural renderer */ - +#define SRAM_REDUCTION_BINRENDERER_ROOM /* Issue 145: reduction of static RAM usage in fastconv binaural room renderer */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_binauralRenderer.c b/lib_dec/ivas_binauralRenderer.c index e094152dda..95c96f3bb8 100644 --- a/lib_dec/ivas_binauralRenderer.c +++ b/lib_dec/ivas_binauralRenderer.c @@ -378,6 +378,9 @@ static void ivas_binaural_obtain_DMX( { int16_t chIdx, bandIdx, k; +#ifdef SRAM_REDUCTION_BINRENDERER_ROOM + // ToDo: hBinRenderer->ivas_format is never set to ISM_FORMAT -> TBV +#endif if ( hBinRenderer->ivas_format == MC_FORMAT || hBinRenderer->ivas_format == ISM_FORMAT ) { /* Obtain the downmix */ @@ -493,8 +496,10 @@ ivas_error ivas_binRenderer_open( { BINAURAL_RENDERER_HANDLE hBinRenderer; int16_t convBand, chIdx, k; +#ifndef SRAM_REDUCTION_BINRENDERER_ROOM float t60[CLDFB_NO_CHANNELS_MAX]; float ene[CLDFB_NO_CHANNELS_MAX]; +#endif ivas_error error; error = IVAS_ERR_OK; @@ -588,10 +593,17 @@ ivas_error ivas_binRenderer_open( /* Allocate memories needed for reverb module */ if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM && st_ivas->hRenderConfig->roomAcoustics.late_reverb_on ) { +#ifdef SRAM_REDUCTION_BINRENDERER_ROOM + if ( ( error = ivas_binaural_reverb_open( &( hBinRenderer->hReverb ), hBinRenderer->conv_band, hBinRenderer->timeSlots, &( st_ivas->hRenderConfig->roomAcoustics ), st_ivas->hIntSetup.output_config, st_ivas->hDecoderConfig->output_Fs, RENDERER_BINAURAL_FASTCONV_ROOM ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_binaural_reverb_open( &( hBinRenderer->hReverb ), hBinRenderer->conv_band, hBinRenderer->timeSlots ) ) != IVAS_ERR_OK ) { return error; } + if ( !st_ivas->hRenderConfig->roomAcoustics.override ) { ivas_binaural_reverb_setReverbTimes( hBinRenderer->hReverb, st_ivas->hDecoderConfig->output_Fs, fastconvReverberationTimes, fastconvReverberationEneCorrections ); @@ -605,6 +617,8 @@ ivas_error ivas_binRenderer_open( } hBinRenderer->hReverb->useBinauralCoherence = 1; +#endif + /* initialize the dmx matrix */ for ( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) { diff --git a/lib_dec/ivas_binaural_reverb.c b/lib_dec/ivas_binaural_reverb.c index 054b8c1558..bfb07c4c53 100644 --- a/lib_dec/ivas_binaural_reverb.c +++ b/lib_dec/ivas_binaural_reverb.c @@ -36,6 +36,9 @@ #include "ivas_prot.h" #include "prot.h" #include "ivas_rom_com.h" +#ifdef SRAM_REDUCTION_BINRENDERER_ROOM +#include "ivas_rom_binauralRenderer.h" +#endif #ifdef DEBUGGING #include "debug.h" #endif @@ -312,12 +315,13 @@ void ivas_binaural_reverb_setReverbTimes( } hReverb->binauralCoherenceDirectGains[bin] = sqrtf( 1.0f - fabsf( tmpVal ) ); +#ifndef SRAM_REDUCTION_BINRENDERER_ROOM /* Determine loop buffer length. The following formula is manually tuned to generate sufficiently long * but not excessively long loops to generate reverberation. */ /* Note: the resulted length is very sensitive to the precision of the constants below (e.g. 1.45 vs. 1.45f) */ hReverb->loopBufLength[bin] = (int16_t) ( 1.45 * (int16_t) ( revTimes[bin] * 150.0 ) + 1 ); hReverb->loopBufLength[bin] = min( hReverb->loopBufLength[bin], hReverb->loopBufLengthMax[bin] ); - +#endif /* Determine attenuation factor that generates the appropriate energy decay according to reverberation time */ attenuationFactorPerSample = powf( 10.0f, -3.0f * ( 1.0f / ( (float) CLDFB_SLOTS_PER_SECOND * revTimes[bin] ) ) ); hReverb->loopAttenuationFactor[bin] = powf( attenuationFactorPerSample, hReverb->loopBufLength[bin] ); @@ -371,6 +375,144 @@ void ivas_binaural_reverb_setReverbTimes( * Allocate and initialize binaural room reverberator handle *------------------------------------------------------------------------*/ +#ifdef SRAM_REDUCTION_BINRENDERER_ROOM +ivas_error ivas_binaural_reverb_open( + REVERB_STRUCT_HANDLE *hReverbPr, /* i/o: binaural reverb handle */ + const int16_t numBins, /* i : number of CLDFB bins */ + const int16_t numCldfbSlotsPerFrame, /* i : number of CLDFB slots per frame */ + ivas_roomAcoustics_t *roomAcoustics, /* i/o: room acoustics parameters */ + const AUDIO_CONFIG output_config, /* i : output audio configuration */ + const int32_t sampling_rate, /* i : sampling rate */ + const RENDERER_TYPE renderer_type /* i : renderer type */ +) +{ + int16_t bin, chIdx, k, len; + REVERB_STRUCT_HANDLE hReverb; + const float *revTimes; + float t60[CLDFB_NO_CHANNELS_MAX]; + float ene[CLDFB_NO_CHANNELS_MAX]; + + if ( ( *hReverbPr = (REVERB_STRUCT_HANDLE) count_malloc( sizeof( REVERB_STRUCT ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); + } + + hReverb = *hReverbPr; + + hReverb->useBinauralCoherence = 1; + hReverb->preDelayBufferLength = 1; + hReverb->preDelayBufferIndex = 0; + + hReverb->numBins = numBins; + hReverb->blockSize = numCldfbSlotsPerFrame; + + for ( k = 0; k < REVERB_PREDELAY_MAX + 1; k++ ) + { + set_f( hReverb->preDelayBufferReal[k], 0.0f, hReverb->numBins ); + set_f( hReverb->preDelayBufferImag[k], 0.0f, hReverb->numBins ); + } + + if ( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + { + if ( !roomAcoustics->override ) + { + revTimes = fastconvReverberationTimes; + } + else + { + revTimes = (float *) sampling_rate; + } + } + else + { + revTimes = parametricReverberationTimes; + } + + for ( bin = 0; bin < hReverb->numBins; bin++ ) + { + /* Loop Buffer */ + hReverb->loopBufLengthMax[bin] = (int16_t) ( 500 / ( 1 + bin ) + ( CLDFB_NO_CHANNELS_MAX - bin ) ); + + len = hReverb->loopBufLengthMax[bin] + hReverb->blockSize; + if ( ( hReverb->loopBufReal[bin] = (float *) count_malloc( len * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); + } + + if ( ( hReverb->loopBufImag[bin] = (float *) count_malloc( len * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); + } + + set_f( hReverb->loopBufReal[bin], 0.0f, len ); + set_f( hReverb->loopBufImag[bin], 0.0f, len ); + + /* Determine loop buffer length. The following formula is manually tuned to generate sufficiently long + * but not excessively long loops to generate reverberation. */ + /* Note: the resulted length is very sensitive to the precision of the constants below (e.g. 1.45 vs. 1.45f) */ + hReverb->loopBufLength[bin] = (int16_t) ( 1.45 * (int16_t) ( revTimes[bin] * 150.0 ) + 1 ); + hReverb->loopBufLength[bin] = min( hReverb->loopBufLength[bin], hReverb->loopBufLengthMax[bin] ); + + /* Sparse Filter Tap Locations */ + for ( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) + { + len = hReverb->loopBufLength[bin]; + + if ( ( hReverb->tapPhaseShiftType[bin][chIdx] = (int16_t *) count_malloc( len * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); + } + set_s( hReverb->tapPhaseShiftType[bin][chIdx], 0, len ); + + if ( ( hReverb->tapPointersReal[bin][chIdx] = (float **) count_malloc( len * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); + } + + if ( ( hReverb->tapPointersImag[bin][chIdx] = (float **) count_malloc( len * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); + } + + len = hReverb->blockSize; + if ( ( hReverb->outputBufferReal[bin][chIdx] = (float *) count_malloc( len * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); + } + + if ( ( hReverb->outputBufferImag[bin][chIdx] = (float *) count_malloc( len * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); + } + + set_f( hReverb->outputBufferReal[bin][chIdx], 0.0f, len ); + set_f( hReverb->outputBufferImag[bin][chIdx], 0.0f, len ); + } + } + + if ( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + { + if ( !roomAcoustics->override ) + { + ivas_binaural_reverb_setReverbTimes( hReverb, sampling_rate, fastconvReverberationTimes, fastconvReverberationEneCorrections ); + ivas_binaural_reverb_setPreDelay( hReverb, 10 ); + } + else + { + ivas_reverb_prepare_cldfb_params( roomAcoustics, output_config, roomAcoustics->use_brir, sampling_rate, t60, ene ); + ivas_binaural_reverb_setReverbTimes( hReverb, sampling_rate, t60, ene ); + ivas_binaural_reverb_setPreDelay( hReverb, (int16_t) roundf( 48000.0f * roomAcoustics->acousticPreDelay / CLDFB_NO_CHANNELS_MAX ) ); + } + } + else + { + ivas_binaural_reverb_setReverbTimes( hReverb, sampling_rate, parametricReverberationTimes, parametricReverberationEneCorrections ); + ivas_binaural_reverb_setPreDelay( hReverb, 10 ); + } + + return IVAS_ERR_OK; +} +#else ivas_error ivas_binaural_reverb_open( REVERB_STRUCT_HANDLE *hReverbPr, /* i/o: binaural reverb handle */ const int16_t numBins, /* i : number of CLDFB bins */ @@ -459,7 +601,7 @@ ivas_error ivas_binaural_reverb_open( return IVAS_ERR_OK; } - +#endif /*------------------------------------------------------------------------- * ivas_binaural_reverb_close() diff --git a/lib_dec/ivas_dirac_dec_binaural_functions.c b/lib_dec/ivas_dirac_dec_binaural_functions.c index 5e698ab289..9eb73edd5e 100644 --- a/lib_dec/ivas_dirac_dec_binaural_functions.c +++ b/lib_dec/ivas_dirac_dec_binaural_functions.c @@ -188,6 +188,22 @@ ivas_error ivas_dirac_dec_init_binaural_data( else if ( renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) /* Indication of binaural rendering with room effect */ { mvr2r( parametricEarlyPartEneCorrection, hBinaural->earlyPartEneCorrection, nBins ); +#ifdef SRAM_REDUCTION_BINRENDERER_ROOM + if ( hBinaural->useSubframeMode ) + { + if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#else if ( hBinaural->useSubframeMode ) { if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES ) ) != IVAS_ERR_OK ) @@ -202,9 +218,11 @@ ivas_error ivas_dirac_dec_init_binaural_data( return error; } } + ivas_binaural_reverb_setReverbTimes( hBinaural->hReverb, output_Fs, parametricReverberationTimes, parametricReverberationEneCorrections ); hBinaural->hReverb->useBinauralCoherence = 1; ivas_binaural_reverb_setPreDelay( hBinaural->hReverb, 10 ); +#endif } else if ( renderer_type == RENDERER_STEREO_PARAMETRIC ) { -- GitLab From d679826c48f5651fef8d12353a59e1a3b2c4c729 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 6 Oct 2022 10:49:21 +0200 Subject: [PATCH 7/8] fix Linux build --- lib_dec/ivas_binaural_reverb.c | 2 +- lib_dec/ivas_rom_binauralRenderer.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib_dec/ivas_binaural_reverb.c b/lib_dec/ivas_binaural_reverb.c index bfb07c4c53..db552e538a 100644 --- a/lib_dec/ivas_binaural_reverb.c +++ b/lib_dec/ivas_binaural_reverb.c @@ -420,7 +420,7 @@ ivas_error ivas_binaural_reverb_open( } else { - revTimes = (float *) sampling_rate; + revTimes = t60; } } else diff --git a/lib_dec/ivas_rom_binauralRenderer.c b/lib_dec/ivas_rom_binauralRenderer.c index 28c8856012..bfd2da9fb4 100644 --- a/lib_dec/ivas_rom_binauralRenderer.c +++ b/lib_dec/ivas_rom_binauralRenderer.c @@ -44033,19 +44033,20 @@ const float rightBRIRImag[BINAURAL_CONVBANDS][15][BINAURAL_NTAPS_MAX]= } }; -const float fastconvReverberationTimes[60] = +const float fastconvReverberationTimes[CLDFB_NO_CHANNELS_MAX] = { 0.429201f, 0.205110f, 0.202338f, 0.208383f, 0.215664f, 0.236545f, 0.230598f, 0.228400f, 0.227467f, 0.218956f, 0.226083f, 0.220702f, 0.221501f, 0.223471f, 0.223705f, 0.227063f, 0.227899f, 0.223071f, 0.220000f, 0.218583f, 0.220417f, 0.218250f, 0.213250f, 0.210333f, 0.207417f, 0.198750f, 0.196250f, 0.194917f, 0.190333f, 0.184500f, 0.180333f, 0.176167f, 0.176500f, 0.177583f, 0.183583f, 0.195917f, 0.203250f, 0.208417f, 0.214667f, 0.220000f, 0.222917f, 0.230417f, 0.233928f, 0.233647f, 0.236333f, 0.237428f, 0.241629f, 0.241118f, 0.238847f, 0.242384f, 0.246292f, 0.245948f, 0.246100f, 0.245396f, 0.243951f, 0.244123f, 0.239270f, 0.241474f, 0.234824f, 0.253040f, }; -const float fastconvReverberationEneCorrections[60] = +const float fastconvReverberationEneCorrections[CLDFB_NO_CHANNELS_MAX] = { 0.000584f, 0.000210f, 0.000233f, 0.000212f, 0.000257f, 0.001518f, 0.001154f, 0.001097f, 0.001265f, 0.001298f, 0.002320f, 0.002432f, 0.002686f, 0.002702f, 0.002632f, 0.002564f, 0.002732f, 0.002727f, 0.002609f, 0.002524f, 0.003417f, 0.001783f, 0.000987f, 0.000699f, 0.000606f, 0.000536f, 0.000511f, 0.000569f, 0.000600f, 0.000543f, 0.001257f, 0.001209f, 0.000957f, 0.000601f, 0.000274f, 0.000106f, 0.000072f, 0.000051f, 0.000040f, 0.000030f, 0.000024f, 0.000018f, 0.000014f, 0.000013f, 0.000012f, 0.000011f, 0.000009f, 0.000009f, 0.000008f, 0.000008f, 0.000007f, 0.000006f, 0.000005f, 0.000003f, 0.000002f, 0.000002f, 0.000001f, 0.000001f, 0.000000f, 0.000000f, }; -const float parametricReverberationTimes[CLDFB_NO_CHANNELS_MAX] = { +const float parametricReverberationTimes[CLDFB_NO_CHANNELS_MAX] = +{ 0.345494f, 0.319454f, 0.332961f, 0.360923f, 0.374299f, 0.370777f, 0.358625f, 0.348103f, 0.343109f, 0.331351f, 0.316502f, 0.304975f, 0.294855f, 0.287549f, 0.279920f, 0.270277f, 0.264042f, 0.256404f, 0.249899f, 0.242040f, 0.235074f, 0.229647f, 0.223730f, 0.218795f, 0.212599f, 0.207689f, 0.202082f, 0.198094f, 0.193907f, 0.185908f, @@ -44055,7 +44056,8 @@ const float parametricReverberationTimes[CLDFB_NO_CHANNELS_MAX] = { }; -const float parametricReverberationEneCorrections[CLDFB_NO_CHANNELS_MAX] = { +const float parametricReverberationEneCorrections[CLDFB_NO_CHANNELS_MAX] = +{ 0.191981f, 0.143739f, 0.113528f, 0.093836f, 0.090147f, 0.079961f, 0.066594f, 0.072700f, 0.076491f, 0.082065f, 0.085265f, 0.093864f, 0.101901f, 0.113728f, 0.117646f, 0.113494f, 0.126125f, 0.126304f, 0.123928f, 0.116067f, 0.098528f, 0.051482f, 0.029950f, 0.025223f, 0.021143f, 0.019358f, 0.016707f, 0.016227f, 0.018416f, 0.018419f, @@ -44065,7 +44067,8 @@ const float parametricReverberationEneCorrections[CLDFB_NO_CHANNELS_MAX] = { }; -const float parametricEarlyPartEneCorrection[CLDFB_NO_CHANNELS_MAX] = { +const float parametricEarlyPartEneCorrection[CLDFB_NO_CHANNELS_MAX] = +{ 0.595541f, 0.684107f, 1.041399f, 0.880102f, 0.726599f, 0.529105f, 0.456758f, 0.383174f, 0.331734f, 0.330565f, 0.436469f, 0.592478f, 0.767344f, 1.110786f, 1.548546f, 1.946089f, 2.550005f, 3.382855f, 4.235532f, 4.688064f, 3.328668f, 1.312207f, 0.376543f, 0.176443f, 0.149840f, 0.130307f, 0.137089f, 0.292711f, 0.580265f, 0.733105f, -- GitLab From 50663c4b73d9c99846835281e485711cce956a50 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 10 Oct 2022 14:52:24 +0200 Subject: [PATCH 8/8] fix Linux segmentation faults --- lib_dec/ivas_binauralRenderer.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib_dec/ivas_binauralRenderer.c b/lib_dec/ivas_binauralRenderer.c index 95c96f3bb8..b3d298b562 100644 --- a/lib_dec/ivas_binauralRenderer.c +++ b/lib_dec/ivas_binauralRenderer.c @@ -188,67 +188,67 @@ static ivas_error ivas_binRenderer_convModuleOpen( #ifdef SRAM_REDUCTION_BINRENDERER /* allocate memory for filter states */ - if ( ( hBinRenConvModule->filterTapsLeftReal = (float ***) count_malloc( hBinRenderer->conv_band * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsLeftReal = (float ***) count_malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsLeftImag = (float ***) count_malloc( hBinRenderer->conv_band * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsLeftImag = (float ***) count_malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsRightReal = (float ***) count_malloc( hBinRenderer->conv_band * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsRightReal = (float ***) count_malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsRightImag = (float ***) count_malloc( hBinRenderer->conv_band * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsRightImag = (float ***) count_malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - if ( ( hBinRenConvModule->filterTapsLeftReal[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsLeftReal[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsLeftImag[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsLeftImag[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsRightReal[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsRightReal[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsRightImag[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsRightImag[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } } - if ( ( hBinRenConvModule->filterStatesLeftReal = (float ***) count_malloc( hBinRenderer->conv_band * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterStatesLeftReal = (float ***) count_malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterStatesLeftImag = (float ***) count_malloc( hBinRenderer->conv_band * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterStatesLeftImag = (float ***) count_malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - if ( ( hBinRenConvModule->filterStatesLeftReal[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterStatesLeftReal[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterStatesLeftImag[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterStatesLeftImag[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } -- GitLab