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

Generated by: LCOV version 1.14