diff --git a/apps/decoder.c b/apps/decoder.c index ebbd4f5dd3651509de5ff5064c1bff2a487afdf6..0b1c48ddb13f3915bed5185ecf1e56dcd56040aa 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 @@ -232,10 +228,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() * @@ -549,7 +546,6 @@ int main( fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } - #ifndef IVAS_RTPDUMP arg.enableHeadRotation = true; #endif @@ -690,6 +686,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 ) @@ -928,6 +925,7 @@ cleanup: free( pAE ); } #endif + if ( arg.aeSequence.count > 0 ) { free( arg.aeSequence.pID ); @@ -1921,6 +1919,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" ); @@ -1944,10 +1946,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 @@ -2051,6 +2049,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 @@ -2638,7 +2637,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 ) { @@ -3458,6 +3457,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 }; @@ -3662,25 +3662,26 @@ 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, + IVAS_DEC_MODE newDecModeInPacket = ( ivasRtp.codecId == IVAS_RTP_EVS ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; + if ( ( error = restartDecoder( + &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 */ - ); - if ( error != 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, 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; } @@ -3719,6 +3720,7 @@ static ivas_error decodeVoIP( goto cleanup; } } + int16_t num_subframes; if ( ( error = IVAS_DEC_GetNumOrientationSubframes( hIvasDec, &num_subframes ) ) != IVAS_ERR_OK ) { @@ -3726,7 +3728,6 @@ static ivas_error decodeVoIP( goto cleanup; } - /* Head-tracking input simulation */ /* Head-tracking input simulation */ if ( arg.enableHeadRotation ) { @@ -3868,12 +3869,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 ) { @@ -3890,7 +3896,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; @@ -3938,26 +3944,30 @@ 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 ) + + 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; @@ -3966,6 +3976,9 @@ static ivas_error decodeVoIP( } #endif + /* Placeholder for memory reallocation */ + /* ... */ + /* Load HRTF binary file data */ if ( arg.hrtfReaderEnabled ) { @@ -4166,7 +4179,6 @@ static ivas_error decodeVoIP( } #endif - vec_pos_update = ( vec_pos_update + 1 ) % vec_pos_len; if ( vec_pos_update == 0 ) { @@ -4686,9 +4698,15 @@ static ivas_error load_hrtf_from_file( #ifdef DECODER_FORMAT_SWITCHING -ivas_error restartDecoder( +/*---------------------------------------------------------------------* + * restartDecoder() + * + * Restart decoder in case of IVAS 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 ) @@ -4706,19 +4724,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; #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, diff --git a/apps/encoder.c b/apps/encoder.c index 162ac9a19dfd4e83a2fbbd46d30e81ca78a7f45e..505e66a282789715f38ebea25be0052adf2566d7 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 9d1bf818317f62dcff6ae08d7f4d8a2e9995cf5d..2a990abae174d75354a423e6714b9d51ba956bc5 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,24 @@ 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 ); + if ( FmtSWFile ) + { + fclose( FmtSWFile ); + } + + return mainFailed ? -1 : 0; } @@ -576,14 +597,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 +801,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 7e91590225e449ef980c7d70d48ccd7ccb03a73f..f4a75208b67140276c09a15db939e95448e89127 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 0f49fd5a0b4d6ad055de1699f4324e5808c720a5..2d3c7e969a674a27491e52e640886b15b23e4e1b 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1608,9 +1608,6 @@ typedef enum #else #define IVAS_REVERB_DEFAULT_N_BANDS 31 #endif -#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 0aaf9d0ba63a62ca6eacb99dae3a184abb890321..3699782aa7789b43210ffec63e682676dbde2e18 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 */ @@ -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( @@ -3238,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 */ @@ -3646,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( @@ -4146,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 */ ); @@ -4263,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, @@ -4555,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_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index f337611110d240d54c96db4fbc9d76de5398bbbc..aa544ce6b81ef070d83d0668ad4145e3b002f2e5 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -99,18 +99,16 @@ 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; int16_t nchan_ism, element_mode_flag; int16_t sba_order, sba_planar, sba_analysis_order; int32_t ivas_total_brate; +#ifdef DECODER_FORMAT_SWITCHING + int16_t Opt_tsm; +#endif uint16_t *bit_stream_orig; AUDIO_CONFIG signaled_config; ivas_error error; @@ -119,6 +117,9 @@ ivas_error ivas_dec_get_format( element_mode_flag = 0; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; +#ifdef DECODER_FORMAT_SWITCHING + Opt_tsm = st_ivas->hDecoderConfig->Opt_tsm; +#endif bit_stream_orig = st_ivas->bit_stream; /*-------------------------------------------------------------------* @@ -135,9 +136,10 @@ 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; + return IVAS_ERR_OK; } else @@ -151,6 +153,7 @@ ivas_error ivas_dec_get_format( } #endif } + /*-------------------------------------------------------------------* * Read other signaling (ISM/MC mode, number of channels, etc.) *-------------------------------------------------------------------*/ @@ -183,9 +186,10 @@ 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; + return IVAS_ERR_OK; } else @@ -218,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; @@ -242,9 +246,10 @@ 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; + return IVAS_ERR_OK; } else @@ -267,11 +272,12 @@ 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] ) { #ifdef DECODER_FORMAT_SWITCHING - if ( st_ivas->nchan_transport == 1 && isVoipMode ) + if ( st_ivas->nchan_transport == 1 && Opt_tsm ) { masaRestartCandidate = 1; } @@ -282,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; } @@ -318,6 +324,7 @@ ivas_error ivas_dec_get_format( else if ( masaRestartCandidate > 0 ) { st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; } #endif @@ -325,9 +332,10 @@ 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; + return IVAS_ERR_OK; } else @@ -355,9 +363,10 @@ 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; + return IVAS_ERR_OK; } else @@ -382,9 +391,10 @@ 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; + return IVAS_ERR_OK; } else @@ -421,9 +431,10 @@ 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; + return IVAS_ERR_OK; } else @@ -461,9 +472,10 @@ 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; + return IVAS_ERR_OK; } else @@ -558,9 +570,10 @@ 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; + return IVAS_ERR_OK; } else @@ -3076,6 +3089,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 ) ); @@ -3101,15 +3123,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 6a8fa5d72bfaa0e64005409ce44a46b25f595a02..6b6a99b32bb24df1c2a37acaae707040346263fe 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1155,7 +1155,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 c4060993287a316dd074b2095a0395fdc56e6ba1..de95304301e1510ec565a371d2c06fd03f1f0d1c 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 @@ -1063,17 +1066,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; } @@ -3321,6 +3320,7 @@ ivas_error IVAS_DEC_HRTF_binary_close( return IVAS_ERR_OK; } + #ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT /*---------------------------------------------------------------------* * IVAS_DEC_AddAcousticEnvironment( ) @@ -3357,12 +3357,42 @@ 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 = 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( 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 = st_ivas->pAcousticEnvironments[n].use_er; + + if ( pAE->use_er == 1 ) + { + 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 ); + } + } + + free( st_ivas->pAcousticEnvironments ); st_ivas->pAcousticEnvironments = ppAE; n = st_ivas->acousticEnvironmentsCount++; pAE = &st_ivas->pAcousticEnvironments[n]; @@ -3395,11 +3425,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 */ @@ -3408,24 +3440,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; @@ -3465,6 +3498,7 @@ ivas_error IVAS_DEC_GetAcousticEnvironment( } #endif + /*---------------------------------------------------------------------* * copyRendererConfigStruct( ) * @@ -3682,14 +3716,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 */ ) @@ -4634,11 +4669,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; } @@ -4646,12 +4690,13 @@ bool IVAS_DEC_isRestartNeeded( /*---------------------------------------------------------------------* * IVAS_DEC_VoIP_IsEmpty( ) * - * + * Returns '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 /* 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 ) @@ -4659,7 +4704,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; } @@ -6008,86 +6055,119 @@ 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 */ - 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 */ +static ivas_error feedSinglePIorientation( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_QUATERNION *orientation /* i : orientation for this PI type */ ) { int16_t i; - ivas_error error = IVAS_ERR_OK; - IVAS_QUATERNION savedInvOrientation; + ivas_error error; + Decoder_Struct *st_ivas; + IVAS_QUATERNION invOrientation; - if ( isOrientationSaved ) + if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { - if ( !hIvasDec->st_ivas->hExtOrientationData ) + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + st_ivas = hIvasDec->st_ivas; + + 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( &( hIvasDec->st_ivas->hExtOrientationData ), hIvasDec->st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } + } - if ( !hIvasDec->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( &( hIvasDec->st_ivas->hCombinedOrientationData ), hIvasDec->st_ivas->hDecoderConfig->output_Fs, hIvasDec->st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } + } - QuaternionInverse( *savedOrientation, &savedInvOrientation ); + QuaternionInverse( *orientation, &invOrientation ); - /* use the new PI orientation or the previously saved orientation in processing */ - for ( i = 0; i < hIvasDec->st_ivas->hExtOrientationData->num_subframes; i++ ) - { - QuaternionProduct( hIvasDec->st_ivas->hExtOrientationData->Quaternions[i], savedInvOrientation, - &hIvasDec->st_ivas->hExtOrientationData->Quaternions[i] ); - hIvasDec->st_ivas->hExtOrientationData->enableExternalOrientation[i] = true; - } - 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; } - return error; + + hIvasDec->updateOrientation = true; + + return IVAS_ERR_OK; } #ifdef RTP_S4_251135_CR26253_0016_REV1 /*---------------------------------------------------------------------* - * IVAS_DEC_setDiegeticInput( ) + * setDiegeticInput( ) * * 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 */ +static void setDiegeticInputPI( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const bool *diegeticPIValues /* i : diegetic values for the input stream */ ) { - if ( hIvasDec->st_ivas->hCombinedOrientationData != NULL ) + int16_t i; + + if ( st_ivas->hCombinedOrientationData != NULL ) { - int8_t i; for ( i = 0; i < ( 1 + IVAS_MAX_NUM_OBJECTS ); i++ ) { - hIvasDec->st_ivas->hCombinedOrientationData->isDiegeticInputPI[i] = diegeticPIValues[i]; + st_ivas->hCombinedOrientationData->isDiegeticInputPI[i] = diegeticPIValues[i]; } - hIvasDec->st_ivas->hCombinedOrientationData->isDiegeticInputPISet = true; + + st_ivas->hCombinedOrientationData->isDiegeticInputPISet = true; } + + return; } #endif + #ifdef IVAS_RTPDUMP -ivas_error IVAS_RTP_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, PIDATA_TS *piData, uint32_t numPiData ) +/*---------------------------------------------------------------------* + * 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 */ +) { + uint32_t i; + Decoder_Struct *st_ivas; ivas_error error = IVAS_ERR_OK; - while ( numPiData-- ) + + if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + st_ivas = hIvasDec->st_ivas; + + for ( i = 0; i < numPiData; i++ ) { uint32_t piDataType = piData->data.noPiData.piDataType; + switch ( piDataType ) { case IVAS_PI_SCENE_ORIENTATION: @@ -6096,7 +6176,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, quat ); } break; @@ -6106,7 +6186,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, quat ); } break; @@ -6118,9 +6198,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; @@ -6132,7 +6212,7 @@ 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 ); + setDiegeticInputPI( st_ivas, piData->data.digeticIndicator.isDiegetic ); } break; #endif @@ -6143,12 +6223,15 @@ 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 51115744df462e366f549c4dcd8a0566aea354db..24a663bd35c8d355d60cacedae8591d6bd275e66 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 */ @@ -343,8 +343,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 @@ -363,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 @@ -486,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 @@ -527,10 +528,11 @@ 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 */ -bool IVAS_DEC_VoIP_IsEmpty( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const int16_t nSamplesAsked +/*! 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 */ + bool *isEmpty /* o : isEmpty flag */ ); ivas_error IVAS_DEC_VoIP_Get_CA_offset( @@ -546,6 +548,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 */ @@ -579,11 +590,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_prot_rend.h b/lib_rend/ivas_prot_rend.h index 91bd0509907cc04df30fdbce056380aae98ac31b..14c2e6594136a1480c09526a947409bbeea37b2e 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/lib_rend/ivas_render_config.c b/lib_rend/ivas_render_config.c index 5cd5b18479700e67b02d4a8dbe9a2973ef43e351..dc44c003f2f5a3f1dd61d5c3952c62599e032cb8 100644 --- a/lib_rend/ivas_render_config.c +++ b/lib_rend/ivas_render_config.c @@ -125,7 +125,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 #ifdef FIX_1318_ROOM_SIZE_CMD_LINE ( *hRenderConfig )->roomAcoustics.nBands = IVAS_REVERB_DEFAULT_L_N_BANDS; diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 95361e116a0128101eb30f9a3d1f73ee0213f0a4..534661af35db3203e7bbadaa2b75b7dc6e1db5e3 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -1256,6 +1256,7 @@ ivas_error combine_external_and_head_orientations( } } #endif + return IVAS_ERR_OK; } diff --git a/lib_util/ivas_rtp_pi_data.h b/lib_util/ivas_rtp_pi_data.h index d3d8487e8e77b79e5177caa33543c2e6d091cf0b..95a2ac99429f7ba825e594eee4bf56d1dfdb1309 100644 --- a/lib_util/ivas_rtp_pi_data.h +++ b/lib_util/ivas_rtp_pi_data.h @@ -519,7 +519,7 @@ typedef union IVAS_PIDATA_NO_DATA noPiData; } PIDATA; -typedef struct +typedef struct pidata_ts_struct { PIDATA data; uint32_t timestamp; diff --git a/readme.txt b/readme.txt index 68444215337703004c15c96f8485b837540cb3e8..62d21f51bacdf05764e470b763bbd0ae659f0023 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: --------------------- @@ -310,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 @@ -334,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 @@ -348,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 @@ -372,8 +381,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 +423,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 +437,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 @@ -680,8 +698,26 @@ 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. 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; +