Commit a532bbaf authored by Devansh Kandpal's avatar Devansh Kandpal
Browse files

All changes in apps/renderer.c

parent bfbdc93a
Loading
Loading
Loading
Loading
+181 −4
Original line number Diff line number Diff line
@@ -142,6 +142,18 @@ typedef struct
    IVAS_CUSTOM_LS_DATA outSetupCustom;
} OutputConfig;

#ifdef FIX_1053_REVERB_RECONFIGURATION
typedef struct
{
    uint16_t *pID;
    uint16_t *pValidity;
    uint16_t count;
    uint16_t selected;
    uint16_t frameCounter;
} AcousticEnvironmentSequence;
#endif


typedef struct
{
    char executableName[RENDERER_MAX_CLI_ARG_LENGTH];
@@ -181,7 +193,11 @@ typedef struct
    float syncMdDelay;
    IVAS_RENDER_FRAMESIZE render_framesize;
    uint16_t directivityPatternId[RENDERER_MAX_ISM_INPUTS];
#ifdef FIX_1053_REVERB_RECONFIGURATION
    AcousticEnvironmentSequence aeSequence;
#else
    uint16_t acousticEnvironmentId;
#endif
} CmdlnArgs;

typedef enum
@@ -314,10 +330,12 @@ static const CmdLnParser_Option cliOptions[] = {
        .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)",
    },
    { .id = CmdlnOptionId_lfeMatrix,
    {
        .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)" },
        .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)",
    },
    {
        .id = CmdLnOptionId_noDelayCmp,
        .match = "no_delay_compensation",
@@ -382,7 +400,11 @@ static const CmdLnParser_Option cliOptions[] = {
        .id = CmdLnOptionId_acousticEnvironmentId,
        .match = "acoustic_environment_id",
        .matchShort = "aeid",
#ifdef FIX_1053_REVERB_RECONFIGURATION
        .description = "Acoustic environment ID( number > 0 ) or a sequence thereof in the format [ID1:duration1,ID2:duration2...] without braces and spaces, with ':' character separating ID from duration and ',' separating ID and duration pairs, where duration is specified in frames for BINAURAL_ROOM_REVERB output configuration.",
#else
        .description = "Acoustic environment ID (number >= 0) for BINAURAL_ROOM_REVERB output configuration",
#endif
    },
};

@@ -715,6 +737,9 @@ int main(
    int16_t zeroPadToWrite = 0;
    int32_t delayTimeScale = 0;
    int16_t i, numChannels;
#ifdef FIX_1053_REVERB_RECONFIGURATION
    uint16_t aeID;
#endif
    ivas_error error = IVAS_ERR_OK;

#ifdef WMOPS
@@ -1170,7 +1195,12 @@ int main(

        if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
        {
#ifdef FIX_1053_REVERB_RECONFIGURATION
            aeID = args.aeSequence.count > 0 ? args.aeSequence.pID[0] : 65535;
            if ( ( error = RenderConfigReader_getAcousticEnvironment( renderConfigReader, aeID, &renderConfig.roomAcoustics ) ) == IVAS_ERR_OK )
#else
            if ( ( error = RenderConfigReader_getAcousticEnvironment( renderConfigReader, args.acousticEnvironmentId, &renderConfig.roomAcoustics ) ) == IVAS_ERR_OK )
#endif
            {
                if ( RenderConfigReader_checkValues( &renderConfig ) != IVAS_ERR_OK )
                {
@@ -1180,7 +1210,11 @@ int main(
            }
            else
            {
#ifdef FIX_1053_REVERB_RECONFIGURATION
                fprintf( stderr, "Failed to get acoustic environment with ID: %d\n\n", aeID );
#else
                fprintf( stderr, "Failed to get acoustic environment with ID: %d\n\n", args.acousticEnvironmentId );
#endif
                exit( -1 );
            }
            renderConfig.roomAcoustics.override = 1;
@@ -1631,6 +1665,40 @@ int main(
        num_in_channels = inBuffer.config.numChannels;
        const bool isCurrentFrameMultipleOf20ms = frame % ( 4 / args.render_framesize ) == 0;

#ifdef FIX_1053_REVERB_RECONFIGURATION
        if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB && renderConfigReader != NULL &&
             args.aeSequence.count > 0 && args.aeSequence.pValidity[args.aeSequence.selected] != 0 )
        {
            if ( ++args.aeSequence.frameCounter >= args.aeSequence.pValidity[args.aeSequence.selected] )
            {
                IVAS_RENDER_CONFIG_DATA renderConfig;

                if ( ++args.aeSequence.selected >= args.aeSequence.count )
                {
                    args.aeSequence.selected = 0;
                }
                args.aeSequence.frameCounter = 0;
                if ( ( error = RenderConfigReader_getAcousticEnvironment( renderConfigReader, args.aeSequence.pID[args.aeSequence.selected], &renderConfig.roomAcoustics ) ) == IVAS_ERR_OK )
                {
                    if ( RenderConfigReader_checkValues( &renderConfig ) != IVAS_ERR_OK )
                    {
                        fprintf( stderr, "Invalid acoustic environment configuratoin parameters\n\n" );
                        goto cleanup;
                    }
                }
                else
                {
                    fprintf( stderr, "Failed to get acoustic environment with ID %d\n\n", args.aeSequence.pID[args.aeSequence.selected] );
                    goto cleanup;
                }
                if ( ( error = IVAS_REND_FeedRenderConfig( hIvasRend, renderConfig ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nIVAS_REND_FeedRenderConfig failed: %s\n\n", ivas_error_to_string( error ) );
                    goto cleanup;
                }
            }
        }
#endif
        numSamplesRead = 0;

        /* Read the input data */
@@ -2130,6 +2198,13 @@ cleanup:
    {
        free( bitsBufferData );
    }
#endif
#ifdef FIX_1053_REVERB_RECONFIGURATION
    if ( args.aeSequence.count > 0 )
    {
        free( args.aeSequence.pID );
        free( args.aeSequence.pValidity );
    }
#endif
    for ( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i )
    {
@@ -2607,6 +2682,93 @@ static bool parseLfePositionConfig(
}


#ifdef FIX_1053_REVERB_RECONFIGURATION
static bool parseAcousticEnvironmentIds(
    const char *value,
    AcousticEnvironmentSequence *aeSequence )
{
    uint16_t k;
    char config_string[RENDERER_MAX_METADATA_LINE_LENGTH];
    char *s;
    char *token;

    strncpy( config_string, value, RENDERER_MAX_METADATA_LINE_LENGTH );
    s = config_string;
    token = config_string;

    if ( !is_digits_only( config_string ) )
    {

        for ( k = 0; s[k]; )
        {
            s[k] == ',' ? k++ : *s++;
        }
        k++;

        if ( k == 0 )
        {
            fprintf( stdout, "Error: Invalid acoustic environment sequence specified: %s\n\n", config_string );
            return false;
        }

        if ( NULL == ( aeSequence->pID = malloc( sizeof( uint16_t ) * k ) ) ||
             NULL == ( aeSequence->pValidity = malloc( sizeof( uint16_t ) * k ) ) )
        {
            fprintf( stdout, "Error: Unable to allocate memory for acoustic environment sequence: %s\n\n", config_string );
            return false;
        }

        aeSequence->count = k;

        k = 0;

        token = strtok( config_string, ":" );

        while ( token != NULL )
        {
            if ( !is_number( token ) )
            {
                fprintf( stdout, "Error: Invalid token %s found in acoustic environment sequence: %s\n\n", token, config_string );
                return false;
            }
            aeSequence->pID[k] = (uint16_t) atoi( token );

            token = strtok( NULL, "," );
            if ( !is_number( token ) )
            {
                fprintf( stdout, "Error: Invalid token %s found in acoustic environment sequence: %s\n\n", token, config_string );
                return false;
            }
            aeSequence->pValidity[k] = (uint16_t) atoi( token );

            token = strtok( NULL, ":" );
            k++;
        }

        if ( k != aeSequence->count )
        {
            fprintf( stdout, "Error while parsing acoustic environment sequence: %s\n\n", config_string );
            return false;
        }
    }
    else
    {
        /* A single acoustic environment */
        if ( NULL == ( aeSequence->pID = malloc( sizeof( uint16_t ) ) ) ||
             NULL == ( aeSequence->pValidity = malloc( sizeof( uint16_t ) ) ) )
        {
            fprintf( stdout, "Error: Unable to allocate memory for acoustic environment sequence: %s\n\n", config_string );
            return false;
        }
        aeSequence->count = 1;
        aeSequence->pID[0] = (int16_t) atoi( config_string );
        aeSequence->pValidity[0] = 0;
    }

    return true;
}
#endif

static bool checkRequiredArgs(
    CmdlnArgs args )
{
@@ -2715,7 +2877,15 @@ static CmdlnArgs defaultArgs(
        args.directivityPatternId[i] = 65535;
    }

#ifdef FIX_1053_REVERB_RECONFIGURATION
    args.aeSequence.count = 0;
    args.aeSequence.pID = NULL;
    args.aeSequence.pValidity = NULL;
    args.aeSequence.selected = 0;
    args.aeSequence.frameCounter = 0;
#else
    args.acousticEnvironmentId = 65535;
#endif

    return args;
}
@@ -2887,12 +3057,19 @@ static void parseOption(
            break;
        case CmdLnOptionId_acousticEnvironmentId:
            assert( numOptionValues == 1 );
#ifdef FIX_1053_REVERB_RECONFIGURATION
            if ( !parseAcousticEnvironmentIds( optionValues[0], &args->aeSequence ) )
            {
                fprintf( stderr, "Invalid acoustic environment ID specified: %s\n", optionValues[0] );
            }
#else
            if ( !is_digits_only( optionValues[0] ) )
            {
                fprintf( stderr, "Invalid acousting environment ID specified: %s\n", optionValues[0] );
                exit( -1 );
            }
            args->acousticEnvironmentId = (int16_t) strtol( optionValues[0], NULL, 10 );
#endif
            break;
        case CmdLnOptionId_syncMdDelay:
            assert( numOptionValues == 1 );