diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1074de71b886bd145d0dfb4a1274b9db29188f8d..71ff18eb921492704a10719070618a85b697eae4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -321,7 +321,6 @@ codec-smoke-test: - *print-common-info - bash ci/smoke_test.sh ### analyze for failures - - cat out/logs/stv1MASA2TC48c_MASA_2TC_1DIR_b96_fb_cbr.enc.txt - if cat smoke_test_output.txt | grep -c "failed"; then echo "Smoke test without PLC failed"; exit 1; fi - if cat smoke_test_output_plc.txt | grep -c "failed"; then echo "Smoke test with PLC failed"; exit 1; fi - if cat smoke_test_output_jbm_noEXT.txt | grep -c "failed"; then echo "Smoke test JBM part failed"; exit 1; fi diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index d7c063bf1a9a2daa1d27a1be9e79d8be020cd002..9b20ab182beac0e36b67ee37001052422c033ac5 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -1801,7 +1801,11 @@ ivas_error preview_indices( if ( bit_stream[2] == 0 ) { st_ivas->ivas_format = SBA_FORMAT; +#ifndef LBR_SBA st_ivas->sba_mode = ivas_sba_mode_select( total_brate ); +#else + st_ivas->sba_mode = ivas_sba_mode_select(); +#endif } else { diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 7b359e2f40ff80ab3db4a1848c9f0e3a781f28d6..8c986b363abb499b01f02f4bfdd211ff980e635a 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -1532,7 +1532,10 @@ typedef enum _DCTTYPE #define TOD_NSPEC 80 /* number of spectral bins of the tonal detector */ #define TOD_THR_MASS 0.86f /* initial value for the adaptive threshold of the tonal detector */ #define P2A_FACT 0.9f /* long-term averaging factor for peak-to-average ratio */ -#define THR_P2A 80.0f /* threshold to detect strongly peaky signals */ +#ifdef FIX_SP2A +#define THR_P2A_HIGH 95.0f /* higher threshold to detect strongly peaky signals at low bitrates*/ +#endif +#define THR_P2A 80.0f /* lower threshold to detect strongly peaky signals at higher bitrates */ /*----------------------------------------------------------------------------------* * LD music post-filter constants diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 2f8d004a9eac6db7e086f09a084fcbf2bbf81ede..1c155a48e25122c1b0afdd03ee776942ceb5ed65 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1007,6 +1007,9 @@ typedef enum /* Common SPAR metadata constants */ #define IVAS_ACTIVEW_DM_F_SCALE 0.5f #define IVAS_ACTIVEW_DM_F_SCALE_DTX 0.25f +#ifdef LBR_SBA +#define IVAS_ACTIVEW_DM_F_SCALE_VLBR 0.25f +#endif #define IVAS_SPAR_FOA_DFLT_FREQ_PER_CHAN 24000 #define MAX_QUANT_STRATS 3 @@ -1039,7 +1042,11 @@ typedef enum DECX_COEFF } ivas_coeffs_type_t; +#ifdef LBR_SBA +#define IVAS_SPAR_BR_TABLE_LEN 20 +#else #define IVAS_SPAR_BR_TABLE_LEN 18 +#endif /* TD decorr */ // VE: not all 16CH are currently supported -> t be revisited later enum diff --git a/lib_com/ivas_cov_smooth.c b/lib_com/ivas_cov_smooth.c index 35ce6b85465eca6da931f068f4dbeb384f25fe1f..ef2f5e369368c5128db1d70f23fa4b1e5c397a97 100644 --- a/lib_com/ivas_cov_smooth.c +++ b/lib_com/ivas_cov_smooth.c @@ -52,11 +52,55 @@ static void ivas_set_up_cov_smoothing( const float max_update_rate, const int16_t min_pool_size, const int16_t nchan_inp /* i : number of input channels */ +#ifdef LBR_SBA_EXTRA_COV_SMOOTH + , + const int32_t ivas_total_brate +#endif ) { int16_t j, k; +#ifdef LBR_SBA_DM_COV_FIX + if ( ivas_total_brate < IVAS_24k4 ) + { + for ( j = 0; j < pFb->filterbank_num_bands; j++ ) + { + float update_factor; + float *p_bin_to_band; + update_factor = 0.0f; + p_bin_to_band = pFb->fb_bin_to_band.pp_short_stride_bin_to_band[j]; + int16_t active_bins; + active_bins = pFb->fb_bin_to_band.p_short_stride_num_bins_per_band[j]; + + for ( k = 0; k < active_bins; k++ ) + { + update_factor += p_bin_to_band[k]; + } - if ( nchan_inp <= FOA_CHANNELS ) + hCovState->pSmoothing_factor[j] = update_factor / min_pool_size; +#ifdef LBR_SBA_EXTRA_COV_SMOOTH + float smooth_fact; + if ( ivas_total_brate < IVAS_24k4 ) + { + smooth_fact = 0.5f; + } + else + { + smooth_fact = 0.75; + } + hCovState->pSmoothing_factor[j] *= ( j + 1 ) * smooth_fact; +#else + hCovState->pSmoothing_factor[j] *= ( j + 1 ) * 0.75f; +#endif + + if ( hCovState->pSmoothing_factor[j] > max_update_rate ) + { + hCovState->pSmoothing_factor[j] = max_update_rate; + } + } + } + else +#endif + if ( nchan_inp <= FOA_CHANNELS ) { for ( j = 0; j < pFb->filterbank_num_bands; j++ ) { @@ -115,6 +159,10 @@ ivas_error ivas_spar_covar_smooth_enc_open( const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i : SPAR config. handle */ ivas_filterbank_t *pFb, /* i/o: FB handle */ const int16_t nchan_inp /* i : number of input channels */ +#ifdef LBR_SBA_EXTRA_COV_SMOOTH + , + const int32_t ivas_total_brate /* i : IVAS total bitrate */ +#endif ) { ivas_cov_smooth_state_t *hCovState; @@ -142,8 +190,11 @@ ivas_error ivas_spar_covar_smooth_enc_open( } } - ivas_set_up_cov_smoothing( hCovState, pFb, cov_smooth_cfg->max_update_rate, cov_smooth_cfg->min_pool_size, - nchan_inp ); +#ifdef LBR_SBA_EXTRA_COV_SMOOTH + ivas_set_up_cov_smoothing( hCovState, pFb, cov_smooth_cfg->max_update_rate, cov_smooth_cfg->min_pool_size, nchan_inp, ivas_total_brate ); +#else + ivas_set_up_cov_smoothing( hCovState, pFb, cov_smooth_cfg->max_update_rate, cov_smooth_cfg->min_pool_size, nchan_inp ); +#endif *hCovState_out = hCovState; diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 01f133a3b7f2fc2d6bd0c5e24ef94419c0dca733..172dbc53650f2b5945e7600a7fdd3937a92b669d 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -259,10 +259,18 @@ void ivas_dirac_config_bands( { band_grouping[reduced_band] = max_band; } +#ifdef LBR_SBA + for ( band = enc_param_start_band + ( DIRAC_MAX_NBANDS - enc_param_start_band ) / 2 - 1, reduced_band = DIRAC_MAX_NBANDS - 1; band >= enc_param_start_band; band--, reduced_band -= step ) + { + dirac_to_spar_md_bands[reduced_band] = dirac_to_spar_md_bands[band]; + dirac_to_spar_md_bands[reduced_band - 1] = dirac_to_spar_md_bands[band]; + } +#else for ( band = enc_param_start_band + 1; band < DIRAC_MAX_NBANDS; band++ ) { dirac_to_spar_md_bands[band] = dirac_to_spar_md_bands[band - 1]; } +#endif } else { diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index dd3c65845515330c100b245d08a477a73eb3199a..a3c2b820434f97009771f4c0ced0a68250d06080 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3219,7 +3219,11 @@ void ivas_dirac_param_est_enc( /*! r: SBA format mode */ SBA_MODE ivas_sba_mode_select( +#ifndef LBR_SBA const int32_t ivas_total_brate /* i : IVAS total bitrate */ +#else + void +#endif ); void ivas_sba_config( @@ -3421,6 +3425,28 @@ void ivas_dirac_dec( const int16_t i_sf ); +#ifdef FIX_417_TD_DECORR_BRATE_SW +ivas_error ivas_td_decorr_reconfig_dec( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int32_t ivas_total_brate, /* i : total IVAS bitrate */ + const int16_t nchan_transport, /* i : number of transport channels */ + const int32_t output_Fs, /* i : output sampling rate */ + ivas_td_decorr_state_t **hTdDecorr, /* i/o: TD decorrelator handle */ + uint16_t *useTdDecorr /* i/o: TD decorrelator flag */ +); + +/*! r: Configured reqularization factor value */ +float configure_reqularization_factor( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int32_t ivas_total_brate /* i : total IVAS bitrate */ +); +#else +ivas_error ivas_dirac_dec_init_binaural_data( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + HRTFS_PARAMBIN_HANDLE hHrtfParambin /* i : HRTF structure for rendering */ +); +#endif + void computeDiffuseness_mdft( float **buffer_intensity[DIRAC_NUM_DIMS], const float *buffer_energy, @@ -4102,6 +4128,10 @@ ivas_error ivas_spar_md_enc_process( const int16_t dtx_vad, const int16_t nchan_inp, const int16_t sba_order /* i : Ambisonic (SBA) order */ +#ifdef LBR_SBA + , + float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i : prior mixer_matrix */ +#endif ); void ivas_compute_spar_params( @@ -4115,6 +4145,9 @@ void ivas_compute_spar_params( const int16_t num_ch, const int16_t bands_bw, const int16_t active_w, +#ifdef LBR_SBA + const int16_t active_w_vlbr, +#endif ivas_spar_md_com_cfg *hSparCfg, ivas_spar_md_t *hSparMd, float *pWscale, @@ -4158,6 +4191,11 @@ void ivas_get_spar_md_from_dirac( const int16_t order, const int16_t dtx_vad, float Wscale_d[IVAS_MAX_NUM_BANDS] +#ifdef LBR_SBA + , + const uint8_t useLowerRes, + const int16_t active_w_vlbr +#endif ); ivas_error ivas_spar_md_dec_open( @@ -4201,6 +4239,10 @@ void ivas_spar_to_dirac( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const int16_t dtx_vad, /* i : DTX frame flag */ const int16_t num_bands_out /* i : number of output bands */ +#ifdef LBR_SBA + , + const int16_t bw /* i : band joining factor */ +#endif ); void ivas_spar_update_md_hist( @@ -4230,6 +4272,10 @@ ivas_error ivas_spar_covar_enc_open( ivas_filterbank_t *pFb, /* i/o: FB handle */ const int32_t input_Fs, /* i : input sampling rate */ const int16_t nchan_inp /* i : number of input channels */ +#ifdef LBR_SBA_EXTRA_COV_SMOOTH + , + const int32_t ivas_total_brate /* i : IVAS total bitrate */ +#endif ); void ivas_spar_covar_enc_close( @@ -4256,6 +4302,10 @@ ivas_error ivas_spar_covar_smooth_enc_open( const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i : SPAR config. handle */ ivas_filterbank_t *pFb, /* i/o: FB handle */ const int16_t nchan_inp /* i : number of input channels */ +#ifdef LBR_SBA_EXTRA_COV_SMOOTH + , + const int32_t ivas_total_brate /* i : IVAS total bitrate */ +#endif ); void ivas_spar_covar_smooth_enc_close( diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 94a11c9a82146b296def7b1871ded80593127987..3783919100a77f3428626604f665311447650909 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -903,6 +903,24 @@ const ivas_spar_br_table_t ivas_spar_br_table_consts[IVAS_SPAR_BR_TABLE_LEN] = { /* When AGC is ON additional (AGC_BITS_PER_CH+1) bits may be taken from each core-coder channel so minimum core-coder bitrate per channel can be min core-coder bitrates as per the table - AGC_BITS_PER_CH */ +#ifdef LBR_SBA + /* preferred tuning (3.2/4.9kbps) with/out TDD */ + { 13200, 0, SBA_FOA_ORDER, FB, 24000, 1, WYXZ, 1, 0, +#ifdef LBR_SBA_PLANAR + { { 11000, 9600, 13150 } }, +#else + { { 10000, 8300, 13150 } }, +#endif + { { 15, 1, 5, 1 },{ 15, 1, 3, 1 },{ 7, 1, 3, 1 } }, 0, 0, 0 }, + + { 16400, 0, SBA_FOA_ORDER, FB, 24000, 1, WYXZ, 1, 0, +#ifdef LBR_SBA_PLANAR + { { 14200, 12800, 16350 } }, +#else + { { 13200, 11500, 16350 } }, +#endif + { { 15, 1, 5, 1 },{ 15, 1, 3, 1 },{ 7, 1, 3, 1 } }, 0, 0, 0 }, +#endif { 24400, 0, SBA_FOA_ORDER, FB, 24000, 1, WYXZ, 1, 0,{ { 16400, 14850, 24350 } }, { { 15, 1, 5, 1 },{ 15, 1, 3, 1 },{ 7, 1, 3, 1 } }, 0, 0, 0 }, diff --git a/lib_com/ivas_sba_config.c b/lib_com/ivas_sba_config.c index 44131d5bd237793d65aa0c9124e3c777ac6c9625..1dc3c4faede2b8aae704c8f3c40a759fcd753ec3 100644 --- a/lib_com/ivas_sba_config.c +++ b/lib_com/ivas_sba_config.c @@ -55,9 +55,12 @@ /*! r: SBA format mode */ SBA_MODE ivas_sba_mode_select( +#ifndef LBR_SBA const int32_t ivas_total_brate /* i : IVAS total bitrate */ +#endif ) { +#ifndef LBR_SBA SBA_MODE sba_mode; if ( ivas_total_brate == IVAS_13k2 || ivas_total_brate == IVAS_16k4 ) @@ -70,6 +73,9 @@ SBA_MODE ivas_sba_mode_select( } return sba_mode; +#else + return SBA_MODE_SPAR; +#endif } /*-------------------------------------------------------------------* * ivas_sba_config() diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index cb6ff23fc011ccfe3ca4364a1b38bb2a4143f6e0..da731676db38baed9b83242e64632632629ee9e5 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -59,8 +59,11 @@ #define IVAS_REMIX_MULT_FAC ( 0.5f ) -#define IVAS_ACTIVEW_DM_F ( 1.0f ) -#define IVAS_ACTIVEW_DM_F_DTX ( 0.25f ) +#define IVAS_ACTIVEW_DM_F ( 1.0f ) +#define IVAS_ACTIVEW_DM_F_DTX ( 0.25f ) +#ifdef LBR_SBA +#define IVAS_ACTIVEW_DM_F_VLBR ( 0.25f ) +#endif #define IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH ( 3.0f ) #define IVAS_P_NORM_SCALING ( 1.0f ) @@ -76,11 +79,20 @@ *------------------------------------------------------------------------------------------*/ -static void ivas_get_pred_coeffs( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], float ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], const int16_t in_chans, const int16_t start_band, const int16_t end_band, const int16_t active_w, const int16_t dtx_vad, const int16_t from_dirac ); +static void ivas_get_pred_coeffs( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], float ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], const int16_t in_chans, const int16_t start_band, const int16_t end_band, const int16_t active_w, +#ifdef LBR_SBA + const int16_t active_w_vlbr, +#endif + const int16_t dtx_vad, + const int16_t from_dirac ); static void ivas_reorder_array( float in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], const int16_t in_chans, const int16_t order[IVAS_SPAR_MAX_CH], float ***mixer_mat, const int16_t start_band, const int16_t end_band ); -static void ivas_get_Wscaling_factor( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], float ***mixer_mat, const int16_t start_band, const int16_t end_band, const int16_t dtx_vad, const int16_t num_ch, const int16_t *pNum_dmx, const int16_t bands_bw, const int16_t active_w, float *pWscale ); +static void ivas_get_Wscaling_factor( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], float ***mixer_mat, const int16_t start_band, const int16_t end_band, const int16_t dtx_vad, const int16_t num_ch, const int16_t *pNum_dmx, const int16_t bands_bw, const int16_t active_w, +#ifdef LBR_SBA + const int16_t active_w_vlbr, +#endif + float *pWscale ); static void ivas_calc_post_pred_per_band( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float ***mixer_mat, const int16_t num_ch, const int16_t num_dmx, const int16_t band_idx, float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] ); @@ -338,8 +350,11 @@ void ivas_spar_config( { ivas_total_brate = IVAS_32k; } - +#ifdef LBR_SBA + assert( ivas_total_brate == IVAS_32k || ivas_total_brate == IVAS_24k4 || ivas_total_brate == IVAS_16k4 || ivas_total_brate == IVAS_13k2 ); +#else assert( ivas_total_brate == IVAS_32k || ivas_total_brate == IVAS_24k4 ); +#endif if ( ivas_total_brate == IVAS_32k ) { *core_nominal_brate = ACELP_24k40; @@ -348,6 +363,16 @@ void ivas_spar_config( { *core_nominal_brate = ACELP_16k40; } +#ifdef LBR_SBA + else if ( ivas_total_brate == IVAS_16k4 ) + { + *core_nominal_brate = ACELP_13k20; + } + else if ( ivas_total_brate == IVAS_13k2 ) + { + *core_nominal_brate = ACELP_9k60; + } +#endif } return; @@ -427,7 +452,11 @@ int16_t ivas_get_sba_num_TCs( { nchan_transport = 1; } +#ifndef LBR_SBA else if ( ivas_sba_mode_select( ivas_total_brate ) == SBA_MODE_DIRAC ) +#else + else if ( ivas_sba_mode_select() == SBA_MODE_DIRAC ) +#endif { nchan_transport = 1; } @@ -456,6 +485,9 @@ static void ivas_get_pred_coeffs( const int16_t start_band, const int16_t end_band, const int16_t active_w, +#ifdef LBR_SBA + const int16_t active_w_vlbr, +#endif const int16_t dtx_vad, const int16_t from_dirac ) { @@ -546,7 +578,11 @@ static void ivas_get_pred_coeffs( } else { +#ifdef LBR_SBA + dm_f_local = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_VLBR : IVAS_ACTIVEW_DM_F; +#else dm_f_local = IVAS_ACTIVEW_DM_F; +#endif } for ( b = start_band; b < end_band; b++ ) @@ -645,6 +681,9 @@ static void ivas_get_Wscaling_factor( const int16_t *pNum_dmx, const int16_t bands_bw, const int16_t active_w, +#ifdef LBR_SBA + const int16_t active_w_vlbr, +#endif float *pWscale ) { int16_t b, ch; @@ -657,7 +696,11 @@ static void ivas_get_Wscaling_factor( } else { +#ifdef LBR_SBA + dm_f_local = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR : IVAS_ACTIVEW_DM_F_SCALE; +#else dm_f_local = IVAS_ACTIVEW_DM_F_SCALE; +#endif } for ( b = start_band; b < end_band; b++ ) @@ -1538,6 +1581,9 @@ void ivas_compute_spar_params( const int16_t num_ch, const int16_t bands_bw, const int16_t active_w, +#ifdef LBR_SBA + const int16_t active_w_vlbr, +#endif ivas_spar_md_com_cfg *hSparCfg, ivas_spar_md_t *hSparMd, float *pWscale, @@ -1546,7 +1592,11 @@ void ivas_compute_spar_params( float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; int16_t b, i, ndm; - ivas_get_pred_coeffs( cov_real, pred_coeffs_re, dm_fv_re, num_ch, start_band, end_band, active_w, dtx_vad, from_dirac ); + ivas_get_pred_coeffs( cov_real, pred_coeffs_re, dm_fv_re, num_ch, start_band, end_band, active_w, +#ifdef LBR_SBA + active_w_vlbr, +#endif + dtx_vad, from_dirac ); #ifdef SPAR_HOA_DBG /*fprintf(stderr, "\n\n Prediction Coefficients:\n"); @@ -1578,7 +1628,11 @@ void ivas_compute_spar_params( #endif ivas_get_Wscaling_factor( cov_real, pred_coeffs_re, mixer_mat, start_band, end_band, dtx_vad, num_ch, - hSparCfg->num_dmx_chans_per_band, bands_bw, active_w, pWscale ); + hSparCfg->num_dmx_chans_per_band, bands_bw, active_w, +#ifdef LBR_SBA + active_w_vlbr, +#endif + pWscale ); for ( b = start_band; b < end_band; b++ ) { @@ -1648,7 +1702,13 @@ void ivas_get_spar_md_from_dirac( const int16_t end_band, const int16_t order, const int16_t dtx_vad, - float Wscale_d[IVAS_MAX_NUM_BANDS] ) + float Wscale_d[IVAS_MAX_NUM_BANDS] +#ifdef LBR_SBA + , + const uint8_t useLowerRes, + const int16_t active_w_vlbr +#endif +) { int16_t num_ch, band, i, j; int16_t block, ch; @@ -1684,7 +1744,11 @@ void ivas_get_spar_md_from_dirac( ppMixer_mat[i] = pMixer_mat[i]; } +#ifdef LBR_SBA + if ( ( start_band >= 6 && hSpar_md_cfg->nchan_transport <= 2 && ( dtx_vad == 1 ) ) || ( useLowerRes && start_band >= 3 && hSpar_md_cfg->nchan_transport <= 2 && ( dtx_vad == 1 ) ) ) +#else if ( start_band >= 6 && hSpar_md_cfg->nchan_transport <= 2 && ( dtx_vad == 1 ) ) +#endif { float P_norm[3]; int16_t idx; @@ -1743,6 +1807,12 @@ void ivas_get_spar_md_from_dirac( { ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][i_ts], (int16_t) ele_dirac[band][i_ts], response_avg, order ); } +#ifdef LBR_SBA + else if ( useLowerRes ) + { + ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][0], (int16_t) ele_dirac[band][0], response_avg, order ); + } +#endif else { for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) @@ -1905,7 +1975,11 @@ void ivas_get_spar_md_from_dirac( #endif ivas_compute_spar_params( pCov_real, dm_fv_re, i_ts, ppMixer_mat, start_band, end_band, dtx_vad, - num_ch, 1, hSpar_md_cfg->active_w, hSpar_md_cfg, hSpar_md, Wscale, 1 ); + num_ch, 1, hSpar_md_cfg->active_w, +#ifdef LBR_SBA + active_w_vlbr, +#endif + hSpar_md_cfg, hSpar_md, Wscale, 1 ); if ( mixer_mat != NULL ) { diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 5f09e0d45a331acae46cfa398580f351393b791e..1103040a2270e4df9afc4c80c4c473c82ba1231b 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -71,6 +71,11 @@ typedef struct float last_true_azimuth; /* MD smoothing in DTX- last true Q azimuth value */ float last_true_elevation; /* MD smoothing in DTX- last true Q elevation value */ +#ifdef FIX_387_ISM_MD_FEC + int16_t ism_md_fec_cnt_enc; /* counter of continuous frames where MD are not transmitted */ + int16_t ism_md_inc_diff_cnt; /* counter of continuous frames where MD are transmitted in inactive segments when MD significantly changes */ +#endif + #ifdef MASA_AND_OBJECTS int16_t ism_imp; /* ISM importance flag */ int16_t ism_vad_flag; diff --git a/lib_com/ivas_td_decorr.c b/lib_com/ivas_td_decorr.c index 23620b3b2db5dc6db7e83828c615efef98faba5e..0215bfcf56b5b682143cc448e5eaf76d81186556 100644 --- a/lib_com/ivas_td_decorr.c +++ b/lib_com/ivas_td_decorr.c @@ -87,12 +87,111 @@ static const float ivas_three_pow_frac[IVAS_MAX_DECORR_APD_SECTIONS] = { }; +#ifdef FIX_417_TD_DECORR_BRATE_SW +#define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN ( 2.0f ) +#define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR ( 3.0f ) +#endif + /*------------------------------------------------------------------------------------------* * Local functions declaration *------------------------------------------------------------------------------------------*/ static int16_t ivas_get_APD_filt_orders( const int16_t num_out_chans, const int32_t output_Fs, int16_t *APD_filt_orders ); -static ivas_error ivas_td_decorr_init( ivas_td_decorr_state_t *hTdDecorr, const int16_t num_out_chans, const int16_t ducking_flag ); + +static void ivas_td_decorr_init( ivas_td_decorr_state_t *hTdDecorr, const int16_t num_out_chans, const int16_t ducking_flag ); + + +#ifdef FIX_417_TD_DECORR_BRATE_SW +/*------------------------------------------------------------------------- + * ivas_td_decorr_reconfig_dec() + * + * Allocate and initialize time domain decorrelator handle + *------------------------------------------------------------------------*/ + +ivas_error ivas_td_decorr_reconfig_dec( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int32_t ivas_total_brate, /* i : total IVAS bitrate */ + const int16_t nchan_transport, /* i : number of transport channels */ + const int32_t output_Fs, /* i : output sampling rate */ + ivas_td_decorr_state_t **hTdDecorr, /* i/o: TD decorrelator handle */ + uint16_t *useTdDecorr /* i/o: TD decorrelator flag */ +) +{ + uint16_t useTdDecorr_new; + ivas_error error; + + useTdDecorr_new = 0; + if ( ivas_format == SBA_FORMAT ) + { + if ( nchan_transport == 1 ) + { + useTdDecorr_new = 1; + } + } + else if ( ivas_format == MASA_FORMAT ) + { + if ( ( ivas_total_brate < IVAS_48k && nchan_transport == 1 ) || ivas_total_brate < MASA_STEREO_MIN_BITRATE ) + { + useTdDecorr_new = 1; + } + } + else if ( ivas_format == MC_FORMAT ) + { + if ( ivas_total_brate < IVAS_48k && nchan_transport == 1 ) + { + useTdDecorr_new = 1; + } + } + + if ( *useTdDecorr != useTdDecorr_new ) + { + *useTdDecorr = useTdDecorr_new; + + if ( *useTdDecorr ) + { + if ( ivas_total_brate >= IVAS_13k2 && ivas_format == SBA_FORMAT ) + { + if ( *hTdDecorr == NULL ) + { + if ( ( error = ivas_td_decorr_dec_open( hTdDecorr, output_Fs, 3, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ivas_total_brate < IVAS_24k4 ) + { + ( *hTdDecorr )->pTrans_det->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR; + } + else + { + ( *hTdDecorr )->pTrans_det->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC_PARA_BIN; + } + } + else + { + if ( *hTdDecorr == NULL ) + { + if ( ( error = ivas_td_decorr_dec_open( hTdDecorr, output_Fs, 3, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + ivas_td_decorr_init( *hTdDecorr, 3, 0 ); + } + } + } + else + { + ivas_td_decorr_dec_close( hTdDecorr ); + } + } + + return IVAS_ERR_OK; +} +#endif /*------------------------------------------------------------------------- @@ -275,7 +374,7 @@ static int16_t ivas_get_APD_filt_orders( * TD decorr Initialisation function *-----------------------------------------------------------------------------------------*/ -static ivas_error ivas_td_decorr_init( +static void ivas_td_decorr_init( ivas_td_decorr_state_t *hTdDecorr, const int16_t num_out_chans, const int16_t ducking_flag ) @@ -295,7 +394,7 @@ static ivas_error ivas_td_decorr_init( } } - return IVAS_ERR_OK; + return; } diff --git a/lib_com/options.h b/lib_com/options.h index 64aab7987873d07c1a742bbd2a44360636bfc151..e78be0744c399b8fc09ad351ee11c74712d831db 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -114,6 +114,7 @@ /*#define DEBUG_SBA*/ /* debug DIRAC/SPAR in-out */ #ifdef DEBUG_SBA +/*#define DEBUG_LBR_SBA*/ /* debug low bitrate SBA (SPAR+DirAC) */ /*#define DEBUG_SBA_AUDIO_DUMP*/ /* SBA intermediate audio wav file dumping */ /*#define DEBUG_SBA_MD_DUMP*/ /* SBA metadata and variable file dumping */ /*#define DEBUG_SPAR_MD_TARGET_TUNING*/ /* SPAR MD target bitrate tuning debug code */ @@ -149,6 +150,7 @@ #define SNS_MSVQ /* FhG: contribution 33 - MSVQ for SNS parameters at stereo mid bitrates */ #define FIX_379_GAININTP /* Eri: Adds a gain interpolation for directional/distance gain to handle abrupt changes in metadata (Non BE) */ +#define FIX_387_ISM_MD_FEC /* VA: Issue 387: fix MD discontinuity in ISM FEC */ #define FIX_418_SID_BITRATE /* Eri: Issue 418: Using the correct bitrate for unified stereo SID */ #define PARAMMC_SHORT_ENC_MDFT /* FhG: Issue 410: complexity optimization for parametric Multichannel modes */ @@ -158,13 +160,22 @@ #define ERI_FDCNGVQ_LOW_ROM /* Eri: Contribution #31 Table ROM saving for IVAS FDCNG-VQ modes */ -#define FIX_401_DIRAC_RENDERER_META_READ_INDICES /* Nokia: Issue 401: Fix metadata reading indices in DirAC renderer. */ -#define FIX_406_IVAS_POSITION /* Eri: Issue 406: Unify IVAS_POSITION to use IVAS_VECTOR3 instead */ -#define REND_DEBUGGING_REVISION /* VA: encapsulate rendering debugging options with DEBUGGING */ #define FIX_416_ISM_BR_SWITCHING /* FhG: add missing CLDFB reconfig to ISM BR switching */ +#define FIX_SP2A /* VA: Issue 412: Adjust threshold for the S_p2a feature in the tonal detector */ +#define FIX_413_SBA_DTX /* Dlb: Fix for issue 413, SBA DTX CNG in 2TC mode*/ +#define FIX_417_TD_DECORR_BRATE_SW /* VA: Issue 417: fix incorrect use of TD decorrelator in bitrate switching */ - +#define LBR_SBA /* Contribution 47: Master macro for low bitrate SBA (SPAR+DirAC) */ +#ifdef LBR_SBA +#define LBR_SBA_BR_SWITCHING /* Clean up changes for SBA bitrate switching */ +#define LBR_SBA_DM_COV_FIX /* Covariance smoothing and resetting fixes proposed at higher bitrates */ +#ifdef LBR_SBA_DM_COV_FIX +#define LBR_SBA_EXTRA_COV_SMOOTH /* Extra covariance smoothing for low bitrate SBA */ +#endif +/*#define LBR_SBA_PLANAR*/ /* Converting low bitrate SBA modes to Planar */ +#define LBR_ADAP_SMOOTHING +#endif #define MASA_AND_OBJECTS /* Nokia: Combination of MASA and objects */ #ifdef MASA_AND_OBJECTS #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index a45fe2bb7d695fb6c14f50bec6cc3935fad24586..687613149c885b1e891417da4e8ac07d7a4573e3 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -316,7 +316,17 @@ ivas_error ivas_dec( return error; } } - +#ifdef DEBUG_LBR_SBA + /* SCE Decoder Output */ + for ( int t = 0; t < 960; t++ ) + { + for ( int c = 0; c < st_ivas->nchan_transport; c++ ) + { + float val = output[c][t] / MAX16B_FLT; + dbgwrite( &val, sizeof( float ), 1, 1, "int_dec_core_out.raw" ); + } + } +#endif #ifdef DEBUG_SBA_AUDIO_DUMP /* Dump audio signal after core-decoding */ ivas_spar_dump_signal_wav( output_frame, NULL, output, st_ivas->nchan_transport, spar_foa_dec_wav[0], "core-decoding" ); diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index a1360fc9854ca4049181c89c05015cbc4dd2e245..9469278bb8dc94ab312f73eea4102b44ad8462a8 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -295,10 +295,14 @@ ivas_error ivas_dec_setup( { int16_t nchan_transport_old, nchan_transport; SBA_MODE sba_mode_old; +#ifndef LBR_SBA int32_t last_ivas_total_brate; last_ivas_total_brate = st_ivas->last_active_ivas_total_brate; sba_mode_old = ivas_sba_mode_select( last_ivas_total_brate ); +#else + sba_mode_old = ivas_sba_mode_select(); +#endif nchan_transport_old = st_ivas->nchan_transport; nchan_transport = ( st_ivas->sid_format == SID_SBA_2TC ) ? 2 : 1; @@ -429,8 +433,11 @@ static ivas_error ivas_read_format( { ( *num_bits_read )++; st_ivas->ivas_format = SBA_FORMAT; - +#ifndef LBR_SBA st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); +#else + st_ivas->sba_mode = ivas_sba_mode_select(); +#endif } break; @@ -1958,7 +1965,7 @@ void ivas_destroy_dec( /*-------------------------------------------------------------------* - * ivas_init_dec_get_num_cldfb_analyses() + * ivas_init_dec_get_num_cldfb_instances() * * Return number of CLDFB analysis & synthesis instances *-------------------------------------------------------------------*/ diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 1dfaf262e112447707b795a3cb1f4cc0c15cef4e..fd8ca233071870790b1bb1845fb50d5edb39e0c2 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -56,7 +56,7 @@ static ivas_error ivas_ism_bitrate_switching( int32_t element_brate_tmp[MAX_NUM_OBJECTS]; int16_t nSCE_old, nCPE_old; #ifdef FIX_416_ISM_BR_SWITCHING - int16_t numCldfbAnalyses_old, numCldfbSyntheses_old; + int16_t numCldfbAnalyses_old, numCldfbSyntheses_old, ism_mode; #endif error = IVAS_ERR_OK; @@ -65,7 +65,11 @@ static ivas_error ivas_ism_bitrate_switching( nSCE_old = st_ivas->nSCE; #ifdef FIX_416_ISM_BR_SWITCHING + /* we have to temporarily set the ism mode back to the old one, otherwise this can give wrong results*/ + ism_mode = st_ivas->ism_mode; + st_ivas->ism_mode = last_ism_mode; ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); + st_ivas->ism_mode = ism_mode; #endif if ( ( error = ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->nchan_ism, NULL, NULL, NULL, element_brate_tmp, NULL, NULL diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 9f1c5750c36591c53a3ad77601fa36b700f75f3b..810bd7bc09a411591fe40d8ccf6214925544c550 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1353,6 +1353,9 @@ ivas_error ivas_masa_dec_reconfigure( uint16_t *bit_stream; Decoder_State **sts; int32_t ivas_total_brate, last_ivas_total_brate; +#ifdef FIX_417_TD_DECORR_BRATE_SW + int16_t numCldfbAnalyses_old, numCldfbSyntheses_old; +#endif ivas_error error; #ifdef MASA_AND_OBJECTS int32_t ism_total_brate; @@ -1363,6 +1366,10 @@ ivas_error ivas_masa_dec_reconfigure( ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; +#ifdef FIX_417_TD_DECORR_BRATE_SW + ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); +#endif + /*-----------------------------------------------------------------* * Allocate and initialize SCE/CPE and other handles *-----------------------------------------------------------------*/ @@ -1420,6 +1427,42 @@ ivas_error ivas_masa_dec_reconfigure( } } +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->last_ivas_format == MASA_FORMAT ) /* note: switching within OMASA is handled in ivas_omasa_dec_config() */ + { +#endif + +#ifdef FIX_417_TD_DECORR_BRATE_SW + /*-----------------------------------------------------------------* + * TD Decorrelator + *-----------------------------------------------------------------*/ + + if ( st_ivas->hDiracDecBin != NULL ) + { + if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /*-----------------------------------------------------------------* + * CLDFB instances + *-----------------------------------------------------------------*/ + + if ( ( error = ivas_cldfb_dec_reconfig( st_ivas, st_ivas->nchan_transport, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) + { + return error; + } + + /*-----------------------------------------------------------------* + * Set-up MASA coding elements and bitrates + *-----------------------------------------------------------------*/ +#endif + +#ifdef MASA_AND_OBJECTS + } +#endif + #ifdef MASA_AND_OBJECTS ism_total_brate = 0; if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) diff --git a/lib_dec/ivas_mcmasa_dec.c b/lib_dec/ivas_mcmasa_dec.c index 0b375d40313ef21dcd72eb81c8e64159385d74b8..59d215e22ca4abfb1e784903fc1bc055efe51da6 100755 --- a/lib_dec/ivas_mcmasa_dec.c +++ b/lib_dec/ivas_mcmasa_dec.c @@ -131,6 +131,16 @@ ivas_error ivas_mcmasa_dec_reconfig( } else { +#ifdef FIX_417_TD_DECORR_BRATE_SW + /* if necessary, close/open td-decorrs */ + if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* regularization factor is bitrate-dependent */ + st_ivas->hDiracDecBin->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); +#else /* the decision for useTdDecorr is done in ivas_dirac_dec_init_binaural_data(). here, comparing against the same condition. */ if ( st_ivas->hDiracDecBin->useTdDecorr != ( ivas_total_brate < IVAS_48k && st_ivas->nchan_transport == 1 ) ) { @@ -141,6 +151,7 @@ ivas_error ivas_mcmasa_dec_reconfig( return error; } } +#endif } } diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 1ad01239cb0aadb2976d61530feff1781c83c568..4d6f8343084bf4e1dc02862741c7351cd47389c5 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -928,6 +928,8 @@ static ivas_error ivas_mc_dec_reconfig( return error; } + +#ifndef FIX_417_TD_DECORR_BRATE_SW /*-----------------------------------------------------------------* * CLDFB instances *-----------------------------------------------------------------*/ @@ -936,7 +938,7 @@ static ivas_error ivas_mc_dec_reconfig( { return error; } - +#endif /*-----------------------------------------------------------------* * Allocate the LFE handle that is coded seperately after the allocation of the core coders *-----------------------------------------------------------------*/ @@ -1121,5 +1123,28 @@ static ivas_error ivas_mc_dec_reconfig( #endif } +#ifdef FIX_417_TD_DECORR_BRATE_SW + /*-----------------------------------------------------------------* + * TD Decorrelator + *-----------------------------------------------------------------*/ + + if ( st_ivas->hDiracDecBin != NULL ) + { + if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /*-----------------------------------------------------------------* + * CLDFB instances + *-----------------------------------------------------------------*/ + + if ( ( error = ivas_cldfb_dec_reconfig( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif + return error; } diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 4fe74fd8410f083c070b08a928ecfb6898e29aee..b89ce050198cb1b41330bc1fb2690680a34ddefa 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -136,6 +136,7 @@ ivas_error ivas_omasa_dec_config( int16_t k, sce_id, nSCE_old, nchan_hp20_old, numCldfbAnalyses_old, numCldfbSyntheses_old, n_MD; int32_t ivas_total_brate, ism_total_brate, cpe_brate; ISM_MODE ism_mode_old; + IVAS_FORMAT ivas_format_orig; ivas_error error; /* initializations */ @@ -146,7 +147,11 @@ ivas_error ivas_omasa_dec_config( ism_mode_old = ivas_omasa_ism_mode_select( st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->nchan_ism ); st_ivas->ism_mode = ism_mode_old; + ivas_format_orig = st_ivas->ivas_format; + st_ivas->ivas_format = st_ivas->last_ivas_format; ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); + st_ivas->ivas_format = ivas_format_orig; + nSCE_old = st_ivas->nSCE; nchan_hp20_old = getNumChanSynthesis( st_ivas ); @@ -202,7 +207,7 @@ ivas_error ivas_omasa_dec_config( ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; } - if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, 1, 2, 0, sep_object_brate[k - 2][st_ivas->nSCE - 1], ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, 1, 2, 0, st_ivas->nSCE > 0 ? sep_object_brate[k - 2][st_ivas->nSCE - 1] : 0, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) { return error; } @@ -238,6 +243,17 @@ ivas_error ivas_omasa_dec_config( ivas_ism_metadata_close( st_ivas->hIsmMetaData, n_MD ); +#ifdef FIX_417_TD_DECORR_BRATE_SW + /* TD Decorrelator */ + if ( st_ivas->hDiracDecBin != NULL ) + { + if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif + /* CLDFB instances */ if ( ( error = ivas_cldfb_dec_reconfig( st_ivas, 2, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) { diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c old mode 100755 new mode 100644 index af7281a5786c4d7f1aaeb301e61fefbcd2d43544..6fb6deab7183ebd15a532dadfcf955c14028304e --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -108,22 +108,30 @@ ivas_error ivas_sba_dec_reconfigure( AUDIO_CONFIG intern_config_old; int16_t numCldfbAnalyses_old, numCldfbSyntheses_old; int16_t sba_dirac_stereo_flag_old; +#ifndef LBR_SBA_BR_SWITCHING SBA_MODE sba_mode_old; - int32_t ivas_total_brate, last_ivas_total_brate; + int32_t last_ivas_total_brate; +#endif + int32_t ivas_total_brate; RENDERER_TYPE old_renderer_type; DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; +#ifndef LBR_SBA_BR_SWITCHING int16_t band_grouping[IVAS_MAX_NUM_BANDS + 1]; - +#endif error = IVAS_ERR_OK; hDecoderConfig = st_ivas->hDecoderConfig; ivas_total_brate = hDecoderConfig->ivas_total_brate; +#ifndef LBR_SBA_BR_SWITCHING last_ivas_total_brate = st_ivas->last_active_ivas_total_brate; - +#ifndef LBR_SBA sba_mode_old = ivas_sba_mode_select( last_ivas_total_brate ); +#else + sba_mode_old = ivas_sba_mode_select(); +#endif st_ivas->sba_mode = sba_mode_old; - +#endif /*-----------------------------------------------------------------* * Set SBA high-level parameters * Save old SBA high-level parameters @@ -137,12 +145,17 @@ ivas_error ivas_sba_dec_reconfigure( sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); +#ifndef LBR_SBA_BR_SWITCHING +#ifndef LBR_SBA st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); - +#else + st_ivas->sba_mode = ivas_sba_mode_select(); +#endif +#endif /*-----------------------------------------------------------------* * Allocate, initialize, and configure SBA handles *-----------------------------------------------------------------*/ - +#ifndef LBR_SBA_BR_SWITCHING if ( st_ivas->sba_mode != SBA_MODE_SPAR ) { ivas_spar_dec_close( &( st_ivas->hSpar ), hDecoderConfig->output_Fs, 0 ); @@ -156,8 +169,10 @@ ivas_error ivas_sba_dec_reconfigure( } else { +#endif int16_t sba_order_internal; - SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; + SPAR_DEC_HANDLE hSpar; + hSpar = st_ivas->hSpar; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); @@ -192,8 +207,9 @@ ivas_error ivas_sba_dec_reconfigure( hSpar = st_ivas->hSpar; st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); +#ifndef LBR_SBA_BR_SWITCHING } - +#endif if ( st_ivas->nchan_transport == 1 ) { st_ivas->element_mode_init = IVAS_SCE; @@ -257,8 +273,11 @@ ivas_error ivas_sba_dec_reconfigure( { ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); } - +#ifndef LBR_SBA_BR_SWITCHING if ( ( ( st_ivas->renderer_type != RENDERER_DISABLE ) && ( st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC ) ) || ( sba_mode_old != st_ivas->sba_mode ) || ( ( st_ivas->sba_mode == SBA_MODE_SPAR ) && ( ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) && ( st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_STEREO ) && ( st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_MONO ) ) ) ) +#else + if ( ( ( st_ivas->renderer_type != RENDERER_DISABLE ) && ( st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC ) ) || ( ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) && ( st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_STEREO ) && ( st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_MONO ) ) ) +#endif { DIRAC_CONFIG_FLAG flag_config; @@ -266,10 +285,12 @@ ivas_error ivas_sba_dec_reconfigure( if ( st_ivas->hDirAC != NULL ) { flag_config = DIRAC_RECONFIGURE_MODE; +#ifndef LBR_SBA_BR_SWITCHING if ( ( sba_mode_old == st_ivas->sba_mode ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) { flag_config = DIRAC_RECONFIGURE; } +#endif } if ( ( error = ivas_dirac_dec_config( st_ivas, flag_config ) ) != IVAS_ERR_OK ) @@ -277,15 +298,18 @@ ivas_error ivas_sba_dec_reconfigure( return error; } } - +#ifndef LBR_SBA_BR_SWITCHING if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { +#endif 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_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) { return error; } +#ifndef LBR_SBA_BR_SWITCHING } - +#endif +#ifndef LBR_SBA_BR_SWITCHING if ( ( ( hDecoderConfig->output_config == AUDIO_CONFIG_FOA ) || ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ) || ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_MONO ) ) && ( ( sba_mode_old != st_ivas->sba_mode ) && ( st_ivas->sba_mode == SBA_MODE_SPAR ) ) ) { ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); @@ -295,15 +319,22 @@ ivas_error ivas_sba_dec_reconfigure( ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); } - +#endif +#ifndef LBR_SBA_BR_SWITCHING else if ( st_ivas->renderer_type == RENDERER_DISABLE || ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->sba_mode != SBA_MODE_SPAR ) ) +#else + if ( st_ivas->renderer_type == RENDERER_DISABLE ) +#endif { ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); vbap_free_data( &( st_ivas->hVBAPdata ) ); } - +#ifndef LBR_SBA_BR_SWITCHING if ( st_ivas->hDirAC != NULL && st_ivas->sba_mode == SBA_MODE_SPAR ) +#else + if ( st_ivas->hDirAC != NULL ) +#endif { mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; @@ -327,6 +358,20 @@ ivas_error ivas_sba_dec_reconfigure( return error; } +#ifdef FIX_417_TD_DECORR_BRATE_SW + /*-----------------------------------------------------------------* + * TD Decorrelator + *-----------------------------------------------------------------*/ + + if ( st_ivas->hDiracDecBin != NULL ) + { + if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif + /*-----------------------------------------------------------------* * CLDFB instances *-----------------------------------------------------------------*/ diff --git a/lib_dec/ivas_sba_dirac_stereo_dec.c b/lib_dec/ivas_sba_dirac_stereo_dec.c index 644a3dc5233175d009837eea080d2da63cd1bc50..089492048021527ec3d025ab1d6d3b96e25383df 100644 --- a/lib_dec/ivas_sba_dirac_stereo_dec.c +++ b/lib_dec/ivas_sba_dirac_stereo_dec.c @@ -879,7 +879,7 @@ void ivas_sba_dirac_stereo_dec( /* DFT Stereo upmix */ stereo_dft_dec( hStereoDft, hCPE->hCoreCoder[0], DFT, NULL, NULL, 1 /*st_ivas->sba_dirac_stereo_flag*/, sba_mono_flag, - ( st_ivas->hSpar != NULL && !mcmasa ) ? st_ivas->hSpar->hMdDec : 0, + ( st_ivas->hSpar != NULL && !mcmasa ) ? st_ivas->hSpar->hMdDec : NULL, ( st_ivas->hSpar != NULL && !mcmasa ) ? st_ivas->hSpar->hFbMixer->cross_fade_start_offset : 0, st_ivas->hDecoderConfig->output_Fs, st_ivas->nchan_transport ); diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 01e4db2ed40c3764b0b9d07e375cb255767d39c2..c5d25392ac2269cdf50d9f494163fa3fd57a2d7d 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -41,6 +41,9 @@ #include "ivas_prot.h" #include "ivas_prot_rend.h" #include "ivas_rom_com.h" +#ifdef LBR_ADAP_SMOOTHING +#include "ivas_rom_dec.h" +#endif #include "ivas_stat_com.h" #include #include @@ -892,6 +895,87 @@ static void ivas_spar_get_skip_mat( } +#ifdef LBR_ADAP_SMOOTHING +static void ivas_spar_calc_smooth_facs( + float *cldfb_in_ts_re[CLDFB_NO_COL_MAX], + float *cldfb_in_ts_im[CLDFB_NO_COL_MAX], + int16_t nbands_spar, + ivas_fb_bin_to_band_data_t *bin2band, + float *smooth_fac, + float smooth_buf[IVAS_MAX_NUM_BANDS][2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1] ) +{ + int16_t b, bin, i, ts; + float subframe_band_nrg[IVAS_MAX_NUM_BANDS]; + float smooth_long_avg[IVAS_MAX_NUM_BANDS]; + float smooth_short_avg[IVAS_MAX_NUM_BANDS]; + + bin = 0; + for ( b = 0; b < nbands_spar; b++ ) + { + if ( b > 0 && bin2band->p_cldfb_map_to_spar_band[bin] < bin2band->p_cldfb_map_to_spar_band[bin - 1] ) + { + break; + } + /* calculate band-wise subframe energies */ + subframe_band_nrg[b] = 0.f; + while ( b == bin2band->p_cldfb_map_to_spar_band[bin] ) + { + for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) + { + subframe_band_nrg[b] += cldfb_in_ts_re[ts][bin] * cldfb_in_ts_re[ts][bin] + cldfb_in_ts_im[ts][bin] * cldfb_in_ts_im[ts][bin]; + } + bin++; + } + subframe_band_nrg[b] = sqrtf( subframe_band_nrg[b] ); + smooth_buf[b][0] = subframe_band_nrg[b]; + + /* calculate short and long energy averages */ + smooth_short_avg[b] = EPSILON; + for ( i = 0; i < 2 * SBA_DIRAC_NRG_SMOOTH_SHORT; i++ ) + { + smooth_short_avg[b] += smooth_buf[b][i]; + } + + smooth_long_avg[b] = smooth_short_avg[b]; + for ( i = 2 * SBA_DIRAC_NRG_SMOOTH_SHORT; i < 2 * SBA_DIRAC_NRG_SMOOTH_LONG; i++ ) + { + smooth_long_avg[b] += smooth_buf[b][i]; + } + smooth_short_avg[b] /= ( 2 * SBA_DIRAC_NRG_SMOOTH_SHORT ); + smooth_long_avg[b] /= ( 2 * SBA_DIRAC_NRG_SMOOTH_LONG ); + + /* calculate smoothing factor based on energy averages */ + /* reduce factor for higher short-term energy */ + smooth_fac[b] = min( 1.f, smooth_long_avg[b] / smooth_short_avg[b] ); + /* map factor to range [0;1] */ + smooth_fac[b] = max( 0.f, smooth_fac[b] - (float) SBA_DIRAC_NRG_SMOOTH_SHORT / SBA_DIRAC_NRG_SMOOTH_LONG ) * ( (float) SBA_DIRAC_NRG_SMOOTH_LONG / ( SBA_DIRAC_NRG_SMOOTH_LONG - SBA_DIRAC_NRG_SMOOTH_SHORT ) ); + /* compress factor (higher compression in lowest bands) */ + if ( b < 2 ) + { + smooth_fac[b] = powf( smooth_fac[b], 0.25f ); + } + else + { + smooth_fac[b] = powf( smooth_fac[b], 0.5f ); + } + + /* apply upper bounds depending on band */ + smooth_fac[b] = max( min_smooth_gains1[b], min( max_smooth_gains2[b], smooth_fac[b] ) ); + } + + for ( b = 0; b < nbands_spar; b++ ) + { + for ( i = 2 * SBA_DIRAC_NRG_SMOOTH_LONG; i > 0; i-- ) + { + smooth_buf[b][i] = smooth_buf[b][i - 1]; + } + } + + return; +} +#endif + + /*-------------------------------------------------------------------* * ivas_spar_dec_upmixer() * @@ -1094,11 +1178,38 @@ void ivas_spar_dec_upmixer( } } +#ifdef LBR_ADAP_SMOOTHING + if ( ( hDecoderConfig->ivas_total_brate < IVAS_24k4 ) && ( ( hDecoderConfig->output_config == AUDIO_CONFIG_HOA2 ) || ( hDecoderConfig->output_config == AUDIO_CONFIG_HOA3 ) ) ) + { + for ( in_ch = 0; in_ch < numch_in; in_ch++ ) + { + ivas_spar_calc_smooth_facs( cldfb_in_ts_re[in_ch], cldfb_in_ts_im[in_ch], num_spar_bands, &hSpar->hFbMixer->pFb->fb_bin_to_band, hSpar->hMdDec->smooth_fac[in_ch], hSpar->hMdDec->smooth_buf[in_ch] ); + } + } +#endif + for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { /* determine SPAR parameters for this time slots */ ivas_spar_get_parameters( hSpar, hDecoderConfig, ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES, numch_out, numch_in, num_spar_bands, mixer_mat ); +#ifdef LBR_ADAP_SMOOTHING + if ( ( hDecoderConfig->ivas_total_brate < IVAS_24k4 ) && ( ( hDecoderConfig->output_config == AUDIO_CONFIG_HOA2 ) || ( hDecoderConfig->output_config == AUDIO_CONFIG_HOA3 ) ) ) + { + for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) + { + for ( out_ch = 0; out_ch < numch_out; out_ch++ ) + { + for ( in_ch = 0; in_ch < numch_in; in_ch++ ) + { + mixer_mat[out_ch][in_ch][spar_band] = ( 1 - hSpar->hMdDec->smooth_fac[in_ch][spar_band] ) * mixer_mat[out_ch][in_ch][spar_band] + hSpar->hMdDec->smooth_fac[in_ch][spar_band] * hSpar->hMdDec->mixer_mat_prev2[out_ch][in_ch][spar_band]; + hSpar->hMdDec->mixer_mat_prev2[out_ch][in_ch][spar_band] = mixer_mat[out_ch][in_ch][spar_band]; + } + } + } + } +#endif + for ( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ ) { float out_re[IVAS_SPAR_MAX_CH]; diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 3b47d6500e1ab98d6a3bcdca8da23c7fcccbfb47..5e50f42b768c3107cd10860d5b60f7a3bb9f36ec 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -63,11 +63,27 @@ static const int16_t ivas_spar_dec_plc_spatial_target[IVAS_SPAR_MAX_CH] = { 1, 0 * Static functions declaration *------------------------------------------------------------------------------------------*/ -static void ivas_get_spar_matrices( ivas_spar_md_dec_state_t *hMdDec, const int16_t num_bands_out, const int16_t n_ts, const int16_t bw, const int16_t dtx_vad, const int16_t nB, const int16_t sba_order ); +static void ivas_get_spar_matrices( ivas_spar_md_dec_state_t *hMdDec, const int16_t num_bands_out, const int16_t n_ts, const int16_t bw, const int16_t dtx_vad, const int16_t nB, const int16_t sba_order +#ifdef LBR_SBA + , + const int16_t active_w_vlbr +#endif +); -static void ivas_decode_arith_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, const uint16_t qsi, const int16_t nB, const int16_t bands_bw, int16_t *pDo_diff, const int16_t freq_diff, const int16_t planarCP ); +static void ivas_decode_arith_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, const uint16_t qsi, const int16_t nB, const int16_t bands_bw, int16_t *pDo_diff, const int16_t freq_diff, const int16_t planarCP +#ifdef LBR_SBA + , + const int16_t strat, + const int32_t ivas_total_brate +#endif +); -static void ivas_decode_huffman_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, const uint16_t qsi, const int16_t nB, const int16_t bands_bw, const int16_t planarCP ); +static void ivas_decode_huffman_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, const uint16_t qsi, const int16_t nB, const int16_t bands_bw, const int16_t planarCP +#ifdef LBR_SBA_PLANAR + , + const int32_t ivas_total_brate +#endif +); static void ivas_fill_band_coeffs_idx( ivas_band_coeffs_ind_t *pBands_idx, const int16_t nB, int16_t *pSymbol_re, ivas_cell_dim_t *pCell_dims, ivas_coeffs_type_t coeff_type, const int16_t planarCP ); @@ -536,6 +552,27 @@ ivas_error ivas_spar_md_dec_init( set_f( hMdDec->spar_md.en_ratio_slow, 0.0f, IVAS_MAX_NUM_BANDS ); set_f( hMdDec->spar_md.ref_pow_slow, 0.0f, IVAS_MAX_NUM_BANDS ); +#ifdef LBR_ADAP_SMOOTHING + for ( i = 0; i < IVAS_SPAR_MAX_CH; i++ ) + { + set_zero( hMdDec->smooth_fac[i], IVAS_MAX_NUM_BANDS ); + } + for ( i = 0; i < IVAS_SPAR_MAX_CH; i++ ) + { + for ( j = 0; j < IVAS_MAX_NUM_BANDS; j++ ) + { + set_zero( hMdDec->smooth_buf[i][j], 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + } + for ( i = 0; i < IVAS_SPAR_MAX_CH; i++ ) + { + for ( j = 0; j < IVAS_SPAR_MAX_CH; j++ ) + { + set_zero( hMdDec->mixer_mat_prev2[i][j], IVAS_MAX_NUM_BANDS ); + } + } +#endif + return IVAS_ERR_OK; } @@ -620,7 +657,10 @@ void ivas_spar_md_dec_process( ivas_spar_md_dec_state_t *hMdDec; hMdDec = st_ivas->hSpar->hMdDec; - +#ifdef LBR_SBA + int16_t active_w_vlbr; + active_w_vlbr = ( st_ivas->hDecoderConfig->ivas_total_brate < IVAS_24k4 ) ? 1 : 0; +#endif ivas_spar_dec_parse_md_bs( hMdDec, st0, &nB, &bw, &dtx_vad, st_ivas->hDecoderConfig->ivas_total_brate, ivas_spar_br_table_consts[hMdDec->table_idx].usePlanarCoeff, st_ivas->hQMetaData->sba_inactive_mode ); @@ -671,9 +711,103 @@ void ivas_spar_md_dec_process( } } #endif +#ifdef DEBUG_LBR_SBA + /* Dumping SPAR HOA Coefficients */ + /*char f_name[100]; + int16_t nbands = 12; + int16_t num_subframes = 1; + int16_t num_elements = 7; + int16_t num_block_group = 1; + int16_t byte_size = sizeof( float ); + + sprintf( f_name, "SBA_MD_values_dec_PR.bin" ); + ( frame == 0 ) ? dbgwrite( &nbands, sizeof( nbands ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_group, sizeof( num_block_group ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + + for ( b = 0; b < nbands; b++ ) + { + for ( int16_t sf = 0; sf < num_subframes; sf++ ) + { + for ( int16_t bl = 0; bl < num_block_group; bl++ ) + { + dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[0], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[1], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[2], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[3], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[4], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[5], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[6], byte_size, 1, 1, f_name ); + // fprintf(stdout, "%f\t%f\t%f\t%d\t%d\n", dirac_md_kbps, spar_md_kbps, sba_md_kbps, qsi, code_strat ); + } + } + } + nbands = 12; // 6 total, just looking at SPAR + num_subframes = 1; + num_elements = 12; + num_block_group = 1; + byte_size = sizeof( float ); + + sprintf( f_name, "SBA_MD_values_dec_C.bin" ); + ( frame == 0 ) ? dbgwrite( &nbands, sizeof( nbands ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_group, sizeof( num_block_group ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + for ( b = 0; b < nbands; b++ ) + { + for ( int16_t sf = 0; sf < num_subframes; sf++ ) + { + for ( int16_t bl = 0; bl < num_block_group; bl++ ) + { + for ( int16_t p = 0; p < 4; p++ ) + { + for ( int16_t r = 0; r < 3; r++ ) + { + dbgwrite( &hMdDec->spar_md.band_coeffs[b].C_re[p][r], byte_size, 1, 1, f_name ); + } + } + } + } + } + nbands = 12; // 6 total, just looking at SPAR + num_subframes = 1; + num_elements = 4; + num_block_group = 1; + byte_size = sizeof( float ); + + sprintf( f_name, "SBA_MD_values_dec_P.bin" ); + ( frame == 0 ) ? dbgwrite( &nbands, sizeof( nbands ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_group, sizeof( num_block_group ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + + for ( b = 0; b < nbands; b++ ) + { + for ( int16_t sf = 0; sf < num_subframes; sf++ ) + { + for ( int16_t bl = 0; bl < num_block_group; bl++ ) + { + dbgwrite( &hMdDec->spar_md.band_coeffs[b].P_re[0], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].P_re[1], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].P_re[2], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].P_re[3], byte_size, 1, 1, f_name ); + // fprintf(stdout, "%f\t%f\t%f\t%d\t%d\n", dirac_md_kbps, spar_md_kbps, sba_md_kbps, qsi, code_strat ); + } + } + }*/ +#endif /* SPAR to DirAC conversion */ - ivas_spar_to_dirac( st_ivas, hMdDec, dtx_vad, num_bands_out ); + ivas_spar_to_dirac( st_ivas, hMdDec, dtx_vad, num_bands_out +#ifdef LBR_SBA + , + bw +#endif + ); /* set correct number of bands*/ nB = IVAS_MAX_NUM_BANDS; @@ -681,7 +815,129 @@ void ivas_spar_md_dec_process( { nB = nB >> 1; } +#ifdef DEBUG_LBR_SBA + /* Dumping SPAR Coefficients */ + char f_name[100]; + int16_t nbands = 4; // 6 total, just looking at SPAR + int16_t num_subframes = 1; + int16_t num_elements = 6; + int16_t num_block_group = 1; + int16_t byte_size = sizeof( float ); + + sprintf( f_name, "SBA_MD_values_dec.bin" ); + ( frame == 0 ) ? dbgwrite( &nbands, sizeof( nbands ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_group, sizeof( num_block_group ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + + for ( b = 0; b < nbands; b++ ) + { + for ( int16_t sf = 0; sf < num_subframes; sf++ ) + { + for ( int16_t bl = 0; bl < num_block_group; bl++ ) + { + dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[0], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[1], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[2], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].P_re[0], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].P_re[1], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].P_re[2], byte_size, 1, 1, f_name ); + // fprintf(stdout, "%f\t%f\t%f\t%d\t%d\n", dirac_md_kbps, spar_md_kbps, sba_md_kbps, qsi, code_strat ); + } + } + } +#endif +#ifdef DEBUG_LBR_SBA + /* Dumping SPAR HOA Coefficients */ + /*char f_name[100]; + int16_t nbands = 12; + int16_t num_subframes = 1; + int16_t num_elements = 7; + int16_t num_block_group = 1; + int16_t byte_size = sizeof( float ); + + sprintf( f_name, "SBA_MD_values_dec_PR.bin" ); + ( frame == 0 ) ? dbgwrite( &nbands, sizeof( nbands ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_group, sizeof( num_block_group ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + + for ( b = 0; b < nbands; b++ ) + { + for ( int16_t sf = 0; sf < num_subframes; sf++ ) + { + for ( int16_t bl = 0; bl < num_block_group; bl++ ) + { + dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[0], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[1], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[2], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[3], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[4], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[5], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[6], byte_size, 1, 1, f_name ); + // fprintf(stdout, "%f\t%f\t%f\t%d\t%d\n", dirac_md_kbps, spar_md_kbps, sba_md_kbps, qsi, code_strat ); + } + } + } + nbands = 12; // 6 total, just looking at SPAR + num_subframes = 1; + num_elements = 12; + num_block_group = 1; + byte_size = sizeof( float ); + + sprintf( f_name, "SBA_MD_values_dec_C.bin" ); + ( frame == 0 ) ? dbgwrite( &nbands, sizeof( nbands ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_group, sizeof( num_block_group ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + + for ( b = 0; b < nbands; b++ ) + { + for ( int16_t sf = 0; sf < num_subframes; sf++ ) + { + for ( int16_t bl = 0; bl < num_block_group; bl++ ) + { + for ( int16_t p = 0; p < 4; p++ ) + { + for ( int16_t r = 0; r < 3; r++ ) + { + dbgwrite( &hMdDec->spar_md.band_coeffs[b].C_re[p][r], byte_size, 1, 1, f_name ); + } + } + } + } + } + nbands = 12; // 6 total, just looking at SPAR + num_subframes = 1; + num_elements = 4; + num_block_group = 1; + byte_size = sizeof( float ); + sprintf( f_name, "SBA_MD_values_dec_P.bin" ); + ( frame == 0 ) ? dbgwrite( &nbands, sizeof( nbands ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_group, sizeof( num_block_group ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + + for ( b = 0; b < nbands; b++ ) + { + for ( int16_t sf = 0; sf < num_subframes; sf++ ) + { + for ( int16_t bl = 0; bl < num_block_group; bl++ ) + { + dbgwrite( &hMdDec->spar_md.band_coeffs[b].P_re[0], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].P_re[1], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].P_re[2], byte_size, 1, 1, f_name ); + dbgwrite( &hMdDec->spar_md.band_coeffs[b].P_re[3], byte_size, 1, 1, f_name ); + // fprintf(stdout, "%f\t%f\t%f\t%d\t%d\n", dirac_md_kbps, spar_md_kbps, sba_md_kbps, qsi, code_strat ); + } + } + }*/ +#endif /* expand DirAC MD to all time slots */ for ( i_ts = 1; i_ts < MAX_PARAM_SPATIAL_SUBFRAMES; i_ts++ ) { @@ -707,7 +963,12 @@ void ivas_spar_md_dec_process( } } - ivas_get_spar_matrices( hMdDec, num_bands_out, MAX_PARAM_SPATIAL_SUBFRAMES, bw, dtx_vad, nB, sba_order ); + ivas_get_spar_matrices( hMdDec, num_bands_out, MAX_PARAM_SPATIAL_SUBFRAMES, bw, dtx_vad, nB, sba_order +#ifdef LBR_SBA + , + active_w_vlbr +#endif + ); #ifdef DEBUG_SPAR_DIRAC_WRITE_OUT_PRED_PARS { @@ -720,7 +981,12 @@ void ivas_spar_md_dec_process( fprintf( fid, "%.6f\n", hMdDec->mixer_mat[1][0][band] ); } #endif - +#ifdef LBR_SBA + if ( bw == IVAS_RED_BAND_FACT ) + { + nB = nB << 1; + } +#endif for ( b = nB; b < num_bands_out; b++ ) { hMdDec->valid_bands[b] = 1; @@ -952,7 +1218,12 @@ static void ivas_get_spar_matrices( const int16_t bw, const int16_t dtx_vad, const int16_t nB, - const int16_t sba_order ) + const int16_t sba_order +#ifdef LBR_SBA + , + const int16_t active_w_vlbr +#endif +) { int16_t numch_out, num_bands, dmx_ch, split_band; int16_t i, j, k, m, b, i_ts, active_w; @@ -994,10 +1265,18 @@ static void ivas_get_spar_matrices( } }*/ #endif - +#ifdef LBR_SBA + if ( bw == IVAS_RED_BAND_FACT ) + { + num_bands = num_bands >> 1; + } +#endif active_w = hMdDec->spar_md_cfg.active_w; +#ifdef LBR_SBA + active_w_dm_fac = ( dtx_vad == 0 ) ? IVAS_ACTIVEW_DM_F_SCALE_DTX : ( ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR : IVAS_ACTIVEW_DM_F_SCALE ); +#else active_w_dm_fac = ( dtx_vad == 0 ) ? IVAS_ACTIVEW_DM_F_SCALE_DTX : IVAS_ACTIVEW_DM_F_SCALE; - +#endif for ( i_ts = 0; i_ts < n_ts; i_ts++ ) { for ( i = 0; i < numch_out; i++ ) @@ -1008,12 +1287,12 @@ static void ivas_get_spar_matrices( set_zero( &hMdDec->spar_coeffs.P_re[i][j][i_ts * IVAS_MAX_NUM_BANDS], IVAS_MAX_NUM_BANDS ); } } - +#ifndef LBR_SBA if ( bw == IVAS_RED_BAND_FACT ) { num_bands = num_bands >> 1; } - +#endif num_bands = min( num_bands, nB ); for ( b = 0; b < num_bands; b++ ) @@ -1439,6 +1718,9 @@ static void ivas_spar_dec_parse_md_bs( int16_t do_diff[IVAS_MAX_NUM_BANDS]; int16_t planarCP; float quant[IVAS_SPAR_MAX_C_COEFF]; +#ifdef LBR_SBA + int16_t do_repeat[IVAS_MAX_NUM_BANDS]; +#endif *dtx_vad = 1; *bands_bw = 1; @@ -1561,6 +1843,9 @@ static void ivas_spar_dec_parse_md_bs( for ( i = 0; i < *nB; i++ ) { do_diff[i] = 0; +#ifdef LBR_SBA + do_repeat[i] = 0; +#endif } } else if ( strat < 4 ) @@ -1570,10 +1855,39 @@ static void ivas_spar_dec_parse_md_bs( for ( i = 0; i < *nB; i++ ) { do_diff[i] = 0; +#ifdef LBR_SBA + do_repeat[i] = 0; +#endif } no_ec = 1; } else +#ifdef LBR_SBA + if ( ivas_total_brate < IVAS_24k4 ) + { + *bands_bw = 2; + *nB = num_bands / *bands_bw; + + for ( i = 0; i < *nB; i++ ) + { + do_diff[i] = 0; + do_repeat[i] = ( ( strat % 2 ) == ( ( i + 1 ) % 2 ) ); + } + } + else + { + *bands_bw = 1; + *nB = num_bands; + + for ( i = 0; i < *nB; i++ ) + { + do_diff[i] = ( ( ( i + 1 ) & 3 ) != strat - 4 ); + do_repeat[i] = 0; + } + + ivas_map_prior_coeffs_quant( &hMdDec->spar_md_prev, &hMdDec->spar_md_cfg, qsi, *nB ); + } +#else { *bands_bw = 1; *nB = num_bands; @@ -1585,6 +1899,7 @@ static void ivas_spar_dec_parse_md_bs( ivas_map_prior_coeffs_quant( &hMdDec->spar_md_prev, &hMdDec->spar_md_cfg, qsi, *nB ); } +#endif #ifdef SPAR_HOA_DBG fprintf( stdout, "\n\n no_ec = %d, strat = %d\n", no_ec, strat ); #endif @@ -1592,11 +1907,21 @@ static void ivas_spar_dec_parse_md_bs( if ( no_ec == 0 ) { - ivas_decode_arith_bs( hMdDec, st0, qsi, *nB, *bands_bw, do_diff, freq_diff, planarCP ); + ivas_decode_arith_bs( hMdDec, st0, qsi, *nB, *bands_bw, do_diff, freq_diff, planarCP +#ifdef LBR_SBA + , + strat, ivas_total_brate +#endif + ); } else { - ivas_decode_huffman_bs( hMdDec, st0, qsi, *nB, *bands_bw, planarCP ); + ivas_decode_huffman_bs( hMdDec, st0, qsi, *nB, *bands_bw, planarCP +#ifdef LBR_SBA_PLANAR + , + ivas_total_brate +#endif + ); } for ( i = 0; i < *nB; i++ ) @@ -1643,9 +1968,16 @@ static void ivas_spar_dec_parse_md_bs( { hMdDec->spar_md_prev.band_coeffs_idx[i].decd_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].decd_index_re[j]; } +#ifdef LBR_SBA + hMdDec->valid_bands[*bands_bw * i] |= ( do_diff[i] == 0 && do_repeat[i] == 0 ) ? 1 : 0; + for ( j = 1; j < *bands_bw; j++ ) + { + hMdDec->valid_bands[*bands_bw * i + j] = hMdDec->valid_bands[*bands_bw * i]; + } +#else hMdDec->valid_bands[i] |= ( do_diff[i] == 0 ) ? 1 : 0; +#endif } - #ifdef SPAR_HOA_DBG int16_t b; b = 0; @@ -1736,7 +2068,13 @@ static void ivas_decode_arith_bs( const int16_t bands_bw, int16_t *pDo_diff, const int16_t freq_diff, - const int16_t planarCP ) + const int16_t planarCP +#ifdef LBR_SBA + , + const int16_t strat, + const int32_t ivas_total_brate +#endif +) { int16_t i, j, ndm, ndec; ivas_cell_dim_t pred_cell_dims[IVAS_MAX_NUM_BANDS]; @@ -1751,22 +2089,46 @@ static void ivas_decode_arith_bs( { ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[bands_bw * i]; ndec = hMdDec->spar_md_cfg.num_decorr_per_band[bands_bw * i]; - - pred_cell_dims[i].dim1 = ndm + ndec - 1; - if ( hMdDec->spar_hoa_md_flag ) +#ifdef LBR_SBA + if ( ( ivas_total_brate < IVAS_24k4 ) && ( strat > 3 ) && ( ( ( i % 2 == 1 ) && ( strat % 2 == 0 ) ) || ( ( i % 2 == 0 ) && ( strat % 2 == 1 ) ) ) ) + { + pred_cell_dims[i].dim1 = 0; + pred_cell_dims[i].dim2 = 0; + drct_cell_dims[i].dim1 = 0; + drct_cell_dims[i].dim2 = 0; + decd_cell_dims[i].dim1 = 0; + decd_cell_dims[i].dim2 = 0; + decx_cell_dims[i].dim1 = 0; + decx_cell_dims[i].dim2 = 0; + } + else { - if ( i >= SPAR_DIRAC_SPLIT_START_BAND ) +#endif + pred_cell_dims[i].dim1 = ndm + ndec - 1; + if ( hMdDec->spar_hoa_md_flag ) + { + if ( i >= SPAR_DIRAC_SPLIT_START_BAND ) + { + pred_cell_dims[i].dim1 -= ( FOA_CHANNELS - 1 ); + } + } + pred_cell_dims[i].dim2 = 1; + drct_cell_dims[i].dim1 = ndec; + drct_cell_dims[i].dim2 = ndm - 1; + decd_cell_dims[i].dim1 = ndec; + decd_cell_dims[i].dim2 = 1; + decx_cell_dims[i].dim1 = ( ndec * ( ndec - 1 ) ) >> 1; + decx_cell_dims[i].dim2 = 1; +#ifdef LBR_SBA_PLANAR + if ( ivas_total_brate < IVAS_24k4 ) { - pred_cell_dims[i].dim1 -= ( FOA_CHANNELS - 1 ); + pred_cell_dims[i].dim1 -= 1; + decd_cell_dims[i].dim1 -= 1; } +#endif +#ifdef LBR_SBA } - pred_cell_dims[i].dim2 = 1; - drct_cell_dims[i].dim1 = ndec; - drct_cell_dims[i].dim2 = ndm - 1; - decd_cell_dims[i].dim1 = ndec; - decd_cell_dims[i].dim2 = 1; - decx_cell_dims[i].dim1 = ( ndec * ( ndec - 1 ) ) >> 1; - decx_cell_dims[i].dim2 = 1; +#endif } any_diff = 0; @@ -1875,7 +2237,20 @@ static void ivas_decode_arith_bs( ivas_get_band_idx_from_differential( &hMdDec->spar_md, hMdDec->spar_md_cfg.quant_strat->P_r.q_levels, 1, nB, DECD_COEFF ); ivas_get_band_idx_from_differential( &hMdDec->spar_md, hMdDec->spar_md_cfg.quant_strat->P_c.q_levels, 0, nB, DECX_COEFF ); } - +#ifdef LBR_SBA_PLANAR + if ( ivas_total_brate < IVAS_24k4 ) + { + for ( i = 0; i < nB; i++ ) /* restore X PR index, force Z PR, P indices to be zero.*/ + { + if ( ( strat < 3 ) || ( ( strat > 3 ) && ( ( ( i % 2 == 0 ) && ( strat % 2 == 0 ) ) || ( ( i % 2 == 1 ) && ( strat % 2 == 1 ) ) ) ) ) + { + hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[2] = hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[1]; + hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[1] = 0; + } + hMdDec->spar_md.band_coeffs_idx[i].decd_index_re[2] = 0; /* shouldn't be needed */ + } + } +#endif return; } @@ -2054,7 +2429,12 @@ static void ivas_decode_huffman_bs( const uint16_t qsi, const int16_t nB, const int16_t bands_bw, - const int16_t planarCP ) + const int16_t planarCP +#ifdef LBR_SBA_PLANAR + , + const int32_t ivas_total_brate +#endif +) { int16_t i, j; int16_t ndm, ndec; @@ -2079,7 +2459,19 @@ static void ivas_decode_huffman_bs( for ( j = pred_offset; j < pred_dim; j++ ) { - ivas_huffman_decode( &hMdDec->huff_coeffs.pred_huff_re[qsi], st0, &hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j] ); +#ifdef LBR_SBA_PLANAR + if ( ( j == 1 ) && ( ivas_total_brate < IVAS_24k4 ) ) + { + hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j] = 0; + } + else + { +#endif + ivas_huffman_decode( &hMdDec->huff_coeffs.pred_huff_re[qsi], st0, + &hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j] ); +#ifdef LBR_SBA_PLANAR + } +#endif } if ( hMdDec->spar_hoa_md_flag ) @@ -2095,7 +2487,11 @@ static void ivas_decode_huffman_bs( for ( j = 0; j < drct_dim; j++ ) { +#ifdef LBR_SBA_PLANAR + if ( ( planarCP && !keep_planar[(int16_t) floor( j / ( ndm - 1 ) )] ) || ( ( j == 2 ) && ( ivas_total_brate < IVAS_24k4 ) ) ) +#else if ( planarCP && !keep_planar[(int16_t) floor( j / ( ndm - 1 ) )] ) +#endif { hMdDec->spar_md.band_coeffs_idx[i].drct_index_re[j] = 0; } @@ -2531,6 +2927,10 @@ void ivas_spar_to_dirac( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const int16_t dtx_vad, /* i : DTX frame flag */ const int16_t num_bands_out /* i : number of output bands */ +#ifdef LBR_SBA + , + const int16_t bw /* i : band joining factor */ +#endif ) { DIRAC_DEC_HANDLE hDirAC; @@ -2559,12 +2959,21 @@ void ivas_spar_to_dirac( sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); start_band = 0; +#ifdef LBR_SBA + end_band = min( num_bands_out, SPAR_DIRAC_SPLIT_START_BAND ) / bw; + + hDirAC = st_ivas->hDirAC; + dirac_to_spar_md_bands = st_ivas->hSpar->dirac_to_spar_md_bands; + enc_param_start_band = st_ivas->hSpar->enc_param_start_band / bw; + int16_t active_w_vlbr; + active_w_vlbr = ( st_ivas->hDecoderConfig->ivas_total_brate < IVAS_24k4 ) ? 1 : 0; +#else end_band = min( num_bands_out, SPAR_DIRAC_SPLIT_START_BAND ); hDirAC = st_ivas->hDirAC; dirac_to_spar_md_bands = st_ivas->hSpar->dirac_to_spar_md_bands; enc_param_start_band = st_ivas->hSpar->enc_param_start_band; - +#endif if ( hDirAC != NULL ) { band_grouping = hDirAC->band_grouping; @@ -2612,7 +3021,11 @@ void ivas_spar_to_dirac( } else { +#ifdef LBR_SBA + f_scale = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR : IVAS_ACTIVEW_DM_F_SCALE; +#else f_scale = IVAS_ACTIVEW_DM_F_SCALE; +#endif } } else @@ -2720,13 +3133,28 @@ void ivas_spar_to_dirac( } /*read DirAC metadata, convert DirAC to SPAR*/ +#ifdef LBR_SBA + for ( ; band < num_bands_out / bw; band++ ) +#else for ( ; band < num_bands_out; band++ ) +#endif { int16_t dirac_band_idx; dirac_band_idx = dirac_to_spar_md_bands[band] - enc_param_start_band; +#ifdef LBR_SBA + int16_t num_subframes; + num_subframes = MAX_PARAM_SPATIAL_SUBFRAMES; + if ( st_ivas->hQMetaData->useLowerRes ) + { + num_subframes = 1; + } + + for ( block = 0; block < num_subframes; block++ ) +#else for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) +#endif { if ( st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block] < 0.f ) { @@ -2742,7 +3170,12 @@ void ivas_spar_to_dirac( /* DirAC MD averaged over 4 subframes and converted to SPAR format similar to encoder processing */ if ( hMdDec->spar_md_cfg.nchan_transport > 1 ) { - ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, 1, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL ); + ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, 1, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL +#ifdef LBR_SBA + , + st_ivas->hQMetaData->useLowerRes, active_w_vlbr +#endif + ); /* temporarily copy frame-wise prediction coefficients in DirAC bands*/ for ( pred_idx = 0; pred_idx < FOA_CHANNELS - 1; pred_idx++ ) @@ -2753,9 +3186,36 @@ void ivas_spar_to_dirac( } } } +#ifdef LBR_SBA + int16_t num_subframes; + num_subframes = MAX_PARAM_SPATIAL_SUBFRAMES; + if ( st_ivas->hQMetaData->useLowerRes ) + { + num_subframes = 1; + } + ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, num_subframes, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, + end_band, num_bands_out / bw, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr ); + if ( st_ivas->hQMetaData->useLowerRes && dtx_vad ) + { + for ( band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++ ) + { + for ( block = 1; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + { + for ( int16_t i = 0; i < FOA_CHANNELS - 1; i++ ) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ + { + hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re[i] = hMdDec->spar_md.band_coeffs[band].pred_re[i]; + } + for ( int16_t i = 0; i < FOA_CHANNELS - 1; i++ ) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ + { + hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].P_re[i] = hMdDec->spar_md.band_coeffs[band].P_re[i]; + } + } + } + } +#else ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, MAX_PARAM_SPATIAL_SUBFRAMES, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL ); - +#endif /* expand DirAC TC 20ms MD for residual channels to all subframes*/ for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { @@ -2772,7 +3232,11 @@ void ivas_spar_to_dirac( } } +#ifdef LBR_SBA + for ( b = end_band * bw; b < num_bands_out; b++ ) +#else for ( b = end_band; b < num_bands_out; b++ ) +#endif { hMdDec->valid_bands[b] = 1; } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index e474e0fd1f7de23180d4f0724b47c16ece603ded..fbaedb04534654f2061cd86be1a422f3272fc909 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -574,7 +574,6 @@ typedef struct dirac_output_synthesis_cov_state_structure } DIRAC_OUTPUT_SYNTHESIS_COV_STATE; - /* MASA stereo transport signal type detection structure */ typedef struct { @@ -813,6 +812,11 @@ typedef struct ivas_spar_md_dec_state_t int16_t table_idx; int16_t dtx_vad; int16_t spar_hoa_md_flag; +#ifdef LBR_ADAP_SMOOTHING + float smooth_buf[IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS][2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1]; + float smooth_fac[IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + float mixer_mat_prev2[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; +#endif } ivas_spar_md_dec_state_t; diff --git a/lib_dec/ivas_stereo_mdct_stereo_dec.c b/lib_dec/ivas_stereo_mdct_stereo_dec.c index cccef8ec84b5553b7761be21f3f2ee9f3ccd9c41..0e788a0821103ce0b6b3e1c8a3891fb9579e3f29 100644 --- a/lib_dec/ivas_stereo_mdct_stereo_dec.c +++ b/lib_dec/ivas_stereo_mdct_stereo_dec.c @@ -468,11 +468,22 @@ ivas_error initMdctStereoDtxData( /* Init FD-CNG */ initFdCngDec( st ); +#ifndef FIX_413_SBA_DTX + if ( ch == 1 && st->cng_sba_flag ) + { + st->hFdCngDec->hFdCngCom->seed += 3; + } +#endif + } +#ifdef FIX_413_SBA_DTX + if ( st->first_CNG == 0 ) + { if ( ch == 1 && st->cng_sba_flag ) { st->hFdCngDec->hFdCngCom->seed += 3; } } +#endif if ( st->cldfbAna == NULL ) { diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 43bc94fb04c06e30858d5419907091bac7b4872a..f48044d1c78fab00d4953f00a6c267d6d18141e5 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -488,7 +488,11 @@ void ivas_dirac_enc_spar_delay_synchro( int16_t sce_id, cpe_id, i_chan; /* check last sba_mode */ +#ifndef LBR_SBA if ( ivas_sba_mode_select( st_ivas->hEncoderConfig->last_ivas_total_brate ) == SBA_MODE_SPAR ) +#else + if ( ivas_sba_mode_select() == SBA_MODE_SPAR ) +#endif { /* initializations */ i_chan = 0; diff --git a/lib_enc/ivas_enc_cov_handler.c b/lib_enc/ivas_enc_cov_handler.c index e117cfc5a55ba7e737c495d437a8c1fe282c91d9..a94436ae34c3f30c5062b38327027d6e1f0f57a0 100644 --- a/lib_enc/ivas_enc_cov_handler.c +++ b/lib_enc/ivas_enc_cov_handler.c @@ -66,6 +66,10 @@ ivas_error ivas_spar_covar_enc_open( ivas_filterbank_t *pFb, /* i/o: FB handle */ const int32_t input_Fs, /* i : input sampling rate */ const int16_t nchan_inp /* i : number of input channels */ +#ifdef LBR_SBA_EXTRA_COV_SMOOTH + , + const int32_t ivas_total_brate /* i : IVAS total bitrate */ +#endif ) { ivas_enc_cov_handler_state_t *hCovState; @@ -83,7 +87,11 @@ ivas_error ivas_spar_covar_enc_open( cov_smooth_cfg.max_update_rate = MAX_UPDATE_RATE; cov_smooth_cfg.min_pool_size = MIN_POOL_SIZE; +#ifdef LBR_SBA_EXTRA_COV_SMOOTH + if ( ( error = ivas_spar_covar_smooth_enc_open( &hCovState->pCov_state, &cov_smooth_cfg, pFb, nchan_inp, ivas_total_brate ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_spar_covar_smooth_enc_open( &hCovState->pCov_state, &cov_smooth_cfg, pFb, nchan_inp ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -91,7 +99,11 @@ ivas_error ivas_spar_covar_enc_open( cov_smooth_cfg.max_update_rate = MAX_UPDATE_RATE_DTX; cov_smooth_cfg.min_pool_size = MIN_POOL_SIZE_DTX; +#ifdef LBR_SBA_EXTRA_COV_SMOOTH + if ( ( error = ivas_spar_covar_smooth_enc_open( &hCovState->pCov_dtx_state, &cov_smooth_cfg, pFb, nchan_inp, ivas_total_brate ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_spar_covar_smooth_enc_open( &hCovState->pCov_dtx_state, &cov_smooth_cfg, pFb, nchan_inp ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index f2b30df804d477854b76bba065b73bc5a7803d36..c2c348f19c6a8ce80bee35e808103bae99fbb2a2 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -377,7 +377,9 @@ ivas_error ivas_init_encoder( /* In IVAS, ensure that minimum coded bandwidth is WB */ hEncoderConfig->max_bwidth = max( hEncoderConfig->max_bwidth, WB ); } - +#ifdef LBR_SBA_BR_SWITCHING + hEncoderConfig->spar_reconfig_flag = 0; +#endif st_ivas->ism_mode = ISM_MODE_NONE; st_ivas->mc_mode = MC_MODE_NONE; st_ivas->sba_mode = SBA_MODE_NONE; @@ -486,8 +488,11 @@ ivas_error ivas_init_encoder( if ( ivas_format == SBA_FORMAT ) { +#ifndef LBR_SBA st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); - +#else + st_ivas->sba_mode = ivas_sba_mode_select(); +#endif st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); if ( st_ivas->sba_mode == SBA_MODE_SPAR ) diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 24924a25bb2229713d962224dc89e57c2830767c..b4c5f01dcb9877d812f9e4d68f22a40fc2aaa323 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -56,6 +56,11 @@ #define ISM_MAX_RADIUS_DIFF_IDX ( ISM_RADIUS_NBITS - 1 /*zero*/ - 1 /*sign*/ ) #define ISM_FEC_MAX 10 +#ifdef FIX_387_ISM_MD_FEC +#define ISM_MD_FEC_DIFF 10 +#define ISM_MD_INC_DIFF_CNT_MAX 6 +#define ISM_MD_FEC_CNT_MAX 25 +#endif #define INTER_OBJECT_PARAM_CHECK ( ( ISM_FEC_MAX / 2 ) - 2 ) /* note: constant must be less than (ISM_FEC_MAX / number of coded parameters) */ @@ -203,7 +208,6 @@ ivas_error ivas_ism_metadata_enc( push_wmops( "ism_meta_enc" ); - /* initialization */ ism_metadata_flag_global = 0; set_s( nb_bits_metadata, 0, nchan_transport ); @@ -242,8 +246,39 @@ ivas_error ivas_ism_metadata_enc( #endif { hIsmMeta[ch]->ism_metadata_flag = localVAD[ch] || hSCE[ch]->hCoreCoder[0]->lp_noise > 10; + +#ifdef FIX_387_ISM_MD_FEC + /* in inactive frames, send MD 1) in ISM_MD_INC_DIFF_CNT_MAX consecutive frames when MD significantly change, 2) at least every ISM_MD_FEC_DIFF frames */ + if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) + { + if ( ( fabsf( hIsmMeta[ch]->azimuth - hIsmMeta[ch]->last_true_azimuth ) > ISM_MD_FEC_DIFF ) || + ( fabsf( hIsmMeta[ch]->elevation - hIsmMeta[ch]->last_true_elevation ) > ISM_MD_FEC_DIFF ) ) + { + hIsmMeta[ch]->ism_metadata_flag = 1; + hIsmMeta[ch]->ism_md_inc_diff_cnt = 0; + } + else if ( hIsmMeta[ch]->ism_md_inc_diff_cnt < ISM_MD_INC_DIFF_CNT_MAX ) + { + hIsmMeta[ch]->ism_metadata_flag = 1; + + if ( hIsmMeta[ch]->ism_md_inc_diff_cnt % 2 == 0 ) + { + hIsmMeta[ch]->position_angle.angle1_diff_cnt = ISM_FEC_MAX; + } + else + { + hIsmMeta[ch]->position_angle.angle2_diff_cnt = ISM_FEC_MAX; + } + } + else if ( hIsmMeta[ch]->ism_md_fec_cnt_enc == ISM_MD_FEC_CNT_MAX ) + { + hIsmMeta[ch]->ism_metadata_flag = 1; + hIsmMeta[ch]->position_angle.angle1_diff_cnt = ISM_FEC_MAX; + } } +#endif } + } /*----------------------------------------------------------------* * Rate importance of particular ISM streams @@ -386,7 +421,9 @@ ivas_error ivas_ism_metadata_enc( idx_angle1_abs = hParamIsm->azi_index[ch]; idx_angle2_abs = hParamIsm->ele_index[ch]; } + encode_angle_indices( hBstr, &( hIsmMetaData->position_angle ), hIsmMetaData->last_ism_metadata_flag, hSCE[0]->hCoreCoder[0]->ini_frame, idx_angle1_abs, idx_angle2_abs, &flag_abs_azimuth[ch], &flag_abs_elevation[ch] ); + /*----------------------------------------------------------------* * Quantize and encode radius, yaw, and pitch *----------------------------------------------------------------*/ @@ -396,6 +433,7 @@ ivas_error ivas_ism_metadata_enc( idx_angle1_abs = ism_quant_meta( hIsmMetaData->yaw, &valQ, ism_azimuth_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_AZIMUTH_NBITS ); idx_angle2_abs = ism_quant_meta( hIsmMetaData->pitch, &valQ, ism_elevation_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_ELEVATION_NBITS ); idx_radius_abs = usquant( hIsmMetaData->radius, &valQ, ISM_RADIUS_MIN, ISM_RADIUS_DELTA, 1 << ISM_RADIUS_NBITS ); + encode_angle_indices( hBstr, &( hIsmMetaData->orientation_angle ), hIsmMetaData->last_ism_metadata_flag, hSCE[0]->hCoreCoder[0]->ini_frame, idx_angle1_abs, idx_angle2_abs, &flag_abs_yaw[ch], &flag_abs_pitch[ch] ); encode_radius( hBstr, &hIsmMetaData->last_radius_idx, &hIsmMetaData->radius_diff_cnt, hIsmMetaData->last_ism_metadata_flag, idx_radius_abs, &flag_abs_radius[ch] ); } @@ -409,6 +447,12 @@ ivas_error ivas_ism_metadata_enc( { nb_bits_metadata[ch] = hBstr->nb_bits_tot - nb_bits_start; } + +#ifdef FIX_387_ISM_MD_FEC + /* Updates */ + hIsmMeta[ch]->last_true_azimuth = hIsmMeta[ch]->azimuth; + hIsmMeta[ch]->last_true_elevation = hIsmMeta[ch]->elevation; +#endif } } @@ -589,6 +633,19 @@ ivas_error ivas_ism_metadata_enc( for ( ch = 0; ch < nchan_ism; ch++ ) { hIsmMeta[ch]->last_ism_metadata_flag = hIsmMeta[ch]->ism_metadata_flag; + +#ifdef FIX_387_ISM_MD_FEC + if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) + { + hIsmMeta[ch]->ism_md_fec_cnt_enc++; + } + else + { + hIsmMeta[ch]->ism_md_fec_cnt_enc = 0; + } + hIsmMeta[ch]->ism_md_inc_diff_cnt++; + hIsmMeta[ch]->ism_md_inc_diff_cnt = min( hIsmMeta[ch]->ism_md_inc_diff_cnt, ISM_MD_INC_DIFF_CNT_MAX ); +#endif } #ifdef MASA_AND_OBJECTS @@ -740,6 +797,13 @@ ivas_error ivas_ism_metadata_enc_create( st_ivas->hIsmMetaData[ch]->last_azimuth = 0.0f; st_ivas->hIsmMetaData[ch]->last_elevation = 0.0f; + +#ifdef FIX_387_ISM_MD_FEC + st_ivas->hIsmMetaData[ch]->last_true_azimuth = 0.0f; + st_ivas->hIsmMetaData[ch]->last_true_elevation = 0.0f; + st_ivas->hIsmMetaData[ch]->ism_md_fec_cnt_enc = 0; + st_ivas->hIsmMetaData[ch]->ism_md_inc_diff_cnt = ISM_MD_INC_DIFF_CNT_MAX; +#endif } #ifdef MASA_AND_OBJECTS @@ -1254,6 +1318,11 @@ void ivas_ism_metadata_sid_enc( hIsmMetaData->position_angle.last_angle1_idx = idx_azimuth << ( ISM_AZIMUTH_NBITS - nBits_azimuth ); hIsmMetaData->position_angle.last_angle2_idx = idx_elevation << ( ISM_ELEVATION_NBITS - nBits_elevation ); } + +#ifdef FIX_387_ISM_MD_FEC + hIsmMetaData->ism_md_fec_cnt_enc = 0; + hIsmMeta[ch]->ism_md_inc_diff_cnt = ISM_MD_INC_DIFF_CNT_MAX; +#endif } } diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 8c6cd7038c329f41d4cec20ff34e29743d3761d6..fc479d3f0b5cd49a8ab940231a653648d33caf8a 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -245,7 +245,7 @@ ivas_error ivas_omasa_enc_config( } /* reconfigure core-coders for ISMs */ - if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, 1, 2, sep_object_brate[k - 2][st_ivas->nSCE - 1], ivas_total_brate - ism_total_brate, MC_MODE_NONE ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, 1, 2, st_ivas->nSCE > 0 ? sep_object_brate[k - 2][st_ivas->nSCE - 1] : 0, ivas_total_brate - ism_total_brate, MC_MODE_NONE ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index d3aab0a6e88b631f34c515061a8d9050da7d3345..1766351c959347389c32c52b6c0871571cf73bf7 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -119,7 +119,9 @@ ivas_error ivas_sba_enc_reconfigure( { DIRAC_ENC_HANDLE hDirAC = st_ivas->hDirAC; SPAR_ENC_HANDLE hSpar; +#ifndef LBR_SBA_BR_SWITCHING SBA_MODE sba_mode_old; +#endif int16_t analysis_order_old; int16_t spar_reconfig_flag; @@ -127,11 +129,17 @@ ivas_error ivas_sba_enc_reconfigure( nchan_transport_old = st_ivas->nchan_transport; nCPE_old = st_ivas->nCPE; nSCE_old = st_ivas->nSCE; +#ifndef LBR_SBA_BR_SWITCHING sba_mode_old = st_ivas->sba_mode; - +#endif st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, hEncoderConfig->sba_order ); +#ifndef LBR_SBA_BR_SWITCHING +#ifndef LBR_SBA st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); - +#else + st_ivas->sba_mode = ivas_sba_mode_select(); +#endif +#endif analysis_order_old = ivas_sba_get_analysis_order( hEncoderConfig->last_ivas_total_brate, hEncoderConfig->sba_order ); if ( analysis_order_old != st_ivas->sba_analysis_order ) @@ -199,7 +207,7 @@ ivas_error ivas_sba_enc_reconfigure( old_mem_hp20_in = NULL; } } - +#ifndef LBR_SBA_BR_SWITCHING if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { if ( st_ivas->hSpar == NULL ) @@ -209,7 +217,7 @@ ivas_error ivas_sba_enc_reconfigure( return error; } } - +#endif ivas_spar_config( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); @@ -222,12 +230,13 @@ ivas_error ivas_sba_enc_reconfigure( } } hDirAC->num_samples_synchro_delay = 0; +#ifndef LBR_SBA_BR_SWITCHING } else { ivas_spar_enc_close( &( st_ivas->hSpar ), hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); } - +#endif hSpar = st_ivas->hSpar; if ( st_ivas->nchan_transport == 1 ) @@ -238,20 +247,26 @@ ivas_error ivas_sba_enc_reconfigure( { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } - +#ifndef LBR_SBA_BR_SWITCHING if ( ( sba_mode_old != st_ivas->sba_mode ) || ( nchan_transport_old != st_ivas->nchan_transport ) ) +#else + if ( nchan_transport_old != st_ivas->nchan_transport ) +#endif { /* FB mixer handle */ +#ifndef LBR_SBA_BR_SWITCHING if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { +#endif if ( hDirAC->hFbMixer != NULL ) { ivas_FB_mixer_close( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs, 0 ); hDirAC->hFbMixer = NULL; } - +#ifndef LBR_SBA_BR_SWITCHING if ( sba_mode_old == SBA_MODE_SPAR ) { +#endif spar_reconfig_flag = 1; ivas_spar_enc_close( &( st_ivas->hSpar ), hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); @@ -259,6 +274,7 @@ ivas_error ivas_sba_enc_reconfigure( { return error; } +#ifndef LBR_SBA_BR_SWITCHING } } else @@ -297,19 +313,24 @@ ivas_error ivas_sba_enc_reconfigure( } } } +#endif } - +#ifdef LBR_SBA_BR_SWITCHING + hEncoderConfig->spar_reconfig_flag = spar_reconfig_flag; +#endif if ( ( error = ivas_dirac_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - +#ifndef LBR_SBA_BR_SWITCHING if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { +#endif mvs2s( hDirAC->dirac_to_spar_md_bands, hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); hSpar->enc_param_start_band = hDirAC->hConfig->enc_param_start_band; +#ifndef LBR_SBA_BR_SWITCHING } - +#endif /*-----------------------------------------------------------------* * Allocate, initialize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index c659979d2b7be0b589bd697fe91870134f9bd355..ad7db2ae6afba597c651bc5f80c36beec6c226b6 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -113,7 +113,11 @@ ivas_error ivas_spar_enc_open( } /* Covariance handle */ +#ifdef LBR_SBA_EXTRA_COV_SMOOTH + if ( ( error = ivas_spar_covar_enc_open( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, input_Fs, nchan_inp, hEncoderConfig->ivas_total_brate ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_spar_covar_enc_open( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, input_Fs, nchan_inp ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -319,7 +323,11 @@ ivas_error ivas_spar_enc( // VE2DB: can hFbMixer->ppFilterbank_prior_input be replaced by st->input ? /* check last sba_mode */ +#ifndef LBR_SBA if ( ivas_sba_mode_select( st_ivas->hEncoderConfig->last_ivas_total_brate ) == SBA_MODE_DIRAC ) +#else + if ( ivas_sba_mode_select() == SBA_MODE_DIRAC ) +#endif { Encoder_State *sts[MCT_MAX_BLOCKS]; @@ -425,7 +433,10 @@ static ivas_error ivas_spar_enc_process( sba_order = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); nchan_inp = ivas_sba_get_nchan_metadata( sba_order ); assert( nchan_inp <= hEncoderConfig->nchan_inp ); - +#ifdef LBR_SBA + int16_t active_w_vlbr; + active_w_vlbr = ( hEncoderConfig->ivas_total_brate < IVAS_24k4 ) ? 1 : 0; +#endif for ( i = FOA_CHANNELS + 1; i < nchan_inp; i++ ) { mvr2r( data_f[HOA_keep_ind[i]], data_f[i], input_frame ); @@ -440,7 +451,12 @@ static ivas_error ivas_spar_enc_process( { transient_det[1] = transient_det[0]; } - +#ifdef LBR_SBA_EXTRA_COV_SMOOTH + if ( ivas_total_brate < IVAS_24k4 ) + { + transient_det[1] = 0; + } +#endif /* store previous input samples for W in local buffer */ assert( num_del_samples <= IVAS_FB_1MS_48K_SAMP ); mvr2r( &hSpar->hFbMixer->ppFilterbank_prior_input[0][hSpar->hFbMixer->fb_cfg->prior_input_length - num_del_samples], w_del_buf, num_del_samples ); @@ -504,6 +520,17 @@ static ivas_error ivas_spar_enc_process( { /* WB 4TC mode bit : disable for now*/ push_next_indice( hMetaData, 0, 1 ); +#ifdef LBR_SBA_PLANAR + /* force planar for LBR SPAR+DirAC, then encode parameters */ + if ( hQMetaData->useLowerRes ) + { + for ( i = hQMetaData->q_direction[0].cfg.start_band; i < hQMetaData->q_direction[0].cfg.nbands; i++ ) + { + /* Make sure elevation is really zero */ + set_zero( hQMetaData->q_direction[0].band_data[i].elevation, hQMetaData->q_direction[0].cfg.nblocks ); + } + } +#endif ivas_qmetadata_enc_encode( hMetaData, hQMetaData ); } else @@ -586,7 +613,11 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->table_idx != table_idx ) { hSpar->hMdEnc->table_idx = table_idx; +#ifdef LBR_SBA_BR_SWITCHING + if ( ( ivas_total_brate != hEncoderConfig->last_ivas_total_brate ) && ( !hEncoderConfig->spar_reconfig_flag ) ) +#else if ( ivas_total_brate != hEncoderConfig->last_ivas_total_brate ) +#endif { if ( ( error = ivas_spar_md_enc_init( hSpar->hMdEnc, hEncoderConfig, sba_order ) ) != IVAS_ERR_OK ) { @@ -620,7 +651,12 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) { - ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order ); + ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order +#ifdef LBR_SBA + , + hSpar->hFbMixer->prior_mixer +#endif + ); } { @@ -662,14 +698,88 @@ static ivas_error ivas_spar_enc_process( Wscale_d[b] = min( 2.0f, max( Wscale_d[b], 1.0f ) ); } - ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, 1, hSpar->hMdEnc->mixer_mat, &hSpar->hMdEnc->spar_md, &hSpar->hMdEnc->spar_md_cfg, d_start_band, d_end_band, ( hSpar->hMdEnc->spar_hoa_md_flag ) ? 1 : sba_order, dtx_vad, Wscale_d ); + ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, 1, hSpar->hMdEnc->mixer_mat, &hSpar->hMdEnc->spar_md, &hSpar->hMdEnc->spar_md_cfg, d_start_band, d_end_band, ( hSpar->hMdEnc->spar_hoa_md_flag ) ? 1 : sba_order, dtx_vad, Wscale_d +#ifdef LBR_SBA + , + hQMetaData->useLowerRes, active_w_vlbr +#endif + ); } if ( hSpar->hMdEnc->spar_hoa_md_flag ) { - ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order ); + ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order +#ifdef LBR_SBA + , + hSpar->hFbMixer->prior_mixer +#endif + ); } +#ifdef DEBUG_LBR_SBA + /* Dumping SPAR Coefficients */ + char f_name[100]; + int16_t nbands = 6; + int16_t num_subframes = 1; + int16_t num_elements = 6; + int16_t num_block_group = 1; + int16_t byte_size = sizeof( float ); + sprintf( f_name, "SBA_MD_values.bin" ); + ( frame == 0 ) ? dbgwrite( &nbands, sizeof( nbands ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_group, sizeof( num_block_group ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + + for ( b = 0; b < nbands; b++ ) + { + for ( int16_t sf = 0; sf < num_subframes; sf++ ) + { + for ( int16_t bl = 0; bl < num_block_group; bl++ ) + { + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[0], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[1], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[2], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[0], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[1], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[2], byte_size, 1, 1, f_name ); + // fprintf(stdout, "%f\t%f\t%f\t%d\t%d\n", dirac_md_kbps, spar_md_kbps, sba_md_kbps, qsi, code_strat ); + } + } + } +#endif +#ifdef DEBUG_LBR_SBA + /* Dumping SPAR Coefficients */ + nbands = 6; + num_subframes = 1; + num_elements = 6; + num_block_group = 1; + byte_size = sizeof( float ); + + sprintf( f_name, "SBA_MD_values_quant.bin" ); + ( frame == 0 ) ? dbgwrite( &nbands, sizeof( nbands ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_group, sizeof( num_block_group ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + + for ( b = 0; b < nbands; b++ ) + { + for ( int16_t sf = 0; sf < num_subframes; sf++ ) + { + for ( int16_t bl = 0; bl < num_block_group; bl++ ) + { + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_quant_re[0], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_quant_re[1], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_quant_re[2], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_quant_re[0], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_quant_re[1], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_quant_re[2], byte_size, 1, 1, f_name ); + // fprintf(stdout, "%f\t%f\t%f\t%d\t%d\n", dirac_md_kbps, spar_md_kbps, sba_md_kbps, qsi, code_strat ); + } + } + } +#endif /*-----------------------------------------------------------------------------------------* * FB mixer *-----------------------------------------------------------------------------------------*/ @@ -742,7 +852,16 @@ static ivas_error ivas_spar_enc_process( push_next_indice( hMetaData, PCA_MODE_INACTIVE, 1 ); } } - +#ifdef DEBUG_LBR_SBA + for ( int t = 0; t < 960; t++ ) + { + for ( int c = 0; c < hSpar->hFbMixer->fb_cfg->num_out_chans; c++ ) + { + float val = p_pcm_tmp[c][t]; // / MAX16B_FLT; + dbgwrite( &val, sizeof( float ), 1, 1, "int_enc_dmx.raw" ); + } + } +#endif #ifdef DEBUG_SBA_AUDIO_DUMP ivas_spar_dump_signal_wav( input_frame, p_pcm_tmp, NULL, nchan_transport, spar_foa_enc_wav[0], "ivas_pca_enc()" ); #endif diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 645f690ac0f8561aaccc1ea1fc050f03616d7aa7..b76a831feae201e21887b598eb74af9a865cbb7f 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -72,15 +72,32 @@ static void ivas_band_mixer( float *cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], static void ivas_get_band_differential_index( ivas_band_coeffs_ind_t *pBand_idx, const int16_t q_levels[2], const int16_t one_sided, const int16_t nB, const int16_t complex_cov, const int16_t dim, const ivas_coeffs_type_t coeff_type ); -static void ivas_get_huffman_coded_bs( ivas_spar_md_enc_state_t *hMdEnc, BSTR_ENC_HANDLE hMetaData, const int16_t nB, const int16_t qsi, const int16_t planarCP ); +static void ivas_get_huffman_coded_bs( ivas_spar_md_enc_state_t *hMdEnc, BSTR_ENC_HANDLE hMetaData, const int16_t nB, const int16_t qsi, const int16_t planarCP +#ifdef LBR_SBA + , + const int16_t bands_bw +#endif +); -static void ivas_get_arith_coded_bs( ivas_spar_md_enc_state_t *hMdEnc, BSTR_ENC_HANDLE hMetaData, const int16_t *pDo_diff, const int16_t bands_bw, const int16_t nB, const int16_t qsi, const int16_t planarCP ); +static void ivas_get_arith_coded_bs( ivas_spar_md_enc_state_t *hMdEnc, BSTR_ENC_HANDLE hMetaData, const int16_t *pDo_diff, const int16_t bands_bw, const int16_t nB, const int16_t qsi, const int16_t planarCP +#ifdef LBR_SBA + , + const int16_t strat, + const int32_t ivas_total_brate +#endif +); static ivas_error ivas_spar_set_enc_config( ivas_spar_md_enc_state_t *hMdEnc, int16_t *max_freq_per_chan, const int16_t nchan_transport, float *pFC, const int16_t nchan_inp ); static void ivas_select_next_strat( ivas_strats_t prior_strat, ivas_strats_t cs[MAX_QUANT_STRATS], const int16_t dmx_switch, const int16_t dtx_vad ); -static void ivas_store_prior_coeffs( ivas_spar_md_enc_state_t *hMdEnc, const int16_t num_bands, const int16_t bands_bw, const int16_t strat, const int16_t dtx_vad, const int16_t qsi ); +static void ivas_store_prior_coeffs( ivas_spar_md_enc_state_t *hMdEnc, const int16_t num_bands, +#ifndef LBR_SBA + const int16_t bands_bw, +#endif + const int16_t strat, + const int16_t dtx_vad, + const int16_t qsi ); static void ivas_write_spar_md_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 strat, const int16_t qsi, const int16_t planarCP ); static void ivas_spar_quant_pred_coeffs_dtx( ivas_spar_md_t *pSpar_md, const float *pValues, const int16_t ndm, int16_t *pIndex, const int16_t dim1, float *pQuant ); @@ -544,6 +561,10 @@ ivas_error ivas_spar_md_enc_process( const int16_t dtx_vad, const int16_t nchan_inp, const int16_t sba_order /* i : Ambisonic (SBA) order */ +#ifdef LBR_SBA + , + float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i : prior mixer_matrix */ +#endif ) { float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; @@ -568,7 +589,10 @@ ivas_error ivas_spar_md_enc_process( bwidth = ivas_get_bw_idx_from_sample_rate( hEncoderConfig->input_Fs ); bwidth = min( bwidth, hEncoderConfig->max_bwidth ); - +#ifdef LBR_SBA + int16_t active_w_vlbr; + active_w_vlbr = ( hEncoderConfig->ivas_total_brate < IVAS_24k4 ) ? 1 : 0; +#endif num_bands = ivas_get_num_bands_from_bw_idx( SPAR_CONFIG_BW ); if ( hMdEnc->spar_hoa_md_flag == 0 ) { @@ -621,6 +645,15 @@ ivas_error ivas_spar_md_enc_process( ivas_band_mixer( cov_real, num_ch, &num_bands, bands_bw ); } +#ifdef LBR_SBA + else if ( hEncoderConfig->ivas_total_brate < IVAS_24k4 ) + { + bands_bw = 2; + nB = num_bands / bands_bw; + + ivas_band_mixer( cov_real, num_ch, &num_bands, bands_bw ); + } +#endif else { nB = num_bands; @@ -639,7 +672,11 @@ ivas_error ivas_spar_md_enc_process( } ivas_compute_spar_params( cov_real, dm_fv_re, 0, hMdEnc->mixer_mat, 0, nB, dtx_vad, num_ch, - bands_bw, active_w, &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale, 0 ); + bands_bw, active_w, +#ifdef LBR_SBA + active_w_vlbr, +#endif + &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale, 0 ); for ( i = 0; i < num_ch; i++ ) { @@ -651,7 +688,9 @@ ivas_error ivas_spar_md_enc_process( } } } - +#ifdef DEBUG_LBR_SBA + float dirac_md_kbps = (float) ( hMetaData->nb_bits_tot ) * 50 / 1000; +#endif planarCP = 0; code_strat = 0; #ifdef DEBUG_SBA_MD_DUMP @@ -736,16 +775,77 @@ ivas_error ivas_spar_md_enc_process( fprintf(stderr, "\n\n"); */ #endif } - +#ifdef LBR_SBA_PLANAR + if ( active_w_vlbr ) /* SPAR PLANAR */ + { + pState->spar_md.band_coeffs[b].P_re[2] = 0.0f; + } +#endif ivas_quant_p_per_band( &hMdEnc->spar_md.band_coeffs[b], &hMdEnc->spar_md.band_coeffs_idx[b], &hMdEnc->spar_md_cfg.quant_strat[qsi], num_ch ); } - +#ifdef LBR_SBA_PLANAR + if ( active_w_vlbr ) /* SPAR PLANAR */ + { + pState->spar_md.band_coeffs[b].pred_re[1] = 0.0f; + } +#endif ivas_quant_pred_coeffs_per_band( &hMdEnc->spar_md.band_coeffs[b], &hMdEnc->spar_md.band_coeffs_idx[b], &hMdEnc->spar_md_cfg.quant_strat[qsi], num_ch ); +#ifdef LBR_SBA + if ( active_w_vlbr ) + { + for ( i = 0; i < 3; i++ ) + { +#ifdef LBR_SBA_PLANAR + if ( i == 1 ) /* Z prediction coefficients */ + { + continue; + } +#endif + int16_t i2; + i2 = 0; + switch ( i ) /* PRED (Y,Z,X) and DECD (Y,X,Z) coeffs are in different orders */ + { + case 0: + i2 = 0; + break; + case 1: + i2 = 2; + break; + case 2: + i2 = 1; + break; + } + if ( ( hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re[i] == 0 ) && ( hMdEnc->spar_md.band_coeffs_idx[b].decd_index_re[i2] == 0 ) && ( hMdEnc->spar_md.band_coeffs[b].pred_re[i] != 0.0f ) && ( cov_real[i + 1][i + 1][b] != 0.0f ) ) + { + /* bump up the Pred coeff */ + float PR_uq, PR_step; + ivas_quant_strat_t qs; + qs = hMdEnc->spar_md_cfg.quant_strat[qsi]; + PR_uq = hMdEnc->spar_md.band_coeffs[b].pred_re[i]; + PR_step = ( qs.PR.max - qs.PR.min ) / ( qs.PR.q_levels[0] - 1 ); + + int16_t PR_sign; + PR_sign = ( PR_uq > 0 ) - ( PR_uq < 0 ); + + hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re[i] = PR_sign; + + /* deindex the modified coefficient */ + hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i] = PR_sign * PR_step; + } + } + } +#endif } else { if ( ndm != num_ch ) { +#ifdef LBR_SBA_PLANAR + if ( active_w_vlbr ) /* SPAR PLANAR */ + { + hMdEnc->spar_md.band_coeffs[b].P_re[2] = 0.0f; + } +#endif ivas_quant_p_per_band_dtx( hMdEnc->spar_md.band_coeffs[b].P_re, ndec, ndm, &hMdEnc->spar_md.band_coeffs_idx[b].decd_index_re[0], hMdEnc->spar_md.band_coeffs[b].P_quant_re, num_ch ); } @@ -753,7 +853,12 @@ ivas_error ivas_spar_md_enc_process( { hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i] = 0; } - +#ifdef LBR_SBA_PLANAR + if ( active_w_vlbr ) /* SPAR PLANAR */ + { + hMdEnc->spar_md.band_coeffs[b].pred_re[1] = 0.0f; + } +#endif ivas_spar_quant_pred_coeffs_dtx( &hMdEnc->spar_md, hMdEnc->spar_md.band_coeffs[b].pred_re, ndm, hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re, num_ch - 1, hMdEnc->spar_md.band_coeffs[b].pred_quant_re ); } } @@ -903,6 +1008,66 @@ ivas_error ivas_spar_md_enc_process( { assert( qsi == 0 ); } +#ifdef LBR_SBA + /* Reuse mixer matrix values for unsent bands */ + if ( ( hEncoderConfig->ivas_total_brate < IVAS_24k4 ) && ( code_strat > 3 ) ) + { + for ( b = 0; b < num_bands * bands_bw; b += 2 * bands_bw ) + { + if ( ( b == 0 ) && ( code_strat % 2 == 0 ) ) + { + b += 2; + } + for ( i = 0; i < 1; i++ ) + { + for ( j = 0; j < 4; j++ ) + { + hMdEnc->mixer_mat[i][j][b] = prior_mixer[i][j][b]; + hMdEnc->mixer_mat[i][j][b + 1] = prior_mixer[i][j][b + 1]; + } + } + } + } +#endif +#ifdef DEBUG_LBR_SBA + char f_name[100]; + int16_t nbands = 1; + int16_t num_subframes = 1; + int16_t num_elements = 6; + int16_t num_block_group = 1; + int16_t byte_size = sizeof( float ); + + float sba_md_kbps = (float) hMetaData->nb_bits_tot * 50 / 1000; + float spar_md_kbps = sba_md_kbps - dirac_md_kbps; + float corebr_kbps = (float) hEncoderConfig->ivas_total_brate / 1000 - sba_md_kbps; + + sprintf( f_name, "SBA_MD_bitrate.bin" ); + ( frame == 0 ) ? dbgwrite( &nbands, sizeof( nbands ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_group, sizeof( num_block_group ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + + for ( b = 0; b < nbands; b++ ) + { + for ( int16_t sf = 0; sf < num_subframes; sf++ ) + { + for ( int16_t bl = 0; bl < num_block_group; bl++ ) + { + float fqsi = (float) qsi; + float fcode = (float) code_strat; + + dbgwrite( &dirac_md_kbps, byte_size, 1, 1, f_name ); + dbgwrite( &spar_md_kbps, byte_size, 1, 1, f_name ); + dbgwrite( &sba_md_kbps, byte_size, 1, 1, f_name ); + dbgwrite( &fqsi, byte_size, 1, 1, f_name ); + dbgwrite( &fcode, byte_size, 1, 1, f_name ); + dbgwrite( &corebr_kbps, byte_size, 1, 1, f_name ); + // fprintf(stdout, "%f\t%f\t%f\t%d\t%d\n", dirac_md_kbps, spar_md_kbps, sba_md_kbps, qsi, code_strat ); + } + } + } +#endif #ifdef SPAR_HOA_DBG /*if ( strat >= 4 ) { @@ -1078,7 +1243,11 @@ ivas_error ivas_spar_md_enc_process( fclose( fp ); #endif - ivas_store_prior_coeffs( hMdEnc, num_bands, bands_bw, code_strat, dtx_vad, qsi ); + ivas_store_prior_coeffs( hMdEnc, num_bands, +#ifndef LBR_SBA + bands_bw, +#endif + code_strat, dtx_vad, qsi ); hMdEnc->spar_md.dtx_vad = dtx_vad; hMdEnc->spar_md.num_bands = num_bands; @@ -1170,56 +1339,87 @@ static void ivas_write_spar_md_bitstream( no_ec = 0; - switch ( strat ) +#ifdef LBR_SBA + if ( ivas_total_brate < IVAS_24k4 ) { - case BASE: - push_next_indice( hMetaData, bands_bw - 1, SPAR_NUM_CODING_STRAT_BITS ); - for ( i = 0; i < nB; i++ ) - { - do_diff[i] = 0; - } - break; - case BASE_NOEC: - push_next_indice( hMetaData, bands_bw + 1, SPAR_NUM_CODING_STRAT_BITS ); - for ( i = 0; i < nB; i++ ) - { - do_diff[i] = 0; - } - no_ec = 1; - break; - case FOUR_A: - push_next_indice( hMetaData, 4, SPAR_NUM_CODING_STRAT_BITS ); - for ( i = 0; i < nB; i++ ) - { - do_diff[i] = ( ( ( i + 1 ) & 3 ) != 0 ); - } - ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); - break; - case FOUR_B: - push_next_indice( hMetaData, 5, SPAR_NUM_CODING_STRAT_BITS ); - for ( i = 0; i < nB; i++ ) - { - do_diff[i] = ( ( ( i + 1 ) & 3 ) != 1 ); - } - ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); - break; - case FOUR_C: - push_next_indice( hMetaData, 6, SPAR_NUM_CODING_STRAT_BITS ); - for ( i = 0; i < nB; i++ ) - { - do_diff[i] = ( ( ( i + 1 ) & 3 ) != 2 ); - } - ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); - break; - case FOUR_D: - push_next_indice( hMetaData, 7, SPAR_NUM_CODING_STRAT_BITS ); - for ( i = 0; i < nB; i++ ) - { - do_diff[i] = ( ( ( i + 1 ) & 3 ) != 3 ); - } - ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); - break; + switch ( strat ) + { + case BASE: + push_next_indice( hMetaData, bands_bw - 1, SPAR_NUM_CODING_STRAT_BITS ); + break; + case BASE_NOEC: + push_next_indice( hMetaData, bands_bw + 1, SPAR_NUM_CODING_STRAT_BITS ); + no_ec = 1; + break; + case FOUR_A: + case FOUR_C: + case FOUR_B: + case FOUR_D: + push_next_indice( hMetaData, strat, SPAR_NUM_CODING_STRAT_BITS ); + break; + } + /* for LBR SBA 40MS MD never do time diff */ + for ( i = 0; i < nB; i++ ) + { + do_diff[i] = 0; + } + } + else + { +#endif + switch ( strat ) + { + case BASE: + push_next_indice( hMetaData, bands_bw - 1, SPAR_NUM_CODING_STRAT_BITS ); + for ( i = 0; i < nB; i++ ) + { + do_diff[i] = 0; + } + break; + case BASE_NOEC: + push_next_indice( hMetaData, bands_bw + 1, SPAR_NUM_CODING_STRAT_BITS ); + for ( i = 0; i < nB; i++ ) + { + do_diff[i] = 0; + } + no_ec = 1; + break; + case FOUR_A: + push_next_indice( hMetaData, 4, SPAR_NUM_CODING_STRAT_BITS ); + for ( i = 0; i < nB; i++ ) + { + do_diff[i] = ( ( ( i + 1 ) & 3 ) != 0 ); + } + ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); + break; + case FOUR_B: + push_next_indice( hMetaData, 5, SPAR_NUM_CODING_STRAT_BITS ); + for ( i = 0; i < nB; i++ ) + { + do_diff[i] = ( ( ( i + 1 ) & 3 ) != 1 ); + } + ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); + break; + case FOUR_C: + push_next_indice( hMetaData, 6, SPAR_NUM_CODING_STRAT_BITS ); + for ( i = 0; i < nB; i++ ) + { + do_diff[i] = ( ( ( i + 1 ) & 3 ) != 2 ); + } + ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); + break; + case FOUR_D: + push_next_indice( hMetaData, 7, SPAR_NUM_CODING_STRAT_BITS ); + for ( i = 0; i < nB; i++ ) + { + do_diff[i] = ( ( ( i + 1 ) & 3 ) != 3 ); + } + ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); + break; + } +#ifdef LBR_SBA } +#endif #ifdef SPAR_HOA_DBG if ( strat < 2 ) @@ -1229,11 +1429,22 @@ static void ivas_write_spar_md_bitstream( #endif if ( no_ec == 1 ) { - ivas_get_huffman_coded_bs( hMdEnc, hMetaData, nB, qsi, planarCP ); + ivas_get_huffman_coded_bs( hMdEnc, hMetaData, nB, qsi, planarCP +#ifdef LBR_SBA + , + bands_bw +#endif + ); } else { - ivas_get_arith_coded_bs( hMdEnc, hMetaData, do_diff, bands_bw, nB, qsi, planarCP ); + ivas_get_arith_coded_bs( hMdEnc, hMetaData, do_diff, bands_bw, nB, qsi, planarCP +#ifdef LBR_SBA + , + strat, + ivas_total_brate +#endif + ); } return; @@ -1251,7 +1462,12 @@ static void ivas_get_huffman_coded_bs( BSTR_ENC_HANDLE hMetaData, const int16_t nB, const int16_t qsi, - const int16_t planarCP ) + const int16_t planarCP +#ifdef LBR_SBA + , + const int16_t bands_bw +#endif +) { int16_t i, j; int16_t pred_coeff_dim, pred_offset; @@ -1259,8 +1475,15 @@ static void ivas_get_huffman_coded_bs( for ( i = 0; i < nB; i++ ) { int16_t code, len; - int16_t ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[i]; - int16_t ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[i]; +#ifdef LBR_SBA + int16_t ndm, ndec; + ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[i * bands_bw]; + ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[i * bands_bw]; +#else + int16_t ndm, ndec; + ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[i]; + ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[i]; +#endif pred_coeff_dim = ndm + ndec - 1; pred_offset = 0; @@ -1302,6 +1525,12 @@ static void ivas_get_huffman_coded_bs( { for ( j = pred_offset; j < pred_coeff_dim; j++ ) { +#ifdef LBR_SBA_PLANAR + if ( ( j == 1 ) && ( bands_bw == IVAS_RED_BAND_FACT ) ) + { + continue; + } +#endif ivas_huffman_encode( &hMdEnc->huff_coeffs.pred_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j], &code, &len ); push_next_indice( hMetaData, code, len ); } @@ -1314,6 +1543,12 @@ static void ivas_get_huffman_coded_bs( for ( j = 0; j < ndec; j++ ) { +#ifdef LBR_SBA_PLANAR + if ( ( j == 2 ) && ( bands_bw == IVAS_RED_BAND_FACT ) ) + { + continue; + } +#endif ivas_huffman_encode( &hMdEnc->huff_coeffs.decd_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].decd_index_re[j], &code, &len ); push_next_indice( hMetaData, code, len ); } @@ -1337,7 +1572,13 @@ static void ivas_get_arith_coded_bs( const int16_t bands_bw, const int16_t nB, const int16_t qsi, - const int16_t planarCP ) + const int16_t planarCP +#ifdef LBR_SBA + , + const int16_t strat, + const int32_t ivas_total_brate +#endif +) { int16_t i, j, any_diff; ivas_cell_dim_t pred_cell_dims[IVAS_MAX_NUM_BANDS]; @@ -1352,21 +1593,46 @@ static void ivas_get_arith_coded_bs( int16_t ndm, ndec; ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[bands_bw * i]; ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[bands_bw * i]; - pred_cell_dims[i].dim1 = ndm + ndec - 1; - if ( hMdEnc->spar_hoa_md_flag ) +#ifdef LBR_SBA + if ( ( ivas_total_brate < IVAS_24k4 ) && ( strat > 3 ) && ( ( ( i % 2 == 1 ) && ( strat % 2 == 0 ) ) || ( ( i % 2 == 0 ) && ( strat % 2 == 1 ) ) ) ) { - if ( i >= SPAR_DIRAC_SPLIT_START_BAND ) + pred_cell_dims[i].dim1 = 0; + pred_cell_dims[i].dim2 = 0; + drct_cell_dims[i].dim1 = 0; + drct_cell_dims[i].dim2 = 0; + decd_cell_dims[i].dim1 = 0; + decd_cell_dims[i].dim2 = 0; + decx_cell_dims[i].dim1 = 0; + decx_cell_dims[i].dim2 = 0; + } + else + { +#endif + pred_cell_dims[i].dim1 = ndm + ndec - 1; + if ( hMdEnc->spar_hoa_md_flag ) { - pred_cell_dims[i].dim1 -= ( FOA_CHANNELS - 1 ); + if ( i >= SPAR_DIRAC_SPLIT_START_BAND ) + { + pred_cell_dims[i].dim1 -= ( FOA_CHANNELS - 1 ); + } } + pred_cell_dims[i].dim2 = 1; + drct_cell_dims[i].dim1 = ndec; + drct_cell_dims[i].dim2 = ndm - 1; + decd_cell_dims[i].dim1 = ndec; + decd_cell_dims[i].dim2 = 1; + decx_cell_dims[i].dim1 = ( ndec * ( ndec - 1 ) ) >> 1; + decx_cell_dims[i].dim2 = 1; +#ifdef LBR_SBA_PLANAR + if ( ivas_total_brate < IVAS_24k4 ) + { + pred_cell_dims[i].dim1 -= 1; + decd_cell_dims[i].dim1 -= 1; + } +#endif +#ifdef LBR_SBA } - pred_cell_dims[i].dim2 = 1; - drct_cell_dims[i].dim1 = ndec; - drct_cell_dims[i].dim2 = ndm - 1; - decd_cell_dims[i].dim1 = ndec; - decd_cell_dims[i].dim2 = 1; - decx_cell_dims[i].dim1 = ( ndec * ( ndec - 1 ) ) >> 1; - decx_cell_dims[i].dim2 = 1; +#endif } any_diff = 0; @@ -1398,6 +1664,15 @@ static void ivas_get_arith_coded_bs( } } } +#ifdef LBR_SBA_PLANAR + if ( ivas_total_brate < IVAS_24k4 ) + { + for ( int16_t b = 0; b < nB; b++ ) /* swap X and Z PR coefficients, then code fewer */ + { + hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re[1] = hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re[2]; + } + } +#endif ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md.band_coeffs_idx, nB, symbol_arr_re, pred_cell_dims, PRED_COEFF, planarCP ); if ( any_diff == 1 ) @@ -1540,15 +1815,17 @@ static void ivas_select_next_strat( static void ivas_store_prior_coeffs( ivas_spar_md_enc_state_t *hMdEnc, const int16_t num_bands, +#ifndef LBR_SBA const int16_t bands_bw, +#endif const int16_t strat, const int16_t dtx_vad, const int16_t qsi ) { int16_t i, j, b; - +#ifndef LBR_SBA float one_by_bands_bw = ( 1.0f / bands_bw ); - +#endif if ( dtx_vad == 0 ) { hMdEnc->spar_md_cfg.prior_strat = START; @@ -1562,8 +1839,13 @@ static void ivas_store_prior_coeffs( for ( i = 0; i < num_bands; i++ ) { +#ifdef LBR_SBA + b = i; + /* TODO: Bitrate switching will require dependence on bands_bw, and changes to time differential coding/prior index + storage for 6-12 band switching. e.g. b = (int16_t) floor( i * one_by_bands_bw ); */ +#else b = (int16_t) floor( i * one_by_bands_bw ); - +#endif for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { hMdEnc->spar_md_prior.band_coeffs_idx[i].pred_index_re[j] = hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re[j]; diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 80dddaf9ddb806c50154925c061a09ea46007b90..5927114b2fe2fe266941d6b65fb07a56466c17c1 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1088,7 +1088,9 @@ typedef struct encoder_config_structure /* temp. development parameters */ int16_t Opt_PCA_ON; /* flag indicating PCA operation in SBA */ - +#ifdef LBR_SBA_BR_SWITCHING + int16_t spar_reconfig_flag; +#endif #ifdef DEBUGGING /* debugging options */ int16_t stereo_mode_cmdl; /* stereo mode forced from the command-line */ diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 72ac2c882a8105fc0d29da67bc5f395592f6460e..7278807f52caf9c883ab36223cb834b1035488f7 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -965,7 +965,11 @@ static ivas_error configureEncoder( } #ifdef DEBUG_AGC_ENCODER_CMD_OPTION +#ifndef LBR_SBA if ( hEncoderConfig->Opt_AGC_ON == SBA_AGC_FORCE_ENABLE && !( hEncoderConfig->ivas_format == SBA_FORMAT && ivas_sba_mode_select( hEncoderConfig->ivas_total_brate ) == SBA_MODE_SPAR ) ) +#else + if ( hEncoderConfig->Opt_AGC_ON == SBA_AGC_FORCE_ENABLE && !( hEncoderConfig->ivas_format == SBA_FORMAT && ivas_sba_mode_select() == SBA_MODE_SPAR ) ) +#endif { return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "AGC supported in SBA format at bitrates >= 24.4 kbps only." ); } diff --git a/lib_enc/lsf_msvq_ma_enc.c b/lib_enc/lsf_msvq_ma_enc.c index 190f4e2a74d04ac8981cd0fdbb44306adb08801d..4735b0a6515b2e0af1a428bba014f8a37fb221fc 100644 --- a/lib_enc/lsf_msvq_ma_enc.c +++ b/lib_enc/lsf_msvq_ma_enc.c @@ -111,7 +111,7 @@ void msvq_enc( int16_t check_ind[FDCNG_VQ_DCT_NPOST]; int16_t segm, j_full, maxC_pre; float *st1_syn_vec_ptr; /* 8* 24 floats in dynRAM */ - float *st1_mse_ptr; /* 2^¨7 == 128 floats in existing dRAM used for stage 1 candidate analysis, 128 Word32 in BASOP */ + float *st1_mse_ptr; /* 2^7 == 128 floats in existing dRAM used for stage 1 candidate analysis, 128 Word32 in BASOP */ float res24, high_diff[FDCNG_VQ_MAX_LEN - FDCNG_VQ_MAX_LEN_WB]; maxC_pre = ( FDCNG_VQ_DCT_NSEGM * 2 ); diff --git a/lib_enc/speech_music_classif.c b/lib_enc/speech_music_classif.c index cf8568e649db982127b0cd978a935d7f28b97b2f..80bd2d6d2a8cc8aeb9c7d334e13959d824c0736e 100644 --- a/lib_enc/speech_music_classif.c +++ b/lib_enc/speech_music_classif.c @@ -1828,6 +1828,9 @@ void ivas_smc_mode_selection( float ton; int16_t i; float S_p2a, S_max, S_ave; +#ifdef FIX_SP2A + float thr_sp2a; +#endif SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; @@ -1858,8 +1861,23 @@ void ivas_smc_mode_selection( S_ave = sum_f( st->hSpMusClas->tod_lt_Bin_E, TOD_NSPEC ) / TOD_NSPEC; S_p2a = S_max - S_ave; +#ifdef FIX_SP2A + if ( element_brate <= IVAS_16k4 ) + { + thr_sp2a = THR_P2A_HIGH; + } + else + { + thr_sp2a = THR_P2A; + } +#endif + /* initial 3-way selection of coding modes (ACELP/GSC/TCX) */ +#ifdef FIX_SP2A + if ( relE > -10.0f && ( S_p2a > thr_sp2a || ton > hSpMusClas->tod_thr_lt ) ) +#else if ( relE > -10.0f && ( S_p2a > THR_P2A || ton > hSpMusClas->tod_thr_lt ) ) +#endif { /* select TCX to encode extremely peaky signals or strongly tonal signals */ st->sp_aud_decision1 = 1; diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index e6f645197a3a2ebb0e4bedae254d8887bf7c7a0e..a2c7b242e1df963575b9a5bd8a79dcdc28aef1ce 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -53,8 +53,10 @@ *------------------------------------------------------------------------*/ #define CLDFB_HALF_BIN_FREQUENCY_OFFSET 0.5f +#ifdef FIX_417_TD_DECORR_BRATE_SW #define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN ( 2.0f ) #define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR ( 3.0f ) +#endif #ifdef MASA_AND_OBJECTS #define STEREO_PREPROCESS_IIR_FACTOR ( 0.9f ) #endif @@ -95,7 +97,9 @@ static void matrixMul( float Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Ai static void matrixTransp2Mul( float Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Aim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bre[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS] ); +#ifndef FIX_417_TD_DECORR_BRATE_SW static float configure_reqularization_factor( const IVAS_FORMAT ivas_format, const int32_t ivas_brate ); +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_init_binaural_data() @@ -161,6 +165,7 @@ ivas_error ivas_dirac_dec_init_binaural_data( hBinaural->useSubframeMode = 1; +#ifndef FIX_417_TD_DECORR_BRATE_SW hBinaural->useTdDecorr = 0; if ( st_ivas->ivas_format == SBA_FORMAT ) { @@ -183,6 +188,7 @@ ivas_error ivas_dirac_dec_init_binaural_data( hBinaural->useTdDecorr = 1; } } +#endif for ( bin = 0; bin < nBins; bin++ ) { @@ -260,6 +266,17 @@ ivas_error ivas_dirac_dec_init_binaural_data( assert( false ); } +#ifdef FIX_417_TD_DECORR_BRATE_SW + if ( hBinaural->hTdDecorr == NULL ) + { + hBinaural->useTdDecorr = 0; + } + + if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( hBinaural->hTdDecorr ), &( hBinaural->useTdDecorr ) ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( hBinaural->useTdDecorr ) { if ( st_ivas->hDecoderConfig->ivas_total_brate >= IVAS_13k2 && st_ivas->ivas_format == SBA_FORMAT ) @@ -287,6 +304,7 @@ ivas_error ivas_dirac_dec_init_binaural_data( { ivas_td_decorr_dec_close( &( hBinaural->hTdDecorr ) ); } +#endif hBinaural->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); @@ -2186,10 +2204,15 @@ static void hrtfShGetHrtf( * parametric binauralizer using IVAS codec format and current bitrate. *------------------------------------------------------------------------*/ -/*! r: Configured reqularization factor value to be set. */ -static float configure_reqularization_factor( - const IVAS_FORMAT ivas_format, /* i : IVAS codec format in use */ - const int32_t ivas_brate ) /* i : Current IVAS bitrate */ +/*! r: Configured reqularization factor value */ +#ifndef FIX_417_TD_DECORR_BRATE_SW +static +#endif + float + configure_reqularization_factor( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int32_t ivas_total_brate /* i : IVAS total bitrate */ + ) { float reqularizationFactor; @@ -2197,27 +2220,27 @@ static float configure_reqularization_factor( if ( ivas_format == MASA_FORMAT ) { - if ( ivas_brate >= IVAS_256k ) + if ( ivas_total_brate >= IVAS_256k ) { reqularizationFactor = 0.2f; } - else if ( ivas_brate == IVAS_192k ) + else if ( ivas_total_brate == IVAS_192k ) { reqularizationFactor = 0.3f; } - else if ( ivas_brate == IVAS_160k ) + else if ( ivas_total_brate == IVAS_160k ) { reqularizationFactor = 0.4f; } - else if ( ivas_brate == IVAS_128k ) + else if ( ivas_total_brate == IVAS_128k ) { reqularizationFactor = 0.5f; } - else if ( ivas_brate == IVAS_96k ) + else if ( ivas_total_brate == IVAS_96k ) { reqularizationFactor = 0.6f; } - else if ( ivas_brate >= IVAS_64k ) + else if ( ivas_total_brate >= IVAS_64k ) { reqularizationFactor = 0.8f; } @@ -2229,19 +2252,19 @@ static float configure_reqularization_factor( if ( ivas_format == MC_FORMAT ) /* This is always McMASA for parametric binauralizer. */ { - if ( ivas_brate >= IVAS_96k ) + if ( ivas_total_brate >= IVAS_96k ) { reqularizationFactor = 0.3f; } - else if ( ivas_brate >= IVAS_80k ) + else if ( ivas_total_brate >= IVAS_80k ) { reqularizationFactor = 0.5f; } - else if ( ivas_brate >= IVAS_64k ) + else if ( ivas_total_brate >= IVAS_64k ) { reqularizationFactor = 0.7f; } - else if ( ivas_brate >= IVAS_48k ) + else if ( ivas_total_brate >= IVAS_48k ) { reqularizationFactor = 0.8f; } diff --git a/scripts/binauralRenderer_interface/CMakeLists.txt b/scripts/binauralRenderer_interface/CMakeLists.txt deleted file mode 100644 index 99d62c94172a328e0621e872bd097ef63e5929f4..0000000000000000000000000000000000000000 --- a/scripts/binauralRenderer_interface/CMakeLists.txt +++ /dev/null @@ -1,103 +0,0 @@ -cmake_minimum_required(VERSION 3.0) - -project(generate_crend_ivas_tables) - -set(EXTERNALS_PATH ${PROJECT_SOURCE_DIR}/Externals) -set(IVAS_TRUNK_PATH "${PROJECT_SOURCE_DIR}/../..") -set(IVAS_TRUNK_UTIL_PATH ${IVAS_TRUNK_PATH}/lib_util) -set(IVAS_TRUNK_DEC_PATH ${IVAS_TRUNK_PATH}/lib_dec) -set(IVAS_TRUNK_REND_PATH ${IVAS_TRUNK_PATH}/lib_rend) -set(IVAS_TRUNK_ENC_PATH ${IVAS_TRUNK_PATH}/lib_enc) -set(IVAS_TRUNK_COM_PATH ${IVAS_TRUNK_PATH}/lib_com) -set(IVAS_TRUNK_DEBUG_PATH ${IVAS_TRUNK_PATH}/lib_debug) - -if(WIN32) - find_path(ZLIB_DIR "zlib.h" ${EXTERNALS_PATH}/zlib/zlib-1.2.12) - - if(ZLIB_DIR) - else() - set(ZLIB_DIR ${EXTERNALS_PATH}/zlib) - find_package(Python3 REQUIRED) - - if(Python3_Interpreter_FOUND) - execute_process(COMMAND ${Python3_EXECUTABLE} resolve_build_dep.py - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - RESULT_VARIABLE py_result OUTPUT_VARIABLE ZLIB_DIR) - set(ZLIB_DIR ${PROJECT_SOURCE_DIR} ${ZLIB_DIR}) - endif() - - message(STATUS " ZLIB_DIR: ${ZLIB_DIR}") - endif() -endif() - -if(WIN32) - add_subdirectory(${ZLIB_DIR}) - set(ZLIB_INCLUDE_DIRS ${ZLIB_DIR} ${PROJECT_BINARY_DIR}/Externals/zlib/zlib-1.2.12) - set(zlib zlibstatic) - target_include_directories(example PUBLIC ${ZLIB_INCLUDE_DIRS}) - target_include_directories(minigzip PUBLIC ${ZLIB_INCLUDE_DIRS}) -endif() - -if(UNIX) - find_package(ZLIB) - - if(ZLIB_FOUND) - message(${ZLIB_INCLUDE_DIRS}) - message(${ZLIB_LIBRARIES}) - set(zlib ${ZLIB_LIBRARIES}) - else() - message(FATAL_ERROR "Zlib not found") - endif() -endif() - -find_path(SOFA_READER_DIR "libmysofa.pc.cmake" ${EXTERNALS_PATH}/libmysofa) - -if(SOFA_READER_DIR) -else() - set(SOFA_READER_DIR ${EXTERNALS_PATH}/libmysofa) - set(GIT_URL https://github.com/hoene/libmysofa.git) - execute_process(COMMAND git clone ${GIT_URL} ${EXTERNALS_PATH}/libmysofa) -endif() - -include_directories(${SOFA_READER_DIR}/src ${ZLIB_INCLUDE_DIRS} ${IVAS_TRUNK_UTIL_PATH} ${IVAS_TRUNK_ENC_PATH} ${IVAS_TRUNK_DEC_PATH} ${IVAS_TRUNK_REND_PATH} ${IVAS_TRUNK_COM_PATH} ${IVAS_TRUNK_DEBUG_PATH}) - -option(BUILD_TESTS "Build test programs" OFF) -option(BUILD_SHARED_LIBS "Build shared library" OFF) -add_subdirectory(${SOFA_READER_DIR}) -set(SOURCE_FILES_C - ${PROJECT_SOURCE_DIR}/ivas_crend_binaural_filter_design.c - ${IVAS_TRUNK_COM_PATH}/basop32.c - ${IVAS_TRUNK_COM_PATH}/basop_mpy.c - ${IVAS_TRUNK_COM_PATH}/enh40.c - ${IVAS_TRUNK_COM_PATH}/fft.c - ${IVAS_TRUNK_COM_PATH}/fft_rel.c - ${IVAS_TRUNK_COM_PATH}/ifft_rel.c - ${IVAS_TRUNK_COM_PATH}/ivas_mdft_imdft.c - ${IVAS_TRUNK_COM_PATH}/rom_com.c - ${IVAS_TRUNK_COM_PATH}/ivas_rom_com.c - ${IVAS_TRUNK_COM_PATH}/tools.c - ${IVAS_TRUNK_COM_PATH}/tns_base.c -) - -set(SOURCE_FILES_H - ${PROJECT_SOURCE_DIR}/ivas_crend_binaural_filter_design.c - ${SOFA_READER_DIR}/src/hrtf/mysofa.h - ${IVAS_TRUNK_REND_PATH}/ivas_stat_rend.h - ${IVAS_TRUNK_DEC_PATH}/ivas_stat_dec.h - ${IVAS_TRUNK_DEC_PATH}/stat_dec.h - ${IVAS_TRUNK_COM_PATH}/options.h - ${IVAS_TRUNK_COM_PATH}/ivas_cnst.h - ${IVAS_TRUNK_COM_PATH}/cnst.h - ${IVAS_TRUNK_COM_PATH}/prot.h - ${IVAS_TRUNK_COM_PATH}/ivas_prot.h - ${IVAS_TRUNK_COM_PATH}/common_api_types.h -) - -add_library(${PROJECT_NAME}_lib STATIC ${SOURCE_FILES_C} ${SOURCE_FILES_H}) - -add_executable(${PROJECT_NAME} generate_crend_ivas_tables_from_sofa.c) -target_link_libraries(${PROJECT_NAME} ${PROJECT_NAME}_lib mysofa-static ${zlib}) - -if(WIN32) - add_compile_definitions(_CRT_SECURE_NO_WARNINGS) -endif() diff --git a/scripts/binauralRenderer_interface/Table_Format_Converter/CMakeLists.txt b/scripts/binauralRenderer_interface/Table_Format_Converter/CMakeLists.txt deleted file mode 100644 index 259e3b97b6abc67129aca82147929a3841848e2a..0000000000000000000000000000000000000000 --- a/scripts/binauralRenderer_interface/Table_Format_Converter/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -cmake_minimum_required(VERSION 3.6) - -project(tables_format_converter) - -if(WIN32) - # MSVC compiler flags - add_definitions( - -D_CRT_SECURE_NO_WARNINGS - ) - - # CMake sets /W3 by default, until CMake version 3.15. Instead of setting /W4 separately, replace in existing settings - string(REGEX REPLACE "/W3" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") -endif() - -set(IVAS_PATH "${PROJECT_SOURCE_DIR}/../../..") -set(IVAS_UTIL_PATH ${IVAS_PATH}/lib_util) -set(IVAS_DEC_PATH ${IVAS_PATH}/lib_dec) -set(IVAS_ENC_PATH ${IVAS_PATH}/lib_enc) -set(IVAS_COM_PATH ${IVAS_PATH}/lib_com) -set(IVAS_REND_PATH ${IVAS_PATH}/lib_rend) -set(IVAS_DEBUG_PATH ${IVAS_PATH}/lib_debug) - -include_directories(${IVAS_UTIL_PATH} ${IVAS_ENC_PATH} ${IVAS_DEC_PATH} ${IVAS_COM_PATH} ${IVAS_REND_PATH} ${IVAS_DEBUG_PATH}) - -set(SOURCE_FILES_C - ${IVAS_REND_PATH}/ivas_rom_binauralRenderer.c - ${IVAS_REND_PATH}/ivas_rom_binaural_crend_head.c) - -set(SOURCE_FILES_H - ${IVAS_REND_PATH}/ivas_rom_binauralRenderer.h - ${IVAS_REND_PATH}/ivas_rom_binaural_crend_head.h) - -add_library(${PROJECT_NAME}_lib STATIC ${SOURCE_FILES_C} ${SOURCE_FILES_H}) - -add_executable(${PROJECT_NAME} generate_tables_from_rom_to_bin.c) -target_link_libraries(${PROJECT_NAME} ${PROJECT_NAME}_lib) diff --git a/scripts/prepare_mem_dryrun.py b/scripts/prepare_mem_dryrun.py old mode 100644 new mode 100755 index 21f5b8114592067bdb0b9d04d00fa9bb20c22227..b83018e4682e19decb9cd59991b5a9f7aa0c9eb6 --- a/scripts/prepare_mem_dryrun.py +++ b/scripts/prepare_mem_dryrun.py @@ -1,4 +1,4 @@ -#!/bin/python3 +#!/usr/bin/env python3 import re, os, fnmatch