From 39d594ce32cb79f9d4854eb5b2546c5c30a43432 Mon Sep 17 00:00:00 2001 From: muxe6256 Date: Sun, 15 Jan 2023 22:55:02 +0100 Subject: [PATCH 1/8] fix 197 Merge crend api. Version tested --- lib_com/ivas_prot.h | 54 + lib_com/options.h | 1 + lib_dec/ivas_dec.c | 8 + lib_dec/ivas_init_dec.c | 30 + lib_dec/ivas_ism_param_dec.c | 8 + lib_dec/ivas_mct_dec.c | 34 + lib_dec/ivas_sba_dec.c | 16 + lib_dec/ivas_stat_dec.h | 18 +- lib_rend/ivas_binauralRenderer.c | 4 + lib_rend/ivas_crend.c | 213 +++- lib_rend/ivas_lib_rend_internal.h | 6 + lib_rend/ivas_objectRenderer.c | 8 + lib_rend/ivas_stat_rend.h | 952 ++++++++++++++++++ lib_rend/lib_rend.c | 199 +++- lib_rend/lib_rend.h | 19 +- .../unit_tests/crend/ivas_crend_utest_utils.c | 69 +- 16 files changed, 1627 insertions(+), 12 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index eb14bfdc43..6c95f13fe2 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -40,6 +40,9 @@ #include "stat_enc.h" #include "stat_dec.h" #include "stat_com.h" +#ifdef FIX_197_CREND_INTERFACE +#include "ivas_stat_rend.h" +#endif #include "ivas_stat_enc.h" #include "ivas_stat_dec.h" #include "ivas_stat_com.h" @@ -5334,6 +5337,7 @@ int16_t ivas_get_num_bands_from_bw_idx( /*----------------------------------------------------------------------------------* * Crend renderer *----------------------------------------------------------------------------------*/ +#ifndef FIX_197_CREND_INTERFACE ivas_error ivas_crend_init_from_rom( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ @@ -5352,6 +5356,56 @@ ivas_error ivas_crend_process( float output[][L_FRAME48k] /* i/o: input/output audio channels */ ); +#else + +IVAS_REND_AudioConfigType getAudioConfigType( + const IVAS_REND_AudioConfig config ); + +ivas_error getAudioConfigNumChannels( + const IVAS_REND_AudioConfig config, + int16_t *numChannels ); + +IVAS_REND_AudioConfig getRendAudioConfigFromIvasAudioConfig( + AUDIO_CONFIG config ); + +ivas_error ivas_rend_openCrend( + CREND_WRAPPER_HANDLE *pCrend, + const IVAS_REND_AudioConfig inConfig, + const IVAS_REND_AudioConfig outConfig, + RENDER_CONFIG_DATA *hRendCfg, + int16_t Opt_Headrotation, + const int32_t output_Fs ); + +ivas_error ivas_rend_initCrend( + CREND_WRAPPER *pCrend, + const IVAS_REND_AudioConfig inConfig, + const IVAS_REND_AudioConfig outConfig, + RENDER_CONFIG_DATA *hRendCfg, + const int32_t output_Fs ); + +ivas_error ivas_rend_closeCrend( + CREND_WRAPPER_HANDLE *pCrend ); + +ivas_error ivas_rend_crendProcess( + const CREND_WRAPPER *pCrend, + const IVAS_REND_AudioConfig inConfig, + const IVAS_REND_AudioConfig outConfig, + DECODER_CONFIG_HANDLE hDecoderConfig, + HEAD_TRACK_DATA_HANDLE hHeadTrackData, + IVAS_OUTPUT_SETUP_HANDLE hIntSetup, + EFAP_HANDLE hEFAPdata, + float output[][L_FRAME48k], /* i/o: input/output audio channels */ + const int32_t output_Fs ); + +ivas_error ivas_rend_crendConvolver( + const CREND_WRAPPER *pCrend, + const IVAS_REND_AudioConfig inConfig, + const IVAS_REND_AudioConfig outConfig, + float pcm_in[][L_FRAME48k], + float pcm_out[][L_FRAME48k], + const int32_t output_Fs, + const int16_t i_ts ); +#endif /*----------------------------------------------------------------------------------* * Renderer configuration diff --git a/lib_com/options.h b/lib_com/options.h index bea3e2670e..5b612b02ba 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -152,6 +152,7 @@ #define ENV_STAB_FIX /* Contribution 23: HQ envelope stability memory fix */ #define STABILIZE_GIPD /* FhG: Contribution 22: gIPD stabilization */ +#define FIX_197_CREND_INTERFACE /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ #endif diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index fa341b093f..c9c2e309ff 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -207,7 +207,11 @@ ivas_error ivas_dec( } else if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) { +#ifdef FIX_197_CREND_INTERFACE + ivas_rend_crendProcess( st_ivas->hCrendWrapper, IVAS_REND_AUDIO_CONFIG_7_1_4, IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM, st_ivas->hDecoderConfig, st_ivas->hHeadTrackData, &st_ivas->hIntSetup, NULL, output, output_Fs ); +#else ivas_crend_process( st_ivas, output ); +#endif ivas_binaural_add_LFE( st_ivas, output_frame, output ); } #ifdef DEBUGGING @@ -389,7 +393,11 @@ ivas_error ivas_dec( /* Rendering */ if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) { +#ifdef FIX_197_CREND_INTERFACE + ivas_rend_crendProcess( st_ivas->hCrendWrapper, getRendAudioConfigFromIvasAudioConfig( st_ivas->intern_config ), getRendAudioConfigFromIvasAudioConfig( st_ivas->hOutSetup.output_config ), st_ivas->hDecoderConfig, st_ivas->hHeadTrackData, &st_ivas->hIntSetup, st_ivas->hEFAPdata, output, output_Fs ); +#else ivas_crend_process( st_ivas, output ); +#endif ivas_binaural_add_LFE( st_ivas, output_frame, output ); } else if ( st_ivas->renderer_type == RENDERER_MC ) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 595b362223..61171b1a89 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1145,7 +1145,15 @@ ivas_error ivas_init_decoder( if ( st_ivas->hRenderConfig->roomAcoustics.late_reverb_on ) { +#ifdef FIX_197_CREND_INTERFACE + if ( ( st_ivas->hCrendWrapper = (CREND_WRAPPER_HANDLE) malloc( sizeof( CREND_WRAPPER ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR Crend Wrapper\n" ); + } + if ( ( st_ivas->hCrendWrapper->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) +#else if ( ( st_ivas->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) +#endif { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR Crend\n" ); } @@ -1167,10 +1175,24 @@ ivas_error ivas_init_decoder( } else if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) { +#ifdef FIX_197_CREND_INTERFACE + if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM && st_ivas->ivas_format == MC_FORMAT && st_ivas->hDecoderConfig->Opt_Headrotation ) + { + if ( ( error = efap_init_data( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth, st_ivas->hIntSetup.ls_elevation, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + { + return error; + } + } + if ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), getRendAudioConfigFromIvasAudioConfig( st_ivas->intern_config ), getRendAudioConfigFromIvasAudioConfig( st_ivas->hDecoderConfig->output_config ), st_ivas->hRenderConfig, st_ivas->hDecoderConfig->Opt_Headrotation, st_ivas->hDecoderConfig->output_Fs ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ivas_crend_open( st_ivas ) != IVAS_ERR_OK ) { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "ivas_crend_open failed" ); } +#endif } if ( st_ivas->ivas_format == ISM_FORMAT && @@ -1474,8 +1496,12 @@ void ivas_initialize_handles_dec( st_ivas->hIsmRendererData = NULL; st_ivas->hBinRendererTd = NULL; st_ivas->hMonoDmxRenderer = NULL; +#ifdef FIX_197_CREND_INTERFACE + st_ivas->hCrendWrapper = NULL; +#else st_ivas->hCrend = NULL; st_ivas->hHrtf = NULL; +#endif st_ivas->hoa_dec_mtx = NULL; st_ivas->hHeadTrackData = NULL; @@ -1630,7 +1656,11 @@ void ivas_destroy_dec( ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); /* Crend handle */ +#ifdef FIX_197_CREND_INTERFACE + ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) ); +#else ivas_crend_close( st_ivas ); +#endif /* LS config converter handle */ ivas_ls_setup_conversion_close( &st_ivas->hLsSetUpConversion ); diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 63cbbd91ad..2ad266ee9c 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -1085,7 +1085,11 @@ static ivas_error ivas_ism_bitrate_switching( ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); /* Open Crend Binaural renderer */ +#ifdef FIX_197_CREND_INTERFACE + ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), getRendAudioConfigFromIvasAudioConfig( st_ivas->intern_config ), getRendAudioConfigFromIvasAudioConfig( st_ivas->hOutSetup.output_config ), st_ivas->hRenderConfig, st_ivas->hDecoderConfig->Opt_Headrotation, st_ivas->hDecoderConfig->output_Fs ); +#else ivas_crend_open( st_ivas ); +#endif } } @@ -1128,12 +1132,16 @@ static ivas_error ivas_ism_bitrate_switching( ivas_dirac_dec_init_binaural_data( st_ivas ); /* close the crend binaural renderer */ +#ifdef FIX_197_CREND_INTERFACE + ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) ); +#else ivas_crend_close( st_ivas ); if ( st_ivas->hHrtf != NULL ) { st_ivas->hHrtf = NULL; } +#endif } } diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 14c8cc3be1..75ecc6f923 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -1034,9 +1034,17 @@ static ivas_error ivas_mc_dec_reconfig( ivas_binRenderer_close( &st_ivas->hBinRenderer ); } +#ifdef FIX_197_CREND_INTERFACE + if ( ( st_ivas->hCrendWrapper != NULL ) && ( st_ivas->hCrendWrapper->hCrend != NULL ) && ( st_ivas->renderer_type != RENDERER_BINAURAL_MIXER_CONV && st_ivas->renderer_type != RENDERER_BINAURAL_MIXER_CONV_ROOM && ( st_ivas->renderer_type != RENDERER_BINAURAL_OBJECTS_TD || st_ivas->hRenderConfig->roomAcoustics.late_reverb_on == 0 ) ) ) +#else if ( st_ivas->hCrend != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_MIXER_CONV && st_ivas->renderer_type != RENDERER_BINAURAL_MIXER_CONV_ROOM && ( st_ivas->renderer_type != RENDERER_BINAURAL_OBJECTS_TD || st_ivas->hRenderConfig->roomAcoustics.late_reverb_on == 0 ) ) ) +#endif { +#ifdef FIX_197_CREND_INTERFACE + ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) ); +#else ivas_crend_close( st_ivas ); +#endif } if ( st_ivas->hBinRendererTd != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_OBJECTS_TD ) ) @@ -1084,6 +1092,19 @@ static ivas_error ivas_mc_dec_reconfig( return error; } +#ifdef FIX_197_CREND_INTERFACE + if ( st_ivas->hRenderConfig->roomAcoustics.late_reverb_on ) + { + if ( ( st_ivas->hCrendWrapper = (CREND_WRAPPER_HANDLE) malloc( sizeof( CREND_WRAPPER ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR Crend Wrapper\n" ); + } + if ( ( st_ivas->hCrendWrapper->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR Crend\n" ); + } + } +#else if ( st_ivas->hCrend == NULL && st_ivas->hRenderConfig->roomAcoustics.late_reverb_on ) { if ( ( st_ivas->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) @@ -1091,6 +1112,17 @@ static ivas_error ivas_mc_dec_reconfig( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR Crend\n" ); } } +#endif + } +#ifdef FIX_197_CREND_INTERFACE + else if ( st_ivas->hCrendWrapper == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) + { + if ( ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), getRendAudioConfigFromIvasAudioConfig( st_ivas->intern_config ), getRendAudioConfigFromIvasAudioConfig( st_ivas->hDecoderConfig->output_config ), st_ivas->hRenderConfig, st_ivas->hDecoderConfig->Opt_Headrotation, st_ivas->hDecoderConfig->output_Fs ) != IVAS_ERR_OK ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "ivas_crend_open failed" ); + } + } +#else } else if ( st_ivas->hCrend == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) { @@ -1099,6 +1131,8 @@ static ivas_error ivas_mc_dec_reconfig( return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "ivas_crend_open failed" ); } } + + #endif } /* mono/stereo */ else if ( output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO ) diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 82123af232..09060dc23b 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -169,7 +169,11 @@ ivas_error ivas_sba_dec_reinit( ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); /* Crend handle */ +#ifdef FIX_197_CREND_INTERFACE + ivas_rend_closeCrend( &st_ivas->hCrendWrapper ); +#else ivas_crend_close( st_ivas ); +#endif /* LS config converter handle */ ivas_ls_setup_conversion_close( &st_ivas->hLsSetUpConversion ); @@ -461,7 +465,15 @@ ivas_error ivas_sba_dec_reinit( if ( st_ivas->hRenderConfig->roomAcoustics.late_reverb_on ) { +#ifdef FIX_197_CREND_INTERFACE + if ( ( st_ivas->hCrendWrapper = (CREND_WRAPPER_HANDLE) malloc( sizeof( CREND_WRAPPER ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR CrendWrapper\n" ); + } + if ( ( st_ivas->hCrendWrapper->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) +#else if ( ( st_ivas->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) +#endif { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR Crend\n" ); } @@ -483,7 +495,11 @@ ivas_error ivas_sba_dec_reinit( } else if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) { +#ifdef FIX_197_CREND_INTERFACE + if ( ivas_rend_openCrend( &st_ivas->hCrendWrapper, getRendAudioConfigFromIvasAudioConfig( st_ivas->intern_config ), getRendAudioConfigFromIvasAudioConfig( st_ivas->hDecoderConfig->output_config ), st_ivas->hRenderConfig, st_ivas->hDecoderConfig->Opt_Headrotation, st_ivas->hDecoderConfig->output_Fs ) != IVAS_ERR_OK ) +#else if ( ivas_crend_open( st_ivas ) != IVAS_ERR_OK ) +#endif { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "ivas_crend_open failed" ); } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index c09629466d..4fceaf79f6 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -40,8 +40,11 @@ #include "ivas_cnst.h" #include "ivas_stat_com.h" #include "ivas_stat_rend.h" +#ifndef FIX_197_CREND_INTERFACE #include "common_api_types.h" // VE2AT: don't we want to avoid this include in the library? I admit that the rules hefre are not 100% clear to me but introducing it just for IVAS_QUATERNION is not necessry I think +#endif +#ifndef FIX_197_CREND_INTERFACE /*----------------------------------------------------------------------------------* * Output configuration for renderer (e.g. DirAC, MASA, Binaural Renderer...) @@ -66,7 +69,7 @@ typedef struct ivas_output_setup_structure } IVAS_OUTPUT_SETUP, *IVAS_OUTPUT_SETUP_HANDLE; - +#endif /*----------------------------------------------------------------------------------* * DFT Stereo decoder structure *----------------------------------------------------------------------------------*/ @@ -817,6 +820,7 @@ typedef struct ivas_spar_md_dec_state_t int16_t spar_hoa_md_flag; } ivas_spar_md_dec_state_t; +#ifndef FIX_197_CREND_INTERFACE /* AGC structure */ typedef struct ivas_agc_dec_chan_state_t @@ -856,6 +860,8 @@ typedef struct ivas_td_decorr_state_t } ivas_td_decorr_state_t; +#endif + /* PCA structure */ typedef struct { @@ -987,6 +993,7 @@ typedef struct mct_dec_data_structure } MCT_DEC_DATA, *MCT_DEC_HANDLE; +#ifndef FIX_197_CREND_INTERFACE /*----------------------------------------------------------------------------------* * EFAP structures @@ -1120,7 +1127,7 @@ typedef struct renderer_struct } ISM_RENDERER_DATA, *ISM_RENDERER_HANDLE; - +#endif /*----------------------------------------------------------------------------------* * MASA decoder structures *----------------------------------------------------------------------------------*/ @@ -1175,6 +1182,7 @@ typedef struct ivas_masa_decoder_struct } MASA_DECODER, *MASA_DECODER_HANDLE; +#ifndef FIX_197_CREND_INTERFACE /*----------------------------------------------------------------------------------* * Binaural Rendering structure @@ -1815,7 +1823,7 @@ typedef struct decoder_config_structure } DECODER_CONFIG, *DECODER_CONFIG_HANDLE; - +#endif /*----------------------------------------------------------------------------------* * * Main IVAS decoder structure @@ -1889,8 +1897,12 @@ typedef struct Decoder_Struct EFAP_HANDLE hEFAPdata; /* EFAP structure */ VBAP_HANDLE hVBAPdata; /* VBAP structure */ MONO_DOWNMIX_RENDERER_HANDLE hMonoDmxRenderer; /* Mono downmix structure */ +#ifdef FIX_197_CREND_INTERFACE + CREND_WRAPPER_HANDLE hCrendWrapper; +#else CREND_HANDLE hCrend; /* Convolution mixer renderer structure */ HRTFS_HANDLE hHrtf; /* HRTFs handle */ +#endif LSSETUP_CUSTOM_HANDLE hLsSetupCustom; /* Custom LS configuration handle */ float *hoa_dec_mtx; /* Pointer to decoder matrix for SBA */ HEAD_TRACK_DATA_HANDLE hHeadTrackData; /* Head tracking data structure */ diff --git a/lib_rend/ivas_binauralRenderer.c b/lib_rend/ivas_binauralRenderer.c index be2a8193c8..ed98cb764a 100644 --- a/lib_rend/ivas_binauralRenderer.c +++ b/lib_rend/ivas_binauralRenderer.c @@ -791,7 +791,11 @@ void ivas_binaural_add_LFE( if ( render_lfe ) { +#ifdef FIX_197_CREND_INTERFACE + gain = ( st_ivas->hCrendWrapper != NULL ) && ( st_ivas->hCrendWrapper->hHrtfCrend != NULL ) ? st_ivas->hCrendWrapper->hHrtfCrend->gain_lfe : GAIN_LFE; +#else gain = st_ivas->hHrtf != NULL ? st_ivas->hHrtf->gain_lfe : GAIN_LFE; +#endif for ( idx_lfe = 0; idx_lfe < st_ivas->hIntSetup.num_lfe; idx_lfe++ ) { v_multc( output_f[st_ivas->hIntSetup.index_lfe[idx_lfe]], gain, output_f[st_ivas->hIntSetup.index_lfe[idx_lfe]], output_frame ); diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 41c60261f7..cf1d0ea098 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -39,8 +39,13 @@ #include "ivas_stat_dec.h" #include #include "ivas_rom_binaural_crend_head.h" +#ifdef FIX_197_CREND_INTERFACE +#include "ivas_stat_rend.h" +#include "lib_rend.h" +#else #include "lib_rend.h" #include "ivas_lib_rend_internal.h" +#endif #ifdef DEBUGGING #include "debug.h" #endif @@ -163,7 +168,12 @@ ivas_error ivas_crend_init_from_rom( AUDIO_CONFIG intern_config; HRTFS_HANDLE hHrtf; +#ifdef FIX_197_CREND_INTERFACE + hHrtf = st_ivas->hCrendWrapper->hHrtfCrend; +#else hHrtf = st_ivas->hHrtf; +#endif + output_Fs = st_ivas->hDecoderConfig->output_Fs; intern_config = st_ivas->intern_config; @@ -635,12 +645,16 @@ ivas_error ivas_crend_init_from_rom( return IVAS_ERROR( IVAS_ERR_INTERNAL, "Unsupported renderer type in Crend" ); } +#ifdef FIX_197_CREND_INTERFACE + st_ivas->hCrendWrapper->hHrtfCrend = hHrtf; +#else st_ivas->hHrtf = hHrtf; +#endif return IVAS_ERR_OK; } - +#ifndef FIX_197_CREND_INTERFACE /*------------------------------------------------------------------------- * ivas_crend_open() * @@ -803,7 +817,9 @@ ivas_error ivas_crend_open( return error; } +#endif +#ifndef FIX_197_CREND_INTERFACE /*------------------------------------------------------------------------- * ivas_crend_close() @@ -882,7 +898,9 @@ ivas_error ivas_crend_close( return IVAS_ERR_OK; } +#endif +#ifndef FIX_197_CREND_INTERFACE /*-----------------------------------------------------------------------------------------* * Function ivas_crend_convolver() @@ -1020,7 +1038,9 @@ static ivas_error ivas_crend_convolver( return IVAS_ERR_OK; } +#endif +#ifndef FIX_197_CREND_INTERFACE /*-----------------------------------------------------------------------------------------* * Function ivas_crend_process() @@ -1121,7 +1141,7 @@ ivas_error ivas_crend_process( return IVAS_ERR_OK; } - +#endif /*------------------------------------------------------------------------- * ivas_rend_openCrend() @@ -1130,10 +1150,17 @@ ivas_error ivas_crend_process( *------------------------------------------------------------------------*/ ivas_error ivas_rend_openCrend( +#ifdef FIX_197_CREND_INTERFACE + CREND_WRAPPER_HANDLE *pCrend, +#else CREND_WRAPPER *pCrend, +#endif const IVAS_REND_AudioConfig inConfig, const IVAS_REND_AudioConfig outConfig, RENDER_CONFIG_DATA *hRendCfg, +#ifdef FIX_197_CREND_INTERFACE + int16_t Opt_Headrotation, +#endif const int32_t output_Fs ) { /* TODO tmu : Based on ivas_crend_open() - could be harmonized / refactored */ @@ -1144,8 +1171,36 @@ ivas_error ivas_rend_openCrend( ivas_error error; error = IVAS_ERR_OK; + +#ifdef FIX_197_CREND_INTERFACE + if ( pCrend == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR Crend Wrapper\n" ); + } + + if ( *pCrend == NULL ) + { + if ( ( *pCrend = (CREND_WRAPPER_HANDLE) malloc( sizeof( CREND_WRAPPER ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR Crend Wrapper\n" ); + } + ( *pCrend )->binaural_latency_ns = 0; + ( *pCrend )->hCrend = NULL; + ( *pCrend )->hHrtfCrend = NULL; + } +#endif + subframe_length = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES; +#ifdef FIX_197_CREND_INTERFACE + if ( ( *pCrend )->hHrtfCrend == NULL ) + { + if ( ( error = ivas_rend_initCrend( *pCrend, inConfig, outConfig, hRendCfg, output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#else if ( pCrend->hHrtfCrend == NULL ) { if ( ( error = ivas_rend_initCrend( pCrend, inConfig, outConfig, hRendCfg, output_Fs ) ) != IVAS_ERR_OK ) @@ -1153,6 +1208,7 @@ ivas_error ivas_rend_openCrend( return error; } } +#endif if ( ( hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) { @@ -1182,7 +1238,11 @@ ivas_error ivas_rend_openCrend( hCrend->m_fPitch = 0; hCrend->m_fRoll = 0; +#ifdef FIX_197_CREND_INTERFACE + hHrtf = ( *pCrend )->hHrtfCrend; +#else hHrtf = pCrend->hHrtfCrend; +#endif if ( hHrtf != NULL ) { @@ -1247,8 +1307,11 @@ ivas_error ivas_rend_openCrend( { hCrend->lfe_delay_line = NULL; } - +#ifdef FIX_197_CREND_INTERFACE + if ( Opt_Headrotation ) +#else if ( false ) /* TODO tmu : check renderer headrotation flag */ +#endif { if ( ( hCrend->hTrack = (ivas_orient_trk_state_t *) malloc( sizeof( ivas_orient_trk_state_t ) ) ) == NULL ) { @@ -1266,7 +1329,11 @@ ivas_error ivas_rend_openCrend( { if ( ( error = ivas_reverb_open( &( hCrend->hReverb ), getIvasAudioConfigFromRendAudioConfig( inConfig ), +#ifdef FIX_197_CREND_INTERFACE + ( *pCrend )->hHrtfCrend, +#else pCrend->hHrtfCrend, +#endif hRendCfg, output_Fs ) ) != IVAS_ERR_OK ) { @@ -1278,10 +1345,18 @@ ivas_error ivas_rend_openCrend( hCrend->hReverb = NULL; } +#ifdef FIX_197_CREND_INTERFACE + ( *pCrend )->binaural_latency_ns = (int32_t) ( ( *pCrend )->hHrtfCrend->latency_s * 1000000000.f ); +#else pCrend->binaural_latency_ns = (int32_t) ( pCrend->hHrtfCrend->latency_s * 1000000000.f ); +#endif } +#ifdef FIX_197_CREND_INTERFACE + ( *pCrend )->hCrend = hCrend; +#else pCrend->hCrend = hCrend; +#endif return IVAS_ERR_OK; } @@ -1679,10 +1754,88 @@ ivas_error ivas_rend_initCrend( *------------------------------------------------------------------------*/ ivas_error ivas_rend_closeCrend( +#ifdef FIX_197_CREND_INTERFACE + CREND_WRAPPER_HANDLE *pCrend ) +#else CREND_WRAPPER *pCrend ) +#endif { int16_t i; +#ifdef FIX_197_CREND_INTERFACE + if ( pCrend == NULL ) + { + return IVAS_ERR_OK; + } + + if ( *pCrend == NULL ) + { + return IVAS_ERR_OK; + } + + if ( ( *pCrend )->hHrtfCrend != NULL ) + { + ivas_hrtf_close( &( *pCrend )->hHrtfCrend ); + } + + if ( ( *pCrend )->hCrend != NULL ) + { + + for ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) + { + 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; + } + } + + for ( i = 0; i < BINAURAL_CHANNELS; i++ ) + { + if ( ( *pCrend )->hCrend->prev_out_buffer[i] != NULL ) + { + free( ( *pCrend )->hCrend->prev_out_buffer[i] ); + ( *pCrend )->hCrend->prev_out_buffer[i] = 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_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; + } + + ivas_reverb_close( &( *pCrend )->hCrend->hReverb ); + + free( ( *pCrend )->hCrend ); + ( *pCrend )->hCrend = NULL; + free( *pCrend ); + *pCrend = NULL; + } +#else if ( pCrend->hHrtfCrend != NULL ) { ivas_hrtf_close( &pCrend->hHrtfCrend ); @@ -1743,7 +1896,7 @@ ivas_error ivas_rend_closeCrend( free( pCrend->hCrend ); pCrend->hCrend = NULL; } - +#endif return IVAS_ERR_OK; } @@ -1757,10 +1910,20 @@ ivas_error ivas_rend_crendProcess( const CREND_WRAPPER *pCrend, const IVAS_REND_AudioConfig inConfig, const IVAS_REND_AudioConfig outConfig, +#ifdef FIX_197_CREND_INTERFACE + DECODER_CONFIG_HANDLE hDecoderConfig, + HEAD_TRACK_DATA_HANDLE hHeadTrackData, + IVAS_OUTPUT_SETUP_HANDLE hIntSetup, + EFAP_HANDLE hEFAPdata, +#endif float output[][L_FRAME48k], /* i/o: input/output audio channels */ const int32_t output_Fs ) { +#ifdef FIX_197_CREND_INTERFACE + int16_t i, subframe_idx, output_frame, subframe_len; +#else int16_t i, subframe_idx, output_frame; +#endif int16_t nchan_out; float pcm_tmp[BINAURAL_CHANNELS][L_FRAME48k]; AUDIO_CONFIG in_config; @@ -1773,9 +1936,49 @@ ivas_error ivas_rend_crendProcess( inConfigType = getAudioConfigType( inConfig ); getAudioConfigNumChannels( outConfig, &nchan_out ); output_frame = (int16_t) ( output_Fs / FRAMES_PER_SEC ); - +#ifdef FIX_197_CREND_INTERFACE + subframe_len = output_frame / MAX_PARAM_SPATIAL_SUBFRAMES; +#endif for ( subframe_idx = 0; subframe_idx < MAX_PARAM_SPATIAL_SUBFRAMES; subframe_idx++ ) { +#ifdef FIX_197_CREND_INTERFACE + if ( hDecoderConfig && hDecoderConfig->Opt_Headrotation && hHeadTrackData && hHeadTrackData->num_quaternions >= 0 ) + { + /* Orientation tracking */ + if ( pCrend->hCrend->hTrack != NULL ) + { + if ( hDecoderConfig->orientation_tracking == IVAS_ORIENT_TRK_AVG ) + { + ivas_orient_trk_SetTrackingType( pCrend->hCrend->hTrack, OTR_TRACKING_AVG_ORIENT ); + } + else + { + ivas_orient_trk_SetTrackingType( pCrend->hCrend->hTrack, OTR_TRACKING_REF_ORIENT ); + } + + /* get current subframe quaternion and convert to euler angles */ + Quat2Euler( hHeadTrackData->Quaternions[subframe_idx], &( pCrend->hCrend->m_fYaw ), &( pCrend->hCrend->m_fPitch ), &( pCrend->hCrend->m_fRoll ) ); + ivas_orient_trk_SetAbsoluteOrientation( pCrend->hCrend->hTrack, pCrend->hCrend->m_fYaw, pCrend->hCrend->m_fPitch, pCrend->hCrend->m_fRoll ); + ivas_orient_trk_Process( pCrend->hCrend->hTrack ); + ivas_orient_trk_GetTrackedOrientation( pCrend->hCrend->hTrack, &( pCrend->hCrend->m_fYaw ), &( pCrend->hCrend->m_fPitch ), &( pCrend->hCrend->m_fRoll ) ); + } + + /* Rotation in SHD for: + MC with elevation (5_1_2 / 5_1_4 / 7_1_4) -> BINAURAL + SBA SPAR -> BINAURAL or BINAURAL_ROOM + */ + if ( in_config == AUDIO_CONFIG_FOA || in_config == AUDIO_CONFIG_HOA2 || in_config == AUDIO_CONFIG_HOA3 ) + { + rotateFrame_shd( hHeadTrackData, output, subframe_len, *hIntSetup, subframe_idx ); + } + /* Rotation in SD for MC -> BINAURAL_ROOM */ + else if ( ( hIntSetup != NULL ) && hIntSetup->is_loudspeaker_setup ) + { + rotateFrame_sd( hHeadTrackData, output, subframe_len, *hIntSetup, hEFAPdata, subframe_idx ); + } + } +#endif + if ( ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) || ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) ) { if ( ( error = ivas_rend_crendConvolver( pCrend, inConfig, outConfig, output, pcm_tmp, output_Fs, subframe_idx ) ) != IVAS_ERR_OK ) diff --git a/lib_rend/ivas_lib_rend_internal.h b/lib_rend/ivas_lib_rend_internal.h index c779916703..3d784d9bb3 100644 --- a/lib_rend/ivas_lib_rend_internal.h +++ b/lib_rend/ivas_lib_rend_internal.h @@ -31,12 +31,17 @@ *******************************************************************************************************/ #include "ivas_error.h" +#ifdef FIX_197_CREND_INTERFACE +#include "ivas_stat_rend.h" +#else #include "lib_rend.h" +#endif #include "ivas_stat_dec.h" #ifndef IVAS_LIB_REND_INTERNALS_H #define IVAS_LIB_REND_INTERNALS_H +#ifndef FIX_197_CREND_INTERFACE typedef struct { int8_t headRotEnabled; @@ -100,6 +105,7 @@ ivas_error ivas_rend_crendConvolver( float pcm_out[][L_FRAME48k], const int32_t output_Fs, const int16_t i_ts ); +#endif ivas_error ivas_rend_TDObjRenderFrame( const TDREND_WRAPPER *pTDRend, /* i : TD Renderer wrapper structure */ diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index 3aad7fe5a0..10617d3c62 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -245,7 +245,11 @@ void ObjRenderIVASFrame( if ( st_ivas->hRenderConfig->roomAcoustics.late_reverb_on && ( st_ivas->ini_frame == 0 ) ) { +#ifdef FIX_197_CREND_INTERFACE + ivas_reverb_open( &st_ivas->hCrendWrapper->hCrend->hReverb, st_ivas->transport_config, NULL, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ); +#else ivas_reverb_open( &st_ivas->hCrend->hReverb, st_ivas->transport_config, NULL, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ); +#endif } } @@ -261,7 +265,11 @@ void ObjRenderIVASFrame( if ( ( st_ivas->hRenderConfig != NULL ) && ( st_ivas->hRenderConfig->roomAcoustics.late_reverb_on ) ) { +#ifdef FIX_197_CREND_INTERFACE + ivas_reverb_process( st_ivas->hCrendWrapper->hCrend->hReverb, st_ivas->transport_config, 0, output, reverb_signal, subframe_idx ); +#else ivas_reverb_process( st_ivas->hCrend->hReverb, st_ivas->transport_config, 0, output, reverb_signal, subframe_idx ); +#endif } /* Render subframe */ diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index a38b8d96c1..fe247287ce 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -34,10 +34,962 @@ #define IVAS_STAT_REND_H #include +#ifdef FIX_197_CREND_INTERFACE +#include "cnst.h" #include "ivas_cnst.h" +#include "ivas_stat_com.h" +#include "common_api_types.h" // VE2AT: don't we want to avoid this include in the library? I admit that the rules hefre are not 100% clear to me but introducing it just for IVAS_QUATERNION is not necessry I think +#endif #define MAX_SPEAKERS 12 /* Max number of speakers (including LFE) in a channel-based config */ + +#ifdef FIX_197_CREND_INTERFACE + +#define RENDERER_HEAD_POSITIONS_PER_FRAME 4 // todo (Marc) -> renanr IVAS_RENDERER_HEAD_POSITIONS_PER_FRAME ? + +typedef struct +{ + int16_t numSamplesPerChannel; + int16_t numChannels; +} IVAS_REND_AudioBufferConfig; + +typedef struct +{ + IVAS_REND_AudioBufferConfig config; + float *data; +} IVAS_REND_AudioBuffer; + +typedef struct +{ + IVAS_REND_AudioBufferConfig config; + const float *data; +} IVAS_REND_ReadOnlyAudioBuffer; + +typedef struct +{ + float azimuth; + float elevation; +} IVAS_REND_AudioObjectPosition; + +typedef struct IVAS_REND *IVAS_REND_HANDLE; +typedef struct IVAS_REND const *IVAS_REND_CONST_HANDLE; + +typedef enum +{ + IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED = 0, + IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS, + IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED, + IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL, + IVAS_REND_AUDIO_CONFIG_TYPE_MASA, + IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN, +} IVAS_REND_AudioConfigType; + +/* TODO(sgi): Harmonize with AUDIO_CONFIG */ +/* + Note: numerical values carry specific information here. + + MSB LSB + -------------------------------------------------------------------------------- + ... unused (assumed all 0) ... | config type (1 byte) | config variant (1 byte) | + -------------------------------------------------------------------------------- + + Where "config type" is the general type from the following list: + - unknown + - channel-based + - ambisonics + - object-based + - binaural + - MASA + + Config variants are concrete configs of each type. + */ +typedef enum +{ + IVAS_REND_AUDIO_CONFIG_MONO = IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED << 8 | 0, + IVAS_REND_AUDIO_CONFIG_STEREO = IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED << 8 | 1, + IVAS_REND_AUDIO_CONFIG_5_1 = IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED << 8 | 2, + IVAS_REND_AUDIO_CONFIG_7_1 = IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED << 8 | 3, + IVAS_REND_AUDIO_CONFIG_5_1_2 = IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED << 8 | 4, + IVAS_REND_AUDIO_CONFIG_5_1_4 = IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED << 8 | 5, + IVAS_REND_AUDIO_CONFIG_7_1_4 = IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED << 8 | 6, + IVAS_REND_AUDIO_CONFIG_LS_CUSTOM = IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED << 8 | 255, + + IVAS_REND_AUDIO_CONFIG_FOA = IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS << 8 | 0, + IVAS_REND_AUDIO_CONFIG_HOA2 = IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS << 8 | 1, + IVAS_REND_AUDIO_CONFIG_HOA3 = IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS << 8 | 2, + + IVAS_REND_AUDIO_CONFIG_OBJECT = IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED << 8 | 0, + + IVAS_REND_AUDIO_CONFIG_BINAURAL = IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL << 8 | 0, + IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM = IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL << 8 | 1, + + IVAS_REND_AUDIO_CONFIG_MASA1 = IVAS_REND_AUDIO_CONFIG_TYPE_MASA << 8 | 0, + IVAS_REND_AUDIO_CONFIG_MASA2 = IVAS_REND_AUDIO_CONFIG_TYPE_MASA << 8 | 1, + + IVAS_REND_AUDIO_CONFIG_UNKNOWN = IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN << 8 | 0, +} IVAS_REND_AudioConfig; + +typedef uint16_t IVAS_REND_InputId; + +typedef struct +{ + int16_t numLfeChannels; + float lfeOutputGains[IVAS_MAX_INPUT_LFE_CHANNELS][IVAS_MAX_OUTPUT_CHANNELS]; +} IVAS_REND_LfeRouting; + +typedef struct +{ + int8_t headRotEnabled; + IVAS_QUATERNION headPositions[RENDERER_HEAD_POSITIONS_PER_FRAME]; + float crossfade[L_FRAME48k / RENDERER_HEAD_POSITIONS_PER_FRAME]; +} IVAS_REND_HeadRotData; + +/*----------------------------------------------------------------------------------* + * Binaural Rendering structure + *----------------------------------------------------------------------------------*/ +// VE2AT: move to ivas_rom_rend.h ? +/* Binaural reverberator structure */ +typedef struct ivas_binaural_reverb_struct +{ + float *loopBufReal[CLDFB_NO_CHANNELS_MAX]; + float *loopBufImag[CLDFB_NO_CHANNELS_MAX]; + float preDelayBufferReal[REVERB_PREDELAY_MAX + 1][CLDFB_NO_CHANNELS_MAX]; + float preDelayBufferImag[REVERB_PREDELAY_MAX + 1][CLDFB_NO_CHANNELS_MAX]; + float **tapPointersReal[CLDFB_NO_CHANNELS_MAX][BINAURAL_CHANNELS]; + float **tapPointersImag[CLDFB_NO_CHANNELS_MAX][BINAURAL_CHANNELS]; + + float binauralCoherenceCrossmixGains[CLDFB_NO_CHANNELS_MAX]; + float binauralCoherenceDirectGains[CLDFB_NO_CHANNELS_MAX]; + float reverbEqGains[CLDFB_NO_CHANNELS_MAX]; + float loopAttenuationFactor[CLDFB_NO_CHANNELS_MAX]; + + float *outputBufferReal[CLDFB_NO_CHANNELS_MAX][BINAURAL_CHANNELS]; + float *outputBufferImag[CLDFB_NO_CHANNELS_MAX][BINAURAL_CHANNELS]; + + int16_t numBins; + + int16_t useBinauralCoherence; + int16_t loopBufLength[CLDFB_NO_CHANNELS_MAX]; + int16_t loopBufLengthMax[CLDFB_NO_CHANNELS_MAX]; + int16_t preDelayBufferIndex; + int16_t preDelayBufferLength; + + int16_t taps[CLDFB_NO_CHANNELS_MAX][BINAURAL_CHANNELS]; + int16_t *tapPhaseShiftType[CLDFB_NO_CHANNELS_MAX][BINAURAL_CHANNELS]; + + int16_t blockSize; + uint32_t binRend_RandNext; + int16_t highestBinauralCoherenceBin; + + float dmxmtx[BINAURAL_CHANNELS][MAX_OUTPUT_CHANNELS]; + float foa_enc[MAX_OUTPUT_CHANNELS][FOA_CHANNELS]; + +} REVERB_STRUCT, *REVERB_STRUCT_HANDLE; + +/* AGC structure */ +typedef struct ivas_agc_dec_chan_state_t +{ + float lastGain; + int16_t gainExpVal; + +} ivas_agc_dec_chan_state_t; + +typedef struct ivas_agc_dec_state_t +{ + ivas_agc_com_state_t agc_com; + ivas_agc_dec_chan_state_t *gain_state; + ivas_agc_chan_data_t *gain_data; + +} ivas_agc_dec_state_t; + +/* TD decorr */ +typedef struct ivas_td_decorr_APD_filt_state_t +{ + int16_t order[IVAS_MAX_DECORR_APD_SECTIONS]; + int16_t idx[IVAS_MAX_DECORR_APD_SECTIONS]; + float coeffs[IVAS_MAX_DECORR_APD_SECTIONS]; + float *state[IVAS_MAX_DECORR_APD_SECTIONS]; + +} ivas_td_decorr_APD_filt_state_t; + +typedef struct ivas_td_decorr_state_t +{ + ivas_trans_det_state_t *pTrans_det; + float *look_ahead_buf; + ivas_td_decorr_APD_filt_state_t APD_filt_state[IVAS_MAX_DECORR_CHS]; + + int16_t num_apd_outputs; + int16_t num_apd_sections; + int16_t ducking_flag; + +} ivas_td_decorr_state_t; + +/* Parametric binaural data structure */ +typedef struct ivas_dirac_dec_binaural_data_structure +{ + float ChEnePrev[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + float ChCrossRePrev[CLDFB_NO_CHANNELS_MAX]; + float ChCrossImPrev[CLDFB_NO_CHANNELS_MAX]; + float ChEne[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + float ChCrossRe[CLDFB_NO_CHANNELS_MAX]; + float ChCrossIm[CLDFB_NO_CHANNELS_MAX]; + float ChEneOutPrev[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + float ChCrossReOutPrev[CLDFB_NO_CHANNELS_MAX]; + float ChCrossImOutPrev[CLDFB_NO_CHANNELS_MAX]; + float ChEneOut[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + float ChCrossReOut[CLDFB_NO_CHANNELS_MAX]; + float ChCrossImOut[CLDFB_NO_CHANNELS_MAX]; + float processMtxRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS + 1][CLDFB_NO_CHANNELS_MAX]; /* +1 refers to SeparateChannel */ + float processMtxIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS + 1][CLDFB_NO_CHANNELS_MAX]; + float processMtxDecRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + float processMtxDecIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + float diffuseFieldCoherence[CLDFB_NO_CHANNELS_MAX]; + float diffuseFieldCoherenceX[BINAURAL_COHERENCE_DIFFERENCE_BINS]; + float diffuseFieldCoherenceY[BINAURAL_COHERENCE_DIFFERENCE_BINS]; + float diffuseFieldCoherenceZ[BINAURAL_COHERENCE_DIFFERENCE_BINS]; + float earlyPartEneCorrection[CLDFB_NO_CHANNELS_MAX]; + REVERB_STRUCT_HANDLE hReverb; + uint8_t renderStereoOutputInsteadOfBinaural; + float frameMeanDiffuseness[CLDFB_NO_CHANNELS_MAX]; + float processMtxRePrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS + 1][CLDFB_NO_CHANNELS_MAX]; + float processMtxImPrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS + 1][CLDFB_NO_CHANNELS_MAX]; + float processMtxDecRePrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + float processMtxDecImPrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + uint16_t useSubframeMode; /* 0 = process in 20 ms frames, 1 = process in 5 ms subframes */ + uint16_t useTdDecorr; + ivas_td_decorr_state_t *hTdDecorr; + +} DIRAC_DEC_BIN_DATA, *DIRAC_DEC_BIN_HANDLE; + +typedef struct ivas_binaural_rendering_conv_module_struct +{ + float ***filterTapsLeftReal; + float ***filterTapsLeftImag; + float ***filterTapsRightReal; + float ***filterTapsRightImag; + + float ***filterStatesLeftReal; + float ***filterStatesLeftImag; + + int16_t numTapsArray[BINAURAL_CONVBANDS]; + int16_t numTaps; + +} BINRENDERER_CONV_MODULE, *BINRENDERER_CONV_MODULE_HANDLE; + +/*----------------------------------------------------------------------------------* + * Output configuration for renderer (e.g. DirAC, MASA, Binaural Renderer...) + *----------------------------------------------------------------------------------*/ +typedef struct ivas_output_setup_structure +{ + AUDIO_CONFIG output_config; + int16_t nchan_out_woLFE; /* number of output audio channels without LFE */ + int16_t ambisonics_order; + int8_t is_loudspeaker_setup; + int8_t is_planar_setup; + int8_t is_binaural_setup; + + int16_t num_lfe; + int16_t index_lfe[1]; + const float *ls_azimuth; + const float *ls_elevation; + + uint8_t separateChannelEnabled; + int16_t separateChannelIndex; + +} IVAS_OUTPUT_SETUP, *IVAS_OUTPUT_SETUP_HANDLE; + +/*----------------------------------------------------------------------------------* + * EFAP structures + *----------------------------------------------------------------------------------*/ +// VE2AT: move to ivas_rom_rend.h ? +typedef struct EFAP_VERTEX +{ + float azi; /* azimuth of the loudspeaker */ + float ele; /* elevation of the loudspeaker */ + float pos[3]; /* [x y z] cartesian coordinate vector */ + int16_t idx; /* integer, that corresponds to the first index for the LS in the 1D output */ + int16_t isNaN; /* used to indicate if the vertex is a virtual speaker */ + EFAP_VTX_DMX_TYPE dmxType; /* virtual speaker downmix type */ + +} EFAP_VERTEX; + +typedef struct EFAP_VERTEX_DATA +{ + EFAP_VERTEX *vertexArray; /* Array of vertices */ + int16_t numVtx; /* Number of vertices */ + int16_t *vtxOrder; /* Array that indicates the order of the vertex ranked by increasing azimuth */ + +} EFAP_VERTEX_DATA; + +typedef struct EFAP_POLYSET +{ + int16_t chan[EFAP_MAX_CHAN_NUM]; /* An array indicating the loudspeaker index of the polygon vertices */ + int16_t isNaN[EFAP_MAX_CHAN_NUM]; /* Indicates if one of the vertices isNaN */ + int16_t numChan; /* An integer between 0 and EFAP_MAX_CHAN_NUM corresponding to the number of vertices of the polygon */ + float polyAzi[EFAP_MAX_CHAN_NUM]; /* An array (same length as "chan"), with the azimuth of the channels */ + float polyEle[EFAP_MAX_CHAN_NUM]; /* An array (same length as "chan"), with the elevation of the channels */ + +} EFAP_POLYSET; + +typedef struct EFAP_LS_TRIANGLE +{ + int16_t LS[3]; /* Array indicating the loudspeaker index of the triangle vertices */ + +} EFAP_LS_TRIANGLE; + +typedef struct EFAP_POLYSET_DATA +{ + EFAP_POLYSET polysetArray[EFAP_MAX_POLY_SET]; /* Array of polygons */ + int16_t numPoly; /* Number of polygons */ + EFAP_LS_TRIANGLE triArray[EFAP_MAX_POLY_SET]; /* Array of triangles */ + int16_t numTri; /* Number of triangles */ + +} EFAP_POLYSET_DATA; + +typedef struct EFAP +{ + int16_t numSpk; /* Number of loudspeakers */ + float *aziSpk; /* Loudspeaker azimuths */ + float *eleSpk; /* Loudspeaker elevations */ + EFAP_VERTEX_DATA vtxData; /* Vertex Data, contains all the data concerning the vertex */ + EFAP_POLYSET_DATA polyData; /* Polygon data */ + float **dmTranspose; /* Downmix Matrix used for redistributing the energy of ghosts LS and its transpose */ + float *bufferLong; /* tmp buffer that will be given as a parameter for computing the gain; this is a 1D array of length numVtx */ + float *bufferShort; /* tmp buffer that will be given as a parameter for computing the gain; this is the result of downMixMatrix*bufferLong, length is numSpk */ + int16_t numTot; /* Total number of real + ghost loudspeakers, used later for freeing memory */ + +} EFAP, *EFAP_HANDLE; + + +/*----------------------------------------------------------------------------------* + * VBAP structures + *----------------------------------------------------------------------------------*/ +// VE2AT: move to ivas_rom_rend.h ? +enum SpeakerNodeGroup +{ + SPEAKER_NODE_BOTTOM_HALF, + SPEAKER_NODE_HORIZONTAL, + SPEAKER_NODE_TOP_HALF, + SPEAKER_NODE_BACK, + SPEAKER_NODE_ALL +}; + +/* Defines a single virtual surface triplet of loudspeakers + * with a precalculated inverse matrix */ +typedef struct vbap_vs_triplet_structure +{ + uint8_t speaker_node[3]; + float inverse_matrix[3][3]; + +} VBAP_VS_TRIPLET; + +/* Defines a single speaker node */ +typedef struct vbap_speaker_node_structure +{ + float azi_deg; + float ele_deg; + float unit_vec[3]; + enum SpeakerNodeGroup group; + +} VBAP_SPEAKER_NODE; + +/* Storage structure for fast runtime triplet search */ +typedef struct triplet_search_structure +{ + VBAP_VS_TRIPLET *triplets; + int16_t num_triplets; + int16_t initial_search_indices[VBAP_NUM_SEARCH_SECTORS]; + +} VBAP_SEARCH_STRUCT; + +/* VBAP data structure. Contains the formed virtual surface arrangement * and supporting data. */ +typedef struct vbap_data_structure +{ + VBAP_SEARCH_STRUCT search_struct[2]; /* Default to max two groups in this implementation */ + int16_t num_search_structs; + int16_t num_speaker_nodes; + int16_t num_speaker_nodes_internal; + int16_t top_virtual_speaker_node_index; /* These indices can be negative */ + int16_t bottom_virtual_speaker_node_index; + int16_t back_virtual_speaker_node_index; + float *bottom_virtual_speaker_node_division_gains; + float *top_virtual_speaker_node_division_gains; + float *back_virtual_speaker_node_division_gains; + +} VBAP_DATA, *VBAP_HANDLE; + + +/*----------------------------------------------------------------------------------* + * renderer structures + *----------------------------------------------------------------------------------*/ +// VE2AT: move to ivas_rom_rend.h ? +typedef struct renderer_struct +{ + float prev_gains[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; + float interpolator[L_FRAME48k]; + +} ISM_RENDERER_DATA, *ISM_RENDERER_HANDLE; + +/* Fastconv binaural data structure */ +typedef struct ivas_binaural_rendering_struct +{ + /* Common variables for all modules */ + IVAS_OUTPUT_SETUP_HANDLE hInputSetup; /* pointer to input spatial format for binaural renderer*/ + EFAP_HANDLE hEFAPdata; /* EFAP structure*/ + float *hoa_dec_mtx; /* pointer to HOA decoder mtx */ + int8_t rotInCldfb; /* Flag to enable rotation within bin Renderer in CLDFB*/ + int16_t max_band; /* band upto which rendering is performed */ + int16_t conv_band; /* band upto which convolution in cldfb domain is performed */ + int16_t timeSlots; /* number of time slots of binaural renderer */ + int16_t nInChannels; /* number input channels */ + int8_t render_lfe; /* Flag to render LFE in binaural rendering*/ + IVAS_FORMAT ivas_format; /* format; corresponds to st_ivas->ivas_format, unless the signal gets transormed to a different domain for rendering */ + + /* Convolution module structure */ + BINRENDERER_CONV_MODULE_HANDLE hBinRenConvModule; + + /* Variables related to reverb module */ + float earlyPartEneCorrection[CLDFB_NO_CHANNELS_MAX]; + REVERB_STRUCT_HANDLE hReverb; + +} BINAURAL_RENDERER, *BINAURAL_RENDERER_HANDLE; + + +/*----------------------------------------------------------------------------------* + * Head tracking data structure + *----------------------------------------------------------------------------------*/ +// VE2AT: move to ivas_rom_rend.h ? + +typedef struct ivas_binaural_head_track_struct +{ + int16_t num_quaternions; + IVAS_QUATERNION Quaternions[MAX_PARAM_SPATIAL_SUBFRAMES]; + float Rmat[3][3]; + float Rmat_prev[3][3]; + + uint8_t lrSwitchedNext; + uint8_t lrSwitchedCurrent; + float lrSwitchInterpVal; + + int16_t shd_rot_max_order; + +} HEAD_TRACK_DATA, *HEAD_TRACK_DATA_HANDLE; + +/* Reverberator structures */ + + +typedef struct ivas_roomAcoustics_t +{ + int16_t override; + int16_t use_brir; + int16_t late_reverb_on; + int16_t nBands; /* Number of frequency bands for which reverb properties are provided, integer, range [2..256] */ + float pFc_input[CLDFB_NO_CHANNELS_MAX]; /* Center frequencies for which following values are provided: */ + float pAcoustic_rt60[CLDFB_NO_CHANNELS_MAX]; /* - The room's T60 per center frequency */ + float pAcoustic_dsr[CLDFB_NO_CHANNELS_MAX]; /* - The room's Diffuse to Source Ratio per center frequency */ + float acousticPreDelay; /* Time elapsed between input signal and late reverberation start, float, range [0.001..10] */ + float inputPreDelay; /* Offset in seconds from where DSR is computed in the RIR (0 = at source), float, range [0.001..10] */ + +} ivas_roomAcoustics_t; + +typedef struct ivas_render_config_t +{ +#ifdef DEBUGGING + ivas_renderTypeOverride renderer_type_override; +#endif + ivas_roomAcoustics_t roomAcoustics; + +} RENDER_CONFIG_DATA, *RENDER_CONFIG_HANDLE; + + +typedef struct ivas_rev_delay_line_t +{ + float *pBuffer; + uint16_t MaxDelay; + int16_t Delay; + uint16_t BufferPos; + float Gain; + +} ivas_rev_delay_line_t; + +typedef struct ivas_rev_iir_filter_t +{ + uint16_t MaxTaps; + uint16_t nr_taps; + uint16_t isFIR; + float Output; + float CoefA[IVAS_REV_MAX_IIR_FILTER_LENGTH]; + float CoefB[IVAS_REV_MAX_IIR_FILTER_LENGTH]; + float pBuffer[IVAS_REV_MAX_IIR_FILTER_LENGTH]; + +} ivas_rev_iir_filter_t; + + +typedef float rv_fftwf_type_complex[2]; /* complex type of fftwf library */ + +/* Convertion block for FFT filter: from time domain to frequency domain (with OLS) and back */ +typedef struct ivas_reverb_t2f_f2t_t +{ + int16_t fft_size; + int16_t log2_fft_size; + int16_t block_size; + int16_t hist_size; /* rv_fft_size - rv_block_size */ + float fft_history_L[RV_FILTER_MAX_HISTORY]; + float fft_history_R[RV_FILTER_MAX_HISTORY]; + +} ivas_reverb_t2f_f2t_t; + +/* FFT filter with its frequency response coefficients */ +typedef struct ivas_reverb_fft_filter_t +{ + int16_t fft_size; + float fft_spectrum[RV_FILTER_MAX_FFT_SIZE]; + +} ivas_reverb_fft_filter_t; + + +typedef struct ivas_reverb_state_t +{ + RENDER_CONFIG_DATA pConfig; + + /* input downmixer: */ + float dmx_gain; /* downmix gain */ + + /* predelay: */ + ivas_rev_delay_line_t predelay_line; + float *pPredelay_buffer; + + /* jot reverberator: */ + uint16_t nr_of_branches; /* number of feedback loops */ + ivas_rev_delay_line_t delay_line[IVAS_REV_MAX_NR_BRANCHES]; /* feedback loop delays */ + float *loop_delay_buffer[IVAS_REV_MAX_NR_BRANCHES]; /* feedback loop delay sample buffers */ + ivas_rev_iir_filter_t t60[IVAS_REV_MAX_NR_BRANCHES]; /* feedback loop filters */ + float gain_matrix[IVAS_REV_MAX_NR_BRANCHES][IVAS_REV_MAX_NR_BRANCHES]; /* feedback matrix */ + float mixer[BINAURAL_CHANNELS][IVAS_REV_MAX_NR_BRANCHES]; /* output mixer matrix */ + + /* binauralization filters: */ + int16_t do_corr_filter; + ivas_reverb_t2f_f2t_t fft_filter_ols; + ivas_reverb_fft_filter_t fft_filter_correl_0; + ivas_reverb_fft_filter_t fft_filter_correl_1; + ivas_reverb_fft_filter_t fft_filter_color_0; + ivas_reverb_fft_filter_t fft_filter_color_1; + uint16_t fft_size; /* fft processing size */ + uint16_t fft_subblock_size; /* fft block processing size */ + uint16_t num_fft_subblocks; /* number of fft subblocks */ + uint16_t full_block_size; /* full block processing size */ + +} REVERB_DATA, *REVERB_HANDLE; + + +typedef struct ivas_orient_trk_state_t +{ + OTR_TRACKING_T trackingType; + float centerAdaptationRate; + float offCenterAdaptationRate; + float adaptationAngle; + + float alpha; + + float absYaw; /* absolute orientation */ + float absPitch; + float absRoll; + + float absAvgYaw; /* average absolute orientation */ + float absAvgPitch; + float absAvgRoll; + + float refYaw; /* reference orientation */ + float refPitch; + float refRoll; + + float trkYaw; /* tracked orientation */ + float trkPitch; + float trkRoll; + +} ivas_orient_trk_state_t; + + +/*----------------------------------------------------------------------------------* + * TD ISm Object Renderer structure + *----------------------------------------------------------------------------------*/ + + +typedef struct +{ + int16_t modelROM; /* Flag that indicates that the model resides in ROM (controls init/dealloc). */ + int16_t UseItdModel; /* Controls whether ITD model is used. */ + int16_t SplineDegree; /* Degree of the spline functions */ + int16_t K; /* Length of filter */ + int16_t elevDim2; + int16_t elevDim3; + int16_t AlphaN; /* Number of rows in Alpha matrices */ + int16_t num_unique_azim_splines; + int16_t elevSegSamples; + + int16_t elevBsLen[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + int16_t elevBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + const int16_t *azimDim2; + const int16_t *azimDim3; + const int16_t *azim_start_idx; + const int16_t *azimSegSamples; + const int16_t *azimShapeIdx; + const int16_t *azimShapeSampFactor; + + const float *elevKSeq; /* Array, N x elevDim2 x elevDim3 */ + const float *AlphaL; /* Array, size AlphaN x K */ + const float *AlphaR; /* Array, size AlphaN x K */ + const float *elevBsShape; + float **azimKSeq; /* Array, length azimDim3+1 */ + const float **azimBsShape; + + int16_t azimDim3Max; + int16_t iSecFirst[HRTF_MODEL_N_SECTIONS]; /* Indices for start of sections */ + int16_t iSecLast[HRTF_MODEL_N_SECTIONS]; /* Indices for end of sections */ + const float *EL; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ + const float *ER; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ + + /* Pointers for allocation of dynamic memory */ + float *AlphaL_dyn; + float *AlphaR_dyn; + float *EL_dyn; + float *ER_dyn; + float *elevBsShape_dyn; + float *elevKSeq_dyn; + int16_t *azimDim2_dyn; + int16_t *azimDim3_dyn; + int16_t *azim_start_idx_dyn; + int16_t *azimSegSamples_dyn; + int16_t *azimShapeIdx_dyn; + int16_t *azimShapeSampFactor_dyn; + float **azimBsShape_dyn; + +} ModelParams_t; + +typedef struct +{ + int16_t N; /* Polynomial degree */ + + int16_t elevDim2; + int16_t elevDim3; + const float *elevKSeq; /* Array, length elevDim3-2 */ + int16_t azimDim2; + int16_t azimDim3; + const float *azimKSeq; /* Array, length azimDim3-2 */ + const float *W; /* Array, size (elevDim3*azimDim3) x K */ + + int16_t azimBsLen[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + int16_t azimBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + const float *azimBsShape; + int16_t azimSegSamples; + + int16_t elevBsLen[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + int16_t elevBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + const float *elevBsShape; + int16_t elevSegSamples; + float resamp_factor; + + /* Pointers for allocation of dynamic memory */ + float *elevKSeq_dyn; + float *azimKSeq_dyn; + float *W_dyn; + float *azimBsShape_dyn; + float *elevBsShape_dyn; + +} ModelParamsITD_t; + +typedef struct +{ + float val; + int16_t i; + +} ValueIndex_t; + +/* Shared memory for use when evaluating BSpline HR filter model*/ +typedef struct +{ + float BM[HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ]; + ValueIndex_t BMEnergiesL[HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ]; + ValueIndex_t BMEnergiesR[HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ]; + int16_t UseIndsL[HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ]; + int16_t UseIndsR[HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ]; + float *hrfModL; + float *hrfModR; + float elevBfVec[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + float azimBfVec[HRTF_MODEL_BSPLINE_NUM_COEFFS][HRTF_MODEL_BSPLINE_NUM_COEFFS]; + float BM_ITD[HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ]; + float elevBfVecITD[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + float azimBfVecITD[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + float itdMod; + +} ModelEval_t; + +/* Mixer listener */ +typedef struct +{ + int16_t PoseUpdated; + float Pos[3]; + float Front[3]; + float Up[3]; + float Right[3]; + + int16_t VelUpdated; + float Vel[3]; + +} TDREND_MIX_Listener_t; + +/* HR filter */ +typedef struct TDREND_HRFILT_FiltSet_struct +{ + int32_t SampleRate; /* Sample rate of the HR filter */ + int16_t NumPos; + int16_t NumElev; + float Dist; + float *ItdSet_p; + int16_t FiltLength; + float *Azim_p; + float *Elev_p; + float *ItdSetNominal_p; + float *LeftFiltSet_p; + float *RightFiltSet_p; +#ifdef TDREND_HRTF_TABLE_METHODS + int16_t *AzimStartIdx_p; + int16_t *NumAzim_p; + float *ElevFull_p; + float ElevIncr; +#endif + ModelParams_t ModelParams; + ModelEval_t ModelEval; + ModelParamsITD_t ModelParamsITD; + TDREND_HRFILT_Method_t FilterMethod; /* HR filtering method */ + +} TDREND_HRFILT_FiltSet_t; + + +/* Distance attenuation */ +typedef struct +{ + TDREND_DistAttenModel_t DistAttenModel; + float RefDist; + float MaxDist; + float RollOffFactor; + +} TDREND_DistAtten_t; + +/* Directional attenuation */ +typedef struct +{ + float ConeInnerAngle; + float ConeOuterAngle; + float ConeOuterGain; + +} TDREND_DirAtten_t; + +/* Mixer spatial specification */ +typedef struct +{ + int16_t UseCommonDistAttenModel; /* Common distance attenuation model flag */ + TDREND_DistAttenModel_t DistAttenModel; /* Distance attenuation model */ + +} TDREND_MixSpatSpec_t; + + +typedef struct TDREND_SRC_REND_s +{ + int16_t InputAvailable; + TDREND_PlayStatus_t PlayStatus; + + /* Gains */ + int16_t SrcGainUpdated; + float SrcGain_p[SPAT_BIN_MAX_INPUT_CHANNELS]; + float SrcGainMin_p[SPAT_BIN_MAX_INPUT_CHANNELS]; + float SrcGainMax_p[SPAT_BIN_MAX_INPUT_CHANNELS]; + float DirGain_p[SPAT_BIN_MAX_INPUT_CHANNELS]; + float DistGain_p[SPAT_BIN_MAX_INPUT_CHANNELS]; +} TDREND_SRC_REND_t; + + +/* Source spatial parameters */ +typedef struct +{ + int16_t Updated; + TDREND_PosType_t PosType; + float Pos_p[3 * SPAT_BIN_MAX_INPUT_CHANNELS]; + float Front_p[3 * SPAT_BIN_MAX_INPUT_CHANNELS]; + int16_t DirAttenEnabled; + TDREND_DirAtten_t DirAtten; + int16_t DistAttenEnabled; + TDREND_DistAtten_t DistAtten; + +} TDREND_SRC_SPATIAL_t; + +typedef struct +{ + float *InputFrame_p; /* Input frame pointer */ + TDREND_SRC_SPATIAL_t *SrcSpatial_p; + TDREND_SRC_REND_t *SrcRend_p; + int16_t itd; + int16_t previtd; + int16_t filterlength; + float mem_itd[ITD_MEM_LEN]; + float hrf_left_prev[SFX_SPAT_BIN_MAX_FILTER_LENGTH]; /* Todo: Should we allocate these buffers with malloc() instead of the maximum length? */ + float hrf_right_prev[SFX_SPAT_BIN_MAX_FILTER_LENGTH]; + float azim_prev; + float elev_prev; + float mem_hrf_left[SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1]; + float mem_hrf_right[SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1]; + float Gain; +} TDREND_SRC_t; + +/* Top level TD binaural renderer handle */ +typedef struct ivas_binaural_td_rendering_struct +{ + TDREND_MixSpatSpec_t *TdRend_MixSpatSpec_p; + TDREND_DirAtten_t *DirAtten_p; + int16_t NumOfSrcs; + int16_t MaxSrcInd; + + TDREND_SRC_t *Sources[MAX_NUM_TDREND_CHANNELS]; + + float Gain; /* Mixer gain */ + TDREND_MIX_Listener_t *Listener_p; /* The virtual listener */ + TDREND_HRFILT_FiltSet_t *HrFiltSet_p; /* HR filter set */ + + int16_t UseCommonDistAttenModel; /* Use common dist atten model (TRUE/FALSE) */ + int16_t DistAttenEnabled; /* (TRUE/FALSE) */ + TDREND_DistAttenModel_t DistAttenModel; /* Common distance attenuation model */ + +} BINAURAL_TD_OBJECT_RENDERER, *BINAURAL_TD_OBJECT_RENDERER_HANDLE; + +/*------------------------------------------------------------------------------------------* + * Crend structures + *------------------------------------------------------------------------------------------*/ +// VE2AT: move to ivas_rom_rend.h ? +typedef struct ivas_hrtfs_structure +{ + float *pOut_to_bin_re[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS]; + float *pOut_to_bin_im[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS]; + float *pOut_to_bin_diffuse_re[BINAURAL_CHANNELS]; + float *pOut_to_bin_diffuse_im[BINAURAL_CHANNELS]; + float latency_s; + uint16_t num_iterations[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS]; + uint16_t num_iterations_diffuse[BINAURAL_CHANNELS]; + uint16_t *pIndex_frequency_max[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS]; + uint16_t *pIndex_frequency_max_diffuse[BINAURAL_CHANNELS]; + uint16_t index_frequency_max_diffuse; + int16_t max_num_ir; + int16_t max_num_iterations; + float inv_diffuse_weight[MAX_INTERN_CHANNELS]; /* inverse diffuse weights array, access one inverse weight by pInvDiffuseWeight[channel] */ + float gain_lfe; + +} HRTFS_DATA, *HRTFS_HANDLE; + + +/* Main Crend structure */ +typedef struct ivas_crend_state_t +{ + float *freq_buffer_re[MAX_INTERN_CHANNELS]; + float *freq_buffer_im[MAX_INTERN_CHANNELS]; + float *freq_buffer_re_diffuse; + float *freq_buffer_im_diffuse; + float *prev_out_buffer[BINAURAL_CHANNELS]; + float *lfe_delay_line; + float m_fYaw; + float m_fPitch; + float m_fRoll; + ivas_orient_trk_state_t *hTrack; + REVERB_HANDLE hReverb; + int16_t delay_line_rw_index; + int16_t diffuse_delay_line_rw_index; + +} CREND_DATA, *CREND_HANDLE; + +/* Main Crend wrapper structure */ +typedef struct ivas_binaural_crend_wrapper_struct +{ + int32_t binaural_latency_ns; + CREND_HANDLE hCrend; + HRTFS_HANDLE hHrtfCrend; +} CREND_WRAPPER, *CREND_WRAPPER_HANDLE; + +/*----------------------------------------------------------------------------------* + * LFE decoder structure + *----------------------------------------------------------------------------------*/ + +typedef struct ivas_lfe_dec_data_structure +{ + ivas_filters_process_state_t filter_state; + LFE_WINDOW_HANDLE pWindow_state; + const uint16_t *cum_freq_models[IVAS_MAX_NUM_QUANT_STRATS][IVAS_MAX_NUM_DCT_COEF_GROUPS]; + int16_t lfe_dec_indices_coeffs_tbl[IVAS_MAX_NUM_QUANT_STRATS][IVAS_MAX_NUM_DCT_COEF_GROUPS]; + float lfe_block_delay_s; + int16_t lfe_prior_buf_len; + float *prior_out_buffer; + + float *prevsynth_buf; + float *lfe_delay_buf; + int16_t lfe_addl_delay; + int16_t bfi_count; + +} LFE_DEC_DATA, *LFE_DEC_HANDLE; + + +/*----------------------------------------------------------------------------------* + * Limiter structure + *----------------------------------------------------------------------------------*/ + +typedef struct +{ + int16_t max_num_channels; + int16_t num_channels; + float **channel_ptrs; + int32_t sampling_rate; + float gain; + float release_heuristic; + float attack_constant; + int16_t strong_saturation_count; +#ifdef DEBUGGING + int32_t cnt_frames_limited; /* counter of frames in which the limiter is applied */ +#endif + +} IVAS_LIMITER, *IVAS_LIMITER_HANDLE; + + +/*----------------------------------------------------------------------------------* + * Decoder configuration structure + *----------------------------------------------------------------------------------*/ + +typedef struct decoder_config_structure +{ + int32_t ivas_total_brate; /* IVAS total bitrate in bps */ + int32_t last_ivas_total_brate; /* last IVAS total bitrate in bps */ + int32_t output_Fs; /* output signal sampling frequency in Hz */ + int16_t nchan_out; /* number of output audio channels */ + AUDIO_CONFIG output_config; /* output audio configuration */ + int16_t Opt_LsCustom; /* indicates whether loudspeaker custom setup is used */ + int16_t Opt_HRTF_binary; /* indicates whether HRTF binary file is used */ + int16_t Opt_Headrotation; /* indicates whether head-rotation is used */ + int16_t orientation_tracking; /* indicates orientation tracking type */ + float no_diegetic_pan; + int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ + + /* temp. development parameters */ +#ifdef DEBUGGING + int16_t forceSubframeBinauralization; /* Flag for forcing Parametric binauralizer to subframe mode */ + int16_t force_rend; /* forced TD/CLDFB binaural renderer (for ISM and MC) */ +#endif + +} DECODER_CONFIG, *DECODER_CONFIG_HANDLE; + +typedef struct +{ + int32_t binaural_latency_ns; + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd; + TDREND_HRFILT_FiltSet_t *hHrtfTD; +} TDREND_WRAPPER, *TDREND_WRAPPER_HANDLE; +#endif + /*----------------------------------------------------------------------------------* * Loudspeaker Configuration Conversion structure *----------------------------------------------------------------------------------*/ diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 028b0f6274..54d18072f7 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -38,6 +38,9 @@ #include "ivas_rom_dec.h" #include "ivas_rom_rend.h" #include "ivas_lib_rend_internal.h" +#ifdef FIX_197_CREND_INTERFACE +#include "lib_rend.h" +#endif #include "prot.h" #include "wmc_auto.h" @@ -111,7 +114,11 @@ typedef struct IVAS_REND_AudioObjectPosition currentPos; IVAS_REND_AudioObjectPosition previousPos; TDREND_WRAPPER tdRendWrapper; +#ifdef FIX_197_CREND_INTERFACE + CREND_WRAPPER_HANDLE crendWrapper; +#else CREND_WRAPPER crendWrapper; +#endif rotation_matrix rot_mat_prev; } input_ism; @@ -126,7 +133,11 @@ typedef struct LSSETUP_CUSTOM_STRUCT customLsInput; EFAP_WRAPPER efapInWrapper; TDREND_WRAPPER tdRendWrapper; +#ifdef FIX_197_CREND_INTERFACE + CREND_WRAPPER_HANDLE crendWrapper; +#else CREND_WRAPPER crendWrapper; +#endif rotation_gains rot_gains_prev; IVAS_REND_LfeRouting lfeRouting; } input_mc; @@ -135,7 +146,11 @@ typedef struct { input_base base; pan_matrix hoaDecMtx; +#ifdef FIX_197_CREND_INTERFACE + CREND_WRAPPER_HANDLE crendWrapper; +#else CREND_WRAPPER crendWrapper; +#endif rotation_gains rot_gains_prev; } input_sba; @@ -287,7 +302,11 @@ static int32_t limitRendererOutput( return numClipping; } -static AUDIO_CONFIG rendAudioConfigToIvasAudioConfig( // VE2AT: similar is defined again at line 397, why? +#ifdef FIX_197_CREND_INTERFACE +AUDIO_CONFIG getIvasAudioConfigFromRendAudioConfig( +#else +static AUDIO_CONFIG rendAudioConfigToIvasAudioConfig( // VE2AT: similar is defined again at line 397, why?#endif +#endif IVAS_REND_AudioConfig rendConfig ) { switch ( rendConfig ) @@ -433,11 +452,42 @@ ivas_error getAudioConfigNumChannels( return IVAS_ERR_OK; } +#ifdef FIX_197_CREND_INTERFACE +IVAS_REND_AudioConfig getRendAudioConfigFromIvasAudioConfig( + AUDIO_CONFIG config ) +#else AUDIO_CONFIG getIvasAudioConfigFromRendAudioConfig( IVAS_REND_AudioConfig config ) +#endif { switch ( config ) { +#ifdef FIX_197_CREND_INTERFACE + case AUDIO_CONFIG_MONO: + return IVAS_REND_AUDIO_CONFIG_MONO; + case AUDIO_CONFIG_STEREO: + return IVAS_REND_AUDIO_CONFIG_STEREO; + case AUDIO_CONFIG_BINAURAL: + return IVAS_REND_AUDIO_CONFIG_BINAURAL; + case AUDIO_CONFIG_BINAURAL_ROOM: + return IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM; + case AUDIO_CONFIG_5_1: + return IVAS_REND_AUDIO_CONFIG_5_1; + case AUDIO_CONFIG_7_1: + return IVAS_REND_AUDIO_CONFIG_7_1; + case AUDIO_CONFIG_5_1_2: + return IVAS_REND_AUDIO_CONFIG_5_1_2; + case AUDIO_CONFIG_5_1_4: + return IVAS_REND_AUDIO_CONFIG_5_1_4; + case AUDIO_CONFIG_7_1_4: + return IVAS_REND_AUDIO_CONFIG_7_1_4; + case AUDIO_CONFIG_FOA: + return IVAS_REND_AUDIO_CONFIG_FOA; + case AUDIO_CONFIG_HOA2: + return IVAS_REND_AUDIO_CONFIG_HOA2; + case AUDIO_CONFIG_HOA3: + return IVAS_REND_AUDIO_CONFIG_HOA3; +#else case IVAS_REND_AUDIO_CONFIG_MONO: return AUDIO_CONFIG_MONO; case IVAS_REND_AUDIO_CONFIG_STEREO: @@ -462,6 +512,7 @@ AUDIO_CONFIG getIvasAudioConfigFromRendAudioConfig( return AUDIO_CONFIG_HOA2; case IVAS_REND_AUDIO_CONFIG_HOA3: return AUDIO_CONFIG_HOA3; +#endif default: break; } @@ -964,7 +1015,11 @@ static ivas_error setRendInputActiveIsm( inputIsm->currentPos = defaultObjectPosition(); inputIsm->previousPos = defaultObjectPosition(); +#ifdef FIX_197_CREND_INTERFACE + inputIsm->crendWrapper = NULL; +#else inputIsm->crendWrapper = defaultCrendWrapper(); +#endif inputIsm->tdRendWrapper = defaultTdRendWrapper(); initRotMatrix( inputIsm->rot_mat_prev ); @@ -979,6 +1034,9 @@ static ivas_error setRendInputActiveIsm( IVAS_REND_AUDIO_CONFIG_7_1_4, outConfig, hRendCfg, +#ifdef FIX_197_CREND_INTERFACE + 0, +#endif *rendCtx.pOutSampleRate ); } if ( error != IVAS_ERR_OK ) @@ -999,7 +1057,11 @@ static void clearInputIsm( initRendInputBase( &inputIsm->base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, rendCtx ); /* Free input's internal handles */ +#ifdef FIX_197_CREND_INTERFACE + if ( inputIsm->crendWrapper != NULL ) +#else if ( inputIsm->crendWrapper.hCrend != NULL ) +#endif { ivas_rend_closeCrend( &inputIsm->crendWrapper ); } @@ -1074,8 +1136,13 @@ static ivas_error initMcPanGainsWithConversionMapping( AUDIO_CONFIG ivasConfigIn, ivasConfigOut; int16_t i; +#ifdef FIX_197_CREND_INTERFACE + ivasConfigIn = getIvasAudioConfigFromRendAudioConfig( inputMc->base.inConfig ); + ivasConfigOut = getIvasAudioConfigFromRendAudioConfig( outConfig ); +#else ivasConfigIn = rendAudioConfigToIvasAudioConfig( inputMc->base.inConfig ); ivasConfigOut = rendAudioConfigToIvasAudioConfig( outConfig ); +#endif /* Find conversion mapping for current I/O config pair. * Stay with default panning matrix if conversion_matrix is NULL */ @@ -1523,7 +1590,11 @@ static ivas_error initMcBinauralRendering( ivas_td_binaural_close( &inputMc->tdRendWrapper.hBinRendererTd ); inputMc->tdRendWrapper.hHrtfTD = NULL; } +#ifdef FIX_197_CREND_INTERFACE + if ( inputMc->crendWrapper != NULL ) +#else if ( inputMc->crendWrapper.hCrend != NULL ) +#endif { ivas_rend_closeCrend( &inputMc->crendWrapper ); } @@ -1563,6 +1634,9 @@ static ivas_error initMcBinauralRendering( ( inConfig == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) ? IVAS_REND_AUDIO_CONFIG_7_1_4 : inConfig, outConfig, hRendCfg, +#ifdef FIX_197_CREND_INTERFACE + 0, +#endif outSampleRate ) ) != IVAS_ERR_OK ) { return error; @@ -1652,7 +1726,11 @@ static ivas_error setRendInputActiveMc( setZeroPanMatrix( inputMc->panGains ); inputMc->customLsInput = defaultCustomLs(); inputMc->tdRendWrapper = defaultTdRendWrapper(); +#ifdef FIX_197_CREND_INTERFACE + inputMc->crendWrapper = NULL; +#else inputMc->crendWrapper = defaultCrendWrapper(); +#endif initRotGains( inputMc->rot_gains_prev ); inputMc->lfeRouting = defaultLfeRouting( inConfig, inputMc->customLsInput, outConfig, *inputMc->base.ctx.pCustomLsOut ); @@ -1686,7 +1764,11 @@ static void clearInputMc( { efap_free_data( &inputMc->efapInWrapper.hEfap ); } +#ifdef FIX_197_CREND_INTERFACE + if ( inputMc->crendWrapper != NULL ) +#else if ( inputMc->crendWrapper.hCrend != NULL ) +#endif { ivas_rend_closeCrend( &inputMc->crendWrapper ); } @@ -1726,7 +1808,11 @@ static ivas_error initSbaPanGainsForMcOut( case IVAS_REND_AUDIO_CONFIG_MONO: hOutSetup.ls_azimuth = ls_azimuth_CICP1; hOutSetup.ls_elevation = ls_elevation_CICP1; +#ifdef FIX_197_CREND_INTERFACE + ivas_output_init( &hOutSetup, getIvasAudioConfigFromRendAudioConfig( outConfig ) ); +#else ivas_output_init( &hOutSetup, rendAudioConfigToIvasAudioConfig( outConfig ) ); +#endif break; case IVAS_REND_AUDIO_CONFIG_STEREO: case IVAS_REND_AUDIO_CONFIG_5_1: @@ -1734,7 +1820,11 @@ static ivas_error initSbaPanGainsForMcOut( case IVAS_REND_AUDIO_CONFIG_5_1_2: case IVAS_REND_AUDIO_CONFIG_5_1_4: case IVAS_REND_AUDIO_CONFIG_7_1_4: +#ifdef FIX_197_CREND_INTERFACE + ivas_output_init( &hOutSetup, getIvasAudioConfigFromRendAudioConfig( outConfig ) ); +#else ivas_output_init( &hOutSetup, rendAudioConfigToIvasAudioConfig( outConfig ) ); +#endif break; case IVAS_REND_AUDIO_CONFIG_LS_CUSTOM: ivas_ls_custom_setup( &hOutSetup, outSetupCustom ); @@ -1814,14 +1904,22 @@ static ivas_error updateSbaPanGains( switch ( outConfig ) { case IVAS_REND_AUDIO_CONFIG_BINAURAL: +#ifdef FIX_197_CREND_INTERFACE + error = ivas_rend_openCrend( &inputSba->crendWrapper, inConfig, outConfig, hRendCfg, 0, *rendCtx.pOutSampleRate ); +#else error = ivas_rend_openCrend( &inputSba->crendWrapper, inConfig, outConfig, hRendCfg, *rendCtx.pOutSampleRate ); +#endif break; case IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM: if ( ( error = initSbaPanGainsForMcOut( inputSba, IVAS_REND_AUDIO_CONFIG_7_1_4, NULL ) ) != IVAS_ERR_OK ) { return error; } +#ifdef FIX_197_CREND_INTERFACE + error = ivas_rend_openCrend( &inputSba->crendWrapper, IVAS_REND_AUDIO_CONFIG_7_1_4, outConfig, hRendCfg, 0, *rendCtx.pOutSampleRate ); +#else error = ivas_rend_openCrend( &inputSba->crendWrapper, IVAS_REND_AUDIO_CONFIG_7_1_4, outConfig, hRendCfg, *rendCtx.pOutSampleRate ); +#endif break; default: return IVAS_ERR_INVALID_OUTPUT_FORMAT; @@ -1856,7 +1954,11 @@ static ivas_error setRendInputActiveSba( initRendInputBase( &inputSba->base, inConfig, id, rendCtx ); setZeroPanMatrix( inputSba->hoaDecMtx ); +#ifdef FIX_197_CREND_INTERFACE + inputSba->crendWrapper = NULL; +#else inputSba->crendWrapper = defaultCrendWrapper(); +#endif initRotGains( inputSba->rot_gains_prev ); if ( ( error = updateSbaPanGains( inputSba, outConfig, hRendCfg ) ) != IVAS_ERR_OK ) @@ -1877,7 +1979,11 @@ static void clearInputSba( initRendInputBase( &inputSba->base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, rendCtx ); /* Free input's internal handles */ +#ifdef FIX_197_CREND_INTERFACE + if ( inputSba->crendWrapper != NULL ) +#else if ( inputSba->crendWrapper.hCrend != NULL ) +#endif { ivas_rend_closeCrend( &inputSba->crendWrapper ); } @@ -1895,7 +2001,11 @@ static ivas_error initMasaDummyDecForMcOut( input_masa *inputMasa, IVAS_REND_Aud DecoderDummy *decDummy; decDummy = inputMasa->decDummy; +#ifdef FIX_197_CREND_INTERFACE + output_config = getIvasAudioConfigFromRendAudioConfig( outConfig ); +#else output_config = rendAudioConfigToIvasAudioConfig( outConfig ); +#endif decDummy->hDecoderConfig->output_config = output_config; decDummy->hDecoderConfig->ivas_total_brate = IVAS_512k; /* Todo Nokia: This is preventing initialization of 2TC as 1TC, should be fixed properly in ivas_dirac_dec_config() */ @@ -1976,7 +2086,11 @@ static ivas_error initMasaDummyDecForSbaOut( input_masa *inputMasa, IVAS_REND_Au decDummy = inputMasa->decDummy; +#ifdef FIX_197_CREND_INTERFACE + output_config = getIvasAudioConfigFromRendAudioConfig( outConfig ); +#else output_config = rendAudioConfigToIvasAudioConfig( outConfig ); +#endif decDummy->hDecoderConfig->output_config = output_config; decDummy->hDecoderConfig->ivas_total_brate = IVAS_512k; /* Todo Nokia: This is preventing initialization of 2TC as 1TC, should be fixed properly in ivas_dirac_dec_config() */ @@ -2041,7 +2155,11 @@ static ivas_error initMasaDummyDecForBinauralOut( input_masa *inputMasa, IVAS_RE decDummy = inputMasa->decDummy; +#ifdef FIX_197_CREND_INTERFACE + output_config = getIvasAudioConfigFromRendAudioConfig( outConfig ); +#else output_config = rendAudioConfigToIvasAudioConfig( outConfig ); +#endif decDummy->hDecoderConfig->output_config = output_config; output_config = decDummy->hDecoderConfig->output_config; @@ -2144,7 +2262,12 @@ static DecoderDummy *initDecoderDummy( int32_t sampleRate, int16_t numTransChann decDummy->hBinRenderer = NULL; decDummy->hEFAPdata = NULL; +#ifdef FIX_197_CREND_INTERFACE + decDummy->hCrendWrapper = NULL; +#else decDummy->hHrtf = NULL; + decDummy->hCrend = NULL; +#endif decDummy->hHrtfTD = NULL; decDummy->hSpar = NULL; decDummy->hoa_dec_mtx = NULL; @@ -2152,7 +2275,11 @@ static DecoderDummy *initDecoderDummy( int32_t sampleRate, int16_t numTransChann decDummy->hMasa = NULL; decDummy->hDiracDecBin = NULL; decDummy->hQMetaData = NULL; +#ifdef FIX_197_CREND_INTERFACE + decDummy->hDecoderConfig->output_config = getIvasAudioConfigFromRendAudioConfig( outConfig ); +#else decDummy->hDecoderConfig->output_config = rendAudioConfigToIvasAudioConfig( outConfig ); +#endif decDummy->nchan_transport = numTransChannels; if ( outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM || outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) @@ -2363,20 +2490,32 @@ ivas_error IVAS_REND_Open( for ( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i ) { initRendInputBase( &hIvasRend->inputsIsm[i].base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, getRendCtx( hIvasRend ) ); +#ifdef FIX_197_CREND_INTERFACE + hIvasRend->inputsIsm[i].crendWrapper = NULL; +#else hIvasRend->inputsIsm[i].crendWrapper.hCrend = NULL; +#endif hIvasRend->inputsIsm[i].tdRendWrapper.hBinRendererTd = NULL; } for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i ) { initRendInputBase( &hIvasRend->inputsMc[i].base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, getRendCtx( hIvasRend ) ); hIvasRend->inputsMc[i].efapInWrapper.hEfap = NULL; +#ifdef FIX_197_CREND_INTERFACE + hIvasRend->inputsMc[i].crendWrapper = NULL; +#else hIvasRend->inputsMc[i].crendWrapper.hCrend = NULL; +#endif hIvasRend->inputsMc[i].tdRendWrapper.hBinRendererTd = NULL; } for ( i = 0; i < RENDERER_MAX_SBA_INPUTS; ++i ) { initRendInputBase( &hIvasRend->inputsSba[i].base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, getRendCtx( hIvasRend ) ); +#ifdef FIX_197_CREND_INTERFACE + hIvasRend->inputsSba[i].crendWrapper = NULL; +#else hIvasRend->inputsSba[i].crendWrapper.hCrend = NULL; +#endif } for ( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i ) { @@ -3045,8 +3184,13 @@ ivas_error IVAS_REND_GetDelay( { if ( hIvasRend->inputsIsm[i].base.inConfig != IVAS_REND_AUDIO_CONFIG_UNKNOWN ) { +#ifdef FIX_197_CREND_INTERFACE + latency_ns = max( hIvasRend->inputsIsm[i].crendWrapper->binaural_latency_ns, + hIvasRend->inputsIsm[i].tdRendWrapper.binaural_latency_ns ); +#else latency_ns = max( hIvasRend->inputsIsm[i].crendWrapper.binaural_latency_ns, hIvasRend->inputsIsm[i].tdRendWrapper.binaural_latency_ns ); +#endif *nSamples = max( *nSamples, NS2SA( *timeScale, latency_ns ) ); } } @@ -3055,8 +3199,13 @@ ivas_error IVAS_REND_GetDelay( { if ( hIvasRend->inputsMc[i].base.inConfig != IVAS_REND_AUDIO_CONFIG_UNKNOWN ) { +#ifdef FIX_197_CREND_INTERFACE + latency_ns = max( hIvasRend->inputsMc[i].crendWrapper->binaural_latency_ns, + hIvasRend->inputsMc[i].tdRendWrapper.binaural_latency_ns ); +#else latency_ns = max( hIvasRend->inputsMc[i].crendWrapper.binaural_latency_ns, hIvasRend->inputsMc[i].tdRendWrapper.binaural_latency_ns ); +#endif *nSamples = max( *nSamples, NS2SA( *timeScale, latency_ns ) ); } } @@ -3065,7 +3214,11 @@ ivas_error IVAS_REND_GetDelay( { if ( hIvasRend->inputsSba[i].base.inConfig != IVAS_REND_AUDIO_CONFIG_UNKNOWN ) { +#ifdef FIX_197_CREND_INTERFACE + latency_ns = hIvasRend->inputsSba[i].crendWrapper->binaural_latency_ns; +#else latency_ns = hIvasRend->inputsSba[i].crendWrapper.binaural_latency_ns; +#endif *nSamples = max( *nSamples, NS2SA( *timeScale, latency_ns ) ); } } @@ -3761,7 +3914,11 @@ static ivas_error renderIsmToBinauralRoom( copyBufferTo2dArray( tmpMcBuffer, tmpCrendBuffer ); +#ifdef FIX_197_CREND_INTERFACE + ivas_rend_crendProcess( ismInput->crendWrapper, IVAS_REND_AUDIO_CONFIG_7_1_4, IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM, NULL, NULL, NULL, NULL, tmpCrendBuffer, *ismInput->base.ctx.pOutSampleRate ); +#else ivas_rend_crendProcess( &ismInput->crendWrapper, IVAS_REND_AUDIO_CONFIG_7_1_4, IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM, tmpCrendBuffer, *ismInput->base.ctx.pOutSampleRate ); +#endif accumulate2dArrayToBuffer( tmpCrendBuffer, &outAudio ); @@ -4063,7 +4220,11 @@ static ivas_error renderMcToBinaural( } /* call CREND */ +#ifdef FIX_197_CREND_INTERFACE + if ( ( error = ivas_rend_crendProcess( mcInput->crendWrapper, mcInput->base.inConfig, outConfig, NULL, NULL, NULL, NULL, tmpRendBuffer, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_rend_crendProcess( &mcInput->crendWrapper, mcInput->base.inConfig, outConfig, tmpRendBuffer, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -4115,7 +4276,11 @@ static ivas_error renderMcToBinauralRoom( } /* call CREND */ +#ifdef FIX_197_CREND_INTERFACE + if ( ( error = ivas_rend_crendProcess( mcInput->crendWrapper, mcInput->base.inConfig, outConfig, NULL, NULL, NULL, NULL, tmpCrendBuffer, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_rend_crendProcess( &mcInput->crendWrapper, mcInput->base.inConfig, outConfig, tmpCrendBuffer, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -4182,7 +4347,11 @@ static ivas_error renderMcCustomLsToBinauralRoom( copyBufferTo2dArray( tmpMcBuffer, tmpCrendBuffer ); /* call CREND */ +#ifdef FIX_197_CREND_INTERFACE + if ( ( error = ivas_rend_crendProcess( mcInput->crendWrapper, IVAS_REND_AUDIO_CONFIG_7_1_4, outConfig, NULL, NULL, NULL, NULL, tmpCrendBuffer, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_rend_crendProcess( &mcInput->crendWrapper, IVAS_REND_AUDIO_CONFIG_7_1_4, outConfig, tmpCrendBuffer, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -4410,7 +4579,11 @@ static ivas_error renderSbaToBinaural( } /* call CREND */ +#ifdef FIX_197_CREND_INTERFACE + if ( ( error = ivas_rend_crendProcess( sbaInput->crendWrapper, sbaInput->base.inConfig, outConfig, NULL, NULL, NULL, NULL, tmpCrendBuffer, *sbaInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_rend_crendProcess( &sbaInput->crendWrapper, sbaInput->base.inConfig, outConfig, tmpCrendBuffer, *sbaInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -4470,7 +4643,11 @@ static ivas_error renderSbaToBinauralRoom( copyBufferTo2dArray( tmpMcBuffer, tmpCrendBuffer ); /* call CREND */ +#ifdef FIX_197_CREND_INTERFACE + if ( ( error = ivas_rend_crendProcess( sbaInput->crendWrapper, IVAS_REND_AUDIO_CONFIG_7_1_4, outConfig, NULL, NULL, NULL, NULL, tmpCrendBuffer, *sbaInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_rend_crendProcess( &sbaInput->crendWrapper, IVAS_REND_AUDIO_CONFIG_7_1_4, outConfig, tmpCrendBuffer, *sbaInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -4873,3 +5050,23 @@ int32_t IVAS_REND_GetCntFramesLimited( return hIvasRend->hLimiter->cnt_frames_limited; } #endif + +#ifdef FIX_197_CREND_INTERFACE +ivas_error ivas_rend_initEfap( + AUDIO_CONFIG outConfig, + EFAP_HANDLE *hEfap ) +{ + ivas_error err; + IVAS_REND_AudioConfig audioCfg; + EFAP_WRAPPER wrap; + LSSETUP_CUSTOM_STRUCT customLsOut; + wrap.hEfap = NULL; + wrap.pCustomLsSetup = NULL; + audioCfg = getRendAudioConfigFromIvasAudioConfig( outConfig ); + memset( &customLsOut, 0, sizeof( LSSETUP_CUSTOM_STRUCT ) ); + err = initEfap( &wrap, audioCfg, &customLsOut ); + *hEfap = wrap.hEfap; + + return err; +} +#endif \ No newline at end of file diff --git a/lib_rend/lib_rend.h b/lib_rend/lib_rend.h index ea4b84d897..e9b84b7043 100644 --- a/lib_rend/lib_rend.h +++ b/lib_rend/lib_rend.h @@ -40,13 +40,17 @@ #include "options.h" #include "common_api_types.h" #include "ivas_error.h" - +#ifdef FIX_197_CREND_INTERFACE +#include "ivas_stat_rend.h" +#endif #define RENDERER_MAX_ISM_INPUTS 4 #define RENDERER_MAX_MC_INPUTS 1 #define RENDERER_MAX_SBA_INPUTS 1 #define RENDERER_MAX_MASA_INPUTS 1 +#ifndef FIX_197_CREND_INTERFACE + #define RENDERER_HEAD_POSITIONS_PER_FRAME 4 typedef struct @@ -139,6 +143,13 @@ typedef struct float lfeOutputGains[IVAS_MAX_INPUT_LFE_CHANNELS][IVAS_MAX_OUTPUT_CHANNELS]; } IVAS_REND_LfeRouting; +#else + +AUDIO_CONFIG getIvasAudioConfigFromRendAudioConfig( + IVAS_REND_AudioConfig config ); + +#endif + /* clang-format off */ /*----------------------------------------------------------------------------------* * Function prototypes @@ -275,6 +286,12 @@ int32_t IVAS_REND_GetCntFramesLimited( ); #endif +#ifdef FIX_197_CREND_INTERFACE +ivas_error ivas_rend_initEfap( + AUDIO_CONFIG outConfig, + EFAP_HANDLE *hEfap + ); +#endif /* clang-format on */ #endif diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c index eb7b25dfa5..ea0bf89fee 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c @@ -63,7 +63,9 @@ #include "options.h" #include "render_config_reader.h" #include "wmc_auto.h" - +#ifdef FIX_197_CREND_INTERFACE +#include "lib_rend.h" +#endif static int32_t ivas_check_rounding( float binaural_latencys_s[3], int16_t use_round_latency, int16_t use_round_for_lfe, int32_t *err_lfe, int32_t *err_dec, int16_t verbose ) { @@ -1100,7 +1102,11 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl float *ppDelay_lines[IVAS_MAX_NUM_CH]; const float *filt_coeff; int16_t delay_lp = 0; +#ifdef FIX_197_CREND_INTERFACE + Decoder_Struct st_ivas = { 0 }; +#else Decoder_Struct st_ivas; +#endif HeadRotFileReader *headRotReader = NULL; memset( &st_ivas, 0, sizeof( Decoder_Struct ) ); @@ -1142,7 +1148,11 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl if ( IVAS_SUCCESS != result ) { fprintf( stderr, "WAV header skip failed\n" ); +#ifdef FIX_197_CREND_INTERFACE + ivas_rend_closeCrend( &st_ivas.hCrendWrapper ); +#else ivas_crend_close( &st_ivas ); +#endif exit( -1 ); } } @@ -1291,7 +1301,11 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl } else { +#ifdef FIX_197_CREND_INTERFACE + ivas_hrtf_init( st_ivas.hCrendWrapper->hHrtfCrend ); +#else ivas_hrtf_init( st_ivas.hHrtf ); +#endif } int16_t in_ch = audioCfg2channels( st_ivas.transport_config ); @@ -1300,7 +1314,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl /*------------------------------------------------------------------------------------------* * State memory allocation for Common renderer *------------------------------------------------------------------------------------------*/ - st_ivas.hDecoderConfig->Opt_Headrotation = pIo_params->orientation_tracking != OTR_TRACKING_NONE ? 1 : 0; + st_ivas.hDecoderConfig->Opt_Headrotation = ( pIo_params->orientation_tracking != OTR_TRACKING_NONE ) ? 1 : 0; /*-------------------------------------------------------------------* * Allocate and initialize Head-Tracking handle *--------------------------------------------------------------------*/ @@ -1357,7 +1371,11 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl else if ( pIo_params->test == TD_BIN_TEST ) { ivas_output_init( &st_ivas.hIntSetup, st_ivas.transport_config ); +#ifdef FIX_197_CREND_INTERFACE + ivas_output_init( &st_ivas.hOutSetup, st_ivas.hOutSetup.output_config ); +#else ivas_output_init( &st_ivas.hOutSetup, st_ivas.transport_config ); +#endif ivas_td_binaural_open( &st_ivas ); } else if ( pIo_params->test == PARAM_BIN_TEST ) @@ -1369,7 +1387,11 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl } ivas_output_init( &st_ivas.hIntSetup, st_ivas.transport_config ); +#ifdef FIX_197_CREND_INTERFACE + ivas_output_init( &st_ivas.hOutSetup, st_ivas.hOutSetup.output_config ); +#else ivas_output_init( &st_ivas.hOutSetup, st_ivas.transport_config ); +#endif st_ivas.hOutSetup.separateChannelEnabled = 1; int16_t numCldfbAnalyses, numCldfbSyntheses; numCldfbAnalyses = st_ivas.nchan_transport; @@ -1402,17 +1424,32 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl else { ivas_output_init( &st_ivas.hIntSetup, st_ivas.transport_config ); +#ifdef FIX_197_CREND_INTERFACE + ivas_output_init( &st_ivas.hOutSetup, st_ivas.hOutSetup.output_config ); + ivas_rend_openCrend( &st_ivas.hCrendWrapper, getRendAudioConfigFromIvasAudioConfig( st_ivas.transport_config ), getRendAudioConfigFromIvasAudioConfig( st_ivas.hOutSetup.output_config ), st_ivas.hRenderConfig, st_ivas.hDecoderConfig->Opt_Headrotation, pIo_params->sample_rate ); +#else ivas_output_init( &st_ivas.hOutSetup, st_ivas.transport_config ); ivas_crend_open( &st_ivas ); +#endif } if ( pIo_params->test == CREND_BIN_TEST ) { +#ifdef FIX_197_CREND_INTERFACE + pIo_params->latency_ns = st_ivas.hCrendWrapper->binaural_latency_ns; +#else pIo_params->latency_ns = (int32_t) ( st_ivas.hHrtf->latency_s * 1000000000.f ); +#endif } if ( st_ivas.ivas_format == MC_FORMAT ) { +#ifdef FIX_197_CREND_INTERFACE + if ( st_ivas.hDecoderConfig->Opt_Headrotation ) + { + ivas_rend_initEfap( st_ivas.hIntSetup.output_config, &st_ivas.hEFAPdata ); + } +#endif ivas_create_lfe_dec( &st_ivas.hLFE, st_ivas.hDecoderConfig->output_Fs, pIo_params->latency_ns ); if ( st_ivas.hLFE->lfe_addl_delay > 0 ) @@ -1592,7 +1629,11 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl } else { +#ifdef FIX_197_CREND_INTERFACE + ivas_rend_crendProcess( st_ivas.hCrendWrapper, getRendAudioConfigFromIvasAudioConfig( st_ivas.transport_config ), getRendAudioConfigFromIvasAudioConfig( st_ivas.hOutSetup.output_config ), st_ivas.hDecoderConfig, st_ivas.hHeadTrackData, &st_ivas.hIntSetup, st_ivas.hEFAPdata, ppPcm_in, pIo_params->sample_rate ); +#else ivas_crend_process( &st_ivas, ppPcm_in ); +#endif } } @@ -1690,7 +1731,11 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl ivas_dirac_dec_close( st_ivas.hDirAC ); if ( st_ivas.hBinRenderer != NULL ) ivas_binRenderer_close( &st_ivas.hBinRenderer ); +#ifdef FIX_197_CREND_INTERFACE + ivas_rend_closeCrend( &st_ivas.hCrendWrapper ); +#else ivas_crend_close( &st_ivas ); +#endif if ( st_ivas.hBinRendererTd != NULL ) ivas_td_binaural_close( &st_ivas.hBinRendererTd ); if ( st_ivas.hLimiter != NULL ) @@ -1776,7 +1821,11 @@ ivas_result_t ivas_object_mixer_renderer( ivas_crend_io_params_t *pIo_params, in if ( IVAS_SUCCESS != result ) { fprintf( stderr, "WAV header skip failed\n" ); +#ifdef FIX_197_CREND_INTERFACE + ivas_rend_closeCrend( &st_ivas.hCrendWrapper ); +#else ivas_crend_close( &st_ivas ); +#endif exit( -1 ); } } @@ -1791,7 +1840,11 @@ ivas_result_t ivas_object_mixer_renderer( ivas_crend_io_params_t *pIo_params, in if ( IVAS_SUCCESS != result ) { fprintf( stderr, "Crend configuration parameters setting failed\n" ); +#ifdef FIX_197_CREND_INTERFACE + ivas_rend_closeCrend( &st_ivas.hCrendWrapper ); +#else ivas_crend_close( &st_ivas ); +#endif exit( -1 ); } @@ -1799,7 +1852,11 @@ ivas_result_t ivas_object_mixer_renderer( ivas_crend_io_params_t *pIo_params, in * State memory allocation for Common renderer *------------------------------------------------------------------------------------------*/ decoder_config.Opt_Headrotation = 0; +#ifdef FIX_197_CREND_INTERFACE + ivas_rend_openCrend( &st_ivas.hCrendWrapper, getRendAudioConfigFromIvasAudioConfig( st_ivas.transport_config ), getRendAudioConfigFromIvasAudioConfig( st_ivas.transport_config ), st_ivas.hRenderConfig, st_ivas.hDecoderConfig->Opt_Headrotation, pIo_params->sample_rate ); +#else ivas_crend_open( &st_ivas ); +#endif /*------------------------------------------------------------------------------------------* * In/out buffer memory allocation for encoder @@ -1846,7 +1903,11 @@ ivas_result_t ivas_object_mixer_renderer( ivas_crend_io_params_t *pIo_params, in if ( IVAS_SUCCESS != result ) { fprintf( stderr, "Error: ivas_crend_process failed with %d \n\n", (int32_t) result ); +#ifdef FIX_197_CREND_INTERFACE + ivas_rend_closeCrend( &st_ivas.hCrendWrapper ); +#else ivas_crend_close( &st_ivas ); +#endif exit( -1 ); } @@ -1899,7 +1960,11 @@ ivas_result_t ivas_object_mixer_renderer( ivas_crend_io_params_t *pIo_params, in #endif printf( "Total Frames Processed : %lld\n", (long long int) frame_count ); +#ifdef FIX_197_CREND_INTERFACE + ivas_rend_closeCrend( &st_ivas.hCrendWrapper ); +#else ivas_crend_close( &st_ivas ); +#endif return IVAS_SUCCESS; } -- GitLab From 0c07e259b669f9939556fa1466da8539207afc57 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 18 Jan 2023 10:31:35 +0100 Subject: [PATCH 2/8] - correctly handle error return for refactored function calls - change return type of ivas_rend_closeCrend to void - replace references to "SPAR Crend" by just "Crend" - minor formatting --- lib_com/ivas_prot.h | 4 ++++ lib_dec/ivas_dec.c | 26 ++++++++++++++++++++++++-- lib_dec/ivas_init_dec.c | 16 ++++++++++++---- lib_dec/ivas_ism_param_dec.c | 10 +++++++++- lib_dec/ivas_mct_dec.c | 32 ++++++++++++++++++-------------- lib_dec/ivas_sba_dec.c | 15 ++++++++++++--- lib_rend/ivas_binauralRenderer.c | 2 +- lib_rend/ivas_crend.c | 16 ++++++++++------ lib_rend/lib_rend.c | 11 +++++++---- 9 files changed, 97 insertions(+), 35 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 6c95f13fe2..97c57084e0 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5383,7 +5383,11 @@ ivas_error ivas_rend_initCrend( RENDER_CONFIG_DATA *hRendCfg, const int32_t output_Fs ); +#ifdef FIX_197_CREND_INTERFACE +void ivas_rend_closeCrend( +#else ivas_error ivas_rend_closeCrend( +#endif CREND_WRAPPER_HANDLE *pCrend ); ivas_error ivas_rend_crendProcess( diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index c9c2e309ff..452284cfb3 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -208,7 +208,18 @@ ivas_error ivas_dec( else if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) { #ifdef FIX_197_CREND_INTERFACE - ivas_rend_crendProcess( st_ivas->hCrendWrapper, IVAS_REND_AUDIO_CONFIG_7_1_4, IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM, st_ivas->hDecoderConfig, st_ivas->hHeadTrackData, &st_ivas->hIntSetup, NULL, output, output_Fs ); + if ( ( error = ivas_rend_crendProcess( st_ivas->hCrendWrapper, + IVAS_REND_AUDIO_CONFIG_7_1_4, + IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM, + st_ivas->hDecoderConfig, + st_ivas->hHeadTrackData, + &st_ivas->hIntSetup, + NULL, + output, + output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } #else ivas_crend_process( st_ivas, output ); #endif @@ -394,7 +405,18 @@ ivas_error ivas_dec( if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) { #ifdef FIX_197_CREND_INTERFACE - ivas_rend_crendProcess( st_ivas->hCrendWrapper, getRendAudioConfigFromIvasAudioConfig( st_ivas->intern_config ), getRendAudioConfigFromIvasAudioConfig( st_ivas->hOutSetup.output_config ), st_ivas->hDecoderConfig, st_ivas->hHeadTrackData, &st_ivas->hIntSetup, st_ivas->hEFAPdata, output, output_Fs ); + if ( ( error = ivas_rend_crendProcess( st_ivas->hCrendWrapper, + getRendAudioConfigFromIvasAudioConfig( st_ivas->intern_config ), + getRendAudioConfigFromIvasAudioConfig( st_ivas->hOutSetup.output_config ), + st_ivas->hDecoderConfig, + st_ivas->hHeadTrackData, + &st_ivas->hIntSetup, + st_ivas->hEFAPdata, + output, + output_Fs ) != IVAS_ERR_OK ) ) + { + return error; + } #else ivas_crend_process( st_ivas, output ); #endif diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 61171b1a89..f2fdf1f9b0 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1148,14 +1148,14 @@ ivas_error ivas_init_decoder( #ifdef FIX_197_CREND_INTERFACE if ( ( st_ivas->hCrendWrapper = (CREND_WRAPPER_HANDLE) malloc( sizeof( CREND_WRAPPER ) ) ) == NULL ) { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR Crend Wrapper\n" ); + 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 ) #else if ( ( st_ivas->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) #endif { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR Crend\n" ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend\n" ); } } } @@ -1178,12 +1178,20 @@ ivas_error ivas_init_decoder( #ifdef FIX_197_CREND_INTERFACE if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM && st_ivas->ivas_format == MC_FORMAT && st_ivas->hDecoderConfig->Opt_Headrotation ) { - if ( ( error = efap_init_data( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth, st_ivas->hIntSetup.ls_elevation, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + if ( ( error = efap_init_data( &( st_ivas->hEFAPdata ), + st_ivas->hIntSetup.ls_azimuth, + st_ivas->hIntSetup.ls_elevation, + st_ivas->hIntSetup.nchan_out_woLFE, + EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) { return error; } } - if ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), getRendAudioConfigFromIvasAudioConfig( st_ivas->intern_config ), getRendAudioConfigFromIvasAudioConfig( st_ivas->hDecoderConfig->output_config ), st_ivas->hRenderConfig, st_ivas->hDecoderConfig->Opt_Headrotation, st_ivas->hDecoderConfig->output_Fs ) != IVAS_ERR_OK ) + if ( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), + getRendAudioConfigFromIvasAudioConfig( st_ivas->intern_config ), + getRendAudioConfigFromIvasAudioConfig( st_ivas->hDecoderConfig->output_config ), + st_ivas->hRenderConfig, st_ivas->hDecoderConfig->Opt_Headrotation, + st_ivas->hDecoderConfig->output_Fs ) != IVAS_ERR_OK ) ) { return error; } diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 2ad266ee9c..d8c9908bf2 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -1086,7 +1086,15 @@ static ivas_error ivas_ism_bitrate_switching( /* Open Crend Binaural renderer */ #ifdef FIX_197_CREND_INTERFACE - ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), getRendAudioConfigFromIvasAudioConfig( st_ivas->intern_config ), getRendAudioConfigFromIvasAudioConfig( st_ivas->hOutSetup.output_config ), st_ivas->hRenderConfig, st_ivas->hDecoderConfig->Opt_Headrotation, st_ivas->hDecoderConfig->output_Fs ); + if ( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), + getRendAudioConfigFromIvasAudioConfig( st_ivas->intern_config ), + getRendAudioConfigFromIvasAudioConfig( st_ivas->hOutSetup.output_config ), + st_ivas->hRenderConfig, + st_ivas->hDecoderConfig->Opt_Headrotation, + st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } #else ivas_crend_open( st_ivas ); #endif diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 75ecc6f923..104efadd9b 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -1097,11 +1097,11 @@ static ivas_error ivas_mc_dec_reconfig( { if ( ( st_ivas->hCrendWrapper = (CREND_WRAPPER_HANDLE) malloc( sizeof( CREND_WRAPPER ) ) ) == NULL ) { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR Crend Wrapper\n" ); + 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 ) { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR Crend\n" ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend\n" ); } } #else @@ -1109,30 +1109,34 @@ static ivas_error ivas_mc_dec_reconfig( { if ( ( st_ivas->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR Crend\n" ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend\n" ); } } -#endif +#endif } #ifdef FIX_197_CREND_INTERFACE else if ( st_ivas->hCrendWrapper == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) { - if ( ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), getRendAudioConfigFromIvasAudioConfig( st_ivas->intern_config ), getRendAudioConfigFromIvasAudioConfig( st_ivas->hDecoderConfig->output_config ), st_ivas->hRenderConfig, st_ivas->hDecoderConfig->Opt_Headrotation, st_ivas->hDecoderConfig->output_Fs ) != IVAS_ERR_OK ) + if ( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), + getRendAudioConfigFromIvasAudioConfig( st_ivas->intern_config ), + getRendAudioConfigFromIvasAudioConfig( st_ivas->hDecoderConfig->output_config ), + st_ivas->hRenderConfig, st_ivas->hDecoderConfig->Opt_Headrotation, + st_ivas->hDecoderConfig->output_Fs ) != IVAS_ERR_OK ) ) { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "ivas_crend_open failed" ); + return error; } } #else - } - else if ( st_ivas->hCrend == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) + } + else if ( st_ivas->hCrend == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) + { + if ( ivas_crend_open( st_ivas ) != IVAS_ERR_OK ) { - if ( ivas_crend_open( st_ivas ) != IVAS_ERR_OK ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "ivas_crend_open failed" ); - } + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "ivas_crend_open failed" ); } - - #endif + } + +#endif } /* mono/stereo */ else if ( output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO ) diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 09060dc23b..984ce22cb1 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -468,14 +468,14 @@ ivas_error ivas_sba_dec_reinit( #ifdef FIX_197_CREND_INTERFACE if ( ( st_ivas->hCrendWrapper = (CREND_WRAPPER_HANDLE) malloc( sizeof( CREND_WRAPPER ) ) ) == NULL ) { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR CrendWrapper\n" ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CrendWrapper\n" ); } if ( ( st_ivas->hCrendWrapper->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) #else if ( ( st_ivas->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) #endif { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR Crend\n" ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend\n" ); } } } @@ -496,12 +496,21 @@ ivas_error ivas_sba_dec_reinit( else if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) { #ifdef FIX_197_CREND_INTERFACE - if ( ivas_rend_openCrend( &st_ivas->hCrendWrapper, getRendAudioConfigFromIvasAudioConfig( st_ivas->intern_config ), getRendAudioConfigFromIvasAudioConfig( st_ivas->hDecoderConfig->output_config ), st_ivas->hRenderConfig, st_ivas->hDecoderConfig->Opt_Headrotation, st_ivas->hDecoderConfig->output_Fs ) != IVAS_ERR_OK ) + if ( ( error = ivas_rend_openCrend( &st_ivas->hCrendWrapper, + getRendAudioConfigFromIvasAudioConfig( st_ivas->intern_config ), + getRendAudioConfigFromIvasAudioConfig( st_ivas->hDecoderConfig->output_config ), + st_ivas->hRenderConfig, + t_ivas->hDecoderConfig->Opt_Headrotation, + st_ivas->hDecoderConfig->output_Fs ) != IVAS_ERR_OK ) ) #else if ( ivas_crend_open( st_ivas ) != IVAS_ERR_OK ) #endif { +#ifdef FIX_197_CREND_INTERFACE + return error; +#else return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "ivas_crend_open failed" ); +#endif } } ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses ); diff --git a/lib_rend/ivas_binauralRenderer.c b/lib_rend/ivas_binauralRenderer.c index ed98cb764a..6503e8e1f7 100644 --- a/lib_rend/ivas_binauralRenderer.c +++ b/lib_rend/ivas_binauralRenderer.c @@ -792,7 +792,7 @@ void ivas_binaural_add_LFE( if ( render_lfe ) { #ifdef FIX_197_CREND_INTERFACE - gain = ( st_ivas->hCrendWrapper != NULL ) && ( st_ivas->hCrendWrapper->hHrtfCrend != NULL ) ? st_ivas->hCrendWrapper->hHrtfCrend->gain_lfe : GAIN_LFE; + gain = ( ( st_ivas->hCrendWrapper != NULL ) && ( st_ivas->hCrendWrapper->hHrtfCrend != NULL ) ) ? st_ivas->hCrendWrapper->hHrtfCrend->gain_lfe : GAIN_LFE; #else gain = st_ivas->hHrtf != NULL ? st_ivas->hHrtf->gain_lfe : GAIN_LFE; #endif diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index cf1d0ea098..55b7e55bf6 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -153,6 +153,7 @@ static ivas_error ivas_hrtf_close( } +#ifndef FIX_197_CREND_INTERFACE /*------------------------------------------------------------------------- * ivas_crend_init_from_rom() * @@ -653,6 +654,7 @@ ivas_error ivas_crend_init_from_rom( return IVAS_ERR_OK; } +#endif #ifndef FIX_197_CREND_INTERFACE /*------------------------------------------------------------------------- @@ -1175,14 +1177,14 @@ ivas_error ivas_rend_openCrend( #ifdef FIX_197_CREND_INTERFACE if ( pCrend == NULL ) { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR Crend Wrapper\n" ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Wrapper\n" ); } if ( *pCrend == NULL ) { if ( ( *pCrend = (CREND_WRAPPER_HANDLE) malloc( sizeof( CREND_WRAPPER ) ) ) == NULL ) { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR Crend Wrapper\n" ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Wrapper\n" ); } ( *pCrend )->binaural_latency_ns = 0; ( *pCrend )->hCrend = NULL; @@ -1753,10 +1755,11 @@ ivas_error ivas_rend_initCrend( * Deallocate Crend renderer handle *------------------------------------------------------------------------*/ -ivas_error ivas_rend_closeCrend( #ifdef FIX_197_CREND_INTERFACE +void ivas_rend_closeCrend( CREND_WRAPPER_HANDLE *pCrend ) #else +ivas_error ivas_rend_closeCrend( CREND_WRAPPER *pCrend ) #endif { @@ -1765,12 +1768,12 @@ ivas_error ivas_rend_closeCrend( #ifdef FIX_197_CREND_INTERFACE if ( pCrend == NULL ) { - return IVAS_ERR_OK; + return; } if ( *pCrend == NULL ) { - return IVAS_ERR_OK; + return; } if ( ( *pCrend )->hHrtfCrend != NULL ) @@ -1835,6 +1838,7 @@ ivas_error ivas_rend_closeCrend( free( *pCrend ); *pCrend = NULL; } + return; #else if ( pCrend->hHrtfCrend != NULL ) { @@ -1896,8 +1900,8 @@ ivas_error ivas_rend_closeCrend( free( pCrend->hCrend ); pCrend->hCrend = NULL; } -#endif return IVAS_ERR_OK; +#endif } /*-----------------------------------------------------------------------------------------* diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 54d18072f7..e7c78b2690 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -305,7 +305,7 @@ static int32_t limitRendererOutput( #ifdef FIX_197_CREND_INTERFACE AUDIO_CONFIG getIvasAudioConfigFromRendAudioConfig( #else -static AUDIO_CONFIG rendAudioConfigToIvasAudioConfig( // VE2AT: similar is defined again at line 397, why?#endif +static AUDIO_CONFIG rendAudioConfigToIvasAudioConfig( // VE2AT: similar is defined again at line 397, why? #endif IVAS_REND_AudioConfig rendConfig ) { @@ -487,6 +487,10 @@ AUDIO_CONFIG getIvasAudioConfigFromRendAudioConfig( return IVAS_REND_AUDIO_CONFIG_HOA2; case AUDIO_CONFIG_HOA3: return IVAS_REND_AUDIO_CONFIG_HOA3; + default: + break; + } + return IVAS_REND_AUDIO_CONFIG_UNKNOWN; #else case IVAS_REND_AUDIO_CONFIG_MONO: return AUDIO_CONFIG_MONO; @@ -512,12 +516,11 @@ AUDIO_CONFIG getIvasAudioConfigFromRendAudioConfig( return AUDIO_CONFIG_HOA2; case IVAS_REND_AUDIO_CONFIG_HOA3: return AUDIO_CONFIG_HOA3; -#endif default: break; } - return AUDIO_CONFIG_INVALID; +#endif } static ivas_error initLimiter( @@ -5069,4 +5072,4 @@ ivas_error ivas_rend_initEfap( return err; } -#endif \ No newline at end of file +#endif -- GitLab From 2652552fcdff92c2b7ec95f9126cc8aa3e59b47c Mon Sep 17 00:00:00 2001 From: muxe6256 Date: Wed, 18 Jan 2023 16:19:57 +0100 Subject: [PATCH 3/8] fix IVAS_REND_LfePanMtx declaration --- lib_rend/ivas_stat_rend.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index fe247287ce..b710202ce3 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -48,6 +48,9 @@ #define RENDERER_HEAD_POSITIONS_PER_FRAME 4 // todo (Marc) -> renanr IVAS_RENDERER_HEAD_POSITIONS_PER_FRAME ? +#ifdef REND_CFG_LFE +typedef float IVAS_REND_LfePanMtx[IVAS_MAX_INPUT_LFE_CHANNELS][IVAS_MAX_OUTPUT_CHANNELS]; +#endif typedef struct { int16_t numSamplesPerChannel; -- GitLab From 81d7c6b387301df7d992ec53265a772ce1eb7c12 Mon Sep 17 00:00:00 2001 From: muxe6256 Date: Wed, 18 Jan 2023 16:28:55 +0100 Subject: [PATCH 4/8] remove ivas_unittests --- .../unit_tests/crend/ivas_crend_utest_utils.c | 1970 ----------------- 1 file changed, 1970 deletions(-) delete mode 100644 scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c deleted file mode 100644 index ea0bf89fee..0000000000 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c +++ /dev/null @@ -1,1970 +0,0 @@ -/****************************************************************************************************** - - (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/**************************************************************************** - * File description - - * This source file contains utility definitions specific to IVAS common renderer unit tests - ****************************************************************************/ - - -/*------------------------------------------------------------------------------------------* - * include header files - *------------------------------------------------------------------------------------------*/ - -#include "stdio.h" -#include "stdlib.h" -#include "string.h" -#include -#include -#include "options.h" -#include "ivas_dec_parse_io.h" -#include "ivas_crend_public.h" -#include "ivas_stat_dec.h" -#include "ivas_prox_mix.h" -#include "prot.h" -#include "ivas_prot.h" -#include "cmdl_tools.h" -#include "ivas_stat_dec.h" -#include "ivas_cnst.h" -#include "assert.h" -#include "ivas_rom_binaural_crend_head.h" -#include "ivas_rom_binauralRenderer.h" -#include "ivas_rom_com.h" -#include "head_rotation_file_reader.h" -#include "options.h" -#include "render_config_reader.h" -#include "wmc_auto.h" -#ifdef FIX_197_CREND_INTERFACE -#include "lib_rend.h" -#endif - -static int32_t ivas_check_rounding( float binaural_latencys_s[3], int16_t use_round_latency, int16_t use_round_for_lfe, int32_t *err_lfe, int32_t *err_dec, int16_t verbose ) -{ - // float delay_ns_float[3]; - int32_t delay_ns[3]; - - float sampleRates[3] = { 48000.f, 32000.f, 16000.f }; - - // float binaural_latencys_s[3] = { 1.f / 48000.f, 2.f / 48000.f, 3.f / 48000.f }; - - int32_t delay_lfe[3][3]; - - int32_t delay_dec[3][3]; - - int32_t wanted; - - *err_lfe = 0; - *err_dec = 0; - - for ( int ind1 = 0; ind1 < 3; ind1++ ) - { - if ( verbose ) - printf( "\nsample rate = %f", sampleRates[ind1] ); - - for ( int ind2 = 0; ind2 < 3; ind2++ ) - { - wanted = (int32_t) roundf( binaural_latencys_s[ind2] * sampleRates[ind1] ); - if ( verbose ) - printf( "\nbinaural_latencys_s = %f wanted = %d", binaural_latencys_s[ind2], wanted ); - if ( use_round_latency ) - delay_ns[ind2] = (int32_t) roundf( binaural_latencys_s[ind2] * 1000000000.f ); - else - delay_ns[ind2] = (int32_t) ( binaural_latencys_s[ind2] * 1000000000.f ); - if ( verbose ) - printf( "\n delay_ns[%d] = %d \n", ind2, delay_ns[ind2] ); - - if ( use_round_for_lfe ) - delay_lfe[ind1][ind2] = (int32_t) roundf( delay_ns[ind2] * sampleRates[ind1] / 1000000000.f ); - else - delay_lfe[ind1][ind2] = (int32_t) NS2SA( sampleRates[ind1], delay_ns[ind2] ); - if ( verbose ) - printf( "\ndelay_lfe[%d][%d] = %d\n", ind1, ind2, delay_lfe[ind1][ind2] ); - - *err_lfe += abs( delay_lfe[ind1][ind2] - wanted ); - - delay_dec[ind1][ind2] = NS2SA( sampleRates[ind1], (float) delay_ns[ind2] + 0.5f ); - /* delay_dec[ind1][ind2] = NS2SA( sampleRates[ind1], (float) delay_ns[ind2] );*/ - - if ( verbose ) - printf( "\ndelay_dec[%d][%d] = %d \n", ind1, ind2, delay_dec[ind1][ind2] ); - - *err_dec += abs( delay_dec[ind1][ind2] - wanted ); - } - } - return *err_lfe + *err_dec; -} - - -static ivas_result_t ivas_dec_default_io_params( ivas_dec_io_params_t *pIO_params ) -{ - memset( pIO_params, 0, sizeof( ivas_dec_io_params_t ) ); - pIO_params->quiet_mode = IVAS_DEFAULT_QUIET_MODE; - pIO_params->no_delay_cmp = IVAS_DEFAULT_NO_DELAY_COMP_MODE; - pIO_params->bs_format = IVAS_DEFAULT_BS_FORMAT; - pIO_params->out_fmt = IVAS_DEFAULT_FMT; - pIO_params->in_fmt = IVAS_DEFAULT_FMT; - pIO_params->lfe_ch_idx = IVAS_DEFAULT_LFE_CH_IDX; - pIO_params->block_offset_ms = IVAS_EXT_ADD_DELAY_MS; - pIO_params->no_diegetic_pan = 0; - pIO_params->orientation_tracking = OTR_TRACKING_NONE; - - return IVAS_SUCCESS; -} - -/*------------------------------------------------------------------------- - * ivas_hrtf_init() - * - * Initialize hHrtf handle - *------------------------------------------------------------------------*/ - -static ivas_error ivas_hrtf_init( - HRTFS_DATA *hHrtf /* i/o: HRTF handle */ -) -{ - int16_t i, j; - - if ( hHrtf == NULL ) - { - return IVAS_ERR_WRONG_PARAMS; - } - - hHrtf->latency_s = 0; - hHrtf->max_num_ir = 0; - hHrtf->max_num_iterations = 0; - hHrtf->gain_lfe = 0; - hHrtf->index_frequency_max_diffuse = 0; - - for ( i = 0; i < IVAS_MAX_NUM_CH; i++ ) - { - hHrtf->inv_diffuse_weight[i] = 0; - for ( j = 0; j < BINAURAL_CHANNELS; j++ ) - { - hHrtf->num_iterations[i][j] = 0; - hHrtf->pIndex_frequency_max[i][j] = NULL; - hHrtf->pOut_to_bin_re[i][j] = NULL; - hHrtf->pOut_to_bin_im[i][j] = NULL; - } - } - for ( j = 0; j < BINAURAL_CHANNELS; j++ ) - { - hHrtf->num_iterations_diffuse[j] = 0; - hHrtf->pIndex_frequency_max_diffuse[j] = NULL; - hHrtf->pOut_to_bin_diffuse_re[j] = NULL; - hHrtf->pOut_to_bin_diffuse_im[j] = NULL; - } - - return IVAS_ERR_OK; -} - -AUDIO_CONFIG ivas_crend_map_out_fmt( - IVAS_IN_OUT_FMT_CONFIG fmt ) -{ - switch ( fmt ) - { - case MONO_1: - return AUDIO_CONFIG_MONO; - case STEREO_2: - return AUDIO_CONFIG_STEREO; - case BIN_2: - return AUDIO_CONFIG_BINAURAL; - case FOA_4: - return AUDIO_CONFIG_FOA; - case HOA_9: - return AUDIO_CONFIG_HOA2; - case HOA_16: - return AUDIO_CONFIG_HOA3; - case MULT_CH_5_1: - return AUDIO_CONFIG_5_1; - case MULT_CH_7_1: - return AUDIO_CONFIG_7_1; - case MULT_CH_5_1_2: - return AUDIO_CONFIG_5_1_2; - case MULT_CH_5_1_4: - return AUDIO_CONFIG_5_1_4; - case MULT_CH_7_1_4: - return AUDIO_CONFIG_7_1_4; - default: - return -1; - } -} - -const char *ivas_crend_map_in_fmt( - IVAS_IN_OUT_FMT_CONFIG fmt ) -{ - switch ( fmt ) - { - case MONO_1: - case STEREO_2: - case MULT_CH_5_1: - case MULT_CH_7_1: - case MULT_CH_5_1_2: - case MULT_CH_5_1_4: - case MULT_CH_7_1_4: - return IVAS_IN_FMT_COMBINED; - case FOA_4: - case HOA_9: - case HOA_16: - return IVAS_IN_FMT_HOA_3; - default: - return ""; - } -} - - -int16_t ivas_get_num_channels( - const int16_t ch_format ) -{ - int16_t num_channels = 0; - - switch ( ch_format ) - { - case MONO_1: - num_channels = 1; - break; - case BIN_2: - case STEREO_2: - num_channels = 2; - break; - case FOA_4: - num_channels = FOA_CHANNELS; - break; - case MULT_CH_5_1: - num_channels = 6; - break; - case MULT_CH_7_1: - num_channels = 8; - break; - case HOA_9: - num_channels = 9; - break; - case HOA_16: - num_channels = 16; - break; - case OBA: - num_channels = 8; - break; - case MULT_CH_5_1_2: - num_channels = 8; - break; - case MULT_CH_5_1_4: - num_channels = 10; - break; - case MULT_CH_7_1_4: - num_channels = 12; - break; - default: - assert( !"Not supported Input format for Common Renderer!" ); - break; - } - - return num_channels; -} - -static ivas_result_t ivas_crend_mixer( - float ppPcm_in[][L_FRAME48k], - float ppPcm_out[][L_FRAME48k], - int16_t in_ch, - int16_t out_ch, - const float *pMixer_gain, - const int16_t frame_len ) -{ - int16_t i, j, k, offset; - - for ( i = 0; i < out_ch; i++ ) - { - offset = i * in_ch; - - for ( j = 0; j < frame_len; j++ ) - { - float temp = 0; - const float *pMixer = &pMixer_gain[offset]; - - for ( k = 0; k < in_ch; k++ ) - { - temp += ( ppPcm_in[k][j] * pMixer[k] ); - } - ppPcm_out[i][j] = temp; - } - } - - return IVAS_SUCCESS; -} - -/* prototypes */ -static void ivas_copy_io_params_to_dec_io_params( ivas_crend_io_params_t *pIo_params, ivas_dec_io_params_t *pDec_io_params ); -ivas_result_t ivas_crend_copy_latencies_to_io_params( ivas_crend_io_params_t *pIo_params, HRTFS_DATA *pCrend_hrtfs ); - - -/*-----------------------------------------------------------------------------------------* - * Function description - - * Unit test usage details - * - * Inputs - - * - * Outputs - - * - *-----------------------------------------------------------------------------------------*/ -static void ivas_crend_unit_test_usage( void ) -{ - fprintf( stdout, "Usage: ivas_crend_unit_test.exe -test -sr -ifmt -ofmt [options]\n\n" ); - - fprintf( stdout, "Mandatory arguments:\n" ); - fprintf( stdout, "--------------------\n" ); - fprintf( stdout, "-test : Test case for binaural renderer to run (crend = 1, fastconv = 2, param = 3, td = 4)\n" ); - fprintf( stdout, "-sr : Sampling rate in kHz\n" ); - fprintf( stdout, "\nOptional arguments:\n" ); - fprintf( stdout, "---------------------\n" ); - fprintf( stdout, "-ifmt : Input format index\n" ); - fprintf( stdout, " (0 - MONO, 1 - STEREO, 2 - BINAURAL, 3 - FOA, 4 - 5.1, 5 - 7.1, 6 - 5.1.2, 7 - 5.1.4, 8 - 7.1.4, 9 - HOA2, 10 - HOA3)\n" ); - fprintf( stdout, "-ofmt : Output format index\n" ); - fprintf( stdout, " (0 - MONO, 1 - STEREO, 2 - BINAURAL, 3 - FOA, 4 - 5.1, 5 - 7.1, 6 - 5.1.2, 7 - 5.1.4, 8 - 7.1.4, 9 - HOA2, 10 - HOA3)\n" ); - fprintf( stdout, "-i : Input path/file\n" ); - fprintf( stdout, "-o : Output file\n" ); - fprintf( stdout, "-r : Reference path/file\n" ); - fprintf( stdout, "-otr : orientation tracker mode\n" ); - fprintf( stdout, "-t : CSV files path\n" ); - fprintf( stdout, "-prox : prox files path\n" ); - fprintf( stdout, "-zero_tol : ability to force some tests to check for bitexactness\n" ); - fprintf( stdout, "-limiter : add limiter\n" ); - fprintf( stdout, "-lp_lfe : add low pass filtering on LFE channel\n" ); - fprintf( stdout, "-no_delay_cmp : avoid delay conpensation on output wav file\n" ); - fprintf( stdout, "-brir : use default brir if available for de specified binaural renderer\n" ); - fprintf( stdout, "-render_config file : Renderer configuration file\n" ); - fprintf( stdout, "-no_diegetic_pan : panning mono no dietic sound to stereo -1<= pan <=1,\n" ); - fprintf( stdout, " left or l or 1->left, right or r or -1->right, center or c or 0->middle\n" ); - - fprintf( stdout, "\n" ); - - exit( -1 ); -} - -/*-----------------------------------------------------------------------------------------* - * Function description - - * Set default IO parameters to 0 - * - * Inputs - - * ivas_crend_io_params_t *pIO_params - * - * Outputs - - * ivas_crend_io_params_t *pIO_params - * - *-----------------------------------------------------------------------------------------*/ -ivas_result_t ivas_crend_default_io_params( ivas_crend_io_params_t *pIO_params ) -{ - memset( pIO_params, 0, sizeof( ivas_crend_io_params_t ) ); - pIO_params->tol = TC_TOL; - pIO_params->orientation_tracking = OTR_TRACKING_NONE; - - return IVAS_SUCCESS; -} - -/*-----------------------------------------------------------------------------------------* - * Function description - - * Get frame length - * - * Inputs - - * int32_t sample_rate - * - * Outputs - - * - *-----------------------------------------------------------------------------------------*/ -int16_t ivas_wrapper_get_frame_len( int32_t sample_rate ) -{ - return ( (int16_t) ( sample_rate / FRAMES_PER_SEC ) ); -} - -/*-----------------------------------------------------------------------------------------* - * Function description - - * Set config parameters - * - * Inputs - - * ivas_crend_io_params_t *p_io_params - * ivas_crend_hrtfs_t *pCrend_hrtfs - * - * Outputs - - * ivas_dec_cfg_t *pDec_cfg - *-----------------------------------------------------------------------------------------*/ -static ivas_result_t ivas_crend_set_config_params( - DECODER_CONFIG_HANDLE hDecoderConfig, - ivas_dec_io_params_t *p_io_params, - int16_t *in_format, - int16_t *lfe_ch_idx ) -{ - *in_format = p_io_params->in_fmt; - hDecoderConfig->output_config = ivas_crend_map_out_fmt( p_io_params->out_fmt ); - - *lfe_ch_idx = p_io_params->lfe_ch_idx; - - hDecoderConfig->nchan_out = audioCfg2channels( hDecoderConfig->output_config ); - - hDecoderConfig->output_Fs = p_io_params->out_sample_rate; - hDecoderConfig->no_diegetic_pan = p_io_params->no_diegetic_pan; - - return IVAS_SUCCESS; -} - -/*-----------------------------------------------------------------------------------------* - * Function description - - * Copy latencies to io_params - * - * Inputs - - * ivas_crend_hrtfs_t *pCrend_hrtfs - * - * Outputs - - * ivas_dec_cfg_t *pDec_cfg - *-----------------------------------------------------------------------------------------*/ -ivas_result_t ivas_crend_copy_latencies_to_io_params( ivas_crend_io_params_t *pIo_params, HRTFS_DATA *pCrend_hrtfs ) -{ -#ifdef FIX_FIX_I59 - pIo_params->latency_ns = (int32_t) ( pCrend_hrtfs->latency_s * 1000000000.f ); -#else - pIo_params->latency_s = pCrend_hrtfs->latency_s; -#endif - - return IVAS_SUCCESS; -} - -/*-----------------------------------------------------------------------------------------* - * Function description - - * Copy hrtf data to config parameters - * - * Inputs - - * ivas_crend_hrtfs_t *pCrend_hrtfs - * - * Outputs - - * ivas_dec_cfg_t *pDec_cfg - *-----------------------------------------------------------------------------------------*/ -ivas_result_t ivas_crend_copy_hrtf_data( HRTFS_DATA *hHrtf, HRTFS_DATA *pCrend_hrtfs ) -{ - int16_t i, j; - - hHrtf->latency_s = pCrend_hrtfs->latency_s; - hHrtf->max_num_ir = pCrend_hrtfs->max_num_ir; - hHrtf->max_num_iterations = pCrend_hrtfs->max_num_iterations; - hHrtf->gain_lfe = pCrend_hrtfs->gain_lfe; - - for ( i = 0; i < pCrend_hrtfs->max_num_ir; i++ ) - { - for ( j = 0; j < BINAURAL_CHANNELS; j++ ) - { - hHrtf->pOut_to_bin_re[i][j] = pCrend_hrtfs->pOut_to_bin_re[i][j]; - hHrtf->pOut_to_bin_im[i][j] = pCrend_hrtfs->pOut_to_bin_im[i][j]; - hHrtf->num_iterations[i][j] = pCrend_hrtfs->num_iterations[i][j]; - hHrtf->pIndex_frequency_max[i][j] = pCrend_hrtfs->pIndex_frequency_max[i][j]; - } - hHrtf->inv_diffuse_weight[i] = pCrend_hrtfs->inv_diffuse_weight[i]; - } - for ( j = 0; j < BINAURAL_CHANNELS; j++ ) - { - hHrtf->pOut_to_bin_diffuse_re[j] = pCrend_hrtfs->pOut_to_bin_diffuse_re[j]; - hHrtf->pOut_to_bin_diffuse_im[j] = pCrend_hrtfs->pOut_to_bin_diffuse_im[j]; - hHrtf->num_iterations_diffuse[j] = pCrend_hrtfs->num_iterations_diffuse[j]; - hHrtf->pIndex_frequency_max_diffuse[j] = pCrend_hrtfs->pIndex_frequency_max_diffuse[j]; - } - hHrtf->index_frequency_max_diffuse = pCrend_hrtfs->index_frequency_max_diffuse; - - return IVAS_SUCCESS; -} - - -/*-----------------------------------------------------------------------------------------* - * Function description - - * Open files corresponding to the reference tests - * - * Inputs - - * ivas_crend_io_params_t *pIo_params - * - * Outputs - - * ivas_crend_io_params_t *pIo_params - * - *-----------------------------------------------------------------------------------------*/ - -void ivas_open_files_crend( ivas_crend_io_params_t *pIo_params ) -{ - /* Input File */ -#ifdef USE_PCM_OUT - if ( ( pIo_params->fIn[0] = fopen( pIo_params->in_path, "rb" ) ) == NULL ) -#else - if ( AudioFileReader_open( &pIo_params->fIn[0], pIo_params->in_path, &pIo_params->sample_rate ) != IVAS_ERR_OK ) -#endif - { - fprintf( stderr, "Error: Input audio file %s could not be opened\n\n", pIo_params->in_path ); - ivas_crend_unit_test_usage(); - } - fprintf( stdout, "Input audio file: %s\n", pIo_params->in_path ); - - /* Reference File */ -#ifdef USE_PCM_OUT - if ( ( strlen( pIo_params->ref_path ) > 0 ) && ( ( pIo_params->fRef = fopen( pIo_params->ref_path, "rb" ) ) == NULL ) ) -#else - if ( ( strlen( pIo_params->ref_path ) > 0 ) && ( AudioFileReader_open( &pIo_params->fRef, pIo_params->ref_path, &pIo_params->sample_rate ) != IVAS_ERR_OK ) ) -#endif - { - fprintf( stderr, "Error: Reference audio file %s could not be opened\n\n", pIo_params->ref_path ); - ivas_crend_unit_test_usage(); - } - fprintf( stdout, "Reference audio file: %s\n", pIo_params->ref_path ); - - - /*if (pIo_params->test == CREND_IR_GREATER_960) - { - if ((pIo_params->custom_hrtf = fopen(pIo_params->sofa_path, "rb")) == NULL) - { - fprintf(stderr, "Error: Custom HRTF file %s could not be opened\n\n", pIo_params->sofa_path); - ivas_crend_unit_test_usage(); - } - }*/ - - - if ( pIo_params->test == CREND_ACOUSTIC_PROXIMITY ) - { - /* open proximity bitstream file */ - if ( ( pIo_params->fProx = fopen( pIo_params->prox_path, "rb" ) ) == NULL ) - { - fprintf( stderr, "Error: LocSharing bitstream file %s could not be opened\n\n", pIo_params->prox_path ); - ivas_crend_unit_test_usage(); - } - } - fprintf( stdout, "prox file or path: %s\n", pIo_params->prox_path ); -} - -/*-----------------------------------------------------------------------------------------* - * Function description - - * Parse the cmd line params into IO param structure - * - * Inputs - - * int argc - * char** argv - * - * Outputs - - * ivas_enc_io_params_t *pIO_params - * - * - *-----------------------------------------------------------------------------------------*/ -ivas_result_t ivas_crend_parse_io_params( int argc, char **argv, ivas_crend_io_params_t *pIo_params ) -{ - int i = 1; - int mandatory_args = 0; - int optional_args = 0; - int check_output_format_set = 0; - -#ifdef DEBUG_SBA - fprintf( stderr, "Number of cmd line args: %d\n", argc ); - fprintf( stderr, "CMD: " ); - while ( i < argc ) - { - /*printing with stderr so that it gets printed always*/ - fprintf( stderr, "%s ", argv[i++] ); - } - fprintf( stderr, "\n\n" ); - - i = 1; -#endif - - while ( i < argc ) - { - /*-----------------------------------------------------------------* - * Sampling rate - *-----------------------------------------------------------------*/ - if ( strcmp( to_upper( argv[i] ), "-SR" ) == 0 ) - { - pIo_params->sample_rate = atoi( argv[++i] ) * 1000; - if ( ( pIo_params->sample_rate != 8000 ) && ( pIo_params->sample_rate != 16000 ) && ( pIo_params->sample_rate != 32000 ) && ( pIo_params->sample_rate != 48000 ) ) - { - fprintf( stderr, "Error: %d kHz is not a supported sampling rate\n\n", atoi( argv[i] ) ); - ivas_crend_unit_test_usage(); - } - i++; - mandatory_args++; - } - /*-----------------------------------------------------------------* - *render config - *-----------------------------------------------------------------*/ - else if ( strcmp( to_upper( argv[i] ), "-RENDER_CONFIG" ) == 0 ) - { - pIo_params->renderConfigFilename[0] = '\0'; - pIo_params->renderConfigEnabled = true; - strcpy( pIo_params->renderConfigFilename, argv[++i] ); - - if ( pIo_params->renderConfigFilename[0] == '\0' ) - { - fprintf( stderr, "Error: Renderer configuration file path not specified\n\n" ); - ivas_crend_unit_test_usage(); - } - i++; - optional_args++; - } - /*-----------------------------------------------------------------* - * Input Format - *-----------------------------------------------------------------*/ - else if ( strcmp( to_upper( argv[i] ), "-IFMT" ) == 0 ) - { - pIo_params->in_fmt = atoi( argv[++i] ); - if ( ( pIo_params->in_fmt != MONO_1 ) && ( pIo_params->in_fmt != STEREO_2 ) && ( pIo_params->in_fmt != BIN_2 ) && ( pIo_params->in_fmt != FOA_4 ) && ( pIo_params->in_fmt != HOA_9 ) && ( pIo_params->in_fmt != HOA_16 ) && ( pIo_params->in_fmt != MULT_CH_5_1 ) && ( pIo_params->in_fmt != MULT_CH_7_1 ) && ( pIo_params->in_fmt != MULT_CH_5_1_2 ) && ( pIo_params->in_fmt != MULT_CH_5_1_4 ) && ( pIo_params->in_fmt != MULT_CH_7_1_4 ) && ( pIo_params->in_fmt != OBA ) ) - { - fprintf( stderr, "Error: Invalid input format\n\n" ); - ivas_crend_unit_test_usage(); - } - i++; - mandatory_args++; - } - /*-----------------------------------------------------------------* - * Output Format - *-----------------------------------------------------------------*/ - else if ( strcmp( to_upper( argv[i] ), "-OFMT" ) == 0 ) - { - pIo_params->out_fmt = atoi( argv[++i] ); - if ( ( pIo_params->out_fmt != MONO_1 ) && ( pIo_params->out_fmt != STEREO_2 ) && ( pIo_params->out_fmt != BIN_2 ) && ( pIo_params->out_fmt != FOA_4 ) && ( pIo_params->out_fmt != HOA_9 ) && ( pIo_params->out_fmt != HOA_16 ) && ( pIo_params->out_fmt != MULT_CH_5_1 ) && ( pIo_params->out_fmt != MULT_CH_7_1 ) && ( pIo_params->out_fmt != MULT_CH_5_1_2 ) && ( pIo_params->out_fmt != MULT_CH_5_1_4 ) && ( pIo_params->out_fmt != MULT_CH_7_1_4 ) ) - { - fprintf( stderr, "Error: Invalid output format\n\n" ); - ivas_crend_unit_test_usage(); - } - check_output_format_set = 1; - i++; - mandatory_args++; - } - /*-----------------------------------------------------------------* - * Input file(s) - *-----------------------------------------------------------------*/ - else if ( strcmp( to_upper( argv[i] ), "-I" ) == 0 ) - { - strcpy( pIo_params->in_path, argv[++i] ); - if ( pIo_params->in_path[0] == '\0' ) - { - fprintf( stderr, "Error: input folder %s could not be opened\n\n", argv[i] ); - ivas_crend_unit_test_usage(); - } - i++; - mandatory_args++; - } - - /*-----------------------------------------------------------------* - * Proximity file - *------------------------------------------------------------------*/ - else if ( strcmp( to_upper( argv[i] ), "-PROX" ) == 0 ) - { - if ( strlen( argv[++i] ) > IVAS_MAX_PATH_LEN ) - { - fprintf( stderr, "Error: input proximity path %s too big\n\n", argv[i] ); - ivas_crend_unit_test_usage(); - } - strcpy( pIo_params->prox_path, argv[i] ); - if ( pIo_params->prox_path[0] == '\0' ) - { - fprintf( stderr, "Error: input proximity folder %s could not be opened\n\n", argv[i] ); - ivas_crend_unit_test_usage(); - } - i++; - optional_args++; - } - /*-----------------------------------------------------------------* - * Input csv file - *-----------------------------------------------------------------*/ - else if ( strcmp( to_upper( argv[i] ), "-T" ) == 0 ) - { - if ( strlen( argv[++i] ) > IVAS_MAX_PATH_LEN ) - { - fprintf( stderr, "Error: input head orientation CSV file path %s too long\n\n", argv[i] ); - ivas_crend_unit_test_usage(); - } - strcpy( pIo_params->csv_path, argv[i] ); - if ( pIo_params->csv_path[0] == '\0' ) - { - fprintf( stderr, "Error: input head orientation CSV file %s could not be opened\n\n", argv[i] ); - ivas_crend_unit_test_usage(); - } - - i++; - optional_args++; - } - - /*-----------------------------------------------------------------* - * Orientation tracking - *-----------------------------------------------------------------*/ - else if ( strcmp( to_upper( argv[i] ), "-OTR" ) == 0 ) - { - char tmp[5]; - strcpy( tmp, argv[++i] ); - if ( strcmp( to_upper( tmp ), "AVG" ) == 0 ) - { - pIo_params->orientation_tracking = OTR_TRACKING_AVG_ORIENT; - } - else if ( strcmp( to_upper( tmp ), "REF" ) == 0 ) - { - pIo_params->orientation_tracking = OTR_TRACKING_REF_ORIENT; - } - else - { - fprintf( stderr, "Error: Invalid orientation tracking type\n\n" ); - ivas_crend_unit_test_usage(); - } - i++; - optional_args++; - } - - /*-----------------------------------------------------------------* - * Output file(s) - *-----------------------------------------------------------------*/ - else if ( strcmp( to_upper( argv[i] ), "-O" ) == 0 ) - { - if ( check_output_format_set == 0 ) - { - fprintf( stderr, "Error: Output format flag must be set beform output file name\n\n" ); - ivas_crend_unit_test_usage(); - } - if ( pIo_params->sample_rate == 0 ) - { - fprintf( stderr, "Error: Sample rate flag must be set beform output file name\n\n" ); - ivas_crend_unit_test_usage(); - } - strcpy( pIo_params->out_path, argv[++i] ); -#ifdef USE_PCM_OUT - if ( ( pIo_params->fOut = fopen( pIo_params->out_path, "wb+" ) ) == NULL ) -#else - if ( AudioFileWriter_open( &pIo_params->fOut, pIo_params->out_path, pIo_params->sample_rate, ivas_get_num_channels( pIo_params->out_fmt ) ) != IVAS_ERR_OK ) -#endif - { - fprintf( stderr, "Error: output audio file %s could not be opened\n\n", argv[i] ); - ivas_crend_unit_test_usage(); - } - fprintf( stdout, "Output audio file: %s\n", argv[i] ); - i++; - mandatory_args++; - } - /*-----------------------------------------------------------------* - * Reference file(s) path - *-----------------------------------------------------------------*/ - else if ( strcmp( to_upper( argv[i] ), "-R" ) == 0 ) - { - strcpy( pIo_params->ref_path, argv[++i] ); - if ( pIo_params->ref_path[0] == '\0' ) - { - fprintf( stderr, "Error: Ref folder %s could not be opened\n\n", argv[i] ); - ivas_crend_unit_test_usage(); - } - i++; - optional_args++; - } - /*-----------------------------------------------------------------* - * Test to Run - *-----------------------------------------------------------------*/ - else if ( strcmp( to_upper( argv[i] ), "-TEST" ) == 0 ) - { - pIo_params->test = atoi( argv[++i] ); - if ( pIo_params->test < 0 || pIo_params->test >= CREND_NUM_TESTS ) - { - fprintf( stderr, "Error: Invalid Test case\n\n" ); - ivas_crend_unit_test_usage(); - } - i++; - mandatory_args++; - } - /*-----------------------------------------------------------------* - * Use BRIR Length - *-----------------------------------------------------------------*/ - else if ( strcmp( to_upper( argv[i] ), "-BRIR" ) == 0 ) - { - pIo_params->use_brir = 1; - i++; - optional_args++; - } - /*-----------------------------------------------------------------* - * Apply low pass filter to LFE - *-----------------------------------------------------------------*/ - else if ( strcmp( to_upper( argv[i] ), "-LP_LFE" ) == 0 ) - { - pIo_params->lfe_lp_enable = 1; - i++; - optional_args++; - } - /*-----------------------------------------------------------------* - * Apply limiter - *-----------------------------------------------------------------*/ - else if ( strcmp( to_upper( argv[i] ), "-LIMITER" ) == 0 ) - { - pIo_params->limiter_enable = 1; - i++; - optional_args++; - } - /*-----------------------------------------------------------------* - * CREND non diegetic panning value - *-----------------------------------------------------------------*/ - else if ( strcmp( to_upper( argv[i] ), "-NO_DIEGETIC_PAN" ) == 0 ) - { - i++; - char *param = to_upper( argv[i++] ); - if ( ( strcmp( param, "CENTER" ) == 0 ) || ( strchr( param, 'C' ) != NULL ) ) - { - pIo_params->no_diegetic_pan = 0; - } - else if ( ( strcmp( param, "LEFT" ) == 0 ) || ( strchr( param, 'L' ) != NULL ) ) - { - pIo_params->no_diegetic_pan = -1; - } - else if ( ( strcmp( param, "RIGHT" ) == 0 ) || ( strchr( param, 'R' ) != NULL ) ) - { - pIo_params->no_diegetic_pan = 1; - } - else - { - pIo_params->no_diegetic_pan = (float) atof( param ); - } - optional_args++; - } - else if ( strcmp( to_upper( argv[i] ), "-ZERO_TOL" ) == 0 ) - { - pIo_params->tol = 0.0f; - i++; - optional_args++; - } - else if ( strcmp( to_upper( argv[i] ), "-NO_DELAY_CMP" ) == 0 ) - { - pIo_params->no_delay_cmp = 1; - i++; - optional_args++; - } - else - { - fprintf( stderr, "Error: Flag not found\n\n" ); - i++; - } - } - if ( mandatory_args != CREND_MAND_ARGS ) - { - fprintf( stderr, "Error: Not enough mandatory arguments\n\n" ); - ivas_crend_unit_test_usage(); - } - - return IVAS_SUCCESS; -} - -/*-----------------------------------------------------------------------------------------* - * Function description - - * Skip WAV header from a WAV file - * - * Inputs - - * FILE *in_file - * - * Outputs - - * - *-----------------------------------------------------------------------------------------*/ -ivas_result_t ivas_wav_header_skip( FILE *in_file ) -{ - int8_t data_start[4] = { 0 }; - int32_t check, count = 0; - int32_t length; - - check = 1; - while ( check ) - { - if ( data_start[0] == 'd' && data_start[1] == 'a' && - data_start[2] == 't' && data_start[3] == 'a' ) - { - ( fread( &length, 4, 1, in_file ) ); - check = 0; - } - else - { - data_start[0] = data_start[1]; - data_start[1] = data_start[2]; - data_start[2] = data_start[3]; - ( fread( &data_start[3], 1, 1, in_file ) ); - } - count++; - if ( count > 2000 ) - { - length = 0xffffffff; - return IVAS_FAILED; - } - } - return IVAS_SUCCESS; -} - -/*-----------------------------------------------------------------------------------------* - * Function description - - * Read/Generate inputs - * - * Inputs - - * ivas_enc_io_params_t *pIo_params - * - * Outputs - - * ivas_enc_in_buf_t *pIn_buf - * - * - *-----------------------------------------------------------------------------------------*/ -static ivas_result_t ivas_wrapper_get_in_buf( ivas_crend_io_params_t *pIo_params, float ppPcm_in[][L_FRAME48k] ) -{ - int16_t i = 0, j = 0, samples_read = 0, num_in_ch = 0; - int16_t offset; - int16_t input_frame_len = ivas_wrapper_get_frame_len( pIo_params->sample_rate ); - int16_t tmp, read = 0; - - num_in_ch = ivas_get_num_channels( pIo_params->in_fmt ); - if ( pIo_params->test == CREND_BIN_TEST || pIo_params->test == FASTCONV_BIN_TEST || pIo_params->test == PARAM_BIN_TEST || pIo_params->test == TD_BIN_TEST || pIo_params->test == CREND_ACOUSTIC_PROXIMITY ) - { - /* Read in PCM */ - for ( j = 0; j < input_frame_len; j++ ) - { - for ( i = 0; i < num_in_ch; i++ ) - { -#ifdef USE_PCM_OUT - if ( ( read = (int16_t) fread( &tmp, sizeof( int16_t ), 1, pIo_params->fIn[0] ) ) > 0 ) -#else - if ( ( AudioFileReader_read( pIo_params->fIn[0], &tmp, 1, &read ) == IVAS_ERR_OK ) && ( read > 0 ) ) -#endif - { - ppPcm_in[i][j] = (float) tmp; - // ppPcm_in[i][j] *= ( 1.0 / PCM16_TO_FLT_FAC ); - samples_read += 1; - } - else - { - if ( samples_read != 0 && samples_read < input_frame_len * num_in_ch ) - { - /* Setting remaining buffer to zeros */ - offset = samples_read / num_in_ch; - for ( i = 0; i < num_in_ch; i++ ) - { - set_zero( &ppPcm_in[i][offset], input_frame_len - offset ); - } - return IVAS_SUCCESS; - } - else - { - return IVAS_READ_DONE; - } - } - } - } - } - else - { - /* Read in PCM */ - for ( i = 0; i < num_in_ch; i++ ) - { - samples_read = 0; - for ( j = 0; j < input_frame_len; j++ ) - { -#ifdef USE_PCM_OUT - if ( ( read = (int16_t) fread( &tmp, sizeof( int16_t ), 1, pIo_params->fIn[i] ) ) > 0 ) -#else - if ( ( AudioFileReader_read( pIo_params->fIn[i], &tmp, 1, &read ) == IVAS_ERR_OK ) && ( read > 0 ) ) -#endif - { - ppPcm_in[i][j] = (float) tmp; - // ppPcm_in[i][j] *= ( 1.0 / PCM16_TO_FLT_FAC ); - samples_read += 1; - } - else - { - if ( samples_read != 0 && samples_read < input_frame_len ) - { - /* Setting remaining buffer to zeros */ - offset = samples_read; - set_zero( &ppPcm_in[i][offset], input_frame_len - offset ); - break; - } - else - { - return IVAS_READ_DONE; - } - } - } - } - } - - return IVAS_SUCCESS; -} -/*---------------------------------------------------------------------* - * ivas_feed_head_track_data( ) - * - * Feed the decoder with the head tracking data - *---------------------------------------------------------------------*/ - -static ivas_result_t ivas_feed_head_track_data( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - IVAS_QUATERNION *orientation /* i : head-tracking data */ -) -{ - HEAD_TRACK_DATA_HANDLE hHeadTrackData; - int16_t i; - - - hHeadTrackData = st_ivas->hHeadTrackData; - - if ( hHeadTrackData == NULL ) - { - return IVAS_FAILED; - } - - /* Move head-tracking data to the decoder handle */ - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - hHeadTrackData->Quaternions[i].w = orientation[i].w; - hHeadTrackData->Quaternions[i].x = orientation[i].x; - hHeadTrackData->Quaternions[i].y = orientation[i].y; - hHeadTrackData->Quaternions[i].z = orientation[i].z; - } - - st_ivas->hHeadTrackData->num_quaternions = 0; - - return IVAS_SUCCESS; -} - - -/*-----------------------------------------------------------------------------------------* - * Function description - - * Copy io_params to dec_io_params - * - * Inputs - - * ivas_crend_io_params_t *pIo_params - * - * Outputs - - * ivas_dec_io_params_t *pDec_io_params - * - *-----------------------------------------------------------------------------------------*/ -static void ivas_copy_io_params_to_dec_io_params( ivas_crend_io_params_t *pIo_params, ivas_dec_io_params_t *pDec_io_params ) -{ - pDec_io_params->in_fmt = pIo_params->in_fmt; - pDec_io_params->out_fmt = pIo_params->out_fmt; - pDec_io_params->out_sample_rate = pIo_params->sample_rate; - pDec_io_params->no_diegetic_pan = pIo_params->no_diegetic_pan; - pDec_io_params->renderConfigEnabled = pIo_params->renderConfigEnabled; - pDec_io_params->use_brir = pIo_params->use_brir; - strcpy( pDec_io_params->renderConfigFilename, pIo_params->renderConfigFilename ); - pDec_io_params->orientation_tracking = pIo_params->orientation_tracking; - switch ( pIo_params->in_fmt ) - { - case MULT_CH_5_1: - case MULT_CH_7_1: - case MULT_CH_5_1_2: - case MULT_CH_5_1_4: - case MULT_CH_7_1_4: - pDec_io_params->lfe_ch_idx = IVAS_DEFAULT_LFE_CH_IDX; - break; - case FOA_4: - case HOA_9: - case HOA_16: - default: - pDec_io_params->lfe_ch_idx = -1; - break; - } -} - -/*-----------------------------------------------------------------------------------------* - * Function description - - * Main Common Renderer block - * - * Inputs - - * ivas_enc_io_params_t io_params - * float* mixer - * int16_t delay_cmp - * - * Outputs - - * - *-----------------------------------------------------------------------------------------*/ -ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, float *mixer ) -{ - ivas_result_t result = IVAS_SUCCESS; - ivas_error error; - - float ppPcm_in[IVAS_MAX_NUM_CH][L_FRAME48k]; - float ppPcm_out[IVAS_MAX_NUM_CH][L_FRAME48k]; - float *ppDelay_lines[IVAS_MAX_NUM_CH]; - const float *filt_coeff; - int16_t delay_lp = 0; -#ifdef FIX_197_CREND_INTERFACE - Decoder_Struct st_ivas = { 0 }; -#else - Decoder_Struct st_ivas; -#endif - HeadRotFileReader *headRotReader = NULL; - - memset( &st_ivas, 0, sizeof( Decoder_Struct ) ); - - int64_t frame_count = 0; - - int16_t i = 0, j = 0; - int16_t frame_len = 0; - - ivas_dec_io_params_t dec_io_params; - int16_t in_format; - int16_t lfe_ch_idx; - DECODER_CONFIG decConfig; - - st_ivas.hDecoderConfig = &decConfig; - memset( st_ivas.hDecoderConfig, 0, sizeof( DECODER_CONFIG ) ); - memset( &st_ivas.hOutSetup, 0, sizeof( IVAS_OUTPUT_SETUP ) ); - - ivas_dec_default_io_params( &dec_io_params ); - ivas_copy_io_params_to_dec_io_params( pIo_params, &dec_io_params ); - result = ivas_crend_set_config_params( st_ivas.hDecoderConfig, &dec_io_params, &in_format, &lfe_ch_idx ); - st_ivas.transport_config = st_ivas.intern_config = ivas_crend_map_out_fmt( in_format ); - - if ( IVAS_SUCCESS != result ) - { - fprintf( stderr, "Crend configuration parameters setting failed\n" ); - exit( -1 ); - } - - frame_len = ivas_wrapper_get_frame_len( pIo_params->sample_rate ); - frame_len = frame_len >> 2; -#ifdef USE_PCM_OUT - /* skip WAV header */ - for ( i = 0; i < IVAS_MAX_NUM_CH; i++ ) - { - if ( pIo_params->fIn[i] != NULL ) - { - result = ivas_wav_header_skip( pIo_params->fIn[i] ); - if ( IVAS_SUCCESS != result ) - { - fprintf( stderr, "WAV header skip failed\n" ); -#ifdef FIX_197_CREND_INTERFACE - ivas_rend_closeCrend( &st_ivas.hCrendWrapper ); -#else - ivas_crend_close( &st_ivas ); -#endif - exit( -1 ); - } - } - } -#endif - /* test rounding error */ - float binaural_latencys_fastconv_s[3]; - float binaural_latencys_crend_s[3] = { 1.f / 48000.f, 2.f / 48000.f, 3.f / 48000.f }; - float binaural_latencys_td_s[3] = { BINAURAL_TD_LATENCY_S, BINAURAL_TD_LATENCY_S + 1.f / 48000.f, BINAURAL_TD_LATENCY_S + 2.f / 48000.f }; - - int32_t err = 0, err_lfe = 0, err_dec = 0; - - binaural_latencys_fastconv_s[0] = FASTCONV_HRIR_latency_s; - binaural_latencys_fastconv_s[1] = FASTCONV_BRIR_latency_s; - binaural_latencys_fastconv_s[2] = FASTCONV_BRIR_latency_s; - - err = ivas_check_rounding( binaural_latencys_fastconv_s, 0, 0, &err_lfe, &err_dec, 0 ); - printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); - err += ivas_check_rounding( binaural_latencys_crend_s, 0, 0, &err_lfe, &err_dec, 0 ); - printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); - err += ivas_check_rounding( binaural_latencys_td_s, 0, 0, &err_lfe, &err_dec, 0 ); - printf( "\n\nerr = %d err_lfe = %d err_dec = %d\n\n", err, err_lfe, err_dec ); - - err = ivas_check_rounding( binaural_latencys_fastconv_s, 0, 1, &err_lfe, &err_dec, 0 ); - printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); - err += ivas_check_rounding( binaural_latencys_crend_s, 0, 1, &err_lfe, &err_dec, 0 ); - printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); - err += ivas_check_rounding( binaural_latencys_td_s, 0, 1, &err_lfe, &err_dec, 0 ); - printf( "\n\nerr = %d err_lfe = %d err_dec = %d\n\n", err, err_lfe, err_dec ); - - err = ivas_check_rounding( binaural_latencys_fastconv_s, 1, 0, &err_lfe, &err_dec, 0 ); - printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); - err += ivas_check_rounding( binaural_latencys_crend_s, 1, 0, &err_lfe, &err_dec, 0 ); - printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); - err += ivas_check_rounding( binaural_latencys_td_s, 1, 0, &err_lfe, &err_dec, 0 ); - printf( "\n\nerr = %d err_lfe = %d err_dec = %d\n\n", err, err_lfe, err_dec ); - - err = ivas_check_rounding( binaural_latencys_fastconv_s, 1, 1, &err_lfe, &err_dec, 0 ); - printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); - err += ivas_check_rounding( binaural_latencys_crend_s, 1, 1, &err_lfe, &err_dec, 0 ); - printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); - err += ivas_check_rounding( binaural_latencys_td_s, 1, 1, &err_lfe, &err_dec, 0 ); - printf( "\n\nerr = %d err_lfe = %d err_dec = %d\n\n", err, err_lfe, err_dec ); - - ivas_render_config_open( &st_ivas.hRenderConfig ); - ivas_render_config_init_from_rom( &st_ivas.hRenderConfig, 0 ); - if ( pIo_params->renderConfigEnabled ) - { - RenderConfigReader *renderConfigReader = NULL; - if ( ( error = RenderConfigReader_open( pIo_params->renderConfigFilename, &renderConfigReader ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError: Can't open Renderer configuration file %s \n\n", pIo_params->renderConfigFilename ); - exit( -1 ); - } - if ( RenderConfigReader_read( renderConfigReader, (IVAS_RENDER_CONFIG_HANDLE) st_ivas.hRenderConfig ) != IVAS_ERR_OK ) - { - fprintf( stderr, "Failed to read renderer configuration from file %s\n", pIo_params->renderConfigFilename ); - exit( -1 ); - } - } - - st_ivas.hRenderConfig->roomAcoustics.use_brir = pIo_params->use_brir; - - if ( ( pIo_params->in_fmt >= MULT_CH_5_1 ) && ( pIo_params->in_fmt <= MULT_CH_7_1_4 ) ) - { - st_ivas.ivas_format = MC_FORMAT; - } - else - { - st_ivas.ivas_format = SBA_FORMAT; - } - - if ( ( pIo_params->out_fmt == BIN_2 ) && ( pIo_params->in_fmt != pIo_params->out_fmt ) ) - { - if ( pIo_params->test == FASTCONV_BIN_TEST ) - { - if ( st_ivas.hRenderConfig->roomAcoustics.use_brir ) - { - st_ivas.renderer_type = RENDERER_BINAURAL_FASTCONV_ROOM; - st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL_ROOM; - pIo_params->latency_ns = ( IVAS_FB_DEC_DELAY_NS + (int32_t) ( FASTCONV_BRIR_latency_s * 1000000000.f ) ); - } - else - { - st_ivas.renderer_type = RENDERER_BINAURAL_FASTCONV; - st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL; - if ( st_ivas.ivas_format == MC_FORMAT ) - pIo_params->latency_ns = ( IVAS_FB_DEC_DELAY_NS + (int32_t) ( FASTCONV_HRIR_latency_s * 1000000000.f ) ); - else - pIo_params->latency_ns = ( IVAS_FB_DEC_DELAY_NS + (int32_t) ( FASTCONV_HOA3_latency_s * 1000000000.f ) ); - } - } - else if ( pIo_params->test == TD_BIN_TEST ) - { - if ( st_ivas.ivas_format == SBA_FORMAT ) - { - fprintf( stderr, "TD Renderer configuration wrong input format\n" ); - exit( -1 ); - } - - if ( st_ivas.hRenderConfig->roomAcoustics.use_brir ) - { - st_ivas.renderer_type = RENDERER_BINAURAL_OBJECTS_TD; - st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL; - } - else - { - st_ivas.renderer_type = RENDERER_BINAURAL_OBJECTS_TD; - st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL; - } - - pIo_params->latency_ns = (int32_t) ( BINAURAL_TD_LATENCY_S * 1000000000.f ); - } - else if ( pIo_params->test == PARAM_BIN_TEST ) - { - if ( st_ivas.hRenderConfig->roomAcoustics.use_brir ) - { - st_ivas.renderer_type = RENDERER_BINAURAL_PARAMETRIC_ROOM; - st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL_ROOM; - } - else - { - st_ivas.renderer_type = RENDERER_BINAURAL_PARAMETRIC; - st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL; - } - pIo_params->latency_ns = IVAS_FB_DEC_DELAY_NS; - } - else if ( pIo_params->test == CREND_BIN_TEST ) - { - if ( st_ivas.hRenderConfig->roomAcoustics.use_brir ) - { - st_ivas.renderer_type = RENDERER_BINAURAL_MIXER_CONV_ROOM; - st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL_ROOM; - } - else - { - st_ivas.renderer_type = RENDERER_BINAURAL_MIXER_CONV; - st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL; - } - } - else - { - fprintf( stderr, "Crend configuration wrong renderer\n" ); - exit( -1 ); - } - } - else - { -#ifdef FIX_197_CREND_INTERFACE - ivas_hrtf_init( st_ivas.hCrendWrapper->hHrtfCrend ); -#else - ivas_hrtf_init( st_ivas.hHrtf ); -#endif - } - - int16_t in_ch = audioCfg2channels( st_ivas.transport_config ); - int16_t out_ch = audioCfg2channels( st_ivas.hDecoderConfig->output_config ); - - /*------------------------------------------------------------------------------------------* - * State memory allocation for Common renderer - *------------------------------------------------------------------------------------------*/ - st_ivas.hDecoderConfig->Opt_Headrotation = ( pIo_params->orientation_tracking != OTR_TRACKING_NONE ) ? 1 : 0; - /*-------------------------------------------------------------------* - * Allocate and initialize Head-Tracking handle - *--------------------------------------------------------------------*/ - - if ( st_ivas.hDecoderConfig->Opt_Headrotation ) - { - if ( ( error = ivas_headTrack_open( &( st_ivas.hHeadTrackData ) ) ) != IVAS_ERR_OK ) - { - return IVAS_FAILED; - } - if ( ( error = HeadRotationFileReader_open( pIo_params->csv_path, &headRotReader ) ) != IVAS_ERR_OK ) - { - return IVAS_FAILED; - } - } - - st_ivas.nchan_transport = audioCfg2channels( st_ivas.transport_config ); - st_ivas.hIntSetup.index_lfe[0] = lfe_ch_idx; - st_ivas.hIntSetup.num_lfe = lfe_ch_idx > 0 ? 1 : 0; - - if ( pIo_params->test == FASTCONV_BIN_TEST ) - { - ivas_output_init( &st_ivas.hIntSetup, st_ivas.transport_config ); - int16_t numCldfbAnalyses, numCldfbSyntheses; - numCldfbAnalyses = st_ivas.nchan_transport; - numCldfbSyntheses = st_ivas.hDecoderConfig->nchan_out; - - for ( i = 0; i < numCldfbAnalyses; i++ ) - { - if ( ( error = openCldfb( &( st_ivas.cldfbAnaDec[i] ), CLDFB_ANALYSIS, dec_io_params.out_sample_rate, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) - { - return IVAS_FAILED; - } - } - for ( ; i < MAX_INTERN_CHANNELS; i++ ) - { - st_ivas.cldfbAnaDec[i] = NULL; - } - - for ( i = 0; i < numCldfbSyntheses; i++ ) - { - if ( ( error = openCldfb( &( st_ivas.cldfbSynDec[i] ), CLDFB_SYNTHESIS, dec_io_params.out_sample_rate, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) - { - return IVAS_FAILED; - } - } - for ( ; i < MAX_OUTPUT_CHANNELS; i++ ) - { - st_ivas.cldfbSynDec[i] = NULL; - } - - ivas_binRenderer_open( &st_ivas ); - } - else if ( pIo_params->test == TD_BIN_TEST ) - { - ivas_output_init( &st_ivas.hIntSetup, st_ivas.transport_config ); -#ifdef FIX_197_CREND_INTERFACE - ivas_output_init( &st_ivas.hOutSetup, st_ivas.hOutSetup.output_config ); -#else - ivas_output_init( &st_ivas.hOutSetup, st_ivas.transport_config ); -#endif - ivas_td_binaural_open( &st_ivas ); - } - else if ( pIo_params->test == PARAM_BIN_TEST ) - { - if ( ( pIo_params->in_fmt != FOA_4 ) && ( pIo_params->in_fmt != HOA_9 ) && ( pIo_params->in_fmt != HOA_16 ) ) - { - fprintf( stderr, "PARAM renderer configuration wrong format, must be FOA or HOA up to order 3\n" ); - exit( -1 ); - } - - ivas_output_init( &st_ivas.hIntSetup, st_ivas.transport_config ); -#ifdef FIX_197_CREND_INTERFACE - ivas_output_init( &st_ivas.hOutSetup, st_ivas.hOutSetup.output_config ); -#else - ivas_output_init( &st_ivas.hOutSetup, st_ivas.transport_config ); -#endif - st_ivas.hOutSetup.separateChannelEnabled = 1; - int16_t numCldfbAnalyses, numCldfbSyntheses; - numCldfbAnalyses = st_ivas.nchan_transport; - numCldfbSyntheses = st_ivas.hDecoderConfig->nchan_out; - - for ( i = 0; i < numCldfbAnalyses; i++ ) - { - if ( ( error = openCldfb( &( st_ivas.cldfbAnaDec[i] ), CLDFB_ANALYSIS, dec_io_params.out_sample_rate, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) - { - return IVAS_FAILED; - } - } - for ( ; i < MAX_INTERN_CHANNELS; i++ ) - { - st_ivas.cldfbAnaDec[i] = NULL; - } - - for ( i = 0; i < numCldfbSyntheses; i++ ) - { - if ( ( error = openCldfb( &( st_ivas.cldfbSynDec[i] ), CLDFB_SYNTHESIS, dec_io_params.out_sample_rate, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) - { - return IVAS_FAILED; - } - } - for ( ; i < MAX_OUTPUT_CHANNELS; i++ ) - { - st_ivas.cldfbSynDec[i] = NULL; - } - } - else - { - ivas_output_init( &st_ivas.hIntSetup, st_ivas.transport_config ); -#ifdef FIX_197_CREND_INTERFACE - ivas_output_init( &st_ivas.hOutSetup, st_ivas.hOutSetup.output_config ); - ivas_rend_openCrend( &st_ivas.hCrendWrapper, getRendAudioConfigFromIvasAudioConfig( st_ivas.transport_config ), getRendAudioConfigFromIvasAudioConfig( st_ivas.hOutSetup.output_config ), st_ivas.hRenderConfig, st_ivas.hDecoderConfig->Opt_Headrotation, pIo_params->sample_rate ); -#else - ivas_output_init( &st_ivas.hOutSetup, st_ivas.transport_config ); - ivas_crend_open( &st_ivas ); -#endif - } - - if ( pIo_params->test == CREND_BIN_TEST ) - { -#ifdef FIX_197_CREND_INTERFACE - pIo_params->latency_ns = st_ivas.hCrendWrapper->binaural_latency_ns; -#else - pIo_params->latency_ns = (int32_t) ( st_ivas.hHrtf->latency_s * 1000000000.f ); -#endif - } - - if ( st_ivas.ivas_format == MC_FORMAT ) - { -#ifdef FIX_197_CREND_INTERFACE - if ( st_ivas.hDecoderConfig->Opt_Headrotation ) - { - ivas_rend_initEfap( st_ivas.hIntSetup.output_config, &st_ivas.hEFAPdata ); - } -#endif - ivas_create_lfe_dec( &st_ivas.hLFE, st_ivas.hDecoderConfig->output_Fs, pIo_params->latency_ns ); - - if ( st_ivas.hLFE->lfe_addl_delay > 0 ) - { - if ( st_ivas.hLFE->lfe_delay_buf != NULL ) - { - free( st_ivas.hLFE->lfe_delay_buf ); - st_ivas.hLFE->lfe_delay_buf = NULL; - } - - if ( pIo_params->latency_ns > 0 ) - { - st_ivas.hLFE->lfe_addl_delay = (int16_t) roundf( (float) pIo_params->latency_ns * (float) dec_io_params.out_sample_rate / 1000000000.f ); - - if ( st_ivas.hLFE->lfe_addl_delay > 0 ) - { - if ( ( st_ivas.hLFE->lfe_delay_buf = (float *) malloc( st_ivas.hLFE->lfe_addl_delay * sizeof( float ) ) ) == NULL ) - { - fprintf( stderr, "Can not allocate memory for LFE additional delay buffer\n" ); - return IVAS_FAILED; - } - set_zero( (float *) st_ivas.hLFE->lfe_delay_buf, st_ivas.hLFE->lfe_addl_delay ); - } - } - else - { - st_ivas.hLFE->lfe_addl_delay = 0; - } - } - - /* delay input channel of latency of lp filter*/ - if ( pIo_params->lfe_lp_enable ) - { - delay_lp = (int16_t) ( ivas_lfe_lpf_delay[1] * (float) pIo_params->sample_rate ); - for ( i = 0; i < in_ch - st_ivas.hIntSetup.num_lfe; i++ ) - { - if ( ( ppDelay_lines[i] = (float *) malloc( delay_lp * sizeof( float ) ) ) == NULL ) - { - fprintf( stderr, "Can not allocate memory for LFE additional delay buffer\n" ); - return IVAS_FAILED; - } - set_zero( (float *) ppDelay_lines[i], delay_lp ); - } - ivas_lfe_lpf_select_filt_coeff( pIo_params->sample_rate, IVAS_FILTER_ORDER_4, &filt_coeff ); - ivas_filters_init( &st_ivas.hLFE->filter_state, filt_coeff, IVAS_FILTER_ORDER_4 ); - pIo_params->latency_ns = pIo_params->latency_ns + (int32_t) ( ivas_lfe_lpf_delay[1] * 1000000000.f ); - } - else - { - delay_lp = 0; - } - } - - if ( pIo_params->limiter_enable ) - { - st_ivas.hLimiter = ivas_limiter_open( out_ch, pIo_params->sample_rate ); - } - - /*------------------------------------------------------------------------------------------* - * Loop for every frame of input data - * - Read the input data - * - Run the Common renderer - * - Write the parameters into output bitstream file - *------------------------------------------------------------------------------------------*/ - -#define _FIND_MAX_ -#ifdef _FIND_MAX_ - float valMax = 0; - float valEner = 0; -#endif - - /* delay adjustment */ - int32_t skip_samples = 0; - int32_t skipped_samples = 0; - int16_t write_flag = 0; - - if ( ( pIo_params->out_fmt == BIN_2 ) && ( pIo_params->no_delay_cmp == 0 ) ) - { - skip_samples = (int32_t) roundf( (float) pIo_params->latency_ns * pIo_params->sample_rate / 1000000000.f ); - } - fprintf( stdout, "IVAS Common Renderer skip samples = %d\n", (int) skip_samples ); - - frame_len = frame_len << 2; - - int32_t frame_dec = 0; - IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { 0 }; - - /* process loop */ - while ( ( ( result = ivas_wrapper_get_in_buf( pIo_params, ppPcm_in ) ) == IVAS_SUCCESS ) && ( ( st_ivas.hDecoderConfig->Opt_Headrotation == 0 ) || ( ( st_ivas.hDecoderConfig->Opt_Headrotation == 1 ) && ( HeadRotationFileReading( headRotReader, Quaternions, frame_dec ) == IVAS_ERR_OK ) ) ) ) - { - int16_t pcm[MAX_OUTPUT_CHANNELS]; - frame_dec++; - result = IVAS_SUCCESS; - if ( ( st_ivas.hDecoderConfig->Opt_Headrotation == 1 ) && ( ivas_feed_head_track_data( &st_ivas, Quaternions ) != IVAS_SUCCESS ) ) - { - return IVAS_IO_ERROR; - } - - if ( pIo_params->lfe_lp_enable ) - { - /* ADD delay to make overall max(block_offset, 11.5)*/ - if ( st_ivas.hLFE->lfe_addl_delay > 0 ) - { - delay_signal( ppPcm_in[lfe_ch_idx], frame_len, st_ivas.hLFE->lfe_delay_buf, st_ivas.hLFE->lfe_addl_delay ); - } - - ivas_filter_process( &st_ivas.hLFE->filter_state, ppPcm_in[lfe_ch_idx], frame_len ); - } - - if ( pIo_params->test == FASTCONV_BIN_TEST ) - { - ivas_binaural_cldfb( &st_ivas, ppPcm_in ); - } - else if ( pIo_params->test == TD_BIN_TEST ) - { - ObjRenderIVASFrame( &st_ivas, ppPcm_in, frame_len ); - } - else if ( pIo_params->test == PARAM_BIN_TEST ) - { - float Cldfb_RealBuffer[MAX_INTERN_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - float Cldfb_ImagBuffer[MAX_INTERN_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - float RealBuffer[CLDFB_NO_CHANNELS_MAX]; - float ImagBuffer[CLDFB_NO_CHANNELS_MAX]; - int16_t slot_idx, maxBand, ch; - float gain = powf( 10.f, -6.f / 20.f ); /* add gain to compensate loudness with decoder, but are missing when compare to other renderers*/ - - /* Implement a 5 msec loops */ - maxBand = (int16_t) ( ( CLDFB_NO_CHANNELS_MAX * st_ivas.hDecoderConfig->output_Fs ) / 48000 ); - - for ( slot_idx = 0; slot_idx < (int16_t) CLDFB_NO_COL_MAX; slot_idx++ ) - { - - for ( ch = 0; ch < in_ch; ch++ ) - { - cldfbAnalysis_ts( &( ppPcm_in[ch][maxBand * slot_idx] ), - Cldfb_RealBuffer[ch][slot_idx], - Cldfb_ImagBuffer[ch][slot_idx], - maxBand, st_ivas.cldfbAnaDec[ch] ); - } - } - - for ( slot_idx = 0; slot_idx < (int16_t) CLDFB_NO_COL_MAX; slot_idx++ ) - { - /* Implement binaural rendering */ - for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) - { - float *outSlotRePr, *outSlotImPr; /* Pointers needed for function call compatibility */ - - set_zero( RealBuffer, maxBand ); - set_zero( ImagBuffer, maxBand ); - - int16_t bandIdx, chIdx; - const float *filterTapsRealPtr, *filterTapsImagPtr; - - for ( chIdx = 0; chIdx < in_ch; chIdx++ ) - { - filterTapsRealPtr = hrtfShCoeffsRe[ch][chIdx]; - filterTapsImagPtr = hrtfShCoeffsIm[ch][chIdx]; - - for ( bandIdx = 0; bandIdx < maxBand; bandIdx++ ) - { - RealBuffer[bandIdx] += gain * ( Cldfb_RealBuffer[chIdx][slot_idx][bandIdx] * filterTapsRealPtr[bandIdx] ) - ( Cldfb_ImagBuffer[chIdx][slot_idx][bandIdx] * filterTapsImagPtr[bandIdx] ); - ImagBuffer[bandIdx] += gain * ( Cldfb_RealBuffer[chIdx][slot_idx][bandIdx] * filterTapsImagPtr[bandIdx] ) + ( Cldfb_ImagBuffer[chIdx][slot_idx][bandIdx] * filterTapsRealPtr[bandIdx] ); - } - } - outSlotRePr = &( RealBuffer[0] ); - outSlotImPr = &( ImagBuffer[0] ); - cldfbSynthesis( &outSlotRePr, &outSlotImPr, &( ppPcm_in[ch][slot_idx * maxBand] ), maxBand, st_ivas.cldfbSynDec[ch] ); - } - } - } - else - { - if ( mixer != NULL ) - { - ivas_crend_mixer( ppPcm_in, ppPcm_out, in_ch, out_ch, mixer, frame_len ); - } - else - { -#ifdef FIX_197_CREND_INTERFACE - ivas_rend_crendProcess( st_ivas.hCrendWrapper, getRendAudioConfigFromIvasAudioConfig( st_ivas.transport_config ), getRendAudioConfigFromIvasAudioConfig( st_ivas.hOutSetup.output_config ), st_ivas.hDecoderConfig, st_ivas.hHeadTrackData, &st_ivas.hIntSetup, st_ivas.hEFAPdata, ppPcm_in, pIo_params->sample_rate ); -#else - ivas_crend_process( &st_ivas, ppPcm_in ); -#endif - } - } - - if ( mixer == NULL ) - { - if ( pIo_params->lfe_lp_enable ) - { - for ( i = 0; i < out_ch; i++ ) - { - delay_signal( ppPcm_in[i], frame_len, ppDelay_lines[i], delay_lp ); - } - } - - ivas_binaural_add_LFE( &st_ivas, frame_len, ppPcm_in ); - - for ( i = 0; i < out_ch; i++ ) - { - mvr2r( ppPcm_in[i], ppPcm_out[i], frame_len ); - } - if ( pIo_params->limiter_enable ) - { - ivas_limiter_dec( st_ivas.hLimiter, ppPcm_out, out_ch, frame_len, 0 ); - } - } - - - float valMaxLoc = 0; - float clip = 1.0f; - for ( j = 0; j < frame_len; j++ ) - { - if ( ( write_flag == 0 ) && ( skipped_samples == skip_samples ) ) - { - write_flag = 1; - } - for ( i = 0; i < out_ch; i++ ) - { - // float temp = roundf( ppPcm_out[i][j] * PCM16_TO_FLT_FAC ); - float temp; -#ifdef _FIND_MAX_ - valMaxLoc = ( ppPcm_out[i][j] > valMaxLoc ) ? ppPcm_out[i][j] : ( ppPcm_out[i][j] < -valMaxLoc ) ? -ppPcm_out[i][j] - : valMaxLoc; - /* if (valMaxLoc > 1.0) printf("Saturation valMax = %f at frame_len = %ld sample = %ld \n", valMaxLoc, frame_len, i); */ - if ( valMax < valMaxLoc ) - valMax = valMaxLoc; - valEner += ppPcm_out[i][j] * ppPcm_out[i][j]; -#endif - temp = ( ppPcm_out[i][j] > MAX16B_FLT ) ? MAX16B_FLT : ( ppPcm_out[i][j] < MIN16B_FLT ) ? MIN16B_FLT - : ppPcm_out[i][j]; - pcm[i] = (short) roundf( temp ); - clip = max( clip, fabsf( ppPcm_out[i][j] ) ); - } - if ( write_flag == 1 ) - { -#ifdef USE_PCM_OUT - fwrite( pcm, sizeof( int16_t ), out_ch, pIo_params->fOut ); -#else - AudioFileWriter_write( pIo_params->fOut, pcm, out_ch ); -#endif - } - if ( write_flag == 0 ) - skipped_samples++; - } - if ( clip > MAX16B_FLT ) - { - fprintf( stdout, "IVAS Common Renderer Clipped: max gain = %f\n", clip ); - } - - fprintf( stdout, "Processed frame: %ld\r", (long) frame_count ); - frame_count++; - -#ifdef WMOPS - update_wmops(); -#endif - } - - int16_t pcm[MAX_OUTPUT_CHANNELS] = { 0 }; - while ( skipped_samples > 0 ) - { - AudioFileWriter_write( pIo_params->fOut, pcm, out_ch ); - skipped_samples--; - } - -#ifdef _FIND_MAX_ - valEner = sqrtf( valEner / ( frame_count * frame_len ) ); - printf( "valMax = %f valEner = %f \n", 20.f * log10( valMax ), 20.f * log10( valEner ) ); -#endif - printf( "Total Frames Processed : %lld\n", (long long int) frame_count ); - - if ( st_ivas.hLFE ) - { - ivas_lfe_dec_close( st_ivas.hLFE ); - } - - if ( st_ivas.hDirAC != NULL ) - ivas_dirac_dec_close( st_ivas.hDirAC ); - if ( st_ivas.hBinRenderer != NULL ) - ivas_binRenderer_close( &st_ivas.hBinRenderer ); -#ifdef FIX_197_CREND_INTERFACE - ivas_rend_closeCrend( &st_ivas.hCrendWrapper ); -#else - ivas_crend_close( &st_ivas ); -#endif - if ( st_ivas.hBinRendererTd != NULL ) - ivas_td_binaural_close( &st_ivas.hBinRendererTd ); - if ( st_ivas.hLimiter != NULL ) - ivas_limiter_close( &st_ivas.hLimiter ); - if ( st_ivas.hEFAPdata != NULL ) - efap_free_data( &st_ivas.hEFAPdata ); - - if ( pIo_params->lfe_lp_enable ) - { - for ( i = 0; i < in_ch - st_ivas.hIntSetup.num_lfe; i++ ) - { - free( ppDelay_lines[i] ); - } - } - if ( st_ivas.hRenderConfig != NULL ) - { - ivas_render_config_close( &st_ivas.hRenderConfig ); - } - - /* Head track data handle */ - if ( st_ivas.hHeadTrackData != NULL ) - { - free( st_ivas.hHeadTrackData ); - st_ivas.hHeadTrackData = NULL; - } - - if ( headRotReader ) - { - HeadRotationFileReader_close( &headRotReader ); - } - - return IVAS_SUCCESS; -} - -/*-----------------------------------------------------------------------------------------* - * Function description - - * Object mixer renderer block - * - * Inputs - - * ivas_enc_io_params_t io_params - * - * Outputs - - * - *-----------------------------------------------------------------------------------------*/ -ivas_result_t ivas_object_mixer_renderer( ivas_crend_io_params_t *pIo_params, int16_t *userLoc ) -{ - ivas_result_t result = IVAS_SUCCESS; - - float ppPcm_in[IVAS_MAX_NUM_CH][L_FRAME48k]; - float ppPcm_out[IVAS_MAX_NUM_CH][L_FRAME48k]; - DECODER_CONFIG decoder_config; - Decoder_Struct st_ivas; - - memset( &st_ivas, 0, sizeof( Decoder_Struct ) ); - - st_ivas.hDecoderConfig = &decoder_config; - memset( st_ivas.hDecoderConfig, 0, sizeof( DECODER_CONFIG ) ); - - int64_t frame_count = 0; - - int16_t i = 0, j = 0; - int16_t frame_len = 0; - - float *Smixer; - float *powvec; - ivas_dec_io_params_t dec_io_params = { 0 }; - int16_t in_format; - int16_t lfe_ch_idx; - - ivas_dec_default_io_params( &dec_io_params ); - ivas_copy_io_params_to_dec_io_params( pIo_params, &dec_io_params ); - - frame_len = ivas_wrapper_get_frame_len( pIo_params->sample_rate ); - -#ifdef USE_PCM_OUT - /* skip WAV header */ - for ( i = 0; i < IVAS_MAX_NUM_CH; i++ ) - { - if ( pIo_params->fIn[i] != NULL ) - { - result = ivas_wav_header_skip( pIo_params->fIn[i] ); - - if ( IVAS_SUCCESS != result ) - { - fprintf( stderr, "WAV header skip failed\n" ); -#ifdef FIX_197_CREND_INTERFACE - ivas_rend_closeCrend( &st_ivas.hCrendWrapper ); -#else - ivas_crend_close( &st_ivas ); -#endif - exit( -1 ); - } - } - } -#endif - - result = ivas_crend_set_config_params( &decoder_config, &dec_io_params, &in_format, &lfe_ch_idx ); - - st_ivas.transport_config = ivas_crend_map_out_fmt( in_format ); - - - if ( IVAS_SUCCESS != result ) - { - fprintf( stderr, "Crend configuration parameters setting failed\n" ); -#ifdef FIX_197_CREND_INTERFACE - ivas_rend_closeCrend( &st_ivas.hCrendWrapper ); -#else - ivas_crend_close( &st_ivas ); -#endif - exit( -1 ); - } - - /*------------------------------------------------------------------------------------------* - * State memory allocation for Common renderer - *------------------------------------------------------------------------------------------*/ - decoder_config.Opt_Headrotation = 0; -#ifdef FIX_197_CREND_INTERFACE - ivas_rend_openCrend( &st_ivas.hCrendWrapper, getRendAudioConfigFromIvasAudioConfig( st_ivas.transport_config ), getRendAudioConfigFromIvasAudioConfig( st_ivas.transport_config ), st_ivas.hRenderConfig, st_ivas.hDecoderConfig->Opt_Headrotation, pIo_params->sample_rate ); -#else - ivas_crend_open( &st_ivas ); -#endif - - /*------------------------------------------------------------------------------------------* - * In/out buffer memory allocation for encoder - *------------------------------------------------------------------------------------------*/ - int16_t in_ch = ivas_get_num_channels( pIo_params->in_fmt ); - int16_t out_ch = ivas_get_num_channels( pIo_params->out_fmt ); - - Smixer = (float *) calloc( in_ch, sizeof( float ) ); - powvec = (float *) calloc( in_ch, sizeof( float ) ); - - /* init - ignore FLC */ - for ( i = 0; i < in_ch; i++ ) - { - powvec[i] = 0.0f; - } - - /*------------------------------------------------------------------------------------------* - * Loop for every frame of input data - * - Read the input data - * - Run the Common renderer - * - Write the parameters into output bitstream file - *------------------------------------------------------------------------------------------*/ - -#define _FIND_MAX_ -#ifdef _FIND_MAX_ - float valMax = 0; - float valEner = 0; -#endif - - while ( ( ( result = ivas_wrapper_get_in_buf( pIo_params, ppPcm_in ) ) == IVAS_SUCCESS ) ) /* process loop */ - { -#ifdef USE_PCM_OUT - int16_t pcm; -#else - int16_t pcm[MAX_OUTPUT_CHANNELS]; -#endif - result = IVAS_SUCCESS; - - /* get the mixing matrix.. */ - get_prox_downmix_mixer( (int16_t) PROXIMITY_USER_ID, Smixer, userLoc, in_ch, ppPcm_in, frame_len, powvec ); - - result = ivas_crend_mixer( ppPcm_in, ppPcm_out, in_ch, out_ch, Smixer, frame_len ); - - if ( IVAS_SUCCESS != result ) - { - fprintf( stderr, "Error: ivas_crend_process failed with %d \n\n", (int32_t) result ); -#ifdef FIX_197_CREND_INTERFACE - ivas_rend_closeCrend( &st_ivas.hCrendWrapper ); -#else - ivas_crend_close( &st_ivas ); -#endif - exit( -1 ); - } - - float valMaxLoc = 0; - - for ( j = 0; j < frame_len; j++ ) - { - - for ( i = 0; i < out_ch; i++ ) - { - - // float temp = roundf( ppPcm_out[i][j] * PCM16_TO_FLT_FAC ); - float temp = roundf( ppPcm_out[i][j] ); -#ifdef _FIND_MAX_ - - valMaxLoc = ( ppPcm_out[i][j] > valMaxLoc ) ? ppPcm_out[i][j] : ( ppPcm_out[i][j] < -valMaxLoc ) ? -ppPcm_out[i][j] - : valMaxLoc; - /* if (valMaxLoc > 1.0) printf("Saturation valMax = %f at frame_len = %ld sample = %ld \n", valMaxLoc, frame_len, i); */ - - if ( valMax < valMaxLoc ) - { - valMax = valMaxLoc; - } - valEner += ppPcm_out[i][j] * ppPcm_out[i][j]; -#endif - -#ifdef USE_PCM_OUT - pcm = ( temp > MAX16B_FLT ) ? MAX16B : ( temp < MIN16B_FLT ) ? MIN16B - : (short) temp; - fwrite( &pcm, sizeof( int16_t ), 1, pIo_params->fOut ); -#else - pcm[i] = ( temp > MAX16B_FLT ) ? MAX16B : ( temp < MIN16B_FLT ) ? MIN16B - : (short) temp; - -#endif - } -#ifndef USE_PCM_OUT - AudioFileWriter_write( pIo_params->fOut, pcm, out_ch ); -#endif - } - - frame_count++; - } - free( powvec ); - free( Smixer ); - -#ifdef _FIND_MAX_ - valEner = sqrtf( valEner / ( frame_count * frame_len ) ); - printf( "valMax = %f valEner = %f \n", 20.f * log10( valMax ), 20.f * log10( valEner ) ); -#endif - printf( "Total Frames Processed : %lld\n", (long long int) frame_count ); - -#ifdef FIX_197_CREND_INTERFACE - ivas_rend_closeCrend( &st_ivas.hCrendWrapper ); -#else - ivas_crend_close( &st_ivas ); -#endif - - return IVAS_SUCCESS; -} -- GitLab From e3c30094e9a75132d93c2617f6608908b4daac7a Mon Sep 17 00:00:00 2001 From: muxe6256 Date: Thu, 19 Jan 2023 16:19:37 +0100 Subject: [PATCH 5/8] Fix tests fails --- lib_dec/ivas_dec.c | 6 +++--- lib_dec/ivas_init_dec.c | 1 + lib_dec/ivas_ism_param_dec.c | 1 + lib_dec/ivas_mct_dec.c | 1 + lib_rend/ivas_crend.c | 7 +++++++ 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 452284cfb3..b52c92b239 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -211,9 +211,9 @@ ivas_error ivas_dec( if ( ( error = ivas_rend_crendProcess( st_ivas->hCrendWrapper, IVAS_REND_AUDIO_CONFIG_7_1_4, IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM, - st_ivas->hDecoderConfig, - st_ivas->hHeadTrackData, - &st_ivas->hIntSetup, + NULL, + NULL, + NULL, NULL, output, output_Fs ) ) != IVAS_ERR_OK ) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index f2fdf1f9b0..20fccb60d1 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1195,6 +1195,7 @@ ivas_error ivas_init_decoder( { return error; } + st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns; #else if ( ivas_crend_open( st_ivas ) != IVAS_ERR_OK ) { diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index d8c9908bf2..090a69257c 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -1095,6 +1095,7 @@ static ivas_error ivas_ism_bitrate_switching( { return error; } + st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns; #else ivas_crend_open( st_ivas ); #endif diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 104efadd9b..48381432a5 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -1125,6 +1125,7 @@ static ivas_error ivas_mc_dec_reconfig( { return error; } + st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns; } #else } diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 55b7e55bf6..9ca923318b 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -1404,10 +1404,17 @@ ivas_error ivas_rend_initCrend( /* set BRIR flag */ use_brir = false; +#ifdef FIX_197_CREND_INTERFACE + if ( ( ( hRendCfg != NULL ) && hRendCfg->roomAcoustics.use_brir ) || ( ( hRendCfg == NULL ) && ( outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) ) ) + { + use_brir = true; + } +#else if ( ( hRendCfg != NULL && hRendCfg->roomAcoustics.use_brir ) || outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) { use_brir = true; } +#endif if ( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ) != IVAS_ERR_OK ) -- GitLab From e66335a17dc94ab0207a0e6c2b144037e1af50f8 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 19 Jan 2023 16:06:51 +0100 Subject: [PATCH 6/8] fix MSVC warnings (data conversion warning) --- lib_rend/lib_rend.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index eeab8fb2a9..641c757b4c 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -676,7 +676,7 @@ static ivas_error getAmbisonicsOrder( return IVAS_ERR_OK; } -static int32_t getNumLfeChannels( +static int16_t getNumLfeChannels( input_mc *inputMc ) { switch ( inputMc->base.inConfig ) @@ -1524,8 +1524,8 @@ static ivas_error updateLfePanGainsForAmbiOut( for ( i = 0; i < numLfeIn; i++ ) { /* panning gains */ - ivas_dirac_dec_get_response( inputMc->lfeRouting.lfeOutputAzimuth, - inputMc->lfeRouting.lfeOutputElevation, + ivas_dirac_dec_get_response( (int16_t) inputMc->lfeRouting.lfeOutputAzimuth, + (int16_t) inputMc->lfeRouting.lfeOutputElevation, inputMc->lfeRouting.lfePanMtx[i], outAmbiOrder ); -- GitLab From 123d75cf045434dfda7509d986cc0c329fa1b4d4 Mon Sep 17 00:00:00 2001 From: muxe6256 Date: Fri, 20 Jan 2023 12:54:24 +0100 Subject: [PATCH 7/8] fix ivas_rend_crendConvolver --- lib_com/ivas_prot.h | 9 --- lib_dec/ivas_sba_dec.c | 10 +-- lib_rend/ivas_crend.c | 161 +++++++++++++++++++++++++++++++++++++++++ lib_rend/lib_rend.c | 19 +++-- 4 files changed, 179 insertions(+), 20 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 97c57084e0..8b4d2b08ce 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5400,15 +5400,6 @@ ivas_error ivas_rend_crendProcess( EFAP_HANDLE hEFAPdata, float output[][L_FRAME48k], /* i/o: input/output audio channels */ const int32_t output_Fs ); - -ivas_error ivas_rend_crendConvolver( - const CREND_WRAPPER *pCrend, - const IVAS_REND_AudioConfig inConfig, - const IVAS_REND_AudioConfig outConfig, - float pcm_in[][L_FRAME48k], - float pcm_out[][L_FRAME48k], - const int32_t output_Fs, - const int16_t i_ts ); #endif /*----------------------------------------------------------------------------------* diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 984ce22cb1..126ab55944 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -502,16 +502,16 @@ ivas_error ivas_sba_dec_reinit( st_ivas->hRenderConfig, t_ivas->hDecoderConfig->Opt_Headrotation, st_ivas->hDecoderConfig->output_Fs ) != IVAS_ERR_OK ) ) -#else - if ( ivas_crend_open( st_ivas ) != IVAS_ERR_OK ) -#endif { -#ifdef FIX_197_CREND_INTERFACE return error; + } + st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns; #else + if ( ivas_crend_open( st_ivas ) != IVAS_ERR_OK ) + { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "ivas_crend_open failed" ); -#endif } +#endif } ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses ); diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 9ca923318b..d824e2b758 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -1911,6 +1911,163 @@ ivas_error ivas_rend_closeCrend( #endif } +#ifdef FIX_197_CREND_INTERFACE + +/*-----------------------------------------------------------------------------------------* + * Function ivas_crend_convolver() + * + * Convolver block + *-----------------------------------------------------------------------------------------*/ + +static ivas_error ivas_rend_crendConvolver( + const CREND_WRAPPER *pCrend, + IVAS_REND_AudioConfig inConfig, + IVAS_REND_AudioConfig outConfig, + float pcm_in[][L_FRAME48k], + float pcm_out[][L_FRAME48k], + const int32_t output_Fs, + const int16_t i_ts ) +{ + int16_t i, j, k, m; + int16_t subframe_length, idx_in; + int16_t lfe_idx_in; + int16_t offset, offset_in, offset_diffuse; + int16_t nchan_in, nchan_out; + float *pIn; + float *pFreq_buf_re, *pFreq_buf_im; + float *pFreq_filt_re, *pFreq_filt_im; + float pOut[L_FRAME48k * 2]; + float tmp_out_re[L_FRAME48k], tmp_out_im[L_FRAME48k]; + + getAudioConfigNumChannels( inConfig, &nchan_in ); + getAudioConfigNumChannels( outConfig, &nchan_out ); + + subframe_length = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES; + + lfe_idx_in = -1; + if ( getAudioConfigType( inConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) + { + if ( inConfig != IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) + { + lfe_idx_in = LFE_CHANNEL; + } + else + { + assert( 0 && "Custom LS not supported in CRend" ); + } + } + + offset = pCrend->hCrend->delay_line_rw_index * subframe_length; /* subframe_length * ( pCrend->hHrtfCrend->max_num_iterations - 1 ); */ + offset_diffuse = pCrend->hCrend->diffuse_delay_line_rw_index * subframe_length; /* subframe_length *( pCrend->hHrtfCrend->num_iterations_diffuse[0] - 1 ); */ + + if ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 ) + { + set_zero( &pCrend->hCrend->freq_buffer_re_diffuse[offset_diffuse], subframe_length ); + set_zero( &pCrend->hCrend->freq_buffer_im_diffuse[offset_diffuse], subframe_length ); + } + + i = 0; + for ( idx_in = 0; idx_in < nchan_in; idx_in++ ) + { + pIn = &pcm_in[idx_in][i_ts * subframe_length]; + if ( idx_in != lfe_idx_in ) + { + if ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 ) + { + pFreq_buf_re = &pCrend->hCrend->freq_buffer_re_diffuse[offset_diffuse]; + pFreq_buf_im = &pCrend->hCrend->freq_buffer_im_diffuse[offset_diffuse]; + pFreq_filt_re = &pCrend->hCrend->freq_buffer_re[i][offset]; + pFreq_filt_im = &pCrend->hCrend->freq_buffer_im[i][offset]; + + for ( k = 0; k < pCrend->hHrtfCrend->index_frequency_max_diffuse; k++ ) + { + pFreq_buf_re[k] += pFreq_filt_re[k] * pCrend->hHrtfCrend->inv_diffuse_weight[i]; + pFreq_buf_im[k] += pFreq_filt_im[k] * pCrend->hHrtfCrend->inv_diffuse_weight[i]; + } + } + + pFreq_buf_re = &pCrend->hCrend->freq_buffer_re[i][offset]; + pFreq_buf_im = &pCrend->hCrend->freq_buffer_im[i][offset]; + + ivas_mdft( pIn, pFreq_buf_re, pFreq_buf_im, subframe_length, subframe_length ); + i++; + } + } + + for ( j = 0; j < nchan_out; j++ ) + { + set_zero( tmp_out_re, subframe_length ); + set_zero( tmp_out_im, subframe_length ); + + i = 0; + for ( idx_in = 0; idx_in < nchan_in; idx_in++ ) + { + if ( idx_in != lfe_idx_in ) + { + offset = 0; + for ( m = 0; m < pCrend->hHrtfCrend->num_iterations[i][j]; m++ ) + { + offset_in = ( pCrend->hCrend->delay_line_rw_index + pCrend->hHrtfCrend->max_num_iterations - pCrend->hHrtfCrend->num_iterations[i][j] + m + 1 ); + offset_in = offset_in % ( pCrend->hHrtfCrend->max_num_iterations ); + offset_in = offset_in * subframe_length; + pFreq_buf_re = &pCrend->hCrend->freq_buffer_re[i][offset_in]; + pFreq_buf_im = &pCrend->hCrend->freq_buffer_im[i][offset_in]; + pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_re[i][j][offset]; + pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_im[i][j][offset]; + + for ( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max[i][j][m]; k++ ) + { + tmp_out_re[k] += pFreq_buf_re[k] * pFreq_filt_re[k] - pFreq_buf_im[k] * pFreq_filt_im[k]; + tmp_out_im[k] += pFreq_buf_re[k] * pFreq_filt_im[k] + pFreq_buf_im[k] * pFreq_filt_re[k]; + } + offset = offset + k; + } + i++; + } + } + + offset = 0; + for ( m = 0; m < pCrend->hHrtfCrend->num_iterations_diffuse[j]; m++ ) + { + offset_diffuse = ( pCrend->hCrend->diffuse_delay_line_rw_index + m + 1 ); + offset_diffuse = offset_diffuse % pCrend->hHrtfCrend->num_iterations_diffuse[0]; + offset_diffuse = offset_diffuse * subframe_length; + pFreq_buf_re = &pCrend->hCrend->freq_buffer_re_diffuse[offset_diffuse]; + pFreq_buf_im = &pCrend->hCrend->freq_buffer_im_diffuse[offset_diffuse]; + pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_re[j][offset]; + pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_im[j][offset]; + + for ( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max_diffuse[j][m]; k++ ) + { + tmp_out_re[k] += pFreq_buf_re[k] * pFreq_filt_re[k] - pFreq_buf_im[k] * pFreq_filt_im[k]; + tmp_out_im[k] += pFreq_buf_re[k] * pFreq_filt_im[k] + pFreq_buf_im[k] * pFreq_filt_re[k]; + } + offset = offset + k; + } + + ivas_imdft( tmp_out_re, tmp_out_im, pOut, subframe_length ); + + pFreq_buf_re = &pcm_out[j][i_ts * subframe_length]; + for ( k = 0; k < subframe_length; k++ ) + { + pFreq_buf_re[k] = pOut[k] + pCrend->hCrend->prev_out_buffer[j][k]; + pCrend->hCrend->prev_out_buffer[j][k] = pOut[k + subframe_length]; + } + } + + pCrend->hCrend->delay_line_rw_index++; + pCrend->hCrend->delay_line_rw_index = pCrend->hCrend->delay_line_rw_index % ( pCrend->hHrtfCrend->max_num_iterations ); + if ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 ) + { + pCrend->hCrend->diffuse_delay_line_rw_index++; + pCrend->hCrend->diffuse_delay_line_rw_index = pCrend->hCrend->diffuse_delay_line_rw_index % ( pCrend->hHrtfCrend->num_iterations_diffuse[0] ); + } + + return IVAS_ERR_OK; +} + +#endif + /*-----------------------------------------------------------------------------------------* * Function ivas_rend_crend_Process() * @@ -2022,6 +2179,8 @@ ivas_error ivas_rend_crendProcess( return IVAS_ERR_OK; } +#ifndef FIX_197_CREND_INTERFACE + /*-----------------------------------------------------------------------------------------* * Function ivas_crend_convolver() * @@ -2174,3 +2333,5 @@ ivas_error ivas_rend_crendConvolver( return IVAS_ERR_OK; } + +#endif diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 641c757b4c..ff7ba6e275 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -3580,15 +3580,22 @@ ivas_error IVAS_REND_InitConfig( IVAS_REND_HANDLE st, st->rendererConfigEnabled = 0; } - if ( ( error = ivas_render_config_open( &( st->hRendererConfig ) ) ) != IVAS_ERR_OK ) +#ifdef FIX_197_CREND_INTERFACE + if ( rendererConfigEnabled ) { - return error; - } +#endif + if ( ( error = ivas_render_config_open( &( st->hRendererConfig ) ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( ivas_render_config_init_from_rom( &st->hRendererConfig, st->rendererConfigEnabled ) != IVAS_ERR_OK ) - { - return IVAS_ERR_INTERNAL_FATAL; + if ( ivas_render_config_init_from_rom( &st->hRendererConfig, st->rendererConfigEnabled ) != IVAS_ERR_OK ) + { + return IVAS_ERR_INTERNAL_FATAL; + } +#ifdef FIX_197_CREND_INTERFACE } +#endif return IVAS_ERR_OK; } -- GitLab From f0c250d65afa54d1b8bce393a752c07e01317e65 Mon Sep 17 00:00:00 2001 From: muxe6256 Date: Sat, 21 Jan 2023 09:21:30 +0100 Subject: [PATCH 8/8] fix masan renderer error --- lib_rend/lib_rend.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index ff7ba6e275..237838499e 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -3583,7 +3583,6 @@ ivas_error IVAS_REND_InitConfig( IVAS_REND_HANDLE st, #ifdef FIX_197_CREND_INTERFACE if ( rendererConfigEnabled ) { -#endif if ( ( error = ivas_render_config_open( &( st->hRendererConfig ) ) ) != IVAS_ERR_OK ) { return error; @@ -3593,7 +3592,20 @@ ivas_error IVAS_REND_InitConfig( IVAS_REND_HANDLE st, { return IVAS_ERR_INTERNAL_FATAL; } -#ifdef FIX_197_CREND_INTERFACE + } + else + { + st->hRendererConfig = NULL; + } +#else + if ( ( error = ivas_render_config_open( &( st->hRendererConfig ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ivas_render_config_init_from_rom( &st->hRendererConfig, st->rendererConfigEnabled ) != IVAS_ERR_OK ) + { + return IVAS_ERR_INTERNAL_FATAL; } #endif -- GitLab