Commit 29405fe4 authored by multrus's avatar multrus
Browse files

Merge branch '20230124_cleanup' into 'main'

20230124 cleanup

See merge request !400
parents b8925bcb 9577cd28
Loading
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -501,14 +501,12 @@ cleanup:
#ifdef DEBUG_SBA_AUDIO_DUMP
    IVAS_DEC_GetSbaDebugParams( hIvasDec, &numOutChannels, &numTransportChannels, &pca_ingest_channels );
#endif
#ifdef FIX_235
    if ( arg.hrtfReaderEnabled )
    {
        IVAS_DEC_HRTF_HANDLE hHrtfTD;
        IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtfTD );
        dealloc_HRTF_binary( hHrtfTD );
    }
#endif
    IVAS_DEC_Close( &hIvasDec );
    CustomLsReader_close( &hLsCustomReader );
    hrtfFileReader_close( &hrtfReader );
+0 −127
Original line number Diff line number Diff line
@@ -132,14 +132,12 @@ typedef struct
    bool quietModeEnabled;
    bool sceneDescriptionInput;
    float inputGainGlobal; /* Linear gain (not in dB) */
#ifdef REND_CFG_LFE
    bool lfePanningEnabled;
    float lfeConfigGain; /* Linear gain (not in dB) */
    float lfeConfigAzimuth;
    float lfeConfigElevation;
    bool lfeCustomRoutingEnabled;
    char inLfePanningMatrixFile[RENDERER_MAX_CLI_ARG_LENGTH];
#endif
} CmdlnArgs;

typedef enum
@@ -154,12 +152,8 @@ typedef enum
    CmdLnOptionId_renderConfigFile,
    CmdLnOptionId_noDiegeticPan,
    CmdLnOptionId_orientationTracking,
#ifdef REND_CFG_LFE
    CmdlnOptionId_lfePosition,
    CmdlnOptionId_lfeMatrix,
#else
    CmdLnOptionId_customLfeRouting,
#endif
    CmdLnOptionId_noDelayCmp,
    CmdLnOptionId_quietModeEnabled,
    CmdLnOptionId_inputMetadata,
@@ -235,26 +229,15 @@ static const CmdLnParser_Option cliOptions[] = {
        .description = "Head orientation tracking type: 'ref' or 'avg' (only for BINAURAL and BINAURAL_ROOM) (todo: check implementation)",
    },
    {
#ifdef REND_CFG_LFE
        .id = CmdlnOptionId_lfePosition,
        .match = "lfe_position",
        .matchShort = "lp",
        .description = "Output LFE position. Comma-delimited triplet of [gain, azimuth, elevation] where gain is linear (like --gain, -g) and azimuth, elevation are in degrees.\nIf specified, overrides the default behavior which attempts to map input to output LFE channel(s)",
#else
        /* TODO(sgi): Replace with more configurable input, e.g. ask for a list of triplets: (gain, azimuth, elevation) to place LFE signal */
        /* rename to "lfeHandling" */
        .id = CmdLnOptionId_customLfeRouting,
        .match = "neverDropLfe",
        .matchShort = "ndl",
        .description = "[flag] If set, renderer tries to render LFE into other channels in an optimal way when rendering to configs w/o LFE",
#endif
    },
#ifdef REND_CFG_LFE
    { .id = CmdlnOptionId_lfeMatrix,
      .match = "lfe_matrix",
      .matchShort = "lm",
      .description = "LFE panning matrix. File (CSV table) containing a matrix of dimensions [ num_input_lfe x num_output_channels ] with elements specifying linear routing gain (like --gain, -g). \nIf specified, overrides the output LFE position option and the default behavior which attempts to map input to output LFE channel(s)" },
#endif
    {
        .id = CmdLnOptionId_noDelayCmp,
        .match = "no_delay_cmp",
@@ -360,11 +343,9 @@ static void parseMetadata(
    IsmPositionProvider *positionProvider,
    MasaFileReader **masaReaders );

#ifdef REND_CFG_LFE
static ivas_error parseLfePanMtxFile(
    const char *lfeRoutingMatrixFilePath,
    IVAS_REND_LfePanMtx *lfePanMtx );
#endif

static void convert_backslash( char *str );

@@ -582,9 +563,7 @@ int main(
    convert_backslash( args.inputFilePath );
    convert_backslash( args.outputFilePath );
    convert_backslash( args.headRotationFilePath );
#ifdef REND_CFG_LFE
    convert_backslash( args.inLfePanningMatrixFile );
#endif

    if ( !isEmptyString( args.headRotationFilePath ) )
    {
@@ -691,7 +670,6 @@ int main(
        }
    }

#ifdef REND_CFG_LFE
    IVAS_REND_LfePanMtx lfePanMatrix;

    /* parse input LFE panning matrix */
@@ -704,7 +682,6 @@ int main(
            exit( -1 );
        }
    }
#endif

    for ( i = 0; i < args.inConfig.numMultiChannelBuses; ++i )
    {
@@ -729,7 +706,6 @@ int main(
            }
        }

#ifdef REND_CFG_LFE
        /* set panning matrix for input LFE */
        if ( args.lfeCustomRoutingEnabled )
        {
@@ -754,9 +730,6 @@ int main(
                exit( -1 );
            }
        }
#else
        /* TODO(sgi): Test custom LFE routing here */
#endif
    }

    for ( i = 0; i < args.inConfig.numAudioObjects; ++i )
@@ -1100,7 +1073,6 @@ static IVAS_REND_AudioConfig ambisonicsOrderToEnum(
    return IVAS_REND_AUDIO_CONFIG_UNKNOWN;
}

#ifdef FIX_293_EXT_RENDERER_CLI
static const CmdLnParser_Option *findOptionById(
    const int32_t id )
{
@@ -1114,7 +1086,6 @@ static const CmdLnParser_Option *findOptionById(

    return NULL;
}
#endif

static bool parseInConfig(
    const char *inFormatStr,
@@ -1203,13 +1174,9 @@ static bool parseInConfig(

                if ( error == IVAS_ERR_FAILED_FILE_OPEN )
                {
#ifdef FIX_293_EXT_RENDERER_CLI
                    /* Failed to open with given string - most likely wasn't a file path */
                    const CmdLnParser_Option *listOption = findOptionById( CmdLnOptionId_listFormats );
                    fprintf( stderr, "Unsupported input format: %s. To list valid formats, use option --%s.\n", inFormatStr, listOption->match );
#else
                    fprintf( stderr, "Unsupported input format: %s\n", inFormatStr );
#endif
                    return false;
                }
                if ( error != IVAS_ERR_OK )
@@ -1224,7 +1191,6 @@ static bool parseInConfig(
            }
            break;
        default:
#ifdef FIX_293_EXT_RENDERER_CLI
        {
            /* Default case covers formats that are defined in the IVAS_REND_AudioConfig enum,
             * but cannot be used at input, e.g. BINAURAL */
@@ -1232,12 +1198,6 @@ static bool parseInConfig(
            fprintf( stderr, "Unsupported input format: %s. To list valid formats, use option --%s.\n", inFormatStr, listOption->match );
            return false;
        }
#else
            /* Default case covers formats that are defined in the IVAS_REND_AudioConfig enum,
             * but cannot be used at input, e.g. BINAURAL */
            fprintf( stderr, "Unsupported input format: %s\n", inFormatStr );
            return false;
#endif
    }

    return true;
@@ -1265,18 +1225,10 @@ static bool parseOutConfig(
    return true;
}

#ifdef REND_CFG_LFE
static bool parseDiegeticPan(
#else
static int8_t parseDiegeticPan(
#endif
    char *value,
    float *noDiegeticPan )
{
#ifndef REND_CFG_LFE
    int8_t success;
    success = 1;
#endif
    to_upper( value );

    if ( ( strcmp( value, "CENTER" ) == 0 ) || ( strchr( value, 'C' ) != NULL ) )
@@ -1298,32 +1250,16 @@ static int8_t parseDiegeticPan(
        if ( *noDiegeticPan > 1.0f || *noDiegeticPan < -1.0f )
        {
            fprintf( stderr, "Error: Incorrect value for panning option argument specified!\n\n" );
#ifdef REND_CFG_LFE
            return false;
#else
            success = 0;
#endif
        }
    }
#ifdef REND_CFG_LFE
    return false;
#else
    return success ? 0 : -1;
#endif
}

#ifdef REND_CFG_LFE
static bool parseOrientationTracking(
#else
static int8_t parseOrientationTracking(
#endif
    char *value,
    int8_t *tracking_type )
{
#ifndef REND_CFG_LFE
    int8_t success;
    success = 1;
#endif

    to_upper( value );

@@ -1338,18 +1274,10 @@ static int8_t parseOrientationTracking(
    else
    {
        fprintf( stderr, "Error: Invalid orientation tracking type %s \n\n", value );
#ifdef REND_CFG_LFE
        return false;
#else
        success = 0;
#endif
    }

#ifdef REND_CFG_LFE
    return true;
#else
    return success ? 0 : -1;
#endif
}

static IVAS_REND_AudioConfig parseAudioConfig(
@@ -1403,7 +1331,6 @@ static IVAS_REND_AudioConfig parseAudioConfig(
    }
    if ( strncmp( charBuf, "ISM", 3 ) == 0 )
    {
#ifdef FIX_293_EXT_RENDERER_CLI
        /* Accept input config as ISM only if the 4th character is a number from 1 to 4.
         * Otherwise, do nothing. Unknown audio config will be returned. */
        switch ( charBuf[3] )
@@ -1414,9 +1341,6 @@ static IVAS_REND_AudioConfig parseAudioConfig(
            case '4':
                return IVAS_REND_AUDIO_CONFIG_OBJECT;
        }
#else
        return IVAS_REND_AUDIO_CONFIG_OBJECT;
#endif
    }
    if ( strncmp( charBuf, "MASA", 4 ) == 0 )
    {
@@ -1444,7 +1368,6 @@ static IVAS_REND_AudioConfig parseAudioConfig(
    return IVAS_REND_AUDIO_CONFIG_UNKNOWN;
}

#ifdef REND_CFG_LFE
static bool parseLfePositionConfig(
    const char *value,
    float *lfeGain,
@@ -1490,23 +1413,7 @@ static bool parseLfePositionConfig(
    *lfeElevation = values[2];
    return true;
}
#endif

#ifndef FIX_293_EXT_RENDERER_CLI
static const CmdLnParser_Option *findOptionById(
    const int32_t id )
{
    for ( int32_t i = 0; i < numCliOptions; ++i )
    {
        if ( cliOptions[i].id == id )
        {
            return &cliOptions[i];
        }
    }

    return NULL;
}
#endif

static bool checkRequiredArgs(
    CmdlnArgs args )
@@ -1591,7 +1498,6 @@ static CmdlnArgs defaultArgs(
    args.sceneDescriptionInput = false;
    args.inputGainGlobal = 1.0f;

#ifdef REND_CFG_LFE
    args.lfePanningEnabled = false;
    args.lfeConfigGain = 1.0f;
    args.lfeConfigAzimuth = 0;
@@ -1599,7 +1505,6 @@ static CmdlnArgs defaultArgs(

    args.lfeCustomRoutingEnabled = false;
    clearString( args.inLfePanningMatrixFile );
#endif
    return args;
}

@@ -1670,11 +1575,7 @@ static void parseOption(
            break;
        case CmdLnOptionId_noDiegeticPan:
            assert( numOptionValues == 1 );
#ifdef REND_CFG_LFE
            if ( !parseDiegeticPan( optionValues[0], &args->noDiegeticPan ) )
#else
            if ( parseDiegeticPan( optionValues[0], &args->noDiegeticPan ) != 0 )
#endif
            {
                fprintf( stderr, "Unknown option for diegetic panning: %s\n", optionValues[0] );
                exit( -1 );
@@ -1682,17 +1583,12 @@ static void parseOption(
            break;
        case CmdLnOptionId_orientationTracking:
            assert( numOptionValues == 1 );
#ifdef REND_CFG_LFE
            if ( !parseOrientationTracking( optionValues[0], &args->orientationTracking ) )
#else
            if ( parseOrientationTracking( optionValues[0], &args->orientationTracking ) != 0 )
#endif
            {
                fprintf( stderr, "Unknown option for orientation tracking: %s\n", optionValues[0] );
                exit( -1 );
            }
            break;
#ifdef REND_CFG_LFE
        case CmdlnOptionId_lfePosition:
            assert( numOptionValues == 1 );
            if ( !parseLfePositionConfig( optionValues[0], &args->lfeConfigGain, &args->lfeConfigAzimuth, &args->lfeConfigElevation ) )
@@ -1702,18 +1598,12 @@ static void parseOption(
            }
            args->lfePanningEnabled = true;
            break;
#else
        case CmdLnOptionId_customLfeRouting:
            assert( 0 && "Not yet implemented in CLI" );
#endif
            break;
#ifdef REND_CFG_LFE
        case CmdlnOptionId_lfeMatrix:
            assert( numOptionValues == 1 );
            strncpy( args->inLfePanningMatrixFile, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 );
            args->lfeCustomRoutingEnabled = true;
            break;
#endif
        case CmdLnOptionId_noDelayCmp:
            assert( numOptionValues == 0 );
            args->delayCompensationEnabled = false;
@@ -1836,7 +1726,6 @@ void IsmPositionProvider_getNextFrame(

    for ( objIdx = 0; objIdx < positionProvider->numObjects; ++objIdx )
    {
#ifdef FIX_293_EXT_RENDERER_CLI
        /* If ISM metadata reader is open, read from metadata file */
        if ( positionProvider->ismReaders[objIdx] != NULL )
        {
@@ -1853,16 +1742,6 @@ void IsmPositionProvider_getNextFrame(
            objectMetadataBuffer->positions[objIdx].azimuth = 0.0f;
            objectMetadataBuffer->positions[objIdx].elevation = 0.0f;
        }
#else
        if ( positionProvider->ismReaders[objIdx] != NULL )
        {
            getMetadataFromFileReader( positionProvider->ismReaders[objIdx], objectMetadataBuffer, objIdx );
        }
        else
        {
            readFromShorthandMetadata( positionProvider, objectMetadataBuffer, objIdx );
        }
#endif

        /* Wrap azimuth to lie within (-180, 180] range */
        while ( objectMetadataBuffer->positions[objIdx].azimuth < 0.0f )
@@ -2250,11 +2129,7 @@ static void parseMasa(
    if ( strncmp( line, "MASA", 4 ) != 0 )
    {
        char numTcs = *line;
#ifdef FIX_293_EXT_RENDERER_CLI
        snprintf( line, 6 /* write at most 6 characters: MASAx + null termination */, "MASA%c", numTcs );
#else
        sprintf( line, "MASA%c", numTcs );
#endif
    }

    inConfig->masaBuses[idx].audioConfig = parseAudioConfig( line );
@@ -2496,7 +2371,6 @@ static void printSupportedAudioConfigs()
    return;
}

#ifdef REND_CFG_LFE
static ivas_error parseLfePanMtxFile(
    const char *lfeRoutingMatrixFilePath,
    IVAS_REND_LfePanMtx *lfePanMtx )
@@ -2560,7 +2434,6 @@ static ivas_error parseLfePanMtxFile(
    fclose( mtxFile );
    return IVAS_ERR_OK;
}
#endif

// VE2AT: possibly move these functions to cmdln_parser.c ?
static void convert_backslash(
+0 −2
Original line number Diff line number Diff line
@@ -1682,14 +1682,12 @@ enum
#define HALF_D_STAB_TBL_FX                  ( (Word16) 422 )        /* Q13 0.1013138/2.0 */
#define NUM_ENV_STAB_PLC_STATES             2                       /* Number of states of markov model */

#ifdef ENV_STAB_FIX
#define ENV_STAB_EST1                       2.93f                   /* env_stab estimation coefficient 1 */
#define ENV_STAB_EST2                       (-2.20f)                /* env_stab estimation coefficient 2 */
#define ENV_STAB_EST3                       0.741f                  /* env_stab estimation coefficient 3 */
#define STAB_FAC_EST1                       1.093f                  /* stab_fac HQ estimation coefficient 1 */
#define STAB_FAC_EST2                       (-5.84e-05f)            /* stab_fac HQ estimation coefficient 2, including Q12 scaling */
#define STAB_FAC_EST3                       0.125f                  /* stab_fac HQ estimation coefficient 3 */
#endif

#define ATT_LIM_HANGOVER                    150                     /* Number of hangover frames for disabling stability dependent attenuation */
#define DELTA_TH                            5.0f                    /* Delta energy threshold for transient detection for envelope stability */
+3 −58
Original line number Diff line number Diff line
@@ -66,12 +66,8 @@ float env_stability(
    const int16_t *ynrm,              /* i  : Norm vector for current frame          */
    const int16_t nb_sfm,             /* i  : Number of sub-bands                    */
    int16_t *mem_norm,                /* i/o: Norm vector memory from past frame     */
#ifdef ENV_STAB_FIX
    int16_t *mem_env_delta,           /* i/o: Envelope stability memory for smoothing*/
    const int16_t core_switching_flag /* i  : Core switching flag        */
#else
    int16_t *mem_env_delta /* i/o: Envelope stability memory for smoothing*/
#endif
)
{
    Word16 env_delta;
@@ -87,7 +83,6 @@ float env_stability(
    Flag Overflow;
#endif /* BASOP_NOGLOB */

#ifdef ENV_STAB_FIX
    if ( core_switching_flag )
    {
        for ( i = 0; i < nb_sfm; i++ )
@@ -150,56 +145,6 @@ float env_stability(
        env_delta = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow );              /* Q13 */
#endif                                             /* BASOP_NOGLOB */
    }
#else

    /* Calculate envelope stability parameter */
    L_env_delta = L_deposit_l( 0 );
    for ( i = 0; i < nb_sfm; i++ )
    {
        tmp = sub( mem_norm[i], ynrm[i] );
        L_env_delta = L_mac0( L_env_delta, tmp, tmp );
        mem_norm[i] = ynrm[i];
    }

#ifdef DEBUGGING
    assert( nb_sfm == 27 || nb_sfm == 26 );
#endif
    inv_nb_sfm = 19418; /* Q19 */
    if ( nb_sfm == 26 )
    {
        inv_nb_sfm = 20165; /* Q19 */
    }
    exp = norm_l( L_env_delta );
    L_env_delta = Mult_32_16( L_shl( L_env_delta, exp ), inv_nb_sfm ); /* 0+exp+19-15 */

    L_tmp = Sqrt_l( L_env_delta, &exp2 ); /* exp+4+31+exp2 */

    exp = add( 35, add( exp, exp2 ) );
    if ( sub( s_and( exp, 1 ), 1 ) == 0 )
    {
        L_tmp = Mult_32_16( L_tmp, 23170 ); /* 1/sqrt(2) in Q15 */
    }
    exp = shr( exp, 1 );

#ifndef BASOP_NOGLOB
    env_delta = round_fx( L_shl( L_tmp, sub( 26, exp ) ) ); /* Q10 */
    L_tmp = L_mult0( 26214, env_delta );                    /* 26214 is 0.1 in Q18. Q28 */
    L_tmp = L_mac( L_tmp, 29491, *mem_env_delta );          /* 29491 is 0.9 in Q15. Q28 */
    *mem_env_delta = round_fx( L_tmp );                     /* Q12 */
#else  /* BASOP_NOGLOB */
    env_delta = round_fx_o( L_shl_o( L_tmp, sub( 26, exp ), &Overflow ), &Overflow ); /* Q10 */
    L_tmp = L_mult0( 26214, env_delta );                                              /* 26214 is 0.1 in Q18. Q28 */
    L_tmp = L_mac_o( L_tmp, 29491, *mem_env_delta, &Overflow );                       /* 29491 is 0.9 in Q15. Q28 */
    *mem_env_delta = round_fx_o( L_tmp, &Overflow );                                  /* Q12 */
#endif /* BASOP_NOGLOB */
    Overflow = 0;
#ifndef BASOP_NOGLOB
    env_delta = round_fx( L_shl( L_tmp, 1 ) ); /* Q13 */
#else /* BASOP_NOGLOB */
    env_delta = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow );              /* Q13 */
#endif
                                               /* BASOP_NOGLOB */
#endif
    if ( Overflow != 0 ) /* Saturated due to the above up-shifting operation. */
    {
        env_stab = stab_trans_fx[L_STAB_TBL - 1];             /* The highest quantized index. */
+0 −2
Original line number Diff line number Diff line
@@ -520,9 +520,7 @@ typedef enum

#define STEREO_DFT_XCORR_LB_MAX                 24

#ifdef STABILIZE_GIPD
#define STEREO_DFT_IPD_BUF_LEN                  5
#endif

#define STEREO_DFT_N_COH_PRED                   4                           /* Number of intra-frame predictors for coherence vector */
#define STEREO_DFT_COH_PRED_COEFFS              15                          /* Number of coefficients per predictor */
Loading