From 47c25bda5d19e2e70652a7033954c4ec37c01e3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhold=20B=C3=B6hm?= Date: Tue, 9 Aug 2022 17:17:40 +0200 Subject: [PATCH 1/2] LFE_NO_ENTROPY_CODING: added no entropy coding in LFE --- lib_com/options.h | 2 +- lib_dec/ivas_lfe_dec.c | 51 +++++++++++++++++++--- lib_dec/ivas_stat_dec.h | 3 ++ lib_enc/ivas_lfe_enc.c | 96 +++++++++++++++++++++++++++++++++++++++++ lib_enc/ivas_stat_enc.h | 3 ++ 5 files changed, 147 insertions(+), 8 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index a51b60d748..6d2417efcb 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -155,9 +155,9 @@ #define FIX_I68_MC_REVERB_FOR_514 /* Fix HRTF processing for Jot reverb in case of 5.1.4 input format */ #define FIX_I54_LS_CONVERSION /* FhG: fix incorrect downmix matrix for 5_1_4 to 5_1_2 and upmix matrix for 7_1 to 7_1_4 */ #define FIX_I25_FBE_FB_BITS /* issue 25: properly skip reading of TBE FB bits when decoder output sampling rate is not 48 kHz */ +#define LFE_NO_ENTROPY_CODING /* issue 65: changes to add no entropy coding in LFE */ #define ORDER_BITS_ADDITION /* issue 14: Transmit SBA order and planar bits at all bitrates */ - /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ #endif diff --git a/lib_dec/ivas_lfe_dec.c b/lib_dec/ivas_lfe_dec.c index fd9233c4f9..b4a0119820 100644 --- a/lib_dec/ivas_lfe_dec.c +++ b/lib_dec/ivas_lfe_dec.c @@ -154,6 +154,10 @@ static int16_t ivas_lfe_dec_dequant( { int16_t shift_bits, i; int16_t quant_strategy; +#ifdef LFE_NO_ENTROPY_CODING + int16_t coding_strategy; + int16_t base2_bit_size; +#endif int16_t lfe_bits; int16_t all_zeros_dct; int16_t min_shift_bits; @@ -195,16 +199,34 @@ static int16_t ivas_lfe_dec_dequant( sign_bits[i] = get_next_indice( st0, 1 ); } - for ( iii = 0; iii < num_groups; iii++ ) - { - extra_bits_read = 0; - ivas_ari_start_decoding_14bits_ext_1_lfe( st0, &as, &extra_bits_read ); +#ifdef LFE_NO_ENTROPY_CODING + coding_strategy = get_next_indice( st0, 1 ); - for ( i = 0; i < 4; i++ ) + if ( coding_strategy ) + { + for ( iii = 0; iii < num_groups; iii++ ) + { + base2_bit_size = hLFE->lfe_dec_indices_coeffs_tbl[quant_strategy][iii]; + for ( i = 0; i < 4; i++ ) + { + abs_values[iii * 4 + i] = get_next_indice( st0, base2_bit_size ); + } + } + } + else +#endif + { + for ( iii = 0; iii < num_groups; iii++ ) { - abs_values[iii * 4 + i] = ivas_ari_decode_14bits_bit_ext_1_lfe( st0, &as, hLFE->cum_freq_models[quant_strategy][iii], &extra_bits_read ); + extra_bits_read = 0; + ivas_ari_start_decoding_14bits_ext_1_lfe( st0, &as, &extra_bits_read ); + + for ( i = 0; i < 4; i++ ) + { + abs_values[iii * 4 + i] = ivas_ari_decode_14bits_bit_ext_1_lfe( st0, &as, hLFE->cum_freq_models[quant_strategy][iii], &extra_bits_read ); + } + ivas_ari_done_decoding_14bits_ext_1_lfe( st0, extra_bits_read ); } - ivas_ari_done_decoding_14bits_ext_1_lfe( st0, extra_bits_read ); } for ( i = 0; i < num_dct_coeffs; i++ ) @@ -342,6 +364,9 @@ ivas_error ivas_create_lfe_dec( const float *filt_coeff; LFE_DEC_HANDLE hLFE; float lfe_addl_delay_s; +#ifdef LFE_NO_ENTROPY_CODING + int16_t i, j; +#endif low_pass_delay_dec_out = 0; block_offset_s = 0; @@ -441,6 +466,18 @@ ivas_error ivas_create_lfe_dec( hLFE->lfe_delay_buf = NULL; } +#ifdef LFE_NO_ENTROPY_CODING + /* Initialization base2 bits for each subgroup for no entropy coding */ + for ( i = 0; i < IVAS_MAX_NUM_QUANT_STRATS; i++ ) + { + for ( j = 0; j < IVAS_MAX_NUM_DCT_COEF_GROUPS; j++ ) + { + hLFE->lfe_dec_indices_coeffs_tbl[i][j] = + (int16_t) ceilf( log2f( (float) ( ivas_lfe_num_ele_in_coder_models[i][j] + 1 ) ) ); + } + } +#endif + *hLFE_out = hLFE; return IVAS_ERR_OK; diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 18fc4b4741..a682ff5698 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1862,6 +1862,9 @@ typedef struct ivas_lfe_dec_data_structure ivas_filters_process_state_t filter_state; LFE_WINDOW_HANDLE pWindow_state; const uint16_t *cum_freq_models[IVAS_MAX_NUM_QUANT_STRATS][IVAS_MAX_NUM_DCT_COEF_GROUPS]; +#ifdef LFE_NO_ENTROPY_CODING + int16_t lfe_dec_indices_coeffs_tbl[IVAS_MAX_NUM_QUANT_STRATS][IVAS_MAX_NUM_DCT_COEF_GROUPS]; +#endif float lfe_block_delay_s; int16_t lfe_prior_buf_len; float *prior_out_buffer; diff --git a/lib_enc/ivas_lfe_enc.c b/lib_enc/ivas_lfe_enc.c index feb164d201..552788590f 100644 --- a/lib_enc/ivas_lfe_enc.c +++ b/lib_enc/ivas_lfe_enc.c @@ -105,6 +105,13 @@ static void ivas_lfe_enc_quant( int16_t values[IVAS_LFE_MAX_NUM_DCT_COEFFS << 1]; float temp_lfe_dct[IVAS_LFE_MAX_NUM_DCT_COEFFS]; int16_t target_bits; +#ifdef LFE_NO_ENTROPY_CODING + int16_t base2_num_bits_tot; + int16_t coding_strategy; + int16_t bits_written_arith_enc; + int16_t next_ind_pos_arith_enc; + int16_t num_ele_per_grp = IVAS_LFE_NUM_COEFFS_IN_SUBGRP << 1; +#endif target_bits = (int16_t) ( IVAS_LFE_BITRATE_5000 / FRAMES_PER_SEC ); @@ -127,6 +134,9 @@ static void ivas_lfe_enc_quant( uint16_t all_zeros_dct; lfe_abs_sum = 0; +#ifdef LFE_NO_ENTROPY_CODING + coding_strategy = 0; +#endif num_dct_pass_bins = ivas_lfe_num_dct_pass_bins_tbl[quant_strategy]; max_of_vals = 0; num_groups = num_dct_pass_bins >> 1; @@ -236,8 +246,24 @@ static void ivas_lfe_enc_quant( push_next_indice( hBstr, write_bit, 1 ); } +#ifdef LFE_NO_ENTROPY_CODING + bits_written_arith_enc = hBstr->nb_bits_tot; + next_ind_pos_arith_enc = hBstr->next_ind; + push_next_indice( hBstr, coding_strategy, 1 ); + base2_num_bits_tot = hBstr->nb_bits_tot - bits_written; +#endif + ivas_lfe_arith_coding( hLFE, hBstr, quant_strategy, values ); +#ifdef LFE_NO_ENTROPY_CODING + for ( i = 0; i < num_groups; i++ ) + { + int16_t base2_num_bits = hLFE->lfe_enc_indices_coeffs_tbl[quant_strategy][i]; + base2_num_bits_tot += ( num_ele_per_grp * base2_num_bits ); + } +#endif + +#ifndef LFE_NO_ENTROPY_CODING if ( ( target_bits + IVAS_LFE_ID_BITS ) >= ( hBstr->nb_bits_tot - bits_written ) ) { break; @@ -256,6 +282,61 @@ static void ivas_lfe_enc_quant( hBstr->next_ind = next_ind_pos; } } +#else + if ( ( base2_num_bits_tot ) < ( hBstr->nb_bits_tot - bits_written ) ) + { + if ( quant_strategy == ( num_quant_strategies - 1 ) || ( ( target_bits + IVAS_LFE_ID_BITS ) >= base2_num_bits_tot ) ) + { + /* reset bits buffer and code the indices with base 2 coding */ + for ( j = hBstr->next_ind - 1; j >= next_ind_pos_arith_enc; j-- ) + { + hBstr->ind_list[j].nb_bits = -1; + } + hBstr->nb_bits_tot = bits_written_arith_enc; + hBstr->next_ind = next_ind_pos_arith_enc; + coding_strategy = 1; + push_next_indice( hBstr, coding_strategy, 1 ); + + for ( i = 0; i < num_groups; i++ ) + { + max_value = ivas_lfe_num_ele_in_coder_models[quant_strategy][i]; + int16_t base2_write_bits = hLFE->lfe_enc_indices_coeffs_tbl[quant_strategy][i]; + int16_t offset = 4 * i; + + for ( j = 0; j < num_ele_per_grp; j++ ) + { + if ( values[j + offset] > max_value ) + { + values[j + offset] = max_value; + } + push_next_indice( hBstr, values[j + offset], base2_write_bits ); + } + } + break; + } + } + else + { + if ( ( target_bits + IVAS_LFE_ID_BITS ) >= ( hBstr->nb_bits_tot - bits_written ) ) + { + break; + } + else + { + if ( quant_strategy < ( num_quant_strategies - 1 ) ) + { + /* reset all indices that were already written - TODO: maybe better store them temporarily first and write at the very end? */ + for ( j = hBstr->next_ind - 1; j >= next_ind_pos; j-- ) + { + hBstr->ind_list[j].nb_bits = -1; + } + + hBstr->nb_bits_tot = bits_written; + hBstr->next_ind = next_ind_pos; + } + } + } +#endif } /* bits spent for LFE coding */ @@ -331,6 +412,9 @@ ivas_error ivas_create_lfe_enc( int16_t input_frame; LFE_ENC_HANDLE hLFE; const float *filt_coeff; +#ifdef LFE_NO_ENTROPY_CODING + int16_t i, j; +#endif input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); @@ -392,6 +476,18 @@ ivas_error ivas_create_lfe_enc( hLFE->cum_freq_models[1][2] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg3; hLFE->cum_freq_models[1][3] = &ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg4; +#ifdef LFE_NO_ENTROPY_CODING + /* Initialization base2 bits for each subgroup for no entropy coding */ + for ( i = 0; i < IVAS_MAX_NUM_QUANT_STRATS; i++ ) + { + for ( j = 0; j < IVAS_MAX_NUM_DCT_COEF_GROUPS; j++ ) + { + hLFE->lfe_enc_indices_coeffs_tbl[i][j] = + (int16_t) ceilf( log2f( (float) ( ivas_lfe_num_ele_in_coder_models[i][j] + 1 ) ) ); + } + } +#endif + *hLFE_out = hLFE; return IVAS_ERR_OK; diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 331e1a75e7..dcba372dfb 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -971,6 +971,9 @@ typedef struct ivas_lfe_enc_data_structure LFE_WINDOW_HANDLE pWindow_state; BSTR_ENC_HANDLE hBstr; /* pointer to encoder bitstream handle */ const uint16_t *cum_freq_models[IVAS_MAX_NUM_QUANT_STRATS][IVAS_MAX_NUM_DCT_COEF_GROUPS]; +#ifdef LFE_NO_ENTROPY_CODING + int16_t lfe_enc_indices_coeffs_tbl[IVAS_MAX_NUM_QUANT_STRATS][IVAS_MAX_NUM_DCT_COEF_GROUPS]; +#endif int16_t lfe_bits; float *old_wtda_audio; -- GitLab From d384e387de1107577bfeb214c6e8425675a267e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhold=20B=C3=B6hm?= Date: Tue, 9 Aug 2022 17:52:05 +0200 Subject: [PATCH 2/2] fix instrumented build --- lib_enc/ivas_lfe_enc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/ivas_lfe_enc.c b/lib_enc/ivas_lfe_enc.c index 552788590f..b3f73635a1 100644 --- a/lib_enc/ivas_lfe_enc.c +++ b/lib_enc/ivas_lfe_enc.c @@ -299,9 +299,9 @@ static void ivas_lfe_enc_quant( for ( i = 0; i < num_groups; i++ ) { - max_value = ivas_lfe_num_ele_in_coder_models[quant_strategy][i]; int16_t base2_write_bits = hLFE->lfe_enc_indices_coeffs_tbl[quant_strategy][i]; int16_t offset = 4 * i; + max_value = ivas_lfe_num_ele_in_coder_models[quant_strategy][i]; for ( j = 0; j < num_ele_per_grp; j++ ) { -- GitLab