Commit 39be30e8 authored by Tapani Pihlajakuja's avatar Tapani Pihlajakuja
Browse files

Implements contribution 42 - MASA support for prerenderer

parent b5f18301
Loading
Loading
Loading
Loading
+154 −2
Original line number Diff line number Diff line
@@ -49,6 +49,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"
@@ -416,6 +419,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;
    }

@@ -539,6 +545,9 @@ int main(
    IsmPositionProvider *positionProvider;
    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;
@@ -684,7 +693,6 @@ int main(
                fprintf( stderr, "Sampling rate must be specified on command line when using raw PCM input\n" );
                exit( -1 );
            }
            args.sampleRate = inFileSampleRate;
            break;
        default:
            fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
@@ -713,7 +721,11 @@ int main(

    /* === Configure === */
#ifdef TD5
#ifdef MASA_PREREND
    if ( ( error = IVAS_REND_InitConfig( hIvasRend, strlen( args.renderConfigFilePath ) != 0 ) ) != IVAS_ERR_OK )
#else
    if ( ( error = IVAS_REND_InitConfig( hIvasRend, ( args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) || ( args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL ) ) ) != IVAS_ERR_OK )
#endif
#else
    if ( ( error = IVAS_REND_InitConfig( hIvasRend, strlen( args.renderConfigFilePath ) != 0 ) ) != IVAS_ERR_OK )
#endif
@@ -776,6 +788,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 */
@@ -851,6 +882,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 )
@@ -1071,6 +1110,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 )
@@ -1084,6 +1160,7 @@ int main(
                fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
                exit( -1 );
            }
#endif
        }

        for ( i = 0; i < args.inConfig.numAmbisonicsBuses; ++i )
@@ -1175,6 +1252,81 @@ 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;

            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 )
        {
+8 −0
Original line number Diff line number Diff line
@@ -4661,6 +4661,14 @@ void ivas_spar_param_to_masa_param_mapping(
    const int16_t nSubframes                                    /* i  : Number of subframes to map                      */
);

#ifdef MASA_PREREND
uint16_t index_theta_phi_16(
    float theta,                                                /* i  : input elevation to be indexed */
    float phi,                                                  /* i  : input azimuth to be indexed  */
    SPHERICAL_GRID_DATA *gridData                               /* i  : generated grid data */
);
#endif


/*---------------------------------------------------------------------------------*
 * Binaural FastConv Renderer Prototypes
+1 −0
Original line number Diff line number Diff line
@@ -162,6 +162,7 @@
#define FIX_MDCT_BASED_BWD                              /* FhG: fixes for BWD for issues with reaction to transients for MDCT-stereo and MCT */
#define DISCRETE_ISM_DTX_CNG                            /* FhG/VA: contribution 15 - DTX/CNG for (discrete) ISM */
#define NCHAN_ISM_PARAMETER                             /* VA: make 'nchan_ism' parameter part of st_ivas/hEncoderConfig */
#define MASA_PREREND                                    /* Nokia: MASA output support to IVAS_rend */


/* ################## End DEVELOPMENT switches ######################### */
+6 −0
Original line number Diff line number Diff line
@@ -57,7 +57,9 @@
 *-----------------------------------------------------------------------*/

static int16_t quantize_theta( float x, int16_t no_cb, float *xhat );
#ifndef MASA_PREREND
static uint16_t index_theta_phi_16( float theta, float phi, SPHERICAL_GRID_DATA *Sph_Grid16 );
#endif
static int16_t quantize_phi_masa( float phi, int16_t flag_delta, float *phi_hat, const int16_t n );
static void index_16bits( IVAS_QMETADATA_HANDLE hQMetaData, SPHERICAL_GRID_DATA *Sph_Grid16 );
#ifdef FIX_350_MASA_DELAY_COMP
@@ -639,7 +641,11 @@ static int16_t quantize_phi_masa(


/* !r: output index for direction */
#ifdef MASA_PREREND
uint16_t index_theta_phi_16(
#else
static uint16_t index_theta_phi_16(
#endif
    float theta,                  /* i  : input elevation to be indexed */
    float phi,                    /* i  : input azimuth to be indexed  */
    SPHERICAL_GRID_DATA *gridData /* i  : generated grid data */
+406 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading