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

Merge remote-tracking branch 'origin/main' into...

Merge remote-tracking branch 'origin/main' into 350-masa-audio-and-meta-out-of-sync-in-decoder-when-delay-compensation-is-disabled
parents 604544d3 c4d690de
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ workflow:
    # see https://docs.gitlab.com/ee/ci/yaml/workflow.html#switch-between-branch-pipelines-and-merge-request-pipelines
    - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push"
      when: never
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event' # Runs for merge requests
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
    - if: $CI_PIPELINE_SOURCE == 'push' && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Pushes to main
    - if: $CI_PIPELINE_SOURCE == 'schedule' && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Scheduled in main
    - if: $CI_PIPELINE_SOURCE == 'web' # for testing
@@ -130,7 +130,7 @@ stages:
.rules-merge-request:
  extends: .rules-basis
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main" # only have MR pipelines for MRs to main
    - if: $CI_PIPELINE_SOURCE == 'push'
      when: never

+7 −9
Original line number Diff line number Diff line
@@ -112,45 +112,42 @@ project(stereo-evs)
set_property(GLOBAL PROPERTY USE_FOLDERS ON) # make Visual Studio projects look nicer
include(CTest)

include_directories(
  lib_com
  lib_debug
  lib_dec
  lib_enc
  lib_rend
  lib_util
)

file(GLOB libComSrcs "lib_com/*.c")
file(GLOB libComHeaders "lib_com/*.h")
add_library(lib_com ${libComSrcs} ${libComHeaders})
if(UNIX)
  target_link_libraries(lib_com m)
endif()
target_include_directories(lib_com PUBLIC lib_com PRIVATE lib_enc lib_dec lib_rend lib_debug)

file(GLOB libDebugSrcs "lib_debug/*.c")
file(GLOB libDebugHeaders "lib_debug/*.h")
add_library(lib_debug ${libDebugSrcs} ${libDebugHeaders})
target_link_libraries(lib_debug lib_com)
target_include_directories(lib_debug PUBLIC lib_debug PRIVATE lib_enc lib_dec lib_rend)

file(GLOB libEncSrcs "lib_enc/*.c")
file(GLOB libEncHeaders "lib_enc/*.h")
add_library(lib_enc ${libEncSrcs} ${libEncHeaders})
target_link_libraries(lib_enc lib_com lib_debug)
target_include_directories(lib_enc PUBLIC lib_enc PRIVATE lib_dec lib_rend)

file(GLOB libRendSrcs "lib_rend/*.c")
file(GLOB libRendHeaders "lib_rend/*.h")
add_library(lib_rend ${libRendSrcs} ${libRendHeaders})
target_link_libraries(lib_rend lib_dec lib_com lib_debug) # Todo refactor: This dependency on lib_dec should be removed.
target_include_directories(lib_rend PUBLIC lib_rend PRIVATE lib_enc)

file(GLOB libDecSrcs "lib_dec/*.c")
file(GLOB libDecHeaders "lib_dec/*.h")
add_library(lib_dec ${libDecSrcs} ${libDecHeaders})
target_link_libraries(lib_dec lib_com lib_rend lib_debug)
target_include_directories(lib_dec PUBLIC lib_dec lib_rend PRIVATE lib_enc)

file(GLOB libUtilSrcs "lib_util/*.c")
file(GLOB libUtilHeaders "lib_util/*.h")
add_library(lib_util ${libUtilSrcs} ${libUtilHeaders})
target_include_directories(lib_util PUBLIC lib_util PRIVATE lib_com lib_enc lib_dec lib_rend lib_debug)

add_executable(IVAS_cod apps/encoder.c)
target_link_libraries(IVAS_cod lib_enc lib_util)
@@ -166,6 +163,7 @@ endif()

add_executable(IVAS_rend apps/renderer.c)
target_link_libraries(IVAS_rend lib_rend lib_util)
target_include_directories(IVAS_rend PRIVATE lib_enc)

if(COPY_EXECUTABLES_FROM_BUILD_DIR)
  # Optionally copy executables to the same place where Make puts them (useful for tests that expect executables in specific places)
+131 −83
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "options.h"
#include "lib_dec.h"
#include "cmdl_tools.h"
#include "audio_file_writer.h"
@@ -105,7 +104,9 @@ typedef struct
    char *renderConfigFilename;

#ifdef DEBUGGING
#ifndef REMOVE_FORCE_SUBFRAME_BIN
    bool forceSubframeBinauralization;
#endif
    IVAS_DEC_FORCED_REND_MODE forcedRendMode;
#ifdef DEBUG_FOA_AGC
    FILE *agcBitstream; /* temporary */
@@ -221,8 +222,21 @@ int main(

    if ( arg.hrtfReaderEnabled )
    {
#ifdef FIX_351_HRTF_COMMAND
        /* sanity check */
        if ( arg.outputFormat != IVAS_DEC_OUTPUT_BINAURAL && arg.outputFormat != IVAS_DEC_OUTPUT_BINAURAL_ROOM )
        {
            arg.hrtfReaderEnabled = false;
            fprintf( stderr, "\nError: HRTF binary file cannot be used in this output configuration.\n\n" );
            goto cleanup;
        }
#endif

        if ( ( error = hrtfFileReader_open( arg.hrtfFileName, &hrtfReader ) ) != IVAS_ERR_OK )
        {
#ifdef FIX_351_HRTF_COMMAND
            arg.hrtfReaderEnabled = false;
#endif
            fprintf( stderr, "\nError: Can't open HRTF binary file %s \n\n", arg.hrtfFileName );
            goto cleanup;
        }
@@ -234,6 +248,15 @@ int main(

    if ( arg.enableHeadRotation )
    {
#ifdef FIX_351_HRTF_COMMAND
        /* sanity check */
        if ( arg.outputFormat != IVAS_DEC_OUTPUT_BINAURAL && arg.outputFormat != IVAS_DEC_OUTPUT_BINAURAL_ROOM )
        {
            fprintf( stderr, "\nError: Head-rotation file file cannot be used in this output configuration.\n\n" );
            goto cleanup;
        }
#endif

        if ( ( error = HeadRotationFileReader_open( arg.headrotTrajFileName, &headRotReader ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nError: Can't open head-rotation file %s \n\n", arg.headrotTrajFileName );
@@ -260,6 +283,15 @@ int main(

    if ( arg.renderConfigEnabled )
    {
#ifdef FIX_351_HRTF_COMMAND
        /* sanity check */
        if ( arg.outputFormat != IVAS_DEC_OUTPUT_BINAURAL && arg.outputFormat != IVAS_DEC_OUTPUT_BINAURAL_ROOM )
        {
            fprintf( stderr, "\nError: Renderer configuration file cannot be used in this output configuration.\n\n" );
            goto cleanup;
        }
#endif

        if ( ( error = RenderConfigReader_open( arg.renderConfigFilename, &renderConfigReader ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nError: Can't open Renderer configuration file %s \n\n", arg.renderConfigFilename );
@@ -271,10 +303,22 @@ int main(
     * Configure the decoder
     *------------------------------------------------------------------------------------------*/

#ifdef REMOVE_FORCE_SUBFRAME_BIN
    if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputFormat, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation, arg.renderConfigEnabled ) ) != IVAS_ERR_OK )
#else
#ifdef DEBUGGING
#ifdef FIX_351_HRTF_COMMAND
    if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputFormat, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation, arg.renderConfigEnabled, arg.forceSubframeBinauralization ) ) != IVAS_ERR_OK )
#else
    if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputFormat, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation, arg.forceSubframeBinauralization ) ) != IVAS_ERR_OK )
#endif
#else
#ifdef FIX_351_HRTF_COMMAND
    if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputFormat, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation, arg.renderConfigEnabled ) ) != IVAS_ERR_OK )
#else
    if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputFormat, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation ) ) != IVAS_ERR_OK )
#endif
#endif
#endif
    {
        fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
@@ -451,9 +495,7 @@ int main(
        if ( ( error = create_SetOfHRTF_from_binary( hSetOfHRTF, hrtfReader, arg.output_Fs ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nError in loading HRTF binary file %s for CRend \n\n", arg.hrtfCRendFileName );
#ifndef FIX_FOR_TEST
            goto cleanup;
#endif
        }
        IVAS_DEC_HRTF_FASTCONV_HANDLE hHrtfFastConv;
        IVAS_DEC_GetHrtfFastConvHandle( hIvasDec, &hHrtfFastConv );
@@ -530,16 +572,15 @@ cleanup:
#ifdef DEBUG_SBA_AUDIO_DUMP
    IVAS_DEC_GetSbaDebugParams( hIvasDec, &numOutChannels, &numTransportChannels, &pca_ingest_channels );
#endif

    if ( arg.hrtfReaderEnabled )
    {
        IVAS_DEC_HRTF_HANDLE hHrtfTD;
        IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtfTD );
        dealloc_HRTF_binary( hHrtfTD );
#ifdef FIX_MEMORY_COUNTING_HRTF_BINARY_FILE
        IVAS_DEC_HRTF_CREND_HANDLE hSetOfHRTF;
        IVAS_DEC_GetHrtfCRendHandle( hIvasDec, &hSetOfHRTF );
        destroy_SetOfHRTF( hSetOfHRTF );
#endif
    }
    IVAS_DEC_Close( &hIvasDec );
    CustomLsReader_close( &hLsCustomReader );
@@ -588,9 +629,7 @@ static IVAS_DEC_AUDIO_CONFIG cmdline2config(
    char argv_to_upper[FILENAME_MAX];

    strncpy( argv_to_upper, argv, sizeof( argv_to_upper ) - 1 );
#ifdef FIX_343_TO_UPPER
    argv_to_upper[sizeof( argv_to_upper ) - 1] = '\0';
#endif
    to_upper( argv_to_upper );

    if ( strcmp( argv_to_upper, "EXT" ) == 0 ) /* external renderer */
@@ -669,12 +708,11 @@ static bool parseCmdlIVAS_dec(
    char argv_to_upper[FILENAME_MAX];
#ifdef DEBUGGING
    float ftmp;
#ifndef FIX_343_TO_UPPER
    char stmp[FILENAME_MAX];
#endif

    arg->forcedRendMode = IVAS_DEC_FORCE_REND_UNFORCED;
#ifndef REMOVE_FORCE_SUBFRAME_BIN
    arg->forceSubframeBinauralization = false;
#endif
#ifdef DEBUG_FOA_AGC
    arg->agcBitstream = NULL;
#endif
@@ -733,9 +771,7 @@ static bool parseCmdlIVAS_dec(
    while ( argv[i][0] == '-' )
    {
        strncpy( argv_to_upper, argv[i], sizeof( argv_to_upper ) - 1 );
#ifdef FIX_343_TO_UPPER
        argv_to_upper[sizeof( argv_to_upper ) - 1] = '\0';
#endif
        to_upper( argv_to_upper );

        if ( strcmp( argv_to_upper, "-VOIP" ) == 0 )
@@ -743,21 +779,13 @@ static bool parseCmdlIVAS_dec(
            arg->voipMode = 1;
            i++;
        }
#ifdef FIX_343_TO_UPPER
        else if ( strcmp( argv_to_upper, "-VOIP_HF_ONLY=0" ) == 0 )
#else
        else if ( strcmp( to_upper( argv[i] ), "-VOIP_HF_ONLY=0" ) == 0 )
#endif
        {
            arg->voipMode = 1;
            arg->inputFormat = IVAS_DEC_INPUT_FORMAT_RTPDUMP;
            i++;
        }
#ifdef FIX_343_TO_UPPER
        else if ( strcmp( argv_to_upper, "-VOIP_HF_ONLY=1" ) == 0 )
#else
        else if ( strcmp( to_upper( argv[i] ), "-VOIP_HF_ONLY=1" ) == 0 )
#endif
        {
            arg->voipMode = 1;
            arg->inputFormat = IVAS_DEC_INPUT_FORMAT_RTPDUMP_HF;
@@ -830,22 +858,19 @@ static bool parseCmdlIVAS_dec(
            i++;
            if ( i < argc - 3 )
            {
#ifdef FIX_343_TO_UPPER
                strncpy( argv_to_upper, argv[i], sizeof( argv_to_upper ) - 1 );
                argv_to_upper[sizeof( argv_to_upper ) - 1] = '\0';
                arg->forcedRendMode = parseForcedRendModeDec( argv_to_upper );
#else
                strncpy( stmp, argv[i], sizeof( stmp ) );
                arg->forcedRendMode = parseForcedRendModeDec( stmp );
#endif
                i++;
            }
        }
#ifndef REMOVE_FORCE_SUBFRAME_BIN
        else if ( strcmp( argv_to_upper, "-FORCE_SUBFRAME_BIN" ) == 0 ) /* Force binauralization to subframe (5 ms) resolution */
        {
            arg->forceSubframeBinauralization = true;
            i++;
        }
#endif
#ifdef DEBUG_MODE_INFO
#ifdef DEBUG_MODE_INFO_TWEAK
        /*-----------------------------------------------------------------*
@@ -890,7 +915,6 @@ static bool parseCmdlIVAS_dec(
                return false;
            }

#ifdef FIX_343_TO_UPPER
            strncpy( argv_to_upper, argv[i + 1], sizeof( argv_to_upper ) - 1 );
            argv_to_upper[sizeof( argv_to_upper ) - 1] = '\0';
            to_upper( argv_to_upper );
@@ -909,25 +933,6 @@ static bool parseCmdlIVAS_dec(
                usage_dec();
                return false;
            }
#else
            char tmp[4];
            strcpy( tmp, argv[i + 1] );

            if ( strcmp( to_upper( tmp ), "REF" ) == 0 )
            {
                arg->orientation_tracking = IVAS_PUBLIC_ORIENT_TRK_REF;
            }
            else if ( strcmp( to_upper( tmp ), "AVG" ) == 0 )
            {
                arg->orientation_tracking = IVAS_PUBLIC_ORIENT_TRK_AVG;
            }
            else
            {
                fprintf( stderr, "Error: Invalid orientation tracking type %s \n\n", tmp );
                usage_dec();
                return false;
            }
#endif
            i += 2;
        }
        else if ( strcmp( argv_to_upper, "-RENDER_CONFIG" ) == 0 )
@@ -954,7 +959,6 @@ static bool parseCmdlIVAS_dec(
                return false;
            }

#ifdef FIX_343_TO_UPPER
            strncpy( argv_to_upper, argv[i], sizeof( argv_to_upper ) - 1 );
            argv_to_upper[sizeof( argv_to_upper ) - 1] = '\0';
            if ( ( strcmp( argv_to_upper, "CENTER" ) == 0 ) || ( strchr( argv_to_upper, 'C' ) != NULL ) )
@@ -980,32 +984,6 @@ static bool parseCmdlIVAS_dec(
                    return false;
                }
            }
#else
            char *param = to_upper( argv[i] );
            if ( ( strcmp( param, "CENTER" ) == 0 ) || ( strchr( param, 'C' ) != NULL ) )
            {
                arg->no_diegetic_pan = 0.f;
            }
            else if ( ( strcmp( param, "LEFT" ) == 0 ) || ( strchr( param, 'L' ) != NULL ) )
            {
                arg->no_diegetic_pan = -1.f;
            }
            else if ( ( strcmp( param, "RIGHT" ) == 0 ) || ( strchr( param, 'R' ) != NULL ) )
            {
                arg->no_diegetic_pan = 1.f;
            }
            else
            {
                arg->no_diegetic_pan = (float) atof( param );

                if ( arg->no_diegetic_pan > 1.0f || arg->no_diegetic_pan < -1.0f )
                {
                    fprintf( stderr, "Error: Incorrect value for panning option argument specified!\n\n" );
                    usage_dec();
                    return false;
                }
            }
#endif
            i++;
        }

@@ -1142,8 +1120,10 @@ static void usage_dec( void )
    fprintf( stdout, "-T File             : Head rotation specified by external trajectory File\n" );
    fprintf( stdout, "-hrtf File          : HRTF filter File used in BINAURAL output configuration\n" );
#ifdef DEBUGGING
#ifndef REMOVE_FORCE_SUBFRAME_BIN
    fprintf( stdout, "-force_subframe_bin : Forces parametric binauralizer code to use 5 ms time resolution even when\n" );
    fprintf( stdout, "                      output time resolution is larger.\n" );
#endif
    fprintf( stdout, "-FEC X              : Insert frame erasures, X = 0-10 is the percentage\n" );
    fprintf( stdout, "                      of erased frames, or X may be the name of binary file or \n" );
    fprintf( stdout, "                      file with G192 headers indicating GOOD FRAME or BAD FRAME\n" );
@@ -1211,9 +1191,17 @@ static ivas_error initOnFirstGoodFrame(
    }
    else
    {
#ifdef BINAURALIZATION_DELAY_REPORT
        pFullDelayNumSamples[0] = 0;
#else
        *pFullDelayNumSamples = 0;
#endif
    }
#ifdef BINAURALIZATION_DELAY_REPORT
    *pRemainingDelayNumSamples = pFullDelayNumSamples[0];
#else
    *pRemainingDelayNumSamples = *pFullDelayNumSamples;
#endif

    if ( ( error = IVAS_DEC_GetNumOutputChannels( hIvasDec, pNumOutChannels ) ) != IVAS_ERR_OK )
    {
@@ -1377,7 +1365,11 @@ static ivas_error decodeG192(
    int16_t numInitialBadFrames = 0; /* Number of bad frames received until first good frame is decoded */
    int16_t nOutChannels = 0;
    int16_t delayNumSamples = -1;
#ifdef BINAURALIZATION_DELAY_REPORT
    int16_t delayNumSamples_orig[3]; /* stores: overall delay, dec+rend delay, and binauralization delay */
#else
    int16_t delayNumSamples_orig = 0;
#endif
    int16_t nOutSamples = 0;
    int32_t delayTimeScale = 0;
    ivas_error error = IVAS_ERR_UNKNOWN;
@@ -1400,6 +1392,10 @@ static ivas_error decodeG192(
        fprintf( stdout, "\n-- Start the decoder (quiet mode) --\n\n" );
    }

#ifdef BINAURALIZATION_DELAY_REPORT
    delayNumSamples_orig[0] = -1;
#endif

#ifdef WMOPS
    reset_stack();
    reset_wmops();
@@ -1490,7 +1486,11 @@ static ivas_error decodeG192(
                    arg,
                    numInitialBadFrames,
                    nOutSamples,
#ifdef BINAURALIZATION_DELAY_REPORT
                    delayNumSamples_orig,
#else
                    &delayNumSamples_orig,
#endif
                    &delayNumSamples,
                    &delayTimeScale,
                    &bsFormat,
@@ -1595,9 +1595,25 @@ static ivas_error decodeG192(
#endif
        }
#ifdef WMOPS
        update_wmops();
        update_mem();
        update_wmops();
#endif
    }

    /*------------------------------------------------------------------------------------------*
     * Add zeros at the end to have equal length of synthesized signals
     *------------------------------------------------------------------------------------------*/

#ifdef BINAURALIZATION_DELAY_REPORT
    memset( pcmBuf, 0, delayNumSamples_orig[0] * nOutChannels * sizeof( int16_t ) );
    if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig[0] * nOutChannels ) ) != IVAS_ERR_OK )
#else
    memset( pcmBuf, 0, delayNumSamples_orig * nOutChannels * sizeof( int16_t ) );
    if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig * nOutChannels ) ) != IVAS_ERR_OK )
#endif
    {
        fprintf( stderr, "\nError writing output file: %s\n", ivas_error_to_string( error ) );
        goto cleanup;
    }

    /*------------------------------------------------------------------------------------------*
@@ -1606,7 +1622,17 @@ static ivas_error decodeG192(

    if ( !arg.quietModeEnabled )
    {
#ifdef BINAURALIZATION_DELAY_REPORT
        printf( "\n\nDecoder+renderer delay: %4.2f ms   (%3u samples at timescale %5u)\n", 1000.f * delayNumSamples_orig[1] / (float) delayTimeScale, delayNumSamples_orig[1], delayTimeScale );

        if ( delayNumSamples_orig[2] > 0 )
        {
            printf( "HRIR/BRIR delay:        %4.2f ms   (%3u samples at timescale %5u)\n", 1000.f * delayNumSamples_orig[2] / (float) delayTimeScale, delayNumSamples_orig[2], delayTimeScale );
            printf( "Total delay:            %4.2f ms   (%3u samples at timescale %5u)\n", 1000.f * delayNumSamples_orig[0] / (float) delayTimeScale, delayNumSamples_orig[0], delayTimeScale );
        }
#else
        fprintf( stdout, "\nDecoder delay:          %-5u [samples]  - Timescale: %5u\n", delayNumSamples_orig, delayTimeScale );
#endif
    }

    /* Print output metadata file name(s) */
@@ -1626,14 +1652,6 @@ static ivas_error decodeG192(
        }
    }

    /* add zeros at the end to have equal length of synthesized signals */
    memset( pcmBuf, 0, delayNumSamples_orig * nOutChannels * sizeof( int16_t ) );
    if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig * nOutChannels ) ) != IVAS_ERR_OK )
    {
        fprintf( stderr, "\nError writing output file: %s\n", ivas_error_to_string( error ) );
        goto cleanup;
    }

    /*------------------------------------------------------------------------------------------*
     * Close files and deallocate resources
     *------------------------------------------------------------------------------------------*/
@@ -1803,7 +1821,11 @@ static ivas_error decodeVoIP(
#endif
    JbmOffsetFileWriter *jbmOffsetWriter = NULL;

#ifdef BINAURALIZATION_DELAY_REPORT
    int16_t delayNumSamples_orig[3]; /* stores: overall delay, dec+rend delay, and binauralization delay */
#else
    int16_t delayNumSamples_orig = -1;
#endif
    int16_t delayNumSamples = -1;
    int32_t delayTimeScale = -1;

@@ -1817,11 +1839,15 @@ static ivas_error decodeVoIP(

    IVAS_DEC_BS_FORMAT bsFormat = IVAS_DEC_BS_UNKOWN;
    IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS];

    for ( int16_t i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i )
    {
        ismWriters[i] = NULL;
    }

#ifdef BINAURALIZATION_DELAY_REPORT
    delayNumSamples_orig[0] = -1;
#endif

    rtpdumpDepacker.rtpdump = NULL;
    switch ( arg.inputFormat )
@@ -2018,7 +2044,11 @@ static ivas_error decodeVoIP(
                    arg,
                    numInitialBadFrames,
                    nOutSamples,
#ifdef BINAURALIZATION_DELAY_REPORT
                    delayNumSamples_orig,
#else
                    &delayNumSamples_orig,
#endif
                    &delayNumSamples,
                    &delayTimeScale,
                    &bsFormat,
@@ -2066,14 +2096,22 @@ static ivas_error decodeVoIP(
        systemTime_ms += 20;

#ifdef WMOPS
        update_wmops();
        update_mem();
        update_wmops();
#endif
    }

    /* add zeros at the end to have equal length of synthesized signals */
    /*------------------------------------------------------------------------------------------*
     * Add zeros at the end to have equal length of synthesized signals
     *------------------------------------------------------------------------------------------*/

#ifdef BINAURALIZATION_DELAY_REPORT
    memset( pcmBuf, 0, delayNumSamples_orig[0] * nOutChannels * sizeof( int16_t ) );
    if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig[0] * nOutChannels ) ) != IVAS_ERR_OK )
#else
    memset( pcmBuf, 0, delayNumSamples_orig * nOutChannels * sizeof( int16_t ) );
    if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig * nOutChannels ) ) != IVAS_ERR_OK )
#endif
    {
        fprintf( stderr, "\nError writing output file: %s\n", ivas_error_to_string( error ) );
        goto cleanup;
@@ -2085,7 +2123,17 @@ static ivas_error decodeVoIP(

    if ( !arg.quietModeEnabled )
    {
#ifdef BINAURALIZATION_DELAY_REPORT
        printf( "\n\nDecoder+renderer delay: %4.2f ms   (%3u samples at timescale %5u)\n", 1000.f * delayNumSamples_orig[1] / (float) delayTimeScale, delayNumSamples_orig[1], delayTimeScale );

        if ( delayNumSamples_orig[2] > 0 )
        {
            printf( "HRIR/BRIR delay:        %4.2f ms   (%3u samples at timescale %5u)\n", 1000.f * delayNumSamples_orig[2] / (float) delayTimeScale, delayNumSamples_orig[2], delayTimeScale );
            printf( "Total delay:            %4.2f ms   (%3u samples at timescale %5u)\n", 1000.f * delayNumSamples_orig[0] / (float) delayTimeScale, delayNumSamples_orig[0], delayTimeScale );
        }
#else
        printf( "\nDecoder delay:       %5u [samples]  - Timescale: %5u\n", delayNumSamples_orig, delayTimeScale );
#endif
    }

    /*------------------------------------------------------------------------------------------*
+80 −35

File changed.

Preview size limit exceeded, changes collapsed.

+52 −11
Original line number Diff line number Diff line
@@ -30,23 +30,20 @@

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

#include "lib_rend.h"
#include <assert.h>
#include <ctype.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "options.h"
#include "audio_file_reader.h"
#include "audio_file_writer.h"
#include "cmdl_tools.h"
#include "cmdln_parser.h"
#include "common_api_types.h"
#include "head_rotation_file_reader.h"
#include "hrtf_file_reader.h"
#include "ism_file_reader.h"
#include "lib_rend.h"
#include "ls_custom_file_reader.h"
#include "masa_file_reader.h"
#include "prot.h"
@@ -460,9 +457,7 @@ static void setupWithSingleFormatInput(
            /* It is allowed on CLI to have no metadata for an ISM input - skip opening if string is empty or contains "NULL" */
            char charBuf[FILENAME_MAX];
            strncpy( charBuf, args.inMetadataFilePaths[i], min( FILENAME_MAX, RENDERER_MAX_CLI_ARG_LENGTH ) - 1 );
#ifdef FIX_343_TO_UPPER
            charBuf[min( FILENAME_MAX, RENDERER_MAX_CLI_ARG_LENGTH ) - 1] = '\0';
#endif
            to_upper( charBuf );
            if ( isEmptyString( args.inMetadataFilePaths[i] ) || strncmp( charBuf, "NULL", 4 ) == 0 )
            {
@@ -570,6 +565,51 @@ int main(
        setupWithSingleFormatInput( args, audioFilePath, positionProvider, masaReaders );
    }

#ifdef FIX_94_VERIFY_WAV_NUM_CHANNELS
    if ( AudioFileReader_open( &audioReader, audioFilePath ) != IVAS_ERR_OK )
    {
        fprintf( stderr, "Error opening file: %s\n", audioFilePath );
        exit( -1 );
    }

    int32_t inFileSampleRate = 0;
    error = AudioFileReader_getSamplingRate( audioReader, &inFileSampleRate );
    switch ( error )
    {
        case IVAS_ERR_OK:
            /* If sampling rate not given on command line, use the one from wav file */
            if ( args.sampleRate == 0 )
            {
                args.sampleRate = inFileSampleRate;
            }
            /* else if sampling rate given on command line, compare with wav file */
            else if ( inFileSampleRate != args.sampleRate )
            {
                fprintf( stderr, "Sampling rate mismatch: %d Hz requested, but %d Hz found in file %s\n", args.sampleRate, inFileSampleRate, args.inputFilePath );
                exit( -1 );
            }
            break;
        case IVAS_ERR_SAMPLING_RATE_UNKNOWN: /* Returned when input is raw PCM */
            if ( args.sampleRate == 0 )
            {
                fprintf( stderr, "Sampling rate must be specified on command line when using raw PCM input\n" );
                exit( -1 );
            }
            args.sampleRate = inFileSampleRate;
            break;
        default:
            fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
            exit( -1 );
    }

    int16_t inFileNumChannels = 0;
    error = AudioFileReader_getNumChannels( audioReader, &inFileNumChannels );
    if ( error != IVAS_ERR_OK && error != IVAS_ERR_NUM_CHANNELS_UNKNOWN )
    {
        fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
        exit( -1 );
    }
#else
    int32_t inFileSampleRate = 0;
    if ( AudioFileReader_open( &audioReader, audioFilePath, &inFileSampleRate ) != IVAS_ERR_OK )
    {
@@ -590,6 +630,7 @@ int main(
    {
        args.sampleRate = inFileSampleRate;
    }
#endif
    const int16_t frameSize_smpls = (int16_t) ( 20 * args.sampleRate / 1000 );

    IVAS_REND_InputId mcIds[RENDERER_MAX_MC_INPUTS] = { 0 };
@@ -757,8 +798,12 @@ int main(

    const int16_t totalNumInChannels = getTotalNumInChannels( hIvasRend, mcIds, ismIds, sbaIds, masaIds );

#ifdef FIX_94_VERIFY_WAV_NUM_CHANNELS
    if ( inFileNumChannels != 0 /* inFileNumChannels is 0 with raw PCM input */ && totalNumInChannels != inFileNumChannels )
#else
    if ( AudioFileReader_getNumChannels( audioReader ) != 0 /* If input file is raw PCM, audio reader has no info about number of channels */
         && totalNumInChannels != AudioFileReader_getNumChannels( audioReader ) )
#endif
    {
        fprintf( stderr, "Number of channels in input file does not match selected configuration\n" );
        exit( -1 );
@@ -976,8 +1021,8 @@ int main(
        }

#ifdef WMOPS
        update_wmops();
        update_mem();
        update_wmops();
#endif
    }

@@ -1083,9 +1128,7 @@ static bool parseInConfig(

    /* First check if input is being set to scene description file - this is not covered by parseAudioConfig(). */
    strncpy( charBuf, inFormatStr, sizeof( charBuf ) - 1 );
#ifdef FIX_343_TO_UPPER
    charBuf[sizeof( charBuf ) - 1] = '\0';
#endif
    to_upper( charBuf );
    if ( strcmp( charBuf, "META" ) == 0 )
    {
@@ -1271,9 +1314,7 @@ static IVAS_REND_AudioConfig parseAudioConfig(
    charBuf[13] = '\0';

    strncpy( charBuf, configString, sizeof( charBuf ) - 1 );
#ifdef FIX_343_TO_UPPER
    charBuf[sizeof( charBuf ) - 1] = '\0';
#endif
    to_upper( charBuf );

    if ( ( strcmp( charBuf, "MONO" ) == 0 ) || ( strcmp( charBuf, "HOA0" ) == 0 ) || ( strcmp( charBuf, "SBA0" ) == 0 ) )
Loading