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

Ensure changes are cleanly wrapped in SPLIT_REND_WITH_HEAD_ROT (WIP) Part 2

parent 5addf2b5
Loading
Loading
Loading
Loading
Loading
+31 −16
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "assert.h"
#include <assert.h>
#include "options.h"
#include "lib_dec.h"
#include "cmdl_tools.h"
@@ -74,14 +74,16 @@ static

#define MIN_NUM_BITS_ACTIVE_FRAME 56
#define NUM_BITS_SID_IVAS_5K2     104
#ifdef SPLIT_REND_WITH_HEAD_ROT
#define NUM_FRAMES_PER_SEC 50
#define MAX_FRAME_SIZE     ( 48000 / NUM_FRAMES_PER_SEC )
#else
#define MAX_FRAME_SIZE ( 48000 / 50 )
#endif
#define MAX_NUM_OUTPUT_CHANNELS    16
#define MAX_OUTPUT_PCM_BUFFER_SIZE ( MAX_NUM_OUTPUT_CHANNELS * MAX_FRAME_SIZE )
#ifdef SPLIT_REND_WITH_HEAD_ROT
#ifdef SPLIT_REND_WITH_HEAD_ROT
#define MAX_SPLIT_REND_BITRATE                   ( 1792000 ) /* TODO tmu: unify with SPLIT_REND_MAX_BRATE ?*/
#endif
#define MAX_SPLIT_REND_BITS_BUFFER_SIZE_IN_BYTES ( ( ( (int32_t) MAX_SPLIT_REND_BITRATE / NUM_FRAMES_PER_SEC ) + 7 ) >> 3 )
#endif
#define IVAS_PUBLIC_ORIENT_TRK_NONE        ( 0 )
@@ -154,6 +156,7 @@ typedef struct
    uint16_t frontendFetchSizeMs;
#endif
#endif

} DecArguments;


@@ -877,6 +880,7 @@ static IVAS_DEC_AUDIO_CONFIG cmdline2config(
    return output_config;
}


/*---------------------------------------------------------------------*
 * parseCmdlIVAS_dec()
 *
@@ -1571,7 +1575,6 @@ static ivas_error initOnFirstGoodFrame(
    }
    *pRemainingDelayNumSamples = pFullDelayNumSamples[0];


    if ( ( error = IVAS_DEC_GetNumOutputChannels( hIvasDec, pNumOutChannels ) ) != IVAS_ERR_OK )
    {
        fprintf( stderr, "\nError in IVAS_DEC_GetNumOutputChannels, code: %d\n", error );
@@ -1601,9 +1604,7 @@ static ivas_error initOnFirstGoodFrame(
        *ppAfWriter = NULL;
    }
    else
#endif
    {
#ifdef SPLIT_REND_WITH_HEAD_ROT
        if ( arg.outputFormat == IVAS_DEC_OUTPUT_SPLIT_BINAURAL_PCM )
        {
            int16_t delayNumSamples_temp[3];
@@ -1625,7 +1626,10 @@ static ivas_error initOnFirstGoodFrame(
            fprintf( stderr, "\nUnable to open output file %s\n", arg.outputWavFilename );
            return error;
        }
#ifdef SPLIT_REND_WITH_HEAD_ROT
    }
#endif


    int16_t *zeroBuf = malloc( pcmFrameSize * sizeof( int16_t ) );
    memset( zeroBuf, 0, pcmFrameSize * sizeof( int16_t ) );
@@ -1646,8 +1650,8 @@ static ivas_error initOnFirstGoodFrame(
            }
        }
        else
#endif
        {
#endif
            if ( *pRemainingDelayNumSamples < numOutSamples )
            {
                if ( ( error = AudioFileWriter_write( *ppAfWriter, zeroBuf, numOutSamples * *pNumOutChannels - ( *pRemainingDelayNumSamples * *pNumOutChannels ) ) ) != IVAS_ERR_OK )
@@ -1661,7 +1665,9 @@ static ivas_error initOnFirstGoodFrame(
            {
                *pRemainingDelayNumSamples -= numOutSamples;
            }
#ifdef SPLIT_REND_WITH_HEAD_ROT
        }
#endif
    }

    free( zeroBuf );
@@ -1906,6 +1912,7 @@ static ivas_error decodeG192(
        if ( arg.enableHeadRotation )
        {
            IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES];

#ifdef SPLIT_REND_WITH_HEAD_ROT
            if ( headRotReader == NULL )
            {
@@ -1918,8 +1925,8 @@ static ivas_error decodeG192(
                }
            }
            else
#endif
            {
#endif
                for ( i = 0; i < IVAS_MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
                {
                    if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i], &Pos[i] ) ) != IVAS_ERR_OK )
@@ -1929,7 +1936,9 @@ static ivas_error decodeG192(
                        goto cleanup;
                    }
                }
#ifdef SPLIT_REND_WITH_HEAD_ROT
            }
#endif

            if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions, Pos
#ifdef SPLIT_REND_WITH_HEAD_ROT
@@ -2037,9 +2046,7 @@ static ivas_error decodeG192(
                }
            }
            else
#endif
            {
#ifdef SPLIT_REND_WITH_HEAD_ROT
                if ( ( hSplitRendFileReadWrite != NULL ) && ( arg.outputFormat == IVAS_DEC_OUTPUT_SPLIT_BINAURAL_PCM ) )
                {
                    if ( split_rend_write_bitstream_to_file( hSplitRendFileReadWrite, splitRendBits.bits_buf, &splitRendBits.bits_read, &splitRendBits.bits_written,
@@ -2063,7 +2070,9 @@ static ivas_error decodeG192(
                {
                    delayNumSamples -= nOutSamples;
                }
#ifdef SPLIT_REND_WITH_HEAD_ROT
            }
#endif
        }

        /* Write ISM metadata to external file(s) */
@@ -2138,14 +2147,18 @@ static ivas_error decodeG192(

    memset( pcmBuf, 0, delayNumSamples_orig[0] * nOutChannels * sizeof( int16_t ) );

#ifdef SPLIT_REND_WITH_HEAD_ROT
    if ( afWriter != NULL )
    {
#endif
        if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig[0] * nOutChannels ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nError writing output file: %s\n", ivas_error_to_string( error ) );
            goto cleanup;
        }
#ifdef SPLIT_REND_WITH_HEAD_ROT
    }
#endif

    /*------------------------------------------------------------------------------------------*
     * Printouts after decoding has finished
@@ -2192,10 +2205,12 @@ cleanup:
        split_rend_reader_writer_close( &hSplitRendFileReadWrite );
    }
    if ( afWriter != NULL )
#endif
    {
#endif
        AudioFileWriter_close( &afWriter );
#ifdef SPLIT_REND_WITH_HEAD_ROT
    }
#endif
    MasaFileWriter_close( &masaWriter );
    for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; i++ )
    {
+60 −56
Original line number Diff line number Diff line
@@ -932,24 +932,30 @@ int main(
        audioReader = NULL;
    }
    else
#endif
    {
#endif
        if ( AudioFileReader_open( &audioReader, audioFilePath ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "Error opening file: %s\n", audioFilePath );
            exit( -1 );
        }
#ifdef SPLIT_REND_WITH_HEAD_ROT
    }
#endif

    int32_t inFileSampleRate = 0;
#ifdef SPLIT_REND_WITH_HEAD_ROT
    if ( audioReader != NULL )
    {
#endif
        error = AudioFileReader_getSamplingRate( audioReader, &inFileSampleRate );
#ifdef SPLIT_REND_WITH_HEAD_ROT
    }
    else
    {
        inFileSampleRate = args.sampleRate;
    }
#endif
    switch ( error )
    {
        case IVAS_ERR_OK:
@@ -978,23 +984,20 @@ int main(
    }

    int16_t inFileNumChannels = 0;
#ifdef SPLIT_REND_WITH_HEAD_ROT
    if ( audioReader != NULL )
    {
#endif
        error = AudioFileReader_getNumChannels( audioReader, &inFileNumChannels );
        if ( error != IVAS_ERR_OK && error != IVAS_ERR_NUM_CHANNELS_UNKNOWN )
        {
            fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
            exit( -1 );
        }
    }
    const int16_t frameSize_smpls = (int16_t) ( 20 * args.sampleRate / 1000 );

#ifndef SPLIT_REND_WITH_HEAD_ROT
#ifdef SPLIT_REND_WITH_HEAD_ROT
    const int16_t CLDFBframeSize_smpls = (int16_t) frameSize_smpls * 2;
    cldfb_in = get_cldfb_in_flag( &args );
#endif
    }
#endif
    const int16_t frameSize_smpls = (int16_t) ( 20 * args.sampleRate / 1000 );

    IVAS_REND_InputId mcIds[RENDERER_MAX_MC_INPUTS] = { 0 };
    IVAS_REND_InputId ismIds[RENDERER_MAX_ISM_INPUTS] = { 0 };
@@ -1044,7 +1047,11 @@ int main(

        if ( ( error = IVAS_REND_GetRenderConfig( hIvasRend, &renderConfig ) ) != IVAS_ERR_OK )
        {
#ifdef SPLIT_REND_WITH_HEAD_ROT
            fprintf( stderr, "\nIVAS_DEC_GetRenderConfig failed: %s\n", ivas_error_to_string( error ) );
#else
            fprintf( stderr, "\nIVAS_DEC_GetRenderConfig failed\n" );
#endif
            exit( -1 );
        }

@@ -1061,7 +1068,11 @@ int main(

        if ( ( error = IVAS_REND_FeedRenderConfig( hIvasRend, renderConfig ) ) != IVAS_ERR_OK )
        {
#ifdef SPLIT_REND_WITH_HEAD_ROT
            fprintf( stderr, "\nIVAS_REND_FeedRenderConfig failed: %s\n", ivas_error_to_string( error ) );
#else
            fprintf( stderr, "\nIVAS_DEC_FeedRenderConfig failed\n" );
#endif
            exit( -1 );
        }
#ifdef SPLIT_REND_WITH_HEAD_ROT
@@ -1296,9 +1307,7 @@ int main(
    {
        rend_openCldfb( cldfbAna, cldfbSyn, totalNumInChannels, numOutChannels, args.sampleRate );
    }
#endif

#ifdef SPLIT_REND_WITH_HEAD_ROT
    if ( args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_SPLIT_CODED )
    {
        IVAS_REND_GetDelay( hIvasRend, &delayNumSamples_temp, &delayTimeScale_temp );
@@ -1331,20 +1340,8 @@ int main(
#ifdef SPLIT_REND_WITH_HEAD_ROT
    }
#endif

    inBufferSize = frameSize_smpls * totalNumInChannels;
    outBufferSize = frameSize_smpls * numOutChannels;
#ifdef SPLIT_REND_WITH_HEAD_ROT
    if ( is_split_pre_rend_mode( &args ) || is_split_post_rend_mode( &args ) )
    {
        bitsBufferSize = SPLIT_REND_BITS_BUFF_SIZE;
    }
    else
    {
        bitsBufferSize = 0;
    }
#endif

    inpInt16Buffer = malloc( inBufferSize * sizeof( int16_t ) );
#ifdef SPLIT_REND_WITH_HEAD_ROT
    if ( cldfb_in == 0 )
@@ -1361,29 +1358,27 @@ int main(
        outFloatBuffer = malloc( CLDFBframeSize_smpls * totalNumInChannels * sizeof( float ) );
        outBuffer.config.numSamplesPerChannel = (int16_t) CLDFBframeSize_smpls;
    }
#else
    inBuffer.config.numSamplesPerChannel = (int16_t) frameSize_smpls;
    inFloatBuffer = malloc( inBufferSize * sizeof( float ) );
    outFloatBuffer = malloc( outBufferSize * sizeof( float ) );
    outBuffer.config.numSamplesPerChannel = (int16_t) frameSize_smpls;
#endif
    outInt16Buffer = malloc( outBufferSize * sizeof( int16_t ) );

#ifdef SPLIT_REND_WITH_HEAD_ROT
    inBuffer.config.is_cldfb = cldfb_in;
#endif
    inBuffer.config.numChannels = (int16_t) totalNumInChannels;
    inBuffer.data = inFloatBuffer;

#ifdef SPLIT_REND_WITH_HEAD_ROT
    outBuffer.config.is_cldfb = cldfb_in;
#endif
    outBuffer.config.numChannels = (int16_t) numOutChannels;
    outBuffer.data = outFloatBuffer;

    memset( outBuffer.data, 0, outBuffer.config.numSamplesPerChannel * outBuffer.config.numChannels * sizeof( float ) );

    if ( is_split_pre_rend_mode( &args ) || is_split_post_rend_mode( &args ) )
    {
        bitsBufferSize = SPLIT_REND_BITS_BUFF_SIZE;
    }
    else
    {
        bitsBufferSize = 0;
    }

#ifdef SPLIT_REND_WITH_HEAD_ROT
    if ( bitsBufferSize > 0 )
    {
        bitsBufferData = malloc( bitsBufferSize * sizeof( uint8_t ) );
@@ -1393,12 +1388,22 @@ int main(
        bitsBufferData = NULL;
    }

#endif
#ifdef SPLIT_REND_WITH_HEAD_ROT
    bitsBuffer.bits = bitsBufferData;
    bitsBuffer.config.bitsRead = 0;
    bitsBuffer.config.bitsWritten = 0;
    bitsBuffer.config.bufLenInBytes = bitsBufferSize;
#else
    inFloatBuffer = malloc( inBufferSize * sizeof( float ) );
    outInt16Buffer = malloc( outBufferSize * sizeof( int16_t ) );
    outFloatBuffer = malloc( outBufferSize * sizeof( float ) );

    inBuffer.config.numSamplesPerChannel = (int16_t) frameSize_smpls;
    inBuffer.config.numChannels = (int16_t) totalNumInChannels;
    inBuffer.data = inFloatBuffer;

    outBuffer.config.numSamplesPerChannel = (int16_t) frameSize_smpls;
    outBuffer.config.numChannels = (int16_t) numOutChannels;
    outBuffer.data = outFloatBuffer;
#endif

#ifdef WMOPS
@@ -1443,15 +1448,17 @@ int main(
            }
        }
        if ( audioReader != NULL )
#endif
        {
#endif
            /* Read the input data */
            if ( ( error = AudioFileReader_read( audioReader, inpInt16Buffer, (int16_t) inBufferSize, &numSamplesRead ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nError reading from file %s\n", audioFilePath );
                exit( -1 );
            }
#ifdef SPLIT_REND_WITH_HEAD_ROT
        }
#endif

        if ( numSamplesRead == 0 )
        {
@@ -1534,7 +1541,6 @@ int main(
#endif
            );
            if ( error != IVAS_ERR_OK && error != IVAS_ERR_INVALID_OUTPUT_FORMAT )

            {
                fprintf( stderr, "Error setting Head Rotation: %s\n", ivas_error_to_string( error ) );
                exit( -1 );
@@ -1706,7 +1712,11 @@ int main(
#endif
                                             ) ) != IVAS_ERR_OK )
        {
#ifdef SPLIT_REND_WITH_HEAD_ROT
            fprintf( stderr, "Error %s\n", ivas_error_to_string( error ) );
#else
            fprintf( stderr, "Error in getting samples\n" );
#endif
            exit( -1 );
        }

@@ -1764,8 +1774,8 @@ int main(
            }
        }
        if ( audioWriter != NULL )
#endif
        {
#endif
            if ( delayNumSamples < outBufferSize )
            {
                if ( AudioFileWriter_write( audioWriter, &outInt16Buffer[delayNumSamples * num_out_channels], outBufferSize - ( delayNumSamples * num_out_channels ) ) != IVAS_ERR_OK )
@@ -1779,8 +1789,8 @@ int main(
            {
                delayNumSamples -= (int16_t) outBufferSize;
            }
        }
#ifdef SPLIT_REND_WITH_HEAD_ROT
        }
        bitsBuffer.config.bitsRead = 0;
        bitsBuffer.config.bitsWritten = 0;
#endif
@@ -1875,15 +1885,17 @@ int main(
    /* add zeros at the end to have equal length of synthesized signals */
#ifdef SPLIT_REND_WITH_HEAD_ROT
    if ( audioWriter != NULL )
#endif
    {
#endif
        memset( outInt16Buffer, 0, zeroPad * outBuffer.config.numChannels * sizeof( int16_t ) );
        if ( ( error = AudioFileWriter_write( audioWriter, outInt16Buffer, zeroPad * outBuffer.config.numChannels ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nOutput audio file writer error\n" );
            exit( -1 );
        }
#ifdef SPLIT_REND_WITH_HEAD_ROT
    }
#endif

    if ( !args.quietModeEnabled && args.delayCompensationEnabled )
    {
@@ -1925,25 +1937,13 @@ int main(
    {
        rend_closeCldfb( cldfbAna, cldfbSyn );
    }
#endif

#ifdef SPLIT_REND_WITH_HEAD_ROT
    if ( audioReader != NULL )
#endif
    {
        AudioFileReader_close( &audioReader );
    }

#ifdef SPLIT_REND_WITH_HEAD_ROT
    if ( hSplitRendFileReadWrite != NULL )
    {
        split_rend_reader_writer_close( &hSplitRendFileReadWrite );
    }
    if ( audioWriter != NULL )
#endif
    {
        AudioFileWriter_close( &audioWriter );
    }

    for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i )
    {
        LfeRoutingConfig_close( lfeRoutingConfigs[i] );
@@ -2021,6 +2021,7 @@ static bool parseInConfig(
#ifdef SPLIT_REND_WITH_HEAD_ROT
    inConfig->numBinBuses = 0;
#endif

    /* First check if input is being set to scene description file - this is not covered by parseAudioConfig(). */
    strncpy( charBuf, inFormatStr, sizeof( charBuf ) - 1 );
    charBuf[sizeof( charBuf ) - 1] = '\0';
@@ -2401,7 +2402,6 @@ static bool checkRequiredArgs(
                                      args.inConfig.numMultiChannelBuses != 0 ||
                                      args.inConfig.numMasaBuses != 0;
#endif

    if ( !args.sceneDescriptionInput && !singleInputSpecified )
    {
        /* Neither scene description input nor single-type input was specified on command line */
@@ -3649,8 +3649,8 @@ static void convertInputBuffer(
        }
    }
    else
#endif
    {
#endif
        for ( smpl = 0; smpl < numFloatSamplesPerChannel; ++smpl )
        {
            for ( chnl = 0; chnl < numChannels; ++chnl )
@@ -3667,7 +3667,9 @@ static void convertInputBuffer(
                ++i;
            }
        }
#ifdef SPLIT_REND_WITH_HEAD_ROT
    }
#endif

    return;
}
@@ -3742,8 +3744,8 @@ static void convertOutputBuffer(
        }
    }
    else
#endif
    {
#endif
        for ( smpl = 0; smpl < numSamplesPerChannel; ++smpl )
        {
            for ( chnl = 0; chnl < numChannels; ++chnl )
@@ -3763,7 +3765,9 @@ static void convertOutputBuffer(
                ++i;
            }
        }
#ifdef SPLIT_REND_WITH_HEAD_ROT
    }
#endif

    return;
}
+2 −4
Original line number Diff line number Diff line
@@ -100,9 +100,7 @@ typedef enum
    YAW_ROLL,
    PITCH_ROLL
} IVAS_SPLIT_REND_ROT_AXIS;
#endif

#ifdef SPLIT_REND_WITH_HEAD_ROT
typedef enum
{
    IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE,
@@ -149,7 +147,7 @@ typedef struct ivas_hrtfs_crend_structure *IVAS_DEC_HRTF_CREND_HANDLE;
typedef struct ivas_hrtfs_fastconv_struct *IVAS_DEC_HRTF_FASTCONV_HANDLE;
typedef struct ivas_hrtfs_parambin_struct *IVAS_DEC_HRTF_PARAMBIN_HANDLE;

#if ( defined DEBUGGING ) || ( defined SPLIT_REND_WITH_HEAD_ROT )
#ifdef DEBUGGING
typedef enum
{
    IVAS_RENDER_TYPE_OVERRIDE_NONE,
@@ -200,7 +198,7 @@ typedef struct _IVAS_SPLIT_REND_CONFIG

typedef struct _IVAS_RENDER_CONFIG
{
#if ( defined DEBUGGING ) || ( defined SPLIT_REND_WITH_HEAD_ROT )
#ifdef DEBUGGING
    IVAS_RENDER_TYPE_OVERRIDE renderer_type_override;
#endif
    IVAS_ROOM_ACOUSTICS_CONFIG_DATA room_acoustics;
+3 −1
Original line number Diff line number Diff line
@@ -104,14 +104,16 @@ int32_t get_delay(

#ifdef SPLIT_REND_WITH_HEAD_ROT
            if ( output_config != AUDIO_CONFIG_BINAURAL_SPLIT_CODED )
#endif
            {
#endif
                if ( hCldfb != NULL )
                {
                    /* compensate for filterbank delay */
                    delay += IVAS_FB_DEC_DELAY_NS;
                }
#ifdef SPLIT_REND_WITH_HEAD_ROT
            }
#endif

            if ( ivas_format == MASA_FORMAT )
            {
+2 −1
Original line number Diff line number Diff line
@@ -117,7 +117,7 @@ typedef enum

} AUDIO_CONFIG;

#if ( defined DEBUGGING ) || ( defined SPLIT_REND_WITH_HEAD_ROT )
#ifdef DEBUGGING
typedef enum
{
    RENDER_TYPE_OVERRIDE_NONE,
@@ -1804,6 +1804,7 @@ typedef enum
#define SPLIT_REND_ADDITIONAL_BYTES_TO_READ ( 1 )

#endif

/*----------------------------------------------------------------------------------*
 * Limiter constants
 *----------------------------------------------------------------------------------*/
Loading