From 1cc2ac306701fead017cea1cc6eff3b0c9670da0 Mon Sep 17 00:00:00 2001 From: Shanush Prema Thasarathan Date: Tue, 20 Sep 2022 18:19:57 +1000 Subject: [PATCH] Pointer variables clean up for ivas_quantise_real_values() and ivas_deindex_real_index() These functions were originally written to quantise/unquantise two dimensional arrays but currently they are being used to quantise either one variable at a time OR one dimensional arrays. Hence code has been simplified to handle both one dimensional arrays and single variables, removing unnecessary pointer manipulation --- lib_com/ivas_prot.h | 32 +++-- lib_com/ivas_spar_com_quant_util.c | 59 +++++++-- lib_com/options.h | 1 + lib_dec/ivas_spar_md_dec.c | 186 ++++++++++++++++++++++++++--- lib_enc/ivas_spar_md_enc.c | 178 ++++++++++++++++++++++----- 5 files changed, 387 insertions(+), 69 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index c4e93a9545..e32e7bff96 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4242,17 +4242,31 @@ int16_t ivas_map_num_drct_r_to_idx( const int16_t num_quant_points_drct_r ); int16_t ivas_map_num_decd_r_to_idx( const int16_t num_quant_points_decd_r ); /* Quantization utilities */ -void ivas_quantise_real_values( - float **values, - const int16_t q_levels, - const float min_value, - const float max_value, - int16_t **index, - float **quant, - const int16_t dim1, - const int16_t dim2 +void ivas_quantise_real_values( +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + const float *values, +#else + float **values, +#endif + const int16_t q_levels, + const float min_value, + const float max_value, +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + int16_t *index, + float *quant, +#else + int16_t **index, + float **quant, +#endif +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + const int16_t dim +#else + const int16_t dim1, + const int16_t dim2 +#endif ); + void ivas_spar_get_uniform_quant_strat( ivas_spar_md_com_cfg *pSpar_md_com_cfg, const int16_t table_idx diff --git a/lib_com/ivas_spar_com_quant_util.c b/lib_com/ivas_spar_com_quant_util.c index 5755f05324..4feca8c98a 100644 --- a/lib_com/ivas_spar_com_quant_util.c +++ b/lib_com/ivas_spar_com_quant_util.c @@ -41,7 +41,7 @@ #include "ivas_rom_com.h" #include #include "wmops.h" - +#ifndef QUANTISE_REAL_FCN_CLEAN_UP /*-----------------------------------------------------------------------------------------* * Function ivas_limit_values() * @@ -56,7 +56,6 @@ static void ivas_limit_values( const int16_t dim2 ) { int16_t i, j; - for ( i = 0; i < dim1; i++ ) { for ( j = 0; j < dim2; j++ ) @@ -64,48 +63,73 @@ static void ivas_limit_values( ppValues[i][j] = max( min_value, min( ppValues[i][j], max_value ) ); } } - return; } - +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_quantise_real_values() * * Quantize real values *-----------------------------------------------------------------------------------------*/ - void ivas_quantise_real_values( +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + const float *values, +#else float **values, +#endif const int16_t q_levels, const float min_value, const float max_value, +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + int16_t *index, + float *quant, +#else int16_t **index, float **quant, +#endif +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + const int16_t dim +#else const int16_t dim1, - const int16_t dim2 ) + const int16_t dim2 +#endif +) { +#ifndef QUANTISE_REAL_FCN_CLEAN_UP int16_t i, j; +#else + int16_t i; +#endif float q_step, one_by_q_step; - if ( q_levels == 1 ) { +#ifndef QUANTISE_REAL_FCN_CLEAN_UP for ( i = 0; i < dim1; i++ ) { for ( j = 0; j < dim2; j++ ) { + quant[i][j] = 0; index[i][j] = 0; } } +#else + for ( i = 0; i < dim; i++ ) + { + quant[i] = 0; + index[i] = 0; + } +#endif } else if ( q_levels && max_value != min_value ) { +#ifndef QUANTISE_REAL_FCN_CLEAN_UP ivas_limit_values( values, min_value, max_value, dim1, dim2 ); - +#endif q_step = ( max_value - min_value ) / ( q_levels - 1 ); one_by_q_step = ( q_levels - 1 ) / ( max_value - min_value ); - +#ifndef QUANTISE_REAL_FCN_CLEAN_UP for ( i = 0; i < dim1; i++ ) { for ( j = 0; j < dim2; j++ ) @@ -114,9 +138,19 @@ void ivas_quantise_real_values( quant[i][j] = index[i][j] * q_step; } } +#else + float val; + for ( i = 0; i < dim; i++ ) + { + val = max( min_value, min( values[i], max_value ) ); + index[i] = (int16_t) round( one_by_q_step * val ); + quant[i] = index[i] * q_step; + } +#endif } else { +#ifndef QUANTISE_REAL_FCN_CLEAN_UP for ( i = 0; i < dim1; i++ ) { for ( j = 0; j < dim2; j++ ) @@ -124,8 +158,13 @@ void ivas_quantise_real_values( quant[i][j] = values[i][j]; } } +#else + for ( i = 0; i < dim; i++ ) + { + quant[i] = values[i]; + } +#endif } - return; } diff --git a/lib_com/options.h b/lib_com/options.h index 54d2700014..db358692a9 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -150,6 +150,7 @@ #define SBA_INTERN_CONFIG_FIX_HOA2 /* Issue 99 : Fix for incorrect internal_config when output format is HOA2 or FOA*/ #define FIX_I98_HANDLES_TO_NULL /* Issue 98: do the setting of all handles to NULL in one place */ +#define QUANTISE_REAL_FCN_CLEAN_UP /*Clean up the ivas_quantise_real_values() function*/ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index cdc6ab57a6..36954e110c 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -82,9 +82,11 @@ static void ivas_spar_md_fill_invalid_bands( ivas_spar_dec_matrices_t *pSpar_coe static ivas_error ivas_spar_set_dec_config( ivas_spar_md_dec_state_t *hMdDec, const int16_t nchan_transport, float *pFC ); static void ivas_parse_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, Decoder_State *st, const int16_t bw, const int16_t num_bands, int16_t *num_dmx_per_band, int16_t *num_dec_per_band ); - +#ifdef QUANTISE_REAL_FCN_CLEAN_UP +static ivas_error ivas_deindex_real_index( const int16_t *index, const int16_t q_levels, const float min_value, const float max_value, float *quant, const int16_t num_ch_dim2 ); +#else static ivas_error ivas_deindex_real_index( int16_t **index, const int16_t q_levels, const float min_value, const float max_value, float **quant, const int16_t num_ch, const int16_t dim2 ); - +#endif static void ivas_spar_dec_parse_md_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, int16_t *nB, int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, const int16_t use_planar_coeff, const int16_t sba_inactive_mode ); @@ -1601,23 +1603,31 @@ static void ivas_spar_dec_parse_md_bs( for ( i = 0; i < *nB; i++ ) { int16_t ii, jj; +#ifndef QUANTISE_REAL_FCN_CLEAN_UP int16_t *index_scratch[IVAS_SPAR_P_LOWERTRI]; float *quant_scratch[IVAS_SPAR_P_LOWERTRI]; +#endif int16_t ndec = hMdDec->spar_md_cfg.num_decorr_per_band[( *bands_bw ) * i]; int16_t ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[( *bands_bw ) * i]; +#ifndef QUANTISE_REAL_FCN_CLEAN_UP int16_t **index = (int16_t **) &index_scratch[0]; float **quant = (float **) &quant_scratch[0]; float coeff_decd[IVAS_SPAR_MAX_CH - 1]; float coeff_decx_re[IVAS_SPAR_P_LOWERTRI]; + int16_t decx_index_re[IVAS_SPAR_P_LOWERTRI]; int16_t pred_index_re[IVAS_SPAR_MAX_CH - 1]; int16_t drct_index_re[IVAS_SPAR_MAX_C_COEFF]; int16_t decd_index_re[IVAS_SPAR_MAX_CH - 1]; - int16_t decx_index_re[IVAS_SPAR_P_LOWERTRI]; +#else + float quant[IVAS_SPAR_MAX_C_COEFF]; +#endif +#ifndef QUANTISE_REAL_FCN_CLEAN_UP for ( j = 0; j < ndm + ndec - 1; j++ ) { pred_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j]; } + for ( j = 0; j < ndec * ( ndm - 1 ); j++ ) { drct_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].drct_index_re[j]; @@ -1626,10 +1636,14 @@ static void ivas_spar_dec_parse_md_bs( { decd_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].decd_index_re[j]; } - +#endif +#ifndef QUANTISE_REAL_FCN_CLEAN_UP index[0] = &pred_index_re[0]; quant[0] = &hMdDec->spar_md.band_coeffs[i].pred_re[0]; - +#endif +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].pred_index_re, qs.PR.q_levels[0], qs.PR.min, qs.PR.max, hMdDec->spar_md.band_coeffs[i].pred_re, ndm + ndec - 1 ); +#else ivas_deindex_real_index( index, qs.PR.q_levels[0], qs.PR.min, qs.PR.max, quant, 1, ndm + ndec - 1 ); for ( ii = 0; ii < ndec; ii++ ) { @@ -1638,7 +1652,19 @@ static void ivas_spar_dec_parse_md_bs( hMdDec->spar_md.band_coeffs[i].C_re[ii][jj] = 0; } } +#endif + j = 0; +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + for ( ii = 0; ii < ndec; ii++ ) + { + for ( jj = 0; jj < ndm - 1; jj++ ) + { + quant[j] = hMdDec->spar_md.band_coeffs[i].C_re[ii][jj]; + j++; + } + } +#else for ( ii = 0; ii < ndec; ii++ ) { for ( jj = 0; jj < ndm - 1; jj++ ) @@ -1648,29 +1674,76 @@ static void ivas_spar_dec_parse_md_bs( j++; } } +#endif +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].drct_index_re, qs.C.q_levels[0], qs.C.min, qs.C.max, quant, ndec * ( ndm - 1 ) ); +#else ivas_deindex_real_index( index, qs.C.q_levels[0], qs.C.min, qs.C.max, quant, ndec * ( ndm - 1 ), 1 ); - +#endif +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + j = 0; + for ( ii = 0; ii < ndec; ii++ ) + { + for ( jj = 0; jj < ndm - 1; jj++ ) + { + hMdDec->spar_md.band_coeffs[i].C_re[ii][jj] = quant[j]; + j++; + } + } +#endif +#ifndef QUANTISE_REAL_FCN_CLEAN_UP index[0] = &decd_index_re[0]; quant[0] = &coeff_decd[0]; +#endif +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].decd_index_re, qs.P_r.q_levels[0], qs.P_r.min, qs.P_r.max, hMdDec->spar_md.band_coeffs[i].P_re, ndm + ndec - 1 ); +#else ivas_deindex_real_index( index, qs.P_r.q_levels[0], qs.P_r.min, qs.P_r.max, quant, 1, ndm + ndec - 1 ); - +#endif +#ifndef QUANTISE_REAL_FCN_CLEAN_UP index[0] = &decx_index_re[0]; quant[0] = &coeff_decx_re[0]; +#endif +#ifndef QUANTISE_REAL_FCN_CLEAN_UP ivas_deindex_real_index( index, qs.P_c.q_levels[0], qs.P_c.min, qs.P_c.max, quant, 1, ndec * ( ndec - 1 ) >> 2 ); - +#endif +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + /* Store prior coefficient indices */ + for ( j = 0; j < ndm + ndec - 1; j++ ) + { + hMdDec->spar_md_prev.band_coeffs_idx[i].pred_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j]; + } +#else /* Store prior coefficient indices */ for ( j = 0; j < ndm + ndec - 1; j++ ) { hMdDec->spar_md_prev.band_coeffs_idx[i].pred_index_re[j] = pred_index_re[j]; } +#endif +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + for ( j = 0; j < ndec * ( ndm - 1 ); j++ ) + { + hMdDec->spar_md_prev.band_coeffs_idx[i].drct_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].drct_index_re[j]; + } +#else for ( j = 0; j < ndec * ( ndm - 1 ); j++ ) { hMdDec->spar_md_prev.band_coeffs_idx[i].drct_index_re[j] = drct_index_re[j]; } +#endif +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + for ( j = 0; j < ndec; j++ ) + { + hMdDec->spar_md_prev.band_coeffs_idx[i].decd_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].decd_index_re[j]; + } +#else for ( j = 0; j < ndec; j++ ) { hMdDec->spar_md_prev.band_coeffs_idx[i].decd_index_re[j] = decd_index_re[j]; } +#endif + +#ifndef QUANTISE_REAL_FCN_CLEAN_UP for ( k = 0; k < ndec; k++ ) { hMdDec->spar_md.band_coeffs[i].P_re[k] = 0; @@ -1680,7 +1753,7 @@ static void ivas_spar_dec_parse_md_bs( /* Don't bother adding in the decx parameters */ hMdDec->spar_md.band_coeffs[i].P_re[j] = coeff_decd[j]; } - +#endif hMdDec->valid_bands[i] |= ( do_diff[i] == 0 ) ? 1 : 0; } } @@ -2324,35 +2397,58 @@ static void ivas_spar_unquant_dtx_indicies( { int16_t i, b; int16_t q_lvl; +#ifndef QUANTISE_REAL_FCN_CLEAN_UP float **ppVal, *pVal, val; int16_t **ppIdx, *pIdx, idx; +#else + float val; + int16_t idx; +#endif float pr_min_max[2]; pr_min_max[0] = pSpar_md->min_max[0]; pr_min_max[1] = pSpar_md->min_max[1]; - +#ifndef QUANTISE_REAL_FCN_CLEAN_UP ppVal = (float **) &pVal; ppIdx = (int16_t **) &pIdx; ppVal[0] = (float *) &val; ppIdx[0] = (int16_t *) &idx; - +#endif for ( b = 0; b < nB; b++ ) { for ( i = 0; i < FOA_CHANNELS - 1; i++ ) { q_lvl = dtx_pr_real_q_levels[ndm_per_band[bw * b] - 1][i]; +#ifndef QUANTISE_REAL_FCN_CLEAN_UP ppIdx[0][0] = pSpar_md->band_coeffs_idx[b].pred_index_re[i]; +#else + idx = pSpar_md->band_coeffs_idx[b].pred_index_re[i]; +#endif +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + ivas_deindex_real_index( &idx, q_lvl, pr_min_max[0], pr_min_max[1], &val, 1 ); + pSpar_md->band_coeffs[b].pred_re[i] = val; +#else ivas_deindex_real_index( ppIdx, q_lvl, pr_min_max[0], pr_min_max[1], ppVal, 1, 1 ); pSpar_md->band_coeffs[b].pred_re[i] = ppVal[0][0]; +#endif } for ( i = 0; i < FOA_CHANNELS - ndm_per_band[bw * b]; i++ ) { q_lvl = dtx_pd_real_q_levels[ndm_per_band[bw * b] - 1][i]; +#ifndef QUANTISE_REAL_FCN_CLEAN_UP ppIdx[0][0] = pSpar_md->band_coeffs_idx[b].decd_index_re[i]; +#else + idx = pSpar_md->band_coeffs_idx[b].decd_index_re[i]; +#endif +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + ivas_deindex_real_index( &idx, q_lvl, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &val, 1 ); + pSpar_md->band_coeffs[b].P_re[i] = val; +#else ivas_deindex_real_index( ppIdx, q_lvl, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], ppVal, 1, 1 ); pSpar_md->band_coeffs[b].P_re[i] = ppVal[0][0]; +#endif } } @@ -2375,19 +2471,25 @@ static void ivas_parse_parameter_bitstream_dtx( int16_t *num_dec_per_band ) { int16_t i, j; +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + float val; + int16_t idx; +#else float **ppVal, *pVal, val; int16_t **ppIdx, *pIdx, idx; +#endif float pr_min_max[2]; int16_t pr_q_lvls, pr, pd, pd_q_lvls, pr_pd_bits; int16_t pr_q_lvls1, pr_q_lvls2, pr_idx1, pr_idx2, pr_pr_bits; int16_t zero_pad_bits, sid_bits_len; sid_bits_len = st0->next_bit_pos; +#ifndef QUANTISE_REAL_FCN_CLEAN_UP ppVal = (float **) &pVal; ppIdx = (int16_t **) &pIdx; ppVal[0] = (float *) &val; ppIdx[0] = (int16_t *) &idx; - +#endif pr_min_max[0] = pSpar_md->min_max[0]; pr_min_max[1] = pSpar_md->min_max[1]; @@ -2427,16 +2529,26 @@ static void ivas_parse_parameter_bitstream_dtx( pr = (int16_t) floor( value / pd_q_lvls ); pd = value - pr * pd_q_lvls; - +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + val = dtx_pd_real_min_max[0]; + ivas_quantise_real_values( &val, pd_q_lvls, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &idx, &val, 1 ); +#else ppVal[0][0] = dtx_pd_real_min_max[0]; ivas_quantise_real_values( ppVal, pd_q_lvls, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], ppIdx, ppVal, 1, 1 ); +#endif +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + pd = pd + idx; + val = pr_min_max[0]; + ivas_quantise_real_values( &val, pr_q_lvls, pr_min_max[0], pr_min_max[1], &idx, &val, 1 ); + pr = pr + idx; +#else pd = pd + ppIdx[0][0]; ppVal[0][0] = pr_min_max[0]; ivas_quantise_real_values( ppVal, pr_q_lvls, pr_min_max[0], pr_min_max[1], ppIdx, ppVal, 1, 1 ); - pr = pr + ppIdx[0][0]; +#endif if ( ( j + 1 ) <= ndec ) { @@ -2456,7 +2568,17 @@ static void ivas_parse_parameter_bitstream_dtx( pr_idx2 = (int16_t) floor( value / pr_q_lvls1 ); pr_idx1 = value - pr_idx2 * pr_q_lvls1; +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + val = pr_min_max[0]; + ivas_quantise_real_values( &val, pr_q_lvls1, pr_min_max[0], pr_min_max[1], &idx, &val, 1 ); + pr_idx1 += idx; + + val = pr_min_max[0]; + ivas_quantise_real_values( &val, pr_q_lvls2, pr_min_max[0], pr_min_max[1], &idx, &val, 1 ); + + pr_idx2 += idx; +#else ppVal[0][0] = pr_min_max[0]; ivas_quantise_real_values( ppVal, pr_q_lvls1, pr_min_max[0], pr_min_max[1], ppIdx, ppVal, 1, 1 ); @@ -2466,7 +2588,7 @@ static void ivas_parse_parameter_bitstream_dtx( ivas_quantise_real_values( ppVal, pr_q_lvls2, pr_min_max[0], pr_min_max[1], ppIdx, ppVal, 1, 1 ); pr_idx2 += ppIdx[0][0]; - +#endif pSpar_md->band_coeffs_idx[i].pred_index_re[pr_idx_1 - 1] = pr_idx1; pSpar_md->band_coeffs_idx[i].pred_index_re[pr_idx_2 - 1] = pr_idx2; } @@ -2495,15 +2617,32 @@ static void ivas_parse_parameter_bitstream_dtx( *-----------------------------------------------------------------------------------------*/ static ivas_error ivas_deindex_real_index( +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + const int16_t *index, +#else int16_t **index, +#endif const int16_t q_levels, const float min_value, const float max_value, +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + float *quant, +#else float **quant, +#endif +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + const int16_t dim +#else const int16_t num_ch, - const int16_t dim2 ) + const int16_t dim2 +#endif +) { +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + int16_t i; +#else int16_t i, j; +#endif float q_step; if ( q_levels == 0 ) @@ -2513,6 +2652,12 @@ static ivas_error ivas_deindex_real_index( if ( q_levels == 1 ) { +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + for ( i = 0; i < dim; i++ ) + { + quant[i] = 0; + } +#else for ( i = 0; i < num_ch; i++ ) { for ( j = 0; j < dim2; j++ ) @@ -2520,11 +2665,17 @@ static ivas_error ivas_deindex_real_index( quant[i][j] = 0; } } +#endif } else { q_step = ( max_value - min_value ) / ( q_levels - 1 ); - +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + for ( i = 0; i < dim; i++ ) + { + quant[i] = index[i] * q_step; + } +#else for ( i = 0; i < num_ch; i++ ) { for ( j = 0; j < dim2; j++ ) @@ -2532,6 +2683,7 @@ static ivas_error ivas_deindex_real_index( quant[i][j] = index[i][j] * q_step; } } +#endif } return IVAS_ERR_OK; diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index de0c37c925..78028deef2 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -85,11 +85,16 @@ static void ivas_store_prior_coeffs( ivas_spar_md_enc_state_t *hMdEnc, const int static void ivas_write_parameter_bitstream( ivas_spar_md_enc_state_t *hMdEnc, const int16_t nB, const int16_t bands_bw, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate, const int16_t dtx_silence_mode, const int16_t strat, const int16_t qsi, const int16_t planarCP ); static ivas_error ivas_spar_md_enc_init( ivas_spar_md_enc_state_t *hMdEnc, const ENCODER_CONFIG_HANDLE hEncoderConfig, const int16_t sba_order ); - +#ifdef QUANTISE_REAL_FCN_CLEAN_UP +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 ); +#else static void ivas_spar_quant_pred_coeffs_dtx( ivas_spar_md_t *pSpar_md, float **ppValues, const int16_t ndm, int16_t **ppIndex, const int16_t dim1, float **ppQuant ); - +#endif +#ifdef QUANTISE_REAL_FCN_CLEAN_UP +static void ivas_quant_p_per_band_dtx( float *pP_mat, const int16_t num_dec, const int16_t num_dmx, int16_t *ppIdx_pd, float *pP_out, const int16_t num_ch ); +#else static void ivas_quant_p_per_band_dtx( float **ppP_mat, const int16_t num_dec, const int16_t num_dmx, int16_t *ppIdx_pd, float **ppP_out, const int16_t num_ch ); - +#endif static void ivas_write_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, BSTR_ENC_HANDLE hMetaData, int16_t *num_dmx, int16_t *num_dec, const int16_t num_bands ); static void ivas_quant_p_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t num_ch ); @@ -721,39 +726,51 @@ ivas_error ivas_spar_md_enc_process( } else { +#ifndef QUANTISE_REAL_FCN_CLEAN_UP float **ppPred_re, **ppPred_quant, *pPred_re, *pPred_quant; int16_t **ppPred_idx, *pPred_re_idx; +#endif if ( ndm != num_ch ) { +#ifndef QUANTISE_REAL_FCN_CLEAN_UP float *P_re[IVAS_SPAR_MAX_CH - 1], *P_re_quant[IVAS_SPAR_MAX_CH - 1]; float **ppP_re = (float **) &P_re[0]; float **ppP_re_quant = (float **) &P_re_quant[0]; +#endif +#ifndef QUANTISE_REAL_FCN_CLEAN_UP int16_t *ppP_idx = &hMdEnc->spar_md.band_coeffs_idx[b].decd_index_re[0]; for ( i = 0; i < ndec; i++ ) { + ppP_re[i] = hMdEnc->spar_md.band_coeffs[b].P_re; ppP_re_quant[i] = hMdEnc->spar_md.band_coeffs[b].P_quant_re; } - +#endif +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + 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 ); +#else ivas_quant_p_per_band_dtx( ppP_re, ndec, ndm, ppP_idx, ppP_re_quant, num_ch ); +#endif } - +#ifndef QUANTISE_REAL_FCN_CLEAN_UP ppPred_idx = (int16_t **) &pPred_re_idx; ppPred_re = (float **) &pPred_re; ppPred_quant = (float **) &pPred_quant; - ppPred_re[0] = hMdEnc->spar_md.band_coeffs[b].pred_re; ppPred_idx[0] = hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re; ppPred_quant[0] = hMdEnc->spar_md.band_coeffs[b].pred_quant_re; - +#endif for ( i = 0; i < num_ch - 1; i++ ) { hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i] = 0; } - +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + 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 ); +#else ivas_spar_quant_pred_coeffs_dtx( &hMdEnc->spar_md, ppPred_re, ndm, ppPred_idx, num_ch - 1, ppPred_quant ); +#endif } } @@ -1525,27 +1542,44 @@ static void ivas_store_prior_coeffs( static void ivas_spar_quant_pred_coeffs_dtx( ivas_spar_md_t *pSpar_md, +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + const float *pValues, +#else float **ppValues, +#endif const int16_t ndm, +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + int16_t *pIndex, +#else int16_t **ppIndex, +#endif const int16_t dim1, - float **ppQuant ) +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + float *pQuant +#else + float **ppQuant +#endif +) { int16_t i; int16_t q_lvl; +#ifndef QUANTISE_REAL_FCN_CLEAN_UP float *pVal, val, **ppVal; int16_t *pIdx, idx, **ppIdx; +#endif float pr_min_max[2]; +#ifndef QUANTISE_REAL_FCN_CLEAN_UP ppVal = (float **) &pVal; ppIdx = (int16_t **) &pIdx; ppVal[0] = (float *) &val; ppIdx[0] = (int16_t *) &idx; - +#endif pr_min_max[0] = pSpar_md->min_max[0]; pr_min_max[1] = pSpar_md->min_max[1]; +#ifndef QUANTISE_REAL_FCN_CLEAN_UP for ( i = 0; i < dim1; i++ ) { q_lvl = dtx_pr_real_q_levels[ndm - 1][i]; @@ -1555,7 +1589,13 @@ static void ivas_spar_quant_pred_coeffs_dtx( ppIndex[0][i] = ppIdx[0][0]; ppQuant[0][i] = ppVal[0][0]; } - +#else + for ( i = 0; i < dim1; i++ ) + { + q_lvl = dtx_pr_real_q_levels[ndm - 1][i]; + ivas_quantise_real_values( &pValues[i], q_lvl, pr_min_max[0], pr_min_max[1], &pIndex[i], &pQuant[i], 1 ); + } +#endif return; } @@ -1567,31 +1607,48 @@ static void ivas_spar_quant_pred_coeffs_dtx( *-----------------------------------------------------------------------------------------*/ static void ivas_quant_p_per_band_dtx( +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + float *pP_mat, +#else float **ppP_mat, +#endif const int16_t num_dec, const int16_t num_dmx, int16_t *ppIdx_pd, +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + float *pP_out, +#else float **ppP_out, +#endif const int16_t num_ch ) { int16_t i; +#ifndef QUANTISE_REAL_FCN_CLEAN_UP float **ppPd, *pPd, pd; int16_t **ppIdx, *pIdx, idx; +#endif int16_t dim = num_ch - num_dmx; - +#ifndef QUANTISE_REAL_FCN_CLEAN_UP ppPd = (float **) &pPd; ppIdx = (int16_t **) &pIdx; ppPd[0] = (float *) &pd; ppIdx[0] = (int16_t *) &idx; - +#endif if ( num_dec == num_ch - 1 ) { for ( i = 0; i < dim; i++ ) { +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + if ( pP_mat[i] < pr_boost_range[1] && pP_mat[i] > pr_boost_range[0] ) + { + pP_mat[i] = pr_boost_range[1]; + } +#else if ( ppP_mat[i][i] < pr_boost_range[1] && ppP_mat[i][i] > pr_boost_range[0] ) { ppP_mat[i][i] = pr_boost_range[1]; } +#endif } } @@ -1599,21 +1656,23 @@ static void ivas_quant_p_per_band_dtx( { assert( !"Not Supported!" ); } - +#ifndef QUANTISE_REAL_FCN_CLEAN_UP for ( i = 0; i < dim; i++ ) { ppPd[0][0] = ppP_mat[i][i]; - ivas_quantise_real_values( ppPd, dtx_pd_real_q_levels[num_ch - num_dec - 1][i], dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], ppIdx, ppPd, 1, 1 ); - ppP_out[i][i] = ppPd[0][0]; ppIdx_pd[i] = ppIdx[0][0]; } - +#else + for ( i = 0; i < dim; i++ ) + { + ivas_quantise_real_values( &pP_mat[i], dtx_pd_real_q_levels[num_ch - num_dec - 1][i], dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &ppIdx_pd[i], &pP_out[i], 1 ); + } +#endif return; } - /*-----------------------------------------------------------------------------------------* * Function ivas_write_parameter_bitstream_dtx() * @@ -1628,18 +1687,23 @@ static void ivas_write_parameter_bitstream_dtx( const int16_t num_bands ) { int16_t i, j; +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + float val; + int16_t idx; +#else float **ppVal, *pVal, val; int16_t **ppIdx, *pIdx, idx; +#endif float pr_min_max[2]; int16_t zero_pad_bits, sid_bits_len; sid_bits_len = hMetaData->nb_bits_tot; - +#ifndef QUANTISE_REAL_FCN_CLEAN_UP ppVal = (float **) &pVal; ppIdx = (int16_t **) &pIdx; ppVal[0] = (float *) &val; ppIdx[0] = (int16_t *) &idx; - +#endif pr_min_max[0] = pSpar_md->min_max[0]; pr_min_max[1] = pSpar_md->min_max[1]; @@ -1677,7 +1741,17 @@ static void ivas_write_parameter_bitstream_dtx( pd_q_lvls = dtx_pd_real_q_levels[ndm - 1][pd_idx_2 - 1]; pd = pSpar_md->band_coeffs_idx[i].decd_index_re[pd_idx_2 - 1]; } +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + val = dtx_pd_real_min_max[0]; + ivas_quantise_real_values( &val, pd_q_lvls, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &idx, &val, 1 ); + + pd -= idx; + val = pr_min_max[0]; + ivas_quantise_real_values( &val, pr_q_lvls, pr_min_max[0], pr_min_max[1], &idx, &val, 1 ); + + pr -= idx; +#else ppVal[0][0] = dtx_pd_real_min_max[0]; ivas_quantise_real_values( ppVal, pd_q_lvls, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], ppIdx, ppVal, 1, 1 ); @@ -1687,7 +1761,7 @@ static void ivas_write_parameter_bitstream_dtx( ivas_quantise_real_values( ppVal, pr_q_lvls, pr_min_max[0], pr_min_max[1], ppIdx, ppVal, 1, 1 ); pr -= ppIdx[0][0]; - +#endif pr_pd_bits = ivas_get_bits_to_encode( pd_q_lvls * pr_q_lvls ); value = (uint16_t) ( pr * pd_q_lvls + pd ); @@ -1700,7 +1774,21 @@ static void ivas_write_parameter_bitstream_dtx( int16_t pr_idx1, pr_idx2, pr_pr_bits; pr_q_lvls1 = dtx_pr_real_q_levels[ndm - 1][pr_idx_1 - 1]; pr_q_lvls2 = dtx_pr_real_q_levels[ndm - 1][pr_idx_2 - 1]; +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + val = pr_min_max[0]; + ivas_quantise_real_values( &val, pr_q_lvls1, pr_min_max[0], pr_min_max[1], &idx, &val, 1 ); + + pr_idx1 = pSpar_md->band_coeffs_idx[i].pred_index_re[pr_idx_1 - 1]; + + pr_idx1 -= idx; + val = pr_min_max[0]; + ivas_quantise_real_values( &val, pr_q_lvls2, pr_min_max[0], pr_min_max[1], &idx, &val, 1 ); + + pr_idx2 = pSpar_md->band_coeffs_idx[i].pred_index_re[pr_idx_2 - 1]; + + pr_idx2 -= idx; +#else ppVal[0][0] = pr_min_max[0]; ivas_quantise_real_values( ppVal, pr_q_lvls1, pr_min_max[0], pr_min_max[1], ppIdx, ppVal, 1, 1 ); @@ -1714,7 +1802,7 @@ static void ivas_write_parameter_bitstream_dtx( pr_idx2 = pSpar_md->band_coeffs_idx[i].pred_index_re[pr_idx_2 - 1]; pr_idx2 -= ppIdx[0][0]; - +#endif value = (uint16_t) ( pr_idx2 * pr_q_lvls1 + pr_idx1 ); pr_pr_bits = ivas_get_bits_to_encode( pr_q_lvls1 * pr_q_lvls2 ); @@ -1751,6 +1839,7 @@ static void ivas_quant_pred_coeffs_per_band( ivas_quant_strat_t *pQs, const int16_t num_ch ) { +#ifndef QUANTISE_REAL_FCN_CLEAN_UP float *pQuant_re, *pCoeff_re; int16_t *pIdx_re; float **ppPred_coeffs_re = (float **) &pCoeff_re; @@ -1760,9 +1849,12 @@ static void ivas_quant_pred_coeffs_per_band( ppPred_idx_re[0] = &pBand_coeffs_idx->pred_index_re[0]; ppPred_coeffs_re[0] = &pband_coeffs->pred_re[0]; ppPred_quant_re[0] = &pband_coeffs->pred_quant_re[0]; - +#endif +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + ivas_quantise_real_values( pband_coeffs->pred_re, pQs->PR.q_levels[0], pQs->PR.min, pQs->PR.max, pBand_coeffs_idx->pred_index_re, pband_coeffs->pred_quant_re, ( num_ch - 1 ) ); +#else ivas_quantise_real_values( ppPred_coeffs_re, pQs->PR.q_levels[0], pQs->PR.min, pQs->PR.max, ppPred_idx_re, ppPred_quant_re, 1, ( num_ch - 1 ) ); - +#endif return; } @@ -1783,6 +1875,18 @@ static void ivas_quant_c_per_band( int16_t i; int16_t j, k; float C_re[IVAS_SPAR_MAX_C_COEFF]; +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + + k = 0; + for ( i = 0; i < ndec; i++ ) + { + for ( j = 0; j < ndm - 1; j++ ) + { + C_re[k] = pband_coeffs->C_re[i][j]; + k++; + } + } +#else float *pC_re[IVAS_SPAR_MAX_C_COEFF]; int16_t *pIdx_re[IVAS_SPAR_MAX_C_COEFF]; float **ppC_re = (float **) &pC_re[0]; @@ -1803,7 +1907,7 @@ static void ivas_quant_c_per_band( k++; } } - +#endif #ifdef SPAR_HOA_DBG /*for (i = 0; i < ndec; i++) { @@ -1813,9 +1917,11 @@ static void ivas_quant_c_per_band( } }*/ #endif - +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + ivas_quantise_real_values( C_re, pQs->C.q_levels[0], pQs->C.min, pQs->C.max, pBand_coeffs_idx->drct_index_re, C_re, ndec * ( ndm - 1 ) ); +#else ivas_quantise_real_values( ppC_re, pQs->C.q_levels[0], pQs->C.min, pQs->C.max, ppIdx_re, ppC_re, ndec * ( ndm - 1 ), 1 ); - +#endif k = 0; for ( i = 0; i < ndec; i++ ) { @@ -1854,6 +1960,7 @@ static void ivas_quant_p_per_band( ivas_quant_strat_t *pQs, const int16_t num_ch ) { +#ifndef QUANTISE_REAL_FCN_CLEAN_UP float P_re_diag[IVAS_SPAR_MAX_CH - 1]; int16_t i; int16_t dim = num_ch - 1; @@ -1861,18 +1968,20 @@ static void ivas_quant_p_per_band( int16_t *pDecd_idx[IVAS_SPAR_MAX_CH - 1]; float **ppP_diag = (float **) &pP_diag[0]; int16_t **ppDecd_idx = (int16_t **) &pDecd_idx[0]; - +#endif +#ifndef QUANTISE_REAL_FCN_CLEAN_UP for ( i = 0; i < dim; i++ ) { ppP_diag[i] = &P_re_diag[i]; ppDecd_idx[i] = &pBand_coeffs_idx->decd_index_re[i]; } - +#endif +#ifndef QUANTISE_REAL_FCN_CLEAN_UP for ( i = 0; i < dim; i++ ) { P_re_diag[i] = pband_coeffs->P_re[i]; } - +#endif #ifdef SPAR_HOA_DBG /*fprintf(stderr, "\n\n P_d:\n"); for (i = 0; i < dim; i++) @@ -1881,13 +1990,16 @@ static void ivas_quant_p_per_band( } fprintf(stderr, "\n\n");*/ #endif - +#ifdef QUANTISE_REAL_FCN_CLEAN_UP + ivas_quantise_real_values( pband_coeffs->P_re, pQs->P_r.q_levels[0], pQs->P_r.min, pQs->P_r.max, pBand_coeffs_idx->decd_index_re, pband_coeffs->P_quant_re, num_ch - 1 ); +#else ivas_quantise_real_values( ppP_diag, pQs->P_r.q_levels[0], pQs->P_r.min, pQs->P_r.max, ppDecd_idx, ppP_diag, num_ch - 1, 1 ); - +#endif +#ifndef QUANTISE_REAL_FCN_CLEAN_UP for ( i = 0; i < dim; i++ ) { pband_coeffs->P_quant_re[i] = P_re_diag[i]; } - +#endif return; } -- GitLab