LCOV - code coverage report
Current view: top level - lib_enc - enc_gen_voic_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ cede165d26d1b794bfc5f5f6f9ec19d4d64a9a3b Lines: 296 325 91.1 %
Date: 2025-11-01 03:16:20 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : 
       5             : #include <stdint.h>
       6             : #include "options.h"     /* Compilation switches                   */
       7             : #include "cnst.h"        /* Common constants                       */
       8             : #include "prot_fx.h"     /* Function prototypes                    */
       9             : #include "rom_com.h"     /* Static table prototypes                */
      10             : #include "prot_fx_enc.h" /* Function prototypes                    */
      11             : 
      12             : 
      13             : /*-------------------------------------------------------------------*
      14             :  * rem_offset()
      15             :  *
      16             :  *
      17             :  *-------------------------------------------------------------------*/
      18             : 
      19         468 : static void rem_offset(
      20             :     const Word16 *in,
      21             :     Word16 *out,
      22             :     const Word16 l_subfr )
      23             : {
      24             :     Word16 i;
      25             :     Word16 tmp;
      26         468 :     Word32 loffset = 0;
      27         468 :     move32();
      28             : 
      29         468 :     tmp = shl( 2, norm_s( l_subfr ) ); /* l_subfr is expected to be based 2 */
      30       30420 :     FOR( i = 0; i < l_subfr; i++ )
      31             :     {
      32       29952 :         loffset = L_mac( loffset, in[i], tmp );
      33             :     }
      34         468 :     tmp = round_fx_sat( loffset );
      35       30420 :     FOR( i = 0; i < l_subfr; i++ )
      36             :     {
      37       29952 :         out[i] = sub( in[i], tmp );
      38       29952 :         move16();
      39             :     }
      40             : 
      41         468 :     return;
      42             : }
      43             : 
      44             : 
      45             : /*======================================================================*/
      46             : /* FUNCTION : encod_gen_voic_fx()                                                                               */
      47             : /*----------------------------------------------------------------------*/
      48             : /* PURPOSE : encode generic (GC), voiced (VC) and AMR-WB IO frames              */
      49             : /*                                                                                                                                              */
      50             : /*----------------------------------------------------------------------*/
      51             : /*  INPUT ARGUMENTS :                                                                                               */
      52             : /* _ (Struct)   st_fx                   : encoder static memory                                 */
      53             : /* _ (Word16) L_frame_fx                : length of the frame               Q0          */
      54             : 
      55             : /* _ (Word16[]) speech_fx                       : input speech                  Q0              */
      56             : /* _ (Word16[]) Aq_fx                   : LP filter coefficient             Q12         */
      57             : /* _ (Word16[]) A_fx                    : unquantized A(z) filter               */
      58             : /*                                with bandwidth expansion              Q12         */
      59             : /* _ (Word16) coder_type                : coding type                                                   */
      60             : /* _ (Word16) Es_pred_fx                : predicted scaled innov. energy Q8             */
      61             : /* _ (Word16[]) T_op_fx                 : open loop pitch Q0                                    */
      62             : /* _ (Word16[]) voicing_fx          : floating pitch values for each subframe Q15*/
      63             : /* _ (Word16[]) res_fx                  : residual signal                               Q_new   */
      64             : /* _ (Word16[]) exc_fx                  : adapt. excitation exc (Q0)                     */
      65             : /* _ (Word16[]) exc2_fx                 : adapt. excitation/total exc (Q0)               */
      66             : /* _ (Word16[]) pitch_buf_fx    : floating pitch values for each subframe Q6*/
      67             : /* _ (Word16) shift             :       shift                                                                            */
      68             : /* _ (Word16) Q_new             :                                                            */
      69             : /*-----------------------------------------------------------------------*/
      70             : /* OUTPUT ARGUMENTS :                                                                                                    */
      71             : /* _ (Word16[]) exc_fx                  : adapt. excitation exc (Q0)                     */
      72             : /* _ (Word16[]) exc2_fx                 : adapt. excitation/total exc (Q0)               */
      73             : /* _ (Word16[]) syn_fx                  :core synthesis                                 Q_new   */
      74             : /* _ (Word16[]) voice_factors_fx: voicing factors                               Q15              */
      75             : /* _ (Word16[]) bwe_exc_fx              : excitation for SWB TBE        Q0               */
      76             : /*-----------------------------------------------------------------------*/
      77             : 
      78             : 
      79             : /*-----------------------------------------------------------------------*/
      80             : /* RETURN ARGUMENTS :                                                                                                    */
      81             : /* _ None                                                                                                                                */
      82             : /*=======================================================================*/
      83             : 
      84        1291 : void encod_gen_voic_fx(
      85             :     Encoder_State *st_fx,              /* i/o: state structure                                  */
      86             :     const Word16 speech_fx[],          /* i  : input speech                                     Q0*/
      87             :     const Word16 Aw_fx[],              /* i  : weighted A(z) unquantized for subframes          Q12*/
      88             :     const Word16 Aq_fx[],              /* i  : 12k8 Lp coefficient                              Q12*/
      89             :     const Word16 Es_pred_fx,           /* i  : predicted scaled innov. energy                   Q8*/
      90             :     const Word16 *res_fx,              /* i  : residual signal                                  Q_new*/
      91             :     Word16 *syn_fx,                    /* i/o: core synthesis                                   Q_new*/
      92             :     Word16 *exc_fx,                    /* i/o: current non-enhanced excitation                  Q0*/
      93             :     Word16 *exc2_fx,                   /* i/o: current enhanced excitation                      Q0*/
      94             :     Word16 *pitch_buf_fx,              /* i/o: floating pitch values for each subframe          Q6*/
      95             :     Word16 *voice_factors_fx,          /* o  : voicing factors                                  Q15*/
      96             :     Word16 *bwe_exc_fx,                /* o  : excitation for SWB TBE                           Q0*/
      97             :     Word16 *unbits_fx,                 /* i/o: number of unused bits                                                    Q0*/
      98             :     const Word16 tdm_Pitch_reuse_flag, /* i  : primary channel pitch reuse flag                 Q0*/
      99             :     const Word16 tdm_Pri_pitch_buf[],  /* i  : primary channel pitch buffer                     Q6*/
     100             :     Word16 shift,
     101             :     Word16 Q_new )
     102             : {
     103             :     Word16 xn_fx[L_SUBFR];             /* Target vector for pitch search    */
     104             :     Word16 xn2_fx[L_SUBFR];            /* Target vector for codebook search */
     105             :     Word16 cn_fx[L_SUBFR];             /* Target vector in residual domain  */
     106             :     Word16 h1_fx[L_SUBFR + ( M + 1 )]; /* Impulse response vector           */
     107             :     Word16 h2_fx[L_SUBFR + ( M + 1 )]; /* Impulse response vector           */
     108             :     Word16 code_fx[L_SUBFR];           /* Fixed codebook excitation         */
     109        1291 :     Word16 y1_fx[L_SUBFR] = { 0 };     /* Filtered adaptive excitation      */
     110             :     Word16 y2_fx[L_SUBFR];             /* Filtered algebraic excitation     */
     111        1291 :     Word16 gain_pit_fx = 0;            /* Pitch gain                        */
     112        1291 :     move16();
     113             :     Word16 voice_fac_fx;     /* Voicing factor                    */
     114        1291 :     Word32 gain_code_fx = 0; /* Gain of code                      */
     115        1291 :     move32();
     116        1291 :     Word16 gain_inov_fx = 0; /* inovation gain                    */
     117        1291 :     move16();
     118             :     Word32 gc_mem[NB_SUBFR - 1];      /* gain_code from previous subframes */
     119             :     Word16 gp_mem[NB_SUBFR - 1];      /* gain_pitch from previous subframes*/
     120             :     Word16 i, i_subfr_fx;             /* tmp variables                     */
     121        1291 :     Word16 T0_fx = 0, T0_frac_fx = 0; /* close loop integer pitch and fractional part */
     122        1291 :     move16();
     123        1291 :     move16();
     124             :     Word16 T0_min_fx, T0_max_fx;     /* pitch variables                   */
     125             :     Word16 *pt_pitch_fx;             /* pointer to floating pitch buffer  */
     126             :     Word16 g_corr_fx[10];            /* ACELP correl, values + gain pitch */
     127             :     Word16 clip_gain_fx;             /* LSF clip gain                     */
     128             :     const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector*/
     129        1291 :     Word16 error_fx = 0;
     130        1291 :     Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation   */
     131        1291 :     move16();
     132        1291 :     move16();
     133             :     Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation           */
     134        1291 :     Word16 unbits_PI_fx = 0;      /* number of unused bits for  PI     */
     135        1291 :     Word32 norm_gain_code_fx = 0;
     136        1291 :     move16();
     137        1291 :     move32();
     138             :     Word16 pitch_limit_flag;
     139             :     Word16 gcode16;
     140             :     Word32 Ltmp;
     141             :     Word32 Ltmp1;
     142             :     Word32 Lgcode;
     143             :     Word16 tmp1_fx;
     144             :     Word16 shift_wsp;
     145             :     Word16 harm_flag_acelp;
     146             :     Word16 lp_select, lp_flag, L_frame;
     147        1291 :     SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
     148        1291 :     BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
     149        1291 :     SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas;
     150        1291 :     LPD_state_HANDLE hLPDmem = st_fx->hLPDmem;
     151             : 
     152             :     /*------------------------------------------------------------------*
     153             :      * Initializations
     154             :      *------------------------------------------------------------------*/
     155             : 
     156        1291 :     gain_pit_fx = 0;
     157        1291 :     move16();
     158        1291 :     gain_code_fx = L_deposit_l( 0 );
     159        1291 :     gain_preQ_fx = 0;
     160        1291 :     move16();
     161        1291 :     unbits_PI_fx = 0;
     162        1291 :     move16();
     163        1291 :     error_fx = 0;
     164        1291 :     move16();
     165        1291 :     L_frame = st_fx->L_frame;
     166        1291 :     move16();
     167             : 
     168             : 
     169        1291 :     IF( EQ_16( L_frame, L_FRAME ) )
     170             :     {
     171         667 :         T0_max_fx = PIT_MAX;
     172         667 :         move16();
     173         667 :         T0_min_fx = PIT_MIN;
     174         667 :         move16();
     175             :     }
     176             :     ELSE /* L_frame == L_FRAME16k */
     177             :     {
     178         624 :         T0_max_fx = PIT16k_MAX;
     179         624 :         move16();
     180         624 :         T0_min_fx = PIT16k_MIN;
     181         624 :         move16();
     182             :     }
     183        1291 :     lp_flag = st_fx->acelp_cfg.ltf_mode;
     184        1291 :     move16();
     185             : 
     186        1291 :     *unbits_fx = 0;
     187        1291 :     move16();
     188             : 
     189        1291 :     p_Aw_fx = Aw_fx;            /* Q12 */
     190        1291 :     p_Aq_fx = Aq_fx;            /* Q12 */
     191        1291 :     pt_pitch_fx = pitch_buf_fx; /* Q6 */
     192        1291 :     gain_preQ_fx = 0;
     193        1291 :     move16();
     194        1291 :     set16_fx( code_preQ_fx, 0, L_SUBFR );
     195             : 
     196        1291 :     shift_wsp = add( Q_new, shift );
     197             : 
     198             :     /* set and write harmonicity flag */
     199        1291 :     harm_flag_acelp = 0;
     200        1291 :     move16();
     201             : 
     202        1291 :     test();
     203        1291 :     test();
     204        1291 :     IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( st_fx->coder_type, GENERIC ) )
     205             :     {
     206           0 :         if ( GT_16( st_fx->last_harm_flag_acelp, 2 ) )
     207             :         {
     208           0 :             harm_flag_acelp = 1;
     209           0 :             move16();
     210             :         }
     211             : 
     212           0 :         push_indice( hBstr, IND_HARM_FLAG_ACELP, harm_flag_acelp, 1 );
     213             :     }
     214             : 
     215             :     /*------------------------------------------------------------------*
     216             :      * ACELP subframe loop
     217             :      *------------------------------------------------------------------*/
     218             : 
     219        7079 :     FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR )
     220             :     {
     221             : 
     222             :         /*----------------------------------------------------------------*
     223             :          * Find the the excitation search target "xn" and innovation
     224             :          *   target in residual domain "cn"
     225             :          * Compute impulse response, h1[], of weighted synthesis filter
     226             :          *----------------------------------------------------------------*/
     227             : 
     228        5788 :         Copy( &res_fx[i_subfr_fx], &exc_fx[i_subfr_fx], L_SUBFR ); /*Q_new*/
     229             : 
     230        5788 :         find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr_fx, &hLPDmem->mem_w0, p_Aq_fx,
     231        5788 :                          res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx );
     232             : 
     233        5788 :         Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, -2 );  /*Q11*/
     234        5788 :         Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution Q(14+shift)*/
     235             : 
     236             :         /* scaling of xn[] to limit dynamic at 12 bits */
     237        5788 :         Scale_sig( xn_fx, L_SUBFR, shift );
     238             : 
     239             :         /*----------------------------------------------------------------*
     240             :          * Close-loop pitch search and quantization
     241             :          *----------------------------------------------------------------*/
     242             : 
     243       11576 :         *pt_pitch_fx = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, st_fx->core_brate, 0, L_frame, st_fx->coder_type, &pitch_limit_flag, i_subfr_fx, exc_fx,
     244        5788 :                                       L_SUBFR, st_fx->pitch, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, st_fx->element_mode, Q_new ); /* Q6 */
     245             : 
     246             : 
     247        5788 :         tbe_celp_exc( L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx );
     248             : 
     249             :         /*-----------------------------------------------------------------*
     250             :          * Find adaptive exitation
     251             :          *-----------------------------------------------------------------*/
     252             : 
     253        5788 :         pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP );
     254             : 
     255             :         /*-----------------------------------------------------------------*
     256             :          * Gain clipping test to avoid unstable synthesis on frame erasure
     257             :          *-----------------------------------------------------------------*/
     258             : 
     259        5788 :         clip_gain_fx = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr_fx, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, sub( shift_wsp, 1 ) );
     260             : 
     261        5788 :         if ( EQ_16( st_fx->coder_type, INACTIVE ) )
     262             :         {
     263             :             /* in case of AVQ inactive, limit the gain to 0.65 */
     264           0 :             clip_gain_fx = 2;
     265           0 :             move16();
     266             :         }
     267             : 
     268             :         /*-----------------------------------------------------------------*
     269             :          * LP filtering of the adaptive excitation, codebook target computation
     270             :          *-----------------------------------------------------------------*/
     271             : 
     272        5788 :         lp_select = lp_filt_exc_enc_fx( MODE1, st_fx->coder_type, i_subfr_fx, exc_fx, h1_fx,
     273             :                                         xn_fx, y1_fx, xn2_fx, L_SUBFR, L_frame, g_corr_fx, clip_gain_fx, &gain_pit_fx, &lp_flag );
     274             : 
     275        5788 :         IF( EQ_16( lp_flag, NORMAL_OPERATION ) )
     276             :         {
     277        5788 :             push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 );
     278             :         }
     279             : 
     280             :         /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit_fx;*/
     281        5788 :         hSpMusClas->lowrate_pitchGain = round_fx_sat( L_mac_sat( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit_fx ) ); /*Q14*Q16(0.1) + Q15 -> Q15*/
     282             : 
     283             :         /*-----------------------------------------------------------------*
     284             :          * Transform domain contribution encoding - active frames
     285             :          *-----------------------------------------------------------------*/
     286             : 
     287        5788 :         test();
     288        5788 :         IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && NE_16( st_fx->coder_type, INACTIVE ) )
     289             :         {
     290        3120 :             transf_cdbk_enc_fx( st_fx, harm_flag_acelp, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx,
     291             :                                 xn2_fx, y1_fx, y2_fx, Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift );
     292             :         }
     293             : 
     294             :         /*-----------------------------------------------------------------*
     295             :          * Innovation encoding
     296             :          *-----------------------------------------------------------------*/
     297             : 
     298        5788 :         inov_encode_fx( st_fx, st_fx->core_brate, 0, L_frame, st_fx->last_L_frame,
     299        5788 :                         st_fx->coder_type, st_fx->bwidth, st_fx->sharpFlag, i_subfr_fx, -1, p_Aq_fx,
     300        5788 :                         gain_pit_fx, cn_fx, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn2_fx, code_fx, y2_fx, &unbits_PI_fx, L_SUBFR, shift );
     301             : 
     302             :         /*-----------------------------------------------------------------*
     303             :          * Gain encoding
     304             :          *-----------------------------------------------------------------*/
     305             : 
     306        5788 :         IF( LE_32( st_fx->core_brate, ACELP_8k00 ) )
     307             :         {
     308           0 :             gain_enc_lbr_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->coder_type, i_subfr_fx, xn_fx, y1_fx, shift_wsp, y2_fx, code_fx,
     309             :                              &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, gc_mem, gp_mem, clip_gain_fx, L_SUBFR,
     310           0 :                              st_fx->element_mode );
     311             :         }
     312        5788 :         ELSE IF( GT_32( st_fx->core_brate, ACELP_32k ) )
     313             :         {
     314        3120 :             gain_enc_SQ_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr_fx, xn_fx, y1_fx, y2_fx, code_fx, Es_pred_fx,
     315             :                             &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, clip_gain_fx, shift_wsp );
     316             :         }
     317             :         ELSE
     318             :         {
     319        2668 :             gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, i_subfr_fx, -1, xn_fx, y1_fx, shift_wsp, y2_fx, code_fx, Es_pred_fx,
     320             :                                &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, clip_gain_fx );
     321             :         }
     322        5788 :         IF( st_fx->Opt_SC_VBR )
     323             :         {
     324           0 :             if ( EQ_16( hSC_VBR->last_ppp_mode, 1 ) )
     325             :             {
     326             :                 /* SC-VBR - all other st->clip_var values will be updated even in a PPP frame */
     327           0 :                 st_fx->clip_var_fx[1] = gain_pit_fx; /*Q14*/
     328           0 :                 move16();
     329             :             }
     330             :         }
     331        5788 :         gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit_fx, st_fx->clip_var_fx );
     332             : 
     333        5788 :         Lgcode = L_shl_sat( gain_code_fx, Q_new );                                                                 /* scaled gain_code with Qnew -> Q16*/
     334        5788 :         gcode16 = round_fx_sat( Lgcode );                                                                          /*Q0*/
     335        5788 :         hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, Lgcode, &voice_fac_fx, shift ); /* Q15 */
     336        5788 :         move16();
     337             : 
     338             :         /*-----------------------------------------------------------------*
     339             :          * Transform domain contribution encoding - inactive frames
     340             :          *-----------------------------------------------------------------*/
     341             : 
     342        5788 :         test();
     343        5788 :         IF( GE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) && EQ_16( st_fx->coder_type, INACTIVE ) )
     344             :         {
     345           0 :             transf_cdbk_enc_fx( st_fx, 0, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, xn2_fx, y1_fx, y2_fx,
     346             :                                 Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift );
     347             :         }
     348             : 
     349             :         /*-----------------------------------------------------------------*
     350             :          * Update memory of the weighting filter
     351             :          *-----------------------------------------------------------------*/
     352             : 
     353             :         /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */
     354        5788 :         Ltmp = L_mult( gcode16, y2_fx[L_SUBFR - 1] ); /*Q10*/
     355        5788 :         Ltmp = L_shl( Ltmp, add( 5, shift ) );        /*Q15+shift*/
     356        5788 :         Ltmp = L_negate( Ltmp );
     357        5788 :         Ltmp = L_mac( Ltmp, xn_fx[L_SUBFR - 1], 16384 /*Q14*/ );       /* Q_new-1+shift+14+1 */
     358        5788 :         Ltmp = L_msu( Ltmp, y1_fx[L_SUBFR - 1], gain_pit_fx /*Q14*/ ); /* Q_new-1+shift+14+1 */
     359        5788 :         Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) );                     /* 15 + Q_new */
     360        5788 :         hLPDmem->mem_w0 = round_fx_sat( Ltmp );                        /*Q_new-1        */
     361        5788 :         move16();
     362        5788 :         IF( gain_preQ_fx != 0 )
     363             :         {
     364        3120 :             tmp1_fx = add( 16 - ( 2 + Q_AVQ_OUT_DEC + 1 ), Q_new );
     365             : 
     366      202800 :             FOR( i = 0; i < L_SUBFR; i++ )
     367             :             {
     368             :                 /* Contribution from AVQ layer */
     369      199680 :                 Ltmp1 = L_mult_sat( gain_preQ_fx, code_preQ_fx[i] ); /* Q2 + Q6 -> Q9*/
     370      199680 :                 Ltmp1 = L_shl_sat( Ltmp1, tmp1_fx );                 /* Q16 + Q_exc */
     371             : 
     372             :                 /* Compute exc2 */
     373      199680 :                 Ltmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /* Q16 */
     374      199680 :                 exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( Ltmp, Ltmp1 ) );   /* Q0 */
     375      199680 :                 move16();
     376             : 
     377             :                 /* code in Q9, gain_pit in Q14 */
     378      199680 :                 Ltmp = L_mult( gcode16, code_fx[i] );                              /* Q10 */
     379      199680 :                 Ltmp = L_shl( Ltmp, 5 );                                           /* Q15 */
     380      199680 :                 Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx );         /* Q15 */
     381      199680 :                 Ltmp = L_shl_sat( Ltmp, 1 );                                       /* saturation can occur here Q16*/
     382      199680 :                 exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( Ltmp, Ltmp1 ) ); /* Q0 */
     383             :             }
     384             :         }
     385             :         ELSE
     386             :         {
     387             :             /*-----------------------------------------------------------------*
     388             :              * Construct adaptive part of the excitation
     389             :              * Save the non-enhanced excitation for FEC_exc
     390             :              *-----------------------------------------------------------------*/
     391             : 
     392      173420 :             FOR( i = 0; i < L_SUBFR; i++ )
     393             :             {
     394             :                 /* code in Q9, gain_pit in Q14 */
     395      170752 :                 Ltmp = L_mult( gcode16, code_fx[i] );                          /* Q10 */
     396      170752 :                 Ltmp = L_shl_sat( Ltmp, 5 );                                   /* Q15 */
     397      170752 :                 Ltmp = L_mac_sat( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /* Q15 */
     398      170752 :                 Ltmp = L_shl_sat( Ltmp, 1 );                                   /* saturation can occur here Q16*/
     399      170752 :                 exc_fx[i + i_subfr_fx] = round_fx_sat( Ltmp );                 /* Q0 */
     400             :             }
     401             :         }
     402             : 
     403             :         /*-----------------------------------------------------------------*
     404             :          * Prepare TBE excitation
     405             :          *-----------------------------------------------------------------*/
     406             : 
     407        5788 :         prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx,
     408        5788 :                          &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q10, Q_new,
     409        5788 :                          T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate,
     410        5788 :                          st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag );
     411             : 
     412             :         /*-----------------------------------------------------------------*
     413             :          * Synthesize speech to update mem_syn[].
     414             :          * Update A(z) filters
     415             :          *-----------------------------------------------------------------*/
     416             : 
     417        5788 :         Syn_filt_s( 1, p_Aq_fx, M, &exc_fx[i_subfr_fx], &syn_fx[i_subfr_fx], L_SUBFR, hLPDmem->mem_syn, 1 );
     418             : 
     419        5788 :         p_Aw_fx += ( M + 1 );
     420        5788 :         p_Aq_fx += ( M + 1 );
     421        5788 :         pt_pitch_fx++;
     422             :     }
     423             : 
     424             :     /* write reserved bits */
     425        1291 :     WHILE( unbits_PI_fx > 0 )
     426             :     {
     427           0 :         i = s_min( unbits_PI_fx, 16 );
     428           0 :         push_indice( hBstr, IND_UNUSED, 0, i );
     429           0 :         unbits_PI_fx -= i;
     430             :     }
     431        1291 :     IF( st_fx->Opt_SC_VBR )
     432             :     {
     433             :         /* SC-VBR */
     434           0 :         hSC_VBR->prev_ppp_gain_pit_fx = gain_pit_fx; /* Q14 */
     435           0 :         move16();
     436           0 :         hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */
     437           0 :         move16();
     438             :     }
     439             : 
     440        1291 :     return;
     441             : }
     442             : 
     443             : 
     444      117774 : void encod_gen_voic_ivas_fx(
     445             :     Encoder_State *st_fx,              /* i/o: state structure                                  */
     446             :     const Word16 speech_fx[],          /* i  : input speech                                     Qnew -1 */
     447             :     const Word16 Aw_fx[],              /* i  : weighted A(z) unquantized for subframes          Q12*/
     448             :     const Word16 Aq_fx[],              /* i  : 12k8 Lp coefficient                              Q12*/
     449             :     const Word16 Es_pred_fx,           /* i  : predicted scaled innov. energy                   Q8*/
     450             :     const Word16 *res_fx,              /* i  : residual signal                                  Q_new*/
     451             :     Word16 *syn_fx,                    /* i/o: core synthesis                                   Q_new - 1*/
     452             :     Word16 *exc_fx,                    /* i/o: current non-enhanced excitation                  Q_new*/
     453             :     Word16 *exc2_fx,                   /* i/o: current enhanced excitation                      Q_new*/
     454             :     Word16 *pitch_buf_fx,              /* i/o: floating pitch values for each subframe          Q6*/
     455             :     Word16 *voice_factors_fx,          /* o  : voicing factors                                  Q15*/
     456             :     Word16 *bwe_exc_fx,                /* o  : excitation for SWB TBE                           Q0*/
     457             :     Word16 *unbits_fx,                 /* i/o: number of unused bits                                                    Q0*/
     458             :     const Word16 tdm_Pitch_reuse_flag, /* i  : primary channel pitch reuse flag                 Q0*/
     459             :     const Word16 tdm_Pri_pitch_buf[],  /* i  : primary channel pitch buffer                     Q6*/
     460             :     Word16 shift,
     461             :     Word16 Q_new )
     462             : {
     463             :     Word16 xn_fx[L_SUBFR];             /* Target vector for pitch search    */
     464             :     Word16 xn2_fx[L_SUBFR];            /* Target vector for codebook search */
     465             :     Word16 cn_fx[L_SUBFR];             /* Target vector in residual domain  */
     466             :     Word16 h1_fx[L_SUBFR + ( M + 1 )]; /* Impulse response vector           */
     467             :     Word16 h2_fx[L_SUBFR + ( M + 1 )]; /* Impulse response vector           */
     468             :     Word16 code_fx[L_SUBFR];           /* Fixed codebook excitation         */
     469      117774 :     Word16 y1_fx[L_SUBFR] = { 0 };     /* Filtered adaptive excitation      */
     470             :     Word16 y2_fx[L_SUBFR];             /* Filtered algebraic excitation     */
     471      117774 :     Word16 gain_pit_fx = 0;            /* Pitch gain                        */
     472      117774 :     move16();
     473             :     Word16 voice_fac_fx;     /* Voicing factor                    */
     474      117774 :     Word32 gain_code_fx = 0; /* Gain of code                      */
     475      117774 :     Word16 gain_inov_fx = 0; /* inovation gain                    */
     476      117774 :     move32();
     477      117774 :     move16();
     478             :     Word32 gc_mem[NB_SUBFR - 1];      /* gain_code from previous subframes */
     479             :     Word16 gp_mem[NB_SUBFR - 1];      /* gain_pitch from previous subframes*/
     480             :     Word16 i, i_subfr_fx;             /* tmp variables                     */
     481      117774 :     Word16 T0_fx = 0, T0_frac_fx = 0; /* close loop integer pitch and fractional part */
     482      117774 :     move16();
     483      117774 :     move16();
     484             :     Word16 T0_min_fx, T0_max_fx;     /* pitch variables                   */
     485             :     Word16 *pt_pitch_fx;             /* pointer to floating pitch buffer  */
     486             :     Word16 g_corr_fx[10];            /* ACELP correl, values + gain pitch */
     487             :     Word16 clip_gain_fx;             /* LSF clip gain                     */
     488             :     const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector*/
     489      117774 :     Word16 error_fx = 0;
     490      117774 :     Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation   */
     491      117774 :     move16();
     492      117774 :     move16();
     493             :     Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation           */
     494      117774 :     Word16 unbits_PI_fx = 0;      /* number of unused bits for  PI     */
     495      117774 :     Word32 norm_gain_code_fx = 0;
     496      117774 :     move16();
     497      117774 :     move32();
     498             :     Word16 pitch_limit_flag;
     499             :     Word16 gcode16;
     500             :     Word32 Ltmp;
     501             :     Word32 Ltmp1;
     502             :     Word32 Lgcode;
     503             :     Word16 tmp1_fx;
     504             :     Word16 shift_wsp;
     505             :     Word16 harm_flag_acelp;
     506             :     Word16 lp_select, lp_flag, L_frame;
     507             :     Word16 q_h1;
     508      117774 :     SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
     509      117774 :     BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
     510      117774 :     LPD_state_HANDLE hLPDmem = st_fx->hLPDmem;
     511             : 
     512             :     /*------------------------------------------------------------------*
     513             :      * Initializations
     514             :      *------------------------------------------------------------------*/
     515             : 
     516      117774 :     gain_pit_fx = 0;
     517      117774 :     move16();
     518      117774 :     gain_code_fx = L_deposit_l( 0 );
     519      117774 :     gain_preQ_fx = 0;
     520      117774 :     move16();
     521      117774 :     unbits_PI_fx = 0;
     522      117774 :     move16();
     523      117774 :     error_fx = 0;
     524      117774 :     move16();
     525      117774 :     L_frame = st_fx->L_frame;
     526      117774 :     move16();
     527             : 
     528      117774 :     IF( EQ_16( L_frame, L_FRAME ) )
     529             :     {
     530       53881 :         T0_max_fx = PIT_MAX;
     531       53881 :         move16();
     532       53881 :         T0_min_fx = PIT_MIN;
     533       53881 :         move16();
     534             :     }
     535             :     ELSE /* L_frame == L_FRAME16k */
     536             :     {
     537       63893 :         T0_max_fx = PIT16k_MAX;
     538       63893 :         move16();
     539       63893 :         T0_min_fx = PIT16k_MIN;
     540       63893 :         move16();
     541             :     }
     542      117774 :     lp_flag = st_fx->acelp_cfg.ltf_mode;
     543      117774 :     move16();
     544             : 
     545      117774 :     *unbits_fx = 0;
     546      117774 :     move16();
     547             : 
     548      117774 :     p_Aw_fx = Aw_fx;            /*Q12*/
     549      117774 :     p_Aq_fx = Aq_fx;            /*Q12*/
     550      117774 :     pt_pitch_fx = pitch_buf_fx; /*Q6*/
     551      117774 :     gain_preQ_fx = 0;
     552      117774 :     move16();
     553      117774 :     set16_fx( code_preQ_fx, 0, L_SUBFR );
     554             : 
     555      117774 :     shift_wsp = add( Q_new, shift );
     556      117774 :     if ( LT_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) )
     557             :     {
     558      105274 :         shift_wsp = sub( shift_wsp, 1 );
     559             :     }
     560             : 
     561             :     /* set and write harmonicity flag */
     562      117774 :     harm_flag_acelp = 0;
     563      117774 :     move16();
     564             : 
     565      117774 :     test();
     566      117774 :     test();
     567      117774 :     IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( st_fx->coder_type, GENERIC ) )
     568             :     {
     569        8017 :         if ( GT_16( st_fx->last_harm_flag_acelp, 2 ) )
     570             :         {
     571         719 :             harm_flag_acelp = 1;
     572         719 :             move16();
     573             :         }
     574             : 
     575        8017 :         push_indice( hBstr, IND_HARM_FLAG_ACELP, harm_flag_acelp, 1 );
     576             :     }
     577             : 
     578             :     /*------------------------------------------------------------------*
     579             :      * ACELP subframe loop
     580             :      *------------------------------------------------------------------*/
     581             : 
     582      652763 :     FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR )
     583             :     {
     584             : 
     585             :         /*----------------------------------------------------------------*
     586             :          * Find the the excitation search target "xn" and innovation
     587             :          *   target in residual domain "cn"
     588             :          * Compute impulse response, h1[], of weighted synthesis filter
     589             :          *----------------------------------------------------------------*/
     590             : 
     591      534989 :         Copy( &res_fx[i_subfr_fx], &exc_fx[i_subfr_fx], L_SUBFR ); /*Q_new*/
     592             : 
     593      534989 :         find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr_fx, &hLPDmem->mem_w0, p_Aq_fx,
     594      534989 :                               res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx );
     595             : 
     596      534989 :         q_h1 = sub( 14, norm_s( h1_fx[0] ) );
     597      534989 :         Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/
     598      534989 :         Scale_sig( h1_fx, L_SUBFR, sub( 14, q_h1 ) );             /* set h1[] in Q14 with scaling for convolution Q14*/
     599             :         /* scaling of xn[] to limit dynamic at 12 bits */
     600      534989 :         Scale_sig( xn_fx, L_SUBFR, shift );
     601      534989 :         test();
     602      534989 :         test();
     603      534989 :         IF( Es_pred_fx < 0 && LE_16( i_subfr_fx, L_SUBFR ) && NE_16( st_fx->last_core, ACELP_CORE ) )
     604             :         {
     605             :             /* During core transition, when the temporal correlation is non existent  */
     606         234 :             rem_offset( xn_fx, xn_fx, L_SUBFR );
     607         234 :             rem_offset( cn_fx, cn_fx, L_SUBFR );
     608             :         }
     609             : 
     610             :         /*----------------------------------------------------------------*
     611             :          * Close-loop pitch search and quantization
     612             :          *----------------------------------------------------------------*/
     613             : 
     614     1069978 :         *pt_pitch_fx = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, st_fx->core_brate, 0, L_frame, st_fx->coder_type, &pitch_limit_flag, i_subfr_fx, exc_fx,
     615      534989 :                                       L_SUBFR, st_fx->pitch, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, st_fx->element_mode, Q_new ); /* Q6 */
     616      534989 :         move16();
     617             : 
     618      534989 :         tbe_celp_exc_ivas( st_fx->element_mode, st_fx->idchan, L_frame, L_SUBFR, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx, st_fx->tdm_LRTD_flag );
     619             : 
     620             :         /*-----------------------------------------------------------------*
     621             :          * Find adaptive exitation
     622             :          *-----------------------------------------------------------------*/
     623             : 
     624      534989 :         pred_lt4_ivas_fx( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP );
     625             : 
     626             :         /*-----------------------------------------------------------------*
     627             :          * Gain clipping test to avoid unstable synthesis on frame erasure
     628             :          *-----------------------------------------------------------------*/
     629             : 
     630      534989 :         clip_gain_fx = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr_fx, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, sub( shift_wsp, 1 ) );
     631             : 
     632      534989 :         if ( EQ_16( st_fx->coder_type, INACTIVE ) )
     633             :         {
     634             :             /* in case of AVQ inactive, limit the gain to 0.65 */
     635       13030 :             clip_gain_fx = 2;
     636       13030 :             move16();
     637             :         }
     638             : 
     639             :         /*-----------------------------------------------------------------*
     640             :          * LP filtering of the adaptive excitation, codebook target computation
     641             :          *-----------------------------------------------------------------*/
     642             : 
     643      534989 :         lp_select = lp_filt_exc_enc_fx( MODE1, st_fx->coder_type, i_subfr_fx, exc_fx, h1_fx,
     644             :                                         xn_fx, y1_fx, xn2_fx, L_SUBFR, L_frame, g_corr_fx, clip_gain_fx, &gain_pit_fx, &lp_flag );
     645             : 
     646      534989 :         IF( EQ_16( lp_flag, NORMAL_OPERATION ) )
     647             :         {
     648      465953 :             push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 );
     649             :         }
     650             : 
     651             :         /*-----------------------------------------------------------------*
     652             :          * Transform domain contribution encoding - active frames
     653             :          *-----------------------------------------------------------------*/
     654             : 
     655      534989 :         test();
     656      534989 :         IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && NE_16( st_fx->coder_type, INACTIVE ) )
     657             :         {
     658       51245 :             transf_cdbk_enc_ivas_fx( st_fx, harm_flag_acelp, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx,
     659             :                                      xn2_fx, y1_fx, y2_fx, Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift );
     660             :         }
     661             : 
     662             :         /*-----------------------------------------------------------------*
     663             :          * Innovation encoding
     664             :          *-----------------------------------------------------------------*/
     665             : 
     666      534989 :         inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, L_frame, st_fx->last_L_frame,
     667      534989 :                              st_fx->coder_type, st_fx->bwidth, st_fx->sharpFlag, i_subfr_fx, -1, p_Aq_fx,
     668      534989 :                              gain_pit_fx, cn_fx, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn2_fx, code_fx, y2_fx, &unbits_PI_fx, L_SUBFR, shift, Q_new );
     669             : 
     670             :         /*-----------------------------------------------------------------*
     671             :          * Gain encoding
     672             :          *-----------------------------------------------------------------*/
     673             : 
     674      534989 :         IF( LE_32( st_fx->core_brate, ACELP_8k00 ) )
     675             :         {
     676       13560 :             gain_enc_lbr_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->coder_type, i_subfr_fx, xn_fx, y1_fx, shift_wsp, y2_fx, code_fx,
     677             :                              &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, gc_mem, gp_mem, clip_gain_fx, L_SUBFR,
     678       13560 :                              st_fx->element_mode );
     679             :         }
     680      521429 :         ELSE IF( GT_32( st_fx->core_brate, ACELP_32k ) )
     681             :         {
     682       40380 :             gain_enc_SQ_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr_fx, xn_fx, y1_fx, y2_fx, code_fx, Es_pred_fx,
     683             :                             &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, clip_gain_fx, shift_wsp );
     684             :         }
     685             :         ELSE
     686             :         {
     687      481049 :             gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, i_subfr_fx, -1, xn_fx, y1_fx, shift_wsp, y2_fx, code_fx, Es_pred_fx,
     688             :                                &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, clip_gain_fx );
     689             :         }
     690      534989 :         IF( st_fx->Opt_SC_VBR )
     691             :         {
     692           0 :             if ( EQ_16( hSC_VBR->last_ppp_mode, 1 ) )
     693             :             {
     694             :                 /* SC-VBR - all other st->clip_var values will be updated even in a PPP frame */
     695           0 :                 st_fx->clip_var_fx[1] = gain_pit_fx; /* Q14 */
     696           0 :                 move16();
     697             :             }
     698             :         }
     699      534989 :         gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit_fx, st_fx->clip_var_fx );
     700             : 
     701      534989 :         Lgcode = L_shl_sat( gain_code_fx, Q_new ); /* scaled gain_code with Qnew -> Q16*/
     702      534989 :         gcode16 = round_fx_sat( Lgcode );
     703             : 
     704      534989 :         hLPDmem->tilt_code = est_tilt_ivas_fx( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, Q_new, L_SUBFR, 0 ); /* Q15 */
     705      534989 :         move16();
     706             : 
     707             :         /*-----------------------------------------------------------------*
     708             :          * Transform domain contribution encoding - inactive frames
     709             :          *-----------------------------------------------------------------*/
     710             : 
     711      534989 :         test();
     712      534989 :         IF( !st_fx->inactive_coder_type_flag && EQ_16( st_fx->coder_type, INACTIVE ) )
     713             :         {
     714       13030 :             transf_cdbk_enc_ivas_fx( st_fx, 0, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, xn2_fx, y1_fx, y2_fx,
     715             :                                      Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift );
     716             :         }
     717             : 
     718             :         /*-----------------------------------------------------------------*
     719             :          * Update memory of the weighting filter
     720             :          *-----------------------------------------------------------------*/
     721             : 
     722             :         /*At this point
     723             :         xn has to be in Qnew
     724             :         yn has to be in Qnew
     725             :         y2_fx has to be in Q9
     726             :         gcode16 in Q_new
     727             :         gain_pit_fx in Q14
     728             :         */
     729      534989 :         Scale_sig( xn_fx, L_SUBFR, 1 );
     730      534989 :         Scale_sig( y1_fx, L_SUBFR, 1 );
     731             :         /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */
     732      534989 :         Ltmp = L_mult0( gcode16, y2_fx[L_SUBFR - 1] );
     733      534989 :         Ltmp = L_shl( Ltmp, add( 5, shift ) );
     734      534989 :         Ltmp = L_negate( Ltmp );
     735      534989 :         Word32 Ltmp2 = L_mult0( xn_fx[L_SUBFR - 1], 16384 );
     736      534989 :         Ltmp = L_add( Ltmp, Ltmp2 );
     737      534989 :         Word32 Ltmp3 = L_mult0( y1_fx[L_SUBFR - 1], gain_pit_fx );
     738      534989 :         Ltmp = L_sub( Ltmp, Ltmp3 );
     739             : 
     740             :         /*Ltmp is in Q14 + Qnew here
     741             :         We need memWo in Qnew -1 */
     742             : 
     743      534989 :         Ltmp = L_shl( Ltmp, sub( 1, shift ) );  // Q14 + Qnew + 1
     744      534989 :         hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1        */
     745      534989 :         move16();
     746      534989 :         IF( gain_preQ_fx != 0 )
     747             :         {
     748       64270 :             tmp1_fx = add( 16 - ( 2 + Q_AVQ_OUT_DEC + 1 ), Q_new );
     749             : 
     750     4177550 :             FOR( i = 0; i < L_SUBFR; i++ )
     751             :             {
     752             :                 /* Contribution from AVQ layer */
     753     4113280 :                 Ltmp1 = L_mult_sat( gain_preQ_fx, code_preQ_fx[i] );
     754     4113280 :                 Ltmp1 = L_shl_sat( Ltmp1, tmp1_fx );
     755             : 
     756             :                 /* Compute exc2 */
     757     4113280 :                 Ltmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 );
     758     4113280 :                 exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( Ltmp, Ltmp1 ) );
     759     4113280 :                 move16();
     760             : 
     761             :                 /* code in Q9, gain_pit in Q14 */
     762     4113280 :                 Ltmp = L_mult( gcode16, code_fx[i] );                      /*Qnew + 9 + 1 */
     763     4113280 :                 Ltmp = L_shl( Ltmp, 5 );                                   /*Qnew + 9+ 1+5 */
     764     4113280 :                 Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /*Qnew + 14 + 1*/
     765     4113280 :                 Ltmp = L_shl_sat( Ltmp, 1 ); /*Qnew + 14 + 1 +1  */        /* saturation can occur here Q16*/
     766     4113280 :                 exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( Ltmp, Ltmp1 ) );
     767     4113280 :                 move16();
     768             :             }
     769             :         }
     770             :         ELSE
     771             :         {
     772             :             /*-----------------------------------------------------------------*
     773             :              * Construct adaptive part of the excitation
     774             :              * Save the non-enhanced excitation for FEC_exc
     775             :              *-----------------------------------------------------------------*/
     776             : 
     777    30596735 :             FOR( i = 0; i < L_SUBFR; i++ )
     778             :             {
     779             :                 /* code in Q9, gain_pit in Q14 */
     780             :                 /*gcode16 in Qnew*/
     781    30126016 :                 Ltmp = L_mult( gcode16, code_fx[i] );                          /*Qnew + 9 + 1 */
     782    30126016 :                 Ltmp = L_shl_sat( Ltmp, 5 );                                   /*Qnew + 9+ 1+5 */
     783    30126016 :                 Ltmp = L_mac_sat( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /*Qnew + 14 + 1*/
     784    30126016 :                 Ltmp = L_shl_sat( Ltmp, 1 );                                   /*Qnew + 14 + 1 +1  */
     785    30126016 :                 exc_fx[i + i_subfr_fx] = round_fx_sat( Ltmp );
     786             :             }
     787             :         }
     788             : 
     789             :         /*-----------------------------------------------------------------*
     790             :          * Prepare TBE excitation
     791             :          *-----------------------------------------------------------------*/
     792             : 
     793      534989 :         prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx,
     794      534989 :                          &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_AVQ_OUT_DEC, Q_new,
     795      534989 :                          T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate,
     796      534989 :                          st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag );
     797             : 
     798             :         /*-----------------------------------------------------------------*
     799             :          * Synthesize speech to update mem_syn[].
     800             :          * Update A(z) filters
     801             :          *-----------------------------------------------------------------*/
     802             : 
     803      534989 :         syn_filt_fx( 1, p_Aq_fx, M, &exc_fx[i_subfr_fx], &syn_fx[i_subfr_fx], L_SUBFR, hLPDmem->mem_syn, 1 );
     804             : 
     805      534989 :         p_Aw_fx += ( M + 1 );
     806      534989 :         p_Aq_fx += ( M + 1 );
     807      534989 :         pt_pitch_fx++;
     808             :     }
     809             : 
     810             :     /* write reserved bits */
     811      117774 :     WHILE( unbits_PI_fx > 0 )
     812             :     {
     813           0 :         i = s_min( unbits_PI_fx, 16 );
     814           0 :         push_indice( hBstr, IND_UNUSED, 0, i );
     815           0 :         unbits_PI_fx -= i;
     816             :     }
     817      117774 :     IF( st_fx->Opt_SC_VBR )
     818             :     {
     819             :         /* SC-VBR */
     820           0 :         hSC_VBR->prev_ppp_gain_pit_fx = gain_pit_fx;
     821           0 :         move16();
     822           0 :         hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code;
     823           0 :         move16();
     824             :     }
     825      117774 :     return;
     826             : }

Generated by: LCOV version 1.14