Commit ffa2d613 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch...

Merge branch '1066-enhance-the-mode-enforcement-functionality-force-to-include-support-for-read-write-operations' into 'main'

Resolve "Enhance the mode enforcement functionality (-force) to include support for read/write operations."

Closes #1066

See merge request !835
parents 3ad26b63 bfad31be
Loading
Loading
Loading
Loading
+116 −1
Original line number Diff line number Diff line
@@ -45,6 +45,19 @@
#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 <sys/stat.h>
#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

@@ -136,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;
@@ -689,7 +705,12 @@ int main(
        /* 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 )
            if ( ( error = IVAS_ENC_SetForcedMode( hIvasEnc, forcedMode
#ifdef DEBUG_FORCE_DIR
                                                   ,
                                                   arg.forcedModeDir
#endif
                                                   ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nIVAS_ENC_SetForcedMode failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) );
                goto cleanup;
@@ -860,6 +881,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;

@@ -1000,6 +1024,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];
@@ -1026,6 +1072,7 @@ static bool parseCmdlIVAS_enc(
                fprintf( stdout, "Forcing codec to:       %s\n", argv[i + 1] );
#endif
            }
#endif

            i += 2;
        }
@@ -1817,6 +1864,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
@@ -1926,8 +1976,72 @@ 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;
    }
    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;
    }
    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 ) )
    {
@@ -1969,6 +2083,7 @@ static IVAS_ENC_FORCED_MODE parseForcedMode(
    }

    return IVAS_ENC_FORCE_UNDEFINED;
#endif
}


+2 −1
Original line number Diff line number Diff line
@@ -46,6 +46,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 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
+17 −1
Original line number Diff line number Diff line
@@ -364,6 +364,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++;
@@ -752,7 +759,7 @@ int16_t tweakdbgfolder( const char *filename, char *filename_mod, int16_t *textm
#endif


#ifdef DEBUG_MODE_INFO
#ifdef DEBUGGING
/*-------------------------------------------------------------------*
   * fname()
   *
@@ -778,6 +785,15 @@ char *fname(
    sprintf( idd, ".id%d", id );

    strcpy( tmp_fname, dir );
#ifdef DEBUG_FORCE_DIR
    size_t len;
    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 )
+5 −1
Original line number Diff line number Diff line
@@ -60,12 +60,16 @@ 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 );
#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
 *------------------------------------------------------------------------------------------*/
+65 −0
Original line number Diff line number Diff line
@@ -839,6 +839,17 @@ ivas_error pre_proc_front_ivas_fx(
                                   &( st->flag_noisy_speech_snr ), NULL, NULL, -MAX_16, -MAX_16 ); //-100000f == max 16bit float
    move16();

#ifdef DEBUG_FORCE_DIR
    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();
    IF( EQ_16( force_front_vad, 1 ) || EQ_16( front_vad_flag, 1 ) )
    {
@@ -916,6 +927,18 @@ ivas_error pre_proc_front_ivas_fx(
        move16();
    }

#ifdef DEBUG_FORCE_DIR
    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


    /*----------------------------------------------------------------*
     * Noise energy down-ward update and total noise energy estimation
     * Long-term energies and relative frame energy updates
@@ -1456,6 +1479,20 @@ ivas_error pre_proc_front_ivas_fx(
    Copy_Scale_sig_16_32_DEPREC( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) );
#endif

#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                                *
     *-----------------------------------------------------------------*/
@@ -1514,6 +1551,17 @@ 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
    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
    if ( st->idchan == 0 )
    {
@@ -1725,6 +1773,23 @@ 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
    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 ) );
    }
    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

    /*----------------------------------------------------------------*
     * 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)
Loading