LCOV - code coverage report
Current view: top level - lib_dec - er_dec_tcx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ fec202a8f89be4a2f278a9fc377bfb58b58fab11 Lines: 229 247 92.7 %
Date: 2025-09-14 08:49:17 Functions: 1 1 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 "cnst.h"
      38             : #include "ivas_cnst.h"
      39             : #include <assert.h>
      40             : #include <stdint.h>
      41             : #include "options.h"
      42             : #ifdef DEBUGGING
      43             : #include "debug.h"
      44             : #endif
      45             : #include <math.h>
      46             : #include "prot.h"
      47             : #include "rom_dec.h"
      48             : #include "wmc_auto.h"
      49             : 
      50             : /*-----------------------------------------------------------------*
      51             :  * con_tcx()
      52             :  *
      53             :  *
      54             :  *-----------------------------------------------------------------*/
      55             : 
      56      623931 : void con_tcx(
      57             :     Decoder_State *st,       /* i/o: coder memory state          */
      58             :     float synth[],           /* i/o: synth[]                     */
      59             :     const float coh,         /* i  : coherence of stereo signal  */
      60             :     int16_t *noise_seed,     /* i/o: noise seed for stereo       */
      61             :     const int16_t only_left, /* i  : TD-PLC only in left channel */
      62             :     const float A_cng[]      /* i  : CNG LP filter coefficients  */
      63             : )
      64             : {
      65             :     int16_t i, n, L_frame, L_subfr, fLowPassFilter, T0;
      66      623931 :     int16_t offset = 0;
      67             :     int16_t mem_syn_r_size_old, mem_syn_r_size_new;
      68             :     float *noise;
      69             :     float mem_syn[M], *syn;
      70             :     float *exc, buf[OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2];
      71             :     float pre_emph_buf;
      72             :     float pitch_buf[NB_SUBFR16k], hp_filt[L_FIR_FER2];
      73      623931 :     float predPitchLag, alpha = 0.0f;
      74             :     float tmp_deemph, step, gain, gainCNG, gain_inov, ftmp;
      75             :     float *pt_exc, *pt1_exc;
      76             :     int16_t Tc, tmpSeed;
      77      623931 :     int16_t fUseExtrapolatedPitch = 0;
      78             :     float *ana_window;
      79             :     float r[M + 1], A_local[M + 1], mem;
      80             :     float *w;
      81             :     int16_t W1, W2;
      82      623931 :     int16_t extrapolationFailed = 1;
      83             :     float gainSynthDeemph;
      84      623931 :     float tmp = 0.f;
      85             :     float old_pitch_buf[2 * NB_SUBFR16k + 2];
      86      623931 :     TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec;
      87      623931 :     TCX_DEC_HANDLE hTcxDec = st->hTcxDec;
      88             : 
      89             :     /* Framing parameters */
      90      623931 :     L_frame = hTcxDec->L_frameTCX;
      91      623931 :     L_subfr = hTcxDec->L_frameTCX / st->nb_subfr;
      92      623931 :     w = st->hTcxCfg->tcx_mdct_windowFB;
      93      623931 :     W1 = st->hTcxCfg->tcx_mdct_window_lengthFB;
      94      623931 :     W2 = st->hTcxCfg->tcx_mdct_window_lengthFB / 2;
      95             : 
      96             :     /* take the previous frame last pitch */
      97      623931 :     Tc = (int16_t) ( st->old_fpitchFB + 0.5f );
      98             : 
      99      623931 :     set_zero( buf, OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2 );
     100             : 
     101      623931 :     v_multc( st->old_pitch_buf, (float) L_frame / st->L_frame, old_pitch_buf, 2 * NB_SUBFR16k + 2 );
     102             : 
     103             :     /* set excitation memory*/
     104      623931 :     exc = buf + OLD_EXC_SIZE_DEC;
     105             : 
     106      623931 :     tmp_deemph = synth[-1];
     107      623931 :     pre_emph_buf = synth[-1];
     108             : 
     109      623931 :     if ( st->nbLostCmpt == 1 || hTcxDec->tcxConceal_recalc_exc )
     110             :     {
     111             :         /* apply pre-emphasis to the signal */
     112      302687 :         mem = synth[-( L_frame / 2 + hTcxDec->pit_max_TCX + 2 * M ) - 1];
     113             : 
     114      302687 :         preemph( &synth[-( L_frame / 2 + hTcxDec->pit_max_TCX + 2 * M )], st->preemph_fac, L_frame / 2 + hTcxDec->pit_max_TCX + 2 * M, &mem );
     115      302687 :         st->lp_gainc = 0.0f;
     116             : 
     117      302687 :         st->lp_gainp = get_gain( synth - 2 * L_subfr, synth - 2 * L_subfr - Tc, 2 * L_subfr, NULL );
     118             : 
     119      302687 :         if ( st->lp_gainp < 0.0f )
     120             :         {
     121        3418 :             st->lp_gainp = 0.0f;
     122             :         }
     123             : 
     124      302687 :         if ( st->lp_gainp > 1.0f )
     125             :         {
     126       40366 :             st->lp_gainp = 1.0f;
     127             :         }
     128      302687 :         ana_window = buf;
     129      302687 :         ham_cos_window( ana_window, 3 * L_frame / 4, L_frame / 4 );
     130             : 
     131             :         /* Autocorrelation */
     132      302687 :         autocorr( &( synth[-L_frame - 1] ), r, M, L_frame, ana_window, 0, 0, 0 );
     133             : 
     134             :         /* Lag windowing */
     135      302687 :         lag_wind( r, M, st->output_Fs, LAGW_STRONG );
     136             : 
     137             :         /* Levinson Durbin */
     138      302687 :         lev_dur( A_local, r, M, NULL );
     139             : 
     140             :         /* copy for multiple frame loss */
     141      302687 :         mvr2r( A_local, st->old_Aq_12_8, M + 1 );
     142             : 
     143             :         /* Residu */
     144      302687 :         assert( ( 2 * L_subfr + Tc + 1 + M ) <= st->hTcxDec->old_synth_lenFB );
     145      302687 :         residu( A_local, M, &( synth[-( 2 * L_subfr + Tc + 1 + M )] ), &( exc[-( 2 * L_subfr + Tc + 1 + M )] ), 2 * L_subfr + Tc + 1 + M );
     146             :     }
     147             :     else
     148             :     {
     149             :         /* apply pre-emphasis to the signal */
     150      321244 :         mem = synth[-L_frame - 1];
     151             : 
     152      321244 :         preemph( &synth[-L_frame], st->preemph_fac, L_frame, &mem );
     153      321244 :         mvr2r( st->old_Aq_12_8, A_local, M + 1 );
     154      321244 :         offset = L_frame / 2;
     155             : 
     156      321244 :         if ( st->last_good >= UNVOICED_TRANSITION )
     157             :         {
     158      321244 :             i = max( Tc - L_frame / 2, 0 );
     159      321244 :             mvr2r( st->hTcxDec->old_excFB, &( exc[-i] ), offset + i );
     160             :         }
     161             :         else
     162             :         {
     163           0 :             mvr2r( st->hTcxDec->old_excFB, &( exc[-2 * L_subfr] ), 2 * L_subfr + offset );
     164             :         }
     165             :     }
     166             : 
     167             :     /*-----------------------------------------------------------------*
     168             :      * PLC: Construct the harmonic part of excitation
     169             :      *-----------------------------------------------------------------*/
     170             : 
     171      623931 :     if ( st->last_good != UNVOICED_CLAS && !( ( st->last_good == UNVOICED_TRANSITION ) && ( st->core_ext_mode == GENERIC ) ) )
     172             :     {
     173      623931 :         if ( st->nbLostCmpt == 1 || hTcxDec->tcxConceal_recalc_exc )
     174             :         {
     175      302687 :             st->lp_gainc = 0.0f;
     176             : 
     177    87220911 :             for ( i = 0; i < 2 * L_subfr; i++ )
     178             :             {
     179    86918224 :                 st->lp_gainc += ( exc[i - 2 * L_subfr] - st->lp_gainp * exc[i - 2 * L_subfr - Tc] ) * ( exc[i - 2 * L_subfr] - st->lp_gainp * exc[i - 2 * L_subfr - Tc] );
     180             :             }
     181      302687 :             st->lp_gainc = (float) sqrt( st->lp_gainc / ( 2.0f * L_subfr ) );
     182             :         }
     183      623931 :         if ( ( st->nbLostCmpt == 1 ) && st->rf_frame_type >= RF_TCXFD && st->rf_frame_type <= RF_TCXTD2 && st->use_partial_copy )
     184             :         {
     185          12 :             predPitchLag = ( hTcxLtpDec->tcxltp_pitch_int + hTcxLtpDec->tcxltp_pitch_fr / (float) st->pit_res_max ) * (float) hTcxDec->L_frameTCX / (float) st->L_frame;
     186          12 :             T0 = (int16_t) ( predPitchLag + 0.5f );
     187             : 
     188          12 :             if ( ( T0 > 0 ) && ( T0 != Tc ) && ( (float) abs( T0 - Tc ) < 0.15f * Tc ) )
     189             :             {
     190          12 :                 fUseExtrapolatedPitch = 1;
     191             :             }
     192             :         }
     193             :         else
     194             :         {
     195      623919 :             pitch_pred_linear_fit( st->nbLostCmpt, st->last_good, old_pitch_buf, &( st->old_fpitchFB ), &predPitchLag, hTcxDec->pit_min_TCX, hTcxDec->pit_max_TCX, st->mem_pitch_gain, st->output_Fs > 25600, st->plc_use_future_lag, &extrapolationFailed, st->nb_subfr );
     196             : 
     197      623919 :             T0 = (int16_t) ( predPitchLag + 0.5f );
     198             : 
     199      623919 :             if ( ( T0 > 0 ) && ( T0 != Tc ) && ( (float) abs( T0 - Tc ) < 0.15f * Tc ) && extrapolationFailed == 0 )
     200             :             {
     201      115189 :                 fUseExtrapolatedPitch = 1;
     202             :             }
     203             :         }
     204             : 
     205      623931 :         fLowPassFilter = 0;
     206      623931 :         pt_exc = exc + offset;
     207             : 
     208      623931 :         pt1_exc = pt_exc - Tc;
     209             : 
     210      623931 :         if ( fUseExtrapolatedPitch != 0 )
     211             :         {
     212      115201 :             pt_exc = buf;
     213             :         }
     214             : 
     215      623931 :         if ( st->stab_fac < 1 && st->nbLostCmpt == 1 )
     216             :         {
     217             :             /* pitch cycle is first low-pass filtered */
     218    22714058 :             for ( i = 0; i < Tc; i++ )
     219             :             {
     220    22602484 :                 if ( st->output_Fs <= 16000 )
     221             :                 {
     222     3787056 :                     *pt_exc++ = ( 0.0053f * pt1_exc[-5] + 0.0000f * pt1_exc[-4] + -0.0440f * pt1_exc[-3] + 0.0000f * pt1_exc[-2] + 0.2637f * pt1_exc[-1] + 0.5500f * pt1_exc[0] + 0.2637f * pt1_exc[1] + 0.0000f * pt1_exc[2] + -0.0440f * pt1_exc[3] + 0.0000f * pt1_exc[4] + 0.0053f * pt1_exc[5] );
     223             :                 }
     224             :                 else /*(st->output_Fs >= 32000)*/
     225             :                 {
     226    18815428 :                     *pt_exc++ = ( -0.0053f * pt1_exc[-5] + -0.0037f * pt1_exc[-4] + -0.0140f * pt1_exc[-3] + 0.0180f * pt1_exc[-2] + 0.2668f * pt1_exc[-1] + 0.4991f * pt1_exc[0] + 0.2668f * pt1_exc[1] + 0.0180f * pt1_exc[2] + -0.0140f * pt1_exc[3] + -0.0037f * pt1_exc[4] + -0.0053f * pt1_exc[5] );
     227             :                 }
     228    22602484 :                 pt1_exc++;
     229             :             }
     230      111574 :             fLowPassFilter = 1;
     231             :         }
     232             :         else
     233             :         {
     234             :             /* copy the first pitch cycle without low-pass filtering */
     235   117791586 :             for ( i = 0; i < Tc; i++ )
     236             :             {
     237   117279229 :                 *pt_exc++ = *pt1_exc++;
     238             :             }
     239      512357 :             fLowPassFilter = 1;
     240             :         }
     241             : 
     242      623931 :         if ( fUseExtrapolatedPitch != 0 )
     243             :         {
     244      115201 :             pt1_exc = buf;
     245             :         }
     246             : 
     247   355759578 :         for ( i = 0; i < L_frame - fLowPassFilter * Tc + L_subfr; i++ )
     248             :         {
     249   355135647 :             *pt_exc++ = *pt1_exc++;
     250             :         }
     251             : 
     252      623931 :         if ( fUseExtrapolatedPitch != 0 )
     253             :         {
     254      115201 :             get_subframe_pitch( st->nb_subfr, st->old_fpitch, predPitchLag * st->L_frame / L_frame, pitch_buf );
     255             : 
     256      115201 :             PulseResynchronization( buf, exc, L_frame, st->nb_subfr, st->old_fpitchFB, predPitchLag );
     257             :         }
     258             :         else
     259             :         {
     260      508730 :             set_f( pitch_buf, st->old_fpitch, st->nb_subfr );
     261             :         }
     262             : 
     263      623931 :         if ( st->nbLostCmpt == 1 )
     264             :         {
     265      302687 :             pt_exc = exc + L_frame;
     266      302687 :             pt1_exc = pt_exc - ( ( T0 == 0 ) ? Tc : T0 );
     267             : 
     268    99505887 :             for ( i = 0; i < L_frame / 2; i++ )
     269             :             {
     270    99203200 :                 *pt_exc++ = *pt1_exc++;
     271             :             }
     272             :         }
     273             : 
     274      623931 :         if ( fUseExtrapolatedPitch != 0 )
     275             :         {
     276      115201 :             st->old_fpitchFB = predPitchLag;
     277             :         }
     278      623931 :         st->bpf_gain_param = 0;
     279             : 
     280             :         /* PLC: calculate damping factor */
     281      623931 :         alpha = Damping_fact( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &( st->lp_gainp ), ACELP_CORE );
     282             : 
     283      623931 :         if ( st->nbLostCmpt == 1 )
     284             :         {
     285      302687 :             st->cummulative_damping = 1;
     286             :         }
     287             :         else
     288             :         {
     289      321244 :             st->cummulative_damping *= alpha;
     290             :         }
     291             : 
     292      623931 :         gain = 1.0f;
     293      623931 :         if ( st->rf_frame_type == RF_TCXTD1 && st->use_partial_copy == 1 )
     294             :         {
     295           6 :             gain = 0.5f;
     296             :         }
     297             : 
     298      623931 :         step = ( 1.0f / ( L_frame + ( L_frame / 2 ) ) ) * ( gain - alpha );
     299             : 
     300             :         /* PLC: Apply fade out */
     301   505515291 :         for ( i = offset; i < L_frame + ( L_frame / 2 ); i++ )
     302             :         {
     303   504891360 :             exc[i] *= gain;
     304   504891360 :             gain -= step;
     305             :         }
     306             : 
     307      623931 :         offset = max( ( (int16_t) ( st->old_fpitchFB + 0.5f ) ) - L_frame / 2, 0 );
     308      623931 :         mvr2r( exc + L_frame - offset, st->hTcxDec->old_excFB, L_frame / 2 + offset );
     309             : 
     310             :         /* copy old_exc as 16kHz for acelp decoding */
     311      623931 :         if ( st->nbLostCmpt == 1 )
     312             :         {
     313      302687 :             lerp( exc - L_frame / 2, st->old_exc, L_EXC_MEM_DEC, L_frame + L_frame / 2 );
     314             :         }
     315             :         else
     316             :         {
     317      321244 :             mvr2r( st->old_exc + L_FRAME16k, st->old_exc, L_FRAME16k / 2 );
     318      321244 :             lerp( exc, st->old_exc + L_FRAME16k / 2, L_FRAME16k, L_frame );
     319             :         }
     320             :     }
     321             :     else
     322             :     {
     323             :         /* No harmonic part */
     324           0 :         set_zero( &exc[0], L_frame + L_frame / 2 );
     325             : 
     326           0 :         if ( st->nbLostCmpt == 1 )
     327             :         {
     328           0 :             st->lp_gainc = 0.0f;
     329             : 
     330           0 :             for ( i = 0; i < 2 * L_subfr; i++ )
     331             :             {
     332           0 :                 st->lp_gainc += ( exc[i - 2 * L_subfr] ) * ( exc[i - 2 * L_subfr] );
     333             :             }
     334           0 :             st->lp_gainc = (float) sqrt( st->lp_gainc / ( 2.0f * L_subfr ) );
     335             :         }
     336             : 
     337           0 :         set_f( pitch_buf, (float) L_SUBFR, st->nb_subfr );
     338             : 
     339             :         /* PLC: calculate damping factor */
     340           0 :         alpha = Damping_fact( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &( st->lp_gainp ), ACELP_CORE );
     341             :     }
     342             : 
     343             :     /*-----------------------------------------------------------------*
     344             :      * Construct the random part of excitation
     345             :      *-----------------------------------------------------------------*/
     346             : 
     347      623931 :     if ( coh != -1.f )
     348             :     {
     349             :         int16_t tmpSeed1;
     350             :         float alpha_coh;
     351             :         float random1, random2;
     352             : 
     353      116812 :         tmpSeed1 = *noise_seed;
     354      116812 :         noise = buf;
     355             : 
     356      116812 :         alpha_coh = sqrtf( ( 1 - coh ) / ( 1 + coh ) );
     357      116812 :         if ( st->idchan == 1 )
     358             :         {
     359       54690 :             alpha_coh = -alpha_coh;
     360             :         }
     361             : 
     362    77049412 :         for ( i = 0; i < L_frame + L_FIR_FER2 - 1; i++ )
     363             :         {
     364    76932600 :             random1 = (float) own_random( &tmpSeed1 );
     365    76932600 :             random2 = (float) own_random( &tmpSeed1 );
     366    76932600 :             noise[i] = random1 + alpha_coh * random2;
     367             :         }
     368             : 
     369      116812 :         if ( st->idchan == 1 || only_left )
     370             :         {
     371       76081 :             *noise_seed = tmpSeed1;
     372             :         }
     373             : 
     374    39400796 :         for ( ; i < L_frame + ( L_frame / 2 ) + 2 * L_FIR_FER2; i++ )
     375             :         {
     376    39283984 :             random1 = (float) own_random( &tmpSeed1 );
     377    39283984 :             random2 = (float) own_random( &tmpSeed1 );
     378    39283984 :             noise[i] = random1 + alpha_coh * random2;
     379             :         }
     380             :     }
     381             :     else
     382             :     {
     383      507119 :         tmpSeed = st->seed_acelp;
     384      507119 :         noise = buf;
     385             : 
     386   335501989 :         for ( i = 0; i < L_frame + L_FIR_FER2 - 1; i++ )
     387             :         {
     388   334994870 :             noise[i] = (float) own_random( &tmpSeed );
     389             :         }
     390      507119 :         st->seed_acelp = tmpSeed;
     391             : 
     392   171554387 :         for ( ; i < L_frame + ( L_frame / 2 ) + 2 * L_FIR_FER2; i++ )
     393             :         {
     394   171047268 :             noise[i] = (float) own_random( &tmpSeed );
     395             :         }
     396             :     }
     397             : 
     398      623931 :     if ( st->last_good == VOICED_CLAS || st->last_good == ONSET )
     399             :     {
     400      592377 :         mem = noise[0];
     401      592377 :         preemph( &noise[1], st->output_Fs <= 16000 ? 0.2f : 0.6f, L_frame + ( L_frame / 2 ) + L_FIR_FER2, &mem );
     402             :     }
     403             : 
     404             :     /* high rate filter tuning */
     405      623931 :     if ( st->output_Fs <= 16000 )
     406             :     {
     407     2381880 :         for ( i = 0; i < L_FIR_FER2; i++ )
     408             :         {
     409     2183390 :             hp_filt[i] = h_high3_16[i];
     410             :         }
     411             :     }
     412             :     else /*(st->output_Fs==32000)*/
     413             :     {
     414     5105292 :         for ( i = 0; i < L_FIR_FER2; i++ )
     415             :         {
     416     4679851 :             hp_filt[i] = h_high3_32[i];
     417             :         }
     418             :     }
     419             : 
     420      623931 :     if ( st->nbLostCmpt == 1 )
     421             :     {
     422      302687 :         highPassFiltering( st->last_good, L_frame + L_frame / 2 + L_FIR_FER2, noise, hp_filt, L_FIR_FER2 );
     423             :     }
     424             :     else
     425             :     {
     426      321244 :         if ( st->last_good > UNVOICED_TRANSITION )
     427             :         {
     428   314777568 :             for ( i = 0; i < L_frame + L_frame / 2 + L_FIR_FER2; i++ )
     429             :             {
     430   314456324 :                 noise[i] = ( 1 - st->cummulative_damping ) * noise[i] + st->cummulative_damping * dotp( &noise[i], hp_filt, L_FIR_FER2 );
     431             :             }
     432             :         }
     433             :     }
     434             : 
     435             :     /* PLC: [TCX: Fade-out] retrieve background level */
     436      623931 :     tmp = 1.0f;
     437      623931 :     if ( A_cng != NULL )
     438             :     {
     439      116812 :         gainSynthDeemph = getLevelSynDeemph( &( tmp ), A_cng, L_frame / 4, st->preemph_fac, 1 ) / 4.f;
     440             :     }
     441             :     else
     442             :     {
     443      507119 :         gainSynthDeemph = getLevelSynDeemph( &( tmp ), A_local, L_frame / 4, st->preemph_fac, 1 );
     444             :     }
     445      623931 :     if ( st->tcxonly )
     446             :     {
     447      509679 :         gainCNG = hTcxDec->CngLevelBackgroundTrace_bfi / gainSynthDeemph;
     448             : 
     449      509679 :         if ( st->element_mode == IVAS_CPE_MDCT && A_cng != NULL )
     450             :         {
     451      116812 :             if ( st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME + MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN )
     452             :             {
     453           0 :                 gainCNG = 0.f;
     454             :             }
     455      116812 :             else if ( st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME )
     456             :             {
     457           0 :                 gainCNG *= 1.f - (float) ( st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN;
     458             :             }
     459             :         }
     460             :     }
     461             :     else
     462             :     {
     463      114252 :         gainCNG = st->cngTDLevel / gainSynthDeemph;
     464             :     }
     465      623931 :     gain = st->lp_gainc; /* start-of-the-frame gain */
     466             : 
     467      623931 :     if ( st->rf_frame_type == RF_TCXTD1 && st->use_partial_copy == 1 )
     468             :     {
     469           6 :         gain *= 0.7f;
     470             :     }
     471             : 
     472      623931 :     ftmp = 2.0f * gain;
     473             : 
     474      623931 :     if ( gainCNG > ftmp )
     475             :     {
     476         171 :         gainCNG = ftmp;
     477             :     }
     478             : 
     479      623931 :     st->lp_gainc = alpha * st->lp_gainc + ( 1.0f - alpha ) * gainCNG; /* end-of-the-frame gain */
     480             : 
     481             :     /* PLC: [TCX: Fade-out] Linearly attenuate the gain through the frame */
     482      623931 :     step = ( 1.0f / L_frame ) * ( gain - st->lp_gainc );
     483      623931 :     pt_exc = noise + L_FIR_FER2 / 2;
     484             : 
     485      623931 :     gain_inov = 1.0f / (float) sqrt( dotp( pt_exc, pt_exc, L_frame ) / L_frame + 0.01f ); /* normalize energy */
     486             : 
     487      623931 :     if ( ( st->last_good == UNVOICED_CLAS ) && ( st->core_ext_mode != UNVOICED ) )
     488             :     {
     489           0 :         gain_inov *= 0.8f;
     490             :     }
     491      623931 :     else if ( !( ( st->last_good == UNVOICED_CLAS ) || ( st->last_good == UNVOICED_TRANSITION ) ) )
     492             :     {
     493      623931 :         gain_inov *= ( 1.1f - 0.75f * st->lp_gainp );
     494             :     }
     495      623931 :     st->lp_gainp = alpha;
     496      623931 :     pt_exc = noise; /* non-causal ringing of the FIR filter   */
     497             : 
     498     3743586 :     for ( i = 0; i < L_FIR_FER2 / 2; i++ )
     499             :     {
     500     3119655 :         *pt_exc++ *= ( gain_inov * gain );
     501             :     }
     502             : 
     503   409431746 :     for ( i = 0; i < L_frame + L_FIR_FER2 / 2; i++ ) /* Actual filtered random part of excitation */
     504             :     {
     505   408807815 :         *pt_exc++ *= ( gain_inov * gain );
     506   408807815 :         gain -= step;
     507             :     }
     508             : 
     509   203468011 :     for ( i = 0; i < ( L_frame / 2 ); i++ ) /* causal ringing of the FIR filter */
     510             :     {
     511   202844080 :         *pt_exc++ *= ( gain_inov * gain );
     512             :     }
     513             : 
     514             :     /*-----------------------------------------------------------------*
     515             :      * Construct the total excitation
     516             :      *-----------------------------------------------------------------*/
     517             : 
     518      623931 :     if ( st->last_good >= UNVOICED_TRANSITION )
     519             :     {
     520   609156171 :         for ( i = 0; i < ( L_frame + L_frame / 2 ); i++ )
     521             :         {
     522   608532240 :             exc[i] += noise[i + ( L_FIR_FER2 / 2 )];
     523             :         }
     524             :     }
     525             :     else
     526             :     {
     527           0 :         mvr2r( noise + L_FIR_FER2 / 2, exc, L_frame + L_frame / 2 );
     528           0 :         mvr2r( exc + L_frame - 2 * L_subfr, st->hTcxDec->old_excFB, 2 * L_subfr + L_frame / 2 );
     529             : 
     530             :         /* copy old_exc as 16kHz for acelp decoding */
     531           0 :         if ( st->nbLostCmpt == 1 )
     532             :         {
     533           0 :             lerp( exc, st->old_exc, L_EXC_MEM_DEC, L_frame + L_frame / 2 );
     534             :         }
     535             :         else
     536             :         {
     537           0 :             mvr2r( st->old_exc + L_FRAME16k, st->old_exc, L_FRAME16k / 2 );
     538           0 :             lerp( exc, st->old_exc + L_FRAME16k / 2, L_FRAME16k, L_frame );
     539             :         }
     540             :     }
     541             : 
     542             :     /* Update Pitch Lag memory */
     543      623931 :     mvr2r( &st->old_pitch_buf[st->nb_subfr], st->old_pitch_buf, st->nb_subfr );
     544      623931 :     mvr2r( pitch_buf, &st->old_pitch_buf[st->nb_subfr], st->nb_subfr );
     545             : 
     546             :     /*----------------------------------------------------------*
     547             :      * - compute the synthesis speech                           *
     548             :      *----------------------------------------------------------*/
     549             : 
     550      623931 :     syn = buf + M;
     551      623931 :     mvr2r( synth - M, buf, M );
     552      623931 :     mvr2r( buf, mem_syn, M );
     553             : 
     554      623931 :     if ( A_cng != NULL )
     555             :     {
     556             :         float alpha_delayed;
     557             : 
     558      116812 :         alpha_delayed = 1.0f;
     559      116812 :         if ( st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE )
     560             :         {
     561       41194 :             alpha_delayed = Damping_fact( st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE, st->last_good, st->stab_fac, &( st->lp_gainp ), ACELP_CORE );
     562             :         }
     563             : 
     564      116812 :         if ( st->plcBackgroundNoiseUpdated && alpha_delayed != 1.0f )
     565             :         {
     566             :             float lsp_local[M], lsp_fade[M], alpha_inv;
     567             : 
     568       27648 :             alpha_inv = 1.0f - alpha_delayed;
     569             : 
     570       27648 :             a2lsp_stab( A_local, lsp_local, st->lspold_cng );
     571             : 
     572      470016 :             for ( i = 0; i < M; i++ )
     573             :             {
     574      442368 :                 lsp_fade[i] = alpha_delayed * lsp_local[i] + alpha_inv * st->lspold_cng[i];
     575             :             }
     576             : 
     577       27648 :             lsp2a_stab( lsp_fade, A_local, M );
     578             :         }
     579             :     }
     580             : 
     581      623931 :     syn_filt( A_local, M, &exc[0], &syn[0], L_frame + ( L_frame / 2 ), mem_syn, 1 );
     582             : 
     583      623931 :     n = (int16_t) ( (float) L_frame * N_ZERO_MDCT_NS / FRAME_SIZE_NS );
     584             : 
     585             :     /* update ACELP synthesis memory */
     586      623931 :     mem_syn_r_size_old = (int16_t) ( 1.25 * L_frame / 20.f );
     587             : 
     588             :     /* copy mem_syn as 16kHz */
     589      623931 :     mem_syn_r_size_new = (int16_t) ( 1.25 * L_FRAME16k / 20.f );
     590      623931 :     mvr2r( syn + L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM );
     591      623931 :     lerp( st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
     592      623931 :     mvr2r( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2, M );
     593             : 
     594             :     /* Deemphasis and output synth and ZIR */
     595      623931 :     deemph( syn, st->preemph_fac, L_frame + L_frame / 2, &tmp_deemph );
     596      623931 :     mvr2r( syn + L_frame - M - 1, st->syn, 1 + M );
     597             : 
     598             : 
     599      623931 :     lerp( syn + L_frame - L_frame / 2, st->hTcxDec->old_syn_Overl, st->L_frame / 2, L_frame / 2 );
     600      623931 :     mvr2r( syn + L_frame - n, st->hHQ_core->old_out, L_frame - n );
     601             : 
     602   178112501 :     for ( i = 0; i < W1; i++ )
     603             :     {
     604   177488570 :         st->hHQ_core->old_out[i + n] *= w[W1 - 1 - i] * w[W1 - 1 - i];
     605             :     }
     606      623931 :     set_zero( &st->hHQ_core->old_out[W1 + n], n );
     607             : 
     608      623931 :     mvr2r( syn, synth, L_frame );
     609             : 
     610      623931 :     mvr2r( syn + L_frame, st->hTcxDec->syn_OverlFB, L_frame / 2 );
     611             : 
     612             :     /* copy total excitation exc2 as 16kHz for ACELP MODE1 decoding */
     613      623931 :     if ( st->hWIDec != NULL )
     614             :     {
     615         194 :         lerp( exc, st->hWIDec->old_exc2, L_EXC_MEM, L_frame );
     616         194 :         lerp( syn, st->hWIDec->old_syn2, L_EXC_MEM, L_frame );
     617             :     }
     618      623931 :     st->bfi_pitch = pitch_buf[st->nb_subfr - 1];
     619      623931 :     st->bfi_pitch_frame = st->L_frame;
     620             : 
     621             :     /* create aliasing and windowing need for transition to TCX10/5 */
     622      623931 :     mvr2r( syn + L_frame, st->hTcxDec->syn_Overl_TDACFB, L_frame / 2 );
     623             : 
     624   178112501 :     for ( i = 0; i < W1; i++ )
     625             :     {
     626   177488570 :         buf[i] = st->hTcxDec->syn_Overl_TDACFB[i] * w[W1 - 1 - i];
     627             :     }
     628             : 
     629    89368216 :     for ( i = 0; i < W2; i++ )
     630             :     {
     631    88744285 :         st->hTcxDec->syn_Overl_TDACFB[i] = buf[i] + buf[W1 - 1 - i]; /* A-D */
     632             :     }
     633             : 
     634    89368216 :     for ( i = 0; i < W2; i++ )
     635             :     {
     636    88744285 :         st->hTcxDec->syn_Overl_TDACFB[W2 + i] = buf[W2 + i] + buf[W1 - 1 - W2 - i]; /* B-C */
     637             :     }
     638             : 
     639   178112501 :     for ( i = 0; i < W1; i++ )
     640             :     {
     641   177488570 :         st->hTcxDec->syn_Overl_TDACFB[i] *= w[W1 - 1 - i];
     642             :     }
     643             : 
     644      623931 :     st->hTcxCfg->tcx_curr_overlap_mode = FULL_OVERLAP;
     645      623931 :     synth[-1] = pre_emph_buf;
     646             : 
     647             :     /* update memory for low band */
     648      623931 :     lerp( st->hTcxDec->syn_OverlFB, st->hTcxDec->syn_Overl, st->L_frame / 2, L_frame / 2 );
     649      623931 :     lerp( st->hTcxDec->syn_Overl_TDACFB, st->hTcxDec->syn_Overl_TDAC, st->L_frame / 2, L_frame / 2 );
     650      623931 :     lerp( st->hHQ_core->old_out, st->hHQ_core->old_outLB, st->L_frame, L_frame );
     651             : 
     652      623931 :     st->old_enr_LP = enr_1_Az( A_local, L_SUBFR );
     653             : 
     654      623931 :     return;
     655             : }

Generated by: LCOV version 1.14