Commit c7f3151e authored by Tapani Pihlajakuja's avatar Tapani Pihlajakuja
Browse files

Merge branch 'nokia/contribution-42-masa-prerend' into 'main'

Nokia/contribution 42 masa prerend

See merge request !716
parents f67fd052 b82c9409
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -202,14 +202,18 @@
    <ClCompile Include="..\lib_rend\ivas_sba_rendering.c" />
    <ClCompile Include="..\lib_rend\ivas_allrad_dec.c" />
    <ClCompile Include="..\lib_rend\ivas_crend.c" />
    <ClCompile Include="..\lib_rend\ivas_dirac_ana.c" />
    <ClCompile Include="..\lib_rend\ivas_efap.c" />
    <ClCompile Include="..\lib_rend\ivas_limiter.c" />
    <ClCompile Include="..\lib_rend\ivas_masa_merge.c" />
    <ClCompile Include="..\lib_rend\ivas_mcmasa_ana.c" />
    <ClCompile Include="..\lib_rend\ivas_objectRenderer.c" />
    <ClCompile Include="..\lib_rend\ivas_objectRenderer_hrFilt.c" />
    <ClCompile Include="..\lib_rend\ivas_objectRenderer_mix.c" />
    <ClCompile Include="..\lib_rend\ivas_objectRenderer_sfx.c" />
    <ClCompile Include="..\lib_rend\ivas_objectRenderer_sources.c" />
    <ClCompile Include="..\lib_rend\ivas_objectRenderer_vec.c" />
    <ClCompile Include="..\lib_rend\ivas_omasa_ana.c" />
    <ClCompile Include="..\lib_rend\ivas_orient_trk.c" />
    <ClCompile Include="..\lib_rend\ivas_output_init.c" />
    <ClCompile Include="..\lib_rend\ivas_render_config.c" />
+173 −0
Original line number Diff line number Diff line
@@ -51,6 +51,9 @@
#include "ism_file_reader.h"
#include "ls_custom_file_reader.h"
#include "masa_file_reader.h"
#ifdef MASA_PREREND
#include "masa_file_writer.h"
#endif
#include "prot.h"
#include "render_config_reader.h"
#include "wmc_auto.h"
@@ -443,6 +446,9 @@ static int16_t getTotalNumInChannels(
            fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
            exit( -1 );
        }
#ifdef MASA_PREREND
        IVAS_REND_GetNumAllObjects( hIvasRend, &numInputChannels ); /* In case of MASA output, modify the numInputChannels to contain all objects. Otherwise, keep the original value. */
#endif
        totalNumInChannels += numInputChannels;
    }

@@ -571,6 +577,9 @@ int main(
#endif
    RenderConfigReader *renderConfigReader = NULL;
    MasaFileReader *masaReaders[RENDERER_MAX_MASA_INPUTS];
#ifdef MASA_PREREND
    MasaFileWriter *masaWriter = NULL;
#endif
    IVAS_MASA_METADATA_HANDLE hMasaMetadata[RENDERER_MAX_MASA_INPUTS];
    char audioFilePath[FILENAME_MAX];
    AudioFileReader *audioReader = NULL;
@@ -721,6 +730,26 @@ int main(
        setupWithSingleFormatInput( args, audioFilePath, positionProvider, masaReaders );
    }

#ifdef MASA_PREREND
    /* Check that there is allowed configuration for MASA format output */
    if ( args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA1 || args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA2 )
    {
        if ( args.inConfig.numMasaBuses == 0 )
        {
            fprintf( stderr, "\nInvalid configuration - Merging to MASA output requires MASA input and at least one another input to be present\n" );
            fprintf( stderr, "\nMASA input is missing\n" );
            exit( -1 );
        }

        if ( args.inConfig.numAudioObjects == 0 && args.inConfig.numMultiChannelBuses == 0 && args.inConfig.numAmbisonicsBuses == 0 )
        {
            fprintf( stderr, "\nInvalid configuration - Merging to MASA output requires MASA input and at least one another input to be present\n" );
            fprintf( stderr, "\nNo object, multi-channel, or Ambisonic input present.\n" );
            exit( -1 );
        }
    }
#endif

    if ( AudioFileReader_open( &audioReader, audioFilePath ) != IVAS_ERR_OK )
    {
        fprintf( stderr, "Error opening file: %s\n", audioFilePath );
@@ -827,6 +856,25 @@ int main(
        }
    }

#ifdef MASA_PREREND
    /* Set up MASA writer for MASA output */
    if ( args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA1 || args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA2 )
    {
        MasaFileWriter_open( args.outputFilePath, true, &masaWriter ); /* No delay for audio in renderer, so calling metadata writer in delayCompensated mode, i.e., no delay applied to meta */
        if ( masaWriter == NULL )
        {
            fprintf( stderr, "Could not open MASA metadata file %s\n", args.outputFilePath );
            exit( -1 );
        }
    }

    /* Set the total number of objects */
    if ( args.inConfig.numAudioObjects > 0 )
    {
        IVAS_REND_SetTotalNumberOfObjects( hIvasRend, args.inConfig.numAudioObjects );
    }
#endif

    IVAS_REND_LfePanMtx lfePanMatrix;

    /* parse input LFE panning matrix */
@@ -937,6 +985,14 @@ int main(
            fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
            exit( -1 );
        }

#ifdef MASA_PREREND
        /* With MASA output, all objects are handled at once, so add only one input having all objects in it */
        if ( args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA1 || args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA2 )
        {
            break;
        }
#endif
    }

    for ( i = 0; i < args.inConfig.numAmbisonicsBuses; ++i )
@@ -1165,6 +1221,43 @@ int main(

        for ( i = 0; i < args.inConfig.numAudioObjects; ++i )
        {
#ifdef MASA_PREREND
            if ( args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA1 || args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA2 )
            {
                if ( i == 0 )
                {
                    IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, (int16_t) args.inConfig.audioObjects[i].inputChannelIndex, args.inConfig.numAudioObjects );

                    if ( ( error = IVAS_REND_FeedInputAudio( hIvasRend, ismIds[i], tmpBuffer ) ) != IVAS_ERR_OK )
                    {
                        fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
                        exit( -1 );
                    }
                }

                if ( ( error = IVAS_REND_FeedInputObjectMetadataToOMasa( hIvasRend, i, mtdBuffer.positions[i] ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }
            }
            else
            {
                IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, (int16_t) args.inConfig.audioObjects[i].inputChannelIndex, 1 );

                if ( ( error = IVAS_REND_FeedInputAudio( hIvasRend, ismIds[i], tmpBuffer ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }

                if ( ( error = IVAS_REND_FeedInputObjectMetadata( hIvasRend, ismIds[i], mtdBuffer.positions[i] ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }
            }
#else
            IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, (int16_t) args.inConfig.audioObjects[i].inputChannelIndex, 1 );

            if ( ( error = IVAS_REND_FeedInputAudio( hIvasRend, ismIds[i], tmpBuffer ) ) != IVAS_ERR_OK )
@@ -1178,6 +1271,7 @@ int main(
                fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
                exit( -1 );
            }
#endif
        }

        for ( i = 0; i < args.inConfig.numAmbisonicsBuses; ++i )
@@ -1269,6 +1363,82 @@ int main(
            delayNumSamples -= (int16_t) outBufferSize;
        }

#ifdef MASA_PREREND
        /* Write MASA metadata for MASA outputs */
        if ( args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA1 || args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA2 )
        {
            IVAS_REND_AudioConfigType inputType1;
            IVAS_REND_AudioConfigType inputType2;
            MASA_DECODER_EXT_OUT_META_HANDLE hMetaOutput;
            int16_t numInputFormats;

            inputType1 = IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN;
            inputType2 = IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN;
            hMetaOutput = NULL;

            numInputFormats = 0;
            if ( args.inConfig.numAmbisonicsBuses > 0 )
            {
                numInputFormats++;
                inputType1 = IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS;
            }
            if ( args.inConfig.numMultiChannelBuses > 0 )
            {
                numInputFormats++;
                if ( inputType1 == IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN )
                {
                    inputType1 = IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED;
                }
            }
            if ( args.inConfig.numMasaBuses > 0 )
            {
                numInputFormats++;
                if ( inputType1 == IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN )
                {
                    inputType1 = IVAS_REND_AUDIO_CONFIG_TYPE_MASA;
                }
            }
            if ( args.inConfig.numAudioObjects > 0 )
            {
                numInputFormats++;
                if ( inputType1 == IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN )
                {
                    inputType1 = IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED;
                }
            }

            if ( numInputFormats == 1 )
            {
                IVAS_REND_GetMasaMetadata( hIvasRend, &hMetaOutput, inputType1 );
            }
            else
            {
                if ( args.inConfig.numAmbisonicsBuses > 0 && args.inConfig.numMultiChannelBuses > 0 )
                {
                    inputType2 = IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED;
                    IVAS_REND_MergeMasaMetadata( hIvasRend, &hMetaOutput, inputType1, inputType2 );
                }

                if ( ( args.inConfig.numAmbisonicsBuses > 0 || args.inConfig.numMultiChannelBuses > 0 ) && args.inConfig.numMasaBuses > 0 )
                {
                    inputType2 = IVAS_REND_AUDIO_CONFIG_TYPE_MASA;
                    IVAS_REND_MergeMasaMetadata( hIvasRend, &hMetaOutput, inputType1, inputType2 );
                }

                if ( ( args.inConfig.numAmbisonicsBuses > 0 || args.inConfig.numMultiChannelBuses > 0 || args.inConfig.numMasaBuses > 0 ) && args.inConfig.numAudioObjects > 0 )
                {
                    inputType2 = IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED;
                    IVAS_REND_MergeMasaMetadata( hIvasRend, &hMetaOutput, inputType1, inputType2 );
                }
            }

            if ( ( error = MasaFileWriter_writeFrame( masaWriter, hMetaOutput ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nError writing MASA metadata to file: %s\n", MasaFileWriter_getFilePath( masaWriter ) );
            }
        }
#endif

        frame++;
        if ( !args.quietModeEnabled )
        {
@@ -1322,6 +1492,9 @@ int main(
    {
        LfeRoutingConfig_close( lfeRoutingConfigs[i] );
    }
#endif
#ifdef MASA_PREREND
    MasaFileWriter_close( &masaWriter );
#endif
    AudioFileReader_close( &audioReader );
    AudioFileWriter_close( &audioWriter );
+2 −0
Original line number Diff line number Diff line
@@ -172,6 +172,8 @@

#define EXTERNAL_ORIENTATIONS                           /* Nokia: Contribution 41: (external) orientation information handling */

#define MASA_PREREND                                    /* Nokia: Contribution 42: Support for IVAS_rend to merge MASA + other format to MASA */

/* ################## End DEVELOPMENT switches ######################### */
/* clang-format on */

+406 −0

File added.

Preview size limit exceeded, changes collapsed.

+362 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading