LCOV - code coverage report
Current view: top level - lib_enc - enc_tran_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ 6f242bfba52bceb943b7a88041852ac1e7eddc9b Lines: 299 319 93.7 %
Date: 2025-10-14 22:22:54 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"        /* Compilation switches                   */
       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      :  void encod_tran_fx ()                                                                              */
      15             : /*---------------------------------------------------------------------------------*/
      16             : /* PURPOSE       :                                                                                                                             */
      17             : /*---------------------------------------------------------------------------------*/
      18             : /* INPUT ARGUMENTS  :                                                                                                                  */
      19             : /*   (Word16) L_frame_fx          : length of the frame                           Q0   */
      20             : /*       (Word16[]) speech_fx     : input speech                                                                  Q0   */
      21             : /*       (Word16[]) Aq_fx                 : 12k8 Lp coefficient                                                   Q12  */
      22             : /*       (Word16[]) A_fx                  : unquantized A(z) filter with bandwidth expansion Q12  */
      23             : /*   (Word16) coder_type          : coding type                                                                    Q0  */
      24             : /*   (Word16) Es_pred_fx          : predicted scaled innov. energy                             Q8  */
      25             : /*       (Word16[]) T_op_fx               : open loop pitch                                    Q0  */
      26             : /*       (Word16[]) voicing_fx    : voicing                                                    Q15 */
      27             : /*       (Word16*) res_fx                 : residual signal                                    Q_new*/
      28             : /*       (Word16) gsc_attack_flag : Flag to indicate when an audio attack is deal with TM*/
      29             : /*       (Word16) shift                   : shift factor                                                                   */
      30             : /*       (Word16[]) Q_new                 : input scaling                                                      */
      31             : /*---------------------------------------------------------------------------------*/
      32             : /* OUTPUT ARGUMENTS :                                                                                                                  */
      33             : /*       (Word16*) voice_factors  : voicing factors                                                     Q15            */
      34             : /*---------------------------------------------------------------------------------*/
      35             : /* INPUT/OUTPUT ARGUMENTS :                                                                                                            */
      36             : /*   Encoder_State *st_fx  :Encoder state structure                                                    */
      37             : /*       (Word16*) syn_fx                 :core synthesis                                                       Qnew       */
      38             : /*       (Word16*) exc_fx                 :current non-enhanced excitation                      Q0             */
      39             : /*       (Word16*) exc2_fx                :current enhanced excitation                          Q0         */
      40             : /*       (Word16*) pitch_buf_fx   :floating pitch values for each subframe  Q6         */
      41             : /*   (Word16*) bwe_exc_fx         :excitation for SWB TBE                   Q0         */
      42             : /*---------------------------------------------------------------------------------*/
      43             : /* RETURN ARGUMENTS :                                                                                                                  */
      44             : /*                                       _ None                                                                                                    */
      45             : /*---------------------------------------------------------------------------------*/
      46             : 
      47         124 : Word16 encod_tran_fx(
      48             :     Encoder_State *st_fx,     /* i/o: state structure                                   */
      49             :     const Word16 speech_fx[], /* i  : input speech                                      Q0*/
      50             :     const Word16 Aw_fx[],     /* i  : weighted A(z) unquantized for subframes                   Q12*/
      51             :     const Word16 Aq_fx[],     /* i  : 12k8 Lp coefficient                               Q12*/
      52             :     const Word16 Es_pred_fx,  /* i  : predicted scaled innov. energy                    Q8*/
      53             :     const Word16 *res_fx,     /* i  : residual signal                                   Q_new*/
      54             :     Word16 *syn_fx,           /* i/o: core synthesis                                    Q_new*/
      55             :     Word16 *exc_fx,           /* i/o: current non-enhanced excitation                   Q0*/
      56             :     Word16 *exc2_fx,          /* i/o: current enhanced excitation                       Q0*/
      57             :     Word16 *pitch_buf_fx,     /* i/o: floating pitch values for each subframe           Q6*/
      58             :     Word16 *voice_factors,    /* o  : voicing factors                                   Q15*/
      59             :     Word16 *bwe_exc_fx,       /* i/o: excitation for SWB TBE                            Q0*/
      60             :     Word16 tc_subfr,          /* i/o: TC subframe classification                        Q0*/
      61             :     Word16 position,          /* i  : maximum of residual signal index                  Q0*/
      62             :     Word16 *unbits,           /* i/o: number of unused bits                             Q0*/
      63             :     const Word16 shift,       /* i  : Scaling to get 12 bits                            */
      64             :     const Word16 Q_new        /* i  : Input scaling                                     */
      65             : )
      66             : {
      67             :     Word16 xn[L_SUBFR];                       /* Target vector for pitch search               */
      68             :     Word16 xn2[L_SUBFR];                      /* Target vector for codebook search            */
      69             :     Word16 cn[L_SUBFR];                       /* Target vector in residual domain             */
      70             :     Word16 h1[L_SUBFR + ( M + 1 )];           /* Impulse response vector                      */
      71             :     Word16 h2_fx[L_SUBFR + ( M + 1 )];        /* Impulse response vector                      */
      72             :     Word16 code[L_SUBFR];                     /* Fixed codebook excitation                    */
      73             :     Word16 y1[L_SUBFR];                       /* Filtered adaptive excitation                 */
      74             :     Word16 y2[L_SUBFR];                       /* Filtered algebraic excitation                */
      75         124 :     Word16 gain_pit = 0, Gain_pitX2, gcode16; /* Pitch gain                                   */
      76             :     Word16 voice_fac;                         /* Voicing factor                               */
      77         124 :     Word32 gain_code = 0;                     /* Gain of code                                 */
      78             :     Word32 Lgcode;
      79         124 :     Word16 gain_inov = 0;               /* inovation gain                               */
      80             :     Word16 i, i_subfr, tmp1_fx, tmp_fx; /* tmp variables                                */
      81             :     Word16 unbits_ACELP;
      82             :     Word16 T0_min, T0_max;     /* pitch and TC variables                       */
      83             :     Word16 T0, T0_frac;        /* close loop integer pitch and fractional part */
      84             :     Word16 *pt_pitch;          /* pointer to floating pitch buffer             */
      85             :     Word16 g_corr[10];         /* ACELP correlation values  and gain pitch     */
      86             :     Word16 clip_gain;          /* LSF clip gain                                */
      87             :     const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector      */
      88         124 :     Word16 gain_preQ = 0;      /* Gain of prequantizer excitation              */
      89             :     Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation                      */
      90             :     Word16 Jopt_flag;          /* joint optimization flag                      */
      91         124 :     Word16 unbits_PI = 0;      /* saved bits for PI                            */
      92         124 :     Word32 norm_gain_code = 0;
      93             :     Word16 L_frame_fx;
      94             :     Word16 shift_wsp;
      95             :     Word32 L_tmp;
      96             : #ifndef ISSUE_1867_replace_overflow_libenc
      97             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      98             :     Flag Overflow = 0;
      99             :     move32();
     100             : #endif
     101             : #endif
     102         124 :     BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
     103         124 :     SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
     104         124 :     LPD_state_HANDLE hLPDmem = st_fx->hLPDmem;
     105             : 
     106         124 :     L_frame_fx = st_fx->L_frame;
     107         124 :     move16();
     108             :     /*------------------------------------------------------------------*
     109             :      * Initializations
     110             :      *------------------------------------------------------------------*/
     111         124 :     gain_pit = 0;
     112         124 :     move16();
     113         124 :     gain_code = L_deposit_l( 0 );
     114         124 :     gain_preQ = 0;
     115         124 :     move16();
     116         124 :     unbits_PI = 0;
     117         124 :     move16();
     118         124 :     IF( EQ_16( L_frame_fx, L_FRAME ) )
     119             :     {
     120          74 :         T0_max = PIT_MAX;
     121          74 :         move16();
     122          74 :         T0_min = PIT_MIN;
     123          74 :         move16();
     124             :     }
     125             :     ELSE /* L_frame == L_FRAME16k */
     126             :     {
     127          50 :         T0_max = PIT16k_MAX;
     128          50 :         move16();
     129          50 :         T0_min = PIT16k_MIN;
     130          50 :         move16();
     131             :     }
     132             : 
     133             :     /**unbits = 0;move16();*/
     134         124 :     Jopt_flag = 0;
     135         124 :     move16();
     136         124 :     unbits_ACELP = *unbits; /* Q0 */
     137         124 :     move16();
     138         124 :     *unbits = 0;
     139         124 :     move16();
     140             : 
     141         124 :     p_Aw = Aw_fx;            /* Q12 */
     142         124 :     p_Aq = Aq_fx;            /* Q12 */
     143         124 :     pt_pitch = pitch_buf_fx; /* Q6 */
     144         124 :     gain_preQ = 0;
     145         124 :     move16();
     146         124 :     set16_fx( code_preQ, 0, L_SUBFR );
     147         124 :     shift_wsp = add( Q_new, shift );
     148             : 
     149             :     /*----------------------------------------------------------------*
     150             :      * ACELP subframe loop
     151             :      *----------------------------------------------------------------*/
     152             : 
     153         670 :     FOR( i_subfr = 0; i_subfr < L_frame_fx; i_subfr += L_SUBFR )
     154             :     {
     155             :         /*----------------------------------------------------------------*
     156             :          * Find the the excitation search target "xn" and innovation
     157             :          *   target in residual domain "cn"
     158             :          * Compute impulse response, h1[], of weighted synthesis filter
     159             :          *----------------------------------------------------------------*/
     160             : 
     161         546 :         Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */
     162             : 
     163         546 :         find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq,
     164         546 :                          res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 );
     165             : 
     166         546 :         Copy_Scale_sig( h1, h2_fx, L_SUBFR, -2 );
     167         546 :         Scale_sig( h1, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */
     168             : 
     169             :         /* scaling of xn[] to limit dynamic at 12 bits */
     170         546 :         Scale_sig( xn, L_SUBFR, shift );
     171             : 
     172             :         /*-----------------------------------------------------------------*
     173             :          * TC: subframe determination &
     174             :          * adaptive/glottal part of excitation construction
     175             :          *-----------------------------------------------------------------*/
     176             : 
     177         546 :         transition_enc_fx( st_fx, i_subfr, &tc_subfr, &Jopt_flag, &position, &T0, &T0_frac, &T0_min, &T0_max, exc_fx, y1,
     178         546 :                            h1, xn, xn2, st_fx->clip_var_fx, &gain_pit, g_corr, &clip_gain, &pt_pitch, bwe_exc_fx, &unbits_ACELP, Q_new, shift );
     179             : 
     180             :         /*-----------------------------------------------------------------*
     181             :          * Transform domain contribution encoding - active frames
     182             :          *-----------------------------------------------------------------*/
     183             : 
     184         546 :         IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) )
     185             :         {
     186         250 :             transf_cdbk_enc_fx( st_fx, 0, i_subfr, cn, exc_fx, p_Aq, Aw_fx, h1, xn, xn2, y1, y2, Es_pred_fx,
     187             :                                 &gain_pit, gain_code, g_corr, clip_gain, &gain_preQ, code_preQ, unbits, Q_new, shift );
     188             :         }
     189             : 
     190             :         /*-----------------------------------------------------------------*
     191             :          * ACELP codebook search + pitch sharpening
     192             :          *-----------------------------------------------------------------*/
     193             : 
     194         546 :         inov_encode_fx( st_fx, st_fx->core_brate, 0, L_frame_fx, st_fx->last_L_frame, st_fx->coder_type, st_fx->bwidth, st_fx->sharpFlag,
     195         546 :                         i_subfr, tc_subfr, p_Aq, gain_pit, cn, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift );
     196             : 
     197         546 :         test();
     198         546 :         test();
     199         546 :         test();
     200         546 :         if ( ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) && ( tc_subfr == 0 ) && ( EQ_16( i_subfr, L_SUBFR ) ) && ( EQ_16( T0, 2 * L_SUBFR ) ) )
     201             :         {
     202           7 :             Jopt_flag = 1;
     203           7 :             move16();
     204             :         }
     205             :         /*-----------------------------------------------------------------*
     206             :          * Quantize the gains
     207             :          * Test quantized gain of pitch for pitch clipping algorithm
     208             :          * Update tilt of code: 0.0 (unvoiced) to 0.5 (voiced)
     209             :          *-----------------------------------------------------------------*/
     210         546 :         IF( Jopt_flag == 0 )
     211             :         {
     212             :             /* SQ gain_code */
     213          90 :             gain_enc_tc_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y2, code, Es_pred_fx,
     214             :                             &gain_pit, &gain_code, &gain_inov, &norm_gain_code, shift_wsp );
     215             :         }
     216             :         ELSE
     217             :         {
     218         456 :             IF( GT_32( st_fx->core_brate, ACELP_32k ) )
     219             :             {
     220             :                 /* SQ gain_pit and gain_code */
     221         238 :                 gain_enc_SQ_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y1, y2, code, Es_pred_fx,
     222             :                                 &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain, shift_wsp );
     223             :             }
     224             :             ELSE
     225             :             {
     226             :                 /* VQ gain_pit and gain_code */
     227         218 :                 gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame_fx, i_subfr, tc_subfr, xn, y1, shift_wsp, y2, code, Es_pred_fx,
     228             :                                    &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain );
     229             :             }
     230             :         }
     231         546 :         gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx );
     232             : 
     233             : #ifdef ISSUE_1867_replace_overflow_libenc
     234         546 :         Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/
     235         546 :         gcode16 = round_fx_sat( Lgcode );
     236             : #else
     237             :         Lgcode = L_shl_o( gain_code, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/
     238             :         gcode16 = round_fx_o( Lgcode, &Overflow );
     239             : #endif
     240         546 :         hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); /* Q15  */
     241             :         /*-----------------------------------------------------------------*
     242             :          * Update memory of the weighting filter
     243             :          *-----------------------------------------------------------------*/
     244             : 
     245             :         /*st->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]);*/
     246         546 :         L_tmp = L_mult( gcode16, y2[L_SUBFR - 1] ); /* Q10 + Q_new */
     247         546 :         L_tmp = L_shl( L_tmp, add( 5, shift ) );    /* Q15 + Q_new + shift */
     248         546 :         L_tmp = L_negate( L_tmp );
     249         546 :         L_tmp = L_mac( L_tmp, xn[L_SUBFR - 1], 16384 );
     250         546 :         L_tmp = L_msu( L_tmp, y1[L_SUBFR - 1], gain_pit );
     251         546 :         L_tmp = L_shl_sat( L_tmp, sub( 1, shift ) ); /* Q_new + 15 */
     252         546 :         hLPDmem->mem_w0 = round_fx_sat( L_tmp );     /*Q_new-1*/
     253             :         /*-----------------------------------------------------------------*
     254             :          * Construct adaptive part of the excitation
     255             :          * Save the non-enhanced excitation for FEC_exc
     256             :          *-----------------------------------------------------------------*/
     257             : 
     258             :         /* Here, all these conditions have one purpose: to use   */
     259             :         /* the most efficient loop (the one with the least ops)  */
     260             :         /* This is done by upscaling gain_pit_fx and/or gain_code16 */
     261             :         /* when they don't use all 16 bits of precision          */
     262             : 
     263             :         /* exc Q_exc, gpit Q14, code Q12, gcode Q0 */
     264         546 :         IF( norm_s( gain_pit ) == 0 )
     265             :         {
     266       12350 :             FOR( i = 0; i < L_SUBFR; i++ )
     267             :             {
     268       12160 :                 exc2_fx[i + i_subfr] = round_fx_sat( L_shl_sat( L_mult_sat( gain_pit, exc_fx[i + i_subfr] ), 1 ) ); /* Q_new */
     269             :             }
     270             :         }
     271             :         ELSE
     272             :         {
     273         356 :             Gain_pitX2 = shl( gain_pit, 1 ); /* Q15 */
     274       23140 :             FOR( i = 0; i < L_SUBFR; i++ )
     275             :             {
     276       22784 :                 exc2_fx[i + i_subfr] = mult_r( Gain_pitX2, exc_fx[i + i_subfr] ); /* Q_new */
     277             :             }
     278             :         }
     279             : 
     280             :         /*-----------------------------------------------------------------*
     281             :          * Construct adaptive part of the excitation
     282             :          * Save the non-enhanced excitation for FEC_exc
     283             :          *-----------------------------------------------------------------*/
     284       35490 :         FOR( i = 0; i < L_SUBFR; i++ )
     285             :         {
     286             :             /* code in Q9, gain_pit in Q14 */
     287       34944 :             L_tmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new  */
     288             : #ifdef ISSUE_1867_replace_overflow_libenc
     289       34944 :             L_tmp = L_shl_sat( L_tmp, 5 );                             /* Q15 + Q_new */
     290       34944 :             L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr], gain_pit ); /* Q15 + Q_new */
     291       34944 :             L_tmp = L_shl_sat( L_tmp, 1 );                             /* saturation can occur here Q16 + Q_new */
     292       34944 :             exc_fx[i + i_subfr] = round_fx_sat( L_tmp );               /* Q_new */
     293             : #else
     294             :             L_tmp = L_shl_o( L_tmp, 5, &Overflow );                             /* Q15 + Q_new */
     295             :             L_tmp = L_mac_o( L_tmp, exc_fx[i + i_subfr], gain_pit, &Overflow ); /* Q15 + Q_new */
     296             :             L_tmp = L_shl_o( L_tmp, 1, &Overflow );                             /* saturation can occur here Q16 + Q_new */
     297             :             exc_fx[i + i_subfr] = round_fx_o( L_tmp, &Overflow );               /* Q_new */
     298             : #endif
     299             :         }
     300             : 
     301             :         /*-----------------------------------------------------------------*
     302             :          * Add the ACELP pre-quantizer contribution
     303             :          *-----------------------------------------------------------------*/
     304             : 
     305         546 :         IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) )
     306             :         {
     307         250 :             tmp1_fx = add( 16 - ( 2 + Q_AVQ_OUT_DEC + 1 ), Q_new );
     308       16250 :             FOR( i = 0; i < L_SUBFR; i++ )
     309             :             {
     310       16000 :                 L_tmp = L_mult( gain_preQ, code_preQ[i] ); /* Q2 + Q10 -> Q13*/
     311             : #ifdef ISSUE_1867_replace_overflow_libenc
     312       16000 :                 L_tmp = L_shl_sat( L_tmp, tmp1_fx ); /* Q16 + Q_exc    */
     313       16000 :                 tmp_fx = round_fx_sat( L_tmp );
     314       16000 :                 exc2_fx[i + i_subfr] = add_sat( exc2_fx[i + i_subfr], tmp_fx ); /* Q_exc */
     315       16000 :                 move16();
     316       16000 :                 exc_fx[i + i_subfr] = add_sat( exc_fx[i + i_subfr], tmp_fx ); /* Q_exc */
     317       16000 :                 move16();
     318             : #else
     319             :                 L_tmp = L_shl_o( L_tmp, tmp1_fx, &Overflow );                   /* Q16 + Q_exc    */
     320             :                 tmp_fx = round_fx_o( L_tmp, &Overflow );
     321             :                 exc2_fx[i + i_subfr] = add_o( exc2_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */
     322             :                 move16();
     323             :                 exc_fx[i + i_subfr] = add_o( exc_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */
     324             :                 move16();
     325             : #endif
     326             :             }
     327             :         }
     328             : 
     329             :         /*-----------------------------------------------------------------*
     330             :          * Prepare TBE excitation
     331             :          *-----------------------------------------------------------------*/
     332             : 
     333             : #ifdef FIX_2010_PREP_TBE_EXC
     334         546 :         prep_tbe_exc_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR],
     335         546 :                          bwe_exc_fx, gain_preQ, code_preQ, Q10, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag );
     336             : #else
     337             :         prep_tbe_exc_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR],
     338             :                          bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag );
     339             : #endif
     340             : 
     341             :         /*-----------------------------------------------------------------*
     342             :          * Synthesize speech to update mem_syn[].
     343             :          * Update A(z) filters
     344             :          *-----------------------------------------------------------------*/
     345             : 
     346         546 :         Syn_filt_s( 1, p_Aq, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 );
     347             : 
     348         546 :         p_Aw += ( M + 1 );
     349         546 :         p_Aq += ( M + 1 );
     350         546 :         pt_pitch++;
     351             :     }
     352             : 
     353             :     /* write reserved bits */
     354         124 :     WHILE( unbits_PI > 0 )
     355             :     {
     356           0 :         i = s_min( unbits_PI, 16 );
     357           0 :         push_indice( hBstr, IND_UNUSED, 0, i );
     358           0 :         unbits_PI -= i;
     359             :     }
     360             : 
     361             :     /* write TC configuration */
     362         124 :     IF( EQ_16( L_frame_fx, L_FRAME ) )
     363             :     {
     364          74 :         IF( EQ_16( tc_subfr, TC_0_0 ) )
     365             :         {
     366          31 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     367             :         }
     368          43 :         ELSE IF( EQ_16( tc_subfr, TC_0_64 ) )
     369             :         {
     370           9 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     371           9 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     372           9 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     373           9 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     374             :         }
     375          34 :         ELSE IF( EQ_16( tc_subfr, TC_0_128 ) )
     376             :         {
     377           5 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     378           5 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     379           5 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     380           5 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     381             :         }
     382          29 :         ELSE IF( EQ_16( tc_subfr, TC_0_192 ) )
     383             :         {
     384           3 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     385           3 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     386           3 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     387             :         }
     388          26 :         ELSE IF( EQ_16( tc_subfr, L_SUBFR ) )
     389             :         {
     390           5 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     391           5 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     392           5 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     393             :         }
     394          21 :         ELSE IF( EQ_16( tc_subfr, 2 * L_SUBFR ) )
     395             :         {
     396           1 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     397           1 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     398           1 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     399           1 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     400             :         }
     401          20 :         ELSE IF( EQ_16( tc_subfr, 3 * L_SUBFR ) )
     402             :         {
     403          20 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     404          20 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     405          20 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     406          20 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     407             :         }
     408             :     }
     409             :     ELSE /* L_frame == L_FRAME16k */
     410             :     {
     411          50 :         IF( tc_subfr == 0 )
     412             :         {
     413          39 :             push_indice( hBstr, IND_TC_SUBFR, 0, 2 );
     414             :         }
     415          11 :         ELSE IF( EQ_16( tc_subfr, L_SUBFR ) )
     416             :         {
     417          10 :             push_indice( hBstr, IND_TC_SUBFR, 1, 2 );
     418             :         }
     419           1 :         ELSE IF( EQ_16( tc_subfr, 2 * L_SUBFR ) )
     420             :         {
     421           1 :             push_indice( hBstr, IND_TC_SUBFR, 2, 2 );
     422             :         }
     423           0 :         ELSE IF( EQ_16( tc_subfr, 3 * L_SUBFR ) )
     424             :         {
     425           0 :             push_indice( hBstr, IND_TC_SUBFR, 3, 2 );
     426           0 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     427             :         }
     428           0 :         ELSE IF( EQ_16( tc_subfr, 4 * L_SUBFR ) )
     429             :         {
     430           0 :             push_indice( hBstr, IND_TC_SUBFR, 3, 2 );
     431           0 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     432             :         }
     433             :     }
     434             : 
     435         124 :     IF( st_fx->Opt_SC_VBR )
     436             :     {
     437             :         /* SC-VBR */
     438           0 :         hSC_VBR->prev_ppp_gain_pit_fx = gain_pit; /* Q14 */
     439           0 :         move16();
     440           0 :         hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */
     441           0 :         move16();
     442             :     }
     443             : 
     444         124 :     return tc_subfr;
     445             : }
     446             : 
     447       14253 : Word16 encod_tran_ivas_fx(
     448             :     Encoder_State *st_fx,     /* i/o: state structure                                   */
     449             :     const Word16 speech_fx[], /* i  : input speech                                      Q0*/
     450             :     const Word16 Aw_fx[],     /* i  : weighted A(z) unquantized for subframes                   Q12*/
     451             :     const Word16 Aq_fx[],     /* i  : 12k8 Lp coefficient                               Q12*/
     452             :     const Word16 Es_pred_fx,  /* i  : predicted scaled innov. energy                    Q8*/
     453             :     const Word16 *res_fx,     /* i  : residual signal                                   Q_new*/
     454             :     Word16 *syn_fx,           /* i/o: core synthesis                                    Q_new*/
     455             :     Word16 *exc_fx,           /* i/o: current non-enhanced excitation                   Q0*/
     456             :     Word16 *exc2_fx,          /* i/o: current enhanced excitation                       Q0*/
     457             :     Word16 *pitch_buf_fx,     /* i/o: floating pitch values for each subframe           Q6*/
     458             :     Word16 *voice_factors,    /* o  : voicing factors                                   Q15*/
     459             :     Word16 *bwe_exc_fx,       /* i/o: excitation for SWB TBE                            Q0*/
     460             :     Word16 tc_subfr,          /* i/o: TC subframe classification                        Q0*/
     461             :     Word16 position,          /* i  : maximum of residual signal index                  Q0*/
     462             :     Word16 *unbits,           /* i/o: number of unused bits                             Q0*/
     463             :     const Word16 shift,       /* i  : Scaling to get 12 bits                            */
     464             :     const Word16 Q_new        /* i  : Input scaling                                     */
     465             : )
     466             : {
     467             :     Word16 xn[L_SUBFR];                       /* Target vector for pitch search               */
     468             :     Word16 xn2[L_SUBFR];                      /* Target vector for codebook search            */
     469             :     Word16 cn[L_SUBFR];                       /* Target vector in residual domain             */
     470             :     Word16 h1[L_SUBFR + ( M + 1 )];           /* Impulse response vector                      */
     471             :     Word16 h2_fx[L_SUBFR + ( M + 1 )];        /* Impulse response vector                      */
     472             :     Word16 code[L_SUBFR];                     /* Fixed codebook excitation                    */
     473             :     Word16 y1[L_SUBFR];                       /* Filtered adaptive excitation                 */
     474             :     Word16 y2[L_SUBFR];                       /* Filtered algebraic excitation                */
     475       14253 :     Word16 gain_pit = 0, Gain_pitX2, gcode16; /* Pitch gain                                   */
     476             :     Word16 voice_fac;                         /* Voicing factor                               */
     477       14253 :     Word32 gain_code = 0;                     /* Gain of code                                 */
     478             :     Word32 Lgcode;
     479       14253 :     Word16 gain_inov = 0;               /* inovation gain                               */
     480             :     Word16 i, i_subfr, tmp1_fx, tmp_fx; /* tmp variables                                */
     481             :     Word16 unbits_ACELP;
     482             :     Word16 T0_min, T0_max;     /* pitch and TC variables                       */
     483             :     Word16 T0, T0_frac;        /* close loop integer pitch and fractional part */
     484             :     Word16 *pt_pitch;          /* pointer to floating pitch buffer             */
     485             :     Word16 g_corr[10];         /* ACELP correlation values  and gain pitch     */
     486             :     Word16 clip_gain;          /* LSF clip gain                                */
     487             :     const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector      */
     488       14253 :     Word16 gain_preQ = 0;      /* Gain of prequantizer excitation              */
     489             :     Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation                      */
     490             :     Word16 Jopt_flag;          /* joint optimization flag                      */
     491       14253 :     Word16 unbits_PI = 0;      /* saved bits for PI                            */
     492       14253 :     Word32 norm_gain_code = 0;
     493             :     Word16 L_frame_fx;
     494             :     Word16 shift_wsp;
     495             :     Word32 L_tmp;
     496             :     Word16 q_h1;
     497             : #ifndef ISSUE_1867_replace_overflow_libenc
     498             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     499             :     Flag Overflow = 0;
     500             :     move32();
     501             : #endif
     502             : #endif
     503       14253 :     BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
     504       14253 :     SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
     505       14253 :     LPD_state_HANDLE hLPDmem = st_fx->hLPDmem;
     506             : 
     507       14253 :     L_frame_fx = st_fx->L_frame;
     508       14253 :     move16();
     509             : 
     510       14253 :     set16_fx( h1, 0, L_SUBFR + ( M + 1 ) );
     511             : 
     512             :     /*------------------------------------------------------------------*
     513             :      * Initializations
     514             :      *------------------------------------------------------------------*/
     515       14253 :     gain_pit = 0;
     516       14253 :     move16();
     517       14253 :     gain_code = L_deposit_l( 0 );
     518       14253 :     gain_preQ = 0;
     519       14253 :     move16();
     520       14253 :     unbits_PI = 0;
     521       14253 :     move16();
     522       14253 :     IF( EQ_16( L_frame_fx, L_FRAME ) )
     523             :     {
     524        7470 :         T0_max = PIT_MAX;
     525        7470 :         move16();
     526        7470 :         T0_min = PIT_MIN;
     527        7470 :         move16();
     528             :     }
     529             :     ELSE /* L_frame == L_FRAME16k */
     530             :     {
     531        6783 :         T0_max = PIT16k_MAX;
     532        6783 :         move16();
     533        6783 :         T0_min = PIT16k_MIN;
     534        6783 :         move16();
     535             :     }
     536             : 
     537             :     /**unbits = 0;move16();*/
     538       14253 :     Jopt_flag = 0;
     539       14253 :     move16();
     540       14253 :     unbits_ACELP = *unbits; /* Q0 */
     541       14253 :     move16();
     542       14253 :     *unbits = 0;
     543       14253 :     move16();
     544             : 
     545       14253 :     p_Aw = Aw_fx; /* Q12 */
     546       14253 :     p_Aq = Aq_fx; /* Q12 */
     547       14253 :     pt_pitch = pitch_buf_fx;
     548       14253 :     gain_preQ = 0;
     549       14253 :     move16();
     550       14253 :     set16_fx( code_preQ, 0, L_SUBFR );
     551       14253 :     shift_wsp = add( Q_new, shift );
     552       14253 :     if ( LT_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) )
     553             :     {
     554       12980 :         shift_wsp = sub( shift_wsp, 1 );
     555             :     }
     556             :     /*----------------------------------------------------------------*
     557             :      * ACELP subframe loop
     558             :      *----------------------------------------------------------------*/
     559             : 
     560       78048 :     FOR( i_subfr = 0; i_subfr < L_frame_fx; i_subfr += L_SUBFR )
     561             :     {
     562             :         /*----------------------------------------------------------------*
     563             :          * Find the the excitation search target "xn" and innovation
     564             :          *   target in residual domain "cn"
     565             :          * Compute impulse response, h1[], of weighted synthesis filter
     566             :          *----------------------------------------------------------------*/
     567             : 
     568       63795 :         Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */
     569             : 
     570             : 
     571       63795 :         find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq,
     572       63795 :                               res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 );
     573             : 
     574       63795 :         q_h1 = sub( 14, norm_s( h1[0] ) );
     575       63795 :         Copy_Scale_sig( h1, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/
     576       63795 :         Scale_sig( h1, L_SUBFR, sub( 14, q_h1 ) );
     577             : 
     578             :         /* scaling of xn[] to limit dynamic at 12 bits */
     579       63795 :         Scale_sig( xn, L_SUBFR, shift );
     580             : 
     581             :         /*-----------------------------------------------------------------*
     582             :          * TC: subframe determination &
     583             :          * adaptive/glottal part of excitation construction
     584             :          *-----------------------------------------------------------------*/
     585             : 
     586       63795 :         transition_enc_ivas_fx( st_fx, i_subfr, &tc_subfr, &Jopt_flag, &position, &T0, &T0_frac, &T0_min, &T0_max, exc_fx, y1,
     587       63795 :                                 h1, xn, xn2, st_fx->clip_var_fx, &gain_pit, g_corr, &clip_gain, &pt_pitch, bwe_exc_fx, &unbits_ACELP, Q_new, shift );
     588             : 
     589             :         /*-----------------------------------------------------------------*
     590             :          * Transform domain contribution encoding - active frames
     591             :          *-----------------------------------------------------------------*/
     592             : 
     593       63795 :         IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) )
     594             :         {
     595        6365 :             transf_cdbk_enc_ivas_fx( st_fx, 0, i_subfr, cn, exc_fx, p_Aq, Aw_fx, h1, xn, xn2, y1, y2, Es_pred_fx,
     596             :                                      &gain_pit, gain_code, g_corr, clip_gain, &gain_preQ, code_preQ, unbits, Q_new, shift );
     597             :         }
     598             : 
     599             :         /*-----------------------------------------------------------------*
     600             :          * ACELP codebook search + pitch sharpening
     601             :          *-----------------------------------------------------------------*/
     602             : 
     603       63795 :         inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, L_frame_fx, st_fx->last_L_frame, st_fx->coder_type, st_fx->bwidth, st_fx->sharpFlag,
     604       63795 :                              i_subfr, tc_subfr, p_Aq, gain_pit, cn, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift, Q_new );
     605             : 
     606       63795 :         test();
     607       63795 :         test();
     608       63795 :         test();
     609       63795 :         if ( ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) && ( tc_subfr == 0 ) && ( EQ_16( i_subfr, L_SUBFR ) ) && ( EQ_16( T0, 2 * L_SUBFR ) ) )
     610             :         {
     611         475 :             Jopt_flag = 1;
     612         475 :             move16();
     613             :         }
     614             :         /*-----------------------------------------------------------------*
     615             :          * Quantize the gains
     616             :          * Test quantized gain of pitch for pitch clipping algorithm
     617             :          * Update tilt of code: 0.0 (unvoiced) to 0.5 (voiced)
     618             :          *-----------------------------------------------------------------*/
     619       63795 :         IF( Jopt_flag == 0 )
     620             :         {
     621             :             /* SQ gain_code */
     622       20268 :             gain_enc_tc_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y2, code, Es_pred_fx,
     623             :                             &gain_pit, &gain_code, &gain_inov, &norm_gain_code, shift_wsp );
     624             :         }
     625             :         ELSE
     626             :         {
     627       43527 :             IF( GT_32( st_fx->core_brate, ACELP_32k ) )
     628             :             {
     629             :                 /* SQ gain_pit and gain_code */
     630        2770 :                 gain_enc_SQ_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y1, y2, code, Es_pred_fx,
     631             :                                 &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain, shift_wsp );
     632             :             }
     633             :             ELSE
     634             :             {
     635             :                 /* VQ gain_pit and gain_code */
     636       40757 :                 gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame_fx, i_subfr, tc_subfr, xn, y1, shift_wsp, y2, code, Es_pred_fx,
     637             :                                    &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain );
     638             :             }
     639             :         }
     640       63795 :         gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx );
     641             : 
     642             : #ifdef ISSUE_1867_replace_overflow_libenc
     643       63795 :         Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/
     644       63795 :         gcode16 = round_fx_sat( Lgcode );
     645             : #else
     646             :         Lgcode = L_shl_o( gain_code, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/
     647             :         gcode16 = round_fx_o( Lgcode, &Overflow );
     648             : #endif
     649       63795 :         hLPDmem->tilt_code = est_tilt_ivas_fx( &exc_fx[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_SUBFR, 0 ); // Q15
     650             :         /*-----------------------------------------------------------------*
     651             :          * Update memory of the weighting filter
     652             :          *-----------------------------------------------------------------*/
     653             : 
     654             :         /*st->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]);*/
     655       63795 :         L_tmp = L_mult0( gcode16, y2[L_SUBFR - 1] );
     656       63795 :         L_tmp = L_shl( L_tmp, add( 5, shift ) ); // Q_new+14+shift
     657       63795 :         L_tmp = L_negate( L_tmp );
     658       63795 :         L_tmp = L_mac( L_tmp, xn[L_SUBFR - 1], 16384 );    // Q_new-1+15+shift
     659       63795 :         L_tmp = L_msu( L_tmp, y1[L_SUBFR - 1], gain_pit ); // Q_new-1+15+shift
     660       63795 :         L_tmp = L_shl_sat( L_tmp, sub( 1, shift ) );       // Q_new+15
     661       63795 :         hLPDmem->mem_w0 = round_fx_sat( L_tmp );           /*Q_new-1*/
     662             :         /*-----------------------------------------------------------------*
     663             :          * Construct adaptive part of the excitation
     664             :          * Save the non-enhanced excitation for FEC_exc
     665             :          *-----------------------------------------------------------------*/
     666             : 
     667             :         /* Here, all these conditions have one purpose: to use   */
     668             :         /* the most efficient loop (the one with the least ops)  */
     669             :         /* This is done by upscaling gain_pit_fx and/or gain_code16 */
     670             :         /* when they don't use all 16 bits of precision          */
     671             : 
     672             :         /* exc Q_exc, gpit Q14, code Q12, gcode Q0 */
     673       63795 :         IF( norm_s( gain_pit ) == 0 )
     674             :         {
     675     1722825 :             FOR( i = 0; i < L_SUBFR; i++ )
     676             :             {
     677     1696320 :                 exc2_fx[i + i_subfr] = round_fx_sat( L_shl_sat( L_mult_sat( gain_pit, exc_fx[i + i_subfr] ), 1 ) ); /* Q_exc */
     678             :             }
     679             :         }
     680             :         ELSE
     681             :         {
     682       37290 :             Gain_pitX2 = shl( gain_pit, 1 );
     683     2423850 :             FOR( i = 0; i < L_SUBFR; i++ )
     684             :             {
     685     2386560 :                 exc2_fx[i + i_subfr] = mult_r( Gain_pitX2, exc_fx[i + i_subfr] ); /* Q_exc */
     686             :             }
     687             :         }
     688             : 
     689             :         /*-----------------------------------------------------------------*
     690             :          * Construct adaptive part of the excitation
     691             :          * Save the non-enhanced excitation for FEC_exc
     692             :          *-----------------------------------------------------------------*/
     693     4146675 :         FOR( i = 0; i < L_SUBFR; i++ )
     694             :         {
     695             :             /* code in Q9, gain_pit in Q14 */
     696     4082880 :             L_tmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */
     697             : #ifdef ISSUE_1867_replace_overflow_libenc
     698     4082880 :             L_tmp = L_shl_sat( L_tmp, 5 );                             /* Q15 + Q_new */
     699     4082880 :             L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr], gain_pit ); /* Q15 + Q_new */
     700     4082880 :             L_tmp = L_shl_sat( L_tmp, 1 );                             /* saturation can occur here Q16 + Q_new */
     701     4082880 :             exc_fx[i + i_subfr] = round_fx_sat( L_tmp );               /* Q_new */
     702             : #else
     703             :             L_tmp = L_shl_o( L_tmp, 5, &Overflow );                             /* Q15 + Q_new */
     704             :             L_tmp = L_mac_o( L_tmp, exc_fx[i + i_subfr], gain_pit, &Overflow ); /* Q15 + Q_new */
     705             :             L_tmp = L_shl_o( L_tmp, 1, &Overflow );                             /* saturation can occur here Q16 + Q_new */
     706             :             exc_fx[i + i_subfr] = round_fx_o( L_tmp, &Overflow );               /* Q_new */
     707             : #endif
     708             :         }
     709             : 
     710             :         /*-----------------------------------------------------------------*
     711             :          * Add the ACELP pre-quantizer contribution
     712             :          *-----------------------------------------------------------------*/
     713             : 
     714       63795 :         IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) )
     715             :         {
     716        6365 :             tmp1_fx = add( 16 - ( 2 + Q_AVQ_OUT_DEC + 1 ), Q_new );
     717      413725 :             FOR( i = 0; i < L_SUBFR; i++ )
     718             :             {
     719      407360 :                 L_tmp = L_mult( gain_preQ, code_preQ[i] ); /* Q2 + Q10 -> Q13*/
     720             : #ifdef ISSUE_1867_replace_overflow_libenc
     721      407360 :                 L_tmp = L_shl_sat( L_tmp, tmp1_fx ); /* Q16 + Q_exc    */
     722      407360 :                 tmp_fx = round_fx_sat( L_tmp );
     723             : 
     724      407360 :                 exc2_fx[i + i_subfr] = add_sat( exc2_fx[i + i_subfr], tmp_fx ); /* Q_exc */
     725      407360 :                 move16();
     726      407360 :                 exc_fx[i + i_subfr] = add_sat( exc_fx[i + i_subfr], tmp_fx ); /* Q_exc */
     727             : #else
     728             :                 L_tmp = L_shl_o( L_tmp, tmp1_fx, &Overflow );                   /* Q16 + Q_exc    */
     729             :                 tmp_fx = round_fx_o( L_tmp, &Overflow );
     730             : 
     731             :                 exc2_fx[i + i_subfr] = add_o( exc2_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */
     732             :                 move16();
     733             :                 exc_fx[i + i_subfr] = add_o( exc_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */
     734             : #endif
     735      407360 :                 move16();
     736             :             }
     737             :         }
     738             : 
     739             :         /*-----------------------------------------------------------------*
     740             :          * Prepare TBE excitation
     741             :          *-----------------------------------------------------------------*/
     742             : 
     743             : #ifdef FIX_2010_PREP_TBE_EXC
     744       63795 :         prep_tbe_exc_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR],
     745       63795 :                          bwe_exc_fx, gain_preQ, code_preQ, Q10, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate,
     746       63795 :                          st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag );
     747             : #else
     748             :         prep_tbe_exc_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR],
     749             :                          bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate,
     750             :                          st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag );
     751             : #endif
     752             : 
     753             :         /*-----------------------------------------------------------------*
     754             :          * Synthesize speech to update mem_syn[].
     755             :          * Update A(z) filters
     756             :          *-----------------------------------------------------------------*/
     757             : 
     758       63795 :         Syn_filt_s( 1, p_Aq, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 );
     759             : 
     760       63795 :         p_Aw += ( M + 1 );
     761       63795 :         p_Aq += ( M + 1 );
     762       63795 :         pt_pitch++;
     763             :     }
     764             : 
     765             :     /* write reserved bits */
     766       14253 :     WHILE( unbits_PI > 0 )
     767             :     {
     768           0 :         i = s_min( unbits_PI, 16 );
     769           0 :         push_indice( hBstr, IND_UNUSED, 0, i );
     770           0 :         unbits_PI -= i;
     771             :     }
     772             : 
     773             :     /* write TC configuration */
     774       14253 :     IF( EQ_16( L_frame_fx, L_FRAME ) )
     775             :     {
     776        7470 :         IF( EQ_16( tc_subfr, TC_0_0 ) )
     777             :         {
     778        1673 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     779             :         }
     780        5797 :         ELSE IF( EQ_16( tc_subfr, TC_0_64 ) )
     781             :         {
     782        1372 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     783        1372 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     784        1372 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     785        1372 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     786             :         }
     787        4425 :         ELSE IF( EQ_16( tc_subfr, TC_0_128 ) )
     788             :         {
     789         683 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     790         683 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     791         683 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     792         683 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     793             :         }
     794        3742 :         ELSE IF( EQ_16( tc_subfr, TC_0_192 ) )
     795             :         {
     796         214 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     797         214 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     798         214 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     799             :         }
     800        3528 :         ELSE IF( EQ_16( tc_subfr, L_SUBFR ) )
     801             :         {
     802        1151 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     803        1151 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     804        1151 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     805             :         }
     806        2377 :         ELSE IF( EQ_16( tc_subfr, 2 * L_SUBFR ) )
     807             :         {
     808         561 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     809         561 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     810         561 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     811         561 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     812             :         }
     813        1816 :         ELSE IF( EQ_16( tc_subfr, 3 * L_SUBFR ) )
     814             :         {
     815        1816 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     816        1816 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     817        1816 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     818        1816 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     819             :         }
     820             :     }
     821             :     ELSE /* L_frame == L_FRAME16k */
     822             :     {
     823        6783 :         IF( tc_subfr == 0 )
     824             :         {
     825        2788 :             push_indice( hBstr, IND_TC_SUBFR, 0, 2 );
     826             :         }
     827        3995 :         ELSE IF( EQ_16( tc_subfr, L_SUBFR ) )
     828             :         {
     829         988 :             push_indice( hBstr, IND_TC_SUBFR, 1, 2 );
     830             :         }
     831        3007 :         ELSE IF( EQ_16( tc_subfr, 2 * L_SUBFR ) )
     832             :         {
     833         664 :             push_indice( hBstr, IND_TC_SUBFR, 2, 2 );
     834             :         }
     835        2343 :         ELSE IF( EQ_16( tc_subfr, 3 * L_SUBFR ) )
     836             :         {
     837         252 :             push_indice( hBstr, IND_TC_SUBFR, 3, 2 );
     838         252 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     839             :         }
     840        2091 :         ELSE IF( EQ_16( tc_subfr, 4 * L_SUBFR ) )
     841             :         {
     842        2091 :             push_indice( hBstr, IND_TC_SUBFR, 3, 2 );
     843        2091 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     844             :         }
     845             :     }
     846             : 
     847       14253 :     IF( st_fx->Opt_SC_VBR )
     848             :     {
     849             :         /* SC-VBR */
     850           0 :         hSC_VBR->prev_ppp_gain_pit_fx = gain_pit; /* Q14 */
     851           0 :         move16();
     852           0 :         hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */
     853           0 :         move16();
     854             :     }
     855             : 
     856       14253 :     return tc_subfr;
     857             : }

Generated by: LCOV version 1.14