From a815f3b736cb48bdc19890498cbb19b7c1adfd81 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Fri, 21 Oct 2022 00:04:40 +0200 Subject: [PATCH 01/16] added get/feed renderconfig --- apps/renderer.c | 50 +++++++++++++++++++++++++-- lib_rend/lib_rend.c | 82 +++++++++++++++++++++++++++++++++++++++++++++ lib_rend/lib_rend.h | 10 ++++++ 3 files changed, 139 insertions(+), 3 deletions(-) diff --git a/apps/renderer.c b/apps/renderer.c index 3369dfcee2..66c0a01d07 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -40,10 +40,10 @@ #include "hrtf_file_reader.h" #include "ism_file_reader.h" #include "lib_rend.h" +#include "render_config_reader.h" #include "ls_custom_file_reader.h" #include "masa_file_reader.h" #include "prot.h" -#include "render_config_reader.h" #ifdef WMOPS #include "PROM_Size_lib_rend.h" #include "wmops.h" @@ -460,8 +460,11 @@ int32_t main( int32_t argc, char **argv ) if ( args.renderConfigFile[0] != '\0' ) { - RenderConfigReader_open( args.renderConfigFile, &renderConfigReader ); - } + if ( ( error = RenderConfigReader_open( args.renderConfigFile, &renderConfigReader ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: Can't open Renderer configuration file %s \n\n", args.renderConfigFile ); + exit( -1 ); + } } if ( args.sceneDescriptionInput ) { @@ -585,6 +588,47 @@ int32_t main( int32_t argc, char **argv ) hMasaMetadata = MasaFileReader_getMetadataHandle( masaReader ); } + if ( args.renderConfigFile[0] != '\0' ) + { + IVAS_RENDER_CONFIG_DATA renderConfig; + + /* sanity check */ +/* if ( args.outConfig.audioConfig != IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) + { + fprintf( stderr, "\nExternal Renderer Config is supported only when BINAURAL_ROOM is used as output. Exiting. \n" ); + exit( -1 ); // goto cleanup; + } + + if ( ( error = ivas_render_config_open( &hIvasRend->hRendererConfig ) ) != IVAS_ERR_OK ) + { + ivas_render_config_open(&renderConfig); + return error; + } + + if ( ivas_render_config_init_from_rom( &st->hRendererConfig, st->rendererConfigEnabled ) != IVAS_ERR_OK ) + { + return IVAS_ERR_INTERNAL_FATAL; + } +*/ + if ( ( error = IVAS_REND_GetRenderConfig( hIvasRend, &renderConfig ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_GetRenderConfig failed\n" ); + exit( -1 ); // goto cleanup; + } + + if ( RenderConfigReader_read( renderConfigReader, &renderConfig ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Failed to read renderer configuration from file %s\n", args.renderConfigFile ); + exit( -1 ); // goto cleanup; + } + + if ( ( error = IVAS_REND_FeedRenderConfig( hIvasRend, renderConfig ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_FeedRenderConfig failed\n" ); + exit( -1 ); // goto cleanup; + } + } + int32_t numOutChannels; if ( ( error = IVAS_REND_NumOutChannels( hIvasRend, &numOutChannels ) ) != IVAS_ERR_OK ) { diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index b31ffafac5..5fb320e01a 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -152,6 +152,7 @@ struct IVAS_REND EFAP_WRAPPER efapOutWrapper; IVAS_LSSETUP_CUSTOM_STRUCT customLsOut; IVAS_REND_HeadRotData headRotData; + RENDER_CONFIG_DATA *hRendererConfig; /* Renderer config pointer */ }; static int32_t limitRendererOutput( @@ -2627,6 +2628,87 @@ ivas_error IVAS_REND_FeedInputObjectMetadata( return IVAS_ERR_OK; } + +int16_t IVAS_REND_GetRenderConfig( + IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ + const IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render configuration handle */ +) +{ + RENDER_CONFIG_HANDLE hRCin; + + if ( hIvasRend == NULL || hIvasRend->hRendererConfig == NULL || hRCout == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + hRCin = hIvasRend->hRendererConfig; +#ifdef DEBUGGING + switch ( hRCin->renderer_type_override ) + { + case RENDER_TYPE_OVERRIDE_CREND: + hRCout->renderer_type_override = IVAS_RENDER_TYPE_OVERRIDE_CREND; + break; + case RENDER_TYPE_OVERRIDE_FASTCONV: + hRCout->renderer_type_override = IVAS_RENDER_TYPE_OVERRIDE_FASTCONV; + break; + default: + hRCout->renderer_type_override = IVAS_RENDER_TYPE_OVERRIDE_NONE; + break; + } +#endif + hRCout->room_acoustics.override = hRCin->roomAcoustics.override; + hRCout->room_acoustics.use_brir = hRCin->roomAcoustics.use_brir; + hRCout->room_acoustics.late_reverb_on = hRCin->roomAcoustics.late_reverb_on; + hRCout->room_acoustics.nBands = hRCin->roomAcoustics.nBands; + hRCout->room_acoustics.acousticPreDelay = hRCin->roomAcoustics.acousticPreDelay; + hRCout->room_acoustics.inputPreDelay = hRCin->roomAcoustics.inputPreDelay; + + mvr2r( hRCin->roomAcoustics.pFc_input, hRCout->room_acoustics.pFc_input, CLDFB_NO_CHANNELS_MAX ); + mvr2r( hRCin->roomAcoustics.pAcoustic_rt60, hRCout->room_acoustics.pAcoustic_rt60, CLDFB_NO_CHANNELS_MAX ); + mvr2r( hRCin->roomAcoustics.pAcoustic_dsr, hRCout->room_acoustics.pAcoustic_dsr, CLDFB_NO_CHANNELS_MAX ); + + return IVAS_ERR_OK; +} + + +int16_t IVAS_REND_FeedRenderConfig( + IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ + const IVAS_RENDER_CONFIG_DATA renderConfig /* i : Render configuration struct */ +) +{ + RENDER_CONFIG_HANDLE hRenderConfig; + + if ( hIvasRend == NULL || hIvasRend->hRendererConfig == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + hRenderConfig = hIvasRend->hRendererConfig; +#ifdef DEBUGGING + hRenderConfig->renderer_type_override = RENDER_TYPE_OVERRIDE_NONE; + if ( renderConfig.renderer_type_override == IVAS_RENDER_TYPE_OVERRIDE_FASTCONV ) + { + hRenderConfig->renderer_type_override = RENDER_TYPE_OVERRIDE_FASTCONV; + } + if ( renderConfig.renderer_type_override == IVAS_RENDER_TYPE_OVERRIDE_CREND ) + { + hRenderConfig->renderer_type_override = RENDER_TYPE_OVERRIDE_CREND; + } +#endif + hRenderConfig->roomAcoustics.override = renderConfig.room_acoustics.override; + hRenderConfig->roomAcoustics.use_brir = renderConfig.room_acoustics.use_brir; + hRenderConfig->roomAcoustics.late_reverb_on = renderConfig.room_acoustics.late_reverb_on; + hRenderConfig->roomAcoustics.nBands = renderConfig.room_acoustics.nBands; + hRenderConfig->roomAcoustics.acousticPreDelay = renderConfig.room_acoustics.acousticPreDelay; + hRenderConfig->roomAcoustics.inputPreDelay = renderConfig.room_acoustics.inputPreDelay; + mvr2r( renderConfig.room_acoustics.pFc_input, hRenderConfig->roomAcoustics.pFc_input, CLDFB_NO_CHANNELS_MAX ); + mvr2r( renderConfig.room_acoustics.pAcoustic_rt60, hRenderConfig->roomAcoustics.pAcoustic_rt60, CLDFB_NO_CHANNELS_MAX ); + mvr2r( renderConfig.room_acoustics.pAcoustic_dsr, hRenderConfig->roomAcoustics.pAcoustic_dsr, CLDFB_NO_CHANNELS_MAX ); + + return IVAS_ERR_OK; +} + + ivas_error IVAS_REND_SetHeadRotation( IVAS_REND_HANDLE hIvasRend, const IVAS_QUATERNION headRot[RENDERER_HEAD_POSITIONS_PER_FRAME] ) diff --git a/lib_rend/lib_rend.h b/lib_rend/lib_rend.h index 3be9ad9964..6093228adc 100644 --- a/lib_rend/lib_rend.h +++ b/lib_rend/lib_rend.h @@ -234,6 +234,16 @@ ivas_error IVAS_REND_FeedInputMasaMetadata( void* TODO ); +int16_t IVAS_REND_GetRenderConfig( + IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ + const IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render configuration handle */ +); + +int16_t IVAS_REND_FeedRenderConfig( + IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ + const IVAS_RENDER_CONFIG_DATA renderConfig /* i : Render configuration struct */ +); + ivas_error IVAS_REND_SetHeadRotation( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_QUATERNION headRot[RENDERER_HEAD_POSITIONS_PER_FRAME] /* i : head positions for next rendering call */ -- GitLab From 0e02fd9205d324e3f54a87d1d787c466af8ae207 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Sun, 23 Oct 2022 02:41:40 +0200 Subject: [PATCH 02/16] added render config open and init from rom --- apps/renderer.c | 19 +++++++------------ lib_rend/lib_rend.c | 31 +++++++++++++++++++++++++++++++ lib_rend/lib_rend.h | 6 ++++++ 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/apps/renderer.c b/apps/renderer.c index 66c0a01d07..186ca87c6c 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -588,28 +588,23 @@ int32_t main( int32_t argc, char **argv ) hMasaMetadata = MasaFileReader_getMetadataHandle( masaReader ); } + /* === Configure === */ + if ( ( error = IVAS_REND_ConfigureConfig( hIvasRend, args.trajectoryFile[0] != '\0', args.renderConfigFile[0] != '\0' ) ) != IVAS_ERR_OK ) + { + exit( -1 ); + } + if ( args.renderConfigFile[0] != '\0' ) { IVAS_RENDER_CONFIG_DATA renderConfig; /* sanity check */ -/* if ( args.outConfig.audioConfig != IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) + if ( args.outConfig.audioConfig != IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) { fprintf( stderr, "\nExternal Renderer Config is supported only when BINAURAL_ROOM is used as output. Exiting. \n" ); exit( -1 ); // goto cleanup; } - if ( ( error = ivas_render_config_open( &hIvasRend->hRendererConfig ) ) != IVAS_ERR_OK ) - { - ivas_render_config_open(&renderConfig); - return error; - } - - if ( ivas_render_config_init_from_rom( &st->hRendererConfig, st->rendererConfigEnabled ) != IVAS_ERR_OK ) - { - return IVAS_ERR_INTERNAL_FATAL; - } -*/ if ( ( error = IVAS_REND_GetRenderConfig( hIvasRend, &renderConfig ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_DEC_GetRenderConfig failed\n" ); diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 5fb320e01a..2caca428fb 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -151,7 +151,11 @@ struct IVAS_REND IVAS_REND_AudioConfig outputConfig; EFAP_WRAPPER efapOutWrapper; IVAS_LSSETUP_CUSTOM_STRUCT customLsOut; + + int8_t enableHeadRotation; /* head rotation flag */ IVAS_REND_HeadRotData headRotData; + + int8_t rendererConfigEnabled; RENDER_CONFIG_DATA *hRendererConfig; /* Renderer config pointer */ }; @@ -2628,6 +2632,33 @@ ivas_error IVAS_REND_FeedInputObjectMetadata( return IVAS_ERR_OK; } +ivas_error IVAS_REND_ConfigureConfig( IVAS_REND_HANDLE st, + bool headRotationEnabled, + bool rendererConfigEnabled ) +{ + ivas_error error; + + if ( headRotationEnabled ) + { + st->enableHeadRotation = 1; + } + + if ( rendererConfigEnabled ) + { + st->rendererConfigEnabled = 1; + } + + 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; + } + +} int16_t IVAS_REND_GetRenderConfig( IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ diff --git a/lib_rend/lib_rend.h b/lib_rend/lib_rend.h index 6093228adc..75d580e1c0 100644 --- a/lib_rend/lib_rend.h +++ b/lib_rend/lib_rend.h @@ -234,6 +234,12 @@ ivas_error IVAS_REND_FeedInputMasaMetadata( void* TODO ); +ivas_error IVAS_REND_ConfigureConfig( + IVAS_REND_HANDLE st, /* i/o: Renderer handle */ + bool headRotationEnabled, /* i : enable head rotation for binaural output, ignored for other output formats */ + bool rendererConfigEnabled /* i : flag indicating if a renderer configuration file was supplied */ +); + int16_t IVAS_REND_GetRenderConfig( IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ const IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render configuration handle */ -- GitLab From a51b2d3560e5c1ad587c68294a54a33fca3cb310 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Sun, 23 Oct 2022 03:12:51 +0200 Subject: [PATCH 03/16] return value --- lib_rend/lib_rend.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 2caca428fb..3405cbb548 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -2658,6 +2658,7 @@ ivas_error IVAS_REND_ConfigureConfig( IVAS_REND_HANDLE st, return IVAS_ERR_INTERNAL_FATAL; } + return IVAS_ERR_OK; } int16_t IVAS_REND_GetRenderConfig( -- GitLab From 891e871270c481b7f3b2c61b1ef30766ac8d4809 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Sun, 23 Oct 2022 03:56:48 +0200 Subject: [PATCH 04/16] added deallocation --- apps/renderer.c | 3 ++- lib_rend/lib_rend.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/renderer.c b/apps/renderer.c index 186ca87c6c..b6d51ce43c 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -464,7 +464,8 @@ int32_t main( int32_t argc, char **argv ) { fprintf( stderr, "\nError: Can't open Renderer configuration file %s \n\n", args.renderConfigFile ); exit( -1 ); - } } + } + } if ( args.sceneDescriptionInput ) { diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 3405cbb548..98fe8fdb1f 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -4095,6 +4095,10 @@ void IVAS_REND_Close( IVAS_REND_HANDLE *phIvasRend ) clearInputSba( &hIvasRend->inputsSba[i] ); } + /* clear Config. Renderer */ + ivas_render_config_close( &( hIvasRend->hRendererConfig ) ); + + ivas_limiter_close( &hIvasRend->hLimiter ); count_free( hIvasRend ); -- GitLab From d267a03c41aaf97ea72f6519228dab65fe8077ac Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Wed, 26 Oct 2022 01:11:10 +0200 Subject: [PATCH 05/16] fix compiler warnings --- lib_util/render_config_reader.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_util/render_config_reader.c b/lib_util/render_config_reader.c index 58e0eee286..27eed3bf14 100644 --- a/lib_util/render_config_reader.c +++ b/lib_util/render_config_reader.c @@ -419,7 +419,7 @@ ivas_error RenderConfigReader_read( while ( sscanf( pParams + params_idx, "%64[^=]=%[^;];", item, pValue ) == 2 ) { hRenderConfig->room_acoustics.override = true; - params_idx += strlen( item ) + strlen( pValue ) + 2; + params_idx += (int32_t) ( strlen( item ) + strlen( pValue ) + 2 ); #ifdef DEBUGGING fprintf( stderr, " PARAM: %s -> %s\n", item, pValue ); #endif @@ -506,7 +506,7 @@ ivas_error RenderConfigReader_read( pValue = (char *) calloc( strlen( pParams ), sizeof( char ) ); while ( sscanf( pParams + params_idx, "%64[^=]=%[^;];", item, pValue ) == 2 ) { - params_idx += strlen( item ) + strlen( pValue ) + 2; + params_idx += (int32_t) ( strlen( item ) + strlen( pValue ) + 2 ); fprintf( stderr, " PARAM: %s -> %s\n", item, pValue ); if ( strcmp( item, "RENDERER" ) == 0 ) { -- GitLab From af202945e86b23266b862c747e48d999bc61dc05 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Thu, 27 Oct 2022 12:48:10 +0200 Subject: [PATCH 06/16] interim commit to check changes on FhG branch --- lib_rend/ivas_crend.c | 20 +++++++++++--------- lib_rend/ivas_lib_rend_internal.h | 2 ++ lib_rend/lib_rend.c | 2 ++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index bec08cbbaf..defdbae74b 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -30,6 +30,7 @@ *******************************************************************************************************/ +#include "common_api_types.h" #include #include #include "options.h" @@ -1148,6 +1149,7 @@ ivas_error ivas_rend_openCrend( CREND_WRAPPER *pCrend, IVAS_REND_AudioConfig inConfig, IVAS_REND_AudioConfig outConfig, + //IVAS_RENDER_CONFIG_HANDLE hRendererConfig, int32_t output_Fs ) { /* TODO tmu : Based on ivas_crend_open() - could be harmonized / refactored */ @@ -1277,14 +1279,14 @@ ivas_error ivas_rend_openCrend( } /* TODO tmu : implement renderConfig */ - // if ( ( ( st_ivas->hRenderConfig != NULL ) && st_ivas->hRenderConfig->roomAcoustics.late_reverb_on ) ) - // { - // if ( ( error = ivas_reverb_open( &( hCrend->hReverb ), st_ivas->intern_config, hHrtf, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) - // { - // return error; - // } - // } - // else + //if ( ( ( hRendererConfig != NULL ) && hRendererConfig->room_acoustics.late_reverb_on ) ) + //{ + // //if ( ( error = ivas_reverb_open( &( hCrend->hReverb ), st_ivas->intern_config, hHrtf, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + // { + // return error; + // } + //} + //else { hCrend->hReverb = NULL; } @@ -1760,7 +1762,7 @@ ivas_error ivas_rend_closeCrend( } /*-----------------------------------------------------------------------------------------* - * Function ivas_crend_process() + * Function ivas_rend_crend_process() * * Process call for IVAS Crend renderer *-----------------------------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_lib_rend_internal.h b/lib_rend/ivas_lib_rend_internal.h index e82348484f..339131c811 100644 --- a/lib_rend/ivas_lib_rend_internal.h +++ b/lib_rend/ivas_lib_rend_internal.h @@ -1,3 +1,4 @@ +#include "common_api_types.h" #include "ivas_error.h" #include "lib_rend.h" #include "ivas_stat_dec.h" @@ -40,6 +41,7 @@ ivas_error ivas_rend_openCrend( CREND_WRAPPER *pCrend, IVAS_REND_AudioConfig inConfig, IVAS_REND_AudioConfig outConfig, +// IVAS_RENDER_CONFIG_HANDLE hRendererConfig, int32_t output_Fs ); ivas_error ivas_rend_initCrend( diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 98fe8fdb1f..6a803b1cd1 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -148,6 +148,7 @@ struct IVAS_REND input_mc inputsMc[RENDERER_MAX_MC_INPUTS]; input_sba inputsSba[RENDERER_MAX_SBA_INPUTS]; + IVAS_REND_AudioConfig inputConfig; IVAS_REND_AudioConfig outputConfig; EFAP_WRAPPER efapOutWrapper; IVAS_LSSETUP_CUSTOM_STRUCT customLsOut; @@ -3751,6 +3752,7 @@ static ivas_error renderActiveInputsMc( /* Skip inactive inputs */ continue; } + if ( ( error = renderInputMc( pCurrentInput, hIvasRend->outputConfig, outAudio ) ) != IVAS_ERR_OK ) -- GitLab From 7182b13c9dd4650967d6d21c0a17e0e58573503c Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Fri, 28 Oct 2022 01:09:44 +0200 Subject: [PATCH 07/16] wired up renderconfig to ivas_rend_openCrend and children --- apps/renderer.c | 72 +++++++++++++++---------------- lib_dec/ivas_stat_dec.h | 1 - lib_rend/ivas_crend.c | 31 +++++++------ lib_rend/ivas_lib_rend_internal.h | 3 +- lib_rend/lib_rend.c | 31 ++++++++----- 5 files changed, 75 insertions(+), 63 deletions(-) diff --git a/apps/renderer.c b/apps/renderer.c index b6d51ce43c..22311cfa96 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -501,6 +501,42 @@ int32_t main( int32_t argc, char **argv ) exit( -1 ); } + /* === Configure === */ + if ( ( error = IVAS_REND_ConfigureConfig( hIvasRend, args.trajectoryFile[0] != '\0', args.renderConfigFile[0] != '\0' ) ) != IVAS_ERR_OK ) + { + exit( -1 ); + } + + if ( args.renderConfigFile[0] != '\0' ) + { + IVAS_RENDER_CONFIG_DATA renderConfig; + + /* sanity check */ + if ( args.outConfig.audioConfig != IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) + { + fprintf( stderr, "\nExternal Renderer Config is supported only when BINAURAL_ROOM is used as output. Exiting. \n" ); + exit( -1 ); // goto cleanup; + } + + if ( ( error = IVAS_REND_GetRenderConfig( hIvasRend, &renderConfig ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_GetRenderConfig failed\n" ); + exit( -1 ); // goto cleanup; + } + + if ( RenderConfigReader_read( renderConfigReader, &renderConfig ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Failed to read renderer configuration from file %s\n", args.renderConfigFile ); + exit( -1 ); // goto cleanup; + } + + if ( ( error = IVAS_REND_FeedRenderConfig( hIvasRend, renderConfig ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_FeedRenderConfig failed\n" ); + exit( -1 ); // goto cleanup; + } + } + /* Set up output custom layout configuration */ if ( args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) { @@ -589,42 +625,6 @@ int32_t main( int32_t argc, char **argv ) hMasaMetadata = MasaFileReader_getMetadataHandle( masaReader ); } - /* === Configure === */ - if ( ( error = IVAS_REND_ConfigureConfig( hIvasRend, args.trajectoryFile[0] != '\0', args.renderConfigFile[0] != '\0' ) ) != IVAS_ERR_OK ) - { - exit( -1 ); - } - - if ( args.renderConfigFile[0] != '\0' ) - { - IVAS_RENDER_CONFIG_DATA renderConfig; - - /* sanity check */ - if ( args.outConfig.audioConfig != IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) - { - fprintf( stderr, "\nExternal Renderer Config is supported only when BINAURAL_ROOM is used as output. Exiting. \n" ); - exit( -1 ); // goto cleanup; - } - - if ( ( error = IVAS_REND_GetRenderConfig( hIvasRend, &renderConfig ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_GetRenderConfig failed\n" ); - exit( -1 ); // goto cleanup; - } - - if ( RenderConfigReader_read( renderConfigReader, &renderConfig ) != IVAS_ERR_OK ) - { - fprintf( stderr, "Failed to read renderer configuration from file %s\n", args.renderConfigFile ); - exit( -1 ); // goto cleanup; - } - - if ( ( error = IVAS_REND_FeedRenderConfig( hIvasRend, renderConfig ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_FeedRenderConfig failed\n" ); - exit( -1 ); // goto cleanup; - } - } - int32_t numOutChannels; if ( ( error = IVAS_REND_NumOutChannels( hIvasRend, &numOutChannels ) ) != IVAS_ERR_OK ) { diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 2284f9d09d..42354c201d 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1658,7 +1658,6 @@ typedef struct ivas_hrtfs_structure /* Reverberator structures */ - typedef struct ivas_roomAcoustics_t { int16_t override; diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index defdbae74b..924997f008 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -1149,7 +1149,7 @@ ivas_error ivas_rend_openCrend( CREND_WRAPPER *pCrend, IVAS_REND_AudioConfig inConfig, IVAS_REND_AudioConfig outConfig, - //IVAS_RENDER_CONFIG_HANDLE hRendererConfig, + RENDER_CONFIG_DATA *hRend, int32_t output_Fs ) { /* TODO tmu : Based on ivas_crend_open() - could be harmonized / refactored */ @@ -1164,7 +1164,7 @@ ivas_error ivas_rend_openCrend( if ( pCrend->hHrtfCrend == NULL ) { - if ( ( error = ivas_rend_initCrend( pCrend, inConfig, outConfig, output_Fs ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_rend_initCrend( pCrend, inConfig, outConfig, hRend, output_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -1278,15 +1278,19 @@ ivas_error ivas_rend_openCrend( hCrend->hTrack = NULL; } - /* TODO tmu : implement renderConfig */ - //if ( ( ( hRendererConfig != NULL ) && hRendererConfig->room_acoustics.late_reverb_on ) ) - //{ - // //if ( ( error = ivas_reverb_open( &( hCrend->hReverb ), st_ivas->intern_config, hHrtf, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) - // { - // return error; - // } - //} - //else + if ( ( hRend != NULL ) && (hRend->roomAcoustics.late_reverb_on ) ) + { + if ( ( error = ivas_reverb_open( &(hCrend->hReverb), + getIvasAudioConfigFromRendAudioConfig( inConfig ), + pCrend->hHrtfCrend, + hRend, + output_Fs + ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else { hCrend->hReverb = NULL; } @@ -1308,6 +1312,7 @@ ivas_error ivas_rend_initCrend( CREND_WRAPPER *pCrend, IVAS_REND_AudioConfig inConfig, IVAS_REND_AudioConfig outConfig, + RENDER_CONFIG_DATA *hRend, int32_t output_Fs ) { int16_t i, j, tmp; @@ -1339,9 +1344,7 @@ ivas_error ivas_rend_initCrend( /* set BRIR flag */ use_brir = false; - /* TODO tmu : pass down render config handle */ - // if ((pCrend->hRenderConfig != NULL && pCrend->hRenderConfig->roomAcoustics.use_brir) || outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) - if ( outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) + if ( (hRend != NULL && hRend->roomAcoustics.use_brir ) || outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) { use_brir = true; } diff --git a/lib_rend/ivas_lib_rend_internal.h b/lib_rend/ivas_lib_rend_internal.h index 339131c811..0628e4d4b0 100644 --- a/lib_rend/ivas_lib_rend_internal.h +++ b/lib_rend/ivas_lib_rend_internal.h @@ -41,13 +41,14 @@ ivas_error ivas_rend_openCrend( CREND_WRAPPER *pCrend, IVAS_REND_AudioConfig inConfig, IVAS_REND_AudioConfig outConfig, -// IVAS_RENDER_CONFIG_HANDLE hRendererConfig, + RENDER_CONFIG_DATA *hRend, int32_t output_Fs ); ivas_error ivas_rend_initCrend( CREND_WRAPPER *pCrend, IVAS_REND_AudioConfig inConfig, IVAS_REND_AudioConfig outConfig, + RENDER_CONFIG_DATA *hRend, int32_t output_Fs ); ivas_error ivas_rend_closeCrend( diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 6a803b1cd1..1da589469f 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -887,7 +887,8 @@ static CREND_WRAPPER defaultCrendWrapper( void ) static ivas_error setRendInputActiveIsm( void *input, IVAS_REND_AudioConfig inConfig, - IVAS_REND_InputId id ) + IVAS_REND_InputId id, + RENDER_CONFIG_DATA *hRend ) { ivas_error error; rendering_context rendCtx; @@ -919,6 +920,7 @@ static ivas_error setRendInputActiveIsm( error = ivas_rend_openCrend( &inputIsm->crendWrapper, IVAS_REND_AUDIO_CONFIG_7_1_4, outConfig, + hRend, *rendCtx.pOutSampleRate ); } if ( error != IVAS_ERR_OK ) @@ -1428,7 +1430,8 @@ static void tmpFixBuggyTdBinRendInit( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRen static ivas_error initMcBinauralRendering( input_mc *inputMc, IVAS_REND_AudioConfig inConfig, - IVAS_REND_AudioConfig outConfig ) + IVAS_REND_AudioConfig outConfig, + RENDER_CONFIG_DATA *hRend ) { ivas_error error; int32_t outSampleRate; @@ -1480,6 +1483,7 @@ static ivas_error initMcBinauralRendering( if ( ( error = ivas_rend_openCrend( &inputMc->crendWrapper, ( inConfig == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) ? IVAS_REND_AUDIO_CONFIG_7_1_4 : inConfig, outConfig, + hRend, outSampleRate ) ) != IVAS_ERR_OK ) { return error; @@ -1547,7 +1551,8 @@ static IVAS_REND_LfeRouting defaultLfeRouting( static ivas_error setRendInputActiveMc( void *input, IVAS_REND_AudioConfig inConfig, - IVAS_REND_InputId id ) + IVAS_REND_InputId id, + RENDER_CONFIG_DATA *hRend ) { ivas_error error; rendering_context rendCtx; @@ -1571,7 +1576,7 @@ static ivas_error setRendInputActiveMc( if ( outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL || outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) { - if ( ( error = initMcBinauralRendering( inputMc, inConfig, outConfig ) ) != IVAS_ERR_OK ) + if ( ( error = initMcBinauralRendering( inputMc, inConfig, outConfig, hRend ) ) != IVAS_ERR_OK ) { return error; } @@ -1695,7 +1700,7 @@ static ivas_error initSbaPanGainsForSbaOut( input_sba *inputSba, IVAS_REND_Audio return error; } -static ivas_error updateSbaPanGains( input_sba *inputSba, IVAS_REND_AudioConfig outConfig ) +static ivas_error updateSbaPanGains( input_sba *inputSba, IVAS_REND_AudioConfig outConfig, RENDER_CONFIG_DATA *hRend ) { ivas_error error; IVAS_REND_AudioConfig inConfig; @@ -1722,6 +1727,7 @@ static ivas_error updateSbaPanGains( input_sba *inputSba, IVAS_REND_AudioConfig error = ivas_rend_openCrend( &inputSba->crendWrapper, inConfig, outConfig, + hRend, *rendCtx.pOutSampleRate ); break; case IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM: @@ -1732,6 +1738,7 @@ static ivas_error updateSbaPanGains( input_sba *inputSba, IVAS_REND_AudioConfig error = ivas_rend_openCrend( &inputSba->crendWrapper, IVAS_REND_AUDIO_CONFIG_7_1_4, outConfig, + hRend, *rendCtx.pOutSampleRate ); break; default: @@ -1753,7 +1760,8 @@ static ivas_error updateSbaPanGains( input_sba *inputSba, IVAS_REND_AudioConfig static ivas_error setRendInputActiveSba( void *input, IVAS_REND_AudioConfig inConfig, - IVAS_REND_InputId id ) + IVAS_REND_InputId id, + RENDER_CONFIG_DATA *hRend ) { ivas_error error; rendering_context rendCtx; @@ -1769,7 +1777,7 @@ static ivas_error setRendInputActiveSba( inputSba->crendWrapper = defaultCrendWrapper(); initRotGains( inputSba->rot_gains_prev ); - if ( ( error = updateSbaPanGains( inputSba, outConfig ) ) != IVAS_ERR_OK ) + if ( ( error = updateSbaPanGains( inputSba, outConfig, hRend ) ) != IVAS_ERR_OK ) { return error; } @@ -2007,7 +2015,7 @@ ivas_error IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( /* Input inactive, skip. */ continue; } - if ( ( error = updateSbaPanGains( inputSba, hIvasRend->outputConfig ) ) != IVAS_ERR_OK ) + if ( ( error = updateSbaPanGains( inputSba, hIvasRend->outputConfig, hIvasRend->hRendererConfig ) ) != IVAS_ERR_OK ) { return error; } @@ -2217,7 +2225,7 @@ ivas_error IVAS_REND_AddInput( int32_t maxNumInputsOfType; void *inputsArray; int32_t inputStructSize; - ivas_error ( *activateInput )( void *, IVAS_REND_AudioConfig, IVAS_REND_InputId ); + ivas_error ( *activateInput )( void *, IVAS_REND_AudioConfig, IVAS_REND_InputId, RENDER_CONFIG_DATA * ); int32_t inputIndex; /*-----------------------------------------------------------------* @@ -2266,7 +2274,8 @@ ivas_error IVAS_REND_AddInput( if ( ( error = activateInput( (uint8_t *) inputsArray + inputStructSize * inputIndex, inConfig, - *inputId ) ) != IVAS_ERR_OK ) + *inputId, + hIvasRend->hRendererConfig ) ) != IVAS_ERR_OK ) { return error; } @@ -2318,7 +2327,7 @@ ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout( if ( hIvasRend->outputConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL || hIvasRend->outputConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) { - if ( ( error = initMcBinauralRendering( inputMc, inputMc->base.inConfig, hIvasRend->outputConfig ) ) != IVAS_ERR_OK ) + if ( ( error = initMcBinauralRendering( inputMc, inputMc->base.inConfig, hIvasRend->outputConfig, hIvasRend->hRendererConfig ) ) != IVAS_ERR_OK ) { return error; } -- GitLab From c989e5df084115413d4cbbebdccef5383bd1a8c1 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Wed, 2 Nov 2022 15:30:19 +0100 Subject: [PATCH 08/16] remove redundant dependencies --- lib_rend/ivas_crend.c | 1 - lib_rend/ivas_lib_rend_internal.h | 1 - 2 files changed, 2 deletions(-) diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 0f27efc55c..c87a61e44f 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -30,7 +30,6 @@ *******************************************************************************************************/ -#include "common_api_types.h" #include #include #include "options.h" diff --git a/lib_rend/ivas_lib_rend_internal.h b/lib_rend/ivas_lib_rend_internal.h index fb53d22a59..117d492d17 100644 --- a/lib_rend/ivas_lib_rend_internal.h +++ b/lib_rend/ivas_lib_rend_internal.h @@ -1,4 +1,3 @@ -#include "common_api_types.h" #include "ivas_error.h" #include "lib_rend.h" #include "ivas_stat_dec.h" -- GitLab From af9e776a708c36752c82ff08feabbc23b1705875 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Wed, 2 Nov 2022 22:33:33 +0100 Subject: [PATCH 09/16] added lib_rend_internal.h to MSVC project and added IVAS header --- Workspace_msvc/lib_rend.vcxproj | 1 + 1 file changed, 1 insertion(+) diff --git a/Workspace_msvc/lib_rend.vcxproj b/Workspace_msvc/lib_rend.vcxproj index e87baf5605..c3a1268694 100644 --- a/Workspace_msvc/lib_rend.vcxproj +++ b/Workspace_msvc/lib_rend.vcxproj @@ -229,6 +229,7 @@ + -- GitLab From c671ada28040bf84fcd42075662c50f60309192c Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Wed, 2 Nov 2022 22:37:32 +0100 Subject: [PATCH 10/16] rename ConfigureConfig to InitConfig --- apps/renderer.c | 2 +- lib_rend/ivas_lib_rend_internal.h | 32 +++++++++++++++++++++++++++++++ lib_rend/lib_rend.c | 2 +- lib_rend/lib_rend.h | 2 +- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/apps/renderer.c b/apps/renderer.c index 88a8aa88a4..e4d6bf36d0 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -665,7 +665,7 @@ int32_t main( int32_t argc, char **argv ) } /* === Configure === */ - if ( ( error = IVAS_REND_ConfigureConfig( hIvasRend, headRotReader != NULL, args.renderConfigFilePath[0] != '\0' ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_REND_InitConfig( hIvasRend, headRotReader != NULL, args.renderConfigFilePath[0] != '\0' ) ) != IVAS_ERR_OK ) { exit( -1 ); } diff --git a/lib_rend/ivas_lib_rend_internal.h b/lib_rend/ivas_lib_rend_internal.h index 117d492d17..773b75309b 100644 --- a/lib_rend/ivas_lib_rend_internal.h +++ b/lib_rend/ivas_lib_rend_internal.h @@ -1,3 +1,35 @@ +/****************************************************************************************************** + + (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. + +*******************************************************************************************************/ + #include "ivas_error.h" #include "lib_rend.h" #include "ivas_stat_dec.h" diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index e6ac1967ae..eea5a0c7ea 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -2640,7 +2640,7 @@ ivas_error IVAS_REND_FeedInputObjectMetadata( return IVAS_ERR_OK; } -ivas_error IVAS_REND_ConfigureConfig( IVAS_REND_HANDLE st, +ivas_error IVAS_REND_InitConfig( IVAS_REND_HANDLE st, bool headRotationEnabled, bool rendererConfigEnabled ) { diff --git a/lib_rend/lib_rend.h b/lib_rend/lib_rend.h index 7e3d07c0fd..924bc0e6fe 100644 --- a/lib_rend/lib_rend.h +++ b/lib_rend/lib_rend.h @@ -236,7 +236,7 @@ ivas_error IVAS_REND_FeedInputMasaMetadata( void* TODO ); -ivas_error IVAS_REND_ConfigureConfig( +ivas_error IVAS_REND_InitConfig( IVAS_REND_HANDLE st, /* i/o: Renderer handle */ bool headRotationEnabled, /* i : enable head rotation for binaural output, ignored for other output formats */ bool rendererConfigEnabled /* i : flag indicating if a renderer configuration file was supplied */ -- GitLab From 7a1aa576f8f9b55b914da57bb6264e508e4611d6 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Wed, 2 Nov 2022 22:41:25 +0100 Subject: [PATCH 11/16] renamed hRend to hRendCfg --- lib_rend/ivas_crend.c | 12 ++++++------ lib_rend/lib_rend.c | 22 +++++++++++----------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index c87a61e44f..ae910b1f25 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -1148,7 +1148,7 @@ ivas_error ivas_rend_openCrend( CREND_WRAPPER *pCrend, IVAS_REND_AudioConfig inConfig, IVAS_REND_AudioConfig outConfig, - RENDER_CONFIG_DATA *hRend, + RENDER_CONFIG_DATA *hRendCfg, int32_t output_Fs ) { /* TODO tmu : Based on ivas_crend_open() - could be harmonized / refactored */ @@ -1163,7 +1163,7 @@ ivas_error ivas_rend_openCrend( if ( pCrend->hHrtfCrend == NULL ) { - if ( ( error = ivas_rend_initCrend( pCrend, inConfig, outConfig, hRend, output_Fs ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_rend_initCrend( pCrend, inConfig, outConfig, hRendCfg, output_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -1277,12 +1277,12 @@ ivas_error ivas_rend_openCrend( hCrend->hTrack = NULL; } - if ( ( hRend != NULL ) && (hRend->roomAcoustics.late_reverb_on ) ) + if ( ( hRendCfg != NULL ) && (hRendCfg->roomAcoustics.late_reverb_on ) ) { if ( ( error = ivas_reverb_open( &(hCrend->hReverb), getIvasAudioConfigFromRendAudioConfig( inConfig ), pCrend->hHrtfCrend, - hRend, + hRendCfg, output_Fs ) ) != IVAS_ERR_OK ) { @@ -1311,7 +1311,7 @@ ivas_error ivas_rend_initCrend( CREND_WRAPPER *pCrend, IVAS_REND_AudioConfig inConfig, IVAS_REND_AudioConfig outConfig, - RENDER_CONFIG_DATA *hRend, + RENDER_CONFIG_DATA *hRendCfg, int32_t output_Fs ) { int16_t i, j, tmp; @@ -1343,7 +1343,7 @@ ivas_error ivas_rend_initCrend( /* set BRIR flag */ use_brir = false; - if ( (hRend != NULL && hRend->roomAcoustics.use_brir ) || outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) + if ( (hRendCfg != NULL && hRendCfg->roomAcoustics.use_brir ) || outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) { use_brir = true; } diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index eea5a0c7ea..3a3fb1658b 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -886,7 +886,7 @@ static ivas_error setRendInputActiveIsm( void *input, IVAS_REND_AudioConfig inConfig, IVAS_REND_InputId id, - RENDER_CONFIG_DATA *hRend ) + RENDER_CONFIG_DATA *hRendCfg ) { ivas_error error; rendering_context rendCtx; @@ -918,7 +918,7 @@ static ivas_error setRendInputActiveIsm( error = ivas_rend_openCrend( &inputIsm->crendWrapper, IVAS_REND_AUDIO_CONFIG_7_1_4, outConfig, - hRend, + hRendCfg, *rendCtx.pOutSampleRate ); } if ( error != IVAS_ERR_OK ) @@ -1429,7 +1429,7 @@ static ivas_error initMcBinauralRendering( input_mc *inputMc, IVAS_REND_AudioConfig inConfig, IVAS_REND_AudioConfig outConfig, - RENDER_CONFIG_DATA *hRend ) + RENDER_CONFIG_DATA *hRendCfg ) { ivas_error error; int32_t outSampleRate; @@ -1481,7 +1481,7 @@ static ivas_error initMcBinauralRendering( if ( ( error = ivas_rend_openCrend( &inputMc->crendWrapper, ( inConfig == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) ? IVAS_REND_AUDIO_CONFIG_7_1_4 : inConfig, outConfig, - hRend, + hRendCfg, outSampleRate ) ) != IVAS_ERR_OK ) { return error; @@ -1550,7 +1550,7 @@ static ivas_error setRendInputActiveMc( void *input, IVAS_REND_AudioConfig inConfig, IVAS_REND_InputId id, - RENDER_CONFIG_DATA *hRend ) + RENDER_CONFIG_DATA *hRendCfg ) { ivas_error error; rendering_context rendCtx; @@ -1574,7 +1574,7 @@ static ivas_error setRendInputActiveMc( if ( outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL || outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) { - if ( ( error = initMcBinauralRendering( inputMc, inConfig, outConfig, hRend ) ) != IVAS_ERR_OK ) + if ( ( error = initMcBinauralRendering( inputMc, inConfig, outConfig, hRendCfg ) ) != IVAS_ERR_OK ) { return error; } @@ -1698,7 +1698,7 @@ static ivas_error initSbaPanGainsForSbaOut( input_sba *inputSba, IVAS_REND_Audio return error; } -static ivas_error updateSbaPanGains( input_sba *inputSba, IVAS_REND_AudioConfig outConfig, RENDER_CONFIG_DATA *hRend ) +static ivas_error updateSbaPanGains( input_sba *inputSba, IVAS_REND_AudioConfig outConfig, RENDER_CONFIG_DATA *hRendCfg ) { ivas_error error; IVAS_REND_AudioConfig inConfig; @@ -1725,7 +1725,7 @@ static ivas_error updateSbaPanGains( input_sba *inputSba, IVAS_REND_AudioConfig error = ivas_rend_openCrend( &inputSba->crendWrapper, inConfig, outConfig, - hRend, + hRendCfg, *rendCtx.pOutSampleRate ); break; case IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM: @@ -1736,7 +1736,7 @@ static ivas_error updateSbaPanGains( input_sba *inputSba, IVAS_REND_AudioConfig error = ivas_rend_openCrend( &inputSba->crendWrapper, IVAS_REND_AUDIO_CONFIG_7_1_4, outConfig, - hRend, + hRendCfg, *rendCtx.pOutSampleRate ); break; default: @@ -1759,7 +1759,7 @@ static ivas_error setRendInputActiveSba( void *input, IVAS_REND_AudioConfig inConfig, IVAS_REND_InputId id, - RENDER_CONFIG_DATA *hRend ) + RENDER_CONFIG_DATA *hRendCfg ) { ivas_error error; rendering_context rendCtx; @@ -1775,7 +1775,7 @@ static ivas_error setRendInputActiveSba( inputSba->crendWrapper = defaultCrendWrapper(); initRotGains( inputSba->rot_gains_prev ); - if ( ( error = updateSbaPanGains( inputSba, outConfig, hRend ) ) != IVAS_ERR_OK ) + if ( ( error = updateSbaPanGains( inputSba, outConfig, hRendCfg ) ) != IVAS_ERR_OK ) { return error; } -- GitLab From e8691f0132194a3a1d4b1354aa06c205c3182d80 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Wed, 2 Nov 2022 22:45:05 +0100 Subject: [PATCH 12/16] cosmetics --- apps/renderer.c | 8 ++++---- lib_rend/lib_rend.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/renderer.c b/apps/renderer.c index e4d6bf36d0..5345c938ca 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -678,25 +678,25 @@ int32_t main( int32_t argc, char **argv ) if ( args.outConfig.audioConfig != IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) { fprintf( stderr, "\nExternal Renderer Config is supported only when BINAURAL_ROOM is used as output. Exiting. \n" ); - exit( -1 ); // goto cleanup; + exit( -1 ); } if ( ( error = IVAS_REND_GetRenderConfig( hIvasRend, &renderConfig ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_DEC_GetRenderConfig failed\n" ); - exit( -1 ); // goto cleanup; + exit( -1 ); } if ( RenderConfigReader_read( renderConfigReader, &renderConfig ) != IVAS_ERR_OK ) { fprintf( stderr, "Failed to read renderer configuration from file %s\n", args.renderConfigFilePath ); - exit( -1 ); // goto cleanup; + exit( -1 ); } if ( ( error = IVAS_REND_FeedRenderConfig( hIvasRend, renderConfig ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_DEC_FeedRenderConfig failed\n" ); - exit( -1 ); // goto cleanup; + exit( -1 ); } } diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 3a3fb1658b..aa3fb2599f 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -2670,7 +2670,7 @@ ivas_error IVAS_REND_InitConfig( IVAS_REND_HANDLE st, } int16_t IVAS_REND_GetRenderConfig( - IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ + IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ const IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render configuration handle */ ) { @@ -2712,7 +2712,7 @@ int16_t IVAS_REND_GetRenderConfig( int16_t IVAS_REND_FeedRenderConfig( - IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ + IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ const IVAS_RENDER_CONFIG_DATA renderConfig /* i : Render configuration struct */ ) { -- GitLab From b45c0e3f9794495ceff6b34585dee4dd4a499eaf Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Wed, 2 Nov 2022 22:47:51 +0100 Subject: [PATCH 13/16] pacifying compiler --- apps/renderer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/renderer.c b/apps/renderer.c index 5345c938ca..05de0db262 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -2214,7 +2214,7 @@ static void convert_backslash( char *str ) int32_t i, len; /* check that all backslashes are correct on the given platform */ - len = strlen( str ); + len = (int32_t) strlen( str ); for ( i = 0; i < len; i++ ) { -- GitLab From 2ebf0e7b99819fe947b0ef38d07cf2efee79b439 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Tue, 8 Nov 2022 00:03:30 +0100 Subject: [PATCH 14/16] fix 21 renderer test fails --- apps/renderer.c | 2 +- lib_rend/lib_rend.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/renderer.c b/apps/renderer.c index 05de0db262..7cae5dd044 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -665,7 +665,7 @@ int32_t main( int32_t argc, char **argv ) } /* === Configure === */ - if ( ( error = IVAS_REND_InitConfig( hIvasRend, headRotReader != NULL, args.renderConfigFilePath[0] != '\0' ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_REND_InitConfig( hIvasRend, headRotReader != NULL, strlen(args.renderConfigFilePath) != 0 ) ) != IVAS_ERR_OK ) { exit( -1 ); } diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index aa3fb2599f..9366003b08 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -2650,11 +2650,19 @@ ivas_error IVAS_REND_InitConfig( IVAS_REND_HANDLE st, { st->enableHeadRotation = 1; } + else + { + st->enableHeadRotation = 0; + } if ( rendererConfigEnabled ) { st->rendererConfigEnabled = 1; } + else + { + st->rendererConfigEnabled = 0; + } if ( ( error = ivas_render_config_open( &( st->hRendererConfig ) ) ) != IVAS_ERR_OK ) { -- GitLab From 034ca33e5ac406f2c8b8c637fbb49aab17a258d9 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Tue, 8 Nov 2022 14:46:20 +0100 Subject: [PATCH 15/16] merge with FhG/external-renderer --- apps/encoder.c | 34 +- apps/renderer.c | 365 +++++---- ci/run_scheduled_sanitizer_test.py | 7 +- ci/smoke_test.sh | 7 +- lib_com/cnst.h | 3 + lib_com/fill_spectrum.c | 8 - lib_com/ivas_cnst.h | 12 +- lib_com/ivas_cov_smooth.c | 41 +- lib_com/ivas_error.h | 3 + lib_com/ivas_prot.h | 75 +- lib_com/ivas_rom_com.c | 32 +- lib_com/ivas_sba_config.c | 34 +- lib_com/ivas_spar_com.c | 31 +- lib_com/ivas_stat_com.h | 10 - lib_com/ivas_stereo_psychlpc_com.c | 16 +- lib_com/options.h | 23 +- lib_com/vlpc_2st_com.c | 3 +- lib_debug/mem_count.c | 5 +- lib_dec/dec_tcx.c | 16 +- lib_dec/igf_dec.c | 7 +- lib_dec/init_dec.c | 7 +- lib_dec/ivas_agc_dec.c | 15 + lib_dec/ivas_core_dec.c | 24 +- lib_dec/ivas_corecoder_dec_reconfig.c | 4 - lib_dec/ivas_dirac_dec.c | 6 +- lib_dec/ivas_dirac_dec_binaural_functions.c | 4 +- lib_dec/ivas_init_dec.c | 31 +- lib_dec/ivas_ism_param_dec.c | 94 --- lib_dec/ivas_ism_renderer.c | 2 +- lib_dec/ivas_mct_dec_mct.c | 4 - lib_dec/ivas_mdct_core_dec.c | 6 - lib_dec/ivas_mono_dmx_renderer.c | 2 +- lib_dec/ivas_out_setup_conversion.c | 2 +- lib_dec/ivas_post_proc.c | 4 + lib_dec/ivas_rom_dec.c | 2 +- lib_dec/ivas_sba_dec.c | 779 ++++++++++++-------- lib_dec/ivas_spar_decoder.c | 39 +- lib_dec/ivas_spar_md_dec.c | 429 +++++------ lib_dec/ivas_stat_dec.h | 21 +- lib_dec/ivas_stereo_mdct_core_dec.c | 4 - lib_dec/ivas_stereo_mdct_stereo_dec.c | 12 - lib_dec/ivas_tcx_core_dec.c | 70 ++ lib_dec/ivas_vbap.c | 2 +- lib_dec/lib_dec.c | 2 +- lib_enc/igf_enc.c | 6 +- lib_enc/init_enc.c | 7 +- lib_enc/ivas_agc_enc.c | 52 +- lib_enc/ivas_core_enc.c | 18 +- lib_enc/ivas_core_pre_proc.c | 12 +- lib_enc/ivas_core_pre_proc_front.c | 2 +- lib_enc/ivas_corecoder_enc_reconfig.c | 2 - lib_enc/ivas_cpe_enc.c | 4 - lib_enc/ivas_dirac_enc.c | 38 +- lib_enc/ivas_enc.c | 22 +- lib_enc/ivas_enc_cov_handler.c | 71 +- lib_enc/ivas_entropy_coder.c | 15 - lib_enc/ivas_front_vad.c | 4 + lib_enc/ivas_init_enc.c | 2 - lib_enc/ivas_ism_enc.c | 4 - lib_enc/ivas_ism_param_enc.c | 212 ------ lib_enc/ivas_mcmasa_enc.c | 8 +- lib_enc/ivas_mct_core_enc.c | 2 - lib_enc/ivas_sba_enc.c | 497 ++++++------- lib_enc/ivas_sce_enc.c | 12 - lib_enc/ivas_sns_enc.c | 1 - lib_enc/ivas_spar_encoder.c | 266 +------ lib_enc/ivas_spar_md_enc.c | 132 +--- lib_enc/ivas_stat_enc.h | 35 +- lib_enc/lib_enc.c | 100 ++- lib_enc/lib_enc.h | 8 +- lib_rend/ivas_allrad_dec.c | 4 - lib_rend/ivas_crend.c | 40 +- lib_rend/ivas_efap.c | 22 - lib_rend/ivas_lib_rend_internal.h | 38 +- lib_rend/ivas_limiter.c | 2 +- lib_rend/ivas_objectRenderer.c | 29 +- lib_rend/ivas_output_init.c | 14 +- lib_rend/lib_rend.c | 684 ++++++++--------- lib_rend/lib_rend.h | 42 +- 79 files changed, 2045 insertions(+), 2659 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index c039cba91b..836775b342 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -120,11 +120,13 @@ typedef struct const char *ca_config_file; bool mimeOutput; +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION #ifdef AGC_ENABLE_FOR_LBR IVAS_ENC_AGC agc; #else bool agc; -#endif +#endif /* AGC_ENABLE_FOR_LBR */ +#endif /* DEBUG_AGC_ENCODER_CMD_OPTION */ bool pca; #ifdef DEBUG_FOA_AGC FILE *agcBitstream; /* temporary */ @@ -450,11 +452,25 @@ int main( } break; case IVAS_ENC_INPUT_SBA: + if ( ( error = + IVAS_ENC_ConfigureForAmbisonics( + hIvasEnc, + arg.inputFs, + totalBitrate, + arg.max_bwidth_user, + bandwidth, + arg.dtxConfig, + arg.inputFormatConfig.sba.order, + arg.inputFormatConfig.sba.isPlanar, +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION + arg.agc, +#endif + arg.pca #ifdef DEBUG_SBA_AUDIO_DUMP - if ( ( error = IVAS_ENC_ConfigureForAmbisonics( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.inputFormatConfig.sba.order, arg.inputFormatConfig.sba.isPlanar, arg.agc, arg.pca, &numTransportChannels ) ) != IVAS_ERR_OK ) -#else - if ( ( error = IVAS_ENC_ConfigureForAmbisonics( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.inputFormatConfig.sba.order, arg.inputFormatConfig.sba.isPlanar, arg.agc, arg.pca ) ) != IVAS_ERR_OK ) + , + &numTransportChannels #endif + ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_ENC_ConfigureForAmbisonics failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); goto cleanup; @@ -880,11 +896,13 @@ static void initArgStruct( EncArguments *arg ) arg->ca_config_file = NULL; arg->mimeOutput = false; +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION #ifdef AGC_ENABLE_FOR_LBR arg->agc = IVAS_ENC_AGC_UNDEFINED; #else arg->agc = IVAS_DEFAULT_AGC; -#endif +#endif /* AGC_ENABLE_FOR_LBR */ +#endif /* DEBUG_AGC_ENCODER_CMD_OPTION */ arg->pca = false; #ifdef DEBUG_FOA_AGC arg->agcBitstream = NULL; @@ -1390,6 +1408,7 @@ static bool parseCmdlIVAS_enc( arg->inputFormatConfig.stereoToMonoDownmix = true; i++; } +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION else if ( strcmp( argv_to_upper, "-AGC" ) == 0 ) { i++; @@ -1415,6 +1434,7 @@ static bool parseCmdlIVAS_enc( return false; } } +#endif else if ( strcmp( argv_to_upper, "-BYPASS" ) == 0 ) // VE: should be renamed to "-pca" { i++; @@ -1654,13 +1674,15 @@ static void usage_enc( void ) #ifdef DEBUG_SBA fprintf( stdout, "-tag : Tag name for intermediate debug files\n" ); #endif +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION #ifdef AGC_ENABLE_FOR_LBR fprintf( stdout, "-agc op : SBA Adaptive gain control, op = (0, 1). \n" ); fprintf( stdout, " By default op is 1 (activated) for bitrates between 24400 and 32000,\n" ); fprintf( stdout, " otherwise it is 0 (deactivated) for all other bitrates\n" ); #else fprintf( stdout, "-agc op : SBA Adaptive gain control, op = (0, 1), by default op is 0 or deactivated\n" ); -#endif +#endif /* AGC_ENABLE_FOR_LBR */ +#endif /* DEBUG_AGC_ENCODER_CMD_OPTION */ fprintf( stdout, "-bypass mode : SBA PCA by-pass, mode = (1, 2), 1 = PCA off, 2 = signal adaptive, default is 1\n" ); #ifdef DEBUGGING diff --git a/apps/renderer.c b/apps/renderer.c index 7cae5dd044..c7c1b8cf8f 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -41,10 +41,10 @@ #include "hrtf_file_reader.h" #include "ism_file_reader.h" #include "lib_rend.h" -#include "render_config_reader.h" #include "ls_custom_file_reader.h" #include "masa_file_reader.h" #include "prot.h" +#include "render_config_reader.h" #ifdef WMOPS #include "PROM_Size_lib_rend.h" #include "wmops.h" @@ -104,29 +104,27 @@ extern int16_t *ptr_max_stack; extern int32_t wc_frame; extern char location_max_stack[256]; -/* clang-format off */ /*------------------------------------------------------------------------------------------* -* Function to print complexity & memory estimates -*------------------------------------------------------------------------------------------*/ -static void print_mem_renderer(size_t SRAM_size) + * Function to print complexity & memory estimates + *------------------------------------------------------------------------------------------*/ +static void print_mem_renderer( size_t SRAM_size ) { - fprintf( stdout, "\n\n --- Renderer cmdln demo memory usage --- \n\n" ); + fprintf( stdout, "\n\n --- Renderer memory usage --- \n\n" ); - fprintf( stdout, "PROM size (renderer): %d words (or instructions)\n", PROM_Size_lib_rend ); - fprintf( stdout, "Stack size: %d words in %s() in frame #%d\n", ( ptr_base_stack - ptr_max_stack ) * sizeof( int16_t ) / sizeof( float ), location_max_stack, wc_frame ); - fprintf( stdout, "Table ROM size(renderer): %d words\n", (Const_Data_Size_ivas_rom_rend() ) / sizeof( float ) ); - fprintf( stdout, "Table ROM size (binaural renderer): %ld words\n", ( Const_Data_Size_ivas_rom_binauralRen() + Const_Data_Size_ivas_rom_TdBinauralR() + Const_Data_Size_ivas_rom_binaural_cr() ) / sizeof( float ) ); + fprintf( stdout, "PROM size (renderer): %d words (or instructions)\n", PROM_Size_lib_rend ); + fprintf( stdout, "Stack size: %d words in %s() in frame #%d\n", ( ptr_base_stack - ptr_max_stack ) * sizeof( int16_t ) / sizeof( float ), location_max_stack, wc_frame ); + fprintf( stdout, "Table ROM size(renderer): %d words\n", ( Const_Data_Size_ivas_rom_rend() ) / sizeof( float ) ); + fprintf( stdout, "Table ROM size (binaural renderer): %ld words\n", ( Const_Data_Size_ivas_rom_binauralRen() + Const_Data_Size_ivas_rom_TdBinauralR() + Const_Data_Size_ivas_rom_binaural_cr() ) / sizeof( float ) ); #ifdef RAM_COUNTING_TOOL - fprintf( stdout, "Static RAM size: %d words\n\n", SRAM_size ); + fprintf( stdout, "Static RAM size: %d words\n\n", SRAM_size ); #endif - print_stack_call_tree(); + print_stack_call_tree(); - fprintf( stdout, "Note: this is an optimistic estimate of the memory consumption assuming\n" ); - fprintf( stdout, " that each variable (short, long or float) in the codec requires\n" ); - fprintf( stdout, " 32 bits of memory and may therefore be represented by 1 word.\n" ); - fprintf( stdout, " The following formula is used: sizeof('memory array')/sizeof(float)\n\n" ); + fprintf( stdout, "Note: this is an optimistic estimate of the memory consumption assuming\n" ); + fprintf( stdout, " that each variable (short, long or float) in the codec requires\n" ); + fprintf( stdout, " 32 bits of memory and may therefore be represented by 1 word.\n" ); + fprintf( stdout, " The following formula is used: sizeof('memory array')/sizeof(float)\n\n" ); } -/* clang-format on */ #endif typedef struct @@ -182,7 +180,7 @@ typedef struct InputConfig inConfig; OutputConfig outConfig; char inMetadataFilePaths[RENDERER_MAX_ISM_INPUTS][RENDERER_MAX_CLI_ARG_LENGTH]; - int32_t numInMetadataFiles; + int16_t numInMetadataFiles; char headRotationFilePath[RENDERER_MAX_CLI_ARG_LENGTH]; char customHrtfFilePath[RENDERER_MAX_CLI_ARG_LENGTH]; char renderConfigFilePath[RENDERER_MAX_CLI_ARG_LENGTH]; @@ -318,7 +316,7 @@ static const CmdLnParser_Option cliOptions[] = { static const int32_t numCliOptions = sizeof( cliOptions ) / sizeof( CmdLnParser_Option ); static IVAS_REND_AudioConfig ambisonicsOrderToEnum( - int32_t order ); + const int16_t order ); static void parseSceneDescriptionFile( char *path, @@ -332,7 +330,7 @@ static ivas_error parseCustomLayoutFile( IVAS_CUSTOM_LS_DATA *pLsSetupCustom ); static CmdlnArgs parseCmdlnArgs( - int32_t argc, + const int argc, char **argv ); static IsmPositionProvider *IsmPositionProvider_open( @@ -348,12 +346,12 @@ static void IsmPositionProvider_close( static void readFromShorthandMetadata( IsmPositionProvider *positionProvider, ObjectPositionBuffer *objectMetadataBuffer, - uint32_t objIdx ); + const uint32_t objIdx ); void getMetadataFromFileReader( IsmFileReader *ismReader, ObjectPositionBuffer *objectMetadataBuffer, - uint32_t objIdx ); + const uint32_t objIdx ); static void splitConfigFile( const char *mdfFilePath, @@ -394,11 +392,9 @@ static void parseMetadata( IsmPositionProvider *positionProvider, MasaFileReader **masaReaders ); -static void convert_backslash( - char *str ); +static void convert_backslash( char *str ); -static void remove_cr( - char *str ); +static void remove_cr( char *str ); static void clearString( char *str ); @@ -408,37 +404,33 @@ static void printSupportedAudioConfigs( void ); static IVAS_REND_AudioConfig parseAudioConfig( const char *configString ); -static void convertInputBuffer( const int16_t *intBuffer, - int32_t numIntSamplesPerChannel, /* Number of samples per channel in the int buffer */ - int32_t numFloatSamplesPerChannel, /* Per-channel length of the float buffer. If > numIntSamplesPerChannel, remaining samples will be set to 0. */ - int32_t numChannels, - float *floatBuffer ); +static void convertInputBuffer( const int16_t *intBuffer, const int16_t numIntSamplesPerChannel, const int16_t numFloatSamplesPerChannel, const int16_t numChannels, float *floatBuffer ); -static void convertOutputBuffer( const float *floatBuffer, - int32_t numSamplesPerChannel, - int32_t numChannels, - int16_t *intBuffer ); +static void convertOutputBuffer( const float *floatBuffer, const int16_t numSamplesPerChannel, const int16_t numChannels, int16_t *intBuffer ); -static IVAS_REND_ReadOnlyAudioBuffer getReadOnlySubBuffer( IVAS_REND_AudioBuffer buffer, int32_t chBeginIdx, int32_t numChannels ) + +static IVAS_REND_ReadOnlyAudioBuffer getReadOnlySubBuffer( IVAS_REND_AudioBuffer buffer, const int16_t chBeginIdx, const int16_t numChannels ) { IVAS_REND_ReadOnlyAudioBuffer subBuffer; subBuffer.config = buffer.config; - subBuffer.config.numChannels = (int16_t) numChannels; + subBuffer.config.numChannels = numChannels; subBuffer.data = buffer.data + subBuffer.config.numSamplesPerChannel * chBeginIdx; return subBuffer; } -static int32_t getTotalNumInChannels( IVAS_REND_HANDLE hIvasRend, - IVAS_REND_InputId mcIds[RENDERER_MAX_MC_INPUTS], - IVAS_REND_InputId ismIds[RENDERER_MAX_ISM_INPUTS], - IVAS_REND_InputId sbaIds[RENDERER_MAX_SBA_INPUTS] ) +static int16_t getTotalNumInChannels( + IVAS_REND_HANDLE hIvasRend, + IVAS_REND_InputId mcIds[RENDERER_MAX_MC_INPUTS], + IVAS_REND_InputId ismIds[RENDERER_MAX_ISM_INPUTS], + IVAS_REND_InputId sbaIds[RENDERER_MAX_SBA_INPUTS] ) { - int32_t totalNumInChannels = 0; + int16_t totalNumInChannels = 0; + int16_t i, numInputChannels; ivas_error error; - for ( int32_t i = 0; i < RENDERER_MAX_MC_INPUTS; ++i ) + for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i ) { if ( mcIds[i] == 0 ) { @@ -446,7 +438,6 @@ static int32_t getTotalNumInChannels( IVAS_REND_HANDLE hIvasRend, continue; } - int32_t numInputChannels; if ( ( error = IVAS_REND_GetInputNumChannels( hIvasRend, mcIds[i], &numInputChannels ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); @@ -455,7 +446,7 @@ static int32_t getTotalNumInChannels( IVAS_REND_HANDLE hIvasRend, totalNumInChannels += numInputChannels; } - for ( int32_t i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i ) + for ( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i ) { if ( ismIds[i] == 0 ) { @@ -463,7 +454,6 @@ static int32_t getTotalNumInChannels( IVAS_REND_HANDLE hIvasRend, continue; } - int32_t numInputChannels; if ( ( error = IVAS_REND_GetInputNumChannels( hIvasRend, ismIds[i], &numInputChannels ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); @@ -472,7 +462,7 @@ static int32_t getTotalNumInChannels( IVAS_REND_HANDLE hIvasRend, totalNumInChannels += numInputChannels; } - for ( int32_t i = 0; i < RENDERER_MAX_SBA_INPUTS; ++i ) + for ( i = 0; i < RENDERER_MAX_SBA_INPUTS; ++i ) { if ( sbaIds[i] == 0 ) { @@ -480,7 +470,7 @@ static int32_t getTotalNumInChannels( IVAS_REND_HANDLE hIvasRend, continue; } - int32_t numInputChannels; + if ( ( error = IVAS_REND_GetInputNumChannels( hIvasRend, sbaIds[i], &numInputChannels ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); @@ -492,7 +482,11 @@ static int32_t getTotalNumInChannels( IVAS_REND_HANDLE hIvasRend, return totalNumInChannels; } -static void setupWithSingleFormatInput( CmdlnArgs args, char *audioFilePath, IsmPositionProvider *positionProvider, MasaFileReader **masaReaders ) +static void setupWithSingleFormatInput( + CmdlnArgs args, + char *audioFilePath, + IsmPositionProvider *positionProvider, + MasaFileReader **masaReaders ) { /* With single-format input, inputFilePath is the path to input audio file. */ strncpy( audioFilePath, args.inputFilePath, FILENAME_MAX - 1 ); @@ -519,7 +513,7 @@ static void setupWithSingleFormatInput( CmdlnArgs args, char *audioFilePath, Ism else if ( args.inConfig.numAudioObjects != 0 ) { positionProvider->numObjects = args.inConfig.numAudioObjects; - for ( int32_t i = 0; i < positionProvider->numObjects; ++i ) + for ( int16_t i = 0; i < positionProvider->numObjects; ++i ) { /* It is allowed on CLI to have no metadata for an ISM input - skip opening if string is empty or contains "NULL" */ char charBuf[FILENAME_MAX]; @@ -540,7 +534,8 @@ static void setupWithSingleFormatInput( CmdlnArgs args, char *audioFilePath, Ism } } -static float dBToLin( float gain_dB ) +static float dBToLin( + const float gain_dB ) { return powf( 10.0f, gain_dB / 20.0f ); } @@ -548,7 +543,9 @@ static float dBToLin( float gain_dB ) /* ============================================================================ */ -int32_t main( int32_t argc, char **argv ) +int main( + int argc, + char **argv ) { IVAS_REND_HANDLE hIvasRend; HeadRotFileReader *headRotReader = NULL; @@ -573,6 +570,7 @@ int32_t main( int32_t argc, char **argv ) int16_t delayNumSamples_orig = 0; int16_t zeroPad = 0; int32_t delayTimeScale = 0; + int16_t i, numChannels; ivas_error error = IVAS_ERR_OK; #ifdef WMOPS size_t SRAM_size; @@ -587,7 +585,7 @@ int32_t main( int32_t argc, char **argv ) mem_count_init( 0, USE_32BITS ); #endif - for ( int32_t i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i ) + for ( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i ) { masaReaders[i] = NULL; hMasaMetadata[i] = NULL; @@ -613,11 +611,7 @@ int32_t main( int32_t argc, char **argv ) if ( !isEmptyString( args.renderConfigFilePath ) ) { - if ( ( error = RenderConfigReader_open( args.renderConfigFilePath , &renderConfigReader ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError: Can't open Renderer configuration file %s \n\n", args.renderConfigFilePath ); - exit( -1 ); - } + RenderConfigReader_open( args.renderConfigFilePath, &renderConfigReader ); } /* Initialize main input files, i.e. audio and metadata */ @@ -652,7 +646,7 @@ int32_t main( int32_t argc, char **argv ) { args.sampleRate = inFileSampleRate; } - const int32_t frameSize_smpls = 20 * args.sampleRate / 1000; + const int16_t frameSize_smpls = (int16_t) ( 20 * args.sampleRate / 1000 ); IVAS_REND_InputId mcIds[RENDERER_MAX_MC_INPUTS] = { 0 }; IVAS_REND_InputId ismIds[RENDERER_MAX_ISM_INPUTS] = { 0 }; @@ -709,7 +703,7 @@ int32_t main( int32_t argc, char **argv ) } } - for ( int32_t i = 0; i < args.inConfig.numMultiChannelBuses; ++i ) + for ( i = 0; i < args.inConfig.numMultiChannelBuses; ++i ) { if ( ( error = IVAS_REND_AddInput( hIvasRend, args.inConfig.multiChannelBuses[i].audioConfig, &mcIds[i] ) ) != IVAS_ERR_OK ) { @@ -735,7 +729,7 @@ int32_t main( int32_t argc, char **argv ) /* TODO(sgi): Test custom LFE routing here */ } - for ( int32_t i = 0; i < args.inConfig.numAudioObjects; ++i ) + for ( i = 0; i < args.inConfig.numAudioObjects; ++i ) { if ( ( error = IVAS_REND_AddInput( hIvasRend, IVAS_REND_AUDIO_CONFIG_OBJECT, &ismIds[i] ) ) != IVAS_ERR_OK ) { @@ -750,7 +744,7 @@ int32_t main( int32_t argc, char **argv ) } } - for ( int32_t i = 0; i < args.inConfig.numAmbisonicsBuses; ++i ) + for ( i = 0; i < args.inConfig.numAmbisonicsBuses; ++i ) { if ( ( error = IVAS_REND_AddInput( hIvasRend, args.inConfig.ambisonicsBuses[i].audioConfig, &sbaIds[i] ) ) != IVAS_ERR_OK ) { @@ -765,7 +759,7 @@ int32_t main( int32_t argc, char **argv ) } } - const int32_t totalNumInChannels = getTotalNumInChannels( hIvasRend, mcIds, ismIds, sbaIds ); + const int16_t totalNumInChannels = getTotalNumInChannels( hIvasRend, mcIds, ismIds, sbaIds ); if ( AudioFileReader_getNumChannels( audioReader ) != 0 /* If input file is raw PCM, audio reader has no info about number of channels */ && totalNumInChannels != AudioFileReader_getNumChannels( audioReader ) ) { @@ -773,7 +767,7 @@ int32_t main( int32_t argc, char **argv ) exit( -1 ); } - for ( int32_t i = 0; i < args.inConfig.numMasaBuses; ++i ) + for ( i = 0; i < args.inConfig.numMasaBuses; ++i ) { if ( masaReaders[i] != NULL ) { @@ -781,7 +775,7 @@ int32_t main( int32_t argc, char **argv ) } } - int32_t numOutChannels; + int16_t numOutChannels; if ( ( error = IVAS_REND_NumOutChannels( hIvasRend, &numOutChannels ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); @@ -828,7 +822,7 @@ int32_t main( int32_t argc, char **argv ) while ( 1 ) { - int32_t num_in_channels; + int16_t num_in_channels; num_in_channels = inBuffer.config.numChannels; /* Read the input data */ @@ -861,7 +855,7 @@ int32_t main( int32_t argc, char **argv ) } #endif - for ( int32_t i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i ) + for ( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i ) { if ( masaReaders[i] != NULL ) { @@ -887,15 +881,14 @@ int32_t main( int32_t argc, char **argv ) IVAS_REND_SetHeadRotation( hIvasRend, NULL ); } - for ( int32_t i = 0; i < args.inConfig.numMultiChannelBuses; ++i ) + for ( i = 0; i < args.inConfig.numMultiChannelBuses; ++i ) { - int32_t numChannels; if ( ( error = IVAS_REND_GetInputNumChannels( hIvasRend, mcIds[i], &numChannels ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); exit( -1 ); } - IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, args.inConfig.multiChannelBuses[i].inputChannelIndex, numChannels ); + IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, (int16_t) args.inConfig.multiChannelBuses[i].inputChannelIndex, numChannels ); if ( ( error = IVAS_REND_FeedInputAudio( hIvasRend, mcIds[i], tmpBuffer ) ) != IVAS_ERR_OK ) { @@ -904,9 +897,9 @@ int32_t main( int32_t argc, char **argv ) } } - for ( int32_t i = 0; i < args.inConfig.numAudioObjects; ++i ) + for ( i = 0; i < args.inConfig.numAudioObjects; ++i ) { - IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, args.inConfig.audioObjects[i].inputChannelIndex, 1 ); + IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, (int16_t) args.inConfig.audioObjects[i].inputChannelIndex, 1 ); if ( ( error = IVAS_REND_FeedInputAudio( hIvasRend, ismIds[i], tmpBuffer ) ) != IVAS_ERR_OK ) { @@ -921,15 +914,14 @@ int32_t main( int32_t argc, char **argv ) } } - for ( int32_t i = 0; i < args.inConfig.numAmbisonicsBuses; ++i ) + for ( i = 0; i < args.inConfig.numAmbisonicsBuses; ++i ) { - int32_t numChannels; if ( ( error = IVAS_REND_GetInputNumChannels( hIvasRend, sbaIds[i], &numChannels ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); exit( -1 ); } - IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, args.inConfig.ambisonicsBuses[i].inputChannelIndex, numChannels ); + IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, (int16_t) args.inConfig.ambisonicsBuses[i].inputChannelIndex, numChannels ); if ( ( error = IVAS_REND_FeedInputAudio( hIvasRend, sbaIds[i], tmpBuffer ) ) != IVAS_ERR_OK ) { @@ -940,7 +932,7 @@ int32_t main( int32_t argc, char **argv ) IVAS_REND_GetSamples( hIvasRend, outBuffer ); - int32_t num_out_channels; + int16_t num_out_channels; num_out_channels = outBuffer.config.numChannels; /* Convert from float to int and from packed to interleaved. @@ -1022,7 +1014,7 @@ int32_t main( int32_t argc, char **argv ) count_free( inFloatBuffer ); count_free( outInt16Buffer ); count_free( outFloatBuffer ); - for ( int32_t i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i ) + for ( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i ) { MasaFileReader_close( &masaReaders[i] ); } @@ -1042,13 +1034,14 @@ int32_t main( int32_t argc, char **argv ) #endif #ifdef WMOPS print_wmops(); - /* print_mem_renderer( SRAM_size ); */ + print_mem_renderer( SRAM_size ); #endif return 0; } -static IVAS_REND_AudioConfig ambisonicsOrderToEnum( int32_t order ) +static IVAS_REND_AudioConfig ambisonicsOrderToEnum( + const int16_t order ) { switch ( order ) { @@ -1063,7 +1056,10 @@ static IVAS_REND_AudioConfig ambisonicsOrderToEnum( int32_t order ) return IVAS_REND_AUDIO_CONFIG_UNKNOWN; } -static bool parseInConfig( const char *inFormatStr, InputConfig *inConfig, bool *sceneDescriptionInput ) +static bool parseInConfig( + const char *inFormatStr, + InputConfig *inConfig, + bool *sceneDescriptionInput ) { char charBuf[FILENAME_MAX]; @@ -1131,7 +1127,7 @@ static bool parseInConfig( const char *inFormatStr, InputConfig *inConfig, bool fprintf( stderr, "Too many objects at input. Max %d supported.", RENDERER_MAX_ISM_INPUTS ); return false; } - for ( int32_t i = 0; i < inConfig->numAudioObjects; ++i ) + for ( int16_t i = 0; i < inConfig->numAudioObjects; ++i ) { inConfig->audioObjects[i].audioConfig = audioConfig; inConfig->audioObjects[i].inputChannelIndex = i; @@ -1172,7 +1168,9 @@ static bool parseInConfig( const char *inFormatStr, InputConfig *inConfig, bool return true; } -static bool parseOutConfig( const char *outputFormatStr, OutputConfig *outConfig ) +static bool parseOutConfig( + const char *outputFormatStr, + OutputConfig *outConfig ) { ivas_error error; @@ -1192,7 +1190,9 @@ static bool parseOutConfig( const char *outputFormatStr, OutputConfig *outConfig return true; } -static int8_t parseDiegeticPan( char *value, float *noDiegeticPan ) +static int8_t parseDiegeticPan( + char *value, + float *noDiegeticPan ) { int8_t success; success = 1; @@ -1223,7 +1223,9 @@ static int8_t parseDiegeticPan( char *value, float *noDiegeticPan ) return success ? 0 : -1; } -static int8_t parseOrientationTracking( char *value, int8_t *tracking_type ) +static int8_t parseOrientationTracking( + char *value, + int8_t *tracking_type ) { int8_t success; success = 1; @@ -1247,7 +1249,8 @@ static int8_t parseOrientationTracking( char *value, int8_t *tracking_type ) return success ? 0 : -1; } -static IVAS_REND_AudioConfig parseAudioConfig( const char *configString ) +static IVAS_REND_AudioConfig parseAudioConfig( + const char *configString ) { char charBuf[14]; charBuf[13] = '\0'; @@ -1323,7 +1326,8 @@ static IVAS_REND_AudioConfig parseAudioConfig( const char *configString ) return IVAS_REND_AUDIO_CONFIG_UNKNOWN; } -static const CmdLnParser_Option *findOptionById( int32_t id ) +static const CmdLnParser_Option *findOptionById( + const int32_t id ) { for ( int32_t i = 0; i < numCliOptions; ++i ) { @@ -1336,7 +1340,8 @@ static const CmdLnParser_Option *findOptionById( int32_t id ) return NULL; } -static bool checkRequiredArgs( CmdlnArgs args ) +static bool checkRequiredArgs( + CmdlnArgs args ) { const CmdLnParser_Option *tmpOption; @@ -1379,7 +1384,8 @@ static bool checkRequiredArgs( CmdlnArgs args ) return !missingRequiredArg; } -static CmdlnArgs defaultArgs( const char *executableName ) +static CmdlnArgs defaultArgs( + const char *executableName ) { CmdlnArgs args; @@ -1420,7 +1426,11 @@ static CmdlnArgs defaultArgs( const char *executableName ) return args; } -static void parseOption( int32_t optionId, char **optionValues, int16_t numOptionValues, void *pOutputStruct ) +static void parseOption( + const int32_t optionId, + char **optionValues, + const int16_t numOptionValues, + void *pOutputStruct ) { CmdlnArgs *args = pOutputStruct; @@ -1443,7 +1453,7 @@ static void parseOption( int32_t optionId, char **optionValues, int16_t numOptio break; case CmdLnOptionId_inputMetadata: assert( numOptionValues <= RENDERER_MAX_ISM_INPUTS ); - for ( int32_t i = 0; i < numOptionValues; ++i ) + for ( int16_t i = 0; i < numOptionValues; ++i ) { strncpy( args->inMetadataFilePaths[i], optionValues[i], RENDERER_MAX_CLI_ARG_LENGTH - 1 ); } @@ -1521,9 +1531,13 @@ static void parseOption( int32_t optionId, char **optionValues, int16_t numOptio assert( 0 && "This should be unreachable - all command line options should be explicitly handled." ); break; } + + return; } -static CmdlnArgs parseCmdlnArgs( int32_t argc, char **argv ) +static CmdlnArgs parseCmdlnArgs( + const int argc, + char **argv ) { CmdlnArgs args = defaultArgs( argv[0] ); @@ -1541,10 +1555,11 @@ static CmdlnArgs parseCmdlnArgs( int32_t argc, char **argv ) } -IsmPositionProvider *IsmPositionProvider_open( void ) +IsmPositionProvider *IsmPositionProvider_open( + void ) { IsmPositionProvider *ipp; - uint32_t i; + uint16_t i; ipp = (IsmPositionProvider *) count_malloc( sizeof( IsmPositionProvider ) ); ipp->frameCounter = 0; @@ -1565,7 +1580,7 @@ IsmPositionProvider *IsmPositionProvider_open( void ) void getMetadataFromFileReader( IsmFileReader *ismReader, ObjectPositionBuffer *objectMetadataBuffer, - uint32_t objIdx ) + const uint32_t objIdx ) { IVAS_ISM_METADATA ismMetadata; ivas_error error; @@ -1578,11 +1593,14 @@ void getMetadataFromFileReader( objectMetadataBuffer->positions[objIdx].azimuth = ismMetadata.azimuth; objectMetadataBuffer->positions[objIdx].elevation = ismMetadata.elevation; + + return; } -void readFromShorthandMetadata( IsmPositionProvider *positionProvider, - ObjectPositionBuffer *objectMetadataBuffer, - uint32_t objIdx ) +void readFromShorthandMetadata( + IsmPositionProvider *positionProvider, + ObjectPositionBuffer *objectMetadataBuffer, + const uint32_t objIdx ) { uint32_t preUpdatePositionIdx; uint32_t postUpdatePositionIdx; @@ -1600,6 +1618,8 @@ void readFromShorthandMetadata( IsmPositionProvider *positionProvider, postUpdatePositionIdx = positionProvider->currentPositionIdxs[objIdx]; objectMetadataBuffer->positions[objIdx] = positionProvider->positions[objIdx][postUpdatePositionIdx]; + + return; } void IsmPositionProvider_getNextFrame( @@ -1636,6 +1656,8 @@ void IsmPositionProvider_getNextFrame( } ++positionProvider->frameCounter; + + return; } void IsmPositionProvider_close( IsmPositionProvider *positionProvider ) @@ -1666,13 +1688,16 @@ void IsmPositionProvider_close( IsmPositionProvider *positionProvider ) } count_free( positionProvider ); + + return; } -static void splitConfigFile( const char *mdfFilePath, - char *metadataString, - uint32_t *metadataStringLength, - char *wavFileName, - uint32_t *wavFileNameLength ) +static void splitConfigFile( + const char *mdfFilePath, + char *metadataString, + uint32_t *metadataStringLength, + char *wavFileName, + uint32_t *wavFileNameLength ) { FILE *file; uint32_t bufferlength; @@ -1723,10 +1748,15 @@ static void splitConfigFile( const char *mdfFilePath, *metadataStringLength = mdlength + 1; fclose( file ); + + return; } /* r: pointer to character following last found delimiter */ -static char *readNextMetadataChunkFrom( char *start_char, char *line, const char *delimiter ) +static char *readNextMetadataChunkFrom( + char *start_char, + char *line, + const char *delimiter ) { char *token; @@ -1749,12 +1779,16 @@ static char *readNextMetadataChunkFrom( char *start_char, char *line, const char } /* r: pointer to character following last found delimiter */ -static char *readNextMetadataChunk( char *line, const char *delimiter ) +static char *readNextMetadataChunk( + char *line, + const char *delimiter ) { return readNextMetadataChunkFrom( NULL, line, delimiter ); } -static void parseUint8( const char *line, uint8_t *ret ) +static void parseUint8( + const char *line, + uint8_t *ret ) { char *ptr; ptr = NULL; @@ -1765,9 +1799,13 @@ static void parseUint8( const char *line, uint8_t *ret ) fprintf( stderr, "Cannot parse string \"%s\" as an integer value\n", line ); exit( -1 ); } + + return; } -static int8_t parseUint32( const char *line, uint32_t *ret ) +static int8_t parseUint32( + const char *line, + uint32_t *ret ) { char *ptr; ptr = NULL; @@ -1781,7 +1819,9 @@ static int8_t parseUint32( const char *line, uint32_t *ret ) return 0; } -static int8_t parseInt32( const char *line, int32_t *ret ) +static int8_t parseInt32( + const char *line, + int32_t *ret ) { char *ptr; ptr = NULL; @@ -1836,11 +1876,14 @@ static void parseOptionalInputValues( parse_pos = readNextMetadataChunkFrom( parse_pos, line, "\n" ); } + + return; } -static void parseObjectPosition( char *line, - IVAS_REND_AudioObjectPosition *position, - uint16_t *positionDuration ) +static void parseObjectPosition( + char *line, + IVAS_REND_AudioObjectPosition *position, + uint16_t *positionDuration ) { char *endptr; @@ -1869,6 +1912,8 @@ static void parseObjectPosition( char *line, fprintf( stderr, "Error reading metadata\n" ); exit( -1 ); } + + return; } static void parseIsm( @@ -1876,7 +1921,7 @@ static void parseIsm( char *inDir, InputConfig *inConfig, IsmPositionProvider *positionProvider, - int32_t idx ) + const int32_t idx ) { uint32_t numberOfObjectPositionsToRead; uint32_t i; @@ -1914,11 +1959,14 @@ static void parseIsm( /* Read optional values */ parseOptionalInputValues( line, &inConfig->audioObjects[idx].gain_dB ); + + return; } -static void parseSba( char *line, - InputConfig *inConfig, - int32_t idx ) +static void parseSba( + char *line, + InputConfig *inConfig, + const int32_t idx ) { uint8_t ambiOrder; @@ -1932,11 +1980,14 @@ static void parseSba( char *line, /* Read optional values */ parseOptionalInputValues( line, &inConfig->ambisonicsBuses[idx].gain_dB ); + + return; } -static void parseMc( char *line, - InputConfig *inConfig, - int32_t idx ) +static void parseMc( + char *line, + InputConfig *inConfig, + const int32_t idx ) { readNextMetadataChunk( line, "\n" ); parseInt32( line, &inConfig->multiChannelBuses[idx].inputChannelIndex ); @@ -1955,6 +2006,8 @@ static void parseMc( char *line, /* Read optional values */ parseOptionalInputValues( line, &inConfig->multiChannelBuses[idx].gain_dB ); + + return; } static void parseMasa( @@ -1962,7 +2015,7 @@ static void parseMasa( char *inDir, InputConfig *inConfig, MasaFileReader **masaReaders, - int32_t idx ) + const int32_t idx ) { readNextMetadataChunk( line, "\n" ); parseInt32( line, &inConfig->masaBuses[idx].inputChannelIndex ); @@ -1994,6 +2047,8 @@ static void parseMasa( /* Read optional values */ parseOptionalInputValues( line, &inConfig->masaBuses[idx].gain_dB ); + + return; } static ivas_error parseCustomLayoutFile( @@ -2143,9 +2198,16 @@ static void parseMetadata( fprintf( stderr, "Trailing text in metadata file\n" ); exit( -1 ); } + + return; } -static void parseSceneDescriptionFile( char *path, char *audioFilePath, InputConfig *inConfig, IsmPositionProvider *positionProvider, MasaFileReader **masaReaders ) +static void parseSceneDescriptionFile( + char *path, + char *audioFilePath, + InputConfig *inConfig, + IsmPositionProvider *positionProvider, + MasaFileReader **masaReaders ) { uint32_t inAudioFilePathLen; char inAudioFilePath[FILENAME_MAX]; @@ -2156,11 +2218,7 @@ static void parseSceneDescriptionFile( char *path, char *audioFilePath, InputCon inAudioFilePathLen = FILENAME_MAX; mtdStrLen = RENDERER_MAX_METADATA_LENGTH; - splitConfigFile( path, - mtdStr, - &mtdStrLen, - inAudioFilePath, - &inAudioFilePathLen ); + splitConfigFile( path, mtdStr, &mtdStrLen, inAudioFilePath, &inAudioFilePathLen ); remove_cr( mtdStr ); convert_backslash( inAudioFilePath ); @@ -2183,7 +2241,7 @@ static void parseSceneDescriptionFile( char *path, char *audioFilePath, InputCon static void printSupportedAudioConfigs() { - uint32_t i; + uint16_t i; const char *supportedFormats[] = { "MONO", "STEREO", @@ -2207,14 +2265,18 @@ static void printSupportedAudioConfigs() { fprintf( stdout, "%s\n", supportedFormats[i] ); } + + return; } -static void convert_backslash( char *str ) +// VE2AT: possibly move these functions to cmdln_parser.c ? +static void convert_backslash( + char *str ) { - int32_t i, len; + int16_t i, len; /* check that all backslashes are correct on the given platform */ - len = (int32_t) strlen( str ); + len = (int16_t) strlen( str ); for ( i = 0; i < len; i++ ) { @@ -2230,6 +2292,8 @@ static void convert_backslash( char *str ) } #endif } + + return; } static void remove_cr( char *str ) @@ -2243,14 +2307,20 @@ static void remove_cr( char *str ) strcpy( pos, pos + 1 ); pos = strchr( pos, '\r' ); } + + return; } -static void clearString( char *str ) +static void clearString( + char *str ) { str[0] = '\0'; + + return; } -static bool isEmptyString( const char *str ) +static bool isEmptyString( + const char *str ) { return str[0] == '\0'; } @@ -2261,17 +2331,18 @@ static bool isEmptyString( const char *str ) * Convert input buffer from WAV/PCM file (int16_t, interleaved) to a format * accepted by the renderer (float, packed) *--------------------------------------------------------------------------*/ -static void convertInputBuffer( const int16_t *intBuffer, - int32_t numIntSamplesPerChannel, - int32_t numFloatSamplesPerChannel, - int32_t numChannels, - float *floatBuffer ) + +static void convertInputBuffer( + const int16_t *intBuffer, + const int16_t numIntSamplesPerChannel, + const int16_t numFloatSamplesPerChannel, + const int16_t numChannels, + float *floatBuffer ) { - int32_t chnl, smpl, i; + int16_t chnl, smpl, i; i = 0; - for ( smpl = 0; smpl < numFloatSamplesPerChannel; ++smpl ) { for ( chnl = 0; chnl < numChannels; ++chnl ) @@ -2288,6 +2359,8 @@ static void convertInputBuffer( const int16_t *intBuffer, ++i; } } + + return; } /*--------------------------------------------------------------------------* @@ -2296,12 +2369,14 @@ static void convertInputBuffer( const int16_t *intBuffer, * Convert output buffer from the renderer (float, packed) to a format ready * for writing to a WAV/PCM file (int16_t, interleaved) *--------------------------------------------------------------------------*/ -static void convertOutputBuffer( const float *floatBuffer, - int32_t numSamplesPerChannel, - int32_t numChannels, - int16_t *intBuffer ) + +static void convertOutputBuffer( + const float *floatBuffer, + const int16_t numSamplesPerChannel, + const int16_t numChannels, + int16_t *intBuffer ) { - int32_t chnl, smpl, i; + int16_t chnl, smpl, i; i = 0; @@ -2314,9 +2389,13 @@ static void convertOutputBuffer( const float *floatBuffer, ++i; } } + + return; } #else -int32_t main( int32_t argc, char **argv ) +int main( + int argc, + char **argv ) { (void) argc; (void) argv; diff --git a/ci/run_scheduled_sanitizer_test.py b/ci/run_scheduled_sanitizer_test.py index 4f3cd25c0b..6696e184c2 100644 --- a/ci/run_scheduled_sanitizer_test.py +++ b/ci/run_scheduled_sanitizer_test.py @@ -6,8 +6,8 @@ import subprocess import pathlib -DURATION = "120" -CFG = "ci_linux.json" +DURATION = "30" +CFG = "ci_linux_ltv.json" SUPPORTED_TESTS = ["CLANG1", "CLANG2", "CLANG3", "VALGRIND"] EP_FILE = "ep_015.g192" GENPATT_CMD = f"gen-patt -tailstat -fer -g192 -gamma 0 -rate 0.15 -tol 0.001 -reset -n {int(DURATION) * 50} {EP_FILE}" @@ -48,9 +48,6 @@ def get_modes(in_format: str) -> list: in_format = "MC_" + in_format + "_b" mode_list = [m for m in output.splitlines() if in_format in m] - if "SBA" in in_format: - # rate switching not implemented yet - mode_list = [m for m in mode_list if not "_rs" in m] return mode_list diff --git a/ci/smoke_test.sh b/ci/smoke_test.sh index b8c4bdd3f0..e3caac3533 100755 --- a/ci/smoke_test.sh +++ b/ci/smoke_test.sh @@ -8,8 +8,5 @@ fi make clean make all -j 8 -# get all modes except SBA rate switching (which is broken currently) -list=$(./scripts/runIvasCodec.py -l | grep -v "SBA.*rs") -./scripts/runIvasCodec.py -p ./scripts/config/ci_linux.json -m $list -U 1 | tee smoke_test_output.txt - -./scripts/runIvasCodec.py -p ./scripts/config/ci_linux.json -m $list -U 1 -D="-fec 15" --decoder_only | tee smoke_test_output_plc.txt +./scripts/runIvasCodec.py -p ./scripts/config/ci_linux.json -U 1 | tee smoke_test_output.txt +./scripts/runIvasCodec.py -p ./scripts/config/ci_linux.json -U 1 -D="-fec 15" --decoder_only | tee smoke_test_output_plc.txt diff --git a/lib_com/cnst.h b/lib_com/cnst.h index e62ef001dc..be668b01c7 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -132,6 +132,9 @@ enum{ #define MAX_V_MULT_MAT 100 /* maximum array length for the function v_mult_mat() */ +#define SBA_AGC_FORCE_ENABLE 1 +#define SBA_AGC_FORCE_DISABLE 0 +#define SBA_AGC_DEFAULT -1 /*----------------------------------------------------------------------------------* * Layers diff --git a/lib_com/fill_spectrum.c b/lib_com/fill_spectrum.c index c1837d5140..a3dbcf304b 100644 --- a/lib_com/fill_spectrum.c +++ b/lib_com/fill_spectrum.c @@ -90,18 +90,10 @@ void fill_spectrum( const int16_t element_mode /* i : element mode */ ) { -#ifdef FIX_I178_HQ_BUFFER_OVERRUN float CodeBook[L_SPEC48k_EXT]; -#else - float CodeBook[FREQ_LENGTH]; -#endif int16_t cb_size = 0; int16_t last_sfm; -#ifdef FIX_I178_HQ_BUFFER_OVERRUN float CodeBook_mod[L_SPEC48k_EXT]; -#else - float CodeBook_mod[FREQ_LENGTH]; -#endif float norm_adj[NB_SFM]; int16_t high_sfm = 23; int16_t flag_32K_env_hangover; diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 3708e0181c..e0c1e0e501 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -837,11 +837,19 @@ typedef enum { * SBA Constants *----------------------------------------------------------------------------------*/ +#define SBA_FOA_ORDER 1 +#define SBA_HOA2_ORDER 2 +#define SBA_HOA3_ORDER 3 + #define SBA_PLANAR_BITS 1 #define SBA_ORDER_BITS 2 + #define SBA_MIN_BRATE_HOA IVAS_256k #define SBA_NHARM_HOA3 16 #define SBA_T_DESIGN_11_SIZE 70 +#ifdef FIX_SBA_DTX_DECODE_ERROR +#define SBA_DTX_BITRATE_THRESHOLD IVAS_80k +#endif typedef enum { @@ -1325,11 +1333,7 @@ typedef enum #define PANNING_ELE_RESOLUTION 5 #define EFAP_MAX_CHAN_NUM 5 /* Maximum number of channels that constitute a polygon, 4 or 5 */ -#ifdef ALLRAD_OPTIM #define EFAP_MAX_POLY_SET 50 /* Upper bound on number of polygons; with a Speaker setup of 16.0, we obtain 44 polygons/triangles in the matlab implementation. */ -#else -#define EFAP_MAX_POLY_SET 70 /* Upper bound on number of polygons; with a Speaker setup of 26.0, we obtain 54 polygons/triangles in the matlab implementation. */ -#endif #define EFAP_MODE_EFAP 0 /* EFAP Panning */ #define EFAP_MODE_EFIP 1 /* EFIP Panning */ diff --git a/lib_com/ivas_cov_smooth.c b/lib_com/ivas_cov_smooth.c index 0015871287..eaaec6a982 100644 --- a/lib_com/ivas_cov_smooth.c +++ b/lib_com/ivas_cov_smooth.c @@ -169,36 +169,22 @@ void ivas_spar_covar_smooth_enc_close( static void ivas_compute_smooth_cov( ivas_cov_smooth_state_t *hCovState, -#ifndef SBA_SPAR_HARM - ivas_cov_smooth_in_buf_t *pIn_buf, -#endif ivas_filterbank_t *pFb, float *pCov_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float *pPrior_cov_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const float fac, const int16_t start_band, - const int16_t end_band -#ifdef SBA_SPAR_HARM - , + const int16_t end_band, const int16_t num_ch, - const int16_t transient_det -#endif -) + const int16_t transient_det ) { int16_t i, j, k; int16_t prev_idx = hCovState->prior_bank_idx; -#ifndef SBA_SPAR_HARM - int16_t num_ch = pIn_buf->num_ch; -#endif float factor = 0; assert( end_band <= pFb->filterbank_num_bands ); -#ifdef SBA_SPAR_HARM if ( prev_idx == -1 || transient_det == 1 ) -#else - if ( prev_idx == -1 || pIn_buf->reset_cov == 1 ) -#endif { for ( i = 0; i < num_ch; i++ ) { @@ -243,42 +229,23 @@ static void ivas_compute_smooth_cov( void ivas_cov_smooth_process( ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */ -#ifdef SBA_SPAR_HARM float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], -#else - ivas_cov_smooth_in_buf_t *pIn_buf, -#endif ivas_filterbank_t *pFb, /* i/o: FB handle */ const int16_t start_band, - const int16_t end_band -#ifdef SBA_SPAR_HARM - , + const int16_t end_band, const int16_t num_ch, - const int16_t transient_det -#endif -) + const int16_t transient_det ) { int16_t i, j; -#ifndef SBA_SPAR_HARM - int16_t num_ch = pIn_buf->num_ch; -#endif int16_t num_bands = end_band - start_band; -#ifdef SBA_SPAR_HARM ivas_compute_smooth_cov( hCovState, pFb, cov_real, hCovState->pPrior_cov_real, 1e-20f, start_band, end_band, num_ch, transient_det ); -#else - ivas_compute_smooth_cov( hCovState, pIn_buf, pFb, pIn_buf->cov_real, hCovState->pPrior_cov_real, 1e-20f, start_band, end_band ); -#endif for ( i = 0; i < num_ch; i++ ) { for ( j = 0; j < num_ch; j++ ) { -#ifdef SBA_SPAR_HARM mvr2r( &cov_real[i][j][start_band], &hCovState->pPrior_cov_real[i][j][start_band], num_bands ); -#else - mvr2r( &pIn_buf->cov_real[i][j][start_band], &hCovState->pPrior_cov_real[i][j][start_band], num_bands ); -#endif } } diff --git a/lib_com/ivas_error.h b/lib_com/ivas_error.h index 8168a6c6d6..bfc9396f09 100644 --- a/lib_com/ivas_error.h +++ b/lib_com/ivas_error.h @@ -93,6 +93,9 @@ typedef enum IVAS_ERR_WRONG_NUM_CHANNELS, IVAS_ERR_INVALID_BUFFER_SIZE, #endif +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION + IVAS_ERR_INVALID_AGC, +#endif /*----------------------------------------* * input data errors * diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 7de6bde693..71622fd939 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -44,9 +44,6 @@ #include "ivas_stat_dec.h" #include "ivas_stat_com.h" #include "ivas_error_utils.h" -#ifdef AGC_ENABLE_FOR_LBR -#include "lib_enc.h" -#endif /* clang-format off */ @@ -108,7 +105,17 @@ ivas_error mct_enc_reconfigure( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const uint16_t b_nchan_change /* i : flag indicating different channel count */ ); - +#ifdef SBA_BR_SWITCHING +ivas_error ivas_sba_enc_reinit( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); +#endif +#ifdef SBA_BR_SWITCHING +int16_t get_sba_reinit_flag( + int32_t ivas_total_bitrate, /* i: current bitrate */ + int32_t last_ivas_total_brate /* i: previous bitrate */ +); +#endif ivas_error ivas_sba_enc_reconfigure( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); @@ -125,14 +132,12 @@ void ivas_mct_enc_close( MCT_ENC_HANDLE hMCT /* i/o: MCT encoder structure */ ); -#ifdef CORECODER_BITRATE_SWITCHING ivas_error ivas_corecoder_enc_reconfig( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ const int16_t nCPE_old, /* i : number of CPEs in previous frame */ const int16_t nchan_transport_old /* i : number of TCs in previous frame */ ); -#endif ivas_error ivas_sce_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ @@ -206,9 +211,7 @@ ivas_error pre_proc_ivas( Encoder_State *st, /* i/o: encoder state structure */ const int16_t last_element_mode, /* i : last element mode */ const int32_t element_brate, /* i : element bitrate */ -#ifdef CORECODER_BITRATE_SWITCHING const int32_t last_element_brate, /* i : last element bitrate */ -#endif const int16_t input_frame, /* i : frame length */ float old_inp_12k8[], /* i/o: buffer of old input signal */ float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ @@ -333,7 +336,6 @@ void ivas_mct_dec_close( MCT_DEC_HANDLE *hMCT /* i/o: MCT decoder structure */ ); -#ifdef CORECODER_BITRATE_SWITCHING ivas_error ivas_corecoder_dec_reconfig( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ @@ -346,7 +348,6 @@ ivas_error ivas_hp20_dec_reconfig( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nchan_hp20_old /* i : number of HP20 filters in previous frame*/ ); -#endif ivas_error ivas_sce_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -418,9 +419,7 @@ ivas_error ivas_core_enc( float enerBuffer[CPE_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */ float fft_buff[CPE_CHANNELS][2 * L_FFT], /* i : FFT buffer */ const int16_t tdm_SM_flag, /* i : channel combination scheme flag */ -#ifdef CORECODER_BITRATE_SWITCHING const int16_t ivas_format, /* i : IVAS format */ -#endif const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ ); @@ -2169,12 +2168,8 @@ void stereo_decoder_tcx( const int16_t core_l, /* i : core for left channel (TCX20/TCX10) */ const int16_t core_r, /* i : core for right channel (TCX20/TCX10) */ const int16_t igf, /* i : flag for IGF activity */ -#ifdef FIX_TCX10_STEREO_PROC const int16_t L_frameTCX_l, /* i : TCX frame length of left channel */ const int16_t L_frameTCX_r, /* i : TCX frame length of right channel */ -#else - const int16_t L_frame, /* i : TCX frame length */ -#endif const int16_t mct_on, /* i : flag mct block (1) or stereo (0) */ const int16_t last_core_l, /* i : last core for left channel */ const int16_t last_core_r, /* i : last core for right channel */ @@ -3030,10 +3025,8 @@ void ivas_dirac_param_est_enc( float **pp_fr_real, float **pp_fr_imag, const int16_t input_frame -#ifdef SBA_HOA_HBR_IMPROV , const SBA_MODE sba_mode -#endif ); /*----------------------------------------------------------------------------------* @@ -3055,7 +3048,11 @@ void ivas_sba_config( int16_t *nCPE, /* o : number of CPEs */ int16_t *element_mode /* o : element mode of the core coder */ ); - +#ifdef SBA_BR_SWITCHING +ivas_error ivas_sba_dec_reinit( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); +#endif ivas_error ivas_sba_dec_reconfigure( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); @@ -3093,13 +3090,11 @@ int16_t ivas_sba_get_nchan_metadata( const int16_t sba_order /* i : Ambisonic (SBA) order */ ); -#ifdef SBA_HOA_HBR_IMPROV /*! r: flag indicating to code SPAR HOA MD for all bands */ int16_t ivas_sba_get_spar_hoa_md_flag( const int16_t sba_order, /* i : Ambisonic (SBA) order */ const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); -#endif void ivas_sba_zero_vert_comp( float sba_data[][L_FRAME48k], /* i/o: SBA data frame */ @@ -3783,9 +3778,12 @@ void ivas_sba_prototype_renderer( /* AGC */ #ifdef AGC_ENABLE_FOR_LBR -int16_t ivas_agc_enc_get_enablement_flag( - IVAS_ENC_AGC agc_configuration, /* i : configuration used when encoder was initialised from cmd line */ - int16_t nchan_transport /* i : number of transport channels */ +/*! r: AGC enable flag */ +int16_t ivas_agc_enc_get_flag( +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION + int16_t agc_configuration, /* i : AGC configuration from command-line */ +#endif + int16_t nchan_transport /* i : number of transport channels */ ); #endif @@ -3929,19 +3927,11 @@ void ivas_spar_md_enc_close( ivas_error ivas_spar_md_enc_process( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ -#ifdef SBA_SPAR_HARM float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], -#else - ivas_spar_md_enc_in_buf_t *pIn_buf, -#endif BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ -#ifdef SBA_SPAR_HARM int16_t dtx_vad, const int16_t nchan_inp, -#else - const int16_t dtx_silence_mode, -#endif const int16_t sba_order /* i : Ambisonic (SBA) order */ ); @@ -4005,10 +3995,8 @@ ivas_error ivas_spar_md_dec_open( ivas_spar_md_dec_state_t **hMdDec_out, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ const int16_t num_channels /* i : number of internal channels */ -#ifdef SBA_HOA_HBR_IMPROV , const int16_t sba_order /* i : SBA order */ -#endif ); void ivas_spar_md_dec_close( @@ -4028,7 +4016,8 @@ void ivas_spar_get_parameters( ivas_error ivas_spar_md_dec_init( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t num_channels /* i : number of internal channels */ + const int16_t num_channels, /* i : number of internal channels */ + const int16_t sba_order /* i : SBA order */ ); void ivas_spar_md_dec_process( @@ -4081,24 +4070,16 @@ void ivas_spar_covar_enc_close( void ivas_enc_cov_handler_process( ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ -#ifdef SBA_SPAR_HARM float **ppIn_FR_real, float **ppIn_FR_imag, float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], -#else - ivas_enc_cov_handler_in_buf_t *pIn_buf, - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], -#endif ivas_filterbank_t *pFb, /* i/o: FB handle */ const int16_t start_band, const int16_t end_band -#ifdef SBA_SPAR_HARM ,const int16_t nchan_inp, const int16_t dtx_vad, const int16_t transient_det -#endif ); ivas_error ivas_spar_covar_smooth_enc_open( @@ -4115,19 +4096,13 @@ void ivas_spar_covar_smooth_enc_close( void ivas_cov_smooth_process( ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */ -#ifdef SBA_SPAR_HARM float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], -#else - ivas_cov_smooth_in_buf_t *pIn_buf, -#endif ivas_filterbank_t *pFb, /* i/o: FB handle */ const int16_t start_band, const int16_t end_band -#ifdef SBA_SPAR_HARM , const int16_t num_ch, const int16_t transient_det -#endif ); /* Transient detector module */ @@ -4876,10 +4851,8 @@ void computeReferencePower_enc( float *reference_power, /* o : Estimated power */ const int16_t enc_param_start_band, /* i : first band to process */ const int16_t num_freq_bands /* i : Number of frequency bands */ -#ifdef SBA_HOA_HBR_IMPROV , const SBA_MODE sba_mode /* i : SBA mode */ -#endif ); diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 4169e4ee92..c843d5ddc4 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -903,57 +903,57 @@ const ivas_spar_br_table_t ivas_spar_br_table_consts[IVAS_SPAR_BR_TABLE_LEN] = { /* When AGC is ON additional (AGC_BITS_PER_CH+1) bits may be taken from each core-coder channel so minimum core-coder bitrate per channel can be min core-coder bitrates as per the table - AGC_BITS_PER_CH */ - { 24400, 0, 1, FB, 24000, 1, WYXZ, 1, 0,{ { 16400, 14850, 24350 } }, + { 24400, 0, SBA_FOA_ORDER, FB, 24000, 1, WYXZ, 1, 0,{ { 16400, 14850, 24350 } }, { { 15, 1, 5, 1 },{ 15, 1, 3, 1 },{ 7, 1, 3, 1 } }, 0, 0, 0 }, - { 32000, 0, 1, FB, 24000, 1, WYXZ, 1, 0,{ { 24000, 20450, 31950 } }, + { 32000, 0, SBA_FOA_ORDER, FB, 24000, 1, WYXZ, 1, 0,{ { 24000, 20450, 31950 } }, { { 21, 1, 5, 1 },{ 15, 1, 5, 1 },{ 15, 1, 3, 1 } }, 0, 0, 0 }, - { 48000, 0, 1, FB, 24000, 2, WYXZ, 0, 0,{ { 24000, 21000, 31950 },{ 16000, 15000, 20400 } }, + { 48000, 0, SBA_FOA_ORDER, FB, 24000, 2, WYXZ, 0, 0,{ { 24000, 21000, 31950 },{ 16000, 15000, 20400 } }, { { 15, 7, 5, 1 },{ 15, 7, 3, 1 },{ 7, 7, 3, 1 } }, 1, 0, 0 }, - { 64000, 0, 1, FB, 24000, 2, WYXZ, 0, 0,{ { 38000, 34050, 56000 },{ 16000, 15600, 20400 } },{ { 21, 7, 5, 1 },{ 15, 7, 5, 1 },{ 15, 7, 3, 1 } }, 1, 1, 0 }, + { 64000, 0, SBA_FOA_ORDER, FB, 24000, 2, WYXZ, 0, 0,{ { 38000, 34050, 56000 },{ 16000, 15600, 20400 } },{ { 21, 7, 5, 1 },{ 15, 7, 5, 1 },{ 15, 7, 3, 1 } }, 1, 1, 0 }, - { 80000, 0, 1, FB, 24000, 2, WYXZ, 0, 0,{ { 46000, 43000, 56000 },{ 24000, 23000, 31950 } }, + { 80000, 0, SBA_FOA_ORDER, FB, 24000, 2, WYXZ, 0, 0,{ { 46000, 43000, 56000 },{ 24000, 23000, 31950 } }, { { 21, 7, 5, 1 },{ 15, 7, 5, 1 },{ 15, 7, 3, 1 } }, 1, 0, 0 }, - { 96000, 0, 1, FB, 24000, 3, WYXZ, 0, 0,{ { 47000, 42600, 56000 },{ 23000, 22600, 31950 },{ 16000, 15600, 20400 } }, + { 96000, 0, SBA_FOA_ORDER, FB, 24000, 3, WYXZ, 0, 0,{ { 47000, 42600, 56000 },{ 23000, 22600, 31950 },{ 16000, 15600, 20400 } }, { { 21, 9, 9, 1 },{ 21, 7, 5, 1 },{ 21, 7, 5, 1 } }, 1, 0, 0 }, - { 128000, 0, 1, FB, 24000, 3, WYXZ, 0, 0,{ { 55000, 50000, 56000 },{ 36000, 36000, 56000 },{ 27000, 27000, 31950 } }, + { 128000, 0, SBA_FOA_ORDER, FB, 24000, 3, WYXZ, 0, 0,{ { 55000, 50000, 56000 },{ 36000, 36000, 56000 },{ 27000, 27000, 31950 } }, { { 21, 11, 9, 1 },{ 21, 9, 7, 1 },{ 21, 7, 7, 1 } }, 1, 0, 0 }, - { 160000, 0, 1, FB, 24000, 3, WYXZ, 0, 0,{ { 74000, 70900, 112000 },{ 41000, 40050, 56000 },{ 35000, 34050, 56000 } }, + { 160000, 0, SBA_FOA_ORDER, FB, 24000, 3, WYXZ, 0, 0,{ { 74000, 70900, 112000 },{ 41000, 40050, 56000 },{ 35000, 34050, 56000 } }, { { 21, 11, 11, 1 },{ 21, 9, 9, 1 },{ 21, 7, 7, 1 } }, 1, 0, 0 }, - { 192000, 0, 1, FB, 24000, 3, WYXZ, 0, 0,{ { 90000, 87900, 112000 },{ 50000, 48050, 56000 },{ 42000, 41050, 56000 } }, + { 192000, 0, SBA_FOA_ORDER, FB, 24000, 3, WYXZ, 0, 0,{ { 90000, 87900, 112000 },{ 50000, 48050, 56000 },{ 42000, 41050, 56000 } }, { { 21, 11, 11, 1 },{ 21, 9, 9, 1 },{ 21, 7, 7, 1 } }, 1, 0, 0 }, - { 256000, 0, 1, FB, 24000, 4, WYXZ, 0, 0,{ { 90000, 85000, 112000 },{ 70000, 69000, 112000 },{ 50000, 48950, 56000 },{ 36400, 35600, 56000 } }, + { 256000, 0, SBA_FOA_ORDER, FB, 24000, 4, WYXZ, 0, 0,{ { 90000, 85000, 112000 },{ 70000, 69000, 112000 },{ 50000, 48950, 56000 },{ 36400, 35600, 56000 } }, { { 31, 1, 1, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 }, - { 256000, 0, 2, FB, 24000, 4, WYXZ, 0, 0,{ { 84650, 83000, 112000 },{ 65850, 64550, 56000 },{ 47000, 46100, 48000 },{ 28200, 27650, 40000 } }, + { 256000, 0, SBA_HOA2_ORDER, FB, 24000, 4, WYXZ, 0, 0,{ { 84650, 83000, 112000 },{ 65850, 64550, 56000 },{ 47000, 46100, 48000 },{ 28200, 27650, 40000 } }, { { 31, 11, 11, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 }, - { 256000, 0, 3, FB, 24000, 4, WYXZ, 0, 0,{ { 76300, 73550, 112000 },{ 59350, 57200, 56000 },{ 42400, 40850, 48000 },{ 25450, 24500, 40000 } }, + { 256000, 0, SBA_HOA3_ORDER, FB, 24000, 4, WYXZ, 0, 0,{ { 76300, 73550, 112000 },{ 59350, 57200, 56000 },{ 42400, 40850, 48000 },{ 25450, 24500, 40000 } }, { { 31, 11, 11, 1 },{ 1, 1, 1, 1 },{ 31, 1, 1, 1 } }, 1, 2, 0 }, { 384000, 0, 1, FB, 24000, 4, WYXZ, 0, 0,{ { 128000, 128000, 128000 },{ 100000, 100000, 128000 },{ 79850, 79850, 104000 },{ 66600, 66600, 104000 } }, // not yet optimized { { 31, 1, 1, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 }, - { 384000, 0, 2, FB, 24000, 4, WYXZ, 0, 0,{ { 128000, 128000, 128000 },{ 105350, 103300, 112000 },{ 75200, 73750, 96000 },{ 45100, 44250, 48000 } }, // just added as a place holder, not necessarily operational + { 384000, 0, SBA_HOA2_ORDER, FB, 24000, 4, WYXZ, 0, 0,{ { 128000, 128000, 128000 },{ 105350, 103300, 112000 },{ 75200, 73750, 96000 },{ 45100, 44250, 48000 } }, // just added as a place holder, not necessarily operational { { 31, 11, 11, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 }, - { 384000, 0, 3, FB, 24000, 4, WYXZ, 0, 0,{ { 124300, 121550, 128000 },{ 96700, 94550, 112000 },{ 69050, 67500, 96000 },{ 41450, 40500, 48000 } }, // just added as a place holder, not necessarily operational + { 384000, 0, SBA_HOA3_ORDER, FB, 24000, 4, WYXZ, 0, 0,{ { 124300, 121550, 128000 },{ 96700, 94550, 112000 },{ 69050, 67500, 96000 },{ 41450, 40500, 48000 } }, // just added as a place holder, not necessarily operational { { 31, 11, 11, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 }, { 512000, 0, 1, FB, 24000, 4, WYXZ, 0, 0,{ { 128000, 128000, 128000 },{ 128000, 128000, 128000 },{ 128000, 128000, 128000 }, {118450, 118450, 128000 } }, // not yet optimized { { 31, 1, 1, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 }, - { 512000, 0, 2, FB, 24000, 4, WYXZ, 0, 0,{ { 128000, 128000, 128000 },{ 128000, 128000, 128000 },{ 128000, 128000, 128000 },{ 97700, 93300, 128000 } }, // not yet optimized + { 512000, 0, SBA_HOA2_ORDER, FB, 24000, 4, WYXZ, 0, 0,{ { 128000, 128000, 128000 },{ 128000, 128000, 128000 },{ 128000, 128000, 128000 },{ 97700, 93300, 128000 } }, // not yet optimized { { 31, 11, 11, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 }, - { 512000, 0, 3, FB, 24000, 4, WYXZ, 0, 0,{ { 128000, 128000, 128000 },{ 128000, 128000, 128000 },{ 127200, 122550, 128000 },{ 76300, 73550, 128000 } }, // not yet optimized + { 512000, 0, SBA_HOA3_ORDER, FB, 24000, 4, WYXZ, 0, 0,{ { 128000, 128000, 128000 },{ 128000, 128000, 128000 },{ 127200, 122550, 128000 },{ 76300, 73550, 128000 } }, // not yet optimized { { 31, 11, 11, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 }, }; diff --git a/lib_com/ivas_sba_config.c b/lib_com/ivas_sba_config.c index cf22cf38ff..5b6cfd48cb 100644 --- a/lib_com/ivas_sba_config.c +++ b/lib_com/ivas_sba_config.c @@ -71,8 +71,26 @@ SBA_MODE ivas_sba_mode_select( return sba_mode; } - - +#ifdef SBA_BR_SWITCHING +/*-------------------------------------------------------------------* + * get_sba_reinit_flag() + * + * Get SBA reinitialisation flag + *-------------------------------------------------------------------*/ +int16_t get_sba_reinit_flag( + int32_t ivas_total_bitrate, /* i : Current bitrate */ + int32_t last_ivas_total_brate /* i : Previous bitrate */ +) +{ + int16_t sba_reinit_flag; + sba_reinit_flag = 0; + if ( ivas_total_bitrate != last_ivas_total_brate && ( last_ivas_total_brate > IVAS_SID_5k2 ) && ( ivas_total_bitrate > IVAS_SID_5k2 ) ) + { + sba_reinit_flag = 1; + } + return sba_reinit_flag; +} +#endif /*-------------------------------------------------------------------* * ivas_sba_config() * @@ -194,7 +212,7 @@ int16_t ivas_sba_get_analysis_order( if ( ivas_total_brate < SBA_MIN_BRATE_HOA ) { /* Hard coding the sba_analysis_order as 1 as higher not supported below SBA_MIN_BRATE_HOA bitrate */ - sba_analysis_order = 1; + sba_analysis_order = SBA_FOA_ORDER; } return sba_analysis_order; @@ -213,15 +231,15 @@ int16_t ivas_sba_get_order_transport( { int16_t sba_order; - sba_order = 1; + sba_order = SBA_FOA_ORDER; if ( nchan_transport > 6 ) { - sba_order = 3; + sba_order = SBA_HOA3_ORDER; } else if ( nchan_transport > 4 ) { - sba_order = 2; + sba_order = SBA_HOA2_ORDER; } return ( sba_order ); @@ -268,7 +286,7 @@ int16_t ivas_sba_get_nchan_metadata( { int16_t nb_channels; - if ( sba_order == 1 ) + if ( sba_order == SBA_FOA_ORDER ) { nb_channels = FOA_CHANNELS; } @@ -281,7 +299,6 @@ int16_t ivas_sba_get_nchan_metadata( return ( nb_channels ); } -#ifdef SBA_HOA_HBR_IMPROV /*-------------------------------------------------------------------* * ivas_sba_get_spar_hoa_md_flag() * @@ -307,7 +324,6 @@ int16_t ivas_sba_get_spar_hoa_md_flag( return spar_hoa_md_flag; } -#endif /*-------------------------------------------------------------------* * ivas_sba_zero_vert_comp() diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index b5821e4632..89b59d9392 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -1667,8 +1667,8 @@ void ivas_get_spar_md_from_dirac( remix_order = remix_order_set[hSpar_md_cfg->remix_unmix_order]; - num_ch = 2 * order + 2; - hoa2_ch = 6; + num_ch = ivas_sba_get_nchan_metadata( order ); + hoa2_ch = ivas_sba_get_nchan_metadata( SBA_HOA2_ORDER ); foa_ch = FOA_CHANNELS; diff_norm_order1 = 3.0f; diff_norm_order2 = 5.0f; @@ -1687,6 +1687,7 @@ void ivas_get_spar_md_from_dirac( { float P_norm[3]; int16_t idx; + ndm = hSpar_md_cfg->num_dmx_chans_per_band[start_band - 1]; P_norm[0] = 0.0f; for ( i = 0; i < max( 0, foa_ch - ndm ); i++ ) @@ -1737,11 +1738,6 @@ void ivas_get_spar_md_from_dirac( /*SPAR from DirAC*/ set_f( response_avg, 0.0f, MAX_OUTPUT_CHANNELS ); -#ifndef SBA_HOA_HBR_IMPROV - set_f( hSpar_md->band_coeffs[band + i_ts * IVAS_MAX_NUM_BANDS].pred_re, 0.0f, IVAS_SPAR_MAX_CH - 1 ); - set_f( &hSpar_md->band_coeffs[band + i_ts * IVAS_MAX_NUM_BANDS].C_re[0][0], 0.0f, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); - set_f( &hSpar_md->band_coeffs[band + i_ts * IVAS_MAX_NUM_BANDS].P_re[0], 0.0f, ( IVAS_SPAR_MAX_CH - 1 ) ); -#endif if ( n_ts > 1 ) { ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][i_ts], (int16_t) ele_dirac[band][i_ts], response_avg, order ); @@ -1759,7 +1755,7 @@ void ivas_get_spar_md_from_dirac( int16_t num_ch_order, hoa2_ch_order; num_ch_order = ivas_sba_get_nchan( order, 0 ); - hoa2_ch_order = 9; + hoa2_ch_order = ivas_sba_get_nchan( SBA_HOA2_ORDER, 0 ); for ( ch = 0; ch < num_ch_order; ch++ ) { @@ -2114,17 +2110,7 @@ void ivas_spar_set_bitrate_config( pSpar_md_cfg->agc_bits_ch_idx = ivas_spar_br_table_consts[table_idx].agc_bits_ch_idx; ivas_spar_get_uniform_quant_strat( pSpar_md_cfg, table_idx ); - if ( pSpar_md_cfg->quant_strat->C.q_levels[0] == 0 || pSpar_md_cfg->quant_strat->C.q_levels[1] == 0 || pSpar_md_cfg->quant_strat->PR.q_levels[0] == 0 || pSpar_md_cfg->quant_strat->PR.q_levels[1] == 0 || pSpar_md_cfg->quant_strat->P_c.q_levels[0] == 0 || pSpar_md_cfg->quant_strat->P_c.q_levels[1] == 0 || pSpar_md_cfg->quant_strat->P_r.q_levels[0] == 0 || pSpar_md_cfg->quant_strat->P_r.q_levels[1] == 0 ) - { - pSpar_md_cfg->gen_bs = 0; - } - else - { - if ( 0 != pSpar_md_cfg->gen_bs ) - { - pSpar_md_cfg->quant_strat_bits = ivas_get_bits_to_encode( MAX_QUANT_STRATS ); - } - } + pSpar_md_cfg->quant_strat_bits = ivas_get_bits_to_encode( MAX_QUANT_STRATS ); /* BLOCK: getEntropyCoderModels */ @@ -2136,18 +2122,19 @@ void ivas_spar_set_bitrate_config( ivas_total_brate = ivas_spar_br_table_consts[table_idx].ivas_total_brate; sba_order = ivas_spar_br_table_consts[table_idx].sba_order; - ivas_get_spar_table_idx( ivas_total_brate, sba_order, ivas_spar_br_table_consts[table_idx].bwidth, &code, &length ); + ivas_get_spar_table_idx( ivas_total_brate, sba_order, ivas_spar_br_table_consts[table_idx].bwidth, &length, &code ); for ( i = 0; i < pSpar_md_cfg->nchan_transport; i++ ) { total_bits += (int16_t) ( ivas_spar_br_table_consts[table_idx].core_brs[i][0] / FRAMES_PER_SEC ); max_bits += (int16_t) ( ivas_spar_br_table_consts[table_idx].core_brs[i][1] / FRAMES_PER_SEC ); } - pSpar_md_cfg->tgt_bits_per_blk = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC ) - IVAS_FORMAT_SIGNALING_NBITS_SBA - SBA_PLANAR_BITS - SBA_ORDER_BITS - length - total_bits; + pSpar_md_cfg->tgt_bits_per_blk = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC ) - IVAS_FORMAT_SIGNALING_NBITS_SBA - SBA_PLANAR_BITS - SBA_ORDER_BITS - length - total_bits; pSpar_md_cfg->max_bits_per_blk = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC ) - IVAS_FORMAT_SIGNALING_NBITS_SBA - SBA_PLANAR_BITS - SBA_ORDER_BITS - length - max_bits; md_coding_bits_header = SPAR_NUM_CODING_STRAT_BITS + pSpar_md_cfg->quant_strat_bits; + pSpar_md_cfg->tgt_bits_per_blk -= md_coding_bits_header; pSpar_md_cfg->max_bits_per_blk -= md_coding_bits_header; @@ -2156,9 +2143,11 @@ void ivas_spar_set_bitrate_config( pSpar_md_cfg->tgt_bits_per_blk += md_coding_bits_header; pSpar_md_cfg->max_bits_per_blk += md_coding_bits_header; + return; } + #ifdef FIX_I1_113 /*-----------------------------------------------------------------------------------------* * Function ivas_spar_bitrate_dist() diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 026191559b..8dd59f1d18 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -229,7 +229,6 @@ typedef struct ivas_spar_md_com_cfg int16_t active_w; int16_t remix_unmix_order; ivas_quant_strat_t quant_strat[MAX_QUANT_STRATS]; - int16_t gen_bs; int16_t quant_strat_bits; int16_t nchan_transport; int16_t num_quant_strats; @@ -352,15 +351,6 @@ typedef struct ivas_cov_smooth_cfg_t } ivas_cov_smooth_cfg_t; -#ifndef SBA_SPAR_HARM -typedef struct ivas_cov_smooth_in_buf_t -{ - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - int16_t num_ch; - int16_t reset_cov; - -} ivas_cov_smooth_in_buf_t; -#endif /* SPAR bitrate constant table structure */ typedef struct ivas_spar_br_table_t diff --git a/lib_com/ivas_stereo_psychlpc_com.c b/lib_com/ivas_stereo_psychlpc_com.c index 3cbca73cc0..8a50caaa29 100644 --- a/lib_com/ivas_stereo_psychlpc_com.c +++ b/lib_com/ivas_stereo_psychlpc_com.c @@ -68,14 +68,14 @@ static void SpectrumWeighting_Init( * initialize a PsychoacousticParameters structure *-------------------------------------------------------------------*/ - ivas_error - PsychoacousticParameters_Init( - const int32_t sr_core, /* i : sampling rate of core-coder */ - const int16_t nBins, /* i : Number of bins (spectral lines) */ - const int8_t nBands, /* i : Number of spectrum subbands */ - const int16_t isTCX20, /* i : Flag indicating if the subband division is for TCX20 or TCX10 */ - const int16_t isWarped, /* i : Flag indicating if the scale is linear or warped */ - PsychoacousticParameters *pPsychParams ) +ivas_error +PsychoacousticParameters_Init( + const int32_t sr_core, /* i : sampling rate of core-coder */ + const int16_t nBins, /* i : Number of bins (spectral lines) */ + const int8_t nBands, /* i : Number of spectrum subbands */ + const int16_t isTCX20, /* i : Flag indicating if the subband division is for TCX20 or TCX10 */ + const int16_t isWarped, /* i : Flag indicating if the scale is linear or warped */ + PsychoacousticParameters *pPsychParams ) { if ( pPsychParams == NULL ) diff --git a/lib_com/options.h b/lib_com/options.h index 884fb23615..71b4d7f6f0 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -126,6 +126,7 @@ #endif /*#define SPAR_HOA_DBG*/ /* SPAR HOA debug statements */ /*#define DEBUG_BINAURAL_FILTER_DESIGN*/ /* debugging of Crend binaural filter design */ +#define DEBUG_AGC_ENCODER_CMD_OPTION /* Ability to force enable or disable AGC behaviour in DIRAC/SPAR via command line option */ #endif /* #################### End DEBUGGING switches ############################ */ @@ -143,25 +144,25 @@ /*#define ITD_WINNER_GAIN_MODIFY */ /* ITD optimization - WORK IN PROGRESS */ /*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */ /*#define FIX_I1_113*/ /* under review : MCT bit distribution optimization for SBA high bitrates*/ - -#define FIX_I13_TCX_TNS_ISSUE /* Issue 13: Fix reported artifacts. Bug in TNS with TCX5 */ -#define FIX_TCX10_STEREO_PROC /* Issue 11 */ -#define CORECODER_BITRATE_SWITCHING /* Issue 133: support bitrate switching in core-coder */ -#define ISM_BITRATE_SWITCHING /* Issue 115: Support for Bitrate Switching in ISM */ -#define SBA_SPAR_HARM /* Issue 92: maintenance of the SBA SPAR functions */ -#define FIX_155_HP20_ISSUE /* Issue 155: apply hp20 on all input channels instead of just 2 channels */ -#define EFAP_FIX_POLY /* Issue 167: fix bug in EFAP polygon selection */ -#define SBA_HOA_HBR_IMPROV /* issue 91: Improvements to SBA high bitrate HOA3 coding */ -#define ALLRAD_OPTIM /* Issue 159: Optimize memory allocation for ALLRAD */ -#define FIX_I178_HQ_BUFFER_OVERRUN /* issue 178: Buffer overrun in HQ core decoder -- spectral filling buffer did not account for extended transition frame in IVAS */ #define PRINT_SBA_ORDER /* Issue 179: print-out also the SBA order of IVAS SBA format to stdout */ #define EXT_RENDERER /* FhG: external renderer library and standalone application */ #define FIX_EFAP_MATH /* fix for EFAP: remove angle quantization and a bug in polygon lookup causing incorrect gains. minor tweak for ALLRAD. non-BE for modes using EFAP */ +#define SPAR_STEREO_NO_DIRAC /* Issue 180: skip DirAC processing channels for stereo output */ #define AGC_TUNING_IMPROVEMENT /* Issue 168: Enable AGC for low bit rate (1 TC) */ #ifdef AGC_TUNING_IMPROVEMENT #define AGC_ENABLE_FOR_LBR /* Issue 168: Enable AGC for low bit rate (1 TC) */ #endif +#define FIX_I173_I174 /* Issues 173 and 174: Remove frame and subframe index from ISm metadata and headtracking respectively. */ +#define FIX_TCX_DEC_RECONF_BFI +#define FIX_SBA_DTX_DECODE_ERROR /* Issue 176: SBA decoder error with DTX at 80kbps SWB, Issue 21: SBA front-VAD threshold (203) */ +#define FIX_124_DONT_ALLOC_PLCINFO_IN_IVAS /* Issue 124: do not allocate unused plc struct in IVAS modes which is only used in EVS mono */ +/*#define FIX_MCT_PLC_RECOVERY*/ /* Issue 184: scale the old synthesis part correctly in the first good frame after lost frames in MCT modes - to be activated after previous switch is merged */ +#define FIX_MSAN_ERROR_STEREO_RATE_SWITCHING /* addresses Issue 177 */ +#define SBA_BR_SWITCHING /* Issue 114: Changes for sba bit rate switching*/ +#define FIX_AGC_WINFUNC_MEMORY /* Issue 62: lower agc_com.winFunc memory consumption */ + + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_com/vlpc_2st_com.c b/lib_com/vlpc_2st_com.c index f027ecd8ea..86fdf68c5f 100644 --- a/lib_com/vlpc_2st_com.c +++ b/lib_com/vlpc_2st_com.c @@ -52,8 +52,7 @@ void lsf_weight_2st( const float *lsfq, float *w, const int16_t mode, - const int32_t sr_core -) + const int32_t sr_core ) { int16_t i; float d[M + 1]; diff --git a/lib_debug/mem_count.c b/lib_debug/mem_count.c index b12639ae3f..ca4832399f 100644 --- a/lib_debug/mem_count.c +++ b/lib_debug/mem_count.c @@ -93,8 +93,11 @@ typedef INT64 int64_t; /* This is the maximum number of allocations for which to keep information. It can be increased if required. */ +#ifdef SBA_BR_SWITCHING +#define MAX_INFO_RECORDS 8000 +#else #define MAX_INFO_RECORDS 3000 - +#endif /* This is the length after which the function name will be truncated when the summary is printed. */ #define MAX_FUNCTION_NAME_LENGTH 18 diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c index c74564e1f7..20e4dedbe3 100644 --- a/lib_dec/dec_tcx.c +++ b/lib_dec/dec_tcx.c @@ -152,7 +152,11 @@ void decoder_tcx_post( if ( bfi && !st->use_partial_copy ) { /* run lpc gain compensation not for waveform adjustment */ +#ifdef FIX_124_DONT_ALLOC_PLCINFO_IN_IVAS + if ( !st->enablePlcWaveadjust || ( st->hPlcInfo != NULL && st->hPlcInfo->concealment_method == TCX_TONAL ) ) +#else if ( !st->enablePlcWaveadjust || st->hPlcInfo->concealment_method == TCX_TONAL ) +#endif { float gainHelperFB = hTcxDec->gainHelper; float stepCompensateFB = hTcxDec->stepCompensate * st->L_frame / hTcxDec->L_frameTCX; @@ -1465,12 +1469,6 @@ void decoder_tcx_tns( isTCX5 = 1; tcx5SpectrumDeinterleaving( L >> 1, x ); -#ifndef FIX_I13_TCX_TNS_ISSUE - if ( hTcxCfg->fIsTNSAllowed && fUseTns != 0 && bfi != 1 && tnsData->tnsOnWhitenedSpectra == whitenedDomain ) - { - tcx5TnsGrouping( L >> 1, hTcxCfg->tnsConfig[0][0].iFilterBorders[0] >> 1, x ); - } -#endif } } @@ -1488,12 +1486,10 @@ void decoder_tcx_tns( /* Apply TNS to get the reconstructed signal */ SetTnsConfig( hTcxCfg, L_frame_glob == st->L_frame, ( st->last_core == ACELP_CORE ) && ( frame_cnt == 0 ) ); -#ifdef FIX_I13_TCX_TNS_ISSUE if ( ( L_frame == st->L_frame >> 1 ) && st->tcxonly && isTCX5 ) { tcx5TnsGrouping( L >> 1, hTcxCfg->tnsConfig[0][0].iFilterBorders[0] >> 1, x ); } -#endif ApplyTnsFilter( hTcxCfg->pCurrentTnsConfig, tnsData, x, 0 ); #ifdef DEBUG_PLOT @@ -1502,9 +1498,6 @@ void decoder_tcx_tns( if ( ( L_frame == st->L_frame >> 1 ) && st->tcxonly && isTCX5 ) { -#ifndef FIX_I13_TCX_TNS_ISSUE - tcx5TnsUngrouping( L_frameTCX >> 1, hTcxCfg->tnsConfig[0][0].iFilterBorders[0] >> 1, x, DEC ); -#else if ( st->element_mode == EVS_MONO || L_spec < L_frameTCX ) /* TBC: this is temporary to maintain EVS BE, this is a bug and should be fixed also for EVS (see issue 13) */ { tcx5TnsUngrouping( L_frameTCX >> 1, hTcxCfg->tnsConfig[0][0].iFilterBorders[0] >> 1, x, DEC ); @@ -1513,7 +1506,6 @@ void decoder_tcx_tns( { tcx5TnsUngrouping( L >> 1, hTcxCfg->tnsConfig[0][0].iFilterBorders[0] >> 1, x, DEC ); } -#endif } } diff --git a/lib_dec/igf_dec.c b/lib_dec/igf_dec.c index f876391b2d..2cded75928 100644 --- a/lib_dec/igf_dec.c +++ b/lib_dec/igf_dec.c @@ -679,8 +679,8 @@ static void IGF_appl( float *pSpectralData, /* i/o: Q31 | MDCT spectrum */ const float *igf_spec, /* i : Q31 | prepared IGF spectrum */ float *virtualSpec, /* o : Q31 | virtual IGF spectrum, used for temp flattening */ - int16_t *flag_sparse, /* o : Q0 | temp flattening indicator */ - const int16_t bfi_apply_damping /* i : flag to indicate if damping for lost frames should be applied */ + int16_t *flag_sparse, /* o : Q0 | temp flattening indicator */ + const int16_t bfi_apply_damping /* i : flag to indicate if damping for lost frames should be applied */ ) { H_IGF_GRID hGrid; @@ -1240,8 +1240,7 @@ void IGFDecApplyStereo( const int16_t *coreMsMask, const int16_t restrict_hopsize, const int16_t bfi, /* i : frame loss == 1, frame good == 0 */ - const int16_t bfi_apply_damping -) + const int16_t bfi_apply_damping ) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateDataL, hPrivateDataR; H_IGF_GRID hGrid; diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c index 4f022e2811..4b74ccebb9 100644 --- a/lib_dec/init_dec.c +++ b/lib_dec/init_dec.c @@ -661,7 +661,11 @@ ivas_error init_decoder( * Mode 2 initialization *-----------------------------------------------------------------*/ +#ifdef FIX_124_DONT_ALLOC_PLCINFO_IN_IVAS + if ( st->element_mode == EVS_MONO ) +#else if ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) +#endif { if ( ( st->hPlcInfo = (T_PLCInfo_HANDLE) count_malloc( sizeof( T_PLCInfo ) ) ) == NULL ) { @@ -685,8 +689,9 @@ ivas_error init_decoder( st->hTECDec = NULL; } +#ifndef FIX_124_DONT_ALLOC_PLCINFO_IN_IVAS // the initialziation is done in open_decoder_LPD() st->enablePlcWaveadjust = 0; - +#endif /* Init Core Decoder */ open_decoder_LPD( st, st->total_brate, st->last_total_brate, st->bwidth, 0, st->element_mode, 1 ); diff --git a/lib_dec/ivas_agc_dec.c b/lib_dec/ivas_agc_dec.c index 81039651d8..e522574bb2 100644 --- a/lib_dec/ivas_agc_dec.c +++ b/lib_dec/ivas_agc_dec.c @@ -98,7 +98,11 @@ ivas_error ivas_spar_agc_dec_open( ) { ivas_agc_dec_state_t *hAgc; +#ifdef FIX_AGC_WINFUNC_MEMORY + int16_t output_frame, delay; +#else int16_t output_frame; +#endif if ( ( hAgc = (ivas_agc_dec_state_t *) count_malloc( sizeof( ivas_agc_dec_state_t ) ) ) == NULL ) { @@ -106,8 +110,15 @@ ivas_error ivas_spar_agc_dec_open( } output_frame = (int16_t) ( output_Fs / FRAMES_PER_SEC ); +#ifdef FIX_AGC_WINFUNC_MEMORY + delay = NS2SA( output_Fs, ( IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ) ); +#endif +#ifdef FIX_AGC_WINFUNC_MEMORY + if ( ( hAgc->agc_com.winFunc = (float *) count_malloc( sizeof( float ) * ( output_frame - delay ) ) ) == NULL ) +#else if ( ( hAgc->agc_com.winFunc = (float *) count_malloc( sizeof( float ) * output_frame ) ) == NULL ) +#endif { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AGC decoder" ); } @@ -122,7 +133,11 @@ ivas_error ivas_spar_agc_dec_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AGC decoder" ); } +#ifdef FIX_AGC_WINFUNC_MEMORY + ivas_agc_dec_init( hAgc, output_frame, delay ); +#else ivas_agc_dec_init( hAgc, output_frame, NS2SA( output_Fs, ( IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ) ) ); +#endif *hAgcDec = hAgc; diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index fd5d5b3c1e..5c189b7d32 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -181,13 +181,32 @@ ivas_error ivas_core_dec( st->flagGuidedAcelp = 0; } +#ifdef FIX_124_DONT_ALLOC_PLCINFO_IN_IVAS +#ifdef FIX_MCT_PLC_RECOVERY + if ( !st->bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hTcxDec != NULL ) +#else + if ( !st->bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hTcxDec != NULL && hMCT == NULL ) +#endif + { + float gain; + + gain = st->hTcxDec->conceal_eof_gain * st->last_concealed_gain_syn_deemph; + v_multc( st->hHQ_core->old_out, gain, st->hHQ_core->old_out, st->hTcxDec->L_frameTCX ); + v_multc( st->hHQ_core->old_outLB, gain, st->hHQ_core->old_outLB, st->L_frame ); + + if ( !st->hTcxCfg->last_aldo ) + { + v_multc( st->hTcxDec->syn_OverlFB, gain, st->hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB ); + v_multc( st->hTcxDec->syn_Overl, gain, st->hTcxDec->syn_Overl, st->hTcxCfg->tcx_mdct_window_length ); + } + } +#else /* PLC: [TCX: Fade-out-recovery] - overlapping part needs to be attenuated for first good frame */ if ( !st->bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) ) { float gain; - gain = ( st->element_mode == IVAS_CPE_MDCT ) ? st->hTcxDec->conceal_eof_gain : - ( st->hPlcInfo != NULL ) ? st->hPlcInfo->recovery_gain : 0.0f; + gain = ( st->element_mode == IVAS_CPE_MDCT ) ? st->hTcxDec->conceal_eof_gain : ( st->hPlcInfo != NULL ) ? st->hPlcInfo->recovery_gain : 0.0f; if ( ( st->element_mode == IVAS_CPE_MDCT && hMCT == NULL ) || ( st->hPlcInfo != NULL ) ) { @@ -201,6 +220,7 @@ ivas_error ivas_core_dec( } } } +#endif set_f( voice_factors[n], 0.f, NB_SUBFR16k ); set_f( hb_synth[n], 0.0f, L_FRAME48k ); diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index cebd170100..b11ba6cd39 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -46,7 +46,6 @@ #include "wmops.h" -#ifdef CORECODER_BITRATE_SWITCHING /*-------------------------------------------------------------------* * ivas_corecoder_dec_reconfig() * @@ -272,9 +271,7 @@ ivas_error ivas_corecoder_dec_reconfig( *-----------------------------------------------------------------*/ /// VE: this could be merged with part of ivas_init_decoder() -#ifdef ISM_BITRATE_SWITCHING if ( st_ivas->ivas_format == SBA_FORMAT ) -#endif { if ( st_ivas->sba_mode == SBA_MODE_SPAR && st_ivas->nchan_transport == 1 ) { @@ -401,4 +398,3 @@ ivas_error ivas_hp20_dec_reconfig( return error; } -#endif diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index ec9a712065..d7feb33256 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -234,13 +234,13 @@ ivas_error ivas_dirac_dec_config( if ( hDirAC->hOutSetup.ambisonics_order == -1 ) { - hDirAC->hOutSetup.ambisonics_order = 3; /* Order 3 is used by default in DirAC for SHD processing */ + hDirAC->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */ if ( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_MONO || hDirAC->hOutSetup.output_config == AUDIO_CONFIG_STEREO ) { - hDirAC->hOutSetup.ambisonics_order = 1; + hDirAC->hOutSetup.ambisonics_order = SBA_FOA_ORDER; } } - else if ( hDirAC->hOutSetup.ambisonics_order >= 1 ) + else if ( hDirAC->hOutSetup.ambisonics_order >= SBA_FOA_ORDER ) { mvr2r( ls_azimuth_4d4, ls_azimuth, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS ); mvr2r( ls_elevation_4d4, ls_elevation, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS ); diff --git a/lib_dec/ivas_dirac_dec_binaural_functions.c b/lib_dec/ivas_dirac_dec_binaural_functions.c index ca9f0a4587..1418193139 100644 --- a/lib_dec/ivas_dirac_dec_binaural_functions.c +++ b/lib_dec/ivas_dirac_dec_binaural_functions.c @@ -29,7 +29,7 @@ the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ - +// VE2AT: move to lib_rend ? #include #include "options.h" #include @@ -37,7 +37,7 @@ #include "prot.h" #include "ivas_prot.h" #include "ivas_cnst.h" -#include "ivas_rom_binauralRenderer.h" +#include "ivas_rom_binauralRenderer.h" // VE2AT: what about to put these includes ust into ivas_rom_rend.c ? #include "ivas_rom_dec.h" #ifdef DEBUGGING #include "debug.h" diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index e3849dfbe0..5cc318b86f 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -69,7 +69,6 @@ ivas_error ivas_dec_setup( Decoder_State *st; int32_t ivas_total_brate; ivas_error error; - error = IVAS_ERR_OK; num_bits_read = 0; @@ -128,10 +127,24 @@ ivas_error ivas_dec_setup( num_bits_read += SBA_ORDER_BITS; if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate && ivas_total_brate > IVAS_SID_5k2 ) { - if ( ( error = ivas_sba_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) +#ifdef SBA_BR_SWITCHING + if ( get_sba_reinit_flag( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) { - return error; + if ( ( error = ivas_sba_dec_reinit( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { +#endif + if ( ( error = ivas_sba_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef SBA_BR_SWITCHING } +#endif } else { @@ -410,7 +423,7 @@ static ivas_error ivas_read_format( // TBD: needs more work for HOA if ( st_ivas->sba_analysis_order == 0 ) { - st_ivas->sba_analysis_order = 1; + st_ivas->sba_analysis_order = SBA_FOA_ORDER; } if ( idx == 1 ) { @@ -790,7 +803,11 @@ ivas_error ivas_init_decoder( return error; } - if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) + if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA +#ifdef SPAR_STEREO_NO_DIRAC + && st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_STEREO && st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_MONO +#endif + ) { if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK ) { @@ -887,9 +904,7 @@ ivas_error ivas_init_decoder( } st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ -#ifdef CORECODER_BITRATE_SWITCHING st_ivas->hCPE[0]->hCoreCoder[1] = NULL; -#endif } if ( st_ivas->nCPE > 1 ) @@ -1087,9 +1102,7 @@ ivas_error ivas_init_decoder( } st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ -#ifdef CORECODER_BITRATE_SWITCHING st_ivas->hCPE[0]->hCoreCoder[1] = NULL; -#endif } /* set CNA/CNG flags */ diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index c6c1f99c9c..8ebf27afb5 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -1004,7 +1004,6 @@ void ivas_param_ism_params_to_masa_param_mapping( } -#ifdef ISM_BITRATE_SWITCHING /*-------------------------------------------------------------------------* * ivas_ism_bitrate_switching() * @@ -1018,9 +1017,6 @@ static ivas_error ivas_ism_bitrate_switching( const int16_t num_obj /* i : number of objects in the bitstream */ ) { -#ifndef CORECODER_BITRATE_SWITCHING - int16_t sce_id; -#endif ivas_error error; int32_t element_brate_tmp[MAX_NUM_OBJECTS]; @@ -1029,85 +1025,9 @@ static ivas_error ivas_ism_bitrate_switching( ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, num_obj, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ); st_ivas->nSCE = st_ivas->nchan_transport; -#ifdef CORECODER_BITRATE_SWITCHING ivas_corecoder_dec_reconfig( st_ivas, nchan_transport_old, 0, nchan_transport_old, 0 ); -#else - if ( st_ivas->nchan_transport > nchan_transport_old ) - { - /* Initialize for new bitrate */ - for ( sce_id = 0; sce_id < nchan_transport_old; sce_id++ ) - { - st_ivas->hSCE[sce_id]->element_brate = st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport; - st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - } - /* Initialize some memories */ - for ( sce_id = nchan_transport_old; sce_id < st_ivas->nchan_transport; sce_id++ ) - { - if ( ( error = create_sce_dec( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) - { - return error; - } - } - } - else - { - /* Initialize for new bitrate */ - for ( sce_id = 0; sce_id < st_ivas->nchan_transport; sce_id++ ) - { - st_ivas->hSCE[sce_id]->element_brate = st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport; - st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - } - - /* Destroy the core coder memory */ - for ( ; sce_id < nchan_transport_old; sce_id++ ) - { - destroy_sce_dec( st_ivas->hSCE[sce_id] ); - st_ivas->hSCE[sce_id] = NULL; - } - } -#endif - -#ifdef CORECODER_BITRATE_SWITCHING ivas_hp20_dec_reconfig( st_ivas, nchan_transport_old ); -#else - /* destroy the memory of hp20*/ - if ( st_ivas->mem_hp20_out != NULL ) - { - for ( sce_id = 0; sce_id < nchan_transport_old; sce_id++ ) - { - count_free( st_ivas->mem_hp20_out[sce_id] ); - st_ivas->mem_hp20_out[sce_id] = NULL; - } - count_free( st_ivas->mem_hp20_out ); - st_ivas->mem_hp20_out = NULL; - } - - /* re initialize the memory of hp20 */ - /* set number of input channels used for analysis/coding */ - - if ( st_ivas->nchan_transport > 0 ) - { - if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( st_ivas->nchan_transport * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - } - else - { - st_ivas->mem_hp20_out = NULL; - } - - for ( sce_id = 0; sce_id < st_ivas->nchan_transport; sce_id++ ) - { - if ( ( st_ivas->mem_hp20_out[sce_id] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - set_f( st_ivas->mem_hp20_out[sce_id], 0.0f, L_HP20_MEM ); - } -#endif /* Initialize the needed renderer struct and destroy the unnecessary renderer struct */ @@ -1215,7 +1135,6 @@ static ivas_error ivas_ism_bitrate_switching( return error; } -#endif /*------------------------------------------------------------------------- * ivas_ism_dec_config() @@ -1233,9 +1152,7 @@ ivas_error ivas_ism_dec_config( int32_t ivas_total_brate; ISM_MODE last_ism_mode; ivas_error error; -#ifdef ISM_BITRATE_SWITCHING int16_t nchan_transport_old; -#endif error = IVAS_ERR_OK; @@ -1243,14 +1160,12 @@ ivas_error ivas_ism_dec_config( /* store last frame ISM mode */ last_ism_mode = st_ivas->ism_mode; -#ifdef ISM_BITRATE_SWITCHING /* Assumes that num of input objects are constant */ nchan_transport_old = num_obj; if ( last_ism_mode == ISM_MODE_PARAM ) { nchan_transport_old = 2; } -#endif if ( !st_ivas->bfi && ivas_total_brate != IVAS_SID_5k2 && ivas_total_brate != FRAME_NO_DATA ) { @@ -1269,7 +1184,6 @@ ivas_error ivas_ism_dec_config( if ( st_ivas->ini_active_frame != 0 ) { -#ifdef ISM_BITRATE_SWITCHING /* ISM bit-rate switching */ if ( st_ivas->hDecoderConfig->last_ivas_total_brate != IVAS_SID_5k2 && st_ivas->hDecoderConfig->last_ivas_total_brate != FRAME_NO_DATA ) { @@ -1278,14 +1192,6 @@ ivas_error ivas_ism_dec_config( ivas_ism_bitrate_switching( st_ivas, nchan_transport_old, last_ism_mode, num_obj ); } } -#else - /* ISM format switching */ - if ( st_ivas->ism_mode != last_ism_mode ) - { - /*ivas_ism_dec_reconfigure( st_ivas );*/ - return IVAS_ERROR( IVAS_ERR_RECONFIGURE_NOT_SUPPORTED, "\n\n!!! Error: ISM format switching not supported yet!!!\n\n" ); - } -#endif } } else if ( !st_ivas->bfi && ivas_total_brate == IVAS_SID_5k2 ) diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index 0e7f5f864a..f27d49b111 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -29,7 +29,7 @@ the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ - +// VE2AT: move to lib_rend ? #include #include "options.h" #include "ivas_cnst.h" diff --git a/lib_dec/ivas_mct_dec_mct.c b/lib_dec/ivas_mct_dec_mct.c index 2dd7b18d52..6b8f9b74fa 100644 --- a/lib_dec/ivas_mct_dec_mct.c +++ b/lib_dec/ivas_mct_dec_mct.c @@ -220,11 +220,7 @@ void apply_MCT_dec( { hBlock = hMCT->hBlockData[pair]; -#ifdef FIX_TCX10_STEREO_PROC stereo_decoder_tcx( hBlock->hStereoMdct, hBlock->mask, &x[hBlock->ch2][0], &x[hBlock->ch1][0], &x[hBlock->ch2][0], hBlock->hStereoMdct->mdct_stereo_mode, sts[hBlock->ch1]->core, sts[hBlock->ch2]->core, sts[0]->igf, sts[0]->hTcxDec->L_frameTCX, sts[1]->hTcxDec->L_frameTCX, 1, TCX_20_CORE, TCX_20_CORE, 0 ); -#else - stereo_decoder_tcx( hBlock->hStereoMdct, hBlock->mask, &x[hBlock->ch2][0], &x[hBlock->ch1][0], &x[hBlock->ch2][0], hBlock->hStereoMdct->mdct_stereo_mode, sts[hBlock->ch1]->core, sts[hBlock->ch2]->core, sts[0]->igf, sts[0]->hTcxDec->L_frameTCX, 1, TCX_20_CORE, TCX_20_CORE, 0 ); -#endif } applyGlobalILD( sts, hMCT, x ); diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index 748475dc5c..3e186d61b8 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -494,16 +494,10 @@ void ivas_mdct_core_invQ( if ( bfi && !MCT_flag && ( hCPE->hStereoMdct->mdct_stereo_mode[0] > SMDCT_DUAL_MONO || hCPE->hStereoMdct->mdct_stereo_mode[1] > SMDCT_DUAL_MONO ) ) { L_frameTCX[0] = sts[0]->L_frameTCX_past; -#ifdef FIX_TCX10_STEREO_PROC L_frameTCX[1] = sts[1]->L_frameTCX_past; -#endif mvr2r( sts[0]->hTonalMDCTConc->lastBlockData.spectralData, tmp_ms_sig[0], L_frameTCX[0] ); mvr2r( sts[1]->hTonalMDCTConc->lastBlockData.spectralData, tmp_ms_sig[1], L_frameTCX[0] ); -#ifdef FIX_TCX10_STEREO_PROC stereo_decoder_tcx( hCPE->hStereoMdct, ms_mask, x_0[1], &sts[0]->hTonalMDCTConc->lastBlockData.spectralData, &sts[1]->hTonalMDCTConc->lastBlockData.spectralData, &hCPE->hStereoMdct->mdct_stereo_mode[0], sts[0]->core, sts[1]->core, sts[0]->igf, L_frameTCX[0], L_frameTCX[1], 0, sts[0]->last_core, sts[1]->last_core, 1 ); -#else - stereo_decoder_tcx( hCPE->hStereoMdct, ms_mask, x_0[1], &sts[0]->hTonalMDCTConc->lastBlockData.spectralData, &sts[1]->hTonalMDCTConc->lastBlockData.spectralData, &hCPE->hStereoMdct->mdct_stereo_mode[0], sts[0]->core, sts[1]->core, sts[0]->igf, L_frameTCX[0], 0, sts[0]->last_core, sts[1]->last_core, 1 ); -#endif } if ( bfi ) diff --git a/lib_dec/ivas_mono_dmx_renderer.c b/lib_dec/ivas_mono_dmx_renderer.c index 468b0215b0..20b677075e 100644 --- a/lib_dec/ivas_mono_dmx_renderer.c +++ b/lib_dec/ivas_mono_dmx_renderer.c @@ -29,7 +29,7 @@ the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ - +// VE2AT: move to lib_rend ? #include #include "options.h" #include diff --git a/lib_dec/ivas_out_setup_conversion.c b/lib_dec/ivas_out_setup_conversion.c index 9ed27e56c3..55f53bae73 100644 --- a/lib_dec/ivas_out_setup_conversion.c +++ b/lib_dec/ivas_out_setup_conversion.c @@ -29,7 +29,7 @@ the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ - +// VE2AT: move to lib_rend ? #include #include #include "options.h" diff --git a/lib_dec/ivas_post_proc.c b/lib_dec/ivas_post_proc.c index a295a8b2a2..b2cc27d5ef 100644 --- a/lib_dec/ivas_post_proc.c +++ b/lib_dec/ivas_post_proc.c @@ -478,7 +478,11 @@ void stereo_dft_dec_core_switching( mvr2r( output, pAp_input, st->L_frame ); } +#ifdef FIX_MSAN_ERROR_STEREO_RATE_SWITCHING + if ( st->last_core == ACELP_CORE && !( st->prev_bfi == 1 && st->last_core == ACELP_CORE && st->last_con_tcx == 1 ) && !st->tcxonly ) /* ACELP -> TCX/HQ-Core */ +#else if ( st->last_core == ACELP_CORE && !( st->prev_bfi == 1 && st->last_core == ACELP_CORE && st->last_con_tcx == 1 ) ) /* ACELP -> TCX/HQ-Core */ +#endif { mvr2r( tcx_core_buf, tmp_fade, ap_fade_len ); for ( i = 0; i < ap_fade_len; i++ ) diff --git a/lib_dec/ivas_rom_dec.c b/lib_dec/ivas_rom_dec.c index 3a08c33e79..c79bc38019 100644 --- a/lib_dec/ivas_rom_dec.c +++ b/lib_dec/ivas_rom_dec.c @@ -516,7 +516,7 @@ const int16_t sba_map_tc[8] = /*----------------------------------------------------------------------------------* * FASTCONV and PARAMETRIC binaural renderer ROM tables *----------------------------------------------------------------------------------*/ - +// VE2AT: move to in ivas_rom_dec ? const float surCohEne[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS] = { 3.0903f, 2.0053f, 1.0860f, 0.8072f, 0.7079f diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 0f1bedbad7..fe043c746b 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -45,378 +45,618 @@ #include "wmops.h" +#ifdef SBA_BR_SWITCHING /*-------------------------------------------------------------------* - * ivas_sba_dec_decoder() + * ivas_sba_dec_reinit() * - * Reconfigure IVAS SBA decoder + * Reinitialisation of IVAS SBA decoder *-------------------------------------------------------------------*/ -ivas_error ivas_sba_dec_reconfigure( +ivas_error ivas_sba_dec_reinit( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { -#ifdef CORECODER_BITRATE_SWITCHING - int16_t i; - int16_t nchan_transport, nchan_transport_old; - int16_t nSCE_old, nCPE_old, nchan_hp20_old; -#else - int16_t i, n, sce_id, cpe_id; - int16_t nchan_transport, nchan_transport_old; - int16_t nSCE_old, nCPE_old; -#endif - AUDIO_CONFIG intern_config_old; - int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses, numCldfbSyntheses_old; - int16_t sba_dirac_stereo_flag_old; - int32_t ivas_total_brate, last_ivas_total_brate; + int16_t i, k, n; + int16_t sce_id, cpe_id; + int16_t numCldfbAnalyses; + int16_t numCldfbSyntheses; + int32_t output_Fs, ivas_total_brate; + AUDIO_CONFIG output_config; + DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; error = IVAS_ERR_OK; - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; + output_Fs = st_ivas->hDecoderConfig->output_Fs; + hDecoderConfig = st_ivas->hDecoderConfig; + output_config = hDecoderConfig->output_config; + ivas_total_brate = hDecoderConfig->ivas_total_brate; - /*-----------------------------------------------------------------* - * Allocate, initalize, and configure SBA and rendering handles - *-----------------------------------------------------------------*/ + hDecoderConfig->last_ivas_total_brate = ivas_total_brate; + /*------------------------------------------------------------------------------------------* + * Closing Decoder handles before Reinitialisation + *------------------------------------------------------------------------------------------*/ + /* Qmetadata handle */ + ivas_qmetadata_close( &st_ivas->hQMetaData ); - ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); - numCldfbAnalyses = 0; + /* DirAC handle */ + if ( st_ivas->hDirAC != NULL ) + { + if ( st_ivas->ivas_format == ISM_FORMAT ) + { + ivas_param_ism_dec_close( st_ivas->hDirAC, st_ivas->hDecoderConfig->output_config ); + } + else + { + ivas_dirac_dec_close( st_ivas->hDirAC ); + } + st_ivas->hDirAC = NULL; + } -#ifdef CORECODER_BITRATE_SWITCHING - nchan_hp20_old = getNumChanSynthesis( st_ivas ); -#endif + /* Spar handle */ + if ( st_ivas->hSpar != NULL ) + { + ivas_spar_dec_close( st_ivas->hSpar, st_ivas->hDecoderConfig->output_Fs ); + st_ivas->hSpar = NULL; + } - nSCE_old = st_ivas->nSCE; - nCPE_old = st_ivas->nCPE; - nchan_transport_old = st_ivas->nchan_transport; - sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; + /* SCE handles */ + for ( i = 0; i < MAX_SCE; i++ ) + { + if ( st_ivas->hSCE[i] != NULL ) + { + destroy_sce_dec( st_ivas->hSCE[i] ); + st_ivas->hSCE[i] = NULL; + } + } - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); + /* CPE handles */ + for ( i = 0; i < MAX_CPE; i++ ) + { + if ( st_ivas->hCPE[i] != NULL ) + { + /* set pointer to NULL as core coder already deallocated in destroy_sce_dec() */ + if ( st_ivas->sba_dirac_stereo_flag ) + { + st_ivas->hCPE[i]->hCoreCoder[0] = NULL; + st_ivas->hCPE[i]->hCoreCoder[1] = NULL; + } + destroy_cpe_dec( st_ivas->hCPE[i] ); + st_ivas->hCPE[i] = NULL; + } + } - ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); + /* MCT handle */ + ivas_mct_dec_close( &st_ivas->hMCT ); - st_ivas->nchan_transport = nchan_transport; + /* HP20 filter handles */ + if ( st_ivas->mem_hp20_out != NULL ) + { + for ( i = 0; i < getNumChanSynthesis( st_ivas ); i++ ) + { + count_free( st_ivas->mem_hp20_out[i] ); + st_ivas->mem_hp20_out[i] = NULL; + } + count_free( st_ivas->mem_hp20_out ); + st_ivas->mem_hp20_out = NULL; + } - /* renderer might have changed */ - intern_config_old = st_ivas->intern_config; - ivas_renderer_select( st_ivas ); + /* HOA decoder matrix */ + if ( st_ivas->hoa_dec_mtx != NULL ) + { + count_free( st_ivas->hoa_dec_mtx ); + st_ivas->hoa_dec_mtx = NULL; + } - /* side effect of the renderer selection can be a changed internal config */ - if ( st_ivas->intern_config != intern_config_old ) + /* Parametric MC handle */ + ivas_param_mc_dec_close( &st_ivas->hParamMC ); + + /* EFAP handle */ + efap_free_data( &st_ivas->hEFAPdata ); + + /* VBAP handle */ + vbap_free_data( &( st_ivas->hVBAPdata ) ); + + /* Fastconv binaural renderer handle */ + ivas_binRenderer_close( &st_ivas->hBinRenderer ); + + /* Parametric binaural renderer handle */ + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); + + /* Crend handle */ + ivas_crend_close( st_ivas ); + + /* LS config converter handle */ + ivas_ls_setup_conversion_close( &st_ivas->hLsSetUpConversion ); + + /* Custom LS configuration handle */ + if ( st_ivas->hLsSetupCustom != NULL ) { - ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); + count_free( st_ivas->hLsSetupCustom ); + st_ivas->hLsSetupCustom = NULL; } - if ( st_ivas->sba_mode != SBA_MODE_SPAR ) + /* MASA decoder structure */ + if ( st_ivas->hMasa != NULL ) { - st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); + ivas_masa_dec_close( st_ivas->hMasa ); + st_ivas->hMasa = NULL; + } - if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) + /* Downmix structure */ + if ( st_ivas->hMonoDmxRenderer != NULL ) + { + count_free( st_ivas->hMonoDmxRenderer ); + st_ivas->hMonoDmxRenderer = NULL; + } + + /* Head track data handle */ + if ( st_ivas->hHeadTrackData != NULL ) + { + count_free( st_ivas->hHeadTrackData ); + st_ivas->hHeadTrackData = NULL; + } + + /* Time Domain binaural renderer handle */ + if ( st_ivas->hBinRendererTd != NULL ) + { + ivas_td_binaural_close( &st_ivas->hBinRendererTd ); + } + else if ( st_ivas->hHrtfTD != NULL ) + { + /* Case when HRTF filter is mistakenly specified but TD renderer was not active */ + if ( st_ivas->hHrtfTD->ModelParams.UseItdModel && !st_ivas->hHrtfTD->ModelParams.modelROM ) { - return error; + BSplineModelEvalITDDealloc( &st_ivas->hHrtfTD->ModelParamsITD ); } + + BSplineModelEvalDealloc( &st_ivas->hHrtfTD->ModelParams, &st_ivas->hHrtfTD->ModelEval ); + + ivas_HRTF_binary_close( &st_ivas->hHrtfTD ); } - else - { - int16_t sba_order_internal; - sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); - ivas_spar_config( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); + /* Config. Renderer */ + ivas_render_config_close( &( st_ivas->hRenderConfig ) ); - if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) + for ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) + { + if ( st_ivas->cldfbAnaDec[i] != NULL ) { - return error; + deleteCldfb( &( st_ivas->cldfbAnaDec[i] ) ); + st_ivas->cldfbAnaDec[i] = NULL; } } - if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && ( last_ivas_total_brate > IVAS_SID_5k2 || nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) + for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - if ( st_ivas->hDirAC != NULL ) + if ( st_ivas->cldfbSynDec[i] != NULL ) { - if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) - { - return error; - } + deleteCldfb( &( st_ivas->cldfbSynDec[i] ) ); + st_ivas->cldfbSynDec[i] = NULL; } - else + } + + /*------------------------------------------------------------------------------------------* + * Reopening Decoder handles for Reinitialisation + *------------------------------------------------------------------------------------------*/ + + /* Allocate and initialize Custom loudspeaker layout handle */ + if ( st_ivas->hDecoderConfig->Opt_LsCustom ) + { + if ( ( error = ivas_ls_custom_open( &( st_ivas->hLsSetupCustom ) ) ) != IVAS_ERR_OK ) { - if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } } - else if ( st_ivas->renderer_type == RENDERER_DISABLE || ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->sba_mode != SBA_MODE_SPAR ) ) + + /* Allocate and initialize Head-Tracking handle */ + if ( st_ivas->hDecoderConfig->Opt_Headrotation ) { - if ( st_ivas->hDirAC != NULL ) + if ( ( error = ivas_headTrack_open( &( st_ivas->hHeadTrackData ) ) ) != IVAS_ERR_OK ) { - ivas_dirac_dec_close( st_ivas->hDirAC ); - st_ivas->hDirAC = NULL; + return error; } + } - if ( st_ivas->hVBAPdata != NULL ) + /* Allocate HRTF binary handle */ + if ( st_ivas->hDecoderConfig->Opt_HRTF_binary ) + { + if ( ( error = ivas_HRTF_binary_open( &( st_ivas->hHrtfTD ) ) ) != IVAS_ERR_OK ) { - vbap_free_data( &( st_ivas->hVBAPdata ) ); + return error; } } - /*-----------------------------------------------------------------* - * Allocate, initalize, and configure SCE/CPE/MCT handles - *-----------------------------------------------------------------*/ - -#ifdef CORECODER_BITRATE_SWITCHING - ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old ); - - /*-----------------------------------------------------------------* - * HP20 memories - *-----------------------------------------------------------------*/ - - ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ); -#else - - if ( nchan_transport == nchan_transport_old ) + st_ivas->sba_dirac_stereo_flag = 0; + /*Reconfigure output paramaters*/ + ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); + ivas_renderer_select( st_ivas ); + ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); + if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + return error; + } + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) + { + if ( ( error = ivas_spar_dec_open( st_ivas ) ) != IVAS_ERR_OK ) { - st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; - st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + return error; } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->hOutSetup.is_loudspeaker_setup ) { - st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; - - /* prepare bitstream buffers */ - for ( n = 0; n < CPE_CHANNELS; n++ ) + if ( ( error = ivas_sba_get_hoa_dec_matrix( st_ivas->hOutSetup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + return error; } } - if ( st_ivas->nCPE > 1 ) + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) { - if ( ( error = mct_dec_reconfigure( st_ivas, 0 ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } + + for ( k = 0; k < DIRAC_MAX_NBANDS; k++ ) + { + st_ivas->hSpar->dirac_to_spar_md_bands[k] = st_ivas->hDirAC->dirac_to_spar_md_bands[k]; + } + st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + } + else + { + int16_t band_grouping[IVAS_MAX_NUM_BANDS + 1]; + + st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); + + ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), + st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); } } else { - int16_t nSCE_existing; - int16_t nCPE_existing; + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) + { + return error; + } - nSCE_existing = min( nSCE_old, st_ivas->nSCE ); - nCPE_existing = min( nCPE_old, st_ivas->nCPE ); + st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && output_config == AUDIO_CONFIG_STEREO ); - /* destroy superfluous core coder elements */ - for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ ) + if ( ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC ) && st_ivas->hOutSetup.is_loudspeaker_setup ) { - destroy_sce_dec( st_ivas->hSCE[sce_id] ); - st_ivas->hSCE[sce_id] = NULL; + int16_t ambisonics_order; + + ambisonics_order = ivas_sba_get_order_transport( st_ivas->nchan_transport ); // VE: is it needed ? - /* remove dummy CPE needed for 1TC->Stereo rendering via DFT stereo*/ - if ( sba_dirac_stereo_flag_old ) + if ( ( error = ivas_sba_get_hoa_dec_matrix( st_ivas->hOutSetup, &st_ivas->hoa_dec_mtx, ambisonics_order ) ) != IVAS_ERR_OK ) { -#ifdef DEBUGGING - assert( st_ivas->hCPE[0] ); -#endif - st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hCPE[0]->hCoreCoder[1] = NULL; - destroy_cpe_dec( st_ivas->hCPE[0] ); - st_ivas->hCPE[0] = NULL; + return error; } } + else if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) && !st_ivas->hIntSetup.is_loudspeaker_setup ) + { + IVAS_OUTPUT_SETUP out_setup; - for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ ) + ivas_output_init( &out_setup, AUDIO_CONFIG_7_1_4 ); + if ( ( error = ivas_sba_get_hoa_dec_matrix( out_setup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + if ( st_ivas->renderer_type != RENDERER_BINAURAL_MIXER_CONV && st_ivas->renderer_type != RENDERER_BINAURAL_MIXER_CONV_ROOM && + st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && st_ivas->sba_mode != SBA_MODE_SPAR ) + { + if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK ) { - destroy_cpe_dec( st_ivas->hCPE[cpe_id] ); - st_ivas->hCPE[cpe_id] = NULL; + return error; } - - if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL ) + } + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + if ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) { - ivas_mct_dec_close( &st_ivas->hMCT ); + return error; } - /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles from the first CPE*/ - if ( st_ivas->nCPE > 1 && nCPE_old == 1 ) + reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); + } + + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + if ( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) { - count_free( st_ivas->hCPE[0]->hStereoMdct ); - st_ivas->hCPE[0]->hStereoMdct = NULL; + return error; } - for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ ) + for ( n = 0; n < CPE_CHANNELS; n++ ) { - st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; - st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] ); } - for ( ; sce_id < st_ivas->nSCE; sce_id++ ) + } + + /* create CPE element for DFT Stereo like upmix */ + if ( st_ivas->sba_dirac_stereo_flag ) + { + if ( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) { - if ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } - for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) - { - st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; + st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ + } - /* prepare bitstream buffers */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - } - } - for ( ; cpe_id < st_ivas->nCPE; cpe_id++ ) + /* set CNA/CNG flags */ + if ( st_ivas->sba_mode == SBA_MODE_SPAR && st_ivas->nchan_transport == 1 ) + { + st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 0; /* Todo: Check if these can be enabled */ + st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 0; + } + else if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) ) + { + st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; + st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1; + } + else if ( st_ivas->nchan_transport == 2 ) + { + for ( n = 0; n < CPE_CHANNELS; n++ ) { - if ( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) - { - return error; - } + st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0; /* Todo: Check if these can be enabled */ + st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1; } + } - /* create CPE element for DFT Stereo like upmix */ - if ( st_ivas->sba_dirac_stereo_flag ) + if ( st_ivas->nCPE > 1 ) + { + if ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK ) { - if ( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; + } + } + /* set number of output channels used for synthesis/decoding */ + n = getNumChanSynthesis( st_ivas ); - st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ + if ( n > 0 ) + { + if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( n * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } + } + else + { + st_ivas->mem_hp20_out = NULL; + } - if ( st_ivas->nCPE > 1 && nCPE_old <= 1 ) + for ( i = 0; i < n; i++ ) + { + if ( ( st_ivas->mem_hp20_out[i] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) { - if ( nCPE_old == 1 ) - { - /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; - st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); - st_ivas->hCPE[0]->hCoreCoder[n]->igf = 0; - } - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } - if ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } + set_f( st_ivas->mem_hp20_out[i], 0.0f, L_HP20_MEM ); + } + if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL_ROOM ) + { + if ( ( error = ivas_render_config_open( &( st_ivas->hRenderConfig ) ) ) != IVAS_ERR_OK ) + { + return error; } - else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 ) + if ( ivas_render_config_init_from_rom( &st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL_ROOM ) != IVAS_ERR_OK ) { - if ( ( error = mct_dec_reconfigure( st_ivas, st_ivas->nCPE != nCPE_old ) ) != IVAS_ERR_OK ) - { - return error; - } + return IVAS_ERR_INTERNAL_FATAL; + } + } + if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + { + if ( ( error = ivas_binRenderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + { + if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) + { + if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; } - /* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */ - if ( st_ivas->nCPE == 1 && nCPE_old > 1 ) + if ( st_ivas->hRenderConfig->roomAcoustics.late_reverb_on ) { - if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) count_malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) + if ( ( st_ivas->hCrend = (CREND_HANDLE) count_malloc( sizeof( CREND_DATA ) ) ) == NULL ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR Crend\n" ); } + } + } + else if ( st_ivas->renderer_type == RENDERER_MC ) + { + if ( ( error = ivas_ls_setup_conversion_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) + { + if ( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( 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 ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "ivas_crend_open failed" ); + } + } + ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses ); - st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->use_itd = 0; - st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->reverse_dmx = 0; - st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->smooth_ratio = 1.f; + for ( i = 0; i < numCldfbAnalyses; i++ ) + { + if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + for ( ; i < MAX_INTERN_CHANNELS; i++ ) + { + st_ivas->cldfbAnaDec[i] = NULL; + } - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - /* reset mct_chan_mode */ - st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; - } + for ( i = 0; i < numCldfbSyntheses; i++ ) + { + if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + { + return error; } + } + for ( ; i < MAX_OUTPUT_CHANNELS; i++ ) + { + st_ivas->cldfbSynDec[i] = NULL; + } - /*-----------------------------------------------------------------* - * HP20 memories - *-----------------------------------------------------------------*/ + /* CLDFB Interpolation weights */ + if ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->sba_mode == SBA_MODE_SPAR ) + { + ivas_spar_get_cldfb_gains( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig ); + } + return error; +} +#endif - if ( nchan_transport > nchan_transport_old ) - { - /* create additional hp20 memories */ - float **old_mem_hp20_out; - uint16_t n_old; +/*-------------------------------------------------------------------* + * ivas_sba_dec_decoder() + * + * Reconfigure IVAS SBA decoder + *-------------------------------------------------------------------*/ - if ( sba_dirac_stereo_flag_old ) - { - n_old = CPE_CHANNELS; - } - else - { - n_old = nchan_transport_old; - } - n = st_ivas->nchan_transport; +ivas_error ivas_sba_dec_reconfigure( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + int16_t i; + int16_t nchan_transport, nchan_transport_old; + int16_t nSCE_old, nCPE_old, nchan_hp20_old; + AUDIO_CONFIG intern_config_old; + int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses, numCldfbSyntheses_old; + int16_t sba_dirac_stereo_flag_old; + int32_t ivas_total_brate, last_ivas_total_brate; + ivas_error error; - /* save old mem_hp_20 pointer */ - old_mem_hp20_out = st_ivas->mem_hp20_out; - st_ivas->mem_hp20_out = NULL; - if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( n * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } + error = IVAS_ERR_OK; - for ( i = 0; i < n_old; i++ ) - { - st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i]; - old_mem_hp20_out[i] = NULL; - } - for ( ; i < nchan_transport; i++ ) - { - if ( ( st_ivas->mem_hp20_out[i] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; - set_f( st_ivas->mem_hp20_out[i], 0.0f, L_HP20_MEM ); - } + /*-----------------------------------------------------------------* + * Allocate, initalize, and configure SBA and rendering handles + *-----------------------------------------------------------------*/ - count_free( old_mem_hp20_out ); - old_mem_hp20_out = NULL; - } - else if ( nchan_transport < nchan_transport_old ) - { - /* remove superfluous hp20 memories */ - float **old_mem_hp20_out; + ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); + numCldfbAnalyses = 0; - if ( st_ivas->sba_dirac_stereo_flag ) - { - n = CPE_CHANNELS; - } - else - { - n = st_ivas->nchan_transport; - } + nchan_hp20_old = getNumChanSynthesis( st_ivas ); - /* save old mem_hp_20 pointer */ - old_mem_hp20_out = st_ivas->mem_hp20_out; - st_ivas->mem_hp20_out = NULL; - if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( n * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } + nSCE_old = st_ivas->nSCE; + nCPE_old = st_ivas->nCPE; + nchan_transport_old = st_ivas->nchan_transport; + sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; + + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); + + ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); + + st_ivas->nchan_transport = nchan_transport; + + /* renderer might have changed */ + intern_config_old = st_ivas->intern_config; + ivas_renderer_select( st_ivas ); + + /* side effect of the renderer selection can be a changed internal config */ + if ( st_ivas->intern_config != intern_config_old ) + { + ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); + } - for ( i = 0; i < n; i++ ) + if ( st_ivas->sba_mode != SBA_MODE_SPAR ) + { + st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + int16_t sba_order_internal; + + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + ivas_spar_config( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); + + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && ( last_ivas_total_brate > IVAS_SID_5k2 || nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) + { + if ( st_ivas->hDirAC != NULL ) + { + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) { - st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i]; - old_mem_hp20_out[i] = NULL; + return error; } - for ( ; i < nchan_transport_old; i++ ) + } + else + { + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) { - count_free( old_mem_hp20_out[i] ); - old_mem_hp20_out[i] = NULL; + return error; } + } + } + else if ( st_ivas->renderer_type == RENDERER_DISABLE || ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->sba_mode != SBA_MODE_SPAR ) ) + { + if ( st_ivas->hDirAC != NULL ) + { + ivas_dirac_dec_close( st_ivas->hDirAC ); + st_ivas->hDirAC = NULL; + } - count_free( old_mem_hp20_out ); - old_mem_hp20_out = NULL; + if ( st_ivas->hVBAPdata != NULL ) + { + vbap_free_data( &( st_ivas->hVBAPdata ) ); } } -#endif + + /*-----------------------------------------------------------------* + * Allocate, initalize, and configure SCE/CPE/MCT handles + *-----------------------------------------------------------------*/ + + ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old ); + + /*-----------------------------------------------------------------* + * HP20 memories + *-----------------------------------------------------------------*/ + + ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ); /*-----------------------------------------------------------------* * CLDFB instances @@ -477,49 +717,6 @@ ivas_error ivas_sba_dec_reconfigure( } } -#ifndef CORECODER_BITRATE_SWITCHING - /*-----------------------------------------------------------------* - * Set CNA/CNG flags - *-----------------------------------------------------------------*/ - - if ( st_ivas->sba_mode == SBA_MODE_SPAR && st_ivas->nchan_transport == 1 ) - { - /* skip as done in init function */ - } - else if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) - { - st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; - st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1; - } - else if ( st_ivas->nchan_transport == 2 ) - { - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0; - st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1; - } - } - else - { - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) - { - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cna_dirac_flag = 0; - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 0; - } - } - } - - /* special case, if the decoder goes from 1TC DTX to 2TC active frame (in case the bitstream started with an SBA SID frame), allocate DTX memories */ - if ( last_ivas_total_brate <= IVAS_SID_5k2 && st_ivas->nCPE >= 1 ) - { - if ( ( error = initMdctStereoDtxData( st_ivas->hCPE[0] ) ) != IVAS_ERR_OK ) - { - return error; - } - } -#endif /*-------------------------------------------------------------------* * Reallocate and initialize binaural rendering handles diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index eea34b31dc..d196cda9b6 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -89,12 +89,7 @@ ivas_error ivas_spar_dec_open( } /* MD handle */ - if ( ( error = ivas_spar_md_dec_open( &hSpar->hMdDec, st_ivas->hDecoderConfig, num_channels_internal -#ifdef SBA_HOA_HBR_IMPROV - , - sba_order_internal -#endif - ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_md_dec_open( &hSpar->hMdDec, st_ivas->hDecoderConfig, num_channels_internal, sba_order_internal ) ) != IVAS_ERR_OK ) { return error; } @@ -649,13 +644,11 @@ static void ivas_spar_dec_MD( { ivas_parse_spar_header( hDecoderConfig->ivas_total_brate, sba_order, st0, &table_idx ); -#ifdef SBA_HOA_HBR_IMPROV if ( hSpar->hMdDec->spar_hoa_md_flag ) { hSpar->hMdDec->spar_md.num_bands = IVAS_MAX_NUM_BANDS; } else -#endif { hSpar->hMdDec->spar_md.num_bands = min( SPAR_DIRAC_SPLIT_START_BAND, IVAS_MAX_NUM_BANDS ); } @@ -665,7 +658,7 @@ static void ivas_spar_dec_MD( hSpar->hMdDec->table_idx = table_idx; hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[table_idx].td_ducking; - ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, num_channels ); + ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, num_channels, sba_order ); } } @@ -801,11 +794,7 @@ void ivas_spar_get_parameters( weight = ivas_spar_get_cldfb_slot_gain( hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms ); -#ifdef SBA_HOA_HBR_IMPROV split_band = hSpar->hMdDec->spar_md.num_bands; -#else - split_band = SPAR_DIRAC_SPLIT_START_BAND; -#endif for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) { @@ -1022,20 +1011,17 @@ void ivas_spar_dec_upmixer( { mvr2r( pPcm_tmp[hSpar->hTdDecorr->num_apd_outputs - 1 - i], output[nchan_internal - 1 - i], output_frame ); } - - hSpar->hFbMixer->fb_cfg->num_in_chans = num_in_ingest; - } - else - { - hSpar->hFbMixer->fb_cfg->num_in_chans = num_in_ingest; } + hSpar->hFbMixer->fb_cfg->num_in_chans = num_in_ingest; + + /*---------------------------------------------------------------------* * Prepare CLDFB buffers *---------------------------------------------------------------------*/ /* set-up pointers */ - if ( st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) + if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) { /* at this point, output channels are used as intermediate procesing buffers */ for ( in_ch = 0; in_ch < MAX_OUTPUT_CHANNELS; in_ch++ ) @@ -1076,7 +1062,7 @@ void ivas_spar_dec_upmixer( /* determine if we can skip certain data */ ivas_spar_get_skip_mat( hSpar, numch_out, numch_in, num_spar_bands, b_skip_mat ); /* this can be precomputed based on bitrate and format*/ - numch_out_dirac = st_ivas->hDecoderConfig->nchan_out; + numch_out_dirac = hDecoderConfig->nchan_out; for ( int16_t i_sf = 0; i_sf < MAX_PARAM_SPATIAL_SUBFRAMES; i_sf++ ) { @@ -1097,7 +1083,7 @@ void ivas_spar_dec_upmixer( for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { /* determine SPAR parameters for this time slots */ - ivas_spar_get_parameters( hSpar, st_ivas->hDecoderConfig, ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES, numch_out, numch_in, num_spar_bands, mixer_mat ); + ivas_spar_get_parameters( hSpar, hDecoderConfig, ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES, numch_out, numch_in, num_spar_bands, mixer_mat ); for ( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ ) { @@ -1146,7 +1132,11 @@ void ivas_spar_dec_upmixer( } } - if ( st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) + if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA +#ifdef SPAR_STEREO_NO_DIRAC + && hDecoderConfig->output_config != AUDIO_CONFIG_STEREO && hDecoderConfig->output_config != AUDIO_CONFIG_MONO +#endif + ) { ivas_dirac_dec( st_ivas, output, nchan_internal, cldfb_in_ts_re, cldfb_in_ts_im, i_sf ); } @@ -1171,8 +1161,7 @@ void ivas_spar_dec_upmixer( } else { - if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA || - !( st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL || st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL_ROOM ) ) + if ( hDecoderConfig->output_config == AUDIO_CONFIG_FOA || !( st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL || st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL_ROOM ) ) { for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 3d5f03b208..0feda3a83c 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -82,7 +82,9 @@ static void ivas_spar_md_fill_invalid_bands( ivas_spar_dec_matrices_t *pSpar_coe static ivas_error ivas_spar_set_dec_config( ivas_spar_md_dec_state_t *hMdDec, const int16_t nchan_transport, float *pFC ); static void ivas_parse_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, Decoder_State *st, const int16_t bw, const int16_t num_bands, int16_t *num_dmx_per_band, int16_t *num_dec_per_band ); + static ivas_error ivas_deindex_real_index( const int16_t *index, const int16_t q_levels, const float min_value, const float max_value, float *quant, const int16_t num_ch_dim2 ); + static void ivas_spar_dec_parse_md_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, int16_t *nB, int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, const int16_t use_planar_coeff, const int16_t sba_inactive_mode ); @@ -249,11 +251,8 @@ static ivas_error ivas_spar_md_dec_matrix_open( ivas_error ivas_spar_md_dec_open( ivas_spar_md_dec_state_t **hMdDec_out, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t num_channels /* i : number of internal channels */ -#ifdef SBA_HOA_HBR_IMPROV - , - const int16_t sba_order /* i : SBA order */ -#endif + const int16_t num_channels, /* i : number of internal channels */ + const int16_t sba_order /* i : SBA order */ ) { ivas_spar_md_dec_state_t *hMdDec; @@ -271,12 +270,9 @@ ivas_error ivas_spar_md_dec_open( return error; } -#ifdef SBA_HOA_HBR_IMPROV - hMdDec->spar_hoa_md_flag = ivas_sba_get_spar_hoa_md_flag( sba_order, hDecoderConfig->ivas_total_brate ); -#endif hMdDec->table_idx = 0; /* just to initialize state variables*/ - if ( ( error = ivas_spar_md_dec_init( hMdDec, hDecoderConfig, num_channels ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_md_dec_init( hMdDec, hDecoderConfig, num_channels, sba_order ) ) != IVAS_ERR_OK ) { return error; } @@ -437,28 +433,18 @@ void ivas_spar_md_dec_close( ivas_error ivas_spar_md_dec_init( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t num_channels /* i : number of internal channels */ + const int16_t num_channels, /* i : number of internal channels */ + const int16_t sba_order /* i : SBA order */ ) { int16_t i, j, k; int16_t nchan_transport; float pFC[IVAS_MAX_NUM_BANDS], PR_minmax[2]; - hMdDec->spar_md_cfg.gen_bs = 1; // VE2DB : always 1 - can it be removed? - -#ifdef SBA_HOA_HBR_IMPROV + hMdDec->spar_hoa_md_flag = ivas_sba_get_spar_hoa_md_flag( sba_order, hDecoderConfig->ivas_total_brate ); hMdDec->spar_md.num_bands = ( hMdDec->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); -#else - hMdDec->spar_md.num_bands = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); -#endif - ivas_spar_set_bitrate_config( &hMdDec->spar_md_cfg, hMdDec->table_idx, -#ifdef SBA_HOA_HBR_IMPROV - hMdDec->spar_md.num_bands -#else - min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ) -#endif - ); + ivas_spar_set_bitrate_config( &hMdDec->spar_md_cfg, hMdDec->table_idx, hMdDec->spar_md.num_bands ); nchan_transport = hMdDec->spar_md_cfg.nchan_transport; @@ -641,7 +627,7 @@ void ivas_spar_md_dec_process( char f_name[100]; int16_t num_bands = nB; int16_t num_subframes = 1, num_block_groups = 1, num_elements = 1, byte_size = sizeof( float ); - int16_t num_ch = 2 * sba_order + 2; + int16_t num_ch = ivas_sba_get_nchan_metadata( sba_order ); for ( b = 0; b < num_bands; b++ ) { sprintf( f_name, "spar_band_pred_coeffs_dec.bin" ); @@ -684,33 +670,20 @@ void ivas_spar_md_dec_process( } #endif -#ifndef SBA_SPAR_HARM - /* SPAR to DirAC and DirAC to SPAR conversion */ // VE2DB: -> "DirAC to SPAR conversion" only? - if ( st_ivas->sba_mode == SBA_MODE_SPAR ) // VE2DB: this looks obsolete - { -#else /* SPAR to DirAC conversion */ -#endif - ivas_spar_to_dirac( st_ivas, hMdDec, dtx_vad, num_bands_out ); + ivas_spar_to_dirac( st_ivas, hMdDec, dtx_vad, num_bands_out ); - /* set correct number of bands*/ - nB = IVAS_MAX_NUM_BANDS; - if ( bw == IVAS_RED_BAND_FACT ) - { - nB = nB >> 1; - } -#ifndef SBA_SPAR_HARM + /* set correct number of bands*/ + nB = IVAS_MAX_NUM_BANDS; + if ( bw == IVAS_RED_BAND_FACT ) + { + nB = nB >> 1; } -#endif /* expand DirAC MD to all time slots */ for ( i_ts = 1; i_ts < MAX_PARAM_SPATIAL_SUBFRAMES; i_ts++ ) { -#ifdef SBA_HOA_HBR_IMPROV for ( b = 0; b < hMdDec->spar_md.num_bands; b++ ) -#else - for ( b = 0; b < min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); b++ ) -#endif { for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { @@ -1371,7 +1344,6 @@ void ivas_spar_dec_gen_umx_mat( ) { int16_t i, j, b, i_ts, num_out_ch; - int16_t fb_ducking_flag = 0; // VE2DB: always 0 - can it be removed? num_out_ch = hMdDec->spar_md_cfg.num_umx_chs; @@ -1400,11 +1372,6 @@ void ivas_spar_dec_gen_umx_mat( } } } - - if ( fb_ducking_flag ) - { - assert( 0 ); /* fb_ducking_flag not supported */ - } } else { @@ -1419,7 +1386,7 @@ void ivas_spar_dec_gen_umx_mat( } } } - + #ifdef DEBUG_SBA_MD_DUMP { static FILE *f_mat = 0; @@ -1464,226 +1431,220 @@ static void ivas_spar_dec_parse_md_bs( const int16_t sba_inactive_mode ) { int16_t i, j, k, num_bands; + int16_t ii, jj, ndec, ndm, b, idx; uint16_t qsi; ivas_quant_strat_t qs; int16_t strat, freq_diff, no_ec; int16_t do_diff[IVAS_MAX_NUM_BANDS]; - int16_t planarCP = 0; + int16_t planarCP; + float quant[IVAS_SPAR_MAX_C_COEFF]; *dtx_vad = 1; *bands_bw = 1; qsi = 0; num_bands = hMdDec->spar_md.num_bands; - if ( hMdDec->spar_md_cfg.gen_bs == 1 ) + if ( ivas_total_brate > IVAS_SID_5k2 ) { - if ( ivas_total_brate > IVAS_SID_5k2 ) + if ( hMdDec->spar_md_cfg.quant_strat_bits > 0 ) { - if ( hMdDec->spar_md_cfg.quant_strat_bits > 0 ) + if ( ivas_total_brate >= BRATE_SPAR_Q_STRAT ) { - if ( ivas_total_brate >= BRATE_SPAR_Q_STRAT ) - { - /*only one bit written for quantization strategy to indicate either a fixed quantization strategy or dtx_vad==0 */ - qsi = get_next_indice( st0, 1 ); - if ( qsi == 1 ) - { - *dtx_vad = 0; - } - } - else + /*only one bit written for quantization strategy to indicate either a fixed quantization strategy or dtx_vad==0 */ + qsi = get_next_indice( st0, 1 ); + if ( qsi == 1 ) { - if ( sba_inactive_mode == 1 ) - { - *dtx_vad = 0; - qsi = hMdDec->spar_md_cfg.quant_strat_bits + 1; - } - else - { - qsi = get_next_indice( st0, hMdDec->spar_md_cfg.quant_strat_bits ); - } + *dtx_vad = 0; } } else { - qsi = 0; + if ( sba_inactive_mode == 1 ) + { + *dtx_vad = 0; + qsi = hMdDec->spar_md_cfg.quant_strat_bits + 1; + } + else + { + qsi = get_next_indice( st0, hMdDec->spar_md_cfg.quant_strat_bits ); + } } } else { - *dtx_vad = 0; + qsi = 0; } + } + else + { + *dtx_vad = 0; + } - hMdDec->dtx_vad = *dtx_vad; + hMdDec->dtx_vad = *dtx_vad; - if ( *dtx_vad == 0 ) - { - *nB = SPAR_DTX_BANDS; - *bands_bw = num_bands / *nB; + if ( *dtx_vad == 0 ) + { + *nB = SPAR_DTX_BANDS; + *bands_bw = num_bands / *nB; - for ( i = 0; i < *nB; i++ ) + for ( i = 0; i < *nB; i++ ) + { + for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) - { - hMdDec->spar_md.band_coeffs[i].pred_re[j] = 0; - hMdDec->spar_md.band_coeffs[i].P_re[j] = 0; - } - hMdDec->valid_bands[i] = 1; + hMdDec->spar_md.band_coeffs[i].pred_re[j] = 0; + hMdDec->spar_md.band_coeffs[i].P_re[j] = 0; } - for ( i = 0; i < num_bands; i++ ) + hMdDec->valid_bands[i] = 1; + } + + for ( i = 0; i < num_bands; i++ ) + { + for ( j = 0; j < ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ); j++ ) { - for ( j = 0; j < ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ); j++ ) + for ( k = 0; k < ( IVAS_SPAR_MAX_DMX_CHS - 1 ); k++ ) { - for ( k = 0; k < ( IVAS_SPAR_MAX_DMX_CHS - 1 ); k++ ) - { - hMdDec->spar_md.band_coeffs[i].C_re[j][k] = 0; - } + hMdDec->spar_md.band_coeffs[i].C_re[j][k] = 0; } } + } + + ivas_parse_parameter_bitstream_dtx( &hMdDec->spar_md, st0, *bands_bw, *nB, hMdDec->spar_md_cfg.num_dmx_chans_per_band, hMdDec->spar_md_cfg.num_decorr_per_band ); - ivas_parse_parameter_bitstream_dtx( &hMdDec->spar_md, st0, *bands_bw, *nB, - hMdDec->spar_md_cfg.num_dmx_chans_per_band, hMdDec->spar_md_cfg.num_decorr_per_band ); + for ( i = *nB - 1; i >= 0; i-- ) + { + ndec = hMdDec->spar_md_cfg.num_decorr_per_band[( *bands_bw ) * i]; + + for ( b = *bands_bw - 1; b >= 0; b-- ) { - int16_t ndec, b, idx; - for ( i = *nB - 1; i >= 0; i-- ) + idx = i * *bands_bw + b; + for ( j = 0; j < FOA_CHANNELS - 1; j++ ) { - ndec = hMdDec->spar_md_cfg.num_decorr_per_band[( *bands_bw ) * i]; - - for ( b = *bands_bw - 1; b >= 0; b-- ) - { - idx = i * *bands_bw + b; - for ( j = 0; j < FOA_CHANNELS - 1; j++ ) - { - hMdDec->spar_md.band_coeffs[idx].pred_re[j] = hMdDec->spar_md.band_coeffs[i].pred_re[j]; - } - for ( j = 0; j < ndec; j++ ) - { - hMdDec->spar_md.band_coeffs[idx].P_re[j] = hMdDec->spar_md.band_coeffs[i].P_re[j]; - } - hMdDec->valid_bands[idx] = 1; - } + hMdDec->spar_md.band_coeffs[idx].pred_re[j] = hMdDec->spar_md.band_coeffs[i].pred_re[j]; } - *nB = num_bands; - *bands_bw = 1; + for ( j = 0; j < ndec; j++ ) + { + hMdDec->spar_md.band_coeffs[idx].P_re[j] = hMdDec->spar_md.band_coeffs[i].P_re[j]; + } + hMdDec->valid_bands[idx] = 1; } - - return; } - qs = hMdDec->spar_md_cfg.quant_strat[qsi]; - if ( ( qsi == 2 ) && ( use_planar_coeff ) ) - { - planarCP = 1; + *nB = num_bands; + *bands_bw = 1; + + return; + } + + qs = hMdDec->spar_md_cfg.quant_strat[qsi]; + + planarCP = 0; + if ( ( qsi == 2 ) && ( use_planar_coeff ) ) + { + planarCP = 1; #ifdef SPAR_HOA_DBG - fprintf( stdout, "planarCP = 1\n" ); + fprintf( stdout, "planarCP = 1\n" ); #endif - } - strat = get_next_indice( st0, 3 ); + } + strat = get_next_indice( st0, 3 ); + #ifdef SPAR_HOA_DBG - /*fprintf(stdout, "\n\n no_ec = %d, strat = %d\n", no_ec, strat);*/ + /*fprintf(stdout, "\n\n no_ec = %d, strat = %d\n", no_ec, strat);*/ #endif - freq_diff = 0; - no_ec = 0; + freq_diff = 0; + no_ec = 0; - if ( strat < 2 ) + if ( strat < 2 ) + { + *bands_bw = strat + 1; + *nB = num_bands / *bands_bw; + for ( i = 0; i < *nB; i++ ) { - *bands_bw = strat + 1; - *nB = num_bands / *bands_bw; - for ( i = 0; i < *nB; i++ ) - { - do_diff[i] = 0; - } + do_diff[i] = 0; } - else if ( strat < 4 ) + } + else if ( strat < 4 ) + { + *bands_bw = strat - 1; + *nB = num_bands / *bands_bw; + for ( i = 0; i < *nB; i++ ) { - *bands_bw = strat - 1; - *nB = num_bands / *bands_bw; - for ( i = 0; i < *nB; i++ ) - { - do_diff[i] = 0; - } - no_ec = 1; + do_diff[i] = 0; } - else - { - *bands_bw = 1; - *nB = num_bands; - - for ( i = 0; i < *nB; i++ ) - { - do_diff[i] = ( ( ( i + 1 ) & 3 ) != strat - 4 ); - } + no_ec = 1; + } + else + { + *bands_bw = 1; + *nB = num_bands; - ivas_map_prior_coeffs_quant( &hMdDec->spar_md_prev, &hMdDec->spar_md_cfg, qsi, *nB ); + for ( i = 0; i < *nB; i++ ) + { + do_diff[i] = ( ( ( i + 1 ) & 3 ) != strat - 4 ); } + + ivas_map_prior_coeffs_quant( &hMdDec->spar_md_prev, &hMdDec->spar_md_cfg, qsi, *nB ); + } #ifdef SPAR_HOA_DBG - fprintf( stdout, "\n\n no_ec = %d, strat = %d\n", no_ec, strat ); + fprintf( stdout, "\n\n no_ec = %d, strat = %d\n", no_ec, strat ); #endif - hMdDec->spar_md_cfg.prev_quant_idx = qsi; + hMdDec->spar_md_cfg.prev_quant_idx = qsi; - if ( no_ec == 0 ) - { - ivas_decode_arith_bs( hMdDec, st0, qsi, *nB, *bands_bw, do_diff, freq_diff, planarCP ); - } - else - { - ivas_decode_huffman_bs( hMdDec, st0, qsi, *nB, *bands_bw, planarCP ); - } + if ( no_ec == 0 ) + { + ivas_decode_arith_bs( hMdDec, st0, qsi, *nB, *bands_bw, do_diff, freq_diff, planarCP ); + } + else + { + ivas_decode_huffman_bs( hMdDec, st0, qsi, *nB, *bands_bw, planarCP ); + } - for ( i = 0; i < *nB; i++ ) - { - int16_t ii, jj; - int16_t ndec = hMdDec->spar_md_cfg.num_decorr_per_band[( *bands_bw ) * i]; - int16_t ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[( *bands_bw ) * i]; - float quant[IVAS_SPAR_MAX_C_COEFF]; - ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].pred_index_re, qs.PR.q_levels[0], qs.PR.min, qs.PR.max, hMdDec->spar_md.band_coeffs[i].pred_re, ndm + ndec - 1 ); + for ( i = 0; i < *nB; i++ ) + { + ndec = hMdDec->spar_md_cfg.num_decorr_per_band[( *bands_bw ) * i]; + ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[( *bands_bw ) * i]; - j = 0; - for ( ii = 0; ii < ndec; ii++ ) - { - for ( jj = 0; jj < ndm - 1; jj++ ) - { - quant[j] = hMdDec->spar_md.band_coeffs[i].C_re[ii][jj]; - j++; - } - } - ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].drct_index_re, qs.C.q_levels[0], qs.C.min, qs.C.max, quant, ndec * ( ndm - 1 ) ); - j = 0; - for ( ii = 0; ii < ndec; ii++ ) - { - for ( jj = 0; jj < ndm - 1; jj++ ) - { - hMdDec->spar_md.band_coeffs[i].C_re[ii][jj] = quant[j]; - j++; - } - } - ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].decd_index_re, qs.P_r.q_levels[0], qs.P_r.min, qs.P_r.max, hMdDec->spar_md.band_coeffs[i].P_re, ndm + ndec - 1 ); - /* Store prior coefficient indices */ - for ( j = 0; j < ndm + ndec - 1; j++ ) - { - hMdDec->spar_md_prev.band_coeffs_idx[i].pred_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j]; - } - for ( j = 0; j < ndec * ( ndm - 1 ); j++ ) + ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].pred_index_re, qs.PR.q_levels[0], qs.PR.min, qs.PR.max, hMdDec->spar_md.band_coeffs[i].pred_re, ndm + ndec - 1 ); + + j = 0; + for ( ii = 0; ii < ndec; ii++ ) + { + for ( jj = 0; jj < ndm - 1; jj++ ) { - hMdDec->spar_md_prev.band_coeffs_idx[i].drct_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].drct_index_re[j]; + quant[j] = hMdDec->spar_md.band_coeffs[i].C_re[ii][jj]; + j++; } - for ( j = 0; j < ndec; j++ ) + } + + ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].drct_index_re, qs.C.q_levels[0], qs.C.min, qs.C.max, quant, ndec * ( ndm - 1 ) ); + + j = 0; + for ( ii = 0; ii < ndec; ii++ ) + { + for ( jj = 0; jj < ndm - 1; jj++ ) { - hMdDec->spar_md_prev.band_coeffs_idx[i].decd_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].decd_index_re[j]; + hMdDec->spar_md.band_coeffs[i].C_re[ii][jj] = quant[j]; + j++; } - hMdDec->valid_bands[i] |= ( do_diff[i] == 0 ) ? 1 : 0; } - } - else - { - *dtx_vad = hMdDec->spar_md.dtx_vad; - *nB = num_bands; - *bands_bw = num_bands / *nB; - for ( i = 0; i < *nB; i++ ) + ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].decd_index_re, qs.P_r.q_levels[0], qs.P_r.min, qs.P_r.max, hMdDec->spar_md.band_coeffs[i].P_re, ndm + ndec - 1 ); + + /* Store prior coefficient indices */ + for ( j = 0; j < ndm + ndec - 1; j++ ) { - hMdDec->valid_bands[i] = 1; + hMdDec->spar_md_prev.band_coeffs_idx[i].pred_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j]; + } + for ( j = 0; j < ndec * ( ndm - 1 ); j++ ) + { + hMdDec->spar_md_prev.band_coeffs_idx[i].drct_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].drct_index_re[j]; + } + for ( j = 0; j < ndec; j++ ) + { + hMdDec->spar_md_prev.band_coeffs_idx[i].decd_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].decd_index_re[j]; } + hMdDec->valid_bands[i] |= ( do_diff[i] == 0 ) ? 1 : 0; } + #ifdef SPAR_HOA_DBG int16_t b; b = 0; @@ -1776,14 +1737,14 @@ static void ivas_decode_arith_bs( const int16_t freq_diff, const int16_t planarCP ) { - int16_t i, ndm, ndec; + int16_t i, j, ndm, ndec; ivas_cell_dim_t pred_cell_dims[IVAS_MAX_NUM_BANDS]; ivas_cell_dim_t drct_cell_dims[IVAS_MAX_NUM_BANDS]; ivas_cell_dim_t decd_cell_dims[IVAS_MAX_NUM_BANDS]; ivas_cell_dim_t decx_cell_dims[IVAS_MAX_NUM_BANDS]; int16_t symbol_arr_re[IVAS_MAX_INPUT_LEN]; int16_t symbol_arr_old_re[IVAS_MAX_INPUT_LEN]; - int16_t any_diff = 0; + int16_t any_diff; for ( i = 0; i < nB; i++ ) { @@ -1791,7 +1752,6 @@ static void ivas_decode_arith_bs( ndec = hMdDec->spar_md_cfg.num_decorr_per_band[bands_bw * i]; pred_cell_dims[i].dim1 = ndm + ndec - 1; -#ifdef SBA_HOA_HBR_IMPROV if ( hMdDec->spar_hoa_md_flag ) { if ( i >= SPAR_DIRAC_SPLIT_START_BAND ) @@ -1799,7 +1759,6 @@ static void ivas_decode_arith_bs( pred_cell_dims[i].dim1 -= ( FOA_CHANNELS - 1 ); } } -#endif pred_cell_dims[i].dim2 = 1; drct_cell_dims[i].dim1 = ndec; drct_cell_dims[i].dim2 = ndm - 1; @@ -1809,6 +1768,7 @@ static void ivas_decode_arith_bs( decx_cell_dims[i].dim2 = 1; } + any_diff = 0; for ( i = 0; i < nB; i++ ) { if ( pDo_diff[i] != 0 ) @@ -1820,10 +1780,8 @@ static void ivas_decode_arith_bs( if ( any_diff == 1 ) { -#ifdef SBA_HOA_HBR_IMPROV if ( hMdDec->spar_hoa_md_flag ) { - int16_t j; for ( i = 0; i < nB; i++ ) { if ( i >= SPAR_DIRAC_SPLIT_START_BAND ) @@ -1836,7 +1794,6 @@ static void ivas_decode_arith_bs( } } } -#endif ivas_copy_band_coeffs_idx_to_arr( hMdDec->spar_md_prev.band_coeffs_idx_mapped, nB, symbol_arr_old_re, pred_cell_dims, PRED_COEFF, planarCP ); } @@ -1845,10 +1802,8 @@ static void ivas_decode_arith_bs( ivas_fill_band_coeffs_idx( hMdDec->spar_md.band_coeffs_idx, nB, symbol_arr_re, pred_cell_dims, PRED_COEFF, planarCP ); -#ifdef SBA_HOA_HBR_IMPROV if ( hMdDec->spar_hoa_md_flag ) { - int16_t j; for ( i = 0; i < nB; i++ ) { if ( i >= SPAR_DIRAC_SPLIT_START_BAND ) @@ -1865,7 +1820,6 @@ static void ivas_decode_arith_bs( } } } -#endif if ( any_diff == 1 ) { @@ -2102,12 +2056,11 @@ static void ivas_decode_huffman_bs( const int16_t planarCP ) { int16_t i, j; + int16_t ndm, ndec; + int16_t pred_dim, drct_dim, decd_dim, pred_offset; for ( i = 0; i < nB; i++ ) { - int16_t ndm, ndec; - int16_t pred_dim, drct_dim, decd_dim, pred_offset; - ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[bands_bw * i]; ndec = hMdDec->spar_md_cfg.num_decorr_per_band[bands_bw * i]; @@ -2115,7 +2068,6 @@ static void ivas_decode_huffman_bs( drct_dim = ndec * ( ndm - 1 ); decd_dim = ndec; pred_offset = 0; -#ifdef SBA_HOA_HBR_IMPROV if ( hMdDec->spar_hoa_md_flag ) { if ( i >= SPAR_DIRAC_SPLIT_START_BAND ) @@ -2123,15 +2075,12 @@ static void ivas_decode_huffman_bs( pred_offset = FOA_CHANNELS - 1; } } -#endif for ( j = pred_offset; j < pred_dim; j++ ) { - ivas_huffman_decode( &hMdDec->huff_coeffs.pred_huff_re[qsi], st0, - &hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j] ); + ivas_huffman_decode( &hMdDec->huff_coeffs.pred_huff_re[qsi], st0, &hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j] ); } -#ifdef SBA_HOA_HBR_IMPROV if ( hMdDec->spar_hoa_md_flag ) { if ( i >= SPAR_DIRAC_SPLIT_START_BAND ) @@ -2142,7 +2091,6 @@ static void ivas_decode_huffman_bs( } } } -#endif for ( j = 0; j < drct_dim; j++ ) { @@ -2152,8 +2100,7 @@ static void ivas_decode_huffman_bs( } else { - ivas_huffman_decode( &hMdDec->huff_coeffs.drct_huff_re[qsi], st0, - &hMdDec->spar_md.band_coeffs_idx[i].drct_index_re[j] ); + ivas_huffman_decode( &hMdDec->huff_coeffs.drct_huff_re[qsi], st0, &hMdDec->spar_md.band_coeffs_idx[i].drct_index_re[j] ); } } @@ -2165,8 +2112,7 @@ static void ivas_decode_huffman_bs( } else { - ivas_huffman_decode( &hMdDec->huff_coeffs.decd_huff_re[qsi], st0, - &hMdDec->spar_md.band_coeffs_idx[i].decd_index_re[j] ); + ivas_huffman_decode( &hMdDec->huff_coeffs.decd_huff_re[qsi], st0, &hMdDec->spar_md.band_coeffs_idx[i].decd_index_re[j] ); } } } @@ -2390,6 +2336,7 @@ static void ivas_spar_unquant_dtx_indicies( pr_min_max[0] = pSpar_md->min_max[0]; pr_min_max[1] = pSpar_md->min_max[1]; + for ( b = 0; b < nB; b++ ) { for ( i = 0; i < FOA_CHANNELS - 1; i++ ) @@ -2427,7 +2374,7 @@ static void ivas_parse_parameter_bitstream_dtx( int16_t *num_dmx_per_band, int16_t *num_dec_per_band ) { - int16_t i, j; + int16_t i, j, ndec, ndm; float val; int16_t idx; float pr_min_max[2]; @@ -2440,8 +2387,8 @@ static void ivas_parse_parameter_bitstream_dtx( for ( i = 0; i < num_bands; i++ ) { - int16_t ndec = num_dec_per_band[bw * i]; - int16_t ndm = num_dmx_per_band[bw * i]; + ndec = num_dec_per_band[bw * i]; + ndm = num_dmx_per_band[bw * i]; for ( j = 0; j < FOA_CHANNELS - 1; j++ ) { @@ -2794,14 +2741,7 @@ void ivas_spar_to_dirac( /* DirAC MD averaged over 4 subframes and converted to SPAR format similar to encoder processing */ if ( hMdDec->spar_md_cfg.nchan_transport > 1 ) { - ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, 1, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, - end_band, num_bands_out, -#ifdef SBA_HOA_HBR_IMPROV - ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, -#else - sba_order_internal, -#endif - dtx_vad, NULL ); + ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, 1, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL ); /* temporarily copy frame-wise prediction coefficients in DirAC bands*/ for ( pred_idx = 0; pred_idx < FOA_CHANNELS - 1; pred_idx++ ) @@ -2813,14 +2753,7 @@ void ivas_spar_to_dirac( } } - ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, MAX_PARAM_SPATIAL_SUBFRAMES, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, - end_band, num_bands_out, -#ifdef SBA_HOA_HBR_IMPROV - ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, -#else - sba_order_internal, -#endif - dtx_vad, NULL ); + ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, MAX_PARAM_SPATIAL_SUBFRAMES, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL ); /* expand DirAC TC 20ms MD for residual channels to all subframes*/ for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 75af2658d3..50369fab6d 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -41,7 +41,7 @@ #include "ivas_stat_com.h" #include "ivas_stat_rend.h" #ifdef EXT_RENDERER -#include "common_api_types.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 @@ -807,9 +807,7 @@ typedef struct ivas_spar_md_dec_state_t ivas_huff_coeffs_t huff_coeffs; int16_t table_idx; int16_t dtx_vad; -#ifdef SBA_HOA_HBR_IMPROV int16_t spar_hoa_md_flag; -#endif } ivas_spar_md_dec_state_t; @@ -876,7 +874,7 @@ typedef struct ivas_spar_dec_lib_t int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; int16_t enc_param_start_band; int32_t core_nominal_brate; /* Nominal bitrate for core coding */ - int32_t i_subframe; + int16_t i_subframe; #ifdef DEBUG_SBA_AUDIO_DUMP int16_t numOutChannels; @@ -986,7 +984,7 @@ typedef struct mct_dec_data_structure /*----------------------------------------------------------------------------------* * EFAP structures *----------------------------------------------------------------------------------*/ - +// VE2AT: move to ivas_rom_rend.h ? typedef struct EFAP_VERTEX { float azi; /* azimuth of the loudspeaker */ @@ -1049,7 +1047,7 @@ typedef struct EFAP /*----------------------------------------------------------------------------------* * VBAP structures *----------------------------------------------------------------------------------*/ - +// VE2AT: move to ivas_rom_rend.h ? enum SpeakerNodeGroup { SPEAKER_NODE_BOTTOM_HALF, @@ -1107,7 +1105,7 @@ typedef struct vbap_data_structure /*----------------------------------------------------------------------------------* * renderer structures *----------------------------------------------------------------------------------*/ - +// VE2AT: move to ivas_rom_rend.h ? typedef struct renderer_struct { float prev_gains[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; @@ -1174,7 +1172,7 @@ typedef struct ivas_masa_decoder_struct /*----------------------------------------------------------------------------------* * Binaural Rendering structure *----------------------------------------------------------------------------------*/ - +// VE2AT: move to ivas_rom_rend.h ? /* Binaural reverberator structure */ typedef struct ivas_binaural_reverb_struct { @@ -1293,7 +1291,7 @@ typedef struct ivas_binaural_rendering_struct /*----------------------------------------------------------------------------------* * Head tracking data structure *----------------------------------------------------------------------------------*/ - +// VE2AT: move to ivas_rom_rend.h ? #ifndef EXT_RENDERER /* Quaternion type for head orientation */ typedef struct Quaternion_struct @@ -1326,7 +1324,7 @@ typedef struct ivas_binaural_head_track_struct /*----------------------------------------------------------------------------------* * TD ISm Object Renderer structure *----------------------------------------------------------------------------------*/ - +// VE2AT: move to ivas_rom_rend.h ? typedef struct { SFX_OpMode_t OpMode; /* Operating mode. This effect can only be TRANSIENT or OFF. */ @@ -1634,7 +1632,7 @@ typedef struct ivas_binaural_td_rendering_struct /*------------------------------------------------------------------------------------------* * Crend structures *------------------------------------------------------------------------------------------*/ - +// VE2AT: move to ivas_rom_rend.h ? typedef struct ivas_hrtfs_structure { float *pOut_to_bin_re[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS]; @@ -1656,6 +1654,7 @@ typedef struct ivas_hrtfs_structure /* Reverberator structures */ + typedef struct ivas_roomAcoustics_t { int16_t override; diff --git a/lib_dec/ivas_stereo_mdct_core_dec.c b/lib_dec/ivas_stereo_mdct_core_dec.c index 82ad3fc95b..d0d05f1fa0 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec.c +++ b/lib_dec/ivas_stereo_mdct_core_dec.c @@ -340,11 +340,7 @@ void stereo_mdct_core_dec( #ifdef DEBUGGING assert( ( sts[0]->core == sts[1]->core ) || ( ( hCPE->hStereoMdct->mdct_stereo_mode[0] == SMDCT_DUAL_MONO ) && ( hCPE->hStereoMdct->mdct_stereo_mode[1] == SMDCT_DUAL_MONO ) ) ); #endif -#ifdef FIX_TCX10_STEREO_PROC stereo_decoder_tcx( hCPE->hStereoMdct, ms_mask, x_0[1], x[0], x[1], &hCPE->hStereoMdct->mdct_stereo_mode[0], sts[0]->core, sts[1]->core, sts[0]->igf, L_frameTCX[0], L_frameTCX[1], 0, sts[0]->last_core, sts[1]->last_core, 0 ); -#else - stereo_decoder_tcx( hCPE->hStereoMdct, ms_mask, x_0[1], x[0], x[1], &hCPE->hStereoMdct->mdct_stereo_mode[0], sts[0]->core, sts[1]->core, sts[0]->igf, L_frameTCX[0], 0, sts[0]->last_core, sts[1]->last_core, 0 ); -#endif } ivas_mdct_core_tns_ns( hCPE, 0, fUseTns, tnsData, x, Aq, 0 ); diff --git a/lib_dec/ivas_stereo_mdct_stereo_dec.c b/lib_dec/ivas_stereo_mdct_stereo_dec.c index 1bdbb5eda7..67b893a9f2 100644 --- a/lib_dec/ivas_stereo_mdct_stereo_dec.c +++ b/lib_dec/ivas_stereo_mdct_stereo_dec.c @@ -214,12 +214,8 @@ void stereo_decoder_tcx( const int16_t core_l, /* i : core for left channel (TCX20/TCX10) */ const int16_t core_r, /* i : core for right channel (TCX20/TCX10) */ const int16_t igf, /* i : flag for IGF activity */ -#ifdef FIX_TCX10_STEREO_PROC const int16_t L_frameTCX_l, /* i : TCX frame length of left channel */ const int16_t L_frameTCX_r, /* i : TCX frame length of right channel */ -#else - const int16_t L_frame, /* i : TCX frame length */ -#endif const int16_t mct_on, /* i : flag mct block (1) or stereo (0) */ const int16_t last_core_l, /* i : last core for left channel */ const int16_t last_core_r, /* i : last core for right channel */ @@ -333,19 +329,11 @@ void stereo_decoder_tcx( if ( ( nrgRatio > 1.0f ) && ( k < ( ( core_r == TCX_20_CORE ) ? 1 : NB_DIV ) ) ) { -#ifdef FIX_TCX10_STEREO_PROC v_multc( spec_r[k], nrgRatio, spec_r[k], L_frameTCX_r ); -#else - v_multc( spec_r[k], nrgRatio, spec_r[k], L_frame / ( ( core_r == TCX_20_CORE ) ? 1 : NB_DIV ) ); -#endif } else if ( ( nrgRatio < 1.0f ) && ( k < ( ( core_l == TCX_20_CORE ) ? 1 : NB_DIV ) ) ) { -#ifdef FIX_TCX10_STEREO_PROC v_multc( spec_l[k], 1.0f / nrgRatio, spec_l[k], L_frameTCX_l ); -#else - v_multc( spec_l[k], 1.0f / nrgRatio, spec_l[k], L_frame / ( ( core_l == TCX_20_CORE ) ? 1 : NB_DIV ) ); -#endif } } } /* for k */ diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index 41196b6b02..8e56ed5ef7 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -51,7 +51,14 @@ * Local prototypes *-------------------------------------------------------------*/ +#ifdef FIX_TCX_DEC_RECONF_BFI +static void dec_prm_tcx( Decoder_State *st, int16_t param[], int16_t param_lpc[], int16_t *total_nbbits, const int16_t last_element_mode, int16_t *bitsRead ); +#else static void dec_prm_tcx( Decoder_State *st, int16_t param[], int16_t param_lpc[], int16_t *total_nbbits, int16_t *bitsRead ); +#endif +#ifdef FIX_TCX_DEC_RECONF_BFI +static void stereo_tcx_dec_mode_switch_reconf( Decoder_State *st, const int16_t MCT_flag, const int16_t last_element_mode ); +#endif /*-------------------------------------------------------------* @@ -66,7 +73,9 @@ void stereo_tcx_init_dec( const int16_t last_element_mode /* i : element mode of previous frame */ ) { +#ifndef FIX_TCX_DEC_RECONF_BFI int16_t frame_size_index; +#endif TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; TCX_DEC_HANDLE hTcxDec = st->hTcxDec; @@ -125,9 +134,19 @@ void stereo_tcx_init_dec( } } +#ifdef FIX_TCX_DEC_RECONF_BFI + if ( ( st->bits_frame_nominal != st->last_bits_frame_nominal ) || + ( st->bwidth != st->last_bwidth ) || + ( st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE && !( st->prev_bfi == 1 && st->last_core == ACELP_CORE && st->last_con_tcx == 1 ) ) || + ( st->idchan == 1 && st->element_mode == IVAS_CPE_MDCT && last_element_mode != IVAS_CPE_MDCT ) ) +#else if ( ( st->bits_frame_nominal != st->last_bits_frame_nominal ) || ( st->bwidth != st->last_bwidth ) || ( st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE && !( st->prev_bfi == 1 && st->last_core == ACELP_CORE && st->last_con_tcx == 1 ) ) || ( st->idchan == 1 && st->element_mode == IVAS_CPE_MDCT && last_element_mode != IVAS_CPE_MDCT ) ) +#endif { /*re-initialization*/ +#ifdef FIX_TCX_DEC_RECONF_BFI + stereo_tcx_dec_mode_switch_reconf( st, MCT_flag, last_element_mode ); +#else st->rate_switching_init = 1; /* Identify frame type - TCX Reconfiguration */ @@ -151,6 +170,7 @@ void stereo_tcx_init_dec( /* Reconfigure Core */ mode_switch_decoder_LPD( st, st->bwidth, st->bits_frame_nominal * FRAMES_PER_SEC, st->last_bits_frame_nominal * FRAMES_PER_SEC, frame_size_index, MCT_flag, last_element_mode ); +#endif } return; @@ -284,7 +304,11 @@ void stereo_tcx_core_dec( tcx_current_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode; #endif +#ifdef FIX_TCX_DEC_RECONF_BFI + dec_prm_tcx( st, param, param_lpc, &total_nbbits, last_element_mode, &bitsRead ); +#else dec_prm_tcx( st, param, param_lpc, &total_nbbits, &bitsRead ); +#endif #ifdef FIX_IVAS_337 /*IVAS-337 consider BER */ if ( !st->rate_switching_init && st->BER_detect ) @@ -808,6 +832,9 @@ static void dec_prm_tcx( int16_t param[], /* o : decoded parameters */ int16_t param_lpc[], /* o : LPC parameters */ int16_t *total_nbbits, /* i/o: number of bits / decoded bits */ +#ifdef FIX_TCX_DEC_RECONF_BFI + const int16_t last_element_mode, +#endif int16_t *bitsRead /* o : number of read bits */ ) { @@ -861,6 +888,14 @@ static void dec_prm_tcx( st->prev_bfi = 1; } +#ifdef FIX_TCX_DEC_RECONF_BFI + /* possible need for reconfiguration can only be decided correctly once last_core_from_bs has been decoded */ + if ( ( st->last_core != st->last_core_from_bs ) && ( st->last_core_from_bs != TCX_20_CORE && st->last_core_from_bs != TCX_10_CORE && !( st->prev_bfi == 1 && st->last_core_from_bs == ACELP_CORE && st->last_con_tcx == 1 ) ) ) + { + stereo_tcx_dec_mode_switch_reconf( st, 0, last_element_mode ); + } +#endif + st->last_core = st->last_core_from_bs; /*for TCX 10 force last_core to be TCX since ACELP as previous core is forbidden*/ @@ -923,3 +958,38 @@ static void dec_prm_tcx( return; } + +#ifdef FIX_TCX_DEC_RECONF_BFI +static void stereo_tcx_dec_mode_switch_reconf( + Decoder_State *st, + const int16_t MCT_flag, + const int16_t last_element_mode +) +{ + int16_t frame_size_index; + + st->rate_switching_init = 1; + + /* Identify frame type - TCX Reconfiguration */ + for ( frame_size_index = 0; frame_size_index < FRAME_SIZE_NB; frame_size_index++ ) + { + if ( frame_size_index < FRAME_SIZE_NB - 1 ) + { + if ( ( FrameSizeConfig[frame_size_index].frame_bits <= st->bits_frame_nominal ) && ( FrameSizeConfig[frame_size_index + 1].frame_bits > st->bits_frame_nominal ) ) + { + break; + } + } + else + { + if ( FrameSizeConfig[frame_size_index].frame_bits <= st->bits_frame_nominal ) + { + break; + } + } + } + + /* Reconfigure Core */ + mode_switch_decoder_LPD( st, st->bwidth, st->bits_frame_nominal * FRAMES_PER_SEC, st->last_bits_frame_nominal * FRAMES_PER_SEC, frame_size_index, MCT_flag, last_element_mode ); +} +#endif diff --git a/lib_dec/ivas_vbap.c b/lib_dec/ivas_vbap.c index 2534854e8b..f0960bd127 100644 --- a/lib_dec/ivas_vbap.c +++ b/lib_dec/ivas_vbap.c @@ -29,7 +29,7 @@ the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ - +// VE2AT: move to lib_rend ? #include #include "options.h" #include diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index c63a2e064e..d16d1f2494 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1767,7 +1767,7 @@ static ivas_error printConfigInfo_dec( else if ( st_ivas->ivas_format == SBA_FORMAT ) { #ifdef PRINT_SBA_ORDER - fprintf( stdout, "Input configuration: Scene Based Analysis, Ambisonic order %i%s, %d transport channel(s)\n", st_ivas->sba_order, st_ivas->sba_planar ? " (Planar)" : "", st_ivas->nchan_transport ); + fprintf( stdout, "Input configuration: Scene Based Audio, Ambisonic order %i%s, %d transport channel(s)\n", st_ivas->sba_order, st_ivas->sba_planar ? " (Planar)" : "", st_ivas->nchan_transport ); #else fprintf( stdout, "Input configuration: SBA - %d transport channel(s) %s\n", st_ivas->nchan_transport, st_ivas->sba_planar ? "(Planar)" : "" ); #endif diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index 6050354a8f..e355cd2083 100755 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -462,7 +462,7 @@ static void IGF_CalculateEnvelope( float diffSFM; float shiftedSFM = 0.f; - tmp_tb = IGF_getSFM_new( pPowerSpectrum, hPrivateData->logSpec, swb_offset[sfb], swb_offset[sfb + 1] ) / IGF_getCrest_new( hPrivateData->logSpec, swb_offset[sfb], swb_offset[sfb + 1] ); + tmp_tb = IGF_getSFM_new( pPowerSpectrum, hPrivateData->logSpec, swb_offset[sfb], swb_offset[sfb + 1] ) / IGF_getCrest_new( hPrivateData->logSpec, swb_offset[sfb], swb_offset[sfb + 1] ); tmp_sb = IGF_getSFM_new( pPowerSpectrum, hPrivateData->logSpec, tmp, strt_cpy ) / IGF_getCrest_new( hPrivateData->logSpec, tmp, strt_cpy ); if ( last_core_acelp || hPrivateData->wasTransient ) @@ -494,12 +494,12 @@ static void IGF_CalculateEnvelope( if ( slope < -threshold ) { int16_t shift = width >> 1; - shiftedSFM = IGF_getSFM_new( pPowerSpectrum, hPrivateData->logSpec, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ) / IGF_getCrest_new ( hPrivateData->logSpec, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ); + shiftedSFM = IGF_getSFM_new( pPowerSpectrum, hPrivateData->logSpec, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ) / IGF_getCrest_new( hPrivateData->logSpec, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ); } else if ( ( slope > 1.f * threshold ) && ( sfb != hGrid->sfbWrap[hGrid->nTiles] - 1 ) ) { int16_t shift = width >> 1; - shiftedSFM = IGF_getSFM_new( pPowerSpectrum, hPrivateData->logSpec, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ) / IGF_getCrest_new ( hPrivateData->logSpec, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ); + shiftedSFM = IGF_getSFM_new( pPowerSpectrum, hPrivateData->logSpec, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ) / IGF_getCrest_new( hPrivateData->logSpec, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ); } if ( shiftedSFM > 0.04f ) diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 1ae2f48c66..4e4ab24369 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -785,7 +785,12 @@ ivas_error init_encoder( } initFdCngEnc( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); - configureFdCngEnc( st->hFdCngEnc, st->bwidth, st->rf_mode && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate ); + + /* initialization for IVAS modes happens in first frame pre-processing */ + if ( st->element_mode == EVS_MONO ) + { + configureFdCngEnc( st->hFdCngEnc, st->bwidth, st->rf_mode && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate ); + } } else { diff --git a/lib_enc/ivas_agc_enc.c b/lib_enc/ivas_agc_enc.c index 0f3274f43c..b7f69b38b0 100644 --- a/lib_enc/ivas_agc_enc.c +++ b/lib_enc/ivas_agc_enc.c @@ -60,24 +60,42 @@ static int16_t ivas_agc_writeBits( FILE *stream, const int16_t n_channels, ivas_ #endif #ifdef AGC_ENABLE_FOR_LBR +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION /*-----------------------------------------------------------------------------------------* - * Function ivas_agc_enc_get_enablement_flag() + * Function ivas_agc_enc_get_flag() * * This function determines if AGC should be enabled or disabled. * If agc_configuration is not undefined, then this value decides on the state of * enablement, otherwise AGC is enabled only if there is one transport channel. * *-----------------------------------------------------------------------------------------*/ +#else +/*-----------------------------------------------------------------------------------------* + * Function ivas_agc_enc_get_flag() + * + * This function determines if AGC should be enabled or disabled. + * AGC is enabled only if there is one transport channel. + * + *-----------------------------------------------------------------------------------------*/ +#endif -int16_t ivas_agc_enc_get_enablement_flag( - IVAS_ENC_AGC agc_configuration, - int16_t nchan_transport ) +/*! r: AGC enable flag */ +int16_t ivas_agc_enc_get_flag( +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION + int16_t agc_configuration, /* i : AGC configuration from command-line */ +#endif + int16_t nchan_transport /* i : number of transport channels */ +) { - return (int16_t) ( ( agc_configuration == IVAS_ENC_AGC_UNDEFINED ) - ? ( nchan_transport == 1 ) - : agc_configuration ); -} +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION + return (int16_t) ( ( agc_configuration == SBA_AGC_DEFAULT ) + ? ( nchan_transport == 1 ) + : agc_configuration ); +#else + return (int16_t) ( nchan_transport == 1 ); #endif +} +#endif /* AGC_ENABLE_FOR_LBR */ /*-----------------------------------------------------------------------------------------* * Function ivas_agc_enc_init() @@ -127,6 +145,7 @@ static void ivas_agc_enc_init( return; } + /*------------------------------------------------------------------------- * ivas_spar_agc_enc_open() * @@ -140,7 +159,11 @@ ivas_error ivas_spar_agc_enc_open( ) { ivas_agc_enc_state_t *hAgc; +#ifdef FIX_AGC_WINFUNC_MEMORY + int16_t input_frame, delay; +#else int16_t input_frame; +#endif if ( ( hAgc = (ivas_agc_enc_state_t *) count_malloc( sizeof( ivas_agc_enc_state_t ) ) ) == NULL ) { @@ -148,8 +171,15 @@ ivas_error ivas_spar_agc_enc_open( } input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); +#ifdef FIX_AGC_WINFUNC_MEMORY + delay = NS2SA( input_Fs, ( IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ) ); +#endif +#ifdef FIX_AGC_WINFUNC_MEMORY + if ( ( hAgc->agc_com.winFunc = (float *) count_malloc( sizeof( float ) * ( input_frame - delay ) ) ) == NULL ) +#else if ( ( hAgc->agc_com.winFunc = (float *) count_malloc( sizeof( float ) * input_frame ) ) == NULL ) +#endif { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR AGC encoder" ); } @@ -164,13 +194,18 @@ ivas_error ivas_spar_agc_enc_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR AGC encoder" ); } +#ifdef FIX_AGC_WINFUNC_MEMORY + ivas_agc_enc_init( hAgc, input_frame, nchan_inp, delay ); +#else ivas_agc_enc_init( hAgc, input_frame, nchan_inp, NS2SA( input_Fs, ( IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ) ) ); +#endif *hAgcEnc = hAgc; return IVAS_ERR_OK; } + /*------------------------------------------------------------------------- * ivas_spar_agc_enc_close() * @@ -203,6 +238,7 @@ void ivas_spar_agc_enc_close( return; } + /*-----------------------------------------------------------------------------------------* * Function ivas_agc_enc_process() * diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 597f1d5854..b863944b57 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -79,10 +79,8 @@ ivas_error ivas_core_enc( float enerBuffer[CPE_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */ float fft_buff[CPE_CHANNELS][2 * L_FFT], /* i : FFT buffer */ const int16_t tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel */ -#ifdef CORECODER_BITRATE_SWITCHING - const int16_t ivas_format, /* i : IVAS format */ -#endif - const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ + const int16_t ivas_format, /* i : IVAS format */ + const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ ) { int16_t n, input_frame; @@ -104,11 +102,7 @@ ivas_error ivas_core_enc( int16_t unbits[CPE_CHANNELS]; float tdm_lspQ_PCh[M], tdm_lsfQ_PCh[M]; int16_t last_element_mode, tdm_Pitch_reuse_flag; -#ifdef CORECODER_BITRATE_SWITCHING int32_t element_brate, last_element_brate, input_Fs; -#else - int32_t element_brate, input_Fs; -#endif ivas_error error; wmops_sub_start( "ivas_core_enc" ); @@ -127,9 +121,7 @@ ivas_error ivas_core_enc( hStereoTD = NULL; hStereoICBWE = NULL; element_brate = hSCE->element_brate; -#ifdef CORECODER_BITRATE_SWITCHING last_element_brate = hSCE->last_element_brate; -#endif last_element_mode = IVAS_SCE; tdm_Pitch_reuse_flag = -1; } @@ -144,9 +136,7 @@ ivas_error ivas_core_enc( sts = hCPE->hCoreCoder; hStereoICBWE = hCPE->hStereoICBWE; element_brate = hCPE->element_brate; -#ifdef CORECODER_BITRATE_SWITCHING last_element_brate = hCPE->last_element_brate; -#endif last_element_mode = hCPE->last_element_mode; if ( hCPE->hStereoTD != NULL ) @@ -187,11 +177,7 @@ ivas_error ivas_core_enc( * Pre-processing, incl. Decision matrix *---------------------------------------------------------------------*/ -#ifdef CORECODER_BITRATE_SWITCHING if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, ivas_format == SBA_FORMAT ? last_element_brate : element_brate, input_frame, old_inp_12k8[n], old_inp_16k[n], &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], cor_map_sum[n], vad_flag_dtx[n], enerBuffer[n], fft_buff[n], MCT_flag, vad_hover_flag[n], flag_16k_smc ) ) != IVAS_ERR_OK ) -#else - if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, input_frame, old_inp_12k8[n], old_inp_16k[n], &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], cor_map_sum[n], vad_flag_dtx[n], enerBuffer[n], fft_buff[n], MCT_flag, vad_hover_flag[n], flag_16k_smc ) ) != IVAS_ERR_OK ) -#endif { return error; } diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index 3cc206e65e..acbacc09e0 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -52,12 +52,10 @@ *--------------------------------------------------------------------*/ ivas_error pre_proc_ivas( - Encoder_State *st, /* i/o: encoder state structure */ - const int16_t last_element_mode, /* i : last element mode */ - const int32_t element_brate, /* i : element bitrate */ -#ifdef CORECODER_BITRATE_SWITCHING - const int32_t last_element_brate, /* i : last element bitrate */ -#endif + Encoder_State *st, /* i/o: encoder state structure */ + const int16_t last_element_mode, /* i : last element mode */ + const int32_t element_brate, /* i : element bitrate */ + const int32_t last_element_brate, /* i : last element bitrate */ const int16_t input_frame, /* i : frame length */ float old_inp_12k8[], /* i/o: buffer of old input signal */ float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ @@ -278,12 +276,10 @@ ivas_error pre_proc_ivas( { st->hTcxEnc->tfm_mem = 0.75f; } -#ifdef CORECODER_BITRATE_SWITCHING else if ( element_brate != last_element_brate ) { SetModeIndex( st, st->bits_frame_nominal * FRAMES_PER_SEC, element_mode, MCT_flag ); } -#endif /*-----------------------------------------------------------------* diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 51a549505f..b4336bdf62 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -553,7 +553,7 @@ ivas_error pre_proc_front_ivas( * Adjust FD-CNG Noise Estimator *----------------------------------------------------------------*/ - if ( st->hFdCngEnc != NULL && ( last_element_brate != element_brate || st->last_bwidth != st->bwidth ) ) + if ( st->hFdCngEnc != NULL && ( st->ini_frame == 0 || last_element_brate != element_brate || st->last_bwidth != st->bwidth ) ) { configureFdCngEnc( st->hFdCngEnc, max( st->input_bwidth, WB ), st->bits_frame_nominal * FRAMES_PER_SEC ); if ( hCPE != NULL ) diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index f4b302eefd..dffd53bb93 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -43,7 +43,6 @@ #include "wmops.h" -#ifdef CORECODER_BITRATE_SWITCHING /*-------------------------------------------------------------------* * ivas_corecoder_enc_reconfig() * @@ -393,4 +392,3 @@ ivas_error ivas_corecoder_enc_reconfig( return error; } -#endif diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 491a9ab358..e047defac6 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -612,11 +612,7 @@ ivas_error ivas_cpe_enc( * Core Encoder *----------------------------------------------------------------*/ -#ifdef CORECODER_BITRATE_SWITCHING if ( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8, old_inp_16k, Etot, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, tdm_SM_or_LRTD_Pri, ivas_format, 0 ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8, old_inp_16k, Etot, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, tdm_SM_or_LRTD_Pri, 0 ) ) != IVAS_ERR_OK ) -#endif { return error; } diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 6d281256d9..96a005a0b3 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -334,12 +334,8 @@ void ivas_dirac_enc( set_zero( data_f[2], input_frame ); } - ivas_dirac_param_est_enc( hDirAC, &( hQMetaData->q_direction[0] ), hQMetaData->useLowerRes, data_f, NULL, NULL, input_frame -#ifdef SBA_HOA_HBR_IMPROV - , - SBA_MODE_DIRAC -#endif - ); + ivas_dirac_param_est_enc( hDirAC, &( hQMetaData->q_direction[0] ), hQMetaData->useLowerRes, data_f, NULL, NULL, input_frame, + SBA_MODE_DIRAC ); /* encode parameters */ if ( sba_planar || hQMetaData->useLowerRes ) { @@ -457,7 +453,6 @@ void ivas_dirac_enc_spar_delay_synchro( { int16_t ch_idx; float tmp_buffer[L_FRAME48k]; -#ifdef CORECODER_BITRATE_SWITCHING Encoder_State *sts[MCT_MAX_BLOCKS]; int16_t sce_id, cpe_id, i_chan; @@ -487,7 +482,6 @@ void ivas_dirac_enc_spar_delay_synchro( mvr2r( sts[ch_idx]->input, st_ivas->hDirAC->sba_synchro_buffer[ch_idx], st_ivas->hDirAC->num_samples_synchro_delay ); } } -#endif for ( ch_idx = 0; ch_idx < DIRAC_MAX_ANA_CHANS; ch_idx++ ) { @@ -514,18 +508,14 @@ void computeReferencePower_enc( float *reference_power, /* o : Estimated power */ const int16_t enc_param_start_band, /* i : first band to process */ const int16_t num_freq_bands /* i : Number of frequency bands */ -#ifdef SBA_HOA_HBR_IMPROV , const SBA_MODE sba_mode /* i : SBA mode */ -#endif ) { int16_t brange[2]; int16_t ch_idx, i, j; -#ifdef SBA_HOA_HBR_IMPROV float reference_power_W[DIRAC_MAX_NBANDS]; -#endif for ( i = 0; i < num_freq_bands; i++ ) { @@ -533,19 +523,13 @@ void computeReferencePower_enc( brange[1] = band_grouping[i + enc_param_start_band + 1]; reference_power[i] = 0; -#ifdef SBA_HOA_HBR_IMPROV reference_power_W[i] = 0; for ( j = brange[0]; j < brange[1]; j++ ) { reference_power_W[i] += ( Cldfb_RealBuffer[0][j] * Cldfb_RealBuffer[0][j] ) + ( Cldfb_ImagBuffer[0][j] * Cldfb_ImagBuffer[0][j] ); } reference_power[i] += reference_power_W[i]; -#endif -#ifdef SBA_HOA_HBR_IMPROV for ( ch_idx = 1; ch_idx < DIRAC_MAX_ANA_CHANS; ch_idx++ ) -#else - for ( ch_idx = 0; ch_idx < DIRAC_MAX_ANA_CHANS; ch_idx++ ) -#endif { /* abs()^2 */ for ( j = brange[0]; j < brange[1]; j++ ) @@ -556,7 +540,6 @@ void computeReferencePower_enc( } v_multc( reference_power, 0.5f, reference_power, num_freq_bands ); -#ifdef SBA_HOA_HBR_IMPROV if ( sba_mode == SBA_MODE_SPAR ) { for ( i = 0; i < num_freq_bands; i++ ) @@ -564,7 +547,6 @@ void computeReferencePower_enc( reference_power[i] = max( reference_power[i], reference_power_W[i] ); } } -#endif return; } @@ -583,12 +565,8 @@ void ivas_dirac_param_est_enc( float data_f[][L_FRAME48k], float **pp_fr_real, float **pp_fr_imag, - const int16_t input_frame -#ifdef SBA_HOA_HBR_IMPROV - , - const SBA_MODE sba_mode -#endif -) + const int16_t input_frame, + const SBA_MODE sba_mode ) { int16_t i, d, ts, index, l_ts, num_freq_bands; int16_t band_m_idx, block_m_idx; @@ -686,12 +664,8 @@ void ivas_dirac_param_est_enc( Cldfb_ImagBuffer, reference_power[ts], hDirAC->hConfig->enc_param_start_band, - num_freq_bands -#ifdef SBA_HOA_HBR_IMPROV - , - sba_mode -#endif - ); + num_freq_bands, + sba_mode ); computeIntensityVector_enc( hDirAC, diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 75ffc5212d..7be1f11c49 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -65,7 +65,9 @@ ivas_error ivas_enc( float data_f[MAX_INPUT_CHANNELS][L_FRAME48k]; /* IVAS_fmToDo: buffer can be allocated dynamically based on the number of analysed channels */ int32_t ivas_total_brate; ivas_error error; - +#ifdef SBA_BR_SWITCHING + int16_t sba_reinit_flag; +#endif error = IVAS_ERR_OK; wmops_sub_start( "ivas_enc" ); @@ -85,6 +87,20 @@ ivas_error ivas_enc( n_samples_chan = n_samples / nchan_inp; set_s( nb_bits_metadata, 0, MAX_SCE ); +#ifdef SBA_BR_SWITCHING + sba_reinit_flag = 0; + if ( ivas_format == SBA_FORMAT ) + { + sba_reinit_flag = get_sba_reinit_flag( ivas_total_brate, st_ivas->hEncoderConfig->last_ivas_total_brate ); + if ( sba_reinit_flag ) + { + if ( ( error = ivas_sba_enc_reinit( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } +#endif /*----------------------------------------------------------------* * convert 'short' input data to 'float' @@ -189,7 +205,11 @@ ivas_error ivas_enc( /* SBA/MASA configuration */ if ( ivas_format == SBA_FORMAT ) { +#ifndef SBA_BR_SWITCHING if ( st_ivas->sba_mode == SBA_MODE_DIRAC ) +#else + if ( ( st_ivas->sba_mode == SBA_MODE_DIRAC ) && ( !sba_reinit_flag ) ) +#endif { if ( ( error = ivas_sba_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) { diff --git a/lib_enc/ivas_enc_cov_handler.c b/lib_enc/ivas_enc_cov_handler.c index 907b8c5908..933c2c5de9 100644 --- a/lib_enc/ivas_enc_cov_handler.c +++ b/lib_enc/ivas_enc_cov_handler.c @@ -141,44 +141,23 @@ void ivas_spar_covar_enc_close( void ivas_enc_cov_handler_process( ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ -#ifdef SBA_SPAR_HARM float **ppIn_FR_real, float **ppIn_FR_imag, float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], -#else - ivas_enc_cov_handler_in_buf_t *pIn_buf, - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], -#endif ivas_filterbank_t *pFb, /* i/o: FB handle */ const int16_t start_band, - const int16_t end_band -#ifdef SBA_SPAR_HARM - , + const int16_t end_band, const int16_t num_ch, const int16_t dtx_vad, - const int16_t transient_det -#endif -) + const int16_t transient_det ) { int16_t i, j; -#ifdef SBA_SPAR_HARM int16_t dtx_cov_flag; dtx_cov_flag = ( dtx_vad == 1 ) ? 0 : 1; -#else - ivas_cov_smooth_in_buf_t pCov_in_buf; - int16_t num_ch = pIn_buf->num_ch; - - pCov_in_buf.num_ch = num_ch; -#endif -#ifdef SBA_SPAR_HARM ivas_band_cov( ppIn_FR_real, ppIn_FR_imag, num_ch, hCovEnc->num_bins, -#else - ivas_band_cov( pIn_buf->ppIn_FR_real, pIn_buf->ppIn_FR_imag, pIn_buf->num_ch, hCovEnc->num_bins, -#endif pFb->fb_bin_to_band.short_stride, pFb->fb_bin_to_band.pp_short_stride_bin_to_band, pFb->fb_bin_to_band.p_short_stride_start_bin_per_band, @@ -213,36 +192,20 @@ void ivas_enc_cov_handler_process( { for ( j = 0; j < num_ch; j++ ) { -#ifndef SBA_SPAR_HARM - pCov_in_buf.cov_real[i][j] = cov_real[i][j]; -#endif mvr2r( cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); } } -#ifdef SBA_SPAR_HARM ivas_cov_smooth_process( hCovEnc->pCov_state, cov_real, pFb, start_band, end_band, num_ch, transient_det ); -#else - ivas_cov_smooth_process( hCovEnc->pCov_state, &pCov_in_buf, pFb, start_band, end_band ); -#endif -#ifdef SBA_SPAR_HARM if ( dtx_cov_flag == 0 ) -#else - if ( pIn_buf->dtx_cov_flag == 0 ) -#endif { for ( i = 0; i < num_ch; i++ ) { for ( j = 0; j < num_ch; j++ ) { -#ifdef SBA_SPAR_HARM mvr2r( cov_real[i][j], hCovEnc->pCov_dtx_state->pPrior_cov_real[i][j], pFb->filterbank_num_bands ); mvr2r( cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); -#else - mvr2r( pCov_in_buf.cov_real[i][j], hCovEnc->pCov_dtx_state->pPrior_cov_real[i][j], pFb->filterbank_num_bands ); - mvr2r( pCov_in_buf.cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); -#endif } } @@ -250,46 +213,16 @@ void ivas_enc_cov_handler_process( } else { -#ifdef SBA_SPAR_HARM if ( transient_det == 0 ) -#else - if ( pIn_buf->transient_det == 0 ) -#endif { -#ifdef SBA_SPAR_HARM ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, cov_dtx_real, pFb, start_band, end_band, num_ch, transient_det ); -#else - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - pCov_in_buf.cov_real[i][j] = cov_dtx_real[i][j]; - } - } - - pCov_in_buf.reset_cov = 0; - ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, &pCov_in_buf, pFb, start_band, end_band ); -#endif hCovEnc->prior_dtx_present = 1; } else { if ( hCovEnc->prior_dtx_present == 0 ) { -#ifdef SBA_SPAR_HARM ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, cov_dtx_real, pFb, start_band, end_band, num_ch, transient_det ); -#else - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - pCov_in_buf.cov_real[i][j] = cov_dtx_real[i][j]; - } - } - - pCov_in_buf.reset_cov = 1; - ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, &pCov_in_buf, pFb, start_band, end_band ); -#endif hCovEnc->prior_dtx_present = 1; } else diff --git a/lib_enc/ivas_entropy_coder.c b/lib_enc/ivas_entropy_coder.c index 7f5ab7b996..a3714821f3 100644 --- a/lib_enc/ivas_entropy_coder.c +++ b/lib_enc/ivas_entropy_coder.c @@ -316,17 +316,13 @@ void ivas_arith_encode_cmplx_cell_array( int16_t input[IVAS_MAX_INPUT_LEN]; ivas_cell_dim_t cell_dim[IVAS_MAX_NUM_BANDS], cell_dim_diff[IVAS_MAX_NUM_BANDS]; int16_t len, idx, i, j, idx1; -#ifdef SBA_HOA_HBR_IMPROV int16_t total_len; -#endif idx1 = 0; if ( any_diff == 1 ) { idx = 0; -#ifdef SBA_HOA_HBR_IMPROV total_len = 0; -#endif for ( i = 0; i < nB; i++ ) { len = ( pCell_dims[i].dim1 * pCell_dims[i].dim2 ); @@ -334,13 +330,8 @@ void ivas_arith_encode_cmplx_cell_array( { for ( j = 0; j < len; j++ ) { -#ifdef SBA_HOA_HBR_IMPROV input_old[idx] = pSymbol_old_re[total_len + j]; input_new[idx++] = pSymbol_re[total_len + j]; -#else - input_old[idx] = pSymbol_old_re[i * len + j]; - input_new[idx++] = pSymbol_re[i * len + j]; -#endif } cell_dim_diff[i].dim1 = pCell_dims[i].dim1; cell_dim_diff[i].dim2 = pCell_dims[i].dim2; @@ -351,20 +342,14 @@ void ivas_arith_encode_cmplx_cell_array( { for ( j = 0; j < len; j++ ) { -#ifdef SBA_HOA_HBR_IMPROV input[idx1++] = pSymbol_re[total_len + j]; -#else - input[idx1++] = pSymbol_re[i * len + j]; -#endif } cell_dim_diff[i].dim1 = 0; cell_dim_diff[i].dim2 = 0; cell_dim[i].dim1 = pCell_dims[i].dim1; cell_dim[i].dim2 = pCell_dims[i].dim2; } -#ifdef SBA_HOA_HBR_IMPROV total_len += len; -#endif } #ifdef SPAR_HOA_DBG /*if ( 0 )*/ /*(pCell_dims[0].dim1 == 12)*/ diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 1d18af7761..62eeee5a02 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -396,7 +396,11 @@ ivas_error front_vad_spar( hFrontVad = hSpar->hFrontVad; st = hSpar->hCoreCoderVAD; +#ifdef FIX_SBA_DTX_DECODE_ERROR + if ( hEncoderConfig->Opt_DTX_ON && hEncoderConfig->ivas_total_brate <= SBA_DTX_BITRATE_THRESHOLD ) +#else if ( hEncoderConfig->Opt_DTX_ON && hEncoderConfig->ivas_total_brate <= IVAS_80k ) +#endif { /*------------------------------------------------------------------* * Initialization diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 8d79594c7e..18280a60e2 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -190,12 +190,10 @@ int16_t getNumChanAnalysis( { n = st_ivas->hEncoderConfig->nchan_inp; } -#ifdef FIX_155_HP20_ISSUE else if ( st_ivas->hEncoderConfig->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM ) { n = st_ivas->hEncoderConfig->nchan_inp; } -#endif return n; } diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 2122dcf874..3c8a1f04b3 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -262,11 +262,7 @@ ivas_error ivas_ism_enc( * Encoder *----------------------------------------------------------------*/ -#ifdef CORECODER_BITRATE_SWITCHING if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8[sce_id], old_inp_16k[sce_id], Etot[sce_id], ener[sce_id], A[sce_id], Aw[sce_id], epsP[sce_id], lsp_new[sce_id], lsp_mid[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer[sce_id], imagBuffer[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum[sce_id], vad_flag_dtx[sce_id], enerBuffer[sce_id], fft_buff[sce_id], 0, ISM_FORMAT, 0 ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8[sce_id], old_inp_16k[sce_id], Etot[sce_id], ener[sce_id], A[sce_id], Aw[sce_id], epsP[sce_id], lsp_new[sce_id], lsp_mid[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer[sce_id], imagBuffer[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum[sce_id], vad_flag_dtx[sce_id], enerBuffer[sce_id], fft_buff[sce_id], 0, 0 ) ) != IVAS_ERR_OK ) -#endif { return error; } diff --git a/lib_enc/ivas_ism_param_enc.c b/lib_enc/ivas_ism_param_enc.c index 3358e41e21..8dcdef30b5 100644 --- a/lib_enc/ivas_ism_param_enc.c +++ b/lib_enc/ivas_ism_param_enc.c @@ -41,11 +41,6 @@ #include "ivas_rom_com.h" #include "wmops.h" -#ifndef FIX_155_HP20_ISSUE -#ifdef CORECODER_BITRATE_SWITCHING -static ivas_error ivas_hp20_reconfig( Encoder_Struct *st_ivas, const int16_t nchan_hp20_old ); -#endif -#endif /*------------------------------------------------------------------------- * Local function definitions *------------------------------------------------------------------------*/ @@ -419,14 +414,7 @@ ivas_error ivas_ism_enc_config( { ivas_error error; ISM_MODE last_ism_mode; -#ifdef ISM_BITRATE_SWITCHING -#ifdef CORECODER_BITRATE_SWITCHING int16_t nchan_transport_old; -#else - int16_t nSCE_old, nchan_transport_old; - int16_t sce_id, n; -#endif -#endif error = IVAS_ERR_OK; last_ism_mode = st_ivas->ism_mode; @@ -434,18 +422,11 @@ ivas_error ivas_ism_enc_config( /* select ISM format mode */ st_ivas->ism_mode = ivas_ism_mode_select( st_ivas->hEncoderConfig->nchan_inp, st_ivas->hEncoderConfig->ivas_total_brate ); -#ifdef ISM_BITRATE_SWITCHING /* ISM bit-rate switching */ if ( ( st_ivas->ism_mode != last_ism_mode ) || ( st_ivas->hEncoderConfig->ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) ) { int32_t element_brate_tmp[MAX_NUM_OBJECTS]; -#ifndef CORECODER_BITRATE_SWITCHING - Indice *ind_list_sce, *ind_list_metadata; -#endif -#ifndef CORECODER_BITRATE_SWITCHING - nSCE_old = st_ivas->nSCE; -#endif nchan_transport_old = st_ivas->nchan_transport; /* Reset and Initialize */ @@ -463,60 +444,7 @@ ivas_error ivas_ism_enc_config( ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hEncoderConfig->nchan_inp, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ); -#ifdef CORECODER_BITRATE_SWITCHING ivas_corecoder_enc_reconfig( st_ivas, nchan_transport_old, 0, nchan_transport_old ); -#else - if ( st_ivas->nSCE > nSCE_old ) - { - /* Reconfigure the core coders */ - for ( sce_id = 0; sce_id < nSCE_old; sce_id++ ) - { - copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); - st_ivas->hSCE[sce_id]->element_brate = st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport; - st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - } - - /* Initialize the extra required memory */ - ind_list_sce = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list; - ind_list_metadata = st_ivas->hSCE[0]->hMetaData->ind_list; - - for ( sce_id = nSCE_old; sce_id < st_ivas->nSCE; sce_id++ ) - { - /* Initialize the Core Coder */ - if ( ( error = create_sce_enc( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) - { - return error; - } - - /* prepare bitstream buffers */ - st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list_sce + ( sce_id * MAX_NUM_INDICES ); - reset_indices_enc( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, MAX_NUM_INDICES ); - - st_ivas->hSCE[sce_id]->hMetaData->ind_list = ind_list_metadata + ( sce_id * MAX_BITS_METADATA ); - reset_indices_enc( st_ivas->hSCE[sce_id]->hMetaData, MAX_BITS_METADATA ); - } - } - else - { - /* Reconfigure the Core Coders */ - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) - { - copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); - st_ivas->hSCE[sce_id]->element_brate = st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport; - st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - } - - /* Delete the extra memory */ - for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ ) - { - if ( st_ivas->hSCE[sce_id] != NULL ) - { - destroy_sce_enc( st_ivas->hSCE[sce_id] ); - st_ivas->hSCE[sce_id] = NULL; - } - } - } -#endif if ( st_ivas->ism_mode == ISM_MODE_PARAM && last_ism_mode == ISM_MODE_DISC ) { @@ -533,147 +461,7 @@ ivas_error ivas_ism_enc_config( ivas_param_ism_enc_close( st_ivas->hDirAC, st_ivas->hEncoderConfig->input_Fs ); st_ivas->hDirAC = NULL; } - -#ifndef FIX_155_HP20_ISSUE -#ifdef CORECODER_BITRATE_SWITCHING - ivas_hp20_reconfig( st_ivas, nchan_transport_old ); -#else - /* destroy the memory of hp20*/ - if ( st_ivas->mem_hp20_in != NULL ) - { - for ( sce_id = 0; sce_id < nSCE_old; sce_id++ ) - { - count_free( st_ivas->mem_hp20_in[sce_id] ); - st_ivas->mem_hp20_in[sce_id] = NULL; - } - count_free( st_ivas->mem_hp20_in ); - st_ivas->mem_hp20_in = NULL; - } - - /* re initialize the memory of hp20 */ - /* set number of input channels used for analysis/coding */ - n = getNumChanAnalysis( st_ivas ); - - if ( n > 0 ) - { - if ( ( st_ivas->mem_hp20_in = (float **) count_malloc( n * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - } - else - { - st_ivas->mem_hp20_in = NULL; - } - - for ( sce_id = 0; sce_id < n; sce_id++ ) - { - if ( ( st_ivas->mem_hp20_in[sce_id] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - set_f( st_ivas->mem_hp20_in[sce_id], 0.0f, L_HP20_MEM ); - } -#endif -#endif } -#else - /* ISM format switching */ - if ( st_ivas->ism_mode != last_ism_mode ) - { - /*ivas_ism_dec_reconfigure( st_ivas );*/ - return IVAS_ERROR( IVAS_ERR_RECONFIGURE_NOT_SUPPORTED, "Error: ISM format switching not supported yet!!!\n\n" ); - } -#endif return error; } - -#ifndef FIX_155_HP20_ISSUE -#ifdef CORECODER_BITRATE_SWITCHING -// VE: this is the same function as at the decoder -> harmonize them to a new file ivas_corecoder_reconfig.c -/*-------------------------------------------------------------------* - * ivas_hp20_dec_reconfig() - * - * Allocate, initialize, and configure HP20 memory handles in case of bitrate switching - *-------------------------------------------------------------------*/ - -static ivas_error ivas_hp20_reconfig( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const int16_t nchan_hp20_old /* i : number of HP20 filters in previous frame */ -) -{ - int16_t i, nchan_hp20; - float **old_mem_hp20_out; - ivas_error error; - - error = IVAS_ERR_OK; - - /*-----------------------------------------------------------------* - * HP20 memories - *-----------------------------------------------------------------*/ - - nchan_hp20 = getNumChanAnalysis( st_ivas ); - - if ( nchan_hp20 > nchan_hp20_old ) - { - /* save old mem_hp_20 pointer */ - old_mem_hp20_out = st_ivas->mem_hp20_in; - st_ivas->mem_hp20_in = NULL; - - if ( ( st_ivas->mem_hp20_in = (float **) count_malloc( nchan_hp20 * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - for ( i = 0; i < nchan_hp20_old; i++ ) - { - st_ivas->mem_hp20_in[i] = old_mem_hp20_out[i]; - old_mem_hp20_out[i] = NULL; - } - /* create additional hp20 memories */ - for ( ; i < nchan_hp20; i++ ) - { - if ( ( st_ivas->mem_hp20_in[i] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); - } - - count_free( old_mem_hp20_out ); - old_mem_hp20_out = NULL; - } - else if ( nchan_hp20 < nchan_hp20_old ) - { - /* save old mem_hp_20 pointer */ - old_mem_hp20_out = st_ivas->mem_hp20_in; - st_ivas->mem_hp20_in = NULL; - - if ( ( st_ivas->mem_hp20_in = (float **) count_malloc( nchan_hp20 * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - for ( i = 0; i < nchan_hp20; i++ ) - { - st_ivas->mem_hp20_in[i] = old_mem_hp20_out[i]; - old_mem_hp20_out[i] = NULL; - } - /* remove superfluous hp20 memories */ - for ( ; i < nchan_hp20_old; i++ ) - { - count_free( old_mem_hp20_out[i] ); - old_mem_hp20_out[i] = NULL; - } - - count_free( old_mem_hp20_out ); - old_mem_hp20_out = NULL; - } - - return error; -} -#endif -#endif diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index 1329e572ae..de816f3bf7 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -892,12 +892,8 @@ void ivas_mcmasa_param_est_enc( intensity_even_real ); computeReferencePower_enc( hMcMasa->band_grouping, FoaEven_RealBuffer, FoaEven_ImagBuffer, reference_power[ts], 0, - num_freq_bands -#ifdef SBA_HOA_HBR_IMPROV - , - SBA_MODE_NONE -#endif - ); + num_freq_bands, + SBA_MODE_NONE ); /* Fill buffers of length "averaging_length" time slots for intensity and energy */ hMcMasa->index_buffer_intensity = ( hMcMasa->index_buffer_intensity % hMcMasa->no_col_avg_diff ) + 1; /* averaging_length = 32 */ diff --git a/lib_enc/ivas_mct_core_enc.c b/lib_enc/ivas_mct_core_enc.c index f682a380f7..30e7022698 100644 --- a/lib_enc/ivas_mct_core_enc.c +++ b/lib_enc/ivas_mct_core_enc.c @@ -178,7 +178,6 @@ static void AdjustChannelRatios( } chBitRatios[1] += ratio_diff; -#ifdef SBA_HOA_HBR_IMPROV /* make sure final ratios are within range*/ sum_ratio = 0.0f; for ( i = 0; i < nChannels; i++ ) @@ -190,7 +189,6 @@ static void AdjustChannelRatios( cur_ratio = chBitRatios[i] / sum_ratio; chBitRatios[i] = min( BITRATE_MCT_RATIO_RANGE - 1, max( 1, (uint16_t) ( BITRATE_MCT_RATIO_RANGE * cur_ratio + 0.5f ) ) ); } -#endif return; } diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index d4c7c70b21..aca565b64d 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -93,329 +93,260 @@ void ivas_sba_getTCs( return; } - +#ifdef SBA_BR_SWITCHING /*-------------------------------------------------------------------* - * ivas_sba_enc_reconfigure() + * ivas_sba_enc_reinit() * - * Reconfigure IVAS SBA encoder + * Reinitialise IVAS SBA encoder *-------------------------------------------------------------------*/ -ivas_error ivas_sba_enc_reconfigure( +ivas_error ivas_sba_enc_reinit( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { - int16_t nSCE_old, nCPE_old, nchan_transport_old; -#ifndef CORECODER_BITRATE_SWITCHING - int16_t n, sce_id, cpe_id; + int16_t nSCE_old; + int16_t nCPE_old; + int16_t sce_id; + int16_t cpe_id; + int16_t n; Indice *ind_list_metadata; -#endif int32_t ivas_total_brate; + int16_t i, nchan_inp; ivas_error error; + ENCODER_CONFIG_HANDLE hEncoderConfig; + Indice *ind_list; + BSTR_ENC_HANDLE hBstr; + BSTR_ENC_HANDLE hMetaData; + hEncoderConfig = st_ivas->hEncoderConfig; + ivas_total_brate = hEncoderConfig->ivas_total_brate; error = IVAS_ERR_OK; - + nchan_inp = st_ivas->hEncoderConfig->nchan_inp; ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; - if ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) + nCPE_old = st_ivas->nCPE; + nSCE_old = st_ivas->nSCE; + ind_list_metadata = NULL; + + + ind_list = NULL; + hBstr = NULL; + hMetaData = NULL; + + /* get the index list pointers */ + if ( nSCE_old ) { - nchan_transport_old = st_ivas->nchan_transport; - nCPE_old = st_ivas->nCPE; - nSCE_old = st_ivas->nSCE; -#ifndef CORECODER_BITRATE_SWITCHING - ind_list_metadata = NULL; -#endif + hBstr = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr; + hMetaData = st_ivas->hSCE[0]->hMetaData; + } + else if ( nCPE_old ) + { + hBstr = st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; + hMetaData = st_ivas->hCPE[nCPE_old - 1]->hMetaData; + } - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); + /* save bitstream information */ + ind_list = hBstr->ind_list; + ind_list_metadata = hMetaData->ind_list; - ivas_dirac_enc_reconfigure( st_ivas ); + /*------------------------------------------------------------------------------------------* + * Closing Encoder handles before Reinitialisation + *------------------------------------------------------------------------------------------*/ + /* Q Metadata handle */ + ivas_qmetadata_close( &( st_ivas->hQMetaData ) ); + /* DirAC handle */ + if ( st_ivas->hDirAC != NULL ) + { + ivas_dirac_enc_close( st_ivas->hDirAC, st_ivas->hEncoderConfig->input_Fs ); -#ifdef CORECODER_BITRATE_SWITCHING - /*-----------------------------------------------------------------* - * Allocate, initalize, and configure SCE/CPE/MCT handles - *-----------------------------------------------------------------*/ + st_ivas->hDirAC = NULL; + } - ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old ); -#else + /* SPAR handle */ + if ( st_ivas->hSpar != NULL ) + { + ivas_spar_enc_close( st_ivas->hSpar, st_ivas->hEncoderConfig->input_Fs, nchan_inp ); + st_ivas->hSpar = NULL; + } + /* SCE handles */ + for ( i = 0; i < MAX_SCE; i++ ) + { + if ( st_ivas->hSCE[i] != NULL ) + { + destroy_sce_enc( st_ivas->hSCE[i] ); + st_ivas->hSCE[i] = NULL; + } + } - if ( hEncoderConfig->nchan_transport == nchan_transport_old ) + /* CPE handles */ + for ( i = 0; i < MAX_CPE; i++ ) + { + if ( st_ivas->hCPE[i] != NULL ) { - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) - { - copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); - st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; - st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - } + destroy_cpe_enc( st_ivas->hCPE[i] ); + st_ivas->hCPE[i] = NULL; + } + } + /* MCT handle */ + if ( st_ivas->hMCT != NULL ) + { + ivas_mct_enc_close( st_ivas->hMCT ); + st_ivas->hMCT = NULL; + } + if ( st_ivas->mem_hp20_in != NULL ) + { + n = getNumChanAnalysis( st_ivas ); - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) - { - st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; - /* prepare bitstream buffers */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); - - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - } - } + for ( i = 0; i < n; i++ ) + { + count_free( st_ivas->mem_hp20_in[i] ); + st_ivas->mem_hp20_in[i] = NULL; + } + count_free( st_ivas->mem_hp20_in ); + st_ivas->mem_hp20_in = NULL; + } - if ( st_ivas->nCPE > 1 ) - { - if ( ( error = mct_enc_reconfigure( st_ivas, 0 ) ) != IVAS_ERR_OK ) - { - return error; - } - } + /*------------------------------------------------------------------------------------------* + * Reopening Encoder handles for Reinitialisation + *------------------------------------------------------------------------------------------*/ + + if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); + + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) + { + if ( ( error = ivas_spar_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; } - else + } + + if ( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + if ( ( error = create_sce_enc( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) { - Indice *ind_list; - int16_t nb_bits_tot; - int16_t next_ind; - int16_t last_ind; - BSTR_ENC_HANDLE hBstr; - BSTR_ENC_HANDLE hMetaData; - - ind_list = NULL; - hBstr = NULL; - hMetaData = NULL; - - /* get the index list pointers */ - if ( nSCE_old ) - { - hBstr = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr; - hMetaData = st_ivas->hSCE[0]->hMetaData; - } - else if ( nCPE_old ) - { - hBstr = st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; - hMetaData = st_ivas->hCPE[nCPE_old - 1]->hMetaData; - } -#ifdef DEBUGGING - else - { - assert( 0 && "At least one SCE or one CPE should have existed before!\n" ); - } -#endif + return error; + } - /* save bitstream information */ - ind_list = hBstr->ind_list; - nb_bits_tot = hBstr->nb_bits_tot; - next_ind = hBstr->next_ind; - last_ind = hBstr->last_ind; - ind_list_metadata = hMetaData->ind_list; + /* prepare bitstream buffers */ + st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list + sce_id * MAX_NUM_INDICES; + reset_indices_enc( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, MAX_NUM_INDICES ); - /* destroy superfluous core coder elements */ - for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ ) - { - destroy_sce_enc( st_ivas->hSCE[sce_id] ); - st_ivas->hSCE[sce_id] = NULL; - } + st_ivas->hSCE[sce_id]->hMetaData->ind_list = ind_list_metadata + sce_id * MAX_BITS_METADATA; + reset_indices_enc( st_ivas->hSCE[sce_id]->hMetaData, MAX_BITS_METADATA ); - for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ ) - { - destroy_cpe_enc( st_ivas->hCPE[cpe_id] ); - st_ivas->hCPE[cpe_id] = NULL; - } + if ( st_ivas->sba_mode == SBA_MODE_SPAR && st_ivas->hEncoderConfig->Opt_DTX_ON ) + { + st_ivas->hSCE[sce_id]->hCoreCoder[0]->dtx_sce_sba = 1; + } + } - if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL ) - { - ivas_mct_enc_close( st_ivas->hMCT ); - st_ivas->hMCT = NULL; - } + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + { + return error; + } - /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles */ - if ( st_ivas->nCPE > 1 && nCPE_old == 1 ) - { - count_free( st_ivas->hCPE[0]->hStereoMdct ); - st_ivas->hCPE[0]->hStereoMdct = NULL; - } + /* prepare bitstream buffers */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list + ( cpe_id * CPE_CHANNELS + n ) * MAX_NUM_INDICES; + reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES ); - /* create missing core coder elements and set element bitrates for alrady existing ones */ - if ( st_ivas->nSCE > 0 ) + if ( hEncoderConfig->Opt_DTX_ON ) { - int16_t nSCE_existing; - nSCE_existing = min( nSCE_old, st_ivas->nSCE ); - for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ ) - { - copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); - st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; - st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - } - for ( sce_id = nSCE_existing; sce_id < st_ivas->nSCE; sce_id++ ) - { - if ( ( error = create_sce_enc( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) - { - return error; - } - - /* prepare bitstream buffers */ - st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list + sce_id * MAX_NUM_INDICES; - - /* only reset indices if it is not the first index list, this already contains the IVAS format bits */ - if ( sce_id > 0 ) - { - reset_indices_enc( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, MAX_NUM_INDICES ); - } - else - { - st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->last_ind = last_ind; - st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot; - st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->next_ind = next_ind; - } - - st_ivas->hSCE[sce_id]->hMetaData->ind_list = ind_list_metadata + sce_id * MAX_BITS_METADATA; - reset_indices_enc( st_ivas->hSCE[sce_id]->hMetaData, MAX_BITS_METADATA ); - } + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1; } + } - if ( st_ivas->nCPE > 0 ) - { - int16_t nCPE_existing; - nCPE_existing = min( nCPE_old, st_ivas->nCPE ); - for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) - { - st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; - - /* prepare bitstream buffers */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - } - } - - for ( cpe_id = nCPE_existing; cpe_id < st_ivas->nCPE; cpe_id++ ) - { - if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) - { - return error; - } - - /* prepare bitstream buffers */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list + ( cpe_id * CPE_CHANNELS + n ) * MAX_NUM_INDICES; - if ( cpe_id * CPE_CHANNELS + n > 0 ) - { - reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES ); - } - else - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->last_ind = last_ind; - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_bits_tot = nb_bits_tot; - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->next_ind = next_ind; - } - - if ( st_ivas->hEncoderConfig->Opt_DTX_ON ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1; - } - } - } - } + /* Metadata only initialized for the last CPE index */ + if ( cpe_id == st_ivas->nCPE - 1 ) + { + st_ivas->hCPE[cpe_id]->hMetaData->ind_list = ind_list_metadata + sce_id * MAX_BITS_METADATA; + reset_indices_enc( st_ivas->hCPE[cpe_id]->hMetaData, MAX_BITS_METADATA ); + } + } - if ( st_ivas->nCPE > 1 && nCPE_old <= 1 ) - { - if ( nCPE_old == 1 ) - { - /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; - - st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); - st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, - st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC, - st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, - st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode, - st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode ); - - if ( st_ivas->hCPE[0]->hCoreCoder[n]->igf ) - { - IGFEncSetMode( st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc, - st_ivas->hCPE[0]->element_brate, - st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, - st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, - st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ); - } - } - } - - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 ) - { - if ( ( error = mct_enc_reconfigure( st_ivas, st_ivas->nCPE != nCPE_old ) ) != IVAS_ERR_OK ) - { - return error; - } - } + if ( st_ivas->nCPE > 1 ) + { + if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + n = getNumChanAnalysis( st_ivas ); - /* metadata handling for CPEs */ - if ( st_ivas->nCPE > 0 ) - { - if ( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData == NULL ) - { - if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData = (BSTR_ENC_HANDLE) count_malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MetaData structure\n" ) ); - } - } - - st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData->ind_list = ind_list_metadata; - reset_indices_enc( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData, MAX_BITS_METADATA ); - - for ( cpe_id = 0; cpe_id < st_ivas->nCPE - 1; cpe_id++ ) - { - if ( st_ivas->hCPE[cpe_id]->hMetaData != NULL ) - { - count_free( st_ivas->hCPE[cpe_id]->hMetaData ); - st_ivas->hCPE[cpe_id]->hMetaData = NULL; - } - } - } + if ( n > 0 ) + { + if ( ( st_ivas->mem_hp20_in = (float **) count_malloc( n * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + } + else + { + st_ivas->mem_hp20_in = NULL; + } - /* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */ - if ( st_ivas->nCPE == 1 && nCPE_old > 1 ) - { - if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_ENC_DATA_HANDLE) count_malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); - } - - /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handle */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; - - st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); - st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, - st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC, - st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, - st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode, - st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode ); - - if ( st_ivas->hCPE[0]->hCoreCoder[n]->igf ) - { - IGFEncSetMode( st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc, - st_ivas->hCPE[0]->element_brate, - st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, - st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, - st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ); - } - /* reset mct_chan_mode */ - st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; - } - - initMdctStereoEncData( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct, st_ivas->hEncoderConfig->ivas_format, st_ivas->hCPE[st_ivas->nCPE - 1]->element_mode, st_ivas->hCPE[st_ivas->nCPE - 1]->element_brate, st_ivas->hEncoderConfig->max_bwidth, 0, NULL, 1 ); - st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = ( ( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); - } + for ( i = 0; i < n; i++ ) + { + if ( ( st_ivas->mem_hp20_in[i] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } + + set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); + } + return error; +} #endif +/*-------------------------------------------------------------------* + * ivas_sba_enc_reconfigure() + * + * Reconfigure IVAS SBA encoder + *-------------------------------------------------------------------*/ + +ivas_error ivas_sba_enc_reconfigure( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + int16_t nSCE_old, nCPE_old, nchan_transport_old; + int32_t ivas_total_brate; + ivas_error error; + + error = IVAS_ERR_OK; + + ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + + if ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) + { + nchan_transport_old = st_ivas->nchan_transport; + nCPE_old = st_ivas->nCPE; + nSCE_old = st_ivas->nSCE; + + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); + + ivas_dirac_enc_reconfigure( st_ivas ); + + + /*-----------------------------------------------------------------* + * Allocate, initalize, and configure SCE/CPE/MCT handles + *-----------------------------------------------------------------*/ + + ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old ); } return error; diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 2592b578f6..0b49c56854 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -166,15 +166,11 @@ ivas_error ivas_sce_enc( st->total_brate = hSCE->element_brate - nb_bits_metadata * FRAMES_PER_SEC; /* set flag for sampling rate of OL S/M classifier */ -#ifdef CORECODER_BITRATE_SWITCHING // VE2EF: TBV whether it can be done more efficiently flag_16k_smc = 0; if ( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT && ( st_ivas->hEncoderConfig->ivas_total_brate == IVAS_24k4 || st_ivas->hEncoderConfig->ivas_total_brate == IVAS_32k ) && hSCE->element_brate == hSCE->last_element_brate ) { flag_16k_smc = 1; } -#else - flag_16k_smc = ( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT && ( st_ivas->hEncoderConfig->ivas_total_brate == IVAS_24k4 || st_ivas->hEncoderConfig->ivas_total_brate == IVAS_32k ) ); -#endif #ifdef DEBUG_MODE_INFO dbgwrite( st->input - NS2SA( st->input_Fs, ACELP_LOOK_NS ), sizeof( float ), input_frame, 1, "res/input_DMX" ); @@ -241,11 +237,7 @@ ivas_error ivas_sce_enc( * Encoder *----------------------------------------------------------------*/ -#ifdef CORECODER_BITRATE_SWITCHING if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8, old_inp_16k, Etot, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, 0, ivas_format, flag_16k_smc ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8, old_inp_16k, Etot, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, 0, flag_16k_smc ) ) != IVAS_ERR_OK ) -#endif { return error; } @@ -257,9 +249,7 @@ ivas_error ivas_sce_enc( /* update input samples buffer */ mvr2r( st->input, st->old_input_signal, input_frame ); -#ifdef CORECODER_BITRATE_SWITCHING hSCE->last_element_brate = hSCE->element_brate; -#endif #ifdef DEBUG_MODE_INFO { @@ -307,9 +297,7 @@ ivas_error create_sce_enc( hSCE->sce_id = sce_id; hSCE->element_brate = element_brate; -#ifdef CORECODER_BITRATE_SWITCHING hSCE->last_element_brate = hSCE->element_brate; -#endif /*-----------------------------------------------------------------* * Metadata: allocate and initialize diff --git a/lib_enc/ivas_sns_enc.c b/lib_enc/ivas_sns_enc.c index 6790f0cf6d..45c04ac9ea 100644 --- a/lib_enc/ivas_sns_enc.c +++ b/lib_enc/ivas_sns_enc.c @@ -44,7 +44,6 @@ #include "wmops.h" - /*------------------------------------------------------------------- * sns_1st_cod() * diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index b5f00848a8..00d185fe08 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -121,13 +121,23 @@ ivas_error ivas_spar_enc_open( /* AGC handle */ #ifdef AGC_ENABLE_FOR_LBR - hSpar->AGC_Enable = ivas_agc_enc_get_enablement_flag( hEncoderConfig->Opt_AGC_ON, nchan_transport ); +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION + hSpar->AGC_Enable = ivas_agc_enc_get_flag( hEncoderConfig->Opt_AGC_ON, nchan_transport ); +#else + hSpar->AGC_Enable = ivas_agc_enc_get_flag( nchan_transport ); +#endif +#endif + +#ifdef AGC_ENABLE_FOR_LBR + hSpar->hAgcEnc = NULL; + if ( hSpar->AGC_Enable ) #endif - if ( ( error = ivas_spar_agc_enc_open( &hSpar->hAgcEnc, input_Fs, nchan_inp ) ) != IVAS_ERR_OK ) { - return error; + if ( ( error = ivas_spar_agc_enc_open( &hSpar->hAgcEnc, input_Fs, nchan_inp ) ) != IVAS_ERR_OK ) + { + return error; + } } - /* PCA handle */ hSpar->hPCA = NULL; if ( hEncoderConfig->Opt_PCA_ON ) @@ -151,11 +161,11 @@ ivas_error ivas_spar_enc_open( if ( st_ivas->nchan_transport == 1 ) { - st_ivas->hEncoderConfig->element_mode_init = IVAS_SCE; + hEncoderConfig->element_mode_init = IVAS_SCE; } else { - st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } /*-----------------------------------------------------------------* @@ -233,7 +243,6 @@ void ivas_spar_enc_close( hSpar->hFrontVad = NULL; } - num_chans = hSpar->hFbMixer->fb_cfg->num_in_chans; assert( num_chans <= nchan_inp ); @@ -288,7 +297,7 @@ ivas_error ivas_spar_enc( hEncoderConfig = st_ivas->hEncoderConfig; /* front VAD */ - if ( ( error = front_vad_spar( st_ivas->hSpar, data_f[0], st_ivas->hEncoderConfig, input_frame ) ) != IVAS_ERR_OK ) + if ( ( error = front_vad_spar( st_ivas->hSpar, data_f[0], hEncoderConfig, input_frame ) ) != IVAS_ERR_OK ) { return error; } @@ -310,8 +319,13 @@ ivas_error ivas_spar_enc( *nb_bits_metadata = hMetaData->nb_bits_tot; +#ifdef FIX_SBA_DTX_DECODE_ERROR + /* Force IVAS front pre-proc decision for higher bitrates */ + if ( hEncoderConfig->ivas_total_brate > SBA_DTX_BITRATE_THRESHOLD || hEncoderConfig->Opt_DTX_ON == 0 ) +#else /* temp hack to not force IVAS front pre-proc decision for higher bitrates */ if ( hEncoderConfig->ivas_total_brate > IVAS_64k || hEncoderConfig->Opt_DTX_ON == 0 ) +#endif { st_ivas->hSpar->front_vad_flag = 0; } @@ -319,69 +333,6 @@ ivas_error ivas_spar_enc( return error; } -#ifndef SBA_SPAR_HARM -/*-----------------------------------------------------------------------------------------* - * Function ivas_spar_enc_get_windowed_fr() - * - * Get windowed FRs - *-----------------------------------------------------------------------------------------*/ - -static void ivas_spar_enc_get_windowed_fr( - IVAS_FB_MIXER_HANDLE hFbMixer, - float *pIn_blocks[IVAS_SPAR_MAX_CH], - ivas_enc_cov_handler_in_buf_t *pCov_in_buf, - const int16_t input_frame, - const int16_t nchan_inp, - const int16_t num_past_samples ) -{ - int16_t i, j, rev_offset; - - for ( i = 0; i < nchan_inp; i++ ) - { - const int16_t stride = hFbMixer->pFb->fb_bin_to_band.short_stride; - float tmp_buf[MDFT_FB_BANDS_240 * 2]; - int16_t win_len = (int16_t) hFbMixer->ana_window_offset; - float *mdft_in_ptr = tmp_buf + stride - win_len; - float tmp_in_block[L_FRAME48k + MDFT_FB_BANDS_240]; - float *data_ptr = tmp_in_block; - float *fr_re_ptr = pCov_in_buf->ppIn_FR_real[i]; - float *fr_im_ptr = pCov_in_buf->ppIn_FR_imag[i]; - - set_f( tmp_buf, 0, MDFT_FB_BANDS_240 * 2 ); - - /* copy input data, because pIn_blocks and fr_re_ptr + fr_im_ptr use the same memory */ - mvr2r( &pIn_blocks[i][input_frame - num_past_samples], tmp_in_block, input_frame + win_len ); - - for ( int16_t blk = 0; blk < input_frame / stride; blk++ ) - { - - for ( j = 0; j < win_len; j++ ) - { - mdft_in_ptr[j] = data_ptr[j] * hFbMixer->pAna_window[j]; - } - - for ( j = win_len; j < stride; j++ ) - { - mdft_in_ptr[j] = data_ptr[j]; - } - - rev_offset = win_len - 1; - for ( j = stride; j < stride + win_len; j++ ) - { - mdft_in_ptr[j] = data_ptr[j] * hFbMixer->pAna_window[rev_offset--]; - } - - ivas_mdft( tmp_buf, fr_re_ptr, fr_im_ptr, stride << 1, stride ); - - data_ptr += stride; - fr_re_ptr += stride; - fr_im_ptr += stride; - } - } - - return; -} -#endif /*-----------------------------------------------------------------------------------------* * Function ivas_spar_enc_process() @@ -399,24 +350,11 @@ static ivas_error ivas_spar_enc_process( { float pcm_tmp[IVAS_SPAR_MAX_CH][L_FRAME48k * 2]; float *p_pcm_tmp[IVAS_SPAR_MAX_CH]; -#ifdef SBA_SPAR_HARM int16_t i, j, b, i_ts, input_frame, transient_det, dtx_vad; -#else - int16_t i, j, k, b, i_ts, input_frame, num_bands_bw; - int16_t dtx_vad, dtx_cov_flag, dtx_silence_mode; -#endif int32_t ivas_total_brate, input_Fs; -#ifndef SBA_SPAR_HARM - ivas_enc_cov_handler_in_buf_t cov_in_buf; -#endif float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; -#ifdef SBA_SPAR_HARM int16_t nchan_inp, nchan_transport, sba_order; -#else - ivas_spar_md_enc_in_buf_t md_in_buf; - int16_t nchan_inp, nchan_transport, bwidth, sba_order; -#endif int16_t table_idx; int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; ivas_error error; @@ -451,19 +389,11 @@ static ivas_error ivas_spar_enc_process( mvr2r( data_f[HOA_keep_ind[i]], data_f[i], input_frame ); } -#ifndef SBA_SPAR_HARM - table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); -#endif - /*-----------------------------------------------------------------------------------------* * Transient detector *-----------------------------------------------------------------------------------------*/ -#ifdef SBA_SPAR_HARM transient_det = ivas_transient_det_process( hSpar->hTranDet, data_f[0], input_frame ); -#else - cov_in_buf.transient_det = ivas_transient_det_process( hSpar->hTranDet, data_f[0], input_frame ); -#endif /* store previous input samples for W in local buffer */ assert( num_del_samples <= IVAS_FB_1MS_48K_SAMP ); @@ -482,27 +412,12 @@ static ivas_error ivas_spar_enc_process( ivas_fb_mixer_pcm_ingest( hSpar->hFbMixer, data_f, p_pcm_tmp, input_frame ); /* prepare Parameter MDFT analysis */ -#ifdef SBA_SPAR_HARM for ( i = 0; i < nchan_inp; i++ ) { ppIn_FR_real[i] = p_pcm_tmp[i]; ppIn_FR_imag[i] = p_pcm_tmp[i] + input_frame; p_pcm_tmp[i] = &data_f[i][0]; } -#else - for ( i = 0; i < nchan_inp; i++ ) - { - cov_in_buf.ppIn_FR_real[i] = p_pcm_tmp[i]; - cov_in_buf.ppIn_FR_imag[i] = p_pcm_tmp[i] + input_frame; - } - - for ( i = 0; i < nchan_inp; i++ ) - { - p_pcm_tmp[i] = &data_f[i][0]; - ppIn_FR_real[i] = cov_in_buf.ppIn_FR_real[i]; - ppIn_FR_imag[i] = cov_in_buf.ppIn_FR_imag[i]; - } -#endif l_ts = input_frame / MAX_PARAM_SPATIAL_SUBFRAMES; @@ -522,41 +437,18 @@ static ivas_error ivas_spar_enc_process( /* turn pointers back to the local buffer, needed for the following processing */ for ( i = 0; i < nchan_inp; i++ ) { -#ifdef SBA_SPAR_HARM ppIn_FR_real[i] = pcm_tmp[i]; ppIn_FR_imag[i] = pcm_tmp[i] + input_frame; -#endif p_pcm_tmp[i] = pcm_tmp[i]; } -#ifndef SBA_SPAR_HARM - cov_in_buf.num_ch = nchan_inp; -#endif - dtx_vad = ( hEncoderConfig->Opt_DTX_ON == 1 ) ? front_vad_flag : 1; /*-----------------------------------------------------------------------------------------* * DirAC encoding *-----------------------------------------------------------------------------------------*/ -#ifdef SBA_SPAR_HARM - ivas_dirac_param_est_enc( st_ivas->hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, - data_f, ppIn_FR_real, ppIn_FR_imag, input_frame -#ifdef SBA_HOA_HBR_IMPROV - , - st_ivas->sba_mode -#endif - ); -#else - ivas_dirac_param_est_enc( st_ivas->hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, - data_f, cov_in_buf.ppIn_FR_real, cov_in_buf.ppIn_FR_imag, input_frame -#ifdef SBA_HOA_HBR_IMPROV - , - st_ivas->sba_mode -#endif - ); -#endif - + ivas_dirac_param_est_enc( st_ivas->hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, data_f, ppIn_FR_real, ppIn_FR_imag, input_frame, st_ivas->sba_mode ); if ( hQMetaData->q_direction->cfg.nbands > 0 ) { @@ -641,26 +533,10 @@ static ivas_error ivas_spar_enc_process( } } -#ifndef SBA_SPAR_HARM - /*-----------------------------------------------------------------------------------------* - * Pre-proc flags - *-----------------------------------------------------------------------------------------*/ - - /* use just VAD function to get VAD flags */ - dtx_vad = ( hEncoderConfig->Opt_DTX_ON == 1 ) ? front_vad_flag : 1; - dtx_cov_flag = ( dtx_vad == 1 ) ? 0 : 1; - dtx_silence_mode = 0; // VE2DB: this variable is always 0 - please review or remove it - bwidth = ivas_get_bw_idx_from_sample_rate( input_Fs ); - bwidth = min( bwidth, hEncoderConfig->max_bwidth ); -#endif - /*-----------------------------------------------------------------------------------------* * Covariance process *-----------------------------------------------------------------------------------------*/ -#ifndef SBA_SPAR_HARM - cov_in_buf.num_ch = nchan_inp; -#endif for ( i = 0; i < nchan_inp; i++ ) { for ( j = 0; j < nchan_inp; j++ ) @@ -670,104 +546,31 @@ static ivas_error ivas_spar_enc_process( } } -#ifdef SBA_SPAR_HARM ivas_enc_cov_handler_process( hSpar->hCovEnc, ppIn_FR_real, ppIn_FR_imag, cov_real, cov_dtx_real, hSpar->hFbMixer->pFb, 0, hSpar->hFbMixer->pFb->filterbank_num_bands, nchan_inp, dtx_vad, transient_det ); -#else - cov_in_buf.dtx_cov_flag = dtx_cov_flag; - - ivas_enc_cov_handler_process( hSpar->hCovEnc, &cov_in_buf, cov_real, cov_dtx_real, hSpar->hFbMixer->pFb, 0, hSpar->hFbMixer->pFb->filterbank_num_bands ); -#endif /*-----------------------------------------------------------------------------------------* * Set SPAR bitrates *-----------------------------------------------------------------------------------------*/ -#ifdef SBA_SPAR_HARM table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); -#endif if ( hSpar->hMdEnc->table_idx != table_idx ) { hSpar->hMdEnc->table_idx = table_idx; - ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, -#ifdef SBA_HOA_HBR_IMPROV - ( hSpar->hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND -#else - SPAR_DIRAC_SPLIT_START_BAND -#endif - ); + ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, ( hSpar->hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND ); } -#ifdef SBA_SPAR_HARM nchan_transport = st_ivas->nchan_transport; -#else - nchan_transport = hSpar->hMdEnc->spar_md_cfg.nchan_transport; -#endif /*-----------------------------------------------------------------------------------------* * MetaData encoder *-----------------------------------------------------------------------------------------*/ -#ifdef SBA_SPAR_HARM -#ifdef SBA_HOA_HBR_IMPROV if ( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) -#endif { ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order ); } -#else - num_bands_bw = ivas_get_num_bands_from_bw_idx( bwidth ); - - if ( dtx_vad == 0 ) - { - for ( i = 0; i < nchan_inp; i++ ) - { - for ( j = 0; j < nchan_inp; j++ ) - { - md_in_buf.cov_real[i][j] = cov_dtx_real[i][j]; - for ( k = num_bands_bw; k < IVAS_MAX_NUM_BANDS; k++ ) - { - md_in_buf.cov_real[i][j][k] = 0; - } - } - } - } - else - { - for ( i = 0; i < nchan_inp; i++ ) - { - for ( j = 0; j < nchan_inp; j++ ) - { - md_in_buf.cov_real[i][j] = cov_real[i][j]; - for ( k = num_bands_bw; k < IVAS_MAX_NUM_BANDS; k++ ) - { - md_in_buf.cov_real[i][j][k] = 0; - } - } - } - } - md_in_buf.num_bands = ivas_get_num_bands_from_bw_idx( SPAR_CONFIG_BW ); -#ifdef SBA_HOA_HBR_IMPROV - if ( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) -#endif - { - md_in_buf.num_bands = min( md_in_buf.num_bands, SPAR_DIRAC_SPLIT_START_BAND ); - } - - md_in_buf.dtx_vad = dtx_vad; - -#ifdef SBA_HOA_HBR_IMPROV - if ( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) -#endif - { - ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, &md_in_buf, hMetaData, dtx_silence_mode, sba_order ); - } -#endif - -#ifndef SBA_SPAR_HARM - if ( st_ivas->sba_mode == SBA_MODE_SPAR ) // VE2DB: this looks obsolete -#endif { float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; @@ -800,33 +603,20 @@ static ivas_error ivas_spar_enc_process( Wscale_d[b] = 1.0f; for ( i = 1; i < nchan_inp; i++ ) { -#ifdef SBA_SPAR_HARM Wscale_d[b] += cov_real[i][i][b] / max( EPSILON, cov_real[0][0][b] ); -#else - Wscale_d[b] += md_in_buf.cov_real[i][i][b] / max( EPSILON, md_in_buf.cov_real[0][0][b] ); -#endif } Wscale_d[b] = Wscale_d[b] / ( 1.0f + (float) sba_order ); /*DirAC normalized signal variance sums to 1 + order*/ Wscale_d[b] = sqrtf( Wscale_d[b] ); Wscale_d[b] = min( 2.0f, max( Wscale_d[b], 1.0f ) ); } - ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, 1, hSpar->hMdEnc->mixer_mat, &hSpar->hMdEnc->spar_md, &hSpar->hMdEnc->spar_md_cfg, - d_start_band, d_end_band, -#ifdef SBA_HOA_HBR_IMPROV - ( hSpar->hMdEnc->spar_hoa_md_flag ) ? 1 : sba_order, -#else - sba_order, -#endif - dtx_vad, Wscale_d ); + ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, 1, hSpar->hMdEnc->mixer_mat, &hSpar->hMdEnc->spar_md, &hSpar->hMdEnc->spar_md_cfg, d_start_band, d_end_band, ( hSpar->hMdEnc->spar_hoa_md_flag ) ? 1 : sba_order, dtx_vad, Wscale_d ); } -#ifdef SBA_HOA_HBR_IMPROV if ( hSpar->hMdEnc->spar_hoa_md_flag ) { ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order ); } -#endif /*-----------------------------------------------------------------------------------------* * FB mixer @@ -894,7 +684,7 @@ static ivas_error ivas_spar_enc_process( } else { - if ( ivas_total_brate == PCA_BRATE && sba_order == 1 ) + if ( ivas_total_brate == PCA_BRATE && sba_order == SBA_FOA_ORDER ) { /* write PCA bypass bit */ push_next_indice( hMetaData, PCA_MODE_INACTIVE, 1 ); @@ -935,6 +725,10 @@ static ivas_error ivas_spar_enc_process( } else { + /* IVAS_fmToDo: This AGC on/off bit should be removed when the command line option to force enable/disable AGC is + * removed. + * On the decoder side, ivas_agc_enc_get_flag could be used instead to determine if AGC is on or not. The + * ivas_agc_enc_get_flag function should be moved to ivas_agc_com.c and renamed when this occurs. */ push_next_indice( hMetaData, 0, 1 ); } } diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 263d32292a..e6e8b0db61 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -82,11 +82,14 @@ static void ivas_select_next_strat( ivas_strats_t prior_strat, ivas_strats_t cs[ static void ivas_store_prior_coeffs( ivas_spar_md_enc_state_t *hMdEnc, const int16_t num_bands, const int16_t bands_bw, const int16_t strat, const int16_t dtx_vad, const int16_t qsi ); -static void ivas_write_spar_md_bitstream( ivas_spar_md_enc_state_t *hMdEnc, const int16_t nB, const int16_t bands_bw, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate, const int16_t dtx_silence_mode, const int16_t strat, const int16_t qsi, const int16_t planarCP ); +static void ivas_write_spar_md_bitstream( ivas_spar_md_enc_state_t *hMdEnc, const int16_t nB, const int16_t bands_bw, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate, const int16_t strat, const int16_t qsi, const int16_t planarCP ); static ivas_error ivas_spar_md_enc_init( ivas_spar_md_enc_state_t *hMdEnc, const ENCODER_CONFIG_HANDLE hEncoderConfig, const int16_t sba_order ); + static void ivas_spar_quant_pred_coeffs_dtx( ivas_spar_md_t *pSpar_md, const float *pValues, const int16_t ndm, int16_t *pIndex, const int16_t dim1, float *pQuant ); + static void ivas_quant_p_per_band_dtx( float *pP_mat, const int16_t num_dec, const int16_t num_dmx, int16_t *ppIdx_pd, float *pP_out, const int16_t num_ch ); + static void ivas_write_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, BSTR_ENC_HANDLE hMetaData, int16_t *num_dmx, int16_t *num_dec, const int16_t num_bands ); static void ivas_quant_p_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t num_ch ); @@ -119,11 +122,7 @@ ivas_error ivas_spar_md_enc_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD encoder" ); } - num_channels = 2 * sba_order + 2; - -#ifdef SBA_HOA_HBR_IMPROV - hMdEnc->spar_hoa_md_flag = ivas_sba_get_spar_hoa_md_flag( sba_order, hEncoderConfig->ivas_total_brate ); -#endif + num_channels = ivas_sba_get_nchan_metadata( sba_order ); if ( ( hMdEnc->spar_md.band_coeffs = (ivas_band_coeffs_t *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) { @@ -319,18 +318,12 @@ static ivas_error ivas_spar_md_enc_init( float PR_minmax[2]; int16_t num_channels, i, j, k; + hMdEnc->spar_hoa_md_flag = ivas_sba_get_spar_hoa_md_flag( sba_order, hEncoderConfig->ivas_total_brate ); num_channels = ivas_sba_get_nchan_metadata( sba_order ); table_idx = ivas_get_spar_table_idx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); - hMdEnc->spar_md_cfg.gen_bs = 1; - ivas_spar_set_bitrate_config( &hMdEnc->spar_md_cfg, table_idx, -#ifdef SBA_HOA_HBR_IMPROV - ( hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND -#else - SPAR_DIRAC_SPLIT_START_BAND -#endif - ); + ivas_spar_set_bitrate_config( &hMdEnc->spar_md_cfg, table_idx, ( hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND ); /* get FB coefficients */ for ( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) @@ -339,19 +332,6 @@ static ivas_error ivas_spar_md_enc_init( } ivas_spar_set_enc_config( hMdEnc, hMdEnc->spar_md_cfg.max_freq_per_chan, hMdEnc->spar_md_cfg.nchan_transport, pFC, num_channels ); - /* - if(hMdEnc->spar_md_cfg.quant_strat[0].C.q_levels[0] == 0 || hMdEnc->spar_md_cfg.quant_strat[0].C.q_levels[1] == 0 - || hMdEnc->spar_md_cfg.quant_strat[0].PR.q_levels[0] == 0 || hMdEnc->spar_md_cfg.quant_strat[0].PR.q_levels[1] == 0 - || hMdEnc->spar_md_cfg.quant_strat[0].P_c.q_levels[0] == 0 || hMdEnc->spar_md_cfg.quant_strat[0].P_c.q_levels[1] == 0 - || hMdEnc->spar_md_cfg.quant_strat[0].P_r.q_levels[0] == 0 || hMdEnc->spar_md_cfg.quant_strat[0].P_r.q_levels[1] == 0) - { - hMdEnc->spar_md_cfg.gen_bs = 0; - } - else if(0 != hMdEnc->spar_md_cfg.gen_bs) - { - hMdEnc->spar_md_cfg.quant_strat_bits = ivas_get_bits_to_encode(MAX_QUANT_STRATS); - } -*/ if ( hMdEnc->spar_md_cfg.nchan_transport != 2 && ( ( hMdEnc->spar_md_cfg.remix_unmix_order == 1 ) || ( hMdEnc->spar_md_cfg.remix_unmix_order == 2 ) ) ) { @@ -562,35 +542,20 @@ static void write_metadata_buffer( ivas_error ivas_spar_md_enc_process( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ -#ifdef SBA_SPAR_HARM float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], -#else - ivas_spar_md_enc_in_buf_t *pIn_buf, -#endif BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ -#ifdef SBA_SPAR_HARM int16_t dtx_vad, const int16_t nchan_inp, -#else - const int16_t dtx_silence_mode, -#endif const int16_t sba_order /* i : Ambisonic (SBA) order */ ) { float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; -#ifdef SBA_HOA_HBR_IMPROV float pred_coeffs_re_local[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; -#endif int16_t i, b, qsi, ndm, ndec, num_ch, num_quant_strats; int16_t j, planarCP; -#ifdef SBA_SPAR_HARM int16_t k, bwidth, num_bands, num_bands_full, num_bands_bw; -#else - int16_t num_bands = pIn_buf->num_bands; - int16_t dtx_vad = pIn_buf->dtx_vad; -#endif int16_t active_w, nchan_transport, dmx_switch, strat; int16_t nB, bands_bw, packed_ok = 0; ivas_strats_t cs[MAX_CODING_STRATS]; @@ -605,14 +570,11 @@ ivas_error ivas_spar_md_enc_process( active_w = hMdEnc->spar_md_cfg.active_w; nchan_transport = hMdEnc->spar_md_cfg.nchan_transport; -#ifdef SBA_SPAR_HARM bwidth = ivas_get_bw_idx_from_sample_rate( hEncoderConfig->input_Fs ); bwidth = min( bwidth, hEncoderConfig->max_bwidth ); num_bands = ivas_get_num_bands_from_bw_idx( SPAR_CONFIG_BW ); -#ifdef SBA_HOA_HBR_IMPROV if ( hMdEnc->spar_hoa_md_flag == 0 ) -#endif { num_bands = min( num_bands, SPAR_DIRAC_SPLIT_START_BAND ); } @@ -626,30 +588,22 @@ ivas_error ivas_spar_md_enc_process( for ( j = 0; j < nchan_inp; j++ ) { cov_real[i][j] = cov_dtx_real[i][j]; - for ( k = num_bands_bw; k < IVAS_MAX_NUM_BANDS; k++ ) - { - cov_real[i][j][k] = 0; - } } } } - else + + for ( i = 0; i < nchan_inp; i++ ) { - for ( i = 0; i < nchan_inp; i++ ) + for ( j = 0; j < nchan_inp; j++ ) { - for ( j = 0; j < nchan_inp; j++ ) + for ( k = num_bands_bw; k < IVAS_MAX_NUM_BANDS; k++ ) { - cov_real[i][j] = cov_real[i][j]; - for ( k = num_bands_bw; k < IVAS_MAX_NUM_BANDS; k++ ) - { - cov_real[i][j][k] = 0; - } + cov_real[i][j][k] = 0; } } } -#endif - if ( hEncoderConfig->ivas_total_brate == BRATE_SPAR_Q_STRAT && sba_order == 1 ) + if ( hEncoderConfig->ivas_total_brate == BRATE_SPAR_Q_STRAT && sba_order == SBA_FOA_ORDER ) { /* make sure that qsi is always 0 (temporary bits are '00') */ num_quant_strats = 1; @@ -662,12 +616,6 @@ ivas_error ivas_spar_md_enc_process( next_ind_start = hMetaData->next_ind; last_ind_start = hMetaData->last_ind; -#ifndef SBA_SPAR_HARM - if ( hEncoderConfig->Opt_DTX_ON == 0 ) - { - dtx_vad = 1; - } -#endif dmx_switch = 0; @@ -676,11 +624,7 @@ ivas_error ivas_spar_md_enc_process( nB = SPAR_DTX_BANDS; bands_bw = num_bands / nB; -#ifdef SBA_SPAR_HARM ivas_band_mixer( cov_real, num_ch, &num_bands, bands_bw ); -#else - ivas_band_mixer( pIn_buf->cov_real, num_ch, &num_bands, bands_bw ); -#endif } else { @@ -688,7 +632,6 @@ ivas_error ivas_spar_md_enc_process( bands_bw = 1; } -#ifdef SBA_HOA_HBR_IMPROV if ( hMdEnc->spar_hoa_md_flag ) { for ( b = SPAR_DIRAC_SPLIT_START_BAND; b < num_bands; b++ ) @@ -700,15 +643,9 @@ ivas_error ivas_spar_md_enc_process( } } } -#endif -#ifdef SBA_SPAR_HARM ivas_compute_spar_params( cov_real, dm_fv_re, 0, hMdEnc->mixer_mat, 0, nB, dtx_vad, num_ch, bands_bw, active_w, &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale, 0 ); -#else - ivas_compute_spar_params( pIn_buf->cov_real, dm_fv_re, 0, hMdEnc->mixer_mat, 0, nB, dtx_vad, num_ch, - bands_bw, active_w, &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale, 0 ); -#endif for ( i = 0; i < num_ch; i++ ) { @@ -755,11 +692,7 @@ ivas_error ivas_spar_md_enc_process( if ( ndm != num_ch ) { -#ifdef SBA_SPAR_HARM ivas_calc_c_p_coeffs( &hMdEnc->spar_md, cov_real, 0, hMdEnc->mixer_mat_local, num_ch, ndm, b, dtx_vad, 1, planarCP ); -#else - ivas_calc_c_p_coeffs( &hMdEnc->spar_md, pIn_buf->cov_real, 0, hMdEnc->mixer_mat_local, num_ch, ndm, b, dtx_vad, 1, planarCP ); -#endif } } } @@ -838,7 +771,6 @@ ivas_error ivas_spar_md_enc_process( } } -#ifdef SBA_HOA_HBR_IMPROV if ( hMdEnc->spar_hoa_md_flag ) { for ( b = SPAR_DIRAC_SPLIT_START_BAND; b < num_bands; b++ ) @@ -852,7 +784,6 @@ ivas_error ivas_spar_md_enc_process( } } } -#endif ivas_create_fullr_dmx_mat( pred_coeffs_re, dm_fv_re, hMdEnc->mixer_mat, num_ch, 0, num_bands, active_w, &hMdEnc->spar_md_cfg ); @@ -868,11 +799,7 @@ ivas_error ivas_spar_md_enc_process( if ( ( ndm != num_ch ) && ( ndm != 1 ) ) { -#ifdef SBA_SPAR_HARM ivas_calc_c_p_coeffs( &hMdEnc->spar_md, cov_real, 0, hMdEnc->mixer_mat, num_ch, ndm, b, dtx_vad, 0, planarCP ); -#else - ivas_calc_c_p_coeffs( &hMdEnc->spar_md, pIn_buf->cov_real, 0, hMdEnc->mixer_mat, num_ch, ndm, b, dtx_vad, 0, planarCP ); -#endif #ifdef SPAR_HOA_DBG /*fprintf(stderr, "\n\n C coefficients: band %d\n", b); @@ -933,16 +860,7 @@ ivas_error ivas_spar_md_enc_process( /* band mixing */ if ( bands_bw > 1 ) { -#ifdef SBA_SPAR_HARM ivas_band_mixing( hMdEnc, num_ch, num_bands, nchan_transport, num_bands_full ); -#else - ivas_band_mixing( hMdEnc, num_ch, num_bands, nchan_transport, pIn_buf->num_bands ); -#endif - } - - if ( hMdEnc->spar_md_cfg.gen_bs == 0 ) - { - break; } if ( dtx_vad == 0 ) @@ -960,14 +878,14 @@ ivas_error ivas_spar_md_enc_process( { reset_indices_enc( &hMetaData_tmp, MAX_BITS_METADATA ); - ivas_write_spar_md_bitstream( hMdEnc, num_bands, bands_bw, &hMetaData_tmp, hEncoderConfig->ivas_total_brate, 0, strat, qsi, planarCP ); + ivas_write_spar_md_bitstream( hMdEnc, num_bands, bands_bw, &hMetaData_tmp, hEncoderConfig->ivas_total_brate, strat, qsi, planarCP ); if ( hMetaData->nb_bits_tot == bit_pos_start || hMetaData_tmp.nb_bits_tot < ( hMetaData->nb_bits_tot - bit_pos_start ) ) { write_metadata_buffer( &hMetaData_tmp, hMetaData, bit_pos_start, next_ind_start, last_ind_start ); code_strat = strat; } - if ( hMetaData->nb_bits_tot - bit_pos_start + ( ( ( hEncoderConfig->ivas_total_brate == IVAS_256k ) && ( sba_order == 1 ) ) ? 1 : 0 ) <= hMdEnc->spar_md_cfg.tgt_bits_per_blk ) + if ( hMetaData->nb_bits_tot - bit_pos_start + ( ( ( hEncoderConfig->ivas_total_brate == IVAS_256k ) && ( sba_order == SBA_FOA_ORDER ) ) ? 1 : 0 ) <= hMdEnc->spar_md_cfg.tgt_bits_per_blk ) { packed_ok = 1; break; @@ -980,7 +898,7 @@ ivas_error ivas_spar_md_enc_process( break; } - if ( hMetaData->nb_bits_tot - bit_pos_start + ( ( ( hEncoderConfig->ivas_total_brate == IVAS_256k ) && ( sba_order == 1 ) ) ? 1 : 0 ) <= hMdEnc->spar_md_cfg.max_bits_per_blk ) + if ( hMetaData->nb_bits_tot - bit_pos_start + ( ( ( hEncoderConfig->ivas_total_brate == IVAS_256k ) && ( sba_order == SBA_FOA_ORDER ) ) ? 1 : 0 ) <= hMdEnc->spar_md_cfg.max_bits_per_blk ) { break; } @@ -1158,17 +1076,14 @@ ivas_error ivas_spar_md_enc_process( } #endif #ifdef DEBUG_SPAR_MD_TARGET_TUNING - int16_t md_bits = hMetaData->nb_bits_tot - bit_pos_start + ( ( ( hEncoderConfig->ivas_total_brate == IVAS_256k ) && ( sba_order == 1 ) ) ? 1 : 0 ); + int16_t md_bits = hMetaData->nb_bits_tot - bit_pos_start + ( ( ( hEncoderConfig->ivas_total_brate == IVAS_256k ) && ( sba_order == SBA_FOA_ORDER ) ) ? 1 : 0 ); FILE *fp = fopen( "spar_md_bitrate.txt", "a" ); fprintf( fp, "%d\t %d \t %d\n", md_bits, qsi, code_strat ); fclose( fp ); #endif - if ( hMdEnc->spar_md_cfg.gen_bs == 1 ) - { - ivas_store_prior_coeffs( hMdEnc, num_bands, bands_bw, code_strat, dtx_vad, qsi ); - } + ivas_store_prior_coeffs( hMdEnc, num_bands, bands_bw, code_strat, dtx_vad, qsi ); hMdEnc->spar_md.dtx_vad = dtx_vad; hMdEnc->spar_md.num_bands = num_bands; @@ -1236,7 +1151,6 @@ static void ivas_write_spar_md_bitstream( const int16_t bands_bw, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate, - const int16_t dtx_silence_mode, // VE2DB: it is always 0 -> remove it? const int16_t strat, const int16_t qsi, const int16_t planarCP ) @@ -1250,7 +1164,7 @@ static void ivas_write_spar_md_bitstream( } /* write quant strat */ - if ( dtx_silence_mode == 0 && ivas_total_brate >= BRATE_SPAR_Q_STRAT ) + if ( ivas_total_brate >= BRATE_SPAR_Q_STRAT ) { push_next_indice( hMetaData, qsi >> 1, hMdEnc->spar_md_cfg.quant_strat_bits - 1 ); } @@ -1355,7 +1269,6 @@ static void ivas_get_huffman_coded_bs( pred_coeff_dim = ndm + ndec - 1; pred_offset = 0; -#ifdef SBA_HOA_HBR_IMPROV if ( hMdEnc->spar_hoa_md_flag ) { if ( i >= SPAR_DIRAC_SPLIT_START_BAND ) @@ -1363,7 +1276,6 @@ static void ivas_get_huffman_coded_bs( pred_offset = FOA_CHANNELS - 1; } } -#endif if ( planarCP ) { @@ -1446,7 +1358,6 @@ static void ivas_get_arith_coded_bs( ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[bands_bw * i]; ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[bands_bw * i]; pred_cell_dims[i].dim1 = ndm + ndec - 1; -#ifdef SBA_HOA_HBR_IMPROV if ( hMdEnc->spar_hoa_md_flag ) { if ( i >= SPAR_DIRAC_SPLIT_START_BAND ) @@ -1454,7 +1365,6 @@ static void ivas_get_arith_coded_bs( pred_cell_dims[i].dim1 -= ( FOA_CHANNELS - 1 ); } } -#endif pred_cell_dims[i].dim2 = 1; drct_cell_dims[i].dim1 = ndec; drct_cell_dims[i].dim2 = ndm - 1; @@ -1473,7 +1383,6 @@ static void ivas_get_arith_coded_bs( break; } } -#ifdef SBA_HOA_HBR_IMPROV if ( hMdEnc->spar_hoa_md_flag ) { int16_t j; @@ -1494,7 +1403,6 @@ static void ivas_get_arith_coded_bs( } } } -#endif ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md.band_coeffs_idx, nB, symbol_arr_re, pred_cell_dims, PRED_COEFF, planarCP ); if ( any_diff == 1 ) @@ -1506,7 +1414,6 @@ static void ivas_get_arith_coded_bs( ivas_arith_encode_cmplx_cell_array( &hMdEnc->arith_coeffs.pred_arith_re[qsi], &hMdEnc->arith_coeffs.pred_arith_re_diff[qsi], pDo_diff, nB, symbol_arr_re, symbol_arr_old_re, pred_cell_dims, hMetaData, any_diff ); -#ifdef SBA_HOA_HBR_IMPROV if ( hMdEnc->spar_hoa_md_flag ) { int16_t j; @@ -1526,7 +1433,6 @@ static void ivas_get_arith_coded_bs( } } } -#endif #ifdef SPAR_HOA_DBG /*fprintf(stderr, "\n\n band_indexes:\n"); diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 531e69d85a..4ae2e2f41f 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -40,9 +40,6 @@ #include "stat_enc.h" #include "ivas_cnst.h" #include "ivas_stat_com.h" -#ifdef AGC_ENABLE_FOR_LBR -#include "lib_enc.h" -#endif /*----------------------------------------------------------------------------------* * DFT Stereo encoder structures @@ -631,17 +628,6 @@ typedef struct ivas_enc_cov_handler_state_t } ivas_enc_cov_handler_state_t; -#ifndef SBA_SPAR_HARM -typedef struct ivas_enc_cov_handler_in_buf_t -{ - float *ppIn_FR_real[IVAS_SPAR_MAX_CH]; - float *ppIn_FR_imag[IVAS_SPAR_MAX_CH]; - int16_t num_ch; - int16_t transient_det; - int16_t dtx_cov_flag; - -} ivas_enc_cov_handler_in_buf_t; -#endif /* SPAR MD structures */ typedef struct ivas_spar_md_enc_state_t @@ -659,20 +645,9 @@ typedef struct ivas_spar_md_enc_state_t ivas_arith_coeffs_t arith_coeffs; ivas_huff_coeffs_t huff_coeffs; int16_t table_idx; -#ifdef SBA_HOA_HBR_IMPROV int16_t spar_hoa_md_flag; -#endif } ivas_spar_md_enc_state_t; -#ifndef SBA_SPAR_HARM -typedef struct ivas_spar_md_enc_in_buf_t -{ - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - int16_t num_bands; - int16_t dtx_vad; - -} ivas_spar_md_enc_in_buf_t; -#endif /* PCA structure */ typedef struct { @@ -850,11 +825,9 @@ typedef struct stereo_cng_enc typedef struct sce_enc_data_structure { - int16_t sce_id; /* SCE # identifier */ - int32_t element_brate; /* SCE element total bitrate in bps */ -#ifdef CORECODER_BITRATE_SWITCHING + int16_t sce_id; /* SCE # identifier */ + int32_t element_brate; /* SCE element total bitrate in bps */ int32_t last_element_brate; /* last SCE element bitrate in bps */ -#endif BSTR_ENC_HANDLE hMetaData; /* Metadata bitstream handle */ @@ -1027,10 +1000,8 @@ typedef struct encoder_config_structure int16_t Opt_SC_VBR; /* flag indicating SC-VBR mode */ int16_t last_Opt_SC_VBR; /* flag indicating prev frame's SC-VBR mode */ -#ifdef AGC_ENABLE_FOR_LBR - IVAS_ENC_AGC Opt_AGC_ON; /* flag indicating AGC operation in SBA */ -#else /* temp. development parameters */ +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION int16_t Opt_AGC_ON; /* flag indicating AGC operation in SBA */ #endif int16_t Opt_PCA_ON; /* flag indicating PCA operation in SBA */ diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 6e674502f5..079a73922b 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -78,12 +78,13 @@ static int16_t getInputBufferSize( const Encoder_Struct *st_ivas ); static ivas_error doCommonConfigureChecks( IVAS_ENC_HANDLE hIvasEnc ); static ivas_error doCommonSetterChecks( IVAS_ENC_HANDLE hIvasEnc ); static ivas_error sanitizeBandwidth( const IVAS_ENC_HANDLE hIvasEnc ); -#ifdef ISM_BITRATE_SWITCHING static ivas_error sanitizeBitrateISM( const ENCODER_CONFIG_HANDLE hEncoderConfig ); -#endif static void init_encoder_config( ENCODER_CONFIG_HANDLE hEncoderConfig ); static void resetIsmMetadataProvidedFlags( IVAS_ENC_HANDLE hIvasEnc ); static ivas_error bandwidthApiToInternal( const IVAS_ENC_BANDWIDTH maxBandwidth, int16_t *internalMaxBandwidth ); +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION +static ivas_error agcAPIToInternal( const IVAS_ENC_AGC agcOption, int16_t *internalAGCOption ); +#endif static ivas_error fecIndicatorApiToInternal( const IVAS_ENC_FEC_INDICATOR fecIndicator, int16_t *fecIndicatorInternal ); #ifdef DEBUGGING static ivas_error forcedModeApiToInternal( IVAS_ENC_FORCED_MODE forcedMode, int16_t *forcedModeInternal ); @@ -451,11 +452,13 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ const IVAS_ENC_SBA_ORDER order, /* i : order of the Ambisonics input */ const bool isPlanar, /* i : if true, input is treated as planar Ambisonics */ +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION #ifdef AGC_ENABLE_FOR_LBR const IVAS_ENC_AGC Opt_AGC_ON, /* i : AGC on/off/undefined flag */ #else const bool Opt_AGC_ON, /* i : AGC on/off flag */ -#endif +#endif /* AGC_ENABLE_FOR_LBR */ +#endif /* DEBUG_AGC_ENCODER_CMD_OPTION */ const bool Opt_PCA_ON /* i : PCA option flag */ #ifdef DEBUG_SBA_AUDIO_DUMP , @@ -477,13 +480,21 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( hEncoderConfig->element_mode_init = IVAS_SCE; /* Just needs to be something not mono, will be set later */ hEncoderConfig->sba_planar = isPlanar; hEncoderConfig->sba_order = order; + /* Input in ACN/SN3D in all cases (3D and planar): get number of channels */ hEncoderConfig->nchan_inp = ivas_sba_get_nchan( hEncoderConfig->sba_order, 0 ); /*planar input arg. deliberately set to zero since input always in ACN/SN3D*/ + +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION #ifdef AGC_ENABLE_FOR_LBR - hEncoderConfig->Opt_AGC_ON = Opt_AGC_ON; + if ( ( error = agcAPIToInternal( Opt_AGC_ON, &( hEncoderConfig->Opt_AGC_ON ) ) ) != IVAS_ERR_OK ) + { + return error; + } #else hEncoderConfig->Opt_AGC_ON = (int16_t) Opt_AGC_ON; -#endif +#endif /* AGC_ENABLE_FOR_LBR */ +#endif /* DEBUG_AGC_ENCODER_CMD_OPTION */ + hEncoderConfig->Opt_PCA_ON = (int16_t) Opt_PCA_ON; hIvasEnc->maxBandwidthUser = max_bwidth_user; @@ -772,29 +783,10 @@ static ivas_error configureEncoder( } else if ( hEncoderConfig->ivas_format == ISM_FORMAT ) { -#ifdef ISM_BITRATE_SWITCHING if ( ( error = sanitizeBitrateISM( hEncoderConfig ) ) != IVAS_ERR_OK ) { return error; } -#else - if ( hEncoderConfig->ivas_total_brate > IVAS_256k ) - { - return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); - } - if ( hEncoderConfig->ivas_total_brate < IVAS_16k4 && hEncoderConfig->nchan_inp == 2 ) - { - return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 2 ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); - } - if ( hEncoderConfig->ivas_total_brate < IVAS_24k4 && hEncoderConfig->nchan_inp == 3 ) - { - return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 3 ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); - } - if ( hEncoderConfig->ivas_total_brate < IVAS_24k4 && hEncoderConfig->nchan_inp == 4 ) - { - return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 4 ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); - } -#endif } else if ( hEncoderConfig->ivas_format == SBA_FORMAT ) { @@ -897,16 +889,19 @@ static ivas_error configureEncoder( return IVAS_ERROR( IVAS_ERR_DTX_NOT_SUPPORTED, "DTX is not supported in this IVAS format and element mode." ); } +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION #ifdef AGC_ENABLE_FOR_LBR - if ( hEncoderConfig->Opt_AGC_ON == IVAS_ENC_AGC_ENABLED && !( hEncoderConfig->ivas_format == SBA_FORMAT && ivas_sba_mode_select( hEncoderConfig->ivas_total_brate ) == SBA_MODE_SPAR ) ) + if ( hEncoderConfig->Opt_AGC_ON == SBA_AGC_FORCE_ENABLE && !( hEncoderConfig->ivas_format == SBA_FORMAT && ivas_sba_mode_select( hEncoderConfig->ivas_total_brate ) == SBA_MODE_SPAR ) ) #else if ( hEncoderConfig->Opt_AGC_ON && !( hEncoderConfig->ivas_format == SBA_FORMAT && ivas_sba_mode_select( hEncoderConfig->ivas_total_brate ) == SBA_MODE_SPAR ) ) -#endif +#endif /* AGC_ENABLE_FOR_LBR */ { return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "AGC supported in SBA format at bitrates >= 24.4 kbps only." ); } +#endif /* DEBUG_AGC_ENCODER_CMD_OPTION */ + - if ( hEncoderConfig->Opt_PCA_ON && !( hEncoderConfig->ivas_format == SBA_FORMAT && hEncoderConfig->ivas_total_brate == PCA_BRATE && hEncoderConfig->sba_order == 1 ) ) + if ( hEncoderConfig->Opt_PCA_ON && !( hEncoderConfig->ivas_format == SBA_FORMAT && hEncoderConfig->ivas_total_brate == PCA_BRATE && hEncoderConfig->sba_order == SBA_FOA_ORDER ) ) { return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "PCA supported at SBA FOA 256 kbps only." ); } @@ -1514,7 +1509,7 @@ static ivas_error printConfigInfo_enc( else if ( hEncoderConfig->ivas_format == SBA_FORMAT ) { #ifdef PRINT_SBA_ORDER - fprintf( stdout, "IVAS format: Scene Based Analysis, Ambisonic order %i %s ", hEncoderConfig->sba_order, hEncoderConfig->sba_planar ? "(Planar)" : "" ); + fprintf( stdout, "IVAS format: Scene Based Audio, Ambisonic order %i %s ", hEncoderConfig->sba_order, hEncoderConfig->sba_planar ? "(Planar)" : "" ); #else fprintf( stdout, "IVAS format: Scene Based Analysis %s ", hEncoderConfig->sba_planar ? "(Planar)" : "" ); #endif @@ -1522,16 +1517,17 @@ static ivas_error printConfigInfo_enc( { fprintf( stdout, "- PCA configured with signal adaptive decision " ); } +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION #ifdef AGC_ENABLE_FOR_LBR switch ( hEncoderConfig->Opt_AGC_ON ) { - case IVAS_ENC_AGC_ENABLED: + case SBA_AGC_FORCE_ENABLE: fprintf( stdout, "- AGC FORCED ON " ); break; - case IVAS_ENC_AGC_DISABLED: + case SBA_AGC_FORCE_DISABLE: fprintf( stdout, "- AGC FORCED OFF " ); break; - case IVAS_ENC_AGC_UNDEFINED: + case SBA_AGC_DEFAULT: fprintf( stdout, "- AGC default mode " ); break; default: @@ -1543,7 +1539,10 @@ static ivas_error printConfigInfo_enc( { fprintf( stdout, "- AGC ON " ); } -#endif +#endif /* AGC_ENABLE_FOR_LBR */ +#else + fprintf( stdout, "- AGC default mode " ); +#endif /* DEBUG_AGC_ENCODER_CMD_OPTION */ fprintf( stdout, "\n" ); } else if ( hEncoderConfig->ivas_format == MASA_FORMAT ) @@ -1669,9 +1668,7 @@ static ivas_error setBitrate( { Encoder_Struct *st_ivas; ENCODER_CONFIG_HANDLE hEncoderConfig; -#ifdef ISM_BITRATE_SWITCHING ivas_error error; -#endif st_ivas = hIvasEnc->st_ivas; hEncoderConfig = st_ivas->hEncoderConfig; @@ -1718,7 +1715,6 @@ static ivas_error setBitrate( } } -#ifdef ISM_BITRATE_SWITCHING if ( hEncoderConfig->ivas_format == ISM_FORMAT ) { if ( ( error = sanitizeBitrateISM( hEncoderConfig ) ) != IVAS_ERR_OK ) @@ -1726,7 +1722,6 @@ static ivas_error setBitrate( return error; } } -#endif st_ivas->codec_mode = MODE1; @@ -1954,7 +1949,6 @@ static ivas_error sanitizeBandwidth( } -#ifdef ISM_BITRATE_SWITCHING /*---------------------------------------------------------------------* * sanitizeBitrateISM() * @@ -1986,7 +1980,6 @@ static ivas_error sanitizeBitrateISM( return IVAS_ERR_OK; } -#endif /*---------------------------------------------------------------------* @@ -2082,6 +2075,31 @@ static ivas_error bandwidthApiToInternal( return IVAS_ERR_OK; } +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION +static ivas_error agcAPIToInternal( + const IVAS_ENC_AGC agcOption, + int16_t *internalAGCOption ) +{ + switch ( agcOption ) + { + case IVAS_ENC_AGC_ENABLED: + *internalAGCOption = SBA_AGC_FORCE_ENABLE; + break; + case IVAS_ENC_AGC_DISABLED: + *internalAGCOption = SBA_AGC_FORCE_DISABLE; + break; + case IVAS_ENC_AGC_UNDEFINED: + *internalAGCOption = SBA_AGC_DEFAULT; + break; + default: + return IVAS_ERR_INVALID_AGC; + break; + } + + return IVAS_ERR_OK; +} +#endif + /*---------------------------------------------------------------------* * fecIndicatorApiToInternal() @@ -2216,11 +2234,13 @@ static void init_encoder_config( hEncoderConfig->stereo_dmx_evs = 0; hEncoderConfig->sba_order = 0; hEncoderConfig->sba_planar = 0; +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION #ifdef AGC_ENABLE_FOR_LBR - hEncoderConfig->Opt_AGC_ON = IVAS_ENC_AGC_UNDEFINED; + hEncoderConfig->Opt_AGC_ON = SBA_AGC_DEFAULT; #else hEncoderConfig->Opt_AGC_ON = 0; -#endif +#endif /* AGC_ENABLE_FOR_LBR */ +#endif /* DEBUG_AGC_ENCODER_CMD_OPTION */ hEncoderConfig->Opt_PCA_ON = 0; return; diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index 20eef7b1fe..373da97f96 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -124,13 +124,15 @@ typedef enum _IVAS_ENC_FORCED_MODE #endif #ifdef AGC_ENABLE_FOR_LBR +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION typedef enum _IVAS_ENC_AGC { IVAS_ENC_AGC_DISABLED = 0, IVAS_ENC_AGC_ENABLED, IVAS_ENC_AGC_UNDEFINED = 0xffff } IVAS_ENC_AGC; -#endif +#endif /* DEBUG_AGC_ENCODER_CMD_OPTION */ +#endif /* AGC_ENABLE_FOR_LBR */ /*---------------------------------------------------------------------* * Encoder structures @@ -197,11 +199,13 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ const IVAS_ENC_SBA_ORDER order, /* i : order of the Ambisonics input */ const bool isPlanar, /* i : if true, input is treated as planar Ambisonics */ +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION #ifdef AGC_ENABLE_FOR_LBR const IVAS_ENC_AGC Opt_AGC_ON, /* i : AGC on/off/undefined flag */ #else const bool Opt_AGC_ON, /* i : AGC on/off flag */ -#endif +#endif /* AGC_ENABLE_FOR_LBR */ +#endif /* DEBUG_AGC_ENCODER_CMD_OPTION */ const bool Opt_PCA_ON /* i : PCA option flag */ #ifdef DEBUG_SBA_AUDIO_DUMP , diff --git a/lib_rend/ivas_allrad_dec.c b/lib_rend/ivas_allrad_dec.c index 119b89b2cc..a61f543cb1 100644 --- a/lib_rend/ivas_allrad_dec.c +++ b/lib_rend/ivas_allrad_dec.c @@ -108,11 +108,7 @@ ivas_error ivas_sba_get_hoa_dec_matrix( /* Allocate memory */ assert( *hoa_dec_mtx == NULL && "hoa_dec_mtx != NULL" ); -#ifdef ALLRAD_OPTIM if ( ( *hoa_dec_mtx = (float *) count_malloc( SBA_NHARM_HOA3 * ( hOutSetup.nchan_out_woLFE ) * sizeof( float ) ) ) == NULL ) -#else - if ( ( *hoa_dec_mtx = (float *) count_malloc( SBA_NHARM_HOA3 * MAX_OUTPUT_CHANNELS * sizeof( float ) ) ) == NULL ) -#endif { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "ALLRAD: Cannot allocate memory!" ) ); } diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index ae910b1f25..698612b1ad 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -1146,10 +1146,10 @@ ivas_error ivas_crend_process( ivas_error ivas_rend_openCrend( CREND_WRAPPER *pCrend, - IVAS_REND_AudioConfig inConfig, - IVAS_REND_AudioConfig outConfig, + const IVAS_REND_AudioConfig inConfig, + const IVAS_REND_AudioConfig outConfig, RENDER_CONFIG_DATA *hRendCfg, - int32_t output_Fs ) + const int32_t output_Fs ) { /* TODO tmu : Based on ivas_crend_open() - could be harmonized / refactored */ int16_t i, subframe_length; @@ -1309,13 +1309,13 @@ ivas_error ivas_rend_openCrend( ivas_error ivas_rend_initCrend( CREND_WRAPPER *pCrend, - IVAS_REND_AudioConfig inConfig, - IVAS_REND_AudioConfig outConfig, + const IVAS_REND_AudioConfig inConfig, + const IVAS_REND_AudioConfig outConfig, RENDER_CONFIG_DATA *hRendCfg, - int32_t output_Fs ) + const int32_t output_Fs ) { int16_t i, j, tmp; - int32_t nchan_in; + int16_t nchan_in; bool use_brir; IVAS_REND_AudioConfigType inConfigType; HRTFS_HANDLE hHrtf; @@ -1353,7 +1353,7 @@ ivas_error ivas_rend_initCrend( { return error; } - hHrtf->max_num_ir = (int16_t) nchan_in; + hHrtf->max_num_ir = nchan_in; if ( hHrtf->max_num_ir <= 0 ) { @@ -1764,26 +1764,26 @@ ivas_error ivas_rend_closeCrend( } /*-----------------------------------------------------------------------------------------* - * Function ivas_rend_crend_process() + * Function ivas_rend_crend_Process() * * Process call for IVAS Crend renderer *-----------------------------------------------------------------------------------------*/ ivas_error ivas_rend_crendProcess( const CREND_WRAPPER *pCrend, - IVAS_REND_AudioConfig inConfig, - IVAS_REND_AudioConfig outConfig, + const IVAS_REND_AudioConfig inConfig, + const IVAS_REND_AudioConfig outConfig, float output[][L_FRAME48k], /* i/o: input/output audio channels */ - int32_t output_Fs ) + const int32_t output_Fs ) { int16_t i, subframe_idx, output_frame; - int32_t nchan_out; + int16_t nchan_out; float pcm_tmp[BINAURAL_CHANNELS][L_FRAME48k]; AUDIO_CONFIG in_config; IVAS_REND_AudioConfigType inConfigType; ivas_error error; - wmops_sub_start( "ivas_crend_process" ); + wmops_sub_start( "ivas_rend_crendProcess" ); in_config = getIvasAudioConfigFromRendAudioConfig( inConfig ); inConfigType = getAudioConfigType( inConfig ); @@ -1819,6 +1819,8 @@ ivas_error ivas_rend_crendProcess( mvr2r( pcm_tmp[i], output[i], output_frame ); } + wmops_sub_end(); + return IVAS_ERR_OK; } @@ -1834,19 +1836,17 @@ ivas_error ivas_rend_crendConvolver( IVAS_REND_AudioConfig outConfig, float pcm_in[][L_FRAME48k], float pcm_out[][L_FRAME48k], - int32_t output_Fs, + 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; - int32_t nchan_in, nchan_out; + int16_t nchan_in, nchan_out; float *pIn; - float *pFreq_buf_re; - float *pFreq_buf_im; - float *pFreq_filt_re; - float *pFreq_filt_im; + 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]; diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index 1c58e0a25e..8a3dd6ad05 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -100,9 +100,7 @@ static float vertex_distance( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGL static float point_plane_distance( const float P1[3], const float P2[3], const float P3[3], const float X[3] ); -#ifdef EFAP_FIX_POLY static float point_poly_distance( const EFAP_POLYSET poly, const float X[3] ); -#endif static void efap_crossp( const float *v1, const float *v2, float *v ); static int16_t find_int_in_tri( const EFAP_LS_TRIANGLE *tri, const int16_t n, const int16_t r, int16_t *pos ); @@ -127,9 +125,7 @@ static int16_t in_poly( const float P[2], const EFAP_POLYSET poly ); static int16_t in_tri( float A[2], float B[2], float C[2], float P_minus_A[2] ); -#ifdef EFAP_FIX_POLY static void sph2cart( const float azi, const float ele, float *pos ); -#endif /*-----------------------------------------------------------------------* * Global function definitions @@ -1506,13 +1502,7 @@ static void add_vertex( vtxArray[pos].ele = ( ( -180.0f > tmp ) ? -180.0f : tmp ); /* Converting spherical coordinates to cartesians, assuming radius = 1 */ -#ifdef EFAP_FIX_POLY sph2cart( vtxArray[pos].azi, vtxArray[pos].ele, &vtxArray[pos].pos[0] ); -#else - vtxArray[pos].pos[0] = cosf( vtxArray[pos].azi * PI_OVER_180 ) * cosf( vtxArray[pos].ele * PI_OVER_180 ); - vtxArray[pos].pos[1] = sinf( vtxArray[pos].azi * PI_OVER_180 ) * cosf( vtxArray[pos].ele * PI_OVER_180 ); - vtxArray[pos].pos[2] = sinf( vtxArray[pos].ele * PI_OVER_180 ); -#endif /* Computing the index defined by idx = idxAziTmp + 181 * idxEleTmp */ @@ -1604,7 +1594,6 @@ static float vertex_distance( return point_plane_distance( A, B, C, P ); } -#ifdef EFAP_FIX_POLY /*-------------------------------------------------------------------------* * point_poly_distance() * @@ -1624,7 +1613,6 @@ static float point_poly_distance( return point_plane_distance( P1, P2, P3, X ); } -#endif /*-------------------------------------------------------------------------* * point_plane_distance() @@ -2116,7 +2104,6 @@ static int16_t get_poly_num( ) { int16_t i; -#ifdef EFAP_FIX_POLY int16_t num_poly, found_poly; int16_t poly_tmp[EFAP_MAX_CHAN_NUM]; float poly_dist[EFAP_MAX_CHAN_NUM]; @@ -2129,12 +2116,10 @@ static int16_t get_poly_num( sph2cart( P[0], P[1], &pos[0] ); /* Filter the polygon list with a fast 2d check */ -#endif for ( i = 0; i < polyData->numPoly; ++i ) { if ( in_poly( P, polyData->polysetArray[i] ) ) { -#ifdef EFAP_FIX_POLY /* select only polygons which are visible from the point */ dist_tmp = point_poly_distance( polyData->polysetArray[i], pos ); if ( dist_tmp == 0 ) @@ -2147,12 +2132,8 @@ static int16_t get_poly_num( poly_dist[num_poly] = dist_tmp; num_poly++; } -#else - return i; -#endif } } -#ifdef EFAP_FIX_POLY if ( num_poly == 0 ) { return -1; @@ -2171,9 +2152,6 @@ static int16_t get_poly_num( } return found_poly; -#else - return -1; -#endif } diff --git a/lib_rend/ivas_lib_rend_internal.h b/lib_rend/ivas_lib_rend_internal.h index 773b75309b..94a762c315 100644 --- a/lib_rend/ivas_lib_rend_internal.h +++ b/lib_rend/ivas_lib_rend_internal.h @@ -60,46 +60,46 @@ typedef struct } CREND_WRAPPER; IVAS_REND_AudioConfigType getAudioConfigType( - IVAS_REND_AudioConfig config ); + const IVAS_REND_AudioConfig config ); ivas_error getAudioConfigNumChannels( - IVAS_REND_AudioConfig config, - int32_t *numChannels ); + const IVAS_REND_AudioConfig config, + int16_t *numChannels ); AUDIO_CONFIG getIvasAudioConfigFromRendAudioConfig( IVAS_REND_AudioConfig config ); ivas_error ivas_rend_openCrend( CREND_WRAPPER *pCrend, - IVAS_REND_AudioConfig inConfig, - IVAS_REND_AudioConfig outConfig, - RENDER_CONFIG_DATA *hRend, - int32_t output_Fs ); + const IVAS_REND_AudioConfig inConfig, + const IVAS_REND_AudioConfig outConfig, + RENDER_CONFIG_DATA *hRendCfg, + const int32_t output_Fs ); ivas_error ivas_rend_initCrend( CREND_WRAPPER *pCrend, - IVAS_REND_AudioConfig inConfig, - IVAS_REND_AudioConfig outConfig, - RENDER_CONFIG_DATA *hRend, - int32_t output_Fs ); + 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 *pCrend ); ivas_error ivas_rend_crendProcess( const CREND_WRAPPER *pCrend, - IVAS_REND_AudioConfig inConfig, - IVAS_REND_AudioConfig outConfig, + const IVAS_REND_AudioConfig inConfig, + const IVAS_REND_AudioConfig outConfig, float output[][L_FRAME48k], /* i/o: input/output audio channels */ - int32_t output_Fs ); + const int32_t output_Fs ); ivas_error ivas_rend_crendConvolver( const CREND_WRAPPER *pCrend, - IVAS_REND_AudioConfig inConfig, - IVAS_REND_AudioConfig outConfig, + const IVAS_REND_AudioConfig inConfig, + const IVAS_REND_AudioConfig outConfig, float pcm_in[][L_FRAME48k], float pcm_out[][L_FRAME48k], - int32_t output_Fs, + const int32_t output_Fs, const int16_t i_ts ); ivas_error ivas_rend_TDObjRenderFrame( @@ -115,9 +115,9 @@ ivas_error ivas_rend_TDObjRenderFrame( ivas_error ivas_rend_TDObjRendOpen( TDREND_WRAPPER *pTDRend, - IVAS_REND_AudioConfig inConfig, + const IVAS_REND_AudioConfig inConfig, LSSETUP_CUSTOM_STRUCT *customLsInput, - int32_t outFs ); + const int32_t output_Fs ); #endif #endif diff --git a/lib_rend/ivas_limiter.c b/lib_rend/ivas_limiter.c index 25fad180b9..a4dffb180d 100644 --- a/lib_rend/ivas_limiter.c +++ b/lib_rend/ivas_limiter.c @@ -29,7 +29,7 @@ the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ - +// VE2AT: keep in lib_rend or move to lib_dec ? #include #include #include diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index e4f0706193..7bd892cdac 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -51,7 +51,9 @@ *---------------------------------------------------------------------*/ static ivas_error TDREND_GetMix( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, float output[][L_FRAME48k], const int16_t subframe_length, const int32_t output_Fs, const int16_t subframe_idx ); + static void TDREND_Clear_Update_flags( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd ); + static void TDREND_Update_listener_orientation( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, const int16_t headRotEnabled, #ifdef EXT_RENDERER @@ -269,9 +271,7 @@ void ObjRenderIVASFrame( for ( subframe_idx = 0; subframe_idx < MAX_PARAM_SPATIAL_SUBFRAMES; subframe_idx++ ) { /* Update the listener's location/orientation */ - TDREND_Update_listener_orientation( st_ivas->hBinRendererTd, - st_ivas->hDecoderConfig->Opt_Headrotation, - ( st_ivas->hHeadTrackData != NULL ) ? &st_ivas->hHeadTrackData->Quaternions[subframe_idx] : NULL ); + TDREND_Update_listener_orientation( st_ivas->hBinRendererTd, st_ivas->hDecoderConfig->Opt_Headrotation, ( st_ivas->hHeadTrackData != NULL ) ? &st_ivas->hHeadTrackData->Quaternions[subframe_idx] : NULL ); if ( ( st_ivas->hRenderConfig != NULL ) && ( st_ivas->hRenderConfig->roomAcoustics.late_reverb_on ) ) { @@ -512,7 +512,7 @@ ivas_error ivas_rend_TDObjRendOpen( TDREND_WRAPPER *pTDRend, IVAS_REND_AudioConfig inConfig, LSSETUP_CUSTOM_STRUCT *customLsInput, - int32_t outFs ) + const int32_t outFs ) { /* TODO tmu : Based on ivas_td_binaural_open() - could be harmonized / refactored - review error handling @@ -526,7 +526,7 @@ ivas_error ivas_rend_TDObjRendOpen( float Pos[3]; float Dir[3]; TDREND_DirAtten_t *DirAtten_p; - int32_t nchan_rend; + int16_t nchan_rend; ivas_error error; error = IVAS_ERR_OK; @@ -645,7 +645,6 @@ ivas_error ivas_rend_TDObjRendOpen( pTDRend->binaural_latency_ns = (int32_t) ( BINAURAL_TD_LATENCY_S * 1000000000.f ); - return IVAS_ERR_OK; } @@ -672,12 +671,14 @@ ivas_error ivas_rend_TDObjRenderFrame( int16_t subframe_idx; ISM_METADATA_HANDLE hIsmMetaData[1]; int16_t lfe_idx; - int32_t num_src; + int16_t num_src; /* TODO tmu : pass down renderer config struct */ // float reverb_signal[BINAURAL_CHANNELS][L_FRAME48k]; IVAS_FORMAT ivas_format; IVAS_REND_AudioConfigType inConfigType; + wmops_sub_start( "ivas_rend_TDObjRenderFrame" ); + inConfigType = getAudioConfigType( inConfig ); lfe_idx = LFE_CHANNEL; if ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) @@ -714,12 +715,7 @@ ivas_error ivas_rend_TDObjRenderFrame( // } /* Update object position(s) */ - TDREND_Update_object_positions( pTDRend->hBinRendererTd, - (int16_t) num_src, - lfe_idx, - ivas_format, - hIsmMetaData, - output ); + TDREND_Update_object_positions( pTDRend->hBinRendererTd, num_src, lfe_idx, ivas_format, hIsmMetaData, output ); /* TODO tmu : needs a refactor / better approach */ if ( ivas_format == ISM_FORMAT ) @@ -730,9 +726,7 @@ ivas_error ivas_rend_TDObjRenderFrame( for ( subframe_idx = 0; subframe_idx < MAX_PARAM_SPATIAL_SUBFRAMES; subframe_idx++ ) { /* Update the listener's location/orientation */ - TDREND_Update_listener_orientation( pTDRend->hBinRendererTd, - headRotData->headRotEnabled, - ( headRotData != NULL ) ? &headRotData->headPositions[subframe_idx] : NULL ); + TDREND_Update_listener_orientation( pTDRend->hBinRendererTd, headRotData->headRotEnabled, ( headRotData != NULL ) ? &headRotData->headPositions[subframe_idx] : NULL ); /* TODO tmu : pass down renderer config struct */ // if ( ( hRenderConfig != NULL ) && ( hRenderConfig->roomAcoustics.late_reverb_on ) ) @@ -754,6 +748,9 @@ ivas_error ivas_rend_TDObjRenderFrame( // v_add( reverb_signal[1], output[1], output[1], output_frame ); // } // } + + wmops_sub_end(); + return IVAS_ERR_OK; } #endif diff --git a/lib_rend/ivas_output_init.c b/lib_rend/ivas_output_init.c index 307b29e74a..2cbd476ac1 100644 --- a/lib_rend/ivas_output_init.c +++ b/lib_rend/ivas_output_init.c @@ -29,7 +29,7 @@ the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ - +// VE2AT: keep in lib_rend or move to lib_dec ? #include #include #include "options.h" @@ -171,13 +171,13 @@ void ivas_output_init( hOutSetup->ls_elevation = ls_elevation_CICP2; break; case AUDIO_CONFIG_FOA: - hOutSetup->ambisonics_order = 1; + hOutSetup->ambisonics_order = SBA_FOA_ORDER; break; case AUDIO_CONFIG_HOA2: - hOutSetup->ambisonics_order = 2; + hOutSetup->ambisonics_order = SBA_HOA2_ORDER; break; case AUDIO_CONFIG_HOA3: - hOutSetup->ambisonics_order = 3; + hOutSetup->ambisonics_order = SBA_HOA3_ORDER; break; case AUDIO_CONFIG_5_1: hOutSetup->num_lfe = 1; @@ -515,6 +515,12 @@ void ivas_renderer_select( { *internal_config = output_config; } +#ifdef SPAR_STEREO_NO_DIRAC + else if ( output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO ) + { + *internal_config = AUDIO_CONFIG_FOA; + } +#endif else { *internal_config = AUDIO_CONFIG_HOA3; diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 9366003b08..87babcdb47 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -152,22 +152,16 @@ struct IVAS_REND IVAS_REND_AudioConfig outputConfig; EFAP_WRAPPER efapOutWrapper; IVAS_LSSETUP_CUSTOM_STRUCT customLsOut; - - int8_t enableHeadRotation; /* head rotation flag */ + + int8_t enableHeadRotation; IVAS_REND_HeadRotData headRotData; int8_t rendererConfigEnabled; RENDER_CONFIG_DATA *hRendererConfig; /* Renderer config pointer */ }; -static int32_t limitRendererOutput( - IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ - float *output, /* i/o: I/O buffer */ - const int16_t output_frame, /* i : number of samples per channel in the buffer */ - const float threshold /* i : signal amplitude above which limiting starts to be applied */ -); - -static IVAS_QUATERNION quaternionInit( void ) +static IVAS_QUATERNION quaternionInit( + void ) { IVAS_QUATERNION q; q.w = 1.0f; @@ -175,12 +169,17 @@ static IVAS_QUATERNION quaternionInit( void ) return q; } -static float *getSmplPtr( IVAS_REND_AudioBuffer buffer, uint32_t chnlIdx, uint32_t smplIdx ) +static float *getSmplPtr( + IVAS_REND_AudioBuffer buffer, + uint32_t chnlIdx, + uint32_t smplIdx ) { return buffer.data + chnlIdx * buffer.config.numSamplesPerChannel + smplIdx; } -static void copyBufferTo2dArray( const IVAS_REND_AudioBuffer buffer, float array[MAX_OUTPUT_CHANNELS][L_FRAME48k] ) +static void copyBufferTo2dArray( + const IVAS_REND_AudioBuffer buffer, + float array[MAX_OUTPUT_CHANNELS][L_FRAME48k] ) { uint32_t smplIdx; uint32_t chnlIdx; @@ -195,11 +194,15 @@ static void copyBufferTo2dArray( const IVAS_REND_AudioBuffer buffer, float array array[chnlIdx][smplIdx] = *readPtr++; } } + + return; } -static void accumulate2dArrayToBuffer( float array[MAX_OUTPUT_CHANNELS][L_FRAME48k], IVAS_REND_AudioBuffer *buffer ) +static void accumulate2dArrayToBuffer( + float array[MAX_OUTPUT_CHANNELS][L_FRAME48k], + IVAS_REND_AudioBuffer *buffer ) { - int32_t smplIdx, chnlIdx; + int16_t smplIdx, chnlIdx; float *writePtr; writePtr = buffer->data; @@ -210,6 +213,8 @@ static void accumulate2dArrayToBuffer( float array[MAX_OUTPUT_CHANNELS][L_FRAME4 *writePtr++ += array[chnlIdx][smplIdx]; } } + + return; } /*-------------------------------------------------------------------* @@ -217,8 +222,10 @@ static void accumulate2dArrayToBuffer( float array[MAX_OUTPUT_CHANNELS][L_FRAME4 * * In-place saturation control for multichannel buffers with adaptive release time * - * r: number of clipped output samples + * *-------------------------------------------------------------------*/ + +/*! r: number of clipped output samples */ static int32_t limitRendererOutput( IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ float *output, /* i/o: I/O buffer */ @@ -263,7 +270,8 @@ static int32_t limitRendererOutput( return numClipping; } -static AUDIO_CONFIG rendAudioConfigToIvasAudioConfig( IVAS_REND_AudioConfig rendConfig ) +static AUDIO_CONFIG rendAudioConfigToIvasAudioConfig( // VE2AT: similar is defined again at line 397, why? + IVAS_REND_AudioConfig rendConfig ) { switch ( rendConfig ) { @@ -306,7 +314,8 @@ static AUDIO_CONFIG rendAudioConfigToIvasAudioConfig( IVAS_REND_AudioConfig rend return AUDIO_CONFIG_INVALID; } -static ivas_error validateOutputAudioConfig( IVAS_REND_AudioConfig outConfig ) +static ivas_error validateOutputAudioConfig( + IVAS_REND_AudioConfig outConfig ) { switch ( outConfig ) { @@ -331,13 +340,16 @@ static ivas_error validateOutputAudioConfig( IVAS_REND_AudioConfig outConfig ) return IVAS_ERR_INVALID_OUTPUT_FORMAT; } -IVAS_REND_AudioConfigType getAudioConfigType( IVAS_REND_AudioConfig config ) +IVAS_REND_AudioConfigType getAudioConfigType( + IVAS_REND_AudioConfig config ) { /* By definition, config type is the second byte (from LSB) of IVAS_REND_AudioConfig enum. */ - return ( config & 0xFF00 ) >> 8; + return ( config & 0xFF00 ) >> 8; // VE2AT: MSVC returns warning C4244: 'return': conversion from 'int' to 'IVAS_REND_InputId', possible loss of data } -static ivas_error validateOutputSampleRate( int32_t sampleRate, IVAS_REND_AudioConfig outConfig ) +static ivas_error validateOutputSampleRate( + const int32_t sampleRate, + const IVAS_REND_AudioConfig outConfig ) { if ( getAudioConfigType( outConfig ) != IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL ) { @@ -358,7 +370,9 @@ static ivas_error validateOutputSampleRate( int32_t sampleRate, IVAS_REND_AudioC return IVAS_ERR_INVALID_SAMPLING_RATE; } -ivas_error getAudioConfigNumChannels( IVAS_REND_AudioConfig config, int32_t *numChannels ) +ivas_error getAudioConfigNumChannels( + const IVAS_REND_AudioConfig config, + int16_t *numChannels ) { switch ( config ) { @@ -400,7 +414,8 @@ ivas_error getAudioConfigNumChannels( IVAS_REND_AudioConfig config, int32_t *num return IVAS_ERR_OK; } -AUDIO_CONFIG getIvasAudioConfigFromRendAudioConfig( IVAS_REND_AudioConfig config ) +AUDIO_CONFIG getIvasAudioConfigFromRendAudioConfig( + IVAS_REND_AudioConfig config ) { switch ( config ) { @@ -433,7 +448,10 @@ AUDIO_CONFIG getIvasAudioConfigFromRendAudioConfig( IVAS_REND_AudioConfig config } } -static ivas_error initLimiter( IVAS_LIMITER_HANDLE *phLimiter, int32_t numChannels, int32_t sampleRate ) +static ivas_error initLimiter( + IVAS_LIMITER_HANDLE *phLimiter, + const int16_t numChannels, + const int32_t sampleRate ) { /* If re-initializing with unchanged values, return early */ if ( *phLimiter != NULL && @@ -458,7 +476,8 @@ static ivas_error initLimiter( IVAS_LIMITER_HANDLE *phLimiter, int32_t numChanne return IVAS_ERR_OK; } -static LSSETUP_CUSTOM_STRUCT defaultCustomLs( void ) +static LSSETUP_CUSTOM_STRUCT defaultCustomLs( + void ) { LSSETUP_CUSTOM_STRUCT ls; @@ -476,7 +495,9 @@ static LSSETUP_CUSTOM_STRUCT defaultCustomLs( void ) return ls; } -static ivas_error getSpeakerAzimuths( IVAS_REND_AudioConfig config, const float **azimuths ) +static ivas_error getSpeakerAzimuths( + IVAS_REND_AudioConfig config, + const float **azimuths ) { switch ( config ) { @@ -508,7 +529,9 @@ static ivas_error getSpeakerAzimuths( IVAS_REND_AudioConfig config, const float return IVAS_ERR_OK; } -static ivas_error getSpeakerElevations( IVAS_REND_AudioConfig config, const float **elevations ) +static ivas_error getSpeakerElevations( + IVAS_REND_AudioConfig config, + const float **elevations ) { switch ( config ) { @@ -540,7 +563,9 @@ static ivas_error getSpeakerElevations( IVAS_REND_AudioConfig config, const floa return IVAS_ERR_OK; } -static ivas_error getAmbisonicsOrder( IVAS_REND_AudioConfig config, int16_t *order ) +static ivas_error getAmbisonicsOrder( + IVAS_REND_AudioConfig config, + int16_t *order ) { switch ( config ) { @@ -560,7 +585,9 @@ static ivas_error getAmbisonicsOrder( IVAS_REND_AudioConfig config, int16_t *ord return IVAS_ERR_OK; } -static ivas_error getNumNonLfeChannelsInSpeakerLayout( IVAS_REND_AudioConfig config, int16_t *numNonLfeChannels ) +static ivas_error getNumNonLfeChannelsInSpeakerLayout( + IVAS_REND_AudioConfig config, + int16_t *numNonLfeChannels ) { switch ( config ) { @@ -595,8 +622,8 @@ static ivas_error getMcConfigValues( LSSETUP_CUSTOM_STRUCT inCustomLs, const float **azimuth, const float **elevation, - int32_t *lfe_idx, - int32_t *is_planar ) + int16_t *lfe_idx, + int16_t *is_planar ) { int16_t i; @@ -643,7 +670,10 @@ static ivas_error getMcConfigValues( return IVAS_ERR_OK; } -static ivas_error initEfap( EFAP_WRAPPER *pEfapWrapper, IVAS_REND_AudioConfig outConfig, const LSSETUP_CUSTOM_STRUCT *pCustomLsOut ) +static ivas_error initEfap( + EFAP_WRAPPER *pEfapWrapper, + IVAS_REND_AudioConfig outConfig, + const LSSETUP_CUSTOM_STRUCT *pCustomLsOut ) { ivas_error error; const float *azimuths; @@ -675,11 +705,7 @@ static ivas_error initEfap( EFAP_WRAPPER *pEfapWrapper, IVAS_REND_AudioConfig ou if ( outConfig == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) { - if ( ( error = efap_init_data( &pEfapWrapper->hEfap, - pCustomLsOut->ls_azimuth, - pCustomLsOut->ls_elevation, - pCustomLsOut->num_spk, - EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + if ( ( error = efap_init_data( &pEfapWrapper->hEfap, pCustomLsOut->ls_azimuth, pCustomLsOut->ls_elevation, pCustomLsOut->num_spk, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) { return error; } @@ -698,11 +724,7 @@ static ivas_error initEfap( EFAP_WRAPPER *pEfapWrapper, IVAS_REND_AudioConfig ou { return error; } - if ( ( error = efap_init_data( &pEfapWrapper->hEfap, - azimuths, - elevations, - numNonLfeChannels, - EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + if ( ( error = efap_init_data( &pEfapWrapper->hEfap, azimuths, elevations, numNonLfeChannels, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) { return error; } @@ -711,16 +733,17 @@ static ivas_error initEfap( EFAP_WRAPPER *pEfapWrapper, IVAS_REND_AudioConfig ou return IVAS_ERR_OK; } -static ivas_error getEfapGains( EFAP_WRAPPER efapWrapper, - const float azi, - const float ele, - pan_vector panGains ) +static ivas_error getEfapGains( + EFAP_WRAPPER efapWrapper, + const float azi, + const float ele, + pan_vector panGains ) { pan_vector tmpPanGains; /* tmp pan gain buffer without LFE channels */ float *readPtr; - int32_t i; + int16_t i; int16_t lfeCount; - int32_t numChannels; + int16_t numChannels; ivas_error error; /* EFAP returns an array of gains only for non-LFE speakers */ @@ -794,21 +817,28 @@ static void initHeadRotation( { hIvasRend->headRotData.headPositions[i] = quaternionInit(); } + + return; } -static void initRotMatrix( rotation_matrix rot_mat ) +static void initRotMatrix( + rotation_matrix rot_mat ) { int16_t i; + /* Initialize rotation matrices */ for ( i = 0; i < 3; i++ ) { set_zero( rot_mat[i], 3 ); rot_mat[i][i] = 1.f; } + + return; } -static void initRotGains( rotation_gains rot_gains ) +static void initRotGains( + rotation_gains rot_gains ) { int16_t i; /* Set gains to passthrough */ @@ -817,9 +847,15 @@ static void initRotGains( rotation_gains rot_gains ) set_zero( rot_gains[i], MAX_INPUT_CHANNELS ); rot_gains[i][i] = 1.f; } + + return; } -static void initRendInputBase( input_base *inputBase, IVAS_REND_AudioConfig inConfig, IVAS_REND_InputId id, rendering_context rendCtx ) +static void initRendInputBase( + input_base *inputBase, + const IVAS_REND_AudioConfig inConfig, + const IVAS_REND_InputId id, + const rendering_context rendCtx ) { inputBase->inConfig = inConfig; inputBase->id = id; @@ -832,9 +868,12 @@ static void initRendInputBase( input_base *inputBase, IVAS_REND_AudioConfig inCo inputBase->inputBuffer.data = inputBase->bufferData; set_zero( inputBase->bufferData, MAX_BUFFER_LENGTH ); + + return; } -static IVAS_REND_AudioObjectPosition defaultObjectPosition( void ) +static IVAS_REND_AudioObjectPosition defaultObjectPosition( + void ) { IVAS_REND_AudioObjectPosition pos; @@ -844,7 +883,8 @@ static IVAS_REND_AudioObjectPosition defaultObjectPosition( void ) return pos; } -static rendering_context getRendCtx( IVAS_REND_HANDLE hIvasRend ) +static rendering_context getRendCtx( + IVAS_REND_HANDLE hIvasRend ) { rendering_context ctx; @@ -860,7 +900,8 @@ static rendering_context getRendCtx( IVAS_REND_HANDLE hIvasRend ) return ctx; } -static TDREND_WRAPPER defaultTdRendWrapper( void ) +static TDREND_WRAPPER defaultTdRendWrapper( + void ) { TDREND_WRAPPER w; @@ -871,7 +912,8 @@ static TDREND_WRAPPER defaultTdRendWrapper( void ) return w; } -static CREND_WRAPPER defaultCrendWrapper( void ) +static CREND_WRAPPER defaultCrendWrapper( + void ) { CREND_WRAPPER w; @@ -884,8 +926,8 @@ static CREND_WRAPPER defaultCrendWrapper( void ) static ivas_error setRendInputActiveIsm( void *input, - IVAS_REND_AudioConfig inConfig, - IVAS_REND_InputId id, + const IVAS_REND_AudioConfig inConfig, + const IVAS_REND_InputId id, RENDER_CONFIG_DATA *hRendCfg ) { ivas_error error; @@ -908,10 +950,7 @@ static ivas_error setRendInputActiveIsm( error = IVAS_ERR_OK; if ( outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL ) { - error = ivas_rend_TDObjRendOpen( &inputIsm->tdRendWrapper, - inConfig, - NULL, - *rendCtx.pOutSampleRate ); + error = ivas_rend_TDObjRendOpen( &inputIsm->tdRendWrapper, inConfig, NULL, *rendCtx.pOutSampleRate ); } else if ( outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) { @@ -929,7 +968,8 @@ static ivas_error setRendInputActiveIsm( return IVAS_ERR_OK; } -static void clearInputIsm( input_ism *inputIsm ) +static void clearInputIsm( + input_ism *inputIsm ) { rendering_context rendCtx; @@ -949,16 +989,18 @@ static void clearInputIsm( input_ism *inputIsm ) } } -static void copyLsConversionMatrixToPanMatrix( const LS_CONVERSION_MATRIX *lsConvMatrix, pan_matrix panMatrix ) +static void copyLsConversionMatrixToPanMatrix( + const LS_CONVERSION_MATRIX *lsConvMatrix, + pan_matrix panMatrix ) { - int32_t i; - int32_t inCh, outCh; - int32_t numNonZeroGains; - int32_t numColumns; + int16_t i; + int16_t inCh, outCh; + int16_t numNonZeroGains; + int16_t numColumns; /* Index 0 is special and describes the following values */ numNonZeroGains = lsConvMatrix[0].index; - numColumns = (int32_t) lsConvMatrix[0].value; + numColumns = (int16_t) lsConvMatrix[0].value; for ( i = 1; i < numNonZeroGains + 1; ++i ) { @@ -967,22 +1009,28 @@ static void copyLsConversionMatrixToPanMatrix( const LS_CONVERSION_MATRIX *lsCon panMatrix[inCh][outCh] = lsConvMatrix[i].value; } + + return; } -static void setZeroPanMatrix( pan_matrix panMatrix ) +static void setZeroPanMatrix( + pan_matrix panMatrix ) { - int32_t i; + int16_t i; for ( i = 0; i < MAX_INPUT_CHANNELS; ++i ) { set_zero( panMatrix[i], MAX_OUTPUT_CHANNELS ); } + + return; } /* Note: this only sets non-zero elements, call setZeroPanMatrix() to init first. */ -static void fillIdentityPanMatrix( pan_matrix panMatrix ) +static void fillIdentityPanMatrix( + pan_matrix panMatrix ) { - int32_t i; + int16_t i; for ( i = 0; i < min( MAX_INPUT_CHANNELS, MAX_OUTPUT_CHANNELS ); ++i ) { @@ -990,17 +1038,20 @@ static void fillIdentityPanMatrix( pan_matrix panMatrix ) } } -static ivas_error initMcPanGainsWithIdentMatrix( input_mc *inputMc ) +static ivas_error initMcPanGainsWithIdentMatrix( + input_mc *inputMc ) { fillIdentityPanMatrix( inputMc->panGains ); return IVAS_ERR_OK; } -static ivas_error initMcPanGainsWithConversionMapping( input_mc *inputMc, IVAS_REND_AudioConfig outConfig ) +static ivas_error initMcPanGainsWithConversionMapping( + input_mc *inputMc, + const IVAS_REND_AudioConfig outConfig ) { AUDIO_CONFIG ivasConfigIn, ivasConfigOut; - int32_t i; + int16_t i; ivasConfigIn = rendAudioConfigToIvasAudioConfig( inputMc->base.inConfig ); ivasConfigOut = rendAudioConfigToIvasAudioConfig( outConfig ); @@ -1074,10 +1125,7 @@ static ivas_error initMcPanGainsWithEfap( input_mc *inputMc, IVAS_REND_AudioConf ++outChIdx; } - if ( ( error = getEfapGains( *inputMc->base.ctx.pEfapOutWrapper, - spkAzi[i], - spkEle[i], - inputMc->panGains[outChIdx] ) ) != IVAS_ERR_OK ) + if ( ( error = getEfapGains( *inputMc->base.ctx.pEfapOutWrapper, spkAzi[i], spkEle[i], inputMc->panGains[outChIdx] ) ) != IVAS_ERR_OK ) { return error; } @@ -1095,7 +1143,9 @@ static ivas_error initMcPanGainsWithEfap( input_mc *inputMc, IVAS_REND_AudioConf return IVAS_ERR_OK; } -static ivas_error getRendInputNumChannels( const void *rendInput, int32_t *numInChannels ) +static ivas_error getRendInputNumChannels( + const void *rendInput, + int16_t *numInChannels ) { /* Using a void pointer for this function to be reusable for any input type (input_ism, input_mc, input_sba). Assumptions: @@ -1124,10 +1174,11 @@ static ivas_error getRendInputNumChannels( const void *rendInput, int32_t *numIn return IVAS_ERR_OK; } -static ivas_error initMcPanGainsWithMonoOut( input_mc *inputMc ) +static ivas_error initMcPanGainsWithMonoOut( + input_mc *inputMc ) { - int32_t i; - int32_t numInChannels; + int16_t i; + int16_t numInChannels; ivas_error error; if ( ( error = getRendInputNumChannels( inputMc, &numInChannels ) ) != IVAS_ERR_OK ) @@ -1145,12 +1196,13 @@ static ivas_error initMcPanGainsWithMonoOut( input_mc *inputMc ) return IVAS_ERR_OK; } -static ivas_error initMcPanGainsWithStereoLookup( input_mc *inputMc ) +static ivas_error initMcPanGainsWithStereoLookup( + input_mc *inputMc ) { - int32_t readIdx; - int32_t writeIdx; + int16_t readIdx; + int16_t writeIdx; bool skipSideSpeakers; - int32_t numInChannels; + int16_t numInChannels; ivas_error error; /* Special case - MONO input. @@ -1197,7 +1249,7 @@ static bool configsAreEqual( IVAS_REND_AudioConfig configB, LSSETUP_CUSTOM_STRUCT customLsB ) { - int32_t i; + int16_t i; /* Both input and output are custom LS - compare structs */ if ( configA == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM && configB == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) @@ -1238,7 +1290,9 @@ static bool configsAreEqual( return configA == configB; } -static ivas_error updateMcPanGainsForMcOut( input_mc *inputMc, IVAS_REND_AudioConfig outConfig ) +static ivas_error updateMcPanGainsForMcOut( + input_mc *inputMc, + const IVAS_REND_AudioConfig outConfig ) { ivas_error error; @@ -1254,10 +1308,7 @@ static ivas_error updateMcPanGainsForMcOut( input_mc *inputMc, IVAS_REND_AudioCo +-----------+----------+---------------+-----------+--------------------+ */ - if ( configsAreEqual( inputMc->base.inConfig, - inputMc->customLsInput, - outConfig, - *inputMc->base.ctx.pCustomLsOut ) ) + if ( configsAreEqual( inputMc->base.inConfig, inputMc->customLsInput, outConfig, *inputMc->base.ctx.pCustomLsOut ) ) { error = initMcPanGainsWithIdentMatrix( inputMc ); } @@ -1283,7 +1334,9 @@ static ivas_error updateMcPanGainsForMcOut( input_mc *inputMc, IVAS_REND_AudioCo return error; } -static ivas_error updateMcPanGainsForAmbiOut( input_mc *inputMc, IVAS_REND_AudioConfig outConfig ) +static ivas_error updateMcPanGainsForAmbiOut( + input_mc *inputMc, + const IVAS_REND_AudioConfig outConfig ) { int16_t ch_in, ch_out, lfeIdx; int16_t numNonLfeInChannels, outAmbiOrder; @@ -1316,10 +1369,7 @@ static ivas_error updateMcPanGainsForAmbiOut( input_mc *inputMc, IVAS_REND_Audio { ++ch_out; } - ivas_dirac_dec_get_response( (int16_t) spkAzi[ch_in], - (int16_t) spkEle[ch_in], - inputMc->panGains[ch_out], - outAmbiOrder ); + ivas_dirac_dec_get_response( (int16_t) spkAzi[ch_in], (int16_t) spkEle[ch_in], inputMc->panGains[ch_out], outAmbiOrder ); } } else @@ -1339,19 +1389,18 @@ static ivas_error updateMcPanGainsForAmbiOut( input_mc *inputMc, IVAS_REND_Audio } } - ivas_dirac_dec_get_response( (int16_t) spkAzi[ch_in], - (int16_t) spkEle[ch_in], - inputMc->panGains[ch_out], - outAmbiOrder ); + ivas_dirac_dec_get_response( (int16_t) spkAzi[ch_in], (int16_t) spkEle[ch_in], inputMc->panGains[ch_out], outAmbiOrder ); } } return IVAS_ERR_OK; } -static ivas_error updateMcPanGains( input_mc *inputMc, IVAS_REND_AudioConfig outConfig ) +static ivas_error updateMcPanGains( + input_mc *inputMc, + const IVAS_REND_AudioConfig outConfig ) { - int32_t i; + int16_t i; ivas_error error; /* Reset to all zeros - some functions below only write non-zero elements. */ @@ -1410,7 +1459,7 @@ static ivas_error updateMcPanGains( input_mc *inputMc, IVAS_REND_AudioConfig out See issue: https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec/-/issues/81 */ static void tmpFixBuggyTdBinRendInit( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd ) { - int32_t i, j; + int16_t i, j; for ( i = 0; i < hBinRendererTd->NumOfSrcs; ++i ) { @@ -1427,8 +1476,8 @@ static void tmpFixBuggyTdBinRendInit( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRen static ivas_error initMcBinauralRendering( input_mc *inputMc, - IVAS_REND_AudioConfig inConfig, - IVAS_REND_AudioConfig outConfig, + const IVAS_REND_AudioConfig inConfig, + const IVAS_REND_AudioConfig outConfig, RENDER_CONFIG_DATA *hRendCfg ) { ivas_error error; @@ -1465,10 +1514,7 @@ static ivas_error initMcBinauralRendering( // if ( initTDRend ) { - if ( ( error = ivas_rend_TDObjRendOpen( &inputMc->tdRendWrapper, - inConfig, - &inputMc->customLsInput, - outSampleRate ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_rend_TDObjRendOpen( &inputMc->tdRendWrapper, inConfig, &inputMc->customLsInput, outSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -1548,8 +1594,8 @@ static IVAS_REND_LfeRouting defaultLfeRouting( static ivas_error setRendInputActiveMc( void *input, - IVAS_REND_AudioConfig inConfig, - IVAS_REND_InputId id, + const IVAS_REND_AudioConfig inConfig, + const IVAS_REND_InputId id, RENDER_CONFIG_DATA *hRendCfg ) { ivas_error error; @@ -1567,10 +1613,7 @@ static ivas_error setRendInputActiveMc( inputMc->tdRendWrapper = defaultTdRendWrapper(); inputMc->crendWrapper = defaultCrendWrapper(); initRotGains( inputMc->rot_gains_prev ); - inputMc->lfeRouting = defaultLfeRouting( inConfig, - inputMc->customLsInput, - outConfig, - *inputMc->base.ctx.pCustomLsOut ); + inputMc->lfeRouting = defaultLfeRouting( inConfig, inputMc->customLsInput, outConfig, *inputMc->base.ctx.pCustomLsOut ); if ( outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL || outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) { @@ -1588,7 +1631,8 @@ static ivas_error setRendInputActiveMc( return IVAS_ERR_OK; } -static void clearInputMc( input_mc *inputMc ) +static void clearInputMc( + input_mc *inputMc ) { rendering_context rendCtx; @@ -1610,11 +1654,13 @@ static void clearInputMc( input_mc *inputMc ) ivas_td_binaural_close( &inputMc->tdRendWrapper.hBinRendererTd ); inputMc->tdRendWrapper.hHrtfTD = NULL; } + + return; } static ivas_error initSbaPanGainsForMcOut( input_sba *inputSba, - IVAS_REND_AudioConfig outConfig, + const IVAS_REND_AudioConfig outConfig, const LSSETUP_CUSTOM_STRUCT *outSetupCustom ) { int16_t ambiOrderIn; @@ -1682,7 +1728,9 @@ static ivas_error initSbaPanGainsForMcOut( return IVAS_ERR_OK; } -static ivas_error initSbaPanGainsForSbaOut( input_sba *inputSba, IVAS_REND_AudioConfig outConfig ) +static ivas_error initSbaPanGainsForSbaOut( + input_sba *inputSba, + const IVAS_REND_AudioConfig outConfig ) { ivas_error error; error = IVAS_ERR_OK; @@ -1698,7 +1746,10 @@ static ivas_error initSbaPanGainsForSbaOut( input_sba *inputSba, IVAS_REND_Audio return error; } -static ivas_error updateSbaPanGains( input_sba *inputSba, IVAS_REND_AudioConfig outConfig, RENDER_CONFIG_DATA *hRendCfg ) +static ivas_error updateSbaPanGains( + input_sba *inputSba, + const IVAS_REND_AudioConfig outConfig, + RENDER_CONFIG_DATA *hRendCfg ) { ivas_error error; IVAS_REND_AudioConfig inConfig; @@ -1722,22 +1773,14 @@ static ivas_error updateSbaPanGains( input_sba *inputSba, IVAS_REND_AudioConfig switch ( outConfig ) { case IVAS_REND_AUDIO_CONFIG_BINAURAL: - error = ivas_rend_openCrend( &inputSba->crendWrapper, - inConfig, - outConfig, - hRendCfg, - *rendCtx.pOutSampleRate ); + error = ivas_rend_openCrend( &inputSba->crendWrapper, inConfig, outConfig, hRendCfg, *rendCtx.pOutSampleRate ); 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; } - error = ivas_rend_openCrend( &inputSba->crendWrapper, - IVAS_REND_AUDIO_CONFIG_7_1_4, - outConfig, - hRendCfg, - *rendCtx.pOutSampleRate ); + error = ivas_rend_openCrend( &inputSba->crendWrapper, IVAS_REND_AUDIO_CONFIG_7_1_4, outConfig, hRendCfg, *rendCtx.pOutSampleRate ); break; default: return IVAS_ERR_INVALID_OUTPUT_FORMAT; @@ -1757,8 +1800,8 @@ static ivas_error updateSbaPanGains( input_sba *inputSba, IVAS_REND_AudioConfig static ivas_error setRendInputActiveSba( void *input, - IVAS_REND_AudioConfig inConfig, - IVAS_REND_InputId id, + const IVAS_REND_AudioConfig inConfig, + const IVAS_REND_InputId id, RENDER_CONFIG_DATA *hRendCfg ) { ivas_error error; @@ -1783,7 +1826,8 @@ static ivas_error setRendInputActiveSba( return error; } -static void clearInputSba( input_sba *inputSba ) +static void clearInputSba( + input_sba *inputSba ) { rendering_context rendCtx; @@ -1796,17 +1840,19 @@ static void clearInputSba( input_sba *inputSba ) { ivas_rend_closeCrend( &inputSba->crendWrapper ); } + + return; } ivas_error IVAS_REND_Open( IVAS_REND_HANDLE *phIvasRend, - int32_t outputSampleRate, - IVAS_REND_AudioConfig outConfig ) + const int32_t outputSampleRate, + const IVAS_REND_AudioConfig outConfig ) { int16_t i; IVAS_REND_HANDLE hIvasRend; ivas_error error; - int32_t numOutChannels; + int16_t numOutChannels; /*-----------------------------------------------------------------* * Validate function arguments @@ -1858,36 +1904,28 @@ ivas_error IVAS_REND_Open( /* Initialize inputs */ for ( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i ) { - initRendInputBase( &hIvasRend->inputsIsm[i].base, - IVAS_REND_AUDIO_CONFIG_UNKNOWN, - 0, - getRendCtx( hIvasRend ) ); + initRendInputBase( &hIvasRend->inputsIsm[i].base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, getRendCtx( hIvasRend ) ); hIvasRend->inputsIsm[i].crendWrapper.hCrend = NULL; 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 ) ); + initRendInputBase( &hIvasRend->inputsMc[i].base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, getRendCtx( hIvasRend ) ); hIvasRend->inputsMc[i].efapInWrapper.hEfap = NULL; hIvasRend->inputsMc[i].crendWrapper.hCrend = NULL; 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 ) ); + initRendInputBase( &hIvasRend->inputsSba[i].base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, getRendCtx( hIvasRend ) ); hIvasRend->inputsSba[i].crendWrapper.hCrend = NULL; } return IVAS_ERR_OK; } -static LSSETUP_CUSTOM_STRUCT makeCustomLsSetup( IVAS_CUSTOM_LS_DATA rendCustomLsLayout ) +static LSSETUP_CUSTOM_STRUCT makeCustomLsSetup( + const IVAS_CUSTOM_LS_DATA rendCustomLsLayout ) { int16_t i; LSSETUP_CUSTOM_STRUCT customLs; @@ -1913,9 +1951,10 @@ static LSSETUP_CUSTOM_STRUCT makeCustomLsSetup( IVAS_CUSTOM_LS_DATA rendCustomLs return customLs; } -static ivas_error validateCustomLsLayout( IVAS_CUSTOM_LS_DATA layout ) +static ivas_error validateCustomLsLayout( + const IVAS_CUSTOM_LS_DATA layout ) { - int32_t i; + int16_t i; /* Negative number of speakers or LFEs makes no sense */ if ( layout.num_spk < 0 || layout.num_lfe < 0 ) @@ -1941,11 +1980,10 @@ static ivas_error validateCustomLsLayout( IVAS_CUSTOM_LS_DATA layout ) ivas_error IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( IVAS_REND_HANDLE hIvasRend, - IVAS_CUSTOM_LS_DATA layout ) + const IVAS_CUSTOM_LS_DATA layout ) { - int32_t numOutChannels; + int16_t i, numOutChannels; ivas_error error; - int32_t i; input_mc *inputMc; input_sba *inputSba; @@ -1974,14 +2012,10 @@ ivas_error IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( { return error; } - initLimiter( &hIvasRend->hLimiter, - numOutChannels, - hIvasRend->sampleRateOut ); + initLimiter( &hIvasRend->hLimiter, numOutChannels, hIvasRend->sampleRateOut ); /* Re-initialize EFAP - output layout has changed or has been fully defined for the first time */ - initEfap( &hIvasRend->efapOutWrapper, - hIvasRend->outputConfig, - &hIvasRend->customLsOut ); + initEfap( &hIvasRend->efapOutWrapper, hIvasRend->outputConfig, &hIvasRend->customLsOut ); /* Re-initialize panning gains for each active MC input, This includes re-initializing * LFE handling for the new output layout, which means custom LFE handling is overwritten, @@ -1994,10 +2028,9 @@ ivas_error IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( /* Input inactive, skip. */ continue; } - inputMc->lfeRouting = defaultLfeRouting( inputMc->base.inConfig, - inputMc->customLsInput, - hIvasRend->outputConfig, - *inputMc->base.ctx.pCustomLsOut ); + + inputMc->lfeRouting = defaultLfeRouting( inputMc->base.inConfig, inputMc->customLsInput, hIvasRend->outputConfig, *inputMc->base.ctx.pCustomLsOut ); + if ( ( error = updateMcPanGains( inputMc, hIvasRend->outputConfig ) ) != IVAS_ERR_OK ) { return error; @@ -2024,7 +2057,7 @@ ivas_error IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( ivas_error IVAS_REND_NumOutChannels( IVAS_REND_CONST_HANDLE hIvasRend, - int32_t *numOutChannels ) + int16_t *numOutChannels ) { ivas_error error; @@ -2056,7 +2089,9 @@ ivas_error IVAS_REND_NumOutChannels( return IVAS_ERR_OK; } -static IVAS_REND_InputId makeInputId( IVAS_REND_AudioConfig config, int32_t inputIndex ) +static IVAS_REND_InputId makeInputId( + IVAS_REND_AudioConfig config, + const int32_t inputIndex ) { /* Put config type in second byte (from LSB), put index + 1 in first byte * @@ -2064,7 +2099,10 @@ static IVAS_REND_InputId makeInputId( IVAS_REND_AudioConfig config, int32_t inpu return getAudioConfigType( config ) << 8 | ( inputIndex + 1 ); } -static ivas_error getInputById( IVAS_REND_HANDLE hIvasRend, IVAS_REND_InputId inputId, void **ppInput ) +static ivas_error getInputById( + IVAS_REND_HANDLE hIvasRend, + IVAS_REND_InputId inputId, + void **ppInput ) { int32_t inputIndex; IVAS_REND_AudioConfigType configType; @@ -2119,7 +2157,10 @@ static ivas_error getInputById( IVAS_REND_HANDLE hIvasRend, IVAS_REND_InputId in } /* Unfortunately code duplication here is the only way to avoid warnings about const casting */ -static ivas_error getConstInputById( IVAS_REND_CONST_HANDLE hIvasRend, IVAS_REND_InputId inputId, const void **ppInput ) +static ivas_error getConstInputById( + IVAS_REND_CONST_HANDLE hIvasRend, + const IVAS_REND_InputId inputId, + const void **ppInput ) { int32_t inputIndex; IVAS_REND_AudioConfigType configType; @@ -2260,20 +2301,14 @@ ivas_error IVAS_REND_AddInput( } /* Find first free input in array corresponding to input type */ - if ( ( error = findFreeInputSlot( inputsArray, - inputStructSize, - maxNumInputsOfType, - &inputIndex ) ) != IVAS_ERR_OK ) + if ( ( error = findFreeInputSlot( inputsArray, inputStructSize, maxNumInputsOfType, &inputIndex ) ) != IVAS_ERR_OK ) { return error; } *inputId = makeInputId( inConfig, inputIndex ); - if ( ( error = activateInput( (uint8_t *) inputsArray + inputStructSize * inputIndex, - inConfig, - *inputId, - hIvasRend->hRendererConfig ) ) != IVAS_ERR_OK ) + if ( ( error = activateInput( (uint8_t *) inputsArray + inputStructSize * inputIndex, inConfig, *inputId, hIvasRend->hRendererConfig ) ) != IVAS_ERR_OK ) { return error; } @@ -2283,8 +2318,8 @@ ivas_error IVAS_REND_AddInput( ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout( IVAS_REND_HANDLE hIvasRend, - IVAS_REND_InputId inputId, - IVAS_CUSTOM_LS_DATA layout ) + const IVAS_REND_InputId inputId, + const IVAS_CUSTOM_LS_DATA layout ) { input_mc *inputMc; ivas_error error; @@ -2316,10 +2351,7 @@ ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout( * set for the MC input. */ inputMc->customLsInput = makeCustomLsSetup( layout ); - inputMc->lfeRouting = defaultLfeRouting( inputMc->base.inConfig, - inputMc->customLsInput, - hIvasRend->outputConfig, - *inputMc->base.ctx.pCustomLsOut ); + inputMc->lfeRouting = defaultLfeRouting( inputMc->base.inConfig, inputMc->customLsInput, hIvasRend->outputConfig, *inputMc->base.ctx.pCustomLsOut ); initEfap( &inputMc->efapInWrapper, inputMc->base.inConfig, &inputMc->customLsInput ); @@ -2340,8 +2372,8 @@ ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout( ivas_error IVAS_REND_SetInputGain( IVAS_REND_HANDLE hIvasRend, - IVAS_REND_InputId inputId, - float gain /* linear gain, not in dB */ + const IVAS_REND_InputId inputId, + const float gain /* linear gain, not in dB */ ) { input_base *inputBase; @@ -2365,7 +2397,8 @@ ivas_error IVAS_REND_SetInputGain( return IVAS_ERR_OK; } -static int32_t getNumLfeChannels( input_mc *inputMc ) +static int32_t getNumLfeChannels( + input_mc *inputMc ) { switch ( inputMc->base.inConfig ) { @@ -2386,8 +2419,8 @@ static int32_t getNumLfeChannels( input_mc *inputMc ) ivas_error IVAS_REND_SetInputLfeRouting( IVAS_REND_HANDLE hIvasRend, - IVAS_REND_InputId inputId, - IVAS_REND_LfeRouting lfeRouting ) + const IVAS_REND_InputId inputId, + const IVAS_REND_LfeRouting lfeRouting ) { input_base *pInputBase; input_mc *pInputMc; @@ -2428,7 +2461,7 @@ ivas_error IVAS_REND_SetInputLfeRouting( ivas_error IVAS_REND_RemoveInput( IVAS_REND_HANDLE hIvasRend, - IVAS_REND_InputId inputId ) + const IVAS_REND_InputId inputId ) { ivas_error error; input_base *inputBase; @@ -2466,8 +2499,8 @@ ivas_error IVAS_REND_RemoveInput( ivas_error IVAS_REND_GetInputNumChannels( IVAS_REND_CONST_HANDLE hIvasRend, - IVAS_REND_InputId inputId, - int32_t *numChannels ) + const IVAS_REND_InputId inputId, + int16_t *numChannels ) { ivas_error error; const input_base *pInput; @@ -2552,12 +2585,12 @@ ivas_error IVAS_REND_GetDelay( ivas_error IVAS_REND_FeedInputAudio( IVAS_REND_HANDLE hIvasRend, - IVAS_REND_InputId inputId, - IVAS_REND_ReadOnlyAudioBuffer inputAudio ) + const IVAS_REND_InputId inputId, + const IVAS_REND_ReadOnlyAudioBuffer inputAudio ) { ivas_error error; input_base *inputBase; - int32_t numInputChannels; + int16_t numInputChannels; /*-----------------------------------------------------------------* * Validate function arguments @@ -2597,9 +2630,7 @@ ivas_error IVAS_REND_FeedInputAudio( inputBase->inputBuffer.config = inputAudio.config; - mvr2r( inputAudio.data, - inputBase->inputBuffer.data, - inputAudio.config.numSamplesPerChannel * inputAudio.config.numChannels ); + mvr2r( inputAudio.data, inputBase->inputBuffer.data, inputAudio.config.numSamplesPerChannel * inputAudio.config.numChannels ); inputBase->numNewSamplesPerChannel = inputAudio.config.numSamplesPerChannel; @@ -2608,8 +2639,8 @@ ivas_error IVAS_REND_FeedInputAudio( ivas_error IVAS_REND_FeedInputObjectMetadata( IVAS_REND_HANDLE hIvasRend, - IVAS_REND_InputId inputId, - IVAS_REND_AudioObjectPosition objectPosition ) + const IVAS_REND_InputId inputId, + const IVAS_REND_AudioObjectPosition objectPosition ) { input_base *inputBase; input_ism *inputIsm; @@ -2873,6 +2904,8 @@ static void renderBufferChannel( IVAS_REND_AudioBuffer outAudio ) { renderBufferChannelLerp( inAudio, inChannelIdx, outputGains, NULL, outAudio ); + + return; } static ivas_error rotateFrameMc( @@ -2887,20 +2920,18 @@ static ivas_error rotateFrameMc( { int16_t i; int16_t subframe_idx, subframe_len; - int16_t azimuth, elevation; - int32_t is_planar_setup, lfe_idx; - int32_t nchan; - int32_t ch_in, ch_out; - int32_t ch_in_woLFE, ch_out_woLFE; - + int16_t is_planar_setup, lfe_idx; + int16_t nchan; + int16_t ch_in, ch_out; + int16_t ch_in_woLFE, ch_out_woLFE; float *readPtr, *writePtr; const float *ls_azimuth, *ls_elevation; rotation_matrix Rmat; rotation_gains gains; float tmp_gains[MAX_INPUT_CHANNELS]; - wmops_sub_start("rotateFrameMc"); + wmops_sub_start( "rotateFrameMc" ); if ( inConfig != IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) { @@ -2911,12 +2942,7 @@ static ivas_error rotateFrameMc( nchan = inCustomLs.num_spk + inCustomLs.num_lfe; } - getMcConfigValues( inConfig, - inCustomLs, - &ls_azimuth, - &ls_elevation, - &lfe_idx, - &is_planar_setup ); + getMcConfigValues( inConfig, inCustomLs, &ls_azimuth, &ls_elevation, &lfe_idx, &is_planar_setup ); /* initialize gains to passthrough */ for ( ch_in = 0; ch_in < nchan; ch_in++ ) @@ -2944,20 +2970,11 @@ static ivas_error rotateFrameMc( ch_in_woLFE = ( ( lfe_idx > 0 ) && ( ch_in >= lfe_idx ) ) ? ch_in - 1 : ch_in; /* gains for current subframe rotation */ - rotateAziEle( ls_azimuth[ch_in_woLFE], - ls_elevation[ch_in_woLFE], - &azimuth, - &elevation, - Rmat, - (int16_t) is_planar_setup ); + rotateAziEle( ls_azimuth[ch_in_woLFE], ls_elevation[ch_in_woLFE], &azimuth, &elevation, Rmat, is_planar_setup ); if ( hEFAPdata != NULL && ( ls_azimuth[ch_in_woLFE] != azimuth || ls_elevation[ch_in_woLFE] != elevation ) ) { - efap_determine_gains( hEFAPdata, - tmp_gains, - azimuth, - elevation, - EFAP_MODE_EFAP ); + efap_determine_gains( hEFAPdata, tmp_gains, azimuth, elevation, EFAP_MODE_EFAP ); for ( ch_out = 0; ch_out < nchan; ch_out++ ) { @@ -3017,13 +3034,12 @@ static ivas_error rotateFrameSba( int16_t m1, m2; int16_t shd_rot_max_order; int16_t subframe_idx, subframe_len; - float *readPtr, *writePtr; rotation_matrix Rmat; float tmpRot[2 * HEADROT_ORDER + 1]; rotation_gains gains; - wmops_sub_start("rotateFrameSba"); + wmops_sub_start( "rotateFrameSba" ); getAmbisonicsOrder( inConfig, &shd_rot_max_order ); @@ -3109,10 +3125,9 @@ static ivas_error renderIsmToBinaural( IVAS_REND_AudioBuffer outAudio ) { float tmpTDRendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - ivas_error error; - wmops_sub_start("renderIsmToBinaural"); + wmops_sub_start( "renderIsmToBinaural" ); copyBufferTo2dArray( ismInput->base.inputBuffer, tmpTDRendBuffer ); @@ -3143,11 +3158,10 @@ static ivas_error renderIsmToBinauralRoom( int16_t i; int16_t azi_rot, ele_rot; int16_t subframe_idx, subframe_len; - int32_t tmp; + int16_t tmp; rotation_matrix Rmat; float tmpCrendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; IVAS_QUATERNION quat; - ivas_error error; pan_vector currentPanGains; pan_vector previousPanGains; @@ -3155,7 +3169,7 @@ static ivas_error renderIsmToBinauralRoom( IVAS_REND_AudioObjectPosition rotatedPos; const IVAS_REND_HeadRotData *headRotData; - wmops_sub_start("renderIsmToBinauralRoom"); + wmops_sub_start( "renderIsmToBinauralRoom" ); headRotData = ismInput->base.ctx.pHeadRotData; rotatedPos = defaultObjectPosition(); @@ -3182,12 +3196,7 @@ static ivas_error renderIsmToBinauralRoom( /* previous position gains */ if ( headRotData->headRotEnabled ) { - rotateAziEle( ismInput->previousPos.azimuth, - ismInput->previousPos.elevation, - &azi_rot, - &ele_rot, - ismInput->rot_mat_prev, - 0 ); + rotateAziEle( ismInput->previousPos.azimuth, ismInput->previousPos.elevation, &azi_rot, &ele_rot, ismInput->rot_mat_prev, 0 ); rotatedPos.azimuth = (float) azi_rot; rotatedPos.elevation = (float) ele_rot; } @@ -3202,12 +3211,7 @@ static ivas_error renderIsmToBinauralRoom( /* current position gains */ if ( headRotData->headRotEnabled ) { - rotateAziEle( ismInput->currentPos.azimuth, - ismInput->currentPos.elevation, - &azi_rot, - &ele_rot, - Rmat, - 0 ); + rotateAziEle( ismInput->currentPos.azimuth, ismInput->currentPos.elevation, &azi_rot, &ele_rot, Rmat, 0 ); rotatedPos.azimuth = (float) azi_rot; rotatedPos.elevation = (float) ele_rot; } @@ -3227,23 +3231,15 @@ static ivas_error renderIsmToBinauralRoom( /* intermediate rendering to 7_1_4 */ tmpMcBuffer = ismInput->base.inputBuffer; getAudioConfigNumChannels( IVAS_REND_AUDIO_CONFIG_7_1_4, &tmp ); - tmpMcBuffer.config.numChannels = (int16_t) tmp; + tmpMcBuffer.config.numChannels = tmp; tmpMcBuffer.data = count_malloc( tmpMcBuffer.config.numSamplesPerChannel * tmpMcBuffer.config.numChannels * sizeof( float ) ); set_zero( tmpMcBuffer.data, tmpMcBuffer.config.numSamplesPerChannel * tmpMcBuffer.config.numChannels ); - renderBufferChannelLerp( ismInput->base.inputBuffer, - 0, - currentPanGains, - previousPanGains, - tmpMcBuffer ); + renderBufferChannelLerp( ismInput->base.inputBuffer, 0, currentPanGains, previousPanGains, tmpMcBuffer ); copyBufferTo2dArray( tmpMcBuffer, tmpCrendBuffer ); - ivas_rend_crendProcess( &ismInput->crendWrapper, - IVAS_REND_AUDIO_CONFIG_7_1_4, - IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM, - tmpCrendBuffer, - *ismInput->base.ctx.pOutSampleRate ); + ivas_rend_crendProcess( &ismInput->crendWrapper, IVAS_REND_AUDIO_CONFIG_7_1_4, IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM, tmpCrendBuffer, *ismInput->base.ctx.pOutSampleRate ); accumulate2dArrayToBuffer( tmpCrendBuffer, &outAudio ); @@ -3256,37 +3252,27 @@ static ivas_error renderIsmToBinauralRoom( static ivas_error renderIsmToMc( const input_ism *ismInput, - IVAS_REND_AudioBuffer outAudio ) + const IVAS_REND_AudioBuffer outAudio ) { pan_vector currentPanGains; pan_vector previousPanGains; ivas_error error; - wmops_sub_start("renderIsmToMc"); + wmops_sub_start( "renderIsmToMc" ); /* TODO(sgi): Possible optimization: less processing needed if position didn't change */ - if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, - ismInput->currentPos.azimuth, - ismInput->currentPos.elevation, - currentPanGains ) ) != IVAS_ERR_OK ) + if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, ismInput->currentPos.azimuth, ismInput->currentPos.elevation, currentPanGains ) ) != IVAS_ERR_OK ) { return error; } - if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, - ismInput->previousPos.azimuth, - ismInput->previousPos.elevation, - previousPanGains ) ) != IVAS_ERR_OK ) + if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, ismInput->previousPos.azimuth, ismInput->previousPos.elevation, previousPanGains ) ) != IVAS_ERR_OK ) { return error; } /* Assume num channels in audio buffer to be 1. * This should have been validated in IVAS_REND_FeedInputAudio() */ - renderBufferChannelLerp( ismInput->base.inputBuffer, - 0, - currentPanGains, - previousPanGains, - outAudio ); + renderBufferChannelLerp( ismInput->base.inputBuffer, 0, currentPanGains, previousPanGains, outAudio ); wmops_sub_end(); @@ -3295,17 +3281,17 @@ static ivas_error renderIsmToMc( static ivas_error renderIsmToSba( const input_ism *ismInput, - IVAS_REND_AudioConfig outConfig, - IVAS_REND_AudioBuffer outAudio ) + const IVAS_REND_AudioConfig outConfig, + const IVAS_REND_AudioBuffer outAudio ) { int16_t ambiOrderOut; - int32_t numOutChannels; + int16_t numOutChannels; pan_vector currentPanGains; pan_vector previousPanGains; ivas_error error; error = IVAS_ERR_OK; - wmops_sub_start("renderIsmToSba"); + wmops_sub_start( "renderIsmToSba" ); if ( ( error = getAudioConfigNumChannels( outConfig, &numOutChannels ) ) != IVAS_ERR_OK ) { @@ -3316,10 +3302,7 @@ static ivas_error renderIsmToSba( return error; } - ivas_dirac_dec_get_response( (int16_t) ismInput->previousPos.azimuth, - (int16_t) ismInput->previousPos.elevation, - previousPanGains, - (int16_t) ambiOrderOut ); + ivas_dirac_dec_get_response( (int16_t) ismInput->previousPos.azimuth, (int16_t) ismInput->previousPos.elevation, previousPanGains, ambiOrderOut ); if ( ( ismInput->currentPos.azimuth == ismInput->previousPos.azimuth ) && ( ismInput->currentPos.elevation == ismInput->previousPos.elevation ) ) @@ -3328,19 +3311,12 @@ static ivas_error renderIsmToSba( } else { - ivas_dirac_dec_get_response( (int16_t) ismInput->currentPos.azimuth, - (int16_t) ismInput->currentPos.elevation, - currentPanGains, - (int16_t) ambiOrderOut ); + ivas_dirac_dec_get_response( (int16_t) ismInput->currentPos.azimuth, (int16_t) ismInput->currentPos.elevation, currentPanGains, ambiOrderOut ); } /* Assume num channels in audio buffer to be 1. * This should have been validated in IVAS_REND_FeedInputAudio() */ - renderBufferChannelLerp( ismInput->base.inputBuffer, - 0, - currentPanGains, - previousPanGains, - outAudio ); + renderBufferChannelLerp( ismInput->base.inputBuffer, 0, currentPanGains, previousPanGains, outAudio ); wmops_sub_end(); @@ -3349,8 +3325,8 @@ static ivas_error renderIsmToSba( static ivas_error renderInputIsm( input_ism *ismInput, - IVAS_REND_AudioConfig outConfig, - IVAS_REND_AudioBuffer outAudio ) + const IVAS_REND_AudioConfig outConfig, + const IVAS_REND_AudioBuffer outAudio ) { ivas_error error; IVAS_REND_AudioBuffer inAudio; @@ -3365,10 +3341,7 @@ static ivas_error renderInputIsm( ismInput->base.numNewSamplesPerChannel = 0; /* Apply input gain to new audio */ - v_multc( inAudio.data, - ismInput->base.gain, - inAudio.data, - inAudio.config.numSamplesPerChannel * inAudio.config.numChannels ); + v_multc( inAudio.data, ismInput->base.gain, inAudio.data, inAudio.config.numSamplesPerChannel * inAudio.config.numChannels ); switch ( getAudioConfigType( outConfig ) ) @@ -3408,7 +3381,7 @@ static ivas_error renderActiveInputsIsm( IVAS_REND_HANDLE hIvasRend, IVAS_REND_AudioBuffer outAudio ) { - int32_t i; + int16_t i; input_ism *pCurrentInput; ivas_error error; @@ -3419,9 +3392,7 @@ static ivas_error renderActiveInputsIsm( /* Skip inactive inputs */ continue; } - if ( ( error = renderInputIsm( pCurrentInput, - hIvasRend->outputConfig, - outAudio ) ) != IVAS_ERR_OK ) + if ( ( error = renderInputIsm( pCurrentInput, hIvasRend->outputConfig, outAudio ) ) != IVAS_ERR_OK ) { return error; } @@ -3441,7 +3412,7 @@ static ivas_error renderLfeToBinaural( assert( ( outAudio.config.numChannels == 2 ) && "Must be binaural output" ); - wmops_sub_start("renderLfeToBinaural"); + wmops_sub_start( "renderLfeToBinaural" ); gain = GAIN_LFE; @@ -3481,7 +3452,7 @@ static ivas_error renderLfeToBinaural( static ivas_error renderMcToBinaural( input_mc *mcInput, - IVAS_REND_AudioConfig outConfig, + const IVAS_REND_AudioConfig outConfig, IVAS_REND_AudioBuffer outAudio ) { int8_t headRotEnabled; @@ -3491,7 +3462,7 @@ static ivas_error renderMcToBinaural( ivas_error error; IVAS_REND_AudioBuffer tmpRotBuffer; - wmops_sub_start("renderMcToBinaural"); + wmops_sub_start( "renderMcToBinaural" ); headRotEnabled = mcInput->base.ctx.pHeadRotData->headRotEnabled; inConfig = mcInput->base.inConfig; @@ -3539,11 +3510,7 @@ static ivas_error renderMcToBinaural( } /* call CREND */ - if ( ( error = ivas_rend_crendProcess( &mcInput->crendWrapper, - mcInput->base.inConfig, - outConfig, - tmpRendBuffer, - *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_rend_crendProcess( &mcInput->crendWrapper, mcInput->base.inConfig, outConfig, tmpRendBuffer, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -3561,7 +3528,7 @@ static ivas_error renderMcToBinaural( static ivas_error renderMcToBinauralRoom( input_mc *mcInput, - IVAS_REND_AudioConfig outConfig, + const IVAS_REND_AudioConfig outConfig, IVAS_REND_AudioBuffer outAudio ) { float tmpCrendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; @@ -3569,7 +3536,7 @@ static ivas_error renderMcToBinauralRoom( ivas_error error; IVAS_REND_AudioBuffer tmpRotBuffer; - wmops_sub_start("renderMcToBinauralRoom"); + wmops_sub_start( "renderMcToBinauralRoom" ); /* apply rotation */ if ( mcInput->base.ctx.pHeadRotData->headRotEnabled ) @@ -3595,11 +3562,7 @@ static ivas_error renderMcToBinauralRoom( } /* call CREND */ - if ( ( error = ivas_rend_crendProcess( &mcInput->crendWrapper, - mcInput->base.inConfig, - outConfig, - tmpCrendBuffer, - *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_rend_crendProcess( &mcInput->crendWrapper, mcInput->base.inConfig, outConfig, tmpCrendBuffer, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -3617,20 +3580,21 @@ static ivas_error renderMcToBinauralRoom( static ivas_error renderMcCustomLsToBinauralRoom( input_mc *mcInput, - IVAS_REND_AudioConfig outConfig, + const IVAS_REND_AudioConfig outConfig, IVAS_REND_AudioBuffer outAudio ) { int8_t headRotEnabled; int16_t i; - int32_t tmp; + int16_t tmp; float tmpCrendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - ivas_error error; IVAS_REND_AudioBuffer tmpRotBuffer; IVAS_REND_AudioBuffer tmpMcBuffer; IVAS_REND_AudioBuffer *tmpBufPtr; - wmops_sub_start("renderMcCustomLsToBinauralRoom"); + wmops_sub_start( "renderMcCustomLsToBinauralRoom" ); + + tmpRotBuffer = outAudio; /* avoid compilation warning */ headRotEnabled = mcInput->base.ctx.pHeadRotData->headRotEnabled; @@ -3660,19 +3624,12 @@ static ivas_error renderMcCustomLsToBinauralRoom( tmpBufPtr = ( headRotEnabled ) ? &tmpRotBuffer : &mcInput->base.inputBuffer; for ( i = 0; i < mcInput->base.inputBuffer.config.numChannels; i++ ) { - renderBufferChannel( *tmpBufPtr, - i, - mcInput->panGains[i], - tmpMcBuffer ); + renderBufferChannel( *tmpBufPtr, i, mcInput->panGains[i], tmpMcBuffer ); } copyBufferTo2dArray( tmpMcBuffer, tmpCrendBuffer ); /* call CREND */ - if ( ( error = ivas_rend_crendProcess( &mcInput->crendWrapper, - IVAS_REND_AUDIO_CONFIG_7_1_4, - outConfig, - tmpCrendBuffer, - *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_rend_crendProcess( &mcInput->crendWrapper, IVAS_REND_AUDIO_CONFIG_7_1_4, outConfig, tmpCrendBuffer, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -3697,10 +3654,10 @@ static ivas_error renderMcToMc( const input_mc *mcInput, IVAS_REND_AudioBuffer outAudio ) { - int32_t i; + int16_t i; IVAS_REND_AudioBuffer inAudio; - wmops_sub_start("renderMcToMc"); + wmops_sub_start( "renderMcToMc" ); inAudio = mcInput->base.inputBuffer; @@ -3718,10 +3675,10 @@ static ivas_error renderMcToSba( const input_mc *mcInput, IVAS_REND_AudioBuffer outAudio ) { - int32_t i; + int16_t i; IVAS_REND_AudioBuffer inAudio; - wmops_sub_start("renderMcToSba"); + wmops_sub_start( "renderMcToSba" ); inAudio = mcInput->base.inputBuffer; @@ -3802,7 +3759,7 @@ static ivas_error renderActiveInputsMc( IVAS_REND_HANDLE hIvasRend, IVAS_REND_AudioBuffer outAudio ) { - int32_t i; + int16_t i; input_mc *pCurrentInput; ivas_error error; @@ -3813,10 +3770,7 @@ static ivas_error renderActiveInputsMc( /* Skip inactive inputs */ continue; } - - if ( ( error = renderInputMc( pCurrentInput, - hIvasRend->outputConfig, - outAudio ) ) != IVAS_ERR_OK ) + if ( ( error = renderInputMc( pCurrentInput, hIvasRend->outputConfig, outAudio ) ) != IVAS_ERR_OK ) { return error; } @@ -3829,10 +3783,10 @@ static ivas_error renderSbaToMc( const input_sba *sbaInput, IVAS_REND_AudioBuffer outAudio ) { - int32_t i; + int16_t i; IVAS_REND_AudioBuffer inAudio; - wmops_sub_start("renderSbaToMc"); + wmops_sub_start( "renderSbaToMc" ); inAudio = sbaInput->base.inputBuffer; @@ -3850,10 +3804,10 @@ static ivas_error renderSbaToSba( const input_sba *sbaInput, IVAS_REND_AudioBuffer outAudio ) { - int32_t i; + int16_t i; IVAS_REND_AudioBuffer inAudio; - wmops_sub_start("renderSbaToSba"); + wmops_sub_start( "renderSbaToSba" ); inAudio = sbaInput->base.inputBuffer; @@ -3869,7 +3823,7 @@ static ivas_error renderSbaToSba( static ivas_error renderSbaToBinaural( input_sba *sbaInput, - IVAS_REND_AudioConfig outConfig, + const IVAS_REND_AudioConfig outConfig, IVAS_REND_AudioBuffer outAudio ) { float tmpCrendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; @@ -3877,7 +3831,7 @@ static ivas_error renderSbaToBinaural( ivas_error error; IVAS_REND_AudioBuffer tmpRotBuffer; - wmops_sub_start("renderSbaToBinaural"); + wmops_sub_start( "renderSbaToBinaural" ); /* apply rotation */ if ( sbaInput->base.ctx.pHeadRotData->headRotEnabled ) @@ -3903,11 +3857,7 @@ static ivas_error renderSbaToBinaural( } /* call CREND */ - if ( ( error = ivas_rend_crendProcess( &sbaInput->crendWrapper, - sbaInput->base.inConfig, - outConfig, - tmpCrendBuffer, - *sbaInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_rend_crendProcess( &sbaInput->crendWrapper, sbaInput->base.inConfig, outConfig, tmpCrendBuffer, *sbaInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -3921,12 +3871,12 @@ static ivas_error renderSbaToBinaural( static ivas_error renderSbaToBinauralRoom( input_sba *sbaInput, - IVAS_REND_AudioConfig outConfig, + const IVAS_REND_AudioConfig outConfig, IVAS_REND_AudioBuffer outAudio ) { int8_t headRotEnabled; int16_t i; - int32_t tmp; + int16_t tmp; float tmpCrendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; ivas_error error; @@ -3934,7 +3884,9 @@ static ivas_error renderSbaToBinauralRoom( IVAS_REND_AudioBuffer tmpMcBuffer; IVAS_REND_AudioBuffer *tmpBufPtr; - wmops_sub_start("renderSbaToBinauralRoom"); + tmpRotBuffer = outAudio; /* avoid compilation warning */ + + wmops_sub_start( "renderSbaToBinauralRoom" ); headRotEnabled = sbaInput->base.ctx.pHeadRotData->headRotEnabled; @@ -3944,14 +3896,9 @@ static ivas_error renderSbaToBinauralRoom( tmpRotBuffer = sbaInput->base.inputBuffer; tmpRotBuffer.data = count_malloc( tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels * sizeof( float ) ); /* copy input for in-place rotation */ - mvr2r( sbaInput->base.inputBuffer.data, tmpRotBuffer.data, - tmpRotBuffer.config.numChannels * tmpRotBuffer.config.numSamplesPerChannel ); + mvr2r( sbaInput->base.inputBuffer.data, tmpRotBuffer.data, tmpRotBuffer.config.numChannels * tmpRotBuffer.config.numSamplesPerChannel ); - rotateFrameSba( sbaInput->base.inputBuffer, - sbaInput->base.inConfig, - sbaInput->base.ctx.pHeadRotData, - sbaInput->rot_gains_prev, - tmpRotBuffer ); + rotateFrameSba( sbaInput->base.inputBuffer, sbaInput->base.inConfig, sbaInput->base.ctx.pHeadRotData, sbaInput->rot_gains_prev, tmpRotBuffer ); } /* intermediate rendering to 7_1_4 */ @@ -3959,26 +3906,18 @@ static ivas_error renderSbaToBinauralRoom( getAudioConfigNumChannels( IVAS_REND_AUDIO_CONFIG_7_1_4, &tmp ); tmpMcBuffer.config.numChannels = (int16_t) tmp; tmpMcBuffer.data = count_malloc( tmpMcBuffer.config.numSamplesPerChannel * tmpMcBuffer.config.numChannels * sizeof( float ) ); - set_zero( tmpMcBuffer.data, - tmpMcBuffer.config.numChannels * tmpMcBuffer.config.numSamplesPerChannel ); + set_zero( tmpMcBuffer.data, tmpMcBuffer.config.numChannels * tmpMcBuffer.config.numSamplesPerChannel ); tmpBufPtr = ( headRotEnabled ) ? &tmpRotBuffer : &sbaInput->base.inputBuffer; for ( i = 0; i < sbaInput->base.inputBuffer.config.numChannels; i++ ) { - renderBufferChannel( *tmpBufPtr, - i, - sbaInput->hoaDecMtx[i], - tmpMcBuffer ); + renderBufferChannel( *tmpBufPtr, i, sbaInput->hoaDecMtx[i], tmpMcBuffer ); } copyBufferTo2dArray( tmpMcBuffer, tmpCrendBuffer ); /* call CREND */ - if ( ( error = ivas_rend_crendProcess( &sbaInput->crendWrapper, - IVAS_REND_AUDIO_CONFIG_7_1_4, - outConfig, - tmpCrendBuffer, - *sbaInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_rend_crendProcess( &sbaInput->crendWrapper, IVAS_REND_AUDIO_CONFIG_7_1_4, outConfig, tmpCrendBuffer, *sbaInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -3998,7 +3937,7 @@ static ivas_error renderSbaToBinauralRoom( static ivas_error renderInputSba( input_sba *sbaInput, - IVAS_REND_AudioConfig outConfig, + const IVAS_REND_AudioConfig outConfig, IVAS_REND_AudioBuffer outAudio ) { ivas_error error; @@ -4056,7 +3995,7 @@ static ivas_error renderActiveInputsSba( IVAS_REND_HANDLE hIvasRend, IVAS_REND_AudioBuffer outAudio ) { - int32_t i; + int16_t i; input_sba *pCurrentInput; ivas_error error; @@ -4067,9 +4006,8 @@ static ivas_error renderActiveInputsSba( /* Skip inactive inputs */ continue; } - if ( ( error = renderInputSba( pCurrentInput, - hIvasRend->outputConfig, - outAudio ) ) != IVAS_ERR_OK ) + + if ( ( error = renderInputSba( pCurrentInput, hIvasRend->outputConfig, outAudio ) ) != IVAS_ERR_OK ) { return error; } @@ -4083,7 +4021,7 @@ ivas_error IVAS_REND_GetSamples( IVAS_REND_AudioBuffer outAudio ) { ivas_error error; - int32_t numOutChannels; + int16_t numOutChannels; /*-----------------------------------------------------------------* * Validate function arguments @@ -4140,9 +4078,10 @@ ivas_error IVAS_REND_GetSamples( return IVAS_ERR_OK; } -void IVAS_REND_Close( IVAS_REND_HANDLE *phIvasRend ) +void IVAS_REND_Close( + IVAS_REND_HANDLE *phIvasRend ) { - uint32_t i; + uint16_t i; IVAS_REND_HANDLE hIvasRend; /*-----------------------------------------------------------------* @@ -4177,11 +4116,12 @@ void IVAS_REND_Close( IVAS_REND_HANDLE *phIvasRend ) /* clear Config. Renderer */ ivas_render_config_close( &( hIvasRend->hRendererConfig ) ); - ivas_limiter_close( &hIvasRend->hLimiter ); count_free( hIvasRend ); *phIvasRend = NULL; + + return; } #ifdef DEBUGGING diff --git a/lib_rend/lib_rend.h b/lib_rend/lib_rend.h index 924bc0e6fe..831823ad60 100644 --- a/lib_rend/lib_rend.h +++ b/lib_rend/lib_rend.h @@ -132,11 +132,11 @@ typedef enum IVAS_REND_AUDIO_CONFIG_UNKNOWN = IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN << 8 | 0, } IVAS_REND_AudioConfig; -typedef uint32_t IVAS_REND_InputId; +typedef uint16_t IVAS_REND_InputId; typedef struct { - int32_t numLfeChannels; + int16_t numLfeChannels; float lfeOutputGains[IVAS_MAX_INPUT_LFE_CHANNELS][IVAS_MAX_OUTPUT_CHANNELS]; } IVAS_REND_LfeRouting; @@ -149,14 +149,14 @@ typedef struct ivas_error IVAS_REND_Open( IVAS_REND_HANDLE *phIvasRend, /* i/o: Pointer to renderer handle */ - int32_t outputSampleRate, /* i : output sampling rate */ - IVAS_REND_AudioConfig outConfig /* i : output audio config */ + const int32_t outputSampleRate, /* i : output sampling rate */ + const IVAS_REND_AudioConfig outConfig /* i : output audio config */ ); /* Note: this will reset custom LFE routings set for any MC input */ ivas_error IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - IVAS_CUSTOM_LS_DATA layout /* i : custom loudspeaker layout for renderer output */ + const IVAS_CUSTOM_LS_DATA layout /* i : custom loudspeaker layout for renderer output */ ); /* Support for custom HRTFs will be added in the future. */ @@ -170,43 +170,43 @@ ivas_error IVAS_REND_SetCustomHrtf( ivas_error IVAS_REND_NumOutChannels( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ - int32_t *numOutChannels /* o : number of output channels */ + int16_t *numOutChannels /* o : number of output channels */ ); ivas_error IVAS_REND_AddInput( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - IVAS_REND_AudioConfig inConfig, /* i : audio config for a new input */ + const IVAS_REND_AudioConfig inConfig, /* i : audio config for a new input */ IVAS_REND_InputId *inputId /* o : ID of the new input */ ); /* Note: this will reset any custom LFE routing set for the input */ ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - IVAS_REND_InputId inputId, /* i : ID of the input */ - IVAS_CUSTOM_LS_DATA layout /* i : custom loudspeaker layout for input */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const IVAS_CUSTOM_LS_DATA layout /* i : custom loudspeaker layout for input */ ); ivas_error IVAS_REND_SetInputGain( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - IVAS_REND_InputId inputId, /* i : ID of the input */ - float gain /* i : linear gain (not in dB) */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const float gain /* i : linear gain (not in dB) */ ); ivas_error IVAS_REND_SetInputLfeRouting( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - IVAS_REND_InputId inputId, /* i : ID of the input */ - IVAS_REND_LfeRouting lfeRouting /* i : custom LFE routing struct */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const IVAS_REND_LfeRouting lfeRouting /* i : custom LFE routing struct */ ); ivas_error IVAS_REND_RemoveInput( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - IVAS_REND_InputId inputId /* i : ID of the input */ + const IVAS_REND_InputId inputId /* i : ID of the input */ ); ivas_error IVAS_REND_GetInputNumChannels( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ - IVAS_REND_InputId inputId, /* i : ID of the input */ - int32_t *numChannels /* o : number of channels of the input */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + int16_t *numChannels /* o : number of channels of the input */ ); ivas_error IVAS_REND_GetDelay( @@ -219,20 +219,20 @@ ivas_error IVAS_REND_GetDelay( ivas_error IVAS_REND_FeedInputAudio( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - IVAS_REND_InputId inputId, /* i : ID of the input */ - IVAS_REND_ReadOnlyAudioBuffer inputAudio /* i : buffer with input audio */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const IVAS_REND_ReadOnlyAudioBuffer inputAudio /* i : buffer with input audio */ ); ivas_error IVAS_REND_FeedInputObjectMetadata( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - IVAS_REND_InputId inputId, /* i : ID of the input */ - IVAS_REND_AudioObjectPosition objectPosition /* i : object position struct */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const IVAS_REND_AudioObjectPosition objectPosition /* i : object position struct */ ); /* Support for MASA input will be added in the future. */ ivas_error IVAS_REND_FeedInputMasaMetadata( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - IVAS_REND_InputId inputId, /* i : ID of the input */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ void* TODO ); -- GitLab From 08c34b5f1f4f874409624f07457ad8fa2f6e4553 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Tue, 8 Nov 2022 18:35:18 +0100 Subject: [PATCH 16/16] [formatting] apply patch from CI job --- apps/renderer.c | 4 ++-- lib_rend/ivas_crend.c | 15 +++++++-------- lib_rend/lib_rend.c | 16 ++++++++-------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/apps/renderer.c b/apps/renderer.c index c7c1b8cf8f..d626db7d42 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -659,7 +659,7 @@ int main( } /* === Configure === */ - if ( ( error = IVAS_REND_InitConfig( hIvasRend, headRotReader != NULL, strlen(args.renderConfigFilePath) != 0 ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_REND_InitConfig( hIvasRend, headRotReader != NULL, strlen( args.renderConfigFilePath ) != 0 ) ) != IVAS_ERR_OK ) { exit( -1 ); } @@ -667,7 +667,7 @@ int main( if ( args.renderConfigFilePath[0] != '\0' ) { IVAS_RENDER_CONFIG_DATA renderConfig; - + /* sanity check */ if ( args.outConfig.audioConfig != IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) { diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 698612b1ad..d1b79ca3d5 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -1277,14 +1277,13 @@ ivas_error ivas_rend_openCrend( hCrend->hTrack = NULL; } - if ( ( hRendCfg != NULL ) && (hRendCfg->roomAcoustics.late_reverb_on ) ) + if ( ( hRendCfg != NULL ) && ( hRendCfg->roomAcoustics.late_reverb_on ) ) { - if ( ( error = ivas_reverb_open( &(hCrend->hReverb), - getIvasAudioConfigFromRendAudioConfig( inConfig ), - pCrend->hHrtfCrend, - hRendCfg, - output_Fs - ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_reverb_open( &( hCrend->hReverb ), + getIvasAudioConfigFromRendAudioConfig( inConfig ), + pCrend->hHrtfCrend, + hRendCfg, + output_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -1343,7 +1342,7 @@ ivas_error ivas_rend_initCrend( /* set BRIR flag */ use_brir = false; - if ( (hRendCfg != NULL && hRendCfg->roomAcoustics.use_brir ) || outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) + if ( ( hRendCfg != NULL && hRendCfg->roomAcoustics.use_brir ) || outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) { use_brir = true; } diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 0572f560f0..a7966aa4da 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -152,12 +152,12 @@ struct IVAS_REND IVAS_REND_AudioConfig outputConfig; EFAP_WRAPPER efapOutWrapper; IVAS_LSSETUP_CUSTOM_STRUCT customLsOut; - + int8_t enableHeadRotation; IVAS_REND_HeadRotData headRotData; int8_t rendererConfigEnabled; - RENDER_CONFIG_DATA *hRendererConfig; /* Renderer config pointer */ + RENDER_CONFIG_DATA *hRendererConfig; /* Renderer config pointer */ }; static IVAS_QUATERNION quaternionInit( @@ -1747,9 +1747,9 @@ static ivas_error initSbaPanGainsForSbaOut( } static ivas_error updateSbaPanGains( - input_sba *inputSba, - const IVAS_REND_AudioConfig outConfig, - RENDER_CONFIG_DATA *hRendCfg ) + input_sba *inputSba, + const IVAS_REND_AudioConfig outConfig, + RENDER_CONFIG_DATA *hRendCfg ) { ivas_error error; IVAS_REND_AudioConfig inConfig; @@ -2672,8 +2672,8 @@ ivas_error IVAS_REND_FeedInputObjectMetadata( } ivas_error IVAS_REND_InitConfig( IVAS_REND_HANDLE st, - bool headRotationEnabled, - bool rendererConfigEnabled ) + bool headRotationEnabled, + bool rendererConfigEnabled ) { ivas_error error; @@ -2694,7 +2694,7 @@ ivas_error IVAS_REND_InitConfig( IVAS_REND_HANDLE st, { st->rendererConfigEnabled = 0; } - + if ( ( error = ivas_render_config_open( &( st->hRendererConfig ) ) ) != IVAS_ERR_OK ) { return error; -- GitLab