Commit 5d55224d authored by sbsarac's avatar sbsarac
Browse files

Merge branch '1053-reverb-reconfiguration-runtime-test' into 'main'

Reverb reconfiguration in runtime - Add file support and renderer test support

See merge request !1538
parents e99c5b4a 8955db31
Loading
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" />
+12 −51
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
@@ -1543,65 +1546,25 @@ static bool parseCmdlIVAS_dec(
            if ( !is_digits_only( argv[i] ) )
            {
#ifdef FIX_1053_REVERB_RECONFIGURATION
                uint16_t k;
                char *s = argv[i];
                char *token = argv[i];
                aeidFileReader *aeidReader = NULL;

                for ( k = 0; s[k]; )
                if ( aeidFileReader_open( argv[i], &aeidReader ) != IVAS_ERR_OK )
                {
                    s[k] == ',' ? k++ : *s++;
                }
                k++;

                if ( k == 0 )
                {
                    fprintf( stdout, "Error: Invalid acoustic environment sequence specified: %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;
                token = strtok( argv[i++], ":" );

                while ( token != NULL )
                {
                    if ( !is_number( token ) )
                    {
                        fprintf( stdout, "Error: Invalid token %s found in acoustic environment sequence: %s\n\n", token, argv[i] );
                        usage_dec();
                        return false;
                    }
                    arg->aeSequence.pID[k] = (uint16_t) atoi( token );
                aeidFileReader_close( &aeidReader );

                    token = strtok( NULL, "," );
                    if ( !is_number( token ) )
                    {
                        fprintf( stdout, "Error: Invalid token %s found in acoustic environment sequence: %s\n\n", token, argv[i] );
                        usage_dec();
                        return false;
                    }
                    arg->aeSequence.pValidity[k] = (uint16_t) atoi( token );

                    token = strtok( NULL, ":" );
                    k++;
                }

                if ( k != arg->aeSequence.count )
                {
                    fprintf( stdout, "Error while parsing acoustic environment sequence: %s\n\n", argv[i] );
                    usage_dec();
                    return false;
                }
                i++;
#else
                fprintf( stdout, "Error: Invalid acoustic environment ID specified: %s\n\n", argv[i] );
                usage_dec();
@@ -1872,10 +1835,8 @@ static void usage_dec( void )
    fprintf( stdout, "                      ISMs 1,2,3 and 4 respectively. This options needs to be accompanied by a render_config file,\n" );
    fprintf( stdout, "                      otherwise a default directivity pattern is used.\n" );
#ifdef FIX_1053_REVERB_RECONFIGURATION
    fprintf( stdout, "-aeid ID            : Acoustic environment ID (number > 0) or\n" );
    fprintf( stdout, "                      a sequence thereof in the format [ID1:duration1,ID2:duration2...]\n" );
    fprintf( stdout, "                      without braces and spaces, with ':' character separating ID from duration and ',' separating\n" );
    fprintf( stdout, "                      ID and duration pairs, where duration is specified in frames\n" );
    fprintf( stdout, "-aeid ID | File     : Acoustic environment ID (number > 0)\n" );
    fprintf( stdout, "                      alternatively, it can be a text file where each line contains \"ID duration\"\n" );
    fprintf( stdout, "                      for BINAURAL_ROOM_REVERB output configuration.\n" );
#else
    fprintf( stdout, "-aeid ID            : Acoustic environment ID (number >= 0) for BINAURAL_ROOM_REVERB output configuration\n" );
+16 −50
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_1053_REVERB_RECONFIGURATION
#include "aeid_file_reader.h"
#endif
#ifdef SPLIT_REND_WITH_HEAD_ROT
#include "split_render_file_read_write.h"
#include "split_rend_bfi_file_reader.h"
@@ -400,7 +403,7 @@ static const CmdLnParser_Option cliOptions[] = {
        .match = "acoustic_environment_id",
        .matchShort = "aeid",
#ifdef FIX_1053_REVERB_RECONFIGURATION
        .description = "Acoustic environment ID( number > 0 ) or a sequence thereof in the format [ID1:duration1,ID2:duration2...] without braces and spaces, with ':' character separating ID from duration and ',' separating ID and duration pairs, where duration is specified in frames for BINAURAL_ROOM_REVERB output configuration.",
        .description = "Acoustic environment ID (number > 0) alternatively, it can be a text file where each line contains \"ID duration\" for BINAURAL_ROOM_REVERB output configuration.",
#else
        .description = "Acoustic environment ID (number >= 0) for BINAURAL_ROOM_REVERB output configuration",
#endif
@@ -737,6 +740,7 @@ int main(
    int32_t delayTimeScale = 0;
    int16_t i, numChannels;
#ifdef FIX_1053_REVERB_RECONFIGURATION
    IVAS_RENDER_CONFIG_DATA renderConfig;
    uint16_t aeID;
#endif
    ivas_error error = IVAS_ERR_OK;
@@ -1051,7 +1055,9 @@ int main(

    if ( args.renderConfigFilePath[0] != '\0' )
    {
#ifndef FIX_1053_REVERB_RECONFIGURATION
        IVAS_RENDER_CONFIG_DATA renderConfig;
#endif

        /* sanity check */
#ifdef SPLIT_REND_WITH_HEAD_ROT
@@ -1563,8 +1569,10 @@ int main(
        {
            if ( ++args.aeSequence.frameCounter >= args.aeSequence.pValidity[args.aeSequence.selected] )
            {
#ifndef FIX_1053_REVERB_RECONFIGURATION
                IVAS_RENDER_CONFIG_DATA renderConfig;

#endif
                if ( ++args.aeSequence.selected >= args.aeSequence.count )
                {
                    args.aeSequence.selected = 0;
@@ -1574,7 +1582,7 @@ int main(
                {
                    if ( RenderConfigReader_checkValues( &renderConfig ) != IVAS_ERR_OK )
                    {
                        fprintf( stderr, "Invalid acoustic environment configuratoin parameters\n\n" );
                        fprintf( stderr, "Invalid acoustic environment configuration parameters\n\n" );
                        goto cleanup;
                    }
                }
@@ -2569,69 +2577,27 @@ static bool parseAcousticEnvironmentIds(
    const char *value,
    AcousticEnvironmentSequence *aeSequence )
{
    uint16_t k;
    char config_string[RENDERER_MAX_METADATA_LINE_LENGTH];
    char *s;
    char *token;

    strncpy( config_string, value, RENDERER_MAX_METADATA_LINE_LENGTH );
    s = config_string;
    token = config_string;

    if ( !is_digits_only( config_string ) )
    {
        aeidFileReader *aeidReader = NULL;

        for ( k = 0; s[k]; )
        {
            s[k] == ',' ? k++ : *s++;
        }
        k++;

        if ( k == 0 )
        if ( aeidFileReader_open( config_string, &aeidReader ) != IVAS_ERR_OK )
        {
            fprintf( stdout, "Error: Invalid acoustic environment sequence specified: %s\n\n", config_string );
            fprintf( stderr, "\nError: Can't open aeid file %s \n", config_string );
            return false;
        }

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

        aeSequence->count = k;

        k = 0;

        token = strtok( config_string, ":" );

        while ( token != NULL )
        {
            if ( !is_number( token ) )
            {
                fprintf( stdout, "Error: Invalid token %s found in acoustic environment sequence: %s\n\n", token, config_string );
                return false;
            }
            aeSequence->pID[k] = (uint16_t) atoi( token );

            token = strtok( NULL, "," );
            if ( !is_number( token ) )
            {
                fprintf( stdout, "Error: Invalid token %s found in acoustic environment sequence: %s\n\n", token, config_string );
                return false;
            }
            aeSequence->pValidity[k] = (uint16_t) atoi( token );

            token = strtok( NULL, ":" );
            k++;
        }

        if ( k != aeSequence->count )
        {
            fprintf( stdout, "Error while parsing acoustic environment sequence: %s\n\n", config_string );
            return false;
        }
        aeidFileReader_close( &aeidReader );
    }
    else
    {
+9 −5
Original line number Diff line number Diff line
@@ -4393,6 +4393,10 @@ int16_t IVAS_REND_GetRenderConfig(
    hRCout->roomAcoustics.use_er = hRCin->roomAcoustics.use_er;
    hRCout->roomAcoustics.lowComplexity = hRCin->roomAcoustics.lowComplexity;

#ifdef FIX_1053_REVERB_RECONFIGURATION
    mvr2r( hRCin->distAtt, hRCout->distAtt, 3 );
#endif

    return IVAS_ERR_OK;
}

@@ -4439,6 +4443,9 @@ int16_t IVAS_REND_FeedRenderConfig(
    mvr2r( renderConfig.roomAcoustics.pAcoustic_rt60, hRenderConfig->roomAcoustics.pAcoustic_rt60, CLDFB_NO_CHANNELS_MAX );
    mvr2r( renderConfig.roomAcoustics.pAcoustic_dsr, hRenderConfig->roomAcoustics.pAcoustic_dsr, CLDFB_NO_CHANNELS_MAX );
    mvr2r( renderConfig.directivity, hRenderConfig->directivity, 3 * MAX_NUM_OBJECTS );
#ifdef FIX_1053_REVERB_RECONFIGURATION
    mvr2r( renderConfig.distAtt, hRenderConfig->distAtt, 3 );
#endif

    hRenderConfig->roomAcoustics.use_er = 0;
    if ( renderConfig.roomAcoustics.use_er == 1 )
@@ -4468,16 +4475,13 @@ int16_t IVAS_REND_FeedRenderConfig(
                return error;
            }
        }

#ifdef SPLIT_REND_WITH_HEAD_ROT
        if ( pIsmInput->crendWrapper != NULL && pIsmInput->crendWrapper->hCrend[0] != NULL )
#else
        if ( pIsmInput->crendWrapper != NULL && pIsmInput->crendWrapper->hCrend != NULL )
#endif
        {
#ifdef SPLIT_REND_WITH_HEAD_ROT
            if ( ( error = ivas_reverb_open( &pIsmInput->crendWrapper->hCrend[0]->hReverb, hIvasRend->hHrtfs.hHrtfStatistics, hRenderConfig, *pIsmInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK )
#else
        if ( pIsmInput->crendWrapper != NULL && pIsmInput->crendWrapper->hCrend != NULL )
        {
            if ( ( error = ivas_reverb_open( &pIsmInput->crendWrapper->hCrend->hReverb, hIvasRend->hHrtfs.hHrtfStatistics, hRenderConfig, *pIsmInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK )
#endif
            {
+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
Loading