From f90903478e049e01db31509f4b19c7568919460d Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 17 Oct 2022 18:44:30 +0200 Subject: [PATCH 1/4] maintenance of the SBA SPAR functions; under #define SBA_SPAR_HARM --- lib_com/ivas_cov_smooth.c | 40 ++++++++++++-- lib_com/ivas_prot.h | 35 ++++++++++++- lib_com/ivas_spar_com.c | 40 +++++++------- lib_com/ivas_stat_com.h | 4 +- lib_com/options.h | 1 + lib_enc/ivas_enc_cov_handler.c | 62 ++++++++++++++++++---- lib_enc/ivas_spar_encoder.c | 55 +++++++++++++++++++- lib_enc/ivas_spar_md_enc.c | 95 ++++++++++++++++++++++++++++++---- lib_enc/ivas_stat_enc.h | 5 +- 9 files changed, 290 insertions(+), 47 deletions(-) diff --git a/lib_com/ivas_cov_smooth.c b/lib_com/ivas_cov_smooth.c index 507b7cf0cd..4584303293 100644 --- a/lib_com/ivas_cov_smooth.c +++ b/lib_com/ivas_cov_smooth.c @@ -169,22 +169,36 @@ void ivas_spar_covar_smooth_enc_close( static void ivas_compute_smooth_cov( ivas_cov_smooth_state_t *hCovState, +#ifndef SBA_SPAR_HARM ivas_cov_smooth_in_buf_t *pIn_buf, +#endif ivas_filterbank_t *pFb, float *pCov_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float *pPrior_cov_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const float fac, const int16_t start_band, - const int16_t end_band ) + const int16_t end_band +#ifdef SBA_SPAR_HARM + , + const int16_t num_ch, + const int16_t transient_det +#endif +) { int16_t i, j, k; int16_t prev_idx = hCovState->prior_bank_idx; +#ifndef SBA_SPAR_HARM int16_t num_ch = pIn_buf->num_ch; +#endif float factor = 0; assert( end_band <= pFb->filterbank_num_bands ); +#ifdef SBA_SPAR_HARM + if ( prev_idx == -1 || transient_det == 1 ) +#else if ( prev_idx == -1 || pIn_buf->reset_cov == 1 ) +#endif { for ( i = 0; i < num_ch; i++ ) { @@ -229,22 +243,42 @@ static void ivas_compute_smooth_cov( void ivas_cov_smooth_process( ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */ +#ifdef SBA_SPAR_HARM + float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], +#else ivas_cov_smooth_in_buf_t *pIn_buf, +#endif ivas_filterbank_t *pFb, /* i/o: FB handle */ const int16_t start_band, - const int16_t end_band ) + const int16_t end_band +#ifdef SBA_SPAR_HARM + , + const int16_t num_ch, + const int16_t transient_det +#endif +) { int16_t i, j; +#ifndef SBA_SPAR_HARM int16_t num_ch = pIn_buf->num_ch; +#endif int16_t num_bands = end_band - start_band; - ivas_compute_smooth_cov( hCovState, pIn_buf, pFb, pIn_buf->cov_real, hCovState->pPrior_cov_real, 1e-20f, start_band, end_band ); +#ifdef SBA_SPAR_HARM + ivas_compute_smooth_cov( hCovState, pFb, cov_real, hCovState->pPrior_cov_real, 1e-20f, start_band, end_band, num_ch, transient_det ); +#else + ivas_compute_smooth_cov( hCovState, pFb, pIn_buf->cov_real, hCovState->pPrior_cov_real, 1e-20f, start_band, end_band, num_ch, transient_det ); +#endif for ( i = 0; i < num_ch; i++ ) { for ( j = 0; j < num_ch; j++ ) { +#ifdef SBA_SPAR_HARM + mvr2r( &cov_real[i][j][start_band], &hCovState->pPrior_cov_real[i][j][start_band], num_bands ); +#else mvr2r( &pIn_buf->cov_real[i][j][start_band], &hCovState->pPrior_cov_real[i][j][start_band], num_bands ); +#endif } } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index d70d4f1548..eb79d71c38 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3910,9 +3910,20 @@ void ivas_spar_md_enc_close( ivas_error ivas_spar_md_enc_process( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ +#ifdef SBA_SPAR_HARM + float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], +#else ivas_spar_md_enc_in_buf_t *pIn_buf, +#endif BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ +#ifdef SBA_SPAR_HARM + int16_t dtx_vad, + const int16_t bwidth, + const int16_t nchan_inp, +#else const int16_t dtx_silence_mode, +#endif const int16_t sba_order /* i : Ambisonic (SBA) order */ ); @@ -4048,12 +4059,25 @@ void ivas_spar_covar_enc_close( void ivas_enc_cov_handler_process( ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ +#ifdef SBA_SPAR_HARM + float **ppIn_FR_real, + float **ppIn_FR_imag, + float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], +#else ivas_enc_cov_handler_in_buf_t *pIn_buf, float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], +#endif ivas_filterbank_t *pFb, /* i/o: FB handle */ const int16_t start_band, - const int16_t end_band ); + const int16_t end_band +#ifdef SBA_SPAR_HARM + ,const int16_t nchan_inp, + const int16_t dtx_vad, + const int16_t transient_det +#endif +); ivas_error ivas_spar_covar_smooth_enc_open( ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. smoothing handle */ @@ -4069,10 +4093,19 @@ void ivas_spar_covar_smooth_enc_close( void ivas_cov_smooth_process( ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */ +#ifdef SBA_SPAR_HARM + float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], +#else ivas_cov_smooth_in_buf_t *pIn_buf, +#endif ivas_filterbank_t *pFb, /* i/o: FB handle */ const int16_t start_band, const int16_t end_band +#ifdef SBA_SPAR_HARM + , + const int16_t num_ch, + const int16_t transient_det +#endif ); /* Transient detector module */ diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index eec2e5f09a..44e63981a9 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -75,6 +75,7 @@ * Static functions declaration *------------------------------------------------------------------------------------------*/ + 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_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 ); @@ -448,7 +449,7 @@ int16_t ivas_get_sba_num_TCs( *-----------------------------------------------------------------------------------------*/ static void ivas_get_pred_coeffs( - float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + float *cov_real[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, @@ -473,7 +474,7 @@ static void ivas_get_pred_coeffs( set_zero( pPred_temp, IVAS_MAX_NUM_BANDS ); for ( k = start_band; k < end_band; k++ ) { - div_factor[k] = max( 1e-20f, pppCov_mat_re[0][0][k] ); + div_factor[k] = max( 1e-20f, cov_real[0][0][k] ); div_factor[k] = 1 / div_factor[k]; } @@ -481,7 +482,7 @@ static void ivas_get_pred_coeffs( { for ( k = start_band; k < end_band; k++ ) { - ppPred_coeffs_re[i][k] = pppCov_mat_re[i + 1][0][k] * div_factor[k]; + ppPred_coeffs_re[i][k] = cov_real[i + 1][0][k] * div_factor[k]; IVAS_CALCULATE_SQ_ABS_N( ppPred_coeffs_re[i][k], abs_value ); @@ -519,7 +520,7 @@ static void ivas_get_pred_coeffs( { for ( k = start_band; k < end_band; k++ ) { - IVAS_CALCULATE_SQ_ABS_N( pppCov_mat_re[i][0][k], abs_value ); + IVAS_CALCULATE_SQ_ABS_N( cov_real[i][0][k], abs_value ); dm_alpha[k] += abs_value; } } @@ -535,7 +536,7 @@ static void ivas_get_pred_coeffs( { for ( k = start_band; k < end_band; k++ ) { - dm_v_re[i][k] = pppCov_mat_re[i + 1][0][k] * div_factor[k]; + dm_v_re[i][k] = cov_real[i + 1][0][k] * div_factor[k]; } } @@ -558,7 +559,7 @@ static void ivas_get_pred_coeffs( { float re; - IVAS_RMULT_FLOAT( pppCov_mat_re[j + 1][k][b], dm_v_re[k - 1][b], re ); + IVAS_RMULT_FLOAT( cov_real[j + 1][k][b], dm_v_re[k - 1][b], re ); real[j] += re; } } @@ -570,7 +571,7 @@ static void ivas_get_pred_coeffs( dm_beta_re += re; } - dm_w = pppCov_mat_re[0][0][b]; + dm_w = cov_real[0][0][b]; den_f = max( dm_w, 1e-20f ); passive_g = dm_alpha[b] / den_f; @@ -581,7 +582,7 @@ static void ivas_get_pred_coeffs( for ( k = 1; k < in_chans; k++ ) { - dm_y += pppCov_mat_re[k][k][b]; + dm_y += cov_real[k][k][b]; } den_f = max( dm_y, 1e-20f ); den_f = max( den_f, w_norm_fac * dm_w ); @@ -634,7 +635,7 @@ static void ivas_get_pred_coeffs( *-----------------------------------------------------------------------------------------*/ static void ivas_get_Wscaling_factor( - float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + float *cov_real[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, @@ -667,9 +668,9 @@ static void ivas_get_Wscaling_factor( { float Gw_sq, g_sq = 0; - ivas_calc_post_pred_per_band( pppCov_mat_re, mixer_mat, num_ch, pNum_dmx[b * bands_bw], b, postpred_cov_re ); + ivas_calc_post_pred_per_band( cov_real, mixer_mat, num_ch, pNum_dmx[b * bands_bw], b, postpred_cov_re ); - Gw_sq = pppCov_mat_re[0][0][b] / max( postpred_cov_re[0][0], IVAS_FLT_EPS ); + Gw_sq = cov_real[0][0][b] / max( postpred_cov_re[0][0], IVAS_FLT_EPS ); for ( ch = 0; ch < num_ch - 1; ch++ ) { @@ -861,7 +862,7 @@ static void ivas_reorder_array( *-----------------------------------------------------------------------------------------*/ static void ivas_calc_post_pred_per_band( - float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float ***mixer_mat, const int16_t num_ch, const int16_t num_dmx, @@ -898,7 +899,7 @@ static void ivas_calc_post_pred_per_band( temp_mat[i][j] = 0; for ( k = 0; k < num_ch; k++ ) { - IVAS_RMULT_FLOAT( pppCov_mat_re[i][k][band_idx], dmx_mat_conj[k][j], tmp_re ); + IVAS_RMULT_FLOAT( cov_real[i][k][band_idx], dmx_mat_conj[k][j], tmp_re ); temp_mat[i][j] += tmp_re; } } @@ -1239,7 +1240,7 @@ static void ivas_calc_c_coeffs_per_band( void ivas_calc_c_p_coeffs( ivas_spar_md_t *pSparMd, - float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t i_ts, float ***mixer_mat, const int16_t num_ch, @@ -1254,7 +1255,8 @@ void ivas_calc_c_p_coeffs( if ( num_dmx != num_ch ) { - ivas_calc_post_pred_per_band( pppCov_mat_re, mixer_mat, num_ch, num_dmx, band_idx, postpred_cov_re ); + ivas_calc_post_pred_per_band( cov_real, mixer_mat, num_ch, num_dmx, band_idx, postpred_cov_re ); + if ( num_dmx != 1 ) { ivas_calc_c_coeffs_per_band( pSparMd, i_ts, postpred_cov_re, num_ch, num_dmx, band_idx, dtx_vad ); @@ -1524,7 +1526,7 @@ static int16_t ivas_is_mat_inv( *-----------------------------------------------------------------------------------------*/ void ivas_compute_spar_params( - float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], const int16_t i_ts, float ***mixer_mat, @@ -1542,7 +1544,7 @@ 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( pppCov_mat_re, 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, dtx_vad, from_dirac ); #ifdef SPAR_HOA_DBG /*fprintf(stderr, "\n\n Prediction Coefficients:\n"); @@ -1573,7 +1575,7 @@ void ivas_compute_spar_params( fprintf(stderr, "\n\n");*/ #endif - ivas_get_Wscaling_factor( pppCov_mat_re, pred_coeffs_re, mixer_mat, start_band, end_band, dtx_vad, num_ch, + 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 ); for ( b = start_band; b < end_band; b++ ) @@ -1596,7 +1598,7 @@ void ivas_compute_spar_params( if ( ndm != num_ch ) { - ivas_calc_c_p_coeffs( hSparMd, pppCov_mat_re, i_ts, mixer_mat, num_ch, ndm, b, dtx_vad, 1, 0 ); + ivas_calc_c_p_coeffs( hSparMd, cov_real, i_ts, mixer_mat, num_ch, ndm, b, dtx_vad, 1, 0 ); #ifdef SPAR_HOA_DBG /* if (b == 0) */ diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index e19d30dc71..d8b10257e9 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -351,6 +351,7 @@ typedef struct ivas_cov_smooth_cfg_t } ivas_cov_smooth_cfg_t; +#ifndef SBA_SPAR_HARM typedef struct ivas_cov_smooth_in_buf_t { float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; @@ -358,6 +359,7 @@ typedef struct ivas_cov_smooth_in_buf_t int16_t reset_cov; } ivas_cov_smooth_in_buf_t; +#endif /* SPAR bitrate constant table structure */ typedef struct ivas_spar_br_table_t @@ -371,7 +373,7 @@ typedef struct ivas_spar_br_table_t ivas_spar_pmx_strings_t dmx_str; int16_t active_w; int16_t tmode; - int32_t evs_brs[FOA_CHANNELS][3]; + int32_t evs_brs[FOA_CHANNELS][3]; // VE: rename to core_brs int16_t q_lvls[MAX_QUANT_STRATS][NUM_MD_Q_COEFS_SET]; int16_t td_ducking; int16_t agc_bits_ch_idx; /* 0-3, Indicates core-coder channel index from which AGC bits have been taken from*/ diff --git a/lib_com/options.h b/lib_com/options.h index 307b1126d1..0e4dc4549e 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -153,6 +153,7 @@ #define ISM_BITRATE_SWITCHING /* Issue 115: Support for Bitrate Switching in ISM */ +#define SBA_SPAR_HARM /* maintenance of the SBA SPAR functions */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_enc/ivas_enc_cov_handler.c b/lib_enc/ivas_enc_cov_handler.c index 1cc9e404d9..907b8c5908 100644 --- a/lib_enc/ivas_enc_cov_handler.c +++ b/lib_enc/ivas_enc_cov_handler.c @@ -55,7 +55,6 @@ static void ivas_band_cov( float **ppIn_FR_real, float **ppIn_FR_imag, const int16_t num_chans, const int16_t num_bins, int16_t stride, float **pFb_bin_to_band, const int16_t *pFb_start_bin_per_band, const int16_t *pFb_active_bins_per_band, const int16_t start_band, const int16_t end_band, float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] ); - /*------------------------------------------------------------------------- * ivas_spar_covar_enc_open() * @@ -142,20 +141,44 @@ void ivas_spar_covar_enc_close( void ivas_enc_cov_handler_process( ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ +#ifdef SBA_SPAR_HARM + float **ppIn_FR_real, + float **ppIn_FR_imag, + float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], +#else ivas_enc_cov_handler_in_buf_t *pIn_buf, float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], +#endif ivas_filterbank_t *pFb, /* i/o: FB handle */ const int16_t start_band, - const int16_t end_band ) + const int16_t end_band +#ifdef SBA_SPAR_HARM + , + const int16_t num_ch, + const int16_t dtx_vad, + const int16_t transient_det +#endif +) { int16_t i, j; +#ifdef SBA_SPAR_HARM + int16_t dtx_cov_flag; + + dtx_cov_flag = ( dtx_vad == 1 ) ? 0 : 1; +#else ivas_cov_smooth_in_buf_t pCov_in_buf; int16_t num_ch = pIn_buf->num_ch; pCov_in_buf.num_ch = num_ch; +#endif +#ifdef SBA_SPAR_HARM + ivas_band_cov( ppIn_FR_real, ppIn_FR_imag, num_ch, hCovEnc->num_bins, +#else ivas_band_cov( pIn_buf->ppIn_FR_real, pIn_buf->ppIn_FR_imag, pIn_buf->num_ch, hCovEnc->num_bins, +#endif pFb->fb_bin_to_band.short_stride, pFb->fb_bin_to_band.pp_short_stride_bin_to_band, pFb->fb_bin_to_band.p_short_stride_start_bin_per_band, @@ -190,28 +213,36 @@ void ivas_enc_cov_handler_process( { for ( j = 0; j < num_ch; j++ ) { +#ifndef SBA_SPAR_HARM pCov_in_buf.cov_real[i][j] = cov_real[i][j]; - +#endif mvr2r( cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); } } - pCov_in_buf.reset_cov = 0; - if ( pIn_buf->transient_det == 1 ) - { - pCov_in_buf.reset_cov = 1; - } - +#ifdef SBA_SPAR_HARM + ivas_cov_smooth_process( hCovEnc->pCov_state, cov_real, pFb, start_band, end_band, num_ch, transient_det ); +#else ivas_cov_smooth_process( hCovEnc->pCov_state, &pCov_in_buf, pFb, start_band, end_band ); +#endif +#ifdef SBA_SPAR_HARM + if ( dtx_cov_flag == 0 ) +#else if ( pIn_buf->dtx_cov_flag == 0 ) +#endif { for ( i = 0; i < num_ch; i++ ) { for ( j = 0; j < num_ch; j++ ) { +#ifdef SBA_SPAR_HARM + mvr2r( cov_real[i][j], hCovEnc->pCov_dtx_state->pPrior_cov_real[i][j], pFb->filterbank_num_bands ); + mvr2r( cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); +#else mvr2r( pCov_in_buf.cov_real[i][j], hCovEnc->pCov_dtx_state->pPrior_cov_real[i][j], pFb->filterbank_num_bands ); mvr2r( pCov_in_buf.cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); +#endif } } @@ -219,9 +250,15 @@ void ivas_enc_cov_handler_process( } else { - +#ifdef SBA_SPAR_HARM + if ( transient_det == 0 ) +#else if ( pIn_buf->transient_det == 0 ) +#endif { +#ifdef SBA_SPAR_HARM + ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, cov_dtx_real, pFb, start_band, end_band, num_ch, transient_det ); +#else for ( i = 0; i < num_ch; i++ ) { for ( j = 0; j < num_ch; j++ ) @@ -232,12 +269,16 @@ void ivas_enc_cov_handler_process( pCov_in_buf.reset_cov = 0; ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, &pCov_in_buf, pFb, start_band, end_band ); +#endif hCovEnc->prior_dtx_present = 1; } else { if ( hCovEnc->prior_dtx_present == 0 ) { +#ifdef SBA_SPAR_HARM + ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, cov_dtx_real, pFb, start_band, end_band, num_ch, transient_det ); +#else for ( i = 0; i < num_ch; i++ ) { for ( j = 0; j < num_ch; j++ ) @@ -248,6 +289,7 @@ void ivas_enc_cov_handler_process( pCov_in_buf.reset_cov = 1; ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, &pCov_in_buf, pFb, start_band, end_band ); +#endif hCovEnc->prior_dtx_present = 1; } else diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 5c4e834e61..9cf149f2a3 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -316,6 +316,7 @@ ivas_error ivas_spar_enc( return error; } +#ifndef SBA_SPAR_HARM /*-----------------------------------------------------------------------------------------* * Function ivas_spar_enc_get_windowed_fr() * @@ -377,7 +378,7 @@ static void ivas_spar_enc_get_windowed_fr( return; } - +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_spar_enc_process() @@ -395,13 +396,21 @@ static ivas_error ivas_spar_enc_process( { float pcm_tmp[IVAS_SPAR_MAX_CH][L_FRAME48k * 2]; float *p_pcm_tmp[IVAS_SPAR_MAX_CH]; +#ifdef SBA_SPAR_HARM + int16_t i, j, b, i_ts, input_frame, transient_det; +#else int16_t i, j, k, b, i_ts, input_frame, num_bands_bw; +#endif int16_t dtx_vad, dtx_cov_flag, dtx_silence_mode; int32_t ivas_total_brate, input_Fs; +#ifndef SBA_SPAR_HARM ivas_enc_cov_handler_in_buf_t cov_in_buf; +#endif float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; +#ifndef SBA_SPAR_HARM ivas_spar_md_enc_in_buf_t md_in_buf; +#endif int16_t nchan_inp, nchan_transport, bwidth, sba_order; int16_t table_idx; int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; @@ -443,7 +452,11 @@ static ivas_error ivas_spar_enc_process( * Transient detector *-----------------------------------------------------------------------------------------*/ +#ifdef SBA_SPAR_HARM + transient_det = ivas_transient_det_process( hSpar->hTranDet, data_f[0], input_frame ); +#else cov_in_buf.transient_det = ivas_transient_det_process( hSpar->hTranDet, data_f[0], input_frame ); +#endif /* store previous input samples for W in local buffer */ assert( num_del_samples <= IVAS_FB_1MS_48K_SAMP ); @@ -462,6 +475,14 @@ static ivas_error ivas_spar_enc_process( ivas_fb_mixer_pcm_ingest( hSpar->hFbMixer, data_f, p_pcm_tmp, input_frame ); /* prepare Parameter MDFT analysis */ +#ifdef SBA_SPAR_HARM + for ( i = 0; i < nchan_inp; i++ ) + { + ppIn_FR_real[i] = p_pcm_tmp[i]; + ppIn_FR_imag[i] = p_pcm_tmp[i] + input_frame; + p_pcm_tmp[i] = &data_f[i][0]; + } +#else for ( i = 0; i < nchan_inp; i++ ) { cov_in_buf.ppIn_FR_real[i] = p_pcm_tmp[i]; @@ -474,6 +495,7 @@ static ivas_error ivas_spar_enc_process( ppIn_FR_real[i] = cov_in_buf.ppIn_FR_real[i]; ppIn_FR_imag[i] = cov_in_buf.ppIn_FR_imag[i]; } +#endif l_ts = input_frame / MAX_PARAM_SPATIAL_SUBFRAMES; @@ -493,10 +515,16 @@ static ivas_error ivas_spar_enc_process( /* turn pointers back to the local buffer, needed for the following processing */ for ( i = 0; i < nchan_inp; i++ ) { +#ifdef SBA_SPAR_HARM + ppIn_FR_real[i] = pcm_tmp[i]; + ppIn_FR_imag[i] = pcm_tmp[i] + input_frame; +#endif p_pcm_tmp[i] = pcm_tmp[i]; } +#ifndef SBA_SPAR_HARM cov_in_buf.num_ch = nchan_inp; +#endif dtx_vad = ( hEncoderConfig->Opt_DTX_ON == 1 ) ? front_vad_flag : 1; @@ -504,8 +532,13 @@ static ivas_error ivas_spar_enc_process( * DirAC encoding *-----------------------------------------------------------------------------------------*/ +#ifdef SBA_SPAR_HARM + ivas_dirac_param_est_enc( st_ivas->hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, + data_f, ppIn_FR_real, ppIn_FR_imag, input_frame ); +#else ivas_dirac_param_est_enc( st_ivas->hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, data_f, cov_in_buf.ppIn_FR_real, cov_in_buf.ppIn_FR_imag, input_frame ); +#endif if ( hQMetaData->q_direction->cfg.nbands > 0 ) { @@ -596,7 +629,9 @@ static ivas_error ivas_spar_enc_process( *-----------------------------------------------------------------------------------------*/ /* use just VAD function to get VAD flags */ +#ifndef SBA_SPAR_HARM dtx_vad = ( hEncoderConfig->Opt_DTX_ON == 1 ) ? front_vad_flag : 1; +#endif dtx_cov_flag = ( dtx_vad == 1 ) ? 0 : 1; dtx_silence_mode = 0; // VE2DB: this variable is always 0 - please review or remove it bwidth = ivas_get_bw_idx_from_sample_rate( input_Fs ); @@ -606,8 +641,9 @@ static ivas_error ivas_spar_enc_process( * Covariance process *-----------------------------------------------------------------------------------------*/ +#ifndef SBA_SPAR_HARM cov_in_buf.num_ch = nchan_inp; - +#endif for ( i = 0; i < nchan_inp; i++ ) { for ( j = 0; j < nchan_inp; j++ ) @@ -617,8 +653,13 @@ static ivas_error ivas_spar_enc_process( } } +#ifdef SBA_SPAR_HARM + ivas_enc_cov_handler_process( hSpar->hCovEnc, ppIn_FR_real, ppIn_FR_imag, cov_real, cov_dtx_real, hSpar->hFbMixer->pFb, 0, hSpar->hFbMixer->pFb->filterbank_num_bands, nchan_inp, dtx_vad, transient_det ); +#else cov_in_buf.dtx_cov_flag = dtx_cov_flag; + ivas_enc_cov_handler_process( hSpar->hCovEnc, &cov_in_buf, cov_real, cov_dtx_real, hSpar->hFbMixer->pFb, 0, hSpar->hFbMixer->pFb->filterbank_num_bands ); +#endif if ( hSpar->hMdEnc->table_idx != table_idx ) { @@ -632,6 +673,7 @@ static ivas_error ivas_spar_enc_process( * MetaData encoder *-----------------------------------------------------------------------------------------*/ +#ifndef SBA_SPAR_HARM num_bands_bw = ivas_get_num_bands_from_bw_idx( bwidth ); if ( dtx_vad == 0 ) @@ -667,7 +709,12 @@ static ivas_error ivas_spar_enc_process( md_in_buf.num_bands = min( md_in_buf.num_bands, SPAR_DIRAC_SPLIT_START_BAND ); md_in_buf.dtx_vad = dtx_vad; +#endif +#ifdef SBA_SPAR_HARM + ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, bwidth, nchan_inp, sba_order ); +#else ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, &md_in_buf, hMetaData, dtx_silence_mode, sba_order ); +#endif if ( st_ivas->sba_mode == SBA_MODE_SPAR ) // VE2DB: this looks obsolete { @@ -706,7 +753,11 @@ static ivas_error ivas_spar_enc_process( Wscale_d[b] = 1.0f; for ( i = 1; i < nchan_inp; i++ ) { +#ifdef SBA_SPAR_HARM + Wscale_d[b] += cov_real[i][i][b] / max( EPSILON, cov_real[0][0][b] ); +#else Wscale_d[b] += md_in_buf.cov_real[i][i][b] / max( EPSILON, md_in_buf.cov_real[0][0][b] ); +#endif } Wscale_d[b] = Wscale_d[b] / ( 1.0f + (float) sba_order ); /*DirAC normalized signal variance sums to 1 + order*/ Wscale_d[b] = sqrtf( Wscale_d[b] ); diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index ed0d3f7e7e..45765eb97a 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -82,7 +82,7 @@ static void ivas_select_next_strat( ivas_strats_t prior_strat, ivas_strats_t cs[ 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_write_parameter_bitstream( ivas_spar_md_enc_state_t *hMdEnc, const int16_t nB, const int16_t bands_bw, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate, const int16_t dtx_silence_mode, const int16_t strat, const int16_t qsi, const int16_t planarCP ); +static 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 dtx_silence_mode, const int16_t strat, const int16_t qsi, const int16_t planarCP ); static ivas_error ivas_spar_md_enc_init( ivas_spar_md_enc_state_t *hMdEnc, const ENCODER_CONFIG_HANDLE hEncoderConfig, const int16_t sba_order ); 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 ); @@ -552,9 +552,20 @@ static void write_metadata_buffer( ivas_error ivas_spar_md_enc_process( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ +#ifdef SBA_SPAR_HARM + float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], +#else ivas_spar_md_enc_in_buf_t *pIn_buf, +#endif BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ +#ifdef SBA_SPAR_HARM + int16_t dtx_vad, + const int16_t bwidth, + const int16_t nchan_inp, +#else const int16_t dtx_silence_mode, +#endif const int16_t sba_order /* i : Ambisonic (SBA) order */ ) { @@ -563,8 +574,12 @@ ivas_error ivas_spar_md_enc_process( int16_t i, b, qsi, ndm, ndec, num_ch, num_quant_strats; int16_t j, planarCP; +#ifdef SBA_SPAR_HARM + int16_t k, num_bands, num_bands_full, num_bands_bw; +#else int16_t num_bands = pIn_buf->num_bands; int16_t dtx_vad = pIn_buf->dtx_vad; +#endif int16_t active_w, nchan_transport, dmx_switch, strat; int16_t nB, bands_bw, packed_ok = 0; ivas_strats_t cs[MAX_CODING_STRATS]; @@ -579,6 +594,42 @@ ivas_error ivas_spar_md_enc_process( active_w = hMdEnc->spar_md_cfg.active_w; nchan_transport = hMdEnc->spar_md_cfg.nchan_transport; +#ifdef SBA_SPAR_HARM + num_bands = ivas_get_num_bands_from_bw_idx( SPAR_CONFIG_BW ); + num_bands = min( num_bands, SPAR_DIRAC_SPLIT_START_BAND ); + num_bands_full = num_bands; + num_bands_bw = ivas_get_num_bands_from_bw_idx( bwidth ); + + if ( dtx_vad == 0 ) + { + for ( i = 0; i < nchan_inp; i++ ) + { + for ( j = 0; j < nchan_inp; j++ ) + { + cov_real[i][j] = cov_dtx_real[i][j]; + for ( k = num_bands_bw; k < IVAS_MAX_NUM_BANDS; k++ ) + { + cov_real[i][j][k] = 0; + } + } + } + } + else + { + for ( i = 0; i < nchan_inp; i++ ) + { + for ( j = 0; j < nchan_inp; j++ ) + { + cov_real[i][j] = cov_real[i][j]; + for ( k = num_bands_bw; k < IVAS_MAX_NUM_BANDS; k++ ) + { + cov_real[i][j][k] = 0; + } + } + } + } +#endif + if ( hEncoderConfig->ivas_total_brate == BRATE_SPAR_Q_STRAT && sba_order == 1 ) { /* make sure that qsi is always 0 (temporary bits are '00') */ @@ -592,10 +643,12 @@ ivas_error ivas_spar_md_enc_process( next_ind_start = hMetaData->next_ind; last_ind_start = hMetaData->last_ind; +#ifndef SBA_SPAR_HARM if ( hEncoderConfig->Opt_DTX_ON == 0 ) { dtx_vad = 1; } +#endif dmx_switch = 0; @@ -604,7 +657,11 @@ ivas_error ivas_spar_md_enc_process( nB = SPAR_DTX_BANDS; bands_bw = num_bands / nB; +#ifdef SBA_SPAR_HARM + ivas_band_mixer( cov_real, num_ch, &num_bands, bands_bw ); +#else ivas_band_mixer( pIn_buf->cov_real, num_ch, &num_bands, bands_bw ); +#endif } else { @@ -612,8 +669,13 @@ ivas_error ivas_spar_md_enc_process( bands_bw = 1; } +#ifdef SBA_SPAR_HARM + 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 ); +#else ivas_compute_spar_params( pIn_buf->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 ); +#endif for ( i = 0; i < num_ch; i++ ) { @@ -660,7 +722,11 @@ ivas_error ivas_spar_md_enc_process( if ( ndm != num_ch ) { +#ifdef SBA_SPAR_HARM + ivas_calc_c_p_coeffs( &hMdEnc->spar_md, cov_real, 0, hMdEnc->mixer_mat_local, num_ch, ndm, b, dtx_vad, 1, planarCP ); +#else ivas_calc_c_p_coeffs( &hMdEnc->spar_md, pIn_buf->cov_real, 0, hMdEnc->mixer_mat_local, num_ch, ndm, b, dtx_vad, 1, planarCP ); +#endif } } } @@ -753,7 +819,11 @@ ivas_error ivas_spar_md_enc_process( if ( ( ndm != num_ch ) && ( ndm != 1 ) ) { +#ifdef SBA_SPAR_HARM + ivas_calc_c_p_coeffs( &hMdEnc->spar_md, cov_real, 0, hMdEnc->mixer_mat, num_ch, ndm, b, dtx_vad, 0, planarCP ); +#else ivas_calc_c_p_coeffs( &hMdEnc->spar_md, pIn_buf->cov_real, 0, hMdEnc->mixer_mat, num_ch, ndm, b, dtx_vad, 0, planarCP ); +#endif #ifdef SPAR_HOA_DBG /*fprintf(stderr, "\n\n C coefficients: band %d\n", b); @@ -814,7 +884,11 @@ ivas_error ivas_spar_md_enc_process( /* band mixing */ if ( bands_bw > 1 ) { +#ifdef SBA_SPAR_HARM + ivas_band_mixing( hMdEnc, num_ch, num_bands, nchan_transport, num_bands_full ); +#else ivas_band_mixing( hMdEnc, num_ch, num_bands, nchan_transport, pIn_buf->num_bands ); +#endif } if ( hMdEnc->spar_md_cfg.gen_bs == 0 ) @@ -837,7 +911,8 @@ ivas_error ivas_spar_md_enc_process( { reset_indices_enc( &hMetaData_tmp, MAX_BITS_METADATA ); - ivas_write_parameter_bitstream( hMdEnc, num_bands, bands_bw, &hMetaData_tmp, hEncoderConfig->ivas_total_brate, dtx_silence_mode, strat, qsi, planarCP ); + ivas_write_spar_md_bitstream( hMdEnc, num_bands, bands_bw, &hMetaData_tmp, hEncoderConfig->ivas_total_brate, 0, strat, qsi, planarCP ); + if ( hMetaData->nb_bits_tot == bit_pos_start || hMetaData_tmp.nb_bits_tot < ( hMetaData->nb_bits_tot - bit_pos_start ) ) { write_metadata_buffer( &hMetaData_tmp, hMetaData, bit_pos_start, next_ind_start, last_ind_start ); @@ -1058,7 +1133,7 @@ ivas_error ivas_spar_md_enc_process( *-----------------------------------------------------------------------------------------*/ static void ivas_band_mixer( - float *cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t num_ch, int16_t *num_bands, int16_t red_band_fact ) @@ -1079,18 +1154,18 @@ static void ivas_band_mixer( avg_cov = 0.0f; for ( b = 0; b < red_band_fact; b++ ) { - avg_cov += cov_re[i][j][red_band_fact * k + b]; + avg_cov += cov_real[i][j][red_band_fact * k + b]; } - cov_re[i][j][k] = avg_cov; + cov_real[i][j][k] = avg_cov; } avg_cov = 0.0f; for ( b = 0; b < red_band_fact + rem_band; b++ ) { - avg_cov += cov_re[i][j][red_band_fact * ( *num_bands - 1 ) + b]; + avg_cov += cov_real[i][j][red_band_fact * ( *num_bands - 1 ) + b]; } - cov_re[i][j][*num_bands - 1] = avg_cov; + cov_real[i][j][*num_bands - 1] = avg_cov; } } @@ -1099,18 +1174,18 @@ static void ivas_band_mixer( /*-----------------------------------------------------------------------------------------* - * Function ivas_write_parameter_bitstream() + * Function ivas_write_spar_md_bitstream() * * Write MD parameters into bitstream *-----------------------------------------------------------------------------------------*/ -static void ivas_write_parameter_bitstream( +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 dtx_silence_mode, + const int16_t dtx_silence_mode, // VE2DB: it is always 0 -> remove it? const int16_t strat, const int16_t qsi, const int16_t planarCP ) diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 0ec6c21eea..a4e8e1142a 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -629,6 +629,7 @@ typedef struct ivas_enc_cov_handler_state_t } ivas_enc_cov_handler_state_t; +#ifndef SBA_SPAR_HARM typedef struct ivas_enc_cov_handler_in_buf_t { float *ppIn_FR_real[IVAS_SPAR_MAX_CH]; @@ -638,6 +639,7 @@ typedef struct ivas_enc_cov_handler_in_buf_t int16_t dtx_cov_flag; } ivas_enc_cov_handler_in_buf_t; +#endif /* SPAR MD structures */ typedef struct ivas_spar_md_enc_state_t @@ -658,6 +660,7 @@ typedef struct ivas_spar_md_enc_state_t } ivas_spar_md_enc_state_t; +#ifndef SBA_SPAR_HARM typedef struct ivas_spar_md_enc_in_buf_t { float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; @@ -665,7 +668,7 @@ typedef struct ivas_spar_md_enc_in_buf_t int16_t dtx_vad; } ivas_spar_md_enc_in_buf_t; - +#endif /* PCA structure */ typedef struct { -- GitLab From a5ac972ff1d37d5c612e431b5526c1190701fc7a Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 17 Oct 2022 18:46:27 +0200 Subject: [PATCH 2/4] rename evs_brs -> core_brs --- lib_com/ivas_spar_com.c | 9 ++++----- lib_com/ivas_stat_com.h | 3 ++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 44e63981a9..a93326ec9c 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -2139,8 +2139,8 @@ void ivas_spar_set_bitrate_config( for ( i = 0; i < pSpar_md_cfg->nchan_transport; i++ ) { - total_bits += (int16_t) ( ivas_spar_br_table_consts[table_idx].evs_brs[i][0] / FRAMES_PER_SEC ); - max_bits += (int16_t) ( ivas_spar_br_table_consts[table_idx].evs_brs[i][1] / FRAMES_PER_SEC ); + total_bits += (int16_t) ( ivas_spar_br_table_consts[table_idx].core_brs[i][0] / FRAMES_PER_SEC ); + max_bits += (int16_t) ( ivas_spar_br_table_consts[table_idx].core_brs[i][1] / FRAMES_PER_SEC ); } pSpar_md_cfg->tgt_bits_per_blk = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC ) - IVAS_FORMAT_SIGNALING_NBITS_SBA - SBA_PLANAR_BITS - SBA_ORDER_BITS - length - total_bits; @@ -2165,7 +2165,6 @@ void ivas_spar_set_bitrate_config( * Set SPAR bitrate distribution *-----------------------------------------------------------------------------------------*/ -// this function is not currently used but it is kept for future use void ivas_spar_bitrate_dist( int32_t core_brates_act[], /* o : bitrates per core-coder */ const int16_t nAvailBits, /* i : number of available bits */ @@ -2185,7 +2184,7 @@ void ivas_spar_bitrate_dist( sum_core_act_bits = 0; for ( i = 0; i < nchan_transport; i++ ) { - core_bits_act[i] = (int16_t) ( ivas_spar_br_table_consts[table_idx].evs_brs[i][0] / FRAMES_PER_SEC ); + core_bits_act[i] = (int16_t) ( ivas_spar_br_table_consts[table_idx].core_brs[i][0] / FRAMES_PER_SEC ); sum_core_act_bits += core_bits_act[i]; } @@ -2211,7 +2210,7 @@ void ivas_spar_bitrate_dist( { for ( i = 0; i < nchan_transport; i++ ) { - core_range_bits[i] = (int16_t) ( ( ivas_spar_br_table_consts[table_idx].evs_brs[i][0] - ivas_spar_br_table_consts[table_idx].evs_brs[i][1] ) / FRAMES_PER_SEC ); + core_range_bits[i] = (int16_t) ( ( ivas_spar_br_table_consts[table_idx].core_brs[i][0] - ivas_spar_br_table_consts[table_idx].evs_brs[i][1] ) / FRAMES_PER_SEC ); } overflow_bits = -residual_bits; diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index d8b10257e9..4b2c342f4f 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -373,11 +373,12 @@ typedef struct ivas_spar_br_table_t ivas_spar_pmx_strings_t dmx_str; int16_t active_w; int16_t tmode; - int32_t evs_brs[FOA_CHANNELS][3]; // VE: rename to core_brs + int32_t core_brs[FOA_CHANNELS][3]; int16_t q_lvls[MAX_QUANT_STRATS][NUM_MD_Q_COEFS_SET]; int16_t td_ducking; int16_t agc_bits_ch_idx; /* 0-3, Indicates core-coder channel index from which AGC bits have been taken from*/ int16_t usePlanarCoeff; + } ivas_spar_br_table_t; -- GitLab From be0a1a1f9622086935ecdd5990958e450b6d544c Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 17 Oct 2022 19:05:00 +0200 Subject: [PATCH 3/4] address few "VE2DB" comments; + editorial changes --- lib_com/ivas_prot.h | 1 - lib_dec/ivas_spar_md_dec.c | 6 +++++ lib_enc/ivas_spar_encoder.c | 51 ++++++++++++++++++++++--------------- lib_enc/ivas_spar_md_enc.c | 6 +++-- 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index eb79d71c38..84450e89a0 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3919,7 +3919,6 @@ ivas_error ivas_spar_md_enc_process( BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ #ifdef SBA_SPAR_HARM int16_t dtx_vad, - const int16_t bwidth, const int16_t nchan_inp, #else const int16_t dtx_silence_mode, diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 2c8d31ecc0..7f01f64c0f 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -665,9 +665,13 @@ void ivas_spar_md_dec_process( } #endif +#ifndef SBA_SPAR_HARM /* SPAR to DirAC and DirAC to SPAR conversion */ // VE2DB: -> "DirAC to SPAR conversion" only? if ( st_ivas->sba_mode == SBA_MODE_SPAR ) // VE2DB: this looks obsolete { +#else + /* SPAR to DirAC conversion */ +#endif ivas_spar_to_dirac( st_ivas, hMdDec, dtx_vad, num_bands_out ); /* set correct number of bands*/ @@ -676,7 +680,9 @@ void ivas_spar_md_dec_process( { nB = nB >> 1; } +#ifndef SBA_SPAR_HARM } +#endif /* expand DirAC MD to all time slots */ for ( i_ts = 1; i_ts < MAX_PARAM_SPATIAL_SUBFRAMES; i_ts++ ) diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 9cf149f2a3..6c17a5711e 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -397,21 +397,23 @@ static ivas_error ivas_spar_enc_process( float pcm_tmp[IVAS_SPAR_MAX_CH][L_FRAME48k * 2]; float *p_pcm_tmp[IVAS_SPAR_MAX_CH]; #ifdef SBA_SPAR_HARM - int16_t i, j, b, i_ts, input_frame, transient_det; + int16_t i, j, b, i_ts, input_frame, transient_det, dtx_vad; #else int16_t i, j, k, b, i_ts, input_frame, num_bands_bw; -#endif int16_t dtx_vad, dtx_cov_flag, dtx_silence_mode; +#endif int32_t ivas_total_brate, input_Fs; #ifndef SBA_SPAR_HARM ivas_enc_cov_handler_in_buf_t cov_in_buf; #endif float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; -#ifndef SBA_SPAR_HARM +#ifdef SBA_SPAR_HARM + int16_t nchan_inp, nchan_transport, sba_order; +#else ivas_spar_md_enc_in_buf_t md_in_buf; -#endif int16_t nchan_inp, nchan_transport, bwidth, sba_order; +#endif int16_t table_idx; int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; ivas_error error; @@ -446,7 +448,9 @@ static ivas_error ivas_spar_enc_process( mvr2r( data_f[HOA_keep_ind[i]], data_f[i], input_frame ); } +#ifndef SBA_SPAR_HARM table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); +#endif /*-----------------------------------------------------------------------------------------* * Transient detector @@ -623,19 +627,18 @@ static ivas_error ivas_spar_enc_process( } } - +#ifndef SBA_SPAR_HARM /*-----------------------------------------------------------------------------------------* * Pre-proc flags *-----------------------------------------------------------------------------------------*/ /* use just VAD function to get VAD flags */ -#ifndef SBA_SPAR_HARM dtx_vad = ( hEncoderConfig->Opt_DTX_ON == 1 ) ? front_vad_flag : 1; -#endif dtx_cov_flag = ( dtx_vad == 1 ) ? 0 : 1; dtx_silence_mode = 0; // VE2DB: this variable is always 0 - please review or remove it bwidth = ivas_get_bw_idx_from_sample_rate( input_Fs ); bwidth = min( bwidth, hEncoderConfig->max_bwidth ); +#endif /*-----------------------------------------------------------------------------------------* * Covariance process @@ -661,19 +664,33 @@ static ivas_error ivas_spar_enc_process( ivas_enc_cov_handler_process( hSpar->hCovEnc, &cov_in_buf, cov_real, cov_dtx_real, hSpar->hFbMixer->pFb, 0, hSpar->hFbMixer->pFb->filterbank_num_bands ); #endif + /*-----------------------------------------------------------------------------------------* + * Set SPAR bitrates + *-----------------------------------------------------------------------------------------*/ + +#ifdef SBA_SPAR_HARM + table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); +#endif + if ( hSpar->hMdEnc->table_idx != table_idx ) { hSpar->hMdEnc->table_idx = table_idx; ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, SPAR_DIRAC_SPLIT_START_BAND ); } +#ifdef SBA_SPAR_HARM + nchan_transport = st_ivas->nchan_transport; +#else nchan_transport = hSpar->hMdEnc->spar_md_cfg.nchan_transport; +#endif /*-----------------------------------------------------------------------------------------* * MetaData encoder *-----------------------------------------------------------------------------------------*/ -#ifndef SBA_SPAR_HARM +#ifdef SBA_SPAR_HARM + ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order ); +#else num_bands_bw = ivas_get_num_bands_from_bw_idx( bwidth ); if ( dtx_vad == 0 ) @@ -709,14 +726,13 @@ static ivas_error ivas_spar_enc_process( md_in_buf.num_bands = min( md_in_buf.num_bands, SPAR_DIRAC_SPLIT_START_BAND ); md_in_buf.dtx_vad = dtx_vad; -#endif -#ifdef SBA_SPAR_HARM - ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, bwidth, nchan_inp, sba_order ); -#else + ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, &md_in_buf, hMetaData, dtx_silence_mode, sba_order ); #endif +#ifndef SBA_SPAR_HARM if ( st_ivas->sba_mode == SBA_MODE_SPAR ) // VE2DB: this looks obsolete +#endif { float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; @@ -739,13 +755,9 @@ static ivas_error ivas_spar_enc_process( diffuseness[b] = 1.0f - hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0]; } - if ( ( d_start_band >= 6 ) && ( dtx_vad == 1 ) ) + if ( d_start_band >= 6 && dtx_vad == 1 ) { - for ( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) - { - hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_re[i] = - hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_quant_re[i]; - } + mvr2r( hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_quant_re, hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_re, IVAS_SPAR_MAX_CH - 1 ); } for ( b = d_start_band; b < d_end_band; b++ ) @@ -764,8 +776,7 @@ 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, 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, sba_order, dtx_vad, Wscale_d ); } diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 45765eb97a..7ae45903d5 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -561,7 +561,6 @@ ivas_error ivas_spar_md_enc_process( BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ #ifdef SBA_SPAR_HARM int16_t dtx_vad, - const int16_t bwidth, const int16_t nchan_inp, #else const int16_t dtx_silence_mode, @@ -575,7 +574,7 @@ ivas_error ivas_spar_md_enc_process( int16_t i, b, qsi, ndm, ndec, num_ch, num_quant_strats; int16_t j, planarCP; #ifdef SBA_SPAR_HARM - int16_t k, num_bands, num_bands_full, num_bands_bw; + int16_t k, bwidth, num_bands, num_bands_full, num_bands_bw; #else int16_t num_bands = pIn_buf->num_bands; int16_t dtx_vad = pIn_buf->dtx_vad; @@ -595,6 +594,9 @@ ivas_error ivas_spar_md_enc_process( nchan_transport = hMdEnc->spar_md_cfg.nchan_transport; #ifdef SBA_SPAR_HARM + bwidth = ivas_get_bw_idx_from_sample_rate( hEncoderConfig->input_Fs ); + bwidth = min( bwidth, hEncoderConfig->max_bwidth ); + num_bands = ivas_get_num_bands_from_bw_idx( SPAR_CONFIG_BW ); num_bands = min( num_bands, SPAR_DIRAC_SPLIT_START_BAND ); num_bands_full = num_bands; -- GitLab From 86d4c72ac78260a7150e264f339a68465f4be1a6 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 17 Oct 2022 19:27:59 +0200 Subject: [PATCH 4/4] remove empty lines --- lib_com/options.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 0e4dc4549e..ff4cf5f346 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -149,12 +149,10 @@ #define FIX_I13_TCX_TNS_ISSUE /* Issue 13: Fix reported artifacts. Bug in TNS with TCX5 */ #define FIX_TCX10_STEREO_PROC /* Issue 11 */ #define CORECODER_BITRATE_SWITCHING /* Issue 133: support bitrate switching in core-coder */ - #define ISM_BITRATE_SWITCHING /* Issue 115: Support for Bitrate Switching in ISM */ +#define SBA_SPAR_HARM /* Issue 92: maintenance of the SBA SPAR functions */ -#define SBA_SPAR_HARM /* maintenance of the SBA SPAR functions */ - /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ -- GitLab