From b815bed5a4124cef4e492decb4762befe5df4f4f Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Tue, 17 Sep 2024 15:42:26 +0300 Subject: [PATCH 1/5] Fixes issue 1139 to prevent sound coloration artefacts at very low reverberation times --- lib_com/options.h | 2 + lib_rend/ivas_dirac_dec_binaural_functions.c | 12 +++ lib_rend/ivas_prot_rend.h | 13 +++ lib_rend/ivas_reverb.c | 89 ++++++++++++++++++++ 4 files changed, 116 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index ff1bc4ed7a..9d7960e3fd 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -181,6 +181,8 @@ #define NONBE_FIX_1174_MCMASA_LBR_LOOP_ERROR /* Nokia: Fix issue 1174 by removing the unnecessary inner loop causing problems. */ +#define FIX_1139_PARAM_REV_COLORATION_SHORT_T60 /* Nokia: Fix issue 1139, prevent sound coloration artefacts at very low reverberation times */ + /* ##################### End NON-BE switches ########################### */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 1d63b23d09..b8aeca6b7c 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -235,7 +235,19 @@ ivas_error ivas_dirac_dec_init_binaural_data( if ( hDiracDecBin->hReverb == NULL && pos_idx == 0 ) /* open reverb only for the main direction */ { +#ifdef FIX_1139_PARAM_REV_COLORATION_SHORT_T60 + if ( ( error = ivas_binaural_reverb_init_for_parambin( &hDiracDecBin->hReverb, + st_ivas->hHrtfStatistics, + nBins, + CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, + &( st_ivas->hRenderConfig->roomAcoustics ), + output_Fs, + ( *phHrtfParambin )->parametricReverberationTimes, + ( *phHrtfParambin )->parametricReverberationEneCorrections, + hDiracDecBin->earlyPartEneCorrection ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_binaural_reverb_init( &hDiracDecBin->hReverb, st_ivas->hHrtfStatistics, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, &( st_ivas->hRenderConfig->roomAcoustics ), output_Fs, ( *phHrtfParambin )->parametricReverberationTimes, ( *phHrtfParambin )->parametricReverberationEneCorrections ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 8e6980b054..b7916ff52d 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -940,6 +940,19 @@ ivas_error ivas_binaural_reverb_init( const float *defaultEne /* i : default reverberation energies */ ); +#ifdef FIX_1139_PARAM_REV_COLORATION_SHORT_T60 +ivas_error ivas_binaural_reverb_init_for_parambin( + REVERB_STRUCT_HANDLE *hReverbPr, /* i/o: binaural reverb handle */ + const HRTFS_STATISTICS_HANDLE hHrtfStatistics, /* i : HRTF statistics handle */ + const int16_t numBins, /* i : number of CLDFB bins */ + const int16_t numCldfbSlotsPerFrame, /* i : number of CLDFB slots per frame */ + const IVAS_ROOM_ACOUSTICS_CONFIG_DATA *roomAcoustics, /* i/o: room acoustics parameters */ + const int32_t sampling_rate, /* i : sampling rate */ + const float *defaultTimes, /* i : default reverberation times */ + const float *defaultEne, /* i : default reverberation energies */ + float *earlyEne /* i/o: early part energies to be modified */ +); +#endif void ivas_binaural_reverb_close( REVERB_STRUCT_HANDLE *hReverb /* i/o: binaural reverb handle */ diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index 7ea38fe2a7..c3fae0a725 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -254,6 +254,19 @@ static void ivas_binaural_reverb_setReverbTimes( } currentEnergy *= attenuationFactorPerSampleSq; } +#ifdef FIX_1139_PARAM_REV_COLORATION_SHORT_T60 + /* In some configurations with small T60s it is possible the number of taps randomizes to zero. + Ensure at least 1 filter tap. */ + if (tap == 0) + { + hReverb->tapPhaseShiftType[bin][ch][0] = (int16_t) ( binRend_rand( hReverb ) % 4 ); + hReverb->tapPointersReal[bin][ch][0] = &( hReverb->loopBufReal[bin][0] ); + hReverb->tapPointersImag[bin][ch][0] = &( hReverb->loopBufImag[bin][0] ); + tap = 1; + actualizedEnergy = 1; + } +#endif + hReverb->taps[bin][ch] = tap; /* Number of taps determined at the above random procedure */ } @@ -1896,6 +1909,82 @@ ivas_error ivas_binaural_reverb_init( return error; } +#ifdef FIX_1139_PARAM_REV_COLORATION_SHORT_T60 +/*------------------------------------------------------------------------- + * ivas_binaural_reverb_init_for_parambin() + * + * Allocate and initialize binaural room reverberator handle + * for parametric binaural renderer, using room effect parameter adjustment + *------------------------------------------------------------------------*/ +ivas_error ivas_binaural_reverb_init_for_parambin( + REVERB_STRUCT_HANDLE *hReverbPr, /* i/o: binaural reverb handle */ + const HRTFS_STATISTICS_HANDLE hHrtfStatistics, /* i : HRTF statistics handle */ + const int16_t numBins, /* i : number of CLDFB bins */ + const int16_t numCldfbSlotsPerFrame, /* i : number of CLDFB slots per frame */ + const IVAS_ROOM_ACOUSTICS_CONFIG_DATA *roomAcoustics, /* i/o: room acoustics parameters */ + const int32_t sampling_rate, /* i : sampling rate */ + const float *defaultTimes, /* i : default reverberation times */ + const float *defaultEne, /* i : default reverberation energies */ + float *earlyEne /* i/o: Early part energies to be modified */ +) +{ + ivas_error error; + float revTimes[CLDFB_NO_CHANNELS_MAX]; + float revEne[CLDFB_NO_CHANNELS_MAX]; + int16_t preDelay, bin; + + error = IVAS_ERR_OK; + + if ( ( roomAcoustics != NULL ) && roomAcoustics->override ) + { + if ( ( error = ivas_reverb_prepare_cldfb_params( roomAcoustics, hHrtfStatistics, sampling_rate, revTimes, revEne ) ) != IVAS_ERR_OK ) + { + return error; + } + preDelay = (int16_t) roundf( 48000.0f * roomAcoustics->acousticPreDelay / CLDFB_NO_CHANNELS_MAX ); + } + else + { + for ( bin = 0; bin < CLDFB_NO_CHANNELS_MAX; bin++ ) + { + revTimes[bin] = defaultTimes[bin]; + revEne[bin] = defaultEne[bin]; + } + preDelay = 10; + } + for ( bin = 0; bin < 60; bin++ ) + { + /* Adjust the room effect parameters when the reverberation time is less than a threshold value, to avoid + spectral artefacts with the synthetic reverberator. */ + const float revTimeThreshold = 0.2f; + if ( revTimes[bin] < revTimeThreshold ) + { + float adjustedEarlyEne, adjustedLateEne, adjustedRevTime; + float revTimeModifier, energyModifier; + + /* Adjust reverberation times, higher towards a threshold */ + revTimeModifier = fmaxf( 0.0f, 1.0f - ( revTimes[bin] / revTimeThreshold ) ); + adjustedRevTime = ( 1.0f - revTimeModifier ) * revTimes[bin]; + adjustedRevTime += revTimeModifier * ( revTimes[bin] + revTimeThreshold ) * 0.5f; + energyModifier = ( adjustedRevTime - revTimes[bin] ) / adjustedRevTime; + + /* Adjust early and late energies, by moving late energy to early energy */ + adjustedEarlyEne = earlyEne[bin] + revEne[bin] * energyModifier; + adjustedLateEne = revEne[bin] * ( 1.0f - energyModifier ); + + /* Store adjusted room effect parameters to be used in reverb processing */ + revTimes[bin] = adjustedRevTime; + revEne[bin] = adjustedLateEne; + earlyEne[bin] = adjustedEarlyEne; + } + } + + error = ivas_binaural_reverb_open( hReverbPr, numBins, numCldfbSlotsPerFrame, sampling_rate, revTimes, revEne, preDelay ); + + return error; +} +#endif + /*------------------------------------------------------------------------- * ivas_binaural_reverb_close() * -- GitLab From 591b7947afe66985775a7a10da78088d74bbf833 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Tue, 17 Sep 2024 17:30:31 +0300 Subject: [PATCH 2/5] Apply clang format --- lib_rend/ivas_dirac_dec_binaural_functions.c | 16 ++++++++-------- lib_rend/ivas_reverb.c | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index b8aeca6b7c..ac07c39087 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -237,14 +237,14 @@ ivas_error ivas_dirac_dec_init_binaural_data( { #ifdef FIX_1139_PARAM_REV_COLORATION_SHORT_T60 if ( ( error = ivas_binaural_reverb_init_for_parambin( &hDiracDecBin->hReverb, - st_ivas->hHrtfStatistics, - nBins, - CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, - &( st_ivas->hRenderConfig->roomAcoustics ), - output_Fs, - ( *phHrtfParambin )->parametricReverberationTimes, - ( *phHrtfParambin )->parametricReverberationEneCorrections, - hDiracDecBin->earlyPartEneCorrection ) ) != IVAS_ERR_OK ) + st_ivas->hHrtfStatistics, + nBins, + CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, + &( st_ivas->hRenderConfig->roomAcoustics ), + output_Fs, + ( *phHrtfParambin )->parametricReverberationTimes, + ( *phHrtfParambin )->parametricReverberationEneCorrections, + hDiracDecBin->earlyPartEneCorrection ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_binaural_reverb_init( &hDiracDecBin->hReverb, st_ivas->hHrtfStatistics, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, &( st_ivas->hRenderConfig->roomAcoustics ), output_Fs, ( *phHrtfParambin )->parametricReverberationTimes, ( *phHrtfParambin )->parametricReverberationEneCorrections ) ) != IVAS_ERR_OK ) #endif diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index c3fae0a725..a4e7a7a0aa 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -257,7 +257,7 @@ static void ivas_binaural_reverb_setReverbTimes( #ifdef FIX_1139_PARAM_REV_COLORATION_SHORT_T60 /* In some configurations with small T60s it is possible the number of taps randomizes to zero. Ensure at least 1 filter tap. */ - if (tap == 0) + if ( tap == 0 ) { hReverb->tapPhaseShiftType[bin][ch][0] = (int16_t) ( binRend_rand( hReverb ) % 4 ); hReverb->tapPointersReal[bin][ch][0] = &( hReverb->loopBufReal[bin][0] ); -- GitLab From 4b719fcc24c724d4750c408a4d9752876750ea86 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 2 Oct 2024 14:03:51 +0200 Subject: [PATCH 3/5] - rename switch to FIX_1139_REV_COLORATION_SHORT_T60 - update ivas_binaural_reverb_init() and remove _parambin version --- lib_com/options.h | 2 +- lib_dec/ivas_binRenderer_internal.c | 14 +++- lib_dec/lib_dec.c | 28 ++++++- lib_rend/ivas_dirac_dec_binaural_functions.c | 24 +++--- lib_rend/ivas_prot_rend.h | 18 +---- lib_rend/ivas_reverb.c | 83 ++++++++------------ lib_rend/lib_rend.c | 42 +++++++++- 7 files changed, 128 insertions(+), 83 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 9d7960e3fd..d36e88ac00 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -181,7 +181,7 @@ #define NONBE_FIX_1174_MCMASA_LBR_LOOP_ERROR /* Nokia: Fix issue 1174 by removing the unnecessary inner loop causing problems. */ -#define FIX_1139_PARAM_REV_COLORATION_SHORT_T60 /* Nokia: Fix issue 1139, prevent sound coloration artefacts at very low reverberation times */ +#define FIX_1139_REV_COLORATION_SHORT_T60 /* Nokia,FhG: Fix issue 1139, prevent sound coloration artefacts at very low reverberation times */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index 6de77455cc..18369a5d8b 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -1214,7 +1214,19 @@ ivas_error ivas_binRenderer_open( /* Allocate memories needed for reverb module */ if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV && st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { - if ( ( error = ivas_binaural_reverb_init( &( hBinRenderer->hReverb ), st_ivas->hHrtfStatistics, hBinRenderer->conv_band, hBinRenderer->timeSlots, &( st_ivas->hRenderConfig->roomAcoustics ), st_ivas->hDecoderConfig->output_Fs, st_ivas->hHrtfFastConv->fastconvReverberationTimes, st_ivas->hHrtfFastConv->fastconvReverberationEneCorrections ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_binaural_reverb_init( &( hBinRenderer->hReverb ), + st_ivas->hHrtfStatistics, + hBinRenderer->conv_band, + hBinRenderer->timeSlots, + &( st_ivas->hRenderConfig->roomAcoustics ), + st_ivas->hDecoderConfig->output_Fs, + st_ivas->hHrtfFastConv->fastconvReverberationTimes, + st_ivas->hHrtfFastConv->fastconvReverberationEneCorrections +#ifdef FIX_1139_REV_COLORATION_SHORT_T60 + , + hBinRenderer->earlyPartEneCorrection +#endif + ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index a3d3c7492a..85cbd9bca1 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -2842,7 +2842,19 @@ ivas_error IVAS_DEC_FeedRenderConfig( if ( hIvasDec->st_ivas->hDiracDecBin[0] != NULL && hIvasDec->st_ivas->hDiracDecBin[0]->hReverb != NULL ) { ivas_binaural_reverb_close( &( hIvasDec->st_ivas->hDiracDecBin[0]->hReverb ) ); - if ( ( error = ivas_binaural_reverb_init( &( hIvasDec->st_ivas->hDiracDecBin[0]->hReverb ), hIvasDec->st_ivas->hHrtfStatistics, hIvasDec->st_ivas->hSpatParamRendCom->num_freq_bands, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, &( hRenderConfig->roomAcoustics ), hIvasDec->st_ivas->hDecoderConfig->output_Fs, NULL, NULL ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_binaural_reverb_init( &( hIvasDec->st_ivas->hDiracDecBin[0]->hReverb ), + hIvasDec->st_ivas->hHrtfStatistics, + hIvasDec->st_ivas->hSpatParamRendCom->num_freq_bands, + CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, + &( hRenderConfig->roomAcoustics ), + hIvasDec->st_ivas->hDecoderConfig->output_Fs, + NULL, + NULL +#ifdef FIX_1139_REV_COLORATION_SHORT_T60 + , + NULL +#endif + ) ) != IVAS_ERR_OK ) { return error; } @@ -2851,7 +2863,19 @@ ivas_error IVAS_DEC_FeedRenderConfig( if ( hIvasDec->st_ivas->hBinRenderer != NULL && hIvasDec->st_ivas->hBinRenderer->hReverb != NULL ) { ivas_binaural_reverb_close( &( hIvasDec->st_ivas->hBinRenderer->hReverb ) ); - if ( ( error = ivas_binaural_reverb_init( &( hIvasDec->st_ivas->hBinRenderer->hReverb ), hIvasDec->st_ivas->hHrtfStatistics, hIvasDec->st_ivas->hBinRenderer->conv_band, hIvasDec->st_ivas->hBinRenderer->timeSlots, &( hRenderConfig->roomAcoustics ), hIvasDec->st_ivas->hDecoderConfig->output_Fs, NULL, NULL ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_binaural_reverb_init( &( hIvasDec->st_ivas->hBinRenderer->hReverb ), + hIvasDec->st_ivas->hHrtfStatistics, + hIvasDec->st_ivas->hBinRenderer->conv_band, + hIvasDec->st_ivas->hBinRenderer->timeSlots, + &( hRenderConfig->roomAcoustics ), + hIvasDec->st_ivas->hDecoderConfig->output_Fs, + NULL, + NULL +#ifdef FIX_1139_REV_COLORATION_SHORT_T60 + , + NULL +#endif + ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index ac07c39087..cd812c6278 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -235,19 +235,19 @@ ivas_error ivas_dirac_dec_init_binaural_data( if ( hDiracDecBin->hReverb == NULL && pos_idx == 0 ) /* open reverb only for the main direction */ { -#ifdef FIX_1139_PARAM_REV_COLORATION_SHORT_T60 - if ( ( error = ivas_binaural_reverb_init_for_parambin( &hDiracDecBin->hReverb, - st_ivas->hHrtfStatistics, - nBins, - CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, - &( st_ivas->hRenderConfig->roomAcoustics ), - output_Fs, - ( *phHrtfParambin )->parametricReverberationTimes, - ( *phHrtfParambin )->parametricReverberationEneCorrections, - hDiracDecBin->earlyPartEneCorrection ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_binaural_reverb_init( &hDiracDecBin->hReverb, st_ivas->hHrtfStatistics, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, &( st_ivas->hRenderConfig->roomAcoustics ), output_Fs, ( *phHrtfParambin )->parametricReverberationTimes, ( *phHrtfParambin )->parametricReverberationEneCorrections ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_binaural_reverb_init( &hDiracDecBin->hReverb, + st_ivas->hHrtfStatistics, + nBins, + CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, + &( st_ivas->hRenderConfig->roomAcoustics ), + output_Fs, + ( *phHrtfParambin )->parametricReverberationTimes, + ( *phHrtfParambin )->parametricReverberationEneCorrections +#ifdef FIX_1139_REV_COLORATION_SHORT_T60 + , + hDiracDecBin->earlyPartEneCorrection #endif + ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index b7916ff52d..32f7246ef5 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -938,22 +938,12 @@ ivas_error ivas_binaural_reverb_init( const int32_t sampling_rate, /* i : sampling rate */ const float *defaultTimes, /* i : default reverberation times */ const float *defaultEne /* i : default reverberation energies */ + #ifdef FIX_1139_REV_COLORATION_SHORT_T60 + , + float *earlyEne /* i/o: Early part energies to be modified */ + #endif ); -#ifdef FIX_1139_PARAM_REV_COLORATION_SHORT_T60 -ivas_error ivas_binaural_reverb_init_for_parambin( - REVERB_STRUCT_HANDLE *hReverbPr, /* i/o: binaural reverb handle */ - const HRTFS_STATISTICS_HANDLE hHrtfStatistics, /* i : HRTF statistics handle */ - const int16_t numBins, /* i : number of CLDFB bins */ - const int16_t numCldfbSlotsPerFrame, /* i : number of CLDFB slots per frame */ - const IVAS_ROOM_ACOUSTICS_CONFIG_DATA *roomAcoustics, /* i/o: room acoustics parameters */ - const int32_t sampling_rate, /* i : sampling rate */ - const float *defaultTimes, /* i : default reverberation times */ - const float *defaultEne, /* i : default reverberation energies */ - float *earlyEne /* i/o: early part energies to be modified */ -); -#endif - void ivas_binaural_reverb_close( REVERB_STRUCT_HANDLE *hReverb /* i/o: binaural reverb handle */ ); diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index a4e7a7a0aa..c3569df4c4 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -254,7 +254,7 @@ static void ivas_binaural_reverb_setReverbTimes( } currentEnergy *= attenuationFactorPerSampleSq; } -#ifdef FIX_1139_PARAM_REV_COLORATION_SHORT_T60 +#ifdef FIX_1139_REV_COLORATION_SHORT_T60 /* In some configurations with small T60s it is possible the number of taps randomizes to zero. Ensure at least 1 filter tap. */ if ( tap == 0 ) @@ -1875,69 +1875,45 @@ ivas_error ivas_binaural_reverb_init( const int32_t sampling_rate, /* i : sampling rate */ const float *defaultTimes, /* i : default reverberation times */ const float *defaultEne /* i : default reverberation energies */ +#ifdef FIX_1139_REV_COLORATION_SHORT_T60 + , + float *earlyEne /* i/o: Early part energies to be modified */ +#endif ) { ivas_error error; +#ifdef FIX_1139_REV_COLORATION_SHORT_T60 + int16_t preDelay, bin; + float revTimes[CLDFB_NO_CHANNELS_MAX]; + float revEne[CLDFB_NO_CHANNELS_MAX]; +#else const float *revTimes; const float *revEne; float t60[CLDFB_NO_CHANNELS_MAX]; float ene[CLDFB_NO_CHANNELS_MAX]; int16_t preDelay; +#endif error = IVAS_ERR_OK; if ( ( roomAcoustics != NULL ) && roomAcoustics->override ) { +#ifndef FIX_1139_REV_COLORATION_SHORT_T60 revTimes = t60; revEne = ene; +#endif - if ( ( error = ivas_reverb_prepare_cldfb_params( roomAcoustics, hHrtfStatistics, sampling_rate, t60, ene ) ) != IVAS_ERR_OK ) - { - return error; - } - preDelay = (int16_t) roundf( 48000.0f * roomAcoustics->acousticPreDelay / CLDFB_NO_CHANNELS_MAX ); - } - else - { - revTimes = defaultTimes; - revEne = defaultEne; - preDelay = 10; - } - - error = ivas_binaural_reverb_open( hReverbPr, numBins, numCldfbSlotsPerFrame, sampling_rate, revTimes, revEne, preDelay ); - - return error; -} - -#ifdef FIX_1139_PARAM_REV_COLORATION_SHORT_T60 -/*------------------------------------------------------------------------- - * ivas_binaural_reverb_init_for_parambin() - * - * Allocate and initialize binaural room reverberator handle - * for parametric binaural renderer, using room effect parameter adjustment - *------------------------------------------------------------------------*/ -ivas_error ivas_binaural_reverb_init_for_parambin( - REVERB_STRUCT_HANDLE *hReverbPr, /* i/o: binaural reverb handle */ - const HRTFS_STATISTICS_HANDLE hHrtfStatistics, /* i : HRTF statistics handle */ - const int16_t numBins, /* i : number of CLDFB bins */ - const int16_t numCldfbSlotsPerFrame, /* i : number of CLDFB slots per frame */ - const IVAS_ROOM_ACOUSTICS_CONFIG_DATA *roomAcoustics, /* i/o: room acoustics parameters */ - const int32_t sampling_rate, /* i : sampling rate */ - const float *defaultTimes, /* i : default reverberation times */ - const float *defaultEne, /* i : default reverberation energies */ - float *earlyEne /* i/o: Early part energies to be modified */ -) -{ - ivas_error error; - float revTimes[CLDFB_NO_CHANNELS_MAX]; - float revEne[CLDFB_NO_CHANNELS_MAX]; - int16_t preDelay, bin; - - error = IVAS_ERR_OK; - - if ( ( roomAcoustics != NULL ) && roomAcoustics->override ) - { - if ( ( error = ivas_reverb_prepare_cldfb_params( roomAcoustics, hHrtfStatistics, sampling_rate, revTimes, revEne ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_reverb_prepare_cldfb_params( roomAcoustics, + hHrtfStatistics, + sampling_rate, +#ifdef FIX_1139_REV_COLORATION_SHORT_T60 + revTimes, + revEne +#else + t60, + ene +#endif + ) ) != IVAS_ERR_OK ) { return error; } @@ -1945,14 +1921,21 @@ ivas_error ivas_binaural_reverb_init_for_parambin( } else { +#ifdef FIX_1139_REV_COLORATION_SHORT_T60 for ( bin = 0; bin < CLDFB_NO_CHANNELS_MAX; bin++ ) { revTimes[bin] = defaultTimes[bin]; revEne[bin] = defaultEne[bin]; } +#else + revTimes = defaultTimes; + revEne = defaultEne; +#endif preDelay = 10; } - for ( bin = 0; bin < 60; bin++ ) + +#ifdef FIX_1139_REV_COLORATION_SHORT_T60 + for ( bin = 0; bin < CLDFB_NO_CHANNELS_MAX; bin++ ) { /* Adjust the room effect parameters when the reverberation time is less than a threshold value, to avoid spectral artefacts with the synthetic reverberator. */ @@ -1978,12 +1961,12 @@ ivas_error ivas_binaural_reverb_init_for_parambin( earlyEne[bin] = adjustedEarlyEne; } } +#endif error = ivas_binaural_reverb_open( hReverbPr, numBins, numCldfbSlotsPerFrame, sampling_rate, revTimes, revEne, preDelay ); return error; } -#endif /*------------------------------------------------------------------------- * ivas_binaural_reverb_close() diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index e3538025ec..28d5a4cc3a 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -4309,7 +4309,19 @@ ivas_error IVAS_REND_FeedRenderConfig( if ( pMasaInput->hMasaExtRend->hDiracDecBin[0] != NULL && pMasaInput->hMasaExtRend->hDiracDecBin[0]->hReverb != NULL ) { ivas_binaural_reverb_close( &pMasaInput->hMasaExtRend->hDiracDecBin[0]->hReverb ); - if ( ( error = ivas_binaural_reverb_init( &pMasaInput->hMasaExtRend->hDiracDecBin[0]->hReverb, hIvasRend->hHrtfs.hHrtfStatistics, pMasaInput->hMasaExtRend->hSpatParamRendCom->num_freq_bands, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, &( hRenderConfig->roomAcoustics ), *pMasaInput->base.ctx.pOutSampleRate, NULL, NULL ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_binaural_reverb_init( &pMasaInput->hMasaExtRend->hDiracDecBin[0]->hReverb, + hIvasRend->hHrtfs.hHrtfStatistics, + pMasaInput->hMasaExtRend->hSpatParamRendCom->num_freq_bands, + CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, + &( hRenderConfig->roomAcoustics ), + *pMasaInput->base.ctx.pOutSampleRate, + NULL, + NULL +#ifdef FIX_1139_REV_COLORATION_SHORT_T60 + , + NULL +#endif + ) ) != IVAS_ERR_OK ) { return error; } @@ -4318,7 +4330,19 @@ ivas_error IVAS_REND_FeedRenderConfig( if ( pMasaInput->hMasaExtRend->hReverb != NULL ) { ivas_binaural_reverb_close( &pMasaInput->hMasaExtRend->hReverb ); - if ( ( error = ivas_binaural_reverb_init( &pMasaInput->hMasaExtRend->hReverb, hIvasRend->hHrtfs.hHrtfStatistics, pMasaInput->hMasaExtRend->hSpatParamRendCom->num_freq_bands, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, &( hRenderConfig->roomAcoustics ), *pMasaInput->base.ctx.pOutSampleRate, NULL, NULL ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_binaural_reverb_init( &pMasaInput->hMasaExtRend->hReverb, + hIvasRend->hHrtfs.hHrtfStatistics, + pMasaInput->hMasaExtRend->hSpatParamRendCom->num_freq_bands, + CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, + &( hRenderConfig->roomAcoustics ), + *pMasaInput->base.ctx.pOutSampleRate, + NULL, + NULL +#ifdef FIX_1139_REV_COLORATION_SHORT_T60 + , + NULL +#endif + ) ) != IVAS_ERR_OK ) { return error; } @@ -8395,7 +8419,19 @@ static ivas_error ivas_masa_ext_rend_parambin_init( if ( hDiracDecBin->hReverb == NULL && pos_idx == 0 ) /* open reverb only for the main direction */ { - if ( ( error = ivas_binaural_reverb_init( &hDiracDecBin->hReverb, hHrtfStatistics, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, &( hRendCfg->roomAcoustics ), output_Fs, ( *phHrtfParambin )->parametricReverberationTimes, ( *phHrtfParambin )->parametricReverberationEneCorrections ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_binaural_reverb_init( &hDiracDecBin->hReverb, + hHrtfStatistics, + nBins, + CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, + &( hRendCfg->roomAcoustics ), + output_Fs, + ( *phHrtfParambin )->parametricReverberationTimes, + ( *phHrtfParambin )->parametricReverberationEneCorrections +#ifdef FIX_1139_REV_COLORATION_SHORT_T60 + , + hDiracDecBin->earlyPartEneCorrection +#endif + ) ) != IVAS_ERR_OK ) { return error; } -- GitLab From 8d132a937c628eda940c537e040936ee82a835cb Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 2 Oct 2024 14:07:48 +0200 Subject: [PATCH 4/5] clang-format --- 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 c3569df4c4..79075962a4 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -254,7 +254,7 @@ static void ivas_binaural_reverb_setReverbTimes( } currentEnergy *= attenuationFactorPerSampleSq; } -#ifdef FIX_1139_REV_COLORATION_SHORT_T60 +#ifdef FIX_1139_REV_COLORATION_SHORT_T60 /* In some configurations with small T60s it is possible the number of taps randomizes to zero. Ensure at least 1 filter tap. */ if ( tap == 0 ) -- GitLab From e64e719d91805988ab8c5d2ea60102d9635d3542 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Mon, 7 Oct 2024 10:29:26 +0300 Subject: [PATCH 5/5] Convert const float to a define value. --- lib_rend/ivas_reverb.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index c9aacc90c0..bc3bd4c605 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -56,6 +56,10 @@ #define CLDFB_SLOTS_PER_SECOND 800 /* Used for initializing reverb */ +#ifdef FIX_1139_REV_COLORATION_SHORT_T60 +#define REV_TIME_THRESHOLD ( 0.2f ) +#endif + #define INNER_BLK_SIZE 80 /* size of data blocks used for more efficient delay line and IIR filter processing */ /* should be a divisor of the frame length at any sampling rate and an even number*/ #define FFT_FILTER_WND_FLAT_REGION ( 0.40f ) /* flat section (==1) length of FFT filter window, in proportion to overlap */ @@ -1945,16 +1949,15 @@ ivas_error ivas_binaural_reverb_init( { /* Adjust the room effect parameters when the reverberation time is less than a threshold value, to avoid spectral artefacts with the synthetic reverberator. */ - const float revTimeThreshold = 0.2f; - if ( revTimes[bin] < revTimeThreshold ) + if ( revTimes[bin] < REV_TIME_THRESHOLD ) { float adjustedEarlyEne, adjustedLateEne, adjustedRevTime; float revTimeModifier, energyModifier; /* Adjust reverberation times, higher towards a threshold */ - revTimeModifier = fmaxf( 0.0f, 1.0f - ( revTimes[bin] / revTimeThreshold ) ); + revTimeModifier = fmaxf( 0.0f, 1.0f - ( revTimes[bin] / REV_TIME_THRESHOLD ) ); adjustedRevTime = ( 1.0f - revTimeModifier ) * revTimes[bin]; - adjustedRevTime += revTimeModifier * ( revTimes[bin] + revTimeThreshold ) * 0.5f; + adjustedRevTime += revTimeModifier * ( revTimes[bin] + REV_TIME_THRESHOLD ) * 0.5f; energyModifier = ( adjustedRevTime - revTimes[bin] ) / adjustedRevTime; /* Adjust early and late energies, by moving late energy to early energy */ -- GitLab