diff --git a/lib_com/options.h b/lib_com/options.h index ae0fc101406cce26b0f1ad3be902a664a3a2b691..a24596c70ebc7bee9337f3a376d809c6b5064be1 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -160,7 +160,7 @@ #endif #define FIX_818_DOUBLE_PREC_KERNEN_SW /* FhG: Issue 818: Avoid double precision in kernel switching */ - +#define FIX_822_REFACTOR_BIN_REVERB_OPEN /* Nokia: Addresses first step of issue 822 by refactoring ivas_binaural_reverb_open */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index cda75af2ff22d7d508eb69e94e69a5b6c74b356e..6c79c87842b5949ef7c78db2d57f4d2c11392bb0 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -1230,7 +1230,11 @@ ivas_error ivas_binRenderer_open( /* Allocate memories needed for reverb module */ if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV && st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { +#ifdef FIX_822_REFACTOR_BIN_REVERB_OPEN + if ( ( error = ivas_binaural_reverb_open_fastconv( &( hBinRenderer->hReverb ), hBinRenderer->conv_band, hBinRenderer->timeSlots, &( st_ivas->hRenderConfig->roomAcoustics ), st_ivas->hIntSetup.output_config, st_ivas->hDecoderConfig->output_Fs, st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK ) +#else 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, st_ivas->hHrtfFastConv, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index ddc379d2cd70bb820b077535842c719fad2adf81..795f2aeea711f8043083de6f13255e4c74ab1476 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -234,7 +234,12 @@ ivas_error ivas_dirac_dec_init_binaural_data( if ( hDiracDecBin->hReverb == NULL ) #endif { - if ( ( error = ivas_binaural_reverb_open( &hDiracDecBin->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM, st_ivas->hHrtfFastConv, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) +#ifdef FIX_822_REFACTOR_BIN_REVERB_OPEN + /* Todo Philips: Room acoustics should be passed here once the underlying part works. Probably enough to pick it from st_ivas but you know best. */ + if ( ( error = ivas_binaural_reverb_open_parambin( &hDiracDecBin->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, output_Fs, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_binaural_reverb_open( &hDiracDecBin->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM, st_ivas->hHrtfFastConv, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 6909415d34e686e7bac72b86738d1112c00cf524..4f456f4cf110ddf0158a76abd3d0ecb35ced83e0 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -882,6 +882,26 @@ ivas_error ivas_rend_crendProcessSubframe( * Reverberator *----------------------------------------------------------------------------------*/ +#ifdef FIX_822_REFACTOR_BIN_REVERB_OPEN +ivas_error ivas_binaural_reverb_open_fastconv( + 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_ROOM_ACOUSTICS_CONFIG_DATA *roomAcoustics, /* i/o: room acoustics parameters */ + const AUDIO_CONFIG internal_config, /* i : internal audio config for FastConv */ + const int32_t sampling_rate, /* i : sampling rate */ + const HRTFS_FASTCONV_HANDLE hHrtfFastConv /* i : FastConv HRTF handle */ +); + +ivas_error ivas_binaural_reverb_open_parambin( + 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_ROOM_ACOUSTICS_CONFIG_DATA *roomAcoustics, /* i/o: room acoustics parameters */ + const int32_t sampling_rate, /* i : sampling rate */ + const HRTFS_PARAMBIN_HANDLE hHrtfParambin /* i : Parametric binauralizer HRTF handle */ +); +#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 */ @@ -893,6 +913,7 @@ ivas_error ivas_binaural_reverb_open( const HRTFS_FASTCONV_HANDLE hHrtfFastConv, /* i : FastConv HRTF handle */ const HRTFS_PARAMBIN_HANDLE hHrtfParambin /* i : Parametric binauralizer HRTF handle */ ); +#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 26c6287d7960339498efe45577d9f33e9a03a31d..6489460a1cafcfb0b98c0552d71861afb630aeb9 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -1777,6 +1777,17 @@ void ivas_binaural_reverb_processSubframe( * Allocate and initialize binaural room reverberator handle *------------------------------------------------------------------------*/ +#ifdef FIX_822_REFACTOR_BIN_REVERB_OPEN +static 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 */ + const int32_t sampling_rate, /* i : sampling rate */ + const float *revTimes, /* i : reverberation times T60 for each CLDFB bin in seconds */ + const float *revEnes, /* i : spectrum for reverberated sound at each CLDFB bin */ + const int16_t preDelay /* i : reverb pre-delay in CLDFB slots */ +) +#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 */ @@ -1788,13 +1799,16 @@ ivas_error ivas_binaural_reverb_open( const HRTFS_FASTCONV_HANDLE hHrtfFastConv, /* i : FastConv HRTF handle */ const HRTFS_PARAMBIN_HANDLE hHrtfParambin /* i : Parametric binauralizer HRTF handle */ ) +#endif { int16_t bin, chIdx, k, len; REVERB_STRUCT_HANDLE hReverb; +#ifndef FIX_822_REFACTOR_BIN_REVERB_OPEN const float *revTimes; float t60[CLDFB_NO_CHANNELS_MAX]; float ene[CLDFB_NO_CHANNELS_MAX]; ivas_error error; +#endif if ( ( *hReverbPr = (REVERB_STRUCT_HANDLE) malloc( sizeof( REVERB_STRUCT ) ) ) == NULL ) { @@ -1816,6 +1830,7 @@ ivas_error ivas_binaural_reverb_open( set_f( hReverb->preDelayBufferImag[k], 0.0f, hReverb->numBins ); } +#ifndef FIX_822_REFACTOR_BIN_REVERB_OPEN if ( renderer_type == RENDERER_BINAURAL_FASTCONV ) { if ( !roomAcoustics->override ) @@ -1831,7 +1846,7 @@ ivas_error ivas_binaural_reverb_open( { revTimes = hHrtfParambin->parametricReverberationTimes; } - +#endif for ( bin = 0; bin < hReverb->numBins; bin++ ) { /* Loop Buffer */ @@ -1894,7 +1909,10 @@ ivas_error ivas_binaural_reverb_open( } } - +#ifdef FIX_822_REFACTOR_BIN_REVERB_OPEN + ivas_binaural_reverb_setReverbTimes( hReverb, sampling_rate, revTimes, revEnes ); + ivas_binaural_reverb_setPreDelay( hReverb, preDelay ); +#else if ( ( roomAcoustics ) && ( roomAcoustics->override ) ) { if ( ( error = ivas_reverb_prepare_cldfb_params( roomAcoustics, hHrtfFastConv, output_config, false, sampling_rate, t60, ene ) ) != IVAS_ERR_OK ) @@ -1917,11 +1935,109 @@ ivas_error ivas_binaural_reverb_open( ivas_binaural_reverb_setPreDelay( hReverb, 10 ); } } +#endif return IVAS_ERR_OK; } +#ifdef FIX_822_REFACTOR_BIN_REVERB_OPEN +/*------------------------------------------------------------------------- + * ivas_binaural_reverb_open_fastconv() + * + * Allocate and initialize binaural room reverberator handle for FastConv + *------------------------------------------------------------------------*/ + +ivas_error ivas_binaural_reverb_open_fastconv( + 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_ROOM_ACOUSTICS_CONFIG_DATA *roomAcoustics, /* i/o: room acoustics parameters */ + const AUDIO_CONFIG internal_config, /* i : internal audio config for FastConv */ + const int32_t sampling_rate, /* i : sampling rate */ + const HRTFS_FASTCONV_HANDLE hHrtfFastConv /* i : FastConv HRTF handle */ +) +{ + ivas_error error; + const float *revTimes; + const float *revEne; + float t60[CLDFB_NO_CHANNELS_MAX]; + float ene[CLDFB_NO_CHANNELS_MAX]; + int16_t preDelay; + + error = IVAS_ERR_OK; + + if ( ( roomAcoustics != NULL ) && roomAcoustics->override ) + { + revTimes = t60; + revEne = ene; + if ( ( error = ivas_reverb_prepare_cldfb_params( roomAcoustics, hHrtfFastConv, internal_config, false, sampling_rate, t60, ene ) ) != IVAS_ERR_OK ) + { + return error; + } + preDelay = (int16_t) roundf( 48000.0f * roomAcoustics->acousticPreDelay / CLDFB_NO_CHANNELS_MAX ); + } + else + { + revTimes = hHrtfFastConv->fastconvReverberationTimes; + revEne = hHrtfFastConv->fastconvReverberationEneCorrections; + preDelay = 10; + } + + error = ivas_binaural_reverb_open( hReverbPr, numBins, numCldfbSlotsPerFrame, sampling_rate, revTimes, revEne, preDelay ); + + return error; +} + + +/*------------------------------------------------------------------------- + * ivas_binaural_reverb_open_parambin() + * + * Allocate and initialize binaural room reverberator handle for ParamBin + *------------------------------------------------------------------------*/ + +ivas_error ivas_binaural_reverb_open_parambin( + 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_ROOM_ACOUSTICS_CONFIG_DATA *roomAcoustics, /* i/o: room acoustics parameters */ + const int32_t sampling_rate, /* i : sampling rate */ + const HRTFS_PARAMBIN_HANDLE hHrtfParambin /* i : Parametric binauralizer HRTF handle */ +) +{ + ivas_error error; + const float *revTimes; + const float *revEne; + float t60[CLDFB_NO_CHANNELS_MAX]; + float ene[CLDFB_NO_CHANNELS_MAX]; + int16_t preDelay; + + error = IVAS_ERR_OK; + + if ( ( roomAcoustics != NULL ) && roomAcoustics->override ) + { + revTimes = t60; + revEne = ene; + /* Todo Philips: This needs a suitable function for ParamBin here. */ + // if ( ( error = ivas_reverb_prepare_cldfb_params( roomAcoustics, hHrtfFastConv, internal_config, false, sampling_rate, t60, ene ) ) != IVAS_ERR_OK ) + // { + // return error; + // } + preDelay = (int16_t) roundf( 48000.0f * roomAcoustics->acousticPreDelay / CLDFB_NO_CHANNELS_MAX ); + } + else + { + revTimes = hHrtfParambin->parametricReverberationTimes; + revEne = hHrtfParambin->parametricReverberationEneCorrections; + preDelay = 10; + } + + error = ivas_binaural_reverb_open( hReverbPr, numBins, numCldfbSlotsPerFrame, sampling_rate, revTimes, revEne, preDelay ); + + return error; +} +#endif + /*------------------------------------------------------------------------- * ivas_binaural_reverb_close() *