From d3a553444e5585d91267aa02ce6ed60552b5c727 Mon Sep 17 00:00:00 2001 From: malenov Date: Thu, 12 Dec 2024 14:52:00 +0100 Subject: [PATCH 01/14] add support for enforcement of modes/parameters through external binary files --- apps/encoder.c | 59 +++++++++++++++++++++++++++++- lib_com/options.h | 3 +- lib_debug/debug.c | 18 +++++++++ lib_debug/debug.h | 4 ++ lib_enc/ivas_core_pre_proc_front.c | 43 ++++++++++++++++++++++ lib_enc/ivas_cpe_enc.c | 3 ++ lib_enc/ivas_decision_matrix_enc.c | 9 +++++ lib_enc/ivas_stat_enc.h | 6 +++ lib_enc/ivas_stereo_classifier.c | 9 +++++ lib_enc/lib_enc.c | 26 +++++++++++++ lib_enc/lib_enc.h | 3 ++ lib_enc/stat_enc.h | 5 ++- 12 files changed, 184 insertions(+), 4 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index 98fb9aaa2..0eae15fc1 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -45,6 +45,20 @@ #include "masa_file_reader.h" #include "wmc_auto.h" +#ifdef DEBUG_FORCE_DIR +/* Windows does not define the S_ISREG and S_ISDIR macros in stat.h, so we do. + We have to define _CRT_INTERNAL_NONSTDC_NAMES 1 before #including sys/stat.h + in order for Microsoft's stat.h to define names like S_IFMT, S_IFREG, and S_IFDIR, + rather than just defining _S_IFMT, _S_IFREG, and _S_IFDIR as it normally does. */ +#include +#if !defined( S_ISREG ) && defined( S_IFMT ) && defined( S_IFREG ) +#define S_ISREG( m ) ( ( (m) &S_IFMT ) == S_IFREG ) +#endif +#if !defined( S_ISDIR ) && defined( S_IFMT ) && defined( S_IFDIR ) +#define S_ISDIR( m ) ( ( (m) &S_IFMT ) == S_IFDIR ) +#endif +#endif + #define WMC_TOOL_SKIP /*------------------------------------------------------------------------------------------* @@ -184,6 +198,9 @@ int main( int16_t *pcmBuf = NULL; #ifdef DEBUGGING FILE *f_forcedModeProfile = NULL; +#ifdef DEBUG_FORCE_DIR + bool f_forceModeDir = false; +#endif #endif #ifdef WMOPS @@ -529,15 +546,42 @@ int main( #ifdef DEBUGGING IVAS_ENC_FORCED_MODE forcedMode = arg.forcedMode; int32_t force_profile_cnt = 0; +#ifdef DEBUG_FORCE_DIR + struct stat path_stat; +#endif if ( arg.forcedModeFile ) { +#ifdef DEBUG_FORCE_DIR + if ( stat( arg.forcedModeFile, &path_stat ) != 0 ) + { + fprintf( stderr, "\nError: The profile file/dir could not be opened: %s\n\n", arg.forcedModeFile ); + usage_enc(); + goto cleanup; + } + + /* check if it is a directory */ + if ( S_ISDIR( path_stat.st_mode ) ) + { + f_forceModeDir = true; + } + else + { + 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; + } + } +#else 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 } #endif @@ -685,9 +729,17 @@ int main( } /* Force mode not set when configuring, set in first frame even if not reading from file */ - if ( f_forcedModeProfile || frame == 0 ) + if ( f_forcedModeProfile || +#ifdef DEBUG_FORCE_DIR + f_forceModeDir || +#endif + frame == 0 ) { - if ( ( error = IVAS_ENC_SetForcedMode( hIvasEnc, forcedMode ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_ENC_SetForcedMode( hIvasEnc, forcedMode +#ifdef DEBUG_FORCE_DIR + , arg.forcedModeFile +#endif + ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_ENC_SetForcedMode failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); goto cleanup; @@ -1798,6 +1850,9 @@ static void usage_enc( void ) #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" ); +#ifdef DEBUG_FORCE_DIR + fprintf( stdout, " or T can be a directory containing external binary files for modes/parameters enforcement\n" ); +#endif #endif #ifdef DEBUG_MODE_INFO #ifdef DEBUG_MODE_INFO_TWEAK diff --git a/lib_com/options.h b/lib_com/options.h index 5ad891b9b..e57bee05d 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -49,7 +49,8 @@ #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 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 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 DEBUG_FORCE_DIR /* Force modes/parameters by reading from external binary files */ /*#define DBG_WAV_WRITER*/ /* Enable dbgwrite_wav() function for generating ".wav" files */ #endif diff --git a/lib_debug/debug.c b/lib_debug/debug.c index f1cfa928a..2608be30a 100644 --- a/lib_debug/debug.c +++ b/lib_debug/debug.c @@ -363,6 +363,13 @@ int16_t dbgread( { index = in_count; in_fileptr[index] = fopen( filename, "rb" ); +#ifdef DEBUG_FORCE_DIR + if ( in_fileptr[index] == NULL ) + { + /* file does not exist or could not be opened -> just return */ + return -1; + } +#endif in_filename[index] = malloc( sizeof( char ) * ( strlen( filename ) + 1 ) ); strcpy( in_filename[index], filename ); in_count++; @@ -773,8 +780,19 @@ char *fname( { char idd[5] = ".idX"; idd[3] = (char) ( id + '0' ); +#ifdef DEBUG_FORCE_DIR + short len; +#endif strcpy( tmp_fname, dir ); +#ifdef DEBUG_FORCE_DIR + len = strlen( tmp_fname ); + if (tmp_fname[len - 1] != '/' && tmp_fname[len - 1] != '\\' ) + { + /* add trailing '/' slash */ + strcat( tmp_fname, "/" ); + } +#endif strcat( tmp_fname, file ); if ( enc_dec == DEC ) diff --git a/lib_debug/debug.h b/lib_debug/debug.h index e88def922..c1c978bfe 100644 --- a/lib_debug/debug.h +++ b/lib_debug/debug.h @@ -66,6 +66,10 @@ extern char debug_dir[6]; char *fname( char *dir, char *file, const int16_t n, const int16_t id, const int16_t enc_dec ); #endif +#ifdef DEBUG_FORCE_DIR +#define FORCE_DIR_MAX_LENGTH 255 /* maximum length of the directory for modes/parameters enforcement */ +#endif + /*------------------------------------------------------------------------------------------* * Read/write I/O tool *------------------------------------------------------------------------------------------*/ diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 05848dc4c..5b36b6bad 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -1617,6 +1617,15 @@ ivas_error pre_proc_front_ivas_fx( st->vad_flag = wb_vad_ivas_fx( st, fr_bands_fx, &i, &i, &i, &snr_sum_he_fx, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr ), Q_new, NULL, NULL, -MAX_16, -MAX_16 ); //-100000f == max 16bit float move16(); +#ifdef DEBUG_FORCE_DIR + dbgwrite( &st->vad_flag, sizeof( int16_t ), 1, 1, "res/force_vad_flag.enf" ); + + if ( st->force_dir[0] != '\0' ) + { + dbgread( &st->vad_flag, sizeof( int16_t ), 1, fname( st->force_dir, "force_vad_flag.enf", -1, -1, -1 ) ); + } +#endif + test(); IF( EQ_16( force_front_vad, 1 ) || EQ_16( front_vad_flag, 1 ) ) { @@ -1694,6 +1703,16 @@ ivas_error pre_proc_front_ivas_fx( move16(); } +#ifdef DEBUG_FORCE_DIR + dbgwrite( &st->bwidth, sizeof( int16_t ), 1, 1, "res/force_bwidth.enf" ); + + if ( st->force_dir[0] != '\0' ) + { + dbgread( &st->bwidth, sizeof( int16_t ), 1, fname( st->force_dir, "force_bwidth.enf", -1, -1, -1 ) ); + } +#endif + + /*----------------------------------------------------------------* * Noise energy down-ward update and total noise energy estimation * Long-term energies and relative frame energy updates @@ -2340,6 +2359,15 @@ 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 DEBUG_FORCE_DIR + dbgwrite( &smc_dec, sizeof( int16_t ), 1, 1, "res/force_smc_dec_loc1.enf" ); + + if ( st->force_dir[0] != '\0' ) + { + dbgread( &smc_dec, sizeof( int16_t ), 1, fname( st->force_dir, "force_smc_dec_loc1.enf", -1, -1, -1 ) ); + } +#endif + #ifdef DEBUGGING if ( st->idchan == 0 ) { @@ -2533,6 +2561,21 @@ ivas_error pre_proc_front_ivas_fx( ivas_smc_mode_selection_fx( st, element_brate, smc_dec, *relE_fx, Etot_fx, attack_flag, inp_12k8_fx, Q_new, S_map_fx, flag_spitch ); } +#ifdef DEBUG_FORCE_DIR + dbgwrite( &smc_dec, sizeof( int16_t ), 1, 1, "res/force_smc_dec_loc2.enf" ); + dbgwrite( &st->sp_aud_decision0, sizeof( int16_t ), 1, 1, "res/force_sp_aud_decision0.enf" ); + dbgwrite( &st->sp_aud_decision1, sizeof( int16_t ), 1, 1, "res/force_sp_aud_decision1.enf" ); + dbgwrite( &st->sp_aud_decision2, sizeof( int16_t ), 1, 1, "res/force_sp_aud_decision2.enf" ); + + if ( st->force_dir[0] != '\0' ) + { + dbgread( &smc_dec, sizeof( int16_t ), 1, fname( st->force_dir, "force_smc_dec_loc2.enf", -1, -1, -1 ) ); + dbgread( &st->sp_aud_decision0, sizeof( int16_t ), 1, fname( st->force_dir, "force_sp_aud_decision0.enf", -1, -1, -1 ) ); + dbgread( &st->sp_aud_decision1, sizeof( int16_t ), 1, fname( st->force_dir, "force_sp_aud_decision1.enf", -1, -1, -1 ) ); + dbgread( &st->sp_aud_decision2, sizeof( int16_t ), 1, fname( st->force_dir, "force_sp_aud_decision2.enf", -1, -1, -1 ) ); + } +#endif + /*----------------------------------------------------------------* * Final VAD correction (when HE-SAD is used instead of the normal VAD, * rewrite the VAD flag by VAD flag with DTX hangover for further processing) diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index f40980db9..60cf33e8a 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -210,6 +210,9 @@ ivas_error ivas_cpe_enc_fx( #ifdef DEBUGGING sts[n]->force = hEncoderConfig->force; sts[n]->id_element = cpe_id + st_ivas->nSCE; +#ifdef DEBUG_FORCE_DIR + sts[n]->force_dir = hEncoderConfig->force_dir; +#endif #endif } diff --git a/lib_enc/ivas_decision_matrix_enc.c b/lib_enc/ivas_decision_matrix_enc.c index 1da1b2272..d02defa6e 100644 --- a/lib_enc/ivas_decision_matrix_enc.c +++ b/lib_enc/ivas_decision_matrix_enc.c @@ -559,6 +559,15 @@ void ivas_decision_matrix_enc_fx( } #endif +#ifdef DEBUG_FORCE_DIR + dbgwrite( &st->core, sizeof( int16_t ), 1, 1, "res/force_core.enf" ); + + if ( st->force_dir[0] != '\0' ) + { + dbgread( &st->core, sizeof( int16_t ), 1, fname( st->force_dir, "force_core.enf", -1, -1, -1 ) ); + } +#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_stat_enc.h b/lib_enc/ivas_stat_enc.h index 538362f3e..a0e65e586 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -39,6 +39,9 @@ #include "ivas_cnst.h" #include "stat_enc.h" #include "ivas_stat_com.h" +#ifdef DEBUG_FORCE_DIR +#include "debug.h" +#endif /*----------------------------------------------------------------------------------* * DFT Stereo encoder structures @@ -1810,6 +1813,9 @@ typedef struct encoder_config_structure 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 */ +#ifdef DEBUG_FORCE_DIR + char force_dir[FORCE_DIR_MAX_LENGTH]; /* directory containing external binary files for modes/parameters enforcement (empty string indicates no enforcement) */ +#endif #endif diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index b63cf8de3..220c2355c 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -230,6 +230,15 @@ Word16 select_stereo_mode( } } +#ifdef DEBUG_FORCE_DIR + dbgwrite( &element_mode, sizeof( int16_t ), 1, 1, "res/force_element_mode.enf" ); + + if ( hCPE->hCoreCoder[0]->force_dir[0] != '\0' ) + { + dbgread( &element_mode, sizeof( int16_t ), 1, fname( hCPE->hCoreCoder[0]->force_dir, "force_element_mode.enf", -1, -1, -1 ) ); + } +#endif + /* switch from LRTD to DFT when xtalk_decision goes from 0->1 (note: this special case is not handled in the xtalk classifier) */ test(); test(); diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 6c8ec4e29..135d3a8df 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -2359,6 +2359,9 @@ ivas_error IVAS_ENC_SetChannelAwareConfig( ivas_error IVAS_ENC_SetForcedMode( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ const IVAS_ENC_FORCED_MODE forcedMode /* i : forced coding mode */ +#ifdef DEBUG_FORCE_DIR + ,const char *forcedModeDir /* i : directory containing external binary files for modes/parameters enforcement */ +#endif ) { int16_t newForced; @@ -2370,6 +2373,28 @@ ivas_error IVAS_ENC_SetForcedMode( return error; } +#ifdef DEBUG_FORCE_DIR + if ( forcedModeDir == NULL ) + { + hIvasEnc->st_ivas->hEncoderConfig->force_dir[0] = '\0'; + + 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; + } + } + else + { + strcpy( hIvasEnc->st_ivas->hEncoderConfig->force_dir, forcedModeDir ); + hIvasEnc->st_ivas->hEncoderConfig->force = IVAS_ENC_FORCE_UNFORCED; + } +#else if ( ( error = forcedModeApiToInternal( forcedMode, &newForced ) ) != IVAS_ERR_OK ) { return error; @@ -2380,6 +2405,7 @@ ivas_error IVAS_ENC_SetForcedMode( hIvasEnc->st_ivas->hEncoderConfig->force = newForced; hIvasEnc->switchingActive = true; } +#endif return IVAS_ERR_OK; } diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index 03a0bee9e..41ffa4a10 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -340,6 +340,9 @@ ivas_error IVAS_ENC_SetChannelAwareConfig( ivas_error IVAS_ENC_SetForcedMode( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ const IVAS_ENC_FORCED_MODE forcedMode /* i : forced coding mode */ +#ifdef DEBUG_FORCE_DIR + ,const char *forcedModeDir /* i : directory containing external binary files for modes/parameters enforcement */ +#endif ); #endif diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 7a792ae0f..4d517e0bb 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1988,7 +1988,10 @@ 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) */ +#ifdef DEBUG_FORCE_DIR + char *force_dir; /* directory containing external binary files for modes/parameters enforcement (empty string indicates no enforcement) */ +#endif #endif Word16 nTimeSlots; /* for CLDFB */ -- GitLab From fbe043f58a61fb23772da24b755b8924a696667d Mon Sep 17 00:00:00 2001 From: Vladimir Malenovsky Date: Thu, 12 Dec 2024 15:44:08 +0100 Subject: [PATCH 02/14] clang format --- apps/encoder.c | 17 +++++++++-------- lib_enc/lib_enc.c | 3 ++- lib_enc/stat_enc.h | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index 0eae15fc1..c3ba40381 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -561,7 +561,7 @@ int main( } /* check if it is a directory */ - if ( S_ISDIR( path_stat.st_mode ) ) + if ( S_ISDIR( path_stat.st_mode ) ) { f_forceModeDir = true; } @@ -729,17 +729,18 @@ int main( } /* Force mode not set when configuring, set in first frame even if not reading from file */ - if ( f_forcedModeProfile || + if ( f_forcedModeProfile || #ifdef DEBUG_FORCE_DIR - f_forceModeDir || -#endif - frame == 0 ) + f_forceModeDir || +#endif + frame == 0 ) { if ( ( error = IVAS_ENC_SetForcedMode( hIvasEnc, forcedMode #ifdef DEBUG_FORCE_DIR - , arg.forcedModeFile -#endif - ) ) != IVAS_ERR_OK ) + , + arg.forcedModeFile +#endif + ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_ENC_SetForcedMode failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); goto cleanup; diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 135d3a8df..67b30a97e 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -2360,7 +2360,8 @@ ivas_error IVAS_ENC_SetForcedMode( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ const IVAS_ENC_FORCED_MODE forcedMode /* i : forced coding mode */ #ifdef DEBUG_FORCE_DIR - ,const char *forcedModeDir /* i : directory containing external binary files for modes/parameters enforcement */ + , + const char *forcedModeDir /* i : directory containing external binary files for modes/parameters enforcement */ #endif ) { diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 4d517e0bb..9dd9d3346 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) */ #ifdef DEBUG_FORCE_DIR - char *force_dir; /* directory containing external binary files for modes/parameters enforcement (empty string indicates no enforcement) */ + char *force_dir; /* directory containing external binary files for modes/parameters enforcement (empty string indicates no enforcement) */ #endif #endif Word16 nTimeSlots; /* for CLDFB */ -- GitLab From 77ac6379f479db5728140d39734d9f15849e86be Mon Sep 17 00:00:00 2001 From: malenov Date: Thu, 12 Dec 2024 16:11:48 +0100 Subject: [PATCH 03/14] make fname() visible without DEUBG_MODE_INFO on --- lib_debug/debug.c | 4 ++-- lib_debug/debug.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_debug/debug.c b/lib_debug/debug.c index 2608be30a..8053a7cd9 100644 --- a/lib_debug/debug.c +++ b/lib_debug/debug.c @@ -758,7 +758,7 @@ int16_t tweakdbgfolder( const char *filename, char *filename_mod, int16_t *textm #endif -#ifdef DEBUG_MODE_INFO +#ifdef DEBUGGING /*-------------------------------------------------------------------* * fname() * @@ -781,7 +781,7 @@ char *fname( char idd[5] = ".idX"; idd[3] = (char) ( id + '0' ); #ifdef DEBUG_FORCE_DIR - short len; + size_t len; #endif strcpy( tmp_fname, dir ); diff --git a/lib_debug/debug.h b/lib_debug/debug.h index c1c978bfe..92c510147 100644 --- a/lib_debug/debug.h +++ b/lib_debug/debug.h @@ -60,7 +60,7 @@ extern int16_t debug_level; #define DEBUG_LINE( level ) if ( 0 ) #endif -#ifdef DEBUG_MODE_INFO +#ifdef DEBUGGING extern char tmp_fname[]; extern char debug_dir[6]; char *fname( char *dir, char *file, const int16_t n, const int16_t id, const int16_t enc_dec ); -- GitLab From d9b02f271b8b02363a16bb8ba6a92d8ab25a32c5 Mon Sep 17 00:00:00 2001 From: malenov Date: Tue, 14 Jan 2025 10:37:45 +0100 Subject: [PATCH 04/14] make read/write operations exclusive --- lib_enc/ivas_core_pre_proc_front.c | 30 +++++++++++++++++++----------- lib_enc/ivas_decision_matrix_enc.c | 6 ++++-- lib_enc/ivas_stereo_classifier.c | 6 ++++-- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index b9e72f8fa..74af17216 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -825,12 +825,14 @@ ivas_error pre_proc_front_ivas_fx( move16(); #ifdef DEBUG_FORCE_DIR - dbgwrite( &st->vad_flag, sizeof( int16_t ), 1, 1, "res/force_vad_flag.enf" ); - if ( st->force_dir[0] != '\0' ) { dbgread( &st->vad_flag, sizeof( int16_t ), 1, fname( st->force_dir, "force_vad_flag.enf", -1, -1, -1 ) ); } + else + { + dbgwrite( &st->vad_flag, sizeof( int16_t ), 1, 1, "res/force_vad_flag.enf" ); + } #endif test(); @@ -911,12 +913,14 @@ ivas_error pre_proc_front_ivas_fx( } #ifdef DEBUG_FORCE_DIR - dbgwrite( &st->bwidth, sizeof( int16_t ), 1, 1, "res/force_bwidth.enf" ); - if ( st->force_dir[0] != '\0' ) { dbgread( &st->bwidth, sizeof( int16_t ), 1, fname( st->force_dir, "force_bwidth.enf", -1, -1, -1 ) ); } + else + { + dbgwrite( &st->bwidth, sizeof( int16_t ), 1, 1, "res/force_bwidth.enf" ); + } #endif @@ -1511,12 +1515,14 @@ 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 ); /* Q0 */ #ifdef DEBUG_FORCE_DIR - dbgwrite( &smc_dec, sizeof( int16_t ), 1, 1, "res/force_smc_dec_loc1.enf" ); - if ( st->force_dir[0] != '\0' ) { dbgread( &smc_dec, sizeof( int16_t ), 1, fname( st->force_dir, "force_smc_dec_loc1.enf", -1, -1, -1 ) ); } + else + { + dbgwrite( &smc_dec, sizeof( int16_t ), 1, 1, "res/force_smc_dec_loc1.enf" ); + } #endif #ifdef DEBUGGING @@ -1726,11 +1732,6 @@ ivas_error pre_proc_front_ivas_fx( } #ifdef DEBUG_FORCE_DIR - dbgwrite( &smc_dec, sizeof( int16_t ), 1, 1, "res/force_smc_dec_loc2.enf" ); - dbgwrite( &st->sp_aud_decision0, sizeof( int16_t ), 1, 1, "res/force_sp_aud_decision0.enf" ); - dbgwrite( &st->sp_aud_decision1, sizeof( int16_t ), 1, 1, "res/force_sp_aud_decision1.enf" ); - dbgwrite( &st->sp_aud_decision2, sizeof( int16_t ), 1, 1, "res/force_sp_aud_decision2.enf" ); - if ( st->force_dir[0] != '\0' ) { dbgread( &smc_dec, sizeof( int16_t ), 1, fname( st->force_dir, "force_smc_dec_loc2.enf", -1, -1, -1 ) ); @@ -1738,6 +1739,13 @@ ivas_error pre_proc_front_ivas_fx( dbgread( &st->sp_aud_decision1, sizeof( int16_t ), 1, fname( st->force_dir, "force_sp_aud_decision1.enf", -1, -1, -1 ) ); dbgread( &st->sp_aud_decision2, sizeof( int16_t ), 1, fname( st->force_dir, "force_sp_aud_decision2.enf", -1, -1, -1 ) ); } + else + { + dbgwrite( &smc_dec, sizeof( int16_t ), 1, 1, "res/force_smc_dec_loc2.enf" ); + dbgwrite( &st->sp_aud_decision0, sizeof( int16_t ), 1, 1, "res/force_sp_aud_decision0.enf" ); + dbgwrite( &st->sp_aud_decision1, sizeof( int16_t ), 1, 1, "res/force_sp_aud_decision1.enf" ); + dbgwrite( &st->sp_aud_decision2, sizeof( int16_t ), 1, 1, "res/force_sp_aud_decision2.enf" ); + } #endif /*----------------------------------------------------------------* diff --git a/lib_enc/ivas_decision_matrix_enc.c b/lib_enc/ivas_decision_matrix_enc.c index b46361fc2..cb3248b93 100644 --- a/lib_enc/ivas_decision_matrix_enc.c +++ b/lib_enc/ivas_decision_matrix_enc.c @@ -256,12 +256,14 @@ void ivas_decision_matrix_enc_fx( #endif #ifdef DEBUG_FORCE_DIR - dbgwrite( &st->core, sizeof( int16_t ), 1, 1, "res/force_core.enf" ); - if ( st->force_dir[0] != '\0' ) { dbgread( &st->core, sizeof( int16_t ), 1, fname( st->force_dir, "force_core.enf", -1, -1, -1 ) ); } + else + { + dbgwrite( &st->core, sizeof( int16_t ), 1, 1, "res/force_core.enf" ); + } #endif /* TCX not available at low bitrates -> replace it by GSC */ diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index 8391d99a2..96754c97d 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -218,12 +218,14 @@ Word16 select_stereo_mode( } #ifdef DEBUG_FORCE_DIR - dbgwrite( &element_mode, sizeof( int16_t ), 1, 1, "res/force_element_mode.enf" ); - if ( hCPE->hCoreCoder[0]->force_dir[0] != '\0' ) { dbgread( &element_mode, sizeof( int16_t ), 1, fname( hCPE->hCoreCoder[0]->force_dir, "force_element_mode.enf", -1, -1, -1 ) ); } + else + { + dbgwrite( &element_mode, sizeof( int16_t ), 1, 1, "res/force_element_mode.enf" ); + } #endif /* switch from LRTD to DFT when xtalk_decision goes from 0->1 (note: this special case is not handled in the xtalk classifier) */ -- GitLab From ebc2a47326dd706b0e4b2c7d97306908516a7560 Mon Sep 17 00:00:00 2001 From: malenov Date: Tue, 14 Jan 2025 10:43:42 +0100 Subject: [PATCH 05/14] force_element_mode.enf - read/write info in frame 0 --- lib_enc/ivas_cpe_enc.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index e93d3caa0..7b7ab41bf 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -263,6 +263,19 @@ ivas_error ivas_cpe_enc_fx( { hCPE->element_mode = select_stereo_mode( hCPE, ivas_format ); /* Q0 */ } +#ifdef DEBUG_FORCE_DIR + else + { + if ( hCPE->hCoreCoder[0]->force_dir[0] != '\0' ) + { + dbgread( &hCPE->element_mode, sizeof( int16_t ), 1, fname( hCPE->hCoreCoder[0]->force_dir, "force_element_mode.enf", -1, -1, -1 ) ); + } + else + { + dbgwrite( &hCPE->element_mode, sizeof( int16_t ), 1, 1, "res/force_element_mode.enf" ); + } + } +#endif stereo_mode_combined_format_enc_fx( st_ivas, hCPE ); -- GitLab From 7611d58044dcbc5c657024208c4d55c6801342f2 Mon Sep 17 00:00:00 2001 From: malenov Date: Tue, 14 Jan 2025 15:56:11 +0100 Subject: [PATCH 06/14] fix the I/O interface --- apps/encoder.c | 3 +++ lib_enc/ivas_decision_matrix_enc.c | 26 ++++++++++++++++++++++++++ lib_enc/lib_enc.c | 4 ++-- lib_enc/lib_enc.h | 4 ++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index 4e7d55bce..36ba0bcd7 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -149,6 +149,9 @@ typedef struct #ifdef DEBUGGING IVAS_ENC_FORCED_MODE forcedMode; const char *forcedModeFile; +#ifdef DEBUG_FORCE_DIR + const char *forcedModeDir; +#endif #endif bool pca; bool ism_extended_metadata; diff --git a/lib_enc/ivas_decision_matrix_enc.c b/lib_enc/ivas_decision_matrix_enc.c index cb3248b93..08ce3cd21 100644 --- a/lib_enc/ivas_decision_matrix_enc.c +++ b/lib_enc/ivas_decision_matrix_enc.c @@ -354,6 +354,19 @@ void ivas_decision_matrix_enc_fx( } } } + +#ifdef DEBUG_FORCE_DIR + if ( st->force_dir[0] != '\0' ) + { + dbgread( &st->extl, sizeof( int16_t ), 1, fname( st->force_dir, "force_extl.enf", -1, -1, -1 ) ); + dbgread( &st->extl_brate, sizeof( int32_t ), 1, fname( st->force_dir, "force_extl_brate.enf", -1, -1, -1 ) ); + } + else + { + dbgwrite( &st->extl, sizeof( int16_t ), 1, 1, "res/force_extl.enf" ); + dbgwrite( &st->extl_brate, sizeof( int32_t ), 1, 1, "res/force_extl_brate.enf" ); + } +#endif } /* SWB and FB */ @@ -451,6 +464,19 @@ void ivas_decision_matrix_enc_fx( move32(); } +#ifdef DEBUG_FORCE_DIR + if ( st->force_dir[0] != '\0' ) + { + dbgread( &st->extl, sizeof( int16_t ), 1, fname( st->force_dir, "force_extl.enf", -1, -1, -1 ) ); + dbgread( &st->extl_brate, sizeof( int32_t ), 1, fname( st->force_dir, "force_extl_brate.enf", -1, -1, -1 ) ); + } + else + { + dbgwrite( &st->extl, sizeof( int16_t ), 1, 1, "res/force_extl.enf" ); + dbgwrite( &st->extl_brate, sizeof( int32_t ), 1, 1, "res/force_extl_brate.enf" ); + } +#endif + /* set IC-BWE bitrate */ test(); test(); diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 63efaafb8..26fc04a5e 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1888,7 +1888,7 @@ ivas_error IVAS_ENC_SetForcedMode( } #ifdef DEBUG_FORCE_DIR - if ( forcedModeDir == NULL ) + if ( forcedMode < IVAS_ENC_FORCE_FILE ) { hIvasEnc->st_ivas->hEncoderConfig->force_dir[0] = '\0'; @@ -1903,7 +1903,7 @@ ivas_error IVAS_ENC_SetForcedMode( hIvasEnc->switchingActive = true; } } - else + else if ( forcedMode == IVAS_ENC_FORCE_DIR ) { strcpy( hIvasEnc->st_ivas->hEncoderConfig->force_dir, forcedModeDir ); hIvasEnc->st_ivas->hEncoderConfig->force = IVAS_ENC_FORCE_UNFORCED; diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index 09262079b..69f794b69 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -129,6 +129,10 @@ typedef enum _IVAS_ENC_FORCED_MODE IVAS_ENC_FORCE_GSC, IVAS_ENC_FORCE_TCX, IVAS_ENC_FORCE_HQ, +#ifdef DEBUG_FORCE_DIR + IVAS_ENC_FORCE_FILE, + IVAS_ENC_FORCE_DIR, +#endif IVAS_ENC_FORCE_UNFORCED, IVAS_ENC_FORCE_UNDEFINED = 0xffff } IVAS_ENC_FORCED_MODE; -- GitLab From 1c0f36f0aa732ca19ae34a0a0db2cd1bd35c8a5e Mon Sep 17 00:00:00 2001 From: malenov Date: Tue, 4 Feb 2025 10:30:01 +0100 Subject: [PATCH 07/14] refactor the usage of f_forceModeDir in the API --- apps/encoder.c | 115 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 79 insertions(+), 36 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index 36ba0bcd7..56991959f 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -201,9 +201,6 @@ int main( int16_t *pcmBuf = NULL; #ifdef DEBUGGING FILE *f_forcedModeProfile = NULL; -#ifdef DEBUG_FORCE_DIR - bool f_forceModeDir = false; -#endif #endif #ifdef WMOPS @@ -541,42 +538,15 @@ int main( #ifdef DEBUGGING IVAS_ENC_FORCED_MODE forcedMode = arg.forcedMode; int32_t force_profile_cnt = 0; -#ifdef DEBUG_FORCE_DIR - struct stat path_stat; -#endif if ( arg.forcedModeFile ) { -#ifdef DEBUG_FORCE_DIR - if ( stat( arg.forcedModeFile, &path_stat ) != 0 ) - { - fprintf( stderr, "\nError: The profile file/dir could not be opened: %s\n\n", arg.forcedModeFile ); - usage_enc(); - goto cleanup; - } - - /* check if it is a directory */ - if ( S_ISDIR( path_stat.st_mode ) ) - { - f_forceModeDir = true; - } - else - { - 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; - } - } -#else 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 } #endif @@ -724,16 +694,12 @@ int main( } /* Force mode not set when configuring, set in first frame even if not reading from file */ - if ( f_forcedModeProfile || -#ifdef DEBUG_FORCE_DIR - f_forceModeDir || -#endif - frame == 0 ) + if ( f_forcedModeProfile || frame == 0 ) { if ( ( error = IVAS_ENC_SetForcedMode( hIvasEnc, forcedMode #ifdef DEBUG_FORCE_DIR , - arg.forcedModeFile + arg.forcedModeDir #endif ) ) != IVAS_ERR_OK ) { @@ -906,6 +872,9 @@ static void initArgStruct( EncArguments *arg ) #ifdef DEBUGGING arg->forcedMode = IVAS_ENC_FORCE_UNFORCED; arg->forcedModeFile = NULL; +#ifdef DEBUG_FORCE_DIR + arg->forcedModeDir = NULL; +#endif #endif arg->pca = false; @@ -1046,6 +1015,28 @@ static bool parseCmdlIVAS_enc( arg->forcedMode = parseForcedMode( stmp ); +#ifdef DEBUG_FORCE_DIR + if ( arg->forcedMode < IVAS_ENC_FORCE_FILE ) + { + fprintf( stdout, "Forcing codec to: %s\n", argv[i + 1] ); + } + else if ( arg->forcedMode == IVAS_ENC_FORCE_FILE ) + { + arg->forcedModeFile = argv[i + 1]; + fprintf( stdout, "Force switching file: %s\n", argv[i + 1] ); + } + else if ( arg->forcedMode == IVAS_ENC_FORCE_DIR ) + { + arg->forcedModeDir = argv[i + 1]; + fprintf( stdout, "Forcing switching directory: %s\n", argv[i + 1] ); + } + else + { + fprintf( stderr, "\nError: The force switching profile file/dir %s does not exist or could not be opened!\n\n", argv[i + 1] ); + usage_enc(); + return false; + } +#else if ( arg->forcedMode == IVAS_ENC_FORCE_UNDEFINED ) { arg->forcedModeFile = argv[i + 1]; @@ -1055,6 +1046,7 @@ static bool parseCmdlIVAS_enc( { fprintf( stdout, "Forcing codec to: %s\n", argv[i + 1] ); } +#endif i += 2; } @@ -1958,8 +1950,58 @@ static bool readBitrate( static IVAS_ENC_FORCED_MODE parseForcedMode( char *forcedModeChar ) { +#ifdef DEBUG_FORCE_DIR + struct stat path_stat; +#endif + to_upper( forcedModeChar ); +#ifdef DEBUG_FORCE_DIR + if ( ( strcmp( forcedModeChar, "SPEECH" ) == 0 ) || ( strcmp( forcedModeChar, "'SPEECH'" ) == 0 ) || + ( strcmp( forcedModeChar, "0" ) == 0 ) ) + { + return IVAS_ENC_FORCE_SPEECH; + } + else 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; + } + else if ( ( strcmp( forcedModeChar, "ACELP" ) == 0 ) || ( strcmp( forcedModeChar, "'ACELP'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_ACELP; + } + else if ( ( strcmp( forcedModeChar, "GSC" ) == 0 ) || ( strcmp( forcedModeChar, "'GSC'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_GSC; + } + else if ( ( strcmp( forcedModeChar, "TCX" ) == 0 ) || ( strcmp( forcedModeChar, "'TCX'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_TCX; + } + else if ( ( strcmp( forcedModeChar, "HQ" ) == 0 ) || ( strcmp( forcedModeChar, "'HQ'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_HQ; + } + else + { + if ( stat( forcedModeChar, &path_stat ) != 0 ) + { + return IVAS_ENC_FORCE_UNDEFINED; + } + + /* check if the argument represents an existing file or directory */ + if ( S_ISDIR( path_stat.st_mode ) ) + { + /* it's a directory */ + return IVAS_ENC_FORCE_DIR; + } + else + { + /* it's a file */ + return IVAS_ENC_FORCE_FILE; + } + } +#else if ( ( strcmp( forcedModeChar, "SPEECH" ) == 0 ) || ( strcmp( forcedModeChar, "'SPEECH'" ) == 0 ) || ( strcmp( forcedModeChar, "0" ) == 0 ) ) { @@ -1987,6 +2029,7 @@ static IVAS_ENC_FORCED_MODE parseForcedMode( } return IVAS_ENC_FORCE_UNDEFINED; +#endif } -- GitLab From 8926070a3e56e05d2f6724ef71f19517edb796bd Mon Sep 17 00:00:00 2001 From: malenov Date: Tue, 4 Feb 2025 13:19:07 +0100 Subject: [PATCH 08/14] fix force_dir initialization to empty string --- lib_enc/lib_enc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 26fc04a5e..631f7bf38 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1888,10 +1888,9 @@ ivas_error IVAS_ENC_SetForcedMode( } #ifdef DEBUG_FORCE_DIR + hIvasEnc->st_ivas->hEncoderConfig->force_dir[0] = '\0'; if ( forcedMode < IVAS_ENC_FORCE_FILE ) { - hIvasEnc->st_ivas->hEncoderConfig->force_dir[0] = '\0'; - if ( ( error = forcedModeApiToInternal( forcedMode, &newForced ) ) != IVAS_ERR_OK ) { return error; -- GitLab From 0fbfb763563067e4268166f85e8e2ca7fe2fb32c Mon Sep 17 00:00:00 2001 From: malenov Date: Tue, 4 Feb 2025 13:19:39 +0100 Subject: [PATCH 09/14] fix element_mode read/write location --- lib_enc/ivas_stereo_classifier.c | 65 ++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index 96754c97d..bf8f74b14 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -217,17 +217,6 @@ Word16 select_stereo_mode( } } -#ifdef DEBUG_FORCE_DIR - if ( hCPE->hCoreCoder[0]->force_dir[0] != '\0' ) - { - dbgread( &element_mode, sizeof( int16_t ), 1, fname( hCPE->hCoreCoder[0]->force_dir, "force_element_mode.enf", -1, -1, -1 ) ); - } - else - { - dbgwrite( &element_mode, sizeof( int16_t ), 1, 1, "res/force_element_mode.enf" ); - } -#endif - /* switch from LRTD to DFT when xtalk_decision goes from 0->1 (note: this special case is not handled in the xtalk classifier) */ test(); test(); @@ -252,6 +241,17 @@ Word16 select_stereo_mode( } } +#ifdef DEBUG_FORCE_DIR + if ( hCPE->hCoreCoder[0]->force_dir[0] != '\0' ) + { + dbgread( &element_mode, sizeof( int16_t ), 1, fname( hCPE->hCoreCoder[0]->force_dir, "force_element_mode.enf", -1, -1, -1 ) ); + } + else + { + dbgwrite( &element_mode, sizeof( int16_t ), 1, 1, "res/force_element_mode.enf" ); + } +#endif + IF( NE_16( hCPE->last_element_mode, element_mode ) ) { test(); @@ -914,6 +914,16 @@ void unclr_classifier_td_fx( move16(); } +#ifdef DEBUG_FORCE_DIR + if ( hCPE->hCoreCoder[0]->force_dir[0] != '\0' ) + { + dbgread( &hStereoClassif->unclr_decision, sizeof( int16_t ), 1, fname( hCPE->hCoreCoder[0]->force_dir, "force_unclr_decision.enf", -1, -1, -1 ) ); + } + else + { + dbgwrite( &hStereoClassif->unclr_decision, sizeof( int16_t ), 1, 1, "res/force_unclr_decision.enf" ); + } +#endif return; } @@ -1021,6 +1031,16 @@ void unclr_classifier_dft_fx( move16(); } +#ifdef DEBUG_FORCE_DIR + if ( hCPE->hCoreCoder[0]->force_dir[0] != '\0' ) + { + dbgread( &hStereoClassif->unclr_decision, sizeof( int16_t ), 1, fname( hCPE->hCoreCoder[0]->force_dir, "force_unclr_decision.enf", -1, -1, -1 ) ); + } + else + { + dbgwrite( &hStereoClassif->unclr_decision, sizeof( int16_t ), 1, 1, "res/force_unclr_decision.enf" ); + } +#endif return; } @@ -1169,6 +1189,17 @@ void xtalk_classifier_td_fx( move16(); } +#ifdef DEBUG_FORCE_DIR + if ( hCPE->hCoreCoder[0]->force_dir[0] != '\0' ) + { + dbgread( &hStereoClassif->xtalk_decision, sizeof( int16_t ), 1, fname( hCPE->hCoreCoder[0]->force_dir, "force_xtalk_decision.enf", -1, -1, -1 ) ); + } + else + { + dbgwrite( &hStereoClassif->xtalk_decision, sizeof( int16_t ), 1, 1, "res/force_xtalk_decision.enf" ); + } +#endif + return; } @@ -1389,7 +1420,6 @@ void xtalk_classifier_dft_fx( move16(); } - /* updates */ hItd->prev_m1_fx = m1; move32(); @@ -1400,6 +1430,17 @@ void xtalk_classifier_dft_fx( hItd->prev_itd2 = itd2; move16(); +#ifdef DEBUG_FORCE_DIR + if ( hCPE->hCoreCoder[0]->force_dir[0] != '\0' ) + { + dbgread( &hStereoClassif->xtalk_decision, sizeof( int16_t ), 1, fname( hCPE->hCoreCoder[0]->force_dir, "force_xtalk_decision.enf", -1, -1, -1 ) ); + } + else + { + dbgwrite( &hStereoClassif->xtalk_decision, sizeof( int16_t ), 1, 1, "res/force_xtalk_decision.enf" ); + } +#endif + return; } -- GitLab From a7f9fcc5154eda4e05c5fdc5655da3f5144f70ae Mon Sep 17 00:00:00 2001 From: malenov Date: Wed, 5 Feb 2025 12:09:10 +0100 Subject: [PATCH 10/14] fix initialization of st->force_dir in ISM and SCE modes --- lib_enc/ivas_cpe_enc.c | 1 - lib_enc/ivas_init_enc.c | 3 +++ lib_enc/ivas_ism_enc.c | 3 +++ lib_enc/ivas_sce_enc.c | 3 +++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 7b7ab41bf..4f8926eba 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -1198,7 +1198,6 @@ ivas_error ivas_cpe_enc_fx( } } - /*----------------------------------------------------------------* * Core Encoder *----------------------------------------------------------------*/ diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index d6a3597bd..02219c4e3 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -370,6 +370,9 @@ void copy_encoder_config_fx( #ifdef DEBUGGING st_fx->force = st_ivas->hEncoderConfig->force; +#ifdef DEBUG_FORCE_DIR + st_fx->force_dir = st_ivas->hEncoderConfig->force_dir; +#endif #endif st_fx->element_mode = st_ivas->hEncoderConfig->element_mode_init; /* Q0 */ diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 6f8fb2b9f..2fef5a1cb 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -197,6 +197,9 @@ ivas_error ivas_ism_enc_fx( #ifdef DEBUGGING st->force = st_ivas->hEncoderConfig->force; st->id_element = sce_id; +#ifdef DEBUG_FORCE_DIR + st->force_dir = st_ivas->hEncoderConfig->force_dir; +#endif #endif move16(); move16(); diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index d43ed7438..7d76b2fd5 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -161,6 +161,9 @@ ivas_error ivas_sce_enc_fx( #ifdef DEBUGGING st->force = st_ivas->hEncoderConfig->force; st->id_element = sce_id; +#ifdef DEBUG_FORCE_DIR + st->force_dir = st_ivas->hEncoderConfig->force_dir; +#endif #endif move16(); move16(); -- GitLab From d9be453d24945793846bf52d35d2efe197a8ca17 Mon Sep 17 00:00:00 2001 From: malenov Date: Fri, 7 Feb 2025 13:31:44 +0100 Subject: [PATCH 11/14] dumping core.loc2, coder_type and ism_imp --- lib_enc/ivas_core_pre_proc_front.c | 14 +++++++++++++ lib_enc/ivas_decision_matrix_enc.c | 33 ++++++++++++++++++++---------- lib_enc/ivas_ism_enc.c | 19 +++++++++++++++++ lib_enc/ivas_ism_metadata_enc.c | 11 ++++++++++ 4 files changed, 66 insertions(+), 11 deletions(-) diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 74af17216..c06c437ff 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -1456,6 +1456,20 @@ ivas_error pre_proc_front_ivas_fx( Copy_Scale_sig_16_32( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) ); +#ifdef DEBUG_FORCE_DIR + if ( st->force_dir[0] != '\0' ) + { + dbgread( &st->coder_type, sizeof( int16_t ), 1, fname( st->force_dir, "force_coder_type.enf", -1, -1, -1 ) ); + dbgread( &st->coder_type_raw, sizeof( int16_t ), 1, fname( st->force_dir, "force_coder_type_raw.enf", -1, -1, -1 ) ); + } + else + { + dbgwrite( &st->coder_type, sizeof( int16_t ), 1, 1, "res/force_coder_type.enf" ); + dbgwrite( &st->coder_type_raw, sizeof( int16_t ), 1, 1, "res/force_coder_type_raw.enf" ); + } +#endif + + /*-----------------------------------------------------------------* * channel aware mode configuration * *-----------------------------------------------------------------*/ diff --git a/lib_enc/ivas_decision_matrix_enc.c b/lib_enc/ivas_decision_matrix_enc.c index 08ce3cd21..e668641dc 100644 --- a/lib_enc/ivas_decision_matrix_enc.c +++ b/lib_enc/ivas_decision_matrix_enc.c @@ -207,6 +207,17 @@ void ivas_decision_matrix_enc_fx( test(); test(); +#ifdef DEBUG_FORCE_DIR + if ( st->force_dir[0] != '\0' ) + { + dbgread( &st->core, sizeof( int16_t ), 1, fname( st->force_dir, "force_core_loc1.enf", -1, -1, -1 ) ); + } + else + { + dbgwrite( &st->core, sizeof( int16_t ), 1, 1, "res/force_core_loc1.enf" ); + } +#endif + /* do not allow TD stereo ACELP core -> DFT stereo TCX core switching as it is on the WC complexity path */ if ( ( ( st->last_core == ACELP_CORE && EQ_16( last_element_mode, IVAS_CPE_TD ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) || ( EQ_16( st->tdm_LRTD_flag, 1 ) && LE_32( st->total_brate, IVAS_16k4 ) ) ) && EQ_16( st->core, TCX_20_CORE ) && LE_32( st->total_brate, MAX_ACELP_BRATE ) ) /* Override TCX in case of LRTD && primary channel has low bitrate*/ { @@ -255,17 +266,6 @@ void ivas_decision_matrix_enc_fx( } #endif -#ifdef DEBUG_FORCE_DIR - if ( st->force_dir[0] != '\0' ) - { - dbgread( &st->core, sizeof( int16_t ), 1, fname( st->force_dir, "force_core.enf", -1, -1, -1 ) ); - } - else - { - dbgwrite( &st->core, sizeof( int16_t ), 1, 1, "res/force_core.enf" ); - } -#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 ) ) @@ -305,6 +305,17 @@ void ivas_decision_matrix_enc_fx( move16(); } +#ifdef DEBUG_FORCE_DIR + if ( st->force_dir[0] != '\0' ) + { + dbgread( &st->core, sizeof( int16_t ), 1, fname( st->force_dir, "force_core_loc2.enf", -1, -1, -1 ) ); + } + else + { + dbgwrite( &st->core, sizeof( int16_t ), 1, 1, "res/force_core_loc2.enf" ); + } +#endif + /*---------------------------------------------------------------------* * Select ACELP and GSC extension layer *---------------------------------------------------------------------*/ diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 2fef5a1cb..70b049ba8 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -228,6 +228,11 @@ ivas_error ivas_ism_enc_fx( st->bits_frame_nominal = sub( extract_l( Mpy_32_32( hSCE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ), ISM_NB_BITS_METADATA_NOMINAL ); move16(); + +#ifdef DEBUG_MODE_INFO + dbgwrite( &st->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, st->id_element, ENC ) ); +#endif + /*----------------------------------------------------------------* * Front Pre-processing *----------------------------------------------------------------*/ @@ -506,6 +511,20 @@ ivas_error ivas_ism_enc_fx( } } +#ifdef DEBUG_MODE_INFO + for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ ) + { + float tmpF; + int16_t id; + + st = st_ivas->hSCE[sce_id]->hCoreCoder[0]; + id = st->id_element; + + tmpF = st->element_brate / 1000.0f; + dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "element_brate", 0, id, ENC ) ); + } +#endif + pop_wmops(); return error; diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 9bcc34dd8..ef410b59c 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -338,6 +338,17 @@ ivas_error ivas_ism_metadata_enc_fx( } } +#ifdef DEBUG_FORCE_DIR + if ( hSCE[0]->hCoreCoder[0]->force_dir[0] != '\0' ) + { + dbgread( ism_imp, sizeof( int16_t ), nchan_ism, fname( hSCE[0]->hCoreCoder[0]->force_dir, "force_ism_imp.enf", -1, -1, -1 ) ); + } + else + { + dbgwrite( ism_imp, sizeof( int16_t ), nchan_ism, 1, "res/force_ism_imp.enf" ); + } +#endif + /*----------------------------------------------------------------* * Write ISM common signaling *----------------------------------------------------------------*/ -- GitLab From a2d7f097464c57e8949bd25d333312e43a6c241a Mon Sep 17 00:00:00 2001 From: malenov Date: Fri, 21 Feb 2025 14:07:49 +0100 Subject: [PATCH 12/14] proper way of porting SUPPORT_FORCE_TCX10_TCX20 --- apps/encoder.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/encoder.c b/apps/encoder.c index 165d03543..0cdb2cff9 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -2000,10 +2000,24 @@ static IVAS_ENC_FORCED_MODE parseForcedMode( { return IVAS_ENC_FORCE_GSC; } - else if ( ( strcmp( forcedModeChar, "TCX" ) == 0 ) || ( strcmp( forcedModeChar, "'TCX'" ) == 0 ) ) + if ( ( strcmp( forcedModeChar, "TCX" ) == 0 ) || ( strcmp( forcedModeChar, "'TCX'" ) == 0 ) +#ifdef SUPPORT_FORCE_TCX10_TCX20 + || ( strcmp( forcedModeChar, "TCX20" ) == 0 ) || ( strcmp( forcedModeChar, "'TCX20'" ) == 0 ) +#endif + ) { +#ifdef SUPPORT_FORCE_TCX10_TCX20 + return IVAS_ENC_FORCE_TCX20; +#else return IVAS_ENC_FORCE_TCX; +#endif } +#ifdef SUPPORT_FORCE_TCX10_TCX20 + if ( ( strcmp( forcedModeChar, "TCX10" ) == 0 ) || ( strcmp( forcedModeChar, "'TCX10'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_TCX10; + } +#endif else if ( ( strcmp( forcedModeChar, "HQ" ) == 0 ) || ( strcmp( forcedModeChar, "'HQ'" ) == 0 ) ) { return IVAS_ENC_FORCE_HQ; -- GitLab From 82c5e4ca92329673e3fcaca14d11e967c2f37350 Mon Sep 17 00:00:00 2001 From: malenov Date: Wed, 26 Feb 2025 15:35:42 +0100 Subject: [PATCH 13/14] make DEBUG_FORCE_DIR inactive by default --- lib_com/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 46ea18c9d..92c0dd78c 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -50,7 +50,7 @@ #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 DEBUG_FORCE_DIR /* Force modes/parameters by reading from external binary files */ +/*#define DEBUG_FORCE_DIR*/ /* Force modes/parameters by reading from external binary files */ /*#define DBG_WAV_WRITER*/ /* Enable dbgwrite_wav() function for generating ".wav" files */ #define SUPPORT_FORCE_TCX10_TCX20 /* VA: Enable -force tcx10|tcx20 command-line option */ #endif -- GitLab From bfad31be34fc246c8a128dea91c6ca90e56088cb Mon Sep 17 00:00:00 2001 From: Vladimir Malenovsky Date: Wed, 26 Feb 2025 15:52:16 +0100 Subject: [PATCH 14/14] clang format --- lib_enc/ivas_core_pre_proc_front.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 9fc530fa4..184c07505 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -1786,7 +1786,7 @@ ivas_error pre_proc_front_ivas_fx( dbgwrite( &smc_dec, sizeof( int16_t ), 1, 1, "res/force_smc_dec_loc2.enf" ); dbgwrite( &st->sp_aud_decision0, sizeof( int16_t ), 1, 1, "res/force_sp_aud_decision0.enf" ); dbgwrite( &st->sp_aud_decision1, sizeof( int16_t ), 1, 1, "res/force_sp_aud_decision1.enf" ); - dbgwrite( &st->sp_aud_decision2, sizeof( int16_t ), 1, 1, "res/force_sp_aud_decision2.enf" ); + dbgwrite( &st->sp_aud_decision2, sizeof( int16_t ), 1, 1, "res/force_sp_aud_decision2.enf" ); } #endif -- GitLab