From 12d08876e5a648d34be7d2a2f785f5cafa59a008 Mon Sep 17 00:00:00 2001 From: Shanush Prema Thasarathan Date: Thu, 27 Oct 2022 19:44:41 +1100 Subject: [PATCH 1/6] Wrapping AGC command line option in a debugging macro Macro is named `DEBUG_AGC_ENCODER_CMD_OPTION` --- apps/encoder.c | 34 ++++++++++++++++++++++++++++------ lib_com/ivas_prot.h | 6 +++++- lib_com/options.h | 1 + lib_enc/ivas_agc_enc.c | 22 +++++++++++++++++++--- lib_enc/ivas_spar_encoder.c | 4 ++++ lib_enc/ivas_stat_enc.h | 6 +++++- lib_enc/lib_enc.c | 23 ++++++++++++++++++----- lib_enc/lib_enc.h | 8 ++++++-- 8 files changed, 86 insertions(+), 18 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index bcd2dcea78..b3c4602b63 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 */ @@ -444,11 +446,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; @@ -874,11 +890,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; @@ -1384,6 +1402,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++; @@ -1409,6 +1428,7 @@ static bool parseCmdlIVAS_enc( return false; } } +#endif else if ( strcmp( argv_to_upper, "-BYPASS" ) == 0 ) // VE: should be renamed to "-pca" { i++; @@ -1648,13 +1668,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/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 50f0bba4fb..05e481df4a 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -45,8 +45,10 @@ #include "ivas_stat_com.h" #include "ivas_error_utils.h" #ifdef AGC_ENABLE_FOR_LBR +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION #include "lib_enc.h" -#endif +#endif /* DEBUG_AGC_ENCODER_CMD_OPTION */ +#endif /* AGC_ENABLE_FOR_LBR */ /* clang-format off */ @@ -3774,7 +3776,9 @@ void ivas_sba_prototype_renderer( /* AGC */ #ifdef AGC_ENABLE_FOR_LBR int16_t ivas_agc_enc_get_enablement_flag( +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION IVAS_ENC_AGC agc_configuration, /* i : configuration used when encoder was initialised from cmd line */ +#endif int16_t nchan_transport /* i : number of transport channels */ ); #endif diff --git a/lib_com/options.h b/lib_com/options.h index 8ae36580e8..8aaba4184d 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 ############################ */ diff --git a/lib_enc/ivas_agc_enc.c b/lib_enc/ivas_agc_enc.c index 0f3274f43c..2fdd312fd8 100644 --- a/lib_enc/ivas_agc_enc.c +++ b/lib_enc/ivas_agc_enc.c @@ -60,6 +60,7 @@ 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() * @@ -68,16 +69,31 @@ static int16_t ivas_agc_writeBits( FILE *stream, const int16_t n_channels, ivas_ * enablement, otherwise AGC is enabled only if there is one transport channel. * *-----------------------------------------------------------------------------------------*/ +#else +/*-----------------------------------------------------------------------------------------* + * Function ivas_agc_enc_get_enablement_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( +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION IVAS_ENC_AGC agc_configuration, +#endif int16_t nchan_transport ) { +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION return (int16_t) ( ( agc_configuration == IVAS_ENC_AGC_UNDEFINED ) - ? ( nchan_transport == 1 ) - : agc_configuration ); -} + ? ( nchan_transport == 1 ) + : agc_configuration ); +#else + return (int16_t) ( nchan_transport == 1 ); #endif +} +#endif /* AGC_ENABLE_FOR_LBR */ /*-----------------------------------------------------------------------------------------* * Function ivas_agc_enc_init() diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index b5f00848a8..8a97813d11 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -121,7 +121,11 @@ ivas_error ivas_spar_enc_open( /* AGC handle */ #ifdef AGC_ENABLE_FOR_LBR +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION hSpar->AGC_Enable = ivas_agc_enc_get_enablement_flag( hEncoderConfig->Opt_AGC_ON, nchan_transport ); +#else + hSpar->AGC_Enable = ivas_agc_enc_get_enablement_flag( nchan_transport ); +#endif #endif if ( ( error = ivas_spar_agc_enc_open( &hSpar->hAgcEnc, input_Fs, nchan_inp ) ) != IVAS_ERR_OK ) { diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 531e69d85a..1ab14fdd03 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -41,8 +41,10 @@ #include "ivas_cnst.h" #include "ivas_stat_com.h" #ifdef AGC_ENABLE_FOR_LBR +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION #include "lib_enc.h" -#endif +#endif /* DEBUG_AGC_ENCODER_CMD_OPTION */ +#endif /* AGC_ENABLE_FOR_LBR */ /*----------------------------------------------------------------------------------* * DFT Stereo encoder structures @@ -1027,11 +1029,13 @@ 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 DEBUG_AGC_ENCODER_CMD_OPTION #ifdef AGC_ENABLE_FOR_LBR IVAS_ENC_AGC Opt_AGC_ON; /* flag indicating AGC operation in SBA */ #else /* temp. development parameters */ int16_t Opt_AGC_ON; /* flag indicating AGC operation in SBA */ +#endif #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 d6aa8a54f1..ecd98e71f5 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -451,11 +451,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 , @@ -479,11 +481,13 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( 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; #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; @@ -897,14 +901,17 @@ 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 ) ) #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 ) ) { @@ -1522,6 +1529,7 @@ 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 ) { @@ -1543,7 +1551,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 ) @@ -2216,11 +2227,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; #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 , -- GitLab From 95990ff450df3acddaaec97721e02627951f818d Mon Sep 17 00:00:00 2001 From: Shanush Prema Thasarathan Date: Tue, 1 Nov 2022 10:42:08 +1100 Subject: [PATCH 2/6] Decouple IVAS_AGC_ENC enum and rename AGC flag function - Decouple IVAS_AGC_ENC enum within the submodules of the codec - Rename AGC flag function to be a bit smaller. This function will likely be moved and renamed when the future of AGC is more certain --- lib_com/cnst.h | 3 +++ lib_com/ivas_error.h | 3 +++ lib_com/ivas_prot.h | 9 ++------ lib_enc/ivas_agc_enc.c | 10 ++++----- lib_enc/ivas_spar_encoder.c | 4 ++-- lib_enc/ivas_stat_enc.h | 11 +--------- lib_enc/lib_enc.c | 41 +++++++++++++++++++++++++++++++------ 7 files changed, 51 insertions(+), 30 deletions(-) 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/ivas_error.h b/lib_com/ivas_error.h index 58c45ee5ee..8d09e48bbd 100644 --- a/lib_com/ivas_error.h +++ b/lib_com/ivas_error.h @@ -86,6 +86,9 @@ typedef enum IVAS_ERR_FILE_READER_TIMESTAMP_MISMATCH, IVAS_ERR_ISM_FILE_READER_INVALID_METADATA_FORMAT, IVAS_ERR_INVALID_MASA_FORMAT_METADATA_FILE, +#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 5a80aede4d..aadfca8c89 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -44,11 +44,6 @@ #include "ivas_stat_dec.h" #include "ivas_stat_com.h" #include "ivas_error_utils.h" -#ifdef AGC_ENABLE_FOR_LBR -#ifdef DEBUG_AGC_ENCODER_CMD_OPTION -#include "lib_enc.h" -#endif /* DEBUG_AGC_ENCODER_CMD_OPTION */ -#endif /* AGC_ENABLE_FOR_LBR */ /* clang-format off */ @@ -3759,9 +3754,9 @@ void ivas_sba_prototype_renderer( /* AGC */ #ifdef AGC_ENABLE_FOR_LBR -int16_t ivas_agc_enc_get_enablement_flag( +int16_t ivas_agc_enc_get_flag( #ifdef DEBUG_AGC_ENCODER_CMD_OPTION - IVAS_ENC_AGC agc_configuration, /* i : configuration used when encoder was initialised from cmd line */ + int16_t agc_configuration, /* i : configuration used when encoder was initialised from cmd line */ #endif int16_t nchan_transport /* i : number of transport channels */ ); diff --git a/lib_enc/ivas_agc_enc.c b/lib_enc/ivas_agc_enc.c index 2fdd312fd8..70ed1c55db 100644 --- a/lib_enc/ivas_agc_enc.c +++ b/lib_enc/ivas_agc_enc.c @@ -62,7 +62,7 @@ static int16_t ivas_agc_writeBits( FILE *stream, const int16_t n_channels, ivas_ #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 @@ -71,7 +71,7 @@ static int16_t ivas_agc_writeBits( FILE *stream, const int16_t n_channels, ivas_ *-----------------------------------------------------------------------------------------*/ #else /*-----------------------------------------------------------------------------------------* - * Function ivas_agc_enc_get_enablement_flag() + * 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. @@ -79,14 +79,14 @@ static int16_t ivas_agc_writeBits( FILE *stream, const int16_t n_channels, ivas_ *-----------------------------------------------------------------------------------------*/ #endif -int16_t ivas_agc_enc_get_enablement_flag( +int16_t ivas_agc_enc_get_flag( #ifdef DEBUG_AGC_ENCODER_CMD_OPTION - IVAS_ENC_AGC agc_configuration, + int16_t agc_configuration, #endif int16_t nchan_transport ) { #ifdef DEBUG_AGC_ENCODER_CMD_OPTION - return (int16_t) ( ( agc_configuration == IVAS_ENC_AGC_UNDEFINED ) + return (int16_t) ( ( agc_configuration == SBA_AGC_DEFAULT ) ? ( nchan_transport == 1 ) : agc_configuration ); #else diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index a3b9399a85..4f3c7e73ff 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -122,9 +122,9 @@ ivas_error ivas_spar_enc_open( /* AGC handle */ #ifdef AGC_ENABLE_FOR_LBR #ifdef DEBUG_AGC_ENCODER_CMD_OPTION - hSpar->AGC_Enable = ivas_agc_enc_get_enablement_flag( hEncoderConfig->Opt_AGC_ON, nchan_transport ); + hSpar->AGC_Enable = ivas_agc_enc_get_flag( hEncoderConfig->Opt_AGC_ON, nchan_transport ); #else - hSpar->AGC_Enable = ivas_agc_enc_get_enablement_flag( nchan_transport ); + hSpar->AGC_Enable = ivas_agc_enc_get_flag( nchan_transport ); #endif #endif if ( ( error = ivas_spar_agc_enc_open( &hSpar->hAgcEnc, input_Fs, nchan_inp ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 8e58be3d32..4ae2e2f41f 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -40,11 +40,6 @@ #include "stat_enc.h" #include "ivas_cnst.h" #include "ivas_stat_com.h" -#ifdef AGC_ENABLE_FOR_LBR -#ifdef DEBUG_AGC_ENCODER_CMD_OPTION -#include "lib_enc.h" -#endif /* DEBUG_AGC_ENCODER_CMD_OPTION */ -#endif /* AGC_ENABLE_FOR_LBR */ /*----------------------------------------------------------------------------------* * DFT Stereo encoder structures @@ -1005,13 +1000,9 @@ 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 DEBUG_AGC_ENCODER_CMD_OPTION -#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 #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 a7dd232e05..8a5491dd6f 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -82,6 +82,7 @@ static ivas_error sanitizeBitrateISM( const ENCODER_CONFIG_HANDLE hEncoderConfig 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 ); +static ivas_error agcAPIToInternal( const IVAS_ENC_AGC agcOption, int16_t *internalAGCOption ); 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 ); @@ -481,7 +482,10 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( 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 /* AGC_ENABLE_FOR_LBR */ @@ -882,7 +886,7 @@ static ivas_error configureEncoder( #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 /* AGC_ENABLE_FOR_LBR */ @@ -1512,13 +1516,13 @@ static ivas_error printConfigInfo_enc( #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: @@ -2066,6 +2070,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() @@ -2202,7 +2231,7 @@ static void init_encoder_config( 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 /* AGC_ENABLE_FOR_LBR */ -- GitLab From bdfc67db84b86072104775b286e93a7b5ecbc146 Mon Sep 17 00:00:00 2001 From: Shanush Prema Thasarathan Date: Tue, 1 Nov 2022 11:01:48 +1100 Subject: [PATCH 3/6] Allocate and initialise AGC only when AGC is enabled --- lib_enc/ivas_spar_encoder.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 4f3c7e73ff..3249a3c70a 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -123,11 +123,16 @@ ivas_error ivas_spar_enc_open( #ifdef AGC_ENABLE_FOR_LBR #ifdef DEBUG_AGC_ENCODER_CMD_OPTION hSpar->AGC_Enable = ivas_agc_enc_get_flag( hEncoderConfig->Opt_AGC_ON, nchan_transport ); + hSpar->hAgcEnc = NULL; #else hSpar->AGC_Enable = ivas_agc_enc_get_flag( nchan_transport ); #endif #endif - if ( ( error = ivas_spar_agc_enc_open( &hSpar->hAgcEnc, input_Fs, nchan_inp ) ) != IVAS_ERR_OK ) + if ( +#ifdef AGC_ENABLE_FOR_LBR + hSpar->AGC_Enable && +#endif + ( error = ivas_spar_agc_enc_open( &hSpar->hAgcEnc, input_Fs, nchan_inp ) ) != IVAS_ERR_OK ) { return error; } @@ -254,7 +259,14 @@ void ivas_spar_enc_close( ivas_spar_transient_det_close( &hSpar->hTranDet ); /* AGC */ - ivas_spar_agc_enc_close( &hSpar->hAgcEnc ); +#ifdef AGC_ENABLE_FOR_LBR + if ( hSpar->hAgcEnc != NULL ) + { +#endif + ivas_spar_agc_enc_close( &hSpar->hAgcEnc ); +#ifdef AGC_ENABLE_FOR_LBR + } +#endif /* PCA */ if ( hSpar->hPCA != NULL ) -- GitLab From f3e3e3255540ad2f8889a9c186b460f700418fce Mon Sep 17 00:00:00 2001 From: Shanush Prema Thasarathan Date: Tue, 1 Nov 2022 11:12:52 +1100 Subject: [PATCH 4/6] Forgot to encapsulate agcAPIToInternal into the debug macro --- lib_enc/lib_enc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 8a5491dd6f..242a56f7bc 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -82,7 +82,9 @@ static ivas_error sanitizeBitrateISM( const ENCODER_CONFIG_HANDLE hEncoderConfig 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 ); -- GitLab From 7e7e171f20f4e430d1ab353b4fda054cea6444d4 Mon Sep 17 00:00:00 2001 From: Shanush Prema Thasarathan Date: Tue, 1 Nov 2022 11:24:26 +1100 Subject: [PATCH 5/6] Add a fmToDo to remind us to remove this agc bit when the command line option is no longer used --- lib_enc/ivas_spar_encoder.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 3249a3c70a..3b04dbe24b 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -737,6 +737,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 ); } } -- GitLab From cd8a633d2aa672f79c112c4ccc679c0ec3f97d3e Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 1 Nov 2022 09:37:30 +0100 Subject: [PATCH 6/6] editorial improvements --- lib_com/ivas_prot.h | 5 +++-- lib_enc/ivas_agc_enc.c | 9 +++++++-- lib_enc/ivas_spar_encoder.c | 38 +++++++++++-------------------------- lib_enc/lib_enc.c | 3 +++ 4 files changed, 24 insertions(+), 31 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index aadfca8c89..fe0786f023 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3754,11 +3754,12 @@ void ivas_sba_prototype_renderer( /* AGC */ #ifdef AGC_ENABLE_FOR_LBR +/*! r: AGC enable flag */ int16_t ivas_agc_enc_get_flag( #ifdef DEBUG_AGC_ENCODER_CMD_OPTION - int16_t agc_configuration, /* i : configuration used when encoder was initialised from cmd line */ + int16_t agc_configuration, /* i : AGC configuration from command-line */ #endif - int16_t nchan_transport /* i : number of transport channels */ + int16_t nchan_transport /* i : number of transport channels */ ); #endif diff --git a/lib_enc/ivas_agc_enc.c b/lib_enc/ivas_agc_enc.c index 70ed1c55db..53a6df3a13 100644 --- a/lib_enc/ivas_agc_enc.c +++ b/lib_enc/ivas_agc_enc.c @@ -79,11 +79,13 @@ static int16_t ivas_agc_writeBits( FILE *stream, const int16_t n_channels, ivas_ *-----------------------------------------------------------------------------------------*/ #endif +/*! r: AGC enable flag */ int16_t ivas_agc_enc_get_flag( #ifdef DEBUG_AGC_ENCODER_CMD_OPTION - int16_t agc_configuration, + int16_t agc_configuration, /* i : AGC configuration from command-line */ #endif - int16_t nchan_transport ) + int16_t nchan_transport /* i : number of transport channels */ +) { #ifdef DEBUG_AGC_ENCODER_CMD_OPTION return (int16_t) ( ( agc_configuration == SBA_AGC_DEFAULT ) @@ -143,6 +145,7 @@ static void ivas_agc_enc_init( return; } + /*------------------------------------------------------------------------- * ivas_spar_agc_enc_open() * @@ -187,6 +190,7 @@ ivas_error ivas_spar_agc_enc_open( return IVAS_ERR_OK; } + /*------------------------------------------------------------------------- * ivas_spar_agc_enc_close() * @@ -219,6 +223,7 @@ void ivas_spar_agc_enc_close( return; } + /*-----------------------------------------------------------------------------------------* * Function ivas_agc_enc_process() * diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 3b04dbe24b..1beab643d5 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -123,20 +123,21 @@ ivas_error ivas_spar_enc_open( #ifdef AGC_ENABLE_FOR_LBR #ifdef DEBUG_AGC_ENCODER_CMD_OPTION hSpar->AGC_Enable = ivas_agc_enc_get_flag( hEncoderConfig->Opt_AGC_ON, nchan_transport ); - hSpar->hAgcEnc = NULL; #else hSpar->AGC_Enable = ivas_agc_enc_get_flag( nchan_transport ); #endif #endif - if ( + #ifdef AGC_ENABLE_FOR_LBR - hSpar->AGC_Enable && + hSpar->hAgcEnc = NULL; + if ( hSpar->AGC_Enable ) #endif - ( 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 ) @@ -242,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 ); @@ -259,14 +259,7 @@ void ivas_spar_enc_close( ivas_spar_transient_det_close( &hSpar->hTranDet ); /* AGC */ -#ifdef AGC_ENABLE_FOR_LBR - if ( hSpar->hAgcEnc != NULL ) - { -#endif - ivas_spar_agc_enc_close( &hSpar->hAgcEnc ); -#ifdef AGC_ENABLE_FOR_LBR - } -#endif + ivas_spar_agc_enc_close( &hSpar->hAgcEnc ); /* PCA */ if ( hSpar->hPCA != NULL ) @@ -391,7 +384,6 @@ static ivas_error ivas_spar_enc_process( mvr2r( data_f[HOA_keep_ind[i]], data_f[i], input_frame ); } - /*-----------------------------------------------------------------------------------------* * Transient detector *-----------------------------------------------------------------------------------------*/ @@ -445,17 +437,13 @@ static ivas_error ivas_spar_enc_process( p_pcm_tmp[i] = pcm_tmp[i]; } - dtx_vad = ( hEncoderConfig->Opt_DTX_ON == 1 ) ? front_vad_flag : 1; /*-----------------------------------------------------------------------------------------* * DirAC encoding *-----------------------------------------------------------------------------------------*/ - 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 ); - + 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 ) { @@ -540,7 +528,6 @@ static ivas_error ivas_spar_enc_process( } } - /*-----------------------------------------------------------------------------------------* * Covariance process *-----------------------------------------------------------------------------------------*/ @@ -565,8 +552,7 @@ static ivas_error ivas_spar_enc_process( 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, - ( hSpar->hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND ); + 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 ); } nchan_transport = st_ivas->nchan_transport; @@ -620,9 +606,7 @@ static ivas_error ivas_spar_enc_process( } 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 ); + d_start_band, d_end_band, ( hSpar->hMdEnc->spar_hoa_md_flag ) ? 1 : sba_order, dtx_vad, Wscale_d ); } if ( hSpar->hMdEnc->spar_hoa_md_flag ) diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 242a56f7bc..e25afc9fd8 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -480,8 +480,10 @@ 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 if ( ( error = agcAPIToInternal( Opt_AGC_ON, &( hEncoderConfig->Opt_AGC_ON ) ) ) != IVAS_ERR_OK ) @@ -492,6 +494,7 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( hEncoderConfig->Opt_AGC_ON = (int16_t) Opt_AGC_ON; #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; -- GitLab