Commit c39006ac authored by TYAGIRIS's avatar TYAGIRIS
Browse files

Merge branch '65-addition-of-no-entropy-coding-option-in-lfe' into 'main'

[non-BE] adding no entropy coding in LFE

See merge request !76
parents a1f93e28 bf3717c8
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@


#define DIRAC_DRCT_GAIN_TUNING                          /* issue 64: tuning of DirAC energy-compensation gains */

#define LFE_NO_ENTROPY_CODING                           /* issue 65: changes to add no entropy coding in LFE */

/* ################## End DEVELOPMENT switches ######################### */
/* clang-format on */
+44 −7
Original line number Diff line number Diff line
@@ -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,6 +199,23 @@ static int16_t ivas_lfe_dec_dequant(
            sign_bits[i] = get_next_indice( st0, 1 );
        }

#ifdef LFE_NO_ENTROPY_CODING
        coding_strategy = get_next_indice( st0, 1 );

        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++ )
            {
                extra_bits_read = 0;
@@ -206,6 +227,7 @@ static int16_t ivas_lfe_dec_dequant(
                }
                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;
@@ -433,6 +458,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;
+3 −0
Original line number Diff line number Diff line
@@ -1860,6 +1860,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;
+96 −0
Original line number Diff line number Diff line
@@ -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;
@@ -252,11 +278,66 @@ static void ivas_lfe_enc_quant(
                    hBstr->ind_list[j].nb_bits = 0;
                }

                hBstr->nb_bits_tot = bits_written;
                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++ )
                {
                    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++ )
                    {
                        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 */
    hLFE->lfe_bits = hBstr->nb_bits_tot - bits_written;
@@ -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 );

@@ -384,6 +468,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;
+3 −0
Original line number Diff line number Diff line
@@ -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;