From af6a787a4eaa7f583987ef408a73fd4516c93980 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 10 Nov 2025 18:59:43 +0100 Subject: [PATCH 01/19] fixes --- apps/decoder.c | 117 +++++++++++++++------------ apps/encoder.c | 20 +++-- apps/encoder_fmtsw.c | 48 ++++++++--- lib_com/common_api_types.h | 3 + lib_com/ivas_cnst.h | 3 - lib_com/ivas_prot.h | 5 -- lib_dec/ivas_init_dec.c | 40 ++++++---- lib_dec/ivas_stat_dec.h | 2 +- lib_dec/lib_dec.c | 146 +++++++++++++++++++++------------- lib_dec/lib_dec.h | 28 ++++--- lib_rend/ivas_render_config.c | 2 +- lib_util/ivas_rtp_pi_data.h | 4 +- 12 files changed, 256 insertions(+), 162 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index eaaf9b582d..70ec9540af 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -41,10 +41,6 @@ #ifdef IVAS_RTPDUMP #include "ivas_rtp_file.h" #endif -#ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT -#include "ivas_cnst.h" -#endif - #include "jbm_file_writer.h" #include "hrtf_file_reader.h" #include "ls_custom_file_reader.h" @@ -67,9 +63,6 @@ #include "flp_debug.h" #endif -#ifdef FIXED_RTP_SEQUENCE_NUM -#define RANDOM_INITSEED_DEC ( 0xFEEDFADE ) -#endif #define WMC_TOOL_SKIP @@ -85,8 +78,11 @@ static #ifdef DEBUGGING #define MIN_NUM_BITS_ACTIVE_FRAME 56 #define NUM_BITS_SID_IVAS_5K2 104 -#endif +#endif +#ifdef FIXED_RTP_SEQUENCE_NUM +#define RANDOM_INITSEED_DEC ( 0xFEEDFADE ) +#endif /*------------------------------------------------------------------------------------------* * Local structure for storing cmdln arguments @@ -226,10 +222,11 @@ static ivas_error printBitstreamInfoVoip( DecArguments arg, BS_READER_HANDLE hBs static int16_t app_own_random( int16_t *seed ); #endif static void do_object_editing( IVAS_EDITABLE_PARAMETERS *editableParameters, ObjectEditFileReader *objectEditFileReader ); - #ifdef DECODER_FORMAT_SWITCHING -static ivas_error restartDecoder( IVAS_DEC_HANDLE *phIvasDec, IVAS_DEC_MODE codec, DecArguments *arg, IVAS_RENDER_CONFIG_DATA *renderConfig, IVAS_CUSTOM_LS_DATA *hLsCustomData ); +static ivas_error restartDecoder( IVAS_DEC_HANDLE *phIvasDec, const IVAS_DEC_MODE decMode, DecArguments *arg, IVAS_RENDER_CONFIG_DATA *renderConfig, IVAS_CUSTOM_LS_DATA *hLsCustomData ); #endif + + /*------------------------------------------------------------------------------------------* * main() * @@ -534,7 +531,6 @@ int main( fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } - #ifndef IVAS_RTPDUMP arg.enableHeadRotation = true; #endif @@ -673,6 +669,7 @@ int main( fprintf( stderr, "Failed to read renderer configuration from file %s\n\n", arg.renderConfigFilename ); goto cleanup; } + #ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT aeCount = RenderConfigReader_getAcousticEnvironmentCount( renderConfigReader ); if ( aeCount > 0 ) @@ -908,6 +905,7 @@ cleanup: free( pAE ); } #endif + if ( arg.aeSequence.count > 0 ) { free( arg.aeSequence.pID ); @@ -1984,6 +1982,7 @@ static ivas_error initOnFirstGoodFrame( ISAR_SPLIT_REND_POSE_CORRECTION_MODE poseCorrection; int16_t splitRendIsarFrameSizeMs; int16_t lc3plusHighRes; + #ifdef FIXED_RTP_SEQUENCE_NUM /* Ideally ssrc is negotiated via SDP and sequence number is radomized but we use fixed seed for random num generator for regression based tests. Any realtime @@ -2567,7 +2566,7 @@ static ivas_error decodeG192( fprintf( stderr, "\nIVAS_DEC_GetNumOrientationSubframes failed: \n" ); goto cleanup; } - /* Head-tracking input simulation */ + /* Head-tracking input simulation */ if ( arg.enableHeadRotation ) { @@ -3382,6 +3381,7 @@ static ivas_error decodeVoIP( int16_t i; #ifdef DECODER_FORMAT_SWITCHING IVAS_DEC_HANDLE hIvasDec = *phIvasDec; + bool restartNeeded; #endif #ifdef IVAS_RTPDUMP IVAS_RTP ivasRtp = { 0 }; @@ -3580,21 +3580,22 @@ static ivas_error decodeVoIP( nSamplesRendered = 0; #ifdef DECODER_FORMAT_SWITCHING + /* restart decoder in case of format switching */ if ( ivasRtp.restartNeeded ) { - IVAS_DEC_MODE newCodecInPacket = ( ivasRtp.codecId == IVAS_RTP_EVS ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; - error = restartDecoder( - &hIvasDec, - newCodecInPacket, - &arg, - NULL, /* ToDo : Provide rendererConfig */ - NULL /* ToDo : Provide LS Custom Data */ - ); - if ( error != IVAS_ERR_OK ) + IVAS_DEC_MODE newDecModeInPacket = ( ivasRtp.codecId == IVAS_RTP_EVS ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; + if ( ( error = restartDecoder( + &hIvasDec, + newDecModeInPacket, + &arg, + NULL, /* ToDo : Provide rendererConfig */ + NULL /* ToDo : Provide LS Custom Data */ + ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nFailed to restart decoder from %d to %d\n", arg.decMode, newCodecInPacket ); + fprintf( stderr, "\nFailed to restart decoder from %d to %d\n", arg.decMode, newDecModeInPacket ); goto cleanup; } + *phIvasDec = hIvasDec; /* Update for main()' s free */ ivasRtp.restartNeeded = false; } @@ -3633,6 +3634,7 @@ static ivas_error decodeVoIP( goto cleanup; } } + int16_t num_subframes; if ( ( error = IVAS_DEC_GetNumOrientationSubframes( hIvasDec, &num_subframes ) ) != IVAS_ERR_OK ) { @@ -3640,7 +3642,6 @@ static ivas_error decodeVoIP( goto cleanup; } - /* Head-tracking input simulation */ /* Head-tracking input simulation */ if ( arg.enableHeadRotation ) { @@ -3782,12 +3783,17 @@ static ivas_error decodeVoIP( /* we are finished when all packets have been received and jitter buffer is empty */ /* also stop when the input file contains less than two frames, because JBM cannot calculate a delay value and won't start decoding */ /* last clause should make sure that for BE tests we end up with the same number of samples...*/ - if ( nextPacketRcvTime_ms == (uint32_t) ( -1 ) && ( IVAS_DEC_VoIP_IsEmpty( hIvasDec, nOutSamples ) || nFramesFed < 2 ) ) + bool isEmpty; + if ( ( error = IVAS_DEC_VoIP_IsEmpty( hIvasDec, nOutSamples, &isEmpty ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + if ( nextPacketRcvTime_ms == (uint32_t) ( -1 ) && ( isEmpty || nFramesFed < 2 ) ) { break; } - /* decode and get samples */ while ( nSamplesRendered < nOutSamples ) { @@ -3804,7 +3810,7 @@ static ivas_error decodeVoIP( numPiData++; } - if ( ( error = IVAS_RTP_FeedPiDataToDecoder( hIvasDec, &ivasRtp.piData[ivasRtp.nProcPiData], numPiData ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_FeedPiDataToDecoder( hIvasDec, &ivasRtp.piData[ivasRtp.nProcPiData], numPiData ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -3852,34 +3858,38 @@ static ivas_error decodeVoIP( return error; } - /* Placeholder for memory reallocation */ - /* ... */ #ifdef DECODER_FORMAT_SWITCHING - if ( IVAS_DEC_isRestartNeeded( hIvasDec ) ) + /* restart decoder in case of format switching */ + if ( ( error = IVAS_DEC_isRestartNeeded( hIvasDec, &restartNeeded ) ) != IVAS_ERR_OK ) { - IVAS_DEC_BS_FORMAT tempFormat; - if ( ( error = IVAS_DEC_GetFormat( hIvasDec, &tempFormat ) ) != IVAS_ERR_OK ) + return error; + } + + if ( restartNeeded ) + { + IVAS_DEC_BS_FORMAT tempBsFormat; + if ( ( error = IVAS_DEC_GetFormat( hIvasDec, &tempBsFormat ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_DEC_GetFormat, code: %d\n", error ); goto cleanup; } - IVAS_DEC_MODE codecMode = ( tempFormat == IVAS_DEC_BS_MONO ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; - error = restartDecoder( - &hIvasDec, - codecMode, - &arg, - NULL, /* ToDo : Provide rendererConfig */ - NULL /* ToDo : Provide LS Custom Data */ - ); - if ( error != IVAS_ERR_OK ) - { - fprintf( stderr, "\nFailed to restart decoder\n" ); - goto cleanup; - } - *phIvasDec = hIvasDec; /* Update for main()' s free */ + + IVAS_DEC_MODE newDecModeInPacket = ( tempBsFormat == IVAS_DEC_BS_MONO ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; + if ( ( error = error = restartDecoder( + &hIvasDec, + newDecModeInPacket, + &arg, + NULL, /* ToDo : Provide rendererConfig */ + NULL /* ToDo : Provide LS Custom Data */ + ) ) != IVAS_ERR_OK ) + + *phIvasDec = hIvasDec; /* Update for main()' s free */ } #endif + /* Placeholder for memory reallocation */ + /* ... */ + /* Load HRTF binary file data */ if ( arg.hrtfReaderEnabled ) { @@ -4079,7 +4089,6 @@ static ivas_error decodeVoIP( } #endif - vec_pos_update = ( vec_pos_update + 1 ) % vec_pos_len; if ( vec_pos_update == 0 ) { @@ -4599,9 +4608,15 @@ static ivas_error load_hrtf_from_file( #ifdef DECODER_FORMAT_SWITCHING -ivas_error restartDecoder( +/*---------------------------------------------------------------------* + * restartDecoder() + * + * Restart decoder in case of format switching + *---------------------------------------------------------------------*/ + +static ivas_error restartDecoder( IVAS_DEC_HANDLE *phIvasDec, - IVAS_DEC_MODE codec, + const IVAS_DEC_MODE decMode, DecArguments *arg, IVAS_RENDER_CONFIG_DATA *renderConfig, IVAS_CUSTOM_LS_DATA *hLsCustomData ) @@ -4619,19 +4634,19 @@ ivas_error restartDecoder( IVAS_DEC_Close( phIvasDec ); } - if ( ( error = IVAS_DEC_Open( phIvasDec, codec ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_Open( phIvasDec, decMode ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Open failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } - arg->decMode = codec; + arg->decMode = decMode; hIvasDec = *phIvasDec; uint16_t aeID = arg->aeSequence.count > 0 ? arg->aeSequence.pID[0] : 65535; - IVAS_AUDIO_CONFIG outputConfig = ( codec == IVAS_DEC_MODE_IVAS ) ? arg->outputConfig : IVAS_AUDIO_CONFIG_MONO; + IVAS_AUDIO_CONFIG outputConfig = ( decMode == IVAS_DEC_MODE_IVAS ) ? arg->outputConfig : IVAS_AUDIO_CONFIG_MONO; if ( ( error = IVAS_DEC_Configure( hIvasDec, arg->output_Fs, outputConfig, arg->renderFramesize, arg->customLsOutputEnabled, arg->hrtfReaderEnabled, arg->enableHeadRotation, arg->enableExternalOrientation, arg->orientation_tracking, arg->renderConfigEnabled, arg->non_diegetic_pan_enabled, arg->non_diegetic_pan_gain, arg->dpidEnabled, aeID, arg->objEditEnabled, arg->delayCompensationEnabled ) ) != IVAS_ERR_OK ) diff --git a/apps/encoder.c b/apps/encoder.c index 162ac9a19d..505e66a282 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -50,10 +50,6 @@ #include "flp_debug.h" #endif -#ifdef FIXED_RTP_SEQUENCE_NUM -#define RANDOM_INITSEED_ENC ( 0xFEEDDEAF ) -#endif - #define WMC_TOOL_SKIP /*------------------------------------------------------------------------------------------* @@ -65,6 +61,10 @@ static #endif int32_t frame = 0; /* Counter of frames */ +#ifdef FIXED_RTP_SEQUENCE_NUM +#define RANDOM_INITSEED_ENC ( 0xFEEDDEAF ) +#endif + #define DEFAULT_FIXED_SID_RATE 8 /* DTX SID rate */ /* Additional config info for each input format */ @@ -474,14 +474,14 @@ int main( if ( ( error = IVAS_ENC_ConfigureForSBAObjects( hIvasEnc, arg.inputFs, totalBitrate, bandwidth, arg.dtxConfig, arg.inputFormatConfig.sba_ism.numObjects, arg.inputFormatConfig.sba_ism.order, arg.inputFormatConfig.sba_ism.isPlanar, arg.pca ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_ENC_ConfigureForSBAObjects failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); - exit( -1 ); + goto cleanup; } break; case IVAS_ENC_INPUT_MASA_ISM: if ( ( error = IVAS_ENC_ConfigureForMASAObjects( hIvasEnc, arg.inputFs, totalBitrate, bandwidth, arg.dtxConfig, arg.inputFormatConfig.masa_ism.numObjects, arg.inputFormatConfig.masa_ism.masaVariant ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_ENC_ConfigureForMASAObjects failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); - exit( -1 ); + goto cleanup; } break; default: @@ -678,6 +678,10 @@ int main( } #endif + /*------------------------------------------------------------------------------------------* + * Run the encoder + *------------------------------------------------------------------------------------------*/ + int16_t numSamplesRead = 0; uint16_t bitStream[IVAS_MAX_BITS_PER_FRAME]; uint16_t numBits = 0; @@ -1084,7 +1088,6 @@ static bool parseCmdlIVAS_enc( arg->sceneOrientationTrajFileName = NULL; arg->deviceOrientationTrajFileName = NULL; #endif - #ifdef DEBUGGING arg->forcedMode = IVAS_ENC_FORCE_UNFORCED; arg->forcedModeFile = NULL; @@ -1887,6 +1890,7 @@ static bool parseCmdlIVAS_enc( { i++; arg->rtpdumpOutput = true; + if ( i < argc - 4 ) { if ( !is_digits_only( argv[i] ) ) @@ -1903,6 +1907,7 @@ static bool parseCmdlIVAS_enc( } } } + fprintf( stdout, "Output format: RTPDump using %d frames/packet \n", arg->numFramesPerPacket ); } @@ -1961,6 +1966,7 @@ static bool parseCmdlIVAS_enc( usage_enc(); return false; } + if ( arg->deviceOrientationTrajFileName != NULL && arg->rtpdumpOutput == false ) { fprintf( stderr, "Error: Device orientations are only enabled with rtpdump output!\n\n" ); diff --git a/apps/encoder_fmtsw.c b/apps/encoder_fmtsw.c index 9d1bf81831..0e1bebee41 100644 --- a/apps/encoder_fmtsw.c +++ b/apps/encoder_fmtsw.c @@ -50,10 +50,6 @@ #include "flp_debug.h" #endif -#ifdef FIXED_RTP_SEQUENCE_NUM -#define RANDOM_INITSEED_ENC ( 0xFEEDDEAF ) -#endif - #define WMC_TOOL_SKIP /*------------------------------------------------------------------------------------------* @@ -68,6 +64,10 @@ static #endif int32_t frame = 0; /* Counter of frames */ +#ifdef FIXED_RTP_SEQUENCE_NUM +#define RANDOM_INITSEED_ENC ( 0xFEEDDEAF ) +#endif + #define DEFAULT_FIXED_SID_RATE 8 /* DTX SID rate */ /* Additional config info for each input format */ @@ -193,14 +193,14 @@ static int encoder_main( int argc, char *argv[] ); * main() * * Main IVAS encoder function for command-line interface - * supporting format switching + * supporting IVAS format switching *------------------------------------------------------------------------------------------*/ - int main( int argc, char *argv[] ) { + bool mainFailed = true; /* Assume main failed until cleanup is reached without errors */ FILE *FmtSWFile = NULL; char line[2048]; int argc_local = 0; @@ -217,14 +217,14 @@ int main( { fprintf( stdout, "Usage: IVAS_cod_fmtsw.exe format_switching_file\n\n" ); fprintf( stdout, "where format_switching_file is a text file containg a valid encoder command line in each line\n\n" ); - exit( 0 ); + goto cleanup; } fprintf( stdout, "Input format switching file: %s\n", argv[1] ); if ( ( FmtSWFile = fopen( argv[1], "r" ) ) == NULL ) { fprintf( stdout, "error: cannot open format switching file %s\n", argv[1] ); - exit( 0 ); + goto cleanup; } while ( fgets( line, sizeof( line ), FmtSWFile ) ) @@ -237,7 +237,10 @@ int main( if ( strcmp( argv_local[argc_local - 1], (char *) prev_outputBitstreamFilename ) == 0 ) { /* append to last Rtp file */ - encoder_main( argc_local, argv_local, &ivasRtp, 0 ); + if ( encoder_main( argc_local, argv_local, &ivasRtp, 0 ) != 0 ) + { + goto cleanup; + } } else { @@ -245,8 +248,13 @@ int main( { IVAS_RTP_Term( &ivasRtp ); } + /* write in separate Rtp file */ - encoder_main( argc_local, argv_local, &ivasRtp, 1 ); + if ( encoder_main( argc_local, argv_local, &ivasRtp, 1 ) != 0 ) + { + goto cleanup; + } + rtp_term = 1; } strcpy( (char *) prev_outputBitstreamFilename, argv_local[argc_local - 1] ); @@ -254,11 +262,21 @@ int main( encoder_main( argc_local, argv_local ); #endif } + + /*------------------------------------------------------------------------------------------* + * Close files and deallocate resources + *------------------------------------------------------------------------------------------*/ + + mainFailed = false; /* This will stay set to true if cleanup is reached via a goto due to an error */ + +cleanup: + #ifdef IVAS_RTPDUMP IVAS_RTP_Term( &ivasRtp ); #endif fclose( FmtSWFile ); - exit( 0 ); + + return mainFailed ? -1 : 0; } @@ -576,14 +594,14 @@ int encoder_main( if ( ( error = IVAS_ENC_ConfigureForSBAObjects( hIvasEnc, arg.inputFs, totalBitrate, bandwidth, arg.dtxConfig, arg.inputFormatConfig.sba_ism.numObjects, arg.inputFormatConfig.sba_ism.order, arg.inputFormatConfig.sba_ism.isPlanar, arg.pca ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_ENC_ConfigureForSBAObjects failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); - exit( -1 ); + goto cleanup; } break; case IVAS_ENC_INPUT_MASA_ISM: if ( ( error = IVAS_ENC_ConfigureForMASAObjects( hIvasEnc, arg.inputFs, totalBitrate, bandwidth, arg.dtxConfig, arg.inputFormatConfig.masa_ism.numObjects, arg.inputFormatConfig.masa_ism.masaVariant ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_ENC_ConfigureForMASAObjects failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); - exit( -1 ); + goto cleanup; } break; default: @@ -780,6 +798,10 @@ int encoder_main( } #endif + /*------------------------------------------------------------------------------------------* + * Run the encoder + *------------------------------------------------------------------------------------------*/ + int16_t numSamplesRead = 0; uint16_t bitStream[IVAS_MAX_BITS_PER_FRAME]; uint16_t numBits = 0; diff --git a/lib_com/common_api_types.h b/lib_com/common_api_types.h index 506b155ef5..904bf2586c 100644 --- a/lib_com/common_api_types.h +++ b/lib_com/common_api_types.h @@ -59,6 +59,9 @@ #define IVAS_ROOM_ABS_COEFF 6 #define IVAS_REVERB_PREDELAY_MAX 20 /* Max input delay for reverb module */ #define IVAS_ER_LIST_HEIGHT 1.6f +#ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT +#define IVAS_DEFAULT_AEID 65535 +#endif /* JBM constants for adaptive-playout */ #define IVAS_TIME_SCALE_MIN 50 /* min. time-scaling [%] */ diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 7909d6959f..6b29fb22b1 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1602,9 +1602,6 @@ typedef enum #define RV_LENGTH_NR_FC ( RV_FILTER_MAX_FFT_SIZE / 2 ) + 1 #define RV_LENGTH_NR_FC_16KHZ ( RV_FILTER_MAX_FFT_SIZE / 4 ) + 1 #define IVAS_REVERB_DEFAULT_N_BANDS 31 -#ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT -#define IVAS_DEFAULT_AEID ( 65535 ) -#endif #define LR_IAC_LENGTH_NR_FC ( RV_LENGTH_NR_FC ) #define LR_IAC_LENGTH_NR_FC_16KHZ ( RV_LENGTH_NR_FC_16KHZ ) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 0aaf9d0ba6..5a3d627454 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -328,12 +328,7 @@ ivas_error ivas_dec( ); ivas_error ivas_dec_get_format( -#ifdef DECODER_FORMAT_SWITCHING - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const bool isVoipMode /* i : voip mode indicator */ -#else Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -#endif ); ivas_error ivas_dec_setup( diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index b7b18ef204..41b2789a69 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -99,12 +99,7 @@ static AUDIO_CONFIG ivas_set_audio_config_from_sba_order( *---------------------------------------------------------------------*/ ivas_error ivas_dec_get_format( -#ifdef DECODER_FORMAT_SWITCHING - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const bool isVoipMode /* i : voip mode indicator */ -#else Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -#endif ) { int16_t k, idx, num_bits_read; @@ -113,12 +108,18 @@ ivas_error ivas_dec_get_format( int32_t ivas_total_brate; uint16_t *bit_stream_orig; AUDIO_CONFIG signaled_config; +#ifdef DECODER_FORMAT_SWITCHING + int16_t isVoipMode; +#endif ivas_error error; num_bits_read = 0; element_mode_flag = 0; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; +#ifdef DECODER_FORMAT_SWITCHING + isVoipMode = st_ivas->hDecoderConfig->Opt_tsm; +#endif bit_stream_orig = st_ivas->bit_stream; /*-------------------------------------------------------------------* @@ -138,6 +139,7 @@ ivas_error ivas_dec_get_format( if ( isVoipMode ) { st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; } else @@ -186,6 +188,7 @@ ivas_error ivas_dec_get_format( if ( isVoipMode ) { st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; } else @@ -245,6 +248,7 @@ ivas_error ivas_dec_get_format( if ( isVoipMode ) { st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; } else @@ -267,6 +271,7 @@ ivas_error ivas_dec_get_format( #ifdef DECODER_FORMAT_SWITCHING uint8_t masaRestartCandidate = 0; #endif + /* read number of MASA transport channels */ if ( st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 1] ) { @@ -318,6 +323,7 @@ ivas_error ivas_dec_get_format( else if ( masaRestartCandidate > 0 ) { st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; } #endif @@ -328,6 +334,7 @@ ivas_error ivas_dec_get_format( if ( isVoipMode ) { st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; } else @@ -358,6 +365,7 @@ ivas_error ivas_dec_get_format( if ( isVoipMode ) { st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; } else @@ -385,6 +393,7 @@ ivas_error ivas_dec_get_format( if ( isVoipMode ) { st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; } else @@ -424,6 +433,7 @@ ivas_error ivas_dec_get_format( if ( isVoipMode ) { st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; } else @@ -464,6 +474,7 @@ ivas_error ivas_dec_get_format( if ( isVoipMode ) { st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; } else @@ -561,6 +572,7 @@ ivas_error ivas_dec_get_format( if ( isVoipMode ) { st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; } else @@ -3020,6 +3032,15 @@ void ivas_destroy_dec( /* Config. Renderer */ ivas_render_config_close( &( st_ivas->hRenderConfig ) ); +#ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT + /* Acoustic environments */ + if ( st_ivas->pAcousticEnvironments != NULL ) + { + free( st_ivas->pAcousticEnvironments ); + st_ivas->pAcousticEnvironments = NULL; + } +#endif + /* Limiter struct */ ivas_limiter_close( &( st_ivas->hLimiter ) ); @@ -3045,15 +3066,6 @@ void ivas_destroy_dec( st_ivas->p_output_f[i] = NULL; } -#ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT - /* Acoustic environments */ - if ( st_ivas->pAcousticEnvironments != NULL ) - { - free( st_ivas->pAcousticEnvironments ); - st_ivas->pAcousticEnvironments = NULL; - } -#endif - /* main IVAS handle */ free( st_ivas ); diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 6d8e1856ae..5549064159 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1152,7 +1152,7 @@ typedef struct Decoder_Struct int16_t flushing; #endif #ifdef DECODER_FORMAT_SWITCHING - int8_t restartNeeded; /* Flag to check if the decoder requires a restart */ + int16_t restartNeeded; /* Flag to signal decoder restart */ #endif } Decoder_Struct; diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index dba9cf23a2..d533e9c9dc 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -41,6 +41,9 @@ #include "jbm_jb4sb.h" #include "jbm_pcmdsp_apa.h" #include "jbm_pcmdsp_fifo.h" +#ifdef IVAS_RTPDUMP +#include "ivas_rtp_pi_data.h" +#endif #include #include #ifdef DEBUGGING @@ -1054,17 +1057,13 @@ ivas_error IVAS_DEC_ReadFormat( if ( st_ivas->bfi == 0 ) { -#ifdef DECODER_FORMAT_SWITCHING - if ( ( error = ivas_dec_get_format( st_ivas, hIvasDec->hVoIP != NULL ) ) != IVAS_ERR_OK ) -#else if ( ( error = ivas_dec_get_format( st_ivas ) ) != IVAS_ERR_OK ) -#endif { return error; } #ifdef DECODER_FORMAT_SWITCHING - if ( st_ivas->restartNeeded > 0 ) + if ( st_ivas->restartNeeded == 1 ) { return IVAS_ERR_OK; } @@ -3312,6 +3311,7 @@ ivas_error IVAS_DEC_HRTF_binary_close( return IVAS_ERR_OK; } + #ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT /*---------------------------------------------------------------------* * IVAS_DEC_AddAcousticEnvironment( ) @@ -3354,6 +3354,7 @@ ivas_error IVAS_DEC_AddAcousticEnvironment( { return IVAS_ERR_FAILED_ALLOC; } + st_ivas->pAcousticEnvironments = ppAE; n = st_ivas->acousticEnvironmentsCount++; pAE = &st_ivas->pAcousticEnvironments[n]; @@ -3386,11 +3387,13 @@ ivas_error IVAS_DEC_AddAcousticEnvironment( return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * IVAS_DEC_GetAcousticEnvironment( ) * * Gets acoustic environment configuration with a given ID *---------------------------------------------------------------------*/ + ivas_error IVAS_DEC_GetAcousticEnvironment( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ uint16_t aeID, /* i : Acoustic environment ID */ @@ -3399,24 +3402,25 @@ ivas_error IVAS_DEC_GetAcousticEnvironment( { uint16_t n, m; uint16_t found = 0; - Decoder_Struct *st_ivas; if ( hIvasDec == NULL || pAcEnv == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } + st_ivas = hIvasDec->st_ivas; /* In case of default AE ID, select the first one available */ if ( aeID == IVAS_DEFAULT_AEID && st_ivas->acousticEnvironmentsCount > 0 ) { - aeID = (uint16_t) st_ivas->pAcousticEnvironments[0].aeID; + aeID = st_ivas->pAcousticEnvironments[0].aeID; } for ( n = 0; n < st_ivas->acousticEnvironmentsCount; n++ ) { IVAS_ROOM_ACOUSTICS_CONFIG_DATA ae = st_ivas->pAcousticEnvironments[n]; + if ( aeID == ae.aeID ) { found = 1; @@ -3456,6 +3460,8 @@ ivas_error IVAS_DEC_GetAcousticEnvironment( } #endif + + /*---------------------------------------------------------------------* * copyRendererConfigStruct( ) * @@ -3673,14 +3679,15 @@ ivas_error IVAS_DEC_FeedRenderConfig( return IVAS_ERR_OK; } + #ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT /*---------------------------------------------------------------------* - * IVAS_DEC_FeedAcousticEnvPI( ) + * feedAcousticEnvPI( ) * * Set acoustic environment from the PI data *---------------------------------------------------------------------*/ -static ivas_error IVAS_DEC_FeedAcousticEnvPI( +static ivas_error feedAcousticEnvPI( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const IVAS_PIDATA_ACOUSTIC_ENV hAcoustEnvPI /* i : Render configuration struct */ ) @@ -4625,11 +4632,20 @@ ivas_error IVAS_DEC_Flush( * *---------------------------------------------------------------------*/ -bool IVAS_DEC_isRestartNeeded( - IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */ +ivas_error IVAS_DEC_isRestartNeeded( + IVAS_DEC_HANDLE hIvasDec, /* i : IVAS decoder handle */ + bool *restartNeeded /* o : flag to signal decoder restart */ + ) { - return hIvasDec->st_ivas->restartNeeded > 0; + if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + *restartNeeded = hIvasDec->st_ivas->restartNeeded > 0; + + return IVAS_ERR_OK; } @@ -4640,9 +4656,10 @@ bool IVAS_DEC_isRestartNeeded( * *---------------------------------------------------------------------*/ -bool IVAS_DEC_VoIP_IsEmpty( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const int16_t nSamplesAsked /* i : number of output samples asked */ +ivas_error IVAS_DEC_VoIP_IsEmpty( + IVAS_DEC_HANDLE hIvasDec, /* i : IVAS decoder handle */ + const int16_t nSamplesAsked,/* i : number of output samples asked */ + bool *isEmpty /* o : isEmpty flag */ ) { if ( hIvasDec == NULL || hIvasDec->hVoIP == NULL ) @@ -4650,7 +4667,9 @@ bool IVAS_DEC_VoIP_IsEmpty( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - return ( ( JB4_bufferedDataUnits( hIvasDec->hVoIP->hJBM ) == 0 ) && ( hIvasDec->nSamplesAvailableNext < nSamplesAsked ) ); + *isEmpty = ( JB4_bufferedDataUnits( hIvasDec->hVoIP->hJBM ) == 0 ) && ( hIvasDec->nSamplesAvailableNext < nSamplesAsked ); + + return IVAS_ERR_OK; } @@ -5999,35 +6018,44 @@ ivas_error IVAS_DEC_is_split_rendering_coded_out( return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* - * IVAS_DEC_feedSinglePIorientation( ) + * feedSinglePIorientation( ) * * Feed a single orientation PI data to external orientation handle. *---------------------------------------------------------------------*/ -static ivas_error IVAS_DEC_feedSinglePIorientation( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ +static ivas_error feedSinglePIorientation( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ bool isOrientationSaved, /* i : flag to indicate if an orientation for this PI type was previously saved */ - IVAS_QUATERNION *savedOrientation /* i : previously saved orientation for this PI type */ + IVAS_QUATERNION *savedOrientation /* i : previously saved orientation for this PI type */ ) { int16_t i; - ivas_error error = IVAS_ERR_OK; + ivas_error error; + Decoder_Struct *st_ivas; IVAS_QUATERNION savedInvOrientation; + if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + st_ivas = hIvasDec->st_ivas; + if ( isOrientationSaved ) { - if ( !hIvasDec->st_ivas->hExtOrientationData ) + if ( !st_ivas->hExtOrientationData ) { - if ( ( error = ivas_external_orientation_open( &( hIvasDec->st_ivas->hExtOrientationData ), hIvasDec->st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_external_orientation_open( &( st_ivas->hExtOrientationData ), hIvasDec->st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) { return error; } } - if ( !hIvasDec->st_ivas->hCombinedOrientationData ) + if ( !st_ivas->hCombinedOrientationData ) { - if ( ( error = ivas_combined_orientation_open( &( hIvasDec->st_ivas->hCombinedOrientationData ), hIvasDec->st_ivas->hDecoderConfig->output_Fs, hIvasDec->st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_combined_orientation_open( &( st_ivas->hCombinedOrientationData ), hIvasDec->st_ivas->hDecoderConfig->output_Fs, hIvasDec->st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) { return error; } @@ -6036,49 +6064,48 @@ static ivas_error IVAS_DEC_feedSinglePIorientation( QuaternionInverse( *savedOrientation, &savedInvOrientation ); /* use the new PI orientation or the previously saved orientation in processing */ - for ( i = 0; i < hIvasDec->st_ivas->hExtOrientationData->num_subframes; i++ ) + for ( i = 0; i < st_ivas->hExtOrientationData->num_subframes; i++ ) { - QuaternionProduct( hIvasDec->st_ivas->hExtOrientationData->Quaternions[i], savedInvOrientation, - &hIvasDec->st_ivas->hExtOrientationData->Quaternions[i] ); + QuaternionProduct( st_ivas->hExtOrientationData->Quaternions[i], savedInvOrientation, + &st_ivas->hExtOrientationData->Quaternions[i] ); hIvasDec->st_ivas->hExtOrientationData->enableExternalOrientation[i] = true; } + hIvasDec->updateOrientation = true; } - return error; + + return IVAS_ERR_OK; } -#ifdef RTP_S4_251135_CR26253_0016_REV1 +#ifdef IVAS_RTPDUMP /*---------------------------------------------------------------------* - * IVAS_DEC_setDiegeticInput( ) + * IVAS_DEC_FeedPiDataToDecoder( ) + * * - * Set isDiegeticInput flag for combined orientation handle based on PI data. *---------------------------------------------------------------------*/ -static void IVAS_DEC_setDiegeticInputPI( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const bool *diegeticPIValues /* i : diegetic values for the input stream */ +ivas_error IVAS_DEC_FeedPiDataToDecoder( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + hPiDataTs piData, /* i : PI data received in rtp packet */ + uint32_t numPiData /* i : number of PI data received in rtp packet */ ) { - if ( hIvasDec->st_ivas->hCombinedOrientationData != NULL ) + int16_t i; + Decoder_Struct *st_ivas; + ivas_error error = IVAS_ERR_OK; + + if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { - int8_t i; - for ( i = 0; i < ( 1 + IVAS_MAX_NUM_OBJECTS ); i++ ) - { - hIvasDec->st_ivas->hCombinedOrientationData->isDiegeticInputPI[i] = diegeticPIValues[i]; - } - hIvasDec->st_ivas->hCombinedOrientationData->isDiegeticInputPISet = true; + return IVAS_ERR_UNEXPECTED_NULL_POINTER; } -} -#endif -#ifdef IVAS_RTPDUMP -ivas_error IVAS_RTP_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, PIDATA_TS *piData, uint32_t numPiData ) -{ - ivas_error error = IVAS_ERR_OK; + st_ivas = hIvasDec->st_ivas; + while ( numPiData-- ) { uint32_t piDataType = piData->data.noPiData.piDataType; + switch ( piDataType ) { case IVAS_PI_SCENE_ORIENTATION: @@ -6087,7 +6114,7 @@ ivas_error IVAS_RTP_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, PIDATA_TS *pi #ifdef DEBUGGING fprintf( stdout, "PI_SCENE_ORIENTATION : %f, %f, %f, %f\n", quat->w, quat->x, quat->y, quat->z ); #endif - error = IVAS_DEC_feedSinglePIorientation( hIvasDec, true, quat ); + error = feedSinglePIorientation( hIvasDec, true, quat ); } break; @@ -6097,7 +6124,7 @@ ivas_error IVAS_RTP_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, PIDATA_TS *pi #ifdef DEBUGGING fprintf( stdout, "PI_DEVICE_ORIENTATION : %f, %f, %f, %f\n", quat->w, quat->x, quat->y, quat->z ); #endif - error = IVAS_DEC_feedSinglePIorientation( hIvasDec, true, quat ); + error = feedSinglePIorientation( hIvasDec, true, quat ); } break; @@ -6109,9 +6136,9 @@ ivas_error IVAS_RTP_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, PIDATA_TS *pi fprintf( stdout, "PI_ACOUSTIC_ENVIRONMENT : AEID : %d\n", aeid ); #endif - if ( piData->data.acousticEnv.availLateReverb && hIvasDec->st_ivas->hRenderConfig != NULL && aeid != hIvasDec->st_ivas->hRenderConfig->roomAcoustics.aeID ) + if ( piData->data.acousticEnv.availLateReverb && st_ivas->hRenderConfig != NULL && aeid != st_ivas->hRenderConfig->roomAcoustics.aeID ) { - error = IVAS_DEC_FeedAcousticEnvPI( hIvasDec, piData->data.acousticEnv ); + error = feedAcousticEnvPI( hIvasDec, piData->data.acousticEnv ); } } break; @@ -6123,7 +6150,16 @@ ivas_error IVAS_RTP_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, PIDATA_TS *pi #ifdef DEBUGGING fprintf( stdout, "PI_DIEGETIC_TYPE : %d, %d, %d, %d, %d\n", piData->data.digeticIndicator.isDiegetic[0], piData->data.digeticIndicator.isDiegetic[1], piData->data.digeticIndicator.isDiegetic[2], piData->data.digeticIndicator.isDiegetic[3], piData->data.digeticIndicator.isDiegetic[4] ); #endif - IVAS_DEC_setDiegeticInputPI( hIvasDec, piData->data.digeticIndicator.isDiegetic ); + if ( st_ivas->hCombinedOrientationData != NULL ) + { + for ( i = 0; i < ( 1 + IVAS_MAX_NUM_OBJECTS ); i++ ) + { + st_ivas->hCombinedOrientationData->isDiegeticInputPI[i] = piData->data.digeticIndicator.isDiegetic[i]; + } + + st_ivas->hCombinedOrientationData->isDiegeticInputPISet = true; + } + } break; #endif @@ -6134,12 +6170,14 @@ ivas_error IVAS_RTP_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, PIDATA_TS *pi } break; } + if ( error != IVAS_ERR_OK ) { return error; } piData++; } - return error; + + return IVAS_ERR_OK; } #endif diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 4a6c2c7a34..1ca724fc62 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -71,7 +71,6 @@ typedef enum _IVAS_DEC_PCM_TYPE IVAS_DEC_PCM_INVALID } IVAS_DEC_PCM_TYPE; - /* bitstream formats that can be consumed */ typedef enum _IVAS_DEC_BS_FORMAT { @@ -87,6 +86,7 @@ typedef enum _IVAS_DEC_BS_FORMAT } IVAS_DEC_BS_FORMAT; typedef struct IVAS_DEC *IVAS_DEC_HANDLE; +typedef struct pidata_ts_struct *hPiDataTs; #ifdef SUPPORT_JBM_TRACEFILE /* Callback function for JBM tracefile writing */ @@ -340,8 +340,9 @@ ivas_error IVAS_DEC_Flush( ); #ifdef DECODER_FORMAT_SWITCHING -bool IVAS_DEC_isRestartNeeded( - IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */ +ivas_error IVAS_DEC_isRestartNeeded( + IVAS_DEC_HANDLE hIvasDec, /* i : IVAS decoder handle */ + bool *restartNeeded /* o : flag to signal decoder restart */ ); #endif @@ -525,9 +526,10 @@ ivas_error IVAS_DEC_HasDecodedFirstGoodFrame( ); /*! r: true if decoder has no data in VoIP jitter buffer */ -bool IVAS_DEC_VoIP_IsEmpty( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const int16_t nSamplesAsked +ivas_error IVAS_DEC_VoIP_IsEmpty( + IVAS_DEC_HANDLE hIvasDec, /* i : IVAS decoder handle */ + const int16_t nSamplesAsked, /* i : number of output samples asked */ + bool *isEmpty /* o : isEmpty flag */ ); ivas_error IVAS_DEC_VoIP_Get_CA_offset( @@ -543,6 +545,15 @@ ivas_error IVAS_DEC_GetJbmData( ); #endif +#ifdef IVAS_RTPDUMP +ivas_error IVAS_DEC_FeedPiDataToDecoder( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + hPiDataTs piData, /* i : PI data received in rtp packet */ + uint32_t numPiData /* i : number of PI data received in rtp packet */ +); +#endif + + /* Utility functions */ /*! r: pointer to an error message string */ @@ -576,11 +587,6 @@ void IVAS_DEC_PrintDisclaimer( void ); -#ifdef IVAS_RTPDUMP -#include "ivas_rtp_pi_data.h" -ivas_error IVAS_RTP_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, PIDATA_TS *piData, uint32_t numPiData ); -#endif - /* clang-format on */ #endif diff --git a/lib_rend/ivas_render_config.c b/lib_rend/ivas_render_config.c index 63eaaf0227..1ba683033a 100644 --- a/lib_rend/ivas_render_config.c +++ b/lib_rend/ivas_render_config.c @@ -114,7 +114,7 @@ ivas_error ivas_render_config_init_from_rom( ( *hRenderConfig )->renderer_type_override = IVAS_RENDER_TYPE_OVERRIDE_NONE; #endif #ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT - ( *hRenderConfig )->roomAcoustics.aeID = (uint16_t) IVAS_DEFAULT_AEID; + ( *hRenderConfig )->roomAcoustics.aeID = IVAS_DEFAULT_AEID; #endif ( *hRenderConfig )->roomAcoustics.nBands = IVAS_REVERB_DEFAULT_N_BANDS; ( *hRenderConfig )->roomAcoustics.acousticPreDelay = IVAS_REVERB_DEFAULT_PRE_DELAY; diff --git a/lib_util/ivas_rtp_pi_data.h b/lib_util/ivas_rtp_pi_data.h index d3d8487e8e..4b5cd0b811 100644 --- a/lib_util/ivas_rtp_pi_data.h +++ b/lib_util/ivas_rtp_pi_data.h @@ -519,11 +519,11 @@ typedef union IVAS_PIDATA_NO_DATA noPiData; } PIDATA; -typedef struct +typedef struct pidata_ts_struct { PIDATA data; uint32_t timestamp; -} PIDATA_TS; +} PIDATA_TS, *hPiDataTs; #endif /* IVAS_RTPDUMP */ -- GitLab From 66053402f546eb9bee80c574e8c017e5de126f10 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 10 Nov 2025 19:22:04 +0100 Subject: [PATCH 02/19] fix --- lib_dec/ivas_init_dec.c | 33 +++++++++++++++++---------------- lib_dec/lib_dec.c | 12 +++++------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index afb81f7cde..aa544ce6b8 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -106,11 +106,11 @@ ivas_error ivas_dec_get_format( int16_t nchan_ism, element_mode_flag; int16_t sba_order, sba_planar, sba_analysis_order; int32_t ivas_total_brate; - uint16_t *bit_stream_orig; - AUDIO_CONFIG signaled_config; #ifdef DECODER_FORMAT_SWITCHING - int16_t isVoipMode; + int16_t Opt_tsm; #endif + uint16_t *bit_stream_orig; + AUDIO_CONFIG signaled_config; ivas_error error; num_bits_read = 0; @@ -118,7 +118,7 @@ ivas_error ivas_dec_get_format( ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; #ifdef DECODER_FORMAT_SWITCHING - isVoipMode = st_ivas->hDecoderConfig->Opt_tsm; + Opt_tsm = st_ivas->hDecoderConfig->Opt_tsm; #endif bit_stream_orig = st_ivas->bit_stream; @@ -136,7 +136,7 @@ ivas_error ivas_dec_get_format( !( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->last_ivas_format == MASA_FORMAT ) ) { #ifdef DECODER_FORMAT_SWITCHING - if ( isVoipMode ) + if ( Opt_tsm ) { st_ivas->restartNeeded = 1; @@ -153,6 +153,7 @@ ivas_error ivas_dec_get_format( } #endif } + /*-------------------------------------------------------------------* * Read other signaling (ISM/MC mode, number of channels, etc.) *-------------------------------------------------------------------*/ @@ -185,7 +186,7 @@ ivas_error ivas_dec_get_format( if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) { #ifdef DECODER_FORMAT_SWITCHING - if ( isVoipMode ) + if ( Opt_tsm ) { st_ivas->restartNeeded = 1; @@ -221,7 +222,7 @@ ivas_error ivas_dec_get_format( if ( st_ivas->ini_frame > 0 && sba_planar != st_ivas->sba_planar ) { #ifdef DECODER_FORMAT_SWITCHING - if ( isVoipMode ) + if ( Opt_tsm ) { st_ivas->restartNeeded = 1; return IVAS_ERR_OK; @@ -245,7 +246,7 @@ ivas_error ivas_dec_get_format( if ( st_ivas->ini_frame > 0 && sba_order != st_ivas->sba_order ) { #ifdef DECODER_FORMAT_SWITCHING - if ( isVoipMode ) + if ( Opt_tsm ) { st_ivas->restartNeeded = 1; @@ -276,7 +277,7 @@ ivas_error ivas_dec_get_format( if ( st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 1] ) { #ifdef DECODER_FORMAT_SWITCHING - if ( st_ivas->nchan_transport == 1 && isVoipMode ) + if ( st_ivas->nchan_transport == 1 && Opt_tsm ) { masaRestartCandidate = 1; } @@ -287,7 +288,7 @@ ivas_error ivas_dec_get_format( else { #ifdef DECODER_FORMAT_SWITCHING - if ( st_ivas->nchan_transport == 2 && isVoipMode ) + if ( st_ivas->nchan_transport == 2 && Opt_tsm ) { masaRestartCandidate = 1; } @@ -331,7 +332,7 @@ ivas_error ivas_dec_get_format( if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) { #ifdef DECODER_FORMAT_SWITCHING - if ( isVoipMode ) + if ( Opt_tsm ) { st_ivas->restartNeeded = 1; @@ -362,7 +363,7 @@ ivas_error ivas_dec_get_format( if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) { #ifdef DECODER_FORMAT_SWITCHING - if ( isVoipMode ) + if ( Opt_tsm ) { st_ivas->restartNeeded = 1; @@ -390,7 +391,7 @@ ivas_error ivas_dec_get_format( if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) { #ifdef DECODER_FORMAT_SWITCHING - if ( isVoipMode ) + if ( Opt_tsm ) { st_ivas->restartNeeded = 1; @@ -430,7 +431,7 @@ ivas_error ivas_dec_get_format( if ( st_ivas->ini_frame > 0 && sba_order != st_ivas->sba_order ) { #ifdef DECODER_FORMAT_SWITCHING - if ( isVoipMode ) + if ( Opt_tsm ) { st_ivas->restartNeeded = 1; @@ -471,7 +472,7 @@ ivas_error ivas_dec_get_format( if ( st_ivas->ini_frame > 0 && st_ivas->transport_config != signaled_config ) { #ifdef DECODER_FORMAT_SWITCHING - if ( isVoipMode ) + if ( Opt_tsm ) { st_ivas->restartNeeded = 1; @@ -569,7 +570,7 @@ ivas_error ivas_dec_get_format( if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) { #ifdef DECODER_FORMAT_SWITCHING - if ( isVoipMode ) + if ( Opt_tsm ) { st_ivas->restartNeeded = 1; diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 128be6673a..b2c4673307 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -3470,7 +3470,6 @@ ivas_error IVAS_DEC_GetAcousticEnvironment( #endif - /*---------------------------------------------------------------------* * copyRendererConfigStruct( ) * @@ -4666,9 +4665,9 @@ ivas_error IVAS_DEC_isRestartNeeded( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_VoIP_IsEmpty( - IVAS_DEC_HANDLE hIvasDec, /* i : IVAS decoder handle */ - const int16_t nSamplesAsked,/* i : number of output samples asked */ - bool *isEmpty /* o : isEmpty flag */ + IVAS_DEC_HANDLE hIvasDec, /* i : IVAS decoder handle */ + const int16_t nSamplesAsked, /* i : number of output samples asked */ + bool *isEmpty /* o : isEmpty flag */ ) { if ( hIvasDec == NULL || hIvasDec->hVoIP == NULL ) @@ -6094,7 +6093,7 @@ static ivas_error feedSinglePIorientation( * *---------------------------------------------------------------------*/ -ivas_error IVAS_DEC_FeedPiDataToDecoder( +ivas_error IVAS_DEC_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ hPiDataTs piData, /* i : PI data received in rtp packet */ uint32_t numPiData /* i : number of PI data received in rtp packet */ @@ -6114,7 +6113,7 @@ ivas_error IVAS_DEC_FeedPiDataToDecoder( while ( numPiData-- ) { uint32_t piDataType = piData->data.noPiData.piDataType; - + switch ( piDataType ) { case IVAS_PI_SCENE_ORIENTATION: @@ -6168,7 +6167,6 @@ ivas_error IVAS_DEC_FeedPiDataToDecoder( st_ivas->hCombinedOrientationData->isDiegeticInputPISet = true; } - } break; #endif -- GitLab From bdeb6b9de736f02f64d8e7c111fea0a1a6d91a9d Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 10 Nov 2025 19:32:04 +0100 Subject: [PATCH 03/19] fix build --- apps/decoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/decoder.c b/apps/decoder.c index a54d777ee5..b410371a75 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -3931,7 +3931,7 @@ static ivas_error decodeVoIP( } IVAS_DEC_MODE newDecModeInPacket = ( tempBsFormat == IVAS_DEC_BS_MONO ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; - if ( ( error = error = restartDecoder( + if ( ( error = restartDecoder( &hIvasDec, newDecModeInPacket, &arg, -- GitLab From 50265b328438962612d75961c34b29e821a5a53e Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 10 Nov 2025 19:37:37 +0100 Subject: [PATCH 04/19] fix build --- lib_util/ivas_rtp_pi_data.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_util/ivas_rtp_pi_data.h b/lib_util/ivas_rtp_pi_data.h index 4b5cd0b811..95a2ac9942 100644 --- a/lib_util/ivas_rtp_pi_data.h +++ b/lib_util/ivas_rtp_pi_data.h @@ -523,7 +523,7 @@ typedef struct pidata_ts_struct { PIDATA data; uint32_t timestamp; -} PIDATA_TS, *hPiDataTs; +} PIDATA_TS; #endif /* IVAS_RTPDUMP */ -- GitLab From 990251f68131a3ecdb7ef7f8f259dc99fa924342 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 11 Nov 2025 11:23:41 +0100 Subject: [PATCH 05/19] address reviewer's comments --- lib_dec/lib_dec.c | 52 +++++++++++++++++++++++++++++++++-------------- lib_dec/lib_dec.h | 36 ++++++++++++++++---------------- 2 files changed, 55 insertions(+), 33 deletions(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index b2c4673307..8a0cb9afc4 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -6055,7 +6055,7 @@ static ivas_error feedSinglePIorientation( { if ( !st_ivas->hExtOrientationData ) { - if ( ( error = ivas_external_orientation_open( &( st_ivas->hExtOrientationData ), hIvasDec->st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_external_orientation_open( &( st_ivas->hExtOrientationData ), st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) { return error; } @@ -6063,7 +6063,7 @@ static ivas_error feedSinglePIorientation( if ( !st_ivas->hCombinedOrientationData ) { - if ( ( error = ivas_combined_orientation_open( &( st_ivas->hCombinedOrientationData ), hIvasDec->st_ivas->hDecoderConfig->output_Fs, hIvasDec->st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_combined_orientation_open( &( st_ivas->hCombinedOrientationData ), st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) { return error; } @@ -6076,7 +6076,7 @@ static ivas_error feedSinglePIorientation( { QuaternionProduct( st_ivas->hExtOrientationData->Quaternions[i], savedInvOrientation, &st_ivas->hExtOrientationData->Quaternions[i] ); - hIvasDec->st_ivas->hExtOrientationData->enableExternalOrientation[i] = true; + st_ivas->hExtOrientationData->enableExternalOrientation[i] = true; } hIvasDec->updateOrientation = true; @@ -6086,6 +6086,35 @@ static ivas_error feedSinglePIorientation( } +#ifdef RTP_S4_251135_CR26253_0016_REV1 +/*---------------------------------------------------------------------* + * setDiegeticInput( ) + * + * Set isDiegeticInput flag for combined orientation handle based on PI data. + *---------------------------------------------------------------------*/ + +static void setDiegeticInputPI( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const bool *diegeticPIValues /* i : diegetic values for the input stream */ +) +{ + int16_t i; + + if ( st_ivas->hCombinedOrientationData != NULL ) + { + for ( i = 0; i < ( 1 + IVAS_MAX_NUM_OBJECTS ); i++ ) + { + st_ivas->hCombinedOrientationData->isDiegeticInputPI[i] = diegeticPIValues[i]; + } + + st_ivas->hCombinedOrientationData->isDiegeticInputPISet = true; + } + + return; +} +#endif + + #ifdef IVAS_RTPDUMP /*---------------------------------------------------------------------* * IVAS_DEC_FeedPiDataToDecoder( ) @@ -6096,10 +6125,10 @@ static ivas_error feedSinglePIorientation( ivas_error IVAS_DEC_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ hPiDataTs piData, /* i : PI data received in rtp packet */ - uint32_t numPiData /* i : number of PI data received in rtp packet */ + const uint32_t numPiData /* i : number of PI data received in rtp packet */ ) { - int16_t i; + uint16_t i; Decoder_Struct *st_ivas; ivas_error error = IVAS_ERR_OK; @@ -6110,7 +6139,7 @@ ivas_error IVAS_DEC_FeedPiDataToDecoder( st_ivas = hIvasDec->st_ivas; - while ( numPiData-- ) + for( i = 0; i < numPiData; i++ ) { uint32_t piDataType = piData->data.noPiData.piDataType; @@ -6158,15 +6187,7 @@ ivas_error IVAS_DEC_FeedPiDataToDecoder( #ifdef DEBUGGING fprintf( stdout, "PI_DIEGETIC_TYPE : %d, %d, %d, %d, %d\n", piData->data.digeticIndicator.isDiegetic[0], piData->data.digeticIndicator.isDiegetic[1], piData->data.digeticIndicator.isDiegetic[2], piData->data.digeticIndicator.isDiegetic[3], piData->data.digeticIndicator.isDiegetic[4] ); #endif - if ( st_ivas->hCombinedOrientationData != NULL ) - { - for ( i = 0; i < ( 1 + IVAS_MAX_NUM_OBJECTS ); i++ ) - { - st_ivas->hCombinedOrientationData->isDiegeticInputPI[i] = piData->data.digeticIndicator.isDiegetic[i]; - } - - st_ivas->hCombinedOrientationData->isDiegeticInputPISet = true; - } + setDiegeticInputPI( st_ivas, piData->data.digeticIndicator.isDiegetic ); } break; #endif @@ -6182,6 +6203,7 @@ ivas_error IVAS_DEC_FeedPiDataToDecoder( { return error; } + piData++; } diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 036e144e61..4a8aec58ae 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -364,33 +364,33 @@ ivas_error IVAS_DEC_EnableSplitRendering( ); ivas_error IVAS_DEC_SetRenderFramesize( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const IVAS_RENDER_FRAMESIZE render_framesize /* i : render framesize */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const IVAS_RENDER_FRAMESIZE render_framesize /* i : render framesize */ ); ivas_error IVAS_DEC_GetRenderFramesize( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - IVAS_RENDER_FRAMESIZE *render_framesize /* o : render framesize */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_RENDER_FRAMESIZE *render_framesize /* o : render framesize */ ); ivas_error IVAS_DEC_GetRenderFramesizeSamples( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - int16_t *render_framesize /* o : render framesize in samples */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + int16_t *render_framesize /* o : render framesize in samples */ ); ivas_error IVAS_DEC_GetReferencesUpdateFrequency( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - int16_t *update_frequency /* o : update frequency */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + int16_t *update_frequency /* o : update frequency */ ); ivas_error IVAS_DEC_GetNumOrientationSubframes( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - int16_t *num_subframes /* o : render framesize */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + int16_t *num_subframes /* o : render framesize */ ); ivas_error IVAS_DEC_GetRenderFramesizeMs( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - uint32_t *render_framesize /* o : render framesize in samples */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + uint32_t *render_framesize /* o : render framesize in samples */ ); #ifdef DEBUGGING @@ -487,14 +487,14 @@ ivas_error IVAS_DEC_HRTF_binary_close( #ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT ivas_error IVAS_DEC_AddAcousticEnvironment( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const IVAS_ROOM_ACOUSTICS_CONFIG_DATA roomAcousticsConfig /* i : Room acoustic configuration */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const IVAS_ROOM_ACOUSTICS_CONFIG_DATA roomAcousticsConfig /* i : Room acoustic configuration */ ); ivas_error IVAS_DEC_GetAcousticEnvironment( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - uint16_t aeID, /* i : Acoustic environment ID */ - IVAS_ROOM_ACOUSTICS_CONFIG_DATA *pAcEnv /* o : Room acoustic environment data pointer */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + uint16_t aeID, /* i : Acoustic environment ID */ + IVAS_ROOM_ACOUSTICS_CONFIG_DATA *pAcEnv /* o : Room acoustic environment data pointer */ ); #endif @@ -552,7 +552,7 @@ ivas_error IVAS_DEC_GetJbmData( ivas_error IVAS_DEC_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ hPiDataTs piData, /* i : PI data received in rtp packet */ - uint32_t numPiData /* i : number of PI data received in rtp packet */ + const uint32_t numPiData /* i : number of PI data received in rtp packet */ ); #endif -- GitLab From 0005f6612fd710c5deb0311e4236ef6d13b272fa Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 11 Nov 2025 11:30:09 +0100 Subject: [PATCH 06/19] clang-format --- lib_dec/lib_dec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 8a0cb9afc4..d7429348c4 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -6035,7 +6035,7 @@ ivas_error IVAS_DEC_is_split_rendering_coded_out( static ivas_error feedSinglePIorientation( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - bool isOrientationSaved, /* i : flag to indicate if an orientation for this PI type was previously saved */ + const bool isOrientationSaved, /* i : flag to indicate if an orientation for this PI type was previously saved */ IVAS_QUATERNION *savedOrientation /* i : previously saved orientation for this PI type */ ) { @@ -6101,7 +6101,7 @@ static void setDiegeticInputPI( int16_t i; if ( st_ivas->hCombinedOrientationData != NULL ) - { + { for ( i = 0; i < ( 1 + IVAS_MAX_NUM_OBJECTS ); i++ ) { st_ivas->hCombinedOrientationData->isDiegeticInputPI[i] = diegeticPIValues[i]; @@ -6128,7 +6128,7 @@ ivas_error IVAS_DEC_FeedPiDataToDecoder( const uint32_t numPiData /* i : number of PI data received in rtp packet */ ) { - uint16_t i; + uint32_t i; Decoder_Struct *st_ivas; ivas_error error = IVAS_ERR_OK; @@ -6139,7 +6139,7 @@ ivas_error IVAS_DEC_FeedPiDataToDecoder( st_ivas = hIvasDec->st_ivas; - for( i = 0; i < numPiData; i++ ) + for ( i = 0; i < numPiData; i++ ) { uint32_t piDataType = piData->data.noPiData.piDataType; -- GitLab From 707ff0450840f98823250a230d0d2413f67b9a29 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 11 Nov 2025 17:39:21 +0100 Subject: [PATCH 07/19] updates --- apps/decoder.c | 2 +- apps/encoder_fmtsw.c | 5 ++++- lib_dec/lib_dec.c | 5 +++-- lib_dec/lib_dec.h | 4 ++-- readme.txt | 47 +++++++++++++++++++++++++++++--------------- 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index b410371a75..a66e216584 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -4667,7 +4667,7 @@ static ivas_error load_hrtf_from_file( /*---------------------------------------------------------------------* * restartDecoder() * - * Restart decoder in case of format switching + * Restart decoder in case of IVAS format switching *---------------------------------------------------------------------*/ static ivas_error restartDecoder( diff --git a/apps/encoder_fmtsw.c b/apps/encoder_fmtsw.c index 0e1bebee41..2a990abae1 100644 --- a/apps/encoder_fmtsw.c +++ b/apps/encoder_fmtsw.c @@ -274,7 +274,10 @@ cleanup: #ifdef IVAS_RTPDUMP IVAS_RTP_Term( &ivasRtp ); #endif - fclose( FmtSWFile ); + if ( FmtSWFile ) + { + fclose( FmtSWFile ); + } return mainFailed ? -1 : 0; } diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index d7429348c4..0344d4bece 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -4661,7 +4661,7 @@ ivas_error IVAS_DEC_isRestartNeeded( /*---------------------------------------------------------------------* * IVAS_DEC_VoIP_IsEmpty( ) * - * + * Returns 'true' if decoder has no data in VoIP jitter buffer *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_VoIP_IsEmpty( @@ -6125,7 +6125,7 @@ static void setDiegeticInputPI( ivas_error IVAS_DEC_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ hPiDataTs piData, /* i : PI data received in rtp packet */ - const uint32_t numPiData /* i : number of PI data received in rtp packet */ + uint32_t numPiData /* i : number of PI data received in rtp packet */ ) { uint32_t i; @@ -6142,6 +6142,7 @@ ivas_error IVAS_DEC_FeedPiDataToDecoder( for ( i = 0; i < numPiData; i++ ) { uint32_t piDataType = piData->data.noPiData.piDataType; + numPiData--; /* Subtraction of WHILE variable */ switch ( piDataType ) { diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 4a8aec58ae..24a663bd35 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -528,7 +528,7 @@ ivas_error IVAS_DEC_HasDecodedFirstGoodFrame( bool *hasDecodedFirstGoodFrame /* o : flag indicating if the decoder has decoded a good frame since it was configured */ ); -/*! r: true if decoder has no data in VoIP jitter buffer */ +/*! r: error code */ ivas_error IVAS_DEC_VoIP_IsEmpty( IVAS_DEC_HANDLE hIvasDec, /* i : IVAS decoder handle */ const int16_t nSamplesAsked, /* i : number of output samples asked */ @@ -552,7 +552,7 @@ ivas_error IVAS_DEC_GetJbmData( ivas_error IVAS_DEC_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ hPiDataTs piData, /* i : PI data received in rtp packet */ - const uint32_t numPiData /* i : number of PI data received in rtp packet */ + uint32_t numPiData /* i : number of PI data received in rtp packet */ ); #endif diff --git a/readme.txt b/readme.txt index 6844421533..c03a143b68 100644 --- a/readme.txt +++ b/readme.txt @@ -33,13 +33,13 @@ These files represent the 3GPP EVS Codec Extension for Immersive Voice and Audio Services (IVAS) floating-point C simulation. All code is writtten -in ISO/IEC C99. The system is implemented as five separate programs: +in ISO/IEC C99. The system is implemented as six separate programs: IVAS_cod IVAS Encoder IVAS_dec IVAS Decoder IVAS_rend IVAS External Renderer - ISAR_post_rend ISAR Post Renderer - ambi_converter Ambisonics format converter + IVAS_cod_fmtsw IVAS Encoder with support for format switching + ambi_converter example program for Ambisonics format conversion For encoding using the coder program, the input is a binary audio file (*.8k, *.16k, *.32k, *.48k) and the output is a binary @@ -123,7 +123,8 @@ should have the following structure: . `-- c-code - |-- Makefile + |-- readme.txt + |-- Makefile |-- Workspace_msvc |-- apps |-- lib_com @@ -134,21 +135,26 @@ should have the following structure: |-- lib_lc3plus |-- lib_rend |-- lib_util - |-- readme.txt - |-- .clang-format The package includes a Makefile for gcc, which has been verified on 32-bit Linux systems. The code can be compiled by entering the directory "c-code" and typing the command: make. The resulting encoder/decoder/renderer/ ISAR_post_renderer executables are named "IVAS_cod", "IVAS_dec", "IVAS_rend", -and "ISAR_post_rend". All reside in the c-code directory. +and "ISAR_post_rend". All reside in the c-code directory. In addition, this +directory will contain a version of the encoder with support for format switching +(named "IVAS_cod_fmtsw") and an example program for Ambisonics format conversion +(named "ambi_converter"). The package also includes a solution-file for Microsoft Visual Studio 2017 (x86). To compile the code, please open "Workspace_msvc\Workspace_msvc.sln" and build "encoder" for the encoder, "decoder" for the decoder, and "renderer" for the renderer executable. The resulting encoder/decoder/renderer/ISAR_post_renderer executables are "IVAS_cod.exe", "IVAS_dec.exe", "IVAS_rend.exe", and -"ISAR_post_rend.exe". All reside in the c-code main directory. +"ISAR_post_rend.exe". All reside in the c-code main directory. In addition, this +directory will contain a version of the encoder with support for format switching +(named "IVAS_cod_fmtsw.exe") and an example program for Ambisonics format conversion +(named "ambi_converter.exe"). + INTEGRATION AS LIBRARIES @@ -175,7 +181,7 @@ some potential race conditions. The usage of the "IVAS_cod" program is as follows: -------------------------------------------------- -Usage: IVAS_cod.exe [Options] R Fs input_file bitstream_file +Usage: IVAS_cod [Options] R Fs input_file bitstream_file Mandatory parameters: --------------------- @@ -261,9 +267,9 @@ EVS mono is default, for IVAS choose one of the following: -stereo, -ism, -sba, The usage of the "IVAS_dec" program is as follows: -------------------------------------------------- -Usage for EVS: IVAS_dec.exe [Options] Fs bitstream_file output_file +Usage for EVS: IVAS_dec [Options] Fs bitstream_file output_file OR usage for IVAS (below) with -evs option and OutputConf -Usage for IVAS: IVAS_dec.exe [Options] OutputConf Fs bitstream_file output_file +Usage for IVAS: IVAS_dec [Options] OutputConf Fs bitstream_file output_file Mandatory parameters: --------------------- @@ -372,8 +378,8 @@ Options: -q : Quiet mode, limit printouts to terminal, default is deactivated -The usage of the "ISAR_post_rend" program: ------------------------------------------- +The usage of the "ISAR_post_rend" program as follows: +----------------------------------------------------- Usage: ISAR_post_rend [options] @@ -414,8 +420,8 @@ omitted, the LFE input is downmixed to all channels with a factor of 1/N. Positi the LFE channel. Maximum number of supported loudskpeakers N is 16. An example custom loudspeaker layout file is available: ls_setup_16ch_8+4+4.txt -The usage of the "ambi_converter" program ------------------------------------------- +The usage of the "ambi_converter" program as follows: +----------------------------------------------------- Usage: ambi_converter input_file output_file input_convention output_convention @@ -428,7 +434,16 @@ the following conventions are supported: 4 : SID-SN3D 5 : SID-N3D -Either the input or the output convention must always be ACN-SN3D! +Either the input or the output convention must always be ACN-SN3D. + +The usage of the "IVAS_cod_fmtsw" program is as follows: +-------------------------------------------------------- + +Usage: IVAS_cod_fmtsw format_switching_file + +Mandatory parameters: +--------------------- +format_switching_file: Text file containing a valid encoder command line in each line RUNNING THE SELF TEST -- GitLab From 063db99305c8f2f5a577c0f3207e6253227dd12c Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 12 Nov 2025 11:36:27 +0100 Subject: [PATCH 08/19] updates --- apps/decoder.c | 8 ++++---- lib_com/ivas_prot.h | 12 ++++++------ lib_rend/ivas_prot_rend.h | 6 +++--- readme.txt | 11 ++++++++++- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index a66e216584..103414e03c 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1908,6 +1908,10 @@ static void usage_dec( void ) fprintf( stdout, "-rvf File : Reference vector specified by external trajectory File\n" ); fprintf( stdout, " works only in combination with '-otr ref_vec' and 'ref_vec_lev' modes\n" ); fprintf( stdout, "-render_config File : Renderer configuration File\n" ); +#ifdef FIX_1318_ROOM_SIZE_CMD_LINE + fprintf( stdout, "-room_size (S|M|L) : Selects default reverb based on a room size (S - small | M - medium | L - large)\n" ); + fprintf( stdout, " for BINAURAL_ROOM_REVERB output configuration,\n" ); +#endif fprintf( stdout, "-om File : Metadata output File for BINAURAL_SPLIT_PCM OutputConf (only for Fs = 48 kHz)\n" ); fprintf( stdout, "-non_diegetic_pan P : panning mono non-diegetic sound to stereo with panning P, -90<= P <=90,\n" ); fprintf( stdout, " left or l or 90->left, right or r or -90->right, center or c or 0->middle\n" ); @@ -1931,10 +1935,6 @@ static void usage_dec( void ) fprintf( stdout, "-obj_edit File : Object editing instructions file or NULL for built-in example\n" ); fprintf( stdout, "-level level : Complexity level, level = (1, 2, 3), will be defined after characterisation. \n" ); fprintf( stdout, " Currently, all values default to level 3 (full functionality).\n" ); -#ifdef FIX_1318_ROOM_SIZE_CMD_LINE - fprintf( stdout, "-room_size (S|M|L) : Selects default reverb based on a room size (S - small | M - medium | L - large)\n" ); - fprintf( stdout, " for BINAURAL_ROOM_REVERB output configuration,\n" ); -#endif fprintf( stdout, "-q : Quiet mode, no frame counter\n" ); fprintf( stdout, " default is deactivated\n" ); #ifdef DEBUG_MODE_INFO diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 5a3d627454..3699782aa7 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -253,7 +253,7 @@ ivas_error ivas_compute_core_buffers( /*! r: number of clipped samples */ uint32_t ivas_syn_output( - float *synth[], /* i/o: float synthesis signal */ + float *synth[], /* i/o: float synthesis signal */ const int16_t output_frame, /* i : output frame length (one channel) */ const int16_t n_channels, /* i : number of output channels */ int16_t *synth_out /* o : integer 16 bits synthesis signal */ @@ -3233,7 +3233,7 @@ void ivas_qmetadata_enc_sid_encode( IVAS_QMETADATA *q_metadata, /* i/o: metadata handle */ const int16_t masa_sid_descriptor, /* i : description of MASA SID coding structure*/ const int16_t nchan_transport, /* i : number of transport channels */ - const int16_t ivas_format /* i : ivas format */ + const int16_t ivas_format /* i : ivas format */ ); /*! r: number of bits read */ @@ -3641,7 +3641,7 @@ ivas_error ivas_dirac_enc( const int16_t dtx_vad, /* i : DTX vad flag */ const IVAS_FORMAT ivas_format, /* i : ivas format */ const int16_t nchan_transport, /* i : number of transport channels */ - const int16_t hodirac_flag /* i : hodirac flag */ + const int16_t hodirac_flag /* i : hodirac flag */ ); ivas_error ivas_dirac_config( @@ -4141,7 +4141,7 @@ ivas_error ivas_sba_linear_renderer( float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ const int16_t output_frame, /* i : output frame length per channel */ const int16_t nchan_in, /* i : number of input ambisonics channels */ - const int16_t nchan_ism, /* i : number of objects */ + const int16_t nchan_ism, /* i : number of objects */ const AUDIO_CONFIG output_config, /* i : output audio configuration */ const IVAS_OUTPUT_SETUP output_setup /* i : output format setup */ ); @@ -4258,7 +4258,7 @@ int16_t ivas_get_sba_num_TCs( void ivas_spar_set_bitrate_config( ivas_spar_md_com_cfg *pSpar_md_cfg, /* i/o: SPAR MD config. handle */ const int16_t table_idx, /* i : config. table index */ - const int16_t num_bands, /* i : number of bands */ + const int16_t num_bands, /* i : number of bands */ const int16_t dirac2spar_md_flag, const int16_t enc_flag, const int16_t pca_flag, @@ -4550,7 +4550,7 @@ ivas_error ivas_spar_covar_enc_open( const int32_t input_Fs, /* i : input sampling rate */ const int16_t nchan_inp, /* i : number of input channels */ const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ + const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); void ivas_spar_covar_enc_close( diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 91bd050990..14c2e65941 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -735,9 +735,9 @@ ivas_error TDREND_MIX_SRC_SetDir( ); ivas_error TDREND_MIX_SRC_SetGain( - BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - const int16_t SrcInd, /* i : Source index */ - const float Gain /* i : Gain */ + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ + const int16_t SrcInd, /* i : Source index */ + const float Gain /* i : Gain */ ); ivas_error TDREND_MIX_SRC_SetDirAtten( diff --git a/readme.txt b/readme.txt index c03a143b68..c70cea5df7 100644 --- a/readme.txt +++ b/readme.txt @@ -316,6 +316,8 @@ Options: -rvf File : Reference vector specified by external trajectory File works only in combination with '-otr ref_vec' and 'ref_vec_lev' modes -render_config File : Binaural renderer configuration parameters in File (only for binaural outputs) +-room_size (S|M|L) : Selects default reverb based on a room size (S - small | M - medium | L - large) + for BINAURAL_ROOM_REVERB output configuration -non_diegetic_pan P : panning mono non-diegetic sound to stereo -90<= P <=90, left or l or 90->left, right or r or -90->right, center or c or 0->middle -exof File : External orientation trajectory File for simulation of external orientations @@ -340,7 +342,7 @@ Options: -------- -i File : Input audio File (WAV, raw PCM or scene description file) -if Format : Audio Format of input file (e.g. 5_1 or HOA3 or META, use -l for a list) - META is related to the Scene description file, see scripts/testv/renderer_config_format_readme.txt + META is related to the Scene description file, see scripts/testv/renderer_config_format_readme.txt -im Files : Metadata files for ISM/MASA/OMASA/OSBA/BINAURAL_SPLIT_PCM (one file per object). For OMASA input, ISM files must be specified first. -o File : Output audio File @@ -354,6 +356,7 @@ Options: -rf File : Reference rotation trajectory File for simulation of head tracking (only for binaural outputs) -rvf File : Reference vector trajectory File for simulation of head tracking (only for binaural outputs) -render_config File : Binaural renderer configuration parameters in File (only for binaural outputs) +-room_size (S|M|L) : Selects default reverb based on a room size (S - small | M - medium | L - large) -non_diegetic_pan P : Panning mono non-diegetic sound to stereo -90<= P <= 90 left or l or 90->left, right or r or -90->right, center or c or 0 ->middle -exof File : External orientation trajectory File for simulation of external orientations @@ -695,6 +698,12 @@ obj__azi= azimuth angle in degrees to be applied on object , obj__relazi=0|1 if 1, obj__azi is interpreted as a relative modification. default is absolute modification obj__ele= elevation angle in degrees to be applied on object , 0-based indexing obj__relele=0|1 if 1, obj__ele is interpreted as a relative modification. default is absolute modification +obj__radius= linear radius to be applied on object , 0-based indexing +obj__relradius=0|1 if 1, obj__radius is interpreted as a relative modification. default is absolute modification +obj__yaw= yaw angle in degrees to be applied on object , 0-based indexing +obj__relyaw=0|1 if 1, obj__yaw is interpreted as a relative modification. default is absolute modification +obj__pitch= pitch angle in degrees to be applied on object , 0-based indexing +obj__relpitch=0|1 if 1, obj__pitch is interpreted as a relative modification. default is absolute modification If a parameter is not specified, that parameter is not edited. An empty line in the file corresponds to not editing any parameter in the item. -- GitLab From 01c3ffd77f97292c93e2761dcf4e30422e609119 Mon Sep 17 00:00:00 2001 From: Marek Szczerba Date: Wed, 12 Nov 2025 13:27:25 +0100 Subject: [PATCH 09/19] Replacing realloc with malloc/copy/free --- lib_dec/lib_dec.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 0344d4bece..2d0b00aa5d 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -3357,13 +3357,41 @@ ivas_error IVAS_DEC_AddAcousticEnvironment( /* If not found */ if ( pAE == NULL ) { - IVAS_ROOM_ACOUSTICS_CONFIG_DATA *ppAE = realloc( st_ivas->pAcousticEnvironments, ( st_ivas->acousticEnvironmentsCount + 1 ) * sizeof( IVAS_ROOM_ACOUSTICS_CONFIG_DATA ) ); + IVAS_ROOM_ACOUSTICS_CONFIG_DATA *ppAE = malloc( ( st_ivas->acousticEnvironmentsCount + 1 ) * sizeof( IVAS_ROOM_ACOUSTICS_CONFIG_DATA ) ); if ( ppAE == NULL ) { return IVAS_ERR_FAILED_ALLOC; } + for ( n = 0; n < st_ivas->acousticEnvironmentsCount; n++ ) + { + pAE = &ppAE[n]; + pAE->aeID = roomAcousticsConfig.aeID; + pAE->nBands = roomAcousticsConfig.nBands; + pAE->acousticPreDelay = roomAcousticsConfig.acousticPreDelay; + pAE->inputPreDelay = roomAcousticsConfig.inputPreDelay; + + mvr2r( roomAcousticsConfig.pFc_input, pAE->pFc_input, CLDFB_NO_CHANNELS_MAX ); + mvr2r( roomAcousticsConfig.pAcoustic_rt60, pAE->pAcoustic_rt60, CLDFB_NO_CHANNELS_MAX ); + mvr2r( roomAcousticsConfig.pAcoustic_dsr, pAE->pAcoustic_dsr, CLDFB_NO_CHANNELS_MAX ); + + pAE->use_er = roomAcousticsConfig.use_er; + + if ( pAE->use_er == 1 ) + { + pAE->lowComplexity = roomAcousticsConfig.lowComplexity; + pAE->dimensions.x = roomAcousticsConfig.dimensions.x; + pAE->dimensions.y = roomAcousticsConfig.dimensions.y; + pAE->dimensions.z = roomAcousticsConfig.dimensions.z; + pAE->ListenerOrigin.x = roomAcousticsConfig.ListenerOrigin.x; + pAE->ListenerOrigin.y = roomAcousticsConfig.ListenerOrigin.y; + pAE->ListenerOrigin.z = roomAcousticsConfig.ListenerOrigin.z; + + mvr2r( roomAcousticsConfig.AbsCoeff, pAE->AbsCoeff, IVAS_ROOM_ABS_COEFF ); + } + } + st_ivas->pAcousticEnvironments = ppAE; n = st_ivas->acousticEnvironmentsCount++; pAE = &st_ivas->pAcousticEnvironments[n]; -- GitLab From fdbe8354e1ec8a9a58b3508c4f6dd37dd8fd407b Mon Sep 17 00:00:00 2001 From: Marek Szczerba Date: Wed, 12 Nov 2025 14:21:14 +0100 Subject: [PATCH 10/19] And copying the right data... --- lib_dec/lib_dec.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 2d0b00aa5d..9a41ee728d 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -3367,28 +3367,28 @@ ivas_error IVAS_DEC_AddAcousticEnvironment( for ( n = 0; n < st_ivas->acousticEnvironmentsCount; n++ ) { pAE = &ppAE[n]; - pAE->aeID = roomAcousticsConfig.aeID; - pAE->nBands = roomAcousticsConfig.nBands; - pAE->acousticPreDelay = roomAcousticsConfig.acousticPreDelay; - pAE->inputPreDelay = roomAcousticsConfig.inputPreDelay; + pAE->aeID = st_ivas->pAcousticEnvironments[n].aeID; + pAE->nBands = st_ivas->pAcousticEnvironments[n].nBands; + pAE->acousticPreDelay = st_ivas->pAcousticEnvironments[n].acousticPreDelay; + pAE->inputPreDelay = st_ivas->pAcousticEnvironments[n].inputPreDelay; - mvr2r( roomAcousticsConfig.pFc_input, pAE->pFc_input, CLDFB_NO_CHANNELS_MAX ); - mvr2r( roomAcousticsConfig.pAcoustic_rt60, pAE->pAcoustic_rt60, CLDFB_NO_CHANNELS_MAX ); - mvr2r( roomAcousticsConfig.pAcoustic_dsr, pAE->pAcoustic_dsr, CLDFB_NO_CHANNELS_MAX ); + mvr2r( st_ivas->pAcousticEnvironments[n].pFc_input, pAE->pFc_input, CLDFB_NO_CHANNELS_MAX ); + mvr2r( st_ivas->pAcousticEnvironments[n].pAcoustic_rt60, pAE->pAcoustic_rt60, CLDFB_NO_CHANNELS_MAX ); + mvr2r( st_ivas->pAcousticEnvironments[n].pAcoustic_dsr, pAE->pAcoustic_dsr, CLDFB_NO_CHANNELS_MAX ); - pAE->use_er = roomAcousticsConfig.use_er; + pAE->use_er = st_ivas->pAcousticEnvironments[n].use_er; if ( pAE->use_er == 1 ) { - pAE->lowComplexity = roomAcousticsConfig.lowComplexity; - pAE->dimensions.x = roomAcousticsConfig.dimensions.x; - pAE->dimensions.y = roomAcousticsConfig.dimensions.y; - pAE->dimensions.z = roomAcousticsConfig.dimensions.z; - pAE->ListenerOrigin.x = roomAcousticsConfig.ListenerOrigin.x; - pAE->ListenerOrigin.y = roomAcousticsConfig.ListenerOrigin.y; - pAE->ListenerOrigin.z = roomAcousticsConfig.ListenerOrigin.z; - - mvr2r( roomAcousticsConfig.AbsCoeff, pAE->AbsCoeff, IVAS_ROOM_ABS_COEFF ); + pAE->lowComplexity = st_ivas->pAcousticEnvironments[n].lowComplexity; + pAE->dimensions.x = st_ivas->pAcousticEnvironments[n].dimensions.x; + pAE->dimensions.y = st_ivas->pAcousticEnvironments[n].dimensions.y; + pAE->dimensions.z = st_ivas->pAcousticEnvironments[n].dimensions.z; + pAE->ListenerOrigin.x = st_ivas->pAcousticEnvironments[n].ListenerOrigin.x; + pAE->ListenerOrigin.y = st_ivas->pAcousticEnvironments[n].ListenerOrigin.y; + pAE->ListenerOrigin.z = st_ivas->pAcousticEnvironments[n].ListenerOrigin.z; + + mvr2r( st_ivas->pAcousticEnvironments[n].AbsCoeff, pAE->AbsCoeff, IVAS_ROOM_ABS_COEFF ); } } -- GitLab From 13715b636bab8f2ec6e425fd439d9c294f32aa35 Mon Sep 17 00:00:00 2001 From: Marek Szczerba Date: Wed, 12 Nov 2025 14:45:54 +0100 Subject: [PATCH 11/19] And the missing free() --- lib_dec/lib_dec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 9a41ee728d..2c4526a188 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -3392,6 +3392,7 @@ ivas_error IVAS_DEC_AddAcousticEnvironment( } } + free( st_ivas->pAcousticEnvironments ); st_ivas->pAcousticEnvironments = ppAE; n = st_ivas->acousticEnvironmentsCount++; pAE = &st_ivas->pAcousticEnvironments[n]; -- GitLab From bed62a106ed589954a8736f1e484d7d2bbed7cfa Mon Sep 17 00:00:00 2001 From: Lauros Pajunen Date: Wed, 12 Nov 2025 16:03:01 +0200 Subject: [PATCH 12/19] Add missing error print for if-statement --- apps/decoder.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 103414e03c..45b93a941b 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -3938,8 +3938,11 @@ static ivas_error decodeVoIP( NULL, /* ToDo : Provide rendererConfig */ NULL /* ToDo : Provide LS Custom Data */ ) ) != IVAS_ERR_OK ) - - *phIvasDec = hIvasDec; /* Update for main()' s free */ + { + fprintf( stderr, "\nFailed to restart decoder\n" ); + goto cleanup; + } + *phIvasDec = hIvasDec; /* Update for main()' s free */ } #endif -- GitLab From f3036e7b479047a1de0902b5c8b143578b0a5087 Mon Sep 17 00:00:00 2001 From: Lauros Pajunen Date: Wed, 12 Nov 2025 16:20:57 +0200 Subject: [PATCH 13/19] Further simplify feeding single pi orientation function --- lib_dec/lib_dec.c | 50 ++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 2c4526a188..5de234e68f 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -6063,15 +6063,14 @@ ivas_error IVAS_DEC_is_split_rendering_coded_out( *---------------------------------------------------------------------*/ static ivas_error feedSinglePIorientation( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const bool isOrientationSaved, /* i : flag to indicate if an orientation for this PI type was previously saved */ - IVAS_QUATERNION *savedOrientation /* i : previously saved orientation for this PI type */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_QUATERNION *orientation /* i : orientation for this PI type */ ) { int16_t i; ivas_error error; Decoder_Struct *st_ivas; - IVAS_QUATERNION savedInvOrientation; + IVAS_QUATERNION invOrientation; if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { @@ -6080,37 +6079,34 @@ static ivas_error feedSinglePIorientation( st_ivas = hIvasDec->st_ivas; - if ( isOrientationSaved ) + if ( !st_ivas->hExtOrientationData ) { - if ( !st_ivas->hExtOrientationData ) + if ( ( error = ivas_external_orientation_open( &( st_ivas->hExtOrientationData ), st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) { - if ( ( error = ivas_external_orientation_open( &( st_ivas->hExtOrientationData ), st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } + } - if ( !st_ivas->hCombinedOrientationData ) + if ( !st_ivas->hCombinedOrientationData ) + { + if ( ( error = ivas_combined_orientation_open( &( st_ivas->hCombinedOrientationData ), st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) { - if ( ( error = ivas_combined_orientation_open( &( st_ivas->hCombinedOrientationData ), st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } + } - QuaternionInverse( *savedOrientation, &savedInvOrientation ); - - /* use the new PI orientation or the previously saved orientation in processing */ - for ( i = 0; i < st_ivas->hExtOrientationData->num_subframes; i++ ) - { - QuaternionProduct( st_ivas->hExtOrientationData->Quaternions[i], savedInvOrientation, - &st_ivas->hExtOrientationData->Quaternions[i] ); - st_ivas->hExtOrientationData->enableExternalOrientation[i] = true; - } + QuaternionInverse( *orientation, &invOrientation ); - hIvasDec->updateOrientation = true; + /* use the new PI orientation or the previously saved orientation in processing */ + for ( i = 0; i < st_ivas->hExtOrientationData->num_subframes; i++ ) + { + QuaternionProduct( st_ivas->hExtOrientationData->Quaternions[i], invOrientation, + &st_ivas->hExtOrientationData->Quaternions[i] ); + st_ivas->hExtOrientationData->enableExternalOrientation[i] = true; } + hIvasDec->updateOrientation = true; + return IVAS_ERR_OK; } @@ -6181,7 +6177,7 @@ ivas_error IVAS_DEC_FeedPiDataToDecoder( #ifdef DEBUGGING fprintf( stdout, "PI_SCENE_ORIENTATION : %f, %f, %f, %f\n", quat->w, quat->x, quat->y, quat->z ); #endif - error = feedSinglePIorientation( hIvasDec, true, quat ); + error = feedSinglePIorientation( hIvasDec, quat ); } break; @@ -6191,7 +6187,7 @@ ivas_error IVAS_DEC_FeedPiDataToDecoder( #ifdef DEBUGGING fprintf( stdout, "PI_DEVICE_ORIENTATION : %f, %f, %f, %f\n", quat->w, quat->x, quat->y, quat->z ); #endif - error = feedSinglePIorientation( hIvasDec, true, quat ); + error = feedSinglePIorientation( hIvasDec, quat ); } break; -- GitLab From 12f431c12c62fdc97a1f09089780079d4249e4ae Mon Sep 17 00:00:00 2001 From: Lauros Pajunen Date: Wed, 12 Nov 2025 17:02:42 +0200 Subject: [PATCH 14/19] Clang format --- lib_dec/lib_dec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 5de234e68f..abcb1e2a40 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -6063,8 +6063,8 @@ ivas_error IVAS_DEC_is_split_rendering_coded_out( *---------------------------------------------------------------------*/ static ivas_error feedSinglePIorientation( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - IVAS_QUATERNION *orientation /* i : orientation for this PI type */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_QUATERNION *orientation /* i : orientation for this PI type */ ) { int16_t i; -- GitLab From 326c7be185ffe2d14c9a1e18f2464581f34f74fc Mon Sep 17 00:00:00 2001 From: Lauros Pajunen Date: Thu, 13 Nov 2025 09:18:03 +0200 Subject: [PATCH 15/19] Remove extra operation to numpidata --- lib_dec/lib_dec.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index abcb1e2a40..de95304301 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -6167,7 +6167,6 @@ ivas_error IVAS_DEC_FeedPiDataToDecoder( for ( i = 0; i < numPiData; i++ ) { uint32_t piDataType = piData->data.noPiData.piDataType; - numPiData--; /* Subtraction of WHILE variable */ switch ( piDataType ) { -- GitLab From 0d4ce37a3c02e02ba929ccbba218c49fe8bb3625 Mon Sep 17 00:00:00 2001 From: Lauros Pajunen Date: Thu, 13 Nov 2025 11:33:57 +0200 Subject: [PATCH 16/19] Add description for RTP streaming format --- readme.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/readme.txt b/readme.txt index c70cea5df7..62d21f51ba 100644 --- a/readme.txt +++ b/readme.txt @@ -709,3 +709,15 @@ If a parameter is not specified, that parameter is not edited. An empty line in not editing any parameter in the item. Example files are available in folder /scripts/object_edit. + +RTP streaming file +------------------- +IVAS supports a simple packing and unpacking for streaming file for the RTP. In this format a single RTP_streaming_packet +contains the length of an RTP packet followed by the actual RTP packet which is recorded as-is. This format is produced +by the encoder when using the -rtpdump switch and the decoder assumes this format in the input when -VOIP_hf_only=1 is set. + +typedef struct { + u_int32 length; /* size of the RTP packet in bytes */ + (u_int8 * length) RTP_packet; /* RTP packet (sized length * byte) */ +} RTP_streaming_packet; + -- GitLab From 4a611260056d87845799f201184094f0ab010345 Mon Sep 17 00:00:00 2001 From: Lauros Pajunen Date: Thu, 13 Nov 2025 12:49:28 +0200 Subject: [PATCH 17/19] Clang format --- apps/decoder.c | 1560 ++++++++++++++++++++++++------------------------ 1 file changed, 780 insertions(+), 780 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 98f4d67a17..d1ddbde7ce 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -3655,177 +3655,177 @@ static ivas_error decodeVoIP( { IVAS_DEC_MODE newDecModeInPacket = ( ivasRtp.codecId == IVAS_RTP_EVS ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; if ( ( error = restartDecoder( - &hIvasDec, - newDecModeInPacket, - &arg, + &hIvasDec, + newDecModeInPacket, + &arg, #ifdef FIX_SPLIT_RENDERING_ON_DECODER_RESTART - renderConfig, + renderConfig, #else - NULL, /* ToDo : Provide rendererConfig */ + NULL, /* ToDo : Provide rendererConfig */ #endif - NULL /* ToDo : Provide LS Custom Data */ - ) ) != IVAS_ERR_OK ) -{ + NULL /* ToDo : Provide LS Custom Data */ + ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nFailed to restart decoder from %d to %d\n", arg.decMode, newDecModeInPacket ); - goto cleanup; - } + { + fprintf( stderr, "\nFailed to restart decoder from %d to %d\n", arg.decMode, newDecModeInPacket ); + goto cleanup; + } - *phIvasDec = hIvasDec; /* Update for main()' s free */ - ivasRtp.restartNeeded = false; - } + *phIvasDec = hIvasDec; /* Update for main()' s free */ + ivasRtp.restartNeeded = false; + } #endif - /* reference vector */ - if ( arg.enableReferenceVectorTracking && vec_pos_update == 0 ) - { - IVAS_VECTOR3 listenerPosition, referencePosition; - if ( ( error = Vector3PairFileReader_read( referenceVectorReader, &listenerPosition, &referencePosition ) ) != IVAS_ERR_OK ) + /* reference vector */ + if ( arg.enableReferenceVectorTracking && vec_pos_update == 0 ) { - fprintf( stderr, "\nError %s while reading listener and reference positions from %s\n", IVAS_DEC_GetErrorMessage( error ), Vector3PairFileReader_getFilePath( referenceVectorReader ) ); - goto cleanup; - } + IVAS_VECTOR3 listenerPosition, referencePosition; + if ( ( error = Vector3PairFileReader_read( referenceVectorReader, &listenerPosition, &referencePosition ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while reading listener and reference positions from %s\n", IVAS_DEC_GetErrorMessage( error ), Vector3PairFileReader_getFilePath( referenceVectorReader ) ); + goto cleanup; + } - if ( ( error = IVAS_DEC_FeedRefVectorData( hIvasDec, listenerPosition, referencePosition ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_FeedRefVectorData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; + if ( ( error = IVAS_DEC_FeedRefVectorData( hIvasDec, listenerPosition, referencePosition ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_FeedRefVectorData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } } - } - /* Reference rotation */ - if ( arg.enableReferenceRotation && vec_pos_update == 0 ) - { - IVAS_QUATERNION quaternion; - if ( ( error = HeadRotationFileReading( refRotReader, &quaternion, NULL ) ) != IVAS_ERR_OK ) + /* Reference rotation */ + if ( arg.enableReferenceRotation && vec_pos_update == 0 ) { - fprintf( stderr, "\nError %s while reading reference rotation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( refRotReader ) ); - goto cleanup; + IVAS_QUATERNION quaternion; + if ( ( error = HeadRotationFileReading( refRotReader, &quaternion, NULL ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while reading reference rotation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( refRotReader ) ); + goto cleanup; + } + + if ( ( error = IVAS_DEC_FeedRefRotData( hIvasDec, quaternion ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_FeedRefRotData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } } - if ( ( error = IVAS_DEC_FeedRefRotData( hIvasDec, quaternion ) ) != IVAS_ERR_OK ) + int16_t num_subframes; + if ( ( error = IVAS_DEC_GetNumOrientationSubframes( hIvasDec, &num_subframes ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nIVAS_DEC_FeedRefRotData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nIVAS_DEC_GetNumOrientationSubframes failed: \n" ); goto cleanup; } - } - int16_t num_subframes; - if ( ( error = IVAS_DEC_GetNumOrientationSubframes( hIvasDec, &num_subframes ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_GetNumOrientationSubframes failed: \n" ); - goto cleanup; - } + /* Head-tracking input simulation */ + if ( arg.enableHeadRotation ) + { + IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; - /* Head-tracking input simulation */ - if ( arg.enableHeadRotation ) - { - IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; + if ( headRotReader == NULL ) + { + for ( i = 0; i < num_subframes; i++ ) + { + Quaternions[i].w = -3.0f; + Quaternions[i].x = 0.0f; + Quaternions[i].y = 0.0f; + Quaternions[i].z = 0.0f; + Pos[i].x = 0.0f; + Pos[i].y = 0.0f; + Pos[i].z = 0.0f; + } + } + else + { + for ( i = 0; i < num_subframes; i++ ) + { + if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i], &Pos[i] ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), + RotationFileReader_getFilePath( headRotReader ) ); + goto cleanup; + } + } + } - if ( headRotReader == NULL ) - { for ( i = 0; i < num_subframes; i++ ) { - Quaternions[i].w = -3.0f; - Quaternions[i].x = 0.0f; - Quaternions[i].y = 0.0f; - Quaternions[i].z = 0.0f; - Pos[i].x = 0.0f; - Pos[i].y = 0.0f; - Pos[i].z = 0.0f; + if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[i], Pos[i], i, DEFAULT_AXIS ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_FeedHeadTrackData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } } } - else + + 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 < num_subframes; i++ ) { - if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i], &Pos[i] ) ) != IVAS_ERR_OK ) + + if ( ( error = ExternalOrientationFileReading( externalOrientationFileReader, &Quaternions[i], &enableHeadRotation[i], &enableExternalOrientation[i], &enableRotationInterpolation[i], &numFramesToTargetOrientation[i] ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), - RotationFileReader_getFilePath( headRotReader ) ); + fprintf( stderr, "\nError %s while reading external orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), + RotationFileReader_getFilePath( externalOrientationFileReader ) ); goto cleanup; } } - } - - for ( i = 0; i < num_subframes; i++ ) - { - if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[i], Pos[i], i, DEFAULT_AXIS ) ) != IVAS_ERR_OK ) + for ( i = 0; i < num_subframes; i++ ) { - fprintf( stderr, "\nIVAS_DEC_FeedHeadTrackData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; + if ( ( error = IVAS_DEC_FeedExternalOrientationData( hIvasDec, Quaternions[i], enableHeadRotation[i], enableExternalOrientation[i], enableRotationInterpolation[i], numFramesToTargetOrientation[i], i ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_FeedExternalOrientationData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } } } - } - - 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 < num_subframes; i++ ) + if ( arg.objEditEnabled && arg.objEditFileName != NULL && vec_pos_update == 0 ) { - - if ( ( error = ExternalOrientationFileReading( externalOrientationFileReader, &Quaternions[i], &enableHeadRotation[i], &enableExternalOrientation[i], &enableRotationInterpolation[i], &numFramesToTargetOrientation[i] ) ) != IVAS_ERR_OK ) + if ( ( error = ObjectEditFileReader_readNextFrame( objectEditFileReader ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError %s while reading external orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), - RotationFileReader_getFilePath( externalOrientationFileReader ) ); - goto cleanup; + fprintf( stderr, "\nError: could not read object editing instructions from file: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; } } - for ( i = 0; i < num_subframes; i++ ) + + /* read all packets with a receive time smaller than the system time */ + while ( nextPacketRcvTime_ms <= systemTime_ms ) { - if ( ( error = IVAS_DEC_FeedExternalOrientationData( hIvasDec, Quaternions[i], enableHeadRotation[i], enableExternalOrientation[i], enableRotationInterpolation[i], numFramesToTargetOrientation[i], i ) ) != IVAS_ERR_OK ) + /* feed the previous read packet into the receiver now */ + error = IVAS_DEC_VoIP_FeedFrame( hIvasDec, auPtr, auSize, rtpSequenceNumber, rtpTimeStamp, nextPacketRcvTime_ms, qBit ); + if ( error != IVAS_ERR_OK ) { - fprintf( stderr, "\nIVAS_DEC_FeedExternalOrientationData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nError in IVAS_DEC_VoIP_FeedFrame: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } - } - } + ++nFramesFed; - if ( arg.objEditEnabled && arg.objEditFileName != NULL && vec_pos_update == 0 ) - { - if ( ( error = ObjectEditFileReader_readNextFrame( objectEditFileReader ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError: could not read object editing instructions from file: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - return error; - } - } - - /* read all packets with a receive time smaller than the system time */ - while ( nextPacketRcvTime_ms <= systemTime_ms ) - { - /* feed the previous read packet into the receiver now */ - error = IVAS_DEC_VoIP_FeedFrame( hIvasDec, auPtr, auSize, rtpSequenceNumber, rtpTimeStamp, nextPacketRcvTime_ms, qBit ); - if ( error != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError in IVAS_DEC_VoIP_FeedFrame: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - ++nFramesFed; - - /* read the next packet */ - if ( arg.inputFormat == IVAS_DEC_INPUT_FORMAT_G192 ) - { - error = BS_Reader_ReadVoipFrame_compact( hBsReader, au, &auSize, &rtpSequenceNumber, &rtpTimeStamp, &nextPacketRcvTime_ms ); + /* read the next packet */ + if ( arg.inputFormat == IVAS_DEC_INPUT_FORMAT_G192 ) + { + error = BS_Reader_ReadVoipFrame_compact( hBsReader, au, &auSize, &rtpSequenceNumber, &rtpTimeStamp, &nextPacketRcvTime_ms ); - qBit = 1; /* good q_bit for VOIP_G192_RTP */ - } - else - { - auPtr = au; /* might have been set to RTP packet in prev call */ + qBit = 1; /* good q_bit for VOIP_G192_RTP */ + } + else + { + auPtr = au; /* might have been set to RTP packet in prev call */ #ifdef IVAS_RTPDUMP #ifdef RTP_S4_251135_CR26253_0016_REV1 - error = IVAS_RTP_ReadNextFrame( &ivasRtp, au, &auSize, &rtpTimeStamp, &rtpSequenceNumber, &nextPacketRcvTime_ms, NULL, &qBit ); + error = IVAS_RTP_ReadNextFrame( &ivasRtp, au, &auSize, &rtpTimeStamp, &rtpSequenceNumber, &nextPacketRcvTime_ms, NULL, &qBit ); #else - error = IVAS_RTP_ReadNextFrame( &ivasRtp, au, &auSize, &rtpTimeStamp, &rtpSequenceNumber, &nextPacketRcvTime_ms, &qBit ); + error = IVAS_RTP_ReadNextFrame( &ivasRtp, au, &auSize, &rtpTimeStamp, &rtpSequenceNumber, &nextPacketRcvTime_ms, &qBit ); #endif - /* IVAS RTP payload format has timescale 16000, JBM uses 1000 internally */ - rtpTimeStamp = rtpTimeStamp / 16; + /* IVAS RTP payload format has timescale 16000, JBM uses 1000 internally */ + rtpTimeStamp = rtpTimeStamp / 16; #else rtpdumpDepackerError = EVS_RTPDUMP_DEPACKER_readNextFrame( &rtpdumpDepacker, &rtpSequenceNumber, &rtpTimeStamp, &nextPacketRcvTime_ms, @@ -3834,268 +3834,384 @@ static ivas_error decodeVoIP( /* EVS RTP payload format has timescale 16000, JBM uses 1000 internally */ rtpTimeStamp = rtpTimeStamp / 16; #endif - } + } #ifdef IVAS_RTPDUMP - if ( error == IVAS_ERR_END_OF_FILE ) + if ( error == IVAS_ERR_END_OF_FILE ) #else if ( error == IVAS_ERR_END_OF_FILE || rtpdumpDepackerError == EVS_RTPDUMP_DEPACKER_EOF ) #endif - { - /* finished reading */ - nextPacketRcvTime_ms = (uint32_t) -1; - } + { + /* finished reading */ + nextPacketRcvTime_ms = (uint32_t) -1; + } #ifdef IVAS_RTPDUMP - else if ( error != IVAS_ERR_OK ) + else if ( error != IVAS_ERR_OK ) #else else if ( error != IVAS_ERR_OK || rtpdumpDepackerError != EVS_RTPDUMP_DEPACKER_NO_ERROR ) #endif + { + fprintf( stderr, "\nError in BS_Reader_ReadVoipFrame_compact, error code: %d\n", error ); + goto cleanup; + } + } + + /* we are finished when all packets have been received and jitter buffer is empty */ + /* also stop when the input file contains less than two frames, because JBM cannot calculate a delay value and won't start decoding */ + /* last clause should make sure that for BE tests we end up with the same number of samples...*/ + bool isEmpty; + if ( ( error = IVAS_DEC_VoIP_IsEmpty( hIvasDec, nOutSamples, &isEmpty ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError in BS_Reader_ReadVoipFrame_compact, error code: %d\n", error ); + fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } - } - - /* we are finished when all packets have been received and jitter buffer is empty */ - /* also stop when the input file contains less than two frames, because JBM cannot calculate a delay value and won't start decoding */ - /* last clause should make sure that for BE tests we end up with the same number of samples...*/ - bool isEmpty; - if ( ( error = IVAS_DEC_VoIP_IsEmpty( hIvasDec, nOutSamples, &isEmpty ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - if ( nextPacketRcvTime_ms == (uint32_t) ( -1 ) && ( isEmpty || nFramesFed < 2 ) ) - { - break; - } - - /* decode and get samples */ - while ( nSamplesRendered < nOutSamples ) - { -#ifdef IVAS_RTPDUMP - if ( arg.applyPiData ) + if ( nextPacketRcvTime_ms == (uint32_t) ( -1 ) && ( isEmpty || nFramesFed < 2 ) ) { - /* Rudimentry Time Mapping to map system time to rtp timestamp */ - uint32_t piTs = systemTime_ms * 16 + initialTsOffsetSystemAndRTP; - uint32_t numPiData = 0; + break; + } - while ( ivasRtp.nProcPiData + numPiData < ivasRtp.nReadPiData && - ivasRtp.piData[ivasRtp.nProcPiData + numPiData].timestamp <= piTs ) + /* decode and get samples */ + while ( nSamplesRendered < nOutSamples ) + { +#ifdef IVAS_RTPDUMP + if ( arg.applyPiData ) { - numPiData++; - } + /* Rudimentry Time Mapping to map system time to rtp timestamp */ + uint32_t piTs = systemTime_ms * 16 + initialTsOffsetSystemAndRTP; + uint32_t numPiData = 0; - if ( ( error = IVAS_DEC_FeedPiDataToDecoder( hIvasDec, &ivasRtp.piData[ivasRtp.nProcPiData], numPiData ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } + while ( ivasRtp.nProcPiData + numPiData < ivasRtp.nReadPiData && + ivasRtp.piData[ivasRtp.nProcPiData + numPiData].timestamp <= piTs ) + { + numPiData++; + } - ivasRtp.nProcPiData += numPiData; - } + if ( ( error = IVAS_DEC_FeedPiDataToDecoder( hIvasDec, &ivasRtp.piData[ivasRtp.nProcPiData], numPiData ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + ivasRtp.nProcPiData += numPiData; + } #endif #ifdef FIX_1119_SPLIT_RENDERING_VOIP - if ( isSplitRend ) - { + if ( isSplitRend ) + { #ifdef SUPPORT_JBM_TRACEFILE - if ( ( error = IVAS_DEC_VoIP_GetSplitBinauralBitstream( hIvasDec, (void *) pcmBuf, splitRendBits, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_VoIP_GetSplitBinauralBitstream( hIvasDec, (void *) pcmBuf, splitRendBits, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) #else - if ( ( error = IVAS_DEC_VoIP_GetSplitBinauralBitstream( hIvasDec, (void *) pcmBuf, splitRendBits, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_VoIP_GetSplitBinauralBitstream( hIvasDec, (void *) pcmBuf, splitRendBits, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) #endif - { - fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSplitBinauralBitstream: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; + { + fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSplitBinauralBitstream: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } } - } - else - { + else + { #endif #ifdef SUPPORT_JBM_TRACEFILE - if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, &bitstreamReadDone, &nSamplesRendered, ¶meterAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) #endif - { - fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } + { + fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } #ifdef FIX_1119_SPLIT_RENDERING_VOIP - } + } #endif - if ( bitstreamReadDone == true ) - { - /* Read main parameters from the bitstream to set-up the decoder */ - hHrtf->binaural_renderer_old = hHrtf->binaural_renderer; - hHrtf->binaural_renderer_sec_old = hHrtf->binaural_renderer_sec; - if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer, &hHrtf->binaural_renderer_sec, &hHrtf->hrtf_set_audio_cfg ) ) != IVAS_ERR_OK ) + if ( bitstreamReadDone == true ) { - return error; - } + /* Read main parameters from the bitstream to set-up the decoder */ + hHrtf->binaural_renderer_old = hHrtf->binaural_renderer; + hHrtf->binaural_renderer_sec_old = hHrtf->binaural_renderer_sec; + if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer, &hHrtf->binaural_renderer_sec, &hHrtf->hrtf_set_audio_cfg ) ) != IVAS_ERR_OK ) + { + return error; + } #ifdef DECODER_FORMAT_SWITCHING - /* restart decoder in case of format switching */ - if ( ( error = IVAS_DEC_isRestartNeeded( hIvasDec, &restartNeeded ) ) != IVAS_ERR_OK ) - { - return error; - } - - if ( restartNeeded ) - { - IVAS_DEC_BS_FORMAT tempBsFormat; - if ( ( error = IVAS_DEC_GetFormat( hIvasDec, &tempBsFormat ) ) != IVAS_ERR_OK ) + /* restart decoder in case of format switching */ + if ( ( error = IVAS_DEC_isRestartNeeded( hIvasDec, &restartNeeded ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError in IVAS_DEC_GetFormat, code: %d\n", error ); - goto cleanup; + return error; } - IVAS_DEC_MODE newDecModeInPacket = ( tempBsFormat == IVAS_DEC_BS_MONO ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; - if ( ( error = restartDecoder( - &hIvasDec, - newDecModeInPacket, - &arg, - NULL, /* ToDo : Provide rendererConfig */ - NULL /* ToDo : Provide LS Custom Data */ - ) ) != IVAS_ERR_OK ) + if ( restartNeeded ) { - fprintf( stderr, "\nFailed to restart decoder\n" ); - goto cleanup; + IVAS_DEC_BS_FORMAT tempBsFormat; + if ( ( error = IVAS_DEC_GetFormat( hIvasDec, &tempBsFormat ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_GetFormat, code: %d\n", error ); + goto cleanup; + } + + IVAS_DEC_MODE newDecModeInPacket = ( tempBsFormat == IVAS_DEC_BS_MONO ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; + if ( ( error = restartDecoder( + &hIvasDec, + newDecModeInPacket, + &arg, + NULL, /* ToDo : Provide rendererConfig */ + NULL /* ToDo : Provide LS Custom Data */ + ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nFailed to restart decoder\n" ); + goto cleanup; + } + *phIvasDec = hIvasDec; /* Update for main()' s free */ } - *phIvasDec = hIvasDec; /* Update for main()' s free */ - } #endif - /* Placeholder for memory reallocation */ - /* ... */ + /* Placeholder for memory reallocation */ + /* ... */ - /* Load HRTF binary file data */ - if ( arg.hrtfReaderEnabled ) + /* Load HRTF binary file data */ + if ( arg.hrtfReaderEnabled ) + { + if ( ( error = load_hrtf_from_file( hHrtf, hIvasDec, arg.outputConfig, arg.output_Fs ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_LoadHrtfFromFile failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } + } + + /* Object metadata editing */ + if ( arg.objEditEnabled && parametersAvailableForEditing == true ) { - if ( ( error = load_hrtf_from_file( hHrtf, hIvasDec, arg.outputConfig, arg.output_Fs ) ) != IVAS_ERR_OK ) + IVAS_EDITABLE_PARAMETERS editableParameters; + + /* get object parameters */ + if ( ( error = IVAS_DEC_GetEditableParameters( hIvasDec, &editableParameters ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nIVAS_DEC_LoadHrtfFromFile failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; + fprintf( stderr, "\nError: could not get the editable parameters: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; + } + + /* Do object metadata editing here ... */ + do_object_editing( &editableParameters, objectEditFileReader ); + + /* set new object parameters */ + if ( ( error = IVAS_DEC_SetEditableParameters( hIvasDec, editableParameters ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: could not set the editable parameters: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; } } - } + } /* while ( nSamplesRendered < nOutSamples ) */ - /* Object metadata editing */ - if ( arg.objEditEnabled && parametersAvailableForEditing == true ) + /* write JBM Offset file entry */ + if ( jbmOffsetWriter != NULL ) { - IVAS_EDITABLE_PARAMETERS editableParameters; + int16_t optimum_offset, FEC_hi; - /* get object parameters */ - if ( ( error = IVAS_DEC_GetEditableParameters( hIvasDec, &editableParameters ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_VoIP_Get_CA_offset( hIvasDec, &optimum_offset, &FEC_hi ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError: could not get the editable parameters: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - return error; + fprintf( stderr, "\nError in IVAS_DEC_VoIP_Get_CA_offset: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; } - /* Do object metadata editing here ... */ - do_object_editing( &editableParameters, objectEditFileReader ); - - /* set new object parameters */ - if ( ( error = IVAS_DEC_SetEditableParameters( hIvasDec, editableParameters ) ) != IVAS_ERR_OK ) + if ( ( JbmOffsetFileWriter_writeFrame( FEC_hi, optimum_offset, jbmOffsetWriter ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError: could not set the editable parameters: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - return error; + fprintf( stderr, "\nError writing JBM Offset data to file %s\n", arg.jbmOffsetFilename ); + goto cleanup; } } - } /* while ( nSamplesRendered < nOutSamples ) */ - - /* write JBM Offset file entry */ - if ( jbmOffsetWriter != NULL ) - { - int16_t optimum_offset, FEC_hi; - if ( ( error = IVAS_DEC_VoIP_Get_CA_offset( hIvasDec, &optimum_offset, &FEC_hi ) ) != IVAS_ERR_OK ) + /* Continue checking for first good frame until it is found */ + if ( !decodedGoodFrame ) { - fprintf( stderr, "\nError in IVAS_DEC_VoIP_Get_CA_offset: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } + if ( ( error = IVAS_DEC_HasDecodedFirstGoodFrame( hIvasDec, &decodedGoodFrame ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Error in IVAS_DEC_HasDecodedFirstGoodFrame(): %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } - if ( ( JbmOffsetFileWriter_writeFrame( FEC_hi, optimum_offset, jbmOffsetWriter ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError writing JBM Offset data to file %s\n", arg.jbmOffsetFilename ); - goto cleanup; - } - } + /* Once good frame decoded, catch up */ + if ( decodedGoodFrame ) + { +#ifndef FIX_1119_SPLIT_RENDERING_VOIP + SplitFileReadWrite *splitRendWriter = NULL; - /* Continue checking for first good frame until it is found */ - if ( !decodedGoodFrame ) - { - if ( ( error = IVAS_DEC_HasDecodedFirstGoodFrame( hIvasDec, &decodedGoodFrame ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "Error in IVAS_DEC_HasDecodedFirstGoodFrame(): %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; +#endif +#ifdef FIX_1119_SPLIT_RENDERING_VOIP + if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, &vec_pos_len, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, +#else + if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, NULL, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, +#endif +#ifdef IVAS_RTPDUMP + &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &srRtp, &splitRendWriter ) ) != IVAS_ERR_OK ) +#else + &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &splitRendWriter ) ) != IVAS_ERR_OK ) +#endif + { + fprintf( stderr, "Error in initOnFirstGoodFrame(): %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } + else + { + ++numInitialBadFrames; + } } - /* Once good frame decoded, catch up */ - if ( decodedGoodFrame ) + /* Write current frame */ +#ifdef IVAS_RTPDUMP + if ( !srRtp.hPack && decodedGoodFrame ) +#else + if ( decodedGoodFrame ) +#endif { -#ifndef FIX_1119_SPLIT_RENDERING_VOIP - SplitFileReadWrite *splitRendWriter = NULL; +#ifdef FIX_1119_SPLIT_RENDERING_VOIP + if ( isSplitRend ) + { + if ( split_rend_write_bitstream_to_file( splitRendWriter, splitRendBits->bits_buf, &splitRendBits->bits_read, &splitRendBits->bits_written ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nUnable to write to bitstream file!\n" ); + goto cleanup; + } + } + if ( !isSplitCoded ) + { #endif + if ( delayNumSamples < nOutSamples ) + { + if ( ( error = AudioFileWriter_write( afWriter, &pcmBuf[delayNumSamples * nOutChannels], nOutSamples * nOutChannels - ( delayNumSamples * nOutChannels ) ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nOutput audio file writer error\n" ); + goto cleanup; + } + delayNumSamples = 0; + } + else + { + delayNumSamples -= nOutSamples; + } #ifdef FIX_1119_SPLIT_RENDERING_VOIP - if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, &vec_pos_len, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, -#else - if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, NULL, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, + } #endif + + /* Write ISM metadata to external file(s) */ + if ( decodedGoodFrame && arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) + { + if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM ) + { + if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, &numObj ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_GetNumObjects: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + for ( i = 0; i < numObj; ++i ) + { + IVAS_ISM_METADATA IsmMetadata; + + if ( ( error = IVAS_DEC_GetObjectMetadata( hIvasDec, &IsmMetadata, 0, i ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_GetObjectMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + if ( ( IsmFileWriter_writeFrame( IsmMetadata, ismWriters[i] ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError writing ISM metadata to file %s\n", IsmFileWriter_getFilePath( ismWriters[i] ) ); + goto cleanup; + } + } + } + + if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) + { + IVAS_MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta; + int16_t fullDelayNumSamples[3]; + float delayMs; + + /* delayNumSamples_orig is fetched only for the first good frame, but here the delay can change between frames, so need to re-fetch */ + if ( ( error = IVAS_DEC_GetDelay( hIvasDec, fullDelayNumSamples, &delayTimeScale ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nUnable to get delay of decoder: %s\n", ivas_error_to_string( error ) ); + } + if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 1 ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_GetMasaMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + delayMs = (float) ( fullDelayNumSamples[0] ) / (float) ( delayTimeScale ); + if ( ( error = MasaFileWriter_writeFrame( masaWriter, hMasaExtOutMeta, &delayMs ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError writing MASA metadata to file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); + goto cleanup; + } + } + + IVAS_RTP_WriteExtPiData( ivasRtp.f_piExtOut, ivasRtp.piData, ivasRtp.nReadPiData, numObj ); + } + } #ifdef IVAS_RTPDUMP - &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &srRtp, &splitRendWriter ) ) != IVAS_ERR_OK ) -#else - &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &splitRendWriter ) ) != IVAS_ERR_OK ) -#endif + else if ( decodedGoodFrame ) + { + srInfo.bitrateKbps = splitRendBits->bits_written * 1000 / splitRendBits->codec_frame_size_ms; + srInfo.codec = ( splitRendBits->codec == ISAR_SPLIT_REND_CODEC_LC3PLUS ) ? IVAS_SR_TRANSPORT_LC3PLUS : IVAS_SR_TRANSPORT_LCLD; + if ( ( error = IVAS_RTP_WriteNextFrame( &srRtp, splitRendBits->bits_buf, &srInfo, (int16_t) splitRendBits->bits_written, false, false ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "Error in initOnFirstGoodFrame(): %s\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nError %s while pushing SR audio bitstream to RTP pack\n", ivas_error_to_string( error ) ); goto cleanup; } + splitRendBits->bits_written = 0; + splitRendBits->bits_read = 0; } - else +#endif + + vec_pos_update = ( vec_pos_update + 1 ) % vec_pos_len; + if ( vec_pos_update == 0 ) { - ++numInitialBadFrames; + systemTime_ms += vec_pos_len * systemTimeInc_ms; } - } - /* Write current frame */ -#ifdef IVAS_RTPDUMP - if ( !srRtp.hPack && decodedGoodFrame ) -#else - if ( decodedGoodFrame ) -#endif - { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - if ( isSplitRend ) + if ( vec_pos_update == 0 ) { - if ( split_rend_write_bitstream_to_file( splitRendWriter, splitRendBits->bits_buf, &splitRendBits->bits_read, &splitRendBits->bits_written ) != IVAS_ERR_OK ) + frame++; + if ( !arg.quietModeEnabled ) { - fprintf( stderr, "\nUnable to write to bitstream file!\n" ); - goto cleanup; + fprintf( stdout, "%-8d\b\b\b\b\b\b\b\b", frame ); } } - if ( !isSplitCoded ) - { +#ifdef WMOPS + update_mem(); + update_wmops(); #endif - if ( delayNumSamples < nOutSamples ) - { - if ( ( error = AudioFileWriter_write( afWriter, &pcmBuf[delayNumSamples * nOutChannels], nOutSamples * nOutChannels - ( delayNumSamples * nOutChannels ) ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nOutput audio file writer error\n" ); - goto cleanup; - } - delayNumSamples = 0; - } - else - { - delayNumSamples -= nOutSamples; - } + } + + + int16_t nSamplesFlushed = 0; + + /* decode and get samples */ + if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, &nSamplesFlushed ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_VoIP_Flush: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + #ifdef FIX_1119_SPLIT_RENDERING_VOIP - } + if ( nSamplesFlushed && !isSplitCoded ) +#else + if ( nSamplesFlushed ) #endif + { + /* Write current frame */ + if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, nSamplesFlushed * nOutChannels ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nOutput audio file writer error\n" ); + goto cleanup; + } - /* Write ISM metadata to external file(s) */ + /* Write ISm metadata to external file(s) */ if ( decodedGoodFrame && arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) { if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM ) @@ -4130,12 +4246,12 @@ static ivas_error decodeVoIP( int16_t fullDelayNumSamples[3]; float delayMs; - /* delayNumSamples_orig is fetched only for the first good frame, but here the delay can change between frames, so need to re-fetch */ + /* delayNumSamples is zeroed, and delayNumSamples_orig is updated only on first good frame, so need to re-fetch delay info */ if ( ( error = IVAS_DEC_GetDelay( hIvasDec, fullDelayNumSamples, &delayTimeScale ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nUnable to get delay of decoder: %s\n", ivas_error_to_string( error ) ); } - if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 1 ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 0 ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_DEC_GetMasaMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -4152,499 +4268,406 @@ static ivas_error decodeVoIP( IVAS_RTP_WriteExtPiData( ivasRtp.f_piExtOut, ivasRtp.piData, ivasRtp.nReadPiData, numObj ); } } -#ifdef IVAS_RTPDUMP - else if ( decodedGoodFrame ) + + /*------------------------------------------------------------------------------------------* + * Add zeros at the end to have equal length of synthesized signals + *------------------------------------------------------------------------------------------*/ + + memset( pcmBuf, 0, delayNumSamples_orig[0] * nOutChannels * sizeof( int16_t ) ); + +#ifdef FIX_1119_SPLIT_RENDERING_VOIP + if ( afWriter != NULL ) { - srInfo.bitrateKbps = splitRendBits->bits_written * 1000 / splitRendBits->codec_frame_size_ms; - srInfo.codec = ( splitRendBits->codec == ISAR_SPLIT_REND_CODEC_LC3PLUS ) ? IVAS_SR_TRANSPORT_LC3PLUS : IVAS_SR_TRANSPORT_LCLD; - if ( ( error = IVAS_RTP_WriteNextFrame( &srRtp, splitRendBits->bits_buf, &srInfo, (int16_t) splitRendBits->bits_written, false, false ) ) != IVAS_ERR_OK ) +#endif + if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig[0] * nOutChannels ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError %s while pushing SR audio bitstream to RTP pack\n", ivas_error_to_string( error ) ); + fprintf( stderr, "\nError writing output file: %s\n", ivas_error_to_string( error ) ); goto cleanup; } - splitRendBits->bits_written = 0; - splitRendBits->bits_read = 0; +#ifdef FIX_1119_SPLIT_RENDERING_VOIP } #endif - vec_pos_update = ( vec_pos_update + 1 ) % vec_pos_len; - if ( vec_pos_update == 0 ) - { - systemTime_ms += vec_pos_len * systemTimeInc_ms; - } + /*------------------------------------------------------------------------------------------* + * Printouts after decoding has finished + *------------------------------------------------------------------------------------------*/ - if ( vec_pos_update == 0 ) + if ( !arg.quietModeEnabled ) { - frame++; - if ( !arg.quietModeEnabled ) + 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 ) { - fprintf( stdout, "%-8d\b\b\b\b\b\b\b\b", frame ); + 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[1] + delayNumSamples_orig[2] ) / (float) delayTimeScale, delayNumSamples_orig[1] + delayNumSamples_orig[2], delayTimeScale ); } } -#ifdef WMOPS - update_mem(); - update_wmops(); -#endif - } - - - int16_t nSamplesFlushed = 0; - - /* decode and get samples */ - if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, &nSamplesFlushed ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError in IVAS_DEC_VoIP_Flush: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - if ( nSamplesFlushed && !isSplitCoded ) -#else - if ( nSamplesFlushed ) -#endif - { - /* Write current frame */ - if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, nSamplesFlushed * nOutChannels ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nOutput audio file writer error\n" ); - goto cleanup; - } - - /* Write ISm metadata to external file(s) */ - if ( decodedGoodFrame && arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) + /* Print output metadata file name(s) */ + if ( arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) { if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM ) { - if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, &numObj ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError in IVAS_DEC_GetNumObjects: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - - for ( i = 0; i < numObj; ++i ) + for ( i = 0; i < numObj; i++ ) { - IVAS_ISM_METADATA IsmMetadata; - - if ( ( error = IVAS_DEC_GetObjectMetadata( hIvasDec, &IsmMetadata, 0, i ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError in IVAS_DEC_GetObjectMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - - if ( ( IsmFileWriter_writeFrame( IsmMetadata, ismWriters[i] ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError writing ISM metadata to file %s\n", IsmFileWriter_getFilePath( ismWriters[i] ) ); - goto cleanup; - } + fprintf( stdout, "\nOutput ISM metadata file: %s", IsmFileWriter_getFilePath( ismWriters[i] ) ); } + fprintf( stdout, "\n" ); } if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) { - IVAS_MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta; - int16_t fullDelayNumSamples[3]; - float delayMs; - - /* delayNumSamples is zeroed, and delayNumSamples_orig is updated only on first good frame, so need to re-fetch delay info */ - if ( ( error = IVAS_DEC_GetDelay( hIvasDec, fullDelayNumSamples, &delayTimeScale ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nUnable to get delay of decoder: %s\n", ivas_error_to_string( error ) ); - } - if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 0 ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError in IVAS_DEC_GetMasaMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - - delayMs = (float) ( fullDelayNumSamples[0] ) / (float) ( delayTimeScale ); - if ( ( error = MasaFileWriter_writeFrame( masaWriter, hMasaExtOutMeta, &delayMs ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError writing MASA metadata to file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); - goto cleanup; - } - } - - IVAS_RTP_WriteExtPiData( ivasRtp.f_piExtOut, ivasRtp.piData, ivasRtp.nReadPiData, numObj ); - } - } - - /*------------------------------------------------------------------------------------------* - * Add zeros at the end to have equal length of synthesized signals - *------------------------------------------------------------------------------------------*/ - - memset( pcmBuf, 0, delayNumSamples_orig[0] * nOutChannels * sizeof( int16_t ) ); - -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - if ( afWriter != NULL ) - { -#endif - if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig[0] * nOutChannels ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError writing output file: %s\n", ivas_error_to_string( error ) ); - goto cleanup; - } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - } -#endif - - /*------------------------------------------------------------------------------------------* - * Printouts after decoding has finished - *------------------------------------------------------------------------------------------*/ - - if ( !arg.quietModeEnabled ) - { - 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[1] + delayNumSamples_orig[2] ) / (float) delayTimeScale, delayNumSamples_orig[1] + delayNumSamples_orig[2], delayTimeScale ); - } - } - - /* Print output metadata file name(s) */ - if ( arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) - { - if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM ) - { - for ( i = 0; i < numObj; i++ ) - { - fprintf( stdout, "\nOutput ISM metadata file: %s", IsmFileWriter_getFilePath( ismWriters[i] ) ); + fprintf( stdout, "\nOutput MASA metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); } - fprintf( stdout, "\n" ); - } - if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) - { - fprintf( stdout, "\nOutput MASA metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); + fprintf( stdout, "\nOutput PI data file: %s\n", IVAS_RTP_GetExtPiFilePath( &ivasRtp ) ); } - fprintf( stdout, "\nOutput PI data file: %s\n", IVAS_RTP_GetExtPiFilePath( &ivasRtp ) ); - } - - /*------------------------------------------------------------------------------------------* - * Close files and deallocate resources - *------------------------------------------------------------------------------------------*/ + /*------------------------------------------------------------------------------------------* + * Close files and deallocate resources + *------------------------------------------------------------------------------------------*/ - decodingFailed = false; /* This will stay set to true if cleanup is reached via a goto due to an error */ + decodingFailed = false; /* This will stay set to true if cleanup is reached via a goto due to an error */ -cleanup: + cleanup: #ifdef IVAS_RTPDUMP - IVAS_RTP_Term( &srRtp ); - IVAS_RTP_Term( &ivasRtp ); + IVAS_RTP_Term( &srRtp ); + IVAS_RTP_Term( &ivasRtp ); #else EVS_RTPDUMP_DEPACKER_close( &rtpdumpDepacker ); #endif - AudioFileWriter_close( &afWriter ); + AudioFileWriter_close( &afWriter ); #ifdef FIX_1119_SPLIT_RENDERING_VOIP - split_rend_reader_writer_close( &splitRendWriter ); + split_rend_reader_writer_close( &splitRendWriter ); #endif - JbmOffsetFileWriter_close( &jbmOffsetWriter ); + JbmOffsetFileWriter_close( &jbmOffsetWriter ); #ifdef SUPPORT_JBM_TRACEFILE - JbmTraceFileWriter_close( &jbmTraceWriter ); + JbmTraceFileWriter_close( &jbmTraceWriter ); #endif - MasaFileWriter_close( &masaWriter ); - for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; i++ ) - { - IsmFileWriter_close( &ismWriters[i] ); - } - - if ( decodingFailed && error == IVAS_ERR_OK ) - { - return IVAS_ERR_UNKNOWN; - } - - return error; -} - - -/*---------------------------------------------------------------------* - * do_object_editing() - * - * Example function to edit objects parameters - *---------------------------------------------------------------------*/ - -static void do_object_editing( - IVAS_EDITABLE_PARAMETERS *editableParameters, - ObjectEditFileReader *objectEditFileReader ) -{ - /* put the objects equally spaced at the horizontal plane */ - /* and play a little bit with the gains... */ - int16_t obj_idx, non_diegetic_obj_idx; - int16_t num_nondiegetic_objects; + MasaFileWriter_close( &masaWriter ); + for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; i++ ) + { + IsmFileWriter_close( &ismWriters[i] ); + } - num_nondiegetic_objects = 0; - for ( obj_idx = 0; obj_idx < editableParameters->num_obj; obj_idx++ ) - { - if ( !editableParameters->ism_metadata[obj_idx].non_diegetic_flag ) + if ( decodingFailed && error == IVAS_ERR_OK ) { - num_nondiegetic_objects++; + return IVAS_ERR_UNKNOWN; } + + return error; } - if ( objectEditFileReader != NULL ) + + /*---------------------------------------------------------------------* + * do_object_editing() + * + * Example function to edit objects parameters + *---------------------------------------------------------------------*/ + + static void do_object_editing( + IVAS_EDITABLE_PARAMETERS * editableParameters, + ObjectEditFileReader * objectEditFileReader ) { - ReadObjectEditInfo *readInfo; - readInfo = objectEditFileReader->readInfo; + /* put the objects equally spaced at the horizontal plane */ + /* and play a little bit with the gains... */ + int16_t obj_idx, non_diegetic_obj_idx; + int16_t num_nondiegetic_objects; - if ( readInfo->bg_gain_edited ) + num_nondiegetic_objects = 0; + for ( obj_idx = 0; obj_idx < editableParameters->num_obj; obj_idx++ ) { - editableParameters->gain_bed = readInfo->bg_gain; + if ( !editableParameters->ism_metadata[obj_idx].non_diegetic_flag ) + { + num_nondiegetic_objects++; + } } - for ( obj_idx = 0; obj_idx < editableParameters->num_obj; obj_idx++ ) + if ( objectEditFileReader != NULL ) { - if ( !editableParameters->ism_metadata[obj_idx].non_diegetic_flag ) + ReadObjectEditInfo *readInfo; + readInfo = objectEditFileReader->readInfo; + + if ( readInfo->bg_gain_edited ) { - /* object direction editing only for diegetic objects */ - if ( readInfo->obj_azi_edited[obj_idx] ) - { - if ( readInfo->obj_azi_relative[obj_idx] ) - { - /* azimuth: apply relative edit + wrap */ - editableParameters->ism_metadata[obj_idx].azimuth = fmodf( editableParameters->ism_metadata[obj_idx].azimuth + readInfo->obj_azi[obj_idx] + 540.f, 360.f ) - 180.f; - } - else - { - editableParameters->ism_metadata[obj_idx].azimuth = readInfo->obj_azi[obj_idx]; - } - } - if ( readInfo->obj_ele_edited[obj_idx] ) + editableParameters->gain_bed = readInfo->bg_gain; + } + + for ( obj_idx = 0; obj_idx < editableParameters->num_obj; obj_idx++ ) + { + if ( !editableParameters->ism_metadata[obj_idx].non_diegetic_flag ) { - if ( readInfo->obj_ele_relative[obj_idx] ) + /* object direction editing only for diegetic objects */ + if ( readInfo->obj_azi_edited[obj_idx] ) { - /* elevation: apply relative edit + saturation */ - editableParameters->ism_metadata[obj_idx].elevation = fmaxf( fminf( editableParameters->ism_metadata[obj_idx].elevation + readInfo->obj_ele[obj_idx], 90.f ), -90.f ); + if ( readInfo->obj_azi_relative[obj_idx] ) + { + /* azimuth: apply relative edit + wrap */ + editableParameters->ism_metadata[obj_idx].azimuth = fmodf( editableParameters->ism_metadata[obj_idx].azimuth + readInfo->obj_azi[obj_idx] + 540.f, 360.f ) - 180.f; + } + else + { + editableParameters->ism_metadata[obj_idx].azimuth = readInfo->obj_azi[obj_idx]; + } } - else + if ( readInfo->obj_ele_edited[obj_idx] ) { - editableParameters->ism_metadata[obj_idx].elevation = readInfo->obj_ele[obj_idx]; + if ( readInfo->obj_ele_relative[obj_idx] ) + { + /* elevation: apply relative edit + saturation */ + editableParameters->ism_metadata[obj_idx].elevation = fmaxf( fminf( editableParameters->ism_metadata[obj_idx].elevation + readInfo->obj_ele[obj_idx], 90.f ), -90.f ); + } + else + { + editableParameters->ism_metadata[obj_idx].elevation = readInfo->obj_ele[obj_idx]; + } } - } #ifdef FIX_1427_OBJ_EDITING_EXT_METADATA - /* object direction editing only for diegetic objects */ - if ( readInfo->obj_yaw_edited[obj_idx] ) - { - if ( readInfo->obj_yaw_relative[obj_idx] ) - { - /* yaw: apply relative edit + wrap */ - editableParameters->ism_metadata[obj_idx].yaw = fmodf( editableParameters->ism_metadata[obj_idx].yaw + readInfo->obj_yaw[obj_idx] + 540.f, 360.f ) - 180.f; - } - else + /* object direction editing only for diegetic objects */ + if ( readInfo->obj_yaw_edited[obj_idx] ) { - editableParameters->ism_metadata[obj_idx].yaw = readInfo->obj_yaw[obj_idx]; + if ( readInfo->obj_yaw_relative[obj_idx] ) + { + /* yaw: apply relative edit + wrap */ + editableParameters->ism_metadata[obj_idx].yaw = fmodf( editableParameters->ism_metadata[obj_idx].yaw + readInfo->obj_yaw[obj_idx] + 540.f, 360.f ) - 180.f; + } + else + { + editableParameters->ism_metadata[obj_idx].yaw = readInfo->obj_yaw[obj_idx]; + } } - } - if ( readInfo->obj_pitch_edited[obj_idx] ) - { - if ( readInfo->obj_pitch_relative[obj_idx] ) + if ( readInfo->obj_pitch_edited[obj_idx] ) { - /* pitch: apply relative edit + saturation */ - editableParameters->ism_metadata[obj_idx].pitch = fmaxf( fminf( editableParameters->ism_metadata[obj_idx].pitch + readInfo->obj_pitch[obj_idx], 90.f ), -90.f ); + if ( readInfo->obj_pitch_relative[obj_idx] ) + { + /* pitch: apply relative edit + saturation */ + editableParameters->ism_metadata[obj_idx].pitch = fmaxf( fminf( editableParameters->ism_metadata[obj_idx].pitch + readInfo->obj_pitch[obj_idx], 90.f ), -90.f ); + } + else + { + editableParameters->ism_metadata[obj_idx].pitch = readInfo->obj_pitch[obj_idx]; + } } - else + /* radius editing only for diegetic objects */ + if ( readInfo->obj_radius_edited[obj_idx] ) { - editableParameters->ism_metadata[obj_idx].pitch = readInfo->obj_pitch[obj_idx]; + if ( readInfo->obj_radius_relative[obj_idx] ) + { + /* radius: apply relative edit + saturation */ + editableParameters->ism_metadata[obj_idx].radius = fmaxf( fminf( editableParameters->ism_metadata[obj_idx].radius * readInfo->obj_radius[obj_idx], OBJ_EDIT_RADIUS_MAX ), 0.0f ); + } + else + { + editableParameters->ism_metadata[obj_idx].radius = readInfo->obj_radius[obj_idx]; + } } +#endif } - /* radius editing only for diegetic objects */ - if ( readInfo->obj_radius_edited[obj_idx] ) + + /* gain editing for all objects */ + if ( readInfo->obj_gain_edited[obj_idx] ) { - if ( readInfo->obj_radius_relative[obj_idx] ) + if ( readInfo->obj_gain_relative[obj_idx] ) { - /* radius: apply relative edit + saturation */ - editableParameters->ism_metadata[obj_idx].radius = fmaxf( fminf( editableParameters->ism_metadata[obj_idx].radius * readInfo->obj_radius[obj_idx], OBJ_EDIT_RADIUS_MAX ), 0.0f ); + /* gain: apply relative edit + saturation */ + editableParameters->ism_metadata[obj_idx].gain = fmaxf( fminf( editableParameters->ism_metadata[obj_idx].gain * readInfo->obj_gain[obj_idx], OBJ_EDIT_GAIN_MAX ), OBJ_EDIT_GAIN_MIN ); } else { - editableParameters->ism_metadata[obj_idx].radius = readInfo->obj_radius[obj_idx]; + editableParameters->ism_metadata[obj_idx].gain = readInfo->obj_gain[obj_idx]; } } -#endif - } - - /* gain editing for all objects */ - if ( readInfo->obj_gain_edited[obj_idx] ) - { - if ( readInfo->obj_gain_relative[obj_idx] ) - { - /* gain: apply relative edit + saturation */ - editableParameters->ism_metadata[obj_idx].gain = fmaxf( fminf( editableParameters->ism_metadata[obj_idx].gain * readInfo->obj_gain[obj_idx], OBJ_EDIT_GAIN_MAX ), OBJ_EDIT_GAIN_MIN ); - } - else - { - editableParameters->ism_metadata[obj_idx].gain = readInfo->obj_gain[obj_idx]; - } } } - } - else - { - if ( num_nondiegetic_objects ) + else { - float start_angle, angle_inc; - angle_inc = 360.0f / (float) num_nondiegetic_objects; - start_angle = angle_inc / 2.0f; - for ( obj_idx = 0, non_diegetic_obj_idx = 0; obj_idx < editableParameters->num_obj; obj_idx++ ) + if ( num_nondiegetic_objects ) { - if ( !editableParameters->ism_metadata[obj_idx].non_diegetic_flag ) + float start_angle, angle_inc; + angle_inc = 360.0f / (float) num_nondiegetic_objects; + start_angle = angle_inc / 2.0f; + for ( obj_idx = 0, non_diegetic_obj_idx = 0; obj_idx < editableParameters->num_obj; obj_idx++ ) { - editableParameters->ism_metadata[obj_idx].elevation = 0.0f; - editableParameters->ism_metadata[obj_idx].azimuth = start_angle + (float) non_diegetic_obj_idx * angle_inc; - non_diegetic_obj_idx++; + if ( !editableParameters->ism_metadata[obj_idx].non_diegetic_flag ) + { + editableParameters->ism_metadata[obj_idx].elevation = 0.0f; + editableParameters->ism_metadata[obj_idx].azimuth = start_angle + (float) non_diegetic_obj_idx * angle_inc; + non_diegetic_obj_idx++; + } } } - } - /* breakover object gains */ - for ( obj_idx = 0; obj_idx < editableParameters->num_obj; obj_idx++ ) - { - editableParameters->ism_metadata[obj_idx].gain = 0.5f + (float) ( ( frame + obj_idx * 50 ) % 250 ) / 250.0f; + /* breakover object gains */ + for ( obj_idx = 0; obj_idx < editableParameters->num_obj; obj_idx++ ) + { + editableParameters->ism_metadata[obj_idx].gain = 0.5f + (float) ( ( frame + obj_idx * 50 ) % 250 ) / 250.0f; + } + + editableParameters->gain_bed = 0.5f; } - editableParameters->gain_bed = 0.5f; + return; } - return; -} - - -/*---------------------------------------------------------------------* - * load_hrtf_from_file() - * - * Load HRTF coefficients from external binary file - *---------------------------------------------------------------------*/ - -static ivas_error load_hrtf_from_file( - IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, /* i/o: HRTF binary wrapper handle */ - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const IVAS_AUDIO_CONFIG OutputConfig, /* i : output audio configuration */ - const int32_t output_Fs /* i : output sampling rate */ -) -{ - ivas_error error; - IVAS_BIN_RENDERER_TYPE binaural_renderer, binaural_renderer_sec; - - if ( hHrtfBinary == NULL || hIvasDec == NULL ) - { - return IVAS_ERR_UNEXPECTED_NULL_POINTER; - } - binaural_renderer = hHrtfBinary->binaural_renderer; - binaural_renderer_sec = hHrtfBinary->binaural_renderer_sec; + /*---------------------------------------------------------------------* + * load_hrtf_from_file() + * + * Load HRTF coefficients from external binary file + *---------------------------------------------------------------------*/ - if ( ( binaural_renderer != hHrtfBinary->binaural_renderer_old ) || - ( binaural_renderer_sec != hHrtfBinary->binaural_renderer_sec_old ) || - ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) + static ivas_error load_hrtf_from_file( + IVAS_DEC_HRTF_BINARY_WRAPPER * hHrtfBinary, /* i/o: HRTF binary wrapper handle */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const IVAS_AUDIO_CONFIG OutputConfig, /* i : output audio configuration */ + const int32_t output_Fs /* i : output sampling rate */ + ) { - /*------------------------------------------------------------------------------------------* - * Release HRTF binary data - *------------------------------------------------------------------------------------------*/ + ivas_error error; + IVAS_BIN_RENDERER_TYPE binaural_renderer, binaural_renderer_sec; - if ( !( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && binaural_renderer_sec != IVAS_BIN_RENDERER_TYPE_TDREND && hHrtfBinary->hHrtfTD != NULL ) + if ( hHrtfBinary == NULL || hIvasDec == NULL ) { - destroy_td_hrtf( hHrtfBinary->hHrtfTD ); + return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - if ( ( error = IVAS_DEC_HRTF_binary_close( hIvasDec, hHrtfBinary->binaural_renderer_old ) ) != IVAS_ERR_OK ) + binaural_renderer = hHrtfBinary->binaural_renderer; + binaural_renderer_sec = hHrtfBinary->binaural_renderer_sec; + + if ( ( binaural_renderer != hHrtfBinary->binaural_renderer_old ) || + ( binaural_renderer_sec != hHrtfBinary->binaural_renderer_sec_old ) || + ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) { - return error; - } + /*------------------------------------------------------------------------------------------* + * Release HRTF binary data + *------------------------------------------------------------------------------------------*/ - /*------------------------------------------------------------------------------------------* - * Load HRTF binary data - *------------------------------------------------------------------------------------------*/ + if ( !( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && binaural_renderer_sec != IVAS_BIN_RENDERER_TYPE_TDREND && hHrtfBinary->hHrtfTD != NULL ) + { + destroy_td_hrtf( hHrtfBinary->hHrtfTD ); + } - if ( ( error = IVAS_DEC_HRTF_binary_open( hIvasDec, binaural_renderer ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = IVAS_DEC_HRTF_binary_close( hIvasDec, hHrtfBinary->binaural_renderer_old ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( ( error = IVAS_DEC_HRTF_binary_open( hIvasDec, binaural_renderer_sec ) ) != IVAS_ERR_OK ) - { - return error; - } + /*------------------------------------------------------------------------------------------* + * Load HRTF binary data + *------------------------------------------------------------------------------------------*/ - if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_sec == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) - { - if ( ( error = IVAS_DEC_GetHrtfTDrendHandle( hIvasDec, &hHrtfBinary->hHrtfTD ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_HRTF_binary_open( hIvasDec, binaural_renderer ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nIVAS_DEC_GetHrtfTDrendHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); return error; } - if ( ( error = load_TDrend_HRTF_binary( *hHrtfBinary->hHrtfTD, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_HRTF_binary_open( hIvasDec, binaural_renderer_sec ) ) != IVAS_ERR_OK ) { - if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) + return error; + } + + if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_sec == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) + { + if ( ( error = IVAS_DEC_GetHrtfTDrendHandle( hIvasDec, &hHrtfBinary->hHrtfTD ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); + fprintf( stderr, "\nIVAS_DEC_GetHrtfTDrendHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); return error; } - else + + if ( ( error = load_TDrend_HRTF_binary( *hHrtfBinary->hHrtfTD, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) { - destroy_td_hrtf( hHrtfBinary->hHrtfTD ); + if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) + { + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); + return error; + } + else + { + destroy_td_hrtf( hHrtfBinary->hHrtfTD ); + } } } - } - - if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) - { - IVAS_DEC_HRTF_CREND_HANDLE *hHrtfCrend = NULL; - if ( ( error = IVAS_DEC_GetHrtfCRendHandle( hIvasDec, &hHrtfCrend ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_GetHrtfCRendHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - return error; - } - if ( ( error = load_Crend_HRTF_from_binary( *hHrtfCrend, hHrtfBinary->hrtfReader, OutputConfig, hHrtfBinary->hrtf_set_audio_cfg, output_Fs ) ) != IVAS_ERR_OK ) + if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) { - if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) + IVAS_DEC_HRTF_CREND_HANDLE *hHrtfCrend = NULL; + if ( ( error = IVAS_DEC_GetHrtfCRendHandle( hIvasDec, &hHrtfCrend ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); + fprintf( stderr, "\nIVAS_DEC_GetHrtfCRendHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); return error; } - else + + if ( ( error = load_Crend_HRTF_from_binary( *hHrtfCrend, hHrtfBinary->hrtfReader, OutputConfig, hHrtfBinary->hrtf_set_audio_cfg, output_Fs ) ) != IVAS_ERR_OK ) { - destroy_crend_hrtf( hHrtfCrend ); + if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) + { + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); + return error; + } + else + { + destroy_crend_hrtf( hHrtfCrend ); + } } } - } - if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) - { - IVAS_DEC_HRTF_FASTCONV_HANDLE *hHrtfFastConv = NULL; - if ( ( error = IVAS_DEC_GetHrtfFastConvHandle( hIvasDec, &hHrtfFastConv ) ) != IVAS_ERR_OK ) + if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) { - fprintf( stderr, "\nIVAS_DEC_GetHrtfFastConvHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - return error; + IVAS_DEC_HRTF_FASTCONV_HANDLE *hHrtfFastConv = NULL; + if ( ( error = IVAS_DEC_GetHrtfFastConvHandle( hIvasDec, &hHrtfFastConv ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_GetHrtfFastConvHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; + } + + if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, OutputConfig, hHrtfBinary->hrtf_set_audio_cfg, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) + { + if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) + { + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); + return error; + } + else + { + destroy_fastconv_hrtf( hHrtfFastConv ); + } + } } - if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, OutputConfig, hHrtfBinary->hrtf_set_audio_cfg, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) + if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_PARAMBIN || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) { - if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) + IVAS_DEC_HRTF_PARAMBIN_HANDLE *hHrtfParambin = NULL; + if ( ( error = IVAS_DEC_GetHrtfParamBinHandle( hIvasDec, &hHrtfParambin ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); + fprintf( stderr, "\nIVAS_DEC_GetHrtfParamBinHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); return error; } - else + + if ( ( error = load_parambin_HRTF_from_binary( *hHrtfParambin, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) { - destroy_fastconv_hrtf( hHrtfFastConv ); + if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) + { + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); + return error; + } + else + { + destroy_parambin_hrtf( hHrtfParambin ); + } } } } - if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_PARAMBIN || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) + if ( hHrtfBinary->hHrtfStatistics == NULL && ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND ) && OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { - IVAS_DEC_HRTF_PARAMBIN_HANDLE *hHrtfParambin = NULL; - if ( ( error = IVAS_DEC_GetHrtfParamBinHandle( hIvasDec, &hHrtfParambin ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfBinary->hHrtfStatistics ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nIVAS_DEC_GetHrtfParamBinHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nIVAS_DEC_GetHrtfStatisticsHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); return error; } - if ( ( error = load_parambin_HRTF_from_binary( *hHrtfParambin, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) + if ( ( error = load_reverb_binary( *hHrtfBinary->hHrtfStatistics, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { @@ -4653,104 +4676,66 @@ static ivas_error load_hrtf_from_file( } else { - destroy_parambin_hrtf( hHrtfParambin ); + destroy_hrtf_statistics( hHrtfBinary->hHrtfStatistics ); } } } - } - - if ( hHrtfBinary->hHrtfStatistics == NULL && ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND ) && OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) - { - if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfBinary->hHrtfStatistics ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_GetHrtfStatisticsHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - return error; - } - if ( ( error = load_reverb_binary( *hHrtfBinary->hHrtfStatistics, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) - { - if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) - { - fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); - return error; - } - else - { - destroy_hrtf_statistics( hHrtfBinary->hHrtfStatistics ); - } - } + return IVAS_ERR_OK; } - return IVAS_ERR_OK; -} - #ifdef DECODER_FORMAT_SWITCHING -/*---------------------------------------------------------------------* - * restartDecoder() - * - * Restart decoder in case of IVAS format switching - *---------------------------------------------------------------------*/ - -static ivas_error restartDecoder( - IVAS_DEC_HANDLE *phIvasDec, - const IVAS_DEC_MODE decMode, - DecArguments *arg, - IVAS_RENDER_CONFIG_DATA *renderConfig, - IVAS_CUSTOM_LS_DATA *hLsCustomData ) -{ - ivas_error error = IVAS_ERR_OK; - IVAS_DEC_HANDLE hIvasDec; + /*---------------------------------------------------------------------* + * restartDecoder() + * + * Restart decoder in case of IVAS format switching + *---------------------------------------------------------------------*/ - if ( phIvasDec == NULL ) + static ivas_error restartDecoder( + IVAS_DEC_HANDLE * phIvasDec, + const IVAS_DEC_MODE decMode, + DecArguments *arg, + IVAS_RENDER_CONFIG_DATA *renderConfig, + IVAS_CUSTOM_LS_DATA *hLsCustomData ) { - return IVAS_ERR_UNEXPECTED_NULL_POINTER; - } + ivas_error error = IVAS_ERR_OK; + IVAS_DEC_HANDLE hIvasDec; - if ( NULL != *phIvasDec ) - { - IVAS_DEC_Close( phIvasDec ); - } + if ( phIvasDec == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } - if ( ( error = IVAS_DEC_Open( phIvasDec, decMode ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "Open failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } + if ( NULL != *phIvasDec ) + { + IVAS_DEC_Close( phIvasDec ); + } + + if ( ( error = IVAS_DEC_Open( phIvasDec, decMode ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Open failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } - arg->decMode = decMode; + arg->decMode = decMode; - hIvasDec = *phIvasDec; + hIvasDec = *phIvasDec; - uint16_t aeID = arg->aeSequence.count > 0 ? arg->aeSequence.pID[0] : 65535; + uint16_t aeID = arg->aeSequence.count > 0 ? arg->aeSequence.pID[0] : 65535; - IVAS_AUDIO_CONFIG outputConfig = ( decMode == IVAS_DEC_MODE_IVAS ) ? arg->outputConfig : IVAS_AUDIO_CONFIG_MONO; + IVAS_AUDIO_CONFIG outputConfig = ( decMode == IVAS_DEC_MODE_IVAS ) ? arg->outputConfig : IVAS_AUDIO_CONFIG_MONO; #ifdef FIX_1318_ROOM_SIZE_CMD_LINE - if ( ( error = IVAS_DEC_Configure( hIvasDec, arg->output_Fs, outputConfig, arg->renderFramesize, arg->customLsOutputEnabled, arg->hrtfReaderEnabled, - arg->enableHeadRotation, arg->enableExternalOrientation, arg->orientation_tracking, arg->renderConfigEnabled, arg->roomSize, arg->non_diegetic_pan_enabled, - arg->non_diegetic_pan_gain, arg->dpidEnabled, aeID, arg->objEditEnabled, arg->delayCompensationEnabled ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_Configure( hIvasDec, arg->output_Fs, outputConfig, arg->renderFramesize, arg->customLsOutputEnabled, arg->hrtfReaderEnabled, + arg->enableHeadRotation, arg->enableExternalOrientation, arg->orientation_tracking, arg->renderConfigEnabled, arg->roomSize, arg->non_diegetic_pan_enabled, + arg->non_diegetic_pan_gain, arg->dpidEnabled, aeID, arg->objEditEnabled, arg->delayCompensationEnabled ) ) != IVAS_ERR_OK ) #else - if ( ( error = IVAS_DEC_Configure( hIvasDec, arg->output_Fs, outputConfig, arg->renderFramesize, arg->customLsOutputEnabled, arg->hrtfReaderEnabled, - arg->enableHeadRotation, arg->enableExternalOrientation, arg->orientation_tracking, arg->renderConfigEnabled, arg->non_diegetic_pan_enabled, - arg->non_diegetic_pan_gain, arg->dpidEnabled, aeID, arg->objEditEnabled, arg->delayCompensationEnabled ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_Configure( hIvasDec, arg->output_Fs, outputConfig, arg->renderFramesize, arg->customLsOutputEnabled, arg->hrtfReaderEnabled, + arg->enableHeadRotation, arg->enableExternalOrientation, arg->orientation_tracking, arg->renderConfigEnabled, arg->non_diegetic_pan_enabled, + arg->non_diegetic_pan_gain, arg->dpidEnabled, aeID, arg->objEditEnabled, arg->delayCompensationEnabled ) ) != IVAS_ERR_OK ) #endif - { - fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - - if ( ( error = IVAS_DEC_GetRenderFramesize( hIvasDec, &arg->renderFramesize ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - -#ifndef FIX_SPLIT_RENDERING_ON_DECODER_RESTART - if ( arg->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) - { - if ( ( error = IVAS_DEC_EnableSplitRendering( hIvasDec ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nSplit rendering configure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } @@ -4760,58 +4745,73 @@ static ivas_error restartDecoder( goto cleanup; } - arg->enableHeadRotation = true; - } +#ifndef FIX_SPLIT_RENDERING_ON_DECODER_RESTART + if ( arg->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) + { + if ( ( error = IVAS_DEC_EnableSplitRendering( hIvasDec ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nSplit rendering configure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + if ( ( error = IVAS_DEC_GetRenderFramesize( hIvasDec, &arg->renderFramesize ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + arg->enableHeadRotation = true; + } #endif - if ( arg->voipMode ) - { - if ( ( error = IVAS_DEC_EnableVoIP( hIvasDec, 60, arg->inputFormat ) ) != IVAS_ERR_OK ) + if ( arg->voipMode ) { - fprintf( stderr, "\nCould not enable VOIP: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; + if ( ( error = IVAS_DEC_EnableVoIP( hIvasDec, 60, arg->inputFormat ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nCould not enable VOIP: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } } - } - if ( ( error = IVAS_DEC_PrintConfig( hIvasDec, 1, arg->voipMode ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_PrintConfig failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } + if ( ( error = IVAS_DEC_PrintConfig( hIvasDec, 1, arg->voipMode ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_PrintConfig failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } #ifdef FIX_SPLIT_RENDERING_ON_DECODER_RESTART - /* ISAR frame size is set from command line, not renderer config file. - * This will be ignored if output format is not split rendering. */ - if ( renderConfig != NULL ) - { - renderConfig->split_rend_config.isar_frame_size_ms = (int16_t) arg->renderFramesize /* given in number of 5ms subframes */ * 5; - } + /* ISAR frame size is set from command line, not renderer config file. + * This will be ignored if output format is not split rendering. */ + if ( renderConfig != NULL ) + { + renderConfig->split_rend_config.isar_frame_size_ms = (int16_t) arg->renderFramesize /* given in number of 5ms subframes */ * 5; + } #endif - if ( arg->renderConfigEnabled && renderConfig != NULL ) - { - if ( ( error = IVAS_DEC_FeedRenderConfig( hIvasDec, *renderConfig ) ) != IVAS_ERR_OK ) + if ( arg->renderConfigEnabled && renderConfig != NULL ) { - fprintf( stderr, "\nIVAS_DEC_FeedRenderConfig failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; + if ( ( error = IVAS_DEC_FeedRenderConfig( hIvasDec, *renderConfig ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_FeedRenderConfig failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } } - } - if ( arg->customLsOutputEnabled && hLsCustomData != NULL ) - { - if ( ( error = IVAS_DEC_FeedCustomLsData( hIvasDec, *hLsCustomData ) ) != IVAS_ERR_OK ) + if ( arg->customLsOutputEnabled && hLsCustomData != NULL ) { - fprintf( stderr, "\nIVAS_DEC_FeedCustomLsData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; + if ( ( error = IVAS_DEC_FeedCustomLsData( hIvasDec, *hLsCustomData ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_FeedCustomLsData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } } - } - return IVAS_ERR_OK; + return IVAS_ERR_OK; -cleanup: - IVAS_DEC_Close( phIvasDec ); - return error; -} + cleanup: + IVAS_DEC_Close( phIvasDec ); + return error; + } #endif #undef WMC_TOOL_SKIP -- GitLab From 223ab50ec30667879e5585be5c11c9cb36426799 Mon Sep 17 00:00:00 2001 From: Lauros Pajunen Date: Thu, 13 Nov 2025 12:52:01 +0200 Subject: [PATCH 18/19] Remove extra { --- apps/decoder.c | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/decoder.c b/apps/decoder.c index d1ddbde7ce..ab6629bec3 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -3665,7 +3665,6 @@ static ivas_error decodeVoIP( #endif NULL /* ToDo : Provide LS Custom Data */ ) ) != IVAS_ERR_OK ) - { { fprintf( stderr, "\nFailed to restart decoder from %d to %d\n", arg.decMode, newDecModeInPacket ); goto cleanup; -- GitLab From 7faae289357bbc6d38c61a591b33cd7c6e8cbcc4 Mon Sep 17 00:00:00 2001 From: Lauros Pajunen Date: Thu, 13 Nov 2025 12:53:40 +0200 Subject: [PATCH 19/19] Clang format --- apps/decoder.c | 1550 ++++++++++++++++++++++++------------------------ 1 file changed, 775 insertions(+), 775 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index ab6629bec3..0d8514d1c1 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -3665,166 +3665,166 @@ static ivas_error decodeVoIP( #endif NULL /* ToDo : Provide LS Custom Data */ ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nFailed to restart decoder from %d to %d\n", arg.decMode, newDecModeInPacket ); - goto cleanup; - } - - *phIvasDec = hIvasDec; /* Update for main()' s free */ - ivasRtp.restartNeeded = false; + { + fprintf( stderr, "\nFailed to restart decoder from %d to %d\n", arg.decMode, newDecModeInPacket ); + goto cleanup; } + + *phIvasDec = hIvasDec; /* Update for main()' s free */ + ivasRtp.restartNeeded = false; + } #endif - /* reference vector */ - if ( arg.enableReferenceVectorTracking && vec_pos_update == 0 ) + /* reference vector */ + if ( arg.enableReferenceVectorTracking && vec_pos_update == 0 ) + { + IVAS_VECTOR3 listenerPosition, referencePosition; + if ( ( error = Vector3PairFileReader_read( referenceVectorReader, &listenerPosition, &referencePosition ) ) != IVAS_ERR_OK ) { - IVAS_VECTOR3 listenerPosition, referencePosition; - if ( ( error = Vector3PairFileReader_read( referenceVectorReader, &listenerPosition, &referencePosition ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError %s while reading listener and reference positions from %s\n", IVAS_DEC_GetErrorMessage( error ), Vector3PairFileReader_getFilePath( referenceVectorReader ) ); - goto cleanup; - } - - if ( ( error = IVAS_DEC_FeedRefVectorData( hIvasDec, listenerPosition, referencePosition ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_FeedRefVectorData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } + fprintf( stderr, "\nError %s while reading listener and reference positions from %s\n", IVAS_DEC_GetErrorMessage( error ), Vector3PairFileReader_getFilePath( referenceVectorReader ) ); + goto cleanup; } - /* Reference rotation */ - if ( arg.enableReferenceRotation && vec_pos_update == 0 ) + if ( ( error = IVAS_DEC_FeedRefVectorData( hIvasDec, listenerPosition, referencePosition ) ) != IVAS_ERR_OK ) { - IVAS_QUATERNION quaternion; - if ( ( error = HeadRotationFileReading( refRotReader, &quaternion, NULL ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError %s while reading reference rotation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( refRotReader ) ); - goto cleanup; - } - - if ( ( error = IVAS_DEC_FeedRefRotData( hIvasDec, quaternion ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_FeedRefRotData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } + fprintf( stderr, "\nIVAS_DEC_FeedRefVectorData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; } + } - int16_t num_subframes; - if ( ( error = IVAS_DEC_GetNumOrientationSubframes( hIvasDec, &num_subframes ) ) != IVAS_ERR_OK ) + /* Reference rotation */ + if ( arg.enableReferenceRotation && vec_pos_update == 0 ) + { + IVAS_QUATERNION quaternion; + if ( ( error = HeadRotationFileReading( refRotReader, &quaternion, NULL ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nIVAS_DEC_GetNumOrientationSubframes failed: \n" ); + fprintf( stderr, "\nError %s while reading reference rotation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( refRotReader ) ); goto cleanup; } - /* Head-tracking input simulation */ - if ( arg.enableHeadRotation ) + if ( ( error = IVAS_DEC_FeedRefRotData( hIvasDec, quaternion ) ) != IVAS_ERR_OK ) { - IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; + fprintf( stderr, "\nIVAS_DEC_FeedRefRotData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } - if ( headRotReader == NULL ) - { - for ( i = 0; i < num_subframes; i++ ) - { - Quaternions[i].w = -3.0f; - Quaternions[i].x = 0.0f; - Quaternions[i].y = 0.0f; - Quaternions[i].z = 0.0f; - Pos[i].x = 0.0f; - Pos[i].y = 0.0f; - Pos[i].z = 0.0f; - } - } - else - { - for ( i = 0; i < num_subframes; i++ ) - { - if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i], &Pos[i] ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), - RotationFileReader_getFilePath( headRotReader ) ); - goto cleanup; - } - } - } + int16_t num_subframes; + if ( ( error = IVAS_DEC_GetNumOrientationSubframes( hIvasDec, &num_subframes ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_GetNumOrientationSubframes failed: \n" ); + goto cleanup; + } + /* Head-tracking input simulation */ + if ( arg.enableHeadRotation ) + { + IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; + + if ( headRotReader == NULL ) + { for ( i = 0; i < num_subframes; i++ ) { - if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[i], Pos[i], i, DEFAULT_AXIS ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_FeedHeadTrackData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } + Quaternions[i].w = -3.0f; + Quaternions[i].x = 0.0f; + Quaternions[i].y = 0.0f; + Quaternions[i].z = 0.0f; + Pos[i].x = 0.0f; + Pos[i].y = 0.0f; + Pos[i].z = 0.0f; } } - - if ( arg.enableExternalOrientation ) + else { - 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 < num_subframes; i++ ) { - - if ( ( error = ExternalOrientationFileReading( externalOrientationFileReader, &Quaternions[i], &enableHeadRotation[i], &enableExternalOrientation[i], &enableRotationInterpolation[i], &numFramesToTargetOrientation[i] ) ) != IVAS_ERR_OK ) + if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i], &Pos[i] ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError %s while reading external orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), - RotationFileReader_getFilePath( externalOrientationFileReader ) ); + fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), + RotationFileReader_getFilePath( headRotReader ) ); goto cleanup; } } - for ( i = 0; i < num_subframes; i++ ) + } + + for ( i = 0; i < num_subframes; i++ ) + { + if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[i], Pos[i], i, DEFAULT_AXIS ) ) != IVAS_ERR_OK ) { - if ( ( error = IVAS_DEC_FeedExternalOrientationData( hIvasDec, Quaternions[i], enableHeadRotation[i], enableExternalOrientation[i], enableRotationInterpolation[i], numFramesToTargetOrientation[i], i ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_FeedExternalOrientationData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } + fprintf( stderr, "\nIVAS_DEC_FeedHeadTrackData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; } } + } + + 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]; - if ( arg.objEditEnabled && arg.objEditFileName != NULL && vec_pos_update == 0 ) + for ( i = 0; i < num_subframes; i++ ) { - if ( ( error = ObjectEditFileReader_readNextFrame( objectEditFileReader ) ) != IVAS_ERR_OK ) + + if ( ( error = ExternalOrientationFileReading( externalOrientationFileReader, &Quaternions[i], &enableHeadRotation[i], &enableExternalOrientation[i], &enableRotationInterpolation[i], &numFramesToTargetOrientation[i] ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError: could not read object editing instructions from file: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - return error; + fprintf( stderr, "\nError %s while reading external orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), + RotationFileReader_getFilePath( externalOrientationFileReader ) ); + goto cleanup; } } - - /* read all packets with a receive time smaller than the system time */ - while ( nextPacketRcvTime_ms <= systemTime_ms ) + for ( i = 0; i < num_subframes; i++ ) { - /* feed the previous read packet into the receiver now */ - error = IVAS_DEC_VoIP_FeedFrame( hIvasDec, auPtr, auSize, rtpSequenceNumber, rtpTimeStamp, nextPacketRcvTime_ms, qBit ); - if ( error != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_FeedExternalOrientationData( hIvasDec, Quaternions[i], enableHeadRotation[i], enableExternalOrientation[i], enableRotationInterpolation[i], numFramesToTargetOrientation[i], i ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError in IVAS_DEC_VoIP_FeedFrame: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nIVAS_DEC_FeedExternalOrientationData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } - ++nFramesFed; + } + } - /* read the next packet */ - if ( arg.inputFormat == IVAS_DEC_INPUT_FORMAT_G192 ) - { - error = BS_Reader_ReadVoipFrame_compact( hBsReader, au, &auSize, &rtpSequenceNumber, &rtpTimeStamp, &nextPacketRcvTime_ms ); + if ( arg.objEditEnabled && arg.objEditFileName != NULL && vec_pos_update == 0 ) + { + if ( ( error = ObjectEditFileReader_readNextFrame( objectEditFileReader ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: could not read object editing instructions from file: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; + } + } - qBit = 1; /* good q_bit for VOIP_G192_RTP */ - } - else - { - auPtr = au; /* might have been set to RTP packet in prev call */ + /* read all packets with a receive time smaller than the system time */ + while ( nextPacketRcvTime_ms <= systemTime_ms ) + { + /* feed the previous read packet into the receiver now */ + error = IVAS_DEC_VoIP_FeedFrame( hIvasDec, auPtr, auSize, rtpSequenceNumber, rtpTimeStamp, nextPacketRcvTime_ms, qBit ); + if ( error != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_VoIP_FeedFrame: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + ++nFramesFed; + + /* read the next packet */ + if ( arg.inputFormat == IVAS_DEC_INPUT_FORMAT_G192 ) + { + error = BS_Reader_ReadVoipFrame_compact( hBsReader, au, &auSize, &rtpSequenceNumber, &rtpTimeStamp, &nextPacketRcvTime_ms ); + + qBit = 1; /* good q_bit for VOIP_G192_RTP */ + } + else + { + auPtr = au; /* might have been set to RTP packet in prev call */ #ifdef IVAS_RTPDUMP #ifdef RTP_S4_251135_CR26253_0016_REV1 - error = IVAS_RTP_ReadNextFrame( &ivasRtp, au, &auSize, &rtpTimeStamp, &rtpSequenceNumber, &nextPacketRcvTime_ms, NULL, &qBit ); + error = IVAS_RTP_ReadNextFrame( &ivasRtp, au, &auSize, &rtpTimeStamp, &rtpSequenceNumber, &nextPacketRcvTime_ms, NULL, &qBit ); #else - error = IVAS_RTP_ReadNextFrame( &ivasRtp, au, &auSize, &rtpTimeStamp, &rtpSequenceNumber, &nextPacketRcvTime_ms, &qBit ); + error = IVAS_RTP_ReadNextFrame( &ivasRtp, au, &auSize, &rtpTimeStamp, &rtpSequenceNumber, &nextPacketRcvTime_ms, &qBit ); #endif - /* IVAS RTP payload format has timescale 16000, JBM uses 1000 internally */ - rtpTimeStamp = rtpTimeStamp / 16; + /* IVAS RTP payload format has timescale 16000, JBM uses 1000 internally */ + rtpTimeStamp = rtpTimeStamp / 16; #else rtpdumpDepackerError = EVS_RTPDUMP_DEPACKER_readNextFrame( &rtpdumpDepacker, &rtpSequenceNumber, &rtpTimeStamp, &nextPacketRcvTime_ms, @@ -3833,384 +3833,268 @@ static ivas_error decodeVoIP( /* EVS RTP payload format has timescale 16000, JBM uses 1000 internally */ rtpTimeStamp = rtpTimeStamp / 16; #endif - } + } #ifdef IVAS_RTPDUMP - if ( error == IVAS_ERR_END_OF_FILE ) + if ( error == IVAS_ERR_END_OF_FILE ) #else if ( error == IVAS_ERR_END_OF_FILE || rtpdumpDepackerError == EVS_RTPDUMP_DEPACKER_EOF ) #endif - { - /* finished reading */ - nextPacketRcvTime_ms = (uint32_t) -1; - } + { + /* finished reading */ + nextPacketRcvTime_ms = (uint32_t) -1; + } #ifdef IVAS_RTPDUMP - else if ( error != IVAS_ERR_OK ) + else if ( error != IVAS_ERR_OK ) #else else if ( error != IVAS_ERR_OK || rtpdumpDepackerError != EVS_RTPDUMP_DEPACKER_NO_ERROR ) #endif - { - fprintf( stderr, "\nError in BS_Reader_ReadVoipFrame_compact, error code: %d\n", error ); - goto cleanup; - } - } - - /* we are finished when all packets have been received and jitter buffer is empty */ - /* also stop when the input file contains less than two frames, because JBM cannot calculate a delay value and won't start decoding */ - /* last clause should make sure that for BE tests we end up with the same number of samples...*/ - bool isEmpty; - if ( ( error = IVAS_DEC_VoIP_IsEmpty( hIvasDec, nOutSamples, &isEmpty ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nError in BS_Reader_ReadVoipFrame_compact, error code: %d\n", error ); goto cleanup; } - if ( nextPacketRcvTime_ms == (uint32_t) ( -1 ) && ( isEmpty || nFramesFed < 2 ) ) - { - break; - } + } - /* decode and get samples */ - while ( nSamplesRendered < nOutSamples ) - { -#ifdef IVAS_RTPDUMP - if ( arg.applyPiData ) - { - /* Rudimentry Time Mapping to map system time to rtp timestamp */ - uint32_t piTs = systemTime_ms * 16 + initialTsOffsetSystemAndRTP; - uint32_t numPiData = 0; + /* we are finished when all packets have been received and jitter buffer is empty */ + /* also stop when the input file contains less than two frames, because JBM cannot calculate a delay value and won't start decoding */ + /* last clause should make sure that for BE tests we end up with the same number of samples...*/ + bool isEmpty; + if ( ( error = IVAS_DEC_VoIP_IsEmpty( hIvasDec, nOutSamples, &isEmpty ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + if ( nextPacketRcvTime_ms == (uint32_t) ( -1 ) && ( isEmpty || nFramesFed < 2 ) ) + { + break; + } - while ( ivasRtp.nProcPiData + numPiData < ivasRtp.nReadPiData && - ivasRtp.piData[ivasRtp.nProcPiData + numPiData].timestamp <= piTs ) - { - numPiData++; - } + /* decode and get samples */ + while ( nSamplesRendered < nOutSamples ) + { +#ifdef IVAS_RTPDUMP + if ( arg.applyPiData ) + { + /* Rudimentry Time Mapping to map system time to rtp timestamp */ + uint32_t piTs = systemTime_ms * 16 + initialTsOffsetSystemAndRTP; + uint32_t numPiData = 0; - if ( ( error = IVAS_DEC_FeedPiDataToDecoder( hIvasDec, &ivasRtp.piData[ivasRtp.nProcPiData], numPiData ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } + while ( ivasRtp.nProcPiData + numPiData < ivasRtp.nReadPiData && + ivasRtp.piData[ivasRtp.nProcPiData + numPiData].timestamp <= piTs ) + { + numPiData++; + } - ivasRtp.nProcPiData += numPiData; + if ( ( error = IVAS_DEC_FeedPiDataToDecoder( hIvasDec, &ivasRtp.piData[ivasRtp.nProcPiData], numPiData ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; } + + ivasRtp.nProcPiData += numPiData; + } #endif #ifdef FIX_1119_SPLIT_RENDERING_VOIP - if ( isSplitRend ) - { + if ( isSplitRend ) + { #ifdef SUPPORT_JBM_TRACEFILE - if ( ( error = IVAS_DEC_VoIP_GetSplitBinauralBitstream( hIvasDec, (void *) pcmBuf, splitRendBits, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_VoIP_GetSplitBinauralBitstream( hIvasDec, (void *) pcmBuf, splitRendBits, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) #else - if ( ( error = IVAS_DEC_VoIP_GetSplitBinauralBitstream( hIvasDec, (void *) pcmBuf, splitRendBits, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_VoIP_GetSplitBinauralBitstream( hIvasDec, (void *) pcmBuf, splitRendBits, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) #endif - { - fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSplitBinauralBitstream: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - } - else { + fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSplitBinauralBitstream: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } + else + { #endif #ifdef SUPPORT_JBM_TRACEFILE - if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, &bitstreamReadDone, &nSamplesRendered, ¶meterAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) #endif - { - fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP + { + fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; } +#ifdef FIX_1119_SPLIT_RENDERING_VOIP + } #endif - if ( bitstreamReadDone == true ) + if ( bitstreamReadDone == true ) + { + /* Read main parameters from the bitstream to set-up the decoder */ + hHrtf->binaural_renderer_old = hHrtf->binaural_renderer; + hHrtf->binaural_renderer_sec_old = hHrtf->binaural_renderer_sec; + if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer, &hHrtf->binaural_renderer_sec, &hHrtf->hrtf_set_audio_cfg ) ) != IVAS_ERR_OK ) { - /* Read main parameters from the bitstream to set-up the decoder */ - hHrtf->binaural_renderer_old = hHrtf->binaural_renderer; - hHrtf->binaural_renderer_sec_old = hHrtf->binaural_renderer_sec; - if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer, &hHrtf->binaural_renderer_sec, &hHrtf->hrtf_set_audio_cfg ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; + } #ifdef DECODER_FORMAT_SWITCHING - /* restart decoder in case of format switching */ - if ( ( error = IVAS_DEC_isRestartNeeded( hIvasDec, &restartNeeded ) ) != IVAS_ERR_OK ) - { - return error; - } - - if ( restartNeeded ) - { - IVAS_DEC_BS_FORMAT tempBsFormat; - if ( ( error = IVAS_DEC_GetFormat( hIvasDec, &tempBsFormat ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError in IVAS_DEC_GetFormat, code: %d\n", error ); - goto cleanup; - } - - IVAS_DEC_MODE newDecModeInPacket = ( tempBsFormat == IVAS_DEC_BS_MONO ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; - if ( ( error = restartDecoder( - &hIvasDec, - newDecModeInPacket, - &arg, - NULL, /* ToDo : Provide rendererConfig */ - NULL /* ToDo : Provide LS Custom Data */ - ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nFailed to restart decoder\n" ); - goto cleanup; - } - *phIvasDec = hIvasDec; /* Update for main()' s free */ - } -#endif - - /* Placeholder for memory reallocation */ - /* ... */ - - /* Load HRTF binary file data */ - if ( arg.hrtfReaderEnabled ) - { - if ( ( error = load_hrtf_from_file( hHrtf, hIvasDec, arg.outputConfig, arg.output_Fs ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_LoadHrtfFromFile failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - } + /* restart decoder in case of format switching */ + if ( ( error = IVAS_DEC_isRestartNeeded( hIvasDec, &restartNeeded ) ) != IVAS_ERR_OK ) + { + return error; } - /* Object metadata editing */ - if ( arg.objEditEnabled && parametersAvailableForEditing == true ) + if ( restartNeeded ) { - IVAS_EDITABLE_PARAMETERS editableParameters; - - /* get object parameters */ - if ( ( error = IVAS_DEC_GetEditableParameters( hIvasDec, &editableParameters ) ) != IVAS_ERR_OK ) + IVAS_DEC_BS_FORMAT tempBsFormat; + if ( ( error = IVAS_DEC_GetFormat( hIvasDec, &tempBsFormat ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError: could not get the editable parameters: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - return error; + fprintf( stderr, "\nError in IVAS_DEC_GetFormat, code: %d\n", error ); + goto cleanup; } - /* Do object metadata editing here ... */ - do_object_editing( &editableParameters, objectEditFileReader ); - - /* set new object parameters */ - if ( ( error = IVAS_DEC_SetEditableParameters( hIvasDec, editableParameters ) ) != IVAS_ERR_OK ) + IVAS_DEC_MODE newDecModeInPacket = ( tempBsFormat == IVAS_DEC_BS_MONO ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; + if ( ( error = restartDecoder( + &hIvasDec, + newDecModeInPacket, + &arg, + NULL, /* ToDo : Provide rendererConfig */ + NULL /* ToDo : Provide LS Custom Data */ + ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError: could not set the editable parameters: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - return error; + fprintf( stderr, "\nFailed to restart decoder\n" ); + goto cleanup; } + *phIvasDec = hIvasDec; /* Update for main()' s free */ } - } /* while ( nSamplesRendered < nOutSamples ) */ - - /* write JBM Offset file entry */ - if ( jbmOffsetWriter != NULL ) - { - int16_t optimum_offset, FEC_hi; - - if ( ( error = IVAS_DEC_VoIP_Get_CA_offset( hIvasDec, &optimum_offset, &FEC_hi ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError in IVAS_DEC_VoIP_Get_CA_offset: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - - if ( ( JbmOffsetFileWriter_writeFrame( FEC_hi, optimum_offset, jbmOffsetWriter ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError writing JBM Offset data to file %s\n", arg.jbmOffsetFilename ); - goto cleanup; - } - } +#endif - /* Continue checking for first good frame until it is found */ - if ( !decodedGoodFrame ) - { - if ( ( error = IVAS_DEC_HasDecodedFirstGoodFrame( hIvasDec, &decodedGoodFrame ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "Error in IVAS_DEC_HasDecodedFirstGoodFrame(): %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } + /* Placeholder for memory reallocation */ + /* ... */ - /* Once good frame decoded, catch up */ - if ( decodedGoodFrame ) + /* Load HRTF binary file data */ + if ( arg.hrtfReaderEnabled ) { -#ifndef FIX_1119_SPLIT_RENDERING_VOIP - SplitFileReadWrite *splitRendWriter = NULL; - -#endif -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, &vec_pos_len, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, -#else - if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, NULL, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, -#endif -#ifdef IVAS_RTPDUMP - &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &srRtp, &splitRendWriter ) ) != IVAS_ERR_OK ) -#else - &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &splitRendWriter ) ) != IVAS_ERR_OK ) -#endif + if ( ( error = load_hrtf_from_file( hHrtf, hIvasDec, arg.outputConfig, arg.output_Fs ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "Error in initOnFirstGoodFrame(): %s\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nIVAS_DEC_LoadHrtfFromFile failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } } - else - { - ++numInitialBadFrames; - } } - /* Write current frame */ -#ifdef IVAS_RTPDUMP - if ( !srRtp.hPack && decodedGoodFrame ) -#else - if ( decodedGoodFrame ) -#endif + /* Object metadata editing */ + if ( arg.objEditEnabled && parametersAvailableForEditing == true ) { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - if ( isSplitRend ) - { - if ( split_rend_write_bitstream_to_file( splitRendWriter, splitRendBits->bits_buf, &splitRendBits->bits_read, &splitRendBits->bits_written ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nUnable to write to bitstream file!\n" ); - goto cleanup; - } - } + IVAS_EDITABLE_PARAMETERS editableParameters; - if ( !isSplitCoded ) + /* get object parameters */ + if ( ( error = IVAS_DEC_GetEditableParameters( hIvasDec, &editableParameters ) ) != IVAS_ERR_OK ) { -#endif - if ( delayNumSamples < nOutSamples ) - { - if ( ( error = AudioFileWriter_write( afWriter, &pcmBuf[delayNumSamples * nOutChannels], nOutSamples * nOutChannels - ( delayNumSamples * nOutChannels ) ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nOutput audio file writer error\n" ); - goto cleanup; - } - delayNumSamples = 0; - } - else - { - delayNumSamples -= nOutSamples; - } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP + fprintf( stderr, "\nError: could not get the editable parameters: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; } -#endif - /* Write ISM metadata to external file(s) */ - if ( decodedGoodFrame && arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) - { - if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM ) - { - if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, &numObj ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError in IVAS_DEC_GetNumObjects: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } + /* Do object metadata editing here ... */ + do_object_editing( &editableParameters, objectEditFileReader ); - for ( i = 0; i < numObj; ++i ) - { - IVAS_ISM_METADATA IsmMetadata; + /* set new object parameters */ + if ( ( error = IVAS_DEC_SetEditableParameters( hIvasDec, editableParameters ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: could not set the editable parameters: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; + } + } + } /* while ( nSamplesRendered < nOutSamples ) */ - if ( ( error = IVAS_DEC_GetObjectMetadata( hIvasDec, &IsmMetadata, 0, i ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError in IVAS_DEC_GetObjectMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } + /* write JBM Offset file entry */ + if ( jbmOffsetWriter != NULL ) + { + int16_t optimum_offset, FEC_hi; - if ( ( IsmFileWriter_writeFrame( IsmMetadata, ismWriters[i] ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError writing ISM metadata to file %s\n", IsmFileWriter_getFilePath( ismWriters[i] ) ); - goto cleanup; - } - } - } + if ( ( error = IVAS_DEC_VoIP_Get_CA_offset( hIvasDec, &optimum_offset, &FEC_hi ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_VoIP_Get_CA_offset: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } - if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) - { - IVAS_MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta; - int16_t fullDelayNumSamples[3]; - float delayMs; + if ( ( JbmOffsetFileWriter_writeFrame( FEC_hi, optimum_offset, jbmOffsetWriter ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError writing JBM Offset data to file %s\n", arg.jbmOffsetFilename ); + goto cleanup; + } + } - /* delayNumSamples_orig is fetched only for the first good frame, but here the delay can change between frames, so need to re-fetch */ - if ( ( error = IVAS_DEC_GetDelay( hIvasDec, fullDelayNumSamples, &delayTimeScale ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nUnable to get delay of decoder: %s\n", ivas_error_to_string( error ) ); - } - if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 1 ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError in IVAS_DEC_GetMasaMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } + /* Continue checking for first good frame until it is found */ + if ( !decodedGoodFrame ) + { + if ( ( error = IVAS_DEC_HasDecodedFirstGoodFrame( hIvasDec, &decodedGoodFrame ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Error in IVAS_DEC_HasDecodedFirstGoodFrame(): %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } - delayMs = (float) ( fullDelayNumSamples[0] ) / (float) ( delayTimeScale ); - if ( ( error = MasaFileWriter_writeFrame( masaWriter, hMasaExtOutMeta, &delayMs ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError writing MASA metadata to file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); - goto cleanup; - } - } + /* Once good frame decoded, catch up */ + if ( decodedGoodFrame ) + { +#ifndef FIX_1119_SPLIT_RENDERING_VOIP + SplitFileReadWrite *splitRendWriter = NULL; - IVAS_RTP_WriteExtPiData( ivasRtp.f_piExtOut, ivasRtp.piData, ivasRtp.nReadPiData, numObj ); - } - } +#endif +#ifdef FIX_1119_SPLIT_RENDERING_VOIP + if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, &vec_pos_len, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, +#else + if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, NULL, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, +#endif #ifdef IVAS_RTPDUMP - else if ( decodedGoodFrame ) - { - srInfo.bitrateKbps = splitRendBits->bits_written * 1000 / splitRendBits->codec_frame_size_ms; - srInfo.codec = ( splitRendBits->codec == ISAR_SPLIT_REND_CODEC_LC3PLUS ) ? IVAS_SR_TRANSPORT_LC3PLUS : IVAS_SR_TRANSPORT_LCLD; - if ( ( error = IVAS_RTP_WriteNextFrame( &srRtp, splitRendBits->bits_buf, &srInfo, (int16_t) splitRendBits->bits_written, false, false ) ) != IVAS_ERR_OK ) + &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &srRtp, &splitRendWriter ) ) != IVAS_ERR_OK ) +#else + &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &splitRendWriter ) ) != IVAS_ERR_OK ) +#endif { - fprintf( stderr, "\nError %s while pushing SR audio bitstream to RTP pack\n", ivas_error_to_string( error ) ); + fprintf( stderr, "Error in initOnFirstGoodFrame(): %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } - splitRendBits->bits_written = 0; - splitRendBits->bits_read = 0; } -#endif - - vec_pos_update = ( vec_pos_update + 1 ) % vec_pos_len; - if ( vec_pos_update == 0 ) + else { - systemTime_ms += vec_pos_len * systemTimeInc_ms; + ++numInitialBadFrames; } + } - if ( vec_pos_update == 0 ) + /* Write current frame */ +#ifdef IVAS_RTPDUMP + if ( !srRtp.hPack && decodedGoodFrame ) +#else + if ( decodedGoodFrame ) +#endif + { +#ifdef FIX_1119_SPLIT_RENDERING_VOIP + if ( isSplitRend ) { - frame++; - if ( !arg.quietModeEnabled ) + if ( split_rend_write_bitstream_to_file( splitRendWriter, splitRendBits->bits_buf, &splitRendBits->bits_read, &splitRendBits->bits_written ) != IVAS_ERR_OK ) { - fprintf( stdout, "%-8d\b\b\b\b\b\b\b\b", frame ); + fprintf( stderr, "\nUnable to write to bitstream file!\n" ); + goto cleanup; } } -#ifdef WMOPS - update_mem(); - update_wmops(); + if ( !isSplitCoded ) + { #endif - } - - - int16_t nSamplesFlushed = 0; - - /* decode and get samples */ - if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, &nSamplesFlushed ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError in IVAS_DEC_VoIP_Flush: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - + if ( delayNumSamples < nOutSamples ) + { + if ( ( error = AudioFileWriter_write( afWriter, &pcmBuf[delayNumSamples * nOutChannels], nOutSamples * nOutChannels - ( delayNumSamples * nOutChannels ) ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nOutput audio file writer error\n" ); + goto cleanup; + } + delayNumSamples = 0; + } + else + { + delayNumSamples -= nOutSamples; + } #ifdef FIX_1119_SPLIT_RENDERING_VOIP - if ( nSamplesFlushed && !isSplitCoded ) -#else - if ( nSamplesFlushed ) -#endif - { - /* Write current frame */ - if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, nSamplesFlushed * nOutChannels ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nOutput audio file writer error\n" ); - goto cleanup; } +#endif - /* Write ISm metadata to external file(s) */ + /* Write ISM metadata to external file(s) */ if ( decodedGoodFrame && arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) { if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM ) @@ -4245,12 +4129,12 @@ static ivas_error decodeVoIP( int16_t fullDelayNumSamples[3]; float delayMs; - /* delayNumSamples is zeroed, and delayNumSamples_orig is updated only on first good frame, so need to re-fetch delay info */ + /* delayNumSamples_orig is fetched only for the first good frame, but here the delay can change between frames, so need to re-fetch */ if ( ( error = IVAS_DEC_GetDelay( hIvasDec, fullDelayNumSamples, &delayTimeScale ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nUnable to get delay of decoder: %s\n", ivas_error_to_string( error ) ); } - if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 0 ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 1 ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_DEC_GetMasaMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -4267,406 +4151,499 @@ static ivas_error decodeVoIP( IVAS_RTP_WriteExtPiData( ivasRtp.f_piExtOut, ivasRtp.piData, ivasRtp.nReadPiData, numObj ); } } - - /*------------------------------------------------------------------------------------------* - * Add zeros at the end to have equal length of synthesized signals - *------------------------------------------------------------------------------------------*/ - - memset( pcmBuf, 0, delayNumSamples_orig[0] * nOutChannels * sizeof( int16_t ) ); - -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - if ( afWriter != NULL ) +#ifdef IVAS_RTPDUMP + else if ( decodedGoodFrame ) { -#endif - if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig[0] * nOutChannels ) ) != IVAS_ERR_OK ) + srInfo.bitrateKbps = splitRendBits->bits_written * 1000 / splitRendBits->codec_frame_size_ms; + srInfo.codec = ( splitRendBits->codec == ISAR_SPLIT_REND_CODEC_LC3PLUS ) ? IVAS_SR_TRANSPORT_LC3PLUS : IVAS_SR_TRANSPORT_LCLD; + if ( ( error = IVAS_RTP_WriteNextFrame( &srRtp, splitRendBits->bits_buf, &srInfo, (int16_t) splitRendBits->bits_written, false, false ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError writing output file: %s\n", ivas_error_to_string( error ) ); + fprintf( stderr, "\nError %s while pushing SR audio bitstream to RTP pack\n", ivas_error_to_string( error ) ); goto cleanup; } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP + splitRendBits->bits_written = 0; + splitRendBits->bits_read = 0; } #endif - /*------------------------------------------------------------------------------------------* - * Printouts after decoding has finished - *------------------------------------------------------------------------------------------*/ - - if ( !arg.quietModeEnabled ) + vec_pos_update = ( vec_pos_update + 1 ) % vec_pos_len; + if ( vec_pos_update == 0 ) { - 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 ); + systemTime_ms += vec_pos_len * systemTimeInc_ms; + } - if ( delayNumSamples_orig[2] > 0 ) + if ( vec_pos_update == 0 ) + { + frame++; + if ( !arg.quietModeEnabled ) { - 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[1] + delayNumSamples_orig[2] ) / (float) delayTimeScale, delayNumSamples_orig[1] + delayNumSamples_orig[2], delayTimeScale ); + fprintf( stdout, "%-8d\b\b\b\b\b\b\b\b", frame ); } } - /* Print output metadata file name(s) */ - if ( arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) +#ifdef WMOPS + update_mem(); + update_wmops(); +#endif + } + + + int16_t nSamplesFlushed = 0; + + /* decode and get samples */ + if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, &nSamplesFlushed ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_VoIP_Flush: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + +#ifdef FIX_1119_SPLIT_RENDERING_VOIP + if ( nSamplesFlushed && !isSplitCoded ) +#else + if ( nSamplesFlushed ) +#endif + { + /* Write current frame */ + if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, nSamplesFlushed * nOutChannels ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nOutput audio file writer error\n" ); + goto cleanup; + } + + /* Write ISm metadata to external file(s) */ + if ( decodedGoodFrame && arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) { if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM ) { - for ( i = 0; i < numObj; i++ ) + if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, &numObj ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_GetNumObjects: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + for ( i = 0; i < numObj; ++i ) { - fprintf( stdout, "\nOutput ISM metadata file: %s", IsmFileWriter_getFilePath( ismWriters[i] ) ); + IVAS_ISM_METADATA IsmMetadata; + + if ( ( error = IVAS_DEC_GetObjectMetadata( hIvasDec, &IsmMetadata, 0, i ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_GetObjectMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + if ( ( IsmFileWriter_writeFrame( IsmMetadata, ismWriters[i] ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError writing ISM metadata to file %s\n", IsmFileWriter_getFilePath( ismWriters[i] ) ); + goto cleanup; + } } - fprintf( stdout, "\n" ); } if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) { - fprintf( stdout, "\nOutput MASA metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); + IVAS_MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta; + int16_t fullDelayNumSamples[3]; + float delayMs; + + /* delayNumSamples is zeroed, and delayNumSamples_orig is updated only on first good frame, so need to re-fetch delay info */ + if ( ( error = IVAS_DEC_GetDelay( hIvasDec, fullDelayNumSamples, &delayTimeScale ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nUnable to get delay of decoder: %s\n", ivas_error_to_string( error ) ); + } + if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 0 ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_GetMasaMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + delayMs = (float) ( fullDelayNumSamples[0] ) / (float) ( delayTimeScale ); + if ( ( error = MasaFileWriter_writeFrame( masaWriter, hMasaExtOutMeta, &delayMs ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError writing MASA metadata to file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); + goto cleanup; + } + } + + IVAS_RTP_WriteExtPiData( ivasRtp.f_piExtOut, ivasRtp.piData, ivasRtp.nReadPiData, numObj ); + } + } + + /*------------------------------------------------------------------------------------------* + * Add zeros at the end to have equal length of synthesized signals + *------------------------------------------------------------------------------------------*/ + + memset( pcmBuf, 0, delayNumSamples_orig[0] * nOutChannels * sizeof( int16_t ) ); + +#ifdef FIX_1119_SPLIT_RENDERING_VOIP + if ( afWriter != NULL ) + { +#endif + if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig[0] * nOutChannels ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError writing output file: %s\n", ivas_error_to_string( error ) ); + goto cleanup; + } +#ifdef FIX_1119_SPLIT_RENDERING_VOIP + } +#endif + + /*------------------------------------------------------------------------------------------* + * Printouts after decoding has finished + *------------------------------------------------------------------------------------------*/ + + if ( !arg.quietModeEnabled ) + { + 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[1] + delayNumSamples_orig[2] ) / (float) delayTimeScale, delayNumSamples_orig[1] + delayNumSamples_orig[2], delayTimeScale ); + } + } + + /* Print output metadata file name(s) */ + if ( arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) + { + if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM ) + { + for ( i = 0; i < numObj; i++ ) + { + fprintf( stdout, "\nOutput ISM metadata file: %s", IsmFileWriter_getFilePath( ismWriters[i] ) ); } + fprintf( stdout, "\n" ); + } - fprintf( stdout, "\nOutput PI data file: %s\n", IVAS_RTP_GetExtPiFilePath( &ivasRtp ) ); + if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) + { + fprintf( stdout, "\nOutput MASA metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); } - /*------------------------------------------------------------------------------------------* - * Close files and deallocate resources - *------------------------------------------------------------------------------------------*/ + fprintf( stdout, "\nOutput PI data file: %s\n", IVAS_RTP_GetExtPiFilePath( &ivasRtp ) ); + } + + /*------------------------------------------------------------------------------------------* + * Close files and deallocate resources + *------------------------------------------------------------------------------------------*/ - decodingFailed = false; /* This will stay set to true if cleanup is reached via a goto due to an error */ + decodingFailed = false; /* This will stay set to true if cleanup is reached via a goto due to an error */ - cleanup: +cleanup: #ifdef IVAS_RTPDUMP - IVAS_RTP_Term( &srRtp ); - IVAS_RTP_Term( &ivasRtp ); + IVAS_RTP_Term( &srRtp ); + IVAS_RTP_Term( &ivasRtp ); #else EVS_RTPDUMP_DEPACKER_close( &rtpdumpDepacker ); #endif - AudioFileWriter_close( &afWriter ); + AudioFileWriter_close( &afWriter ); #ifdef FIX_1119_SPLIT_RENDERING_VOIP - split_rend_reader_writer_close( &splitRendWriter ); + split_rend_reader_writer_close( &splitRendWriter ); #endif - JbmOffsetFileWriter_close( &jbmOffsetWriter ); + JbmOffsetFileWriter_close( &jbmOffsetWriter ); #ifdef SUPPORT_JBM_TRACEFILE - JbmTraceFileWriter_close( &jbmTraceWriter ); + JbmTraceFileWriter_close( &jbmTraceWriter ); #endif - MasaFileWriter_close( &masaWriter ); - for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; i++ ) - { - IsmFileWriter_close( &ismWriters[i] ); - } - - if ( decodingFailed && error == IVAS_ERR_OK ) - { - return IVAS_ERR_UNKNOWN; - } + MasaFileWriter_close( &masaWriter ); + for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; i++ ) + { + IsmFileWriter_close( &ismWriters[i] ); + } - return error; + if ( decodingFailed && error == IVAS_ERR_OK ) + { + return IVAS_ERR_UNKNOWN; } + return error; +} - /*---------------------------------------------------------------------* - * do_object_editing() - * - * Example function to edit objects parameters - *---------------------------------------------------------------------*/ - static void do_object_editing( - IVAS_EDITABLE_PARAMETERS * editableParameters, - ObjectEditFileReader * objectEditFileReader ) - { - /* put the objects equally spaced at the horizontal plane */ - /* and play a little bit with the gains... */ - int16_t obj_idx, non_diegetic_obj_idx; - int16_t num_nondiegetic_objects; +/*---------------------------------------------------------------------* + * do_object_editing() + * + * Example function to edit objects parameters + *---------------------------------------------------------------------*/ - num_nondiegetic_objects = 0; - for ( obj_idx = 0; obj_idx < editableParameters->num_obj; obj_idx++ ) +static void do_object_editing( + IVAS_EDITABLE_PARAMETERS *editableParameters, + ObjectEditFileReader *objectEditFileReader ) +{ + /* put the objects equally spaced at the horizontal plane */ + /* and play a little bit with the gains... */ + int16_t obj_idx, non_diegetic_obj_idx; + int16_t num_nondiegetic_objects; + + num_nondiegetic_objects = 0; + for ( obj_idx = 0; obj_idx < editableParameters->num_obj; obj_idx++ ) + { + if ( !editableParameters->ism_metadata[obj_idx].non_diegetic_flag ) { - if ( !editableParameters->ism_metadata[obj_idx].non_diegetic_flag ) - { - num_nondiegetic_objects++; - } + num_nondiegetic_objects++; } + } - if ( objectEditFileReader != NULL ) - { - ReadObjectEditInfo *readInfo; - readInfo = objectEditFileReader->readInfo; + if ( objectEditFileReader != NULL ) + { + ReadObjectEditInfo *readInfo; + readInfo = objectEditFileReader->readInfo; - if ( readInfo->bg_gain_edited ) - { - editableParameters->gain_bed = readInfo->bg_gain; - } + if ( readInfo->bg_gain_edited ) + { + editableParameters->gain_bed = readInfo->bg_gain; + } - for ( obj_idx = 0; obj_idx < editableParameters->num_obj; obj_idx++ ) + for ( obj_idx = 0; obj_idx < editableParameters->num_obj; obj_idx++ ) + { + if ( !editableParameters->ism_metadata[obj_idx].non_diegetic_flag ) { - if ( !editableParameters->ism_metadata[obj_idx].non_diegetic_flag ) + /* object direction editing only for diegetic objects */ + if ( readInfo->obj_azi_edited[obj_idx] ) + { + if ( readInfo->obj_azi_relative[obj_idx] ) + { + /* azimuth: apply relative edit + wrap */ + editableParameters->ism_metadata[obj_idx].azimuth = fmodf( editableParameters->ism_metadata[obj_idx].azimuth + readInfo->obj_azi[obj_idx] + 540.f, 360.f ) - 180.f; + } + else + { + editableParameters->ism_metadata[obj_idx].azimuth = readInfo->obj_azi[obj_idx]; + } + } + if ( readInfo->obj_ele_edited[obj_idx] ) { - /* object direction editing only for diegetic objects */ - if ( readInfo->obj_azi_edited[obj_idx] ) + if ( readInfo->obj_ele_relative[obj_idx] ) { - if ( readInfo->obj_azi_relative[obj_idx] ) - { - /* azimuth: apply relative edit + wrap */ - editableParameters->ism_metadata[obj_idx].azimuth = fmodf( editableParameters->ism_metadata[obj_idx].azimuth + readInfo->obj_azi[obj_idx] + 540.f, 360.f ) - 180.f; - } - else - { - editableParameters->ism_metadata[obj_idx].azimuth = readInfo->obj_azi[obj_idx]; - } + /* elevation: apply relative edit + saturation */ + editableParameters->ism_metadata[obj_idx].elevation = fmaxf( fminf( editableParameters->ism_metadata[obj_idx].elevation + readInfo->obj_ele[obj_idx], 90.f ), -90.f ); } - if ( readInfo->obj_ele_edited[obj_idx] ) + else { - if ( readInfo->obj_ele_relative[obj_idx] ) - { - /* elevation: apply relative edit + saturation */ - editableParameters->ism_metadata[obj_idx].elevation = fmaxf( fminf( editableParameters->ism_metadata[obj_idx].elevation + readInfo->obj_ele[obj_idx], 90.f ), -90.f ); - } - else - { - editableParameters->ism_metadata[obj_idx].elevation = readInfo->obj_ele[obj_idx]; - } + editableParameters->ism_metadata[obj_idx].elevation = readInfo->obj_ele[obj_idx]; } + } #ifdef FIX_1427_OBJ_EDITING_EXT_METADATA - /* object direction editing only for diegetic objects */ - if ( readInfo->obj_yaw_edited[obj_idx] ) + /* object direction editing only for diegetic objects */ + if ( readInfo->obj_yaw_edited[obj_idx] ) + { + if ( readInfo->obj_yaw_relative[obj_idx] ) { - if ( readInfo->obj_yaw_relative[obj_idx] ) - { - /* yaw: apply relative edit + wrap */ - editableParameters->ism_metadata[obj_idx].yaw = fmodf( editableParameters->ism_metadata[obj_idx].yaw + readInfo->obj_yaw[obj_idx] + 540.f, 360.f ) - 180.f; - } - else - { - editableParameters->ism_metadata[obj_idx].yaw = readInfo->obj_yaw[obj_idx]; - } + /* yaw: apply relative edit + wrap */ + editableParameters->ism_metadata[obj_idx].yaw = fmodf( editableParameters->ism_metadata[obj_idx].yaw + readInfo->obj_yaw[obj_idx] + 540.f, 360.f ) - 180.f; } - if ( readInfo->obj_pitch_edited[obj_idx] ) + else { - if ( readInfo->obj_pitch_relative[obj_idx] ) - { - /* pitch: apply relative edit + saturation */ - editableParameters->ism_metadata[obj_idx].pitch = fmaxf( fminf( editableParameters->ism_metadata[obj_idx].pitch + readInfo->obj_pitch[obj_idx], 90.f ), -90.f ); - } - else - { - editableParameters->ism_metadata[obj_idx].pitch = readInfo->obj_pitch[obj_idx]; - } + editableParameters->ism_metadata[obj_idx].yaw = readInfo->obj_yaw[obj_idx]; } - /* radius editing only for diegetic objects */ - if ( readInfo->obj_radius_edited[obj_idx] ) + } + if ( readInfo->obj_pitch_edited[obj_idx] ) + { + if ( readInfo->obj_pitch_relative[obj_idx] ) { - if ( readInfo->obj_radius_relative[obj_idx] ) - { - /* radius: apply relative edit + saturation */ - editableParameters->ism_metadata[obj_idx].radius = fmaxf( fminf( editableParameters->ism_metadata[obj_idx].radius * readInfo->obj_radius[obj_idx], OBJ_EDIT_RADIUS_MAX ), 0.0f ); - } - else - { - editableParameters->ism_metadata[obj_idx].radius = readInfo->obj_radius[obj_idx]; - } + /* pitch: apply relative edit + saturation */ + editableParameters->ism_metadata[obj_idx].pitch = fmaxf( fminf( editableParameters->ism_metadata[obj_idx].pitch + readInfo->obj_pitch[obj_idx], 90.f ), -90.f ); + } + else + { + editableParameters->ism_metadata[obj_idx].pitch = readInfo->obj_pitch[obj_idx]; } -#endif } - - /* gain editing for all objects */ - if ( readInfo->obj_gain_edited[obj_idx] ) + /* radius editing only for diegetic objects */ + if ( readInfo->obj_radius_edited[obj_idx] ) { - if ( readInfo->obj_gain_relative[obj_idx] ) + if ( readInfo->obj_radius_relative[obj_idx] ) { - /* gain: apply relative edit + saturation */ - editableParameters->ism_metadata[obj_idx].gain = fmaxf( fminf( editableParameters->ism_metadata[obj_idx].gain * readInfo->obj_gain[obj_idx], OBJ_EDIT_GAIN_MAX ), OBJ_EDIT_GAIN_MIN ); + /* radius: apply relative edit + saturation */ + editableParameters->ism_metadata[obj_idx].radius = fmaxf( fminf( editableParameters->ism_metadata[obj_idx].radius * readInfo->obj_radius[obj_idx], OBJ_EDIT_RADIUS_MAX ), 0.0f ); } else { - editableParameters->ism_metadata[obj_idx].gain = readInfo->obj_gain[obj_idx]; + editableParameters->ism_metadata[obj_idx].radius = readInfo->obj_radius[obj_idx]; } } +#endif } - } - else - { - if ( num_nondiegetic_objects ) + + /* gain editing for all objects */ + if ( readInfo->obj_gain_edited[obj_idx] ) { - float start_angle, angle_inc; - angle_inc = 360.0f / (float) num_nondiegetic_objects; - start_angle = angle_inc / 2.0f; - for ( obj_idx = 0, non_diegetic_obj_idx = 0; obj_idx < editableParameters->num_obj; obj_idx++ ) + if ( readInfo->obj_gain_relative[obj_idx] ) { - if ( !editableParameters->ism_metadata[obj_idx].non_diegetic_flag ) - { - editableParameters->ism_metadata[obj_idx].elevation = 0.0f; - editableParameters->ism_metadata[obj_idx].azimuth = start_angle + (float) non_diegetic_obj_idx * angle_inc; - non_diegetic_obj_idx++; - } + /* gain: apply relative edit + saturation */ + editableParameters->ism_metadata[obj_idx].gain = fmaxf( fminf( editableParameters->ism_metadata[obj_idx].gain * readInfo->obj_gain[obj_idx], OBJ_EDIT_GAIN_MAX ), OBJ_EDIT_GAIN_MIN ); + } + else + { + editableParameters->ism_metadata[obj_idx].gain = readInfo->obj_gain[obj_idx]; } } - - /* breakover object gains */ - for ( obj_idx = 0; obj_idx < editableParameters->num_obj; obj_idx++ ) + } + } + else + { + if ( num_nondiegetic_objects ) + { + float start_angle, angle_inc; + angle_inc = 360.0f / (float) num_nondiegetic_objects; + start_angle = angle_inc / 2.0f; + for ( obj_idx = 0, non_diegetic_obj_idx = 0; obj_idx < editableParameters->num_obj; obj_idx++ ) { - editableParameters->ism_metadata[obj_idx].gain = 0.5f + (float) ( ( frame + obj_idx * 50 ) % 250 ) / 250.0f; + if ( !editableParameters->ism_metadata[obj_idx].non_diegetic_flag ) + { + editableParameters->ism_metadata[obj_idx].elevation = 0.0f; + editableParameters->ism_metadata[obj_idx].azimuth = start_angle + (float) non_diegetic_obj_idx * angle_inc; + non_diegetic_obj_idx++; + } } + } - editableParameters->gain_bed = 0.5f; + /* breakover object gains */ + for ( obj_idx = 0; obj_idx < editableParameters->num_obj; obj_idx++ ) + { + editableParameters->ism_metadata[obj_idx].gain = 0.5f + (float) ( ( frame + obj_idx * 50 ) % 250 ) / 250.0f; } - return; + editableParameters->gain_bed = 0.5f; } + return; +} + + +/*---------------------------------------------------------------------* + * load_hrtf_from_file() + * + * Load HRTF coefficients from external binary file + *---------------------------------------------------------------------*/ + +static ivas_error load_hrtf_from_file( + IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, /* i/o: HRTF binary wrapper handle */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const IVAS_AUDIO_CONFIG OutputConfig, /* i : output audio configuration */ + const int32_t output_Fs /* i : output sampling rate */ +) +{ + ivas_error error; + IVAS_BIN_RENDERER_TYPE binaural_renderer, binaural_renderer_sec; + + if ( hHrtfBinary == NULL || hIvasDec == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } - /*---------------------------------------------------------------------* - * load_hrtf_from_file() - * - * Load HRTF coefficients from external binary file - *---------------------------------------------------------------------*/ + binaural_renderer = hHrtfBinary->binaural_renderer; + binaural_renderer_sec = hHrtfBinary->binaural_renderer_sec; - static ivas_error load_hrtf_from_file( - IVAS_DEC_HRTF_BINARY_WRAPPER * hHrtfBinary, /* i/o: HRTF binary wrapper handle */ - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const IVAS_AUDIO_CONFIG OutputConfig, /* i : output audio configuration */ - const int32_t output_Fs /* i : output sampling rate */ - ) + if ( ( binaural_renderer != hHrtfBinary->binaural_renderer_old ) || + ( binaural_renderer_sec != hHrtfBinary->binaural_renderer_sec_old ) || + ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) { - ivas_error error; - IVAS_BIN_RENDERER_TYPE binaural_renderer, binaural_renderer_sec; + /*------------------------------------------------------------------------------------------* + * Release HRTF binary data + *------------------------------------------------------------------------------------------*/ - if ( hHrtfBinary == NULL || hIvasDec == NULL ) + if ( !( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && binaural_renderer_sec != IVAS_BIN_RENDERER_TYPE_TDREND && hHrtfBinary->hHrtfTD != NULL ) { - return IVAS_ERR_UNEXPECTED_NULL_POINTER; + destroy_td_hrtf( hHrtfBinary->hHrtfTD ); } - binaural_renderer = hHrtfBinary->binaural_renderer; - binaural_renderer_sec = hHrtfBinary->binaural_renderer_sec; - - if ( ( binaural_renderer != hHrtfBinary->binaural_renderer_old ) || - ( binaural_renderer_sec != hHrtfBinary->binaural_renderer_sec_old ) || - ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) + if ( ( error = IVAS_DEC_HRTF_binary_close( hIvasDec, hHrtfBinary->binaural_renderer_old ) ) != IVAS_ERR_OK ) { - /*------------------------------------------------------------------------------------------* - * Release HRTF binary data - *------------------------------------------------------------------------------------------*/ - - if ( !( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && binaural_renderer_sec != IVAS_BIN_RENDERER_TYPE_TDREND && hHrtfBinary->hHrtfTD != NULL ) - { - destroy_td_hrtf( hHrtfBinary->hHrtfTD ); - } + return error; + } - if ( ( error = IVAS_DEC_HRTF_binary_close( hIvasDec, hHrtfBinary->binaural_renderer_old ) ) != IVAS_ERR_OK ) - { - return error; - } + /*------------------------------------------------------------------------------------------* + * Load HRTF binary data + *------------------------------------------------------------------------------------------*/ - /*------------------------------------------------------------------------------------------* - * Load HRTF binary data - *------------------------------------------------------------------------------------------*/ + if ( ( error = IVAS_DEC_HRTF_binary_open( hIvasDec, binaural_renderer ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( ( error = IVAS_DEC_HRTF_binary_open( hIvasDec, binaural_renderer ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = IVAS_DEC_HRTF_binary_open( hIvasDec, binaural_renderer_sec ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( ( error = IVAS_DEC_HRTF_binary_open( hIvasDec, binaural_renderer_sec ) ) != IVAS_ERR_OK ) + if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_sec == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) + { + if ( ( error = IVAS_DEC_GetHrtfTDrendHandle( hIvasDec, &hHrtfBinary->hHrtfTD ) ) != IVAS_ERR_OK ) { + fprintf( stderr, "\nIVAS_DEC_GetHrtfTDrendHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); return error; } - if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_sec == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) + if ( ( error = load_TDrend_HRTF_binary( *hHrtfBinary->hHrtfTD, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) { - if ( ( error = IVAS_DEC_GetHrtfTDrendHandle( hIvasDec, &hHrtfBinary->hHrtfTD ) ) != IVAS_ERR_OK ) + if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { - fprintf( stderr, "\nIVAS_DEC_GetHrtfTDrendHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); return error; } - - if ( ( error = load_TDrend_HRTF_binary( *hHrtfBinary->hHrtfTD, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) + else { - if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) - { - fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); - return error; - } - else - { - destroy_td_hrtf( hHrtfBinary->hHrtfTD ); - } + destroy_td_hrtf( hHrtfBinary->hHrtfTD ); } } + } - if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) + if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) + { + IVAS_DEC_HRTF_CREND_HANDLE *hHrtfCrend = NULL; + if ( ( error = IVAS_DEC_GetHrtfCRendHandle( hIvasDec, &hHrtfCrend ) ) != IVAS_ERR_OK ) { - IVAS_DEC_HRTF_CREND_HANDLE *hHrtfCrend = NULL; - if ( ( error = IVAS_DEC_GetHrtfCRendHandle( hIvasDec, &hHrtfCrend ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_GetHrtfCRendHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - return error; - } - - if ( ( error = load_Crend_HRTF_from_binary( *hHrtfCrend, hHrtfBinary->hrtfReader, OutputConfig, hHrtfBinary->hrtf_set_audio_cfg, output_Fs ) ) != IVAS_ERR_OK ) - { - if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) - { - fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); - return error; - } - else - { - destroy_crend_hrtf( hHrtfCrend ); - } - } + fprintf( stderr, "\nIVAS_DEC_GetHrtfCRendHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; } - if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) + if ( ( error = load_Crend_HRTF_from_binary( *hHrtfCrend, hHrtfBinary->hrtfReader, OutputConfig, hHrtfBinary->hrtf_set_audio_cfg, output_Fs ) ) != IVAS_ERR_OK ) { - IVAS_DEC_HRTF_FASTCONV_HANDLE *hHrtfFastConv = NULL; - if ( ( error = IVAS_DEC_GetHrtfFastConvHandle( hIvasDec, &hHrtfFastConv ) ) != IVAS_ERR_OK ) + if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { - fprintf( stderr, "\nIVAS_DEC_GetHrtfFastConvHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); return error; } - - if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, OutputConfig, hHrtfBinary->hrtf_set_audio_cfg, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) + else { - if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) - { - fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); - return error; - } - else - { - destroy_fastconv_hrtf( hHrtfFastConv ); - } + destroy_crend_hrtf( hHrtfCrend ); } } + } + + if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) + { + IVAS_DEC_HRTF_FASTCONV_HANDLE *hHrtfFastConv = NULL; + if ( ( error = IVAS_DEC_GetHrtfFastConvHandle( hIvasDec, &hHrtfFastConv ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_GetHrtfFastConvHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; + } - if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_PARAMBIN || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) + if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, OutputConfig, hHrtfBinary->hrtf_set_audio_cfg, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) { - IVAS_DEC_HRTF_PARAMBIN_HANDLE *hHrtfParambin = NULL; - if ( ( error = IVAS_DEC_GetHrtfParamBinHandle( hIvasDec, &hHrtfParambin ) ) != IVAS_ERR_OK ) + if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { - fprintf( stderr, "\nIVAS_DEC_GetHrtfParamBinHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); return error; } - - if ( ( error = load_parambin_HRTF_from_binary( *hHrtfParambin, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) + else { - if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) - { - fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); - return error; - } - else - { - destroy_parambin_hrtf( hHrtfParambin ); - } + destroy_fastconv_hrtf( hHrtfFastConv ); } } } - if ( hHrtfBinary->hHrtfStatistics == NULL && ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND ) && OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_PARAMBIN || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) { - if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfBinary->hHrtfStatistics ) ) != IVAS_ERR_OK ) + IVAS_DEC_HRTF_PARAMBIN_HANDLE *hHrtfParambin = NULL; + if ( ( error = IVAS_DEC_GetHrtfParamBinHandle( hIvasDec, &hHrtfParambin ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nIVAS_DEC_GetHrtfStatisticsHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nIVAS_DEC_GetHrtfParamBinHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); return error; } - if ( ( error = load_reverb_binary( *hHrtfBinary->hHrtfStatistics, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) + if ( ( error = load_parambin_HRTF_from_binary( *hHrtfParambin, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { @@ -4675,66 +4652,104 @@ static ivas_error decodeVoIP( } else { - destroy_hrtf_statistics( hHrtfBinary->hHrtfStatistics ); + destroy_parambin_hrtf( hHrtfParambin ); } } } - - return IVAS_ERR_OK; } -#ifdef DECODER_FORMAT_SWITCHING - - /*---------------------------------------------------------------------* - * restartDecoder() - * - * Restart decoder in case of IVAS format switching - *---------------------------------------------------------------------*/ - - static ivas_error restartDecoder( - IVAS_DEC_HANDLE * phIvasDec, - const IVAS_DEC_MODE decMode, - DecArguments *arg, - IVAS_RENDER_CONFIG_DATA *renderConfig, - IVAS_CUSTOM_LS_DATA *hLsCustomData ) + if ( hHrtfBinary->hHrtfStatistics == NULL && ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND ) && OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { - ivas_error error = IVAS_ERR_OK; - IVAS_DEC_HANDLE hIvasDec; - - if ( phIvasDec == NULL ) + if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfBinary->hHrtfStatistics ) ) != IVAS_ERR_OK ) { - return IVAS_ERR_UNEXPECTED_NULL_POINTER; + fprintf( stderr, "\nIVAS_DEC_GetHrtfStatisticsHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; } - if ( NULL != *phIvasDec ) + if ( ( error = load_reverb_binary( *hHrtfBinary->hHrtfStatistics, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) { - IVAS_DEC_Close( phIvasDec ); + if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) + { + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); + return error; + } + else + { + destroy_hrtf_statistics( hHrtfBinary->hHrtfStatistics ); + } } + } - if ( ( error = IVAS_DEC_Open( phIvasDec, decMode ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "Open failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } + return IVAS_ERR_OK; +} + +#ifdef DECODER_FORMAT_SWITCHING + +/*---------------------------------------------------------------------* + * restartDecoder() + * + * Restart decoder in case of IVAS format switching + *---------------------------------------------------------------------*/ + +static ivas_error restartDecoder( + IVAS_DEC_HANDLE *phIvasDec, + const IVAS_DEC_MODE decMode, + DecArguments *arg, + IVAS_RENDER_CONFIG_DATA *renderConfig, + IVAS_CUSTOM_LS_DATA *hLsCustomData ) +{ + ivas_error error = IVAS_ERR_OK; + IVAS_DEC_HANDLE hIvasDec; + + if ( phIvasDec == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + if ( NULL != *phIvasDec ) + { + IVAS_DEC_Close( phIvasDec ); + } + + if ( ( error = IVAS_DEC_Open( phIvasDec, decMode ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Open failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } - arg->decMode = decMode; + arg->decMode = decMode; - hIvasDec = *phIvasDec; + hIvasDec = *phIvasDec; - uint16_t aeID = arg->aeSequence.count > 0 ? arg->aeSequence.pID[0] : 65535; + uint16_t aeID = arg->aeSequence.count > 0 ? arg->aeSequence.pID[0] : 65535; - IVAS_AUDIO_CONFIG outputConfig = ( decMode == IVAS_DEC_MODE_IVAS ) ? arg->outputConfig : IVAS_AUDIO_CONFIG_MONO; + IVAS_AUDIO_CONFIG outputConfig = ( decMode == IVAS_DEC_MODE_IVAS ) ? arg->outputConfig : IVAS_AUDIO_CONFIG_MONO; #ifdef FIX_1318_ROOM_SIZE_CMD_LINE - if ( ( error = IVAS_DEC_Configure( hIvasDec, arg->output_Fs, outputConfig, arg->renderFramesize, arg->customLsOutputEnabled, arg->hrtfReaderEnabled, - arg->enableHeadRotation, arg->enableExternalOrientation, arg->orientation_tracking, arg->renderConfigEnabled, arg->roomSize, arg->non_diegetic_pan_enabled, - arg->non_diegetic_pan_gain, arg->dpidEnabled, aeID, arg->objEditEnabled, arg->delayCompensationEnabled ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_Configure( hIvasDec, arg->output_Fs, outputConfig, arg->renderFramesize, arg->customLsOutputEnabled, arg->hrtfReaderEnabled, + arg->enableHeadRotation, arg->enableExternalOrientation, arg->orientation_tracking, arg->renderConfigEnabled, arg->roomSize, arg->non_diegetic_pan_enabled, + arg->non_diegetic_pan_gain, arg->dpidEnabled, aeID, arg->objEditEnabled, arg->delayCompensationEnabled ) ) != IVAS_ERR_OK ) #else - if ( ( error = IVAS_DEC_Configure( hIvasDec, arg->output_Fs, outputConfig, arg->renderFramesize, arg->customLsOutputEnabled, arg->hrtfReaderEnabled, - arg->enableHeadRotation, arg->enableExternalOrientation, arg->orientation_tracking, arg->renderConfigEnabled, arg->non_diegetic_pan_enabled, - arg->non_diegetic_pan_gain, arg->dpidEnabled, aeID, arg->objEditEnabled, arg->delayCompensationEnabled ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_Configure( hIvasDec, arg->output_Fs, outputConfig, arg->renderFramesize, arg->customLsOutputEnabled, arg->hrtfReaderEnabled, + arg->enableHeadRotation, arg->enableExternalOrientation, arg->orientation_tracking, arg->renderConfigEnabled, arg->non_diegetic_pan_enabled, + arg->non_diegetic_pan_gain, arg->dpidEnabled, aeID, arg->objEditEnabled, arg->delayCompensationEnabled ) ) != IVAS_ERR_OK ) #endif + { + fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + if ( ( error = IVAS_DEC_GetRenderFramesize( hIvasDec, &arg->renderFramesize ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + +#ifndef FIX_SPLIT_RENDERING_ON_DECODER_RESTART + if ( arg->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) + { + if ( ( error = IVAS_DEC_EnableSplitRendering( hIvasDec ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nSplit rendering configure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } @@ -4744,73 +4759,58 @@ static ivas_error decodeVoIP( goto cleanup; } -#ifndef FIX_SPLIT_RENDERING_ON_DECODER_RESTART - if ( arg->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) - { - if ( ( error = IVAS_DEC_EnableSplitRendering( hIvasDec ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nSplit rendering configure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - - if ( ( error = IVAS_DEC_GetRenderFramesize( hIvasDec, &arg->renderFramesize ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - - arg->enableHeadRotation = true; - } + arg->enableHeadRotation = true; + } #endif - if ( arg->voipMode ) - { - if ( ( error = IVAS_DEC_EnableVoIP( hIvasDec, 60, arg->inputFormat ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nCould not enable VOIP: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - } - - if ( ( error = IVAS_DEC_PrintConfig( hIvasDec, 1, arg->voipMode ) ) != IVAS_ERR_OK ) + if ( arg->voipMode ) + { + if ( ( error = IVAS_DEC_EnableVoIP( hIvasDec, 60, arg->inputFormat ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nIVAS_DEC_PrintConfig failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nCould not enable VOIP: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } + } + + if ( ( error = IVAS_DEC_PrintConfig( hIvasDec, 1, arg->voipMode ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_PrintConfig failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } #ifdef FIX_SPLIT_RENDERING_ON_DECODER_RESTART - /* ISAR frame size is set from command line, not renderer config file. - * This will be ignored if output format is not split rendering. */ - if ( renderConfig != NULL ) - { - renderConfig->split_rend_config.isar_frame_size_ms = (int16_t) arg->renderFramesize /* given in number of 5ms subframes */ * 5; - } + /* ISAR frame size is set from command line, not renderer config file. + * This will be ignored if output format is not split rendering. */ + if ( renderConfig != NULL ) + { + renderConfig->split_rend_config.isar_frame_size_ms = (int16_t) arg->renderFramesize /* given in number of 5ms subframes */ * 5; + } #endif - if ( arg->renderConfigEnabled && renderConfig != NULL ) + if ( arg->renderConfigEnabled && renderConfig != NULL ) + { + if ( ( error = IVAS_DEC_FeedRenderConfig( hIvasDec, *renderConfig ) ) != IVAS_ERR_OK ) { - if ( ( error = IVAS_DEC_FeedRenderConfig( hIvasDec, *renderConfig ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_FeedRenderConfig failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } + fprintf( stderr, "\nIVAS_DEC_FeedRenderConfig failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; } + } - if ( arg->customLsOutputEnabled && hLsCustomData != NULL ) + if ( arg->customLsOutputEnabled && hLsCustomData != NULL ) + { + if ( ( error = IVAS_DEC_FeedCustomLsData( hIvasDec, *hLsCustomData ) ) != IVAS_ERR_OK ) { - if ( ( error = IVAS_DEC_FeedCustomLsData( hIvasDec, *hLsCustomData ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_FeedCustomLsData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } + fprintf( stderr, "\nIVAS_DEC_FeedCustomLsData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; } + } - return IVAS_ERR_OK; + return IVAS_ERR_OK; - cleanup: - IVAS_DEC_Close( phIvasDec ); - return error; - } +cleanup: + IVAS_DEC_Close( phIvasDec ); + return error; +} #endif #undef WMC_TOOL_SKIP -- GitLab