Commit 67f5b676 authored by stoutjesdijk's avatar stoutjesdijk 🎧
Browse files

writers integrated in decode_variable_speed

parent c933aab9
Loading
Loading
Loading
Loading
+130 −3
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@

*******************************************************************************************************/

#include "rom_com.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -59,6 +60,9 @@
#include "split_render_file_read_write.h"
#endif
#include "hrtf_file_reader.h"
#ifdef FIX_319_ADD_OTR_EXPORT
#include "head_rotation_file_writer.h"
#endif


#define WMC_TOOL_SKIP
@@ -111,6 +115,12 @@ typedef struct
    char *headrotTrajFileName;
    bool enableReferenceRotation;
    char *refrotTrajFileName;
#ifdef FIX_319_ADD_OTR_EXPORT
    bool enableMainOrientationOutput;
    char *mainOrientationFilePath;
    bool enableTrackedRotationOutput;
    char *trkRotationFilePath;
#endif
    bool enableReferenceVectorTracking;
    char *referenceVectorTrajFileName;
    bool enableExternalOrientation;
@@ -176,8 +186,13 @@ static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, RotF
static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HANDLE hIvasDec );
#ifdef DEBUGGING
#ifdef VARIABLE_SPEED_DECODING
static ivas_error decodeVariableSpeed( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec );
#endif
static ivas_error decodeVariableSpeed( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader,
#ifdef FIX_319_ADD_OTR_EXPORT
    HeadRotFileWriter *mainOrientFileWriter,
    HeadRotFileWriter *trkRotFileWriter,
#endif /* FIX_319_ADD_OTR_EXPORT */
Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec );
#endif /* VARIABLE_SPEED_DECODING */
static ivas_error printBitstreamInfoVoip( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HANDLE hIvasDec );
static int16_t app_own_random( int16_t *seed );
static IVAS_DEC_FORCED_REND_MODE parseForcedRendModeDec( char *forcedRendModeChar );
@@ -204,6 +219,10 @@ int main(
    RotFileReader *externalOrientationFileReader = NULL;
    RotFileReader *refRotReader = NULL;
    Vector3PairFileReader *referenceVectorReader = NULL;
#ifdef FIX_319_ADD_OTR_EXPORT
    HeadRotFileWriter *trkRotWriter = NULL;
    HeadRotFileWriter *mainOrientWriter = NULL;
#endif
    ivas_error error = IVAS_ERR_UNKNOWN;
    int16_t pcmBuf[MAX_OUTPUT_PCM_BUFFER_SIZE];
#ifdef SPLIT_REND_WITH_HEAD_ROT
@@ -387,6 +406,28 @@ int main(
        }
    }

#ifdef FIX_319_ADD_OTR_EXPORT
    /*------------------------------------------------------------------------------------------*
     * Open tracking/orientation output files
     *------------------------------------------------------------------------------------------*/
    if ( arg.enableMainOrientationOutput )
    {
        if ( ( error = HeadRotationFileWriter_open( arg.mainOrientationFilePath, &mainOrientWriter ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nError: Can't open main orientation output file %s \n\n", arg.mainOrientationFilePath );
            goto cleanup;
        }
    }
    if ( arg.enableTrackedRotationOutput )
    {
        if ( ( error = HeadRotationFileWriter_open( arg.trkRotationFilePath, &trkRotWriter ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nError: Can't open tracked rotation output file %s \n\n", arg.trkRotationFilePath );
            goto cleanup;
        }
    }
#endif

    /*------------------------------------------------------------------------------------------*
     * Open custom loudspeaker layout file
     *------------------------------------------------------------------------------------------*/
@@ -691,7 +732,12 @@ int main(
    {
        error = decodeVariableSpeed( arg, hBsReader, headRotReader,
                                     externalOrientationFileReader,
                                     refRotReader, referenceVectorReader, hIvasDec );
                                     refRotReader,
#ifdef FIX_319_ADD_OTR_EXPORT
                                     mainOrientWriter,
                                     trkRotWriter,
#endif /* FIX_319_ADD_OTR_EXPORT */
                                     referenceVectorReader, hIvasDec );
    }
#endif
    else
@@ -760,6 +806,10 @@ cleanup:
    RotationFileReader_close( &headRotReader );
    RotationFileReader_close( &externalOrientationFileReader );
    RotationFileReader_close( &refRotReader );
#ifdef FIX_319_ADD_OTR_EXPORT
    HeadRotationFileWriter_close( &mainOrientWriter );
    HeadRotationFileWriter_close( &trkRotWriter );
#endif
    Vector3PairFileReader_close( &referenceVectorReader );
    RenderConfigReader_close( &renderConfigReader );

@@ -915,6 +965,12 @@ static bool parseCmdlIVAS_dec(
    arg->orientation_tracking = IVAS_PUBLIC_ORIENT_TRK_NONE;
    arg->enableReferenceRotation = false;
    arg->headrotTrajFileName = NULL;
#ifdef FIX_319_ADD_OTR_EXPORT
    arg->enableMainOrientationOutput = false;
    arg->mainOrientationFilePath = NULL;
    arg->enableTrackedRotationOutput = false;
    arg->trkRotationFilePath = NULL;
#endif
    arg->enableReferenceVectorTracking = false;
    arg->referenceVectorTrajFileName = NULL;
    arg->enableExternalOrientation = false;
@@ -1168,6 +1224,38 @@ static bool parseCmdlIVAS_dec(
            arg->headrotTrajFileName = argv[i];
            i++;
        }
#ifdef FIX_319_ADD_OTR_EXPORT
        else if ( strcmp( argv_to_upper, "-MOO" ) == 0 )
        {
            arg->enableMainOrientationOutput = true;
            i++;

            if ( argc - i <= 4 || argv[i][0] == '-' )
            {
                fprintf( stderr, "Error: Main Orientation output file name not specified!\n\n" );
                usage_dec();
                return false;
            }

            arg->mainOrientationFilePath = argv[i];
            i++;
        }
        else if ( strcmp( argv_to_upper, "-TRO" ) == 0 )
        {
            arg->enableTrackedRotationOutput = true;
            i++;

            if ( argc - i <= 4 || argv[i][0] == '-' )
            {
                fprintf( stderr, "Error: Tracked rotation output file name not specified!\n\n" );
                usage_dec();
                return false;
            }

            arg->trkRotationFilePath = argv[i];
            i++;
        }
#endif
        else if ( strcmp( argv_to_upper, "-OTR" ) == 0 )
        {

@@ -1489,6 +1577,10 @@ static void usage_dec( void )
    fprintf( stdout, "                      works only in combination with '-otr ref' mode \n" );
    fprintf( stdout, "-rvf File           : Reference vector specified by external trajectory file\n" );
    fprintf( stdout, "                      works only in combination with '-otr ref_vec' and 'ref_vec_lev' modes\n" );
#ifdef FIX_319_ADD_OTR_EXPORT
    fprintf( stdout, "-moo File           : Main orientation output file\n" );
    fprintf( stdout, "-tro File           : Tracked rotation output file\n" );
#endif
    fprintf( stdout, "-render_config File : Renderer configuration File\n" );
#ifdef SPLIT_REND_WITH_HEAD_ROT
    fprintf( stdout, "-om File            : MD output file for BINAURAL_SPLIT_PCM output format\n" );
@@ -2780,6 +2872,10 @@ static ivas_error decodeVariableSpeed(
    RotFileReader *headRotReader,
    RotFileReader *externalOrientationFileReader,
    RotFileReader *refRotReader,
#ifdef FIX_319_ADD_OTR_EXPORT
    HeadRotFileWriter *mainOrientFileWriter,
    HeadRotFileWriter *trkRotFileWriter,
#endif
    Vector3PairFileReader *referenceVectorReader,
    IVAS_DEC_HANDLE hIvasDec )

@@ -2948,6 +3044,37 @@ static ivas_error decodeVariableSpeed(
            }
        }

#ifdef FIX_319_ADD_OTR_EXPORT
        if ( arg.enableMainOrientationOutput )
        {
            IVAS_QUATERNION quatBuffer[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES];
            IVAS_DEC_GetMainOrientation( hIvasDec, quatBuffer );

            for ( i = 0; i < IVAS_MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
            {
                if ( ( error = HeadRotationFileWriting( mainOrientFileWriter, quatBuffer ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error in Main Orientation File Writing: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }
            }
        }
        if ( arg.enableTrackedRotationOutput )
        {
            IVAS_QUATERNION quatBuffer[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES];
            IVAS_DEC_GetTrackedRotation( hIvasDec, quatBuffer );

            for ( i = 0; i < IVAS_MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
            {
                if ( ( error = HeadRotationFileWriting( trkRotFileWriter, quatBuffer ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error in Tracked Rotation File Writing: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }
            }
        }
#endif

        /* decode and get samples */
        do
        {
+1 −1
Original line number Diff line number Diff line
@@ -1676,7 +1676,7 @@ int main(
        if ( mainOrientWriter != NULL )
        {
            IVAS_QUATERNION quatBuffer[RENDERER_HEAD_POSITIONS_PER_FRAME];
            IVAS_REND_GetTrackedRotation( hIvasRend, quatBuffer );
            IVAS_REND_GetMainOrientation( hIvasRend, quatBuffer );

            for ( i = 0; i < RENDERER_HEAD_POSITIONS_PER_FRAME; i++ )
            {
+0 −1
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@
#ifdef DEBUGGING
#include "debug.h"
#endif
#include "stat_enc.h"
#include "stat_dec.h"
#include "stl.h"
#include "basop_util.h"
+57 −0
Original line number Diff line number Diff line
@@ -1318,6 +1318,63 @@ ivas_error IVAS_DEC_FeedExternalOrientationData(
    return IVAS_ERR_OK;
}

#ifdef FIX_319_ADD_OTR_EXPORT
/*-------------------------------------------------------------------*
 * IVAS_DEC_GetMainOrientation()
 *
 *
 *-------------------------------------------------------------------*/

ivas_error IVAS_DEC_GetMainOrientation(
    IVAS_DEC_HANDLE hIvasDec,   /* i/o: Renderer handle                           */
    IVAS_QUATERNION *pOrientation /* i/o: Quaternion pointer for main orientation   */
)
{
    ivas_error error;

    if ( hIvasDec == NULL || pOrientation == NULL )
    {
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }

    if ( ( error = ivas_orient_trk_GetMainOrientation( hIvasDec->st_ivas->hHeadTrackData->OrientationTracker, pOrientation ) ) != IVAS_ERR_OK )
    {
        return error;
    }

    return IVAS_ERR_OK;
}


/*-------------------------------------------------------------------*
 * IVAS_DEC_GetTrackedRotation()
 *
 *
 *-------------------------------------------------------------------*/

ivas_error IVAS_DEC_GetTrackedRotation(
    IVAS_DEC_HANDLE hIvasDec, /* i/o: Decoder handle                             */
    IVAS_QUATERNION *pRotation  /* i/o: Quaternion pointer processed rotation       */
)
{
    ivas_error error;

    if ( hIvasDec == NULL || pRotation == NULL )
    {
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }

    if ( ( error = ivas_orient_trk_GetTrackedRotation( hIvasDec->st_ivas->hHeadTrackData->OrientationTracker, pRotation ) ) != IVAS_ERR_OK )

    {
        return error;
    }

    return IVAS_ERR_OK;
}

#endif

/*---------------------------------------------------------------------*
 * IVAS_DEC_FeedCustomLsData( )
 *
+12 −0
Original line number Diff line number Diff line
@@ -235,6 +235,18 @@ ivas_error IVAS_DEC_FeedExternalOrientationData(
    int16_t *numFramesToTargetOrientation       /* i  : number of frames until target orientation is reached                    */
);

/*! r: error code */
ivas_error IVAS_DEC_GetMainOrientation(
    IVAS_DEC_HANDLE hIvasDec,                   /* i/o: Decoder handle                           */
    IVAS_QUATERNION *pOrientation               /* i/o: Quaternion pointer for main orientation   */
);

/*! r: error code */
ivas_error IVAS_DEC_GetTrackedRotation(
    IVAS_DEC_HANDLE hIvasDec,                   /* i/o: Decoder handle                             */
    IVAS_QUATERNION *pRotation                  /* i/o: Quaternion pointer processed rotation       */
);

/*! r: error code */
ivas_error IVAS_DEC_VoIP_FeedFrame(
    IVAS_DEC_HANDLE hIvasDec,                   /* i/o: IVAS decoder handle                                                     */