LCOV - code coverage report
Current view: top level - lib_enc - enc_pit_exc_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ cede165d26d1b794bfc5f5f6f9ec19d4d64a9a3b Lines: 314 464 67.7 %
Date: 2025-11-01 03:16:20 Functions: 2 2 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 "rom_com.h"     /* Static table prototypes                */
       9             : #include "prot_fx.h"     /* Function prototypes                    */
      10             : #include "prot_fx_enc.h" /* Function prototypes                    */
      11             : 
      12             : 
      13             : /*======================================================================*/
      14             : /* FUNCTION : enc_pit_exc_fx()                                                                              */
      15             : /*----------------------------------------------------------------------*/
      16             : /* PURPOSE : Encode pitch only contribution                                                             */
      17             : /*                                                                                                                                              */
      18             : /*----------------------------------------------------------------------*/
      19             : /*  INPUT ARGUMENTS :                                                                                               */
      20             : /* _ (Struct)   st_fx                   : encoder static memory                                 */
      21             : /* _ (Word16[]) speech_fx                       : input speech                  Qnew-1  */
      22             : /* _ (Word16[]) Aq_fx                   : LP filter coefficient             Q12         */
      23             : /* _ (Word16[]) A_fx                    : unquantized A(z) filter               */
      24             : /*                                with bandwidth expansion              Q12         */
      25             : /* _ (Word16) coder_type                : coding type                                                   */
      26             : /* _ (Word16) Es_pred_fx                : predicted scaled innov. energy Q8             */
      27             : /* _ (Word16[]) T_op_fx                 : open loop pitch Q0                                    */
      28             : /* _ (Word16[]) voicing_fx          : floating pitch values for each subframe Q15*/
      29             : /* _ (Word16[]) res_fx                  : residual signal                               Q_new    */
      30             : /* _ (Word16[]) exc_fx                  : adapt. excitation exc (Qnew)                   */
      31             : /* _ (Word16[]) exc2_fx                 : adapt. excitation/total exc (Qnew)     */
      32             : /* _ (Word16[]) pitch_buf_fx    : floating pitch values for each subframe Q6*/
      33             : /* _ (Word16[]) *wH1,           : Weighted impulses response mask        */
      34             : /* _ (Word16) shift                     :       shift                                                            */
      35             : /* _ (Word16) Q_new                     :                                            */
      36             : /*-----------------------------------------------------------------------*/
      37             : /* OUTPUT ARGUMENTS :                                                                                                    */
      38             : /* _ (Word16[]) exc_fx                  : adapt. excitation exc (Qnew)                   */
      39             : /* _ (Word16[]) exc2_fx                 : adapt. excitation/total exc (Qnew)     */
      40             : /* _ (Word16[]) syn_fx                  :core synthesis                                              */
      41             : /* _ (Word16[]) voice_factors_fx: voicing factors                               Q15              */
      42             : /* _ (Word16[]) bwe_exc_fx              : excitation for SWB TBE        Q0               */
      43             : /*-----------------------------------------------------------------------*/
      44             : 
      45             : /*-----------------------------------------------------------------------*/
      46             : /* RETURN ARGUMENTS :                                                                                                    */
      47             : /* _ None                                                                                                                                */
      48             : /*=======================================================================*/
      49             : 
      50           8 : void enc_pit_exc_fx(
      51             :     Encoder_State *st_fx,              /* i/o: State structure                                  */
      52             :     const Word16 *speech,              /* i  : Input speech                                     Q_new-1*/
      53             :     const Word16 Aw[],                 /* i  : weighted A(z) unquantized for subframes          Q12*/
      54             :     const Word16 Aq[],                 /* i  : 12k8 Lp coefficient                              Q12*/
      55             :     const Word16 Es_pred,              /* i  : predicted scaled innov. energy                   Q8*/
      56             :     const Word16 *res,                 /* i  : residual signal                                  Q_new*/
      57             :     Word16 *synth,                     /* i/o: core synthesis                                   Q_new*/
      58             :     Word16 *exc,                       /* i/o: current non-enhanced excitation                  Q_new*/
      59             :     Word16 *T0,                        /* i/o: close loop integer pitch                         Q0*/
      60             :     Word16 *T0_frac,                   /* i/o: close-loop pitch period - fractional part        Q0*/
      61             :     Word16 *pitch_buf,                 /* i/o: Fractionnal per subframe pitch                   Q6*/
      62             :     const Word16 nb_subfr,             /* i  : Number of subframe considered                    Q0*/
      63             :     Word16 *gpit,                      /* o  : pitch mean gpit                                  Q15*/
      64             :     Word16 *saved_bit_pos,             /* o  : saved position in the bitstream before pitch contribution        Q0*/
      65             :     const Word16 tdm_Pitch_reuse_flag, /* i  : primary channel pitch reuse flag                                 Q0*/
      66             :     const Word16 tdm_Pri_pitch_buf[],  /* i  : primary channel pitch buffer                                             Q6*/
      67             :     Word16 Q_new,
      68             :     Word16 shift )
      69             : {
      70             :     Word16 xn[PIT_EXC_L_SUBFR];             /* Target vector for pitch search    */
      71             :     Word16 xn2[PIT_EXC_L_SUBFR];            /* Target vector for codebook search */
      72             :     Word16 h1[PIT_EXC_L_SUBFR + ( M + 1 )]; /* Impulse response vector           */
      73             :     Word16 y1[PIT_EXC_L_SUBFR];             /* Filtered adaptive excitation      */
      74             :     Word16 code[2 * L_SUBFR];               /* Fixed codebook excitation         */
      75             :     Word16 y2[2 * L_SUBFR];                 /* Filtered algebraic excitation     */
      76             :     Word16 voice_fac;                       /* Voicing factor                    */
      77             :     Word32 gain_code;                       /* Gain of code                      */
      78             :     Word16 gain_inov;                       /* inovation gain                    */
      79             :     Word16 gain_pit;                        /* Pitch gain                        */
      80             :     Word16 pit_idx, i_subfr;                /* tmp variables                     */
      81             :     Word16 T0_min, T0_max;                  /* pitch variables                   */
      82             :     Word16 g_corr[10];                      /* ACELP correlation values + gain pitch */
      83             :     Word16 clip_gain, i;                    /* LSF clip gain and LP flag         */
      84             :     const Word16 *p_Aw, *p_Aq;              /* pointer to LP filter coefficient vector */
      85             :     Word16 cn1[L_SUBFR], *cn;               /* (Used only when L_subfr == L_SUBFR) Target vector in residual domain  */
      86             :     Word16 *pt_pitch;                       /* pointer to floating pitch         */
      87             :     Word16 L_subfr;
      88             :     Word16 cum_gpit, gpit_tmp;
      89             :     Word32 Local_BR, Pitch_BR;
      90           8 :     Word16 Pitch_CT, unbits_PI = 0; /* saved bits for PI                 */
      91           8 :     move16();
      92             :     Word32 norm_gain_code;
      93             :     Word16 pitch_limit_flag;
      94             :     Word16 h2[PIT_EXC_L_SUBFR + ( M + 1 )]; /* Impulse response vector           */
      95             :     Word32 Ltmp;
      96             :     Word32 Lgcode;
      97             :     Word16 gcode16;
      98             :     Word16 shift_wsp;
      99             :     Word16 lp_select, lp_flag;
     100             :     Word16 use_fcb;
     101             :     Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */
     102             :     Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/
     103           8 :     SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas;
     104           8 :     BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
     105           8 :     GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc;
     106           8 :     LPD_state_HANDLE hLPDmem = st_fx->hLPDmem;
     107             : 
     108             :     /*------------------------------------------------------------------*
     109             :      * Initialization
     110             :      *------------------------------------------------------------------*/
     111             : 
     112           8 :     pitch_limit_flag = 1;
     113           8 :     move16(); /* always extended pitch Q range */
     114           8 :     use_fcb = 0;
     115           8 :     unbits_PI = 0;
     116           8 :     move16();
     117           8 :     move16();
     118           8 :     Pitch_CT = GENERIC;
     119           8 :     move16();
     120             : 
     121           8 :     test();
     122           8 :     test();
     123           8 :     IF( st_fx->GSC_IVAS_mode > 0 && ( st_fx->GSC_noisy_speech || GT_32( st_fx->core_brate, GSC_H_RATE_STG ) ) )
     124             :     {
     125           0 :         Local_BR = ACELP_8k00;
     126           0 :         Pitch_BR = ACELP_8k00;
     127           0 :         move32();
     128           0 :         move32();
     129           0 :         IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
     130             :         {
     131           0 :             Local_BR = ACELP_14k80;
     132           0 :             move32();
     133           0 :             if ( st_fx->GSC_IVAS_mode > 0 )
     134             :             {
     135           0 :                 Local_BR = ACELP_9k60;
     136           0 :                 move32();
     137             :             }
     138           0 :             Pitch_BR = st_fx->core_brate; /* Q0 */
     139           0 :             move32();
     140             :         }
     141             :     }
     142           8 :     ELSE IF( st_fx->GSC_noisy_speech )
     143             :     {
     144           0 :         Local_BR = ACELP_7k20;
     145           0 :         move32();
     146           0 :         Pitch_BR = ACELP_7k20;
     147           0 :         move32();
     148           0 :         Pitch_CT = GENERIC;
     149           0 :         move16();
     150           0 :         if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
     151             :         {
     152           0 :             Pitch_BR = st_fx->core_brate; /* Q0 */
     153           0 :             move32();
     154             :         }
     155             :     }
     156             :     ELSE
     157             :     {
     158           8 :         Local_BR = ACELP_7k20;
     159           8 :         move32();
     160           8 :         Pitch_BR = st_fx->core_brate; /* Q0 */
     161           8 :         move32();
     162           8 :         Pitch_CT = AUDIO;
     163           8 :         move16();
     164             : 
     165           8 :         IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
     166             :         {
     167           0 :             Local_BR = ACELP_13k20;
     168           0 :             move32();
     169           0 :             Pitch_CT = GENERIC;
     170           0 :             move16();
     171             :         }
     172             :     }
     173           8 :     gain_code = 0;
     174           8 :     move16();
     175             : 
     176           8 :     IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
     177             :     {
     178           0 :         T0_max = PIT16k_MAX;
     179           0 :         T0_min = PIT16k_MIN;
     180             :     }
     181             :     ELSE
     182             :     {
     183           8 :         T0_max = PIT_MAX;
     184           8 :         move16();
     185           8 :         T0_min = PIT_MIN;
     186           8 :         move16();
     187             :     }
     188           8 :     cum_gpit = 0;
     189           8 :     move16();
     190             : 
     191           8 :     L_subfr = mult_r( st_fx->L_frame, div_s( 1, nb_subfr ) ); /* Q0 */
     192             : 
     193           8 :     lp_flag = st_fx->acelp_cfg.ltf_mode; /* Q0 */
     194             : 
     195           8 :     test();
     196           8 :     test();
     197           8 :     test();
     198           8 :     test();
     199           8 :     test();
     200           8 :     test();
     201           8 :     test();
     202           8 :     test();
     203           8 :     IF( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) &&
     204             :                                                           ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) ||
     205             :                                                             ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) &&
     206             :           EQ_16( L_subfr, L_SUBFR ) ) )
     207             :     {
     208           0 :         use_fcb = 1;
     209           0 :         move16();
     210             :     }
     211           8 :     ELSE IF( st_fx->GSC_IVAS_mode > 0 && EQ_16( L_subfr, 2 * L_SUBFR ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) )
     212             :     {
     213           0 :         use_fcb = 2;
     214           0 :         st_fx->acelp_cfg.fcb_mode = 1;
     215           0 :         move16();
     216           0 :         move16();
     217           0 :         set16_fx( st_fx->acelp_cfg.gains_mode, 6, NB_SUBFR );
     218           0 :         set16_fx( st_fx->acelp_cfg.pitch_bits, 9, NB_SUBFR );
     219           0 :         set16_fx( st_fx->acelp_cfg.fixed_cdk_index, 14, NB_SUBFR16k );
     220             :     }
     221             : 
     222           8 :     *saved_bit_pos = st_fx->next_bit_pos_fx;
     223           8 :     move16();
     224             : 
     225             :     /*------------------------------------------------------------------*
     226             :      * ACELP subframe loop
     227             :      *------------------------------------------------------------------*/
     228             : 
     229           8 :     cn = NULL;
     230           8 :     if ( EQ_16( L_subfr, L_SUBFR ) )
     231             :     {
     232           0 :         cn = cn1;
     233           0 :         move16();
     234             :     }
     235           8 :     p_Aw = Aw;
     236             : 
     237           8 :     p_Aq = Aq;
     238           8 :     pt_pitch = pitch_buf; /* pointer to the pitch buffer */
     239           8 :     shift_wsp = add( Q_new, shift );
     240             : 
     241          24 :     FOR( i_subfr = 0; i_subfr < st_fx->L_frame; i_subfr += L_subfr )
     242             :     {
     243             : 
     244             :         /*----------------------------------------------------------------*
     245             :          * Bandwidth expansion of A(z) filter coefficients
     246             :          * Find the the excitation search target "xn" and innovation
     247             :          *   target in residual domain "cn"
     248             :          * Compute impulse response, h1[], of weighted synthesis filter
     249             :          *----------------------------------------------------------------*/
     250             : 
     251          16 :         Copy( &res[i_subfr], &exc[i_subfr], L_subfr ); /* Q_new */
     252             :                                                        /* condition on target (compared to float) has been put outside the loop */
     253          16 :         find_targets_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq,
     254          16 :                          res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1 );
     255          16 :         Copy_Scale_sig( h1, h2, L_subfr, -2 );     /* Q13 */
     256          16 :         Scale_sig( h1, L_subfr, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */
     257             : 
     258             :         /* scaling of xn[] to limit dynamic at 12 bits */
     259          16 :         Scale_sig( xn, L_subfr, shift ); /* Q_new - 1 + shift */
     260             : 
     261             :         /*----------------------------------------------------------------*
     262             :          * Close-loop pitch search and quantization
     263             :          * Adaptive exc. construction
     264             :          *----------------------------------------------------------------*/
     265             : 
     266          32 :         *pt_pitch = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, Pitch_BR, 0, st_fx->L_frame, Pitch_CT, &pitch_limit_flag, i_subfr, exc,
     267          16 :                                    L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, st_fx->element_mode, Q_new ); /* Q6 */
     268             : 
     269             : 
     270             :         /*-----------------------------------------------------------------*
     271             :          * Find adaptive exitation
     272             :          *-----------------------------------------------------------------*/
     273             : 
     274          16 :         pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_subfr + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP );
     275             : 
     276             :         /*-----------------------------------------------------------------*
     277             :          * Gain clipping test to avoid unstable synthesis on frame erasure
     278             :          * or in case of floating point encoder & fixed p. decoder
     279             :          *-----------------------------------------------------------------*/
     280             : 
     281          16 :         clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, AUDIO, xn, st_fx->clip_var_fx, sub( shift_wsp, 1 ) ); /* Q0 */
     282             : 
     283             :         /*-----------------------------------------------------------------*
     284             :          * Codebook target computation
     285             :          * (No LP filtering of the adaptive excitation)
     286             :          *-----------------------------------------------------------------*/
     287             : 
     288          16 :         lp_select = lp_filt_exc_enc_fx( MODE1, AUDIO, i_subfr, exc, h1, xn, y1, xn2, L_subfr, st_fx->L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */
     289             : 
     290          16 :         IF( EQ_16( lp_flag, NORMAL_OPERATION ) )
     291             :         {
     292           0 :             push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 );
     293             :         }
     294             : 
     295             :         /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit;*/
     296          16 :         hSpMusClas->lowrate_pitchGain = round_fx_sat( L_mac_sat( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit ) ); /*Q14*Q16(0.1) + Q15 -> Q15*/
     297             : 
     298          16 :         gpit_tmp = gain_pit;
     299          16 :         move16(); /*Q14*/
     300          16 :         test();
     301          16 :         IF( use_fcb > 0 )
     302             :         {
     303             :             /* h2 in Q12 for codebook search */
     304             :             /* h1 has been scaled with 1 + shift so we need to remove 2 and (1+shift) = -3 - shift*/
     305           0 :             Copy_Scale_sig( h1, h2, L_subfr, sub( -2 - 1, shift ) );
     306             :         }
     307             : 
     308          16 :         IF( use_fcb == 0 )
     309             :         {
     310          16 :             IF( GE_32( st_fx->core_brate, MIN_RATE_FCB ) )
     311             :             {
     312           0 :                 pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 32 ); /* Q0 */
     313           0 :                 push_indice( hBstr, IND_PIT_IDX, pit_idx, 5 );
     314             :             }
     315             :             ELSE
     316             :             {
     317          16 :                 pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 16 ); /* Q0 */
     318          16 :                 push_indice( hBstr, IND_PIT_IDX, pit_idx, 4 );
     319             :             }
     320             :         }
     321           0 :         ELSE IF( use_fcb == 2 )
     322             :         {
     323             :             /*-----------------------------------------------------------------*
     324             :              * Innovation encoding
     325             :              *-----------------------------------------------------------------*/
     326             : 
     327           0 :             inov_encode_fx( st_fx, st_fx->core_brate, 0, st_fx->L_frame, st_fx->last_L_frame, GENERIC, st_fx->bwidth, 0, i_subfr, -1, p_Aq,
     328           0 :                             gain_pit, cn, exc, h2, st_fx->hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, 2 * L_SUBFR, shift );
     329             : 
     330             :             /*-----------------------------------------------------------------*
     331             :              * Gain encoding
     332             :              *-----------------------------------------------------------------*/
     333             : 
     334           0 :             gain_enc_lbr_fx( st_fx->hBstr, st_fx->acelp_cfg.gains_mode, GENERIC, i_subfr, xn, y1, shift_wsp, y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR,
     335           0 :                              st_fx->element_mode );
     336             :         }
     337             :         ELSE
     338             :         {
     339             :             /*-----------------------------------------------------------------*
     340             :              * Innovation & gain encoding
     341             :              *-----------------------------------------------------------------*/
     342             : 
     343           0 :             inov_encode_fx( st_fx, Local_BR, 0, st_fx->L_frame, st_fx->last_L_frame, LOCAL_CT, WB, 1, i_subfr, -1, p_Aq,
     344           0 :                             gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift );
     345             : 
     346             :             /*-----------------------------------------------------------------*
     347             :              * Gain encoding
     348             :              *-----------------------------------------------------------------*/
     349             : 
     350           0 :             gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_FRAME, i_subfr, -1, xn, y1, shift_wsp, y2, code, Es_pred,
     351             :                                &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain );
     352             :         }
     353             : 
     354          16 :         gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx );
     355             : 
     356          16 :         Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/
     357          16 :         gcode16 = round_fx_sat( Lgcode );
     358          16 :         IF( use_fcb != 0 )
     359             :         {
     360           0 :             hLPDmem->tilt_code = Est_tilt2( &exc[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); /* Q15 */
     361           0 :             move16();
     362             :         }
     363             :         ELSE
     364             :         {
     365          16 :             hLPDmem->tilt_code = 0;
     366          16 :             move16();
     367             :         }
     368             : 
     369             :         /*-----------------------------------------------------------------*
     370             :          * Update memory of the weighting filter
     371             :          *-----------------------------------------------------------------*/
     372             : 
     373          16 :         IF( use_fcb != 0 )
     374             :         {
     375           0 :             Ltmp = L_mult( gcode16, y2[L_subfr - 1] ); /* Q10 + Q_new */
     376           0 :             Ltmp = L_shl_sat( Ltmp, add( 5, shift ) ); /* Q15 + Q_new + shift */
     377           0 :             Ltmp = L_negate( Ltmp );
     378           0 :             Ltmp = L_mac_sat( Ltmp, xn[L_subfr - 1], 16384 );    /* Q_new + Q15 + shift */
     379           0 :             Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); /* Q_new + Q15 + shift */
     380           0 :             Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) );           /* Q_new + 15 */
     381           0 :             hLPDmem->mem_w0 = round_fx_sat( Ltmp );              /*Q_new-1         */
     382           0 :             move16();
     383             :         }
     384             :         ELSE
     385             :         {
     386          16 :             Ltmp = L_mult( xn[L_subfr - 1], 16384 );             /* Q_new + 14 -shift */
     387          16 :             Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); /* Q_new + 14 -shift */
     388          16 :             Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) );           /* Q_new + 15 */
     389          16 :             hLPDmem->mem_w0 = round_fx_sat( Ltmp );              /*Q_new-1         */
     390          16 :             move16();
     391             :         }
     392             : 
     393             :         /*-----------------------------------------------------------------*
     394             :          * Construct adaptive part of the excitation
     395             :          * Save the non-enhanced excitation for FEC_exc
     396             :          *-----------------------------------------------------------------*/
     397             : 
     398          16 :         IF( use_fcb != 0 )
     399             :         {
     400           0 :             FOR( i = 0; i < L_subfr; i++ )
     401             :             {
     402             :                 /* code in Q9, gain_pit in Q14 */
     403           0 :                 Ltmp = L_mult( gcode16, code[i] );                    /* Q10 + Q_new */
     404           0 :                 Ltmp = L_shl_sat( Ltmp, 5 );                          /* Q15 + Q_new */
     405           0 :                 Ltmp = L_mac_sat( Ltmp, exc[i + i_subfr], gain_pit ); /* Q15 + Q_new */
     406           0 :                 Ltmp = L_shl_sat( Ltmp, 1 );                          /* saturation can occur here              Q_new + Q16*/
     407           0 :                 exc[i + i_subfr] = round_fx_sat( Ltmp );              /* Q_new */
     408           0 :                 move16();
     409             :             }
     410             :         }
     411             :         ELSE
     412             :         {
     413        2064 :             FOR( i = 0; i < L_subfr; i++ )
     414             :             {
     415             : 
     416        2048 :                 Ltmp = L_mult( exc[i + i_subfr], gain_pit ); /* Q15 + Q_new */
     417        2048 :                 Ltmp = L_shl_sat( Ltmp, 1 );                 /* saturation can occur here       Q16 + Q_new */
     418        2048 :                 exc[i + i_subfr] = round_fx_sat( Ltmp );     /* Q_new */
     419             :             }
     420             :         }
     421             : 
     422             :         /*-----------------------------------------------------------------*
     423             :          * Synthesize speech to update mem_syn[].
     424             :          * Update A(z) filters
     425             :          *-----------------------------------------------------------------*/
     426             : 
     427          16 :         Syn_filt_s( 1, p_Aq, M, &exc[i_subfr], &synth[i_subfr], L_subfr, hGSCEnc->mem_syn_tmp_fx, 1 );
     428             : 
     429          16 :         IF( EQ_16( L_subfr, 5 * L_SUBFR ) )
     430             :         {
     431           0 :             cum_gpit = gpit_tmp; /* Q14 */
     432           0 :             move16();
     433           0 :             pt_pitch++;
     434           0 :             *pt_pitch = *( pt_pitch - 1 );
     435           0 :             move16();
     436           0 :             pt_pitch++;
     437           0 :             *pt_pitch = *( pt_pitch - 1 );
     438           0 :             move16();
     439           0 :             pt_pitch++;
     440           0 :             *pt_pitch = *( pt_pitch - 1 );
     441           0 :             move16();
     442           0 :             pt_pitch++;
     443           0 :             *pt_pitch = *( pt_pitch - 1 );
     444           0 :             move16();
     445           0 :             pt_pitch++;
     446             : 
     447           0 :             p_Aw += 5 * ( M + 1 );
     448           0 :             p_Aq += 5 * ( M + 1 );
     449             :         }
     450          16 :         ELSE IF( EQ_16( L_subfr, 5 * L_SUBFR / 2 ) )
     451             :         {
     452           0 :             IF( i_subfr == 0 )
     453             :             {
     454           0 :                 cum_gpit = mult_r( gpit_tmp, 13107 /* .4f in Q15 */ ); /* Q14 */
     455           0 :                 pt_pitch++;
     456           0 :                 *pt_pitch = *( pt_pitch - 1 );
     457           0 :                 move16();
     458           0 :                 pt_pitch++;
     459           0 :                 p_Aw += 2 * ( M + 1 );
     460           0 :                 p_Aq += 2 * ( M + 1 );
     461             :             }
     462             :             ELSE
     463             :             {
     464           0 :                 cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 19660 /* 0.6 in Q15 */ ) ); /* Q14 */
     465           0 :                 pt_pitch++;
     466           0 :                 *pt_pitch = *( pt_pitch - 1 );
     467           0 :                 move16();
     468           0 :                 pt_pitch++;
     469           0 :                 *pt_pitch = *( pt_pitch - 1 );
     470           0 :                 move16();
     471           0 :                 pt_pitch++;
     472           0 :                 p_Aw += 3 * ( M + 1 );
     473           0 :                 p_Aq += 3 * ( M + 1 );
     474             :             }
     475             :         }
     476          16 :         ELSE IF( EQ_16( L_subfr, 2 * L_SUBFR ) )
     477             :         {
     478          16 :             IF( i_subfr == 0 )
     479             :             {
     480           8 :                 cum_gpit = mult_r( gpit_tmp, 16384 /* 0.5 in Q15 */ ); /* Q14 */
     481             :             }
     482             :             ELSE
     483             :             {
     484           8 :                 cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 16384 /* 0.5 in Q15 */ ) ); /* Q14 */
     485             :             }
     486          16 :             p_Aw += 2 * ( M + 1 );
     487          16 :             move16();
     488          16 :             p_Aq += 2 * ( M + 1 );
     489          16 :             move16();
     490          16 :             pt_pitch++;
     491          16 :             *pt_pitch = *( pt_pitch - 1 );
     492          16 :             move16();
     493          16 :             pt_pitch++;
     494             :         }
     495           0 :         ELSE IF( EQ_16( L_subfr, 4 * L_SUBFR ) )
     496             :         {
     497           0 :             cum_gpit = gpit_tmp; /* Q14 */
     498           0 :             move16();
     499             : 
     500           0 :             pt_pitch++;
     501           0 :             *pt_pitch = *( pt_pitch - 1 );
     502           0 :             move16();
     503           0 :             pt_pitch++;
     504           0 :             *pt_pitch = *( pt_pitch - 1 );
     505           0 :             move16();
     506           0 :             pt_pitch++;
     507           0 :             *pt_pitch = *( pt_pitch - 1 );
     508           0 :             pt_pitch++;
     509           0 :             p_Aw += 4 * ( M + 1 );
     510           0 :             p_Aq += 4 * ( M + 1 );
     511             :         }
     512             :         ELSE
     513             :         {
     514           0 :             IF( i_subfr == 0 )
     515             :             {
     516             : 
     517           0 :                 cum_gpit = mult_r( gpit_tmp, 8192 /* 0.25 in Q15 */ ); /* Q14 */
     518             :             }
     519             :             ELSE
     520             :             {
     521           0 :                 cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 8192 /* 0.25 in Q15 */ ) ); /* Q14 */
     522             :             }
     523             : 
     524           0 :             pt_pitch++;
     525           0 :             p_Aw += ( M + 1 );
     526           0 :             p_Aq += ( M + 1 );
     527             :         }
     528             :     }
     529             : 
     530           8 :     cum_gpit = shl_sat( cum_gpit, 1 );                                   /*Q15*/
     531           8 :     *gpit = round_fx( L_mac( L_mult( 3277, *gpit ), 29491, cum_gpit ) ); /*Q15*/
     532             : 
     533           8 :     return;
     534             : }
     535             : 
     536             : 
     537       15087 : void enc_pit_exc_ivas_fx(
     538             :     Encoder_State *st_fx,              /* i/o: State structure                                  */
     539             :     const Word16 *speech,              /* i  : Input speech                                     Q_new-1*/
     540             :     const Word16 Aw[],                 /* i  : weighted A(z) unquantized for subframes          Q12*/
     541             :     const Word16 Aq[],                 /* i  : 12k8 Lp coefficient                              Q12*/
     542             :     const Word16 Es_pred,              /* i  : predicted scaled innov. energy                   Q8*/
     543             :     const Word16 *res,                 /* i  : residual signal                                  Q_new*/
     544             :     Word16 *synth,                     /* i/o: core synthesis                                   Q_new*/
     545             :     Word16 *exc,                       /* i/o: current non-enhanced excitation                  Q_new*/
     546             :     Word16 *T0,                        /* i/o: close loop integer pitch                         Q0*/
     547             :     Word16 *T0_frac,                   /* i/o: close-loop pitch period - fractional part        Q0*/
     548             :     Word16 *pitch_buf,                 /* i/o: Fractionnal per subframe pitch                   Q6*/
     549             :     const Word16 nb_subfr,             /* i  : Number of subframe considered                    Q0*/
     550             :     Word16 *gpit,                      /* o  : pitch mean gpit                                  Q15*/
     551             :     Word16 *saved_bit_pos,             /* o  : saved position in the bitstream before pitch contribution        Q0*/
     552             :     const Word16 tdm_Pitch_reuse_flag, /* i  : primary channel pitch reuse flag                                 Q0*/
     553             :     const Word16 tdm_Pri_pitch_buf[],  /* i  : primary channel pitch buffer                                             Q6*/
     554             :     Word16 Q_new,
     555             :     Word16 shift )
     556             : {
     557             :     Word16 xn[PIT_EXC_L_SUBFR];             /* Target vector for pitch search    */
     558             :     Word16 xn2[PIT_EXC_L_SUBFR];            /* Target vector for codebook search */
     559             :     Word16 h1[PIT_EXC_L_SUBFR + ( M + 1 )]; /* Impulse response vector           */
     560             :     Word16 cn[PIT_EXC_L_SUBFR];
     561             :     Word16 y1[PIT_EXC_L_SUBFR]; /* Filtered adaptive excitation      */
     562             :     Word16 code[2 * L_SUBFR];   /* Fixed codebook excitation         */
     563             :     Word16 y2[2 * L_SUBFR];     /* Filtered algebraic excitation     */
     564             :     Word16 voice_fac;           /* Voicing factor                    */
     565             :     Word32 gain_code;           /* Gain of code                      */
     566             :     Word16 gain_inov;           /* inovation gain                    */
     567             :     Word16 gain_pit;            /* Pitch gain                        */
     568             :     Word16 pit_idx, i_subfr;    /* tmp variables                     */
     569             :     Word16 T0_min, T0_max;      /* pitch variables                   */
     570             :     Word16 g_corr[10];          /* ACELP correlation values + gain pitch */
     571             :     Word16 clip_gain, i;        /* LSF clip gain and LP flag         */
     572             :     const Word16 *p_Aw, *p_Aq;  /* pointer to LP filter coefficient vector */
     573             :     Word16 *pt_pitch;           /* pointer to floating pitch         */
     574             :     Word16 L_subfr;
     575             :     Word16 cum_gpit, gpit_tmp;
     576             :     Word32 Local_BR, Pitch_BR;
     577       15087 :     Word16 Pitch_CT, unbits_PI = 0; /* saved bits for PI                 */
     578             :     Word32 norm_gain_code;
     579             :     Word16 pitch_limit_flag;
     580             :     Word16 h2[PIT_EXC_L_SUBFR + ( M + 1 )]; /* Impulse response vector           */
     581             :     Word32 Ltmp;
     582             :     Word32 Lgcode;
     583             :     Word16 gcode16;
     584             :     Word16 shift_wsp;
     585             :     Word16 lp_select, lp_flag;
     586             :     Word16 use_fcb;
     587             :     Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */
     588             :     Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/
     589             :     Word16 q_h1;
     590       15087 :     BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
     591       15087 :     GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc;
     592       15087 :     LPD_state_HANDLE hLPDmem = st_fx->hLPDmem;
     593             : 
     594             :     /*------------------------------------------------------------------*
     595             :      * Initialization
     596             :      *------------------------------------------------------------------*/
     597             : 
     598       15087 :     pitch_limit_flag = 1;
     599       15087 :     move16(); /* always extended pitch Q range */
     600       15087 :     use_fcb = 0;
     601       15087 :     unbits_PI = 0;
     602       15087 :     move16();
     603       15087 :     move16();
     604       15087 :     Pitch_CT = GENERIC;
     605       15087 :     move16();
     606       15087 :     set16_fx( cn, 0, PIT_EXC_L_SUBFR );
     607       15087 :     test();
     608       15087 :     test();
     609       15087 :     IF( st_fx->GSC_IVAS_mode > 0 && ( st_fx->GSC_noisy_speech || GT_32( st_fx->core_brate, GSC_H_RATE_STG ) ) )
     610             :     {
     611         109 :         Local_BR = ACELP_8k00;
     612         109 :         Pitch_BR = ACELP_8k00;
     613         109 :         move32();
     614         109 :         move32();
     615         109 :         IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
     616             :         {
     617           0 :             Local_BR = ACELP_14k80;
     618           0 :             move32();
     619           0 :             if ( st_fx->GSC_IVAS_mode > 0 )
     620             :             {
     621           0 :                 Local_BR = ACELP_9k60;
     622           0 :                 move32();
     623             :             }
     624           0 :             Pitch_BR = st_fx->core_brate;
     625           0 :             move32();
     626             :         }
     627             :     }
     628       14978 :     ELSE IF( st_fx->GSC_noisy_speech )
     629             :     {
     630         684 :         Local_BR = ACELP_7k20;
     631         684 :         move32();
     632         684 :         Pitch_BR = ACELP_7k20;
     633         684 :         move32();
     634         684 :         Pitch_CT = GENERIC;
     635         684 :         move16();
     636         684 :         if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
     637             :         {
     638           0 :             Pitch_BR = st_fx->core_brate;
     639           0 :             move32();
     640             :         }
     641             :     }
     642             :     ELSE
     643             :     {
     644       14294 :         Local_BR = ACELP_7k20;
     645       14294 :         move32();
     646       14294 :         Pitch_BR = st_fx->core_brate;
     647       14294 :         move32();
     648       14294 :         Pitch_CT = AUDIO;
     649       14294 :         move16();
     650             : 
     651       14294 :         if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
     652             :         {
     653        2659 :             Local_BR = ACELP_13k20;
     654        2659 :             move32();
     655        2659 :             Pitch_CT = GENERIC;
     656        2659 :             move16();
     657             :         }
     658             :     }
     659       15087 :     gain_code = 0;
     660       15087 :     move16();
     661             : 
     662       15087 :     IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
     663             :     {
     664        2659 :         T0_max = PIT16k_MAX;
     665        2659 :         T0_min = PIT16k_MIN;
     666             :     }
     667             :     ELSE
     668             :     {
     669       12428 :         T0_max = PIT_MAX;
     670       12428 :         move16();
     671       12428 :         T0_min = PIT_MIN;
     672       12428 :         move16();
     673             :     }
     674       15087 :     cum_gpit = 0;
     675       15087 :     move16();
     676             : 
     677       15087 :     L_subfr = mult_r( st_fx->L_frame, div_s( 1, nb_subfr ) ); /* Q0 */
     678             : 
     679       15087 :     lp_flag = st_fx->acelp_cfg.ltf_mode;
     680       15087 :     move16();
     681             : 
     682       15087 :     test();
     683       15087 :     test();
     684       15087 :     test();
     685       15087 :     test();
     686       15087 :     test();
     687       15087 :     test();
     688       15087 :     test();
     689       15087 :     test();
     690       15087 :     IF( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) &&
     691             :                                                           ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) ||
     692             :                                                             ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) &&
     693             :           EQ_16( L_subfr, L_SUBFR ) ) )
     694             :     {
     695         684 :         use_fcb = 1;
     696         684 :         move16();
     697             :     }
     698       14403 :     ELSE IF( st_fx->GSC_IVAS_mode > 0 && EQ_16( L_subfr, 2 * L_SUBFR ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) )
     699             :     {
     700        1975 :         use_fcb = 2;
     701        1975 :         st_fx->acelp_cfg.fcb_mode = 1;
     702        1975 :         move16();
     703        1975 :         move16();
     704        1975 :         set16_fx( st_fx->acelp_cfg.gains_mode, 6, NB_SUBFR );
     705        1975 :         set16_fx( st_fx->acelp_cfg.pitch_bits, 9, NB_SUBFR );
     706        1975 :         set16_fx( st_fx->acelp_cfg.fixed_cdk_index, 14, NB_SUBFR16k );
     707             :     }
     708             : 
     709       15087 :     *saved_bit_pos = st_fx->next_bit_pos_fx; /* Q0 */
     710       15087 :     move16();
     711             : 
     712             :     /*------------------------------------------------------------------*
     713             :      * ACELP subframe loop
     714             :      *------------------------------------------------------------------*/
     715             : 
     716       15087 :     p_Aw = Aw;
     717       15087 :     p_Aq = Aq;
     718       15087 :     pt_pitch = pitch_buf; /* pointer to the pitch buffer */
     719       15087 :     shift_wsp = add( Q_new, shift );
     720             : 
     721       44019 :     FOR( i_subfr = 0; i_subfr < st_fx->L_frame; i_subfr += L_subfr )
     722             :     {
     723             : 
     724             :         /*----------------------------------------------------------------*
     725             :          * Bandwidth expansion of A(z) filter coefficients
     726             :          * Find the the excitation search target "xn" and innovation
     727             :          *   target in residual domain "cn"
     728             :          * Compute impulse response, h1[], of weighted synthesis filter
     729             :          *----------------------------------------------------------------*/
     730             : 
     731       28932 :         Copy( &res[i_subfr], &exc[i_subfr], L_subfr ); /* Q_new */
     732             :         /* condition on target (compared to float) has been put outside the loop */
     733             : 
     734       28932 :         find_targets_ivas_fx( speech, hGSCEnc->mem_syn_tmp_fx, i_subfr, &hGSCEnc->mem_w0_tmp_fx, p_Aq,
     735       28932 :                               res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1 );
     736             : 
     737       28932 :         q_h1 = sub( 14, norm_s( h1[0] ) );
     738       28932 :         Copy_Scale_sig( h1, h2, L_subfr, sub( 11, q_h1 ) ); /*Q11*/
     739             : 
     740             :         /* scaling of xn[] to limit dynamic at 12 bits */
     741       28932 :         Scale_sig( xn, L_subfr, shift ); /* Q_new - 1 + shift */
     742             : 
     743             :         /*----------------------------------------------------------------*
     744             :          * Close-loop pitch search and quantization
     745             :          * Adaptive exc. construction
     746             :          *----------------------------------------------------------------*/
     747             : 
     748       57864 :         *pt_pitch = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, Pitch_BR, 0, st_fx->L_frame, Pitch_CT, &pitch_limit_flag, i_subfr, exc,
     749       28932 :                                    L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, st_fx->element_mode, Q_new ); /* Q6 */
     750             : 
     751       28932 :         Scale_sig( h1, L_subfr, sub( 14, q_h1 ) ); /* set h1[] in Q14 with scaling for convolution Q14*/
     752             : 
     753             :         /*-----------------------------------------------------------------*
     754             :          * Find adaptive exitation
     755             :          *-----------------------------------------------------------------*/
     756             : 
     757       28932 :         pred_lt4_ivas_fx( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_subfr + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP );
     758             : 
     759             :         /*-----------------------------------------------------------------*
     760             :          * Gain clipping test to avoid unstable synthesis on frame erasure
     761             :          * or in case of floating point encoder & fixed p. decoder
     762             :          *-----------------------------------------------------------------*/
     763             : 
     764       28932 :         clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, AUDIO, xn, st_fx->clip_var_fx, sub( shift_wsp, 1 ) ); /* Q0 */
     765             : 
     766             :         /*-----------------------------------------------------------------*
     767             :          * Codebook target computation
     768             :          * (No LP filtering of the adaptive excitation)
     769             :          *-----------------------------------------------------------------*/
     770             : 
     771       28932 :         lp_select = lp_filt_exc_enc_fx( MODE1, AUDIO, i_subfr, exc, h1, xn, y1, xn2, L_subfr, st_fx->L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */
     772             : 
     773             : 
     774       28932 :         IF( EQ_16( lp_flag, NORMAL_OPERATION ) )
     775             :         {
     776           0 :             push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 );
     777             :         }
     778             : 
     779       28932 :         st_fx->hSpMusClas->lowrate_pitchGain = mac_r( L_mult( 29491 /* 0.9 in Q15 */, st_fx->hSpMusClas->lowrate_pitchGain ), 3277 /* 0.1 in Q15 */, gain_pit ); /* Q14 */
     780             : 
     781       28932 :         gpit_tmp = gain_pit;
     782       28932 :         move16(); /*Q14*/
     783       28932 :         test();
     784       28932 :         IF( use_fcb > 0 )
     785             :         {
     786             :             /* h2 in Q12 for codebook search */
     787             :             /* h1 has been scaled with 1 + shift so we need to remove 2 and (1+shift) = -3 - shift*/
     788        6686 :             Copy_Scale_sig( h1, h2, L_subfr, sub( -2 - 1, shift ) );
     789             :         }
     790             : 
     791       28932 :         IF( use_fcb == 0 )
     792             :         {
     793       22246 :             IF( GE_32( st_fx->core_brate, MIN_RATE_FCB ) )
     794             :             {
     795         869 :                 pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 32 );
     796         869 :                 push_indice( hBstr, IND_PIT_IDX, pit_idx, 5 );
     797             :             }
     798             :             ELSE
     799             :             {
     800       21377 :                 pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 16 );
     801       21377 :                 push_indice( hBstr, IND_PIT_IDX, pit_idx, 4 );
     802             :             }
     803             :         }
     804        6686 :         ELSE IF( use_fcb == 2 )
     805             :         {
     806             :             /*-----------------------------------------------------------------*
     807             :              * Innovation encoding
     808             :              *-----------------------------------------------------------------*/
     809             : 
     810        3950 :             inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, st_fx->L_frame, st_fx->last_L_frame, GENERIC, st_fx->bwidth, 0, i_subfr, -1, p_Aq,
     811        3950 :                                  gain_pit, cn, exc, h2, st_fx->hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, 2 * L_SUBFR, shift, Q_new );
     812             : 
     813             :             /*-----------------------------------------------------------------*
     814             :              * Gain encoding
     815             :              *-----------------------------------------------------------------*/
     816             : 
     817        3950 :             gain_enc_lbr_fx( st_fx->hBstr, st_fx->acelp_cfg.gains_mode, GENERIC, i_subfr, xn, y1, sub( shift_wsp, 1 ), y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR,
     818        3950 :                              st_fx->element_mode );
     819             :         }
     820             :         ELSE
     821             :         {
     822             :             /*-----------------------------------------------------------------*
     823             :              * Innovation & gain encoding
     824             :              *-----------------------------------------------------------------*/
     825             : 
     826        2736 :             inov_encode_ivas_fx( st_fx, Local_BR, 0, st_fx->L_frame, st_fx->last_L_frame, LOCAL_CT, WB, 1, i_subfr, -1, p_Aq,
     827        2736 :                                  gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift, Q_new );
     828             : 
     829             :             /*-----------------------------------------------------------------*
     830             :              * Gain encoding
     831             :              *-----------------------------------------------------------------*/
     832             : 
     833        2736 :             gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, st_fx->L_frame, i_subfr, -1, xn, y1, sub( shift_wsp, 1 ), y2, code, Es_pred,
     834             :                                &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain );
     835             :         }
     836             : 
     837       28932 :         gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx );
     838             : 
     839       28932 :         Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/
     840       28932 :         gcode16 = round_fx_sat( Lgcode );
     841       28932 :         IF( use_fcb != 0 )
     842             :         {
     843        6686 :             hLPDmem->tilt_code = est_tilt_ivas_fx( &exc[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_subfr, 0 ); // Q15
     844        6686 :             move16();
     845             :         }
     846             :         ELSE
     847             :         {
     848       22246 :             hLPDmem->tilt_code = 0;
     849       22246 :             move16();
     850             :         }
     851             : 
     852             :         /*-----------------------------------------------------------------*
     853             :          * Update memory of the weighting filter
     854             :          *-----------------------------------------------------------------*/
     855             : 
     856       28932 :         IF( use_fcb != 0 )
     857             :         {
     858        6686 :             Ltmp = L_mult0( gcode16, y2[L_subfr - 1] );
     859        6686 :             Ltmp = L_shl_sat( Ltmp, add( 5, shift ) ); // Q_new+14+shift
     860        6686 :             Ltmp = L_negate( Ltmp );
     861        6686 :             Ltmp = L_mac_sat( Ltmp, xn[L_subfr - 1], 16384 );    // Q_new-1+15+shift
     862        6686 :             Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); // Q_new-1+15+shift
     863        6686 :             Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) );           // Q_new+15
     864        6686 :             hGSCEnc->mem_w0_tmp_fx = round_fx_sat( Ltmp );       /*Q_new-1         */
     865             :         }
     866             :         ELSE
     867             :         {
     868       22246 :             Ltmp = L_mult( xn[L_subfr - 1], 16384 );             // Q_new-1+15+shift
     869       22246 :             Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); // Q_new-1+15+shift
     870       22246 :             Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) );           // Q_new+15
     871       22246 :             hGSCEnc->mem_w0_tmp_fx = round_fx_sat( Ltmp );       /*Q_new-1         */
     872             :         }
     873             : 
     874             :         /*-----------------------------------------------------------------*
     875             :          * Construct adaptive part of the excitation
     876             :          * Save the non-enhanced excitation for FEC_exc
     877             :          *-----------------------------------------------------------------*/
     878             : 
     879       28932 :         IF( use_fcb != 0 )
     880             :         {
     881      687390 :             FOR( i = 0; i < L_subfr; i++ )
     882             :             {
     883             :                 /* code in Q9, gain_pit in Q14 */
     884      680704 :                 Ltmp = L_mult( gcode16, code[i] );                    /* Q10 + Q_new */
     885      680704 :                 Ltmp = L_shl_sat( Ltmp, 5 );                          /* Q15 + Q_new */
     886      680704 :                 Ltmp = L_mac_sat( Ltmp, exc[i + i_subfr], gain_pit ); /* Q15 + Q_new */
     887      680704 :                 Ltmp = L_shl_sat( Ltmp, 1 );                          /* saturation can occur here Q16 + Q_new */
     888      680704 :                 exc[i + i_subfr] = round_fx_sat( Ltmp );              /* Q_new */
     889      680704 :                 move16();
     890             :             }
     891             :         }
     892             :         ELSE
     893             :         {
     894     3373990 :             FOR( i = 0; i < L_subfr; i++ )
     895             :             {
     896             : 
     897     3351744 :                 Ltmp = L_mult( exc[i + i_subfr], gain_pit ); /* Q15 + Q_new */
     898     3351744 :                 Ltmp = L_shl_sat( Ltmp, 1 );                 /* saturation can occur here       Q16 + Q_new */
     899     3351744 :                 exc[i + i_subfr] = round_fx_sat( Ltmp );     /* Q_new */
     900     3351744 :                 move16();
     901             :             }
     902             :         }
     903             : 
     904             :         /*-----------------------------------------------------------------*
     905             :          * Synthesize speech to update mem_syn[].
     906             :          * Update A(z) filters
     907             :          *-----------------------------------------------------------------*/
     908             : 
     909       28932 :         Syn_filt_s( 1, p_Aq, M, &exc[i_subfr], &synth[i_subfr], L_subfr, hGSCEnc->mem_syn_tmp_fx, 1 );
     910             : 
     911       28932 :         IF( EQ_16( L_subfr, 5 * L_SUBFR ) )
     912             :         {
     913        2659 :             cum_gpit = gpit_tmp;
     914        2659 :             move16();
     915        2659 :             pt_pitch++;
     916        2659 :             *pt_pitch = *( pt_pitch - 1 );
     917        2659 :             move16();
     918        2659 :             pt_pitch++;
     919        2659 :             *pt_pitch = *( pt_pitch - 1 );
     920        2659 :             move16();
     921        2659 :             pt_pitch++;
     922        2659 :             *pt_pitch = *( pt_pitch - 1 );
     923        2659 :             move16();
     924        2659 :             pt_pitch++;
     925        2659 :             *pt_pitch = *( pt_pitch - 1 );
     926        2659 :             move16();
     927        2659 :             pt_pitch++;
     928             : 
     929        2659 :             p_Aw += 5 * ( M + 1 );
     930        2659 :             p_Aq += 5 * ( M + 1 );
     931             :         }
     932       26273 :         ELSE IF( EQ_16( L_subfr, 5 * L_SUBFR / 2 ) )
     933             :         {
     934           0 :             IF( i_subfr == 0 )
     935             :             {
     936           0 :                 cum_gpit = mult_r( gpit_tmp, 13107 /* .4f in Q15 */ ); /* Q14 */
     937           0 :                 pt_pitch++;
     938           0 :                 *pt_pitch = *( pt_pitch - 1 );
     939           0 :                 move16();
     940           0 :                 pt_pitch++;
     941           0 :                 p_Aw += 2 * ( M + 1 );
     942           0 :                 p_Aq += 2 * ( M + 1 );
     943             :             }
     944             :             ELSE
     945             :             {
     946           0 :                 cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 19660 /* 0.6 in Q15 */ ) ); /* Q14 */
     947           0 :                 pt_pitch++;
     948           0 :                 *pt_pitch = *( pt_pitch - 1 );
     949           0 :                 move16();
     950           0 :                 pt_pitch++;
     951           0 :                 *pt_pitch = *( pt_pitch - 1 );
     952           0 :                 move16();
     953           0 :                 pt_pitch++;
     954           0 :                 p_Aw += 3 * ( M + 1 );
     955           0 :                 p_Aq += 3 * ( M + 1 );
     956             :             }
     957             :         }
     958       26273 :         ELSE IF( EQ_16( L_subfr, 2 * L_SUBFR ) )
     959             :         {
     960        6606 :             IF( i_subfr == 0 )
     961             :             {
     962        3303 :                 cum_gpit = mult_r( gpit_tmp, 16384 /* 0.5 in Q15 */ ); /* Q14 */
     963             :             }
     964             :             ELSE
     965             :             {
     966        3303 :                 cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 16384 /* 0.5 in Q15 */ ) ); /* Q14 */
     967             :             }
     968        6606 :             p_Aw += 2 * ( M + 1 );
     969        6606 :             move16();
     970        6606 :             p_Aq += 2 * ( M + 1 );
     971        6606 :             move16();
     972        6606 :             pt_pitch++;
     973        6606 :             *pt_pitch = *( pt_pitch - 1 );
     974        6606 :             move16();
     975        6606 :             pt_pitch++;
     976             :         }
     977       19667 :         ELSE IF( EQ_16( L_subfr, 4 * L_SUBFR ) )
     978             :         {
     979        5611 :             cum_gpit = gpit_tmp;
     980        5611 :             move16();
     981             : 
     982        5611 :             pt_pitch++;
     983        5611 :             *pt_pitch = *( pt_pitch - 1 );
     984        5611 :             move16();
     985        5611 :             pt_pitch++;
     986        5611 :             *pt_pitch = *( pt_pitch - 1 );
     987        5611 :             move16();
     988        5611 :             pt_pitch++;
     989        5611 :             *pt_pitch = *( pt_pitch - 1 );
     990        5611 :             pt_pitch++;
     991        5611 :             p_Aw += 4 * ( M + 1 );
     992        5611 :             p_Aq += 4 * ( M + 1 );
     993             :         }
     994             :         ELSE
     995             :         {
     996       14056 :             IF( i_subfr == 0 )
     997             :             {
     998             : 
     999        3514 :                 cum_gpit = mult_r( gpit_tmp, 8192 /* 0.25 in Q15 */ ); /* Q14 */
    1000             :             }
    1001             :             ELSE
    1002             :             {
    1003       10542 :                 cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 8192 /* 0.25 in Q15 */ ) ); /* Q14 */
    1004             :             }
    1005             : 
    1006       14056 :             pt_pitch++;
    1007       14056 :             p_Aw += ( M + 1 );
    1008       14056 :             p_Aq += ( M + 1 );
    1009             :         }
    1010             :     }
    1011             : 
    1012       15087 :     cum_gpit = shl_sat( cum_gpit, 1 );                                   /*Q15*/
    1013       15087 :     *gpit = round_fx( L_mac( L_mult( 3277, *gpit ), 29491, cum_gpit ) ); /*Q15*/
    1014             : 
    1015       15087 :     return;
    1016             : }

Generated by: LCOV version 1.14