From 2ed9629af87597fc46c4ef3257da3823636496dd Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 30 Apr 2026 11:20:31 +0200 Subject: [PATCH 1/4] FIX_1585_ASAN_FORMAT_SW --- lib_com/options.h | 1 + lib_dec/lib_dec_fx.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 6579999f2..9b916f5bc 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -111,6 +111,7 @@ #define FIX_2095_REMOVE_UNUSED_ISAR_TABLES /* Dolby: remove unused ISAR */ #define FIX_BASOP_2560_STEREO_DFT_DEC_RESET /* FhG: BASOP issue 2560: align reset of hStereoDft->res_gains_ind_fx[][] between BASOP and float */ #define HARMONIZE_2539_cng_energy /* FhG: basop issue 2539: harmonize cng_energy with its ivas derivate */ +#define FIX_1585_ASAN_FORMAT_SW /* VA: float issue 1585: fix memory leaks with format switching */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index c5b9a765e..1b35af85e 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -456,6 +456,11 @@ ivas_error IVAS_DEC_Restart( hIvasDec->mode = mode; move16(); +#ifdef FIX_1585_ASAN_FORMAT_SW + /* set 'ivas_format' to the last one to properly close IVAS decoder handles */ + hIvasDec->st_ivas->ivas_format = hIvasDec->st_ivas->last_ivas_format; +#endif + /* destroy Split binaural renderer (ISAR) handle */ ivas_destroy_handle_isar( &hIvasDec->st_ivas->hSplitBinRend ); -- GitLab From e2a48c74d236bc30f2d4906333ae0438bb5a7138 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 30 Apr 2026 15:29:38 +0200 Subject: [PATCH 2/4] - port FIX_1585_ASAN_FORMAT_SW_ALT - remove FIX_1585_ASAN_FORMAT_SW --- lib_com/options.h | 2 +- lib_dec/ivas_corecoder_dec_reconfig_fx.c | 24 + lib_dec/ivas_init_dec_fx.c | 841 ++++++++++++----------- lib_dec/ivas_stat_dec.h | 4 + lib_dec/lib_dec_fx.c | 5 - 5 files changed, 450 insertions(+), 426 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 9b916f5bc..e834666da 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -111,7 +111,7 @@ #define FIX_2095_REMOVE_UNUSED_ISAR_TABLES /* Dolby: remove unused ISAR */ #define FIX_BASOP_2560_STEREO_DFT_DEC_RESET /* FhG: BASOP issue 2560: align reset of hStereoDft->res_gains_ind_fx[][] between BASOP and float */ #define HARMONIZE_2539_cng_energy /* FhG: basop issue 2539: harmonize cng_energy with its ivas derivate */ -#define FIX_1585_ASAN_FORMAT_SW /* VA: float issue 1585: fix memory leaks with format switching */ +#define FIX_1585_ASAN_FORMAT_SW_ALT /* VA: float issue 1585: alternative fix memory leaks with format switching */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/ivas_corecoder_dec_reconfig_fx.c b/lib_dec/ivas_corecoder_dec_reconfig_fx.c index 6e6ac9d35..670f559d2 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig_fx.c +++ b/lib_dec/ivas_corecoder_dec_reconfig_fx.c @@ -477,7 +477,9 @@ ivas_error ivas_hp20_dec_reconfig_fx( ) { Word16 i, nchan_hp20; +#ifndef FIX_1585_ASAN_FORMAT_SW_ALT Word32 **old_mem_hp20_out_fx; +#endif ivas_error error; error = IVAS_ERR_OK; @@ -491,6 +493,18 @@ ivas_error ivas_hp20_dec_reconfig_fx( IF( GT_16( nchan_hp20, nchan_hp20_old ) ) { +#ifdef FIX_1585_ASAN_FORMAT_SW_ALT + /* create additional hp20 memories */ + FOR( i = nchan_hp20_old; i < nchan_hp20; i++ ) + { + IF( ( st_ivas->mem_hp20_out_fx[i] = (Word32 *) malloc( ( L_HP20_MEM + 2 ) * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + set32_fx( st_ivas->mem_hp20_out_fx[i], 0, L_HP20_MEM + 2 ); + } +#else /* save old mem_hp_20 pointer */ old_mem_hp20_out_fx = st_ivas->mem_hp20_out_fx; st_ivas->mem_hp20_out_fx = NULL; @@ -519,9 +533,18 @@ ivas_error ivas_hp20_dec_reconfig_fx( free( old_mem_hp20_out_fx ); old_mem_hp20_out_fx = NULL; +#endif } ELSE IF( LT_16( nchan_hp20, nchan_hp20_old ) ) { +#ifdef FIX_1585_ASAN_FORMAT_SW_ALT + /* remove superfluous hp20 memories */ + FOR( i = nchan_hp20; i < nchan_hp20_old; i++ ) + { + free( st_ivas->mem_hp20_out_fx[i] ); + st_ivas->mem_hp20_out_fx[i] = NULL; + } +#else /* save old mem_hp_20 pointer */ old_mem_hp20_out_fx = st_ivas->mem_hp20_out_fx; st_ivas->mem_hp20_out_fx = NULL; @@ -546,6 +569,7 @@ ivas_error ivas_hp20_dec_reconfig_fx( free( old_mem_hp20_out_fx ); old_mem_hp20_out_fx = NULL; +#endif } return error; diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index 355051ccb..0d83cb2c5 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; } @@ -2743,6 +2723,7 @@ ivas_error ivas_init_decoder_fx( /* set number of output channels used for synthesis/decoding */ n = getNumChanSynthesis( st_ivas ); +#ifndef FIX_1585_ASAN_FORMAT_SW_ALT IF( n > 0 ) { IF( ( st_ivas->mem_hp20_out_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) @@ -2754,7 +2735,7 @@ ivas_error ivas_init_decoder_fx( { st_ivas->mem_hp20_out_fx = NULL; } - +#endif FOR( i = 0; i < n; i++ ) { IF( ( st_ivas->mem_hp20_out_fx[i] = (Word32 *) malloc( ( L_HP20_MEM + 2 ) * sizeof( Word32 ) ) ) == NULL ) @@ -2764,6 +2745,13 @@ ivas_error ivas_init_decoder_fx( set32_fx( st_ivas->mem_hp20_out_fx[i], 0, L_HP20_MEM + 2 ); } +#ifdef FIX_1585_ASAN_FORMAT_SW_ALT + FOR( ; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ ) + { + st_ivas->mem_hp20_out_fx[i] = NULL; + } +#endif + /*-------------------------------------------------------------------* * Allocate and initialize rendering handles *--------------------------------------------------------------------*/ @@ -3383,7 +3371,9 @@ void ivas_initialize_handles_dec( #ifdef FIX_FMSW_DEC } #endif +#ifndef FIX_1585_ASAN_FORMAT_SW_ALT st_ivas->mem_hp20_out_fx = NULL; +#endif st_ivas->hLimiter = NULL; /* ISM metadata handles */ @@ -3527,6 +3517,16 @@ void ivas_destroy_dec_fx( } /* HP20 filter handles */ +#ifdef FIX_1585_ASAN_FORMAT_SW_ALT + FOR( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ ) + { + IF( st_ivas->mem_hp20_out_fx[i] != NULL ) + { + free( st_ivas->mem_hp20_out_fx[i] ); + st_ivas->mem_hp20_out_fx[i] = NULL; + } + } +#else IF( st_ivas->mem_hp20_out_fx != NULL ) { FOR( i = 0; i < getNumChanSynthesis( st_ivas ); i++ ) @@ -3537,6 +3537,7 @@ void ivas_destroy_dec_fx( free( st_ivas->mem_hp20_out_fx ); st_ivas->mem_hp20_out_fx = NULL; } +#endif /* ISM metadata handles */ ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 ); diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 2994d56aa..b3c75cb3c 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1119,7 +1119,11 @@ typedef struct Decoder_Struct UWord16 *bit_stream; /* Pointer to bitstream buffer */ Word16 writeFECoffset; /* parameter for debugging JBM stuff */ +#ifdef FIX_1585_ASAN_FORMAT_SW_ALT + Word32 *mem_hp20_out_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; /* output signals HP filter memories */ +#else Word32 **mem_hp20_out_fx; /* output signals HP filter memories */ +#endif IVAS_LIMITER_HANDLE hLimiter; /* Limiter handle */ /* core-decoder modules */ diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 1b35af85e..c5b9a765e 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -456,11 +456,6 @@ ivas_error IVAS_DEC_Restart( hIvasDec->mode = mode; move16(); -#ifdef FIX_1585_ASAN_FORMAT_SW - /* set 'ivas_format' to the last one to properly close IVAS decoder handles */ - hIvasDec->st_ivas->ivas_format = hIvasDec->st_ivas->last_ivas_format; -#endif - /* destroy Split binaural renderer (ISAR) handle */ ivas_destroy_handle_isar( &hIvasDec->st_ivas->hSplitBinRend ); -- GitLab From 949b846436f53c9bb442ceef7a8075f354ad2c8d Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 30 Apr 2026 15:46:24 +0200 Subject: [PATCH 3/4] clang-format --- lib_dec/ivas_init_dec_fx.c | 858 +++++++++++++++++++------------------ 1 file changed, 439 insertions(+), 419 deletions(-) diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index 0d83cb2c5..d17509a02 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(); } - - test(); - IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ){ + 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 ) ) + { #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH - IF( Opt_tsm ){ + IF( Opt_tsm ) + { #endif - st_ivas->restartNeeded = 1; - move16(); - - return IVAS_ERR_OK; + st_ivas->restartNeeded = 1; + move16(); + + 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(); + 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(); - } - - st_ivas->nchan_transport = 1; - move16(); - } + { + masaRestartCandidate = 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 ) ); + st_ivas->nchan_transport = 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; + /* 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 ) ); - /* 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(); + 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(); + } - return IVAS_ERR_OK; - } + /* 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(); - test(); - IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ){ + 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(); - - /* 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 ) ){ + 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 ); + + 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 ); - - test(); - IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ){ + 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 ) ) + { #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 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 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 ); -} + } + + 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) 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 ); + } -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 ); + } -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 ) ) ); + 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 ); } - } - num_bits_read = add( num_bits_read, MC_LS_SETUP_BITS ); - - 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 ) ){ + 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 ); + + 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 ) -{ - /* 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 ); - } - ELSE + 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 394bf84a69903a356799e63d721c6ff11dc64724 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Thu, 30 Apr 2026 16:17:11 +0200 Subject: [PATCH 4/4] clang format --- lib_dec/ivas_init_dec_fx.c | 44 +++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index d17509a02..fd440677b 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -169,7 +169,7 @@ ivas_error ivas_dec_get_format_fx( /*-------------------------------------------------------------------* * Read other signaling (ISM/MC mode, number of channels, etc.) *-------------------------------------------------------------------*/ - + IF( is_DTXrate( ivas_total_brate ) == 0 ) { /*-------------------------------------------------------------------* @@ -179,7 +179,7 @@ ivas_error ivas_dec_get_format_fx( * - in MASA : read number of TC * - in MC : read LS setup *-------------------------------------------------------------------*/ - + IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) { element_mode_flag = 1; @@ -197,7 +197,7 @@ ivas_error ivas_dec_get_format_fx( 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 ) ) { @@ -207,7 +207,7 @@ ivas_error ivas_dec_get_format_fx( #endif st_ivas->restartNeeded = 1; move16(); - + return IVAS_ERR_OK; #ifndef FIX_FLOAT_1539_G192_FORMAT_SWITCH } @@ -220,11 +220,11 @@ ivas_error ivas_dec_get_format_fx( } #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 ) ) @@ -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 ) ) { @@ -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 ) ) { @@ -403,12 +403,12 @@ ivas_error ivas_dec_get_format_fx( { 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 ); - + test(); IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) { @@ -440,7 +440,7 @@ ivas_error ivas_dec_get_format_fx( /* 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 ) ) { @@ -463,20 +463,20 @@ ivas_error ivas_dec_get_format_fx( } #endif } - + 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) 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 ) ) { @@ -510,7 +510,7 @@ ivas_error ivas_dec_get_format_fx( } 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 ); } @@ -527,9 +527,9 @@ ivas_error ivas_dec_get_format_fx( } } num_bits_read = add( num_bits_read, MC_LS_SETUP_BITS ); - + 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 ) ) { @@ -631,7 +631,7 @@ ivas_error ivas_dec_get_format_fx( move16(); BREAK; } - + IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) { /* read the number of objects */ @@ -645,7 +645,7 @@ ivas_error ivas_dec_get_format_fx( k = sub( k, 1 ); } k = sub( k, 1 ); - + test(); IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) { @@ -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