LCOV - code coverage report
Current view: top level - lib_dec - ivas_lfe_dec_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 633e3f2e309758d10805ef21e0436356fe719b7a Lines: 236 243 97.1 %
Date: 2025-08-23 01:22:27 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             : #include "prot_fx.h"
      36             : #include "ivas_prot_fx.h"
      37             : #include "ivas_rom_com.h"
      38             : #include "rom_com.h"
      39             : #include "math.h"
      40             : #include "wmc_auto.h"
      41             : 
      42             : 
      43             : /*------------------------------------------------------------------------------------------*
      44             :  * Local constants
      45             :  *------------------------------------------------------------------------------------------*/
      46             : 
      47             : /* Delay handling of LFE: overall_lfe_delay = max(11.5, BLOCK_OFFSET_MS); */
      48             : #define BLOCK_OFFSET_MS    12
      49             : #define BLOCK_OFFSET_S_Q15 393
      50             : 
      51             : 
      52             : /*-----------------------------------------------------------------------------------------*
      53             :  * Function ivas_lfe_dec_delay_adjust_fx()
      54             :  *
      55             :  * Adjusts the input to be passed to filtering block taking into consideration
      56             :  * LFE delay calculated during initialization time
      57             :  *-----------------------------------------------------------------------------------------*/
      58             : 
      59       53744 : static void ivas_lfe_dec_delay_adjust_fx(
      60             :     LFE_DEC_HANDLE hLFE,
      61             :     Word32 *pInbuf,        // Q9
      62             :     Word32 output_lfe_ch[] // Q9
      63             : )
      64             : {
      65             :     Word16 i, diff, loop_counter;
      66             :     Word16 fade_len, dct_len, zero_pad_len;
      67             :     Word32 tmp_buffer[L_FRAME48k];
      68             : 
      69       53744 :     diff = sub( hLFE->lfe_prior_buf_len, hLFE->pWindow_state->fade_len ); // Q0
      70       53744 :     IF( diff < 0 )
      71             :     {
      72           0 :         loop_counter = 0;
      73             :     }
      74             :     ELSE
      75             :     {
      76       53744 :         loop_counter = diff;
      77             :     }
      78       53744 :     move16();
      79       53744 :     fade_len = hLFE->pWindow_state->fade_len; // Q0
      80       53744 :     move16();
      81       53744 :     dct_len = hLFE->pWindow_state->dct_len; // Q0
      82       53744 :     move16();
      83       53744 :     zero_pad_len = hLFE->pWindow_state->zero_pad_len; // Q0
      84       53744 :     move16();
      85             : 
      86       53744 :     FOR( i = 0; i < loop_counter; i++ )
      87             :     {
      88           0 :         tmp_buffer[i] = hLFE->prior_out_buffer_fx[i]; // Q9
      89           0 :         move32();
      90             :     }
      91             : 
      92    19648752 :     FOR( i = 0; i < fade_len; i++ )
      93             :     {
      94    19595008 :         tmp_buffer[i + loop_counter] = L_add( hLFE->prior_out_buffer_fx[i + loop_counter], pInbuf[i] ); // Q9
      95    19595008 :         move32();
      96             :     }
      97       53744 :     loop_counter = add( loop_counter, fade_len );
      98             : 
      99    24547504 :     FOR( i = 0; i < fade_len + ( zero_pad_len << 1 ); i++ )
     100             :     {
     101    24493760 :         tmp_buffer[i + loop_counter] = pInbuf[i + fade_len];
     102    24493760 :         move32();
     103             :     }
     104             : 
     105    19648752 :     FOR( i = 0; i < hLFE->lfe_prior_buf_len; i++ )
     106             :     {
     107    19595008 :         hLFE->prior_out_buffer_fx[i] = tmp_buffer[i + dct_len];
     108    19595008 :         move32();
     109             :     }
     110             : 
     111    24547504 :     FOR( i = 0; i < dct_len; i++ )
     112             :     {
     113    24493760 :         output_lfe_ch[i] = tmp_buffer[i];
     114    24493760 :         move32();
     115             :     }
     116             : 
     117       53744 :     return;
     118             : }
     119             : 
     120             : 
     121             : /*-----------------------------------------------------------------------------------------*
     122             :  * Function ivas_lfe_dec_windowing_fx()
     123             :  *
     124             :  * LFE windowing block, input is passed through Fielder window
     125             :  *-----------------------------------------------------------------------------------------*/
     126             : 
     127       53744 : static void ivas_lfe_dec_windowing_fx(
     128             :     LFE_DEC_HANDLE hLFE,
     129             :     Word32 *pInbuf // Q9
     130             : )
     131             : {
     132             :     Word16 i;
     133             :     Word16 fade_len;
     134             :     Word16 zero_pad_len;
     135             :     const Word32 *pWindow_coeffs;
     136             : 
     137       53744 :     fade_len = hLFE->pWindow_state->fade_len;
     138       53744 :     move16();
     139       53744 :     zero_pad_len = hLFE->pWindow_state->zero_pad_len;
     140       53744 :     move16();
     141       53744 :     pWindow_coeffs = hLFE->pWindow_state->pWindow_coeffs_fx; // Q31
     142             : 
     143    19648752 :     FOR( i = 0; i < fade_len; i++ )
     144             :     {
     145    19595008 :         pInbuf[i] = Mpy_32_32( pInbuf[zero_pad_len + i], pWindow_coeffs[i] );
     146    19595008 :         pInbuf[i] = Mpy_32_32( pInbuf[zero_pad_len + i], pWindow_coeffs[i] ); // Q9
     147    19595008 :         move32();
     148             :     }
     149             : 
     150     4952496 :     FOR( i = 0; i < zero_pad_len * 2; i++ )
     151             :     {
     152     4898752 :         pInbuf[fade_len + i] = pInbuf[zero_pad_len + fade_len + i];
     153     4898752 :         move32();
     154             :     }
     155             : 
     156    19648752 :     FOR( i = 0; i < fade_len; i++ )
     157             :     {
     158    19595008 :         pInbuf[zero_pad_len * 2 + fade_len + i] = Mpy_32_32( pInbuf[zero_pad_len * 3 + fade_len + i], pWindow_coeffs[fade_len - i - 1] ); // Q9
     159    19595008 :         move32();
     160             :     }
     161             : 
     162       53744 :     return;
     163             : }
     164             : 
     165             : 
     166             : /*-----------------------------------------------------------------------------------------*
     167             :  * Function ivas_lfe_dec_dequant_fx()
     168             :  *
     169             :  * LDE de-quatization block, calls arithmetic deccoding block inside
     170             :  *-----------------------------------------------------------------------------------------*/
     171             : 
     172       26721 : static Word16 ivas_lfe_dec_dequant_fx(
     173             :     LFE_DEC_HANDLE hLFE,
     174             :     Decoder_State *st0,
     175             :     Word32 *pOut_buf, // Q24
     176             :     Word16 *num_dct_pass_bins )
     177             : {
     178             :     Word16 shift_bits, i;
     179             :     Word16 quant_strategy;
     180             :     Word16 coding_strategy;
     181             :     Word16 base2_bit_size;
     182             :     Word16 lfe_bits;
     183             :     Word16 all_zeros_dct;
     184             :     Word16 min_shift_bits;
     185             :     Word16 shift;
     186             :     Word16 sign_bits[IVAS_LFE_MAX_NUM_DCT_COEFFS];
     187             :     Word16 abs_values[IVAS_LFE_MAX_NUM_DCT_COEFFS];
     188             :     Word16 values[IVAS_LFE_MAX_NUM_DCT_COEFFS];
     189             :     Word16 num_dct_coeffs, num_groups;
     190             : 
     191       26721 :     all_zeros_dct = get_next_indice_fx( st0, 1 );
     192       26721 :     lfe_bits = st0->next_bit_pos;
     193       26721 :     move16();
     194       26721 :     shift_bits = IVAS_LFE_SHIFT_BITS;
     195       26721 :     move16();
     196       26721 :     min_shift_bits = 0;
     197       26721 :     move16();
     198       26721 :     shift = 0;
     199       26721 :     move16();
     200             : 
     201       26721 :     IF( EQ_16( all_zeros_dct, 1 ) )
     202             :     {
     203      387515 :         FOR( i = 0; i < IVAS_LFE_MAX_NUM_DCT_COEFFS; i++ )
     204             :         {
     205      364720 :             pOut_buf[i] = 0;
     206      364720 :             move32();
     207             :         }
     208             :     }
     209             :     ELSE
     210             :     {
     211             :         Word32 two_pow_shift_by_4;
     212             :         Tastat as;
     213             :         Word16 iii, extra_bits_read;
     214             : 
     215        3926 :         extra_bits_read = 0;
     216        3926 :         move16();
     217        3926 :         quant_strategy = get_next_indice_fx( st0, 1 );
     218        3926 :         *num_dct_pass_bins = ivas_lfe_num_dct_pass_bins_tbl[quant_strategy];
     219        3926 :         move16();
     220        3926 :         num_dct_coeffs = shl( *num_dct_pass_bins, 1 );
     221        3926 :         num_groups = shr( num_dct_coeffs, 2 );
     222        3926 :         min_shift_bits = ivas_lfe_min_shift_tbl[quant_strategy];
     223        3926 :         move16();
     224        3926 :         shift = add( get_next_indice_fx( st0, shift_bits ), shl( min_shift_bits, 2 ) );
     225             : 
     226       66742 :         FOR( i = 0; i < num_dct_coeffs; i++ )
     227             :         {
     228       62816 :             sign_bits[i] = get_next_indice_fx( st0, 1 );
     229       62816 :             move16();
     230             :         }
     231             : 
     232        3926 :         coding_strategy = get_next_indice_fx( st0, 1 );
     233             : 
     234        3926 :         IF( coding_strategy )
     235             :         {
     236        2035 :             FOR( iii = 0; iii < num_groups; iii++ )
     237             :             {
     238        1628 :                 base2_bit_size = hLFE->lfe_dec_indices_coeffs_tbl[quant_strategy][iii];
     239        1628 :                 move16();
     240        8140 :                 FOR( i = 0; i < 4; i++ )
     241             :                 {
     242        6512 :                     abs_values[iii * 4 + i] = get_next_indice_fx( st0, base2_bit_size );
     243        6512 :                     move16();
     244             :                 }
     245             :             }
     246             :         }
     247             :         ELSE
     248             :         {
     249       17595 :             FOR( iii = 0; iii < num_groups; iii++ )
     250             :             {
     251       14076 :                 extra_bits_read = 0;
     252       14076 :                 move16();
     253       14076 :                 ivas_ari_start_decoding_14bits_ext_1_lfe( st0, &as, &extra_bits_read );
     254             : 
     255       70380 :                 FOR( i = 0; i < 4; i++ )
     256             :                 {
     257       56304 :                     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 );
     258       56304 :                     move16();
     259             :                 }
     260       14076 :                 ivas_ari_done_decoding_14bits_ext_1_lfe( st0, extra_bits_read );
     261             :             }
     262             :         }
     263             : 
     264       66742 :         FOR( i = 0; i < num_dct_coeffs; i++ )
     265             :         {
     266       62816 :             values[i] = shl( abs_values[i], 9 ); // Q9
     267       62816 :             move16();
     268       62816 :             IF( sign_bits[i] > 0 )
     269             :             {
     270       19792 :                 values[i] = shl( sub( negate( abs_values[i] ), 1 ), 9 ); // Q9
     271       19792 :                 move16();
     272             :             }
     273             :         }
     274             : 
     275        3926 :         two_pow_shift_by_4 = tbl_two_pow_shift_by_4[shift];
     276        3926 :         move32();
     277             : 
     278       19630 :         FOR( i = 0; i < num_groups; i++ )
     279             :         {
     280       15704 :             pOut_buf[2 * i] = Mpy_32_16_1( two_pow_shift_by_4, values[4 * i] ); // Q30 + Q9 >> 15 = Q24
     281       15704 :             move32();
     282       15704 :             pOut_buf[2 * i + 1] = Mpy_32_16_1( two_pow_shift_by_4, values[4 * i + 1] ); // Q30 + Q9 >> 15 = Q24
     283       15704 :             move32();
     284             : 
     285       15704 :             pOut_buf[2 * i + *num_dct_pass_bins] = Mpy_32_16_1( two_pow_shift_by_4, values[4 * i + 2] ); // Q30 + Q9 >> 15 = Q24
     286       15704 :             move32();
     287       15704 :             pOut_buf[2 * i + *num_dct_pass_bins + 1] = Mpy_32_16_1( two_pow_shift_by_4, values[4 * i + 3] ); // Q30 + Q9 >> 15 = Q24
     288       15704 :             move32();
     289             :         }
     290             :     }
     291             : 
     292       26721 :     lfe_bits = sub( st0->next_bit_pos, lfe_bits );
     293             : 
     294       26721 :     return lfe_bits;
     295             : }
     296             : 
     297             : 
     298             : #ifdef NONBE_FIX_MC_LFE_LPF
     299             : /*-------------------------------------------------------------------------
     300             :  * ivas_create_lfe_lpf_dec_fx()
     301             :  *
     302             :  * Create, allocate and initialize IVAS decoder LFE low pass filter state handle
     303             :  *-------------------------------------------------------------------------*/
     304             : 
     305           8 : static void ivas_create_lfe_lpf_dec_fx(
     306             :     ivas_filters_process_state_t *hLfeLpf, /* o  : LFE LPF handle          */
     307             :     const Word32 input_Fs                  /* i  : input sampling rate     */
     308             : )
     309             : {
     310             :     const Word32 *filt_coeff; // 31 - filt_coeff_e
     311           8 :     const Word16 *filt_coeff_e = NULL;
     312             : 
     313           8 :     ivas_lfe_lpf_select_filt_coeff_fx( input_Fs, IVAS_FILTER_ORDER_4, &filt_coeff, &filt_coeff_e );
     314           8 :     ivas_filters_init_fx( hLfeLpf, filt_coeff, filt_coeff_e, IVAS_FILTER_ORDER_4 );
     315             : 
     316           8 :     return;
     317             : }
     318             : #endif
     319             : 
     320             : /*-----------------------------------------------------------------------------------------*
     321             :  * Function ivas_lfe_dec_fx()
     322             :  *
     323             :  * LFE channel decoder
     324             :  *-----------------------------------------------------------------------------------------*/
     325             : 
     326       26872 : void ivas_lfe_dec_fx(
     327             :     LFE_DEC_HANDLE hLFE,       /* i/o: LFE decoder handle                              */
     328             :     Decoder_State *st0,        /* i/o: decoder state structure - for bitstream handling*/
     329             :     const Word16 output_frame, /* i  : output frame length per channel                 */
     330             :     const Word16 bfi,          /* i  : BFI flag                                        */
     331             :     Word32 output_lfe_ch[]     /* o  : output LFE synthesis                            Q9*/
     332             : )
     333             : {
     334             :     Word16 num_dct_pass_bins;
     335       26872 :     Word16 i, j, dct_len, q_out = 0;
     336       26872 :     move16();
     337             :     Word32 out[L_FRAME48k];                      // Q9
     338             :     Word32 t_audio[L_FRAME48k];                  // Q24
     339             :     Word32 lfe_dct[IVAS_LFE_MAX_NUM_DCT_COEFFS]; // Q24
     340             : 
     341       26872 :     dct_len = hLFE->pWindow_state->dct_len;
     342       26872 :     move16();
     343       26872 :     num_dct_pass_bins = IVAS_LFE_MAX_NUM_DCT_PASS_BINS;
     344       26872 :     move16();
     345             : 
     346       26872 :     IF( bfi == 0 )
     347             :     {
     348       26721 :         ivas_lfe_dec_dequant_fx( hLFE, st0, lfe_dct, &num_dct_pass_bins ); // Q24
     349             : 
     350       26721 :         set32_fx( t_audio, 0, dct_len );
     351       26721 :         Copy32( lfe_dct, t_audio, num_dct_pass_bins ); // Q24
     352       26721 :         q_out = Q24;
     353       26721 :         move16();
     354       26721 :         ivas_imdct_fx( t_audio, out, dct_len, &q_out );           // Q9
     355       26721 :         ivas_lfe_dec_windowing_fx( hLFE, out );                   // Q9
     356       26721 :         ivas_lfe_dec_delay_adjust_fx( hLFE, out, output_lfe_ch ); // Q9
     357             : 
     358       26721 :         set32_fx( t_audio, 0, dct_len );
     359       26721 :         Copy32( &lfe_dct[num_dct_pass_bins], t_audio, num_dct_pass_bins ); // Q24
     360       26721 :         q_out = Q24;
     361       26721 :         move16();
     362       26721 :         ivas_imdct_fx( t_audio, out, dct_len, &q_out );                     // Q9
     363       26721 :         ivas_lfe_dec_windowing_fx( hLFE, out );                             // Q9
     364       26721 :         ivas_lfe_dec_delay_adjust_fx( hLFE, out, output_lfe_ch + dct_len ); // Q9
     365             : 
     366       26721 :         Copy32( hLFE->prevsynth_buf_fx + L_FRAME_1k6, hLFE->prevsynth_buf_fx, LFE_PLC_BUFLEN - L_FRAME_1k6 );
     367             : 
     368       26721 :         j = 0;
     369       26721 :         move16();
     370      881793 :         FOR( i = 0; i < L_FRAME_1k6; i++ )
     371             :         {
     372      855072 :             hLFE->prevsynth_buf_fx[i + LFE_PLC_BUFLEN - L_FRAME_1k6] = output_lfe_ch[j]; // Q9
     373      855072 :             move32();
     374      855072 :             j = add( j, shr( output_frame, 5 ) );
     375             :         }
     376             : 
     377       26721 :         hLFE->bfi_count = 0;
     378       26721 :         move16();
     379             :     }
     380             :     ELSE
     381             :     {
     382             :         /* note: in BFI branch, buffer 't_audio' is in time-domain ('wtda' signal) */
     383         151 :         hLFE->bfi_count = add( hLFE->bfi_count, 1 );
     384         151 :         move16();
     385         151 :         ivas_lfe_tdplc_fx( hLFE, hLFE->prevsynth_buf_fx, t_audio, output_frame );
     386             : 
     387         151 :         ivas_itda_fx( t_audio, out, dct_len );
     388         151 :         ivas_lfe_dec_windowing_fx( hLFE, out );
     389         151 :         ivas_lfe_dec_delay_adjust_fx( hLFE, out, output_lfe_ch );
     390             : 
     391         151 :         ivas_itda_fx( t_audio + dct_len, out, dct_len );
     392         151 :         ivas_lfe_dec_windowing_fx( hLFE, out );
     393         151 :         ivas_lfe_dec_delay_adjust_fx( hLFE, out, output_lfe_ch + dct_len );
     394             : 
     395         151 :         Copy32( hLFE->prevsynth_buf_fx + L_FRAME_1k6, hLFE->prevsynth_buf_fx, LFE_PLC_BUFLEN - L_FRAME_1k6 );
     396             : 
     397         151 :         j = 0;
     398         151 :         move16();
     399        4983 :         FOR( i = 0; i < L_FRAME_1k6; i++ )
     400             :         {
     401        4832 :             hLFE->prevsynth_buf_fx[i + LFE_PLC_BUFLEN - L_FRAME_1k6] = output_lfe_ch[j];
     402        4832 :             move32();
     403        4832 :             j = add( j, shr( output_frame, 5 ) );
     404             :         }
     405             : #ifdef NONBE_FIX_MC_LFE_LPF
     406         151 :         q_out = Q9;
     407             : #endif
     408             :     }
     409             : 
     410       26872 :     IF( hLFE->filter_state.order > 0 )
     411             :     {
     412             :         /* Low Pass Filter */
     413         330 :         ivas_filter_process_fx( &hLFE->filter_state, output_lfe_ch, output_frame, q_out );
     414             :     }
     415             : 
     416             :     /* add delay to make overall max(block_offset, 11.5) */
     417       26872 :     IF( hLFE->lfe_addl_delay > 0 )
     418             :     {
     419       26872 :         delay_signal32_fx( output_lfe_ch, output_frame, hLFE->lfe_delay_buf_fx, hLFE->lfe_addl_delay );
     420             :     }
     421             : 
     422       26872 :     return;
     423             : }
     424             : 
     425             : 
     426             : /*-------------------------------------------------------------------------
     427             :  * ivas_create_lfe_dec()
     428             :  *
     429             :  * Create, allocate and initialize IVAS decoder LFE handle
     430             :  *-------------------------------------------------------------------------*/
     431             : 
     432         354 : ivas_error ivas_create_lfe_dec_fx(
     433             :     LFE_DEC_HANDLE *hLFE_out, /* o  : IVAS LFE decoder structure                           */
     434             :     const Word32 output_Fs,   /* i  : output sampling rate                                 Q0*/
     435             : #ifdef NONBE_FIX_MC_LFE_LPF
     436             :     const Word32 delay_ns /* i  : additional LFE delay to sync other channel outputs */
     437             : #else
     438             :     const Word32 binauralization_delay_ns /* i  : additional LFE delay to sync with binaural renderer  */
     439             : #endif
     440             : )
     441             : {
     442             :     Word16 low_pass_delay_dec_out, block_offset_s;
     443             :     Word16 filt_order, output_frame;
     444             :     LFE_DEC_HANDLE hLFE;
     445             :     Word16 i, j;
     446             : #ifndef NONBE_1360_LFE_DELAY
     447             :     int16_t add_delay_sa;
     448             :     Word16 lfe_addl_delay_s;
     449             : #else
     450             :     Word16 lfe_block_delay_s_fx;
     451             :     Word16 block_offset_samples, lfe_block_delay_samples;
     452             :     Word16 lfe_addl_delay_samples;
     453             : #endif
     454             :     Word32 output_fs_fx;
     455             : 
     456         354 :     low_pass_delay_dec_out = 0;
     457         354 :     move16();
     458         354 :     block_offset_s = 0;
     459         354 :     move16();
     460             : 
     461         354 :     output_frame = extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) );
     462             : 
     463             :     /*-----------------------------------------------------------------*
     464             :      * Allocate LFE handle
     465             :      *-----------------------------------------------------------------*/
     466             : 
     467         354 :     IF( ( hLFE = (LFE_DEC_HANDLE) malloc( sizeof( LFE_DEC_DATA ) ) ) == NULL )
     468             :     {
     469           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE\n" ) );
     470             :     }
     471             : 
     472             :     /*-----------------------------------------------------------------*
     473             :      * LFE Window: allocate and initialize
     474             :      *-----------------------------------------------------------------*/
     475             : 
     476         354 :     IF( ( hLFE->pWindow_state = (LFE_WINDOW_HANDLE) malloc( sizeof( LFE_WINDOW_DATA ) ) ) == NULL )
     477             :     {
     478           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE window structure\n" ) );
     479             :     }
     480             : 
     481         354 :     ivas_lfe_window_init_fx( hLFE->pWindow_state, output_Fs, output_frame );
     482             : 
     483             :     /* Initialization for entropy coding */
     484         354 :     hLFE->cum_freq_models[0][0] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg1;
     485         354 :     hLFE->cum_freq_models[0][1] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg2;
     486         354 :     hLFE->cum_freq_models[0][2] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg3;
     487         354 :     hLFE->cum_freq_models[0][3] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg4;
     488         354 :     hLFE->cum_freq_models[1][0] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg1;
     489         354 :     hLFE->cum_freq_models[1][1] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg2;
     490         354 :     hLFE->cum_freq_models[1][2] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg3;
     491         354 :     hLFE->cum_freq_models[1][3] = &ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg4;
     492             : 
     493             :     /* delay calculation */
     494             : #ifndef NONBE_1360_LFE_DELAY
     495             :     hLFE->lfe_block_delay_s_fx = add( IVAS_LFE_FADE_S_Q15, ivas_lfe_lpf_delay_Q15[IVAS_FILTER_ORDER_4 - 3] ); // Q15
     496             : #else
     497         354 :     lfe_block_delay_s_fx = add( IVAS_LFE_FADE_S_Q15, ivas_lfe_lpf_delay_Q15[IVAS_FILTER_ORDER_4 - 3] ); // Q15
     498             : #endif
     499         354 :     move16();
     500             : 
     501         354 :     block_offset_s = BLOCK_OFFSET_S_Q15; // Q15
     502         354 :     move16();
     503         354 :     filt_order = 0;
     504         354 :     move16();
     505         354 :     low_pass_delay_dec_out = 0; // Q15
     506         354 :     move16();
     507             : 
     508             : #ifdef NONBE_FIX_MC_LFE_LPF
     509         354 :     if ( delay_ns > ivas_lfe_lpf_delay_ns[IVAS_FILTER_ORDER_4 - 3] )
     510             :     {
     511           8 :         filt_order = 4;
     512           8 :         low_pass_delay_dec_out = ivas_lfe_lpf_delay_Q15[IVAS_FILTER_ORDER_4 - 3];
     513           8 :         ivas_create_lfe_lpf_dec_fx( &( hLFE->filter_state ), output_Fs );
     514             :     }
     515             : #endif
     516             : 
     517         354 :     hLFE->filter_state.order = filt_order;
     518         354 :     move16();
     519             : #ifndef NONBE_1360_LFE_DELAY
     520             :     hLFE->lfe_block_delay_s_fx = add( hLFE->lfe_block_delay_s_fx, low_pass_delay_dec_out ); // Q15
     521             :     move16();
     522             : #else
     523         354 :     lfe_block_delay_s_fx = add( lfe_block_delay_s_fx, low_pass_delay_dec_out );                         // Q15
     524             : #endif
     525         354 :     hLFE->lfe_prior_buf_len = NS2SA_FX2( output_Fs, IVAS_LFE_FADE_NS ); // Q0
     526         354 :     move16();
     527             : 
     528         354 :     hLFE->bfi_count = 0;
     529         354 :     move16();
     530             : 
     531         354 :     IF( NE_32( output_Fs, 48000 ) )
     532             :     {
     533          82 :         IF( NE_32( output_Fs, 32000 ) )
     534             :         {
     535          70 :             output_fs_fx = FS_16K_IN_NS_Q31; // Q31
     536             :         }
     537             :         ELSE
     538             :         {
     539          12 :             output_fs_fx = FS_32K_IN_NS_Q31;
     540             :         }
     541             :     }
     542             :     ELSE
     543             :     {
     544         272 :         output_fs_fx = FS_48K_IN_NS_Q31;
     545             :     }
     546         354 :     move32();
     547             : 
     548             : #ifdef NONBE_1360_LFE_DELAY
     549         354 :     block_offset_samples = (Word16) L_shr( imult3216( output_Fs, block_offset_s ), 15 );                                             // Q0
     550         354 :     block_offset_samples = add( block_offset_samples, (Word16) W_round64_L( W_mult0_32_32( L_shl( delay_ns, 1 ), output_fs_fx ) ) ); // Q0
     551         354 :     lfe_block_delay_samples = (Word16) L_shr( imult3216( output_Fs, lfe_block_delay_s_fx ), 15 );                                    // Q0
     552         354 :     lfe_addl_delay_samples = sub( block_offset_samples, lfe_block_delay_samples );
     553         354 :     lfe_addl_delay_samples = s_max( 0, lfe_addl_delay_samples );
     554         354 :     hLFE->lfe_addl_delay = lfe_addl_delay_samples;
     555         354 :     move16();
     556         354 :     hLFE->delay_ns = delay_ns;
     557         354 :     move32();
     558             : #else
     559             :     lfe_addl_delay_s = sub( block_offset_s, hLFE->lfe_block_delay_s_fx );                               // Q15
     560             :     lfe_addl_delay_s = s_max( 0, lfe_addl_delay_s );
     561             : #ifdef NONBE_FIX_MC_LFE_LPF
     562             :     add_delay_sa = (Word16) W_round64_L( W_mult0_32_32( L_shl( delay_ns, 1 ), output_fs_fx ) ); // Q0
     563             : #else
     564             :     add_delay_sa = (Word16) W_round64_L( W_mult0_32_32( L_shl( binauralization_delay_ns, 1 ), output_fs_fx ) ); // Q0
     565             : #endif
     566             :     move16();
     567             :     hLFE->lfe_addl_delay = add( (Word16) L_shr( imult3216( output_Fs, lfe_addl_delay_s ), 15 ), add_delay_sa ); // Q0
     568             :     move16();
     569             :     IF( add_delay_sa == 0 )
     570             :     {
     571             :         hLFE->lfe_block_delay_s_fx = add( hLFE->lfe_block_delay_s_fx, lfe_addl_delay_s );
     572             :     }
     573             :     ELSE
     574             :     {
     575             :         hLFE->lfe_block_delay_s_fx = add( hLFE->lfe_block_delay_s_fx, add( lfe_addl_delay_s, idiv1616( add_delay_sa, extract_l( output_Fs ) ) ) );
     576             :     }
     577             :     move16();
     578             : #endif
     579             : 
     580         354 :     IF( hLFE->lfe_addl_delay > 0 )
     581             :     {
     582         354 :         IF( ( hLFE->lfe_delay_buf_fx = (Word32 *) malloc( hLFE->lfe_addl_delay * sizeof( Word32 ) ) ) == NULL )
     583             :         {
     584           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE additional delay buffer\n" ) );
     585             :         }
     586         354 :         set32_fx( (Word32 *) hLFE->lfe_delay_buf_fx, 0, hLFE->lfe_addl_delay );
     587             :     }
     588             :     ELSE
     589             :     {
     590           0 :         hLFE->lfe_delay_buf_fx = NULL;
     591             :     }
     592             : 
     593             :     /* Initialization base2 bits for each subgroup for no entropy coding */
     594        1062 :     FOR( i = 0; i < IVAS_MAX_NUM_QUANT_STRATS; i++ )
     595             :     {
     596        3540 :         FOR( j = 0; j < IVAS_MAX_NUM_DCT_COEF_GROUPS; j++ )
     597             :         {
     598        2832 :             hLFE->lfe_dec_indices_coeffs_tbl[i][j] = ivas_lfe_log2_num_ele_in_coder_models_fx[i][j];
     599        2832 :             move16();
     600             :         }
     601             :     }
     602             : 
     603         354 :     *hLFE_out = hLFE;
     604             : 
     605         354 :     return IVAS_ERR_OK;
     606             : }
     607             : 
     608             : 
     609             : /*-------------------------------------------------------------------------
     610             :  * ivas_lfe_dec_close_fx()
     611             :  *
     612             :  * Destroy IVAS decoder LFE handle
     613             :  *-------------------------------------------------------------------------*/
     614             : 
     615        1209 : void ivas_lfe_dec_close_fx(
     616             :     LFE_DEC_HANDLE *hLFE /* i/o: LFE decoder handle */
     617             : )
     618             : {
     619        1209 :     test();
     620        1209 :     IF( hLFE == NULL || *hLFE == NULL )
     621             :     {
     622         855 :         return;
     623             :     }
     624             : 
     625         354 :     free( ( *hLFE )->pWindow_state );
     626         354 :     ( *hLFE )->pWindow_state = NULL;
     627             : 
     628         354 :     IF( ( *hLFE )->lfe_delay_buf_fx != NULL )
     629             :     {
     630         354 :         free( ( *hLFE )->lfe_delay_buf_fx );
     631         354 :         ( *hLFE )->lfe_delay_buf_fx = NULL;
     632             :     }
     633             : 
     634         354 :     free( ( *hLFE ) );
     635         354 :     ( *hLFE ) = NULL;
     636             : 
     637         354 :     return;
     638             : }

Generated by: LCOV version 1.14