LCOV - code coverage report
Current view: top level - lib_dec - ivas_lfe_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 165 170 97.1 %
Date: 2025-05-23 08:37:30 Functions: 7 7 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : #include <stdint.h>
      34             : #include "options.h"
      35             : #ifdef DEBUGGING
      36             : #include "debug.h"
      37             : #endif
      38             : #include "prot.h"
      39             : #include "ivas_prot.h"
      40             : #include "ivas_rom_com.h"
      41             : #include "math.h"
      42             : #include "wmc_auto.h"
      43             : 
      44             : 
      45             : /*------------------------------------------------------------------------------------------*
      46             :  * Local constants
      47             :  *------------------------------------------------------------------------------------------*/
      48             : 
      49             : /* Delay handling of LFE: overall_lfe_delay = max(11.5, BLOCK_OFFSET_MS); */
      50             : #define BLOCK_OFFSET_MS 12
      51             : 
      52             : 
      53             : /*-----------------------------------------------------------------------------------------*
      54             :  * Function ivas_lfe_dec_delay_adjust()
      55             :  *
      56             :  * Adjusts the input to be passed to filtering block taking into consideration
      57             :  * LFE delay calculated during initialization time
      58             :  *-----------------------------------------------------------------------------------------*/
      59             : 
      60      161556 : static void ivas_lfe_dec_delay_adjust(
      61             :     LFE_DEC_HANDLE hLFE,
      62             :     float *pInbuf,
      63             :     float output_lfe_ch[] )
      64             : {
      65             :     int16_t i, diff, loop_counter;
      66             :     int16_t fade_len, dct_len, zero_pad_len;
      67             :     float tmp_buffer[L_FRAME48k];
      68             : 
      69      161556 :     diff = hLFE->lfe_prior_buf_len - hLFE->pWindow_state->fade_len;
      70      161556 :     loop_counter = diff < 0 ? 0 : diff;
      71      161556 :     fade_len = hLFE->pWindow_state->fade_len;
      72      161556 :     dct_len = hLFE->pWindow_state->dct_len;
      73      161556 :     zero_pad_len = hLFE->pWindow_state->zero_pad_len;
      74             : 
      75      161556 :     for ( i = 0; i < loop_counter; i++ )
      76             :     {
      77           0 :         tmp_buffer[i] = hLFE->prior_out_buffer[i];
      78             :     }
      79             : 
      80    59070996 :     for ( i = 0; i < fade_len; i++ )
      81             :     {
      82    58909440 :         tmp_buffer[i + loop_counter] = hLFE->prior_out_buffer[i + loop_counter] + pInbuf[i];
      83             :     }
      84      161556 :     loop_counter += fade_len;
      85             : 
      86    73798356 :     for ( i = 0; i < fade_len + ( zero_pad_len << 1 ); i++ )
      87             :     {
      88    73636800 :         tmp_buffer[i + loop_counter] = pInbuf[i + fade_len];
      89             :     }
      90             : 
      91    59070996 :     for ( i = 0; i < hLFE->lfe_prior_buf_len; i++ )
      92             :     {
      93    58909440 :         hLFE->prior_out_buffer[i] = tmp_buffer[i + dct_len];
      94             :     }
      95             : 
      96    73798356 :     for ( i = 0; i < dct_len; i++ )
      97             :     {
      98    73636800 :         output_lfe_ch[i] = tmp_buffer[i];
      99             :     }
     100             : 
     101      161556 :     return;
     102             : }
     103             : 
     104             : 
     105             : /*-----------------------------------------------------------------------------------------*
     106             :  * Function ivas_lfe_dec_windowing()
     107             :  *
     108             :  * LFE windowing block, input is passed through Fielder window
     109             :  *-----------------------------------------------------------------------------------------*/
     110             : 
     111      161556 : static void ivas_lfe_dec_windowing(
     112             :     LFE_DEC_HANDLE hLFE,
     113             :     float *pInbuf )
     114             : {
     115             :     int16_t i;
     116             :     int16_t fade_len;
     117             :     int16_t zero_pad_len;
     118             :     const float *pWindow_coeffs;
     119             : 
     120      161556 :     fade_len = hLFE->pWindow_state->fade_len;
     121      161556 :     zero_pad_len = hLFE->pWindow_state->zero_pad_len;
     122      161556 :     pWindow_coeffs = hLFE->pWindow_state->pWindow_coeffs;
     123             : 
     124    59070996 :     for ( i = 0; i < fade_len; i++ )
     125             :     {
     126    58909440 :         pInbuf[i] = pInbuf[zero_pad_len + i] * pWindow_coeffs[i];
     127             :     }
     128             : 
     129    14888916 :     for ( i = 0; i < zero_pad_len * 2; i++ )
     130             :     {
     131    14727360 :         pInbuf[fade_len + i] = pInbuf[zero_pad_len + fade_len + i];
     132             :     }
     133             : 
     134    59070996 :     for ( i = 0; i < fade_len; i++ )
     135             :     {
     136    58909440 :         pInbuf[zero_pad_len * 2 + fade_len + i] = pInbuf[zero_pad_len * 3 + fade_len + i] * pWindow_coeffs[fade_len - i - 1];
     137             :     }
     138             : 
     139      161556 :     return;
     140             : }
     141             : 
     142             : 
     143             : /*-----------------------------------------------------------------------------------------*
     144             :  * Function ivas_lfe_dec_dequant()
     145             :  *
     146             :  * LDE de-quatization block, calls arithmetic deccoding block inside
     147             :  *-----------------------------------------------------------------------------------------*/
     148             : 
     149       80118 : static int16_t ivas_lfe_dec_dequant(
     150             :     LFE_DEC_HANDLE hLFE,
     151             :     Decoder_State *st0,
     152             :     float *pOut_buf,
     153             :     int16_t *num_dct_pass_bins )
     154             : {
     155             :     int16_t shift_bits, i;
     156             :     int16_t quant_strategy;
     157             :     int16_t coding_strategy;
     158             :     int16_t base2_bit_size;
     159             :     int16_t lfe_bits;
     160             :     int16_t all_zeros_dct;
     161             :     int16_t min_shift_bits;
     162             :     int16_t shift;
     163             :     int16_t sign_bits[IVAS_LFE_MAX_NUM_DCT_COEFFS];
     164             :     int16_t abs_values[IVAS_LFE_MAX_NUM_DCT_COEFFS];
     165             :     int16_t values[IVAS_LFE_MAX_NUM_DCT_COEFFS];
     166             :     int16_t num_dct_coeffs, num_groups;
     167             : 
     168       80118 :     all_zeros_dct = get_next_indice( st0, 1 );
     169       80118 :     lfe_bits = st0->next_bit_pos;
     170       80118 :     shift_bits = IVAS_LFE_SHIFT_BITS;
     171       80118 :     min_shift_bits = 0;
     172       80118 :     shift = 0;
     173             : 
     174       80118 :     if ( all_zeros_dct == 1 )
     175             :     {
     176     1159638 :         for ( i = 0; i < IVAS_LFE_MAX_NUM_DCT_COEFFS; i++ )
     177             :         {
     178     1091424 :             pOut_buf[i] = 0.0f;
     179             :         }
     180             :     }
     181             :     else
     182             :     {
     183             :         float two_pow_shift_by_4;
     184             :         Tastat as;
     185             :         int16_t iii, extra_bits_read;
     186             : 
     187       11904 :         extra_bits_read = 0;
     188       11904 :         quant_strategy = get_next_indice( st0, 1 );
     189       11904 :         *num_dct_pass_bins = ivas_lfe_num_dct_pass_bins_tbl[quant_strategy];
     190       11904 :         num_dct_coeffs = (int16_t) ( *num_dct_pass_bins * IVAS_LFE_NUM_COEFFS_IN_SUBGRP );
     191       11904 :         num_groups = ( num_dct_coeffs / ( 2 * IVAS_LFE_NUM_COEFFS_IN_SUBGRP ) );
     192       11904 :         min_shift_bits = ivas_lfe_min_shift_tbl[quant_strategy];
     193       11904 :         shift = get_next_indice( st0, shift_bits ) + min_shift_bits * IVAS_LFE_SHIFTS_PER_DOUBLE;
     194             : 
     195      202368 :         for ( i = 0; i < num_dct_coeffs; i++ )
     196             :         {
     197      190464 :             sign_bits[i] = get_next_indice( st0, 1 );
     198             :         }
     199             : 
     200       11904 :         coding_strategy = get_next_indice( st0, 1 );
     201             : 
     202       11904 :         if ( coding_strategy )
     203             :         {
     204        6045 :             for ( iii = 0; iii < num_groups; iii++ )
     205             :             {
     206        4836 :                 base2_bit_size = hLFE->lfe_dec_indices_coeffs_tbl[quant_strategy][iii];
     207       24180 :                 for ( i = 0; i < 4; i++ )
     208             :                 {
     209       19344 :                     abs_values[iii * 4 + i] = get_next_indice( st0, base2_bit_size );
     210             :                 }
     211             :             }
     212             :         }
     213             :         else
     214             :         {
     215       53475 :             for ( iii = 0; iii < num_groups; iii++ )
     216             :             {
     217       42780 :                 extra_bits_read = 0;
     218       42780 :                 ivas_ari_start_decoding_14bits_ext_1_lfe( st0, &as, &extra_bits_read );
     219             : 
     220      213900 :                 for ( i = 0; i < 4; i++ )
     221             :                 {
     222      171120 :                     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 );
     223             :                 }
     224       42780 :                 ivas_ari_done_decoding_14bits_ext_1_lfe( st0, extra_bits_read );
     225             :             }
     226             :         }
     227             : 
     228      202368 :         for ( i = 0; i < num_dct_coeffs; i++ )
     229             :         {
     230      190464 :             values[i] = abs_values[i];
     231      190464 :             if ( sign_bits[i] > 0 )
     232             :             {
     233       59958 :                 values[i] = -abs_values[i] - 1;
     234             :             }
     235             :         }
     236             : 
     237       11904 :         two_pow_shift_by_4 = powf( 2, ( -shift / (float) IVAS_LFE_SHIFTS_PER_DOUBLE ) );
     238             : 
     239       59520 :         for ( i = 0; i < num_groups; i++ )
     240             :         {
     241       47616 :             pOut_buf[2 * i] = values[4 * i] * two_pow_shift_by_4;
     242       47616 :             pOut_buf[2 * i + 1] = values[4 * i + 1] * two_pow_shift_by_4;
     243             : 
     244       47616 :             pOut_buf[2 * i + *num_dct_pass_bins] = values[4 * i + 2] * two_pow_shift_by_4;
     245       47616 :             pOut_buf[2 * i + *num_dct_pass_bins + 1] = values[4 * i + 3] * two_pow_shift_by_4;
     246             :         }
     247             :     }
     248             : 
     249       80118 :     lfe_bits = st0->next_bit_pos - lfe_bits;
     250             : 
     251       80118 :     return lfe_bits;
     252             : }
     253             : 
     254             : 
     255             : /*-------------------------------------------------------------------------
     256             :  * ivas_create_lfe_lpf_dec()
     257             :  *
     258             :  * Create, allocate and initialize IVAS decoder LFE low pass filter state handle
     259             :  *-------------------------------------------------------------------------*/
     260             : 
     261         288 : static void ivas_create_lfe_lpf_dec(
     262             :     ivas_filters_process_state_t *hLfeLpf, /* o  : LFE LPF handle          */
     263             :     const int32_t input_Fs                 /* i  : input sampling rate     */
     264             : )
     265             : {
     266             :     const float *filt_coeff;
     267             : 
     268         288 :     ivas_lfe_lpf_select_filt_coeff( input_Fs, IVAS_FILTER_ORDER_4, &filt_coeff );
     269         288 :     ivas_filters_init( hLfeLpf, filt_coeff, IVAS_FILTER_ORDER_4 );
     270             : 
     271         288 :     return;
     272             : }
     273             : 
     274             : 
     275             : /*-----------------------------------------------------------------------------------------*
     276             :  * Function ivas_lfe_dec()
     277             :  *
     278             :  * LFE channel decoder
     279             :  *-----------------------------------------------------------------------------------------*/
     280             : 
     281       80778 : void ivas_lfe_dec(
     282             :     LFE_DEC_HANDLE hLFE,        /* i/o: LFE decoder handle                              */
     283             :     Decoder_State *st0,         /* i/o: decoder state structure - for bitstream handling*/
     284             :     const int16_t output_frame, /* i  : output frame length per channel                 */
     285             :     const int16_t bfi,          /* i  : BFI flag                                        */
     286             :     float output_lfe_ch[]       /* o  : output LFE synthesis                            */
     287             : )
     288             : {
     289             :     int16_t num_dct_pass_bins;
     290             :     int16_t i, j, dct_len;
     291             :     float out[L_FRAME48k];
     292             :     float t_audio[L_FRAME48k];
     293             :     float lfe_dct[IVAS_LFE_MAX_NUM_DCT_COEFFS];
     294             : 
     295       80778 :     dct_len = hLFE->pWindow_state->dct_len;
     296       80778 :     num_dct_pass_bins = IVAS_LFE_MAX_NUM_DCT_PASS_BINS;
     297             : 
     298       80778 :     if ( bfi == 0 )
     299             :     {
     300       80118 :         ivas_lfe_dec_dequant( hLFE, st0, lfe_dct, &num_dct_pass_bins );
     301             : 
     302       80118 :         set_zero( t_audio, dct_len );
     303       80118 :         mvr2r( lfe_dct, t_audio, num_dct_pass_bins );
     304       80118 :         ivas_imdct( t_audio, out, dct_len );
     305       80118 :         ivas_lfe_dec_windowing( hLFE, out );
     306       80118 :         ivas_lfe_dec_delay_adjust( hLFE, out, output_lfe_ch );
     307             : 
     308       80118 :         set_zero( t_audio, dct_len );
     309       80118 :         mvr2r( &lfe_dct[num_dct_pass_bins], t_audio, num_dct_pass_bins );
     310             : 
     311       80118 :         ivas_imdct( t_audio, out, dct_len );
     312       80118 :         ivas_lfe_dec_windowing( hLFE, out );
     313       80118 :         ivas_lfe_dec_delay_adjust( hLFE, out, output_lfe_ch + dct_len );
     314             : 
     315       80118 :         mvr2r( hLFE->prevsynth_buf + L_FRAME_1k6, hLFE->prevsynth_buf, LFE_PLC_BUFLEN - L_FRAME_1k6 );
     316             : 
     317       80118 :         j = 0;
     318     2643894 :         for ( i = 0; i < L_FRAME_1k6; i++ )
     319             :         {
     320     2563776 :             hLFE->prevsynth_buf[i + LFE_PLC_BUFLEN - L_FRAME_1k6] = output_lfe_ch[j];
     321     2563776 :             j += output_frame / L_FRAME_1k6;
     322             :         }
     323             : 
     324       80118 :         hLFE->bfi_count = 0;
     325             :     }
     326             :     else
     327             :     {
     328             :         /* note: in BFI branch, buffer 't_audio' is in time-domain ('wtda' signal) */
     329         660 :         hLFE->bfi_count++;
     330         660 :         ivas_lfe_tdplc( hLFE, hLFE->prevsynth_buf, t_audio, output_frame );
     331             : 
     332         660 :         ivas_itda( t_audio, out, dct_len );
     333         660 :         ivas_lfe_dec_windowing( hLFE, out );
     334         660 :         ivas_lfe_dec_delay_adjust( hLFE, out, output_lfe_ch );
     335             : 
     336         660 :         ivas_itda( t_audio + dct_len, out, dct_len );
     337         660 :         ivas_lfe_dec_windowing( hLFE, out );
     338         660 :         ivas_lfe_dec_delay_adjust( hLFE, out, output_lfe_ch + dct_len );
     339             : 
     340         660 :         mvr2r( hLFE->prevsynth_buf + L_FRAME_1k6, hLFE->prevsynth_buf, LFE_PLC_BUFLEN - L_FRAME_1k6 );
     341             : 
     342         660 :         j = 0;
     343       21780 :         for ( i = 0; i < L_FRAME_1k6; i++ )
     344             :         {
     345       21120 :             hLFE->prevsynth_buf[i + LFE_PLC_BUFLEN - L_FRAME_1k6] = output_lfe_ch[j];
     346       21120 :             j += output_frame / L_FRAME_1k6;
     347             :         }
     348             :     }
     349             : 
     350       80778 :     if ( hLFE->filter_state.order > 0 )
     351             :     {
     352             :         /* Low Pass Filter */
     353        3504 :         ivas_filter_process( &hLFE->filter_state, output_lfe_ch, output_frame );
     354             :     }
     355             : 
     356             :     /* add delay to make overall max(block_offset, 11.5) */
     357       80778 :     if ( hLFE->lfe_addl_delay > 0 )
     358             :     {
     359       80778 :         delay_signal( output_lfe_ch, output_frame, hLFE->lfe_delay_buf, hLFE->lfe_addl_delay );
     360             :     }
     361             : 
     362       80778 :     return;
     363             : }
     364             : 
     365             : 
     366             : /*-------------------------------------------------------------------------
     367             :  * ivas_create_lfe_dec()
     368             :  *
     369             :  * Create, allocate and initialize IVAS decoder LFE handle
     370             :  *-------------------------------------------------------------------------*/
     371             : 
     372        1065 : ivas_error ivas_create_lfe_dec(
     373             :     LFE_DEC_HANDLE *hLFE_out, /* o  : IVAS LFE decoder structure                           */
     374             :     const int32_t output_Fs,  /* i  : output sampling rate                                 */
     375             :     const int32_t delay_ns    /* i  : additional LFE delay to sync other channel outputs   */
     376             : )
     377             : {
     378             :     float low_pass_delay_dec_out, block_offset_s;
     379             :     int16_t filt_order, output_frame;
     380             :     LFE_DEC_HANDLE hLFE;
     381             :     float lfe_addl_delay_s;
     382             :     int16_t i, j;
     383             :     int16_t add_delay_sa;
     384             : 
     385        1065 :     low_pass_delay_dec_out = 0;
     386        1065 :     block_offset_s = 0;
     387             : 
     388        1065 :     output_frame = (int16_t) ( output_Fs / FRAMES_PER_SEC );
     389             : 
     390             :     /*-----------------------------------------------------------------*
     391             :      * Allocate LFE handle
     392             :      *-----------------------------------------------------------------*/
     393             : 
     394        1065 :     if ( ( hLFE = (LFE_DEC_HANDLE) malloc( sizeof( LFE_DEC_DATA ) ) ) == NULL )
     395             :     {
     396           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE\n" ) );
     397             :     }
     398             : 
     399             :     /*-----------------------------------------------------------------*
     400             :      * LFE Window: allocate and initialize
     401             :      *-----------------------------------------------------------------*/
     402             : 
     403        1065 :     if ( ( hLFE->pWindow_state = (LFE_WINDOW_HANDLE) malloc( sizeof( LFE_WINDOW_DATA ) ) ) == NULL )
     404             :     {
     405           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE window structure\n" ) );
     406             :     }
     407             : 
     408        1065 :     ivas_lfe_window_init( hLFE->pWindow_state, output_Fs, output_frame );
     409             : 
     410             :     /* Initialization for entropy coding */
     411        1065 :     hLFE->cum_freq_models[0][0] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg1;
     412        1065 :     hLFE->cum_freq_models[0][1] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg2;
     413        1065 :     hLFE->cum_freq_models[0][2] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg3;
     414        1065 :     hLFE->cum_freq_models[0][3] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg4;
     415        1065 :     hLFE->cum_freq_models[1][0] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg1;
     416        1065 :     hLFE->cum_freq_models[1][1] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg2;
     417        1065 :     hLFE->cum_freq_models[1][2] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg3;
     418        1065 :     hLFE->cum_freq_models[1][3] = &ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg4;
     419             : 
     420             :     /* delay calculation */
     421        1065 :     hLFE->lfe_block_delay_s = ( IVAS_LFE_FADE_NS / 1000000000.f ) + ivas_lfe_lpf_delay[IVAS_FILTER_ORDER_4 - 3];
     422             : 
     423        1065 :     block_offset_s = BLOCK_OFFSET_MS * 0.001f;
     424        1065 :     filt_order = 0;
     425        1065 :     low_pass_delay_dec_out = 0;
     426        1065 :     if ( ( delay_ns / 1000000000.f ) > ivas_lfe_lpf_delay[IVAS_FILTER_ORDER_4 - 3] )
     427             :     {
     428         288 :         filt_order = 4;
     429         288 :         low_pass_delay_dec_out = ivas_lfe_lpf_delay[IVAS_FILTER_ORDER_4 - 3] * 1000000000.f;
     430         288 :         ivas_create_lfe_lpf_dec( &( hLFE->filter_state ), output_Fs );
     431             :     }
     432             : 
     433        1065 :     hLFE->filter_state.order = filt_order;
     434        1065 :     hLFE->lfe_block_delay_s = hLFE->lfe_block_delay_s + low_pass_delay_dec_out;
     435        1065 :     hLFE->lfe_prior_buf_len = NS2SA( output_Fs, IVAS_LFE_FADE_NS );
     436             : 
     437        1065 :     hLFE->bfi_count = 0;
     438             : 
     439        1065 :     lfe_addl_delay_s = block_offset_s - hLFE->lfe_block_delay_s;
     440        1065 :     lfe_addl_delay_s = max( 0.0f, lfe_addl_delay_s );
     441        1065 :     add_delay_sa = (int16_t) roundf( (float) delay_ns * output_Fs / 1000000000.f );
     442        1065 :     hLFE->lfe_addl_delay = (int16_t) ( lfe_addl_delay_s * output_Fs ) + add_delay_sa;
     443        1065 :     hLFE->lfe_block_delay_s += lfe_addl_delay_s + add_delay_sa / output_Fs;
     444             : 
     445        1065 :     if ( hLFE->lfe_addl_delay > 0 )
     446             :     {
     447        1065 :         if ( ( hLFE->lfe_delay_buf = (float *) malloc( hLFE->lfe_addl_delay * sizeof( float ) ) ) == NULL )
     448             :         {
     449           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE additional delay buffer\n" ) );
     450             :         }
     451        1065 :         set_zero( (float *) hLFE->lfe_delay_buf, hLFE->lfe_addl_delay );
     452             :     }
     453             :     else
     454             :     {
     455           0 :         hLFE->lfe_delay_buf = NULL;
     456             :     }
     457             : 
     458             :     /* Initialization base2 bits for each subgroup for no entropy coding */
     459        3195 :     for ( i = 0; i < IVAS_MAX_NUM_QUANT_STRATS; i++ )
     460             :     {
     461       10650 :         for ( j = 0; j < IVAS_MAX_NUM_DCT_COEF_GROUPS; j++ )
     462             :         {
     463        8520 :             hLFE->lfe_dec_indices_coeffs_tbl[i][j] =
     464        8520 :                 (int16_t) ceilf( log2f( (float) ( ivas_lfe_num_ele_in_coder_models[i][j] + 1 ) ) );
     465             :         }
     466             :     }
     467             : 
     468        1065 :     *hLFE_out = hLFE;
     469             : 
     470        1065 :     return IVAS_ERR_OK;
     471             : }
     472             : 
     473             : 
     474             : /*-------------------------------------------------------------------------
     475             :  * ivas_lfe_dec_close()
     476             :  *
     477             :  * Destroy IVAS decoder LFE handle
     478             :  *-------------------------------------------------------------------------*/
     479             : 
     480        3681 : void ivas_lfe_dec_close(
     481             :     LFE_DEC_HANDLE *hLFE /* i/o: LFE decoder handle */
     482             : )
     483             : {
     484        3681 :     if ( hLFE == NULL || *hLFE == NULL )
     485             :     {
     486        2616 :         return;
     487             :     }
     488             : 
     489        1065 :     free( ( *hLFE )->pWindow_state );
     490        1065 :     ( *hLFE )->pWindow_state = NULL;
     491             : 
     492        1065 :     if ( ( *hLFE )->lfe_delay_buf != NULL )
     493             :     {
     494        1065 :         free( ( *hLFE )->lfe_delay_buf );
     495        1065 :         ( *hLFE )->lfe_delay_buf = NULL;
     496             :     }
     497             : 
     498        1065 :     free( ( *hLFE ) );
     499        1065 :     ( *hLFE ) = NULL;
     500             : 
     501        1065 :     return;
     502             : }

Generated by: LCOV version 1.14