From cde1dbbcfc23f24504dddea688dc2c8c6c7e9897 Mon Sep 17 00:00:00 2001 From: malenov Date: Mon, 2 Dec 2024 13:17:45 +0100 Subject: [PATCH 1/2] porting of mode enforcement logic (-force) from ivas-float-update --- apps/encoder.c | 256 +++++++++++++++++++++++++- lib_com/cnst.h | 11 ++ lib_com/ivas_cnst.h | 4 + lib_com/ivas_error.h | 7 + lib_com/options.h | 7 +- lib_com/prot.h | 10 + lib_enc/core_enc_ol.c | 13 ++ lib_enc/core_enc_ol_fx.c | 13 ++ lib_enc/decision_matrix_enc.c | 15 ++ lib_enc/decision_matrix_enc_fx.c | 15 ++ lib_enc/ivas_core_pre_proc_front.c | 31 ++++ lib_enc/ivas_corecoder_enc_reconfig.c | 4 + lib_enc/ivas_cpe_enc.c | 35 ++++ lib_enc/ivas_decision_matrix_enc.c | 68 ++++++- lib_enc/ivas_front_vad.c | 15 ++ lib_enc/ivas_init_enc.c | 4 + lib_enc/ivas_ism_enc.c | 8 + lib_enc/ivas_mct_enc.c | 16 ++ lib_enc/ivas_sce_enc.c | 10 +- lib_enc/ivas_stat_enc.h | 17 ++ lib_enc/ivas_stereo_classifier.c | 29 ++- lib_enc/ivas_stereo_mdct_core_enc.c | 18 ++ lib_enc/ivas_stereo_mdct_stereo_enc.c | 82 ++++++++- lib_enc/ivas_stereo_switching_enc.c | 8 + lib_enc/ivas_tcx_core_enc.c | 26 +++ lib_enc/lib_enc.c | 179 +++++++++++++++++- lib_enc/lib_enc.h | 36 ++++ lib_enc/speech_music_classif.c | 36 ++++ lib_enc/speech_music_classif_fx.c | 38 +++- lib_enc/stat_enc.h | 3 + 30 files changed, 995 insertions(+), 19 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index 6d34f7758..694f4e936 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -30,8 +30,13 @@ *******************************************************************************************************/ -#include "lib_enc.h" #include +#include "options.h" +#ifdef DEBUGGING +#include "debug.h" +#endif +#include "stl.h" +#include "lib_enc.h" #include "cmdl_tools.h" #include "audio_file_reader.h" #include "bitstream_writer.h" @@ -39,9 +44,6 @@ #include "jbm_file_reader.h" #include "masa_file_reader.h" #include "wmc_auto.h" -#include "options.h" -#include "stl.h" - #define WMC_TOOL_SKIP @@ -62,6 +64,10 @@ typedef union _EncInputFormatConfig /* MONO details */ bool stereoToMonoDownmix; +#ifdef DEBUGGING + /* STEREO details */ + IVAS_ENC_STEREO_MODE stereoMode; +#endif /* ISM details */ struct EncIsmConfig @@ -126,6 +132,10 @@ typedef struct const char *ca_config_file; bool mimeOutput; IVAS_ENC_COMPLEXITY_LEVEL complexityLevel; +#ifdef DEBUGGING + IVAS_ENC_FORCED_MODE forcedMode; + const char *forcedModeFile; +#endif bool pca; bool ism_extended_metadata; @@ -141,6 +151,10 @@ static bool parseCmdlIVAS_enc( int16_t argc, char *argv[], EncArguments *arg ); static void usage_enc( void ); static bool readBandwidth( FILE *file, IVAS_ENC_BANDWIDTH *bandwidth, int32_t *bandwidthFrameCounter ); static bool readBitrate( FILE *file, int32_t *bitrate ); +#ifdef DEBUGGING +static ivas_error readForcedMode( FILE *file, IVAS_ENC_FORCED_MODE *forcedMode, int32_t *forceFrameCounter ); +static IVAS_ENC_FORCED_MODE parseForcedMode( char *forcedModeChar ); +#endif /*------------------------------------------------------------------------------------------* @@ -168,6 +182,9 @@ int main( MasaFileReader *masaReader = NULL; IsmFileReader *ismReaders[IVAS_MAX_NUM_OBJECTS] = { NULL, NULL, NULL, NULL }; int16_t *pcmBuf = NULL; +#ifdef DEBUGGING + FILE *f_forcedModeProfile = NULL; +#endif #ifdef WMOPS reset_wmops(); @@ -357,7 +374,11 @@ int main( } break; case IVAS_ENC_INPUT_STEREO: +#ifdef DEBUGGING + if ( ( error = IVAS_ENC_ConfigureForStereo( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.is_binaural, arg.inputFormatConfig.stereoMode ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_ENC_ConfigureForStereo( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.is_binaural ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nIVAS_ENC_ConfigureForStereo failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); goto cleanup; @@ -505,6 +526,20 @@ int main( } } +#ifdef DEBUGGING + IVAS_ENC_FORCED_MODE forcedMode = arg.forcedMode; + int32_t force_profile_cnt = 0; + + if ( arg.forcedModeFile ) + { + if ( ( f_forcedModeProfile = fopen( arg.forcedModeFile, "rb" ) ) == NULL ) + { + fprintf( stderr, "\nError: Incorrect mode specification or the profile file could not be opened: %s\n\n", arg.forcedModeFile ); + usage_enc(); + goto cleanup; + } + } +#endif /*------------------------------------------------------------------------------------------* * Allocate input data buffer @@ -639,6 +674,27 @@ int main( } } +#ifdef DEBUGGING + if ( f_forcedModeProfile ) + { + if ( ( error = readForcedMode( f_forcedModeProfile, &forcedMode, &force_profile_cnt ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError reading from file: %s\n%s\n", arg.forcedModeFile, IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + /* Force mode not set when configuring, set in first frame even if not reading from file */ + if ( f_forcedModeProfile || frame == 0 ) + { + if ( ( error = IVAS_ENC_SetForcedMode( hIvasEnc, forcedMode ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_SetForcedMode failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } +#endif + /* Read ISM input metadata */ for ( i = 0; i < numIsmInputs; ++i ) { @@ -799,7 +855,10 @@ static void initArgStruct( EncArguments *arg ) arg->mimeOutput = false; arg->ism_extended_metadata = false; arg->complexityLevel = IVAS_ENC_COMPLEXITY_LEVEL_THREE; - +#ifdef DEBUGGING + arg->forcedMode = IVAS_ENC_FORCE_UNFORCED; + arg->forcedModeFile = NULL; +#endif arg->pca = false; return; @@ -928,6 +987,29 @@ static bool parseCmdlIVAS_enc( return false; } } +#ifdef DEBUGGING + /*-----------------------------------------------------------------* + * Force specific mode + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-FORCE" ) == 0 ) + { + strncpy( stmp, argv[i + 1], sizeof( stmp ) ); + + arg->forcedMode = parseForcedMode( stmp ); + + if ( arg->forcedMode == IVAS_ENC_FORCE_UNDEFINED ) + { + arg->forcedModeFile = argv[i + 1]; + fprintf( stdout, "Force switching file: %s\n", argv[i + 1] ); + } + else + { + fprintf( stdout, "Forcing codec to: %s\n", argv[i + 1] ); + } + + i += 2; + } #ifdef DEBUG_MODE_INFO #ifdef DEBUG_MODE_INFO_TWEAK /*-----------------------------------------------------------------* @@ -941,6 +1023,7 @@ static bool parseCmdlIVAS_enc( } #endif /* #ifdef DEBUG_MODE_INFO_TWEAK */ #endif /* #ifdef DEBUG_MODE_INFO */ +#endif /* #ifdef DEBUGGING */ /*-----------------------------------------------------------------* * deactivate delay compensation @@ -1044,6 +1127,78 @@ static bool parseCmdlIVAS_enc( { i++; arg->inputFormat = IVAS_ENC_INPUT_STEREO; + +#ifdef DEBUGGING + if ( ( i < argc - 4 ) && argv[i][0] != 45 ) /* note: 45 corresponds to "-" */ + { + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + if ( tmp == 1 ) + { + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_DFT; + i++; + } + else if ( tmp == 2 ) + { + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_TD; + i++; + } + else if ( tmp == 3 ) + { + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_MDCT_DECISION; +#ifdef DEBUG_FORCE_MDCT_STEREO_MODE + i++; + + /* force mdct stereo mode for debugging purposes */ + if ( i < argc - 4 ) + { + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + if ( tmp == 0 ) + { + /* keep "DECISION" */ + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_MDCT_DECISION; + i++; + } + else if ( tmp == 1 ) + { + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_MDCT_FORCE_LR; + i++; + } + else if ( tmp == 2 ) + { + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_MDCT_FORCE_MS; + i++; + } + else + { + fprintf( stderr, "Error: Incorrect mdct stereo coding method (%d) specified\n\n", tmp ); + usage_enc(); + return false; + } + } + } +#endif + } + else + { + fprintf( stderr, "Error: Incorrect stereo mode (%d) specified\n\n", tmp ); + usage_enc(); + return false; + } + } + else + { + fprintf( stderr, "Error: Stereo mode not specified.\n\n" ); /* in the debugging stage */ + usage_enc(); + return false; + } + } + else + { + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_UNIFIED; + } +#endif /* DEBUGGING */ } else if ( strcmp( argv_to_upper, "-BINAURAL" ) == 0 ) { @@ -1640,6 +1795,10 @@ static void usage_enc( void ) fprintf( stdout, "-pca : activate PCA in SBA format FOA at 256 kbps \n" ); fprintf( stdout, "-level level : Complexity level, level = (1, 2, 3), will be defined after characterisation. \n" ); fprintf( stdout, " Currently, all values default to level 3 (full functionality).\n" ); +#ifdef DEBUGGING + fprintf( stdout, "-force T : Force specific mode, T = (speech, music, ACELP, GSC, TCX, HQ),\n" ); + fprintf( stdout, " alternatively, T can be a text file where each line contains \"nb_frames T\"\n" ); +#endif #ifdef DEBUG_MODE_INFO #ifdef DEBUG_MODE_INFO_TWEAK fprintf( stdout, "-info : specify subfolder name for debug output\n" ); @@ -1738,4 +1897,91 @@ static bool readBitrate( } +#ifdef DEBUGGING +/*---------------------------------------------------------------------* + * parseForcedMode() + * + * + *---------------------------------------------------------------------*/ + +static IVAS_ENC_FORCED_MODE parseForcedMode( + char *forcedModeChar ) +{ + to_upper( forcedModeChar ); + + if ( ( strcmp( forcedModeChar, "SPEECH" ) == 0 ) || ( strcmp( forcedModeChar, "'SPEECH'" ) == 0 ) || + ( strcmp( forcedModeChar, "0" ) == 0 ) ) + { + return IVAS_ENC_FORCE_SPEECH; + } + if ( ( strcmp( forcedModeChar, "MUSIC" ) == 0 ) || ( strcmp( forcedModeChar, "'MUSIC'" ) == 0 ) || ( strcmp( forcedModeChar, "AUDIO" ) == 0 ) || ( strcmp( forcedModeChar, "'AUDIO'" ) == 0 ) || ( strcmp( forcedModeChar, "1" ) == 0 ) ) + { + return IVAS_ENC_FORCE_MUSIC; + } + if ( ( strcmp( forcedModeChar, "ACELP" ) == 0 ) || ( strcmp( forcedModeChar, "'ACELP'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_ACELP; + } + if ( ( strcmp( forcedModeChar, "GSC" ) == 0 ) || ( strcmp( forcedModeChar, "'GSC'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_GSC; + } + if ( ( strcmp( forcedModeChar, "TCX" ) == 0 ) || ( strcmp( forcedModeChar, "'TCX'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_TCX; + } + if ( ( strcmp( forcedModeChar, "HQ" ) == 0 ) || ( strcmp( forcedModeChar, "'HQ'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_HQ; + } + + return IVAS_ENC_FORCE_UNDEFINED; +} + + +/*---------------------------------------------------------------------* + * readForcedMode() + * + * + *---------------------------------------------------------------------*/ + +static ivas_error readForcedMode( + FILE * file, + IVAS_ENC_FORCED_MODE * forcedMode, + int32_t * forceFrameCounter ) +{ + int16_t res; + char stmp[8]; + + if ( *forceFrameCounter == 0 ) + { + /* read next force and number of frames from the profile file */ + while ( ( res = (int16_t) fscanf( file, "%d %7s", forceFrameCounter, stmp ) ) != 2 && feof( file ) ) + { + rewind( file ); + } + + *forcedMode = parseForcedMode( stmp ); + + if ( *forcedMode == IVAS_ENC_FORCE_UNDEFINED ) + { + fprintf( stderr, "Error: incorect mode specification or the force profile file could not be opened: %s\n\n", stmp ); + return IVAS_ERR_WRONG_PARAMS; + } + + if ( res != 2 && !feof( file ) ) + { + fprintf( stderr, "Error: incorrect format of the force profile file (please ensure that it does not contain any empty lines)\n\n" ); + return IVAS_ERR_WRONG_PARAMS; + } + } + + /* current profile still active, only decrease the counter */ + ( *forceFrameCounter )--; + + return IVAS_ERR_OK; +} +#endif + + #undef WMC_TOOL_SKIP diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 7ee29ab3d..21329b3db 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -193,6 +193,17 @@ #define DEC_IVAS 2 /* Index for IVAS decoder */ #define OUTPUT_Q 11 +#ifdef DEBUGGING +#define FORCE_SPEECH 100 /* debugging - force speech on the command line */ +#define FORCE_MUSIC 101 /* debugging - force music on the command line */ +#define FORCE_ACELP 102 /* debugging - force ACELP core on the command line */ +#define FORCE_GSC 103 /* debugging - force GSC core on the command line */ +#define FORCE_TCX 104 /* debugging - force TCX core on the command line */ +#define FORCE_HQ 105 /* debugging - force HQ core on the command line */ +#define FORCE_TD_RENDERER 201 +#define FORCE_CLDFB_RENDERER 202 +#endif + enum{ NB = 0, /* Indicator of 4 kHz bandwidth */ WB = 1, /* Indicator of 8 kHz bandwidth */ diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 546675368..6614e8105 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -882,6 +882,10 @@ enum fea_names /* MDCT stereo modes */ #define SMDCT_MS_DECISION 0 +#ifdef DEBUG_FORCE_MDCT_STEREO_MODE +#define SMDCT_FORCE_LR 1 +#define SMDCT_FORCE_MS 2 +#endif #define MAX_SFB 70 /* Maximum number of stereo frequency bands = 64 + 6 for TCX after ACELP */ diff --git a/lib_com/ivas_error.h b/lib_com/ivas_error.h index fb0809f73..1198008f6 100644 --- a/lib_com/ivas_error.h +++ b/lib_com/ivas_error.h @@ -89,6 +89,9 @@ typedef enum IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED, IVAS_ERR_TSM_NOT_ENABLED, IVAS_ERR_FETCH_SIZE_NO_MULTIPLE_OF_5MS, +#ifdef DEBUGGING + IVAS_ERR_INVALID_FORCE_MODE, +#endif /*----------------------------------------* * input data errors * @@ -210,6 +213,10 @@ static inline const char *ivas_error_to_string( ivas_error error_code ) return "Unexpected NULL pointer"; case IVAS_ERR_METADATA_NOT_EXPECTED: return "Metadata input not expected for current configuration"; +#ifdef DEBUGGING + case IVAS_ERR_INVALID_FORCE_MODE: + return "Invalid force mode"; +#endif case IVAS_ERR_NOT_IMPLEMENTED: return "Not implemented"; case IVAS_ERR_ISM_FILE_READER_INVALID_METADATA_FORMAT: diff --git a/lib_com/options.h b/lib_com/options.h index 21e924688..5491d7124 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -47,9 +47,10 @@ /*#define DEBUGGING*/ /* Allows debugging message to be printed out during runtime */ #ifdef DEBUGGING -#define DEBUG_MODE_INFO /* define to output most important parameters to the subdirectory "res/" */ -#define DEBUG_MODE_INFO_TWEAK /* enable command line switch to specify subdirectory for debug info output inside "./res/" */ -/*#define DBG_WAV_WRITER*/ /* enable dbgwrite_wav() function for generating ".wav" files */ +#define DEBUG_MODE_INFO /* Define to output most important parameters to the subdirectory "res/" */ +#define DEBUG_MODE_INFO_TWEAK /* Enable command line switch to specify subdirectory for debug info output inside "./res/" */ +#define DEBUG_FORCE_MDCT_STEREO_MODE /* Force stereo mode decision for MDCT stereo: -stereo 3 1 forces L/R coding and -stereo 3 2 forces full M/S coding */ +/*#define DBG_WAV_WRITER*/ /* Enable dbgwrite_wav() function for generating ".wav" files */ #endif #define SUPPORT_JBM_TRACEFILE /* Support for JBM tracefile, which is needed for 3GPP objective/subjective testing, but not relevant for real-world implementations */ diff --git a/lib_com/prot.h b/lib_com/prot.h index f7bc0463b..1bb11d157 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2240,6 +2240,9 @@ void io_ini_enc( FILE **f_rate, /* o : bitrate switching profile (0 if N/A) */ FILE **f_bwidth, /* o : bandwidth switching profile (0 if N/A) */ FILE **f_metadata, /* o : metadata files (NULL if N/A) */ +#ifdef DEBUGGING + FILE **f_force, /* o : force switching profile (0 if N/A) */ +#endif FILE **f_rf, /* o : channel aware configuration file */ int16_t *quietMode, /* o : limit printouts */ int16_t *noDelayCmp, /* o : turn off delay compensation */ @@ -2270,6 +2273,13 @@ void read_next_bwidth( int32_t input_Fs /* i : input sampling rate */ ); +#ifdef DEBUGGING +void read_next_force( + int16_t *force, /* i/o: force value (0/1, 0 = speech, 1 = music)*/ + FILE *f_force, /* i : force switching profile (0 if N/A) */ + int32_t *force_profile_cnt /* i/o: counter of frames for force switching profile file */ +); +#endif ivas_error init_encoder( Encoder_State *st, /* i/o: state structure */ diff --git a/lib_enc/core_enc_ol.c b/lib_enc/core_enc_ol.c index 9251d9311..8bb6fbfa5 100644 --- a/lib_enc/core_enc_ol.c +++ b/lib_enc/core_enc_ol.c @@ -960,6 +960,19 @@ void core_acelp_tcx20_switching( st->core = TCX_20_CORE; st->acelpFramesCount = 0; } +#ifdef DEBUGGING + if ( st->force != -1 ) + { + if ( st->force == FORCE_SPEECH ) + { + st->core = ACELP_CORE; + } + else + { + st->core = TCX_20_CORE; + } + } +#endif } /* Fixed Decision (using -C) */ diff --git a/lib_enc/core_enc_ol_fx.c b/lib_enc/core_enc_ol_fx.c index e4782bb28..93c3e4df5 100644 --- a/lib_enc/core_enc_ol_fx.c +++ b/lib_enc/core_enc_ol_fx.c @@ -1313,6 +1313,19 @@ void core_acelp_tcx20_switching_fx( st->acelpFramesCount = 0; move16(); } +#ifdef DEBUGGING + if ( st->force != -1 ) + { + if ( st->force == FORCE_SPEECH ) + { + st->core = ACELP_CORE; + } + else + { + st->core = TCX_20_CORE; + } + } +#endif } /* Fixed Decision (using -C) */ diff --git a/lib_enc/decision_matrix_enc.c b/lib_enc/decision_matrix_enc.c index 9b18819d4..d105a2123 100644 --- a/lib_enc/decision_matrix_enc.c +++ b/lib_enc/decision_matrix_enc.c @@ -183,10 +183,17 @@ void decision_matrix_enc( { st->core = ACELP_CORE; +#ifdef DEBUGGING + if ( st->total_brate >= HQCORE_NB_MIN_RATE && ( st->force == FORCE_MUSIC || ( st->force == -1 && st->sp_aud_decision1 == 1 ) ) ) + { + st->core = HQ_CORE; + } +#else if ( st->total_brate >= HQCORE_NB_MIN_RATE && st->sp_aud_decision1 == 1 ) { st->core = HQ_CORE; } +#endif } /*---------------------------------------------------------------------* @@ -197,7 +204,11 @@ void decision_matrix_enc( { st->core = ACELP_CORE; +#ifdef DEBUGGING + if ( ( st->total_brate >= HQCORE_WB_MIN_RATE && ( st->force == FORCE_MUSIC || ( st->force == -1 && st->sp_aud_decision1 == 1 ) ) ) || st->total_brate >= HQ_96k ) +#else if ( ( st->total_brate >= HQCORE_WB_MIN_RATE && st->sp_aud_decision1 == 1 ) || st->total_brate >= HQ_96k ) +#endif { st->core = HQ_CORE; } @@ -230,7 +241,11 @@ void decision_matrix_enc( else if ( st->bwidth == SWB || st->bwidth == FB ) { +#ifdef DEBUGGING + if ( ( st->total_brate >= HQCORE_WB_MIN_RATE && ( st->force == FORCE_MUSIC || ( st->force == -1 && st->sp_aud_decision1 == 1 ) ) ) || st->total_brate >= HQ_96k ) +#else if ( ( st->total_brate >= HQCORE_SWB_MIN_RATE && st->sp_aud_decision1 == 1 ) || st->total_brate >= HQ_96k ) +#endif { st->core = HQ_CORE; } diff --git a/lib_enc/decision_matrix_enc_fx.c b/lib_enc/decision_matrix_enc_fx.c index 10288131a..3d31e7645 100644 --- a/lib_enc/decision_matrix_enc_fx.c +++ b/lib_enc/decision_matrix_enc_fx.c @@ -188,12 +188,19 @@ void decision_matrix_enc_fx( st_fx->core = ACELP_CORE; move16(); +#ifdef DEBUGGING + if ( st_fx->total_brate >= HQCORE_NB_MIN_RATE && ( st_fx->force == FORCE_MUSIC || ( st_fx->force == -1 && st_fx->sp_aud_decision1 == 1 ) ) ) + { + st_fx->core = HQ_CORE; + } +#else test(); if ( GE_32( st_fx->total_brate, HQCORE_NB_MIN_RATE ) && EQ_16( st_fx->sp_aud_decision1, 1 ) ) { st_fx->core = HQ_CORE; move16(); } +#endif } /*---------------------------------------------------------------------* @@ -205,10 +212,14 @@ void decision_matrix_enc_fx( st_fx->core = ACELP_CORE; move16(); +#ifdef DEBUGGING + if ( ( st_fx->total_brate >= HQCORE_WB_MIN_RATE && ( st_fx->force == FORCE_MUSIC || ( st_fx->force == -1 && st_fx->sp_aud_decision1 == 1 ) ) ) || st_fx->total_brate >= HQ_96k ) +#else test(); test(); IF( ( GE_32( st_fx->total_brate, HQCORE_WB_MIN_RATE ) && EQ_16( st_fx->sp_aud_decision1, 1 ) ) || GE_32( st_fx->total_brate, HQ_96k ) ) +#endif { st_fx->core = HQ_CORE; move16(); @@ -254,10 +265,14 @@ void decision_matrix_enc_fx( ELSE IF( EQ_16( st_fx->bwidth, SWB ) || EQ_16( st_fx->bwidth, FB ) ) { +#ifdef DEBUGGING + if ( ( st_fx->total_brate >= HQCORE_WB_MIN_RATE && ( st_fx->force == FORCE_MUSIC || ( st_fx->force == -1 && st_fx->sp_aud_decision1 == 1 ) ) ) || st_fx->total_brate >= HQ_96k ) +#else test(); test(); IF( ( GE_32( st_fx->total_brate, HQCORE_SWB_MIN_RATE ) && EQ_16( st_fx->sp_aud_decision1, 1 ) ) || GE_32( st_fx->total_brate, HQ_96k ) ) +#endif { st_fx->core = HQ_CORE; move16(); diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 6735fc66a..fee7377d1 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -748,6 +748,21 @@ ivas_error pre_proc_front_ivas( smc_dec = ivas_smc_gmm( st, hStereoClassif, localVAD_HE_SAD, Etot, lsp_new, *cor_map_sum, epsP, PS, non_staX, *relE, &high_lpn_flag, flag_spitch ); +#ifdef DEBUGGING + if ( st->idchan == 0 ) + { + if ( st->force == FORCE_SPEECH ) + { + /* enforce speech */ + st->sp_aud_decision0 = 0; + } + else if ( st->force == FORCE_MUSIC ) + { + /* enforce music */ + st->sp_aud_decision0 = 1; + } + } +#endif /*----------------------------------------------------------------* * VAD energy updates @@ -2305,6 +2320,22 @@ ivas_error pre_proc_front_ivas_fx( smc_dec = ivas_smc_gmm_fx( st, hStereoClassif, localVAD_HE_SAD, Etot_fx, lsp_new_fx, *cor_map_sum_fx /*Q8*/, epsP_fx, PS_fx, non_staX_fx, *relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, *epsP_fx_q, hSpMusClas->past_PS_Q ); +#ifdef DEBUGGING + if ( st->idchan == 0 ) + { + if ( st->force == FORCE_SPEECH ) + { + /* enforce speech */ + st->sp_aud_decision0 = 0; + } + else if ( st->force == FORCE_MUSIC ) + { + /* enforce music */ + st->sp_aud_decision0 = 1; + } + } +#endif + /*----------------------------------------------------------------* * VAD energy updates * Update of old per-band energy spectrum diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index a121e2b61..0e069f0c3 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -1141,6 +1141,10 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move16(); } +#ifdef DEBUGGING + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->mdct_stereo_mode_cmdl = hEncoderConfig->stereo_mode_cmdl; +#endif + initMdctStereoEncData_fx( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct, hEncoderConfig->ivas_format, st_ivas->hCPE[st_ivas->nCPE - 1]->element_mode, st_ivas->hCPE[st_ivas->nCPE - 1]->element_brate, hEncoderConfig->max_bwidth, 0, NULL, 1 ); st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = extract_l( ( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) || EQ_16( hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) && EQ_16( st_ivas->nchan_transport, 2 ) ); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 6798a87bb..7080f5179 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -169,6 +169,13 @@ ivas_error ivas_cpe_enc_fx( move16(); move16(); +#ifdef DEBUGGING + if ( hCPE->hCoreCoder[0]->ini_frame == 0 ) + { + hCPE->stereo_mode_cmdl = hEncoderConfig->stereo_mode_cmdl; + } +#endif + set16_fx( pitch_fr_fx[0], 0, NB_SUBFR ); set16_fx( pitch_fr_fx[1], 0, NB_SUBFR ); set16_fx( voicing_fr_fx[0], 0, NB_SUBFR ); @@ -199,6 +206,11 @@ ivas_error ivas_cpe_enc_fx( sts[n]->bwidth = sts[n]->last_bwidth; /* updated in BWD */ } sts[n]->rate_switching_reset = 0; + +#ifdef DEBUGGING + sts[n]->force = hEncoderConfig->force; + sts[n]->id_element = cpe_id + st_ivas->nSCE; +#endif } Copy32( data_fx_ch0, sts[0]->input32_fx, input_frame ); // Q(q_data_fx) @@ -561,6 +573,9 @@ ivas_error ivas_cpe_enc_fx( /* reconfiguration in case of bitrate switching */ if ( hCPE->element_brate != hCPE->last_element_brate && st_ivas->hMCT == NULL ) { +#ifdef DEBUGGING + hCPE->hStereoMdct->mdct_stereo_mode_cmdl = hEncoderConfig->mdct_stereo_mode_cmdl; +#endif #ifndef IVAS_FLOAT_FIXED initMdctStereoEncData( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, max_bwidth, 0, NULL, 0 ); #else @@ -1325,6 +1340,10 @@ ivas_error ivas_cpe_enc( sts[n]->bwidth = sts[n]->last_bwidth; /* updated in BWD */ } sts[n]->rate_switching_reset = 0; +#ifdef DEBUGGING + sts[n]->force = hEncoderConfig->force; + sts[n]->id_element = cpe_id + st_ivas->nSCE; +#endif } mvr2r( data_f_ch0, sts[0]->input, input_frame ); @@ -2193,7 +2212,11 @@ ivas_error create_cpe_enc( * LR VAD initialization *-----------------------------------------------------------------*/ +#ifdef DEBUGGING + if ( hEncoderConfig->Opt_DTX_ON && ( hCPE->element_mode == IVAS_CPE_TD || hEncoderConfig->stereo_mode_cmdl == 1 ) && !( ivas_format == MASA_FORMAT && element_mode_init == IVAS_CPE_MDCT ) ) +#else if ( hEncoderConfig->Opt_DTX_ON ) +#endif { if ( hCPE->element_mode == IVAS_CPE_TD || hCPE->element_mode == IVAS_CPE_DFT ) { @@ -2304,6 +2327,10 @@ ivas_error create_cpe_enc( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); } +#ifdef DEBUGGING + hCPE->hStereoMdct->mdct_stereo_mode_cmdl = st_ivas->hEncoderConfig->mdct_stereo_mode_cmdl; +#endif + #ifndef IVAS_FLOAT_FIXED initMdctStereoEncData( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, max_bwidth, 0, NULL, 1 ); #else @@ -2489,7 +2516,11 @@ ivas_error create_cpe_enc_fx( * LR VAD initialization *-----------------------------------------------------------------*/ +#ifdef DEBUGGING + if ( hEncoderConfig->Opt_DTX_ON && ( hCPE->element_mode == IVAS_CPE_TD || hEncoderConfig->stereo_mode_cmdl == 1 ) && !( ivas_format == MASA_FORMAT && element_mode_init == IVAS_CPE_MDCT ) ) +#else IF( hEncoderConfig->Opt_DTX_ON ) +#endif { test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) @@ -2591,6 +2622,10 @@ ivas_error create_cpe_enc_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); } +#ifdef DEBUGGING + hCPE->hStereoMdct->mdct_stereo_mode_cmdl = st_ivas->hEncoderConfig->mdct_stereo_mode_cmdl; +#endif + initMdctStereoEncData_fx( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, max_bwidth, 0, NULL, 1 ); test(); test(); diff --git a/lib_enc/ivas_decision_matrix_enc.c b/lib_enc/ivas_decision_matrix_enc.c index 3f9ab4f9b..823a4fc27 100644 --- a/lib_enc/ivas_decision_matrix_enc.c +++ b/lib_enc/ivas_decision_matrix_enc.c @@ -178,6 +178,39 @@ void ivas_decision_matrix_enc( st->core = TCX_20_CORE; } +#ifdef DEBUGGING + if ( st->idchan == 0 ) + { + if ( st->force == FORCE_SPEECH && st->element_mode != IVAS_CPE_MDCT && st->total_brate <= MAX_ACELP_BRATE ) + { + st->core = ACELP_CORE; + } + else if ( st->force == FORCE_MUSIC && st->core == ACELP_CORE ) + { + st->core = TCX_20_CORE; + } + else if ( st->force == FORCE_ACELP && st->element_mode != IVAS_CPE_MDCT && st->total_brate <= MAX_ACELP_BRATE ) + { + st->core = ACELP_CORE; + if ( st->coder_type == AUDIO ) + { + st->coder_type = GENERIC; + } + } + else if ( st->force == FORCE_GSC && element_brate < IVAS_24k4 ) + { + st->core = ACELP_CORE; + } + else if ( st->force == FORCE_TCX ) + { + st->core = TCX_20_CORE; + } + else if ( st->force == FORCE_HQ && st->element_mode != IVAS_CPE_MDCT && element_brate >= IVAS_24k4 ) + { + st->core = HQ_CORE; + } + } +#endif /* TCX not available at low bitrates -> replace it by GSC */ if ( st->core == TCX_20_CORE && st->total_brate < STEREO_TCX_MIN_RATE ) @@ -492,8 +525,41 @@ void ivas_decision_matrix_enc_fx( move16(); } - /* TCX not available at low bitrates -> replace it by GSC */ +#ifdef DEBUGGING + if ( st->idchan == 0 ) + { + if ( st->force == FORCE_SPEECH && st->element_mode != IVAS_CPE_MDCT && st->total_brate <= MAX_ACELP_BRATE ) + { + st->core = ACELP_CORE; + } + else if ( st->force == FORCE_MUSIC && st->core == ACELP_CORE ) + { + st->core = TCX_20_CORE; + } + else if ( st->force == FORCE_ACELP && st->element_mode != IVAS_CPE_MDCT && st->total_brate <= MAX_ACELP_BRATE ) + { + st->core = ACELP_CORE; + if ( st->coder_type == AUDIO ) + { + st->coder_type = GENERIC; + } + } + else if ( st->force == FORCE_GSC && element_brate < IVAS_24k4 ) + { + st->core = ACELP_CORE; + } + else if ( st->force == FORCE_TCX ) + { + st->core = TCX_20_CORE; + } + else if ( st->force == FORCE_HQ && st->element_mode != IVAS_CPE_MDCT && element_brate >= IVAS_24k4 ) + { + st->core = HQ_CORE; + } + } +#endif + /* TCX not available at low bitrates -> replace it by GSC */ test(); IF( EQ_16( st->core, TCX_20_CORE ) && LT_32( st->total_brate, STEREO_TCX_MIN_RATE ) ) { diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 98da900f8..45d0715e3 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -149,6 +149,13 @@ ivas_error front_vad( /* Only run VAD if DTX is on and TD stereo or unified stereo is selected */ if ( hFrontVads[0] != NULL && element_mode != IVAS_CPE_MDCT ) { +#ifdef DEBUGGING + /* If stereo switching is not enabled and TD is selected restore element_mode to TD every frame before the VAD */ + if ( hCPE != NULL && hCPE->stereo_mode_cmdl == IVAS_CPE_TD ) + { + hCPE->element_mode = IVAS_CPE_TD; + } +#endif /*------------------------------------------------------------------* * VAD @@ -365,6 +372,14 @@ ivas_error front_vad_fx( IF( hFrontVads[0] != NULL && NE_16( element_mode, IVAS_CPE_MDCT ) ) { +#ifdef DEBUGGING + /* If stereo switching is not enabled and TD is selected restore element_mode to TD every frame before the VAD */ + if ( hCPE != NULL && hCPE->stereo_mode_cmdl == IVAS_CPE_TD ) + { + hCPE->element_mode = IVAS_CPE_TD; + } +#endif + /*------------------------------------------------------------------* * VAD *-----------------------------------------------------------------*/ diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index aeec8f568..c784cc61a 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -538,6 +538,10 @@ void copy_encoder_config_fx( st_fx->rf_fec_indicator = st_ivas->hEncoderConfig->rf_fec_indicator; move16(); +#ifdef DEBUGGING + st_fx->force = st_ivas->hEncoderConfig->force; +#endif + st_fx->element_mode = st_ivas->hEncoderConfig->element_mode_init; move16(); diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 32b0e9936..7ee82fe31 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -152,6 +152,10 @@ ivas_error ivas_ism_enc( st->input_bwidth = st->last_input_bwidth; /* updated in BWD */ st->bwidth = st->last_bwidth; /* updated in BWD */ st->rate_switching_reset = 0; +#ifdef DEBUGGING + st->force = st_ivas->hEncoderConfig->force; + st->id_element = sce_id; +#endif /*---------------------------------------------------------------* * Time Domain Transient Detector @@ -558,6 +562,10 @@ ivas_error ivas_ism_enc_fx( st->input_bwidth = st->last_input_bwidth; /* updated in BWD */ st->bwidth = st->last_bwidth; /* updated in BWD */ st->rate_switching_reset = 0; +#ifdef DEBUGGING + st->force = st_ivas->hEncoderConfig->force; + st->id_element = sce_id; +#endif move16(); move16(); move16(); diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index f142b1532..fa6c6d46b 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -862,6 +862,10 @@ ivas_error create_mct_enc( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); } +#ifdef DEBUGGING + hMCT->hBlockData[n]->hStereoMdct->mdct_stereo_mode_cmdl = SMDCT_MS_DECISION; +#endif + #ifndef IVAS_FLOAT_FIXED initMdctStereoEncData( hMCT->hBlockData[n]->hStereoMdct, ivas_format, IVAS_CPE_MDCT, cp_bitrate, st_ivas->hEncoderConfig->max_bwidth, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->igf ? st_ivas->hCPE[0]->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid : NULL, 1 ); #else @@ -1001,6 +1005,10 @@ ivas_error create_mct_enc( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); } +#ifdef DEBUGGING + hMCT->hBlockData[n]->hStereoMdct->mdct_stereo_mode_cmdl = SMDCT_MS_DECISION; +#endif + initMdctStereoEncData_fx( hMCT->hBlockData[n]->hStereoMdct, ivas_format, IVAS_CPE_MDCT, cp_bitrate, st_ivas->hEncoderConfig->max_bwidth, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->igf ? st_ivas->hCPE[0]->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid : NULL, 1 ); } @@ -1186,6 +1194,10 @@ ivas_error mct_enc_reconfigure( } } +#ifdef DEBUGGING + hMCT->hBlockData[n]->hStereoMdct->mdct_stereo_mode_cmdl = SMDCT_MS_DECISION; +#endif + #ifndef IVAS_FLOAT_FIXED initMdctStereoEncData( hMCT->hBlockData[n]->hStereoMdct, ivas_format, IVAS_CPE_MDCT, cp_bitrate, st_ivas->hEncoderConfig->max_bwidth, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->igf ? st_ivas->hCPE[0]->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid : NULL, mem_init ); #else @@ -1369,6 +1381,10 @@ ivas_error mct_enc_reconfigure_fx( } } +#ifdef DEBUGGING + hMCT->hBlockData[n]->hStereoMdct->mdct_stereo_mode_cmdl = SMDCT_MS_DECISION; +#endif + initMdctStereoEncData_fx( hMCT->hBlockData[n]->hStereoMdct, ivas_format, IVAS_CPE_MDCT, cp_bitrate, st_ivas->hEncoderConfig->max_bwidth, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->igf ? st_ivas->hCPE[0]->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid : NULL, mem_init ); } diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 7f760cdc9..b77e9009a 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -159,6 +159,10 @@ ivas_error ivas_sce_enc_fx( st->input_bwidth = st->last_input_bwidth; /* updated in BWD */ st->bwidth = st->last_bwidth; /* updated in BWD */ st->rate_switching_reset = 0; +#ifdef DEBUGGING + st->force = st_ivas->hEncoderConfig->force; + st->id_element = sce_id; +#endif move16(); move16(); move32(); @@ -234,7 +238,7 @@ ivas_error ivas_sce_enc_fx( } #ifdef DEBUG_MODE_INFO - dbgwrite( st->input - NS2SA( st->input_Fs, ACELP_LOOK_NS ), sizeof( float ), input_frame, 1, "res/input_DMX" ); + dbgwrite( st->input_fx - NS2SA( st->input_Fs, ACELP_LOOK_NS ), sizeof( Word16 ), input_frame, 1, "res/input_DMX" ); dbgwrite( &st->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, st->id_element, ENC ) ); #endif @@ -467,6 +471,10 @@ ivas_error ivas_sce_enc( st->input_bwidth = st->last_input_bwidth; /* updated in BWD */ st->bwidth = st->last_bwidth; /* updated in BWD */ st->rate_switching_reset = 0; +#ifdef DEBUGGING + st->force = st_ivas->hEncoderConfig->force; + st->id_element = sce_id; +#endif /*---------------------------------------------------------------* * Time Domain Transient Detector diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 43ef21e03..3fa122fa5 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -466,6 +466,11 @@ typedef struct stereo_mdct_enc_data_structure /* only intraframe */ int16_t mdct_stereo_mode[2]; /* mdct stereo mode: LR, MS, band-wise MS */ +#ifdef DEBUGGING + int16_t mdct_stereo_mode_cmdl; /* MDCT stereo mode from command-line */ + int16_t fDualMono; /* force dual mono in MDCT stereo mode */ + int16_t fMSstereo; /* force full-band MS in MDCT stereo mode */ +#endif int16_t global_ild[2]; /* Quantized ILD for the whole spectrum */ int16_t split_ratio; /* Ratio of bitrate (1 to 7), split_ratio = 8 * 1st chn bitrate / (1st + 2nd chn bitrate) */ @@ -1556,6 +1561,11 @@ typedef struct cpe_enc_data_structure Word32 brate_surplus; /* bitrate surplus for bitrate adaptation in combined format coding */ Word16 *input_mem_fx[CPE_CHANNELS]; /* input channels buffers memory; needed to be up-to-date for TD->DFT stereo switching */ Word16 q_input_mem[CPE_CHANNELS]; + +#ifdef DEBUGGING + int16_t stereo_mode_cmdl; /* stereo mode forced from the commaand-line */ +#endif + } CPE_ENC_DATA, *CPE_ENC_HANDLE; @@ -1793,6 +1803,13 @@ typedef struct encoder_config_structure /* temp. development parameters */ Word16 Opt_PCA_ON; /* flag indicating PCA operation in SBA */ +#ifdef DEBUGGING + /* debugging options */ + int16_t stereo_mode_cmdl; /* stereo mode forced from the command-line */ + int16_t force; /* parameter to force specific "core" of the Core-Coder*/ + int16_t mdct_stereo_mode_cmdl; /* mdct stereo mode forced from command-line, employed only when DEBUG_FORCE_MDCT_STEREO_MODE is activated */ +#endif + } ENCODER_CONFIG, *ENCODER_CONFIG_HANDLE; diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index d78fd7433..c4c01caee 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -33,6 +33,9 @@ #include #include #include "options.h" +#ifdef DEBUGGING +#include "debug.h" +#endif #include "cnst.h" #include "rom_com.h" #include "prot.h" @@ -140,7 +143,13 @@ Word16 select_stereo_mode( test(); test(); - IF( GE_32( hCPE->element_brate, MIN_BRATE_MDCT_STEREO ) || ( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && LT_32( hCPE->element_brate, MASA_STEREO_MIN_BITRATE ) ) ) +#ifdef DEBUGGING + IF( GE_32( hCPE->element_brate, MIN_BRATE_MDCT_STEREO ) || ( ( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && + LT_32( hCPE->element_brate, MASA_STEREO_MIN_BITRATE ) ) ) || ( hCPE->stereo_mode_cmdl == IVAS_CPE_DFT || hCPE->stereo_mode_cmdl == IVAS_CPE_TD ) ) +#else + IF( GE_32( hCPE->element_brate, MIN_BRATE_MDCT_STEREO ) || ( ( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && + LT_32( hCPE->element_brate, MASA_STEREO_MIN_BITRATE ) ) ) ) +#endif { stereo_switching_flag = 0; move16(); @@ -193,6 +202,12 @@ Word16 select_stereo_mode( element_mode = IVAS_CPE_DFT; move16(); } +#ifdef DEBUGGING + if ( hCPE->stereo_mode_cmdl > 1 ) + { + element_mode = hCPE->stereo_mode_cmdl; + } +#endif } ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) ) { @@ -305,7 +320,11 @@ int16_t select_stereo_mode( stereo_switching_flag = 1; - if ( hCPE->element_brate >= MIN_BRATE_MDCT_STEREO || ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && hCPE->element_brate < MASA_STEREO_MIN_BITRATE ) ) + if ( hCPE->element_brate >= MIN_BRATE_MDCT_STEREO || ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && hCPE->element_brate < MASA_STEREO_MIN_BITRATE ) +#ifdef DEBUGGING + || ( hCPE->stereo_mode_cmdl == IVAS_CPE_DFT || hCPE->stereo_mode_cmdl == IVAS_CPE_TD ) +#endif + ) { stereo_switching_flag = 0; } @@ -341,6 +360,12 @@ int16_t select_stereo_mode( { element_mode = IVAS_CPE_DFT; } +#ifdef DEBUGGING + if ( hCPE->stereo_mode_cmdl > 1 ) + { + element_mode = hCPE->stereo_mode_cmdl; + } +#endif } else if ( element_mode == IVAS_CPE_TD ) { diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index 56520911b..63499ba90 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -265,8 +265,17 @@ void stereo_mdct_core_enc( if ( hCPE->hCoreCoder[0]->igf ) { +#ifdef DEBUGGING + int16_t orig_mdct_stereo_mode_cmdl = hCPE->hStereoMdct->mdct_stereo_mode_cmdl; + hCPE->hStereoMdct->mdct_stereo_mode_cmdl = SMDCT_MS_DECISION; +#endif + initMdctStereoEncData_fx( hCPE->hStereoMdct, STEREO_FORMAT, IVAS_CPE_MDCT, hCPE->element_brate, hCPE->hCoreCoder[0]->bwidth, hCPE->hCoreCoder[0]->igf, hCPE->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid, 0 ); +#ifdef DEBUGGING + hCPE->hStereoMdct->mdct_stereo_mode_cmdl = orig_mdct_stereo_mode_cmdl; +#endif + stereo_mdct_init_igf_start_band_fx( &( hCPE->hStereoMdct->stbParamsTCX20 ), 16384 /* 1.0f in Q14 */, hCPE->hCoreCoder[0]->bwidth, hCPE->element_brate ); stereo_mdct_init_igf_start_band_fx( &( hCPE->hStereoMdct->stbParamsTCX10 ), 8192 /* 0.5f in Q14 */, hCPE->hCoreCoder[0]->bwidth, hCPE->element_brate ); stereo_mdct_init_igf_start_band_fx( &( hCPE->hStereoMdct->stbParamsTCX20afterACELP ), 20480 /* 1.25f in Q14 */, hCPE->hCoreCoder[0]->bwidth, hCPE->element_brate ); @@ -623,8 +632,17 @@ void stereo_mdct_core_enc_fx( } IF( hCPE->hCoreCoder[0]->igf ) { +#ifdef DEBUGGING + int16_t orig_mdct_stereo_mode_cmdl = hCPE->hStereoMdct->mdct_stereo_mode_cmdl; + hCPE->hStereoMdct->mdct_stereo_mode_cmdl = SMDCT_MS_DECISION; +#endif + initMdctStereoEncData_fx( hCPE->hStereoMdct, STEREO_FORMAT, IVAS_CPE_MDCT, hCPE->element_brate, hCPE->hCoreCoder[0]->bwidth, hCPE->hCoreCoder[0]->igf, hCPE->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid, 0 ); +#ifdef DEBUGGING + hCPE->hStereoMdct->mdct_stereo_mode_cmdl = orig_mdct_stereo_mode_cmdl; +#endif + stereo_mdct_init_igf_start_band_fx( &( hCPE->hStereoMdct->stbParamsTCX20 ), 16384 /* 1.0f in Q14 */, hCPE->hCoreCoder[0]->bwidth, hCPE->element_brate ); stereo_mdct_init_igf_start_band_fx( &( hCPE->hStereoMdct->stbParamsTCX10 ), 8192 /* 0.5f in Q14 */, hCPE->hCoreCoder[0]->bwidth, hCPE->element_brate ); stereo_mdct_init_igf_start_band_fx( &( hCPE->hStereoMdct->stbParamsTCX20afterACELP ), 20480 /* 1.25f in Q14 */, hCPE->hCoreCoder[0]->bwidth, hCPE->element_brate ); diff --git a/lib_enc/ivas_stereo_mdct_stereo_enc.c b/lib_enc/ivas_stereo_mdct_stereo_enc.c index 8ee9b6051..a444a920c 100644 --- a/lib_enc/ivas_stereo_mdct_stereo_enc.c +++ b/lib_enc/ivas_stereo_mdct_stereo_enc.c @@ -360,6 +360,9 @@ void stereo_coder_tcx( } if ( +#ifdef DEBUG_FORCE_MDCT_STEREO_MODE + hStereoMdct->fDualMono || +#endif ( sts[0]->hTcxEnc->transform_type[0] != sts[1]->hTcxEnc->transform_type[0] ) || ( sts[0]->hTcxEnc->transform_type[1] != sts[1]->hTcxEnc->transform_type[1] ) || ( sts[0]->last_core != sts[1]->last_core && ( sts[0]->last_core == ACELP_CORE || sts[1]->last_core == ACELP_CORE ) ) || sts[0]->last_core == ACELP_CORE || sts[1]->last_core == ACELP_CORE ) { hStereoMdct->mdct_stereo_mode[0] = SMDCT_DUAL_MONO; @@ -376,6 +379,28 @@ void stereo_coder_tcx( pop_wmops(); return; } +#ifdef DEBUG_FORCE_MDCT_STEREO_MODE + else if ( hStereoMdct->fMSstereo ) + { + hStereoMdct->mdct_stereo_mode[0] = SMDCT_MS_FULL; + hStereoMdct->mdct_stereo_mode[1] = SMDCT_MS_FULL; + if ( sts[0]->igf ) + { + hStereoMdct->IGFStereoMode[0] = SMDCT_MS_FULL; + hStereoMdct->IGFStereoMode[1] = SMDCT_MS_FULL; + } + for ( k = 0; k < nSubframes; k++ ) + { + convertToMS( L_frameTCX, sts[0]->hTcxEnc->spectrum[k], sts[1]->hTcxEnc->spectrum[k], SQRT2_OVER_2 ); + + /* Make sure that the MDST is processed in the correct way also */ + set_s( &ms_mask[k][0], 1, MAX_SFB ); + } + + pop_wmops(); + return; + } +#endif else /* decide based on signal */ { for ( k = 0; k < nSubframes; k++ ) @@ -586,8 +611,12 @@ void stereo_coder_tcx_fx( } } - IF( +#ifdef DEBUG_FORCE_MDCT_STEREO_MODE + IF( hStereoMdct->fDualMono || ( NE_16( sts[0]->hTcxEnc->transform_type[0], sts[1]->hTcxEnc->transform_type[0] ) ) || NE_16( sts[0]->hTcxEnc->transform_type[1], sts[1]->hTcxEnc->transform_type[1] ) || ( NE_16( sts[0]->last_core, sts[1]->last_core ) && ( EQ_16( sts[0]->last_core, ACELP_CORE ) || EQ_16( sts[1]->last_core, ACELP_CORE ) ) ) || EQ_16( sts[0]->last_core, ACELP_CORE ) || EQ_16( sts[1]->last_core, ACELP_CORE ) ) +#else + IF( ( NE_16( sts[0]->hTcxEnc->transform_type[0], sts[1]->hTcxEnc->transform_type[0] ) ) || NE_16( sts[0]->hTcxEnc->transform_type[1], sts[1]->hTcxEnc->transform_type[1] ) || ( NE_16( sts[0]->last_core, sts[1]->last_core ) && ( EQ_16( sts[0]->last_core, ACELP_CORE ) || EQ_16( sts[1]->last_core, ACELP_CORE ) ) ) || EQ_16( sts[0]->last_core, ACELP_CORE ) || EQ_16( sts[1]->last_core, ACELP_CORE ) ) +#endif { hStereoMdct->mdct_stereo_mode[0] = SMDCT_DUAL_MONO; move16(); @@ -608,6 +637,29 @@ void stereo_coder_tcx_fx( pop_wmops(); return; } +#ifdef DEBUG_FORCE_MDCT_STEREO_MODE + else if ( hStereoMdct->fMSstereo ) + { + hStereoMdct->mdct_stereo_mode[0] = SMDCT_MS_FULL; + hStereoMdct->mdct_stereo_mode[1] = SMDCT_MS_FULL; + + if ( sts[0]->igf ) + { + hStereoMdct->IGFStereoMode[0] = SMDCT_MS_FULL; + hStereoMdct->IGFStereoMode[1] = SMDCT_MS_FULL; + } + for ( k = 0; k < nSubframes; k++ ) + { + convertToMS_fx( L_frameTCX, sts[0]->hTcxEnc->spectrum_fx[k], sts[1]->hTcxEnc->spectrum_fx[k], SQRT2_OVER_2 ); + + /* Make sure that the MDST is processed in the correct way also */ + set_s( &ms_mask[k][0], 1, MAX_SFB ); + } + + pop_wmops(); + return; + } +#endif ELSE /* decide based on signal */ { FOR( k = 0; k < nSubframes; k++ ) @@ -2146,6 +2198,20 @@ void initMdctStereoEncData( set_s( hStereoMdct->IGFStereoMode, -1, 2 ); +#ifdef DEBUG_FORCE_MDCT_STEREO_MODE + /*set all other members to defined states */ + hStereoMdct->fDualMono = 0; + hStereoMdct->fMSstereo = 0; + + if ( hStereoMdct->mdct_stereo_mode_cmdl == SMDCT_FORCE_LR ) + { + hStereoMdct->fDualMono = 1; + } + else if ( hStereoMdct->mdct_stereo_mode_cmdl == SMDCT_FORCE_MS ) + { + hStereoMdct->fMSstereo = 1; + } +#endif hStereoMdct->split_ratio = SMDCT_EQUAL_RATIO_RANGE; set_s( hStereoMdct->global_ild, SMDCT_ILD_RANGE >> 1, 2 ); @@ -2205,6 +2271,20 @@ void initMdctStereoEncData_fx( set16_fx( hStereoMdct->IGFStereoMode, -1, 2 ); +#ifdef DEBUG_FORCE_MDCT_STEREO_MODE + /*set all other members to defined states */ + hStereoMdct->fDualMono = 0; + hStereoMdct->fMSstereo = 0; + + if ( hStereoMdct->mdct_stereo_mode_cmdl == SMDCT_FORCE_LR ) + { + hStereoMdct->fDualMono = 1; + } + else if ( hStereoMdct->mdct_stereo_mode_cmdl == SMDCT_FORCE_MS ) + { + hStereoMdct->fMSstereo = 1; + } +#endif hStereoMdct->split_ratio = SMDCT_EQUAL_RATIO_RANGE; move16(); diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 7b30c3f87..9eccb95c1 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -722,6 +722,10 @@ ivas_error stereo_memory_enc_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); } +#ifdef DEBUGGING + hCPE->hStereoMdct->mdct_stereo_mode_cmdl = SMDCT_MS_DECISION; +#endif + initMdctStereoEncData_fx( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, hCPE->hCoreCoder[0]->max_bwidth, 0, NULL, 1 ); test(); @@ -1127,6 +1131,10 @@ ivas_error stereo_memory_enc( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); } +#ifdef DEBUGGING + hCPE->hStereoMdct->mdct_stereo_mode_cmdl = SMDCT_MS_DECISION; +#endif + #ifndef IVAS_FLOAT_FIXED initMdctStereoEncData( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, hCPE->hCoreCoder[0]->max_bwidth, 0, NULL, 1 ); #else diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index 5297df659..2b0a8e61d 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -1518,6 +1518,18 @@ int16_t ivas_acelp_tcx20_switching( smc_dec_ol = 2; } +#ifdef DEBUGGING + if ( st->force == FORCE_SPEECH ) + { + /* enforce ACELP */ + smc_dec_ol = 0; + } + else if ( st->force == FORCE_MUSIC ) + { + /* enforce TCX */ + smc_dec_ol = 2; + } +#endif st->prevTempFlatness = currFlatness; @@ -2111,6 +2123,20 @@ Word16 ivas_acelp_tcx20_switching_fx( smc_dec_ol = 2; move16(); } + +#ifdef DEBUGGING + if ( st->force == FORCE_SPEECH ) + { + /* enforce ACELP */ + smc_dec_ol = 0; + } + else if ( st->force == FORCE_MUSIC ) + { + /* enforce TCX */ + smc_dec_ol = 2; + } +#endif + st->prevTempFlatness_fx = currFlatness; move16(); return smc_dec_ol; diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 7d7617431..5de0a08d6 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -30,19 +30,23 @@ *******************************************************************************************************/ +#include +#include +#include +#include +#include "options.h" +#ifdef DEBUGGING +#include "debug.h" +#endif #include "lib_enc.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" #include "prot.h" #include "prot_fx.h" #include "prot_fx_enc.h" -#include -#include -#include -#include #include "wmc_auto.h" -#include "options.h" #include "ivas_rom_enc.h" + /*---------------------------------------------------------------------* * Local struct *---------------------------------------------------------------------*/ @@ -52,6 +56,9 @@ struct IVAS_ENC Encoder_Struct *st_ivas; ENC_CORE_HANDLE hCoreCoder; bool isConfigured; +#ifdef DEBUGGING + bool cmd_stereo; +#endif bool switchingActive; /* flag for configuration changes during encoding - currently only used with mono */ int16_t Opt_RF_ON_loc; int16_t rf_fec_offset_loc; @@ -83,6 +90,9 @@ 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 fecIndicatorApiToInternal( const IVAS_ENC_FEC_INDICATOR fecIndicator, int16_t *fecIndicatorInternal ); +#ifdef DEBUGGING +static ivas_error forcedModeApiToInternal( IVAS_ENC_FORCED_MODE forcedMode, int16_t *forcedModeInternal ); +#endif /*---------------------------------------------------------------------* @@ -113,6 +123,9 @@ ivas_error IVAS_ENC_Open( ( *phIvasEnc )->hCoreCoder = NULL; ( *phIvasEnc )->isConfigured = false; +#ifdef DEBUGGING + ( *phIvasEnc )->cmd_stereo = false; +#endif ( *phIvasEnc )->switchingActive = false; ( *phIvasEnc )->maxBandwidthUser = false; resetIsmMetadataProvidedFlags( *phIvasEnc ); @@ -313,6 +326,10 @@ ivas_error IVAS_ENC_ConfigureForStereo( const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ const bool is_binaural /* i : flag indicating if input is binaural audio */ +#ifdef DEBUGGING + , + const IVAS_ENC_STEREO_MODE stereoMode /* i : forces a specific stereo coding mode */ +#endif ) { Encoder_Struct *st_ivas; @@ -331,6 +348,41 @@ ivas_error IVAS_ENC_ConfigureForStereo( hEncoderConfig->ivas_format = STEREO_FORMAT; hEncoderConfig->is_binaural = (int16_t) is_binaural; +#ifdef DEBUGGING + switch ( stereoMode ) + { + case IVAS_ENC_STEREO_MODE_UNIFIED: + hEncoderConfig->stereo_mode_cmdl = 1; /* set unified stereo by default */ + hEncoderConfig->element_mode_init = IVAS_CPE_DFT; + hIvasEnc->cmd_stereo = true; + break; + case IVAS_ENC_STEREO_MODE_DFT: + hEncoderConfig->element_mode_init = IVAS_CPE_DFT; + hEncoderConfig->stereo_mode_cmdl = IVAS_CPE_DFT; + break; + case IVAS_ENC_STEREO_MODE_TD: + hEncoderConfig->stereo_mode_cmdl = IVAS_CPE_TD; + hEncoderConfig->element_mode_init = IVAS_CPE_TD; + break; + case IVAS_ENC_STEREO_MODE_MDCT_DECISION: + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + hEncoderConfig->mdct_stereo_mode_cmdl = SMDCT_MS_DECISION; + break; +#ifdef DEBUG_FORCE_MDCT_STEREO_MODE + case IVAS_ENC_STEREO_MODE_MDCT_FORCE_LR: + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + hEncoderConfig->mdct_stereo_mode_cmdl = SMDCT_FORCE_LR; + break; + case IVAS_ENC_STEREO_MODE_MDCT_FORCE_MS: + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + hEncoderConfig->mdct_stereo_mode_cmdl = SMDCT_FORCE_MS; + break; +#endif + default: + return IVAS_ERR_INVALID_STEREO_MODE; + break; + } +#endif /* DEBUGGING */ hIvasEnc->maxBandwidthUser = max_bwidth_user; @@ -737,6 +789,9 @@ ivas_error IVAS_ENC_ConfigureForMasa( BREAK; case IVAS_ENC_MASA_2CH: hEncoderConfig->nchan_inp = 2; +#ifdef DEBUGGING + hEncoderConfig->stereo_mode_cmdl = 1; /* set unified stereo by default */ +#endif hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */ move16(); move16(); @@ -783,6 +838,9 @@ ivas_error IVAS_ENC_ConfigureForMasa( break; case IVAS_ENC_MASA_2CH: hEncoderConfig->nchan_inp = 2; +#ifdef DEBUGGING + hEncoderConfig->stereo_mode_cmdl = 1; /* set unified stereo by default */ +#endif hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */ break; default: @@ -993,11 +1051,21 @@ static ivas_error configureEncoder( if ( hEncoderConfig->ivas_format == STEREO_FORMAT ) { +#ifdef DEBUGGING + if ( hIvasEnc->cmd_stereo ) +#endif { hEncoderConfig->element_mode_init = IVAS_CPE_DFT; +#ifdef DEBUGGING + hEncoderConfig->stereo_mode_cmdl = 1; +#endif + if ( hEncoderConfig->ivas_total_brate >= MIN_BRATE_MDCT_STEREO ) { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; +#ifdef DEBUGGING + hEncoderConfig->stereo_mode_cmdl = 0; +#endif } } @@ -2281,6 +2349,41 @@ ivas_error IVAS_ENC_SetChannelAwareConfig( return setChannelAwareConfig_fx( hIvasEnc, rfConfig ); } +#ifdef DEBUGGING +/*---------------------------------------------------------------------* + * IVAS_ENC_SetForcedMode() + * + * + *---------------------------------------------------------------------*/ + +ivas_error IVAS_ENC_SetForcedMode( + IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + const IVAS_ENC_FORCED_MODE forcedMode /* i : forced coding mode */ +) +{ + int16_t newForced; + ivas_error error; + + /* Do additional checks for user-facing function */ + if ( ( error = doCommonSetterChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = forcedModeApiToInternal( forcedMode, &newForced ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( hIvasEnc->st_ivas->hEncoderConfig->force != newForced ) + { + hIvasEnc->st_ivas->hEncoderConfig->force = newForced; + hIvasEnc->switchingActive = true; + } + + return IVAS_ERR_OK; +} +#endif /* DEBUGGING */ /*---------------------------------------------------------------------* * IVAS_ENC_GetDefaultBandwidth() @@ -2404,6 +2507,24 @@ static ivas_error printConfigInfo_enc( } else if ( hEncoderConfig->ivas_format == STEREO_FORMAT ) { +#ifdef DEBUGGING + if ( hEncoderConfig->stereo_mode_cmdl == 1 ) + { + fprintf( stdout, "IVAS format: stereo - Unified stereo\n" ); + } + else if ( hEncoderConfig->element_mode_init == IVAS_CPE_DFT ) + { + fprintf( stdout, "IVAS format: stereo - DFT stereo\n" ); + } + else if ( hEncoderConfig->element_mode_init == IVAS_CPE_TD ) + { + fprintf( stdout, "IVAS format: stereo - TD stereo\n" ); + } + else if ( hEncoderConfig->element_mode_init == IVAS_CPE_MDCT ) + { + fprintf( stdout, "IVAS format: stereo - MDCT stereo\n" ); + } +#else if ( hEncoderConfig->element_mode_init != IVAS_CPE_MDCT ) { fprintf( stdout, "IVAS format: stereo - Unified stereo\n" ); @@ -2412,6 +2533,7 @@ static ivas_error printConfigInfo_enc( { fprintf( stdout, "IVAS format: stereo - MDCT stereo\n" ); } +#endif } else if ( hEncoderConfig->ivas_format == ISM_FORMAT ) { @@ -3036,6 +3158,48 @@ static ivas_error fecIndicatorApiToInternal( return IVAS_ERR_OK; } +#ifdef DEBUGGING +/*---------------------------------------------------------------------* + * forcedModeApiToInternal() + * + * + *---------------------------------------------------------------------*/ + +static ivas_error forcedModeApiToInternal( + IVAS_ENC_FORCED_MODE forcedMode, + int16_t *forcedModeInternal ) +{ + switch ( forcedMode ) + { + case IVAS_ENC_FORCE_SPEECH: + *forcedModeInternal = FORCE_SPEECH; + break; + case IVAS_ENC_FORCE_MUSIC: + *forcedModeInternal = FORCE_MUSIC; + break; + case IVAS_ENC_FORCE_ACELP: + *forcedModeInternal = FORCE_ACELP; + break; + case IVAS_ENC_FORCE_GSC: + *forcedModeInternal = FORCE_GSC; + break; + case IVAS_ENC_FORCE_TCX: + *forcedModeInternal = FORCE_TCX; + break; + case IVAS_ENC_FORCE_HQ: + *forcedModeInternal = FORCE_HQ; + break; + case IVAS_ENC_FORCE_UNFORCED: + *forcedModeInternal = -1; + break; + default: + return IVAS_ERR_INVALID_FORCE_MODE; + break; + } + + return IVAS_ERR_OK; +} +#endif /*---------------------------------------------------------------------* * IVAS_ENC_PrintConfig() @@ -3098,6 +3262,11 @@ static void init_encoder_config( hEncoderConfig->sba_order = 0; hEncoderConfig->sba_planar = 0; hEncoderConfig->ism_extended_metadata_flag = 0; +#ifdef DEBUGGING + hEncoderConfig->stereo_mode_cmdl = 0; + hEncoderConfig->force = -1; + hEncoderConfig->mdct_stereo_mode_cmdl = SMDCT_MS_DECISION; +#endif hEncoderConfig->Opt_PCA_ON = 0; return; diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index 67e747393..03a0bee9e 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -109,6 +109,31 @@ typedef enum _IVAS_ENC_COMBINED_FORMAT IVAS_ENC_COMBINED_UNDEFINED = 0xffff } IVAS_ENC_COMBINED_FORMAT; +#ifdef DEBUGGING +typedef enum _IVAS_ENC_STEREO_MODE +{ + IVAS_ENC_STEREO_MODE_UNIFIED, + IVAS_ENC_STEREO_MODE_DFT, + IVAS_ENC_STEREO_MODE_TD, + IVAS_ENC_STEREO_MODE_MDCT_DECISION, + IVAS_ENC_STEREO_MODE_MDCT_FORCE_LR, + IVAS_ENC_STEREO_MODE_MDCT_FORCE_MS, + IVAS_ENC_STEREO_MODE_UNDEFINED = 0xffff +} IVAS_ENC_STEREO_MODE; + +typedef enum _IVAS_ENC_FORCED_MODE +{ + IVAS_ENC_FORCE_SPEECH, + IVAS_ENC_FORCE_MUSIC, + IVAS_ENC_FORCE_ACELP, + IVAS_ENC_FORCE_GSC, + IVAS_ENC_FORCE_TCX, + IVAS_ENC_FORCE_HQ, + IVAS_ENC_FORCE_UNFORCED, + IVAS_ENC_FORCE_UNDEFINED = 0xffff +} IVAS_ENC_FORCED_MODE; + +#endif /*---------------------------------------------------------------------* * Encoder structures @@ -154,6 +179,10 @@ ivas_error IVAS_ENC_ConfigureForStereo( const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ const bool is_binaural /* i : flag indicating if input is binaural audio */ +#ifdef DEBUGGING + , + const IVAS_ENC_STEREO_MODE stereoMode /* i : forces a specific stereo coding mode */ +#endif ); /*! r: error code */ @@ -306,6 +335,13 @@ ivas_error IVAS_ENC_SetChannelAwareConfig( const IVAS_ENC_CHANNEL_AWARE_CONFIG rfConfig /* i : configuration of channel-aware mode */ ); +#ifdef DEBUGGING +/*! r: error code */ +ivas_error IVAS_ENC_SetForcedMode( + IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + const IVAS_ENC_FORCED_MODE forcedMode /* i : forced coding mode */ +); +#endif /* Getter functions - retrieve information from an encoder through a handle */ diff --git a/lib_enc/speech_music_classif.c b/lib_enc/speech_music_classif.c index db163997d..52d516068 100644 --- a/lib_enc/speech_music_classif.c +++ b/lib_enc/speech_music_classif.c @@ -334,7 +334,11 @@ void speech_music_classif( } /* Select AUDIO frames */ +#ifdef DEBUGGING + if ( st->codec_mode == MODE1 && ( st->force == 1 || ( st->force == -1 && ( st->sp_aud_decision2 || st->GSC_noisy_speech ) ) ) ) +#else if ( st->codec_mode == MODE1 && ( st->sp_aud_decision2 || st->GSC_noisy_speech ) ) +#endif { st->coder_type = AUDIO; st->hGSCEnc->noise_lev = NOISE_LEVEL_SP0; @@ -1956,6 +1960,38 @@ void ivas_smc_mode_selection( *attack_flag = attack + 1; } +#ifdef DEBUGGING + if ( st->idchan == 0 && st->coder_type != INACTIVE ) + { + if ( st->force == FORCE_GSC && element_brate < IVAS_24k4 ) + { + /* enforce GSC */ + st->sp_aud_decision1 = 1; + st->sp_aud_decision2 = 0; + } + else if ( st->force == FORCE_SPEECH && ( st->sp_aud_decision1 == 1 || st->sp_aud_decision2 == 1 ) ) + { + if ( element_brate < IVAS_24k4 ) + { + /* convert TCX to GSC */ + st->sp_aud_decision1 = 1; + st->sp_aud_decision2 = 0; + } + else + { + /* convert TCX to ACELP */ + st->sp_aud_decision1 = 0; + st->sp_aud_decision2 = 0; + } + } + else if ( st->force == FORCE_MUSIC ) + { + /* enforce TCX */ + st->sp_aud_decision1 = 1; + st->sp_aud_decision2 = 1; + } + } +#endif /* set GSC noisy speech flag on unvoiced SWB segments */ st->GSC_noisy_speech = 0; diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index 9ce07aff1..b70a90625 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -598,7 +598,11 @@ void speech_music_classif_fx( test(); test(); test(); +#ifdef DEBUGGING + if ( st->codec_mode == MODE1 && ( st->force == 1 || ( st->force == -1 && ( st->sp_aud_decision2 || st->GSC_noisy_speech ) ) ) ) +#else IF( EQ_16( st->codec_mode, MODE1 ) && ( st->sp_aud_decision2 || st->GSC_noisy_speech ) ) +#endif { st->coder_type = AUDIO; move16(); @@ -2624,7 +2628,7 @@ Word16 ivas_smc_gmm_fx( hSpMusClas->past_dec[0] = dec; move16(); #ifdef DEBUG_MODE_INFO - dbgwrite( &st->hSpMusClas->wdlp_0_95_sp, sizeof( float ), 1, 1, "res/wdlp_0_95_sp.x" ); + dbgwrite( &st->hSpMusClas->wdlp_0_95_sp_32fx, sizeof( Word32 ), 1, 1, "res/wdlp_0_95_sp.x" ); #endif return dec; @@ -3188,6 +3192,38 @@ void ivas_smc_mode_selection_fx( move16(); } +#ifdef DEBUGGING + if ( st->idchan == 0 && st->coder_type != INACTIVE ) + { + if ( st->force == FORCE_GSC && element_brate < IVAS_24k4 ) + { + /* enforce GSC */ + st->sp_aud_decision1 = 1; + st->sp_aud_decision2 = 0; + } + else if ( st->force == FORCE_SPEECH && ( st->sp_aud_decision1 == 1 || st->sp_aud_decision2 == 1 ) ) + { + if ( element_brate < IVAS_24k4 ) + { + /* convert TCX to GSC */ + st->sp_aud_decision1 = 1; + st->sp_aud_decision2 = 0; + } + else + { + /* convert TCX to ACELP */ + st->sp_aud_decision1 = 0; + st->sp_aud_decision2 = 0; + } + } + else if ( st->force == FORCE_MUSIC ) + { + /* enforce TCX */ + st->sp_aud_decision1 = 1; + st->sp_aud_decision2 = 1; + } + } +#endif /* set GSC noisy speech flag on unvoiced SWB segments */ st->GSC_noisy_speech = 0; diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index e61931e49..eb25fbdde 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1987,6 +1987,9 @@ typedef struct enc_core_structure int16_t last_Opt_SC_VBR; /* flag indicating prev frame's SC-VBR mode */ int16_t low_rate_mode; /* low-rate mode flag */ int16_t inactive_coder_type_flag; /* inactive coder type flag (0 = AVQ / 1 = GSC) */ +#ifdef DEBUGGING + int16_t force; /* flag indicating specific signal type (0 = speech, 1 = music, -1 = N/A) */ +#endif Word16 nTimeSlots; /* for CLDFB */ Word16 ini_frame; /* initialization frames counter */ -- GitLab From a65227f35ca35d5a076138a56acc0940f1981067 Mon Sep 17 00:00:00 2001 From: Vladimir Malenovsky Date: Mon, 2 Dec 2024 13:23:39 +0100 Subject: [PATCH 2/2] clang format --- apps/encoder.c | 6 +++--- lib_com/prot.h | 14 +++++++------- lib_enc/ivas_stat_enc.h | 4 ++-- lib_enc/ivas_stereo_classifier.c | 9 ++++----- lib_enc/lib_enc.c | 2 +- lib_enc/stat_enc.h | 4 ++-- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index 694f4e936..98fb9aaa2 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -1946,9 +1946,9 @@ static IVAS_ENC_FORCED_MODE parseForcedMode( *---------------------------------------------------------------------*/ static ivas_error readForcedMode( - FILE * file, - IVAS_ENC_FORCED_MODE * forcedMode, - int32_t * forceFrameCounter ) + FILE *file, + IVAS_ENC_FORCED_MODE *forcedMode, + int32_t *forceFrameCounter ) { int16_t res; char stmp[8]; diff --git a/lib_com/prot.h b/lib_com/prot.h index 1bb11d157..416fe08e4 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2233,13 +2233,13 @@ void bit_allocation_second_fx2( const Word16 input_frame ); void io_ini_enc( - const int32_t argc, /* i : command line arguments number */ - char *argv[], /* i : command line arguments */ - FILE **f_input, /* o : input signal file */ - FILE **f_stream, /* o : output bitstream file */ - FILE **f_rate, /* o : bitrate switching profile (0 if N/A) */ - FILE **f_bwidth, /* o : bandwidth switching profile (0 if N/A) */ - FILE **f_metadata, /* o : metadata files (NULL if N/A) */ + const int32_t argc, /* i : command line arguments number */ + char *argv[], /* i : command line arguments */ + FILE **f_input, /* o : input signal file */ + FILE **f_stream, /* o : output bitstream file */ + FILE **f_rate, /* o : bitrate switching profile (0 if N/A) */ + FILE **f_bwidth, /* o : bandwidth switching profile (0 if N/A) */ + FILE **f_metadata, /* o : metadata files (NULL if N/A) */ #ifdef DEBUGGING FILE **f_force, /* o : force switching profile (0 if N/A) */ #endif diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 3fa122fa5..0e80b387a 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -471,8 +471,8 @@ typedef struct stereo_mdct_enc_data_structure int16_t fDualMono; /* force dual mono in MDCT stereo mode */ int16_t fMSstereo; /* force full-band MS in MDCT stereo mode */ #endif - int16_t global_ild[2]; /* Quantized ILD for the whole spectrum */ - int16_t split_ratio; /* Ratio of bitrate (1 to 7), split_ratio = 8 * 1st chn bitrate / (1st + 2nd chn bitrate) */ + int16_t global_ild[2]; /* Quantized ILD for the whole spectrum */ + int16_t split_ratio; /* Ratio of bitrate (1 to 7), split_ratio = 8 * 1st chn bitrate / (1st + 2nd chn bitrate) */ int16_t IGFStereoMode[2]; /* MDCT stereo mode for IGF */ diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index c4c01caee..b63cf8de3 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -144,11 +144,10 @@ Word16 select_stereo_mode( test(); test(); #ifdef DEBUGGING - IF( GE_32( hCPE->element_brate, MIN_BRATE_MDCT_STEREO ) || ( ( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && - LT_32( hCPE->element_brate, MASA_STEREO_MIN_BITRATE ) ) ) || ( hCPE->stereo_mode_cmdl == IVAS_CPE_DFT || hCPE->stereo_mode_cmdl == IVAS_CPE_TD ) ) + IF( GE_32( hCPE->element_brate, MIN_BRATE_MDCT_STEREO ) || ( ( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && LT_32( hCPE->element_brate, MASA_STEREO_MIN_BITRATE ) ) ) || ( hCPE->stereo_mode_cmdl == IVAS_CPE_DFT || hCPE->stereo_mode_cmdl == IVAS_CPE_TD ) ) #else IF( GE_32( hCPE->element_brate, MIN_BRATE_MDCT_STEREO ) || ( ( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && - LT_32( hCPE->element_brate, MASA_STEREO_MIN_BITRATE ) ) ) ) + LT_32( hCPE->element_brate, MASA_STEREO_MIN_BITRATE ) ) ) ) #endif { stereo_switching_flag = 0; @@ -320,11 +319,11 @@ int16_t select_stereo_mode( stereo_switching_flag = 1; - if ( hCPE->element_brate >= MIN_BRATE_MDCT_STEREO || ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && hCPE->element_brate < MASA_STEREO_MIN_BITRATE ) + if ( hCPE->element_brate >= MIN_BRATE_MDCT_STEREO || ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && hCPE->element_brate < MASA_STEREO_MIN_BITRATE ) #ifdef DEBUGGING || ( hCPE->stereo_mode_cmdl == IVAS_CPE_DFT || hCPE->stereo_mode_cmdl == IVAS_CPE_TD ) #endif - ) + ) { stereo_switching_flag = 0; } diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 5de0a08d6..6c8ec4e29 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -839,7 +839,7 @@ ivas_error IVAS_ENC_ConfigureForMasa( case IVAS_ENC_MASA_2CH: hEncoderConfig->nchan_inp = 2; #ifdef DEBUGGING - hEncoderConfig->stereo_mode_cmdl = 1; /* set unified stereo by default */ + hEncoderConfig->stereo_mode_cmdl = 1; /* set unified stereo by default */ #endif hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */ break; diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index eb25fbdde..7a792ae0f 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1988,9 +1988,9 @@ typedef struct enc_core_structure int16_t low_rate_mode; /* low-rate mode flag */ int16_t inactive_coder_type_flag; /* inactive coder type flag (0 = AVQ / 1 = GSC) */ #ifdef DEBUGGING - int16_t force; /* flag indicating specific signal type (0 = speech, 1 = music, -1 = N/A) */ + int16_t force; /* flag indicating specific signal type (0 = speech, 1 = music, -1 = N/A) */ #endif - Word16 nTimeSlots; /* for CLDFB */ + Word16 nTimeSlots; /* for CLDFB */ Word16 ini_frame; /* initialization frames counter */ -- GitLab