Commit bcd757f6 authored by sbsarac's avatar sbsarac
Browse files

Make aeid file reader module

parent b84e2b26
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@
    </Lib>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClCompile Include="..\lib_util\aeid_file_reader.c" />
    <ClCompile Include="..\lib_util\audio_file_reader.c" />
    <ClCompile Include="..\lib_util\audio_file_writer.c" />
    <ClCompile Include="..\lib_util\bitstream_reader.c" />
@@ -126,6 +127,7 @@
    <ClCompile Include="..\lib_util\tsm_scale_file_reader.c" />
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="..\lib_util\aeid_file_reader.h" />
    <ClInclude Include="..\lib_util\audio_file_reader.h" />
    <ClInclude Include="..\lib_util\audio_file_writer.h" />
    <ClInclude Include="..\lib_util\bitstream_reader.h" />
+9 −56
Original line number Diff line number Diff line
@@ -43,6 +43,9 @@
#include "masa_file_writer.h"
#include "render_config_reader.h"
#include "rotation_file_reader.h"
#ifdef FIX_1053_REVERB_RECONFIGURATION
#include "aeid_file_reader.h"
#endif
#ifdef SPLIT_REND_WITH_HEAD_ROT
#include "split_render_file_read_write.h"
#endif
@@ -1530,75 +1533,25 @@ static bool parseCmdlIVAS_dec(
            if ( !is_digits_only( argv[i] ) )
            {
#ifdef FIX_1053_REVERB_RECONFIGURATION
                FILE *aeidFile = NULL;
                int32_t id;
                int32_t duration;
                uint16_t k = 0;

                /* Open aeid file */
                if ( strlen( argv[i] ) < 1 )
                {
                    return IVAS_ERR_FAILED_FILE_OPEN;
                }

                aeidFile = fopen( argv[i], "r" );

                if ( !aeidFile )
                {
                    return IVAS_ERR_FAILED_FILE_OPEN;
                }

                while ( !feof( aeidFile ) )
                {
                    if ( fscanf( aeidFile, "%d:%d", &id, &duration ) == 2 )
                    {
                        k++;
                    }
                    else
                    {
                        fprintf( stdout, "Error while parsing acoustic environment sequence: %s\n\n", argv[i] );
                        usage_dec();
                        return false;
                    }
                }
                aeidFileReader *aeidReader = NULL;

                if ( k == 0 )
                if ( aeidFileReader_open( argv[i], &aeidReader ) != IVAS_ERR_OK )
                {
                    fprintf( stdout, "Error: No acoustic environment: %s\n\n", argv[i] );
                    fprintf( stderr, "\nError: Can't open aeid file %s \n", argv[i] );
                    usage_dec();
                    return false;
                }

                if ( NULL == ( arg->aeSequence.pID = malloc( sizeof( uint16_t ) * k ) ) ||
                     NULL == ( arg->aeSequence.pValidity = malloc( sizeof( uint16_t ) * k ) ) )
                if ( aeidFileReading( aeidReader, &arg->aeSequence.count, &arg->aeSequence.pID, &arg->aeSequence.pValidity ) != IVAS_ERR_OK )
                {
                    fprintf( stdout, "Error: Unable to allocate memory for acoustic environment sequence: %s\n\n", argv[i] );
                    fprintf( stderr, "\nError while reading aeid from %s\n", argv[i] );
                    usage_dec();
                    return false;
                }

                arg->aeSequence.count = k;
                k = 0;

                fseek( aeidFile, 0, SEEK_SET );
                aeidFileReader_close( &aeidReader );

                while ( !feof( aeidFile ) )
                {
                    if ( fscanf( aeidFile, "%d:%d", &id, &duration ) == 2 )
                    {
                        arg->aeSequence.pID[k] = (uint16_t) id;
                        arg->aeSequence.pValidity[k] = (uint16_t) duration;
                        k++;
                    }
                    else
                    {
                        fprintf( stdout, "Error while parsing acoustic environment sequence: %s\n\n", argv[i] );
                        usage_dec();
                        return false;
                    }
                }
                i++;
                fclose( aeidFile );
#else
                fprintf( stdout, "Error: Invalid acoustic environment ID specified: %s\n\n", argv[i] );
                usage_dec();
+187 −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 "aeid_file_reader.h"
#ifdef FIX_1053_REVERB_RECONFIGURATION
#include "ivas_error_utils.h"
#include <stdlib.h>
#include <string.h>

struct aeidFileReader
{
    FILE *aeidFile;
    char *file_path;
};


/*-----------------------------------------------------------------------*
 * aeidFileReader_open()
 *
 * Allocate and initialize rotation handle
 *-----------------------------------------------------------------------*/

ivas_error aeidFileReader_open(
    char *aeidFilePath,         /* i  : aeid file name      */
    aeidFileReader **aeidReader /* o  : aeidFileReader handle               */
)
{
    aeidFileReader *self;
    FILE *aeidFile;

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

    aeidFile = fopen( aeidFilePath, "r" );

    if ( !aeidFile )
    {
        return IVAS_ERR_FAILED_FILE_OPEN;
    }

    self = calloc( sizeof( aeidFileReader ), 1 );
    self->aeidFile = aeidFile;
    self->file_path = calloc( sizeof( char ), strlen( aeidFilePath ) + 1 );
    strcpy( self->file_path, aeidFilePath );

    *aeidReader = self;

    return IVAS_ERR_OK;
}


/*-----------------------------------------------------------------------*
 * aeidFileReading()
 *
 * Read values from the aeid file
 *-----------------------------------------------------------------------*/

ivas_error aeidFileReading(
    aeidFileReader *aeidReader, /* i  : aeidFileReader handle           */
    uint16_t *count,            /* o  : number of sequences             */
    uint16_t **pID,             /* o  : acoustic environment ID data    */
    uint16_t **pValidity        /* o  : duration data                   */
)
{
    int32_t id;
    int32_t duration;
    uint16_t k = 0;

    while ( !feof( aeidReader->aeidFile ) )
    {
        if ( fscanf( aeidReader->aeidFile, "%d:%d", &id, &duration ) == 2 )
        {
            k++;
        }
        else
        {
            return IVAS_ERROR( IVAS_ERR_FAILED_FILE_PARSE, "Error while parsing acoustic environment sequence" );
        }
    }

    if ( k == 0 )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_FILE_PARSE, "No acoustic environment" );
    }

    if ( NULL == ( *pID = malloc( sizeof( uint16_t ) * k ) ) ||
         NULL == ( *pValidity = malloc( sizeof( uint16_t ) * k ) ) )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Unable to allocate memory for acoustic environment sequence" );
    }

    *count = k;

    k = 0;

    fseek( aeidReader->aeidFile, 0, SEEK_SET );

    while ( !feof( aeidReader->aeidFile ) )
    {
        if ( fscanf( aeidReader->aeidFile, "%d:%d", &id, &duration ) == 2 )
        {
            ( *pID )[k] = (uint16_t) id;
            ( *pValidity )[k] = (uint16_t) duration;
            k++;
        }
        else
        {
            return IVAS_ERROR( IVAS_ERR_FAILED_FILE_PARSE, "Error while parsing acoustic environment sequence" );
        }
    }

    return IVAS_ERR_OK;
}

/*-----------------------------------------------------------------------*
 * aeidFileReader_close()
 *
 * Deallocates memory for the aeid handle
 *-----------------------------------------------------------------------*/

void aeidFileReader_close(
    aeidFileReader **aeidReader /* i/o: aeidFileReader handle           */
)
{
    if ( aeidReader == NULL || *aeidReader == NULL )
    {
        return;
    }

    fclose( ( *aeidReader )->aeidFile );
    free( ( *aeidReader )->file_path );
    free( *aeidReader );
    *aeidReader = NULL;

    return;
}

/*-----------------------------------------------------------------------*
 * aeidFileReader_getFilePath()
 *
 *
 *-----------------------------------------------------------------------*/

const char *aeidFileReader_getFilePath(
    aeidFileReader *aeidReader /* i  : aeidFileReader handle           */
)
{
    if ( aeidReader == NULL )
    {
        return NULL;
    }

    return aeidReader->file_path;
}
#endif
+89 −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.

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

#ifndef IVAS_AEID_FILE_READER_H
#define IVAS_AEID_FILE_READER_H

#include "common_api_types.h"

#ifdef FIX_1053_REVERB_RECONFIGURATION

struct aeidFileReader;
typedef struct aeidFileReader aeidFileReader;

/*-----------------------------------------------------------------------*
 * aeidFileReader_open()
 *
 * Allocate and initialize rotation handle
 *-----------------------------------------------------------------------*/

ivas_error aeidFileReader_open(
    char *aeidFilePath,                /* i  : aeid file name      */
    struct aeidFileReader **aeidReader /* o  : aeidFileReader handle               */
);

/*-----------------------------------------------------------------------*
 * aeidFileReading()
 *
 * Read values from the aeid file
 *-----------------------------------------------------------------------*/

ivas_error aeidFileReading(
    aeidFileReader *aeidReader, /* i  : aeidFileReader handle           */
    uint16_t *count,            /* o  : number of sequences             */
    uint16_t **pID,             /* o  : acoustic environment ID data    */
    uint16_t **pValidity        /* o  : duration data                   */
);

/*-----------------------------------------------------------------------*
 * aeidFileReader_close()
 *
 * Deallocates memory for the aeid handle
 *-----------------------------------------------------------------------*/

void aeidFileReader_close(
    aeidFileReader **aeidReader /* i/o: aeidFileReader handle           */
);

/*-----------------------------------------------------------------------*
 * aeidFileReader_getFilePath()
 *
 *
 *-----------------------------------------------------------------------*/

const char *aeidFileReader_getFilePath(
    aeidFileReader *aeidReader /* i  : aeidFileReader handle           */
);

#endif

#endif /* IVAS_AEID_FILE_READER_H */