LCOV - code coverage report
Current view: top level - lib_enc - ivas_lfe_enc.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 169 183 92.3 %
Date: 2025-05-23 08:37:30 Functions: 8 8 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             : #include "math.h"
      36             : #include "prot.h"
      37             : #include "ivas_prot.h"
      38             : #include "ivas_cnst.h"
      39             : #include "ivas_rom_com.h"
      40             : #ifdef DEBUGGING
      41             : #include "debug.h"
      42             : #endif
      43             : #include "wmc_auto.h"
      44             : 
      45             : 
      46             : /*-----------------------------------------------------------------------------------------*
      47             :  * Function ivas_lfe_arith_coding()
      48             :  *
      49             :  * LFE Arithmetic coding block. Writes encoded data to bitstream.
      50             :  *-----------------------------------------------------------------------------------------*/
      51             : 
      52        3991 : static void ivas_lfe_arith_coding(
      53             :     LFE_ENC_HANDLE hLFE,
      54             :     BSTR_ENC_HANDLE hBstr,
      55             :     const int16_t quant_strategy,
      56             :     int16_t *values )
      57             : {
      58             :     Tastat as;
      59             :     int16_t index, i;
      60             :     int16_t max_value, offset;
      61             :     uint16_t num_ele_per_grp;
      62             :     int16_t num_groups;
      63        3991 :     index = 0;
      64        3991 :     num_ele_per_grp = IVAS_LFE_NUM_COEFFS_IN_SUBGRP << 1;
      65        3991 :     num_groups = ivas_lfe_num_dct_pass_bins_tbl[quant_strategy] >> 1;
      66             : 
      67       19955 :     for ( i = 0; i < num_groups; i++ )
      68             :     {
      69       15964 :         max_value = ivas_lfe_num_ele_in_coder_models[quant_strategy][i];
      70       15964 :         ari_start_encoding_14bits( &as );
      71       15964 :         offset = 4 * i;
      72             : 
      73       79820 :         for ( index = 0; index < num_ele_per_grp; index++ )
      74             :         {
      75       63856 :             if ( values[index + offset] > max_value )
      76             :             {
      77        1224 :                 values[index + offset] = max_value;
      78             :             }
      79       63856 :             ivas_ari_encode_14bits_ext( hBstr, &as, values[index + offset], hLFE->cum_freq_models[quant_strategy][i] );
      80             :         }
      81             : 
      82       15964 :         ivas_ari_done_encoding_14bits( hBstr, &as );
      83             :     }
      84             : 
      85        3991 :     return;
      86             : }
      87             : 
      88             : 
      89             : /*-----------------------------------------------------------------------------------------*
      90             :  * Function ivas_lfe_enc_quant()
      91             :  *
      92             :  * LFE quatization block, calls arithmetic coding block inside
      93             :  *-----------------------------------------------------------------------------------------*/
      94             : 
      95       26920 : static void ivas_lfe_enc_quant(
      96             :     LFE_ENC_HANDLE hLFE,
      97             :     float *pLfe_dct,
      98             :     BSTR_ENC_HANDLE hBstr )
      99             : {
     100             :     int16_t bits_written;
     101             :     int16_t nb_ind_tot;
     102             :     uint16_t quant_strategy, write_bit;
     103             :     int16_t num_quant_strategies;
     104             :     int16_t shift_bits;
     105             :     int16_t values[IVAS_LFE_MAX_NUM_DCT_COEFFS << 1];
     106             :     float temp_lfe_dct[IVAS_LFE_MAX_NUM_DCT_COEFFS];
     107             :     int16_t target_bits;
     108             :     int16_t base2_num_bits_tot;
     109             :     int16_t coding_strategy;
     110             :     int16_t bits_written_arith_enc;
     111             :     int16_t next_ind_pos_arith_enc;
     112       26920 :     int16_t num_ele_per_grp = IVAS_LFE_NUM_COEFFS_IN_SUBGRP << 1;
     113             : 
     114       26920 :     target_bits = (int16_t) ( IVAS_LFE_BITRATE_5000 / FRAMES_PER_SEC );
     115             : 
     116       26920 :     write_bit = 0;
     117       26920 :     num_quant_strategies = IVAS_MAX_NUM_QUANT_STRATS;
     118       26920 :     shift_bits = IVAS_LFE_SHIFT_BITS;
     119       26920 :     bits_written = hBstr->nb_bits_tot;
     120       26920 :     nb_ind_tot = hBstr->nb_ind_tot;
     121             : 
     122             : 
     123       26920 :     for ( quant_strategy = 0; quant_strategy < num_quant_strategies; quant_strategy++ )
     124             :     {
     125             :         float lfe_abs_sum;
     126             :         int16_t num_dct_pass_bins;
     127             :         int16_t max_of_vals, num_groups;
     128             :         int16_t shift;
     129             :         uint16_t min_shift, i, j;
     130             :         uint16_t max_shift;
     131             :         uint16_t max_value, num_lfe_ele;
     132             :         uint16_t all_zeros_dct;
     133             : 
     134       26920 :         lfe_abs_sum = 0;
     135       26920 :         coding_strategy = 0;
     136       26920 :         num_dct_pass_bins = ivas_lfe_num_dct_pass_bins_tbl[quant_strategy];
     137       26920 :         max_of_vals = 0;
     138       26920 :         num_groups = num_dct_pass_bins >> 1;
     139       26920 :         shift = 0;
     140       26920 :         min_shift = ivas_lfe_min_shift_tbl[quant_strategy];
     141       26920 :         max_shift = min_shift * IVAS_LFE_SHIFTS_PER_DOUBLE + ( 1 << shift_bits ) - 1;
     142       26920 :         num_lfe_ele = num_dct_pass_bins * IVAS_LFE_NUM_COEFFS_IN_SUBGRP;
     143       26920 :         all_zeros_dct = 0;
     144       26920 :         max_value = ivas_lfe_num_ele_in_coder_models[quant_strategy][0];
     145             : 
     146       26920 :         mvr2r( &pLfe_dct[IVAS_LFE_MAX_NUM_DCT_PASS_BINS], &pLfe_dct[num_dct_pass_bins], num_dct_pass_bins );
     147             : 
     148      134600 :         for ( i = 0; i < num_groups; i++ )
     149             :         {
     150      107680 :             temp_lfe_dct[4 * i] = pLfe_dct[2 * i];
     151      107680 :             lfe_abs_sum += fabsf( temp_lfe_dct[4 * i] );
     152      107680 :             temp_lfe_dct[4 * i + 1] = pLfe_dct[2 * i + 1];
     153      107680 :             lfe_abs_sum += fabsf( temp_lfe_dct[4 * i + 1] );
     154             : 
     155      107680 :             temp_lfe_dct[4 * i + 2] = pLfe_dct[2 * i + num_dct_pass_bins];
     156      107680 :             lfe_abs_sum += fabsf( temp_lfe_dct[4 * i + 2] );
     157      107680 :             temp_lfe_dct[4 * i + 3] = pLfe_dct[2 * i + num_dct_pass_bins + 1];
     158      107680 :             lfe_abs_sum += fabsf( temp_lfe_dct[4 * i + 3] );
     159             :         }
     160             : 
     161       26920 :         if ( lfe_abs_sum <= IVAS_LFE_ABS_SUM_FLT_THR )
     162             :         {
     163           0 :             shift = max_shift;
     164             :         }
     165             :         else
     166             :         {
     167       26920 :             shift = (int16_t) floorf( IVAS_LFE_SHIFTS_PER_DOUBLE * log2_f( max_value / lfe_abs_sum ) );
     168             :         }
     169             : 
     170       26920 :         shift = max( min_shift * IVAS_LFE_SHIFTS_PER_DOUBLE, min( max_shift, shift ) );
     171             : 
     172             :         while ( 1 )
     173             :         {
     174       26920 :             if ( shift == max_shift )
     175             :             {
     176             :                 /* write all LFE bits as 0 */
     177       22929 :                 all_zeros_dct = 1;
     178       22929 :                 break;
     179             :             }
     180             :             else
     181             :             {
     182        3991 :                 max_of_vals = 0;
     183       67847 :                 for ( i = 0; i < num_lfe_ele; i++ )
     184             :                 {
     185             :                     float temp;
     186       63856 :                     temp = temp_lfe_dct[i] * powf( 2, ( (float) shift / IVAS_LFE_SHIFTS_PER_DOUBLE ) );
     187             : 
     188       63856 :                     if ( temp < 0 )
     189             :                     {
     190       31863 :                         values[i] = (int16_t) ( temp - 0.5f );
     191             :                     }
     192             :                     else
     193             :                     {
     194       31993 :                         values[i] = (int16_t) ( temp + 0.5f );
     195             :                     }
     196             : 
     197       63856 :                     if ( max_of_vals < abs( values[i] ) )
     198             :                     {
     199        9821 :                         max_of_vals = (int16_t) abs( values[i] );
     200             :                     }
     201             :                 }
     202             :             }
     203        3991 :             if ( max_of_vals <= max_value )
     204             :             {
     205        3991 :                 break;
     206             :             }
     207           0 :             shift = shift - 1;
     208             :         }
     209             : 
     210       26920 :         if ( shift < min_shift * IVAS_LFE_SHIFTS_PER_DOUBLE )
     211             :         {
     212           0 :             continue;
     213             :         }
     214             : 
     215       26920 :         if ( all_zeros_dct != 1 )
     216             :         {
     217        3991 :             push_next_indice( hBstr, all_zeros_dct, 1 );
     218        3991 :             push_next_indice( hBstr, quant_strategy, 1 );
     219        3991 :             push_next_indice( hBstr, shift - min_shift * IVAS_LFE_SHIFTS_PER_DOUBLE, shift_bits );
     220             :         }
     221             :         else
     222             :         {
     223       22929 :             push_next_indice( hBstr, all_zeros_dct, 1 );
     224       22929 :             hLFE->lfe_bits = hBstr->nb_bits_tot - bits_written;
     225       22929 :             return;
     226             :         }
     227             : 
     228       67847 :         for ( i = 0; i < num_lfe_ele; i++ )
     229             :         {
     230       63856 :             if ( values[i] < 0 )
     231             :             {
     232       20114 :                 write_bit = 1;
     233       20114 :                 values[i] = values[i] + 1;
     234             :             }
     235             :             else
     236             :             {
     237       43742 :                 write_bit = 0;
     238             :             }
     239             : 
     240       63856 :             values[i] = (int16_t) abs( values[i] );
     241             : 
     242       63856 :             push_next_indice( hBstr, write_bit, 1 );
     243             :         }
     244             : 
     245        3991 :         bits_written_arith_enc = hBstr->nb_bits_tot;
     246        3991 :         next_ind_pos_arith_enc = hBstr->nb_ind_tot;
     247        3991 :         push_next_indice( hBstr, coding_strategy, 1 );
     248        3991 :         base2_num_bits_tot = hBstr->nb_bits_tot - bits_written;
     249             : 
     250        3991 :         ivas_lfe_arith_coding( hLFE, hBstr, quant_strategy, values );
     251             : 
     252       19955 :         for ( i = 0; i < num_groups; i++ )
     253             :         {
     254       15964 :             int16_t base2_num_bits = hLFE->lfe_enc_indices_coeffs_tbl[quant_strategy][i];
     255       15964 :             base2_num_bits_tot += ( num_ele_per_grp * base2_num_bits );
     256             :         }
     257             : 
     258        3991 :         if ( ( base2_num_bits_tot ) < ( hBstr->nb_bits_tot - bits_written ) )
     259             :         {
     260         415 :             if ( quant_strategy == ( num_quant_strategies - 1 ) || ( ( target_bits + IVAS_LFE_ID_BITS ) >= base2_num_bits_tot ) )
     261             :             {
     262             :                 /* reset bits buffer and code the indices with base 2 coding */
     263       28743 :                 for ( j = hBstr->nb_ind_tot - 1; j >= next_ind_pos_arith_enc; j-- )
     264             :                 {
     265       28328 :                     hBstr->ind_list[j].nb_bits = -1;
     266             :                 }
     267         415 :                 hBstr->nb_ind_tot = next_ind_pos_arith_enc;
     268         415 :                 hBstr->nb_bits_tot = bits_written_arith_enc;
     269         415 :                 coding_strategy = 1;
     270         415 :                 push_next_indice( hBstr, coding_strategy, 1 );
     271             : 
     272        2075 :                 for ( i = 0; i < num_groups; i++ )
     273             :                 {
     274        1660 :                     int16_t base2_write_bits = hLFE->lfe_enc_indices_coeffs_tbl[quant_strategy][i];
     275        1660 :                     int16_t offset = 4 * i;
     276        1660 :                     max_value = ivas_lfe_num_ele_in_coder_models[quant_strategy][i];
     277             : 
     278        8300 :                     for ( j = 0; j < num_ele_per_grp; j++ )
     279             :                     {
     280        6640 :                         if ( values[j + offset] > max_value )
     281             :                         {
     282           0 :                             values[j + offset] = max_value;
     283             :                         }
     284        6640 :                         push_next_indice( hBstr, values[j + offset], base2_write_bits );
     285             :                     }
     286             :                 }
     287         415 :                 break;
     288             :             }
     289             :         }
     290             :         else
     291             :         {
     292        3576 :             if ( ( target_bits + IVAS_LFE_ID_BITS ) >= ( hBstr->nb_bits_tot - bits_written ) )
     293             :             {
     294        3576 :                 break;
     295             :             }
     296             :             else
     297             :             {
     298           0 :                 if ( quant_strategy < ( num_quant_strategies - 1 ) )
     299             :                 {
     300           0 :                     for ( j = hBstr->nb_ind_tot - 1; j >= nb_ind_tot; j-- )
     301             :                     {
     302           0 :                         hBstr->ind_list[j].nb_bits = -1;
     303             :                     }
     304             : 
     305           0 :                     hBstr->nb_bits_tot = bits_written;
     306           0 :                     hBstr->nb_ind_tot = nb_ind_tot;
     307             :                 }
     308             :             }
     309             :         }
     310             :     }
     311             : 
     312             :     /* bits spent for LFE coding */
     313        3991 :     hLFE->lfe_bits = hBstr->nb_bits_tot - bits_written;
     314             : 
     315        3991 :     return;
     316             : }
     317             : 
     318             : 
     319             : /*-----------------------------------------------------------------------------------------*
     320             :  * Function ivas_lfe_enc()
     321             :  *
     322             :  * LFE channel encoder
     323             :  *-----------------------------------------------------------------------------------------*/
     324             : 
     325       26920 : void ivas_lfe_enc(
     326             :     LFE_ENC_HANDLE hLFE,       /* i/o: LFE encoder handle                       */
     327             :     float data_lfe_ch[],       /* i  : input LFE signal                         */
     328             :     const int16_t input_frame, /* i  : input frame length per channel           */
     329             :     BSTR_ENC_HANDLE hBstr      /* i/o: bitstream handle                         */
     330             : )
     331             : {
     332             :     float t_audio[L_FRAME48k];
     333             :     float wtda_audio[L_FRAME48k];
     334             :     float lfe_dct[IVAS_LFE_MAX_NUM_DCT_COEFFS];
     335             :     int16_t num_dct_pass_bins;
     336             :     int16_t fade_len, full_len, dct_len, zero_pad_len;
     337             :     const float *pWindow_coeffs;
     338             : 
     339             :     /* Initializations */
     340       26920 :     num_dct_pass_bins = IVAS_LFE_MAX_NUM_DCT_PASS_BINS;
     341       26920 :     fade_len = hLFE->pWindow_state->fade_len;
     342       26920 :     full_len = hLFE->pWindow_state->full_len;
     343       26920 :     dct_len = hLFE->pWindow_state->dct_len;
     344       26920 :     zero_pad_len = hLFE->pWindow_state->zero_pad_len;
     345       26920 :     pWindow_coeffs = hLFE->pWindow_state->pWindow_coeffs;
     346             : 
     347             :     /* Windowing */
     348       26920 :     ivas_dct_windowing( fade_len, full_len, dct_len, zero_pad_len, pWindow_coeffs, input_frame, wtda_audio, hLFE->old_wtda_audio, data_lfe_ch );
     349             : 
     350       26920 :     ivas_mdct( wtda_audio, t_audio, dct_len );
     351             : 
     352       26920 :     mvr2r( t_audio, lfe_dct, num_dct_pass_bins );
     353             : 
     354             :     /* windowing */
     355       26920 :     ivas_dct_windowing( fade_len, full_len, dct_len, zero_pad_len, pWindow_coeffs, input_frame, wtda_audio, hLFE->old_wtda_audio, data_lfe_ch + dct_len );
     356             : 
     357             :     /* mdct */
     358       26920 :     ivas_mdct( wtda_audio, t_audio, dct_len );
     359             : 
     360       26920 :     mvr2r( t_audio, lfe_dct + num_dct_pass_bins, num_dct_pass_bins );
     361             : 
     362       26920 :     ivas_lfe_enc_quant( hLFE, lfe_dct, hBstr );
     363             : 
     364       26920 :     return;
     365             : }
     366             : 
     367             : 
     368             : /*-------------------------------------------------------------------------
     369             :  * ivas_create_lfe_enc()
     370             :  *
     371             :  * Create, allocate and initialize IVAS encoder LFE handle
     372             :  *-------------------------------------------------------------------------*/
     373             : 
     374         358 : ivas_error ivas_create_lfe_enc(
     375             :     LFE_ENC_HANDLE *hLFE_out, /* o  : IVAS LFE encoder structure   */
     376             :     const int32_t input_Fs    /* i  : input sampling rate          */
     377             : )
     378             : {
     379             :     int16_t input_frame;
     380             :     LFE_ENC_HANDLE hLFE;
     381             :     int16_t i, j;
     382             : 
     383         358 :     input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC );
     384             : 
     385             :     /*-----------------------------------------------------------------*
     386             :      * Allocate LFE handle
     387             :      *-----------------------------------------------------------------*/
     388             : 
     389         358 :     if ( ( hLFE = (LFE_ENC_HANDLE) malloc( sizeof( LFE_ENC_DATA ) ) ) == NULL )
     390             :     {
     391           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE\n" ) );
     392             :     }
     393             : 
     394             :     /* initializations */
     395         358 :     hLFE->lfe_bits = 0;
     396             : 
     397         358 :     hLFE->pWindow_state = NULL;
     398         358 :     hLFE->hBstr = NULL;
     399             : 
     400             :     /*-----------------------------------------------------------------*
     401             :      * Input memory buffer: allocate and initialize
     402             :      *-----------------------------------------------------------------*/
     403             : 
     404         358 :     if ( ( hLFE->old_wtda_audio = (float *) malloc( sizeof( float ) * NS2SA( input_Fs, IVAS_LFE_FADE_NS ) ) ) == NULL )
     405             :     {
     406           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE memory\n" ) );
     407             :     }
     408             : 
     409         358 :     set_zero( hLFE->old_wtda_audio, NS2SA( input_Fs, IVAS_LFE_FADE_NS ) );
     410             : 
     411             :     /*-----------------------------------------------------------------*
     412             :      * LFE Window: allocate and initialize
     413             :      *-----------------------------------------------------------------*/
     414             : 
     415         358 :     if ( ( hLFE->pWindow_state = (LFE_WINDOW_HANDLE) malloc( sizeof( LFE_WINDOW_DATA ) ) ) == NULL )
     416             :     {
     417           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE window structure\n" ) );
     418             :     }
     419             : 
     420         358 :     ivas_lfe_window_init( hLFE->pWindow_state, input_Fs, input_frame );
     421             : 
     422             :     /* Initialization for entropy coding */
     423         358 :     hLFE->cum_freq_models[0][0] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg1;
     424         358 :     hLFE->cum_freq_models[0][1] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg2;
     425         358 :     hLFE->cum_freq_models[0][2] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg3;
     426         358 :     hLFE->cum_freq_models[0][3] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg4;
     427         358 :     hLFE->cum_freq_models[1][0] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg1;
     428         358 :     hLFE->cum_freq_models[1][1] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg2;
     429         358 :     hLFE->cum_freq_models[1][2] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg3;
     430         358 :     hLFE->cum_freq_models[1][3] = &ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg4;
     431             : 
     432             :     /* Initialization base2 bits for each subgroup for no entropy coding */
     433        1074 :     for ( i = 0; i < IVAS_MAX_NUM_QUANT_STRATS; i++ )
     434             :     {
     435        3580 :         for ( j = 0; j < IVAS_MAX_NUM_DCT_COEF_GROUPS; j++ )
     436             :         {
     437        2864 :             hLFE->lfe_enc_indices_coeffs_tbl[i][j] =
     438        2864 :                 (int16_t) ceilf( log2f( (float) ( ivas_lfe_num_ele_in_coder_models[i][j] + 1 ) ) );
     439             :         }
     440             :     }
     441             : 
     442         358 :     *hLFE_out = hLFE;
     443             : 
     444         358 :     return IVAS_ERR_OK;
     445             : }
     446             : 
     447             : 
     448             : /*-------------------------------------------------------------------------
     449             :  * ivas_lfe_enc_close()
     450             :  *
     451             :  * Destroy IVAS cncoder LFE handle
     452             :  *-------------------------------------------------------------------------*/
     453             : 
     454         929 : void ivas_lfe_enc_close(
     455             :     LFE_ENC_HANDLE *hLFE /* i/o: LFE encoder handle */
     456             : )
     457             : {
     458         929 :     if ( hLFE == NULL || *hLFE == NULL )
     459             :     {
     460         571 :         return;
     461             :     }
     462             : 
     463         358 :     if ( ( *hLFE )->old_wtda_audio != NULL )
     464             :     {
     465         358 :         free( ( *hLFE )->old_wtda_audio );
     466         358 :         ( *hLFE )->old_wtda_audio = NULL;
     467             :     }
     468         358 :     if ( ( *hLFE )->pWindow_state )
     469             :     {
     470         358 :         free( ( *hLFE )->pWindow_state );
     471         358 :         ( *hLFE )->pWindow_state = NULL;
     472             :     }
     473             : 
     474         358 :     free( ( *hLFE ) );
     475         358 :     ( *hLFE ) = NULL;
     476             : 
     477         358 :     return;
     478             : }
     479             : 
     480             : 
     481             : /*-------------------------------------------------------------------------
     482             :  * ivas_create_lfe_lpf_enc()
     483             :  *
     484             :  * Create, allocate and initialize IVAS encoder LFE low pass filter state handle
     485             :  *-------------------------------------------------------------------------*/
     486             : 
     487          82 : ivas_error ivas_create_lfe_lpf_enc(
     488             :     ivas_filters_process_state_t **hLfeLpf, /* o  : LFE LPF handle          */
     489             :     const int32_t input_Fs                  /* i  : input sampling rate     */
     490             : )
     491             : {
     492             :     const float *filt_coeff;
     493             : 
     494          82 :     if ( hLfeLpf == NULL )
     495             :     {
     496           0 :         return ( IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "Can not allocate memory for LFE LPF\n" ) );
     497             :     }
     498             : 
     499             :     /*-----------------------------------------------------------------*
     500             :      * Allocate LFE LPF handle
     501             :      *-----------------------------------------------------------------*/
     502             : 
     503          82 :     if ( ( *hLfeLpf = (ivas_filters_process_state_t *) malloc( sizeof( ivas_filters_process_state_t ) ) ) == NULL )
     504             :     {
     505           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE LPF\n" ) );
     506             :     }
     507             : 
     508          82 :     ivas_lfe_lpf_select_filt_coeff( input_Fs, IVAS_FILTER_ORDER_4, &filt_coeff );
     509             : 
     510          82 :     ivas_filters_init( *hLfeLpf, filt_coeff, IVAS_FILTER_ORDER_4 );
     511             : 
     512          82 :     return IVAS_ERR_OK;
     513             : }
     514             : 
     515             : 
     516             : /*-------------------------------------------------------------------------
     517             :  * ivas_lfe_lpf_enc_close()
     518             :  *
     519             :  * Destroy IVAS cncoder LFE low pass filter state
     520             :  *-------------------------------------------------------------------------*/
     521             : 
     522         627 : void ivas_lfe_lpf_enc_close(
     523             :     ivas_filters_process_state_t **hLfeLpf /* i/o: LFE LPF handle */
     524             : )
     525             : {
     526         627 :     if ( hLfeLpf == NULL || *hLfeLpf == NULL )
     527             :     {
     528         545 :         return;
     529             :     }
     530             : 
     531          82 :     free( ( *hLfeLpf ) );
     532          82 :     ( *hLfeLpf ) = NULL;
     533             : 
     534          82 :     return;
     535             : }
     536             : 
     537             : 
     538             : /*-------------------------------------------------------------------------
     539             :  * ivas_lfe_lpf_enc_apply()
     540             :  *
     541             :  * Apply IVAS cncoder LFE low pass filter
     542             :  *-------------------------------------------------------------------------*/
     543             : 
     544       48850 : void ivas_lfe_lpf_enc_apply(
     545             :     ivas_filters_process_state_t *hLfeLpf, /* i/o: LFE LPF handle                   */
     546             :     float data_lfe_ch[],                   /* i/o: LFE signal                       */
     547             :     const int16_t input_frame              /* i  : input frame length per channel   */
     548             : )
     549             : {
     550       48850 :     ivas_filter_process( hLfeLpf, data_lfe_ch, input_frame );
     551             : 
     552       48850 :     return;
     553             : }

Generated by: LCOV version 1.14