From a168078f26c89fd2fcececcb703c1862dd6bf0a5 Mon Sep 17 00:00:00 2001 From: Charles Kinuthia Date: Wed, 1 Feb 2023 15:50:41 +0100 Subject: [PATCH 1/4] Enable reverb for TD renderer for 5.1 and 7.1 with headtracking enabled for IVAS_dec Under FIX_329_ENABLE_TD_RENDERER_REVERB_MC define --- lib_com/options.h | 1 + lib_rend/ivas_binauralRenderer.c | 11 +++++++++++ lib_rend/ivas_output_init.c | 12 ++++++++++++ 3 files changed, 24 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 5dddf236ea..d4679f40e1 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -167,6 +167,7 @@ #define FIX_317 /* FhG: issue 317 - address sanitizer error in MDCT-Stereo PLC */ +#define FIX_329_ENABLE_TD_RENDERER_REVERB_MC /* Eri: Enable reverb for TD renderer for 5.1 and 7.1 with headtracking enabled for IVAS_dec */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_rend/ivas_binauralRenderer.c b/lib_rend/ivas_binauralRenderer.c index d0eaa6407c..7faea2640c 100644 --- a/lib_rend/ivas_binauralRenderer.c +++ b/lib_rend/ivas_binauralRenderer.c @@ -929,7 +929,18 @@ void ivas_binaural_add_LFE( if ( render_lfe ) { #ifdef FIX_197_CREND_INTERFACE +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) + { + gain = GAIN_LFE; + } + else + { + gain = ( ( st_ivas->hCrendWrapper != NULL ) && ( st_ivas->hCrendWrapper->hHrtfCrend != NULL ) ) ? st_ivas->hCrendWrapper->hHrtfCrend->gain_lfe : GAIN_LFE; + } +#else gain = ( ( st_ivas->hCrendWrapper != NULL ) && ( st_ivas->hCrendWrapper->hHrtfCrend != NULL ) ) ? st_ivas->hCrendWrapper->hHrtfCrend->gain_lfe : GAIN_LFE; +#endif #else gain = st_ivas->hHrtf != NULL ? st_ivas->hHrtf->gain_lfe : GAIN_LFE; #endif diff --git a/lib_rend/ivas_output_init.c b/lib_rend/ivas_output_init.c index 2dfaa6da68..8fbd024f21 100644 --- a/lib_rend/ivas_output_init.c +++ b/lib_rend/ivas_output_init.c @@ -434,7 +434,19 @@ void ivas_renderer_select( } else /* AUDIO_CONFIG_BINAURAL_ROOM */ { +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC +#ifdef DEBUGGING + if ( ( ( ( st_ivas->transport_config == AUDIO_CONFIG_5_1 || st_ivas->transport_config == AUDIO_CONFIG_7_1 ) && st_ivas->hDecoderConfig->Opt_Headrotation && st_ivas->hRenderConfig->roomAcoustics.use_brir == 0 ) || ( st_ivas->hDecoderConfig->force_rend == FORCE_TD_RENDERER ) ) && ( st_ivas->mc_mode == MC_MODE_MCT ) && !( st_ivas->hDecoderConfig->force_rend == FORCE_CLDFB_RENDERER ) ) +#else + if ( ( st_ivas->transport_config == AUDIO_CONFIG_5_1 || st_ivas->transport_config == AUDIO_CONFIG_7_1 ) && st_ivas->hDecoderConfig->Opt_Headrotation && st_ivas->hRenderConfig->roomAcoustics.use_brir == 0 && ( st_ivas->mc_mode == MC_MODE_MCT ) ) +#endif + { + *renderer_type = RENDERER_BINAURAL_OBJECTS_TD; + } + else if ( st_ivas->mc_mode == MC_MODE_MCT ) +#else if ( st_ivas->mc_mode == MC_MODE_MCT ) +#endif { *renderer_type = RENDERER_BINAURAL_MIXER_CONV_ROOM; } -- GitLab From 4c8ee1091a3eabd6b13db824b1cc6bf16c96e990 Mon Sep 17 00:00:00 2001 From: Charles Kinuthia Date: Thu, 2 Feb 2023 09:38:54 +0100 Subject: [PATCH 2/4] fix memory error for TD renderer with reverb and headtracking enabled --- lib_com/ivas_prot.h | 5 ++ lib_dec/ivas_init_dec.c | 4 ++ lib_dec/ivas_ism_param_dec.c | 4 ++ lib_dec/ivas_mct_dec.c | 4 ++ lib_dec/ivas_sba_dec.c | 4 ++ lib_rend/ivas_crend.c | 89 +++++++++++++++++++------------ lib_rend/ivas_lib_rend_internal.h | 5 ++ lib_rend/lib_rend.c | 17 ++++++ 8 files changed, 99 insertions(+), 33 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 6f4d27d5e8..48c82681c0 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5447,7 +5447,12 @@ void ivas_rend_closeCrend( #else ivas_error ivas_rend_closeCrend( #endif +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + CREND_WRAPPER_HANDLE *pCrend, + RENDERER_TYPE *renderer_type ); +#else CREND_WRAPPER_HANDLE *pCrend ); +#endif ivas_error ivas_rend_crendProcess( const CREND_WRAPPER *pCrend, diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 763c83dc39..6eccdc9cde 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1707,7 +1707,11 @@ void ivas_destroy_dec( /* Crend handle */ #ifdef FIX_197_CREND_INTERFACE +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ), &st_ivas->renderer_type ); +#else ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) ); +#endif #else ivas_crend_close( st_ivas ); #endif diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 2b6d0b6876..4c8a8e6a44 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -1155,7 +1155,11 @@ static ivas_error ivas_ism_bitrate_switching( /* close the crend binaural renderer */ #ifdef FIX_197_CREND_INTERFACE +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ), &st_ivas->renderer_type ); +#else ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) ); +#endif #else ivas_crend_close( st_ivas ); diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 7b2fa2982c..3f5a8236d4 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -1041,7 +1041,11 @@ static ivas_error ivas_mc_dec_reconfig( #endif { #ifdef FIX_197_CREND_INTERFACE +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ), &st_ivas->renderer_type ); +#else ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) ); +#endif #else ivas_crend_close( st_ivas ); #endif diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index fbdc4f5857..0c94146d49 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -170,7 +170,11 @@ ivas_error ivas_sba_dec_reinit( /* Crend handle */ #ifdef FIX_197_CREND_INTERFACE +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + ivas_rend_closeCrend( &st_ivas->hCrendWrapper, &st_ivas->renderer_type ); +#else ivas_rend_closeCrend( &st_ivas->hCrendWrapper ); +#endif #else ivas_crend_close( st_ivas ); #endif diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index cf29f0c988..194439143b 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -2222,11 +2222,21 @@ ivas_error ivas_rend_openCrend( #ifdef FIX_197_CREND_INTERFACE void ivas_rend_closeCrend( +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + CREND_WRAPPER_HANDLE *pCrend, + RENDERER_TYPE *renderer_type ) +#else CREND_WRAPPER_HANDLE *pCrend ) +#endif #else ivas_error ivas_rend_closeCrend( +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + CREND_WRAPPERE *pCrend, + RENDERER_TYPE *renderer_type ) +#else CREND_WRAPPER *pCrend ) #endif +#endif { int16_t i; @@ -2241,7 +2251,11 @@ ivas_error ivas_rend_closeCrend( return; } +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + if ( ( *pCrend )->hHrtfCrend != NULL && ( renderer_type == NULL || *renderer_type != RENDERER_BINAURAL_OBJECTS_TD ) ) +#else if ( ( *pCrend )->hHrtfCrend != NULL ) +#endif { ivas_hrtf_close( &( *pCrend )->hHrtfCrend ); } @@ -2249,52 +2263,61 @@ ivas_error ivas_rend_closeCrend( if ( ( *pCrend )->hCrend != NULL ) { - for ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + if ( renderer_type == NULL || *renderer_type != RENDERER_BINAURAL_OBJECTS_TD ) { - if ( ( *pCrend )->hCrend->freq_buffer_re[i] != NULL ) +#endif + + for ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) { - free( ( *pCrend )->hCrend->freq_buffer_re[i] ); - ( *pCrend )->hCrend->freq_buffer_re[i] = NULL; + if ( ( *pCrend )->hCrend->freq_buffer_re[i] != NULL ) + { + free( ( *pCrend )->hCrend->freq_buffer_re[i] ); + ( *pCrend )->hCrend->freq_buffer_re[i] = NULL; + } + if ( ( *pCrend )->hCrend->freq_buffer_im[i] != NULL ) + { + free( ( *pCrend )->hCrend->freq_buffer_im[i] ); + ( *pCrend )->hCrend->freq_buffer_im[i] = NULL; + } } - if ( ( *pCrend )->hCrend->freq_buffer_im[i] != NULL ) + + for ( i = 0; i < BINAURAL_CHANNELS; i++ ) { - free( ( *pCrend )->hCrend->freq_buffer_im[i] ); - ( *pCrend )->hCrend->freq_buffer_im[i] = NULL; + if ( ( *pCrend )->hCrend->prev_out_buffer[i] != NULL ) + { + free( ( *pCrend )->hCrend->prev_out_buffer[i] ); + ( *pCrend )->hCrend->prev_out_buffer[i] = NULL; + } } - } - for ( i = 0; i < BINAURAL_CHANNELS; i++ ) - { - if ( ( *pCrend )->hCrend->prev_out_buffer[i] != NULL ) + if ( ( *pCrend )->hCrend->lfe_delay_line != NULL ) { - free( ( *pCrend )->hCrend->prev_out_buffer[i] ); - ( *pCrend )->hCrend->prev_out_buffer[i] = NULL; + free( ( *pCrend )->hCrend->lfe_delay_line ); + ( *pCrend )->hCrend->lfe_delay_line = NULL; } - } - if ( ( *pCrend )->hCrend->lfe_delay_line != NULL ) - { - free( ( *pCrend )->hCrend->lfe_delay_line ); - ( *pCrend )->hCrend->lfe_delay_line = NULL; - } + if ( ( *pCrend )->hCrend->freq_buffer_re_diffuse != NULL ) + { + free( ( *pCrend )->hCrend->freq_buffer_re_diffuse ); + ( *pCrend )->hCrend->freq_buffer_re_diffuse = NULL; + } - if ( ( *pCrend )->hCrend->freq_buffer_re_diffuse != NULL ) - { - free( ( *pCrend )->hCrend->freq_buffer_re_diffuse ); - ( *pCrend )->hCrend->freq_buffer_re_diffuse = NULL; - } + if ( ( *pCrend )->hCrend->freq_buffer_im_diffuse != NULL ) + { + free( ( *pCrend )->hCrend->freq_buffer_im_diffuse ); + ( *pCrend )->hCrend->freq_buffer_im_diffuse = NULL; + } - if ( ( *pCrend )->hCrend->freq_buffer_im_diffuse != NULL ) - { - free( ( *pCrend )->hCrend->freq_buffer_im_diffuse ); - ( *pCrend )->hCrend->freq_buffer_im_diffuse = NULL; - } + if ( ( *pCrend )->hCrend->hTrack != NULL ) + { + free( ( *pCrend )->hCrend->hTrack ); + ( *pCrend )->hCrend->hTrack = NULL; + } - if ( ( *pCrend )->hCrend->hTrack != NULL ) - { - free( ( *pCrend )->hCrend->hTrack ); - ( *pCrend )->hCrend->hTrack = NULL; +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC } +#endif ivas_reverb_close( &( *pCrend )->hCrend->hReverb ); diff --git a/lib_rend/ivas_lib_rend_internal.h b/lib_rend/ivas_lib_rend_internal.h index 4d36ecf7f0..a2d14e7acd 100644 --- a/lib_rend/ivas_lib_rend_internal.h +++ b/lib_rend/ivas_lib_rend_internal.h @@ -94,7 +94,12 @@ ivas_error ivas_rend_initCrend( const int32_t output_Fs ); ivas_error ivas_rend_closeCrend( +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + CREND_WRAPPER *pCrend, + RENDERER_TYPE *renderer_type ); +#else CREND_WRAPPER *pCrend ); +#endif ivas_error ivas_rend_crendProcess( const CREND_WRAPPER *pCrend, diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index c3b3ef07c2..0a3c6a57c1 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -1099,7 +1099,11 @@ static void clearInputIsm( if ( inputIsm->crendWrapper.hCrend != NULL ) #endif { +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + ivas_rend_closeCrend( &inputIsm->crendWrapper, NULL ); +#else ivas_rend_closeCrend( &inputIsm->crendWrapper ); +#endif } if ( inputIsm->tdRendWrapper.hBinRendererTd != NULL ) { @@ -1736,7 +1740,11 @@ static ivas_error initMcBinauralRendering( if ( inputMc->crendWrapper.hCrend != NULL ) #endif { +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + ivas_rend_closeCrend( &inputMc->crendWrapper, NULL ); +#else ivas_rend_closeCrend( &inputMc->crendWrapper ); +#endif } if ( inputMc->efapInWrapper.hEfap != NULL ) { @@ -1916,7 +1924,12 @@ static void clearInputMc( if ( inputMc->crendWrapper.hCrend != NULL ) #endif { + +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + ivas_rend_closeCrend( &inputMc->crendWrapper, NULL ); +#else ivas_rend_closeCrend( &inputMc->crendWrapper ); +#endif } if ( inputMc->tdRendWrapper.hBinRendererTd != NULL ) { @@ -2147,7 +2160,11 @@ static void clearInputSba( if ( inputSba->crendWrapper.hCrend != NULL ) #endif { +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + ivas_rend_closeCrend( &inputSba->crendWrapper, NULL ); +#else ivas_rend_closeCrend( &inputSba->crendWrapper ); +#endif } return; -- GitLab From 1d625806dccce25772dfe272db4ea8e24dac07c5 Mon Sep 17 00:00:00 2001 From: muxe6256 Date: Fri, 3 Feb 2023 15:18:56 +0100 Subject: [PATCH 3/4] Refactor fix memory uninitialised with TD renderer --- lib_com/ivas_prot.h | 10 +- lib_dec/ivas_init_dec.c | 8 +- lib_dec/ivas_ism_param_dec.c | 4 - lib_dec/ivas_mct_dec.c | 12 ++- lib_dec/ivas_sba_dec.c | 12 ++- lib_rend/ivas_crend.c | 159 +++++++++++++++++++----------- lib_rend/ivas_lib_rend_internal.h | 5 - lib_rend/lib_rend.c | 17 ---- 8 files changed, 126 insertions(+), 101 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 48c82681c0..9bf7f327c8 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5431,6 +5431,11 @@ ivas_error ivas_rend_initCrend( #endif const int32_t output_Fs ); +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC +ivas_error ivas_rend_initCrendWrapper( + CREND_WRAPPER_HANDLE *pCrend ); +#endif + ivas_error ivas_rend_openCrend( CREND_WRAPPER_HANDLE *pCrend, const IVAS_REND_AudioConfig inConfig, @@ -5447,12 +5452,7 @@ void ivas_rend_closeCrend( #else ivas_error ivas_rend_closeCrend( #endif -#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC - CREND_WRAPPER_HANDLE *pCrend, - RENDERER_TYPE *renderer_type ); -#else CREND_WRAPPER_HANDLE *pCrend ); -#endif ivas_error ivas_rend_crendProcess( const CREND_WRAPPER *pCrend, diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 6eccdc9cde..66a64e4b99 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1177,11 +1177,15 @@ ivas_error ivas_init_decoder( if ( st_ivas->hRenderConfig->roomAcoustics.late_reverb_on ) { #ifdef FIX_197_CREND_INTERFACE +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + if ( ( error = ivas_rend_initCrendWrapper( &st_ivas->hCrendWrapper ) ) != IVAS_ERR_OK ) +#else if ( ( st_ivas->hCrendWrapper = (CREND_WRAPPER_HANDLE) malloc( sizeof( CREND_WRAPPER ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Wrapper\n" ); } if ( ( st_ivas->hCrendWrapper->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) +#endif #else if ( ( st_ivas->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) #endif @@ -1707,11 +1711,7 @@ void ivas_destroy_dec( /* Crend handle */ #ifdef FIX_197_CREND_INTERFACE -#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC - ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ), &st_ivas->renderer_type ); -#else ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) ); -#endif #else ivas_crend_close( st_ivas ); #endif diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 4c8a8e6a44..2b6d0b6876 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -1155,11 +1155,7 @@ static ivas_error ivas_ism_bitrate_switching( /* close the crend binaural renderer */ #ifdef FIX_197_CREND_INTERFACE -#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC - ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ), &st_ivas->renderer_type ); -#else ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) ); -#endif #else ivas_crend_close( st_ivas ); diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 3f5a8236d4..096da5c02f 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -1041,11 +1041,7 @@ static ivas_error ivas_mc_dec_reconfig( #endif { #ifdef FIX_197_CREND_INTERFACE -#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC - ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ), &st_ivas->renderer_type ); -#else ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) ); -#endif #else ivas_crend_close( st_ivas ); #endif @@ -1115,10 +1111,18 @@ static ivas_error ivas_mc_dec_reconfig( #ifdef FIX_197_CREND_INTERFACE if ( st_ivas->hRenderConfig->roomAcoustics.late_reverb_on ) { +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + if ( ( error = ivas_rend_initCrendWrapper( &st_ivas->hCrendWrapper ) ) != IVAS_ERR_OK ) +#else if ( ( st_ivas->hCrendWrapper = (CREND_WRAPPER_HANDLE) malloc( sizeof( CREND_WRAPPER ) ) ) == NULL ) +#endif { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Wrapper\n" ); } +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + st_ivas->hCrendWrapper->hCrend = NULL; + st_ivas->hCrendWrapper->hHrtfCrend = NULL; +#endif if ( ( st_ivas->hCrendWrapper->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend\n" ); diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 0c94146d49..e13bdb832f 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -170,11 +170,7 @@ ivas_error ivas_sba_dec_reinit( /* Crend handle */ #ifdef FIX_197_CREND_INTERFACE -#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC - ivas_rend_closeCrend( &st_ivas->hCrendWrapper, &st_ivas->renderer_type ); -#else ivas_rend_closeCrend( &st_ivas->hCrendWrapper ); -#endif #else ivas_crend_close( st_ivas ); #endif @@ -478,10 +474,18 @@ ivas_error ivas_sba_dec_reinit( if ( st_ivas->hRenderConfig->roomAcoustics.late_reverb_on ) { #ifdef FIX_197_CREND_INTERFACE +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + if ( ( error = ivas_rend_initCrendWrapper( &st_ivas->hCrendWrapper ) ) != IVAS_ERR_OK ) +#else if ( ( st_ivas->hCrendWrapper = (CREND_WRAPPER_HANDLE) malloc( sizeof( CREND_WRAPPER ) ) ) == NULL ) +#endif { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CrendWrapper\n" ); } +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + st_ivas->hCrendWrapper->hCrend = NULL; + st_ivas->hCrendWrapper->hHrtfCrend = NULL; +#endif if ( ( st_ivas->hCrendWrapper->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) #else if ( ( st_ivas->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 194439143b..cb5a367f10 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -1986,6 +1986,62 @@ ivas_error ivas_rend_initCrend( return IVAS_ERR_OK; } +#ifdef FIX_197_CREND_INTERFACE +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC +/*------------------------------------------------------------------------- + * ivas_rend_initCrendWrapper() + * + * Allocate and initialize crend renderer handle + *------------------------------------------------------------------------*/ + +ivas_error ivas_rend_initCrendWrapper( + CREND_WRAPPER_HANDLE *pCrend ) +{ + int16_t i; + if ( pCrend == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for renderer handle" ); + } + if ( ( *pCrend = (CREND_WRAPPER_HANDLE) malloc( sizeof( CREND_WRAPPER ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Wrapper\n" ); + } + ( *pCrend )->binaural_latency_ns = 0; + ( *pCrend )->hCrend = NULL; + ( *pCrend )->hHrtfCrend = NULL; + + if ( ( ( *pCrend )->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for renderer handle" ); + } + + ( *pCrend )->hCrend->lfe_delay_line = NULL; + + for ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) + { + ( *pCrend )->hCrend->freq_buffer_re[i] = NULL; + ( *pCrend )->hCrend->freq_buffer_im[i] = NULL; + } + + for ( i = 0; i < BINAURAL_CHANNELS; i++ ) + { + ( *pCrend )->hCrend->prev_out_buffer[i] = NULL; + } + + ( *pCrend )->hCrend->freq_buffer_re_diffuse = NULL; + ( *pCrend )->hCrend->freq_buffer_im_diffuse = NULL; + ( *pCrend )->hCrend->hReverb = NULL; + ( *pCrend )->hCrend->delay_line_rw_index = 0; + ( *pCrend )->hCrend->diffuse_delay_line_rw_index = 0; + ( *pCrend )->hCrend->hTrack = NULL; + ( *pCrend )->hCrend->m_fYaw = 0; + ( *pCrend )->hCrend->m_fPitch = 0; + ( *pCrend )->hCrend->m_fRoll = 0; + + return IVAS_ERR_OK; +} +#endif +#endif /*------------------------------------------------------------------------- * ivas_rend_openCrend() * @@ -2017,8 +2073,14 @@ ivas_error ivas_rend_openCrend( ivas_error error; error = IVAS_ERR_OK; - #ifdef FIX_197_CREND_INTERFACE +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + if ( ( error = ivas_rend_initCrendWrapper( pCrend ) ) != IVAS_ERR_OK ) + { + return error; + } + hCrend = ( *pCrend )->hCrend; +#else if ( pCrend == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Wrapper\n" ); @@ -2034,6 +2096,7 @@ ivas_error ivas_rend_openCrend( ( *pCrend )->hCrend = NULL; ( *pCrend )->hHrtfCrend = NULL; } +#endif #endif subframe_length = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES; @@ -2064,6 +2127,8 @@ ivas_error ivas_rend_openCrend( } #endif +#ifndef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + if ( ( hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for renderer handle" ); @@ -2091,6 +2156,8 @@ ivas_error ivas_rend_openCrend( hCrend->m_fYaw = 0; hCrend->m_fPitch = 0; hCrend->m_fRoll = 0; +#endif + #ifdef FIX_197_CREND_INTERFACE hHrtf = ( *pCrend )->hHrtfCrend; @@ -2222,21 +2289,11 @@ ivas_error ivas_rend_openCrend( #ifdef FIX_197_CREND_INTERFACE void ivas_rend_closeCrend( -#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC - CREND_WRAPPER_HANDLE *pCrend, - RENDERER_TYPE *renderer_type ) -#else CREND_WRAPPER_HANDLE *pCrend ) -#endif #else ivas_error ivas_rend_closeCrend( -#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC - CREND_WRAPPERE *pCrend, - RENDERER_TYPE *renderer_type ) -#else CREND_WRAPPER *pCrend ) #endif -#endif { int16_t i; @@ -2251,73 +2308,59 @@ ivas_error ivas_rend_closeCrend( return; } -#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC - if ( ( *pCrend )->hHrtfCrend != NULL && ( renderer_type == NULL || *renderer_type != RENDERER_BINAURAL_OBJECTS_TD ) ) -#else if ( ( *pCrend )->hHrtfCrend != NULL ) -#endif { ivas_hrtf_close( &( *pCrend )->hHrtfCrend ); } if ( ( *pCrend )->hCrend != NULL ) { - -#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC - if ( renderer_type == NULL || *renderer_type != RENDERER_BINAURAL_OBJECTS_TD ) + for ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) { -#endif - - for ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) + if ( ( *pCrend )->hCrend->freq_buffer_re[i] != NULL ) { - if ( ( *pCrend )->hCrend->freq_buffer_re[i] != NULL ) - { - free( ( *pCrend )->hCrend->freq_buffer_re[i] ); - ( *pCrend )->hCrend->freq_buffer_re[i] = NULL; - } - if ( ( *pCrend )->hCrend->freq_buffer_im[i] != NULL ) - { - free( ( *pCrend )->hCrend->freq_buffer_im[i] ); - ( *pCrend )->hCrend->freq_buffer_im[i] = NULL; - } + free( ( *pCrend )->hCrend->freq_buffer_re[i] ); + ( *pCrend )->hCrend->freq_buffer_re[i] = NULL; } - - for ( i = 0; i < BINAURAL_CHANNELS; i++ ) + if ( ( *pCrend )->hCrend->freq_buffer_im[i] != NULL ) { - if ( ( *pCrend )->hCrend->prev_out_buffer[i] != NULL ) - { - free( ( *pCrend )->hCrend->prev_out_buffer[i] ); - ( *pCrend )->hCrend->prev_out_buffer[i] = NULL; - } + free( ( *pCrend )->hCrend->freq_buffer_im[i] ); + ( *pCrend )->hCrend->freq_buffer_im[i] = NULL; } + } - if ( ( *pCrend )->hCrend->lfe_delay_line != NULL ) + for ( i = 0; i < BINAURAL_CHANNELS; i++ ) + { + if ( ( *pCrend )->hCrend->prev_out_buffer[i] != NULL ) { - free( ( *pCrend )->hCrend->lfe_delay_line ); - ( *pCrend )->hCrend->lfe_delay_line = NULL; + free( ( *pCrend )->hCrend->prev_out_buffer[i] ); + ( *pCrend )->hCrend->prev_out_buffer[i] = NULL; } + } - if ( ( *pCrend )->hCrend->freq_buffer_re_diffuse != NULL ) - { - free( ( *pCrend )->hCrend->freq_buffer_re_diffuse ); - ( *pCrend )->hCrend->freq_buffer_re_diffuse = NULL; - } + if ( ( *pCrend )->hCrend->lfe_delay_line != NULL ) + { + free( ( *pCrend )->hCrend->lfe_delay_line ); + ( *pCrend )->hCrend->lfe_delay_line = NULL; + } - if ( ( *pCrend )->hCrend->freq_buffer_im_diffuse != NULL ) - { - free( ( *pCrend )->hCrend->freq_buffer_im_diffuse ); - ( *pCrend )->hCrend->freq_buffer_im_diffuse = NULL; - } + if ( ( *pCrend )->hCrend->freq_buffer_re_diffuse != NULL ) + { + free( ( *pCrend )->hCrend->freq_buffer_re_diffuse ); + ( *pCrend )->hCrend->freq_buffer_re_diffuse = NULL; + } - if ( ( *pCrend )->hCrend->hTrack != NULL ) - { - free( ( *pCrend )->hCrend->hTrack ); - ( *pCrend )->hCrend->hTrack = NULL; - } + if ( ( *pCrend )->hCrend->freq_buffer_im_diffuse != NULL ) + { + free( ( *pCrend )->hCrend->freq_buffer_im_diffuse ); + ( *pCrend )->hCrend->freq_buffer_im_diffuse = NULL; + } -#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC + if ( ( *pCrend )->hCrend->hTrack != NULL ) + { + free( ( *pCrend )->hCrend->hTrack ); + ( *pCrend )->hCrend->hTrack = NULL; } -#endif ivas_reverb_close( &( *pCrend )->hCrend->hReverb ); diff --git a/lib_rend/ivas_lib_rend_internal.h b/lib_rend/ivas_lib_rend_internal.h index a2d14e7acd..4d36ecf7f0 100644 --- a/lib_rend/ivas_lib_rend_internal.h +++ b/lib_rend/ivas_lib_rend_internal.h @@ -94,12 +94,7 @@ ivas_error ivas_rend_initCrend( const int32_t output_Fs ); ivas_error ivas_rend_closeCrend( -#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC - CREND_WRAPPER *pCrend, - RENDERER_TYPE *renderer_type ); -#else CREND_WRAPPER *pCrend ); -#endif ivas_error ivas_rend_crendProcess( const CREND_WRAPPER *pCrend, diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 0a3c6a57c1..c3b3ef07c2 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -1099,11 +1099,7 @@ static void clearInputIsm( if ( inputIsm->crendWrapper.hCrend != NULL ) #endif { -#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC - ivas_rend_closeCrend( &inputIsm->crendWrapper, NULL ); -#else ivas_rend_closeCrend( &inputIsm->crendWrapper ); -#endif } if ( inputIsm->tdRendWrapper.hBinRendererTd != NULL ) { @@ -1740,11 +1736,7 @@ static ivas_error initMcBinauralRendering( if ( inputMc->crendWrapper.hCrend != NULL ) #endif { -#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC - ivas_rend_closeCrend( &inputMc->crendWrapper, NULL ); -#else ivas_rend_closeCrend( &inputMc->crendWrapper ); -#endif } if ( inputMc->efapInWrapper.hEfap != NULL ) { @@ -1924,12 +1916,7 @@ static void clearInputMc( if ( inputMc->crendWrapper.hCrend != NULL ) #endif { - -#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC - ivas_rend_closeCrend( &inputMc->crendWrapper, NULL ); -#else ivas_rend_closeCrend( &inputMc->crendWrapper ); -#endif } if ( inputMc->tdRendWrapper.hBinRendererTd != NULL ) { @@ -2160,11 +2147,7 @@ static void clearInputSba( if ( inputSba->crendWrapper.hCrend != NULL ) #endif { -#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC - ivas_rend_closeCrend( &inputSba->crendWrapper, NULL ); -#else ivas_rend_closeCrend( &inputSba->crendWrapper ); -#endif } return; -- GitLab From 8b47e05b6da5ca85850dab2ea94f513e48db6b22 Mon Sep 17 00:00:00 2001 From: muxe6256 Date: Fri, 17 Feb 2023 16:04:24 +0100 Subject: [PATCH 4/4] add ivas_rend_initCrendWrapper api declaration --- lib_rend/ivas_prot_rend.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 7b276fc031..6c27317d83 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -507,6 +507,11 @@ ivas_error ivas_rend_closeCrend( CREND_WRAPPER *pCrend ); #endif +#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC +ivas_error ivas_rend_initCrendWrapper( + CREND_WRAPPER_HANDLE *pCrend ); +#endif + ivas_error ivas_rend_crendProcess( const CREND_WRAPPER *pCrend, const AUDIO_CONFIG inConfig, @@ -557,11 +562,6 @@ ivas_error ivas_crend_process( float output[][L_FRAME48k] /* i/o: input/output audio channels */ ); -#ifdef FIX_329_ENABLE_TD_RENDERER_REVERB_MC -ivas_error ivas_rend_initCrendWrapper( - CREND_WRAPPER_HANDLE *pCrend ); -#endif - /*----------------------------------------------------------------------------------* * Reverberator *----------------------------------------------------------------------------------*/ -- GitLab