diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index c22700aeee5b90a821ac5b5f15abf395e5eb88ed..b52f2fa17fc2d0ebbab4769b1ee786e89ca70eab 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -4549,9 +4549,11 @@ ivas_error preview_indices( case SID_ISM: st_ivas->ivas_format = ISM_FORMAT; break; +#ifndef FIX_1209_SID_SIGNALING case SID_MULTICHANNEL: st_ivas->ivas_format = MC_FORMAT; break; +#endif case SID_SBA_1TC: st_ivas->ivas_format = SBA_FORMAT; st_ivas->element_mode_init = IVAS_SCE; @@ -4576,7 +4578,9 @@ ivas_error preview_indices( } break; default: +#ifndef FIX_1209_SID_SIGNALING /* This should actually be impossible, since only 3 bits are read, so if this happens something is broken */ +#endif return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Invalid value %c found in SID format field.", st_ivas->sid_format ); } } diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 0f93c47c8aee4541eeb006139e80640a14ccc0fc..a94f024fc43900807cf29d4b3f6b8d5cc58a7956 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -240,7 +240,11 @@ typedef enum #define SID_MDCT_STEREO 0x1 /* 1| 0| 0 */ #define SID_ISM 0x2 /* 0| 1| 0 */ #define SID_MASA_1TC 0x3 /* 1| 1| 0 */ +#ifdef FIX_1209_SID_SIGNALING +/*reserved*/ /*0x4*/ /* 0| 0| 1 */ +#else #define SID_MULTICHANNEL 0x4 /* 0| 0| 1 */ +#endif #define SID_SBA_1TC 0x5 /* 1| 0| 1 */ #define SID_SBA_2TC 0x6 /* 0| 1| 1 */ #define SID_MASA_2TC 0x7 /* 1| 1| 1 */ diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 40e1eb23c09c3b16892059986940fae44d1b415e..03da5409540387a869ccb9b3fc5e83f3efbee30d 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -336,6 +336,10 @@ ivas_error ivas_dec( int16_t *data /* o : output synthesis signal */ ); +ivas_error ivas_dec_get_format( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + ivas_error ivas_dec_setup( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ diff --git a/lib_com/options.h b/lib_com/options.h index 4db69235caef2f9cb91878a659b6ffa8b4de955f..faafb029dc7b3a80c4eb6b98a198cdcf3f0e7495 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -198,6 +198,7 @@ #define NONBE_1360_LFE_DELAY /* Dlb: LFE delay alignment when rendering in CLDFB domain*/ #define NONBE_1229_FIX_ISM1_DPID /* Eri: issue 1229: fix bug causing ISM 1 to use default -dpid instead of the specified one */ #define NONBE_SVD_OPTIMIZATION +#define FIX_1209_SID_SIGNALING /* VA: issue 1209: remove dead code in IVAS SID signaling */ #define FIX_1158_FASTCONV_REVERB_HRTF /* Philips: issue 1158: Rendering with FastConv to BINAURAL_ROOM_REVERB uses BRIR convolution instead of HRTF */ #define NONBE_FIX_1176_OSBA_REVERB_JBM_ASAN_ERROR /* Ericsson: Issue 1176, fix in TDREND_firfilt for subframes shorter than the filter length */ #define NONBE_1131_ACELP_OOB /* VA: issue 1131: fix division-by-zero in acelp gain decoding caused by wrong length of buffer update when switching from HQ core to ACELP core */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index b85eaf083554ab4d63b0efbc8274112a55c62917..999c59041861efd18316416653a059df2291bd58 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -108,6 +108,372 @@ static AUDIO_CONFIG ivas_set_output_config_from_sba_order( const int16_t sba_ord #endif +#ifdef FIX_1209_SID_SIGNALING +/*---------------------------------------------------------------------* + * ivas_dec_get_format( ) + * + * Read main parameters from the bitstream to set-up the decoder: + * - IVAS format + * - IVAS format specific signaling + *---------------------------------------------------------------------*/ + +ivas_error ivas_dec_get_format( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + int16_t k, idx, num_bits_read; + int16_t nchan_ism, element_mode_flag; + int16_t sba_order, sba_planar, sba_analysis_order; + int32_t ivas_total_brate; + uint16_t *bit_stream_orig; + AUDIO_CONFIG signaled_config; + ivas_error error; + + num_bits_read = 0; + element_mode_flag = 0; + + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + bit_stream_orig = st_ivas->bit_stream; + + /*-------------------------------------------------------------------* + * Read IVAS format + *-------------------------------------------------------------------*/ + + if ( ( error = ivas_read_format( st_ivas, &num_bits_read ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( st_ivas->ini_frame > 0 && st_ivas->ivas_format != st_ivas->last_ivas_format && + !( st_ivas->ivas_format == MASA_FORMAT && st_ivas->last_ivas_format == MASA_ISM_FORMAT ) && + !( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->last_ivas_format == MASA_FORMAT ) ) + { +#ifdef DEBUGGING + 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!" ); + } + + /*-------------------------------------------------------------------* + * 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 + *-------------------------------------------------------------------*/ + + if ( st_ivas->ivas_format == STEREO_FORMAT ) + { + element_mode_flag = 1; + } + else if ( st_ivas->ivas_format == ISM_FORMAT ) + { + /* read the number of objects */ + nchan_ism = 1; + k = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 ); + while ( st_ivas->bit_stream[k] && nchan_ism < MAX_NUM_OBJECTS ) + { + nchan_ism++; + k--; + } + + if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) + { +#ifdef DEBUGGING + 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!" ); + } + + st_ivas->nchan_ism = nchan_ism; + st_ivas->ism_mode = ivas_ism_mode_select( nchan_ism, ivas_total_brate ); + + st_ivas->nchan_transport = nchan_ism; + if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + { + st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; + } + } + else if ( st_ivas->ivas_format == SBA_FORMAT ) + { + /* read Ambisonic (SBA) planar flag */ + sba_planar = st_ivas->bit_stream[num_bits_read]; + num_bits_read += SBA_PLANAR_BITS; + + if ( st_ivas->ini_frame > 0 && sba_planar != st_ivas->sba_planar ) + { +#ifdef DEBUGGING + 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!" ); + } + + /* read Ambisonic (SBA) order */ + sba_order = st_ivas->bit_stream[num_bits_read + 1]; + sba_order += 2 * st_ivas->bit_stream[num_bits_read]; + + if ( st_ivas->ini_frame > 0 && sba_order != st_ivas->sba_order ) + { +#ifdef DEBUGGING + fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" ); +#endif + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" ); + } + + sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, sba_order ); + st_ivas->nchan_transport = ivas_get_sba_num_TCs( ivas_total_brate, sba_analysis_order ); + } + else if ( st_ivas->ivas_format == MASA_FORMAT ) + { + /* read number of MASA transport channels */ + if ( st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 1] ) + { + st_ivas->nchan_transport = 2; + element_mode_flag = 1; + } + else + { + st_ivas->nchan_transport = 1; + } + + /* this should be non-zero if original input format was MASA_ISM_FORMAT */ + st_ivas->ism_mode = ISM_MODE_NONE; + nchan_ism = st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 3] + 2 * st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 2]; + + 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 = 5 - nchan_ism; + if ( st_ivas->nchan_transport == 1 && nchan_ism == 2 ) + { + nchan_ism = 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; + element_mode_flag = 1; + } + + if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) + { +#ifdef DEBUGGING + 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!" ); + } + + st_ivas->nchan_ism = nchan_ism; + } + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + st_ivas->nchan_transport = 2; /* always 2 MASA transport channels */ + + /* the number of objects are written at the end of the bitstream */ + nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + 1; + st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, nchan_ism ); + + if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) + { +#ifdef DEBUGGING + 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!" ); + } + + st_ivas->nchan_ism = nchan_ism; + } + else if ( st_ivas->ivas_format == SBA_ISM_FORMAT ) + { + /* the number of objects is written at the end of the bitstream, in the SBA metadata */ + nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + 1; + + if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) + { +#ifdef DEBUGGING + 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!" ); + } + + st_ivas->nchan_ism = nchan_ism; + + /* read Ambisonic (SBA) planar flag */ + /*sba_planar = st_ivas->bit_stream[num_bits_read];*/ + 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]; + sba_order += 2 * st_ivas->bit_stream[num_bits_read]; + num_bits_read += SBA_ORDER_BITS; + + /* read the real Ambisonic order when the above bits are used to signal OSBA format */ + if ( ivas_total_brate < IVAS_24k4 ) + { + sba_order = st_ivas->bit_stream[num_bits_read + 1]; + sba_order += 2 * st_ivas->bit_stream[num_bits_read]; + num_bits_read += SBA_ORDER_BITS; + } + + if ( st_ivas->ini_frame > 0 && sba_order != st_ivas->sba_order ) + { +#ifdef DEBUGGING + fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" ); +#endif + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" ); + } + + st_ivas->ism_mode = ivas_osba_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); + + sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, sba_order ); + st_ivas->nchan_transport = ivas_get_sba_num_TCs( ivas_total_brate, sba_analysis_order ); + } + else if ( st_ivas->ivas_format == MC_FORMAT ) + { + /* read MC configuration */ + idx = 0; + for ( k = 0; k < MC_LS_SETUP_BITS; k++ ) + { + if ( st_ivas->bit_stream[num_bits_read + k] ) + { + idx += 1 << ( MC_LS_SETUP_BITS - 1 - k ); + } + } + num_bits_read += MC_LS_SETUP_BITS; + + signaled_config = ivas_mc_map_ls_setup_to_output_config( idx ); + + if ( st_ivas->ini_frame > 0 && st_ivas->transport_config != signaled_config ) + { +#ifdef DEBUGGING + fprintf( stderr, "\nError: Switching of MC configurations is not supported!\n" ); +#endif + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "wrong MC configuration signalled!" ); + } + + st_ivas->mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( signaled_config ), st_ivas->hDecoderConfig->ivas_total_brate ); + st_ivas->transport_config = signaled_config; + } + + /*-------------------------------------------------------------------* + * Read element mode + *-------------------------------------------------------------------*/ + + if ( st_ivas->ini_frame == 0 && element_mode_flag ) + { + /* read stereo technology info */ + if ( ivas_total_brate < MIN_BRATE_MDCT_STEREO ) + { + /* 1 bit */ + if ( st_ivas->bit_stream[num_bits_read] ) + { + st_ivas->element_mode_init = 1 + IVAS_CPE_DFT; + } + else + { + st_ivas->element_mode_init = 0 + IVAS_CPE_DFT; + } + } + else + { + st_ivas->element_mode_init = IVAS_CPE_MDCT; + } + } + } + else if ( ivas_total_brate == IVAS_SID_5k2 ) + { + switch ( st_ivas->sid_format ) + { + case SID_DFT_STEREO: + st_ivas->element_mode_init = IVAS_CPE_DFT; + break; + case SID_MDCT_STEREO: + st_ivas->element_mode_init = IVAS_CPE_MDCT; + break; + case SID_ISM: + st_ivas->element_mode_init = IVAS_SCE; + break; + case SID_MASA_1TC: + st_ivas->element_mode_init = IVAS_SCE; + st_ivas->nchan_transport = 1; + break; + case SID_MASA_2TC: + if ( st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1 - SID_FORMAT_NBITS] == 1 ) + { + st_ivas->element_mode_init = IVAS_CPE_MDCT; + } + else + { + st_ivas->element_mode_init = IVAS_CPE_DFT; + } + st_ivas->nchan_transport = 2; + break; + case SID_SBA_1TC: + st_ivas->element_mode_init = IVAS_SCE; + break; + case SID_SBA_2TC: + st_ivas->element_mode_init = IVAS_CPE_MDCT; + break; + } + + if ( st_ivas->ivas_format == ISM_FORMAT ) + { + /* read the number of objects */ + nchan_ism = 1; + k = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 - SID_FORMAT_NBITS ); + while ( st_ivas->bit_stream[k] && nchan_ism < MAX_NUM_OBJECTS ) + { + nchan_ism++; + k--; + } + k--; + + if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) + { +#ifdef DEBUGGING + 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!" ); + } + + st_ivas->nchan_ism = nchan_ism; + + /* read ism_mode */ + st_ivas->ism_mode = ISM_MODE_DISC; + if ( nchan_ism > 2 ) + { + k -= nchan_ism; /* SID metadata flags */ + idx = st_ivas->bit_stream[k]; + st_ivas->ism_mode = (ISM_MODE) ( idx + 1 ); + } + + st_ivas->nchan_transport = nchan_ism; + if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + { + st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; + } + } + } + + st_ivas->bit_stream = bit_stream_orig; + + return IVAS_ERR_OK; +} +#endif + + /*-------------------------------------------------------------------* * ivas_dec_setup() * @@ -138,7 +504,14 @@ ivas_error ivas_dec_setup( * Read IVAS format *-------------------------------------------------------------------*/ +#ifdef FIX_1209_SID_SIGNALING + if ( ( error = ivas_read_format( st_ivas, &num_bits_read ) ) != IVAS_ERR_OK ) + { + return error; + } +#else ivas_read_format( st_ivas, &num_bits_read ); +#endif /*-------------------------------------------------------------------* * Read other signling (ISM/MC mode, number of channels, etc.) @@ -692,11 +1065,12 @@ static ivas_error ivas_read_format( break; case SID_ISM: st_ivas->ivas_format = ISM_FORMAT; - break; +#ifndef FIX_1209_SID_SIGNALING case SID_MULTICHANNEL: st_ivas->ivas_format = MC_FORMAT; break; +#endif case SID_SBA_1TC: st_ivas->ivas_format = SBA_FORMAT; st_ivas->element_mode_init = IVAS_SCE; @@ -721,7 +1095,9 @@ static ivas_error ivas_read_format( } break; default: - /* This should actually be impossible, since only 3 bits are read, so if this happens something is broken */ +#ifndef FIX_1209_SID_SIGNALING +/* This should actually be impossible, since only 3 bits are read, so if this happens something is broken */ +#endif return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Invalid value %c found in SID format field.", st_ivas->sid_format ); } diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index ff67c675b5b9c22f1ccd3c94d155d235da073bf7..dbed65daf8f527f0622f6e23a71eeb0a245e36f2 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -168,9 +168,11 @@ void ivas_write_format_sid( case ISM_FORMAT: ind = SID_ISM; break; +#ifndef FIX_1209_SID_SIGNALING case MC_FORMAT: ind = SID_MULTICHANNEL; break; +#endif case SBA_FORMAT: switch ( element_mode ) {