Commit dd88b91f authored by Lauros Pajunen's avatar Lauros Pajunen
Browse files

Implementation of contribution 41, orientation information handling

parent bacb1e53
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -144,6 +144,7 @@
    <ClCompile Include="..\lib_util\cmdln_parser.c" />
    <ClCompile Include="..\lib_util\cmdl_tools.c" />
    <ClCompile Include="..\lib_util\evs_rtp_payload.c" />
    <ClCompile Include="..\lib_util\external_orientation_file_reader.c" />
    <ClCompile Include="..\lib_util\g192.c" />
    <ClCompile Include="..\lib_util\head_rotation_file_reader.c" />
    <ClCompile Include="..\lib_util\vector3_pair_file_reader.c" />
@@ -167,6 +168,7 @@
    <ClInclude Include="..\lib_util\cmdln_parser.h" />
    <ClInclude Include="..\lib_util\cmdl_tools.h" />
    <ClInclude Include="..\lib_util\evs_rtp_payload.h" />
    <ClInclude Include="..\lib_util\external_orientation_file_reader.h" />
    <ClInclude Include="..\lib_util\g192.h" />
    <ClInclude Include="..\lib_util\vector3_pair_file_reader.h" />
    <ClInclude Include="..\lib_util\head_rotation_file_reader.h" />
+112 −0
Original line number Diff line number Diff line
@@ -42,6 +42,9 @@
#include "ls_custom_file_reader.h"
#include "hrtf_file_reader.h"
#include "head_rotation_file_reader.h"
#ifdef EXTERNAL_ORIENTATIONS
#include "external_orientation_file_reader.h"
#endif
#ifdef OTR_REFERENCE_VECTOR_TRACKING
#include "vector3_pair_file_reader.h"
#endif /* OTR_REFERENCE_VECTOR_TRACKING */
@@ -105,6 +108,10 @@ typedef struct
    bool enableReferenceVectorTracking;
    char *referenceVectorTrajFileName;
#endif /* OTR_REFERENCE_VECTOR_TRACKING */
#ifdef EXTERNAL_ORIENTATIONS
    bool enableExternalOrientation;
    char *externalOrientationTrajFileName;
#endif
#ifdef SUPPORT_JBM_TRACEFILE
    char *jbmTraceFilename;
#endif
@@ -142,13 +149,25 @@ static bool parseCmdlIVAS_dec( int16_t argc, char **argv, DecArguments *arg );
static void usage_dec( void );
#ifdef FIX_I109_ORIENTATION_TRACKING
#ifdef OTR_REFERENCE_VECTOR_TRACKING
#ifdef EXTERNAL_ORIENTATIONS
static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, HeadRotFileReader *headRotReader, HeadRotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ExternalOrientationFileReader *externalOrientationFileReader, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf );
#else
static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, HeadRotFileReader *headRotReader, HeadRotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf );
#endif
#else /* OTR_REFERENCE_VECTOR_TRACKING */
#ifdef EXTERNAL_ORIENTATIONS
static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, HeadRotFileReader *headRotReader, HeadRotFileReader *refRotReader, ExternalOrientationFileReader *externalOrientationFileReader, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf );
#else
static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, HeadRotFileReader *headRotReader, HeadRotFileReader *refRotReader, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf );
#endif
#endif
#else /* FIX_I109_ORIENTATION_TRACKING */
#ifdef EXTERNAL_ORIENTATIONS
static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, HeadRotFileReader *headRotReader, ExternalOrientationFileReader *externalOrientationFileReader, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf );
#else
static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, HeadRotFileReader *headRotReader, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf );
#endif
#endif
static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HANDLE hIvasDec );
#ifdef DEBUGGING
static ivas_error printBitstreamInfoVoip( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HANDLE hIvasDec );
@@ -180,6 +199,9 @@ int main(
#ifdef OTR_REFERENCE_VECTOR_TRACKING
    Vector3PairFileReader *referenceVectorReader = NULL;
#endif /* OTR_REFERENCE_VECTOR_TRACKING */
#ifdef EXTERNAL_ORIENTATIONS
    ExternalOrientationFileReader *externalOrientationFileReader = NULL;
#endif
    ivas_error error = IVAS_ERR_UNKNOWN;
    int16_t pcmBuf[MAX_OUTPUT_PCM_BUFFER_SIZE];
    RenderConfigReader *renderConfigReader = NULL;
@@ -316,6 +338,21 @@ int main(
    }
#endif /* OTR_REFERENCE_VECTOR_TRACKING */

#ifdef EXTERNAL_ORIENTATIONS
    /*------------------------------------------------------------------------------------------*
     * Open external orientation file
     *------------------------------------------------------------------------------------------*/

    if ( arg.enableExternalOrientation )
    {
        if ( ( error = ExternalOrientationFileReader_open( arg.externalOrientationTrajFileName, &externalOrientationFileReader ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nError: Can't open external orientation file %s \n\n", arg.externalOrientationTrajFileName );
            goto cleanup;
        }
    }
#endif

    /*------------------------------------------------------------------------------------------*
     * Open custom loudspeaker layout file
     *------------------------------------------------------------------------------------------*/
@@ -353,7 +390,11 @@ int main(
     * Configure the decoder
     *------------------------------------------------------------------------------------------*/

#ifdef EXTERNAL_ORIENTATIONS
    if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputFormat, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation, arg.enableExternalOrientation, arg.renderConfigEnabled ) ) != IVAS_ERR_OK )
#else
    if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputFormat, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation, arg.renderConfigEnabled ) ) != IVAS_ERR_OK )
#endif
    {
        fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
        goto cleanup;
@@ -574,12 +615,24 @@ int main(
    {
#ifdef FIX_I109_ORIENTATION_TRACKING
#ifdef OTR_REFERENCE_VECTOR_TRACKING
#ifdef EXTERNAL_ORIENTATIONS
        error = decodeG192( arg, hBsReader, headRotReader, refRotReader, referenceVectorReader, externalOrientationFileReader, hIvasDec, pcmBuf );
#else
        error = decodeG192( arg, hBsReader, headRotReader, refRotReader, referenceVectorReader, hIvasDec, pcmBuf );
#endif
#else
#ifdef EXTERNAL_ORIENTATIONS
        error = decodeG192( arg, hBsReader, headRotReader, refRotReader, externalOrientationFileReader, hIvasDec, pcmBuf );
#else
        error = decodeG192( arg, hBsReader, headRotReader, refRotReader, hIvasDec, pcmBuf );
#endif
#endif /* OTR_REFERENCE_VECTOR_TRACKING */
#else
#ifdef EXTERNAL_ORIENTATIONS
        error = decodeG192( arg, hBsReader, headRotReader, externalOrientationFileReader, hIvasDec, pcmBuf );
#else
        error = decodeG192( arg, hBsReader, headRotReader, hIvasDec, pcmBuf );
#endif
#endif
    }

@@ -642,6 +695,9 @@ cleanup:
#ifdef OTR_REFERENCE_VECTOR_TRACKING
    Vector3PairFileReader_close( &referenceVectorReader );
#endif /* OTR_REFERENCE_VECTOR_TRACKING */
#ifdef EXTERNAL_ORIENTATIONS
    ExternalOrientationFileReader_close( &externalOrientationFileReader );
#endif
    RenderConfigReader_close( &renderConfigReader );

    if ( BS_Reader_Close( &hBsReader ) != IVAS_ERR_OK )
@@ -789,6 +845,10 @@ static bool parseCmdlIVAS_dec(
#else
    arg->orientation_tracking = IVAS_PUBLIC_ORIENT_TRK_REF;
#endif
#ifdef EXTERNAL_ORIENTATIONS
    arg->enableExternalOrientation = false;
    arg->externalOrientationTrajFileName = NULL;
#endif

#ifdef SUPPORT_JBM_TRACEFILE
    arg->jbmTraceFilename = NULL;
@@ -1043,6 +1103,23 @@ static bool parseCmdlIVAS_dec(
            i++;
        }
#endif /* OTR_REFERENCE_VECTOR_TRACKING */
#ifdef EXTERNAL_ORIENTATIONS
        else if ( strcmp( argv_to_upper, "-EXOF" ) == 0 )
        {
            arg->enableExternalOrientation = true;
            i++;

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

            arg->externalOrientationTrajFileName = argv[i];
            i++;
        }
#endif
        else if ( strcmp( argv_to_upper, "-RENDER_CONFIG" ) == 0 )
        {
            arg->renderConfigEnabled = true;
@@ -1251,6 +1328,9 @@ static void usage_dec( void )
    fprintf( stdout, "                      left or l or 1->left, right or r or -1->right, center or c or  0->middle\n" );
    fprintf( stdout, "-q                  : Quiet mode, no frame counter\n" );
    fprintf( stdout, "                      default is deactivated\n" );
#ifdef EXTERNAL_ORIENTATIONS
    fprintf( stdout, "-exof File          : External orientation file for external orientation trajectory\n" );
#endif
#ifdef DEBUG_MODE_INFO
#ifdef DEBUG_MODE_INFO_TWEAK
    fprintf( stdout, "-info <folder>      : specify subfolder name for debug output\n" );
@@ -1484,6 +1564,9 @@ static ivas_error decodeG192(
#ifdef OTR_REFERENCE_VECTOR_TRACKING
    Vector3PairFileReader *referenceVectorReader,
#endif /* OTR_REFERENCE_VECTOR_TRACKING */
#endif
#ifdef EXTERNAL_ORIENTATIONS
    ExternalOrientationFileReader *externalOrientationFileReader,
#endif
    IVAS_DEC_HANDLE hIvasDec,
    int16_t *pcmBuf )
@@ -1664,6 +1747,35 @@ static ivas_error decodeG192(
                goto cleanup;
            }
        }

#ifdef EXTERNAL_ORIENTATIONS
        if ( arg.enableExternalOrientation )
        {
            IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES];
            int8_t enableHeadRotation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES];
            int8_t enableExternalOrientation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES];
            int8_t enableRotationInterpolation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES];
            int16_t numFramesToTargetOrientation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES];

            for ( i = 0; i < IVAS_MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
            {

                if ( ( error = ExternalOrientationFileReading( externalOrientationFileReader, &Quaternions[i], &enableHeadRotation[i], &enableExternalOrientation[i], &enableRotationInterpolation[i], &numFramesToTargetOrientation[i] ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nError %s while reading external orientation from %s\n", IVAS_DEC_GetErrorMessage( error ),
                             ExternalOrientationFileReader_getFilePath( externalOrientationFileReader ) );
                    goto cleanup;
                }
            }

            if ( ( error = IVAS_DEC_FeedExternalOrientationData( hIvasDec, Quaternions, enableHeadRotation, enableExternalOrientation, enableRotationInterpolation, numFramesToTargetOrientation ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nIVAS_DEC_FeedExternalOrientationData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) );
                goto cleanup;
            }
        }
#endif

        /* Run decoder for one frame (get rendered output) */
        if ( ( error = IVAS_DEC_GetSamples( hIvasDec, pcmBuf, &nOutSamples ) ) != IVAS_ERR_OK )
        {
+81 −0
Original line number Diff line number Diff line
@@ -45,6 +45,9 @@
#ifdef OTR_REFERENCE_VECTOR_TRACKING
#include "vector3_pair_file_reader.h"
#endif /* OTR_REFERENCE_VECTOR_TRACKING */
#ifdef EXTERNAL_ORIENTATIONS
#include "external_orientation_file_reader.h"
#endif
#include "hrtf_file_reader.h"
#include "ism_file_reader.h"
#include "ls_custom_file_reader.h"
@@ -138,6 +141,9 @@ typedef struct
    char referenceVectorFilePath[RENDERER_MAX_CLI_ARG_LENGTH];
#endif /* OTR_REFERENCE_VECTOR_TRACKING */
    char referenceRotationFilePath[RENDERER_MAX_CLI_ARG_LENGTH];
#endif
#ifdef EXTERNAL_ORIENTATIONS
    char externalOrientationFilePath[RENDERER_MAX_CLI_ARG_LENGTH];
#endif
    char customHrtfFilePath[RENDERER_MAX_CLI_ARG_LENGTH];
    char renderConfigFilePath[RENDERER_MAX_CLI_ARG_LENGTH];
@@ -178,6 +184,9 @@ typedef enum
#ifdef OTR_REFERENCE_VECTOR_TRACKING
    CmdLnOptionId_referenceVectorFile,
#endif /* OTR_REFERENCE_VECTOR_TRACKING */
#ifdef EXTERNAL_ORIENTATIONS
    CmdLnOptionId_exteriorOrientationFile,
#endif
} CmdLnOptionId;

static const CmdLnParser_Option cliOptions[] = {
@@ -303,6 +312,14 @@ static const CmdLnParser_Option cliOptions[] = {
        .description = "Reference vector trajectory file for simulation of head tracking (only for BINAURAL and BINAURAL_ROOM outputs)",
    },
#endif /* OTR_REFERENCE_VECTOR_TRACKING */
#ifdef EXTERNAL_ORIENTATIONS
    {
        .id = CmdLnOptionId_exteriorOrientationFile,
        .match = "exterior_orientation_file",
        .matchShort = "exof",
        .description = "External orientation trajectory file for simulation of external orientations",
    },
#endif
};


@@ -534,6 +551,9 @@ int main(
    Vector3PairFileReader *referenceVectorReader = NULL;
#endif /* OTR_REFERENCE_VECTOR_TRACKING */
    HeadRotFileReader *referenceRotReader = NULL;
#endif
#ifdef EXTERNAL_ORIENTATIONS
    ExternalOrientationFileReader *externalOrientationFileReader = NULL;
#endif
    hrtfFileReader *hrtfFileReader = NULL;
    IsmPositionProvider *positionProvider;
@@ -592,6 +612,9 @@ int main(
    convert_backslash( args.referenceVectorFilePath );
#endif /* OTR_REFERENCE_VECTOR_TRACKING */
    convert_backslash( args.referenceRotationFilePath );
#endif
#ifdef EXTERNAL_ORIENTATIONS
    convert_backslash( args.externalOrientationFilePath );
#endif
    convert_backslash( args.inLfePanningMatrixFile );

@@ -625,6 +648,17 @@ int main(
#endif /* OTR_REFERENCE_VECTOR_TRACKING */
#endif

#ifdef EXTERNAL_ORIENTATIONS
    if ( !isEmptyString( args.externalOrientationFilePath ) )
    {
        if ( ExternalOrientationFileReader_open( args.externalOrientationFilePath, &externalOrientationFileReader ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "Error opening file: %s\n", args.externalOrientationFilePath );
            exit( -1 );
        }
    }
#endif

    if ( !isEmptyString( args.customHrtfFilePath ) )
    {
        if ( hrtfFileReader_open( args.customHrtfFilePath, &hrtfFileReader ) != IVAS_ERR_OK )
@@ -1053,6 +1087,41 @@ int main(
            }
        }

#ifdef EXTERNAL_ORIENTATIONS
        /* Read from external orientation file if specified */
        if ( externalOrientationFileReader != NULL )
        {
            IVAS_QUATERNION quatBuffer[RENDERER_HEAD_POSITIONS_PER_FRAME];
            int8_t enableHeadRotation[RENDERER_HEAD_POSITIONS_PER_FRAME];
            int8_t enableExternalOrientation[RENDERER_HEAD_POSITIONS_PER_FRAME];
            int8_t enableRotationInterpolation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES];
            int16_t numFramesToTargetOrientation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES];

            for ( i = 0; i < RENDERER_HEAD_POSITIONS_PER_FRAME; i++ )
            {
                if ( ( error = ExternalOrientationFileReading( externalOrientationFileReader, &quatBuffer[i], &enableHeadRotation[i], &enableExternalOrientation[i], &enableRotationInterpolation[i], &numFramesToTargetOrientation[i] ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error in External Orientation File Reading: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }
            }

            if ( ( error = IVAS_REND_SetExternalOrientation( hIvasRend, quatBuffer, enableHeadRotation, enableExternalOrientation, enableRotationInterpolation, numFramesToTargetOrientation ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "Error setting External Orientation: %s\n", ivas_error_to_string( error ) );
                exit( -1 );
            }
        }

        /* Combine external orientations and head rotation */

        if ( ( error = IVAS_REND_CombineHeadAndExternalOrientation( hIvasRend ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "Error combining external and head orientations: %s\n", ivas_error_to_string( error ) );
            exit( -1 );
        }
#endif

        for ( i = 0; i < args.inConfig.numMultiChannelBuses; ++i )
        {
            if ( ( error = IVAS_REND_GetInputNumChannels( hIvasRend, mcIds[i], &numChannels ) ) != IVAS_ERR_OK )
@@ -1231,6 +1300,9 @@ int main(
    Vector3PairFileReader_close( &referenceVectorReader );
#endif /* OTR_REFERENCE_VECTOR_TRACKING */
    HeadRotationFileReader_close( &referenceRotReader );
#endif
#ifdef EXTERNAL_ORIENTATIONS
    ExternalOrientationFileReader_close( &externalOrientationFileReader );
#endif
    hrtfFileReader_close( &hrtfFileReader );
    IVAS_REND_Close( &hIvasRend );
@@ -1707,6 +1779,9 @@ static CmdlnArgs defaultArgs(
    clearString( args.referenceVectorFilePath );
#endif /* OTR_REFERENCE_VECTOR_TRACKING */
    clearString( args.referenceRotationFilePath );
#endif
#ifdef EXTERNAL_ORIENTATIONS
    clearString( args.externalOrientationFilePath );
#endif
    clearString( args.customHrtfFilePath );
    clearString( args.renderConfigFilePath );
@@ -1801,6 +1876,12 @@ static void parseOption(
            assert( numOptionValues == 1 );
            strncpy( args->referenceRotationFilePath, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 );
            break;
#endif
#ifdef EXTERNAL_ORIENTATIONS
        case CmdLnOptionId_exteriorOrientationFile:
            assert( numOptionValues == 1 );
            strncpy( args->externalOrientationFilePath, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 );
            break;
#endif
        case CmdLnOptionId_customHrtfFile:
            assert( numOptionValues == 1 );
+3 −0
Original line number Diff line number Diff line
@@ -76,6 +76,9 @@ typedef enum
    IVAS_ERR_WRONG_MODE,
    IVAS_ERR_INVALID_OUTPUT_FORMAT,
    IVAS_ERR_HEAD_ROTATION_NOT_SUPPORTED,
#ifdef EXTERNAL_ORIENTATIONS
    IVAS_ERR_EXT_ORIENTATION_NOT_SUPPORTED,
#endif
    IVAS_ERR_INVALID_HRTF,
    IVAS_ERR_INVALID_INPUT_FORMAT,
    IVAS_ERR_INVALID_INDEX,
+4 −0
Original line number Diff line number Diff line
@@ -4589,6 +4589,10 @@ void ivas_binaural_cldfb(
void ivas_binRenderer(
    BINAURAL_RENDERER_HANDLE hBinRenderer,                      /* i/o: fastconv binaural renderer handle                       */
    HEAD_TRACK_DATA_HANDLE hHeadTrackData,                      /* i/o: head track handle                                       */
#ifdef EXTERNAL_ORIENTATIONS
    COMBINED_ORIENTATION_HANDLE hCombinedOrientationData,       /* i  : combined head and external orientation handle           */
    int16_t subframe_idx,                                                                  /* i  : subframe index               */
#endif
    float Cldfb_RealBuffer_Binaural[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o  : Binaural signals             */
    float Cldfb_ImagBuffer_Binaural[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o  : Binaural signals             */
    float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],                /* i  : LS signals                   */
Loading