From 3343693534b443a01e9ace9dcfa3e73c46c9308f Mon Sep 17 00:00:00 2001 From: "Brown, Stefanie" Date: Tue, 30 Aug 2022 09:39:04 +1000 Subject: [PATCH] Changes for 76 SBA order in the bitstream --- lib_com/bitstream.c | 18 ++++++++++++ lib_com/ivas_dirac_com.c | 8 ++++++ lib_com/ivas_prot.h | 8 ++++++ lib_com/options.h | 2 +- lib_dec/ivas_dirac_dec.c | 8 ++++++ lib_dec/ivas_init_dec.c | 30 ++++++++++++++++++++ lib_dec/ivas_output_init.c | 6 +++- lib_dec/ivas_sba_dec.c | 23 ++++++++++++++-- lib_dec/ivas_sba_rendering.c | 5 +++- lib_dec/ivas_spar_decoder.c | 9 +++++- lib_dec/ivas_spar_md_dec.c | 6 ++-- lib_dec/ivas_stat_dec.h | 9 ++++-- lib_dec/lib_dec.c | 4 +++ lib_enc/ivas_mct_enc.c | 20 ++++++++++++++ lib_enc/ivas_sba_enc.c | 14 ++++++++-- lib_enc/ivas_spar_encoder.c | 33 +++++++++++++++++++--- lib_enc/ivas_spar_md_enc.c | 53 ++++++++++++++++++++++++++++++------ lib_enc/ivas_stat_enc.h | 5 ++-- lib_enc/lib_enc.c | 15 +++++++--- 19 files changed, 245 insertions(+), 31 deletions(-) diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 3a4ebc80cb..4e81fc9166 100755 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -1975,11 +1975,29 @@ ivas_error preview_indices( } else if ( st_ivas->ivas_format == SBA_FORMAT ) { + /* Read SBA planar flag and SBA order */ st_ivas->sba_planar = ( bit_stream[IVAS_FORMAT_SIGNALING_NBITS_SBA] == 1 ); +#ifndef SBA_ORDER_BITSTREAM st_ivas->sba_order = ( bit_stream[IVAS_FORMAT_SIGNALING_NBITS_SBA + 2] == 1 ); st_ivas->sba_order += 2 * ( bit_stream[IVAS_FORMAT_SIGNALING_NBITS_SBA + 1] == 1 ); +#else + st_ivas->hDecoderConfig->sba_order = ( bit_stream[IVAS_FORMAT_SIGNALING_NBITS_SBA + 2] == 1 ); + st_ivas->hDecoderConfig->sba_order += 2 * ( bit_stream[IVAS_FORMAT_SIGNALING_NBITS_SBA + 1] == 1 ); + st_ivas->sba_analysis_order = st_ivas->hDecoderConfig->sba_order; +#endif +#ifdef SBA_ORDER_BITSTREAM + /*Hard coding the the sba_oder as 1 as higher not supported below 256k bitrate*/ + if ( total_brate < IVAS_256k ) + { + st_ivas->sba_analysis_order = 1; + } +#endif +#ifdef SBA_ORDER_BITSTREAM + ivas_sba_config( total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &( st_ivas->nSCE ), &( st_ivas->nCPE ), &( st_ivas->element_mode_init ), st_ivas->sba_mode ); +#else ivas_sba_config( total_brate, st_ivas->sba_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &( st_ivas->nSCE ), &( st_ivas->nCPE ), &( st_ivas->element_mode_init ), st_ivas->sba_mode ); +#endif } } diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 8cade5dee4..849e889739 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -82,7 +82,11 @@ ivas_error ivas_dirac_config( nCPE = &( (Encoder_Struct *) st_ivas )->nCPE; element_mode = &( (Encoder_Struct *) st_ivas )->hEncoderConfig->element_mode_init; nchan_transport = &( (Encoder_Struct *) st_ivas )->nchan_transport; +#ifndef SBA_ORDER_BITSTREAM sba_order = ( (Encoder_Struct *) st_ivas )->hEncoderConfig->sba_order; +#else + sba_order = ( (Encoder_Struct *) st_ivas )->sba_analysis_order; +#endif sba_planar = ( (Encoder_Struct *) st_ivas )->hEncoderConfig->sba_planar; ivas_total_brate = ( (Encoder_Struct *) st_ivas )->hEncoderConfig->ivas_total_brate; Fs = ( (Encoder_Struct *) st_ivas )->hEncoderConfig->input_Fs; @@ -107,7 +111,11 @@ ivas_error ivas_dirac_config( nCPE = &( (Decoder_Struct *) st_ivas )->nCPE; element_mode = &( (Decoder_Struct *) st_ivas )->element_mode_init; nchan_transport = &( (Decoder_Struct *) st_ivas )->nchan_transport; +#ifndef SBA_ORDER_BITSTREAM sba_order = ( (Decoder_Struct *) st_ivas )->sba_order; +#else + sba_order = ( (Decoder_Struct *) st_ivas )->sba_analysis_order; +#endif sba_planar = ( (Decoder_Struct *) st_ivas )->sba_planar; ivas_total_brate = ( (Decoder_Struct *) st_ivas )->hDecoderConfig->ivas_total_brate; Fs = ( (Decoder_Struct *) st_ivas )->hDecoderConfig->output_Fs; diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 497c6a6bef..d947f5248a 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3866,6 +3866,10 @@ void ivas_spar_dec_upmixer( ivas_error ivas_spar_md_enc_open( ivas_spar_md_enc_state_t **hMdEnc, /* i/o: SPAR MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ +#ifdef SBA_ORDER_BITSTREAM + , + int16_t sba_order +#endif ); void ivas_spar_md_enc_close( @@ -3878,6 +3882,10 @@ ivas_error ivas_spar_md_enc_process( ivas_spar_md_enc_in_buf_t *pIn_buf, BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ const int16_t dtx_silence_mode +#ifdef SBA_ORDER_BITSTREAM + , + int16_t sba_order +#endif ); void ivas_compute_spar_params( diff --git a/lib_com/options.h b/lib_com/options.h index 77a14be529..b3d3c5a736 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -153,7 +153,7 @@ #define FIX_I87 /* fix for issue 86: incorrect Ambisonics order set for head rotation in SBA */ - +#define SBA_ORDER_BITSTREAM /* issue 76: Use input sba order for bitstream coding */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ #endif diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index a8022aaa5d..074f635133 100755 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -186,7 +186,11 @@ ivas_error ivas_dirac_dec_config( nchan_transport_orig = st_ivas->nchan_transport; if ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->sba_mode == SBA_MODE_SPAR && !( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) { +#ifdef SBA_ORDER_BITSTREAM + st_ivas->nchan_transport = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order ); +#else st_ivas->nchan_transport = ivas_sba_get_nchan_metadata( st_ivas->sba_order ); +#endif } nchan_transport = st_ivas->nchan_transport; if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ivas_total_brate > IVAS_SID_4k4 ) @@ -197,7 +201,11 @@ ivas_error ivas_dirac_dec_config( if ( flag_config == DIRAC_RECONFIGURE && st_ivas->ivas_format == SBA_FORMAT ) { int16_t tmp1, tmp2, tmp3; +#ifdef SBA_ORDER_BITSTREAM + ivas_sba_config( st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport_old, st_ivas->sba_planar, &tmp1, &tmp2, &tmp3, SBA_MODE_DIRAC ); +#else ivas_sba_config( st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->sba_order, -1, &nchan_transport_old, st_ivas->sba_planar, &tmp1, &tmp2, &tmp3, SBA_MODE_DIRAC ); +#endif } /*-----------------------------------------------------------------* diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index a682cd3c58..b12aa28e40 100755 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -119,8 +119,18 @@ ivas_error ivas_dec_setup( num_bits_read += SBA_PLANAR_BITS; /* read Ambisonic (SBA) order */ +#ifndef SBA_ORDER_BITSTREAM st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1]; st_ivas->sba_order += 2 * st_ivas->bit_stream[num_bits_read]; +#else + st_ivas->hDecoderConfig->sba_order = st_ivas->bit_stream[num_bits_read + 1]; + st_ivas->hDecoderConfig->sba_order += 2 * st_ivas->bit_stream[num_bits_read]; + st_ivas->sba_analysis_order = st_ivas->hDecoderConfig->sba_order; + if ( ivas_total_brate < IVAS_256k ) + { + st_ivas->sba_analysis_order = 1; + } +#endif num_bits_read += SBA_ORDER_BITS; if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate && ivas_total_brate > IVAS_SID_4k4 ) { @@ -131,7 +141,11 @@ ivas_error ivas_dec_setup( } else { +#ifndef SBA_ORDER_BITSTREAM ivas_sba_config( ivas_total_brate, st_ivas->sba_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->sba_mode ); +#else + ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->sba_mode ); +#endif } } else if ( st_ivas->ivas_format == MASA_FORMAT ) @@ -408,10 +422,17 @@ static ivas_error ivas_read_format( tc_mode_offset = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 ); idx = st_ivas->bit_stream[tc_mode_offset]; // TBD: needs more work for HOA +#ifndef SBA_ORDER_BITSTREAM if ( st_ivas->sba_order == 0 ) { st_ivas->sba_order = 1; } +#else + if ( st_ivas->sba_analysis_order == 0 ) + { + st_ivas->sba_analysis_order = 1; + } +#endif if ( idx == 0 ) { st_ivas->sid_format = SID_SBA_1TC; @@ -852,8 +873,13 @@ ivas_error ivas_init_decoder( return error; } } +#ifndef SBA_ORDER_BITSTREAM if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_order, st_ivas->sba_planar, st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_planar, + st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -887,7 +913,11 @@ ivas_error ivas_init_decoder( } else { +#ifndef SBA_ORDER_BITSTREAM if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_order, st_ivas->sba_planar, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_planar, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_dec/ivas_output_init.c b/lib_dec/ivas_output_init.c index c21cbafda3..fcaa6f9442 100644 --- a/lib_dec/ivas_output_init.c +++ b/lib_dec/ivas_output_init.c @@ -263,7 +263,7 @@ void ivas_renderer_select( AUDIO_CONFIG output_config; AUDIO_CONFIG transport_config; - #ifdef FIX_I87 +#ifdef FIX_I87 int16_t nchan_internal; #endif @@ -361,7 +361,11 @@ void ivas_renderer_select( { #ifdef FIX_I87 +#ifdef SBA_ORDER_BITSTREAM + nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order ); +#else nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_order ); +#endif if ( nchan_internal == 2 ) { st_ivas->hHeadTrackData->shd_rot_max_order = 1; diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 52ecc69e27..96ebc693f5 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -273,7 +273,11 @@ int16_t ivas_sba_remapTCs( if ( st_ivas->sba_mode != SBA_MODE_SPAR ) { +#ifndef SBA_ORDER_BITSTREAM ivas_sba_zero_vert_comp( sba_data, st_ivas->sba_order, st_ivas->sba_planar, output_frame ); +#else + ivas_sba_zero_vert_comp( sba_data, st_ivas->sba_analysis_order, st_ivas->sba_planar, output_frame ); +#endif } return ( nchan_remapped ); @@ -486,8 +490,11 @@ ivas_error ivas_sba_dec_reconfigure( nCPE_old = st_ivas->nCPE; nchan_transport_old = st_ivas->nchan_transport; sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; - +#ifndef SBA_ORDER_BITSTREAM ivas_sba_config( sba_total_brate, st_ivas->sba_order, -1, &nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->sba_mode ); +#else + ivas_sba_config( sba_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->sba_mode ); +#endif st_ivas->nchan_transport = nchan_transport; /* renderer might have changed */ @@ -503,7 +510,11 @@ ivas_error ivas_sba_dec_reconfigure( if ( st_ivas->sba_mode != SBA_MODE_SPAR ) { st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); +#ifndef SBA_ORDER_BITSTREAM if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_order, st_ivas->sba_planar, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_planar, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -511,11 +522,19 @@ ivas_error ivas_sba_dec_reconfigure( else { int16_t sba_order_internal; +#ifndef SBA_ORDER_BITSTREAM sba_order_internal = min( st_ivas->sba_order, IVAS_MAX_SBA_ORDER ); +#else + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); +#endif ivas_spar_config( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); - +#ifndef SBA_ORDER_BITSTREAM if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_order, st_ivas->sba_planar, st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_planar, + st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_dec/ivas_sba_rendering.c b/lib_dec/ivas_sba_rendering.c index 41c46bccbe..7f5a3a289b 100755 --- a/lib_dec/ivas_sba_rendering.c +++ b/lib_dec/ivas_sba_rendering.c @@ -214,8 +214,11 @@ void ivas_sba_upmixer_renderer( int16_t nchan_internal; wmops_sub_start( "ivas_sba_upmixer_renderer" ); - +#ifndef SBA_ORDER_BITSTREAM nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_order ); +#else + nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order ); +#endif nchan_out = st_ivas->hDecoderConfig->nchan_out; for ( ch = 0; ch < nchan_remapped; ch++ ) diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 9842097187..cc625f2605 100755 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -71,7 +71,11 @@ ivas_error ivas_spar_dec_open( int32_t output_Fs; error = IVAS_ERR_OK; +#ifndef SBA_ORDER_BITSTREAM sba_order_internal = min( st_ivas->sba_order, IVAS_MAX_SBA_ORDER ); +#else + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); +#endif num_channels_internal = ivas_sba_get_nchan_metadata( sba_order_internal ); /* SPAR decoder handle */ @@ -619,8 +623,11 @@ static void ivas_spar_dec_MD( /*---------------------------------------------------------------------* * Initialization *---------------------------------------------------------------------*/ - +#ifndef SBA_ORDER_BITSTREAM sba_order = min( st_ivas->sba_order, IVAS_MAX_SBA_ORDER ); +#else + sba_order = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); +#endif bfi = st_ivas->bfi; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; num_channels = ivas_sba_get_nchan_metadata( sba_order ); diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 21c244292a..be1b3fcb10 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -2577,9 +2577,11 @@ void ivas_spar_to_dirac( int16_t pred_idx; int16_t *dirac_to_spar_md_bands; int16_t enc_param_start_band; - +#ifndef SBA_ORDER_BITSTREAM sba_order_internal = min( st_ivas->sba_order, IVAS_MAX_SBA_ORDER ); - +#else + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); +#endif start_band = 0; end_band = min( num_bands_out, SPAR_DIRAC_SPLIT_START_BAND ); diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index f8f1c5cb85..7a788f86b6 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1908,7 +1908,9 @@ typedef struct decoder_config_structure int32_t output_Fs; /* output signal sampling frequency in Hz */ int16_t nchan_out; /* number of output audio channels */ AUDIO_CONFIG output_config; /* output audio configuration */ - +#ifdef SBA_ORDER_BITSTREAM + int16_t sba_order; +#endif int16_t Opt_LsCustom; /* indicates whether loudspeaker custom setup is used */ int16_t Opt_HRTF_binary; /* indicates whether HRTF binary file is used */ int16_t Opt_Headrotation; /* indicates whether head-rotation is used */ @@ -1981,8 +1983,11 @@ typedef struct Decoder_Struct ISM_MODE ism_mode; /* ISM format mode */ SBA_MODE sba_mode; /* SBA format mode */ MC_MODE mc_mode; /* MC format mode */ - +#ifdef SBA_ORDER_BITSTREAM + int16_t sba_analysis_order; /* Ambisonic (SBA) order */ +#else int16_t sba_order; /* Ambisonic (SBA) order */ +#endif int16_t sba_planar; /* Ambisonic (SBA) planar flag */ int16_t sba_dirac_stereo_flag; /* flag indicating stereo output for SBA DirAC modes with 1 TC */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index fd27442c37..c12a356146 100755 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -169,7 +169,11 @@ ivas_error IVAS_DEC_Open( hIvasDec->st_ivas->ini_frame = 0; hIvasDec->st_ivas->ini_active_frame = 0; hIvasDec->st_ivas->writeFECoffset = 0; +#ifndef SBA_ORDER_BITSTREAM hIvasDec->st_ivas->sba_order = 0; +#else + hIvasDec->st_ivas->sba_analysis_order = 0; +#endif hIvasDec->st_ivas->sba_planar = 0; /*initialize pointers*/ diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 3f93bbce6b..20a2856654 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -195,13 +195,21 @@ ivas_error create_mct_enc( } else if ( ivas_format == SBA_FORMAT && st_ivas->hSpar ) { +#ifndef SBA_ORDER_BITSTREAM hMCT->nchan_out_woLFE = ivas_get_spar_num_TCs( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); +#else + hMCT->nchan_out_woLFE = ivas_get_spar_num_TCs( ivas_total_brate, st_ivas->sba_analysis_order ); +#endif hMCT->num_lfe = FALSE; } else if ( ivas_format == SBA_FORMAT && st_ivas->hDirAC ) { +#ifndef SBA_ORDER_BITSTREAM hMCT->nchan_out_woLFE = ivas_dirac_getNumTransportChannels( ivas_total_brate, st_ivas->hEncoderConfig->sba_order, st_ivas->hEncoderConfig->sba_planar ); +#else + hMCT->nchan_out_woLFE = ivas_dirac_getNumTransportChannels( ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->hEncoderConfig->sba_planar ); +#endif hMCT->num_lfe = FALSE; } else if ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMMC ) @@ -211,7 +219,11 @@ ivas_error create_mct_enc( } else if ( ivas_format == SBA_FORMAT ) { +#ifndef SBA_ORDER_BITSTREAM hMCT->nchan_out_woLFE = ivas_sba_get_nchan( st_ivas->hEncoderConfig->sba_order, st_ivas->hEncoderConfig->sba_planar ); +#else + hMCT->nchan_out_woLFE = ivas_sba_get_nchan( st_ivas->sba_analysis_order, st_ivas->hEncoderConfig->sba_planar ); +#endif hMCT->num_lfe = FALSE; } else @@ -339,12 +351,20 @@ ivas_error mct_enc_reconfigure( } else if ( ivas_format == SBA_FORMAT && st_ivas->hDirAC ) { +#ifndef SBA_ORDER_BITSTREAM hMCT->nchan_out_woLFE = ivas_dirac_getNumTransportChannels( ivas_total_brate, st_ivas->hEncoderConfig->sba_order, st_ivas->hEncoderConfig->sba_planar ); +#else + hMCT->nchan_out_woLFE = ivas_dirac_getNumTransportChannels( ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->hEncoderConfig->sba_planar ); +#endif hMCT->num_lfe = FALSE; } else if ( ivas_format == SBA_FORMAT ) { +#ifndef SBA_ORDER_BITSTREAM hMCT->nchan_out_woLFE = ivas_sba_get_nchan( st_ivas->hEncoderConfig->sba_order, st_ivas->hEncoderConfig->sba_planar ); +#else + hMCT->nchan_out_woLFE = ivas_sba_get_nchan( st_ivas->sba_analysis_order, st_ivas->hEncoderConfig->sba_planar ); +#endif hMCT->num_lfe = FALSE; } else diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index acce4615af..019c387b93 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -62,12 +62,18 @@ void ivas_sba_getTCs( const int16_t input_frame /* i : frame length */ ) { +#ifndef SBA_ORDER_BITSTREAM ivas_sba_zero_vert_comp( sba_data, st_ivas->hEncoderConfig->sba_order, st_ivas->hEncoderConfig->sba_planar, input_frame ); - +#else + ivas_sba_zero_vert_comp( sba_data, st_ivas->sba_analysis_order, st_ivas->hEncoderConfig->sba_planar, input_frame ); +#endif if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { +#ifndef SBA_ORDER_BITSTREAM st_ivas->nchan_transport = ivas_get_spar_num_TCs( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); - +#else + st_ivas->nchan_transport = ivas_get_spar_num_TCs( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); +#endif if ( st_ivas->nchan_transport >= 3 ) { /*convert WYZX downmix to WYXZ*/ @@ -83,7 +89,11 @@ void ivas_sba_getTCs( } else { +#ifndef SBA_ORDER_BITSTREAM st_ivas->nchan_transport = ivas_dirac_getNumTransportChannels( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->hEncoderConfig->sba_order, st_ivas->hEncoderConfig->sba_planar ); +#else + st_ivas->nchan_transport = ivas_dirac_getNumTransportChannels( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->hEncoderConfig->sba_planar ); +#endif ivas_sba_dmx_enc( sba_data, st_ivas->nchan_transport, input_frame ); } diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index ae9328404d..03e16833e3 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -79,8 +79,11 @@ ivas_error ivas_spar_enc_open( } input_Fs = hEncoderConfig->input_Fs; - +#ifndef SBA_ORDER_BITSTREAM sba_order_internal = min( hEncoderConfig->sba_order, IVAS_MAX_SBA_ORDER ); +#else + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); +#endif nchan_inp = ivas_sba_get_nchan_metadata( sba_order_internal ); assert( nchan_inp <= hEncoderConfig->nchan_inp ); ivas_total_brate = hEncoderConfig->ivas_total_brate; @@ -91,7 +94,11 @@ ivas_error ivas_spar_enc_open( // ivas_set_bitrate_config(&hSpar->hMdEnc->spar_md_cfg, table_idx); /* MD handle */ +#ifndef SBA_ORDER_BITSTREAM if ( ( error = ivas_spar_md_enc_open( &( hSpar->hMdEnc ), hEncoderConfig ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_spar_md_enc_open( &( hSpar->hMdEnc ), hEncoderConfig, sba_order_internal ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -142,9 +149,13 @@ ivas_error ivas_spar_enc_open( /*-----------------------------------------------------------------* * Configuration - set SPAR high-level parameters *-----------------------------------------------------------------*/ - +#ifdef SBA_ORDER_BITSTREAM + ivas_spar_config( hEncoderConfig->ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), + &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1 ); +#else ivas_spar_config( hEncoderConfig->ivas_total_brate, min( hEncoderConfig->sba_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1 ); +#endif if ( st_ivas->nchan_transport == 1 ) { @@ -302,7 +313,11 @@ ivas_error ivas_spar_enc( if ( hEncoderConfig->sba_planar ) { +#ifndef SBA_ORDER_BITSTREAM ivas_sba_zero_vert_comp( data_f, hEncoderConfig->sba_order, hEncoderConfig->sba_planar, input_frame ); +#else + ivas_sba_zero_vert_comp( data_f, st_ivas->sba_analysis_order, hEncoderConfig->sba_planar, input_frame ); +#endif } if ( ( error = ivas_spar_enc_process( st_ivas, hEncoderConfig, hMetaData, st_ivas->hSpar->front_vad_flag, data_f ) ) != IVAS_ERR_OK ) @@ -312,7 +327,11 @@ ivas_error ivas_spar_enc( if ( hEncoderConfig->sba_planar ) { +#ifndef SBA_ORDER_BITSTREAM ivas_sba_zero_vert_comp( data_f, hEncoderConfig->sba_order, hEncoderConfig->sba_planar, input_frame ); // TODO tmu: do we need a second call to this function ? +#else + ivas_sba_zero_vert_comp( data_f, st_ivas->sba_analysis_order, hEncoderConfig->sba_planar, input_frame ); // TODO tmu: do we need a second call to this function ? +#endif } *nb_bits_metadata = hMetaData->nb_bits_tot; @@ -438,7 +457,11 @@ static ivas_error ivas_spar_enc_process( num_del_samples = hSpar->hFbMixer->fb_cfg->fb_latency; input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); +#ifndef SBA_ORDER_BITSTREAM sba_order = min( hEncoderConfig->sba_order, IVAS_MAX_SBA_ORDER ); +#else + sba_order = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); +#endif nchan_inp = ivas_sba_get_nchan_metadata( sba_order ); assert( nchan_inp <= hEncoderConfig->nchan_inp ); @@ -677,9 +700,11 @@ static ivas_error ivas_spar_enc_process( md_in_buf.num_bands = min( md_in_buf.num_bands, SPAR_DIRAC_SPLIT_START_BAND ); md_in_buf.dtx_vad = dtx_vad; - +#ifndef SBA_ORDER_BITSTREAM ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, &md_in_buf, hMetaData, dtx_silence_mode ); - +#else + ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, &md_in_buf, hMetaData, dtx_silence_mode, sba_order ); +#endif if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 39f8746004..dc7c3677dd 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -84,7 +84,12 @@ static void ivas_store_prior_coeffs( ivas_spar_md_enc_state_t *hMdEnc, const int static void ivas_write_parameter_bitstream( ivas_spar_md_enc_state_t *hMdEnc, const int16_t nB, const int16_t bands_bw, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate, const int16_t dtx_silence_mode, const int16_t strat, const int16_t qsi, const int16_t planarCP ); -static ivas_error ivas_spar_md_enc_init( ivas_spar_md_enc_state_t *pState, const ENCODER_CONFIG_HANDLE hEncoderConfig ); +static ivas_error ivas_spar_md_enc_init( ivas_spar_md_enc_state_t *pState, const ENCODER_CONFIG_HANDLE hEncoderConfig +#ifdef SBA_ORDER_BITSTREAM + , + int16_t sba_order +#endif +); static void ivas_spar_quant_pred_coeffs_dtx( ivas_spar_md_t *pSpar_md, float **ppValues, const int16_t ndm, int16_t **ppIndex, const int16_t dim1, float **ppQuant ); @@ -108,22 +113,33 @@ static void ivas_quant_pred_coeffs_per_band( ivas_band_coeffs_t *pband_coeffs, i ivas_error ivas_spar_md_enc_open( ivas_spar_md_enc_state_t **hMdEnc_in, /* i/o: SPAR MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ +#ifdef SBA_ORDER_BITSTREAM + , + int16_t sba_order +#endif ) { ivas_spar_md_enc_state_t *hMdEnc; ivas_error error; +#ifndef SBA_ORDER_BITSTREAM int16_t num_channels, i, j, order; +#else + int16_t num_channels, i, j; +#endif +#ifndef SBA_ORDER_BITSTREAM order = min( hEncoderConfig->sba_order, IVAS_MAX_SBA_ORDER ); - +#endif error = IVAS_ERR_OK; if ( ( hMdEnc = (ivas_spar_md_enc_state_t *) count_malloc( sizeof( ivas_spar_md_enc_state_t ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD encoder" ); } - +#ifndef SBA_ORDER_BITSTREAM num_channels = 2 * order + 2; - +#else + num_channels = 2 * sba_order + 2; +#endif if ( ( hMdEnc->spar_md.band_coeffs = (ivas_band_coeffs_t *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" ); @@ -203,8 +219,11 @@ ivas_error ivas_spar_md_enc_open( } } } - +#ifndef SBA_ORDER_BITSTREAM if ( ( error = ivas_spar_md_enc_init( hMdEnc, hEncoderConfig ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_spar_md_enc_init( hMdEnc, hEncoderConfig, sba_order ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -310,16 +329,22 @@ void ivas_spar_md_enc_close( static ivas_error ivas_spar_md_enc_init( ivas_spar_md_enc_state_t *pState, /* o : MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ +#ifdef SBA_ORDER_BITSTREAM + , + int16_t sba_order +#endif ) { float pFC[IVAS_MAX_NUM_BANDS]; int16_t table_idx; float PR_minmax[2]; +#ifndef SBA_ORDER_BITSTREAM int16_t sba_order; +#endif int16_t num_channels, i, j, k; - +#ifndef SBA_ORDER_BITSTREAM sba_order = min( hEncoderConfig->sba_order, IVAS_MAX_SBA_ORDER ); - +#endif num_channels = ivas_sba_get_nchan_metadata( sba_order ); table_idx = ivas_get_spar_table_idx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); @@ -559,7 +584,12 @@ ivas_error ivas_spar_md_enc_process( const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ ivas_spar_md_enc_in_buf_t *pIn_buf, BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ - const int16_t dtx_silence_mode ) + const int16_t dtx_silence_mode +#ifdef SBA_ORDER_BITSTREAM + , + int16_t sba_order +#endif +) { float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; @@ -568,7 +598,11 @@ ivas_error ivas_spar_md_enc_process( int16_t j, planarCP; int16_t num_bands = pIn_buf->num_bands; int16_t dtx_vad = pIn_buf->dtx_vad; +#ifndef SBA_ORDER_BITSTREAM int16_t active_w, nchan_transport, dmx_switch, strat, sba_order; +#else + int16_t active_w, nchan_transport, dmx_switch, strat; +#endif int16_t nB, bands_bw, packed_ok = 0; ivas_strats_t cs[MAX_CODING_STRATS]; int16_t code_strat; @@ -578,8 +612,9 @@ ivas_error ivas_spar_md_enc_process( float Wscale[IVAS_MAX_NUM_BANDS]; ivas_spar_md_enc_state_t *pState = hMdEnc; int16_t num_quant_strats = pState->spar_md_cfg.num_quant_strats; - +#ifndef SBA_ORDER_BITSTREAM sba_order = min( hEncoderConfig->sba_order, IVAS_MAX_SBA_ORDER ); +#endif num_ch = ivas_sba_get_nchan_metadata( sba_order ); active_w = pState->spar_md_cfg.active_w; nchan_transport = pState->spar_md_cfg.nchan_transport; diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 170c03d997..5c1b060fac 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -998,7 +998,6 @@ typedef struct encoder_config_structure int16_t element_mode_init; /* element mode used at initialization */ int16_t stereo_dmx_evs; /* flag to indicate that stereo downmix for EVS encoder */ - int16_t sba_order; /* Ambisonic (SBA) order */ int16_t sba_planar; /* Ambisonic (SBA) planar flag */ MC_LS_SETUP mc_input_setup; /* multichannel input ls setup */ @@ -1043,7 +1042,9 @@ typedef struct /* high-level encoder parameters */ int16_t nchan_transport; /* number of transport channels */ - +#ifdef SBA_ORDER_BITSTREAM + int16_t sba_analysis_order; /*Ambisonic(SBA) order*/ +#endif int16_t codec_mode; /* Mode1 or Mode2 of core codec */ int16_t last_codec_mode; /* previous frame Mode 1 or 2 */ diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 760ae0d353..b9d4dde032 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -460,10 +460,8 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( hEncoderConfig->element_mode_init = IVAS_SCE; /* Just needs to be something not mono, will be set later */ hEncoderConfig->sba_planar = isPlanar; hEncoderConfig->sba_order = order; - /* Input in ACN/SN3D in all cases (3D and planar): get number of channels */ hEncoderConfig->nchan_inp = ivas_sba_get_nchan( hEncoderConfig->sba_order, 0 ); /*planar input arg. deliberately set to zero since input always in ACN/SN3D*/ - hEncoderConfig->Opt_AGC_ON = (int16_t) Opt_AGC_ON; hEncoderConfig->Opt_PCA_ON = (int16_t) Opt_PCA_ON; @@ -641,7 +639,9 @@ static ivas_error configureEncoder( st_ivas = hIvasEnc->st_ivas; hEncoderConfig = st_ivas->hEncoderConfig; - +#ifdef SBA_ORDER_BITSTREAM + st_ivas->sba_analysis_order = hEncoderConfig->sba_order; +#endif /*-----------------------------------------------------------------* * Bandwidth limitation *-----------------------------------------------------------------*/ @@ -776,7 +776,11 @@ static ivas_error configureEncoder( { /* set SBA order to 1 for bit rates below 256kbps for correct handling of input with higher order */ /* IVAS_fmToDo: needs more work in case of bitrate switching */ +#ifndef SBA_ORDER_BITSTREAM hEncoderConfig->sba_order = 1; +#else + st_ivas->sba_analysis_order = 1; +#endif } } else if ( hEncoderConfig->ivas_format == MASA_FORMAT ) @@ -882,8 +886,11 @@ static ivas_error configureEncoder( { return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "AGC supported in SBA format at bitrates >= 24.4 kbps only." ); } - +#ifndef SBA_ORDER_BITSTREAM if ( hEncoderConfig->Opt_PCA_ON && !( hEncoderConfig->ivas_format == SBA_FORMAT && hEncoderConfig->ivas_total_brate == PCA_BRATE && hEncoderConfig->sba_order == 1 ) ) +#else + if ( hEncoderConfig->Opt_PCA_ON && !( hEncoderConfig->ivas_format == SBA_FORMAT && hEncoderConfig->ivas_total_brate == PCA_BRATE && st_ivas->sba_analysis_order == 1 ) ) +#endif { return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "PCA supported at SBA FOA 256 kbps only." ); } -- GitLab