Commit d3a55344 authored by malenov's avatar malenov
Browse files

add support for enforcement of modes/parameters through external binary files

parent 2d6d9ca8
Loading
Loading
Loading
Loading
Loading
+57 −2
Original line number Diff line number Diff line
@@ -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 <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

/*------------------------------------------------------------------------------------------*
@@ -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,8 +546,26 @@ 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 )
            {
@@ -539,6 +574,15 @@ int main(
                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
+2 −1
Original line number Diff line number Diff line
@@ -50,6 +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 DBG_WAV_WRITER*/                    /* Enable dbgwrite_wav() function for generating ".wav" files */
#endif

+18 −0
Original line number Diff line number Diff line
@@ -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 )
+4 −0
Original line number Diff line number Diff line
@@ -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
 *------------------------------------------------------------------------------------------*/
+43 −0
Original line number Diff line number Diff line
@@ -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)
Loading