diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index a7f5987e38cda57caaaeb7bb3ab5af01fb96371f..fabcc5a0edea6b170f7041adb434b6b137ece487 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3235,12 +3235,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 old mode 100644 new mode 100755 index a35227e091783968f01e1dc13ea4acb27796197d..5d0e0c6088a26df834fd7533d9484f5787f71352 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -152,6 +152,8 @@ #define FIX_DIRAC_CHANNELS /* Issue 71: lower number of DirAC analysis channels */ #define HARMONIZE_SBA_NCHAN_TRANSPORT /* harmonize setting of number of transport channels in SBA */ #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 */ #define FIX_I120_INV_SQRT /* Issue 120: inv_sqrt() shall be used instead of 1 / sqrt() to measure the correct complexity */ diff --git a/lib_dec/ivas_binauralRenderer.c b/lib_dec/ivas_binauralRenderer.c index 153e159adc0daa06c13c8c6d23cda5c329c8de31..b3d298b562871e37dff930eb6e1ba59b8ab91829 100644 --- a/lib_dec/ivas_binauralRenderer.c +++ b/lib_dec/ivas_binauralRenderer.c @@ -186,6 +186,89 @@ 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 ) + { + 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 ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) + { + 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 ) + { + 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 ) + { + 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 ) + { + 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 ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) + { + 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 ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } + + for ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) + { + 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[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" ) ); + } + } + } +#endif + + /* set memories */ for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { for ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) @@ -225,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 ) { @@ -290,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 */ @@ -405,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; @@ -500,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 ); @@ -517,6 +617,8 @@ ivas_error ivas_binRenderer_open( } hBinRenderer->hReverb->useBinauralCoherence = 1; +#endif + /* initialize the dmx matrix */ for ( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) { @@ -560,6 +662,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 bandIdx, chIdx; + BINRENDERER_CONV_MODULE_HANDLE hBinRenConvModule; + + hBinRenConvModule = ( *hBinRenderer )->hBinRenConvModule; + + if ( hBinRenConvModule == NULL ) + { + return; + } + + for ( bandIdx = 0; bandIdx < ( *hBinRenderer )->conv_band; bandIdx++ ) + { + count_free( hBinRenConvModule->filterTapsLeftReal[bandIdx] ); + hBinRenConvModule->filterTapsLeftReal[bandIdx] = NULL; + + count_free( hBinRenConvModule->filterTapsLeftImag[bandIdx] ); + hBinRenConvModule->filterTapsLeftImag[bandIdx] = NULL; + + count_free( hBinRenConvModule->filterTapsRightReal[bandIdx] ); + hBinRenConvModule->filterTapsRightReal[bandIdx] = NULL; + + count_free( hBinRenConvModule->filterTapsRightImag[bandIdx] ); + hBinRenConvModule->filterTapsRightImag[bandIdx] = NULL; + } + + count_free( hBinRenConvModule->filterTapsLeftReal ); + hBinRenConvModule->filterTapsLeftReal = NULL; + + count_free( hBinRenConvModule->filterTapsLeftImag ); + hBinRenConvModule->filterTapsLeftImag = NULL; + + count_free( hBinRenConvModule->filterTapsRightReal ); + hBinRenConvModule->filterTapsRightReal = NULL; + + count_free( hBinRenConvModule->filterTapsRightImag ); + hBinRenConvModule->filterTapsRightImag = NULL; + + + for ( bandIdx = 0; bandIdx < ( *hBinRenderer )->conv_band; bandIdx++ ) + { + for ( chIdx = 0; chIdx < ( *hBinRenderer )->nInChannels; chIdx++ ) + { + count_free( hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx] ); + hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx] = NULL; + + count_free( hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx] ); + hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx] = NULL; + } + + count_free( hBinRenConvModule->filterStatesLeftReal[bandIdx] ); + hBinRenConvModule->filterStatesLeftReal[bandIdx] = NULL; + + count_free( hBinRenConvModule->filterStatesLeftImag[bandIdx] ); + hBinRenConvModule->filterStatesLeftImag[bandIdx] = 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() @@ -578,8 +760,12 @@ void ivas_binRenderer_close( if ( ( *hBinRenderer )->hBinRenConvModule != NULL ) { +#ifdef SRAM_REDUCTION_BINRENDERER + ivas_binRenderer_convModuleClose( hBinRenderer ); +#else count_free( ( *hBinRenderer )->hBinRenConvModule ); ( *hBinRenderer )->hBinRenConvModule = NULL; +#endif } if ( ( *hBinRenderer )->hReverb != NULL ) @@ -775,10 +961,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 ); @@ -791,7 +977,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_binaural_reverb.c b/lib_dec/ivas_binaural_reverb.c index 054b8c1558af5fd09adc51a98d0e26e0c16cbd2e..db552e538a22acbc4c06327a993f24b3bb11abc1 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 = t60; + } + } + 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 6d7bdf2491c765a535c725915c7cca243ad9fbbb..94f504954200b3dc79052609fc50c561258a9ff8 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 ) { diff --git a/lib_dec/ivas_rom_binauralRenderer.c b/lib_dec/ivas_rom_binauralRenderer.c index 28c8856012ef604951b516b59533fa846c8c58ad..bfd2da9fb496a741a7698ce00d1fdbfdd919c66c 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, diff --git a/lib_dec/ivas_rom_binauralRenderer.h b/lib_dec/ivas_rom_binauralRenderer.h index 3bed3c5ec9d9c5d853fa492434df1ee43e815a7d..ca3a527c4cfce2a4d004f8ae92c270b8bb7a8d00 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 aae4dad4b407ab97019f45b73b104ba710131be5..43a30693e60dd6310091aabf35e7da7d9b3cef33 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1303,13 +1303,25 @@ typedef struct ivas_dirac_dec_binaural_data_structure typedef struct ivas_binaural_rendering_conv_module_struct { +#ifdef SRAM_REDUCTION_BINRENDERER + 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]; 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; + float ***filterStatesLeftImag; +#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;