LCOV - code coverage report
Current view: top level - lib_dec - updt_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main @ fec202a8f89be4a2f278a9fc377bfb58b58fab11 Lines: 303 312 97.1 %
Date: 2025-09-14 08:49:17 Functions: 5 5 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 <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     3419340 : 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     3419340 :     HQ_DEC_HANDLE hHQ_core = st->hHQ_core;
      72             : 
      73             :     /* update old excitation buffer */
      74     3419340 :     mvr2r( &old_exc[st->L_frame], st->old_exc, L_EXC_MEM_DEC );
      75     3419340 :     if ( !st->Opt_AMR_WB && st->hBWE_TD != NULL )
      76             :     {
      77     3368061 :         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     3419340 :     mvr2r( lsf_new, st->lsf_old, M );
      82     3419340 :     mvr2r( lsp_new, st->lsp_old, M );
      83             : 
      84             :     /* update last coding type */
      85     3419340 :     st->last_coder_type = st->coder_type;
      86     3419340 :     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      560206 :         st->last_coder_type = UNVOICED;
      90             :     }
      91             : 
      92     3419340 :     if ( st->hGSCDec != NULL )
      93             :     {
      94     3377849 :         if ( ( st->coder_type != AUDIO || st->Last_GSC_noisy_speech_flag != 0 ) && st->hGSCDec->Last_GSC_pit_band_idx > 0 )
      95             :         {
      96      333905 :             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     3419340 :     if ( st->coder_type == INACTIVE && st->total_brate > ACELP_24k40 )
     102             :     {
     103       23199 :         st->last_coder_type = GENERIC;
     104             :     }
     105             : 
     106     3419340 :     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          32 :         st->last_coder_type = UNVOICED;
     110          32 :         st->last_voice_factor = voice_factors[NB_SUBFR - 1];
     111             :     }
     112             : 
     113     3419340 :     if ( !st->Opt_AMR_WB )
     114             :     {
     115             :         /* update voicing factor of TBE to help FEC */
     116     3412045 :         if ( st->L_frame == L_FRAME )
     117             :         {
     118     1789235 :             st->last_voice_factor = voice_factors[NB_SUBFR - 1];
     119             :         }
     120             :         else /* L_frame == L_FRAME16k */
     121             :         {
     122     1622810 :             st->last_voice_factor = voice_factors[NB_SUBFR16k - 1];
     123             :         }
     124             :     }
     125             : 
     126     3419340 :     if ( st->hGSCDec != NULL && st->coder_type != AUDIO && st->coder_type != INACTIVE )
     127             :     {
     128     2772007 :         st->hGSCDec->noise_lev = NOISE_LEVEL_SP3;
     129     2772007 :         set_f( st->hGSCDec->old_y_gain, 0.0f, MBANDS_GN );
     130             : 
     131   712405799 :         for ( i = 0; i < L_FRAME; i++ )
     132             :         {
     133   709633792 :             tmp_seed = st->hGSCDec->seed_tcx;
     134   709633792 :             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     3419340 :     st->Last_GSC_noisy_speech_flag = st->GSC_noisy_speech;
     140             : 
     141             :     /* update counter for FEC pitch estimate */
     142     3419340 :     st->upd_cnt++;
     143     3419340 :     if ( st->upd_cnt > MAX_UPD_CNT )
     144             :     {
     145     1561658 :         st->upd_cnt = MAX_UPD_CNT;
     146             :     }
     147             : 
     148     3419340 :     mvr2r( &st->old_pitch_buf[st->L_frame / L_SUBFR], st->old_pitch_buf, st->L_frame / L_SUBFR );
     149     3419340 :     mvr2r( pitch_buf, &st->old_pitch_buf[st->L_frame / L_SUBFR], st->L_frame / L_SUBFR );
     150     3419340 :     mvr2r( &st->mem_pitch_gain[2], &st->mem_pitch_gain[st->L_frame / L_SUBFR + 2], st->L_frame / L_SUBFR );
     151             : 
     152     3419340 :     if ( st->L_frame == L_FRAME )
     153             :     {
     154     1796530 :         st->mem_pitch_gain[2] = gain_buf[3];
     155     1796530 :         st->mem_pitch_gain[3] = gain_buf[2];
     156     1796530 :         st->mem_pitch_gain[4] = gain_buf[1];
     157     1796530 :         st->mem_pitch_gain[5] = gain_buf[0];
     158             :     }
     159             :     else
     160             :     {
     161     1622810 :         st->mem_pitch_gain[2] = gain_buf[4];
     162     1622810 :         st->mem_pitch_gain[3] = gain_buf[3];
     163     1622810 :         st->mem_pitch_gain[4] = gain_buf[2];
     164     1622810 :         st->mem_pitch_gain[5] = gain_buf[1];
     165     1622810 :         st->mem_pitch_gain[6] = gain_buf[0];
     166             :     }
     167             : 
     168             :     /* FEC - update adaptive LSF mean vector */
     169     3419340 :     mvr2r( st->lsfoldbfi0, st->lsfoldbfi1, M );
     170     3419340 :     mvr2r( lsf_new, st->lsfoldbfi0, M );
     171             : 
     172             :     /* update of pitch and voicing information for HQ FEC */
     173     3419340 :     if ( hHQ_core != NULL && st->last_core != HQ_CORE )
     174             :     {
     175     3375917 :         if ( !st->Opt_AMR_WB && st->coder_type == UNVOICED )
     176             :         {
     177       52074 :             hHQ_core->HqVoicing = 0;
     178             :         }
     179             :         else
     180             :         {
     181     3323843 :             hHQ_core->HqVoicing = 1;
     182             :         }
     183             :     }
     184             : 
     185             :     /* SC-VBR */
     186     3419340 :     st->old_ppp_mode = st->last_ppp_mode_dec;
     187     3419340 :     st->last_ppp_mode_dec = st->ppp_mode_dec;
     188     3419340 :     st->last_nelp_mode_dec = st->nelp_mode_dec;
     189     3419340 :     st->last_vbr_hw_BWE_disable_dec = st->vbr_hw_BWE_disable_dec;
     190             : 
     191             :     /* core switching updates */
     192     3419340 :     mvr2r( &Aq[( st->L_frame / L_SUBFR - 1 ) * ( M + 1 )], st->old_Aq_12_8, M + 1 );
     193     3419340 :     st->old_Es_pred = Es_pred;
     194             : 
     195     3419340 :     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          50 : 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          50 :     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          29 :         mvr2r( stable_LSP, xsp_tmp, M );
     215          29 :         isf2lsf( st->lsf_old, st->lsf_old, xsp_tmp, M, INT_FS_12k8 );
     216          29 :         mvr2r( stable_LSP, xsp_tmp, M );
     217          29 :         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          29 :         mvr2r( stable_LSP, xsp_tmp, M );
     221          29 :         if ( st->hTdCngDec != NULL )
     222             :         {
     223          29 :             isp2lsp( st->lspCNG, st->lspCNG, xsp_tmp, M );
     224          29 :             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          29 :         if ( st->hBWE_TD != NULL )
     229             :         {
     230          29 :             set_f( st->hBWE_TD->old_bwe_exc, 0.0f, PIT16k_MAX * 2 );
     231          29 :             set_f( st->hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET );
     232          29 :             st->hBWE_TD->bwe_non_lin_prev_scale = 0.0;
     233             : 
     234          29 :             wb_tbe_extras_reset( st->hBWE_TD->mem_genSHBexc_filt_down_wb2, st->hBWE_TD->mem_genSHBexc_filt_down_wb3 );
     235          29 :             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          29 :             if ( output_frame >= L_FRAME32k )
     238             :             {
     239          29 :                 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          29 :                 set_f( st->hBWE_TD->GainShape_Delay, 0, NUM_SHB_SUBFR / 2 );
     243          29 :                 st->hBWE_TD->prev_pow_exc16kWhtnd = 1.0f;
     244          29 :                 st->hBWE_TD->prev_mix_factor = 1.0f;
     245             : 
     246          29 :                 swb_tbe_reset_synth( st->hBWE_TD->genSHBsynth_Hilbert_Mem, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local );
     247             :             }
     248             : 
     249          29 :             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          29 :         st->last_voice_factor = 0.0f;
     257             : 
     258             :         /* reset FD BWE buffers */
     259          29 :         if ( st->hBWE_FD != NULL )
     260             :         {
     261          29 :             st->hBWE_FD->prev_mode = NORMAL;
     262          29 :             st->hBWE_FD->prev_Energy = 0.0f;
     263          29 :             st->hBWE_FD->prev_Energy_wb = 0.0f;
     264          29 :             st->hBWE_FD->prev_L_swb_norm = 8;
     265          29 :             st->hBWE_FD->prev_frica_flag = 0;
     266          29 :             set_f( st->hBWE_FD->mem_imdct, 0, L_FRAME48k );
     267          29 :             st->hBWE_FD->prev_td_energy = 0.0f;
     268          29 :             st->hBWE_FD->prev_weight = 0.2f;
     269          29 :             set_f( st->hBWE_FD->old_wtda_swb, 0, L_FRAME48k );
     270             : 
     271          29 :             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          29 :         set_f( st->delay_buf_out, 0, HQ_DELTA_MAX * HQ_DELAY_COMP );
     279             : 
     280             :         /* reset the unvoiced/audio signal improvement  memories */
     281          29 :         st->hGSCDec->seed_tcx = 15687;
     282             : 
     283          29 :         st->use_acelp_preq = 0;
     284          29 :         if ( st->last_flag_filter_NB == 1 )
     285             :         {
     286           0 :             st->cldfbSyn->bandsToZero = 0;
     287             :         }
     288          29 :         st->last_active_bandsToZero_bwdec = 0;
     289          29 :         st->perc_bwddec = 0.0f;
     290          29 :         st->last_flag_filter_NB = 0;
     291          29 :         st->active_frame_cnt_bwddec = 0;
     292          29 :         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          21 :         set_f( st->mem_MA, 0, M );
     300             : 
     301             :         /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */
     302          21 :         mvr2r( stable_ISP, xsp_tmp, M );
     303          21 :         lsf2isf( st->lsf_old, st->lsf_old, xsp_tmp, M, INT_FS_12k8 );
     304          21 :         mvr2r( stable_ISP, xsp_tmp, M );
     305          21 :         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          21 :         mvr2r( stable_ISP, xsp_tmp, M );
     309          21 :         if ( st->hTdCngDec != NULL )
     310             :         {
     311          21 :             lsp2isp( st->lspCNG, st->lspCNG, xsp_tmp, M );
     312          21 :             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          21 :         st->ng_ener_ST = -51.0f;
     317             : 
     318             :         /* reset the unvoiced/audio signal improvement memories */
     319          21 :         st->hGSCDec->seed_tcx = 15687;
     320             : 
     321          21 :         st->psf_lp_noise = st->lp_noise;
     322             : 
     323             :         /* AMR-WB IO init */
     324          21 :         mvr2r( st->hAmrwb_IO->lt_diff_etot, tmpF, MAX_LT );
     325          21 :         amr_wb_dec_init( st->hAmrwb_IO );
     326          21 :         mvr2r( tmpF, st->hAmrwb_IO->lt_diff_etot, MAX_LT );
     327             : 
     328          21 :         hf_synth_amr_wb_reset( st->hAmrwb_IO, st->hBWE_zero );
     329             : 
     330             :         /* reset VBR signaling */
     331          21 :         st->last_ppp_mode_dec = 0;
     332          21 :         st->last_nelp_mode_dec = 0;
     333          21 :         st->ppp_mode_dec = 0;
     334          21 :         st->nelp_mode_dec = 0;
     335             :     }
     336             : 
     337             :     /* CNG - reset */
     338          50 :     if ( st->hTdCngDec != NULL )
     339             :     {
     340          50 :         st->hTdCngDec->ho_hist_size = 0;
     341             :     }
     342             : 
     343             :     /* ISF Q memories */
     344          50 :     mvr2r( UVWB_Ave, st->mem_AR, M );
     345             : 
     346             :     /* FEC - update adaptive LSF mean vector */
     347          50 :     mvr2r( st->lsf_old, st->lsfoldbfi0, M );
     348          50 :     mvr2r( st->lsf_old, st->lsfoldbfi1, M );
     349          50 :     mvr2r( st->lsf_old, st->lsf_adaptive_mean, M );
     350             : 
     351          50 :     return;
     352             : }
     353             : 
     354             : /*-------------------------------------------------------------------*
     355             :  * updt_bw_switching()
     356             :  *
     357             :  * Updates for BW switching
     358             :  *-------------------------------------------------------------------*/
     359             : 
     360    35506508 : void updt_bw_switching(
     361             :     Decoder_State *st, /* i/o: decoder state structure                  */
     362             :     const float *synth /* i  : float synthesis signal                   */
     363             : )
     364             : {
     365    35506508 :     if ( st->output_Fs == 32000 && st->bwidth == SWB )
     366             :     {
     367     8182418 :         calc_tilt_bwe( synth, &( st->tilt_swb ), L_FRAME32k );
     368             :     }
     369             : 
     370    35506508 :     st->prev_enerLH = st->enerLH;
     371    35506508 :     st->prev_enerLL = st->enerLL;
     372    35506508 :     st->last_bwidth = st->bwidth;
     373             : 
     374    35506508 :     if ( st->core == ACELP_CORE )
     375             :     {
     376     3912685 :         if ( st->bwidth == WB && st->bws_cnt == 0 )
     377             :         {
     378     1240581 :             st->last_inner_frame = L_FRAME16k;
     379             :         }
     380             :         else
     381             :         {
     382     2672104 :             st->last_inner_frame = L_FRAME32k;
     383             :         }
     384             :     }
     385             :     else
     386             :     {
     387    31593823 :         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         148 :             st->last_inner_frame = st->last_inner_frame;
     390             :         }
     391             :         else
     392             :         {
     393    31593675 :             st->last_inner_frame = inner_frame_tbl[st->bwidth];
     394             :         }
     395             :     }
     396             : 
     397    35506508 :     st->prev_bws_cnt = st->bws_cnt;
     398             : 
     399    35506508 :     return;
     400             : }
     401             : 
     402             : 
     403             : /*-------------------------------------------------------------------*
     404             :  * updt_dec_common()
     405             :  *
     406             :  * Common updates for MODE1 and MODE2
     407             :  *-------------------------------------------------------------------*/
     408             : 
     409    35729324 : 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    35729324 :     st->last_codec_mode = st->codec_mode;
     421    35729324 :     st->last_extl = st->extl;
     422    35729324 :     st->last_L_frame = st->L_frame;
     423    35729324 :     st->prev_old_bfi = st->prev_bfi;
     424    35729324 :     st->prev_bfi = st->bfi;
     425    35729324 :     if ( st->core != AMR_WB_CORE )
     426             :     {
     427    35722029 :         st->old_bfi_cnt = st->nbLostCmpt;
     428             :     }
     429    35729324 :     st->last_con_tcx = st->con_tcx;
     430    35729324 :     st->con_tcx = 0;
     431             : 
     432    35729324 :     if ( st->hHQ_nbfec != NULL )
     433             :     {
     434      120184 :         st->hHQ_nbfec->prev_last_core = st->last_core;
     435             :     }
     436             : 
     437    35729324 :     if ( st->use_partial_copy )
     438             :     {
     439         184 :         st->prev_rf_frame_type = st->rf_frame_type;
     440             :     }
     441             :     else
     442             :     {
     443    35729140 :         st->prev_rf_frame_type = INACTIVE;
     444             :     }
     445             : 
     446    35729324 :     if ( st->hTcxDec != NULL )
     447             :     {
     448    35690190 :         st->hTcxDec->tcxConceal_recalc_exc = 0;
     449             :     }
     450             : 
     451    35729324 :     if ( ( st->rf_frame_type >= RF_TCXFD && st->rf_frame_type <= RF_TCXTD2 && st->use_partial_copy && st->bfi ) || !st->bfi )
     452             :     {
     453    33103252 :         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    33103252 :         st->last_good = st->clas_dec;
     458             :     }
     459             : 
     460    35729324 :     if ( st->m_frame_type == ACTIVE_FRAME && ( !st->bfi || st->use_partial_copy ) )
     461             :     {
     462    32938527 :         st->rf_flag_last = st->rf_flag;
     463             :     }
     464             : 
     465    35729324 :     if ( st->codec_mode == MODE1 )
     466             :     {
     467    35675004 :         if ( !st->bfi && ( st->core_brate > SID_2k40 || ( st->core_brate > SID_1k75 && st->core == AMR_WB_CORE ) ) )
     468             :         {
     469    32886464 :             st->last_active_brate = st->total_brate;
     470             :         }
     471    35675004 :         if ( !st->bfi || st->element_mode == EVS_MONO )
     472             :         {
     473    33052287 :             st->last_core = st->core;
     474             :         }
     475    35675004 :         st->last_core_bfi = st->core; /* also required for clean channel decoding */
     476    35675004 :         if ( st->hHQ_core != NULL )
     477             :         {
     478    35635870 :             st->hHQ_core->last_hq_core_type = hq_core_type;
     479             :         }
     480             :     }
     481       54320 :     else if ( st->codec_mode == MODE2 )
     482             :     {
     483       54320 :         if ( !st->bfi && st->last_is_cng == 0 )
     484             :         {
     485       52029 :             st->last_active_brate = st->total_brate;
     486             :         }
     487             : 
     488       54320 :         if ( st->m_frame_type != ACTIVE_FRAME )
     489             :         {
     490         626 :             st->last_is_cng = 1;
     491             :         }
     492             : 
     493       54320 :         if ( !st->bfi )
     494             :         {
     495       52655 :             st->last_core = st->core;
     496             :         }
     497       54320 :         st->last_core_bfi = st->core; /* also required for clean channel decoding */
     498             :     }
     499             : 
     500    35729324 :     st->last_core_brate = st->core_brate;
     501             : 
     502             :     /* save synthesis for core switching */
     503    35729324 :     if ( st->element_mode == EVS_MONO && st->core != AMR_WB_CORE )
     504             :     {
     505      112889 :         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    35729324 :     if ( st->element_mode != EVS_MONO )
     510             :     {
     511    35609140 :         output_frame = NS2SA( st->output_Fs, FRAME_SIZE_NS );
     512    35609140 :         log_energy = log2f( ( sum2_f( synth, output_frame ) / output_frame ) + 1.0f );
     513    35609140 :         log_energy_diff = fabsf( st->log_energy_old - log_energy );
     514    35609140 :         st->log_energy_old = log_energy;
     515    35609140 :         st->log_energy_diff_lt = ENV_SMOOTH_FAC * log_energy_diff + ( 1.0f - ENV_SMOOTH_FAC ) * st->log_energy_diff_lt;
     516    35609140 :         if ( st->core == HQ_CORE )
     517             :         {
     518      128295 :             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      128295 :             st->stab_fac = max( 0, st->stab_fac );
     520             :         }
     521    35609140 :         st->stab_fac_smooth_lt = ENV_SMOOTH_FAC * st->stab_fac + ( 1.0f - ENV_SMOOTH_FAC ) * st->stab_fac_smooth_lt;
     522             :     }
     523             : 
     524    35729324 :     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    28176436 :         set_zero( st->mem_MA, M );
     528    28176436 :         if ( st->sr_core == INT_FS_16k )
     529             :         {
     530     6859453 :             mvr2r( GEWB2_Ave, st->mem_AR, M );
     531             :         }
     532             :         else
     533             :         {
     534    21316983 :             mvr2r( GEWB_Ave, st->mem_AR, M );
     535             :         }
     536             :     }
     537             : 
     538    35729324 :     if ( st->codec_mode == MODE2 )
     539             :     {
     540       54320 :         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       54320 :             st->last_nelp_mode_dec = 0;
     547             :         }
     548             :     }
     549             : 
     550    35729324 :     st->prev_use_partial_copy = st->use_partial_copy;
     551             : 
     552    35729324 :     st->prev_tilt_code_dec = 0.0f;
     553   178646620 :     for ( i = 0; i < NB_SUBFR; i++ )
     554             :     {
     555   142917296 :         st->prev_tilt_code_dec += st->tilt_code_dec[i] * 0.25f;
     556             :     }
     557             : 
     558    35729324 :     if ( st->core == HQ_CORE )
     559             :     {
     560      139261 :         st->prev_coder_type = GENERIC;
     561             :     }
     562    35590063 :     else if ( st->core != AMR_WB_CORE )
     563             :     {
     564    35582768 :         st->prev_coder_type = st->coder_type;
     565             :     }
     566             : 
     567             :     /* CNG updates */
     568    35729324 :     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      326094 :         if ( st->hTdCngDec->act_cnt >= BUF_DEC_RATE )
     571             :         {
     572       12712 :             st->hTdCngDec->act_cnt = 0;
     573             :         }
     574             : 
     575      326094 :         st->hTdCngDec->act_cnt++;
     576             : 
     577      326094 :         if ( st->hTdCngDec->act_cnt == BUF_DEC_RATE && st->hTdCngDec->ho_hist_size > 0 )
     578             :         {
     579        2667 :             st->hTdCngDec->ho_hist_size--;
     580             :         }
     581             : 
     582      326094 :         if ( ++( st->hTdCngDec->act_cnt2 ) >= MIN_ACT_CNG_UPD )
     583             :         {
     584      311740 :             st->hTdCngDec->act_cnt2 = MIN_ACT_CNG_UPD;
     585             :         }
     586             :     }
     587             : 
     588    35729324 :     if ( st->core_brate <= SID_2k40 && st->first_CNG == 0 && ( st->cng_type == LP_CNG || st->element_mode == IVAS_CPE_MDCT ) )
     589             :     {
     590         516 :         st->first_CNG = 1;
     591             :     }
     592             : 
     593             :     /* synchronisation of CNG seeds */
     594    35729324 :     if ( st->hTdCngDec != NULL && ( st->bfi || ( st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40 ) ) && st->core != AMR_WB_CORE )
     595             :     {
     596     6801696 :         own_random( &( st->hTdCngDec->cng_seed ) );
     597     6801696 :         own_random( &( st->hTdCngDec->cng_ener_seed ) );
     598             :     }
     599             : 
     600             :     /* general updates */
     601    35729324 :     st->last_flag_cna = st->flag_cna;
     602    35729324 :     if ( st->hFdCngDec != NULL )
     603             :     {
     604    30797462 :         st->hFdCngDec->hFdCngCom->frame_type_previous = st->m_frame_type;
     605             :     }
     606             : 
     607    35729324 :     if ( st->element_mode > EVS_MONO )
     608             :     {
     609    35609140 :         st->m_old_frame_type = st->m_frame_type;
     610             :     }
     611             : 
     612             :     /* update bandwidth switching parameters */
     613    35729324 :     if ( st->core == AMR_WB_CORE )
     614             :     {
     615        7295 :         st->last_bwidth = WB;
     616             : 
     617        7295 :         st->prev_bws_cnt = 0;
     618        7295 :         st->bws_cnt = 0;
     619        7295 :         st->bws_cnt1 = 0;
     620             :     }
     621    35722029 :     else if ( ( st->codec_mode == MODE1 ) && ( ( st->core_brate > SID_2k40 ) || ( st->element_mode == EVS_MONO ) ) )
     622             :     {
     623    35506508 :         updt_bw_switching( st, synth );
     624             :     }
     625             :     else
     626             :     {
     627      215521 :         st->last_bwidth = st->bwidth;
     628      215521 :         st->prev_bws_cnt = st->bws_cnt;
     629             :     }
     630             : 
     631    35729324 :     if ( st->hTcxDec != NULL && st->enablePlcWaveadjust && !concealWholeFrameTmp && st->core != AMR_WB_CORE )
     632             :     {
     633             :         /* update the parameters used in waveform adjustment */
     634       13166 :         concealment_update2( synth, st->hPlcInfo, st->hTcxDec->L_frameTCX );
     635             :     }
     636             : 
     637    35729324 :     st->last_total_brate_ber = st->total_brate;
     638    35729324 :     if ( !st->bfi )
     639             :     {
     640    33103240 :         st->last_total_brate = st->total_brate;
     641    33103240 :         st->last_bits_frame_nominal = st->bits_frame_nominal;
     642             :     }
     643             : 
     644    35729324 :     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    35729324 :     if ( st->ini_frame < MAX_FRAME_COUNTER )
     652             :     {
     653    15749720 :         ( st->ini_frame )++;
     654             :     }
     655             : 
     656    35729324 :     return;
     657             : }
     658             : 
     659             : /*-------------------------------------------------------------------*
     660             :  * update_decoder_LPD_cng()
     661             :  *
     662             :  *
     663             :  *--------------------------------------------------------------------*/
     664             : 
     665         626 : 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         626 :     TCX_DEC_HANDLE hTcxDec = st->hTcxDec;
     679             : 
     680         626 :     synth = synth_buf + ( 1 + M );
     681             : 
     682             :     /* LPC -> LSP/lsp */
     683         626 :     a2lsp_stab( A, lsp, st->lsp_old );
     684             : 
     685             :     /* LSP/lsp -> LSF/lsf */
     686         626 :     if ( st->L_frame == L_FRAME16k )
     687             :     {
     688           0 :         lsp2lsf( lsp, lsf, M, INT_FS_16k );
     689             :     }
     690             :     else
     691             :     {
     692         626 :         lsp2lsf( lsp, lsf, M, INT_FS_12k8 );
     693             :     }
     694             : 
     695         626 :     if ( hTcxDec != NULL )
     696             :     {
     697         626 :         mvr2r( hTcxDec->old_synth, buf_synth, hTcxDec->old_synth_len );
     698         626 :         mvr2r( timeDomainBuffer, buf_synth + hTcxDec->old_synth_len, st->L_frame );
     699             : 
     700             :         /* Update synth memory */
     701         626 :         mvr2r( st->syn, synth_buf, 1 + M );
     702         626 :         mvr2r( timeDomainBuffer, synth, st->L_frame );
     703         626 :         mvr2r( synth + st->L_frame - ( 1 + M ), st->syn, 1 + M );
     704         626 :         mvr2r( hTcxDec->old_synth + st->L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len - st->L_frame );
     705         626 :         mvr2r( synth, hTcxDec->old_synth + hTcxDec->old_synth_len - st->L_frame, st->L_frame );
     706             : 
     707         626 :         mvr2r( synth + st->L_frame - ( st->L_frame / 2 ), hTcxDec->old_syn_Overl, st->L_frame / 2 );
     708             : 
     709         626 :         hTcxDec->tcxltp_last_gain_unmodified = 0.0f;
     710             :     }
     711             : 
     712             :     /* Update pre-synth memory */
     713         626 :     tmp = synth[-( 1 + M )];
     714         626 :     preemph( synth - M, st->preemph_fac, M + st->L_frame, &tmp );
     715         626 :     mvr2r( synth + st->L_frame - M, st->mem_syn2, M );
     716         626 :     mvr2r( synth + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM );
     717             : 
     718             :     /* Update excitation memory */
     719         626 :     assert( st->L_frame < L_EXC_MEM_DEC );
     720         626 :     mvr2r( st->old_exc + st->L_frame, st->old_exc, L_EXC_MEM_DEC - st->L_frame );
     721         626 :     residu( A, M, synth, st->old_exc + L_EXC_MEM_DEC - st->L_frame, st->L_frame );
     722             : 
     723             :     /* Update LPC-related memories */
     724         626 :     mvr2r( lsp, st->lsp_old, M );
     725         626 :     mvr2r( lsf, st->lsf_old, M );
     726         626 :     mvr2r( lsp, st->lspold_uw, M );
     727         626 :     mvr2r( lsf, st->lsfold_uw, M );
     728             : 
     729         626 :     hTcxDec->envWeighted = 0;
     730         626 :     mvr2r( A, st->old_Aq_12_8, M + 1 );
     731         626 :     st->old_Es_pred = 0;
     732             : 
     733             :     /* Reset acelp memories */
     734         626 :     set_zero( st->dispMem, 8 );
     735         626 :     st->tilt_code = TILT_CODE;
     736         626 :     st->gc_threshold = 0.0f;
     737             : 
     738             :     /* Update ace/tcx mode */
     739         626 :     st->core = ACELP_CORE;
     740         626 :     st->last_is_cng = 1;
     741             : 
     742             :     /* Reset TCX overlap */
     743         626 :     if ( st->hTcxCfg != NULL )
     744             :     {
     745         626 :         st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
     746             :     }
     747             : 
     748             :     /* For BWE and Postfilter */
     749         626 :     mvr2r( A, &( st->mem_Aq[0] ), M + 1 );
     750         626 :     mvr2r( A, &( st->mem_Aq[( M + 1 )] ), M + 1 );
     751         626 :     mvr2r( A, &( st->mem_Aq[2 * ( M + 1 )] ), M + 1 );
     752         626 :     mvr2r( A, &( st->mem_Aq[3 * ( M + 1 )] ), M + 1 );
     753         626 :     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         626 :     st->nbLostCmpt = 0;
     760         626 :     st->prev_old_bfi = 0;
     761             : 
     762       10642 :     for ( i = 0; i < M; i++ )
     763             :     {
     764       10016 :         st->lsf_adaptive_mean[i] = ( st->lsfoldbfi1[i] + st->lsfoldbfi0[i] + lsf[i] ) / 3;
     765       10016 :         st->lsfoldbfi1[i] = st->lsfoldbfi0[i];
     766       10016 :         st->lsfoldbfi0[i] = lsf[i];
     767             :     }
     768             : 
     769         626 :     set_f( pitch, (float) L_SUBFR, NB_SUBFR16k );
     770             : 
     771         626 :     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         626 :     pf_pitch[0] = pf_pitch[1] = pf_pitch[2] = pf_pitch[3] = pf_pitch[4] = L_SUBFR;
     775         626 :     pf_gain[0] = pf_gain[1] = pf_gain[2] = pf_gain[3] = pf_gain[4] = 0.f;
     776         626 :     st->bpf_gain_param = 0;
     777             : 
     778         626 :     post_decoder( st, buf_synth, pf_gain, pf_pitch, timeDomainBuffer, bpf_noise_buf );
     779             : 
     780         626 :     return;
     781             : }

Generated by: LCOV version 1.14