Commit e2326bb1 authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

finish implementation for FIX_296_CFG_LFE_SCENE_DESC + remove two TODOs; needs testing

parent ae07b424
Loading
Loading
Loading
Loading
Loading
+149 −6
Original line number Diff line number Diff line
@@ -88,6 +88,15 @@ typedef struct
    uint16_t durationCounters[RENDERER_MAX_ISM_INPUTS];                /* Number of frames spent at current position */
} IsmPositionProvider;

#ifdef FIX_296_CFG_LFE_SCENE_DESC
typedef struct
{
    float lfe_azi;
    float lfe_ele;
    float lfe_gain_dB;
    char lfe_pan_mtx[FILENAME_MAX];
} LfeRoutingConfig;
#endif
typedef struct
{
    IVAS_REND_AudioConfig audioConfig;
@@ -301,7 +310,11 @@ static const int32_t numCliOptions = sizeof( cliOptions ) / sizeof( CmdLnParser_

static IVAS_REND_AudioConfig ambisonicsOrderToEnum( const int16_t order );

#ifdef FIX_296_CFG_LFE_SCENE_DESC
static void parseSceneDescriptionFile( char *path, char *audioFilePath, InputConfig *inConfig, IsmPositionProvider *positionProvider, MasaFileReader **masaReaders, LfeRoutingConfig **lfeRoutingConfigs );
#else
static void parseSceneDescriptionFile( char *path, char *audioFilePath, InputConfig *inConfig, IsmPositionProvider *positionProvider, MasaFileReader **masaReaders );
#endif

static ivas_error parseCustomLayoutFile( const char *filePath, IVAS_CUSTOM_LS_DATA *pLsSetupCustom );

@@ -313,6 +326,11 @@ static void IsmPositionProvider_getNextFrame( IsmPositionProvider *positionProvi

static void IsmPositionProvider_close( IsmPositionProvider *positionProvider );

#ifdef FIX_296_CFG_LFE_SCENE_DESC
static LfeRoutingConfig *LfeRoutingConfig_open( void );
static void LfeRoutingConfig_close( LfeRoutingConfig *lfeRoutingCfg );
#endif

static void readFromShorthandMetadata( IsmPositionProvider *positionProvider, ObjectPositionBuffer *objectMetadataBuffer, const uint32_t objIdx );

void getMetadataFromFileReader( IsmFileReader *ismReader, ObjectPositionBuffer *objectMetadataBuffer, const uint32_t objIdx );
@@ -331,7 +349,11 @@ static int8_t parseInt32( const char *line, int32_t *ret );

static void parseObjectPosition( char *line, IVAS_REND_AudioObjectPosition *position, uint16_t *positionDuration );

#ifdef FIX_296_CFG_LFE_SCENE_DESC
static void parseMetadata( char *metadataString, char *inDir, InputConfig *inConfig, IsmPositionProvider *positionProvider, MasaFileReader **masaReaders, LfeRoutingConfig **lfeRoutingConfigs );
#else
static void parseMetadata( char *metadataString, char *inDir, InputConfig *inConfig, IsmPositionProvider *positionProvider, MasaFileReader **masaReaders );
#endif

static ivas_error parseLfePanMtxFile( const char *lfeRoutingMatrixFilePath, IVAS_REND_LfePanMtx *lfePanMtx );

@@ -520,6 +542,9 @@ int main(
    HeadRotFileReader *referenceRotReader = NULL;
    hrtfFileReader *hrtfFileReader = NULL;
    IsmPositionProvider *positionProvider;
#ifdef FIX_296_CFG_LFE_SCENE_DESC
    LfeRoutingConfig *lfeRoutingConfigs[RENDERER_MAX_MC_INPUTS];
#endif
    RenderConfigReader *renderConfigReader = NULL;
    MasaFileReader *masaReaders[RENDERER_MAX_MASA_INPUTS];
    IVAS_MASA_METADATA_HANDLE hMasaMetadata[RENDERER_MAX_MASA_INPUTS];
@@ -554,6 +579,13 @@ int main(
        hMasaMetadata[i] = NULL;
    }

#ifdef FIX_296_CFG_LFE_SCENE_DESC
    for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i )
    {
        lfeRoutingConfigs[i] = NULL;
    }
#endif

    CmdlnArgs args = parseCmdlnArgs( argc, argv );

    if ( args.nonDiegeticPan && !( ( args.inConfig.numAudioObjects == 0 && args.inConfig.multiChannelBuses[0].audioConfig == IVAS_REND_AUDIO_CONFIG_MONO ) ||
@@ -626,7 +658,16 @@ int main(
    if ( args.sceneDescriptionInput )
    {
        /* With scene description input, inputFilePath is the path to the scene description file. Parse it. */
#ifdef FIX_296_CFG_LFE_SCENE_DESC
        parseSceneDescriptionFile( args.inputFilePath,
                                   audioFilePath,
                                   &args.inConfig,
                                   positionProvider,
                                   masaReaders,
                                   lfeRoutingConfigs );
#else
        parseSceneDescriptionFile( args.inputFilePath, audioFilePath, &args.inConfig, positionProvider, masaReaders );
#endif
    }
    else
    {
@@ -749,7 +790,6 @@ int main(
    /* parse input LFE panning matrix */
    if ( args.lfeCustomRoutingEnabled && !isEmptyString( args.inLfePanningMatrixFile ) )
    {
        /* TODO tmu: how should we handle this on CLI for multiple MC inputs? */
        if ( ( error = parseLfePanMtxFile( args.inLfePanningMatrixFile, &lfePanMatrix ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
@@ -771,7 +811,6 @@ int main(
            exit( -1 );
        }

        /* TODO(sgi): Command line only supports one custom LS input for now, extend */
        if ( args.inConfig.multiChannelBuses[i].audioConfig == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM )
        {
            if ( ( error = IVAS_REND_ConfigureCustomInputLoudspeakerLayout( hIvasRend, mcIds[i], args.inConfig.inSetupCustom ) ) != IVAS_ERR_OK )
@@ -804,6 +843,39 @@ int main(
                exit( -1 );
            }
        }
#ifdef FIX_296_CFG_LFE_SCENE_DESC
        else
        {
            /* check for configuration from scene description file */
            if ( lfeRoutingConfigs[i] != NULL )
            {
                /* prioritise panning matrix if configured */
                if ( lfeRoutingConfigs[i]->lfe_pan_mtx[0] != '\0' )
                {
                    if ( ( error = parseLfePanMtxFile( lfeRoutingConfigs[i]->lfe_pan_mtx, &lfePanMatrix ) ) != IVAS_ERR_OK )
                    {
                        fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
                        exit( -1 );
                    }

                    if ( ( error = IVAS_REND_SetInputLfeMtx( hIvasRend, mcIds[i], (const IVAS_REND_LfePanMtx *) &lfePanMatrix ) ) != IVAS_ERR_OK )
                    {
                        fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
                        exit( -1 );
                    }
                }
                /* set position based gains */
                else
                {
                    if ( ( error = IVAS_REND_SetInputLfePos( hIvasRend, mcIds[i], lfeRoutingConfigs[i]->lfe_gain_dB, lfeRoutingConfigs[i]->lfe_azi, lfeRoutingConfigs[i]->lfe_ele ) ) != IVAS_ERR_OK )
                    {
                        fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
                        exit( -1 );
                    }
                }
            }
        }
#endif
    }

    for ( i = 0; i < args.inConfig.numAudioObjects; ++i )
@@ -1164,6 +1236,12 @@ int main(
    {
        MasaFileReader_close( &masaReaders[i] );
    }
#ifdef FIX_296_CFG_LFE_SCENE_DESC
    for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i )
    {
        LfeRoutingConfig_close( lfeRoutingConfigs[i] );
    }
#endif
    AudioFileReader_close( &audioReader );
    AudioFileWriter_close( &audioWriter );
    HeadRotationFileReader_close( &headRotReader );
@@ -1864,6 +1942,35 @@ IsmPositionProvider *IsmPositionProvider_open(
    return ipp;
}

#ifdef FIX_296_CFG_LFE_SCENE_DESC
LfeRoutingConfig *LfeRoutingConfig_open(
    void )
{
    LfeRoutingConfig *lrc;

    lrc = (LfeRoutingConfig *) malloc( sizeof( LfeRoutingConfig ) );
    lrc->lfe_azi = 0;
    lrc->lfe_ele = 0;
    lrc->lfe_gain_dB = 0;
    lrc->lfe_pan_mtx[0] = '\0';

    return lrc;
}

void LfeRoutingConfig_close(
    LfeRoutingConfig *lfeRoutingCfg )
{
    if ( lfeRoutingCfg == NULL )
    {
        assert( !"Can't close LfeRoutingConfig - pointer is NULL" );
    }

    free( lfeRoutingCfg );

    return;
}
#endif

void getMetadataFromFileReader(
    IsmFileReader *ismReader,
    ObjectPositionBuffer *objectMetadataBuffer,
@@ -2370,6 +2477,9 @@ static void parseSba(
static void parseMc(
    char *line,
    InputConfig *inConfig,
#ifdef FIX_296_CFG_LFE_SCENE_DESC
    LfeRoutingConfig **lfeRoutingConfigs,
#endif
    const int32_t idx )
{
    readNextMetadataChunk( line, "\n" );
@@ -2378,7 +2488,7 @@ static void parseMc(

    readNextMetadataChunk( line, "\n" );
    IVAS_REND_AudioConfig cfg = parseAudioConfig( line );
    if ( cfg == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM )
    if ( cfg == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) // TODO tmu : cfg is never parsed as custom LS?
    {
        parseCustomLayoutFile( line, &inConfig->inSetupCustom );
    }
@@ -2389,9 +2499,24 @@ static void parseMc(

    /* Read optional values */
#ifdef FIX_296_CFG_LFE_SCENE_DESC
    float lg, la, le;
    char tmpfile[FILENAME_MAX];
    parseOptionalInputValues( line, &lg, &la, &le, tmpfile, &inConfig->multiChannelBuses[idx].gain_dB );
    float lfe_gain_dB, lfe_azi, lfe_ele;
    char lfe_pan_mtx[FILENAME_MAX];

    parseOptionalInputValues( line, &lfe_gain_dB, &lfe_azi, &lfe_ele, lfe_pan_mtx, &inConfig->multiChannelBuses[idx].gain_dB );

    if ( ( lfe_gain_dB != 0.f || lfe_azi != 0.f || lfe_ele != 0.f ) ||
         ( lfe_pan_mtx[0] != '\0' ) )
    {
        /* a configuration was specified, set the values */
        lfeRoutingConfigs[idx] = LfeRoutingConfig_open();

        lfeRoutingConfigs[idx]->lfe_gain_dB = lfe_gain_dB;
        lfeRoutingConfigs[idx]->lfe_azi = lfe_azi;
        lfeRoutingConfigs[idx]->lfe_ele = lfe_ele;

        strncpy( lfeRoutingConfigs[idx]->lfe_pan_mtx, lfe_pan_mtx, FILENAME_MAX );
        convert_backslash( lfeRoutingConfigs[idx]->lfe_pan_mtx );
    }
#else
    parseOptionalInputValues( line, &inConfig->multiChannelBuses[idx].gain_dB );
#endif
@@ -2480,7 +2605,12 @@ static void parseMetadata(
    char *inDir,
    InputConfig *inConfig,
    IsmPositionProvider *positionProvider,
#ifdef FIX_296_CFG_LFE_SCENE_DESC
    MasaFileReader **masaReaders,
    LfeRoutingConfig **lfeRoutingConfigs )
#else
    MasaFileReader **masaReaders )
#endif
{
    char line[RENDERER_MAX_METADATA_LINE_LENGTH];
    char *delimiter;
@@ -2532,7 +2662,11 @@ static void parseMetadata(
                fprintf( stderr, "Metadata exceeds the supported number of MC inputs\n" );
                exit( -1 );
            }
#ifdef FIX_296_CFG_LFE_SCENE_DESC
            parseMc( line, inConfig, lfeRoutingConfigs, counterChannelAudioObjects - 1 );
#else
            parseMc( line, inConfig, counterChannelAudioObjects - 1 );
#endif
        }
        else if ( strcmp( line, "SBA" ) == 0 )
        {
@@ -2600,7 +2734,12 @@ static void parseSceneDescriptionFile(
    char *audioFilePath,
    InputConfig *inConfig,
    IsmPositionProvider *positionProvider,
#ifdef FIX_296_CFG_LFE_SCENE_DESC
    MasaFileReader **masaReaders,
    LfeRoutingConfig **lfeRoutingConfigs )
#else
    MasaFileReader **masaReaders )
#endif
{
    uint32_t inAudioFilePathLen;
    char inAudioFilePath[FILENAME_MAX];
@@ -2629,7 +2768,11 @@ static void parseSceneDescriptionFile(
    strcpy( audioFilePath, inDir );
    strncat( audioFilePath, inAudioFilePath, inAudioFilePathLen );

#ifdef FIX_296_CFG_LFE_SCENE_DESC
    parseMetadata( mtdStr, inDir, inConfig, positionProvider, masaReaders, lfeRoutingConfigs );
#else
    parseMetadata( mtdStr, inDir, inConfig, positionProvider, masaReaders );
#endif

    return;
}
+4 −0
Original line number Diff line number Diff line
@@ -109,6 +109,10 @@ Currently the following key-value pairs are supported:
|         key         |              value type              |
|---------------------|--------------------------------------|
|       gain_dB       |                float                 |
|      lfe_matrix     |                 str                  |
|     lfe_gain_dB     |                float                 |
|       lfe_azi       |                float                 |
|       lfe_ele       |                float                 |


================================ Example config =================================