LCOV - code coverage report
Current view: top level - lib_dec - er_dec_tcx_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ da9cc8ead0679b4682d329fdff98cf1616159273 Lines: 887 986 90.0 %
Date: 2025-10-13 22:24:20 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : 
       5             : 
       6             : #include <assert.h>
       7             : #include <stdint.h>
       8             : #include "options.h"
       9             : #include "prot_fx.h"
      10             : #include "basop_util.h"
      11             : #include "rom_dec.h"
      12             : 
      13             : /*****************************************************
      14             :     calcGainc calculates st->lp_gainc
      15             : ******************************************************/
      16        2396 : static void calcGainc_fx( Word16 *exc, Word16 Q_exc, Word32 old_fpitch /*Q16*/, Word16 L_subfr /*Q0*/, Word32 lp_gainp /*Q16*/, Word32 *lp_gainc /*Q16*/ )
      17             : {
      18             :     Word16 tmp16, tmp16_2, tmp16_3, tmp_e, tmp2_e, tmp_loop, i;
      19             : #ifndef FIX_ISSUE_1965_REPLACE_CARRY_OVERFLOW
      20             :     Word32 L_c;
      21             :     Word32 L_acc, L_tmp;
      22             : #else
      23             :     Word64 W_acc;
      24             :     Word32 L_tmp;
      25             : #endif
      26             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      27             : #ifndef FIX_ISSUE_1965_REPLACE_CARRY_OVERFLOW
      28             :     Flag Overflow = 0;
      29             :     Flag Carry = 0;
      30             : #endif
      31        2396 :     move32();
      32        2396 :     move32();
      33             : #endif
      34             : 
      35             : 
      36             : #ifndef FIX_ISSUE_1965_REPLACE_CARRY_OVERFLOW
      37             :     L_acc = L_deposit_l( 0 );
      38             :     L_c = L_deposit_l( 0 );
      39             : #else
      40        2396 :     W_acc = 0;
      41             : #endif
      42             : #ifndef FIX_ISSUE_1965_REPLACE_CARRY_OVERFLOW
      43             :     Overflow = 0;
      44             :     move16();
      45             :     Carry = 0;
      46             :     move16();
      47             : #endif
      48             : 
      49        2396 :     tmp16 = round_fx( old_fpitch ); /*Q0*/
      50        2396 :     tmp_loop = shl( L_subfr, 1 );
      51             :     BASOP_SATURATE_WARNING_OFF_EVS
      52        2396 :     tmp16_2 = round_fx_sat( L_shl_sat( lp_gainp, 2 ) ); /*Q31->Q15, no severe saturation, because st->lp_gainp here is [0,1]*/
      53             :     BASOP_SATURATE_WARNING_ON_EVS
      54             : 
      55      769372 :     FOR( i = 0; i < tmp_loop; i++ )
      56             :     {
      57             :         /*st->lp_gainc += ( exc[i-2*L_subfr] - st->Mode2_lp_gainp * exc[i-2*L_subfr-(int)(st->old_fpitch+0.5f)] ) *
      58             :                           ( exc[i-2*L_subfr] - st->Mode2_lp_gainp * exc[i-2*L_subfr-(int)(st->old_fpitch+0.5f)] );*/
      59      766976 :         tmp16_3 = sub_sat( exc[( i - ( L_subfr * 2 ) )] /*Q1*/, mult_r( tmp16_2 /*Q15*/, exc[( ( i - ( L_subfr * 2 ) ) - tmp16 )] /*Q1*/ ) /*Q1*/ );
      60             : #ifndef FIX_ISSUE_1965_REPLACE_CARRY_OVERFLOW
      61             :         L_acc = L_macNs_co( L_acc, tmp16_3, tmp16_3, &Carry, &Overflow ); /*Q3*/
      62             :         Overflow = 0;
      63             :         move16();
      64             :         L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Accumulate Carrys Q-1*/
      65             :         Carry = 0;
      66             :         move16();
      67             : #else
      68      766976 :         W_acc = W_mac_16_16( W_acc, tmp16_3, tmp16_3 ); /*Q3*/
      69             : #endif
      70             :     }
      71             : #ifndef FIX_ISSUE_1965_REPLACE_CARRY_OVERFLOW
      72             :     L_tmp = norm_llQ31( L_c, L_acc, &tmp_e ); /*Q3,norm,tmp_e*/
      73             : #else
      74        2396 :     L_tmp = w_norm_llQ31( W_acc, &tmp_e );              /*Q3,norm,tmp_e*/
      75             : #endif
      76        2396 :     tmp_e = add( tmp_e, 31 - ( add( shl( Q_exc, 1 ), 1 ) ) ); /*L_tmp is Q31, now*/
      77        2396 :     tmp16 = BASOP_Util_Divide3216_Scale( L_tmp /*Q31,norm,tmp_e*/, shl( L_subfr, 1 ) /*Q15,15*/, &tmp2_e ) /*Q15,tmp2_e+tmp_e-15*/;
      78        2396 :     tmp_e = sub( add( tmp2_e, tmp_e ), 15 );
      79             : 
      80        2396 :     IF( tmp16 != 0 )
      81             :     {
      82        2396 :         tmp16 = Sqrt16( tmp16, &tmp_e ); /*Q15,norm,tmp_e*/
      83             :     }
      84        2396 :     *lp_gainc = L_shl( L_deposit_l( tmp16 ), add( tmp_e, 1 ) ); /*15Q16*/
      85        2396 :     move32();
      86        2396 : }
      87             : 
      88           0 : static void calcGainc2_fx( Word16 *exc, Word16 Q_exc, Word16 L_subfr /*Q0*/, Word32 *lp_gainc /*Q16*/ )
      89             : {
      90             :     Word16 i, cnt, tmp16, tmp_e, tmp2_e;
      91             : #ifndef FIX_ISSUE_1965_REPLACE_CARRY_OVERFLOW
      92             :     Word32 L_c, L_acc, L_tmp;
      93             : #else
      94             :     Word64 W_acc;
      95             :     Word32 L_tmp;
      96             : #endif
      97             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      98             : #ifndef FIX_ISSUE_1965_REPLACE_CARRY_OVERFLOW
      99             :     Flag Overflow = 0;
     100             :     Flag Carry = 0;
     101             : #endif
     102             : #endif
     103           0 :     move16();
     104           0 :     move16();
     105             : 
     106             : 
     107             : #ifndef FIX_ISSUE_1965_REPLACE_CARRY_OVERFLOW
     108             :     Carry = 0;
     109             :     move16();
     110             :     Overflow = 0;
     111             :     move16();
     112             : 
     113             :     L_c = L_deposit_l( 0 );
     114             :     L_acc = L_deposit_l( 0 );
     115             : #else
     116           0 :     W_acc = 0;
     117             : #endif
     118             : 
     119           0 :     cnt = shl( L_subfr, 1 );
     120             : 
     121           0 :     FOR( i = 0; i < cnt; i++ )
     122             :     {
     123             :         /* *gainc += ( exc[i-2*L_subfr] ) * ( exc[i-2*L_subfr]); */
     124             : #ifndef FIX_ISSUE_1965_REPLACE_CARRY_OVERFLOW
     125             :         L_acc = L_macNs_co( L_acc, exc[( i - ( L_subfr * 2 ) )] /*Q1*/, exc[( i - ( L_subfr * 2 ) )] /*Q1*/, &Carry, &Overflow ); /*Q3*/
     126             :         Overflow = 0;
     127             :         move16();
     128             :         L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /* Accumulate Carrys Q-1*/
     129             :         Carry = 0;
     130             :         move16();
     131             : #else
     132           0 :         W_acc = W_mac_16_16( W_acc, exc[( i - ( L_subfr * 2 ) )] /*Q1*/, exc[( i - ( L_subfr * 2 ) )] /*Q1*/ ); /*Q3*/
     133             : #endif
     134             :     }
     135             : 
     136             : #ifndef FIX_ISSUE_1965_REPLACE_CARRY_OVERFLOW
     137             :     L_tmp = norm_llQ31( L_c, L_acc, &tmp_e ); /*Q3,norm,tmp_e*/
     138             : #else
     139           0 :     L_tmp = w_norm_llQ31( W_acc, &tmp_e );                                                                      /*Q3,norm,tmp_e*/
     140             : #endif
     141           0 :     tmp_e = add( tmp_e, sub( 31, ( add( shl( Q_exc, 1 ), 1 ) ) ) ); /*L_tmp is Q31, now*/
     142           0 :     tmp16 = BASOP_Util_Divide3216_Scale( L_tmp /*Q31,norm,tmp_e*/, shl( L_subfr, 1 ) /*Q15,15*/, &tmp2_e ) /*Q15,tmp2_e+tmp_e-15*/;
     143           0 :     tmp_e = sub( add( tmp2_e, tmp_e ), 15 );
     144             : 
     145           0 :     IF( tmp16 != 0 )
     146             :     {
     147           0 :         tmp16 = Sqrt16( tmp16, &tmp_e ); /*Q15,norm,tmp_e*/
     148             :     }
     149           0 :     *lp_gainc = L_shl( L_deposit_l( tmp16 ), add( tmp_e, 1 ) ); /*15Q16*/
     150           0 :     move32();
     151           0 : }
     152             : 
     153             : /******************************************************
     154             : 
     155             : con_tcx
     156             : 
     157             : \brief main function in time domain TCX concealment
     158             : 
     159             : *******************************************************/
     160             : 
     161        1251 : void con_tcx_fx(
     162             :     Decoder_State *st, /* i/o: coder memory state            */
     163             :     Word16 synth[]     /* i/o:   synth[]                     Q0*/
     164             : )
     165             : {
     166             :     Word16 i, s, c, L_frame, L_subfr, fLowPassFilter, T0;
     167             :     Word16 n, mem_syn_r_size_old, mem_syn_r_size_new;
     168             :     Word16 *noise;
     169             :     Word16 mem_syn[M], *syn;
     170             :     Word16 *exc, buf[OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2];
     171             :     Word16 pre_emph_buf;
     172             :     Word16 hp_filt[L_FIR_FER2];
     173             :     Word16 alpha;
     174             :     Word16 tmp_deemph, gain, gainCNG, gain_inov;
     175             :     Word16 *pt_exc, *pt1_exc;
     176             :     Word16 Tc, tmpSeed;
     177             :     Word16 fUseExtrapolatedPitch;
     178             :     Word16 *ana_window;
     179             :     Word16 r_h[M + 1], A_local[M + 1], mem, r_l[M + 1];
     180             :     PWord16 const *w;
     181             :     Word16 W1, W2, W12;
     182             :     Word16 Q_r;
     183             :     Word16 tmp16, tmp16_2, tmp_loop, tmp_e, gain_tmp;
     184             :     Word16 gainCNG_e, noise_e, gain_inov_e; /*Exponents for gainCNG, noise, gain_inov*/
     185             :     Word16 Q_syn;                           /*Q format of temporary synthesis buffer syn*/
     186             :     Word32 L_tmp, L_tmp2, step32_tmp;
     187             :     Word32 predPitchLag, pitch_buf[NB_SUBFR16k], step32, gain32;
     188             :     Word16 extrapolationFailed;
     189             :     Word16 gainSynthDeemph;
     190             :     Word16 gainSynthDeemph_e;
     191             :     Word32 old_pitch_buf[2 * NB_SUBFR16k + 2];
     192             :     Word16 Q_exc, new_Q, exp_scale;
     193             :     Word16 offset;
     194             :     HQ_DEC_HANDLE hHQ_core;
     195             :     TCX_LTP_DEC_HANDLE hTcxLtpDec;
     196             :     TCX_DEC_HANDLE hTcxDec;
     197             : 
     198        1251 :     hTcxLtpDec = st->hTcxLtpDec;
     199        1251 :     hHQ_core = st->hHQ_core;
     200        1251 :     hTcxDec = st->hTcxDec;
     201             : 
     202             :     /* inits */
     203        1251 :     alpha = 0;
     204        1251 :     move16();
     205        1251 :     fUseExtrapolatedPitch = 0;
     206        1251 :     move16();
     207        1251 :     extrapolationFailed = 1;
     208        1251 :     move16();
     209             : 
     210        1251 :     noise_e = 0;
     211        1251 :     move16();
     212        1251 :     Q_syn = -1; /*Q format of temporary synthesis buffer syn*/
     213        1251 :     move16();
     214        1251 :     offset = 0;
     215        1251 :     move16();
     216             : 
     217             :     /* Framing parameters */
     218        1251 :     L_frame = hTcxDec->L_frameTCX; /*Q0*/
     219        1251 :     move16();
     220             :     /* L_subfr = st->L_frameTCX/st->nb_subfr */
     221        1251 :     L_subfr = mult_r( hTcxDec->L_frameTCX, div_s( 1, st->nb_subfr ) ); /*Q0*/
     222        1251 :     assert( L_subfr == hTcxDec->L_frameTCX / st->nb_subfr );
     223        1251 :     move32();
     224        1251 :     w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument Q15*/
     225        1251 :     W1 = st->hTcxCfg->tcx_mdct_window_lengthFB;
     226        1251 :     move16();
     227        1251 :     W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 );
     228        1251 :     W12 = shr( W1, 1 );
     229             : 
     230             :     /* take the previous frame last pitch */
     231        1251 :     Tc = round_fx( st->old_fpitchFB ); /*Q0*/
     232             : 
     233             : 
     234        1251 :     set16_fx( buf, 0, OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2 ); /* initialize buf with 0 */
     235             :     // set16_fx(buf,0,shr(sizeof(buf),1)); /* initialize buf with 0 */
     236             : 
     237        1251 :     c = BASOP_Util_Divide1616_Scale(
     238             :         L_frame,
     239        1251 :         st->L_frame,
     240             :         &s );
     241             : 
     242       16263 :     FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ )
     243             :     {
     244       15012 :         old_pitch_buf[i] = L_shl( Mpy_32_16_1( st->old_pitch_buf_fx[i], c ), s ); /*Q16*/
     245       15012 :         move32();
     246             :     }
     247             : 
     248             :     /* set excitation memory*/
     249        1251 :     exc = buf + OLD_EXC_SIZE_DEC; /*Q_exc*/
     250        1251 :     tmp_deemph = synth[-1];       /*Q0*/
     251        1251 :     move16();
     252        1251 :     pre_emph_buf = synth[-1]; /*Q0*/
     253        1251 :     move16();
     254             : 
     255        1251 :     test();
     256        1251 :     IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc )
     257             :     {
     258             :         /* apply pre-emphasis to the signal */
     259         771 :         mem = synth[( -( ( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )]; /*Q0*/
     260         771 :         move16();
     261         771 :         Q_exc = E_UTIL_f_preemph3( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 );
     262         771 :         st->Mode2_lp_gainc = L_deposit_l( 0 );
     263             : 
     264         771 :         st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) ); /*Q16*/
     265             : 
     266         771 :         st->Mode2_lp_gainp = L_max( st->Mode2_lp_gainp, 0 );                   /*Q16*/
     267         771 :         st->Mode2_lp_gainp = L_min( st->Mode2_lp_gainp, 65536l /*1.0f Q16*/ ); /*Q16*/
     268         771 :         st->Mode2_lp_gainp = L_shl( st->Mode2_lp_gainp, 13 );                  /*Q29*/
     269             : 
     270         771 :         ana_window = buf; /*Q15*/
     271         771 :         ham_cos_window( ana_window, mult( L_frame, 24576 /*0.75f Q15*/ ), shr( L_frame, 2 ) );
     272             : 
     273             :         /* Autocorrelation */
     274         771 :         autocorr_fx( &( synth[( -L_frame - 1 )] ), M, r_h, r_l, &Q_r, L_frame, ana_window, 0, 0 );
     275             : 
     276             :         /* Lag windowing */
     277         771 :         lag_wind( r_h, r_l, M, st->output_Fs, LAGW_STRONG );
     278             : 
     279             :         /* Levinson Durbin */
     280         771 :         E_LPC_lev_dur( r_h, r_l, A_local, NULL, M, NULL );
     281             : 
     282             :         /* copy for multiple frame loss */
     283         771 :         Copy( A_local, st->old_Aq_12_8_fx, M + 1 ); /*Q12*/
     284             : 
     285             :         /* Residu */
     286         771 :         assert( ( 2 * L_subfr + Tc + 1 + M ) <= hTcxDec->old_synth_lenFB );
     287             : 
     288             :         BASOP_SATURATE_WARNING_OFF_EVS /*saturation possible in case of spiky synthesis*/
     289        2313 :             Residu3_fx(
     290             :                 A_local,
     291         771 :                 &( synth[-( ( add( ( L_subfr * 2 ), Tc ) + 1 ) + M )] ), /*Qx   = Q0*/
     292         771 :                 &( exc[-( ( add( ( L_subfr * 2 ), Tc ) + 1 ) + M )] ),   /*Qx+1 = Q1*/
     293         771 :                 add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M ),
     294             :                 1 );
     295             :         BASOP_SATURATE_WARNING_ON_EVS
     296             :     }
     297             :     ELSE
     298             :     {
     299             :         /* apply pre-emphasis to the signal */
     300         480 :         mem = synth[( -L_frame - 1 )]; /*Q0*/
     301         480 :         move16();
     302         480 :         Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 );
     303         480 :         Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q12*/
     304             : 
     305         480 :         offset = shr( L_frame, 1 );
     306         480 :         IF( GE_16( st->last_good, UNVOICED_TRANSITION ) )
     307             :         {
     308         480 :             tmp16 = s_max( sub( Tc, shr( L_frame, 1 ) ), 0 );
     309         480 :             Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), add( offset, tmp16 ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/
     310             :         }
     311             :         ELSE
     312             :         {
     313           0 :             Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-( L_subfr * 2 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/
     314             :         }
     315             :     }
     316             : 
     317             :     /*-----------------------------------------------------------------*
     318             :      * PLC: Construct the harmonic part of excitation
     319             :      *-----------------------------------------------------------------*/
     320             : 
     321        1251 :     test();
     322        1251 :     test();
     323        1251 :     IF( GT_16( st->last_good, UNVOICED_CLAS ) && !( EQ_16( st->last_good, UNVOICED_TRANSITION ) && EQ_16( st->core_ext_mode, GENERIC ) ) )
     324             :     {
     325        1251 :         test();
     326        1251 :         IF( EQ_16( st->nbLostCmpt, 1 ) || hTcxDec->tcxConceal_recalc_exc )
     327             :         {
     328         771 :             calcGainc_fx( exc, Q_exc, st->old_fpitchFB, L_subfr, st->Mode2_lp_gainp, &( st->Mode2_lp_gainc ) );
     329             :         }
     330             : 
     331        1251 :         tmp16 = 0;
     332        1251 :         move16();
     333        1251 :         if ( GT_32( st->output_Fs, 25600 ) )
     334             :         {
     335         988 :             tmp16 = 1;
     336         988 :             move16();
     337             :         }
     338             : 
     339        1251 :         test();
     340        1251 :         test();
     341        1251 :         test();
     342        1251 :         test();
     343        1251 :         IF( ( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) && GE_16( st->rf_frame_type, RF_TCXFD ) && LE_16( st->rf_frame_type, RF_TCXTD2 ) && st->use_partial_copy )
     344           0 :         {
     345             :             Word32 tcxltp_pitch_tmp; /*15Q16*/
     346             :             Word16 scale_tmp;        /*getInvFrameLen()->9Q6*/
     347             :             Word16 tmp_shift;
     348           0 :             tcxltp_pitch_tmp = L_add( L_deposit_h( hTcxLtpDec->tcxltp_pitch_int ), L_shl( L_deposit_l( div_s( hTcxLtpDec->tcxltp_pitch_fr, st->pit_res_max ) ), 1 ) ); /*15Q16*/
     349           0 :             scale_tmp = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) );                                                                                  /*getInvFrameLen()->9Q6*/
     350           0 :             tmp_shift = norm_s( scale_tmp );
     351           0 :             predPitchLag = L_shl( Mpy_32_16_1( tcxltp_pitch_tmp, shl( scale_tmp, tmp_shift ) ), sub( 9, tmp_shift ) ); /*Q16*/
     352             : 
     353           0 :             T0 = round_fx( predPitchLag ); /*Q0*/
     354             : 
     355           0 :             test();
     356           0 :             test();
     357           0 :             if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) )
     358             :             {
     359           0 :                 fUseExtrapolatedPitch = 1;
     360           0 :                 move16();
     361             :             }
     362             :         }
     363             :         ELSE
     364             :         {
     365        1251 :             pitch_pred_linear_fit(
     366        1251 :                 st->nbLostCmpt,
     367        1251 :                 st->last_good,
     368             :                 old_pitch_buf,
     369             :                 &( st->old_fpitchFB ),
     370             :                 &predPitchLag,
     371        1251 :                 hTcxDec->pit_min_TCX,
     372        1251 :                 hTcxDec->pit_max_TCX,
     373        1251 :                 st->mem_pitch_gain,
     374             :                 tmp16,
     375        1251 :                 st->plc_use_future_lag,
     376             :                 &extrapolationFailed,
     377        1251 :                 st->nb_subfr );
     378             : 
     379        1251 :             T0 = round_fx( predPitchLag ); /*Q0*/
     380        1251 :             test();
     381        1251 :             test();
     382        1251 :             test();
     383        1251 :             if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) && ( extrapolationFailed == 0 ) )
     384             :             {
     385         284 :                 fUseExtrapolatedPitch = 1;
     386         284 :                 move16();
     387             :             }
     388             :         }
     389             : 
     390             : 
     391        1251 :         fLowPassFilter = 0;
     392        1251 :         move16();
     393        1251 :         pt_exc = exc + offset; /*Q_exc*/
     394        1251 :         pt1_exc = pt_exc - Tc; /*Q_exc*/
     395             : 
     396        1251 :         if ( fUseExtrapolatedPitch != 0 )
     397             :         {
     398         284 :             pt_exc = buf; /*Q_exc*/
     399             :         }
     400        1251 :         test();
     401        1251 :         IF( LT_16( st->stab_fac_fx, 32767 /*1.f Q15*/ ) && EQ_16( st->nbLostCmpt, 1 ) )
     402             :         {
     403             :             /* pitch cycle is first low-pass filtered */
     404             : 
     405         448 :             IF( LE_32( st->output_Fs, 16000 ) )
     406             :             {
     407        7218 :                 FOR( i = 0; i < Tc; i++ )
     408             :                 {
     409        7145 :                     *pt_exc++ = mac_r_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat(
     410        7145 :                                                                                                                                        L_mult( 174 /* 0.0053f Q15*/, pt1_exc[-5] ),
     411        7145 :                                                                                                                                        0 /* 0.0000f Q15*/, pt1_exc[-4] ),
     412        7145 :                                                                                                                                    -1442 /*-0.0440f Q15*/, pt1_exc[-3] ),
     413        7145 :                                                                                                                         0 /* 0.0000f Q15*/, pt1_exc[-2] ),
     414        7145 :                                                                                                              8641 /* 0.2637f Q15*/, pt1_exc[-1] ),
     415        7145 :                                                                                                   18022 /* 0.5500f Q15*/, pt1_exc[0] ),
     416        7145 :                                                                                        8641 /* 0.2637f Q15*/, pt1_exc[1] ),
     417        7145 :                                                                             0 /* 0.0000f Q15*/, pt1_exc[2] ),
     418        7145 :                                                                  -1442 /*-0.0440f Q15*/, pt1_exc[3] ),
     419        7145 :                                                       0 /* 0.0000f Q15*/, pt1_exc[4] ),
     420        7145 :                                            174 /* 0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/
     421        7145 :                     move16();
     422        7145 :                     pt1_exc++;
     423             :                 }
     424             :             }
     425             :             ELSE /*(st->output_Fs >= 32000)*/
     426             :             {
     427      104676 :                 FOR( i = 0; i < Tc; i++ )
     428             :                 {
     429      104301 :                     *pt_exc++ = mac_r_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat(
     430      104301 :                                                                                                                                        L_mult( -174 /*-0.0053f Q15*/, pt1_exc[-5] ),
     431      104301 :                                                                                                                                        -121 /*-0.0037f Q15*/, pt1_exc[-4] ),
     432      104301 :                                                                                                                                    -459 /*-0.0140f Q15*/, pt1_exc[-3] ),
     433      104301 :                                                                                                                         590 /* 0.0180f Q15*/, pt1_exc[-2] ),
     434      104301 :                                                                                                              8743 /* 0.2668f Q15*/, pt1_exc[-1] ),
     435      104301 :                                                                                                   16355 /* 0.4991f Q15*/, pt1_exc[0] ),
     436      104301 :                                                                                        8743 /* 0.2668f Q15*/, pt1_exc[1] ),
     437      104301 :                                                                             590 /* 0.0180f Q15*/, pt1_exc[2] ),
     438      104301 :                                                                  -459 /*-0.0140f Q15*/, pt1_exc[3] ),
     439      104301 :                                                       -121 /*-0.0037f Q15*/, pt1_exc[4] ),
     440      104301 :                                            -174 /*-0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/
     441      104301 :                     move16();
     442      104301 :                     pt1_exc++;
     443             :                 }
     444             :             }
     445             : 
     446         448 :             fLowPassFilter = 1;
     447         448 :             move16();
     448             :         }
     449             :         ELSE
     450             :         {
     451             :             /* copy the first pitch cycle without low-pass filtering */
     452      187652 :             FOR( i = 0; i < Tc; i++ )
     453             :             {
     454      186849 :                 *pt_exc++ = *pt1_exc++; /*Q_exc*/
     455      186849 :                 move16();
     456             :             }
     457         803 :             fLowPassFilter = 1;
     458         803 :             move16();
     459             :         }
     460             : 
     461        1251 :         if ( fUseExtrapolatedPitch != 0 )
     462             :         {
     463         284 :             pt1_exc = buf; /*Q_exc*/
     464             :         }
     465        1251 :         tmp16 = add( sub( L_frame, imult1616( fLowPassFilter, Tc ) ), L_subfr );
     466      811324 :         FOR( i = 0; i < tmp16; i++ )
     467             :         {
     468      810073 :             *pt_exc++ = *pt1_exc++; /*Q_exc*/
     469      810073 :             move16();
     470             :         }
     471             : 
     472        1251 :         if ( fUseExtrapolatedPitch != 0 )
     473             :         {
     474         284 :             get_subframe_pitch( st->nb_subfr,
     475             :                                 st->old_fpitch,
     476             :                                 /* predPitchLag * L_frame/st->L_frame, */
     477             :                                 L_shr( Mpy_32_16_1( predPitchLag /*Q16*/,
     478         284 :                                                     mult_r( st->L_frame /*Q0*/,
     479         284 :                                                             getInvFrameLen( L_frame ) /*Q21*/
     480             :                                                             )                         /*Q6*/
     481             :                                                     ) /*Q7*/,
     482             :                                        7 - 16 ) /*Q16*/,
     483             :                                 pitch_buf );
     484             : 
     485         284 :             PulseResynchronization_fx( buf, exc, L_frame, st->nb_subfr, st->old_fpitchFB, predPitchLag );
     486             :         }
     487             :         ELSE
     488             :         {
     489         967 :             set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); /*Q16*/
     490             :         }
     491             : 
     492        1251 :         IF( EQ_16( st->nbLostCmpt, 1 ) )
     493             :         {
     494         771 :             pt_exc = exc + L_frame;
     495         771 :             IF( T0 == 0 )
     496             :             {
     497         235 :                 pt1_exc = pt_exc - Tc;
     498             :             }
     499             :             ELSE
     500             :             {
     501         536 :                 pt1_exc = pt_exc - T0;
     502             :             }
     503             : 
     504         771 :             tmp_loop = shr( L_frame, 1 );
     505      304131 :             FOR( i = 0; i < tmp_loop; i++ )
     506             :             {
     507      303360 :                 *pt_exc++ = *pt1_exc++; /*Q_exc*/
     508      303360 :                 move16();
     509             :             }
     510             :         }
     511             : 
     512        1251 :         if ( fUseExtrapolatedPitch != 0 )
     513             :         {
     514         284 :             st->old_fpitchFB = predPitchLag; /*Q16*/
     515         284 :             move32();
     516             :         }
     517        1251 :         st->bpf_gain_param = 0;
     518        1251 :         move16();
     519             : 
     520             :         /* PLC: calculate damping factor */
     521        1251 :         alpha = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac_fx, &( st->Mode2_lp_gainp ), 0 ); /*Q14*/
     522        1251 :         IF( EQ_16( st->nbLostCmpt, 1 ) )
     523             :         {
     524         771 :             st->cummulative_damping = 32767 /*1.f Q15*/;
     525         771 :             move16();
     526             :         }
     527             :         ELSE
     528             :         {
     529         480 :             st->cummulative_damping = shl_sat( mult_r_sat( st->cummulative_damping /*Q15*/, alpha /*Q14*/ ), 1 ) /*Q15*/;
     530         480 :             move16();
     531             :         }
     532             : 
     533        1251 :         gain32 = L_add( 2147483647l /*1.f Q31*/, 0 ); /*Q31*/
     534        1251 :         gain = 32767 /*1.f Q15*/;                     /*Q15*/
     535        1251 :         move16();
     536        1251 :         test();
     537        1251 :         IF( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) )
     538             :         {
     539           0 :             gain32 = 1073741824l /*0.5f Q31*/;
     540           0 :             move32();
     541           0 :             gain = 16384 /*0.5f Q15*/;
     542           0 :             move16();
     543             :         }
     544             : 
     545             :         /*step = (1.0f/(L_frame+(L_frame/2))) * (gain - alpha);*/
     546        1251 :         tmp16 = shr( imult1616( 3, L_frame ), 1 );
     547        1251 :         tmp_e = norm_s( tmp16 );
     548        1251 :         tmp16 = shl( tmp16, tmp_e );
     549        1251 :         tmp16 = div_s( 16384 /*1.f Q14*/, tmp16 ); /*Q15,1+tmp_e-15*/
     550        1251 :         tmp16_2 = sub( shr( gain, 1 ), alpha ) /*Q14*/;
     551        1251 :         step32 = L_shl( L_mult( tmp16, tmp16_2 ) /*Q30, 1+tmp_e-15*/, add( 1 - 14, tmp_e ) ) /*Q31*/;
     552             : 
     553             :         /* PLC: Apply fade out */
     554        1251 :         tmp_loop = shr( imult1616( L_frame, 3 ), 1 );
     555     1218531 :         FOR( i = offset; i < tmp_loop; i++ )
     556             :         {
     557     1217280 :             exc[i] = mult_r( exc[i], round_fx_sat( gain32 ) ) /*Q1*/;
     558     1217280 :             move16();
     559     1217280 :             gain32 = L_sub_sat( gain32, step32 ); /*Q31*/
     560             :         }
     561             : 
     562             :         /* update old exc without random part */
     563        1251 :         offset = s_max( sub( round_fx( st->old_fpitchFB ), shr( L_frame, 1 ) ), 0 );                   /*Q0*/
     564        1251 :         Copy( exc + sub( L_frame, offset ), hTcxDec->old_excFB_fx, add( shr( L_frame, 1 ), offset ) ); /*Q_exc*/
     565             :         /* copy old_exc as 16kHz for acelp decoding */
     566        1251 :         IF( EQ_16( st->nbLostCmpt, 1 ) )
     567             :         {
     568         771 :             lerp( exc - shr( L_frame, 1 ), st->old_exc_fx, L_EXC_MEM_DEC, add( L_frame, shr( L_frame, 1 ) ) );
     569             :         }
     570             :         ELSE
     571             :         {
     572         480 :             Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); /*Q_exc*/
     573         480 :             lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame );
     574             :         }
     575        1251 :         st->Q_exc = Q_exc;
     576        1251 :         move16();
     577             :     }
     578             :     ELSE
     579             :     {
     580             :         /* No harmonic part */
     581           0 :         set16_fx( &exc[0], 0, add( L_frame, shr( L_frame, 1 ) ) );
     582           0 :         IF( EQ_16( st->nbLostCmpt, 1 ) )
     583             :         {
     584           0 :             calcGainc2_fx( &exc[0], Q_exc, L_subfr, &( st->Mode2_lp_gainc ) );
     585             :         }
     586           0 :         set32_fx( pitch_buf, L_deposit_h( L_SUBFR ), st->nb_subfr );                                                              /*Q16*/
     587             :                                                                                                                                   /* PLC: calculate damping factor */
     588           0 :         alpha = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac_fx, &( st->Mode2_lp_gainp ), 0 ); /*Q14*/
     589             :     }
     590             : 
     591             :     /*-----------------------------------------------------------------*
     592             :      * Construct the random part of excitation
     593             :      *-----------------------------------------------------------------*/
     594             : 
     595             :     {
     596        1251 :         tmpSeed = st->seed_acelp;
     597        1251 :         move16();
     598        1251 :         noise = buf;
     599        1251 :         noise_e = 1; /*set exponent of noise to 1*/
     600        1251 :         move16();
     601             : 
     602        1251 :         tmp_loop = add( L_frame, L_FIR_FER2 - 1 );
     603      927681 :         FOR( i = 0; i < tmp_loop; i++ )
     604             :         {
     605      926430 :             Random( &tmpSeed );
     606      926430 :             noise[i] = shr( tmpSeed, noise_e ); /*Q: -noise_e*/
     607      926430 :             move16();
     608             :         }
     609        1251 :         st->seed_acelp = tmpSeed;
     610        1251 :         move16();
     611             : 
     612        1251 :         tmp_loop = add( add( L_frame, shr( L_frame, 1 ) ), shl( L_FIR_FER2, 1 ) );
     613      473223 :         FOR( ; i < tmp_loop; i++ )
     614             :         {
     615      471972 :             Random( &tmpSeed );
     616      471972 :             noise[i] = shr( tmpSeed, noise_e ); /*Q: -noise_e*/
     617      471972 :             move16();
     618             :         }
     619             :     }
     620        1251 :     test();
     621        1251 :     IF( EQ_16( st->last_good, VOICED_CLAS ) || EQ_16( st->last_good, ONSET ) )
     622             :     {
     623        1108 :         tmp16 = 19661 /*0.6f Q15*/;
     624        1108 :         move16();
     625        1108 :         if ( LE_32( st->output_Fs, 16000 ) )
     626             :         {
     627         207 :             tmp16 = 6554 /*0.2f Q15*/;
     628         207 :             move16();
     629             :         }
     630             : 
     631        1108 :         mem = noise[0];
     632        1108 :         move16();
     633        1108 :         preemph_copy_fx( &noise[1], &noise[1], tmp16, add( add( L_frame, shr( L_frame, 1 ) ), L_FIR_FER2 ), &mem );
     634             :     }
     635             :     /* high rate filter tuning */
     636        1251 :     IF( LE_32( st->output_Fs, 16000 ) )
     637             :     {
     638        3156 :         FOR( i = 0; i < L_FIR_FER2; i++ )
     639             :         {
     640        2893 :             hp_filt[i] = h_high3_16[i]; /*Q15*/
     641        2893 :             move16();
     642             :         }
     643             :     }
     644             :     ELSE /*(st->output_Fs==32000)*/
     645             :     {
     646       11856 :         FOR( i = 0; i < L_FIR_FER2; i++ )
     647             :         {
     648       10868 :             hp_filt[i] = h_high3_32[i]; /*Q15*/
     649       10868 :             move16();
     650             :         }
     651             :     }
     652        1251 :     IF( EQ_16( st->nbLostCmpt, 1 ) )
     653             :     {
     654         771 :         highPassFiltering_fx( st->last_good, add( add( L_frame, shr( L_frame, 1 ) ), L_FIR_FER2 ), noise, hp_filt, L_FIR_FER2 );
     655             :     }
     656             :     ELSE
     657             :     {
     658         480 :         IF( GT_16( st->last_good, UNVOICED_TRANSITION ) )
     659             :         {
     660         480 :             tmp_loop = add( add( L_frame, shr( L_frame, 1 ) ), L_FIR_FER2 );
     661         480 :             gain_tmp = negate( add( -32768, st->cummulative_damping ) ); /*Q15*/
     662      466560 :             FOR( i = 0; i < tmp_loop; i++ )
     663             :             {
     664             :                 Word16 j;
     665      466080 :                 L_tmp2 = 0;
     666      466080 :                 move32();
     667     5592960 :                 FOR( j = 11; j > 0; j-- )
     668             :                 {
     669     5126880 :                     L_tmp2 = L_mac( L_tmp2, noise[( i + sub( L_FIR_FER2, j ) )], hp_filt[( L_FIR_FER2 - j )] );
     670             :                 }
     671      466080 :                 L_tmp2 = Mpy_32_16_1( L_tmp2, st->cummulative_damping /*Q15*/ ); /*Q0, noise_e*/
     672      466080 :                 noise[i] = mac_r( L_tmp2, gain_tmp, noise[i] );                  /*Q15, noise_e*/
     673      466080 :                 move16();
     674             :             }
     675             :         }
     676             :     }
     677             : 
     678             :     /* PLC: [TCX: Fade-out] retrieve background level */
     679        1251 :     tmp16 = 32767;
     680        1251 :     move16();
     681        1251 :     gainSynthDeemph = getLevelSynDeemph_fx( &( tmp16 ), A_local, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ); /*Q5*/
     682        1251 :     IF( st->tcxonly != 0 )
     683             :     {
     684             :         /* gainCNG = st->conCngLevelBackgroundTrace/gainSynthDeemph; */
     685         283 :         BASOP_Util_Divide_MantExp( hTcxDec->conCngLevelBackgroundTrace,
     686         283 :                                    hTcxDec->conCngLevelBackgroundTrace_e,
     687             :                                    gainSynthDeemph, gainSynthDeemph_e,
     688             :                                    &gainCNG, &gainCNG_e );
     689             :     }
     690             :     ELSE
     691             :     {
     692             :         /* gainCNG = st->cngTDLevel/gainSynthDeemph; */
     693         968 :         BASOP_Util_Divide_MantExp( st->cngTDLevel,
     694         968 :                                    st->cngTDLevel_e,
     695             :                                    gainSynthDeemph, gainSynthDeemph_e,
     696             :                                    &gainCNG, &gainCNG_e );
     697             :     }
     698             : 
     699        1251 :     gain32 = L_add( st->Mode2_lp_gainc, 0 ); /* start-of-the-frame gain - Q16*/
     700        1251 :     test();
     701        1251 :     if ( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) )
     702             :     {
     703           0 :         gain32 = Mpy_32_16_1( gain32, 22938 /*0.7f Q15*/ ); /*Q16*/
     704             :     }
     705        1251 :     L_tmp = L_shl_sat( gain32, 1 ); /*Q16*/
     706        1251 :     IF( GT_32( L_shl( L_deposit_h( gainCNG ), sub( gainCNG_e, 31 - 16 ) /*Q16*/ ), L_tmp ) )
     707             :     {
     708          15 :         gainCNG_e = sub( 15 + 1, norm_l( L_tmp ) );
     709          15 :         gainCNG = extract_l( L_shr( L_tmp, gainCNG_e ) ); /*Q15,gainCNG_e*/
     710          15 :         gainCNG_e = sub( gainCNG_e, 1 );
     711             :     }
     712             : 
     713             :     /* st->Mode2_lp_gainc = alpha * (st->Mode2_lp_gainc) + (1.0f - alpha) * gainCNG;*/ /* end-of-the-frame gain */
     714             : 
     715        1251 :     L_tmp = Mpy_32_16_1( st->Mode2_lp_gainc, alpha ) /*Q15*/;
     716        1251 :     L_tmp2 = L_mult( sub( 16384 /*1.f Q14*/, alpha ) /*Q14*/, gainCNG /*Q15,gainCNG_e*/ );                      /*Q30,gainCNG_e*/
     717        1251 :     st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp( L_tmp, 31 - 15, L_tmp2, add( gainCNG_e, 31 - 30 ), &tmp_e ); /*Q31-tmp_e*/
     718        1251 :     st->Mode2_lp_gainc = L_shl( st->Mode2_lp_gainc, sub( tmp_e, 31 - 16 ) );                                    /*Q16*/
     719        1251 :     move32();
     720        1251 :     move32();
     721             : 
     722             :     /* PLC: [TCX: Fade-out] Linearly attenuate the gain through the frame */
     723             :     /*step = (1.0f/L_frame) * (gain - (st->Mode2_lp_gainc));*/
     724        1251 :     L_tmp = L_sub( gain32, st->Mode2_lp_gainc ); /*Q16*/
     725        1251 :     tmp_e = norm_l( L_tmp );
     726        1251 :     L_tmp = L_shl( L_tmp, tmp_e );                                                      /*Q16,-tmp_e*/
     727        1251 :     step32 = Mpy_32_16_1( L_tmp /*Q16,-tmp_e*/, getInvFrameLen( L_frame ) /*W16Q21*/ ); /*Q22,-tmp_e*/
     728        1251 :     step32 = L_shl( step32, sub( 25 - 22, tmp_e ) );                                    /*Q25*/
     729             : 
     730        1251 :     pt_exc = noise + L_FIR_FER2 / 2;
     731             : 
     732             :     /*gain_inov = 1.0f / (float)sqrt( dot_product( pt_exc, pt_exc, L_frame ) / L_frame + 0.01f );*/ /* normalize energy */
     733        1251 :     L_tmp = Dot_productSq16HQ( 0, pt_exc /*Q0,15+1*/, L_frame, &tmp_e ) /*Q31,tmp_e+16+16*/;
     734        1251 :     L_tmp = Mpy_32_16_1( L_tmp, getInvFrameLen( L_frame ) /*W16Q21*/ ) /*W32Q37,tmp_e+16+16*/ /*Q5,tmp_e*/;
     735        1251 :     tmp_e = add( tmp_e, 31 - 5 );                     /*-->Q31*/
     736        1251 :     gain_inov = round_fx( ISqrt32( L_tmp, &tmp_e ) ); /*Q15,tmp_e*/
     737        1251 :     gain_inov_e = tmp_e;
     738        1251 :     move16();
     739        1251 :     test();
     740        1251 :     test();
     741        1251 :     IF( EQ_16( st->last_good, UNVOICED_CLAS ) && NE_16( st->core_ext_mode, UNVOICED ) )
     742             :     {
     743           0 :         gain_inov = mult_r( gain_inov, 26214 /*0.8f Q15*/ ); /*Q30*/
     744             :     }
     745        1251 :     ELSE IF( !( EQ_16( st->last_good, UNVOICED_CLAS ) || EQ_16( st->last_good, UNVOICED_TRANSITION ) ) )
     746             :     {
     747             :         /*gain_inov *= (1.1f- 0.75*st->lp_gainp);*/
     748        1251 :         L_tmp = Mpy_32_16_1( L_sub( 590558016l /*1.1f Q29*/, Mpy_32_16_1( st->Mode2_lp_gainp, 24576 ) ) /*Q29*/, gain_inov /*Q15,gain_inov_e*/ ); /*Q29,gain_inov_e*/
     749        1251 :         tmp_e = norm_l( L_tmp );
     750        1251 :         L_tmp = L_shl( L_tmp, tmp_e );
     751        1251 :         gain_inov_e = add( sub( gain_inov_e, tmp_e ), 31 - 29 ); /*->Q31*/
     752        1251 :         gain_inov = round_fx_sat( L_tmp );                       /*Q15,gain_inov_e*/
     753             :     }
     754             : 
     755        1251 :     st->Mode2_lp_gainp = L_shr( L_deposit_h( alpha /*Q14*/ ) /*Q14+16*/, 1 ); /*Q29*/
     756        1251 :     move32();
     757        1251 :     pt_exc = noise; /* non-causal ringing of the FIR filter   */
     758             : 
     759        1251 :     tmp_e = norm_l( gain32 );
     760        1251 :     tmp_e = sub( tmp_e, 5 );         /*5 Bit additional Headroom for the gain - should be enough*/
     761        1251 :     gain32 = L_shl( gain32, tmp_e ); /*Q16,-tmp_e*/
     762        1251 :     L_tmp = Mpy_32_16_1( gain32 /*Q16,-tmp_e*/, gain_inov /*Q15,gain_inov_e*/ ) /*Q16,gain_inov_e-tmp_e*/;
     763             : 
     764        1251 :     gain_tmp = round_fx( L_tmp ); /*Q0, gain_inov_e-tmp_e*/
     765             : 
     766        7506 :     FOR( i = 0; i < L_FIR_FER2 / 2; i++ )
     767             :     {
     768        6255 :         *pt_exc = mult_r( *pt_exc, gain_tmp ); /*Q-15,noise_e+gain_inov_e-tmp_e*/
     769        6255 :         move16();
     770        6255 :         pt_exc++;
     771             :     }
     772        1251 :     tmp16 = add( L_frame, L_FIR_FER2 / 2 );
     773        1251 :     step32_tmp = L_shl( step32 /*Q25*/, sub( tmp_e, 25 - 16 ) ); /*Q16,-tmp_e*/
     774      921426 :     FOR( i = 0; i < tmp16; i++ )                                 /* Actual filtered random part of excitation */
     775             :     {
     776      920175 :         *pt_exc = mult_r( *pt_exc, gain_tmp ); /*Q-15,noise_e+gain_inov_e-tmp_e*/
     777      920175 :         move16();
     778      920175 :         pt_exc++;
     779      920175 :         gain32 = L_sub( gain32 /*Q16,-tmp_e*/, step32_tmp ); /*Q16,-tmp_e*/
     780      920175 :         gain_tmp = mult_r( round_fx( gain32 /*Q16,-tmp_e*/ ) /*Q0*/, gain_inov /*Q15,gain_inov_e*/ ) /*Q0,gain_inov_e-tmp_e*/;
     781             :     }
     782        1251 :     tmp16 = shr( L_frame, 1 );
     783      458211 :     FOR( i = 0; i < tmp16; i++ ) /* causal ringing of the FIR filter */
     784             :     {
     785      456960 :         *pt_exc = mult_r( *pt_exc, gain_tmp ); /*Q-15,noise_e+gain_inov_e-tmp_e*/
     786      456960 :         move16();
     787      456960 :         pt_exc++;
     788             :     }
     789        1251 :     noise_e = add( sub( add( noise_e, gain_inov_e ), tmp_e ), 15 ); /*--> noise is Q0, noise_e*/
     790             :     /*buf[0;L_FIR_FER2 + L_Frame + L_Frame/2] Q0, noise_e*/
     791             : 
     792             :     /*-----------------------------------------------------------------*
     793             :      * Construct the total excitation
     794             :      *-----------------------------------------------------------------*/
     795             : 
     796        1251 :     IF( GE_16( st->last_good, UNVOICED_TRANSITION ) )
     797             :     {
     798        1251 :         tmp16 = add( L_frame, shr( L_frame, 1 ) );
     799     1372131 :         FOR( i = 0; i < tmp16; i++ )
     800             :         {
     801     1370880 :             exc[i] = add_sat( exc[i], shl_sat( noise[i + ( L_FIR_FER2 / 2 )], add( Q_exc, noise_e ) ) ); /*Q1*/
     802     1370880 :             move16();
     803             :         }
     804             :     }
     805             :     ELSE
     806             :     {
     807           0 :         bufferCopyFx( noise + L_FIR_FER2 / 2, exc, add( L_frame, shr( L_frame, 1 ) ), 0 /*Q_noise*/, noise_e, Q_exc, 0 /*exc_e*/ );
     808           0 :         Copy( exc + sub( L_frame, shl( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl( L_subfr, 1 ), shr( L_frame, 1 ) ) ); /*Q_exc*/
     809             :         /* copy old_exc as 16kHz for acelp decoding */
     810           0 :         IF( EQ_16( st->nbLostCmpt, 1 ) )
     811             :         {
     812           0 :             lerp( exc, st->old_exc_fx, L_EXC_MEM_DEC, add( L_frame, shr( L_frame, 1 ) ) );
     813             :         }
     814             :         ELSE
     815             :         {
     816           0 :             Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); /*Q_exc*/
     817           0 :             lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame );
     818             :         }
     819           0 :         st->Q_exc = Q_exc;
     820           0 :         move16();
     821             :     }
     822             :     /*buf[0;L_FIR_FER2 + L_Frame + L_Frame/2] Q0, noise_e*/
     823             :     /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1*/
     824             : 
     825             :     /* Update Pitch Lag memory */
     826        1251 :     Copy32( &st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr ); /*Q16*/
     827        1251 :     Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr );            /*Q16*/
     828             : 
     829             :     /*----------------------------------------------------------*
     830             :      * - compute the synthesis speech                           *
     831             :      *----------------------------------------------------------*/
     832             : 
     833        1251 :     syn = buf + M;             /*Q_syn*/
     834        1251 :     Copy( synth - M, buf, M ); /*Q_syn*/
     835             : 
     836        1251 :     new_Q = sub( Q_exc, 3 );
     837        1251 :     new_Q = s_max( new_Q, -1 );
     838             : 
     839        1251 :     tmp16 = s_min( new_Q, st->prev_Q_syn );
     840        1251 :     st->prev_Q_syn = new_Q;
     841        1251 :     move16();
     842             : 
     843        1251 :     exp_scale = sub( tmp16, sub( Q_exc, 1 ) );
     844        1251 :     Q_syn = tmp16;
     845        1251 :     move16();
     846             : 
     847        1251 :     Copy_Scale_sig( buf, mem_syn, M, exp_scale ); /*Q: tmp16*/
     848             : 
     849        1251 :     tmp_deemph = shl_sat( tmp_deemph, Q_syn ); /*Q_syn*/
     850        1251 :     st->Q_syn = Q_syn;
     851        1251 :     move16();
     852             : 
     853             :     /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1: exc*/
     854             :     /*buf[0;M] Q0: mem_syn*/
     855        1251 :     E_UTIL_synthesis(
     856        1251 :         sub( Q_exc, Q_syn ),
     857             :         A_local,
     858             :         &exc[0],
     859             :         &syn[0],
     860        1251 :         add( L_frame, shr( L_frame, 1 ) ),
     861             :         mem_syn,
     862             :         1,
     863             :         M );
     864             : 
     865             :     /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame-1] Q1: exc*/
     866             :     /*buf[0;M-1] Q0: mem_syn*/
     867             :     /*buf[M;3/2 L_frame-1] Q-1: syn*/
     868             : 
     869        1251 :     n = extract_h( L_mult( L_frame, 9216 /*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/ ) ); /*q0*/
     870             : 
     871             :     /* update ACELP synthesis memory */
     872        1251 :     mem_syn_r_size_old = shr( L_frame, 4 ); /* replace 1.25/20.0 by shr(4) */
     873             :     /* copy mem_syn as 16kHz */
     874        1251 :     mem_syn_r_size_new = shr( L_FRAME16k, 4 ); /* replace 1.25/20.0 by shr(4) */
     875             : 
     876        1251 :     Copy( syn + sub( L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); /*Q_syn*/
     877        1251 :     lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old );
     878        1251 :     Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /*Q_syn*/
     879             : 
     880             :     /* Deemphasis and output synth and ZIR */
     881        1251 :     deemph_fx( syn, st->preemph_fac, add( L_frame, shr( L_frame, 1 ) ), &tmp_deemph );
     882        1251 :     bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); /*Q_syn*/
     883             : 
     884             : 
     885        1251 :     lerp( syn + sub( L_frame, shr( L_frame, 1 ) ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) );
     886        1251 :     st->hTcxDec->Q_old_syn_Overl = Q_syn;
     887        1251 :     move16();
     888        1251 :     Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); /*Q_syn*/
     889             : 
     890      201171 :     FOR( i = 0; i < W12; i++ )
     891             :     {
     892      199920 :         hHQ_core->old_out_fx[( i + n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[( i + n )] ) ); /*Q_syn*/
     893      199920 :         move16();
     894             :     }
     895      201171 :     FOR( ; i < W1; i++ )
     896             :     {
     897      199920 :         hHQ_core->old_out_fx[( i + n )] = round_fx( Mpy_32_16_1( L_mult( w[( ( W12 - 1 ) - ( i - W12 ) )].v.im, w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ), hHQ_core->old_out_fx[( i + n )] ) ); /*Q_syn*/
     898      199920 :         move16();
     899             :     }
     900             : 
     901        1251 :     set16_fx( &hHQ_core->old_out_fx[( W1 + n )], 0, n );
     902             : 
     903        1251 :     hHQ_core->Q_old_wtda = Q_syn;
     904        1251 :     move16();
     905             : 
     906             :     /* As long as there is no synth scaling factor introduced, which
     907             :     is given to the outside, there might occur overflows here */
     908             :     BASOP_SATURATE_WARNING_OFF_EVS
     909        1251 :     bufferCopyFx( syn, synth, L_frame, Q_syn, 0, 0, 0 ); /*Q_syn*/
     910             :     BASOP_SATURATE_WARNING_ON_EVS
     911             : 
     912        1251 :     Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), sub( 0, Q_syn ) ); /*Q0*/
     913        1251 :     hTcxDec->Q_syn_OverlFB = 0;
     914        1251 :     move16();
     915             : 
     916             :     /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */
     917        1251 :     IF( st->hWIDec != NULL )
     918             :     {
     919           0 :         lerp( exc, st->hWIDec->old_exc2_fx, L_EXC_MEM, L_frame );
     920           0 :         lerp( syn, st->hWIDec->old_syn2_fx, L_EXC_MEM, L_frame );
     921             :     }
     922             : 
     923        1251 :     st->bfi_pitch_fx /*Q6*/ = round_fx_sat( L_shl_sat( pitch_buf[( st->nb_subfr - 1 )] /*15Q16*/, 6 /*Q6*/ ) );
     924        1251 :     move16();
     925        1251 :     st->bfi_pitch_frame = st->L_frame;
     926        1251 :     move16();
     927             : 
     928             :     /* create aliasing and windowing need for transition to TCX10/5 */
     929        1251 :     bufferCopyFx( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ), Q_syn, 0, -1, 0 );
     930        1251 :     hTcxDec->Q_syn_Overl_TDACFB = add( st->Q_syn, sub( st->Q_syn, -1 ) );
     931        1251 :     move16();
     932             : 
     933      201171 :     FOR( i = 0; i < W12; i++ )
     934             :     {
     935      199920 :         buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); /*hTcxDec->Q_syn_Overl_TDACFB*/
     936      199920 :         move16();
     937             :     }
     938      201171 :     FOR( ; i < W1; i++ )
     939             :     {
     940      199920 :         buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ); /*hTcxDec->Q_syn_Overl_TDACFB*/
     941      199920 :         move16();
     942             :     }
     943             : 
     944             : 
     945      201171 :     FOR( i = 0; i < W2; i++ )
     946             :     {
     947      199920 :         hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[( ( W1 - 1 ) - i )] ); /*hTcxDec->Q_syn_Overl_TDACFB*/
     948      199920 :         move16();
     949             :     }
     950             : 
     951      201171 :     FOR( i = 0; i < W2; i++ )
     952             :     {
     953      199920 :         hTcxDec->syn_Overl_TDACFB[( W2 + i )] = add_sat( buf[( W2 + i )], buf[( ( ( W1 - 1 ) - W2 ) - i )] ); /*hTcxDec->Q_syn_Overl_TDACFB*/
     954      199920 :         move16();
     955             :     }
     956             : 
     957      201171 :     FOR( i = 0; i < W12; i++ )
     958             :     {
     959      199920 :         hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); /*hTcxDec->Q_syn_Overl_TDACFB*/
     960      199920 :         move16();
     961             :     }
     962      201171 :     FOR( ; i < W1; i++ )
     963             :     {
     964      199920 :         hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ); /*hTcxDec->Q_syn_Overl_TDACFB*/
     965      199920 :         move16();
     966             :     }
     967             : 
     968        1251 :     st->hTcxCfg->tcx_curr_overlap_mode = FULL_OVERLAP;
     969        1251 :     move16();
     970             : 
     971        1251 :     synth[-1] = pre_emph_buf; /*Q0*/
     972        1251 :     move16();
     973             : 
     974             :     /* update memory for low band */
     975        1251 :     Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); /*Q_syn*/
     976        1251 :     hTcxDec->Q_old_syn_Overl = -1;
     977        1251 :     move16();
     978        1251 :     lerp( hTcxDec->syn_OverlFB, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) );
     979        1251 :     hTcxDec->Q_syn_Overl = hTcxDec->Q_syn_OverlFB;
     980        1251 :     move16();
     981        1251 :     lerp( hTcxDec->syn_Overl_TDACFB, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), shr( L_frame, 1 ) );
     982        1251 :     hTcxDec->Q_syn_Overl_TDAC = hTcxDec->Q_syn_Overl_TDACFB;
     983        1251 :     move16();
     984        1251 :     lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, L_frame );
     985             : 
     986        1251 :     st->old_enr_LP = Enr_1_Az_fx( A_local, L_SUBFR ); /*Q3*/
     987        1251 :     move16();
     988             : 
     989        1251 :     return;
     990             : }
     991             : 
     992        3555 : void con_tcx_ivas_fx(
     993             :     Decoder_State *st, /* i/o: coder memory state            */
     994             :     Word16 synth[],
     995             :     /* i/o:   synth[]                     */ /*Q0 */
     996             :     const Word16 coh,                        /* i  : coherence of stereo signal  Q14*/
     997             :     Word16 *noise_seed,                      /* i/o: noise seed for stereo       Q0*/
     998             :     const Word16 only_left,                  /* i  : TD-PLC only in left channel Q0*/
     999             :     const Word16 *A_cng                      /* i  : CNG LP filter coefficients  Q14*/
    1000             : )
    1001             : {
    1002             :     Word16 i, s, c, L_frame, L_subfr, fLowPassFilter, T0;
    1003             :     Word16 n, mem_syn_r_size_old, mem_syn_r_size_new;
    1004             :     Word16 *noise;
    1005             :     Word16 mem_syn[M], *syn;
    1006             :     Word16 *exc, buf[OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2];
    1007             :     Word16 pre_emph_buf;
    1008             :     Word16 hp_filt[L_FIR_FER2];
    1009             :     Word16 alpha;
    1010             : #ifdef FIX_2003_CON_TCX_OVERFLOW
    1011             :     Word16 tmp_deemph, gain, gainCNG, gain_inov, scf;
    1012             : #else
    1013             :     Word16 tmp_deemph, gain, gainCNG, gain_inov;
    1014             : #endif
    1015             :     Word16 *pt_exc, *pt1_exc;
    1016             :     Word16 Tc, tmpSeed;
    1017             :     Word16 fUseExtrapolatedPitch;
    1018             :     Word16 *ana_window;
    1019             :     Word16 r_h[M + 1], A_local[M + 1], mem, r_l[M + 1];
    1020             :     PWord16 const *w;
    1021             :     Word16 W1, W2, W12;
    1022             :     Word16 Q_r;
    1023             :     Word16 tmp16, tmp16_2, tmp_loop, tmp_e, gain_tmp;
    1024             :     Word16 gainCNG_e, noise_e, gain_inov_e; /*Exponents for gainCNG, noise, gain_inov*/
    1025             :     Word16 Q_syn;                           /*Q format of temporary synthesis buffer syn*/
    1026             :     Word32 L_tmp, L_tmp2, step32_tmp;
    1027             :     Word32 predPitchLag, pitch_buf[NB_SUBFR16k], step32, gain32;
    1028             :     Word16 extrapolationFailed;
    1029             :     Word16 gainSynthDeemph;
    1030             :     Word16 gainSynthDeemph_e;
    1031             :     Word32 old_pitch_buf[2 * NB_SUBFR16k + 2];
    1032             :     Word16 Q_exc, new_Q, exp_scale;
    1033             :     Word16 offset;
    1034             :     HQ_DEC_HANDLE hHQ_core;
    1035             :     TCX_LTP_DEC_HANDLE hTcxLtpDec;
    1036             :     TCX_DEC_HANDLE hTcxDec;
    1037             : 
    1038        3555 :     hTcxLtpDec = st->hTcxLtpDec;
    1039        3555 :     hHQ_core = st->hHQ_core;
    1040        3555 :     hTcxDec = st->hTcxDec;
    1041             : 
    1042             :     /* inits */
    1043        3555 :     alpha = 0;
    1044        3555 :     move16();
    1045        3555 :     fUseExtrapolatedPitch = 0;
    1046        3555 :     move16();
    1047        3555 :     extrapolationFailed = 1;
    1048        3555 :     move16();
    1049             : 
    1050        3555 :     noise_e = 0;
    1051        3555 :     move16();
    1052        3555 :     Q_syn = -1; /*Q format of temporary synthesis buffer syn*/
    1053        3555 :     move16();
    1054        3555 :     offset = 0;
    1055        3555 :     move16();
    1056             : 
    1057             :     /* Framing parameters */
    1058        3555 :     L_frame = hTcxDec->L_frameTCX;
    1059        3555 :     move16();
    1060             :     /* L_subfr = st->L_frameTCX/st->nb_subfr */
    1061        3555 :     L_subfr = mult_r( hTcxDec->L_frameTCX, div_s( 1, st->nb_subfr ) ); /*Q0*/
    1062        3555 :     assert( L_subfr == hTcxDec->L_frameTCX / st->nb_subfr );
    1063        3555 :     w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument Q15*/
    1064        3555 :     W1 = st->hTcxCfg->tcx_mdct_window_lengthFB;
    1065        3555 :     move16();
    1066        3555 :     W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 );
    1067        3555 :     W12 = shr( W1, 1 );
    1068             : 
    1069             :     /* take the previous frame last pitch */
    1070        3555 :     Tc = round_fx( st->old_fpitchFB ); /*Q0*/
    1071             : 
    1072             : 
    1073        3555 :     set16_fx( buf, 0, OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2 ); /* initialize buf with 0 */
    1074             :     // set16_fx(buf,0,shr(sizeof(buf),1)); /* initialize buf with 0 */
    1075             : 
    1076        3555 :     c = BASOP_Util_Divide1616_Scale(
    1077             :         L_frame,
    1078        3555 :         st->L_frame,
    1079             :         &s );
    1080             : 
    1081       46215 :     FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ )
    1082             :     {
    1083       42660 :         old_pitch_buf[i] = L_shl( Mpy_32_16_1( st->old_pitch_buf_fx[i], c ), s ); /*Q16*/
    1084       42660 :         move32();
    1085             :     }
    1086             : 
    1087             :     /* set excitation memory*/
    1088        3555 :     exc = buf + OLD_EXC_SIZE_DEC;
    1089             : #ifdef FIX_2003_CON_TCX_OVERFLOW
    1090        3555 :     tmp_deemph = synth[-1]; /*st->Q_syn_factor*/
    1091        3555 :     move16();
    1092        3555 :     pre_emph_buf = synth[-1]; /*st->Q_syn_factor*/
    1093        3555 :     move16();
    1094             : #else
    1095             :     tmp_deemph = synth[-1]; /*Q0*/
    1096             :     move16();
    1097             :     pre_emph_buf = synth[-1];                                                         /*Q0*/
    1098             : #endif
    1099             : 
    1100        3555 :     test();
    1101        3555 :     IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc )
    1102             :     {
    1103             :         /* apply pre-emphasis to the signal */
    1104             : #ifdef FIX_2003_CON_TCX_OVERFLOW
    1105        1625 :         mem = shl( synth[( -( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) - 1 )], st->Q_syn_factor );
    1106             : #else
    1107             :         mem = synth[( -( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) - 1 )]; /*Q0*/
    1108             : #endif
    1109        1625 :         move16();
    1110        1625 :         Q_exc = E_UTIL_f_preemph3_ivas_fx( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 );
    1111             : 
    1112             : #ifdef FIX_2003_CON_TCX_OVERFLOW
    1113        1625 :         scale_sig( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */
    1114             : #endif
    1115             : 
    1116        1625 :         st->Mode2_lp_gainc = L_deposit_l( 0 );
    1117             : 
    1118        1625 :         st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) );
    1119        1625 :         move32();
    1120             : 
    1121        1625 :         st->Mode2_lp_gainp = L_max( st->Mode2_lp_gainp, 0 );                   /*Q16*/
    1122        1625 :         st->Mode2_lp_gainp = L_min( st->Mode2_lp_gainp, 65536l /*1.0f Q16*/ ); /*Q16*/
    1123        1625 :         st->Mode2_lp_gainp = L_shl( st->Mode2_lp_gainp, 13 );                  /*Q29*/
    1124        1625 :         move32();
    1125        1625 :         move32();
    1126        1625 :         move32();
    1127             : 
    1128        1625 :         ana_window = buf; /*Q15*/
    1129        1625 :         ham_cos_window( ana_window, mult( L_frame, 24576 /*0.75f Q15*/ ), shr( L_frame, 2 ) );
    1130             : 
    1131             :         /* Autocorrelation */
    1132        1625 :         autocorr_fx( &( synth[( -L_frame - 1 )] ), M, r_h, r_l, &Q_r, L_frame, ana_window, 0, 0 );
    1133             : 
    1134             :         /* Lag windowing */
    1135        1625 :         lag_wind( r_h, r_l, M, st->output_Fs, LAGW_STRONG );
    1136             : 
    1137             :         /* Levinson Durbin */
    1138        1625 :         E_LPC_lev_dur_ivas_fx( r_h, r_l, A_local, NULL, M, NULL );
    1139             : 
    1140             :         /* copy for multiple frame loss */
    1141        1625 :         Copy( A_local, st->old_Aq_12_8_fx, M + 1 ); /*Q14*/
    1142             : 
    1143             :         /* Residu */
    1144        1625 :         assert( ( 2 * L_subfr + Tc + 1 + M ) <= hTcxDec->old_synth_lenFB );
    1145             : 
    1146             :         BASOP_SATURATE_WARNING_OFF_EVS /*saturation possible in case of spiky synthesis*/
    1147        4875 :             Residu3_fx(
    1148             :                 A_local,
    1149        1625 :                 &( synth[-add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M )] ), /*Qx   = Q0*/
    1150        1625 :                 &( exc[-add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M )] ),   /*Qx+1 = Q1*/
    1151        1625 :                 add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M ),
    1152             :                 1 );
    1153             :         BASOP_SATURATE_WARNING_ON_EVS
    1154             :     }
    1155             :     ELSE
    1156             :     {
    1157             :         /* apply pre-emphasis to the signal */
    1158             : #ifdef FIX_2003_CON_TCX_OVERFLOW
    1159        1930 :         mem = shl( synth[( -L_frame - 1 )], st->Q_syn_factor ); /*hTcxDec->Q_synth_factor_old*/
    1160             : #else
    1161             :         mem = synth[( -L_frame - 1 )];                                                /*Q0*/
    1162             : #endif
    1163        1930 :         move16();
    1164        1930 :         Q_exc = E_UTIL_f_preemph3_ivas_fx( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 );
    1165             : #ifdef FIX_2003_CON_TCX_OVERFLOW
    1166        1930 :         scale_sig( &synth[-L_frame], L_frame, negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */
    1167             : #endif
    1168        1930 :         Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q14*/
    1169             : 
    1170        1930 :         offset = shr( L_frame, 1 );
    1171        1930 :         IF( GE_16( st->last_good, UNVOICED_TRANSITION ) )
    1172             :         {
    1173        1930 :             tmp16 = s_max( Tc - shr( L_frame, 1 ), 0 );
    1174        1930 :             Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), add( offset, tmp16 ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/
    1175             :         }
    1176             :         ELSE
    1177             :         {
    1178           0 :             Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-( L_subfr * 2 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/
    1179             :         }
    1180             :     }
    1181             : 
    1182             :     /*-----------------------------------------------------------------*
    1183             :      * PLC: Construct the harmonic part of excitation
    1184             :      *-----------------------------------------------------------------*/
    1185             : 
    1186        3555 :     test();
    1187        3555 :     test();
    1188        3555 :     IF( GT_16( st->last_good, UNVOICED_CLAS ) && !( EQ_16( st->last_good, UNVOICED_TRANSITION ) && EQ_16( st->core_ext_mode, GENERIC ) ) )
    1189             :     {
    1190        3555 :         test();
    1191        3555 :         IF( EQ_16( st->nbLostCmpt, 1 ) || hTcxDec->tcxConceal_recalc_exc )
    1192             :         {
    1193        1625 :             calcGainc_fx( exc, Q_exc, st->old_fpitchFB, L_subfr, st->Mode2_lp_gainp, &( st->Mode2_lp_gainc ) );
    1194             :         }
    1195             : 
    1196        3555 :         tmp16 = 0;
    1197        3555 :         move16();
    1198        3555 :         if ( GT_32( st->output_Fs, 25600 ) )
    1199             :         {
    1200        2517 :             tmp16 = 1;
    1201        2517 :             move16();
    1202             :         }
    1203             : 
    1204        3555 :         test();
    1205        3555 :         test();
    1206        3555 :         test();
    1207        3555 :         test();
    1208        3555 :         IF( ( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) && GE_16( st->rf_frame_type, RF_TCXFD ) && LE_16( st->rf_frame_type, RF_TCXTD2 ) && st->use_partial_copy )
    1209           0 :         {
    1210             :             Word32 tcxltp_pitch_tmp; /*15Q16*/
    1211             :             Word16 scale_tmp;        /*getInvFrameLen()->9Q6*/
    1212             :             Word16 tmp_shift;
    1213           0 :             tcxltp_pitch_tmp = L_add( L_deposit_h( hTcxLtpDec->tcxltp_pitch_int ), L_shl( L_deposit_l( div_s( hTcxLtpDec->tcxltp_pitch_fr, st->pit_res_max ) ), 1 ) ); /*15Q16*/
    1214           0 :             scale_tmp = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) );                                                                                  /*getInvFrameLen()->9Q6*/
    1215           0 :             tmp_shift = norm_s( scale_tmp );
    1216             : 
    1217           0 :             predPitchLag = L_shl( Mpy_32_16_1( tcxltp_pitch_tmp, shl( scale_tmp, tmp_shift ) ), sub( 9, tmp_shift ) ); /*Q16*/
    1218             : 
    1219           0 :             T0 = round_fx( predPitchLag ); /*Q0*/
    1220             : 
    1221           0 :             test();
    1222           0 :             test();
    1223           0 :             if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) )
    1224             :             {
    1225           0 :                 fUseExtrapolatedPitch = 1;
    1226           0 :                 move16();
    1227             :             }
    1228             :         }
    1229             :         ELSE
    1230             :         {
    1231             : 
    1232        3555 :             pitch_pred_linear_fit(
    1233        3555 :                 st->nbLostCmpt,
    1234        3555 :                 st->last_good,
    1235             :                 old_pitch_buf,
    1236             :                 &( st->old_fpitchFB ),
    1237             :                 &predPitchLag,
    1238        3555 :                 hTcxDec->pit_min_TCX,
    1239        3555 :                 hTcxDec->pit_max_TCX,
    1240        3555 :                 st->mem_pitch_gain,
    1241             :                 tmp16,
    1242        3555 :                 st->plc_use_future_lag,
    1243             :                 &extrapolationFailed,
    1244        3555 :                 st->nb_subfr );
    1245             : 
    1246        3555 :             T0 = round_fx( predPitchLag );
    1247        3555 :             test();
    1248        3555 :             test();
    1249        3555 :             test();
    1250        3555 :             if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) && ( extrapolationFailed == 0 ) )
    1251             :             {
    1252         685 :                 fUseExtrapolatedPitch = 1;
    1253         685 :                 move16();
    1254             :             }
    1255             :         }
    1256             : 
    1257             : 
    1258        3555 :         fLowPassFilter = 0;
    1259        3555 :         move16();
    1260        3555 :         pt_exc = exc + offset; /*Q_exc*/
    1261        3555 :         pt1_exc = pt_exc - Tc; /*Q_exc*/
    1262             : 
    1263        3555 :         if ( fUseExtrapolatedPitch != 0 )
    1264             :         {
    1265         685 :             pt_exc = buf; /*Q_exc*/
    1266             :         }
    1267        3555 :         test();
    1268        3555 :         IF( LT_16( st->stab_fac_fx, 32767 /*1.f Q15*/ ) && EQ_16( st->nbLostCmpt, 1 ) )
    1269             :         {
    1270             :             /* pitch cycle is first low-pass filtered */
    1271             : 
    1272         278 :             IF( LE_32( st->output_Fs, 16000 ) )
    1273             :             {
    1274        5259 :                 FOR( i = 0; i < Tc; i++ )
    1275             :                 {
    1276        5201 :                     *pt_exc++ = mac_r( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac(
    1277        5201 :                                                                                                    L_mult( 174 /* 0.0053f Q15*/, pt1_exc[-5] ),
    1278        5201 :                                                                                                    0 /* 0.0000f Q15*/, pt1_exc[-4] ),
    1279        5201 :                                                                                                -1442 /*-0.0440f Q15*/, pt1_exc[-3] ),
    1280        5201 :                                                                                         0 /* 0.0000f Q15*/, pt1_exc[-2] ),
    1281        5201 :                                                                                  8641 /* 0.2637f Q15*/, pt1_exc[-1] ),
    1282        5201 :                                                                           18022 /* 0.5500f Q15*/, pt1_exc[0] ),
    1283        5201 :                                                                    8641 /* 0.2637f Q15*/, pt1_exc[1] ),
    1284        5201 :                                                             0 /* 0.0000f Q15*/, pt1_exc[2] ),
    1285        5201 :                                                      -1442 /*-0.0440f Q15*/, pt1_exc[3] ),
    1286        5201 :                                               0 /* 0.0000f Q15*/, pt1_exc[4] ),
    1287        5201 :                                        174 /* 0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/
    1288        5201 :                     move16();
    1289        5201 :                     pt1_exc++;
    1290             :                 }
    1291             :             }
    1292             :             ELSE /*(st->output_Fs >= 32000)*/
    1293             :             {
    1294       57425 :                 FOR( i = 0; i < Tc; i++ )
    1295             :                 {
    1296       57205 :                     *pt_exc++ = mac_r( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac(
    1297       57205 :                                                                                                    L_mult( -174 /*-0.0053f Q15*/, pt1_exc[-5] ),
    1298       57205 :                                                                                                    -121 /*-0.0037f Q15*/, pt1_exc[-4] ),
    1299       57205 :                                                                                                -459 /*-0.0140f Q15*/, pt1_exc[-3] ),
    1300       57205 :                                                                                         590 /* 0.0180f Q15*/, pt1_exc[-2] ),
    1301       57205 :                                                                                  8743 /* 0.2668f Q15*/, pt1_exc[-1] ),
    1302       57205 :                                                                           16355 /* 0.4991f Q15*/, pt1_exc[0] ),
    1303       57205 :                                                                    8743 /* 0.2668f Q15*/, pt1_exc[1] ),
    1304       57205 :                                                             590 /* 0.0180f Q15*/, pt1_exc[2] ),
    1305       57205 :                                                      -459 /*-0.0140f Q15*/, pt1_exc[3] ),
    1306       57205 :                                               -121 /*-0.0037f Q15*/, pt1_exc[4] ),
    1307       57205 :                                        -174 /*-0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/
    1308       57205 :                     move16();
    1309       57205 :                     pt1_exc++;
    1310             :                 }
    1311             :             }
    1312             : 
    1313         278 :             fLowPassFilter = 1;
    1314         278 :             move16();
    1315             :         }
    1316             :         ELSE
    1317             :         {
    1318             :             /* copy the first pitch cycle without low-pass filtering */
    1319      752569 :             FOR( i = 0; i < Tc; i++ )
    1320             :             {
    1321      749292 :                 *pt_exc++ = *pt1_exc++; /*Q_exc*/
    1322      749292 :                 move16();
    1323             :             }
    1324        3277 :             fLowPassFilter = 1;
    1325        3277 :             move16();
    1326             :         }
    1327             : 
    1328        3555 :         if ( fUseExtrapolatedPitch != 0 )
    1329             :         {
    1330         685 :             pt1_exc = buf;
    1331             :         }
    1332        3555 :         tmp16 = add( sub( L_frame, imult1616( fLowPassFilter, Tc ) ), L_subfr );
    1333     2124017 :         FOR( i = 0; i < tmp16; i++ )
    1334             :         {
    1335     2120462 :             *pt_exc++ = *pt1_exc++; /*Q_exc*/
    1336     2120462 :             move16();
    1337             :         }
    1338             : 
    1339        3555 :         IF( fUseExtrapolatedPitch != 0 )
    1340             :         {
    1341         685 :             get_subframe_pitch( st->nb_subfr,
    1342             :                                 st->old_fpitch,
    1343             :                                 /* predPitchLag * L_frame/st->L_frame, */
    1344             :                                 L_shr( Mpy_32_16_1( predPitchLag /*Q16*/,
    1345         685 :                                                     mult_r( st->L_frame /*Q0*/,
    1346         685 :                                                             getInvFrameLen( L_frame ) /*Q21*/
    1347             :                                                             )                         /*Q6*/
    1348             :                                                     ) /*Q7*/,
    1349             :                                        7 - 16 ) /*Q16*/,
    1350             :                                 pitch_buf );
    1351             : 
    1352         685 :             PulseResynchronization_fx( buf, exc, L_frame, st->nb_subfr, st->old_fpitchFB, predPitchLag );
    1353             :         }
    1354             :         ELSE
    1355             :         {
    1356        2870 :             set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); /*Q16*/
    1357             :         }
    1358             : 
    1359        3555 :         IF( EQ_16( st->nbLostCmpt, 1 ) )
    1360             :         {
    1361        1625 :             pt_exc = exc + L_frame;
    1362        1625 :             IF( T0 == 0 )
    1363             :             {
    1364         486 :                 pt1_exc = pt_exc - Tc; /*Q_exc*/
    1365             :             }
    1366             :             ELSE
    1367             :             {
    1368        1139 :                 pt1_exc = pt_exc - T0; /*Q_exc*/
    1369             :             }
    1370             : 
    1371        1625 :             tmp_loop = shr( L_frame, 1 );
    1372      571225 :             FOR( i = 0; i < tmp_loop; i++ )
    1373             :             {
    1374      569600 :                 *pt_exc++ = *pt1_exc++; /*Q_exc*/
    1375      569600 :                 move16();
    1376             :             }
    1377             :         }
    1378             : 
    1379        3555 :         if ( fUseExtrapolatedPitch != 0 )
    1380             :         {
    1381         685 :             st->old_fpitchFB = predPitchLag; /*Q16*/
    1382         685 :             move32();
    1383             :         }
    1384        3555 :         st->bpf_gain_param = 0;
    1385        3555 :         move16();
    1386             : 
    1387             :         /* PLC: calculate damping factor */
    1388        3555 :         alpha = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac_fx, &( st->Mode2_lp_gainp ), 0 ); /*Q14*/
    1389        3555 :         IF( EQ_16( st->nbLostCmpt, 1 ) )
    1390             :         {
    1391        1625 :             st->cummulative_damping = 32767 /*1.f Q15*/;
    1392        1625 :             move16();
    1393             :         }
    1394             :         ELSE
    1395             :         {
    1396        1930 :             st->cummulative_damping = shl_sat( mult_r_sat( st->cummulative_damping /*Q15*/, alpha /*Q14*/ ), 1 ) /*Q15*/;
    1397        1930 :             move16();
    1398             :         }
    1399             : 
    1400        3555 :         gain32 = L_add( 2147483647l /*1.f Q31*/, 0 ); /*Q31*/
    1401        3555 :         gain = 32767 /*1.f Q15*/;                     /*Q15*/
    1402        3555 :         move16();
    1403        3555 :         test();
    1404        3555 :         IF( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) )
    1405             :         {
    1406           0 :             gain32 = 1073741824l /*0.5f Q31*/;
    1407           0 :             move32();
    1408           0 :             gain = 16384 /*0.5f Q15*/;
    1409           0 :             move16();
    1410             :         }
    1411             : 
    1412             :         /*step = (1.0f/(L_frame+(L_frame/2))) * (gain - alpha);*/
    1413        3555 :         tmp16 = shr( imult1616( 3, L_frame ), 1 );
    1414        3555 :         tmp_e = norm_s( tmp16 );
    1415        3555 :         tmp16 = shl( tmp16, tmp_e );
    1416        3555 :         tmp16 = div_s( 16384 /*1.f Q14*/, tmp16 ); /*Q15,1+tmp_e-15*/
    1417        3555 :         tmp16_2 = sub( shr( gain, 1 ), alpha ) /*Q14*/;
    1418        3555 :         step32 = L_shl( L_mult( tmp16, tmp16_2 ) /*Q30, 1+tmp_e-15*/, add( 1 - 14, tmp_e ) ) /*Q31*/;
    1419             : 
    1420             :         /* PLC: Apply fade out */
    1421        3555 :         tmp_loop = shr( imult1616( L_frame, 3 ), 1 );
    1422     2971235 :         FOR( i = offset; i < tmp_loop; i++ )
    1423             :         {
    1424     2967680 :             exc[i] = mult_r( exc[i], round_fx_sat( gain32 ) ) /*Q1*/;
    1425     2967680 :             move16();
    1426     2967680 :             gain32 = L_sub_sat( gain32, step32 ); /*Q31*/
    1427             :         }
    1428             : 
    1429             :         /* update old exc without random part */
    1430        3555 :         offset = s_max( sub( round_fx( st->old_fpitchFB ), shr( L_frame, 1 ) ), 0 );                   /*Q0*/
    1431        3555 :         Copy( exc + sub( L_frame, offset ), hTcxDec->old_excFB_fx, add( shr( L_frame, 1 ), offset ) ); /*Q_exc*/
    1432             :         /* copy old_exc as 16kHz for acelp decoding */
    1433        3555 :         IF( EQ_16( st->nbLostCmpt, 1 ) )
    1434             :         {
    1435        1625 :             lerp( exc - shr( L_frame, 1 ), st->old_exc_fx, L_EXC_MEM_DEC, add( L_frame, shr( L_frame, 1 ) ) );
    1436             :         }
    1437             :         ELSE
    1438             :         {
    1439        1930 :             Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); /*Q_exc*/
    1440        1930 :             lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame );
    1441             :         }
    1442        3555 :         st->Q_exc = Q_exc;
    1443        3555 :         move16();
    1444             :     }
    1445             :     ELSE
    1446             :     {
    1447             :         /* No harmonic part */
    1448           0 :         set16_fx( &exc[0], 0, add( L_frame, shr( L_frame, 1 ) ) );
    1449           0 :         IF( EQ_16( st->nbLostCmpt, 1 ) )
    1450             :         {
    1451           0 :             calcGainc2_fx( &exc[0], Q_exc, L_subfr, &( st->Mode2_lp_gainc ) );
    1452             :         }
    1453           0 :         set32_fx( pitch_buf, L_deposit_h( L_SUBFR ), st->nb_subfr );                                                              /*Q16*/
    1454             :                                                                                                                                   /* PLC: calculate damping factor */
    1455           0 :         alpha = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac_fx, &( st->Mode2_lp_gainp ), 0 ); /*Q14*/
    1456             :     }
    1457             : 
    1458             :     /*-----------------------------------------------------------------*
    1459             :      * Construct the random part of excitation
    1460             :      *-----------------------------------------------------------------*/
    1461             : 
    1462        3555 :     IF( NE_16( coh, -16384 ) )
    1463             :     {
    1464             :         Word16 tmpSeed1;
    1465             :         Word16 alpha_coh;
    1466             :         Word16 random1, random2;
    1467             :         Word16 e;
    1468             : 
    1469         912 :         tmpSeed1 = *noise_seed;
    1470         912 :         noise = buf; /*Q15*/
    1471         912 :         noise_e = 2;
    1472         912 :         move16();
    1473         912 :         e = 0;
    1474         912 :         move16();
    1475         912 :         alpha_coh = 0;
    1476         912 :         move16();
    1477             : 
    1478         912 :         IF( NE_16( coh, 16384 /*1.0f in Q14*/ ) )
    1479             :         {
    1480         912 :             alpha_coh = Sqrt16( div_s( sub( 16384 /*1.0f in Q14*/, coh ), add( 16384 /*1.0f in Q14*/, coh ) ), &e ); /* Q15 - e */
    1481             :         }
    1482         912 :         if ( EQ_16( st->idchan, 1 ) )
    1483             :         {
    1484         425 :             alpha_coh = negate( alpha_coh );
    1485             :         }
    1486             : 
    1487      600752 :         FOR( i = 0; i < L_frame + L_FIR_FER2 - 1; i++ )
    1488             :         {
    1489      599840 :             random1 = Random( &tmpSeed1 );
    1490      599840 :             random2 = Random( &tmpSeed1 );
    1491      599840 :             noise[i] = add( shr( random1, noise_e ), shr( mult( alpha_coh, random2 ), sub( noise_e, e ) ) );
    1492      599840 :             move16();
    1493             :         }
    1494             : 
    1495         912 :         test();
    1496         912 :         if ( EQ_16( st->idchan, 1 ) || only_left )
    1497             :         {
    1498         529 :             *noise_seed = tmpSeed1;
    1499         529 :             move16();
    1500             :         }
    1501             : 
    1502      307216 :         FOR( ; i < L_frame + ( L_frame / 2 ) + 2 * L_FIR_FER2; i++ )
    1503             :         {
    1504      306304 :             random1 = Random( &tmpSeed1 );
    1505      306304 :             random2 = Random( &tmpSeed1 );
    1506      306304 :             noise[i] = add( shr( random1, noise_e ), shr( mult( alpha_coh, random2 ), sub( noise_e, e ) ) );
    1507      306304 :             move16();
    1508             :         }
    1509             :     }
    1510             :     ELSE
    1511             :     {
    1512        2643 :         tmpSeed = st->seed_acelp; /*Q0*/
    1513        2643 :         move16();
    1514        2643 :         noise = buf;
    1515        2643 :         noise_e = 1; /*set exponent of noise to 1*/
    1516        2643 :         move16();
    1517             : 
    1518        2643 :         tmp_loop = add( L_frame, L_FIR_FER2 - 1 );
    1519     1836433 :         FOR( i = 0; i < tmp_loop; i++ )
    1520             :         {
    1521     1833790 :             Random( &tmpSeed );
    1522     1833790 :             noise[i] = shr( tmpSeed, noise_e ); /*Q: -noise_e*/
    1523     1833790 :             move16();
    1524             :         }
    1525        2643 :         st->seed_acelp = tmpSeed;
    1526        2643 :         move16();
    1527             : 
    1528        2643 :         tmp_loop = add( add( L_frame, shr( L_frame, 1 ) ), shl( L_FIR_FER2, 1 ) );
    1529      938039 :         FOR( ; i < tmp_loop; i++ )
    1530             :         {
    1531      935396 :             Random( &tmpSeed );
    1532      935396 :             noise[i] = shr( tmpSeed, noise_e ); /*Q: -noise_e*/
    1533      935396 :             move16();
    1534             :         }
    1535             :     }
    1536        3555 :     test();
    1537        3555 :     IF( EQ_16( st->last_good, VOICED_CLAS ) || EQ_16( st->last_good, ONSET ) )
    1538             :     {
    1539        3537 :         tmp16 = 19661 /*0.6f Q15*/;
    1540        3537 :         move16();
    1541        3537 :         if ( LE_32( st->output_Fs, 16000 ) )
    1542             :         {
    1543        1034 :             tmp16 = 6554 /*0.2f Q15*/;
    1544        1034 :             move16();
    1545             :         }
    1546             : 
    1547        3537 :         mem = noise[0];
    1548        3537 :         move16();
    1549        3537 :         preemph_copy_fx( &noise[1], &noise[1], tmp16, add( add( L_frame, shr( L_frame, 1 ) ), L_FIR_FER2 ), &mem );
    1550             :     }
    1551             :     /* high rate filter tuning */
    1552        3555 :     IF( LE_32( st->output_Fs, 16000 ) )
    1553             :     {
    1554       12456 :         FOR( i = 0; i < L_FIR_FER2; i++ )
    1555             :         {
    1556       11418 :             hp_filt[i] = h_high3_16[i]; /*Q15*/
    1557       11418 :             move16();
    1558             :         }
    1559             :     }
    1560             :     ELSE /*(st->output_Fs==32000)*/
    1561             :     {
    1562       30204 :         FOR( i = 0; i < L_FIR_FER2; i++ )
    1563             :         {
    1564       27687 :             hp_filt[i] = h_high3_32[i]; /*Q15*/
    1565       27687 :             move16();
    1566             :         }
    1567             :     }
    1568        3555 :     IF( EQ_16( st->nbLostCmpt, 1 ) )
    1569             :     {
    1570        1625 :         highPassFiltering_fx( st->last_good, add( add( L_frame, shr( L_frame, 1 ) ), L_FIR_FER2 ), noise, hp_filt, L_FIR_FER2 );
    1571             :     }
    1572             :     ELSE
    1573             :     {
    1574        1930 :         IF( GT_16( st->last_good, UNVOICED_TRANSITION ) )
    1575             :         {
    1576        1930 :             tmp_loop = add( add( L_frame, shr( L_frame, 1 ) ), L_FIR_FER2 );
    1577        1930 :             gain_tmp = negate( add( -32768, st->cummulative_damping ) ); /*Q15*/
    1578     1911480 :             FOR( i = 0; i < tmp_loop; i++ )
    1579             :             {
    1580             :                 Word16 j;
    1581     1909550 :                 L_tmp2 = 0;
    1582     1909550 :                 move32();
    1583    22914600 :                 FOR( j = 11; j > 0; j-- )
    1584             :                 {
    1585    21005050 :                     L_tmp2 = L_mac( L_tmp2, noise[( i + ( L_FIR_FER2 - j ) )], hp_filt[sub( L_FIR_FER2, j )] );
    1586             :                 }
    1587     1909550 :                 L_tmp2 = Mpy_32_16_1( L_tmp2, st->cummulative_damping /*Q15*/ ); /*Q0, noise_e*/
    1588     1909550 :                 noise[i] = mac_r( L_tmp2, gain_tmp, noise[i] );                  /*Q15, noise_e*/
    1589     1909550 :                 move16();
    1590             :             }
    1591             :         }
    1592             :     }
    1593             : 
    1594             :     /* PLC: [TCX: Fade-out] retrieve background level */
    1595        3555 :     tmp16 = 32767;
    1596        3555 :     move16();
    1597        3555 :     IF( A_cng != NULL )
    1598             :     {
    1599         912 :         gainSynthDeemph = shr( getLevelSynDeemph_fx( &( tmp16 ), A_cng, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ), 2 ); /*Q13*/
    1600             :     }
    1601             :     ELSE
    1602             :     {
    1603        2643 :         gainSynthDeemph = getLevelSynDeemph_fx( &( tmp16 ), A_local, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ); /*Q13*/
    1604             :     }
    1605        3555 :     IF( st->tcxonly != 0 )
    1606             :     {
    1607             :         /* gainCNG = st->conCngLevelBackgroundTrace/gainSynthDeemph; */
    1608        3555 :         BASOP_Util_Divide_MantExp( hTcxDec->conCngLevelBackgroundTrace,
    1609        3555 :                                    hTcxDec->conCngLevelBackgroundTrace_e,
    1610             :                                    gainSynthDeemph, gainSynthDeemph_e,
    1611             :                                    &gainCNG, &gainCNG_e );
    1612        3555 :         test();
    1613        3555 :         IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && A_cng != NULL )
    1614             :         {
    1615         912 :             IF( GT_16( st->nbLostCmpt, add( MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME, MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN ) ) )
    1616             :             {
    1617           0 :                 gainCNG = 0;
    1618           0 :                 move16();
    1619             :             }
    1620         912 :             ELSE IF( GT_16( st->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) )
    1621             :             {
    1622             :                 // gainCNG *= 1.f - (float)(st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME) / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN;
    1623           0 :                 L_tmp = L_sub( ONE_IN_Q31, imult3216( 107374182 /* 1 / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN in Q31*/, sub( st->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) ) ); /* Q31 */
    1624           0 :                 gainCNG = extract_l( Mpy_32_32( gainCNG, L_tmp ) );                                                                                                             /*Q15-gainCNG_e*/
    1625             :             }
    1626             :         }
    1627             :     }
    1628             :     ELSE
    1629             :     {
    1630             :         /* gainCNG = st->cngTDLevel/gainSynthDeemph; */
    1631           0 :         BASOP_Util_Divide_MantExp( st->cngTDLevel,
    1632           0 :                                    st->cngTDLevel_e,
    1633             :                                    gainSynthDeemph, gainSynthDeemph_e,
    1634             :                                    &gainCNG, &gainCNG_e );
    1635             :     }
    1636             : 
    1637        3555 :     gain32 = L_add( st->Mode2_lp_gainc, 0 ); /* start-of-the-frame gain - Q16*/
    1638        3555 :     IF( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) )
    1639             :     {
    1640           0 :         gain32 = Mpy_32_16_1( gain32, 22938 /*0.7f Q15*/ ); /*Q16*/
    1641             :     }
    1642        3555 :     L_tmp = L_shl( gain32, 1 ); /*Q16*/
    1643             : 
    1644        3555 :     IF( GT_32( L_shl( L_deposit_h( gainCNG ), sub( gainCNG_e, 31 - 16 ) /*Q16*/ ), L_tmp ) )
    1645             :     {
    1646           0 :         gainCNG_e = sub( 15 + 1, norm_l( L_tmp ) );
    1647           0 :         gainCNG = extract_l( L_shr( L_tmp, gainCNG_e ) ); /*Q15,gainCNG_e*/
    1648           0 :         gainCNG_e = sub( gainCNG_e, 1 );
    1649             :     }
    1650             : 
    1651             :     /* st->Mode2_lp_gainc = alpha * (st->Mode2_lp_gainc) + (1.0f - alpha) * gainCNG;*/ /* end-of-the-frame gain */
    1652             : 
    1653        3555 :     L_tmp = Mpy_32_16_1( st->Mode2_lp_gainc, alpha ) /*Q15*/;
    1654        3555 :     L_tmp2 = L_mult( sub( 16384 /*1.f Q14*/, alpha ) /*Q14*/, gainCNG /*Q15,gainCNG_e*/ );                      /*Q30,gainCNG_e*/
    1655        3555 :     st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp( L_tmp, 31 - 15, L_tmp2, add( gainCNG_e, 31 - 30 ), &tmp_e ); /*Q31-tmp_e*/
    1656        3555 :     st->Mode2_lp_gainc = L_shl( st->Mode2_lp_gainc, sub( tmp_e, 31 - 16 ) );                                    /*Q16*/
    1657        3555 :     move32();
    1658        3555 :     move32();
    1659             : 
    1660             :     /* PLC: [TCX: Fade-out] Linearly attenuate the gain through the frame */
    1661             :     /*step = (1.0f/L_frame) * (gain - (st->Mode2_lp_gainc));*/
    1662        3555 :     L_tmp = L_sub( gain32, st->Mode2_lp_gainc ); /*Q16*/
    1663        3555 :     tmp_e = norm_l( L_tmp );
    1664        3555 :     L_tmp = L_shl( L_tmp, tmp_e );                                                      /*Q16,-tmp_e*/
    1665        3555 :     step32 = Mpy_32_16_1( L_tmp /*Q16,-tmp_e*/, getInvFrameLen( L_frame ) /*W16Q21*/ ); /*Q22,-tmp_e*/
    1666        3555 :     step32 = L_shl( step32, sub( 25 - 22, tmp_e ) );                                    /*Q25*/
    1667             : 
    1668        3555 :     pt_exc = noise + shr( L_FIR_FER2, 1 );
    1669             : 
    1670             :     /*gain_inov = 1.0f / (float)sqrt( dot_product( pt_exc, pt_exc, L_frame ) / L_frame + 0.01f );*/ /* normalize energy */
    1671        3555 :     L_tmp = Dot_productSq16HQ( 0, pt_exc /*Q0,15+1*/, L_frame, &tmp_e ) /*Q31,tmp_e+16+16*/;
    1672        3555 :     tmp_e = sub( add( tmp_e, shl( noise_e, 1 ) ), 1 ); // actual multiplier!
    1673        3555 :     L_tmp = Mpy_32_16_1( L_tmp, getInvFrameLen( L_frame ) /*W16Q21*/ ) /*W32Q37,tmp_e+16+16*/ /*Q5,tmp_e*/;
    1674        3555 :     tmp_e = add( tmp_e, 31 - 6 ); /*-->Q31*/
    1675        3555 :     gain_inov = 0;
    1676        3555 :     move16();
    1677        3555 :     gain_inov_e = 0;
    1678        3555 :     move16();
    1679        3555 :     IF( NE_32( L_tmp, 0 ) )
    1680             :     {
    1681        3555 :         gain_inov = round_fx( ISqrt32( L_tmp, &tmp_e ) ); /*Q15,tmp_e*/
    1682        3555 :         gain_inov_e = tmp_e;
    1683        3555 :         move16();
    1684             :     }
    1685        3555 :     test();
    1686        3555 :     test();
    1687        3555 :     IF( EQ_16( st->last_good, UNVOICED_CLAS ) && NE_16( st->core_ext_mode, UNVOICED ) )
    1688             :     {
    1689           0 :         gain_inov = mult_r( gain_inov, 26214 /*0.8f Q15*/ ); /*Q30*/
    1690             :     }
    1691        3555 :     ELSE IF( !( EQ_16( st->last_good, UNVOICED_CLAS ) || EQ_16( st->last_good, UNVOICED_TRANSITION ) ) )
    1692             :     {
    1693             :         /*gain_inov *= (1.1f- 0.75*st->lp_gainp);*/
    1694        3555 :         L_tmp = Mpy_32_16_1( L_sub( 590558016l /*1.1f Q29*/, Mpy_32_16_1( st->Mode2_lp_gainp, 24576 ) ) /*Q29*/, gain_inov /*Q15,gain_inov_e*/ ); /*Q29,gain_inov_e*/
    1695        3555 :         tmp_e = norm_l( L_tmp );
    1696        3555 :         L_tmp = L_shl( L_tmp, tmp_e );
    1697        3555 :         gain_inov_e = add( sub( gain_inov_e, tmp_e ), 31 - 29 ); /*->Q31*/
    1698        3555 :         gain_inov = round_fx_sat( L_tmp );                       /*Q15,gain_inov_e*/
    1699             :     }
    1700             : 
    1701        3555 :     st->Mode2_lp_gainp = L_shr( L_deposit_h( alpha /*Q14*/ ) /*Q14+16*/, 1 ); /*Q29*/
    1702        3555 :     move32();
    1703             : 
    1704        3555 :     pt_exc = noise; /* non-causal ringing of the FIR filter   */
    1705             : 
    1706        3555 :     tmp_e = norm_l( gain32 );
    1707        3555 :     tmp_e = sub( tmp_e, 5 );         /*5 Bit additional Headroom for the gain - should be enough*/
    1708        3555 :     gain32 = L_shl( gain32, tmp_e ); /*Q16,-tmp_e*/
    1709        3555 :     L_tmp = Mpy_32_16_1( gain32 /*Q16,-tmp_e*/, gain_inov /*Q15,gain_inov_e*/ ) /*Q16,gain_inov_e-tmp_e*/;
    1710             : 
    1711        3555 :     gain_tmp = round_fx( L_tmp ); /*Q0, gain_inov_e-tmp_e*/
    1712             : 
    1713       21330 :     FOR( i = 0; i < L_FIR_FER2 / 2; i++ )
    1714             :     {
    1715       17775 :         *pt_exc = mult_r( *pt_exc, gain_tmp ); /*Q-15,noise_e+gain_inov_e-tmp_e*/
    1716       17775 :         move16();
    1717       17775 :         pt_exc++;
    1718             :     }
    1719        3555 :     tmp16 = add( L_frame, L_FIR_FER2 / 2 );
    1720        3555 :     step32_tmp = L_shl( step32 /*Q25*/, sub( tmp_e, 25 - 16 ) ); /*Q16,-tmp_e*/
    1721     2419410 :     FOR( i = 0; i < tmp16; i++ )                                 /* Actual filtered random part of excitation */
    1722             :     {
    1723     2415855 :         *pt_exc = mult_r( *pt_exc, gain_tmp ); /*Q-15,noise_e+gain_inov_e-tmp_e*/
    1724     2415855 :         move16();
    1725     2415855 :         pt_exc++;
    1726     2415855 :         gain32 = L_sub( gain32 /*Q16,-tmp_e*/, step32_tmp ); /*Q16,-tmp_e*/
    1727     2415855 :         gain_tmp = mult_r( round_fx( gain32 /*Q16,-tmp_e*/ ) /*Q0*/, gain_inov /*Q15,gain_inov_e*/ ) /*Q0,gain_inov_e-tmp_e*/;
    1728             :     }
    1729        3555 :     tmp16 = shr( L_frame, 1 );
    1730     1202595 :     FOR( i = 0; i < tmp16; i++ ) /* causal ringing of the FIR filter */
    1731             :     {
    1732     1199040 :         *pt_exc = mult_r( *pt_exc, gain_tmp ); /*Q-15,noise_e+gain_inov_e-tmp_e*/
    1733     1199040 :         move16();
    1734     1199040 :         pt_exc++;
    1735             :     }
    1736        3555 :     noise_e = add( sub( add( noise_e, gain_inov_e ), tmp_e ), 15 ); /*--> noise is Q0, noise_e*/
    1737             :     /*buf[0;L_FIR_FER2 + L_Frame + L_Frame/2] Q0, noise_e*/
    1738             : 
    1739             :     /*-----------------------------------------------------------------*
    1740             :      * Construct the total excitation
    1741             :      *-----------------------------------------------------------------*/
    1742             : 
    1743        3555 :     IF( GE_16( st->last_good, UNVOICED_TRANSITION ) )
    1744             :     {
    1745        3555 :         tmp16 = add( L_frame, shr( L_frame, 1 ) );
    1746     3600675 :         FOR( i = 0; i < tmp16; i++ )
    1747             :         {
    1748     3597120 :             exc[i] = add_sat( exc[i], shl_sat( noise[i + ( L_FIR_FER2 / 2 )], add( Q_exc, noise_e ) ) ); /*Q1*/
    1749     3597120 :             move16();
    1750             :         }
    1751             :     }
    1752             :     ELSE
    1753             :     {
    1754           0 :         bufferCopyFx( noise + L_FIR_FER2 / 2, exc, add( L_frame, shr( L_frame, 1 ) ), 0 /*Q_noise*/, noise_e, Q_exc, 0 /*exc_e*/ );
    1755           0 :         Copy( exc + sub( L_frame, shl( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl( L_subfr, 1 ), shr( L_frame, 1 ) ) ); /*Q_exc*/
    1756             :         /* copy old_exc as 16kHz for acelp decoding */
    1757           0 :         IF( EQ_16( st->nbLostCmpt, 1 ) )
    1758             :         {
    1759           0 :             lerp( exc, st->old_exc_fx, L_EXC_MEM_DEC, add( L_frame, shr( L_frame, 1 ) ) );
    1760             :         }
    1761             :         ELSE
    1762             :         {
    1763           0 :             Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); /*Q_exc*/
    1764           0 :             lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame );
    1765             :         }
    1766           0 :         st->Q_exc = Q_exc;
    1767           0 :         move16();
    1768             :     }
    1769             :     /*buf[0;L_FIR_FER2 + L_Frame + L_Frame/2] Q0, noise_e*/
    1770             :     /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1*/
    1771             : 
    1772             :     /* Update Pitch Lag memory */
    1773        3555 :     Copy32( &st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr ); /*Q16*/
    1774        3555 :     Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr );            /*Q16*/
    1775             : 
    1776             :     /*----------------------------------------------------------*
    1777             :      * - compute the synthesis speech                           *
    1778             :      *----------------------------------------------------------*/
    1779             : 
    1780        3555 :     syn = buf + M;             /*Q_syn*/
    1781        3555 :     Copy( synth - M, buf, M ); /*Q_syn*/
    1782             : 
    1783             : #ifdef FIX_2003_CON_TCX_OVERFLOW
    1784        3555 :     scf = norm_s( tmp_deemph );
    1785        3555 :     new_Q = sub( Q_exc, 4 ); // deemph_fx filter gain can be up to 10 (~2^3.32), so 4 bits of headroom are needed to avoid overflow
    1786             : #else
    1787             :     new_Q = sub( Q_exc, 3 );
    1788             : #endif
    1789        3555 :     new_Q = s_max( new_Q, -1 );
    1790             : #ifdef FIX_2003_CON_TCX_OVERFLOW
    1791        3555 :     new_Q = s_min( new_Q, scf );
    1792             : #else
    1793             :     new_Q = s_min( new_Q, norm_s( tmp_deemph ) );
    1794             : #endif
    1795             : 
    1796        3555 :     tmp16 = s_min( new_Q, st->prev_Q_syn );
    1797        3555 :     st->prev_Q_syn = new_Q;
    1798        3555 :     move16();
    1799             : 
    1800        3555 :     exp_scale = sub( tmp16, sub( Q_exc, 1 ) );
    1801        3555 :     Q_syn = tmp16;
    1802        3555 :     move16();
    1803             : 
    1804        3555 :     Copy_Scale_sig( buf, mem_syn, M, exp_scale ); /* Q: tmp16 */
    1805             : #ifdef FIX_2003_CON_TCX_OVERFLOW
    1806        3555 :     if ( GT_16( sub( Q_syn, st->Q_syn_factor ), scf ) )
    1807             :     {
    1808           0 :         Q_syn = add( scf, st->Q_syn_factor ); // so that (Q_syn - st->Q_syn_factor) = scf;
    1809             :     }
    1810        3555 :     tmp_deemph = shl( tmp_deemph, sub( Q_syn, st->Q_syn_factor ) );
    1811             : #else
    1812             :     tmp_deemph = shl_sat( tmp_deemph, Q_syn );
    1813             : #endif
    1814        3555 :     st->Q_syn = Q_syn;
    1815        3555 :     move16();
    1816             : 
    1817             :     /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1: exc*/
    1818             :     /*buf[0;M] Q0: mem_syn*/
    1819        3555 :     IF( A_cng != NULL )
    1820             :     {
    1821             :         Word16 alpha_delayed;
    1822             : 
    1823         912 :         alpha_delayed = 16384; /*1.0f in Q14*/
    1824         912 :         move16();
    1825         912 :         IF( GT_16( st->nbLostCmpt, MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE ) )
    1826             :         {
    1827         294 :             alpha_delayed = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE, st->last_good, st->stab_fac_fx, &( st->Mode2_lp_gainp ), ACELP_CORE ); /*Q14*/
    1828             :         }
    1829             : 
    1830         912 :         test();
    1831         912 :         IF( st->plcBackgroundNoiseUpdated && NE_16( alpha_delayed, 16384 ) )
    1832             :         {
    1833             :             Word16 lsp_local[M], lsp_fade[M], alpha_inv;
    1834             : 
    1835           0 :             alpha_inv = sub( 16384 /*Q.0f in Q14*/, alpha_delayed ); /*Q14*/
    1836             : 
    1837           0 :             E_LPC_a_lsp_conversion( A_local, lsp_local, st->lspold_cng, M );
    1838             : 
    1839           0 :             FOR( i = 0; i < M; i++ )
    1840             :             {
    1841           0 :                 lsp_fade[i] = add( mult_r( alpha_delayed, lsp_local[i] ), mult_r( alpha_inv, st->lspold_cng[i] ) ); /*Q14*/
    1842           0 :                 move16();
    1843             :             }
    1844             : 
    1845           0 :             Scale_sig( lsp_fade, M, 1 ); /* Q14 -> Q15 */
    1846             : 
    1847           0 :             E_LPC_f_lsp_a_conversion( lsp_fade, A_local, M );
    1848             :         }
    1849             :     }
    1850             : 
    1851        3555 :     E_UTIL_synthesis(
    1852        3555 :         sub( Q_exc, Q_syn ),
    1853             :         A_local,
    1854             :         &exc[0],
    1855             :         &syn[0],
    1856        3555 :         add( L_frame, shr( L_frame, 1 ) ),
    1857             :         mem_syn,
    1858             :         1,
    1859             :         M );
    1860             : 
    1861             :     /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame-1] Q1: exc*/
    1862             :     /*buf[0;M-1] Q0: mem_syn*/
    1863             :     /*buf[M;3/2 L_frame-1] Q-1: syn*/
    1864             : 
    1865        3555 :     n = extract_h( L_mult( L_frame, 9216 /*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/ ) ); /*Q0*/
    1866             : 
    1867             :     /* update ACELP synthesis memory */
    1868        3555 :     mem_syn_r_size_old = shr( L_frame, 4 ); /* replace 1.25/20.0 by shr(4) */
    1869             :     /* copy mem_syn as 16kHz */
    1870        3555 :     mem_syn_r_size_new = shr( L_FRAME16k, 4 ); /* replace 1.25/20.0 by shr(4) */
    1871             : 
    1872        3555 :     Copy( syn + sub( L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); /*Q_syn*/
    1873        3555 :     lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old );
    1874        3555 :     Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /*Q_syn*/
    1875             : 
    1876             :     /* Deemphasis and output synth and ZIR */
    1877        3555 :     deemph_fx( syn, st->preemph_fac, add( L_frame, shr( L_frame, 1 ) ), &tmp_deemph );
    1878             : #ifndef FIX_2003_CON_TCX_OVERFLOW
    1879             :     bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); /*Q_syn*/
    1880             : #endif
    1881             : 
    1882        3555 :     lerp( syn + sub( L_frame, shr( L_frame, 1 ) ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) );
    1883        3555 :     hTcxDec->Q_old_syn_Overl = Q_syn;
    1884        3555 :     move16();
    1885        3555 :     Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); /*Q_syn*/
    1886             : 
    1887      528135 :     FOR( i = 0; i < W12; i++ )
    1888             :     {
    1889      524580 :         hHQ_core->old_out_fx[( i + n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[( i + n )] ) ); /*Q_syn*/
    1890      524580 :         move16();
    1891             :     }
    1892      528135 :     FOR( ; i < W1; i++ )
    1893             :     {
    1894      524580 :         hHQ_core->old_out_fx[( i + n )] = round_fx( Mpy_32_16_1( L_mult( w[( ( W12 - 1 ) - ( i - W12 ) )].v.im, w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ), hHQ_core->old_out_fx[( i + n )] ) ); /*Q_syn*/
    1895      524580 :         move16();
    1896             :     }
    1897             : 
    1898        3555 :     set16_fx( &hHQ_core->old_out_fx[( W1 + n )], 0, n );
    1899             : 
    1900        3555 :     hHQ_core->Q_old_wtda = Q_syn;
    1901        3555 :     move16();
    1902             : 
    1903             : #ifdef FIX_2003_CON_TCX_OVERFLOW
    1904        3555 :     scf = add( getScaleFactor16( syn, L_frame ), Q_syn );
    1905        3555 :     IF( LT_16( scf, 0 ) ) // Only avoid left shift in bufferCopyFX when overflow could occur
    1906             :     {
    1907           2 :         st->Q_syn_factor = scf;
    1908             :     }
    1909             :     ELSE
    1910             :     {
    1911        3553 :         st->Q_syn_factor = 0;
    1912        3553 :         move16();
    1913             :     }
    1914        3555 :     bufferCopyFx( syn, synth, L_frame, Q_syn, st->Q_syn_factor, 0, 0 );
    1915             : 
    1916        3555 :     bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, st->Q_syn_factor, 0, 0 );
    1917             : 
    1918        3555 :     Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), sub( st->Q_syn_factor, Q_syn ) );
    1919        3555 :     hTcxDec->Q_syn_OverlFB = st->Q_syn_factor;
    1920             : #else
    1921             :     /* As long as there is no synth scaling factor introduced, which
    1922             :     is given to the outside, there might occur overflows here */
    1923             :     BASOP_SATURATE_WARNING_OFF_EVS
    1924             :     bufferCopyFx( syn, synth, L_frame, Q_syn, 0, 0, 0 ); /*Q_syn*/
    1925             :     BASOP_SATURATE_WARNING_ON_EVS
    1926             : 
    1927             :     Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), sub( 0, Q_syn ) ); /*Q0*/
    1928             :     hTcxDec->Q_syn_OverlFB = 0;
    1929             :     move16();
    1930             : #endif
    1931             : 
    1932             :     /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */
    1933        3555 :     IF( st->hWIDec != NULL )
    1934             :     {
    1935           0 :         lerp( exc, st->hWIDec->old_exc2_fx, L_EXC_MEM, L_frame );
    1936           0 :         lerp( syn, st->hWIDec->old_syn2_fx, L_EXC_MEM, L_frame );
    1937             :     }
    1938             : 
    1939        3555 :     st->bfi_pitch_fx /*Q6*/ = round_fx_sat( L_shl_sat( pitch_buf[sub( st->nb_subfr, 1 )] /*15Q16*/, 6 /*Q6*/ ) );
    1940        3555 :     move16();
    1941        3555 :     st->bfi_pitch_frame = st->L_frame;
    1942        3555 :     move16();
    1943             : 
    1944             :     /* create aliasing and windowing need for transition to TCX10/5 */
    1945        3555 :     Copy( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ) );
    1946        3555 :     hTcxDec->Q_syn_Overl_TDACFB = Q_syn;
    1947        3555 :     move16();
    1948             : 
    1949      528135 :     FOR( i = 0; i < W12; i++ )
    1950             :     {
    1951      524580 :         buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); /*hTcxDec->Q_syn_Overl_TDACFB*/
    1952      524580 :         move16();
    1953             :     }
    1954      528135 :     FOR( ; i < W1; i++ )
    1955             :     {
    1956      524580 :         buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ); /*hTcxDec->Q_syn_Overl_TDACFB*/
    1957      524580 :         move16();
    1958             :     }
    1959             : 
    1960             : 
    1961      528135 :     FOR( i = 0; i < W2; i++ )
    1962             :     {
    1963      524580 :         hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[( ( W1 - 1 ) - i )] ); /*hTcxDec->Q_syn_Overl_TDACFB*/
    1964      524580 :         move16();
    1965             :     }
    1966             : 
    1967      528135 :     FOR( i = 0; i < W2; i++ )
    1968             :     {
    1969      524580 :         hTcxDec->syn_Overl_TDACFB[( W2 + i )] = add_sat( buf[( W2 + i )], buf[( ( ( W1 - 1 ) - W2 ) - i )] ); /*hTcxDec->Q_syn_Overl_TDACFB*/
    1970      524580 :         move16();
    1971             :     }
    1972             : 
    1973      528135 :     FOR( i = 0; i < W12; i++ )
    1974             :     {
    1975      524580 :         hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); /*hTcxDec->Q_syn_Overl_TDACFB*/
    1976      524580 :         move16();
    1977             :     }
    1978      528135 :     FOR( ; i < W1; i++ )
    1979             :     {
    1980      524580 :         hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ); /*hTcxDec->Q_syn_Overl_TDACFB*/
    1981      524580 :         move16();
    1982             :     }
    1983             : 
    1984        3555 :     st->hTcxCfg->tcx_curr_overlap_mode = FULL_OVERLAP;
    1985        3555 :     move16();
    1986             : 
    1987        3555 :     synth[-1] = pre_emph_buf; /*Q0*/
    1988        3555 :     move16();
    1989             : 
    1990             :     /* update memory for low band */
    1991        3555 :     st->Q_syn = Q_syn;
    1992        3555 :     move16();
    1993        3555 :     lerp( hTcxDec->syn_OverlFB, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) );
    1994        3555 :     hTcxDec->Q_syn_Overl = hTcxDec->Q_syn_OverlFB;
    1995        3555 :     move16();
    1996        3555 :     lerp( hTcxDec->syn_Overl_TDACFB, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), shr( L_frame, 1 ) );
    1997        3555 :     hTcxDec->Q_syn_Overl_TDAC = hTcxDec->Q_syn_Overl_TDACFB;
    1998        3555 :     move16();
    1999        3555 :     lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, L_frame );
    2000        3555 :     st->hHQ_core->Q_old_wtda_LB = Q_syn;              // st->hHQ_core->Q_old_wtda
    2001        3555 :     st->old_enr_LP = Enr_1_Az_fx( A_local, L_SUBFR ); /*Q3*/
    2002        3555 :     move16();
    2003             : 
    2004        3555 :     return;
    2005             : }

Generated by: LCOV version 1.14