LCOV - code coverage report
Current view: top level - lib_enc - ivas_lfe_enc.c (source / functions) Hit Total Coverage
Test: Coverage on main @ 6baab0c613aa6c7100498ed7b93676aa8198a493 Lines: 170 183 92.9 %
Date: 2025-05-28 04:28:20 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      244073 : 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      244073 :     index = 0;
      64      244073 :     num_ele_per_grp = IVAS_LFE_NUM_COEFFS_IN_SUBGRP << 1;
      65      244073 :     num_groups = ivas_lfe_num_dct_pass_bins_tbl[quant_strategy] >> 1;
      66             : 
      67     1220365 :     for ( i = 0; i < num_groups; i++ )
      68             :     {
      69      976292 :         max_value = ivas_lfe_num_ele_in_coder_models[quant_strategy][i];
      70      976292 :         ari_start_encoding_14bits( &as );
      71      976292 :         offset = 4 * i;
      72             : 
      73     4881460 :         for ( index = 0; index < num_ele_per_grp; index++ )
      74             :         {
      75     3905168 :             if ( values[index + offset] > max_value )
      76             :             {
      77        1743 :                 values[index + offset] = max_value;
      78             :             }
      79     3905168 :             ivas_ari_encode_14bits_ext( hBstr, &as, values[index + offset], hLFE->cum_freq_models[quant_strategy][i] );
      80             :         }
      81             : 
      82      976292 :         ivas_ari_done_encoding_14bits( hBstr, &as );
      83             :     }
      84             : 
      85      244073 :     return;
      86             : }
      87             : 
      88             : 
      89             : /*-----------------------------------------------------------------------------------------*
      90             :  * Function ivas_lfe_enc_quant()
      91             :  *
      92             :  * LFE quatization block, calls arithmetic coding block inside
      93             :  *-----------------------------------------------------------------------------------------*/
      94             : 
      95      419802 : 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      419802 :     int16_t num_ele_per_grp = IVAS_LFE_NUM_COEFFS_IN_SUBGRP << 1;
     113             : 
     114      419802 :     target_bits = (int16_t) ( IVAS_LFE_BITRATE_5000 / FRAMES_PER_SEC );
     115             : 
     116      419802 :     write_bit = 0;
     117      419802 :     num_quant_strategies = IVAS_MAX_NUM_QUANT_STRATS;
     118      419802 :     shift_bits = IVAS_LFE_SHIFT_BITS;
     119      419802 :     bits_written = hBstr->nb_bits_tot;
     120      419802 :     nb_ind_tot = hBstr->nb_ind_tot;
     121             : 
     122             : 
     123      419802 :     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      419802 :         lfe_abs_sum = 0;
     135      419802 :         coding_strategy = 0;
     136      419802 :         num_dct_pass_bins = ivas_lfe_num_dct_pass_bins_tbl[quant_strategy];
     137      419802 :         max_of_vals = 0;
     138      419802 :         num_groups = num_dct_pass_bins >> 1;
     139      419802 :         shift = 0;
     140      419802 :         min_shift = ivas_lfe_min_shift_tbl[quant_strategy];
     141      419802 :         max_shift = min_shift * IVAS_LFE_SHIFTS_PER_DOUBLE + ( 1 << shift_bits ) - 1;
     142      419802 :         num_lfe_ele = num_dct_pass_bins * IVAS_LFE_NUM_COEFFS_IN_SUBGRP;
     143      419802 :         all_zeros_dct = 0;
     144      419802 :         max_value = ivas_lfe_num_ele_in_coder_models[quant_strategy][0];
     145             : 
     146      419802 :         mvr2r( &pLfe_dct[IVAS_LFE_MAX_NUM_DCT_PASS_BINS], &pLfe_dct[num_dct_pass_bins], num_dct_pass_bins );
     147             : 
     148     2099010 :         for ( i = 0; i < num_groups; i++ )
     149             :         {
     150     1679208 :             temp_lfe_dct[4 * i] = pLfe_dct[2 * i];
     151     1679208 :             lfe_abs_sum += fabsf( temp_lfe_dct[4 * i] );
     152     1679208 :             temp_lfe_dct[4 * i + 1] = pLfe_dct[2 * i + 1];
     153     1679208 :             lfe_abs_sum += fabsf( temp_lfe_dct[4 * i + 1] );
     154             : 
     155     1679208 :             temp_lfe_dct[4 * i + 2] = pLfe_dct[2 * i + num_dct_pass_bins];
     156     1679208 :             lfe_abs_sum += fabsf( temp_lfe_dct[4 * i + 2] );
     157     1679208 :             temp_lfe_dct[4 * i + 3] = pLfe_dct[2 * i + num_dct_pass_bins + 1];
     158     1679208 :             lfe_abs_sum += fabsf( temp_lfe_dct[4 * i + 3] );
     159             :         }
     160             : 
     161      419802 :         if ( lfe_abs_sum <= IVAS_LFE_ABS_SUM_FLT_THR )
     162             :         {
     163         296 :             shift = max_shift;
     164             :         }
     165             :         else
     166             :         {
     167      419506 :             shift = (int16_t) floorf( IVAS_LFE_SHIFTS_PER_DOUBLE * log2_f( max_value / lfe_abs_sum ) );
     168             :         }
     169             : 
     170      419802 :         shift = max( min_shift * IVAS_LFE_SHIFTS_PER_DOUBLE, min( max_shift, shift ) );
     171             : 
     172             :         while ( 1 )
     173             :         {
     174      419802 :             if ( shift == max_shift )
     175             :             {
     176             :                 /* write all LFE bits as 0 */
     177      175729 :                 all_zeros_dct = 1;
     178      175729 :                 break;
     179             :             }
     180             :             else
     181             :             {
     182      244073 :                 max_of_vals = 0;
     183     4149241 :                 for ( i = 0; i < num_lfe_ele; i++ )
     184             :                 {
     185             :                     float temp;
     186     3905168 :                     temp = temp_lfe_dct[i] * powf( 2, ( (float) shift / IVAS_LFE_SHIFTS_PER_DOUBLE ) );
     187             : 
     188     3905168 :                     if ( temp < 0 )
     189             :                     {
     190     1958885 :                         values[i] = (int16_t) ( temp - 0.5f );
     191             :                     }
     192             :                     else
     193             :                     {
     194     1946283 :                         values[i] = (int16_t) ( temp + 0.5f );
     195             :                     }
     196             : 
     197     3905168 :                     if ( max_of_vals < abs( values[i] ) )
     198             :                     {
     199      514084 :                         max_of_vals = (int16_t) abs( values[i] );
     200             :                     }
     201             :                 }
     202             :             }
     203      244073 :             if ( max_of_vals <= max_value )
     204             :             {
     205      244073 :                 break;
     206             :             }
     207           0 :             shift = shift - 1;
     208             :         }
     209             : 
     210      419802 :         if ( shift < min_shift * IVAS_LFE_SHIFTS_PER_DOUBLE )
     211             :         {
     212           0 :             continue;
     213             :         }
     214             : 
     215      419802 :         if ( all_zeros_dct != 1 )
     216             :         {
     217      244073 :             push_next_indice( hBstr, all_zeros_dct, 1 );
     218      244073 :             push_next_indice( hBstr, quant_strategy, 1 );
     219      244073 :             push_next_indice( hBstr, shift - min_shift * IVAS_LFE_SHIFTS_PER_DOUBLE, shift_bits );
     220             :         }
     221             :         else
     222             :         {
     223      175729 :             push_next_indice( hBstr, all_zeros_dct, 1 );
     224      175729 :             hLFE->lfe_bits = hBstr->nb_bits_tot - bits_written;
     225      175729 :             return;
     226             :         }
     227             : 
     228     4149241 :         for ( i = 0; i < num_lfe_ele; i++ )
     229             :         {
     230     3905168 :             if ( values[i] < 0 )
     231             :             {
     232     1161422 :                 write_bit = 1;
     233     1161422 :                 values[i] = values[i] + 1;
     234             :             }
     235             :             else
     236             :             {
     237     2743746 :                 write_bit = 0;
     238             :             }
     239             : 
     240     3905168 :             values[i] = (int16_t) abs( values[i] );
     241             : 
     242     3905168 :             push_next_indice( hBstr, write_bit, 1 );
     243             :         }
     244             : 
     245      244073 :         bits_written_arith_enc = hBstr->nb_bits_tot;
     246      244073 :         next_ind_pos_arith_enc = hBstr->nb_ind_tot;
     247      244073 :         push_next_indice( hBstr, coding_strategy, 1 );
     248      244073 :         base2_num_bits_tot = hBstr->nb_bits_tot - bits_written;
     249             : 
     250      244073 :         ivas_lfe_arith_coding( hLFE, hBstr, quant_strategy, values );
     251             : 
     252     1220365 :         for ( i = 0; i < num_groups; i++ )
     253             :         {
     254      976292 :             int16_t base2_num_bits = hLFE->lfe_enc_indices_coeffs_tbl[quant_strategy][i];
     255      976292 :             base2_num_bits_tot += ( num_ele_per_grp * base2_num_bits );
     256             :         }
     257             : 
     258      244073 :         if ( ( base2_num_bits_tot ) < ( hBstr->nb_bits_tot - bits_written ) )
     259             :         {
     260         433 :             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       29899 :                 for ( j = hBstr->nb_ind_tot - 1; j >= next_ind_pos_arith_enc; j-- )
     264             :                 {
     265       29466 :                     hBstr->ind_list[j].nb_bits = -1;
     266             :                 }
     267         433 :                 hBstr->nb_ind_tot = next_ind_pos_arith_enc;
     268         433 :                 hBstr->nb_bits_tot = bits_written_arith_enc;
     269         433 :                 coding_strategy = 1;
     270         433 :                 push_next_indice( hBstr, coding_strategy, 1 );
     271             : 
     272        2165 :                 for ( i = 0; i < num_groups; i++ )
     273             :                 {
     274        1732 :                     int16_t base2_write_bits = hLFE->lfe_enc_indices_coeffs_tbl[quant_strategy][i];
     275        1732 :                     int16_t offset = 4 * i;
     276        1732 :                     max_value = ivas_lfe_num_ele_in_coder_models[quant_strategy][i];
     277             : 
     278        8660 :                     for ( j = 0; j < num_ele_per_grp; j++ )
     279             :                     {
     280        6928 :                         if ( values[j + offset] > max_value )
     281             :                         {
     282           0 :                             values[j + offset] = max_value;
     283             :                         }
     284        6928 :                         push_next_indice( hBstr, values[j + offset], base2_write_bits );
     285             :                     }
     286             :                 }
     287         433 :                 break;
     288             :             }
     289             :         }
     290             :         else
     291             :         {
     292      243640 :             if ( ( target_bits + IVAS_LFE_ID_BITS ) >= ( hBstr->nb_bits_tot - bits_written ) )
     293             :             {
     294      243640 :                 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      244073 :     hLFE->lfe_bits = hBstr->nb_bits_tot - bits_written;
     314             : 
     315      244073 :     return;
     316             : }
     317             : 
     318             : 
     319             : /*-----------------------------------------------------------------------------------------*
     320             :  * Function ivas_lfe_enc()
     321             :  *
     322             :  * LFE channel encoder
     323             :  *-----------------------------------------------------------------------------------------*/
     324             : 
     325      419802 : 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      419802 :     num_dct_pass_bins = IVAS_LFE_MAX_NUM_DCT_PASS_BINS;
     341      419802 :     fade_len = hLFE->pWindow_state->fade_len;
     342      419802 :     full_len = hLFE->pWindow_state->full_len;
     343      419802 :     dct_len = hLFE->pWindow_state->dct_len;
     344      419802 :     zero_pad_len = hLFE->pWindow_state->zero_pad_len;
     345      419802 :     pWindow_coeffs = hLFE->pWindow_state->pWindow_coeffs;
     346             : 
     347             :     /* Windowing */
     348      419802 :     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      419802 :     ivas_mdct( wtda_audio, t_audio, dct_len );
     351             : 
     352      419802 :     mvr2r( t_audio, lfe_dct, num_dct_pass_bins );
     353             : 
     354             :     /* windowing */
     355      419802 :     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      419802 :     ivas_mdct( wtda_audio, t_audio, dct_len );
     359             : 
     360      419802 :     mvr2r( t_audio, lfe_dct + num_dct_pass_bins, num_dct_pass_bins );
     361             : 
     362      419802 :     ivas_lfe_enc_quant( hLFE, lfe_dct, hBstr );
     363             : 
     364      419802 :     return;
     365             : }
     366             : 
     367             : 
     368             : /*-------------------------------------------------------------------------
     369             :  * ivas_create_lfe_enc()
     370             :  *
     371             :  * Create, allocate and initialize IVAS encoder LFE handle
     372             :  *-------------------------------------------------------------------------*/
     373             : 
     374        5847 : 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        5847 :     input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC );
     384             : 
     385             :     /*-----------------------------------------------------------------*
     386             :      * Allocate LFE handle
     387             :      *-----------------------------------------------------------------*/
     388             : 
     389        5847 :     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        5847 :     hLFE->lfe_bits = 0;
     396             : 
     397        5847 :     hLFE->pWindow_state = NULL;
     398        5847 :     hLFE->hBstr = NULL;
     399             : 
     400             :     /*-----------------------------------------------------------------*
     401             :      * Input memory buffer: allocate and initialize
     402             :      *-----------------------------------------------------------------*/
     403             : 
     404        5847 :     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        5847 :     set_zero( hLFE->old_wtda_audio, NS2SA( input_Fs, IVAS_LFE_FADE_NS ) );
     410             : 
     411             :     /*-----------------------------------------------------------------*
     412             :      * LFE Window: allocate and initialize
     413             :      *-----------------------------------------------------------------*/
     414             : 
     415        5847 :     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        5847 :     ivas_lfe_window_init( hLFE->pWindow_state, input_Fs, input_frame );
     421             : 
     422             :     /* Initialization for entropy coding */
     423        5847 :     hLFE->cum_freq_models[0][0] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg1;
     424        5847 :     hLFE->cum_freq_models[0][1] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg2;
     425        5847 :     hLFE->cum_freq_models[0][2] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg3;
     426        5847 :     hLFE->cum_freq_models[0][3] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg4;
     427        5847 :     hLFE->cum_freq_models[1][0] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg1;
     428        5847 :     hLFE->cum_freq_models[1][1] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg2;
     429        5847 :     hLFE->cum_freq_models[1][2] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg3;
     430        5847 :     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       17541 :     for ( i = 0; i < IVAS_MAX_NUM_QUANT_STRATS; i++ )
     434             :     {
     435       58470 :         for ( j = 0; j < IVAS_MAX_NUM_DCT_COEF_GROUPS; j++ )
     436             :         {
     437       46776 :             hLFE->lfe_enc_indices_coeffs_tbl[i][j] =
     438       46776 :                 (int16_t) ceilf( log2f( (float) ( ivas_lfe_num_ele_in_coder_models[i][j] + 1 ) ) );
     439             :         }
     440             :     }
     441             : 
     442        5847 :     *hLFE_out = hLFE;
     443             : 
     444        5847 :     return IVAS_ERR_OK;
     445             : }
     446             : 
     447             : 
     448             : /*-------------------------------------------------------------------------
     449             :  * ivas_lfe_enc_close()
     450             :  *
     451             :  * Destroy IVAS cncoder LFE handle
     452             :  *-------------------------------------------------------------------------*/
     453             : 
     454        9920 : void ivas_lfe_enc_close(
     455             :     LFE_ENC_HANDLE *hLFE /* i/o: LFE encoder handle */
     456             : )
     457             : {
     458        9920 :     if ( hLFE == NULL || *hLFE == NULL )
     459             :     {
     460        4073 :         return;
     461             :     }
     462             : 
     463        5847 :     if ( ( *hLFE )->old_wtda_audio != NULL )
     464             :     {
     465        5847 :         free( ( *hLFE )->old_wtda_audio );
     466        5847 :         ( *hLFE )->old_wtda_audio = NULL;
     467             :     }
     468        5847 :     if ( ( *hLFE )->pWindow_state )
     469             :     {
     470        5847 :         free( ( *hLFE )->pWindow_state );
     471        5847 :         ( *hLFE )->pWindow_state = NULL;
     472             :     }
     473             : 
     474        5847 :     free( ( *hLFE ) );
     475        5847 :     ( *hLFE ) = NULL;
     476             : 
     477        5847 :     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         384 : 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         384 :     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         384 :     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         384 :     ivas_lfe_lpf_select_filt_coeff( input_Fs, IVAS_FILTER_ORDER_4, &filt_coeff );
     509             : 
     510         384 :     ivas_filters_init( *hLfeLpf, filt_coeff, IVAS_FILTER_ORDER_4 );
     511             : 
     512         384 :     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        4269 : void ivas_lfe_lpf_enc_close(
     523             :     ivas_filters_process_state_t **hLfeLpf /* i/o: LFE LPF handle */
     524             : )
     525             : {
     526        4269 :     if ( hLfeLpf == NULL || *hLfeLpf == NULL )
     527             :     {
     528        3885 :         return;
     529             :     }
     530             : 
     531         384 :     free( ( *hLfeLpf ) );
     532         384 :     ( *hLfeLpf ) = NULL;
     533             : 
     534         384 :     return;
     535             : }
     536             : 
     537             : 
     538             : /*-------------------------------------------------------------------------
     539             :  * ivas_lfe_lpf_enc_apply()
     540             :  *
     541             :  * Apply IVAS cncoder LFE low pass filter
     542             :  *-------------------------------------------------------------------------*/
     543             : 
     544      728490 : 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      728490 :     ivas_filter_process( hLfeLpf, data_lfe_ch, input_frame );
     551             : 
     552      728490 :     return;
     553             : }

Generated by: LCOV version 1.14