From 09851c989a229e653abd9c9847d7df477ee61015 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 21 Apr 2026 11:05:04 +0200 Subject: [PATCH 1/4] FIX_FMSW_DEC andf FIX_FMSW_DEC_2 --- apps/decoder.c | 50 +- apps/encoder.c | 21 +- lib_com/ivas_prot_fx.h | 7 +- lib_com/options.h | 2 + lib_dec/ivas_init_dec_fx.c | 956 ++++++++++++++++++++----------------- lib_dec/lib_dec.h | 7 + lib_dec/lib_dec_fx.c | 186 +++++++- lib_util/ivas_rtp_api.h | 3 + lib_util/ivas_rtp_file.c | 15 + readme.txt | 1 + 10 files changed, 797 insertions(+), 451 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 5cf6f77f7..53b53e1dc 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -164,10 +164,16 @@ static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS #else static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ObjectEditFileReader *objectEditFileReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); #endif +#ifdef FIX_FMSW_DEC +static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ObjectEditFileReader *objectEditFileReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE *phIvasDec, int16_t *pcmBuf ); +#else static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ObjectEditFileReader *objectEditFileReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_RENDER_CONFIG_DATA *renderConfig, IVAS_DEC_HANDLE *phIvasDec, int16_t *pcmBuf ); +#endif static ivas_error load_hrtf_from_file( IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, IVAS_DEC_HANDLE hIvasDec, const IVAS_AUDIO_CONFIG OutputConfig, const int32_t output_Fs ); static void do_object_editing_fx( IVAS_EDITABLE_PARAMETERS *editableParameters, ObjectEditFileReader *objectEditFileReader ); +#ifndef FIX_FMSW_DEC 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 /*------------------------------------------------------------------------------------------* @@ -668,7 +674,11 @@ int main( if ( arg.voipMode ) { +#ifdef FIX_FMSW_DEC + error = decodeVoIP( arg, hBsReader, &hHrtfBinary, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, objectEditFileReader, &splitRendBits, &hIvasDec, pcmBuf ); +#else error = decodeVoIP( arg, hBsReader, &hHrtfBinary, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, objectEditFileReader, &splitRendBits, &renderConfig, &hIvasDec, pcmBuf ); +#endif } else { @@ -2315,6 +2325,13 @@ static ivas_error decodeG192( if ( restartNeeded ) { +#ifdef FIX_FMSW_DEC + if ( ( error = IVAS_DEC_Restart( hIvasDec, IVAS_DEC_MODE_IVAS ) ) != IVAS_ERR_OK ) /* note: only switching within IVAS formats is supported in G.192 */ + { + fprintf( stderr, "\nIVAS_DEC_Restart restart failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } +#else IVAS_DEC_BS_FORMAT tempFormat; if ( ( error = IVAS_DEC_GetFormat( hIvasDec, &tempFormat ) ) != IVAS_ERR_OK ) { @@ -2335,6 +2352,7 @@ static ivas_error decodeG192( goto cleanup; } *phIvasDec = hIvasDec; /* Update for main()' s free */ +#endif } #endif @@ -2814,7 +2832,9 @@ static ivas_error decodeVoIP( Vector3PairFileReader *referenceVectorReader, ObjectEditFileReader *objectEditFileReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, +#ifndef FIX_FMSW_DEC IVAS_RENDER_CONFIG_DATA *renderConfig, +#endif IVAS_DEC_HANDLE *phIvasDec, int16_t *pcmBuf ) { @@ -2970,6 +2990,15 @@ static ivas_error decodeVoIP( /* EVS RTP payload format has timescale 16000, JBM uses 1000 internally */ rtpTimeStamp = rtpTimeStamp / 16; + +#ifdef FIX_FMSW_DEC_2 + arg.decMode = ( ivasRtp.codecId == IVAS_RTP_EVS ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; + if ( ( error = IVAS_DEC_Restart( hIvasDec, arg.decMode ) ) != IVAS_ERR_OK ) /* note: when the RTP bitstream starts with EVS, do the restart */ + { + fprintf( stderr, "\nIVAS_DEC_Restart restart failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } +#endif } if ( error != IVAS_ERR_OK ) { @@ -3003,6 +3032,14 @@ static ivas_error decodeVoIP( /* restart decoder in case of format switching */ if ( ivasRtp.restartNeeded ) { +#ifdef FIX_FMSW_DEC + arg.decMode = ( ivasRtp.codecId == IVAS_RTP_EVS ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; + if ( ( error = IVAS_DEC_Restart( hIvasDec, arg.decMode ) ) != IVAS_ERR_OK ) /* note: switching between EVS and IVAS is supported in RTP */ + { + fprintf( stderr, "\nIVAS_DEC_Restart restart failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } +#else IVAS_DEC_MODE newDecModeInPacket = ( ivasRtp.codecId == IVAS_RTP_EVS ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; if ( ( error = restartDecoder( &hIvasDec, @@ -3017,6 +3054,7 @@ static ivas_error decodeVoIP( } *phIvasDec = hIvasDec; /* Update for main()' s free */ +#endif ivasRtp.restartNeeded = false; bitstreamReadDone = false; parametersAvailableForEditing = false; @@ -3248,6 +3286,13 @@ static ivas_error decodeVoIP( if ( restartNeeded ) { +#ifdef FIX_FMSW_DEC + if ( ( error = IVAS_DEC_Restart( hIvasDec, IVAS_DEC_MODE_IVAS ) ) != IVAS_ERR_OK ) /* note: only switching within IVAS formats is supported in non-RTP VoIP */ + { + fprintf( stderr, "\nIVAS_DEC_Restart restart failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } +#else IVAS_DEC_BS_FORMAT tempBsFormat; if ( ( error = IVAS_DEC_GetFormat( hIvasDec, &tempBsFormat ) ) != IVAS_ERR_OK ) { @@ -3269,6 +3314,7 @@ static ivas_error decodeVoIP( } *phIvasDec = hIvasDec; /* Update for main()' s free */ +#endif bitstreamReadDone = false; parametersAvailableForEditing = false; } @@ -3961,7 +4007,7 @@ static ivas_error load_hrtf_from_file( return IVAS_ERR_OK; } - +#ifndef FIX_FMSW_DEC /*---------------------------------------------------------------------* * restartDecoder() * @@ -4066,5 +4112,5 @@ cleanup: return error; } - +#endif #undef WMC_TOOL_SKIP diff --git a/apps/encoder.c b/apps/encoder.c index 6c09d308f..9c003ad93 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -254,6 +254,7 @@ int main( fprintf( stderr, "Opening IVAS encoder failed: %s\n", IVAS_ENC_GetErrorMessage( error ) ); goto cleanup; } + /*------------------------------------------------------------------------------------------* * Open output bitstream file *------------------------------------------------------------------------------------------*/ @@ -364,6 +365,21 @@ int main( } } +#ifdef FIX_FMSW_DEC + /*------------------------------------------------------------------------------------------* + * Open remote requests file for rtp packing (E-bytes) + *------------------------------------------------------------------------------------------*/ + + if ( arg.requestsFileName != NULL ) + { + if ( ( error = RequestsFileReader_open( arg.requestsFileName, &requestsFileReader ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: Can't open requests file %s \n\n", arg.requestsFileName ); + goto cleanup; + } + } +#endif + /*------------------------------------------------------------------------------------------* * Handle Channel-aware mode *------------------------------------------------------------------------------------------*/ @@ -661,6 +677,7 @@ int main( } } +#ifndef FIX_FMSW_DEC /*------------------------------------------------------------------------------------------* * Open remote requests file for rtp packing (E-bytes) *------------------------------------------------------------------------------------------*/ @@ -672,7 +689,7 @@ int main( goto cleanup; } } - +#endif /*------------------------------------------------------------------------------------------* * Run the encoder *------------------------------------------------------------------------------------------*/ @@ -2133,9 +2150,9 @@ static void usage_enc( void ) fprintf( stdout, " bitstream frames into TS26.253 Annex A IVAS RTP Payload Format packets and \n" ); fprintf( stdout, " writes those to the output file. In EVS mono operating mode, TS26.445 Annex A.2.2 \n" ); fprintf( stdout, " EVS RTP Payload Format is used. Optional N represents number of frames per RTP packet\n" ); + fprintf( stdout, "-requests : Remote requests file, Only used with rtpdump output.\n" ); fprintf( stdout, "-scene_orientation : Scene orientation trajectory file. Only used with rtpdump output.\n" ); fprintf( stdout, "-device_orientation : Device orientation trajectory file. Only used with rtpdump output.\n" ); - fprintf( stdout, "-requests : Remote requests file, Only used with rtpdump output.\n" ); fprintf( stdout, "\n" ); diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 02d720e2f..b9fef7f66 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2070,7 +2070,11 @@ void destroy_core_dec_fx( ); void ivas_destroy_dec_fx( +#ifdef FIX_FMSW_DEC + Decoder_Struct **st_ivas /* i/o: IVAS decoder structure */ +#else Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#endif ); ivas_error ivas_ism_dec_config_fx( @@ -3725,10 +3729,11 @@ Word16 getNumChanSynthesis( Decoder_Struct *st_ivas /* i : IVAS decoder structure */ ); +#ifndef FIX_FMSW_DEC void ivas_destroy_dec_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); - +#endif ivas_error ivas_core_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ diff --git a/lib_com/options.h b/lib_com/options.h index c09e1ff3d..8e0d79188 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -116,6 +116,8 @@ #define FIX_BASOP_2531_MCT_CP_BITRATE /* FhG: BASOP issue 2531: Fix MCT cp_bitrate calculation; affects bitrate switching only */ #define FIX_BASOP_2541_OMASA_ENC_FIXES /* Nokia: BASOP issue 2541: Fix function ivas_encode_masaism_metadata_fx */ #define FIX_BASOP_2545_FIX_LTV_REGRESSION_2529 /* Nokia: BASOP issue 2545: Fix LTV regression caused by issue 2529 fix */ +#define FIX_FMSW_DEC /* float issue 1542: fix JBM issue in format switching */ +#define FIX_FMSW_DEC_2 /* float issue 1575: fix crash for format switching when bitsream starts with EVS */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index fc1133f74..dba807136 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -144,559 +144,539 @@ ivas_error ivas_dec_get_format_fx( test(); IF( st_ivas->ini_frame > 0 && NE_32( st_ivas->ivas_format, st_ivas->last_ivas_format ) && !( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && EQ_32( st_ivas->last_ivas_format, MASA_ISM_FORMAT ) ) && - !( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->last_ivas_format, MASA_FORMAT ) ) ) - { + !( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->last_ivas_format, MASA_FORMAT ) ) ){ #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ) - { + IF( Opt_tsm ){ #endif st_ivas->restartNeeded = 1; - move16(); + move16(); - return IVAS_ERR_OK; + return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - } - ELSE - { +} +ELSE +{ #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); - } + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); +} #endif - } +} + +/*-------------------------------------------------------------------* + * Read other signaling (ISM/MC mode, number of channels, etc.) + *-------------------------------------------------------------------*/ +IF( is_DTXrate( ivas_total_brate ) == 0 ) +{ /*-------------------------------------------------------------------* - * Read other signaling (ISM/MC mode, number of channels, etc.) + * Read IVAS format related signaling: + * - in ISM : read number of objects + * - in SBA : read SBA planar flag and SBA order + * - in MASA : read number of TC + * - in MC : read LS setup *-------------------------------------------------------------------*/ - IF( is_DTXrate( ivas_total_brate ) == 0 ) + IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) { - /*-------------------------------------------------------------------* - * Read IVAS format related signaling: - * - in ISM : read number of objects - * - in SBA : read SBA planar flag and SBA order - * - in MASA : read number of TC - * - in MC : read LS setup - *-------------------------------------------------------------------*/ - - IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) - { - element_mode_flag = 1; - move16(); - } - ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) + element_mode_flag = 1; + move16(); + } + ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) + { + /* read the number of objects */ + nchan_ism = 1; + move16(); + k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + k = sub( k, 1 ); + WHILE( st_ivas->bit_stream[k] && ( nchan_ism < MAX_NUM_OBJECTS ) ) { - /* read the number of objects */ - nchan_ism = 1; - move16(); - k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + nchan_ism = add( nchan_ism, 1 ); k = sub( k, 1 ); - WHILE( st_ivas->bit_stream[k] && ( nchan_ism < MAX_NUM_OBJECTS ) ) - { - nchan_ism = add( nchan_ism, 1 ); - k = sub( k, 1 ); - } + } - test(); - IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) - { + test(); + IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ){ #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ) - { + IF( Opt_tsm ){ #endif - st_ivas->restartNeeded = 1; - move16(); + st_ivas->restartNeeded = 1; + move16(); - return IVAS_ERR_OK; + return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - } - ELSE - { + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); - } + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } #endif - } +} - st_ivas->nchan_ism = nchan_ism; - move16(); - st_ivas->ism_mode = ivas_ism_mode_select( nchan_ism, ivas_total_brate ); +st_ivas->nchan_ism = nchan_ism; +move16(); +st_ivas->ism_mode = ivas_ism_mode_select( nchan_ism, ivas_total_brate ); - st_ivas->nchan_transport = nchan_ism; - move16(); - if ( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) - { - st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; - move16(); - } - } - ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) - { - /* read Ambisonic (SBA) planar flag */ - sba_planar = st_ivas->bit_stream[num_bits_read]; - num_bits_read = add( num_bits_read, SBA_PLANAR_BITS ); +st_ivas->nchan_transport = nchan_ism; +move16(); +if ( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) +{ + st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; + move16(); +} +} +ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) +{ + /* read Ambisonic (SBA) planar flag */ + sba_planar = st_ivas->bit_stream[num_bits_read]; + num_bits_read = add( num_bits_read, SBA_PLANAR_BITS ); - test(); - IF( st_ivas->ini_frame > 0 && NE_16( sba_planar, st_ivas->sba_planar ) ) - { + test(); + IF( st_ivas->ini_frame > 0 && NE_16( sba_planar, st_ivas->sba_planar ) ){ #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ) - { + IF( Opt_tsm ){ #endif - st_ivas->restartNeeded = 1; - move16(); + st_ivas->restartNeeded = 1; + move16(); - return IVAS_ERR_OK; + return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - } - ELSE - { +} +ELSE +{ #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the SBA planar/3D layout is not supported!\n" ); + fprintf( stderr, "\nError: Changing the SBA planar/3D layout is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA planar flag signalled!" ); - } + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA planar flag signalled!" ); +} #endif - } +} - /* read Ambisonic (SBA) order */ - sba_order = st_ivas->bit_stream[num_bits_read + 1]; - move16(); - sba_order = add( sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) ); +/* read Ambisonic (SBA) order */ +sba_order = st_ivas->bit_stream[num_bits_read + 1]; +move16(); +sba_order = add( sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) ); - test(); - IF( st_ivas->ini_frame > 0 && NE_16( sba_order, st_ivas->sba_order ) ) - { +test(); +IF( st_ivas->ini_frame > 0 && NE_16( sba_order, st_ivas->sba_order ) ){ #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ) - { + IF( Opt_tsm ){ #endif - st_ivas->restartNeeded = 1; - move16(); + st_ivas->restartNeeded = 1; +move16(); - return IVAS_ERR_OK; +return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - } - ELSE - { +} +ELSE +{ #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" ); + fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" ); - } + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" ); +} #endif - } +} - sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, sba_order ); - st_ivas->nchan_transport = ivas_get_sba_num_TCs_fx( ivas_total_brate, sba_analysis_order ); - } - ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) - { - UWord8 masaRestartCandidate; - masaRestartCandidate = 0; - move16(); +sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, sba_order ); +st_ivas->nchan_transport = ivas_get_sba_num_TCs_fx( ivas_total_brate, sba_analysis_order ); +} +ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) +{ + UWord8 masaRestartCandidate; + masaRestartCandidate = 0; + move16(); - /* read number of MASA transport channels */ - k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - IF( st_ivas->bit_stream[k - 1] ) - { + /* read number of MASA transport channels */ + k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + IF( st_ivas->bit_stream[k - 1] ) + { #ifdef FIX_FLOAT_1539_G192_FORMAT_SWITCH - if ( st_ivas->nchan_transport == 1 ) + if ( st_ivas->nchan_transport == 1 ) #else - test(); - if ( st_ivas->nchan_transport == 1 && Opt_tsm ) + test(); + if ( st_ivas->nchan_transport == 1 && Opt_tsm ) #endif - { - masaRestartCandidate = 1; - move16(); - } + { + masaRestartCandidate = 1; + move16(); + } - st_ivas->nchan_transport = 2; - move16(); - element_mode_flag = 1; - move16(); - } - ELSE - { + st_ivas->nchan_transport = 2; + move16(); + element_mode_flag = 1; + move16(); + } + ELSE + { #ifdef FIX_FLOAT_1539_G192_FORMAT_SWITCH - if ( st_ivas->nchan_transport == 2 ) + if ( st_ivas->nchan_transport == 2 ) #else - test(); - if ( st_ivas->nchan_transport == 2 && Opt_tsm ) + test(); + if ( st_ivas->nchan_transport == 2 && Opt_tsm ) #endif - { - masaRestartCandidate = 1; - move16(); - } + { + masaRestartCandidate = 1; + move16(); + } - st_ivas->nchan_transport = 1; - move16(); - } + st_ivas->nchan_transport = 1; + move16(); + } - /* this should be non-zero if original input format was MASA_ISM_FORMAT */ - st_ivas->ism_mode = ISM_MODE_NONE; - move16(); - nchan_ism = add( st_ivas->bit_stream[k - 3], shl( st_ivas->bit_stream[k - 2], 1 ) ); + /* this should be non-zero if original input format was MASA_ISM_FORMAT */ + st_ivas->ism_mode = ISM_MODE_NONE; + move16(); + nchan_ism = add( st_ivas->bit_stream[k - 3], shl( st_ivas->bit_stream[k - 2], 1 ) ); - IF( nchan_ism > 0 ) - { - /* the input_ivas_format should be MASA_ISM_FORMAT, but we cannot initialize it now */ - /* info about the number of objects: - '00' - MASA format at the encoder - '01' - MASA_ISM_FORMAT at the encoder, with 4 objects - '10' - MASA_ISM_FORMAT at the encoder, with 3 objects - '11' - MASA_ISM_FORMAT at the encoder, with 1 or 2 objects - reading if 1 or 2 objects is performed later - */ - nchan_ism = sub( 5, nchan_ism ); - test(); - IF( EQ_16( st_ivas->nchan_transport, 1 ) && EQ_16( nchan_ism, 2 ) ) - { - nchan_ism = 1; - move16(); - } + IF( nchan_ism > 0 ) + { + /* the input_ivas_format should be MASA_ISM_FORMAT, but we cannot initialize it now */ + /* info about the number of objects: + '00' - MASA format at the encoder + '01' - MASA_ISM_FORMAT at the encoder, with 4 objects + '10' - MASA_ISM_FORMAT at the encoder, with 3 objects + '11' - MASA_ISM_FORMAT at the encoder, with 1 or 2 objects + reading if 1 or 2 objects is performed later + */ + nchan_ism = sub( 5, nchan_ism ); + test(); + IF( EQ_16( st_ivas->nchan_transport, 1 ) && EQ_16( nchan_ism, 2 ) ) + { + nchan_ism = 1; + move16(); + } - /* for MASA_ISM_FORMAT at input the number of MASA transport channels is always 2 and the corresponding bit is not used here*/ - st_ivas->nchan_transport = 2; - move16(); - element_mode_flag = 1; - move16(); - } - ELSE IF( masaRestartCandidate > 0 ) - { - st_ivas->restartNeeded = 1; - move16(); + /* for MASA_ISM_FORMAT at input the number of MASA transport channels is always 2 and the corresponding bit is not used here*/ + st_ivas->nchan_transport = 2; + move16(); + element_mode_flag = 1; + move16(); + } + ELSE IF( masaRestartCandidate > 0 ) + { + st_ivas->restartNeeded = 1; + move16(); - return IVAS_ERR_OK; - } + return IVAS_ERR_OK; + } - test(); - IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) - { + test(); + IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ){ #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ) - { + IF( Opt_tsm ){ #endif - st_ivas->restartNeeded = 1; - move16(); + st_ivas->restartNeeded = 1; + move16(); - return IVAS_ERR_OK; + return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - } - ELSE - { +} +ELSE +{ #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); - } + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); +} #endif - } +} - st_ivas->nchan_ism = nchan_ism; - move16(); - } - ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) - { - st_ivas->nchan_transport = 2; /* always 2 MASA transport channels */ - move16(); +st_ivas->nchan_ism = nchan_ism; +move16(); +} +ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) +{ + st_ivas->nchan_transport = 2; /* always 2 MASA transport channels */ + move16(); - /* the number of objects are written at the end of the bitstream */ - k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - nchan_ism = add( add( shl( st_ivas->bit_stream[k - 1], 1 ), st_ivas->bit_stream[k - 2] ), 1 ); - st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, nchan_ism ); + /* the number of objects are written at the end of the bitstream */ + k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + nchan_ism = add( add( shl( st_ivas->bit_stream[k - 1], 1 ), st_ivas->bit_stream[k - 2] ), 1 ); + st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, nchan_ism ); - test(); - IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) - { + test(); + IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ){ #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ) - { + IF( Opt_tsm ){ #endif - st_ivas->restartNeeded = 1; - move16(); + st_ivas->restartNeeded = 1; + move16(); - return IVAS_ERR_OK; + return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - } - ELSE - { +} +ELSE +{ #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); - } + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); +} #endif - } +} - st_ivas->nchan_ism = nchan_ism; - move16(); - } - ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) - { - /* the number of objects is written at the end of the bitstream, in the SBA metadata */ - k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - nchan_ism = add( add( shl( st_ivas->bit_stream[k - 1], 1 ), st_ivas->bit_stream[k - 2] ), 1 ); +st_ivas->nchan_ism = nchan_ism; +move16(); +} +ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) +{ + /* the number of objects is written at the end of the bitstream, in the SBA metadata */ + k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + nchan_ism = add( add( shl( st_ivas->bit_stream[k - 1], 1 ), st_ivas->bit_stream[k - 2] ), 1 ); - test(); - IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) - { + test(); + IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ){ #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ) - { + IF( Opt_tsm ){ #endif - st_ivas->restartNeeded = 1; - move16(); + st_ivas->restartNeeded = 1; + move16(); - return IVAS_ERR_OK; + return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - } - ELSE - { +} +ELSE +{ #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); - } + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); +} #endif - } +} - st_ivas->nchan_ism = nchan_ism; - move16(); +st_ivas->nchan_ism = nchan_ism; +move16(); - /* read Ambisonic (SBA) planar flag */ - /*sba_planar = st_ivas->bit_stream[num_bits_read];*/ - num_bits_read = add( num_bits_read, SBA_PLANAR_BITS ); +/* read Ambisonic (SBA) planar flag */ +/*sba_planar = st_ivas->bit_stream[num_bits_read];*/ +num_bits_read = add( num_bits_read, SBA_PLANAR_BITS ); - /* read Ambisonic (SBA) order (0 for signaling OSBA format at low bitrates)*/ - sba_order = st_ivas->bit_stream[num_bits_read + 1]; - move16(); - sba_order = add( sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) ); - num_bits_read = add( num_bits_read, SBA_ORDER_BITS ); +/* read Ambisonic (SBA) order (0 for signaling OSBA format at low bitrates)*/ +sba_order = st_ivas->bit_stream[num_bits_read + 1]; +move16(); +sba_order = add( sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) ); +num_bits_read = add( num_bits_read, SBA_ORDER_BITS ); - /* read the real Ambisonic order when the above bits are used to signal OSBA format */ - IF( LT_32( ivas_total_brate, IVAS_24k4 ) ) - { - sba_order = st_ivas->bit_stream[num_bits_read + 1]; - move16(); - sba_order = add( sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) ); - num_bits_read = add( num_bits_read, SBA_ORDER_BITS ); - } +/* read the real Ambisonic order when the above bits are used to signal OSBA format */ +IF( LT_32( ivas_total_brate, IVAS_24k4 ) ) +{ + sba_order = st_ivas->bit_stream[num_bits_read + 1]; + move16(); + sba_order = add( sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) ); + num_bits_read = add( num_bits_read, SBA_ORDER_BITS ); +} - test(); - IF( st_ivas->ini_frame > 0 && NE_16( sba_order, st_ivas->sba_order ) ) - { +test(); +IF( st_ivas->ini_frame > 0 && NE_16( sba_order, st_ivas->sba_order ) ){ #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ) - { + IF( Opt_tsm ){ #endif - st_ivas->restartNeeded = 1; - move16(); + st_ivas->restartNeeded = 1; +move16(); - return IVAS_ERR_OK; +return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - } - ELSE - { +} +ELSE +{ #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" ); + fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" ); - } + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" ); +} #endif - } +} - st_ivas->ism_mode = ivas_osba_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); +st_ivas->ism_mode = ivas_osba_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); - sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, sba_order ); - st_ivas->nchan_transport = ivas_get_sba_num_TCs_fx( ivas_total_brate, sba_analysis_order ); - } - ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) +sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, sba_order ); +st_ivas->nchan_transport = ivas_get_sba_num_TCs_fx( ivas_total_brate, sba_analysis_order ); +} +ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) +{ + /* read MC configuration */ + idx = 0; + move16(); + FOR( k = 0; k < MC_LS_SETUP_BITS; k++ ) + { + IF( st_ivas->bit_stream[num_bits_read + k] ) { - /* read MC configuration */ - idx = 0; - move16(); - FOR( k = 0; k < MC_LS_SETUP_BITS; k++ ) - { - IF( st_ivas->bit_stream[num_bits_read + k] ) - { - idx = add( idx, shl( 1, sub( ( MC_LS_SETUP_BITS - 1 ), k ) ) ); - } - } - num_bits_read = add( num_bits_read, MC_LS_SETUP_BITS ); + idx = add( idx, shl( 1, sub( ( MC_LS_SETUP_BITS - 1 ), k ) ) ); + } + } + num_bits_read = add( num_bits_read, MC_LS_SETUP_BITS ); - signaled_config = ivas_mc_map_ls_setup_to_output_config_fx( idx ); + signaled_config = ivas_mc_map_ls_setup_to_output_config_fx( idx ); - test(); - IF( st_ivas->ini_frame > 0 && NE_32( st_ivas->transport_config, signaled_config ) ) - { + test(); + IF( st_ivas->ini_frame > 0 && NE_32( st_ivas->transport_config, signaled_config ) ){ #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ) - { + IF( Opt_tsm ){ #endif - st_ivas->restartNeeded = 1; - move16(); + st_ivas->restartNeeded = 1; + move16(); - return IVAS_ERR_OK; + return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - } - ELSE - { +} +ELSE +{ #ifdef DEBUGGING - fprintf( stderr, "\nError: Switching of MC configurations is not supported!\n" ); + fprintf( stderr, "\nError: Switching of MC configurations is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "wrong MC configuration signalled!" ); - } + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "wrong MC configuration signalled!" ); +} #endif - } +} - st_ivas->mc_mode = ivas_mc_mode_select_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( signaled_config ), ivas_total_brate ); - st_ivas->transport_config = signaled_config; - move16(); - } +st_ivas->mc_mode = ivas_mc_mode_select_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( signaled_config ), ivas_total_brate ); +st_ivas->transport_config = signaled_config; +move16(); +} - /*-------------------------------------------------------------------* - * Read element mode - *-------------------------------------------------------------------*/ +/*-------------------------------------------------------------------* + * Read element mode + *-------------------------------------------------------------------*/ - test(); - IF( st_ivas->ini_frame == 0 && element_mode_flag ) +test(); +IF( st_ivas->ini_frame == 0 && element_mode_flag ) +{ + /* read stereo technology info */ + if ( LT_32( ivas_total_brate, MIN_BRATE_MDCT_STEREO ) ) + { + /* 1 bit */ + IF( st_ivas->bit_stream[num_bits_read] ) { - /* read stereo technology info */ - if ( LT_32( ivas_total_brate, MIN_BRATE_MDCT_STEREO ) ) + st_ivas->element_mode_init = add( 1, IVAS_CPE_DFT ); + } + ELSE + { + st_ivas->element_mode_init = add( 0, IVAS_CPE_DFT ); + } + } + ELSE + { + st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); + } +} +} +ELSE IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) +{ + SWITCH( st_ivas->sid_format ) + { + case SID_DFT_STEREO: + st_ivas->element_mode_init = IVAS_CPE_DFT; + move16(); + BREAK; + case SID_MDCT_STEREO: + st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); + BREAK; + case SID_ISM: + st_ivas->element_mode_init = IVAS_SCE; + move16(); + BREAK; + case SID_MASA_1TC: + st_ivas->element_mode_init = IVAS_SCE; + move16(); + st_ivas->nchan_transport = 1; + move16(); + BREAK; + case SID_MASA_2TC: + k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + IF( st_ivas->bit_stream[k - 1 - SID_FORMAT_NBITS] == 1 ) { - /* 1 bit */ - IF( st_ivas->bit_stream[num_bits_read] ) - { - st_ivas->element_mode_init = add( 1, IVAS_CPE_DFT ); - } - ELSE - { - st_ivas->element_mode_init = add( 0, IVAS_CPE_DFT ); - } + st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); } ELSE { - st_ivas->element_mode_init = IVAS_CPE_MDCT; + st_ivas->element_mode_init = IVAS_CPE_DFT; move16(); } - } + st_ivas->nchan_transport = 2; + move16(); + BREAK; + case SID_SBA_1TC: + st_ivas->element_mode_init = IVAS_SCE; + move16(); + BREAK; + case SID_SBA_2TC: + st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); + BREAK; } - ELSE IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) - { - SWITCH( st_ivas->sid_format ) - { - case SID_DFT_STEREO: - st_ivas->element_mode_init = IVAS_CPE_DFT; - move16(); - BREAK; - case SID_MDCT_STEREO: - st_ivas->element_mode_init = IVAS_CPE_MDCT; - move16(); - BREAK; - case SID_ISM: - st_ivas->element_mode_init = IVAS_SCE; - move16(); - BREAK; - case SID_MASA_1TC: - st_ivas->element_mode_init = IVAS_SCE; - move16(); - st_ivas->nchan_transport = 1; - move16(); - BREAK; - case SID_MASA_2TC: - k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - IF( st_ivas->bit_stream[k - 1 - SID_FORMAT_NBITS] == 1 ) - { - st_ivas->element_mode_init = IVAS_CPE_MDCT; - move16(); - } - ELSE - { - st_ivas->element_mode_init = IVAS_CPE_DFT; - move16(); - } - st_ivas->nchan_transport = 2; - move16(); - BREAK; - case SID_SBA_1TC: - st_ivas->element_mode_init = IVAS_SCE; - move16(); - BREAK; - case SID_SBA_2TC: - st_ivas->element_mode_init = IVAS_CPE_MDCT; - move16(); - BREAK; - } - IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) + IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) + { + /* read the number of objects */ + nchan_ism = 1; + move16(); + k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + k = sub( sub( k, 1 ), SID_FORMAT_NBITS ); + WHILE( st_ivas->bit_stream[k] && ( nchan_ism < MAX_NUM_OBJECTS ) ) { - /* read the number of objects */ - nchan_ism = 1; - move16(); - k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - k = sub( sub( k, 1 ), SID_FORMAT_NBITS ); - WHILE( st_ivas->bit_stream[k] && ( nchan_ism < MAX_NUM_OBJECTS ) ) - { - nchan_ism = add( nchan_ism, 1 ); - k = sub( k, 1 ); - } + nchan_ism = add( nchan_ism, 1 ); k = sub( k, 1 ); + } + k = sub( k, 1 ); - test(); - IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) - { + test(); + IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ){ #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ) - { + IF( Opt_tsm ){ #endif - st_ivas->restartNeeded = 1; - move16(); + st_ivas->restartNeeded = 1; + move16(); - return IVAS_ERR_OK; + return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - } - ELSE - { + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); - } + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } #endif - } +} - st_ivas->nchan_ism = nchan_ism; - move16(); +st_ivas->nchan_ism = nchan_ism; +move16(); - /* read ism_mode */ - st_ivas->ism_mode = ISM_MODE_DISC; - move32(); - IF( GT_16( nchan_ism, 2 ) ) - { - k = sub( k, nchan_ism ); /* SID metadata flags */ - idx = st_ivas->bit_stream[k]; - move16(); - st_ivas->ism_mode = (ISM_MODE) add( idx, 1 ); - move32(); - } +/* read ism_mode */ +st_ivas->ism_mode = ISM_MODE_DISC; +move32(); +IF( GT_16( nchan_ism, 2 ) ) +{ + k = sub( k, nchan_ism ); /* SID metadata flags */ + idx = st_ivas->bit_stream[k]; + move16(); + st_ivas->ism_mode = (ISM_MODE) add( idx, 1 ); + move32(); +} - st_ivas->nchan_transport = nchan_ism; - move16(); - if ( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) - { - st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; - move16(); - } - } - } +st_ivas->nchan_transport = nchan_ism; +move16(); +if ( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) +{ + st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; + move16(); +} +} +} - st_ivas->bit_stream = bit_stream_orig; +st_ivas->bit_stream = bit_stream_orig; - return IVAS_ERR_OK; +return IVAS_ERR_OK; } @@ -1572,7 +1552,12 @@ ivas_error ivas_init_decoder_front( * Allocate and initialize Custom loudspeaker layout handle *--------------------------------------------------------------------*/ +#ifdef FIX_FMSW_DEC + test(); + IF( st_ivas->hDecoderConfig->Opt_LsCustom && st_ivas->hLsSetupCustom == NULL ) +#else IF( st_ivas->hDecoderConfig->Opt_LsCustom ) +#endif { IF( EQ_32( ( error = ivas_ls_custom_open_fx( &( st_ivas->hLsSetupCustom ) ) ), IVAS_ERR_OK ) ) { @@ -1589,7 +1574,12 @@ ivas_error ivas_init_decoder_front( * Allocate and initialize Head-Tracking handle *--------------------------------------------------------------------*/ +#ifdef FIX_FMSW_DEC + test(); + IF( st_ivas->hDecoderConfig->Opt_Headrotation && st_ivas->hHeadTrackData == NULL ) +#else IF( st_ivas->hDecoderConfig->Opt_Headrotation ) +#endif { IF( NE_32( ( error = ivas_headTrack_open_fx( &( st_ivas->hHeadTrackData ) ) ), IVAS_ERR_OK ) ) { @@ -1606,7 +1596,12 @@ ivas_error ivas_init_decoder_front( * Allocate and initialize external orientation handle *--------------------------------------------------------------------*/ +#ifdef FIX_FMSW_DEC + test(); + IF( st_ivas->hDecoderConfig->Opt_ExternalOrientation && st_ivas->hExtOrientationData == NULL ) +#else IF( st_ivas->hDecoderConfig->Opt_ExternalOrientation ) +#endif { IF( NE_32( ( error = ivas_external_orientation_open_fx( &( st_ivas->hExtOrientationData ), st_ivas->hDecoderConfig->render_num_subframes ) ), IVAS_ERR_OK ) ) { @@ -1619,7 +1614,12 @@ ivas_error ivas_init_decoder_front( *--------------------------------------------------------------------*/ test(); +#ifdef FIX_FMSW_DEC + test(); + IF( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && st_ivas->hCombinedOrientationData == NULL ) +#else IF( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) +#endif { IF( NE_32( ( error = ivas_combined_orientation_open_fx( &( st_ivas->hCombinedOrientationData ), st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->render_num_subframes ) ), IVAS_ERR_OK ) ) { @@ -1637,8 +1637,15 @@ ivas_error ivas_init_decoder_front( test(); test(); test(); +#ifdef FIX_FMSW_DEC + test(); + IF( ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) || + ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) && st_ivas->hDecoderConfig->Opt_non_diegetic_pan ) ) && + st_ivas->hRenderConfig == NULL ) +#else IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) || ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) && st_ivas->hDecoderConfig->Opt_non_diegetic_pan ) ) +#endif { IF( NE_32( ( error = ivas_render_config_open_fx( &( st_ivas->hRenderConfig ) ) ), IVAS_ERR_OK ) ) { @@ -3348,7 +3355,14 @@ void ivas_initialize_handles_dec( st_ivas->hCPE[i] = NULL; } - st_ivas->bit_stream = NULL; +#ifdef FIX_FMSW_DEC + IF( !st_ivas->restartNeeded ) + { +#endif + st_ivas->bit_stream = NULL; +#ifdef FIX_FMSW_DEC + } +#endif st_ivas->mem_hp20_out_fx = NULL; st_ivas->hLimiter = NULL; @@ -3393,15 +3407,22 @@ void ivas_initialize_handles_dec( st_ivas->hMasaIsmData = NULL; st_ivas->hSbaIsmData = NULL; - st_ivas->hHeadTrackData = NULL; - st_ivas->hHrtfTD = NULL; - st_ivas->hLsSetupCustom = NULL; - st_ivas->hRenderConfig = NULL; - st_ivas->hExtOrientationData = NULL; - st_ivas->hCombinedOrientationData = NULL; - st_ivas->acousticEnvironmentsCount = 0; - move16(); - st_ivas->pAcousticEnvironments = NULL; +#ifdef FIX_FMSW_DEC + IF( !st_ivas->restartNeeded ) + { +#endif + st_ivas->hHeadTrackData = NULL; + st_ivas->hHrtfTD = NULL; + st_ivas->hLsSetupCustom = NULL; + st_ivas->hRenderConfig = NULL; + st_ivas->hExtOrientationData = NULL; + st_ivas->hCombinedOrientationData = NULL; + st_ivas->acousticEnvironmentsCount = 0; + move16(); + st_ivas->pAcousticEnvironments = NULL; +#ifdef FIX_FMSW_DEC + } +#endif st_ivas->hSplitBinRend = NULL; FOR( i = 0; i < MAX_HEAD_ROT_POSES - 1; ++i ) @@ -3429,10 +3450,17 @@ void ivas_initialize_handles_dec( *-------------------------------------------------------------------------*/ void ivas_destroy_dec_fx( +#ifdef FIX_FMSW_DEC + Decoder_Struct **st_ivas_out /* i/o: IVAS decoder handle */ +#else Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ +#endif ) { Word16 i; +#ifdef FIX_FMSW_DEC + Decoder_Struct *st_ivas = *st_ivas_out; +#endif /* CLDFB handles */ FOR( i = 0; i < MAX_INTERN_CHANNELS; i++ ) @@ -3564,11 +3592,18 @@ void ivas_destroy_dec_fx( ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); /* Custom LS configuration handle */ - IF( st_ivas->hLsSetupCustom != NULL ) +#ifdef FIX_FMSW_DEC + IF( !st_ivas->restartNeeded ) { - free( st_ivas->hLsSetupCustom ); - st_ivas->hLsSetupCustom = NULL; +#endif + IF( st_ivas->hLsSetupCustom != NULL ) + { + free( st_ivas->hLsSetupCustom ); + st_ivas->hLsSetupCustom = NULL; + } +#ifdef FIX_FMSW_DEC } +#endif /* Mono downmix structure */ ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer ); @@ -3604,25 +3639,48 @@ void ivas_destroy_dec_fx( /* HRTF statistics */ ivas_HRTF_statistics_binary_close_fx( &st_ivas->hHrtfStatistics ); - /* Config. Renderer */ - ivas_render_config_close_fx( &( st_ivas->hRenderConfig ) ); +#ifdef FIX_FMSW_DEC + /* Limiter struct */ + ivas_limiter_close_fx( &( st_ivas->hLimiter ) ); - /* Acoustic environments */ - IF( st_ivas->pAcousticEnvironments != NULL ) + IF( !st_ivas->restartNeeded ) { - free( st_ivas->pAcousticEnvironments ); - st_ivas->pAcousticEnvironments = NULL; - } +#endif + /* Config. Renderer */ + ivas_render_config_close_fx( &( st_ivas->hRenderConfig ) ); - /* Limiter struct */ - ivas_limiter_close_fx( &( st_ivas->hLimiter ) ); + /* Acoustic environments */ + IF( st_ivas->pAcousticEnvironments != NULL ) + { + free( st_ivas->pAcousticEnvironments ); + st_ivas->pAcousticEnvironments = NULL; + } - /* Decoder configuration structure */ - IF( st_ivas->hDecoderConfig != NULL ) +#ifndef FIX_FMSW_DEC + /* Limiter struct */ + ivas_limiter_close_fx( &( st_ivas->hLimiter ) ); +#endif + /* Decoder configuration structure */ + IF( st_ivas->hDecoderConfig != NULL ) + { + free( st_ivas->hDecoderConfig ); + st_ivas->hDecoderConfig = NULL; + } +#ifdef FIX_FMSW_DEC + } + ELSE { - free( st_ivas->hDecoderConfig ); - st_ivas->hDecoderConfig = NULL; + /* resets in case of format switching */ + st_ivas->nchan_ism = 0; + st_ivas->ism_mode = ISM_MODE_NONE; + st_ivas->mc_mode = MC_MODE_NONE; + st_ivas->sba_dirac_stereo_flag = 0; + move16(); + move16(); + move16(); + move16(); } +#endif /* TC buffer structure */ ivas_dec_tc_buffer_close_fx( &st_ivas->hTcBuffer ); @@ -3640,7 +3698,15 @@ void ivas_destroy_dec_fx( } /* main IVAS handle */ +#ifdef FIX_FMSW_DEC + if ( !st_ivas->restartNeeded ) + { + free( *st_ivas_out ); + *st_ivas_out = NULL; + } +#else free( st_ivas ); +#endif return; } diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index c42dd0a09..89d2e967c 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -128,6 +128,13 @@ ivas_error IVAS_DEC_Configure( const bool delayCompensationEnabled /* i : enable delay compensation */ ); +#ifdef FIX_FMSW_DEC +ivas_error IVAS_DEC_Restart( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const IVAS_DEC_MODE mode /* i : compatibility mode (EVS or IVAS) */ +); + +#endif void IVAS_DEC_Close( IVAS_DEC_HANDLE *phIvasDec /* i/o: pointer to IVAS decoder handle */ ); diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index f79e5f233..bbc6165ca 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -122,6 +122,96 @@ static Word16 ivas_dec_split_rend_cldfb_in( const RENDERER_TYPE renderer_type ); static void update_voip_rendered20ms( IVAS_DEC_HANDLE hIvasDec, const Word16 nSamplesRendered ); +#ifdef FIX_FMSW_DEC + +/*---------------------------------------------------------------------* + * ivas_dec_handle_init() + * + * Set IVAS decoder handles to NULL + set high-level parameters + *---------------------------------------------------------------------*/ + +static ivas_error ivas_dec_handle_init( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const IVAS_DEC_MODE mode, /* i : compatibility mode (EVS or IVAS) */ + bool *hasDecodedFirstGoodFrame /* o : flag indicating if the decoder has decoded a good frame since it was configured */ +) +{ + IF( st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + /* initialize pointers to handles to NULL */ + ivas_initialize_handles_dec( st_ivas ); + + st_ivas->restartNeeded = 0; + move16(); + + /* set high-level parameters */ + + st_ivas->codec_mode = 0; /* unknown before first frame */ + st_ivas->transport_config = IVAS_AUDIO_CONFIG_INVALID; + st_ivas->intern_config = IVAS_AUDIO_CONFIG_INVALID; + st_ivas->writeFECoffset = 0; + st_ivas->sba_analysis_order = 0; /* not really used in EVS mode, but initialize here to fix MSAN complaint */ + move16(); + move16(); + move16(); + move16(); + move16(); + +#ifdef FIX_FMSW_DEC_2 + st_ivas->last_ivas_format = UNDEFINED_FORMAT; + st_ivas->nSCE = 0; + st_ivas->nCPE = 0; + move16(); + move16(); + move16(); + +#endif + IF( EQ_16( mode, IVAS_DEC_MODE_EVS ) ) + { + st_ivas->element_mode_init = EVS_MONO; + st_ivas->ivas_format = MONO_FORMAT; + *hasDecodedFirstGoodFrame = true; /* Functionality to suppress output for initial lost frames is disabled in EVS operation */ + move16(); + move16(); + move16(); + + return IVAS_ERR_OK; + } + ELSE IF( EQ_16( mode, IVAS_DEC_MODE_IVAS ) ) + { + st_ivas->element_mode_init = -1; + st_ivas->ivas_format = UNDEFINED_FORMAT; + st_ivas->renderer_type = RENDERER_DISABLE; + st_ivas->ini_frame = 0; + st_ivas->ini_active_frame = 0; + + st_ivas->ism_mode = ISM_MODE_NONE; + st_ivas->mc_mode = MC_MODE_NONE; + + st_ivas->sba_order = 0; + st_ivas->sba_planar = 0; + + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + + return IVAS_ERR_OK; + } + + return IVAS_ERR_WRONG_PARAMS; +} + +#endif + /*---------------------------------------------------------------------* * IVAS_DEC_Open() * @@ -142,6 +232,13 @@ ivas_error IVAS_DEC_Open( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } +#ifdef FIX_FMSW_DEC + if ( *phIvasDec != NULL ) + { + return IVAS_ERR_WRONG_PARAMS; + } + +#endif /*-----------------------------------------------------------------* * Allocate and initialize IVAS application decoder handle *-----------------------------------------------------------------*/ @@ -222,9 +319,18 @@ ivas_error IVAS_DEC_Open( st_ivas = hIvasDec->st_ivas; +#ifdef FIX_FMSW_DEC + st_ivas->restartNeeded = 0; + move16(); +#endif + /* initialize Decoder Config. handle */ init_decoder_config( hIvasDec->st_ivas->hDecoderConfig ); +#ifdef FIX_FMSW_DEC + /* Set IVAS decoder handles to NULL + set high-level parameters */ + return ivas_dec_handle_init( st_ivas, mode, &( hIvasDec->hasDecodedFirstGoodFrame ) ); +#else /* initialize pointers to handles to NULL */ ivas_initialize_handles_dec( st_ivas ); @@ -282,8 +388,78 @@ ivas_error IVAS_DEC_Open( } return IVAS_ERR_WRONG_PARAMS; +#endif +} + +#ifdef FIX_FMSW_DEC + +/*---------------------------------------------------------------------* + * IVAS_DEC_Restart() + * + * Restart IVAS decoder - used in case of format switching + *---------------------------------------------------------------------*/ + +ivas_error IVAS_DEC_Restart( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const IVAS_DEC_MODE mode /* i : compatibility mode (EVS or IVAS) */ +) +{ + test(); + IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + IF( !hIvasDec->st_ivas->restartNeeded ) + { + IF( EQ_16( hIvasDec->mode, mode ) ) + { + return IVAS_ERR_OK; + } +#ifdef FIX_FMSW_DEC_2 + ELSE + { + /* switching between EVS and IVAS signaled in RTP */ + hIvasDec->st_ivas->restartNeeded = 1; + move16(); + } +#else + return IVAS_ERR_WRONG_PARAMS; +#endif + } + +#ifdef FIX_FMSW_DEC_2 + IF( NE_16( hIvasDec->mode, mode ) ) /* handle switching between EVS and IVAS */ + { + /* initialize JBM */ + IF( JB4_Init( hIvasDec->hVoIP->hJBM, 60 ) != 0 ) + { + return IVAS_ERR_FAILED_ALLOC; + } + + hIvasDec->hasBeenFedFirstGoodFrame = false; + hIvasDec->hasDecodedFirstGoodFrame = false; + hIvasDec->isInitialized = false; + move16(); + move16(); + move16(); + } + +#endif + hIvasDec->mode = mode; + move16(); + + /* destroy Split binaural renderer (ISAR) handle */ + ivas_destroy_handle_isar( &hIvasDec->st_ivas->hSplitBinRend ); + + /* destroy IVAS decoder handles */ + ivas_destroy_dec_fx( &hIvasDec->st_ivas ); + + /* Set IVAS decoder handles to NULL + set high-level parameters */ + return ivas_dec_handle_init( hIvasDec->st_ivas, mode, &( hIvasDec->hasDecodedFirstGoodFrame ) ); } +#endif /*-------------------------------------------------------------------------* * isar_set_split_rend_setup() @@ -405,8 +581,12 @@ void IVAS_DEC_Close( ivas_destroy_handle_isar( &( *phIvasDec )->st_ivas->hSplitBinRend ); /* destroy IVAS decoder handles */ +#ifdef FIX_FMSW_DEC + ivas_destroy_dec_fx( &( *phIvasDec )->st_ivas ); +#else ivas_destroy_dec_fx( ( *phIvasDec )->st_ivas ); ( *phIvasDec )->st_ivas = NULL; +#endif } apa_exit( &( *phIvasDec )->hTimeScaler ); @@ -4696,7 +4876,7 @@ static ivas_error ivas_dec_voip_get_samples_common IF( hIvasDec->hasBeenFedFirstGoodFrame ) { - /* check if the TC buffer already exists, otherweise nothing is buffered anyway */ + /* check if the TC buffer already exists, otherwise nothing is buffered anyway */ IF( st_ivas->hTcBuffer != NULL ) { nSamplesBuffered = sub( st_ivas->hTcBuffer->n_samples_buffered, st_ivas->hTcBuffer->n_samples_rendered ); @@ -5643,6 +5823,10 @@ static ivas_error evs_dec_main_fx( st_ivas->BER_detect = hCoreCoder[0]->BER_detect; move16(); +#ifdef FIX_FMSW_DEC + st_ivas->last_ivas_format = MONO_FORMAT; + move16(); +#endif /*if ( st_ivas->hDecoderConfig->Opt_tsm && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO )*/ { diff --git a/lib_util/ivas_rtp_api.h b/lib_util/ivas_rtp_api.h index db889f562..7a25e4123 100644 --- a/lib_util/ivas_rtp_api.h +++ b/lib_util/ivas_rtp_api.h @@ -82,6 +82,9 @@ /* IVAS Codec Types */ typedef enum { +#ifdef FIX_FMSW_DEC + IVAS_RTP_UNDEF = -1, /* undefined = Codec Type not set yet */ +#endif IVAS_RTP_EVS, /* EVS */ IVAS_RTP_IVAS /* IVAS */ } IVAS_RTP_CODEC; diff --git a/lib_util/ivas_rtp_file.c b/lib_util/ivas_rtp_file.c index 4aba3a0c0..7e741826b 100644 --- a/lib_util/ivas_rtp_file.c +++ b/lib_util/ivas_rtp_file.c @@ -1000,6 +1000,9 @@ ivas_error IVAS_RTP_READER_Init( rtp->unpackCfg.maxFramesPerPacket = IVAS_MAX_FRAMES_PER_RTP_PACKET; rtp->rtpPacket.buffer = rtp->packet; rtp->rtpPacket.capacity = sizeof( rtp->packet ); +#ifdef FIX_FMSW_DEC + rtp->codecId = IVAS_RTP_UNDEF; +#endif error = IVAS_RTP_UNPACK_Open( &rtp->hUnpack, &rtp->unpackCfg ); if ( error == IVAS_ERR_OK ) @@ -1187,6 +1190,17 @@ ivas_error IVAS_RTP_ReadNextFrame( } else { +#ifdef FIX_FMSW_DEC + if ( rtp->codecId != IVAS_RTP_UNDEF && rtp->codecId != codecId ) + { + rtp->restartNeeded = true; + + fprintf( stdout, "\nRTP packet codec changed %s -> %s\n", + ( rtp->codecId == IVAS_RTP_EVS ) ? "EVS" : "IVAS", + ( codecId == IVAS_RTP_EVS ) ? "EVS" : "IVAS" ); + } +#else + rtp->restartNeeded = ( rtp->codecId != codecId ) || ( codecId == IVAS_RTP_EVS && ( rtp->isAMRWB_IOmode != isAMRWB_IOmode ) ); @@ -1196,6 +1210,7 @@ ivas_error IVAS_RTP_ReadNextFrame( ( rtp->codecId == IVAS_RTP_EVS ) ? ( rtp->isAMRWB_IOmode ? "AMRWB_IO" : "EVS" ) : "IVAS", ( codecId == IVAS_RTP_EVS ) ? ( isAMRWB_IOmode ? "AMRWB_IO" : "EVS" ) : "IVAS" ); } +#endif rtp->codecId = codecId; rtp->isAMRWB_IOmode = isAMRWB_IOmode; diff --git a/readme.txt b/readme.txt index 1db279fc5..1b2d73fd6 100644 --- a/readme.txt +++ b/readme.txt @@ -263,6 +263,7 @@ EVS mono is default, for IVAS choose one of the following: -stereo, -ism, -sba, bitstream frames into TS26.253 Annex A IVAS RTP Payload Format packets and writes those to the output file. In EVS mono operating mode, TS26.445 Annex A.2.2 EVS RTP Payload Format is used. Optional N represents number of frames per RTP packet +-requests : Remote requests file, Only used with rtpdump output. -scene_orientation : Scene orientation trajectory file. Only used with rtpdump output. -device_orientation : Device orientation trajectory file. Only used with rtpdump output. -- GitLab From 1fc10daab5c00026f569bf6afe3f06c0654192b8 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 21 Apr 2026 11:21:02 +0200 Subject: [PATCH 2/4] clang-format --- lib_dec/ivas_init_dec_fx.c | 842 +++++++++++++++++++------------------ 1 file changed, 431 insertions(+), 411 deletions(-) diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index dba807136..50d1c411f 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -144,539 +144,559 @@ ivas_error ivas_dec_get_format_fx( test(); IF( st_ivas->ini_frame > 0 && NE_32( st_ivas->ivas_format, st_ivas->last_ivas_format ) && !( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && EQ_32( st_ivas->last_ivas_format, MASA_ISM_FORMAT ) ) && - !( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->last_ivas_format, MASA_FORMAT ) ) ){ + !( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->last_ivas_format, MASA_FORMAT ) ) ) + { #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ){ + IF( Opt_tsm ) + { #endif st_ivas->restartNeeded = 1; - move16(); + move16(); - return IVAS_ERR_OK; + return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH -} -ELSE -{ + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); -} + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } #endif -} - -/*-------------------------------------------------------------------* - * Read other signaling (ISM/MC mode, number of channels, etc.) - *-------------------------------------------------------------------*/ + } -IF( is_DTXrate( ivas_total_brate ) == 0 ) -{ /*-------------------------------------------------------------------* - * Read IVAS format related signaling: - * - in ISM : read number of objects - * - in SBA : read SBA planar flag and SBA order - * - in MASA : read number of TC - * - in MC : read LS setup + * Read other signaling (ISM/MC mode, number of channels, etc.) *-------------------------------------------------------------------*/ - IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) - { - element_mode_flag = 1; - move16(); - } - ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) + IF( is_DTXrate( ivas_total_brate ) == 0 ) { - /* read the number of objects */ - nchan_ism = 1; - move16(); - k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - k = sub( k, 1 ); - WHILE( st_ivas->bit_stream[k] && ( nchan_ism < MAX_NUM_OBJECTS ) ) + /*-------------------------------------------------------------------* + * Read IVAS format related signaling: + * - in ISM : read number of objects + * - in SBA : read SBA planar flag and SBA order + * - in MASA : read number of TC + * - in MC : read LS setup + *-------------------------------------------------------------------*/ + + IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) { - nchan_ism = add( nchan_ism, 1 ); - k = sub( k, 1 ); + element_mode_flag = 1; + move16(); } + ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) + { + /* read the number of objects */ + nchan_ism = 1; + move16(); + k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + k = sub( k, 1 ); + WHILE( st_ivas->bit_stream[k] && ( nchan_ism < MAX_NUM_OBJECTS ) ) + { + nchan_ism = add( nchan_ism, 1 ); + k = sub( k, 1 ); + } - test(); - IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ){ + test(); + IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) + { #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ){ + IF( Opt_tsm ) + { #endif - st_ivas->restartNeeded = 1; - move16(); + st_ivas->restartNeeded = 1; + move16(); - return IVAS_ERR_OK; + return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - } - ELSE - { + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); - } + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } #endif -} - -st_ivas->nchan_ism = nchan_ism; -move16(); -st_ivas->ism_mode = ivas_ism_mode_select( nchan_ism, ivas_total_brate ); - -st_ivas->nchan_transport = nchan_ism; -move16(); -if ( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) -{ - st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; - move16(); -} -} -ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) -{ - /* read Ambisonic (SBA) planar flag */ - sba_planar = st_ivas->bit_stream[num_bits_read]; - num_bits_read = add( num_bits_read, SBA_PLANAR_BITS ); + } - test(); - IF( st_ivas->ini_frame > 0 && NE_16( sba_planar, st_ivas->sba_planar ) ){ + st_ivas->nchan_ism = nchan_ism; + move16(); + st_ivas->ism_mode = ivas_ism_mode_select( nchan_ism, ivas_total_brate ); + + st_ivas->nchan_transport = nchan_ism; + move16(); + if ( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) + { + st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; + move16(); + } + } + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) + { + /* read Ambisonic (SBA) planar flag */ + sba_planar = st_ivas->bit_stream[num_bits_read]; + num_bits_read = add( num_bits_read, SBA_PLANAR_BITS ); + + test(); + IF( st_ivas->ini_frame > 0 && NE_16( sba_planar, st_ivas->sba_planar ) ) + { #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ){ + IF( Opt_tsm ) + { #endif - st_ivas->restartNeeded = 1; - move16(); + st_ivas->restartNeeded = 1; + move16(); - return IVAS_ERR_OK; + return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH -} -ELSE -{ + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the SBA planar/3D layout is not supported!\n" ); + fprintf( stderr, "\nError: Changing the SBA planar/3D layout is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA planar flag signalled!" ); -} + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA planar flag signalled!" ); + } #endif -} - -/* read Ambisonic (SBA) order */ -sba_order = st_ivas->bit_stream[num_bits_read + 1]; -move16(); -sba_order = add( sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) ); + } -test(); -IF( st_ivas->ini_frame > 0 && NE_16( sba_order, st_ivas->sba_order ) ){ + /* read Ambisonic (SBA) order */ + sba_order = st_ivas->bit_stream[num_bits_read + 1]; + move16(); + sba_order = add( sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) ); + + test(); + IF( st_ivas->ini_frame > 0 && NE_16( sba_order, st_ivas->sba_order ) ) + { #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ){ + IF( Opt_tsm ) + { #endif - st_ivas->restartNeeded = 1; -move16(); + st_ivas->restartNeeded = 1; + move16(); -return IVAS_ERR_OK; + return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH -} -ELSE -{ + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" ); + fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" ); -} + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" ); + } #endif -} - -sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, sba_order ); -st_ivas->nchan_transport = ivas_get_sba_num_TCs_fx( ivas_total_brate, sba_analysis_order ); -} -ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) -{ - UWord8 masaRestartCandidate; - masaRestartCandidate = 0; - move16(); + } - /* read number of MASA transport channels */ - k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - IF( st_ivas->bit_stream[k - 1] ) - { + sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, sba_order ); + st_ivas->nchan_transport = ivas_get_sba_num_TCs_fx( ivas_total_brate, sba_analysis_order ); + } + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) + { + UWord8 masaRestartCandidate; + masaRestartCandidate = 0; + move16(); + + /* read number of MASA transport channels */ + k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + IF( st_ivas->bit_stream[k - 1] ) + { #ifdef FIX_FLOAT_1539_G192_FORMAT_SWITCH - if ( st_ivas->nchan_transport == 1 ) + if ( st_ivas->nchan_transport == 1 ) #else - test(); - if ( st_ivas->nchan_transport == 1 && Opt_tsm ) + test(); + if ( st_ivas->nchan_transport == 1 && Opt_tsm ) #endif - { - masaRestartCandidate = 1; - move16(); - } + { + masaRestartCandidate = 1; + move16(); + } - st_ivas->nchan_transport = 2; - move16(); - element_mode_flag = 1; - move16(); - } - ELSE - { + st_ivas->nchan_transport = 2; + move16(); + element_mode_flag = 1; + move16(); + } + ELSE + { #ifdef FIX_FLOAT_1539_G192_FORMAT_SWITCH - if ( st_ivas->nchan_transport == 2 ) + if ( st_ivas->nchan_transport == 2 ) #else - test(); - if ( st_ivas->nchan_transport == 2 && Opt_tsm ) + test(); + if ( st_ivas->nchan_transport == 2 && Opt_tsm ) #endif - { - masaRestartCandidate = 1; - move16(); - } - - st_ivas->nchan_transport = 1; - move16(); - } - - /* this should be non-zero if original input format was MASA_ISM_FORMAT */ - st_ivas->ism_mode = ISM_MODE_NONE; - move16(); - nchan_ism = add( st_ivas->bit_stream[k - 3], shl( st_ivas->bit_stream[k - 2], 1 ) ); - - IF( nchan_ism > 0 ) - { - /* the input_ivas_format should be MASA_ISM_FORMAT, but we cannot initialize it now */ - /* info about the number of objects: - '00' - MASA format at the encoder - '01' - MASA_ISM_FORMAT at the encoder, with 4 objects - '10' - MASA_ISM_FORMAT at the encoder, with 3 objects - '11' - MASA_ISM_FORMAT at the encoder, with 1 or 2 objects - reading if 1 or 2 objects is performed later - */ - nchan_ism = sub( 5, nchan_ism ); - test(); - IF( EQ_16( st_ivas->nchan_transport, 1 ) && EQ_16( nchan_ism, 2 ) ) - { - nchan_ism = 1; + { + masaRestartCandidate = 1; + move16(); + } + + st_ivas->nchan_transport = 1; + move16(); + } + + /* this should be non-zero if original input format was MASA_ISM_FORMAT */ + st_ivas->ism_mode = ISM_MODE_NONE; move16(); - } - - /* for MASA_ISM_FORMAT at input the number of MASA transport channels is always 2 and the corresponding bit is not used here*/ - st_ivas->nchan_transport = 2; - move16(); - element_mode_flag = 1; - move16(); - } - ELSE IF( masaRestartCandidate > 0 ) - { - st_ivas->restartNeeded = 1; - move16(); - - return IVAS_ERR_OK; - } - - test(); - IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ){ + nchan_ism = add( st_ivas->bit_stream[k - 3], shl( st_ivas->bit_stream[k - 2], 1 ) ); + + IF( nchan_ism > 0 ) + { + /* the input_ivas_format should be MASA_ISM_FORMAT, but we cannot initialize it now */ + /* info about the number of objects: + '00' - MASA format at the encoder + '01' - MASA_ISM_FORMAT at the encoder, with 4 objects + '10' - MASA_ISM_FORMAT at the encoder, with 3 objects + '11' - MASA_ISM_FORMAT at the encoder, with 1 or 2 objects + reading if 1 or 2 objects is performed later + */ + nchan_ism = sub( 5, nchan_ism ); + test(); + IF( EQ_16( st_ivas->nchan_transport, 1 ) && EQ_16( nchan_ism, 2 ) ) + { + nchan_ism = 1; + move16(); + } + + /* for MASA_ISM_FORMAT at input the number of MASA transport channels is always 2 and the corresponding bit is not used here*/ + st_ivas->nchan_transport = 2; + move16(); + element_mode_flag = 1; + move16(); + } + ELSE IF( masaRestartCandidate > 0 ) + { + st_ivas->restartNeeded = 1; + move16(); + + return IVAS_ERR_OK; + } + + test(); + IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) + { #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ){ + IF( Opt_tsm ) + { #endif - st_ivas->restartNeeded = 1; - move16(); + st_ivas->restartNeeded = 1; + move16(); - return IVAS_ERR_OK; + return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH -} -ELSE -{ + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); -} + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } #endif -} + } -st_ivas->nchan_ism = nchan_ism; -move16(); -} -ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) -{ - st_ivas->nchan_transport = 2; /* always 2 MASA transport channels */ - move16(); + st_ivas->nchan_ism = nchan_ism; + move16(); + } + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + { + st_ivas->nchan_transport = 2; /* always 2 MASA transport channels */ + move16(); - /* the number of objects are written at the end of the bitstream */ - k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - nchan_ism = add( add( shl( st_ivas->bit_stream[k - 1], 1 ), st_ivas->bit_stream[k - 2] ), 1 ); - st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, nchan_ism ); + /* the number of objects are written at the end of the bitstream */ + k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + nchan_ism = add( add( shl( st_ivas->bit_stream[k - 1], 1 ), st_ivas->bit_stream[k - 2] ), 1 ); + st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, nchan_ism ); - test(); - IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ){ + test(); + IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) + { #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ){ + IF( Opt_tsm ) + { #endif - st_ivas->restartNeeded = 1; - move16(); + st_ivas->restartNeeded = 1; + move16(); - return IVAS_ERR_OK; + return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH -} -ELSE -{ + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); -} + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } #endif -} + } -st_ivas->nchan_ism = nchan_ism; -move16(); -} -ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) -{ - /* the number of objects is written at the end of the bitstream, in the SBA metadata */ - k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - nchan_ism = add( add( shl( st_ivas->bit_stream[k - 1], 1 ), st_ivas->bit_stream[k - 2] ), 1 ); + st_ivas->nchan_ism = nchan_ism; + move16(); + } + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + { + /* the number of objects is written at the end of the bitstream, in the SBA metadata */ + k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + nchan_ism = add( add( shl( st_ivas->bit_stream[k - 1], 1 ), st_ivas->bit_stream[k - 2] ), 1 ); - test(); - IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ){ + test(); + IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) + { #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ){ + IF( Opt_tsm ) + { #endif - st_ivas->restartNeeded = 1; - move16(); + st_ivas->restartNeeded = 1; + move16(); - return IVAS_ERR_OK; + return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH -} -ELSE -{ + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); -} + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } #endif -} + } -st_ivas->nchan_ism = nchan_ism; -move16(); + st_ivas->nchan_ism = nchan_ism; + move16(); -/* read Ambisonic (SBA) planar flag */ -/*sba_planar = st_ivas->bit_stream[num_bits_read];*/ -num_bits_read = add( num_bits_read, SBA_PLANAR_BITS ); + /* read Ambisonic (SBA) planar flag */ + /*sba_planar = st_ivas->bit_stream[num_bits_read];*/ + num_bits_read = add( num_bits_read, SBA_PLANAR_BITS ); -/* read Ambisonic (SBA) order (0 for signaling OSBA format at low bitrates)*/ -sba_order = st_ivas->bit_stream[num_bits_read + 1]; -move16(); -sba_order = add( sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) ); -num_bits_read = add( num_bits_read, SBA_ORDER_BITS ); + /* read Ambisonic (SBA) order (0 for signaling OSBA format at low bitrates)*/ + sba_order = st_ivas->bit_stream[num_bits_read + 1]; + move16(); + sba_order = add( sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) ); + num_bits_read = add( num_bits_read, SBA_ORDER_BITS ); -/* read the real Ambisonic order when the above bits are used to signal OSBA format */ -IF( LT_32( ivas_total_brate, IVAS_24k4 ) ) -{ - sba_order = st_ivas->bit_stream[num_bits_read + 1]; - move16(); - sba_order = add( sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) ); - num_bits_read = add( num_bits_read, SBA_ORDER_BITS ); -} + /* read the real Ambisonic order when the above bits are used to signal OSBA format */ + IF( LT_32( ivas_total_brate, IVAS_24k4 ) ) + { + sba_order = st_ivas->bit_stream[num_bits_read + 1]; + move16(); + sba_order = add( sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) ); + num_bits_read = add( num_bits_read, SBA_ORDER_BITS ); + } -test(); -IF( st_ivas->ini_frame > 0 && NE_16( sba_order, st_ivas->sba_order ) ){ + test(); + IF( st_ivas->ini_frame > 0 && NE_16( sba_order, st_ivas->sba_order ) ) + { #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ){ + IF( Opt_tsm ) + { #endif - st_ivas->restartNeeded = 1; -move16(); + st_ivas->restartNeeded = 1; + move16(); -return IVAS_ERR_OK; + return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH -} -ELSE -{ + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" ); + fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" ); -} + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" ); + } #endif -} + } -st_ivas->ism_mode = ivas_osba_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); + st_ivas->ism_mode = ivas_osba_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); -sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, sba_order ); -st_ivas->nchan_transport = ivas_get_sba_num_TCs_fx( ivas_total_brate, sba_analysis_order ); -} -ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) -{ - /* read MC configuration */ - idx = 0; - move16(); - FOR( k = 0; k < MC_LS_SETUP_BITS; k++ ) - { - IF( st_ivas->bit_stream[num_bits_read + k] ) - { - idx = add( idx, shl( 1, sub( ( MC_LS_SETUP_BITS - 1 ), k ) ) ); + sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, sba_order ); + st_ivas->nchan_transport = ivas_get_sba_num_TCs_fx( ivas_total_brate, sba_analysis_order ); } - } - num_bits_read = add( num_bits_read, MC_LS_SETUP_BITS ); + ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) + { + /* read MC configuration */ + idx = 0; + move16(); + FOR( k = 0; k < MC_LS_SETUP_BITS; k++ ) + { + IF( st_ivas->bit_stream[num_bits_read + k] ) + { + idx = add( idx, shl( 1, sub( ( MC_LS_SETUP_BITS - 1 ), k ) ) ); + } + } + num_bits_read = add( num_bits_read, MC_LS_SETUP_BITS ); - signaled_config = ivas_mc_map_ls_setup_to_output_config_fx( idx ); + signaled_config = ivas_mc_map_ls_setup_to_output_config_fx( idx ); - test(); - IF( st_ivas->ini_frame > 0 && NE_32( st_ivas->transport_config, signaled_config ) ){ + test(); + IF( st_ivas->ini_frame > 0 && NE_32( st_ivas->transport_config, signaled_config ) ) + { #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ){ + IF( Opt_tsm ) + { #endif - st_ivas->restartNeeded = 1; - move16(); + st_ivas->restartNeeded = 1; + move16(); - return IVAS_ERR_OK; + return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH -} -ELSE -{ + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Switching of MC configurations is not supported!\n" ); + fprintf( stderr, "\nError: Switching of MC configurations is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "wrong MC configuration signalled!" ); -} + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "wrong MC configuration signalled!" ); + } #endif -} - -st_ivas->mc_mode = ivas_mc_mode_select_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( signaled_config ), ivas_total_brate ); -st_ivas->transport_config = signaled_config; -move16(); -} - -/*-------------------------------------------------------------------* - * Read element mode - *-------------------------------------------------------------------*/ + } -test(); -IF( st_ivas->ini_frame == 0 && element_mode_flag ) -{ - /* read stereo technology info */ - if ( LT_32( ivas_total_brate, MIN_BRATE_MDCT_STEREO ) ) - { - /* 1 bit */ - IF( st_ivas->bit_stream[num_bits_read] ) - { - st_ivas->element_mode_init = add( 1, IVAS_CPE_DFT ); + st_ivas->mc_mode = ivas_mc_mode_select_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( signaled_config ), ivas_total_brate ); + st_ivas->transport_config = signaled_config; + move16(); } - ELSE + + /*-------------------------------------------------------------------* + * Read element mode + *-------------------------------------------------------------------*/ + + test(); + IF( st_ivas->ini_frame == 0 && element_mode_flag ) { - st_ivas->element_mode_init = add( 0, IVAS_CPE_DFT ); - } - } - ELSE - { - st_ivas->element_mode_init = IVAS_CPE_MDCT; - move16(); - } -} -} -ELSE IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) -{ - SWITCH( st_ivas->sid_format ) - { - case SID_DFT_STEREO: - st_ivas->element_mode_init = IVAS_CPE_DFT; - move16(); - BREAK; - case SID_MDCT_STEREO: - st_ivas->element_mode_init = IVAS_CPE_MDCT; - move16(); - BREAK; - case SID_ISM: - st_ivas->element_mode_init = IVAS_SCE; - move16(); - BREAK; - case SID_MASA_1TC: - st_ivas->element_mode_init = IVAS_SCE; - move16(); - st_ivas->nchan_transport = 1; - move16(); - BREAK; - case SID_MASA_2TC: - k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - IF( st_ivas->bit_stream[k - 1 - SID_FORMAT_NBITS] == 1 ) + /* read stereo technology info */ + if ( LT_32( ivas_total_brate, MIN_BRATE_MDCT_STEREO ) ) { - st_ivas->element_mode_init = IVAS_CPE_MDCT; - move16(); + /* 1 bit */ + IF( st_ivas->bit_stream[num_bits_read] ) + { + st_ivas->element_mode_init = add( 1, IVAS_CPE_DFT ); + } + ELSE + { + st_ivas->element_mode_init = add( 0, IVAS_CPE_DFT ); + } } ELSE { - st_ivas->element_mode_init = IVAS_CPE_DFT; + st_ivas->element_mode_init = IVAS_CPE_MDCT; move16(); } - st_ivas->nchan_transport = 2; - move16(); - BREAK; - case SID_SBA_1TC: - st_ivas->element_mode_init = IVAS_SCE; - move16(); - BREAK; - case SID_SBA_2TC: - st_ivas->element_mode_init = IVAS_CPE_MDCT; - move16(); - BREAK; + } } - - IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) + ELSE IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - /* read the number of objects */ - nchan_ism = 1; - move16(); - k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - k = sub( sub( k, 1 ), SID_FORMAT_NBITS ); - WHILE( st_ivas->bit_stream[k] && ( nchan_ism < MAX_NUM_OBJECTS ) ) + SWITCH( st_ivas->sid_format ) { - nchan_ism = add( nchan_ism, 1 ); - k = sub( k, 1 ); + case SID_DFT_STEREO: + st_ivas->element_mode_init = IVAS_CPE_DFT; + move16(); + BREAK; + case SID_MDCT_STEREO: + st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); + BREAK; + case SID_ISM: + st_ivas->element_mode_init = IVAS_SCE; + move16(); + BREAK; + case SID_MASA_1TC: + st_ivas->element_mode_init = IVAS_SCE; + move16(); + st_ivas->nchan_transport = 1; + move16(); + BREAK; + case SID_MASA_2TC: + k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + IF( st_ivas->bit_stream[k - 1 - SID_FORMAT_NBITS] == 1 ) + { + st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); + } + ELSE + { + st_ivas->element_mode_init = IVAS_CPE_DFT; + move16(); + } + st_ivas->nchan_transport = 2; + move16(); + BREAK; + case SID_SBA_1TC: + st_ivas->element_mode_init = IVAS_SCE; + move16(); + BREAK; + case SID_SBA_2TC: + st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); + BREAK; } - k = sub( k, 1 ); - test(); - IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ){ + IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) + { + /* read the number of objects */ + nchan_ism = 1; + move16(); + k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + k = sub( sub( k, 1 ), SID_FORMAT_NBITS ); + WHILE( st_ivas->bit_stream[k] && ( nchan_ism < MAX_NUM_OBJECTS ) ) + { + nchan_ism = add( nchan_ism, 1 ); + k = sub( k, 1 ); + } + k = sub( k, 1 ); + + test(); + IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) + { #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ){ + IF( Opt_tsm ) + { #endif - st_ivas->restartNeeded = 1; - move16(); + st_ivas->restartNeeded = 1; + move16(); - return IVAS_ERR_OK; + return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - } - ELSE - { + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); - } + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } #endif -} - -st_ivas->nchan_ism = nchan_ism; -move16(); - -/* read ism_mode */ -st_ivas->ism_mode = ISM_MODE_DISC; -move32(); -IF( GT_16( nchan_ism, 2 ) ) -{ - k = sub( k, nchan_ism ); /* SID metadata flags */ - idx = st_ivas->bit_stream[k]; - move16(); - st_ivas->ism_mode = (ISM_MODE) add( idx, 1 ); - move32(); -} + } -st_ivas->nchan_transport = nchan_ism; -move16(); -if ( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) -{ - st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; - move16(); -} -} -} + st_ivas->nchan_ism = nchan_ism; + move16(); + + /* read ism_mode */ + st_ivas->ism_mode = ISM_MODE_DISC; + move32(); + IF( GT_16( nchan_ism, 2 ) ) + { + k = sub( k, nchan_ism ); /* SID metadata flags */ + idx = st_ivas->bit_stream[k]; + move16(); + st_ivas->ism_mode = (ISM_MODE) add( idx, 1 ); + move32(); + } + + st_ivas->nchan_transport = nchan_ism; + move16(); + if ( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) + { + st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; + move16(); + } + } + } -st_ivas->bit_stream = bit_stream_orig; + st_ivas->bit_stream = bit_stream_orig; -return IVAS_ERR_OK; + return IVAS_ERR_OK; } -- GitLab From 3aa4d1c2f64521e70efa8a4e31a20c0506d8cfb0 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 21 Apr 2026 11:26:35 +0200 Subject: [PATCH 3/4] clang-format --- lib_dec/ivas_init_dec_fx.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index 50d1c411f..607aa9c3a 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -224,7 +224,7 @@ ivas_error ivas_dec_get_format_fx( st_ivas->nchan_ism = nchan_ism; move16(); st_ivas->ism_mode = ivas_ism_mode_select( nchan_ism, ivas_total_brate ); - + st_ivas->nchan_transport = nchan_ism; move16(); if ( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) @@ -238,7 +238,7 @@ ivas_error ivas_dec_get_format_fx( /* read Ambisonic (SBA) planar flag */ sba_planar = st_ivas->bit_stream[num_bits_read]; num_bits_read = add( num_bits_read, SBA_PLANAR_BITS ); - + test(); IF( st_ivas->ini_frame > 0 && NE_16( sba_planar, st_ivas->sba_planar ) ) { @@ -298,7 +298,7 @@ ivas_error ivas_dec_get_format_fx( UWord8 masaRestartCandidate; masaRestartCandidate = 0; move16(); - + /* read number of MASA transport channels */ k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); IF( st_ivas->bit_stream[k - 1] ) @@ -319,7 +319,7 @@ ivas_error ivas_dec_get_format_fx( element_mode_flag = 1; move16(); } - ELSE + ELSE { #ifdef FIX_FLOAT_1539_G192_FORMAT_SWITCH if ( st_ivas->nchan_transport == 2 ) @@ -331,16 +331,16 @@ ivas_error ivas_dec_get_format_fx( masaRestartCandidate = 1; move16(); } - + st_ivas->nchan_transport = 1; move16(); } - + /* this should be non-zero if original input format was MASA_ISM_FORMAT */ st_ivas->ism_mode = ISM_MODE_NONE; move16(); nchan_ism = add( st_ivas->bit_stream[k - 3], shl( st_ivas->bit_stream[k - 2], 1 ) ); - + IF( nchan_ism > 0 ) { /* the input_ivas_format should be MASA_ISM_FORMAT, but we cannot initialize it now */ @@ -358,7 +358,7 @@ ivas_error ivas_dec_get_format_fx( nchan_ism = 1; move16(); } - + /* for MASA_ISM_FORMAT at input the number of MASA transport channels is always 2 and the corresponding bit is not used here*/ st_ivas->nchan_transport = 2; move16(); @@ -369,10 +369,10 @@ ivas_error ivas_dec_get_format_fx( { st_ivas->restartNeeded = 1; move16(); - + return IVAS_ERR_OK; } - + test(); IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) { @@ -561,7 +561,7 @@ ivas_error ivas_dec_get_format_fx( /*-------------------------------------------------------------------* * Read element mode *-------------------------------------------------------------------*/ - + test(); IF( st_ivas->ini_frame == 0 && element_mode_flag ) { @@ -671,7 +671,7 @@ ivas_error ivas_dec_get_format_fx( st_ivas->nchan_ism = nchan_ism; move16(); - + /* read ism_mode */ st_ivas->ism_mode = ISM_MODE_DISC; move32(); @@ -683,7 +683,7 @@ ivas_error ivas_dec_get_format_fx( st_ivas->ism_mode = (ISM_MODE) add( idx, 1 ); move32(); } - + st_ivas->nchan_transport = nchan_ism; move16(); if ( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) -- GitLab From 420e78bf8ea246b713bd95735a936e98e0238ff5 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 21 Apr 2026 11:39:06 +0200 Subject: [PATCH 4/4] clang-format --- apps/encoder.c | 2 +- lib_dec/ivas_init_dec_fx.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index 9c003ad93..4cdcf8c1d 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -369,7 +369,7 @@ int main( /*------------------------------------------------------------------------------------------* * Open remote requests file for rtp packing (E-bytes) *------------------------------------------------------------------------------------------*/ - + if ( arg.requestsFileName != NULL ) { if ( ( error = RequestsFileReader_open( arg.requestsFileName, &requestsFileReader ) ) != IVAS_ERR_OK ) diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index 607aa9c3a..355051ccb 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -266,7 +266,7 @@ ivas_error ivas_dec_get_format_fx( sba_order = st_ivas->bit_stream[num_bits_read + 1]; move16(); sba_order = add( sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) ); - + test(); IF( st_ivas->ini_frame > 0 && NE_16( sba_order, st_ivas->sba_order ) ) { -- GitLab