Commit 7b61675a authored by Marek Szczerba's avatar Marek Szczerba
Browse files

Support for output of main orientation, tracked rotation, and combined...

Support for output of main orientation, tracked rotation, and combined orientation vectors using command line
parent 4f136fa6
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@
    <ClCompile Include="..\lib_util\cmdl_tools.c" />
    <ClCompile Include="..\lib_util\evs_rtp_payload.c" />
    <ClCompile Include="..\lib_util\g192.c" />
    <ClCompile Include="..\lib_util\rotation_file_writer.c" />
    <ClCompile Include="..\lib_util\vector3_pair_file_reader.c" />
    <ClCompile Include="..\lib_util\hrtf_file_reader.c" />
    <ClCompile Include="..\lib_util\ism_file_reader.c" />
@@ -134,6 +135,7 @@
    <ClInclude Include="..\lib_util\cmdl_tools.h" />
    <ClInclude Include="..\lib_util\evs_rtp_payload.h" />
    <ClInclude Include="..\lib_util\g192.h" />
    <ClInclude Include="..\lib_util\rotation_file_writer.h" />
    <ClInclude Include="..\lib_util\vector3_pair_file_reader.h" />
    <ClInclude Include="..\lib_util\hrtf_file_reader.h" />
    <ClInclude Include="..\lib_util\ism_file_reader.h" />
+134 −0
Original line number Diff line number Diff line
@@ -45,6 +45,9 @@
#include "masa_file_writer.h"
#include "render_config_reader.h"
#include "rotation_file_reader.h"
#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
#include "rotation_file_writer.h"
#endif
#ifdef SPLIT_REND_WITH_HEAD_ROT
#include "split_render_file_read_write.h"
#include "split_rend_bfi_file_reader.h"
@@ -178,6 +181,11 @@ typedef struct
    int8_t orientation_tracking;
    int16_t nonDiegeticPan;
    float nonDiegeticPanGain;
#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
    char mainOrientationOutputFilePath[RENDERER_MAX_CLI_ARG_LENGTH];
    char trackedOrientationOutputFilePath[RENDERER_MAX_CLI_ARG_LENGTH];
    char combinedOrientationOutputFilePath[RENDERER_MAX_CLI_ARG_LENGTH];
#endif
    IVAS_REND_COMPLEXITY_LEVEL complexityLevel;
    bool delayCompensationEnabled;
    bool quietModeEnabled;
@@ -226,6 +234,11 @@ typedef enum
#endif
    CmdLnOptionId_referenceVectorFile,
    CmdLnOptionId_exteriorOrientationFile,
#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
    CmdLnOptionId_mainOrientationOutputFile,
    CmdLnOptionId_trackedRotationOutputFile,
    CmdLnOptionId_combinedOrientationOutputFile,
#endif
    CmdLnOptionId_framing,
    CmdLnOptionId_syncMdDelay,
    CmdLnOptionId_directivityPatternId,
@@ -377,6 +390,26 @@ static const CmdLnParser_Option cliOptions[] = {
        .matchShort = "exof",
        .description = "External orientation trajectory file for simulation of external orientations",
    },
#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
    {
        .id = CmdLnOptionId_mainOrientationOutputFile,
        .match = "main_orientation_output_file",
        .matchShort = "moof",
        .description = "Main orientation output file",
    },
    {
        .id = CmdLnOptionId_trackedRotationOutputFile,
        .match = "tracked_rotation_output_file",
        .matchShort = "trof",
        .description = "Tracked rotation output file",
    },
    {
        .id = CmdLnOptionId_combinedOrientationOutputFile,
        .match = "combined_orientation_output_file",
        .matchShort = "coof",
        .description = "Combined orientation output file",
    },
#endif
    {
        .id = CmdLnOptionId_framing,
        .match = "framing",
@@ -687,6 +720,11 @@ int main(
    RotFileReader *headRotReader = NULL;
    RotFileReader *externalOrientationFileReader = NULL;
    RotFileReader *referenceRotReader = NULL;
#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
    RotFileWriter *mainOrientationFileWriter = NULL;
    RotFileWriter *trackedRotationFileWriter = NULL;
    RotFileWriter *combinedOrientationFileWriter = NULL;
#endif
#ifdef SPLIT_REND_WITH_HEAD_ROT
    IVAS_CLDFB_FILTER_BANK_HANDLE cldfbAna[IVAS_MAX_INPUT_CHANNELS];
    IVAS_CLDFB_FILTER_BANK_HANDLE cldfbSyn[IVAS_MAX_INPUT_CHANNELS];
@@ -836,6 +874,37 @@ int main(
        }
    }

#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
    if ( !isEmptyString( args.mainOrientationOutputFilePath ) )
    {
        convert_backslash( args.mainOrientationOutputFilePath );
        if ( RotationFileWriter_open( args.mainOrientationOutputFilePath, &mainOrientationFileWriter ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "Error opening file: %s\n", args.mainOrientationOutputFilePath );
            exit( -1 );
        }
    }

    if ( !isEmptyString( args.trackedOrientationOutputFilePath ) )
    {
        convert_backslash( args.trackedOrientationOutputFilePath );
        if ( RotationFileWriter_open( args.trackedOrientationOutputFilePath, &trackedRotationFileWriter ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "Error opening file: %s\n", args.trackedOrientationOutputFilePath );
            exit( -1 );
        }
    }

    if ( !isEmptyString( args.combinedOrientationOutputFilePath ) )
    {
        convert_backslash( args.combinedOrientationOutputFilePath );
        if ( RotationFileWriter_open( args.combinedOrientationOutputFilePath, &combinedOrientationFileWriter ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "Error opening file: %s\n", args.combinedOrientationOutputFilePath );
            exit( -1 );
        }
    }
#endif

    if ( !isEmptyString( args.renderConfigFilePath ) )
    {
@@ -1659,6 +1728,65 @@ int main(
            }
        }

#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
        if ( mainOrientationFileWriter != NULL )
        {
            for ( sf_idx = 0; sf_idx < num_subframes; sf_idx++ )
            {
                IVAS_QUATERNION mainOrientation;

                if ( ( error = IVAS_REND_GetMainOrientation( hIvasRend, &mainOrientation ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error while getting main orientation: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }
                if ( ( error = RotationFileWriter_write( mainOrientationFileWriter, &mainOrientation ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error while writing main orientation data: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }
            }
        }

        if ( trackedRotationFileWriter != NULL )
        {
            for ( sf_idx = 0; sf_idx < num_subframes; sf_idx++ )
            {
                IVAS_QUATERNION trackedRotation;

                if ( ( error = IVAS_REND_GetTrackedRotation( hIvasRend, &trackedRotation ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error while getting main orientation: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }
                if ( ( error = RotationFileWriter_write( trackedRotationFileWriter, &trackedRotation ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error while writing main orientation data: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }
            }
        }

        if ( combinedOrientationFileWriter != NULL )
        {
            for ( sf_idx = 0; sf_idx < num_subframes; sf_idx++ )
            {
                IVAS_QUATERNION combinedOrientation;

                if ( ( error = IVAS_REND_GetCombinedOrientation( hIvasRend, &combinedOrientation ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error while getting main orientation: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }
                if ( ( error = RotationFileWriter_write( combinedOrientationFileWriter, &combinedOrientation ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error while writing main orientation data: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }
            }
        }
#endif

        /* Combine external orientations and head rotation */

        if ( ( error = IVAS_REND_CombineHeadAndExternalOrientation( hIvasRend ) ) != IVAS_ERR_OK )
@@ -2062,9 +2190,15 @@ cleanup:
    MasaFileWriter_close( &masaWriter );
    AudioFileReader_close( &audioReader );
    AudioFileWriter_close( &audioWriter );

    RotationFileReader_close( &headRotReader );
    RotationFileReader_close( &externalOrientationFileReader );
    RotationFileReader_close( &referenceRotReader );
#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
    RotationFileWriter_close( &mainOrientationFileWriter );
    RotationFileWriter_close( &trackedRotationFileWriter );
    RotationFileWriter_close( &combinedOrientationFileWriter );
#endif

    Vector3PairFileReader_close( &referenceVectorReader );
    destroy_td_hrtf( hHrtfTD );
+1 −1
Original line number Diff line number Diff line
@@ -159,7 +159,7 @@
#define FIX_NUM_SUBFRAME_UPDATE

#define FIX_1053_REVERB_RECONFIGURATION                 /* Philips: issue 1053: fix for dynamic switching of acoustic environment */

#define FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS           /* Philips: issue 1066: orientation output functions support */

/* #################### End BE switches ################################## */

+6 −0
Original line number Diff line number Diff line
@@ -4803,7 +4803,9 @@ ivas_error IVAS_REND_SetReferenceRotation(
 *
 *
 *-------------------------------------------------------------------*/
#ifndef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
// ToDo: not used
#endif
ivas_error IVAS_REND_GetMainOrientation(
    IVAS_REND_HANDLE hIvasRend,   /* i/o: Renderer handle                           */
    IVAS_QUATERNION *pOrientation /* i/o: Quaternion pointer for main orientation   */
@@ -4830,7 +4832,9 @@ ivas_error IVAS_REND_GetMainOrientation(
 *
 *
 *-------------------------------------------------------------------*/
#ifndef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
// ToDo: not used
#endif
ivas_error IVAS_REND_GetTrackedRotation(
    IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle                             */
    IVAS_QUATERNION *pRotation  /* i/o: Quaternion pointer processed rotation       */
@@ -4938,7 +4942,9 @@ ivas_error IVAS_REND_CombineHeadAndExternalOrientation(
 *
 *
 *---------------------------------------------------------------------*/
#ifndef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
// ToDo: not used
#endif
ivas_error IVAS_REND_GetCombinedOrientation(
    IVAS_REND_HANDLE hIvasRend,   /* i/o: Renderer handle                                */
    IVAS_QUATERNION *pOrientation /* i/o: Quaternion pointer processed orientation       */
+136 −0
Original line number Diff line number Diff line
/******************************************************************************************************

   (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
   contributors to this repository. All Rights Reserved.

   This software is protected by copyright law and by international treaties.
   The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
   contributors to this repository retain full ownership rights in their respective contributions in
   the software. This notice grants no license of any kind, including but not limited to patent
   license, nor is any license granted by implication, estoppel or otherwise.

   Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
   contributions.

   This software is provided "AS IS", without any express or implied warranties. The software is in the
   development stage. It is intended exclusively for experts who have experience with such software and
   solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
   and fitness for a particular purpose are hereby disclaimed and excluded.

   Any dispute, controversy or claim arising under or in relation to providing this software shall be
   submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
   accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
   the United Nations Convention on Contracts on the International Sales of Goods.

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

#include "rotation_file_writer.h"
#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS

#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "prot.h"


struct RotFileWriter
{
    FILE *pFile;
    char *filename;
};


/*-----------------------------------------------------------------------*
 * RotationFileWriter_open()
 *
 * Allocate and initialize rotation file writer
 *-----------------------------------------------------------------------*/

ivas_error RotationFileWriter_open(
    char *filename,         /* i  : output file name */
    RotFileWriter **pWriter /* o  : RotFileWriter handle          */
)
{
    RotFileWriter *self;
    FILE *pFile;

    /* Open trajectory file */
    if ( strlen( filename ) < 1 )
    {
        return IVAS_ERR_FAILED_FILE_OPEN;
    }

    pFile = fopen( filename, "wt" );

    if ( !pFile )
    {
        return IVAS_ERR_FAILED_FILE_OPEN;
    }

    self = calloc( sizeof( RotFileWriter ), 1 );
    self->pFile = pFile;
    self->filename = calloc( sizeof( char ), strlen( filename ) + 1 );
    strcpy( self->filename, filename );

    *pWriter = self;

    return IVAS_ERR_OK;
}


/*-----------------------------------------------------------------------*
 * RotationFileWriter_write()
 *
 * Reads values to the trajectory file
 *-----------------------------------------------------------------------*/

ivas_error RotationFileWriter_write(
    RotFileWriter *pWriter,
    IVAS_QUATERNION *pPose )
{
    int32_t bytes_written;

    if ( pWriter == NULL || pPose == NULL )
    {
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }

    if ( ( bytes_written = fprintf( pWriter->pFile, "%f,%f,%f,%f\n", pPose->w, pPose->x, pPose->y, pPose->z ) ) <= 0 )
    {
        return IVAS_ERR_FAILED_FILE_WRITE;
    }

    return IVAS_ERR_OK;
}


/*-----------------------------------------------------------------------*
 * RotationFileWriter_close()
 *
 * Closes and deallocates the rotation file writer
 *-----------------------------------------------------------------------*/

void RotationFileWriter_close(
    RotFileWriter **pWriter /* i/o: RotFileWriter handle       */
)
{
    if ( pWriter == NULL || *pWriter == NULL )
    {
        return;
    }

    fclose( ( *pWriter )->pFile );
    free( ( *pWriter )->filename );
    free( *pWriter );
    *pWriter = NULL;

    return;
}

#endif
Loading