LCOV - code coverage report
Current view: top level - lib_dec - updt_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 167 312 53.5 %
Date: 2025-05-23 08:37:30 Functions: 3 5 60.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 <assert.h>
      38             : #include <stdint.h>
      39             : #include "options.h"
      40             : #ifdef DEBUGGING
      41             : #include "debug.h"
      42             : #endif
      43             : #include "prot.h"
      44             : #include "rom_com.h"
      45             : #include "cnst.h"
      46             : #include <math.h>
      47             : #include "wmc_auto.h"
      48             : 
      49             : /*-------------------------------------------------------------------*
      50             :  * updt_dec()
      51             :  *
      52             :  * Common updates (all frame types)
      53             :  *-------------------------------------------------------------------*/
      54             : 
      55      530307 : void updt_dec(
      56             :     Decoder_State *st,           /* i/o: state structure                          */
      57             :     const float *old_exc,        /* i  : buffer of excitation                     */
      58             :     const float *pitch_buf,      /* i  : floating pitch values for each subframe  */
      59             :     const float Es_pred,         /* i  : predicited scaled innovation energy      */
      60             :     const float *Aq,             /* i  : A(z) quantized for all subframes         */
      61             :     const float *lsf_new,        /* i  : current frame LSF vector                 */
      62             :     const float *lsp_new,        /* i  : current frame LSP vector                 */
      63             :     const float voice_factors[], /* i  : voicing factors                          */
      64             :     const float *old_bwe_exc,    /* i  : buffer of excitation                     */
      65             :     const float *gain_buf        /* o  : floating pitch gain for each subframe    */
      66             : )
      67             : {
      68             :     int16_t i;
      69             :     int16_t tmp_seed;
      70             : 
      71      530307 :     HQ_DEC_HANDLE hHQ_core = st->hHQ_core;
      72             : 
      73             :     /* update old excitation buffer */
      74      530307 :     mvr2r( &old_exc[st->L_frame], st->old_exc, L_EXC_MEM_DEC );
      75      530307 :     if ( !st->Opt_AMR_WB && st->hBWE_TD != NULL )
      76             :     {
      77      508287 :         mvr2r( &old_bwe_exc[L_FRAME32k], st->hBWE_TD->old_bwe_exc, PIT16k_MAX * 2 );
      78             :     }
      79             : 
      80             :     /* update old LSP and LSF vector */
      81      530307 :     mvr2r( lsf_new, st->lsf_old, M );
      82      530307 :     mvr2r( lsp_new, st->lsp_old, M );
      83             : 
      84             :     /* update last coding type */
      85      530307 :     st->last_coder_type = st->coder_type;
      86      530307 :     if ( st->coder_type == INACTIVE || ( st->bpf_off == 1 && st->coder_type != AUDIO && st->coder_type != TRANSITION ) )
      87             :     {
      88             :         /* overwrite previous coding type to help FEC */
      89      110001 :         st->last_coder_type = UNVOICED;
      90             :     }
      91             : 
      92      530307 :     if ( st->hGSCDec != NULL )
      93             :     {
      94      508569 :         if ( ( st->coder_type != AUDIO || st->Last_GSC_noisy_speech_flag != 0 ) && st->hGSCDec->Last_GSC_pit_band_idx > 0 )
      95             :         {
      96       32979 :             st->hGSCDec->Last_GSC_pit_band_idx = 0; /*The temporal contribution of the GSC is meaningless after 1 frame lost for inactive & unvoiced content */
      97             :         }
      98             :     }
      99             : 
     100             :     /* this ensures that st->last_coder_type is never set to INACTIVE in case of AVQ inactive because the FEC does not distinguish between GSC inactive and AVQ inactive */
     101      530307 :     if ( st->coder_type == INACTIVE && st->total_brate > ACELP_24k40 )
     102             :     {
     103        9921 :         st->last_coder_type = GENERIC;
     104             :     }
     105             : 
     106      530307 :     if ( st->Opt_AMR_WB && st->coder_type == INACTIVE && st->core_brate != SID_1k75 && st->core_brate != FRAME_NO_DATA )
     107             :     {
     108             :         /* overwrite previous coding type to help FEC */
     109           0 :         st->last_coder_type = UNVOICED;
     110           0 :         st->last_voice_factor = voice_factors[NB_SUBFR - 1];
     111             :     }
     112             : 
     113      530307 :     if ( !st->Opt_AMR_WB )
     114             :     {
     115             :         /* update voicing factor of TBE to help FEC */
     116      530307 :         if ( st->L_frame == L_FRAME )
     117             :         {
     118      271005 :             st->last_voice_factor = voice_factors[NB_SUBFR - 1];
     119             :         }
     120             :         else /* L_frame == L_FRAME16k */
     121             :         {
     122      259302 :             st->last_voice_factor = voice_factors[NB_SUBFR16k - 1];
     123             :         }
     124             :     }
     125             : 
     126      530307 :     if ( st->hGSCDec != NULL && st->coder_type != AUDIO && st->coder_type != INACTIVE )
     127             :     {
     128      396183 :         st->hGSCDec->noise_lev = NOISE_LEVEL_SP3;
     129      396183 :         set_f( st->hGSCDec->old_y_gain, 0.0f, MBANDS_GN );
     130             : 
     131   101819031 :         for ( i = 0; i < L_FRAME; i++ )
     132             :         {
     133   101422848 :             tmp_seed = st->hGSCDec->seed_tcx;
     134   101422848 :             st->hGSCDec->Last_GSC_spectrum[i] = own_random( &tmp_seed ) / PCM16_TO_FLT_FAC;
     135             :         }
     136             :     }
     137             : 
     138             :     /* update last GSC SWB speech flag for FEC */
     139      530307 :     st->Last_GSC_noisy_speech_flag = st->GSC_noisy_speech;
     140             : 
     141             :     /* update counter for FEC pitch estimate */
     142      530307 :     st->upd_cnt++;
     143      530307 :     if ( st->upd_cnt > MAX_UPD_CNT )
     144             :     {
     145      250164 :         st->upd_cnt = MAX_UPD_CNT;
     146             :     }
     147             : 
     148      530307 :     mvr2r( &st->old_pitch_buf[st->L_frame / L_SUBFR], st->old_pitch_buf, st->L_frame / L_SUBFR );
     149      530307 :     mvr2r( pitch_buf, &st->old_pitch_buf[st->L_frame / L_SUBFR], st->L_frame / L_SUBFR );
     150      530307 :     mvr2r( &st->mem_pitch_gain[2], &st->mem_pitch_gain[st->L_frame / L_SUBFR + 2], st->L_frame / L_SUBFR );
     151             : 
     152      530307 :     if ( st->L_frame == L_FRAME )
     153             :     {
     154      271005 :         st->mem_pitch_gain[2] = gain_buf[3];
     155      271005 :         st->mem_pitch_gain[3] = gain_buf[2];
     156      271005 :         st->mem_pitch_gain[4] = gain_buf[1];
     157      271005 :         st->mem_pitch_gain[5] = gain_buf[0];
     158             :     }
     159             :     else
     160             :     {
     161      259302 :         st->mem_pitch_gain[2] = gain_buf[4];
     162      259302 :         st->mem_pitch_gain[3] = gain_buf[3];
     163      259302 :         st->mem_pitch_gain[4] = gain_buf[2];
     164      259302 :         st->mem_pitch_gain[5] = gain_buf[1];
     165      259302 :         st->mem_pitch_gain[6] = gain_buf[0];
     166             :     }
     167             : 
     168             :     /* FEC - update adaptive LSF mean vector */
     169      530307 :     mvr2r( st->lsfoldbfi0, st->lsfoldbfi1, M );
     170      530307 :     mvr2r( lsf_new, st->lsfoldbfi0, M );
     171             : 
     172             :     /* update of pitch and voicing information for HQ FEC */
     173      530307 :     if ( hHQ_core != NULL && st->last_core != HQ_CORE )
     174             :     {
     175      518208 :         if ( !st->Opt_AMR_WB && st->coder_type == UNVOICED )
     176             :         {
     177        6432 :             hHQ_core->HqVoicing = 0;
     178             :         }
     179             :         else
     180             :         {
     181      511776 :             hHQ_core->HqVoicing = 1;
     182             :         }
     183             :     }
     184             : 
     185             :     /* SC-VBR */
     186      530307 :     st->old_ppp_mode = st->last_ppp_mode_dec;
     187      530307 :     st->last_ppp_mode_dec = st->ppp_mode_dec;
     188      530307 :     st->last_nelp_mode_dec = st->nelp_mode_dec;
     189      530307 :     st->last_vbr_hw_BWE_disable_dec = st->vbr_hw_BWE_disable_dec;
     190             : 
     191             :     /* core switching updates */
     192      530307 :     mvr2r( &Aq[( st->L_frame / L_SUBFR - 1 ) * ( M + 1 )], st->old_Aq_12_8, M + 1 );
     193      530307 :     st->old_Es_pred = Es_pred;
     194             : 
     195      530307 :     return;
     196             : }
     197             : 
     198             : /*-------------------------------------------------------------------*
     199             :  * updt_IO_switch()
     200             :  *
     201             :  * Common updates for AMR-WB IO mode and EVS primary mode switching
     202             :  *-------------------------------------------------------------------*/
     203             : 
     204           0 : void updt_IO_switch_dec(
     205             :     const int16_t output_frame, /* i  : output frame length         */
     206             :     Decoder_State *st           /* i/o: state structure             */
     207             : )
     208             : {
     209             :     float xsp_tmp[M];
     210             : 
     211           0 :     if ( st->last_core == AMR_WB_CORE ) /* switching to EVS primary mode */
     212             :     {
     213             :         /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */
     214           0 :         mvr2r( stable_LSP, xsp_tmp, M );
     215           0 :         isf2lsf( st->lsf_old, st->lsf_old, xsp_tmp, M, INT_FS_12k8 );
     216           0 :         mvr2r( stable_LSP, xsp_tmp, M );
     217           0 :         isp2lsp( st->lsp_old, st->lsp_old, xsp_tmp, M );
     218             : 
     219             :         /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode uses LSF(LSP) */
     220           0 :         mvr2r( stable_LSP, xsp_tmp, M );
     221           0 :         if ( st->hTdCngDec != NULL )
     222             :         {
     223           0 :             isp2lsp( st->lspCNG, st->lspCNG, xsp_tmp, M );
     224           0 :             st->hTdCngDec->old_enr_index = min( (int16_t) ( (float) st->hTdCngDec->old_enr_index / STEP_AMR_WB_SID * STEP_SID ), 127 );
     225             :         }
     226             : 
     227             :         /* reset TD BWE buffers */
     228           0 :         if ( st->hBWE_TD != NULL )
     229             :         {
     230           0 :             set_f( st->hBWE_TD->old_bwe_exc, 0.0f, PIT16k_MAX * 2 );
     231           0 :             set_f( st->hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET );
     232           0 :             st->hBWE_TD->bwe_non_lin_prev_scale = 0.0;
     233             : 
     234           0 :             wb_tbe_extras_reset( st->hBWE_TD->mem_genSHBexc_filt_down_wb2, st->hBWE_TD->mem_genSHBexc_filt_down_wb3 );
     235           0 :             wb_tbe_extras_reset_synth( st->hBWE_TD->state_lsyn_filt_shb, st->hBWE_TD->state_lsyn_filt_dwn_shb, st->hBWE_TD->mem_resamp_HB );
     236             : 
     237           0 :             if ( output_frame >= L_FRAME32k )
     238             :             {
     239           0 :                 swb_tbe_reset( st->hBWE_TD->mem_csfilt, st->hBWE_TD->mem_genSHBexc_filt_down_shb, st->hBWE_TD->state_lpc_syn, st->hBWE_TD->syn_overlap, st->hBWE_TD->state_syn_shbexc, &st->hBWE_TD->tbe_demph, &st->hBWE_TD->tbe_premph, st->hBWE_TD->mem_stp_swb, &( st->hBWE_TD->gain_prec_swb ) );
     240             : 
     241             :                 /* reset GainShape delay for SWB TBE FEC */
     242           0 :                 set_f( st->hBWE_TD->GainShape_Delay, 0, NUM_SHB_SUBFR / 2 );
     243           0 :                 st->hBWE_TD->prev_pow_exc16kWhtnd = 1.0f;
     244           0 :                 st->hBWE_TD->prev_mix_factor = 1.0f;
     245             : 
     246           0 :                 swb_tbe_reset_synth( st->hBWE_TD->genSHBsynth_Hilbert_Mem, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local );
     247             :             }
     248             : 
     249           0 :             if ( output_frame == L_FRAME48k )
     250             :             {
     251           0 :                 set_f( st->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER );
     252           0 :                 st->hBWE_TD->fb_tbe_demph = 0;
     253           0 :                 fb_tbe_reset_synth( st->hBWE_TD->fbbwe_hpf_mem, &st->hBWE_TD->prev_fbbwe_ratio );
     254             :             }
     255             :         }
     256           0 :         st->last_voice_factor = 0.0f;
     257             : 
     258             :         /* reset FD BWE buffers */
     259           0 :         if ( st->hBWE_FD != NULL )
     260             :         {
     261           0 :             st->hBWE_FD->prev_mode = NORMAL;
     262           0 :             st->hBWE_FD->prev_Energy = 0.0f;
     263           0 :             st->hBWE_FD->prev_Energy_wb = 0.0f;
     264           0 :             st->hBWE_FD->prev_L_swb_norm = 8;
     265           0 :             st->hBWE_FD->prev_frica_flag = 0;
     266           0 :             set_f( st->hBWE_FD->mem_imdct, 0, L_FRAME48k );
     267           0 :             st->hBWE_FD->prev_td_energy = 0.0f;
     268           0 :             st->hBWE_FD->prev_weight = 0.2f;
     269           0 :             set_f( st->hBWE_FD->old_wtda_swb, 0, L_FRAME48k );
     270             : 
     271           0 :             if ( output_frame == L_FRAME48k )
     272             :             {
     273           0 :                 st->hBWE_FD->prev_fb_ener_adjust = 0.0f;
     274             :             }
     275             :         }
     276             : 
     277             :         /* HQ core buffers */
     278           0 :         set_f( st->delay_buf_out, 0, HQ_DELTA_MAX * HQ_DELAY_COMP );
     279             : 
     280             :         /* reset the unvoiced/audio signal improvement  memories */
     281           0 :         st->hGSCDec->seed_tcx = 15687;
     282             : 
     283           0 :         st->use_acelp_preq = 0;
     284           0 :         if ( st->last_flag_filter_NB == 1 )
     285             :         {
     286           0 :             st->cldfbSyn->bandsToZero = 0;
     287             :         }
     288           0 :         st->last_active_bandsToZero_bwdec = 0;
     289           0 :         st->perc_bwddec = 0.0f;
     290           0 :         st->last_flag_filter_NB = 0;
     291           0 :         st->active_frame_cnt_bwddec = 0;
     292           0 :         set_s( st->flag_buffer, 0, 20 );
     293             :     }
     294             :     else /* switching to AMR-WB IO mode */
     295             :     {
     296             :         float tmpF[MAX_LT];
     297             : 
     298             :         /* ISF Q memories */
     299           0 :         set_f( st->mem_MA, 0, M );
     300             : 
     301             :         /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */
     302           0 :         mvr2r( stable_ISP, xsp_tmp, M );
     303           0 :         lsf2isf( st->lsf_old, st->lsf_old, xsp_tmp, M, INT_FS_12k8 );
     304           0 :         mvr2r( stable_ISP, xsp_tmp, M );
     305           0 :         lsp2isp( st->lsp_old, st->lsp_old, xsp_tmp, M );
     306             : 
     307             :         /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */
     308           0 :         mvr2r( stable_ISP, xsp_tmp, M );
     309           0 :         if ( st->hTdCngDec != NULL )
     310             :         {
     311           0 :             lsp2isp( st->lspCNG, st->lspCNG, xsp_tmp, M );
     312           0 :             st->hTdCngDec->old_enr_index = min( (int16_t) ( (float) st->hTdCngDec->old_enr_index / STEP_SID * STEP_AMR_WB_SID ), 63 );
     313             :         }
     314             : 
     315             :         /* HF synthesis memories */
     316           0 :         st->ng_ener_ST = -51.0f;
     317             : 
     318             :         /* reset the unvoiced/audio signal improvement memories */
     319           0 :         st->hGSCDec->seed_tcx = 15687;
     320             : 
     321           0 :         st->psf_lp_noise = st->lp_noise;
     322             : 
     323             :         /* AMR-WB IO init */
     324           0 :         mvr2r( st->hAmrwb_IO->lt_diff_etot, tmpF, MAX_LT );
     325           0 :         amr_wb_dec_init( st->hAmrwb_IO );
     326           0 :         mvr2r( tmpF, st->hAmrwb_IO->lt_diff_etot, MAX_LT );
     327             : 
     328           0 :         hf_synth_amr_wb_reset( st->hAmrwb_IO, st->hBWE_zero );
     329             : 
     330             :         /* reset VBR signaling */
     331           0 :         st->last_ppp_mode_dec = 0;
     332           0 :         st->last_nelp_mode_dec = 0;
     333           0 :         st->ppp_mode_dec = 0;
     334           0 :         st->nelp_mode_dec = 0;
     335             :     }
     336             : 
     337             :     /* CNG - reset */
     338           0 :     if ( st->hTdCngDec != NULL )
     339             :     {
     340           0 :         st->hTdCngDec->ho_hist_size = 0;
     341             :     }
     342             : 
     343             :     /* ISF Q memories */
     344           0 :     mvr2r( UVWB_Ave, st->mem_AR, M );
     345             : 
     346             :     /* FEC - update adaptive LSF mean vector */
     347           0 :     mvr2r( st->lsf_old, st->lsfoldbfi0, M );
     348           0 :     mvr2r( st->lsf_old, st->lsfoldbfi1, M );
     349           0 :     mvr2r( st->lsf_old, st->lsf_adaptive_mean, M );
     350             : 
     351           0 :     return;
     352             : }
     353             : 
     354             : /*-------------------------------------------------------------------*
     355             :  * updt_bw_switching()
     356             :  *
     357             :  * Updates for BW switching
     358             :  *-------------------------------------------------------------------*/
     359             : 
     360     3318102 : void updt_bw_switching(
     361             :     Decoder_State *st, /* i/o: decoder state structure                  */
     362             :     const float *synth /* i  : float synthesis signal                   */
     363             : )
     364             : {
     365     3318102 :     if ( st->output_Fs == 32000 && st->bwidth == SWB )
     366             :     {
     367      524583 :         calc_tilt_bwe( synth, &( st->tilt_swb ), L_FRAME32k );
     368             :     }
     369             : 
     370     3318102 :     st->prev_enerLH = st->enerLH;
     371     3318102 :     st->prev_enerLL = st->enerLL;
     372     3318102 :     st->last_bwidth = st->bwidth;
     373             : 
     374     3318102 :     if ( st->core == ACELP_CORE )
     375             :     {
     376      488775 :         if ( st->bwidth == WB && st->bws_cnt == 0 )
     377             :         {
     378       80469 :             st->last_inner_frame = L_FRAME16k;
     379             :         }
     380             :         else
     381             :         {
     382      408306 :             st->last_inner_frame = L_FRAME32k;
     383             :         }
     384             :     }
     385             :     else
     386             :     {
     387     2829327 :         if ( st->last_inner_frame >= L_FRAME16k && inner_frame_tbl[st->bwidth] <= L_FRAME16k && st->bws_cnt > 0 && st->bws_cnt < N_WS2N_FRAMES )
     388             :         {
     389           0 :             st->last_inner_frame = st->last_inner_frame;
     390             :         }
     391             :         else
     392             :         {
     393     2829327 :             st->last_inner_frame = inner_frame_tbl[st->bwidth];
     394             :         }
     395             :     }
     396             : 
     397     3318102 :     st->prev_bws_cnt = st->bws_cnt;
     398             : 
     399     3318102 :     return;
     400             : }
     401             : 
     402             : 
     403             : /*-------------------------------------------------------------------*
     404             :  * updt_dec_common()
     405             :  *
     406             :  * Common updates for MODE1 and MODE2
     407             :  *-------------------------------------------------------------------*/
     408             : 
     409     3399660 : void updt_dec_common(
     410             :     Decoder_State *st,                  /* i/o: decoder state structure     */
     411             :     const int16_t hq_core_type,         /* i  : HQ core type                */
     412             :     const int16_t concealWholeFrameTmp, /* i  : concealWholeFrameTmp flag   */
     413             :     const float *synth                  /* i  : decoded synthesis           */
     414             : )
     415             : {
     416             :     int16_t i;
     417             :     float log_energy, log_energy_diff;
     418             :     int16_t output_frame;
     419             : 
     420     3399660 :     st->last_codec_mode = st->codec_mode;
     421     3399660 :     st->last_extl = st->extl;
     422     3399660 :     st->last_L_frame = st->L_frame;
     423     3399660 :     st->prev_old_bfi = st->prev_bfi;
     424     3399660 :     st->prev_bfi = st->bfi;
     425     3399660 :     if ( st->core != AMR_WB_CORE )
     426             :     {
     427     3399660 :         st->old_bfi_cnt = st->nbLostCmpt;
     428             :     }
     429     3399660 :     st->last_con_tcx = st->con_tcx;
     430     3399660 :     st->con_tcx = 0;
     431             : 
     432     3399660 :     if ( st->hHQ_nbfec != NULL )
     433             :     {
     434        9300 :         st->hHQ_nbfec->prev_last_core = st->last_core;
     435             :     }
     436             : 
     437     3399660 :     if ( st->use_partial_copy )
     438             :     {
     439           0 :         st->prev_rf_frame_type = st->rf_frame_type;
     440             :     }
     441             :     else
     442             :     {
     443     3399660 :         st->prev_rf_frame_type = INACTIVE;
     444             :     }
     445             : 
     446     3399660 :     if ( st->hTcxDec != NULL )
     447             :     {
     448     3388320 :         st->hTcxDec->tcxConceal_recalc_exc = 0;
     449             :     }
     450             : 
     451     3399660 :     if ( ( st->rf_frame_type >= RF_TCXFD && st->rf_frame_type <= RF_TCXTD2 && st->use_partial_copy && st->bfi ) || !st->bfi )
     452             :     {
     453     3332715 :         if ( st->bfi && st->last_good <= UNVOICED_TRANSITION && st->clas_dec > UNVOICED_TRANSITION && st->last_con_tcx && st->hTcxDec != NULL )
     454             :         {
     455           0 :             st->hTcxDec->tcxConceal_recalc_exc = 1;
     456             :         }
     457     3332715 :         st->last_good = st->clas_dec;
     458             :     }
     459             : 
     460     3399660 :     if ( st->m_frame_type == ACTIVE_FRAME && ( !st->bfi || st->use_partial_copy ) )
     461             :     {
     462     3254907 :         st->rf_flag_last = st->rf_flag;
     463             :     }
     464             : 
     465     3399660 :     if ( st->codec_mode == MODE1 )
     466             :     {
     467     3395910 :         if ( !st->bfi && ( st->core_brate > SID_2k40 || ( st->core_brate > SID_1k75 && st->core == AMR_WB_CORE ) ) )
     468             :         {
     469     3251157 :             st->last_active_brate = st->total_brate;
     470             :         }
     471     3395910 :         if ( !st->bfi || st->element_mode == EVS_MONO )
     472             :         {
     473     3328965 :             st->last_core = st->core;
     474             :         }
     475     3395910 :         st->last_core_bfi = st->core; /* also required for clean channel decoding */
     476     3395910 :         if ( st->hHQ_core != NULL )
     477             :         {
     478     3384570 :             st->hHQ_core->last_hq_core_type = hq_core_type;
     479             :         }
     480             :     }
     481        3750 :     else if ( st->codec_mode == MODE2 )
     482             :     {
     483        3750 :         if ( !st->bfi && st->last_is_cng == 0 )
     484             :         {
     485        3750 :             st->last_active_brate = st->total_brate;
     486             :         }
     487             : 
     488        3750 :         if ( st->m_frame_type != ACTIVE_FRAME )
     489             :         {
     490           0 :             st->last_is_cng = 1;
     491             :         }
     492             : 
     493        3750 :         if ( !st->bfi )
     494             :         {
     495        3750 :             st->last_core = st->core;
     496             :         }
     497        3750 :         st->last_core_bfi = st->core; /* also required for clean channel decoding */
     498             :     }
     499             : 
     500     3399660 :     st->last_core_brate = st->core_brate;
     501             : 
     502             :     /* save synthesis for core switching */
     503     3399660 :     if ( st->element_mode == EVS_MONO && st->core != AMR_WB_CORE )
     504             :     {
     505        9300 :         mvr2r( synth + NS2SA( st->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ), st->old_synth_sw, NS2SA( st->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ) );
     506             :     }
     507             : 
     508             :     /* Store long-term estimates of stab_fac and log energy diff to estimate env_stab in case of core switch ACELP/TCX->HQ */
     509     3399660 :     if ( st->element_mode != EVS_MONO )
     510             :     {
     511     3390360 :         output_frame = NS2SA( st->output_Fs, FRAME_SIZE_NS );
     512     3390360 :         log_energy = log2f( ( sum2_f( synth, output_frame ) / output_frame ) + 1.0f );
     513     3390360 :         log_energy_diff = fabsf( st->log_energy_old - log_energy );
     514     3390360 :         st->log_energy_old = log_energy;
     515     3390360 :         st->log_energy_diff_lt = ENV_SMOOTH_FAC * log_energy_diff + ( 1.0f - ENV_SMOOTH_FAC ) * st->log_energy_diff_lt;
     516     3390360 :         if ( st->core == HQ_CORE )
     517             :         {
     518       24114 :             st->stab_fac = min( 1, ( STAB_FAC_EST1 + ( STAB_FAC_EST2 * st->hHQ_core->mem_env_delta ) + ( STAB_FAC_EST3 * st->log_energy_diff_lt ) ) );
     519       24114 :             st->stab_fac = max( 0, st->stab_fac );
     520             :         }
     521     3390360 :         st->stab_fac_smooth_lt = ENV_SMOOTH_FAC * st->stab_fac + ( 1.0f - ENV_SMOOTH_FAC ) * st->stab_fac_smooth_lt;
     522             :     }
     523             : 
     524     3399660 :     if ( ( st->core_brate <= SID_2k40 && st->cng_type == FD_CNG ) || ( st->tcxonly && ( st->codec_mode == MODE2 || st->element_mode > EVS_MONO ) ) )
     525             :     {
     526             :         /* reset LP memories */
     527     2525433 :         set_zero( st->mem_MA, M );
     528     2525433 :         if ( st->sr_core == INT_FS_16k )
     529             :         {
     530      246357 :             mvr2r( GEWB2_Ave, st->mem_AR, M );
     531             :         }
     532             :         else
     533             :         {
     534     2279076 :             mvr2r( GEWB_Ave, st->mem_AR, M );
     535             :         }
     536             :     }
     537             : 
     538     3399660 :     if ( st->codec_mode == MODE2 )
     539             :     {
     540        3750 :         if ( st->use_partial_copy && st->rf_frame_type == RF_NELP )
     541             :         {
     542           0 :             st->last_nelp_mode_dec = 1;
     543             :         }
     544             :         else
     545             :         {
     546        3750 :             st->last_nelp_mode_dec = 0;
     547             :         }
     548             :     }
     549             : 
     550     3399660 :     st->prev_use_partial_copy = st->use_partial_copy;
     551             : 
     552     3399660 :     st->prev_tilt_code_dec = 0.0f;
     553    16998300 :     for ( i = 0; i < NB_SUBFR; i++ )
     554             :     {
     555    13598640 :         st->prev_tilt_code_dec += st->tilt_code_dec[i] * 0.25f;
     556             :     }
     557             : 
     558     3399660 :     if ( st->core == HQ_CORE )
     559             :     {
     560       25434 :         st->prev_coder_type = GENERIC;
     561             :     }
     562     3374226 :     else if ( st->core != AMR_WB_CORE )
     563             :     {
     564     3374226 :         st->prev_coder_type = st->coder_type;
     565             :     }
     566             : 
     567             :     /* CNG updates */
     568     3399660 :     if ( ( st->core_brate > SID_2k40 || ( st->core_brate > SID_1k75 && st->core == AMR_WB_CORE ) ) && st->first_CNG == 1 && st->hTdCngDec != NULL )
     569             :     {
     570       53448 :         if ( st->hTdCngDec->act_cnt >= BUF_DEC_RATE )
     571             :         {
     572        2022 :             st->hTdCngDec->act_cnt = 0;
     573             :         }
     574             : 
     575       53448 :         st->hTdCngDec->act_cnt++;
     576             : 
     577       53448 :         if ( st->hTdCngDec->act_cnt == BUF_DEC_RATE && st->hTdCngDec->ho_hist_size > 0 )
     578             :         {
     579         732 :             st->hTdCngDec->ho_hist_size--;
     580             :         }
     581             : 
     582       53448 :         if ( ++( st->hTdCngDec->act_cnt2 ) >= MIN_ACT_CNG_UPD )
     583             :         {
     584       47895 :             st->hTdCngDec->act_cnt2 = MIN_ACT_CNG_UPD;
     585             :         }
     586             :     }
     587             : 
     588     3399660 :     if ( st->core_brate <= SID_2k40 && st->first_CNG == 0 && ( st->cng_type == LP_CNG || st->element_mode == IVAS_CPE_MDCT ) )
     589             :     {
     590         264 :         st->first_CNG = 1;
     591             :     }
     592             : 
     593             :     /* synchronisation of CNG seeds */
     594     3399660 :     if ( st->hTdCngDec != NULL && ( st->bfi || ( st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40 ) ) && st->core != AMR_WB_CORE )
     595             :     {
     596      713835 :         own_random( &( st->hTdCngDec->cng_seed ) );
     597      713835 :         own_random( &( st->hTdCngDec->cng_ener_seed ) );
     598             :     }
     599             : 
     600             :     /* general updates */
     601     3399660 :     st->last_flag_cna = st->flag_cna;
     602     3399660 :     if ( st->hFdCngDec != NULL )
     603             :     {
     604     2859744 :         st->hFdCngDec->hFdCngCom->frame_type_previous = st->m_frame_type;
     605             :     }
     606             : 
     607     3399660 :     if ( st->element_mode > EVS_MONO )
     608             :     {
     609     3390360 :         st->m_old_frame_type = st->m_frame_type;
     610             :     }
     611             : 
     612             :     /* update bandwidth switching parameters */
     613     3399660 :     if ( st->core == AMR_WB_CORE )
     614             :     {
     615           0 :         st->last_bwidth = WB;
     616             : 
     617           0 :         st->prev_bws_cnt = 0;
     618           0 :         st->bws_cnt = 0;
     619           0 :         st->bws_cnt1 = 0;
     620             :     }
     621     3399660 :     else if ( ( st->codec_mode == MODE1 ) && ( ( st->core_brate > SID_2k40 ) || ( st->element_mode == EVS_MONO ) ) )
     622             :     {
     623     3318102 :         updt_bw_switching( st, synth );
     624             :     }
     625             :     else
     626             :     {
     627       81558 :         st->last_bwidth = st->bwidth;
     628       81558 :         st->prev_bws_cnt = st->bws_cnt;
     629             :     }
     630             : 
     631     3399660 :     if ( st->hTcxDec != NULL && st->enablePlcWaveadjust && !concealWholeFrameTmp && st->core != AMR_WB_CORE )
     632             :     {
     633             :         /* update the parameters used in waveform adjustment */
     634           0 :         concealment_update2( synth, st->hPlcInfo, st->hTcxDec->L_frameTCX );
     635             :     }
     636             : 
     637     3399660 :     st->last_total_brate_ber = st->total_brate;
     638     3399660 :     if ( !st->bfi )
     639             :     {
     640     3332715 :         st->last_total_brate = st->total_brate;
     641     3332715 :         st->last_bits_frame_nominal = st->bits_frame_nominal;
     642             :     }
     643             : 
     644     3399660 :     st->last_low_rate_mode = st->low_rate_mode;
     645             : 
     646             :     /*-----------------------------------------------------------------*
     647             :      * Increase the counter of initialization frames
     648             :      * Limit the max number of init. frames
     649             :      *-----------------------------------------------------------------*/
     650             : 
     651     3399660 :     if ( st->ini_frame < MAX_FRAME_COUNTER )
     652             :     {
     653     1194033 :         ( st->ini_frame )++;
     654             :     }
     655             : 
     656     3399660 :     return;
     657             : }
     658             : 
     659             : /*-------------------------------------------------------------------*
     660             :  * update_decoder_LPD_cng()
     661             :  *
     662             :  *
     663             :  *--------------------------------------------------------------------*/
     664             : 
     665           0 : void update_decoder_LPD_cng(
     666             :     Decoder_State *st,
     667             :     float *timeDomainBuffer,
     668             :     float *A,
     669             :     float *bpf_noise_buf )
     670             : {
     671             :     int16_t i;
     672             :     float lsp[M], lsf[M], pitch[NB_SUBFR16k];
     673             :     float *synth, synth_buf[M + 1 + L_FRAME_MAX + L_FRAME_MAX / 2];
     674             :     float tmp;
     675             :     float buf_synth[OLD_SYNTH_SIZE_DEC + L_FRAME_MAX + M];
     676             :     int16_t pf_pitch[NB_SUBFR16k];
     677             :     float pf_gain[NB_SUBFR16k];
     678           0 :     TCX_DEC_HANDLE hTcxDec = st->hTcxDec;
     679             : 
     680           0 :     synth = synth_buf + ( 1 + M );
     681             : 
     682             :     /* LPC -> LSP/lsp */
     683           0 :     a2lsp_stab( A, lsp, st->lsp_old );
     684             : 
     685             :     /* LSP/lsp -> LSF/lsf */
     686           0 :     if ( st->L_frame == L_FRAME16k )
     687             :     {
     688           0 :         lsp2lsf( lsp, lsf, M, INT_FS_16k );
     689             :     }
     690             :     else
     691             :     {
     692           0 :         lsp2lsf( lsp, lsf, M, INT_FS_12k8 );
     693             :     }
     694             : 
     695           0 :     if ( hTcxDec != NULL )
     696             :     {
     697           0 :         mvr2r( hTcxDec->old_synth, buf_synth, hTcxDec->old_synth_len );
     698           0 :         mvr2r( timeDomainBuffer, buf_synth + hTcxDec->old_synth_len, st->L_frame );
     699             : 
     700             :         /* Update synth memory */
     701           0 :         mvr2r( st->syn, synth_buf, 1 + M );
     702           0 :         mvr2r( timeDomainBuffer, synth, st->L_frame );
     703           0 :         mvr2r( synth + st->L_frame - ( 1 + M ), st->syn, 1 + M );
     704           0 :         mvr2r( hTcxDec->old_synth + st->L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len - st->L_frame );
     705           0 :         mvr2r( synth, hTcxDec->old_synth + hTcxDec->old_synth_len - st->L_frame, st->L_frame );
     706             : 
     707           0 :         mvr2r( synth + st->L_frame - ( st->L_frame / 2 ), hTcxDec->old_syn_Overl, st->L_frame / 2 );
     708             : 
     709           0 :         hTcxDec->tcxltp_last_gain_unmodified = 0.0f;
     710             :     }
     711             : 
     712             :     /* Update pre-synth memory */
     713           0 :     tmp = synth[-( 1 + M )];
     714           0 :     preemph( synth - M, st->preemph_fac, M + st->L_frame, &tmp );
     715           0 :     mvr2r( synth + st->L_frame - M, st->mem_syn2, M );
     716           0 :     mvr2r( synth + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM );
     717             : 
     718             :     /* Update excitation memory */
     719           0 :     assert( st->L_frame < L_EXC_MEM_DEC );
     720           0 :     mvr2r( st->old_exc + st->L_frame, st->old_exc, L_EXC_MEM_DEC - st->L_frame );
     721           0 :     residu( A, M, synth, st->old_exc + L_EXC_MEM_DEC - st->L_frame, st->L_frame );
     722             : 
     723             :     /* Update LPC-related memories */
     724           0 :     mvr2r( lsp, st->lsp_old, M );
     725           0 :     mvr2r( lsf, st->lsf_old, M );
     726           0 :     mvr2r( lsp, st->lspold_uw, M );
     727           0 :     mvr2r( lsf, st->lsfold_uw, M );
     728             : 
     729           0 :     hTcxDec->envWeighted = 0;
     730           0 :     mvr2r( A, st->old_Aq_12_8, M + 1 );
     731           0 :     st->old_Es_pred = 0;
     732             : 
     733             :     /* Reset acelp memories */
     734           0 :     set_zero( st->dispMem, 8 );
     735           0 :     st->tilt_code = TILT_CODE;
     736           0 :     st->gc_threshold = 0.0f;
     737             : 
     738             :     /* Update ace/tcx mode */
     739           0 :     st->core = ACELP_CORE;
     740           0 :     st->last_is_cng = 1;
     741             : 
     742             :     /* Reset TCX overlap */
     743           0 :     if ( st->hTcxCfg != NULL )
     744             :     {
     745           0 :         st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
     746             :     }
     747             : 
     748             :     /* For BWE and Postfilter */
     749           0 :     mvr2r( A, &( st->mem_Aq[0] ), M + 1 );
     750           0 :     mvr2r( A, &( st->mem_Aq[( M + 1 )] ), M + 1 );
     751           0 :     mvr2r( A, &( st->mem_Aq[2 * ( M + 1 )] ), M + 1 );
     752           0 :     mvr2r( A, &( st->mem_Aq[3 * ( M + 1 )] ), M + 1 );
     753           0 :     if ( st->L_frame == L_FRAME16k )
     754             :     {
     755           0 :         mvr2r( A, &( st->mem_Aq[4 * ( M + 1 )] ), M + 1 );
     756             :     }
     757             : 
     758             :     /* Update for concealment */
     759           0 :     st->nbLostCmpt = 0;
     760           0 :     st->prev_old_bfi = 0;
     761             : 
     762           0 :     for ( i = 0; i < M; i++ )
     763             :     {
     764           0 :         st->lsf_adaptive_mean[i] = ( st->lsfoldbfi1[i] + st->lsfoldbfi0[i] + lsf[i] ) / 3;
     765           0 :         st->lsfoldbfi1[i] = st->lsfoldbfi0[i];
     766           0 :         st->lsfoldbfi0[i] = lsf[i];
     767             :     }
     768             : 
     769           0 :     set_f( pitch, (float) L_SUBFR, NB_SUBFR16k );
     770             : 
     771           0 :     FEC_clas_estim( synth, pitch, st->L_frame, UNVOICED, st->codec_mode, st->mem_syn_clas_estim, &( st->clas_dec ), &st->lp_ener_bfi, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1.0f, st->narrowBand, CLASSIFIER_ACELP, 0, st->preemph_fac, st->tcxonly, st->last_core_brate, -1 );
     772             : 
     773             :     /* Postfiltering */
     774           0 :     pf_pitch[0] = pf_pitch[1] = pf_pitch[2] = pf_pitch[3] = pf_pitch[4] = L_SUBFR;
     775           0 :     pf_gain[0] = pf_gain[1] = pf_gain[2] = pf_gain[3] = pf_gain[4] = 0.f;
     776           0 :     st->bpf_gain_param = 0;
     777             : 
     778           0 :     post_decoder( st, buf_synth, pf_gain, pf_pitch, timeDomainBuffer, bpf_noise_buf );
     779             : 
     780           0 :     return;
     781             : }

Generated by: LCOV version 1.14