LCOV - code coverage report
Current view: top level - lib_enc - enc_tran_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ e95243e9e67ddeb69dddf129509de1b3d95b402e Lines: 299 319 93.7 %
Date: 2025-09-14 03:13:15 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             : #include <stdint.h>
       5             : #include "options.h" /* Compilation switches                   */
       6             : #include "cnst.h"    /* Compilation switches                   */
       7             : // #include "prot_fx.h"    /* Function prototypes                    */
       8             : #include "rom_com_fx.h"  /* Static table prototypes                */
       9             : #include "rom_com.h"     /* Static table prototypes                */
      10             : #include "prot_fx.h"     /* Function prototypes                    */
      11             : #include "prot_fx_enc.h" /* Function prototypes                    */
      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         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],
     334         546 :                          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 );
     335             : 
     336             :         /*-----------------------------------------------------------------*
     337             :          * Synthesize speech to update mem_syn[].
     338             :          * Update A(z) filters
     339             :          *-----------------------------------------------------------------*/
     340             : 
     341         546 :         Syn_filt_s( 1, p_Aq, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 );
     342             : 
     343         546 :         p_Aw += ( M + 1 );
     344         546 :         p_Aq += ( M + 1 );
     345         546 :         pt_pitch++;
     346             :     }
     347             : 
     348             :     /* write reserved bits */
     349         124 :     WHILE( unbits_PI > 0 )
     350             :     {
     351           0 :         i = s_min( unbits_PI, 16 );
     352           0 :         push_indice( hBstr, IND_UNUSED, 0, i );
     353           0 :         unbits_PI -= i;
     354             :     }
     355             : 
     356             :     /* write TC configuration */
     357         124 :     IF( EQ_16( L_frame_fx, L_FRAME ) )
     358             :     {
     359          74 :         IF( EQ_16( tc_subfr, TC_0_0 ) )
     360             :         {
     361          31 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     362             :         }
     363          43 :         ELSE IF( EQ_16( tc_subfr, TC_0_64 ) )
     364             :         {
     365           9 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     366           9 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     367           9 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     368           9 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     369             :         }
     370          34 :         ELSE IF( EQ_16( tc_subfr, TC_0_128 ) )
     371             :         {
     372           5 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     373           5 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     374           5 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     375           5 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     376             :         }
     377          29 :         ELSE IF( EQ_16( tc_subfr, TC_0_192 ) )
     378             :         {
     379           3 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     380           3 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     381           3 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     382             :         }
     383          26 :         ELSE IF( EQ_16( tc_subfr, L_SUBFR ) )
     384             :         {
     385           5 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     386           5 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     387           5 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     388             :         }
     389          21 :         ELSE IF( EQ_16( tc_subfr, 2 * L_SUBFR ) )
     390             :         {
     391           1 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     392           1 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     393           1 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     394           1 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     395             :         }
     396          20 :         ELSE IF( EQ_16( tc_subfr, 3 * L_SUBFR ) )
     397             :         {
     398          20 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     399          20 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     400          20 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     401          20 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     402             :         }
     403             :     }
     404             :     ELSE /* L_frame == L_FRAME16k */
     405             :     {
     406          50 :         IF( tc_subfr == 0 )
     407             :         {
     408          39 :             push_indice( hBstr, IND_TC_SUBFR, 0, 2 );
     409             :         }
     410          11 :         ELSE IF( EQ_16( tc_subfr, L_SUBFR ) )
     411             :         {
     412          10 :             push_indice( hBstr, IND_TC_SUBFR, 1, 2 );
     413             :         }
     414           1 :         ELSE IF( EQ_16( tc_subfr, 2 * L_SUBFR ) )
     415             :         {
     416           1 :             push_indice( hBstr, IND_TC_SUBFR, 2, 2 );
     417             :         }
     418           0 :         ELSE IF( EQ_16( tc_subfr, 3 * L_SUBFR ) )
     419             :         {
     420           0 :             push_indice( hBstr, IND_TC_SUBFR, 3, 2 );
     421           0 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     422             :         }
     423           0 :         ELSE IF( EQ_16( tc_subfr, 4 * L_SUBFR ) )
     424             :         {
     425           0 :             push_indice( hBstr, IND_TC_SUBFR, 3, 2 );
     426           0 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     427             :         }
     428             :     }
     429             : 
     430         124 :     IF( st_fx->Opt_SC_VBR )
     431             :     {
     432             :         /* SC-VBR */
     433           0 :         hSC_VBR->prev_ppp_gain_pit_fx = gain_pit; /* Q14 */
     434           0 :         move16();
     435           0 :         hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */
     436           0 :         move16();
     437             :     }
     438             : 
     439         124 :     return tc_subfr;
     440             : }
     441             : 
     442       14289 : Word16 encod_tran_ivas_fx(
     443             :     Encoder_State *st_fx,     /* i/o: state structure                                   */
     444             :     const Word16 speech_fx[], /* i  : input speech                                      Q0*/
     445             :     const Word16 Aw_fx[],     /* i  : weighted A(z) unquantized for subframes                   Q12*/
     446             :     const Word16 Aq_fx[],     /* i  : 12k8 Lp coefficient                               Q12*/
     447             :     const Word16 Es_pred_fx,  /* i  : predicted scaled innov. energy                    Q8*/
     448             :     const Word16 *res_fx,     /* i  : residual signal                                   Q_new*/
     449             :     Word16 *syn_fx,           /* i/o: core synthesis                                    Q_new*/
     450             :     Word16 *exc_fx,           /* i/o: current non-enhanced excitation                   Q0*/
     451             :     Word16 *exc2_fx,          /* i/o: current enhanced excitation                       Q0*/
     452             :     Word16 *pitch_buf_fx,     /* i/o: floating pitch values for each subframe           Q6*/
     453             :     Word16 *voice_factors,    /* o  : voicing factors                                   Q15*/
     454             :     Word16 *bwe_exc_fx,       /* i/o: excitation for SWB TBE                            Q0*/
     455             :     Word16 tc_subfr,          /* i/o: TC subframe classification                        Q0*/
     456             :     Word16 position,          /* i  : maximum of residual signal index                  Q0*/
     457             :     Word16 *unbits,           /* i/o: number of unused bits                             Q0*/
     458             :     const Word16 shift,       /* i  : Scaling to get 12 bits                            */
     459             :     const Word16 Q_new        /* i  : Input scaling                                     */
     460             : )
     461             : {
     462             :     Word16 xn[L_SUBFR];                       /* Target vector for pitch search               */
     463             :     Word16 xn2[L_SUBFR];                      /* Target vector for codebook search            */
     464             :     Word16 cn[L_SUBFR];                       /* Target vector in residual domain             */
     465             :     Word16 h1[L_SUBFR + ( M + 1 )];           /* Impulse response vector                      */
     466             :     Word16 h2_fx[L_SUBFR + ( M + 1 )];        /* Impulse response vector                      */
     467             :     Word16 code[L_SUBFR];                     /* Fixed codebook excitation                    */
     468             :     Word16 y1[L_SUBFR];                       /* Filtered adaptive excitation                 */
     469             :     Word16 y2[L_SUBFR];                       /* Filtered algebraic excitation                */
     470       14289 :     Word16 gain_pit = 0, Gain_pitX2, gcode16; /* Pitch gain                                   */
     471             :     Word16 voice_fac;                         /* Voicing factor                               */
     472       14289 :     Word32 gain_code = 0;                     /* Gain of code                                 */
     473             :     Word32 Lgcode;
     474       14289 :     Word16 gain_inov = 0;               /* inovation gain                               */
     475             :     Word16 i, i_subfr, tmp1_fx, tmp_fx; /* tmp variables                                */
     476             :     Word16 unbits_ACELP;
     477             :     Word16 T0_min, T0_max;     /* pitch and TC variables                       */
     478             :     Word16 T0, T0_frac;        /* close loop integer pitch and fractional part */
     479             :     Word16 *pt_pitch;          /* pointer to floating pitch buffer             */
     480             :     Word16 g_corr[10];         /* ACELP correlation values  and gain pitch     */
     481             :     Word16 clip_gain;          /* LSF clip gain                                */
     482             :     const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector      */
     483       14289 :     Word16 gain_preQ = 0;      /* Gain of prequantizer excitation              */
     484             :     Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation                      */
     485             :     Word16 Jopt_flag;          /* joint optimization flag                      */
     486       14289 :     Word16 unbits_PI = 0;      /* saved bits for PI                            */
     487       14289 :     Word32 norm_gain_code = 0;
     488             :     Word16 L_frame_fx;
     489             :     Word16 shift_wsp;
     490             :     Word32 L_tmp;
     491             :     Word16 q_h1;
     492             : #ifndef ISSUE_1867_replace_overflow_libenc
     493             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     494             :     Flag Overflow = 0;
     495             :     move32();
     496             : #endif
     497             : #endif
     498       14289 :     BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
     499       14289 :     SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
     500       14289 :     LPD_state_HANDLE hLPDmem = st_fx->hLPDmem;
     501             : 
     502       14289 :     L_frame_fx = st_fx->L_frame;
     503       14289 :     move16();
     504             : 
     505       14289 :     set16_fx( h1, 0, L_SUBFR + ( M + 1 ) );
     506             : 
     507             :     /*------------------------------------------------------------------*
     508             :      * Initializations
     509             :      *------------------------------------------------------------------*/
     510       14289 :     gain_pit = 0;
     511       14289 :     move16();
     512       14289 :     gain_code = L_deposit_l( 0 );
     513       14289 :     gain_preQ = 0;
     514       14289 :     move16();
     515       14289 :     unbits_PI = 0;
     516       14289 :     move16();
     517       14289 :     IF( EQ_16( L_frame_fx, L_FRAME ) )
     518             :     {
     519        7487 :         T0_max = PIT_MAX;
     520        7487 :         move16();
     521        7487 :         T0_min = PIT_MIN;
     522        7487 :         move16();
     523             :     }
     524             :     ELSE /* L_frame == L_FRAME16k */
     525             :     {
     526        6802 :         T0_max = PIT16k_MAX;
     527        6802 :         move16();
     528        6802 :         T0_min = PIT16k_MIN;
     529        6802 :         move16();
     530             :     }
     531             : 
     532             :     /**unbits = 0;move16();*/
     533       14289 :     Jopt_flag = 0;
     534       14289 :     move16();
     535       14289 :     unbits_ACELP = *unbits; /* Q0 */
     536       14289 :     move16();
     537       14289 :     *unbits = 0;
     538       14289 :     move16();
     539             : 
     540       14289 :     p_Aw = Aw_fx; /* Q12 */
     541       14289 :     p_Aq = Aq_fx; /* Q12 */
     542       14289 :     pt_pitch = pitch_buf_fx;
     543       14289 :     gain_preQ = 0;
     544       14289 :     move16();
     545       14289 :     set16_fx( code_preQ, 0, L_SUBFR );
     546       14289 :     shift_wsp = add( Q_new, shift );
     547       14289 :     if ( LT_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) )
     548             :     {
     549       13016 :         shift_wsp = sub( shift_wsp, 1 );
     550             :     }
     551             :     /*----------------------------------------------------------------*
     552             :      * ACELP subframe loop
     553             :      *----------------------------------------------------------------*/
     554             : 
     555       78247 :     FOR( i_subfr = 0; i_subfr < L_frame_fx; i_subfr += L_SUBFR )
     556             :     {
     557             :         /*----------------------------------------------------------------*
     558             :          * Find the the excitation search target "xn" and innovation
     559             :          *   target in residual domain "cn"
     560             :          * Compute impulse response, h1[], of weighted synthesis filter
     561             :          *----------------------------------------------------------------*/
     562             : 
     563       63958 :         Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */
     564             : 
     565             : 
     566       63958 :         find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq,
     567       63958 :                               res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 );
     568             : 
     569       63958 :         q_h1 = sub( 14, norm_s( h1[0] ) );
     570       63958 :         Copy_Scale_sig( h1, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/
     571       63958 :         Scale_sig( h1, L_SUBFR, sub( 14, q_h1 ) );
     572             : 
     573             :         /* scaling of xn[] to limit dynamic at 12 bits */
     574       63958 :         Scale_sig( xn, L_SUBFR, shift );
     575             : 
     576             :         /*-----------------------------------------------------------------*
     577             :          * TC: subframe determination &
     578             :          * adaptive/glottal part of excitation construction
     579             :          *-----------------------------------------------------------------*/
     580             : 
     581       63958 :         transition_enc_ivas_fx( st_fx, i_subfr, &tc_subfr, &Jopt_flag, &position, &T0, &T0_frac, &T0_min, &T0_max, exc_fx, y1,
     582       63958 :                                 h1, xn, xn2, st_fx->clip_var_fx, &gain_pit, g_corr, &clip_gain, &pt_pitch, bwe_exc_fx, &unbits_ACELP, Q_new, shift );
     583             : 
     584             :         /*-----------------------------------------------------------------*
     585             :          * Transform domain contribution encoding - active frames
     586             :          *-----------------------------------------------------------------*/
     587             : 
     588       63958 :         IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) )
     589             :         {
     590        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,
     591             :                                      &gain_pit, gain_code, g_corr, clip_gain, &gain_preQ, code_preQ, unbits, Q_new, shift );
     592             :         }
     593             : 
     594             :         /*-----------------------------------------------------------------*
     595             :          * ACELP codebook search + pitch sharpening
     596             :          *-----------------------------------------------------------------*/
     597             : 
     598       63958 :         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,
     599       63958 :                              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 );
     600             : 
     601       63958 :         test();
     602       63958 :         test();
     603       63958 :         test();
     604       63958 :         if ( ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) && ( tc_subfr == 0 ) && ( EQ_16( i_subfr, L_SUBFR ) ) && ( EQ_16( T0, 2 * L_SUBFR ) ) )
     605             :         {
     606         483 :             Jopt_flag = 1;
     607         483 :             move16();
     608             :         }
     609             :         /*-----------------------------------------------------------------*
     610             :          * Quantize the gains
     611             :          * Test quantized gain of pitch for pitch clipping algorithm
     612             :          * Update tilt of code: 0.0 (unvoiced) to 0.5 (voiced)
     613             :          *-----------------------------------------------------------------*/
     614       63958 :         IF( Jopt_flag == 0 )
     615             :         {
     616             :             /* SQ gain_code */
     617       20303 :             gain_enc_tc_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y2, code, Es_pred_fx,
     618             :                             &gain_pit, &gain_code, &gain_inov, &norm_gain_code, shift_wsp );
     619             :         }
     620             :         ELSE
     621             :         {
     622       43655 :             IF( GT_32( st_fx->core_brate, ACELP_32k ) )
     623             :             {
     624             :                 /* SQ gain_pit and gain_code */
     625        2770 :                 gain_enc_SQ_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y1, y2, code, Es_pred_fx,
     626             :                                 &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain, shift_wsp );
     627             :             }
     628             :             ELSE
     629             :             {
     630             :                 /* VQ gain_pit and gain_code */
     631       40885 :                 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,
     632             :                                    &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain );
     633             :             }
     634             :         }
     635       63958 :         gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx );
     636             : 
     637             : #ifdef ISSUE_1867_replace_overflow_libenc
     638       63958 :         Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/
     639       63958 :         gcode16 = round_fx_sat( Lgcode );
     640             : #else
     641             :         Lgcode = L_shl_o( gain_code, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/
     642             :         gcode16 = round_fx_o( Lgcode, &Overflow );
     643             : #endif
     644       63958 :         hLPDmem->tilt_code = est_tilt_ivas_fx( &exc_fx[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_SUBFR, 0 ); // Q15
     645             :         /*-----------------------------------------------------------------*
     646             :          * Update memory of the weighting filter
     647             :          *-----------------------------------------------------------------*/
     648             : 
     649             :         /*st->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]);*/
     650       63958 :         L_tmp = L_mult0( gcode16, y2[L_SUBFR - 1] );
     651       63958 :         L_tmp = L_shl( L_tmp, add( 5, shift ) ); // Q_new+14+shift
     652       63958 :         L_tmp = L_negate( L_tmp );
     653       63958 :         L_tmp = L_mac( L_tmp, xn[L_SUBFR - 1], 16384 );    // Q_new-1+15+shift
     654       63958 :         L_tmp = L_msu( L_tmp, y1[L_SUBFR - 1], gain_pit ); // Q_new-1+15+shift
     655       63958 :         L_tmp = L_shl_sat( L_tmp, sub( 1, shift ) );       // Q_new+15
     656       63958 :         hLPDmem->mem_w0 = round_fx_sat( L_tmp );           /*Q_new-1*/
     657             :         /*-----------------------------------------------------------------*
     658             :          * Construct adaptive part of the excitation
     659             :          * Save the non-enhanced excitation for FEC_exc
     660             :          *-----------------------------------------------------------------*/
     661             : 
     662             :         /* Here, all these conditions have one purpose: to use   */
     663             :         /* the most efficient loop (the one with the least ops)  */
     664             :         /* This is done by upscaling gain_pit_fx and/or gain_code16 */
     665             :         /* when they don't use all 16 bits of precision          */
     666             : 
     667             :         /* exc Q_exc, gpit Q14, code Q12, gcode Q0 */
     668       63958 :         IF( norm_s( gain_pit ) == 0 )
     669             :         {
     670     1724645 :             FOR( i = 0; i < L_SUBFR; i++ )
     671             :             {
     672     1698112 :                 exc2_fx[i + i_subfr] = round_fx_sat( L_shl_sat( L_mult_sat( gain_pit, exc_fx[i + i_subfr] ), 1 ) ); /* Q_exc */
     673             :             }
     674             :         }
     675             :         ELSE
     676             :         {
     677       37425 :             Gain_pitX2 = shl( gain_pit, 1 );
     678     2432625 :             FOR( i = 0; i < L_SUBFR; i++ )
     679             :             {
     680     2395200 :                 exc2_fx[i + i_subfr] = mult_r( Gain_pitX2, exc_fx[i + i_subfr] ); /* Q_exc */
     681             :             }
     682             :         }
     683             : 
     684             :         /*-----------------------------------------------------------------*
     685             :          * Construct adaptive part of the excitation
     686             :          * Save the non-enhanced excitation for FEC_exc
     687             :          *-----------------------------------------------------------------*/
     688     4157270 :         FOR( i = 0; i < L_SUBFR; i++ )
     689             :         {
     690             :             /* code in Q9, gain_pit in Q14 */
     691     4093312 :             L_tmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */
     692             : #ifdef ISSUE_1867_replace_overflow_libenc
     693     4093312 :             L_tmp = L_shl_sat( L_tmp, 5 );                             /* Q15 + Q_new */
     694     4093312 :             L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr], gain_pit ); /* Q15 + Q_new */
     695     4093312 :             L_tmp = L_shl_sat( L_tmp, 1 );                             /* saturation can occur here Q16 + Q_new */
     696     4093312 :             exc_fx[i + i_subfr] = round_fx_sat( L_tmp );               /* Q_new */
     697             : #else
     698             :             L_tmp = L_shl_o( L_tmp, 5, &Overflow );                             /* Q15 + Q_new */
     699             :             L_tmp = L_mac_o( L_tmp, exc_fx[i + i_subfr], gain_pit, &Overflow ); /* Q15 + Q_new */
     700             :             L_tmp = L_shl_o( L_tmp, 1, &Overflow );                             /* saturation can occur here Q16 + Q_new */
     701             :             exc_fx[i + i_subfr] = round_fx_o( L_tmp, &Overflow );               /* Q_new */
     702             : #endif
     703             :         }
     704             : 
     705             :         /*-----------------------------------------------------------------*
     706             :          * Add the ACELP pre-quantizer contribution
     707             :          *-----------------------------------------------------------------*/
     708             : 
     709       63958 :         IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) )
     710             :         {
     711        6365 :             tmp1_fx = add( 16 - ( 2 + Q_AVQ_OUT_DEC + 1 ), Q_new );
     712      413725 :             FOR( i = 0; i < L_SUBFR; i++ )
     713             :             {
     714      407360 :                 L_tmp = L_mult( gain_preQ, code_preQ[i] ); /* Q2 + Q10 -> Q13*/
     715             : #ifdef ISSUE_1867_replace_overflow_libenc
     716      407360 :                 L_tmp = L_shl_sat( L_tmp, tmp1_fx ); /* Q16 + Q_exc    */
     717      407360 :                 tmp_fx = round_fx_sat( L_tmp );
     718             : 
     719      407360 :                 exc2_fx[i + i_subfr] = add_sat( exc2_fx[i + i_subfr], tmp_fx ); /* Q_exc */
     720      407360 :                 move16();
     721      407360 :                 exc_fx[i + i_subfr] = add_sat( exc_fx[i + i_subfr], tmp_fx ); /* Q_exc */
     722             : #else
     723             :                 L_tmp = L_shl_o( L_tmp, tmp1_fx, &Overflow );                   /* Q16 + Q_exc    */
     724             :                 tmp_fx = round_fx_o( L_tmp, &Overflow );
     725             : 
     726             :                 exc2_fx[i + i_subfr] = add_o( exc2_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */
     727             :                 move16();
     728             :                 exc_fx[i + i_subfr] = add_o( exc_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */
     729             : #endif
     730      407360 :                 move16();
     731             :             }
     732             :         }
     733             : 
     734             :         /*-----------------------------------------------------------------*
     735             :          * Prepare TBE excitation
     736             :          *-----------------------------------------------------------------*/
     737             : 
     738       63958 :         prep_tbe_exc_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR],
     739       63958 :                          bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate,
     740       63958 :                          st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag );
     741             : 
     742             :         /*-----------------------------------------------------------------*
     743             :          * Synthesize speech to update mem_syn[].
     744             :          * Update A(z) filters
     745             :          *-----------------------------------------------------------------*/
     746             : 
     747       63958 :         Syn_filt_s( 1, p_Aq, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 );
     748             : 
     749       63958 :         p_Aw += ( M + 1 );
     750       63958 :         p_Aq += ( M + 1 );
     751       63958 :         pt_pitch++;
     752             :     }
     753             : 
     754             :     /* write reserved bits */
     755       14289 :     WHILE( unbits_PI > 0 )
     756             :     {
     757           0 :         i = s_min( unbits_PI, 16 );
     758           0 :         push_indice( hBstr, IND_UNUSED, 0, i );
     759           0 :         unbits_PI -= i;
     760             :     }
     761             : 
     762             :     /* write TC configuration */
     763       14289 :     IF( EQ_16( L_frame_fx, L_FRAME ) )
     764             :     {
     765        7487 :         IF( EQ_16( tc_subfr, TC_0_0 ) )
     766             :         {
     767        1676 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     768             :         }
     769        5811 :         ELSE IF( EQ_16( tc_subfr, TC_0_64 ) )
     770             :         {
     771        1383 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     772        1383 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     773        1383 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     774        1383 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     775             :         }
     776        4428 :         ELSE IF( EQ_16( tc_subfr, TC_0_128 ) )
     777             :         {
     778         688 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     779         688 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     780         688 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     781         688 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     782             :         }
     783        3740 :         ELSE IF( EQ_16( tc_subfr, TC_0_192 ) )
     784             :         {
     785         213 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     786         213 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     787         213 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     788             :         }
     789        3527 :         ELSE IF( EQ_16( tc_subfr, L_SUBFR ) )
     790             :         {
     791        1150 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     792        1150 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     793        1150 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     794             :         }
     795        2377 :         ELSE IF( EQ_16( tc_subfr, 2 * L_SUBFR ) )
     796             :         {
     797         563 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     798         563 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     799         563 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     800         563 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     801             :         }
     802        1814 :         ELSE IF( EQ_16( tc_subfr, 3 * L_SUBFR ) )
     803             :         {
     804        1814 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     805        1814 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     806        1814 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     807        1814 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     808             :         }
     809             :     }
     810             :     ELSE /* L_frame == L_FRAME16k */
     811             :     {
     812        6802 :         IF( tc_subfr == 0 )
     813             :         {
     814        2788 :             push_indice( hBstr, IND_TC_SUBFR, 0, 2 );
     815             :         }
     816        4014 :         ELSE IF( EQ_16( tc_subfr, L_SUBFR ) )
     817             :         {
     818         995 :             push_indice( hBstr, IND_TC_SUBFR, 1, 2 );
     819             :         }
     820        3019 :         ELSE IF( EQ_16( tc_subfr, 2 * L_SUBFR ) )
     821             :         {
     822         677 :             push_indice( hBstr, IND_TC_SUBFR, 2, 2 );
     823             :         }
     824        2342 :         ELSE IF( EQ_16( tc_subfr, 3 * L_SUBFR ) )
     825             :         {
     826         246 :             push_indice( hBstr, IND_TC_SUBFR, 3, 2 );
     827         246 :             push_indice( hBstr, IND_TC_SUBFR, 0, 1 );
     828             :         }
     829        2096 :         ELSE IF( EQ_16( tc_subfr, 4 * L_SUBFR ) )
     830             :         {
     831        2096 :             push_indice( hBstr, IND_TC_SUBFR, 3, 2 );
     832        2096 :             push_indice( hBstr, IND_TC_SUBFR, 1, 1 );
     833             :         }
     834             :     }
     835             : 
     836       14289 :     IF( st_fx->Opt_SC_VBR )
     837             :     {
     838             :         /* SC-VBR */
     839           0 :         hSC_VBR->prev_ppp_gain_pit_fx = gain_pit; /* Q14 */
     840           0 :         move16();
     841           0 :         hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */
     842           0 :         move16();
     843             :     }
     844             : 
     845       14289 :     return tc_subfr;
     846             : }

Generated by: LCOV version 1.14