LCOV - code coverage report
Current view: top level - lib_dec - init_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- long test vectors @ efe53129c9ed87a5067dd0a8fb9dca41db9c4add Lines: 286 311 92.0 %
Date: 2026-02-12 08:06:16 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2026 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             : /*====================================================================================
      34             :     EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
      35             :   ====================================================================================*/
      36             : 
      37             : #include <stdint.h>
      38             : #include "options.h"
      39             : #ifdef DEBUGGING
      40             : #include "debug.h"
      41             : #endif
      42             : #include "cnst.h"
      43             : #include "ivas_cnst.h"
      44             : #include "rom_com.h"
      45             : #include "prot.h"
      46             : #include "wmc_auto.h"
      47             : 
      48             : /*----------------------------------------------------------------------*
      49             :  * init_decoder()
      50             :  *
      51             :  * Initialization of static variables for the decoder
      52             :  *----------------------------------------------------------------------*/
      53             : 
      54      347479 : ivas_error init_decoder(
      55             :     Decoder_State *st,    /* o  : Decoder static variables structure  */
      56             :     const int16_t idchan, /* i  : channel ID                          */
      57             :     const MC_MODE mc_mode /* i  : MC mode                             */
      58             : )
      59             : {
      60             :     int16_t i;
      61             :     ivas_error error;
      62             : 
      63      347479 :     error = IVAS_ERR_OK;
      64             : 
      65             :     /*-----------------------------------------------------------------*
      66             :      * General parameters
      67             :      *-----------------------------------------------------------------*/
      68             : 
      69      347479 :     st->codec_mode = MODE1;
      70      347479 :     st->last_codec_mode = MODE1;
      71      347479 :     st->core = ACELP_CORE;
      72      347479 :     st->L_frame = L_FRAME;
      73      347479 :     st->extl = -1;
      74      347479 :     st->extl_orig = -1;
      75      347479 :     st->extl_brate_orig = 0;
      76      347479 :     st->last_bits_frame_nominal = -1;
      77      347479 :     st->total_brate = ACELP_8k00;
      78      347479 :     st->last_total_brate = -1;
      79      347479 :     st->last_total_brate_ber = -1;
      80      347479 :     st->core_brate = ACELP_8k00;
      81      347479 :     st->ini_frame = 0;
      82      347479 :     if ( st->element_mode == EVS_MONO )
      83             :     {
      84          64 :         st->bwidth = NB;
      85          64 :         st->last_bwidth = NB;
      86             :     }
      87             :     else
      88             :     {
      89      347415 :         st->bwidth = WB;
      90      347415 :         st->last_bwidth = WB;
      91             :     }
      92      347479 :     st->extl_brate = 0;
      93             : 
      94      347479 :     st->coder_type = GENERIC;
      95      347479 :     st->last_coder_type = GENERIC;
      96      347479 :     st->inactive_coder_type_flag = 0;
      97      347479 :     st->last_L_frame = st->L_frame;
      98      347479 :     st->last_core_brate = st->core_brate;
      99      347479 :     st->last_core = -1;
     100      347479 :     st->last_extl = st->extl;
     101             : 
     102      347479 :     st->flag_ACELP16k = set_ACELP_flag( st->element_mode, st->total_brate, st->total_brate, idchan, 0, -1, -1 );
     103             : 
     104             :     /*-----------------------------------------------------------------*
     105             :      * ACELP core parameters
     106             :      *-----------------------------------------------------------------*/
     107             : 
     108             :     /* LSF initilalizations */
     109      347479 :     mvr2r( GEWB_Ave, st->mem_AR, M );
     110             : 
     111      347479 :     set_f( st->mem_MA, 0, M );
     112      347479 :     set_f( st->dispMem, 0, 8 );
     113             : 
     114      347479 :     st->tilt_code = 0.0f;
     115      347479 :     st->gc_threshold = 0.0f;
     116      347479 :     st->last_good = UNVOICED_CLAS;
     117      347479 :     st->clas_dec = UNVOICED_CLAS;
     118      347479 :     st->low_rate_mode = 0;
     119      347479 :     st->last_low_rate_mode = 0;
     120             : 
     121      347479 :     st->lp_gainp = 0.0f;
     122      347479 :     st->lp_gainc = 0.0f;
     123             : 
     124      347479 :     set_f( st->old_exc, 0, L_EXC_MEM_DEC );
     125             : 
     126             :     /* AVQ pre-quantizer memory */
     127      347479 :     st->mem_preemp_preQ = 0.0f;
     128      347479 :     st->last_nq_preQ = 0;
     129      347479 :     st->last_code_preq = 0;
     130      347479 :     st->use_acelp_preq = 0;
     131             : 
     132      347479 :     st->mem_deemph = 0.0f;
     133             : 
     134      347479 :     set_f( st->mem_syn1, 0, M );
     135      347479 :     set_f( st->mem_syn2, 0, M );
     136      347479 :     st->stab_fac = 0.0f;
     137      347479 :     st->stab_fac_smooth = 0.0f;
     138      347479 :     set_f( st->agc_mem2, 0, 2 );
     139      347479 :     set_f( st->mem_syn3, 0, M );
     140      347479 :     st->stab_fac_smooth_lt = 0.0f;
     141      347479 :     st->log_energy_diff_lt = 0.0f;
     142      347479 :     st->log_energy_old = 0.0f;
     143             : 
     144      347479 :     mvr2r( GEWB_Ave, st->lsf_old, M );
     145      347479 :     lsf2lsp( st->lsf_old, st->lsp_old, M, INT_FS_12k8 );
     146             : 
     147      347479 :     st->mid_lsf_int = 0;
     148      347479 :     st->safety_net = 0;
     149             : 
     150             :     /* FEC */
     151      347479 :     st->scaling_flag = 0;
     152      347479 :     st->lp_ener_FEC_av = 5.0e5f;
     153      347479 :     st->lp_ener_FEC_max = 5.0e5f;
     154      347479 :     st->prev_bfi = 0;
     155      347479 :     st->lp_ener_bfi = 60.0f;
     156      347479 :     st->old_enr_LP = 0.0f;
     157      347479 :     st->lp_ener = 0.0f;
     158      347479 :     st->enr_old = 0.0f;
     159      347479 :     st->bfi_pitch = (float) L_SUBFR;
     160      347479 :     st->bfi_pitch_frame = L_FRAME;
     161      347479 :     set_f( st->mem_syn_clas_estim, 0.0f, L_SYN_MEM_CLAS_ESTIM );
     162      347479 :     st->last_con_tcx = 0;
     163             : 
     164     3822269 :     for ( i = 0; i < 2 * NB_SUBFR16k; i++ )
     165             :     {
     166     3474790 :         st->old_pitch_buf[i] = (float) L_SUBFR;
     167             :     }
     168             : 
     169      347479 :     st->upd_cnt = MAX_UPD_CNT;
     170             : 
     171      347479 :     mvr2r( GEWB_Ave, st->lsfoldbfi0, M );
     172      347479 :     mvr2r( GEWB_Ave, st->lsfoldbfi1, M );
     173      347479 :     mvr2r( GEWB_Ave, st->lsf_adaptive_mean, M );
     174             : 
     175      347479 :     st->seed_acelp = RANDOM_INITSEED;
     176      347479 :     st->seed = RANDOM_INITSEED;
     177      347479 :     st->nbLostCmpt = 0;
     178      347479 :     st->decision_hyst = 0;
     179             : 
     180             :     /* Stationary noise UV modification */
     181      347479 :     st->unv_cnt = 0;
     182      347479 :     st->ge_sm = 10;
     183      347479 :     st->uv_count = 0;
     184      347479 :     st->act_count = 3;
     185      347479 :     mvr2r( st->lsp_old, st->lspold_s, M );
     186      347479 :     st->noimix_seed = RANDOM_INITSEED;
     187      347479 :     st->min_alpha = 1;
     188      347479 :     st->exc_pe = 0;
     189             : 
     190      347479 :     st->prev_coder_type = GENERIC;
     191      347479 :     st->tilt_wb = 0.0f;
     192             : 
     193      347479 :     st->last_voice_factor = 0.0f;
     194      347479 :     set_f( st->prev_synth_buffer, 0, NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ) );
     195             : 
     196      347479 :     st->old_bfi_cnt = 0;
     197             : 
     198             :     /*-----------------------------------------------------------------*
     199             :      * parameters for AC mode (GSC)
     200             :      *-----------------------------------------------------------------*/
     201             : 
     202      347479 :     st->GSC_noisy_speech = 0;
     203      347479 :     st->GSC_IVAS_mode = 0;
     204      347479 :     st->Last_GSC_noisy_speech_flag = 0;
     205             : 
     206      347479 :     if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) || st->element_mode == IVAS_CPE_TD )
     207             :     {
     208      150304 :         if ( ( st->hGSCDec = (GSC_DEC_HANDLE) malloc( sizeof( GSC_DEC_DATA ) ) ) == NULL )
     209             :         {
     210           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) );
     211             :         }
     212             : 
     213      150304 :         GSC_dec_init( st->hGSCDec );
     214             :     }
     215             :     else
     216             :     {
     217      197175 :         st->hGSCDec = NULL;
     218             :     }
     219             : 
     220             :     /*-----------------------------------------------------------------*
     221             :      * parameters for fast recovery (WI)
     222             :      *-----------------------------------------------------------------*/
     223             : 
     224      347479 :     if ( st->output_Fs == 16000 && st->element_mode == EVS_MONO )
     225             :     {
     226          20 :         if ( ( st->hWIDec = (WI_DEC_HANDLE) malloc( sizeof( WI_DEC_DATA ) ) ) == NULL )
     227             :         {
     228           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FEC WI\n" ) );
     229             :         }
     230             : 
     231          20 :         set_f( st->hWIDec->old_exc2, 0, L_EXC_MEM );
     232          20 :         set_f( st->hWIDec->old_syn2, 0, L_EXC_MEM );
     233             :     }
     234             :     else
     235             :     {
     236      347459 :         st->hWIDec = NULL;
     237             :     }
     238             : 
     239             :     /*-----------------------------------------------------------------*
     240             :      * NB/formant post-filter
     241             :      *-----------------------------------------------------------------*/
     242             : 
     243      347479 :     if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) || st->element_mode == IVAS_CPE_TD )
     244             :     {
     245      150304 :         if ( ( st->hPFstat = (PFSTAT_HANDLE) malloc( sizeof( PFSTAT ) ) ) == NULL )
     246             :         {
     247           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for NB/formant postflter\n" ) );
     248             :         }
     249             : 
     250      150304 :         Init_post_filter( st->hPFstat );
     251      150304 :         st->psf_lp_noise = 0.0f;
     252             :     }
     253             :     else
     254             :     {
     255      197175 :         st->hPFstat = NULL;
     256             :     }
     257             : 
     258             :     /*-----------------------------------------------------------------*
     259             :      * HF (6-7kHz) (zero) BWE parameters
     260             :      *-----------------------------------------------------------------*/
     261             : 
     262      347479 :     if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) || st->element_mode == IVAS_CPE_TD )
     263             :     {
     264      150304 :         if ( ( st->hBWE_zero = (ZERO_BWE_DEC_HANDLE) malloc( sizeof( ZERO_BWE_DEC_DATA ) ) ) == NULL )
     265             :         {
     266           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for zero BWE\n" ) );
     267             :         }
     268             : 
     269      150304 :         hf_synth_init( st->hBWE_zero );
     270             :     }
     271             :     else
     272             :     {
     273      197175 :         st->hBWE_zero = NULL;
     274             :     }
     275             : 
     276             : 
     277             :     /*-----------------------------------------------------------------*
     278             :      * LD music post-filter
     279             :      *-----------------------------------------------------------------*/
     280             : 
     281      347479 :     if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) || st->element_mode == IVAS_CPE_TD )
     282             :     {
     283      150304 :         if ( ( st->hMusicPF = (MUSIC_POSTFILT_HANDLE) malloc( sizeof( MUSIC_POSTFILT_DATA ) ) ) == NULL )
     284             :         {
     285           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LD music postflter\n" ) );
     286             :         }
     287             : 
     288      150304 :         music_postfilt_init( st->hMusicPF );
     289             :     }
     290             :     else
     291             :     {
     292      197175 :         st->hMusicPF = NULL;
     293             :     }
     294             : 
     295             :     /*-----------------------------------------------------------------*
     296             :      * CNG and DTX
     297             :      *-----------------------------------------------------------------*/
     298             : 
     299      347479 :     st->first_CNG = 0;
     300      347479 :     st->cng_type = -1;
     301      347479 :     st->last_vad = 0;
     302      347479 :     st->last_active_brate = ACELP_7k20;
     303      347479 :     st->last_CNG_L_frame = L_FRAME;
     304      347479 :     st->active_cnt = CNG_TYPE_HO;
     305             : 
     306      347479 :     if ( idchan == 0 && ( st->element_mode == EVS_MONO || st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) )
     307             :     {
     308         355 :         if ( ( st->hTdCngDec = (TD_CNG_DEC_HANDLE) malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL )
     309             :         {
     310           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) );
     311             :         }
     312             : 
     313         355 :         td_cng_dec_init( st );
     314             :     }
     315             :     else
     316             :     {
     317      347124 :         st->hTdCngDec = NULL;
     318             :     }
     319             : 
     320      347479 :     st->masa_sid_format = 0;
     321             : 
     322             :     /*-----------------------------------------------------------------*
     323             :      * HQ core parameters
     324             :      *-----------------------------------------------------------------*/
     325             : 
     326      347479 :     st->prev_old_bfi = 0;
     327      347479 :     set_f( st->delay_buf_out, 0, HQ_DELTA_MAX * HQ_DELAY_COMP );
     328      347479 :     set_f( st->previoussynth, 0, L_FRAME48k );
     329             : 
     330      347479 :     if ( st->element_mode == EVS_MONO )
     331             :     {
     332          64 :         set_f( st->old_synth_sw, 0.0f, NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ) );
     333             :     }
     334             : 
     335      347479 :     if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT || st->element_mode == IVAS_SCE || st->element_mode == EVS_MONO ) )
     336             :     {
     337      347188 :         if ( ( st->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL )
     338             :         {
     339           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) );
     340             :         }
     341             : 
     342             :         /* HQ core initialization */
     343      347188 :         HQ_core_dec_init( st->hHQ_core );
     344             : 
     345      347188 :         if ( st->element_mode == EVS_MONO )
     346             :         {
     347             :             /* HQ NB FEC initialization */
     348          64 :             if ( ( st->hHQ_nbfec = (HQ_NBFEC_HANDLE) malloc( sizeof( HQ_NBFEC_DATA ) ) ) == NULL )
     349             :             {
     350           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ NB FEC\n" ) );
     351             :             }
     352          64 :             HQ_nbfec_init( st->hHQ_nbfec );
     353             :         }
     354             :         else
     355             :         {
     356      347124 :             st->hHQ_nbfec = NULL;
     357             :         }
     358             :     }
     359             :     else
     360             :     {
     361         291 :         st->hHQ_core = NULL;
     362         291 :         st->hHQ_nbfec = NULL;
     363             :     }
     364             : 
     365             :     /*-----------------------------------------------------------------*
     366             :      * TBE parameters
     367             :      *-----------------------------------------------------------------*/
     368             : 
     369      347479 :     if ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT )
     370             :     {
     371      150304 :         if ( ( st->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL )
     372             :         {
     373           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) );
     374             :         }
     375             : 
     376      150304 :         td_bwe_dec_init( st->hBWE_TD, st->extl, st->output_Fs );
     377             :     }
     378             :     else
     379             :     {
     380      197175 :         st->hBWE_TD = NULL;
     381             :     }
     382             : 
     383      347479 :     st->old_bwe_delay = -1;
     384      347479 :     set_f( st->hb_prev_synth_buffer, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) );
     385             : 
     386             :     /*-----------------------------------------------------------------*
     387             :      * SWB BWE parameters
     388             :      *-----------------------------------------------------------------*/
     389             : 
     390      347479 :     if ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT )
     391             :     {
     392      150304 :         if ( ( st->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL )
     393             :         {
     394           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) );
     395             :         }
     396             : 
     397      150304 :         fd_bwe_dec_init( st->hBWE_FD );
     398             :     }
     399             :     else
     400             :     {
     401      197175 :         st->hBWE_FD = NULL;
     402             :     }
     403             : 
     404             :     /*-----------------------------------------------------------------*
     405             :      * WB/SWB bandwidth switching parameters
     406             :      *-----------------------------------------------------------------*/
     407             : 
     408      347479 :     st->tilt_swb = 0.0f;
     409      347479 :     st->prev_ener_shb = 0.0f;
     410      347479 :     st->prev_enerLH = 0.0f;
     411      347479 :     st->enerLH = 0.0f;
     412      347479 :     st->enerLL = 0.0f;
     413      347479 :     st->prev_enerLL = 0.0f;
     414      347479 :     st->prev_fractive = 0;
     415      347479 :     st->prev_bws_cnt = 0;
     416      347479 :     st->bws_cnt = N_WS2N_FRAMES;
     417      347479 :     st->bws_cnt1 = N_NS2W_FRAMES;
     418      347479 :     st->attenu1 = 0.1f;
     419      347479 :     st->last_inner_frame = L_FRAME8k;
     420             : 
     421             :     /*-----------------------------------------------------------------*
     422             :      * HR SWB BWE parameters
     423             :      *-----------------------------------------------------------------*/
     424             : 
     425      347479 :     if ( st->element_mode == EVS_MONO )
     426             :     {
     427          64 :         if ( ( st->hBWE_FD_HR = (HR_BWE_DEC_HANDLE) malloc( sizeof( HR_BWE_DEC_DATA ) ) ) == NULL )
     428             :         {
     429           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HR BWE\n" ) );
     430             :         }
     431             : 
     432          64 :         hr_bwe_dec_init( st->hBWE_FD_HR );
     433             :     }
     434             :     else
     435             :     {
     436      347415 :         st->hBWE_FD_HR = NULL;
     437             :     }
     438             : 
     439             :     /*----------------------------------------------------------------------------------*
     440             :      * AMR-WB IO mode parameters
     441             :      *----------------------------------------------------------------------------------*/
     442             : 
     443      347479 :     if ( st->Opt_AMR_WB || st->element_mode == EVS_MONO )
     444             :     {
     445          64 :         if ( ( st->hAmrwb_IO = (AMRWB_IO_DEC_HANDLE) malloc( sizeof( AMRWB_IO_DEC_DATA ) ) ) == NULL )
     446             :         {
     447           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) );
     448             :         }
     449             : 
     450             :         /* AMR-WB IO init */
     451          64 :         amr_wb_dec_init( st->hAmrwb_IO );
     452             : 
     453             :         /* AMR-WB IO HF synth init */
     454          64 :         hf_synth_amr_wb_init( st->hAmrwb_IO );
     455             :     }
     456             :     else
     457             :     {
     458      347415 :         st->hAmrwb_IO = NULL;
     459             :     }
     460             : 
     461             :     /*-----------------------------------------------------------------*
     462             :      * channel-aware mode parameters
     463             :      *-----------------------------------------------------------------*/
     464             : 
     465      347479 :     set_f( st->tilt_code_dec, 0.0f, NB_SUBFR16k );
     466             : 
     467      347479 :     st->use_partial_copy = 0;
     468      347479 :     st->prev_use_partial_copy = 0;
     469      347479 :     st->rf_flag = 0;
     470      347479 :     st->rf_flag_last = 0;
     471      347479 :     st->prev_rf_frame_type = 0;
     472      347479 :     st->next_coder_type = 0;
     473             : 
     474      347479 :     st->rf_target_bits = 0;
     475             : 
     476      347479 :     st->rf_indx_nelp_fid = 0;
     477      347479 :     st->rf_indx_nelp_iG1 = 0;
     478      347479 :     st->rf_indx_nelp_iG2[0] = 0;
     479      347479 :     st->rf_indx_nelp_iG2[1] = 0;
     480      347479 :     st->rf_indx_tbeGainFr = 0;
     481             : 
     482             :     /*-----------------------------------------------------------------*
     483             :      * Bass post-filter parameters
     484             :      *-----------------------------------------------------------------*/
     485             : 
     486      347479 :     st->bpf_off = 0;
     487             : 
     488      347479 :     if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) || st->element_mode == IVAS_CPE_TD )
     489             :     {
     490      150304 :         if ( ( st->hBPF = (BPF_DEC_HANDLE) malloc( sizeof( BPF_DEC_DATA ) ) ) == NULL )
     491             :         {
     492           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for BPF\n" ) );
     493             :         }
     494             : 
     495      150304 :         bass_psfilter_init( st->hBPF );
     496             :     }
     497             :     else
     498             :     {
     499      197175 :         st->hBPF = NULL;
     500             :     }
     501             : 
     502             :     /*-----------------------------------------------------------------*
     503             :      * FD BPF & resampling tools parameters
     504             :      *-----------------------------------------------------------------*/
     505             : 
     506      347479 :     if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) || st->element_mode == IVAS_CPE_TD )
     507             :     {
     508             :         /* open analysis for max. sampling rate 48kHz */
     509      150304 :         if ( ( error = openCldfb( &st->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK )
     510             :         {
     511           0 :             return error;
     512             :         }
     513             : 
     514             :         /* open analysis BPF for max. internal sampling rate 16kHz */
     515      150304 :         if ( ( error = openCldfb( &st->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK )
     516             :         {
     517           0 :             return error;
     518             :         }
     519             :     }
     520             :     else
     521             :     {
     522      197175 :         st->cldfbAna = NULL;
     523      197175 :         st->cldfbBPF = NULL;
     524             :     }
     525             : 
     526             :     /* open synthesis for output sampling rate */
     527      347479 :     if ( ( error = openCldfb( &st->cldfbSyn, CLDFB_SYNTHESIS, st->output_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK )
     528             :     {
     529           0 :         return error;
     530             :     }
     531             : 
     532      347479 :     st->cldfbSynHB = NULL;
     533             : 
     534      347479 :     st->last_active_bandsToZero_bwdec = 0;
     535      347479 :     st->perc_bwddec = 0.0f;
     536      347479 :     st->last_flag_filter_NB = 0;
     537      347479 :     st->active_frame_cnt_bwddec = 0;
     538      347479 :     st->total_frame_cnt_bwddec = 0;
     539      347479 :     set_s( st->flag_buffer, 0, 20 );
     540      347479 :     st->avg_nrg_LT = 0.0f;
     541             : 
     542             :     /*-----------------------------------------------------------------*
     543             :      * Noise gate parameters
     544             :      *-----------------------------------------------------------------*/
     545             : 
     546      347479 :     st->ng_ener_ST = -51.0f;
     547             : 
     548      347479 :     st->old_Es_pred = 0;
     549      347479 :     set_f( st->old_Aq_12_8 + 1, 0, M );
     550      347479 :     st->old_Aq_12_8[0] = 1;
     551             : 
     552             :     /*-----------------------------------------------------------------*
     553             :      * SC-VBR parameters
     554             :      *-----------------------------------------------------------------*/
     555             : 
     556      347479 :     if ( st->element_mode == EVS_MONO )
     557             :     {
     558          64 :         if ( ( st->hSC_VBR = (SC_VBR_DEC_HANDLE) malloc( sizeof( SC_VBR_DEC_DATA ) ) ) == NULL )
     559             :         {
     560           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n" ) );
     561             :         }
     562             : 
     563          64 :         sc_vbr_dec_init( st->hSC_VBR );
     564             :     }
     565             :     else
     566             :     {
     567      347415 :         st->hSC_VBR = NULL;
     568             :     }
     569             : 
     570      347479 :     st->last_ppp_mode_dec = 0;
     571      347479 :     st->old_ppp_mode = 0;
     572      347479 :     st->ppp_mode_dec = 0;
     573      347479 :     st->last_nelp_mode_dec = 0;
     574      347479 :     st->nelp_mode_dec = 0;
     575      347479 :     st->prev_gain_pit_dec = 0.0f;
     576      347479 :     st->prev_tilt_code_dec = 0.0f;
     577      347479 :     st->vbr_hw_BWE_disable_dec = 0;
     578      347479 :     st->last_vbr_hw_BWE_disable_dec = 0;
     579             : 
     580             : 
     581             :     /*-----------------------------------------------------------------*
     582             :      * TCX core
     583             :      *-----------------------------------------------------------------*/
     584             : 
     585             :     /* TCX-LTP */
     586      347479 :     if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) )
     587             :     {
     588      347188 :         if ( ( st->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL )
     589             :         {
     590           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n" ) );
     591             :         }
     592             :     }
     593             :     else
     594             :     {
     595         291 :         st->hTcxLtpDec = NULL;
     596             :     }
     597             : 
     598             :     /* TCX core */
     599             : 
     600      347479 :     if ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT )
     601             :     {
     602      347188 :         if ( ( st->hTcxDec = (TCX_DEC_HANDLE) malloc( sizeof( TCX_DEC_DATA ) ) ) == NULL )
     603             :         {
     604           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxDec\n" ) );
     605             :         }
     606             : 
     607      347188 :         set_f( st->hTcxDec->FBTCXdelayBuf, 0.0f, 111 );
     608             : 
     609      347188 :         st->hTcxDec->old_synthFB = st->hTcxDec->synth_history + NS2SA( st->output_Fs, PH_ECU_MEM_NS );
     610      347188 :         st->hTcxDec->prev_good_synth = st->hTcxDec->old_synthFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS );
     611             :     }
     612             :     else
     613             :     {
     614         291 :         st->hTcxDec = NULL;
     615             :     }
     616             : 
     617             :     /* TCX config. data structure */
     618      347479 :     if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) )
     619             :     {
     620      347188 :         if ( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL )
     621             :         {
     622           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) );
     623             :         }
     624             :     }
     625             :     else
     626             :     {
     627         291 :         st->hTcxCfg = NULL;
     628             :     }
     629             : 
     630             :     /* Tonal MDCT concealment data structure */
     631      347479 :     if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) )
     632             :     {
     633      347188 :         if ( ( st->hTonalMDCTConc = (TonalMDCTConcealPtr) malloc( sizeof( TonalMDCTConceal_INSTANCE ) ) ) == NULL )
     634             :         {
     635           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TonalMDCTConcealment\n" ) );
     636             :         }
     637             :     }
     638             :     else
     639             :     {
     640         291 :         st->hTonalMDCTConc = NULL;
     641             :     }
     642             : 
     643             :     /*-----------------------------------------------------------------*
     644             :      * IGF
     645             :      *-----------------------------------------------------------------*/
     646             : 
     647      347479 :     if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) )
     648             :     {
     649      347188 :         if ( ( st->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL )
     650             :         {
     651           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for IGF\n" ) );
     652             :         }
     653             : 
     654      347188 :         st->igf = 0;
     655      347188 :         init_igf_dec( st->hIGFDec );
     656             :     }
     657             :     else
     658             :     {
     659         291 :         st->hIGFDec = NULL;
     660             :     }
     661             : 
     662             :     /*-----------------------------------------------------------------*
     663             :      * Mode 2 initialization
     664             :      *-----------------------------------------------------------------*/
     665             : 
     666      347479 :     if ( st->element_mode == EVS_MONO )
     667             :     {
     668          64 :         if ( ( st->hPlcInfo = (T_PLCInfo_HANDLE) malloc( sizeof( T_PLCInfo ) ) ) == NULL )
     669             :         {
     670           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PLC handle\n" ) );
     671             :         }
     672             :     }
     673             :     else
     674             :     {
     675      347415 :         st->hPlcInfo = NULL;
     676             :     }
     677             : 
     678      347479 :     if ( st->element_mode == EVS_MONO )
     679             :     {
     680          64 :         if ( ( st->hTECDec = (TEC_DEC_HANDLE) malloc( sizeof( TEC_DEC_DATA ) ) ) == NULL )
     681             :         {
     682           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n" ) );
     683             :         }
     684             :     }
     685             :     else
     686             :     {
     687      347415 :         st->hTECDec = NULL;
     688             :     }
     689             : 
     690             :     /* Init Core Decoder */
     691      347479 :     open_decoder_LPD( st, st->total_brate, st->last_total_brate, st->bwidth, 0, st->element_mode, 1 );
     692             : 
     693             :     /* PLC mode initialization */
     694      347479 :     st->m_decodeMode = DEC_NO_FRAM_LOSS;
     695             : 
     696             :     /* Init bandwidth / frame_type */
     697      347479 :     st->m_frame_type = ACTIVE_FRAME;
     698      347479 :     st->m_old_frame_type = ACTIVE_FRAME;
     699             : 
     700      347479 :     if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) )
     701             :     {
     702      150304 :         resampleCldfb( st->cldfbAna, st->L_frame * FRAMES_PER_SEC );
     703      150304 :         resampleCldfb( st->cldfbBPF, st->L_frame * FRAMES_PER_SEC );
     704             :     }
     705             : 
     706             :     /*-----------------------------------------------------------------*
     707             :      * FD-CNG decoder
     708             :      *-----------------------------------------------------------------*/
     709             : 
     710      347479 :     if ( ( st->element_mode == IVAS_CPE_MDCT || idchan == 0 ) && mc_mode != MC_MODE_MCT && mc_mode != MC_MODE_PARAMUPMIX )
     711             :     {
     712             :         /* Create FD_CNG instance */
     713      237694 :         if ( ( error = createFdCngDec( &st->hFdCngDec ) ) != IVAS_ERR_OK )
     714             :         {
     715           0 :             return error;
     716             :         }
     717             : 
     718             :         /* Init FD-CNG */
     719      237694 :         initFdCngDec( st );
     720             :     }
     721             :     else
     722             :     {
     723      109785 :         st->hFdCngDec = NULL;
     724             :     }
     725             : 
     726      347479 :     st->cngTDLevel = 0.f;
     727      347479 :     st->lp_noise = -20.0f;
     728      347479 :     st->force_lpd_reset = 0;
     729             : 
     730             :     /*-----------------------------------------------------------------*
     731             :      * IVAS parameters
     732             :      *-----------------------------------------------------------------*/
     733             : 
     734      347479 :     st->tdm_LRTD_flag = 0;
     735      347479 :     st->cna_dirac_flag = 0;
     736      347479 :     st->cng_sba_flag = 0;
     737      347479 :     st->cng_ism_flag = 0;
     738             : 
     739      347479 :     return error;
     740             : }
     741             : 
     742             : 
     743             : /*----------------------------------------------------------------------*
     744             :  * reset_preecho_dec()
     745             :  *
     746             :  * Initialization of static variables for pre-echo
     747             :  *----------------------------------------------------------------------*/
     748             : 
     749    41715521 : void reset_preecho_dec(
     750             :     HQ_DEC_HANDLE hHQ_core /* i/o: HQ decoder handle         */
     751             : )
     752             : {
     753    41715521 :     hHQ_core->memfilt_lb = 0;
     754    41715521 :     hHQ_core->mean_prev_hb = 0;
     755    41715521 :     hHQ_core->smoothmem = 1;
     756    41715521 :     hHQ_core->mean_prev = 0;
     757    41715521 :     hHQ_core->mean_prev_nc = 0;
     758    41715521 :     hHQ_core->wmold_hb = 1;
     759    41715521 :     hHQ_core->prevflag = 0;
     760    41715521 :     hHQ_core->pastpre = 0;
     761             : 
     762    41715521 :     return;
     763             : }
     764             : 
     765             : 
     766             : /*----------------------------------------------------------------------*
     767             :  * destroy_cldfb_decoder()
     768             :  *
     769             :  * Free memory which was allocated in init_decoder()
     770             :  *----------------------------------------------------------------------*/
     771             : 
     772      347479 : void destroy_cldfb_decoder(
     773             :     Decoder_State *st /* o  :   Decoder static variables structure */
     774             : )
     775             : {
     776             :     /* CLDFB BPF & resampling tools */
     777      347479 :     deleteCldfb( &st->cldfbAna ); /* delete analysis at max. sampling rate 48kHz */
     778      347479 :     deleteCldfb( &st->cldfbBPF ); /* delete analysis BPF at max. internal sampling rate 16kHz */
     779      347479 :     deleteCldfb( &st->cldfbSyn ); /* delete synthesis at output sampling rate */
     780      347479 :     deleteCldfb( &st->cldfbSynHB );
     781             : 
     782      347479 :     deleteFdCngDec( &st->hFdCngDec );
     783             : 
     784      347479 :     return;
     785             : }

Generated by: LCOV version 1.14