LCOV - code coverage report
Current view: top level - lib_enc - dtx_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 698 968 72.1 %
Date: 2025-05-03 01:55:50 Functions: 7 7 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"    /* Common constants                       */
       7             : #include "rom_com_fx.h"
       8             : #include "rom_com.h"
       9             : // #include "basop_mpy.h"
      10             : #include <assert.h>
      11             : #include "prot_fx.h"     /* Function prototypes                    */
      12             : #include "prot_fx_enc.h" /* Function prototypes                    */
      13             : 
      14             : /*-------------------------------------------------------------------*
      15             :  * Local constants
      16             :  *-------------------------------------------------------------------*/
      17             : #define ALPHA_ENER_FAST_FX 29491 /* Fast adaptation (noise down, speech up) */
      18             : #define ALPHA_ENER_SLOW_FX 32440 /* Fast adaptation (noise down, speech up) */
      19             : 
      20             : #define MIN_CNT 50 /* Minimum frame number before SID interval adaptation */
      21             : 
      22             : #define SNR_H_FX 13056 /* Estimated SNR and corresponding SID interval        */
      23             : #define SNR_L_FX 9216  /* 51dB corresponds to 25dB SNR before noise supressor */
      24             : #define INT_H    50
      25             : #define INT_L    8
      26             : #define RATIO    ( INT_H - INT_L ) / ( ( SNR_H_FX - SNR_L_FX ) / 256 )
      27             : 
      28             : #define LTE_VAR_FX -1024 /* Q8, -4.0f */
      29             : 
      30             : #define CNG_TYPE_HO 20 /* hangover for switching between CNG types */
      31             : 
      32             : 
      33             : #define MAX_BRATE_DTX_EVS  ACELP_24k40 /* maximum bitrate to which the default DTX is applied in EVS; otherwise DTX is applied only in silence */
      34             : #define MAX_BRATE_DTX_IVAS IVAS_80k    /* maximum bitrate to which the default DTX is applied in IVAS; otherwise DTX is applied only in silence */
      35             : 
      36             : /*-------------------------------------------------------------------*
      37             :  * Local function prototypes
      38             :  *-------------------------------------------------------------------*/
      39             : 
      40             : static void update_SID_cnt_fx( DTX_ENC_HANDLE hDtxEnc, const Word32 core_brate, const Word16 Opt_AMR_WB );
      41             : /*==================================================================================*/
      42             : /* FUNCTION : dtx_ivas_fx()                                                              */
      43             : /*----------------------------------------------------------------------------------*/
      44             : /* PURPOSE :  Discontinuous transmission operation                                  */
      45             : /*----------------------------------------------------------------------------------*/
      46             : /*  INPUT ARGUMENTS :                                                               */
      47             : /* _ (Encoder_State_Fx) st_fx : encoder state structure                             */
      48             : /* _ (Word16)   vad           : vad flag                                       Q0   */
      49             : /* _ (Word16[]) speech_fx     : Pointer to the speech frame               qSpeech   */
      50             : /* _ (Word16)   qSpeech       : speech buffer qformat value                         */
      51             : /* _ (Word16*)  qener         : frame_ener/lt_ener_voiced/lt_ener_noise buf qformat */
      52             : /*----------------------------------------------------------------------------------*/
      53             : /* OUTPUT ARGUMENTS :                                                               */
      54             : /* _ (Word16*)  qener         : frame_ener/lt_ener_voiced/lt_ener_noise buf qformat */
      55             : /* _ (Encoder_State_Fx) st_fx : encoder state structure                             */
      56             : /*----------------------------------------------------------------------------------*/
      57             : 
      58             : /*----------------------------------------------------------------------------------*/
      59             : /* RETURN ARGUMENTS :                                                               */
      60             : /* _ None                                                                           */
      61             : /*==================================================================================*/
      62     1129000 : void dtx_ivas_fx(
      63             :     Encoder_State *st_fx,               /* i/o: encoder state structure                  */
      64             :     const Word32 last_ivas_total_brate, /* i  : last IVAS total bitrate                  Q0*/
      65             :     const Word32 ivas_total_brate,      /* i  : IVAS total bitrate                       Q0*/
      66             :     const Word16 vad,                   /* i  : vad flag for DTX                         Q0*/
      67             :     const Word16 speech[],              /* i  : Pointer to the speech frame              Q_speech*/
      68             :     Word16 Q_speech                     /* i  : Q factor for speech                      */
      69             : )
      70             : {
      71             :     Word16 alpha, i, j, Q_speech2;
      72             :     Word32 L_tmp;
      73     1129000 :     DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc;
      74     1129000 :     TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc;
      75             : 
      76             :     Word16 last_br_cng_flag, last_br_flag, br_dtx_flag;
      77             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      78     1129000 :     Flag Overflow = 0;
      79     1129000 :     move32();
      80             : #endif
      81             :     Word32 total_brate_ref;
      82             : 
      83     1129000 :     total_brate_ref = st_fx->total_brate;
      84     1129000 :     move32();
      85             : 
      86     1129000 :     IF( st_fx->dtx_sce_sba != 0 )
      87             :     {
      88       11370 :         last_br_cng_flag = 1;
      89       11370 :         last_br_flag = 1;
      90       11370 :         move16();
      91       11370 :         move16();
      92             :     }
      93             :     ELSE
      94             :     {
      95     1117630 :         test();
      96     1117630 :         test();
      97     1117630 :         test();
      98     1117630 :         last_br_cng_flag = LE_32( st_fx->last_total_brate_cng, MAX_BRATE_DTX_EVS ) || LT_16( st_fx->lp_noise_fx, DTX_THR * 256 ) || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->last_total_brate_cng, MAX_BRATE_DTX_IVAS ) );
      99             : 
     100     1117630 :         test();
     101     1117630 :         test();
     102     1117630 :         test();
     103             : 
     104     1117630 :         last_br_flag = ( st_fx->element_mode == EVS_MONO && LE_32( st_fx->last_total_brate, MAX_BRATE_DTX_EVS ) ) ||
     105     1822093 :                        ( st_fx->element_mode != EVS_MONO && LE_32( last_ivas_total_brate, MAX_BRATE_DTX_IVAS ) ) ||
     106      704463 :                        LT_16( st_fx->lp_noise_fx, DTX_THR * 256 );
     107             :     }
     108             : 
     109             :     /* Initialization */
     110     1129000 :     IF( st_fx->ini_frame == 0 )
     111             :     {
     112        8212 :         st_fx->active_cnt = CNG_TYPE_HO;
     113        8212 :         move16();
     114             : 
     115        8212 :         st_fx->cng_type = FD_CNG;
     116        8212 :         move16();
     117        8212 :         test();
     118        8212 :         test();
     119        8212 :         test();
     120        8212 :         if ( ( EQ_16( st_fx->codec_mode, MODE1 ) || st_fx->Opt_AMR_WB ) && NE_16( st_fx->element_mode, IVAS_SCE ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) )
     121             :         {
     122         132 :             st_fx->cng_type = LP_CNG;
     123         132 :             move16();
     124             :         }
     125             :     }
     126     1129000 :     test();
     127     1129000 :     test();
     128     1129000 :     test();
     129     1129000 :     test();
     130     1129000 :     test();
     131     1129000 :     IF( st_fx->Opt_DTX_ON && vad == 0 &&
     132             :         GT_16( st_fx->ini_frame, 2 ) && /* CNG coding starts after 2 frames */
     133             :         st_fx->fd_cng_reset_flag == 0 &&
     134             :         NE_16( st_fx->last_core, AMR_WB_CORE ) &&
     135             :         st_fx->Opt_AMR_WB == 0 )
     136             :     {
     137       37977 :         test();
     138       37977 :         test();
     139       37977 :         test();
     140       37977 :         IF( GT_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_total_brate_cng, -1 ) &&
     141             :             NE_32( st_fx->last_total_brate_cng, st_fx->total_brate ) && last_br_cng_flag )
     142             :         {
     143        4097 :             st_fx->total_brate = st_fx->last_total_brate_cng;
     144        4097 :             move32();
     145        4097 :             test();
     146        4097 :             if ( !( EQ_32( st_fx->total_brate, ACELP_7k20 ) && st_fx->Opt_SC_VBR ) )
     147             :             {
     148        4097 :                 st_fx->Opt_SC_VBR = 0;
     149        4097 :                 move16();
     150             :             }
     151        4097 :             st_fx->rf_mode = st_fx->last_rf_mode_cng;
     152        4097 :             move16();
     153        4097 :             st_fx->bwidth = st_fx->last_bwidth_cng;
     154        4097 :             move16();
     155        4097 :             st_fx->codec_mode = st_fx->last_codec_mode_cng;
     156        4097 :             move16();
     157             :         }
     158       37977 :         test();
     159       37977 :         test();
     160       37977 :         IF( LE_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_total_brate, st_fx->total_brate ) && last_br_flag )
     161             : 
     162             :         {
     163        3886 :             st_fx->total_brate = st_fx->last_total_brate;
     164        3886 :             move32();
     165        3886 :             test();
     166        3886 :             if ( !( EQ_32( st_fx->total_brate, ACELP_7k20 ) && st_fx->Opt_SC_VBR ) )
     167             :             {
     168        3886 :                 st_fx->Opt_SC_VBR = 0;
     169        3886 :                 move16();
     170             :             }
     171             : 
     172        3886 :             st_fx->Opt_RF_ON = 0;
     173        3886 :             move16();
     174        3886 :             test();
     175        3886 :             test();
     176        3886 :             test();
     177        3886 :             if ( st_fx->rf_mode && st_fx->rf_fec_offset > 0 && EQ_32( st_fx->total_brate, ACELP_13k20 ) && ( st_fx->bwidth != NB ) )
     178             :             {
     179           0 :                 st_fx->Opt_RF_ON = 1;
     180           0 :                 move16();
     181             :             }
     182        3886 :             st_fx->rf_mode = st_fx->Opt_RF_ON;
     183        3886 :             move16();
     184        3886 :             st_fx->bwidth = st_fx->last_bwidth;
     185        3886 :             move32();
     186        3886 :             IF( st_fx->element_mode > EVS_MONO )
     187             :             {
     188        3886 :                 st_fx->codec_mode = MODE1;
     189        3886 :                 move16();
     190             :             }
     191             :             ELSE
     192             :             {
     193           0 :                 st_fx->codec_mode = get_codec_mode( st_fx->total_brate );
     194           0 :                 move16();
     195             :             }
     196             :         }
     197             :     }
     198             : 
     199             :     /*------------------------------------------------------------------------*
     200             :      * Select SID or FRAME_NO_DATA frame if DTX is enabled
     201             :      *------------------------------------------------------------------------*/
     202             : 
     203     1129000 :     br_dtx_flag = 1;
     204     1129000 :     move16();
     205             : 
     206     1129000 :     IF( st_fx->dtx_sce_sba == 0 )
     207             :     {
     208     1117630 :         test();
     209     1117630 :         test();
     210     1117630 :         test();
     211     1117630 :         test();
     212     1117630 :         br_dtx_flag = ( ( st_fx->element_mode == EVS_MONO ) && LE_32( st_fx->total_brate, MAX_BRATE_DTX_EVS ) ) ||
     213     1826592 :                       ( ( st_fx->element_mode != EVS_MONO ) && LE_32( ivas_total_brate, MAX_BRATE_DTX_IVAS ) ) ||
     214      708962 :                       LT_16( st_fx->lp_noise_fx, DTX_THR * 256 );
     215             :     }
     216     1129000 :     test();
     217     1129000 :     test();
     218     1129000 :     test();
     219     1129000 :     test();
     220     1129000 :     IF( st_fx->Opt_DTX_ON && vad == 0 &&
     221             :         GT_16( st_fx->ini_frame, 2 ) && /* CNG coding starts after 2 frames */
     222             :         br_dtx_flag &&
     223             :         st_fx->fd_cng_reset_flag == 0 )
     224             :     {
     225             :         /* reset counter */
     226       34264 :         st_fx->active_cnt = 0;
     227       34264 :         move16();
     228             : 
     229       34264 :         IF( st_fx->Opt_AMR_WB )
     230             :         {
     231           0 :             st_fx->last_total_brate_cng = -1;
     232           0 :             move16();
     233             :         }
     234             :         ELSE
     235             :         {
     236       34264 :             st_fx->last_total_brate_cng = st_fx->total_brate;
     237       34264 :             move16();
     238       34264 :             st_fx->last_bwidth_cng = st_fx->bwidth;
     239       34264 :             move16();
     240       34264 :             st_fx->last_codec_mode_cng = st_fx->codec_mode;
     241       34264 :             move16();
     242       34264 :             st_fx->last_rf_mode_cng = st_fx->rf_mode;
     243       34264 :             move16();
     244             :         }
     245             : 
     246       34264 :         IF( hDtxEnc->cnt_SID == 0 )
     247             :         {
     248             :             /* this will be a SID frame */
     249        6068 :             IF( st_fx->Opt_AMR_WB )
     250             :             {
     251           0 :                 st_fx->core_brate = SID_1k75;
     252           0 :                 move32();
     253             :             }
     254             :             ELSE
     255             :             {
     256        6068 :                 st_fx->core_brate = SID_2k40;
     257        6068 :                 move32();
     258             :             }
     259             :         }
     260             :         ELSE
     261             :         {
     262             :             /* this will be a no data frame */
     263       28196 :             st_fx->core_brate = FRAME_NO_DATA;
     264       28196 :             move32();
     265             :         }
     266             : 
     267       34264 :         test();
     268       34264 :         test();
     269       34264 :         IF( ( st_fx->core_brate == FRAME_NO_DATA ) && ( st_fx->last_core != ACELP_CORE ) && !st_fx->Opt_AMR_WB )
     270             :         {
     271             :             /* force SID frame when switching from HQ core or AMR-WB IO mode into inactive frame in ACELP core when DTX is on */
     272        2357 :             st_fx->core_brate = SID_2k40;
     273        2357 :             move32();
     274             :         }
     275             :         // PMT("dtx_sce_sba code is missing")
     276       34264 :         test();
     277       34264 :         test();
     278       34264 :         IF( ( ( st_fx->last_core != ACELP_CORE ) || EQ_16( st_fx->cng_type, FD_CNG ) ) && EQ_16( st_fx->dtx_sce_sba, 1 ) )
     279             :         {
     280        1726 :             st_fx->cng_type = FD_CNG;
     281        1726 :             move16();
     282        1726 :             test();
     283        1726 :             test();
     284        1726 :             test();
     285        1726 :             test();
     286        1726 :             test();
     287        1726 :             test();
     288        1726 :             IF( ( st_fx->element_mode == EVS_MONO ) && ( EQ_32( st_fx->total_brate, ACELP_9k60 ) || EQ_32( st_fx->total_brate, ACELP_16k40 ) || EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_48k ) || EQ_32( st_fx->total_brate, HQ_96k ) || EQ_32( st_fx->total_brate, HQ_128k ) ) )
     289             :             {
     290           0 :                 st_fx->codec_mode = MODE2;
     291           0 :                 move16();
     292             :             }
     293             :         }
     294             :         ELSE
     295             :         {
     296       32538 :             test();
     297       32538 :             test();
     298       32538 :             test();
     299       32538 :             test();
     300       32538 :             IF( ( EQ_16( st_fx->cng_type, FD_CNG ) && ( LE_32( st_fx->total_brate, MAX_BRATE_DTX_EVS ) || ( ( st_fx->element_mode != EVS_MONO ) && LE_32( ivas_total_brate, MAX_BRATE_DTX_IVAS ) ) ) ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) /* at highest bitrates, use exclusively LP_CNG */
     301             :             {
     302       29884 :                 test();
     303       29884 :                 test();
     304       29884 :                 test();
     305       29884 :                 IF( ( st_fx->element_mode == EVS_MONO ) && ( EQ_32( st_fx->total_brate, ACELP_9k60 ) || EQ_32( st_fx->total_brate, ACELP_16k40 ) || EQ_32( st_fx->total_brate, ACELP_24k40 ) ) )
     306             :                 {
     307           0 :                     st_fx->codec_mode = MODE2;
     308           0 :                     move16();
     309             :                 }
     310             :             }
     311             :             ELSE
     312             :             {
     313        2654 :                 st_fx->cng_type = LP_CNG;
     314        2654 :                 move16();
     315        2654 :                 if ( EQ_16( st_fx->codec_mode, MODE2 ) )
     316             :                 {
     317           0 :                     hTdCngEnc->lp_cng_mode2 = 1;
     318           0 :                     move16();
     319             :                 }
     320        2654 :                 st_fx->codec_mode = MODE1;
     321        2654 :                 move16();
     322             :             }
     323             :         }
     324             :         /* reset the bitstream (IVAS format signalling was already written) */
     325       34264 :         test();
     326       34264 :         IF( NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) && st_fx->hBstr != NULL )
     327             :         {
     328             : 
     329       22272 :             reset_indices_enc_fx( st_fx->hBstr, st_fx->hBstr->nb_ind_tot );
     330             :         }
     331             :     }
     332     1094736 :     ELSE IF( st_fx->element_mode != EVS_MONO )
     333             :     {
     334     1094736 :         st_fx->total_brate = total_brate_ref;
     335     1094736 :         move32();
     336             :     }
     337             : 
     338             :     /*------------------------------------------------------------------------*
     339             :      * Reset counters when in active frame (not in SID or FRAME_NO_DATA frame)
     340             :      *------------------------------------------------------------------------*/
     341             :     /* NB core bit rate can be "-1"  at startup , so one can not use   core_brate_fx <=2400 */
     342     1129000 :     test();
     343     1129000 :     test();
     344     1129000 :     IF( ( NE_32( st_fx->core_brate, SID_2k40 ) ) && ( NE_32( st_fx->core_brate, SID_1k75 ) ) && ( st_fx->core_brate != FRAME_NO_DATA ) )
     345             :     {
     346     1094736 :         IF( hDtxEnc != NULL )
     347             :         {
     348      104688 :             hDtxEnc->cnt_SID = 0;
     349      104688 :             move16();
     350             : 
     351             :             /* change SID update rate */
     352             :             /* first SID update is only 8 (3) frames after the active speech end */
     353      104688 :             IF( !st_fx->Opt_AMR_WB )
     354             :             {
     355      104688 :                 hDtxEnc->max_SID = FIXED_SID_RATE;
     356      104688 :                 move16();
     357             :             }
     358             :             ELSE
     359             :             {
     360           0 :                 hDtxEnc->max_SID = 3;
     361           0 :                 move16(); /* first SID update is only 3 frames after the active speech end */
     362             :             }
     363             : 
     364      104688 :             if ( LT_16( hDtxEnc->interval_SID, hDtxEnc->max_SID ) )
     365             :             {
     366           0 :                 hDtxEnc->max_SID = hDtxEnc->interval_SID;
     367           0 :                 move16(); /* change SID update rate */
     368             :             }
     369             : 
     370      104688 :             hDtxEnc->cng_cnt = 0;
     371      104688 :             move16(); /* reset the counter of CNG frames for averaging */
     372             :         }
     373     1094736 :         test();
     374     1094736 :         test();
     375     1094736 :         IF( GE_16( st_fx->active_cnt, CNG_TYPE_HO ) && st_fx->Opt_AMR_WB == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) )
     376             :         {
     377      401747 :             IF( EQ_16( st_fx->element_mode, IVAS_SCE ) )
     378             :             {
     379             :                 Word32 lp_thresh, fd_thresh;
     380             :                 // PMT( "lp_thresh scaling is to be found" )
     381      348457 :                 test();
     382      348457 :                 IF( st_fx->Opt_DTX_ON && EQ_16( st_fx->dtx_sce_sba, 1 ) )
     383             :                 {
     384        9446 :                     lp_thresh = 327680; // 5 in Q16
     385        9446 :                     move32();
     386        9446 :                     fd_thresh = 131072; // 2 in Q16
     387        9446 :                     move32();
     388             :                 }
     389             :                 ELSE
     390             :                 {
     391      339011 :                     lp_thresh = 655360; // 10 in Q16
     392      339011 :                     move32();
     393      339011 :                     fd_thresh = 327680; // 5 in Q16
     394      339011 :                     move32();
     395             :                 }
     396             : 
     397             :                 /*More conservative selection of LP-CNG for SCE*/
     398      348457 :                 test();
     399      348457 :                 test();
     400      348457 :                 test();
     401      348457 :                 IF( st_fx->cng_type == LP_CNG && ( GT_32( st_fx->bckr_tilt_lt, lp_thresh ) ) )
     402             :                 {
     403           0 :                     st_fx->cng_type = FD_CNG;
     404           0 :                     move16();
     405             :                 }
     406      348457 :                 ELSE IF( EQ_16( st_fx->cng_type, FD_CNG ) && ( LT_32( st_fx->bckr_tilt_lt, fd_thresh ) ) && ( GT_16( st_fx->lp_noise_fx, 512 /* 2 in Q8 */ ) ) )
     407             :                 {
     408          64 :                     st_fx->cng_type = LP_CNG;
     409          64 :                     move16();
     410             :                 }
     411             :             }
     412             :             ELSE
     413             :             {
     414       53290 :                 test();
     415       53290 :                 test();
     416       53290 :                 test();
     417       53290 :                 test();
     418       53290 :                 test();
     419       53290 :                 test();
     420       53290 :                 test();
     421       53290 :                 test();
     422       53290 :                 IF( ( st_fx->cng_type == LP_CNG ) && ( ( ( st_fx->input_bwidth == NB ) && GT_32( st_fx->bckr_tilt_lt, 589824 /*9.f Q16*/ ) ) || ( ( st_fx->input_bwidth > NB ) && GT_32( st_fx->bckr_tilt_lt, 2949120l /*45.f Q16*/ ) ) ) )
     423             :                 {
     424          66 :                     st_fx->cng_type = FD_CNG;
     425          66 :                     move16();
     426             :                 }
     427       53224 :                 ELSE IF( EQ_16( st_fx->cng_type, FD_CNG ) && ( ( ( st_fx->input_bwidth == NB ) && LT_32( st_fx->bckr_tilt_lt, 131072l /*2.f Q16*/ ) ) || ( ( st_fx->input_bwidth > NB ) && LT_32( st_fx->bckr_tilt_lt, 655360l /*10.f Q16*/ ) ) ) )
     428             :                 {
     429          39 :                     st_fx->cng_type = LP_CNG;
     430          39 :                     move16();
     431             :                 }
     432             :             }
     433      401747 :             st_fx->last_total_brate_cng = -1;
     434      401747 :             move16();
     435             :         }
     436      692989 :         ELSE IF( st_fx->Opt_AMR_WB )
     437             :         {
     438           0 :             st_fx->cng_type = LP_CNG;
     439           0 :             move16();
     440             :         }
     441     1094736 :         st_fx->active_cnt = add( st_fx->active_cnt, 1 );
     442     1094736 :         move16();
     443     1094736 :         st_fx->active_cnt = s_min( st_fx->active_cnt, 200 );
     444     1094736 :         move16();
     445             :     }
     446             : 
     447             :     /*------------------------------------------------------------------------*
     448             :      * Update speech and background noise long-term energy
     449             :      *------------------------------------------------------------------------*/
     450     1129000 :     IF( hDtxEnc != NULL )
     451             :     {
     452      138952 :         hDtxEnc->frame_ener_fx = L_deposit_l( 0 );
     453      138952 :         move32();
     454             : 
     455      138952 :         IF( st_fx->Opt_DTX_ON )
     456             :         {
     457      138952 :             Q_speech2 = add( shl( Q_speech, 1 ), 7 );
     458     2362184 :             FOR( j = 0; j < 16; j++ )
     459             :             {
     460     2223232 :                 L_tmp = L_mult0( *speech, *speech ); /*2*Q_speech*/
     461     2223232 :                 speech++;
     462    35571712 :                 FOR( i = 1; i < L_FRAME / 16; i++ )
     463             :                 {
     464    33348480 :                     L_tmp = L_mac0_o( L_tmp, *speech, *speech, &Overflow ); /*2*Q_speech*/
     465    33348480 :                     speech++;
     466             :                 }
     467     2223232 :                 hDtxEnc->frame_ener_fx = L_add( hDtxEnc->frame_ener_fx, L_shr( L_tmp, Q_speech2 ) ); /* Q(-7) */
     468     2223232 :                 move32();
     469             :             }
     470             : 
     471             :             /* Active speech (voiced) */
     472             : 
     473      138952 :             IF( EQ_16( st_fx->clas, VOICED_CLAS ) )
     474             :             {
     475       20661 :                 alpha = ALPHA_ENER_SLOW_FX; /*Q15 */
     476       20661 :                 move16();
     477       20661 :                 if ( GT_32( hDtxEnc->frame_ener_fx, hDtxEnc->lt_ener_voiced_fx ) )
     478             :                 {
     479        6492 :                     alpha = ALPHA_ENER_FAST_FX; /*Q15 */
     480        6492 :                     move16();
     481             :                 }
     482             : 
     483             :                 /*st_fx->lt_ener_voiced_fx = alpha * st_fx->lt_ener_voiced_fx + (1.0f-alpha) * st_fx->frame_ener_fx;*/
     484       20661 :                 L_tmp = L_sub( hDtxEnc->lt_ener_voiced_fx, hDtxEnc->frame_ener_fx ); /*Q(-7)*/
     485       20661 :                 L_tmp = Mult_32_16( L_tmp, alpha );                                  /*Q(-7)*/
     486       20661 :                 hDtxEnc->lt_ener_voiced_fx = L_add( L_tmp, hDtxEnc->frame_ener_fx ); /* Q(-7) */
     487       20661 :                 move32();
     488             : 
     489       20661 :                 hDtxEnc->VarDTX_cnt_voiced = add( hDtxEnc->VarDTX_cnt_voiced, 1 );
     490       20661 :                 move16();
     491             : 
     492       20661 :                 hDtxEnc->VarDTX_cnt_voiced = s_min( hDtxEnc->VarDTX_cnt_voiced, MIN_CNT );
     493       20661 :                 move16();
     494             :             }
     495             :             /* Background noise */
     496      118291 :             ELSE IF( !st_fx->Opt_AMR_WB )
     497             :             {
     498      118291 :                 alpha = ALPHA_ENER_SLOW_FX; /*Q15*/
     499      118291 :                 move16();
     500      118291 :                 if ( LT_32( hDtxEnc->frame_ener_fx, hDtxEnc->lt_ener_noise_fx ) )
     501             :                 {
     502       30579 :                     alpha = ALPHA_ENER_FAST_FX; /*Q15*/
     503       30579 :                     move16();
     504             :                 }
     505             : 
     506             :                 /*st_fx->lt_ener_noise_fx = alpha * st_fx->lt_ener_noise_fx + (1.0f-alpha) * st_fx->frame_ener_fx;*/
     507      118291 :                 L_tmp = L_sub( hDtxEnc->lt_ener_noise_fx, hDtxEnc->frame_ener_fx ); /* Q(-7) */
     508      118291 :                 L_tmp = Mult_32_16( L_tmp, alpha );                                 /* Q(-7) */
     509      118291 :                 hDtxEnc->lt_ener_noise_fx = L_add( L_tmp, hDtxEnc->frame_ener_fx ); /* Q(-7) */
     510      118291 :                 move32();
     511             : 
     512      118291 :                 hDtxEnc->VarDTX_cnt_noise = add( hDtxEnc->VarDTX_cnt_noise, 1 );
     513      118291 :                 move16();
     514             : 
     515      118291 :                 hDtxEnc->VarDTX_cnt_noise = s_min( hDtxEnc->VarDTX_cnt_noise, MIN_CNT );
     516      118291 :                 move16();
     517             :             }
     518             :         }
     519             :     }
     520             : 
     521             :     /* Update of the SID counter */
     522     1129000 :     update_SID_cnt_fx( hDtxEnc, st_fx->core_brate, st_fx->Opt_AMR_WB );
     523             : 
     524             :     /* Update encoded bandwidth */
     525     1129000 :     test();
     526     1129000 :     test();
     527     1129000 :     IF( st_fx->Opt_DTX_ON && ( EQ_32( st_fx->core_brate, SID_2k40 ) || ( st_fx->core_brate == FRAME_NO_DATA ) ) )
     528             :     {
     529             : 
     530       34264 :         st_fx->bwidth = st_fx->last_bwidth;
     531       34264 :         move16();
     532       34264 :         test();
     533       34264 :         IF( GT_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_total_brate_cng, -1 ) )
     534             :         {
     535        9572 :             st_fx->bwidth = st_fx->last_bwidth_cng;
     536        9572 :             move16();
     537             :         }
     538             : 
     539       34264 :         test();
     540       34264 :         test();
     541       34264 :         IF( st_fx->Opt_RF_ON && ( EQ_32( st_fx->total_brate, ACELP_13k20 ) ) && ( ( st_fx->bwidth == NB ) ) )
     542             :         {
     543           0 :             st_fx->codec_mode = MODE1;
     544           0 :             move16();
     545           0 :             reset_rf_indices_fx( st_fx );
     546           0 :             st_fx->Opt_RF_ON = 0;
     547           0 :             move16();
     548           0 :             st_fx->rf_mode = 0;
     549           0 :             move16();
     550             :         }
     551             : 
     552       34264 :         test();
     553       34264 :         IF( st_fx->Opt_RF_ON && NE_32( st_fx->total_brate, ACELP_13k20 ) )
     554             :         {
     555           0 :             reset_rf_indices_fx( st_fx );
     556           0 :             move16();
     557           0 :             st_fx->Opt_RF_ON = 0;
     558           0 :             move16();
     559           0 :             st_fx->rf_mode = 0;
     560             :         }
     561             : 
     562             :         /* Set and limit the encoded bandwidth */
     563       34264 :         IF( EQ_16( st_fx->codec_mode, MODE2 ) )
     564             :         {
     565             :             Word16 n, bits_frame_nominal;
     566             : 
     567             :             UWord16 lsb;
     568             :             Word16 tmpbandwidthMin;
     569             : 
     570           0 :             Mpy_32_16_ss( st_fx->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */
     571           0 :             bits_frame_nominal = extract_l( L_shr( L_tmp, 3 ) );    /* Q0 */
     572             : 
     573           0 :             FOR( n = 0; n < FRAME_SIZE_NB; n++ )
     574             :             {
     575           0 :                 IF( EQ_16( FrameSizeConfig[n].frame_bits, bits_frame_nominal ) )
     576             :                 {
     577           0 :                     BREAK;
     578             :                 }
     579             :             }
     580           0 :             IF( EQ_16( n, FRAME_SIZE_NB ) )
     581             :             {
     582           0 :                 assert( !"Bitrate not supported: not part of EVS" );
     583             :             }
     584           0 :             tmpbandwidthMin = FrameSizeConfig[n].bandwidth_min;
     585           0 :             move16();
     586           0 :             if ( EQ_16( st_fx->rf_mode, 1 ) )
     587             :             {
     588           0 :                 tmpbandwidthMin = WB;
     589           0 :                 move16();
     590             :             }
     591           0 :             st_fx->bwidth = s_max( s_min( st_fx->bwidth, FrameSizeConfig[n].bandwidth_max ), tmpbandwidthMin );
     592           0 :             move16();
     593             :         }
     594             :     }
     595             : 
     596     1129000 :     return;
     597             : }
     598             : 
     599             : /*==================================================================================*/
     600             : /* FUNCTION : dtx_fx()                                                              */
     601             : /*----------------------------------------------------------------------------------*/
     602             : /* PURPOSE :  Discontinuous transmission operation                                  */
     603             : /*----------------------------------------------------------------------------------*/
     604             : /*  INPUT ARGUMENTS :                                                               */
     605             : /* _ (Encoder_State_Fx) st_fx : encoder state structure                             */
     606             : /* _ (Word16)   vad           : vad flag                                       Q0   */
     607             : /* _ (Word16[]) speech_fx     : Pointer to the speech frame               qSpeech   */
     608             : /* _ (Word16)   qSpeech       : speech buffer qformat value                         */
     609             : /* _ (Word16*)  qener         : frame_ener/lt_ener_voiced/lt_ener_noise buf qformat */
     610             : /*----------------------------------------------------------------------------------*/
     611             : /* OUTPUT ARGUMENTS :                                                               */
     612             : /* _ (Word16*)  qener         : frame_ener/lt_ener_voiced/lt_ener_noise buf qformat */
     613             : /* _ (Encoder_State_Fx) st_fx : encoder state structure                             */
     614             : /*----------------------------------------------------------------------------------*/
     615             : 
     616             : /*----------------------------------------------------------------------------------*/
     617             : /* RETURN ARGUMENTS :                                                               */
     618             : /* _ None                                                                           */
     619             : /*==================================================================================*/
     620        3100 : void dtx_fx(
     621             :     Encoder_State *st_fx,  /* i/o: encoder state structure                  */
     622             :     const Word16 vad,      /* i  : vad flag for DTX                         Q0*/
     623             :     const Word16 speech[], /* i  : Pointer to the speech frame              Q_speech*/
     624             :     Word16 Q_speech        /* i  : Q factor for speech                      */
     625             : 
     626             : )
     627             : {
     628             :     Word16 alpha, j, i, Q_speech2;
     629             :     Word32 L_tmp;
     630        3100 :     DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc;
     631        3100 :     TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc;
     632             : 
     633             :     Word16 last_br_cng_flag, last_br_flag, br_dtx_flag;
     634             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     635        3100 :     Flag Overflow = 0;
     636        3100 :     move32();
     637             : #endif
     638             : 
     639        3100 :     IF( st_fx->dtx_sce_sba != 0 )
     640             :     {
     641           0 :         last_br_cng_flag = 1;
     642           0 :         last_br_flag = 1;
     643           0 :         br_dtx_flag = 1;
     644           0 :         move16();
     645           0 :         move16();
     646           0 :         move16();
     647             :     }
     648             :     ELSE
     649             :     {
     650        3100 :         last_br_cng_flag = LE_32( st_fx->last_total_brate_cng, ACELP_24k40 ) || LT_16( st_fx->lp_noise_fx, DTX_THR * 256 ) || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->last_total_brate_cng, ACELP_32k ) );
     651             : 
     652        3100 :         last_br_flag = LE_32( st_fx->last_total_brate, ACELP_24k40 ) || LT_16( st_fx->lp_noise_fx, DTX_THR * 256 ) || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->last_total_brate, ACELP_32k ) );
     653        3100 :         br_dtx_flag = 0;
     654        3100 :         move16();
     655             :     }
     656             :     /* Initialization */
     657        3100 :     IF( st_fx->ini_frame == 0 )
     658             :     {
     659           3 :         st_fx->active_fr_cnt_fx = CNG_TYPE_HO;
     660           3 :         move16();
     661             : 
     662           3 :         st_fx->cng_type = FD_CNG;
     663           3 :         move16();
     664           3 :         test();
     665           3 :         IF( ( EQ_16( st_fx->codec_mode, MODE1 ) || st_fx->Opt_AMR_WB ) && EQ_16( st_fx->element_mode, IVAS_SCE ) && EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) )
     666             :         {
     667           0 :             st_fx->cng_type = LP_CNG;
     668           0 :             move16();
     669             :         }
     670             :     }
     671        3100 :     test();
     672        3100 :     test();
     673        3100 :     IF( st_fx->Opt_DTX_ON && vad == 0 &&
     674             :         GT_16( st_fx->ini_frame, 2 ) && /* CNG coding starts after 2 frames */
     675             :         st_fx->fd_cng_reset_flag == 0 &&
     676             :         NE_16( st_fx->last_core, AMR_WB_CORE ) &&
     677             :         st_fx->Opt_AMR_WB == 0 )
     678             :     {
     679           0 :         test();
     680           0 :         test();
     681           0 :         test();
     682           0 :         IF( GT_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_total_brate_cng, -1 ) &&
     683             :             NE_32( st_fx->last_total_brate_cng, st_fx->total_brate ) && last_br_cng_flag )
     684             :         {
     685           0 :             st_fx->total_brate = st_fx->last_total_brate_cng;
     686           0 :             move32();
     687           0 :             test();
     688           0 :             IF( !( EQ_32( st_fx->total_brate, ACELP_7k20 ) && st_fx->Opt_SC_VBR ) )
     689             :             {
     690           0 :                 st_fx->Opt_SC_VBR = 0;
     691           0 :                 move16();
     692             :             }
     693           0 :             st_fx->rf_mode = st_fx->last_rf_mode_cng;
     694           0 :             move16();
     695           0 :             st_fx->bwidth = st_fx->last_bwidth_cng;
     696           0 :             move16();
     697           0 :             st_fx->codec_mode = st_fx->last_codec_mode_cng;
     698           0 :             move16();
     699             :         }
     700           0 :         test();
     701           0 :         test();
     702           0 :         IF( LE_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_total_brate, st_fx->total_brate ) && last_br_flag )
     703             : 
     704             :         {
     705           0 :             st_fx->total_brate = st_fx->last_total_brate;
     706           0 :             move32();
     707           0 :             test();
     708           0 :             IF( !( EQ_32( st_fx->total_brate, ACELP_7k20 ) && st_fx->Opt_SC_VBR ) )
     709             :             {
     710           0 :                 st_fx->Opt_SC_VBR = 0;
     711           0 :                 move16();
     712             :             }
     713             : 
     714           0 :             st_fx->Opt_RF_ON = 0;
     715           0 :             move16();
     716           0 :             test();
     717           0 :             test();
     718           0 :             test();
     719           0 :             IF( st_fx->rf_mode && st_fx->rf_fec_offset > 0 && EQ_32( st_fx->total_brate, ACELP_13k20 ) && NE_16( st_fx->bwidth, NB ) )
     720             :             {
     721           0 :                 st_fx->Opt_RF_ON = 1;
     722           0 :                 move16();
     723             :             }
     724           0 :             st_fx->rf_mode = st_fx->Opt_RF_ON;
     725           0 :             move16();
     726           0 :             st_fx->bwidth = st_fx->last_bwidth;
     727           0 :             move32();
     728           0 :             IF( ( st_fx->element_mode > EVS_MONO ) )
     729             :             {
     730           0 :                 st_fx->codec_mode = MODE1;
     731           0 :                 move16();
     732             :             }
     733             :             ELSE
     734             :             {
     735           0 :                 st_fx->codec_mode = get_codec_mode( st_fx->total_brate );
     736             :             }
     737             :         }
     738             :     }
     739             : 
     740             :     /*------------------------------------------------------------------------*
     741             :      * Select SID or FRAME_NO_DATA frame if DTX is enabled
     742             :      *------------------------------------------------------------------------*/
     743             : 
     744        3100 :     if ( st_fx->dtx_sce_sba == 0 )
     745             :     {
     746        7200 :         br_dtx_flag = LE_32( st_fx->total_brate, ACELP_24k40 ) || LT_16( st_fx->lp_noise_fx, DTX_THR * 256 ) || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->total_brate, ACELP_32k ) ) ||
     747        4100 :                       EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && ( LE_32( st_fx->element_brate, IVAS_64k ) || LT_16( st_fx->lp_noise_fx, DTX_THR * 256 ) ) );
     748             :     }
     749        3100 :     test();
     750        3100 :     test();
     751        3100 :     test();
     752        3100 :     test();
     753        3100 :     IF( st_fx->Opt_DTX_ON && vad == 0 &&
     754             :         GT_16( st_fx->ini_frame, 2 ) && /* CNG coding starts after 2 frames */
     755             :         br_dtx_flag &&
     756             :         st_fx->fd_cng_reset_flag == 0 )
     757             :     {
     758             :         /* reset counter */
     759           0 :         st_fx->active_fr_cnt_fx = 0;
     760           0 :         move16();
     761             : 
     762           0 :         IF( st_fx->Opt_AMR_WB )
     763             :         {
     764           0 :             st_fx->last_total_brate_cng = -1;
     765           0 :             st_fx->last_rf_mode_cng = st_fx->rf_mode;
     766           0 :             move32();
     767           0 :             move16();
     768             :         }
     769             :         ELSE
     770             :         {
     771           0 :             st_fx->last_total_brate_cng = st_fx->total_brate;
     772           0 :             st_fx->last_bwidth_cng = st_fx->bwidth;
     773           0 :             st_fx->last_codec_mode_cng = st_fx->codec_mode;
     774           0 :             move32();
     775           0 :             move16();
     776           0 :             move16();
     777             :         }
     778             : 
     779           0 :         IF( hDtxEnc->cnt_SID == 0 )
     780             :         {
     781             :             /* this will be a SID frame */
     782           0 :             IF( st_fx->Opt_AMR_WB )
     783             :             {
     784           0 :                 st_fx->core_brate = SID_1k75;
     785           0 :                 move32();
     786             :             }
     787             :             ELSE
     788             :             {
     789           0 :                 st_fx->core_brate = SID_2k40;
     790           0 :                 move32();
     791             :             }
     792             :         }
     793             :         ELSE
     794             :         {
     795             :             /* this will be a no data frame */
     796           0 :             st_fx->core_brate = FRAME_NO_DATA;
     797           0 :             move32();
     798             :         }
     799             : 
     800           0 :         test();
     801           0 :         test();
     802           0 :         IF( ( st_fx->core_brate == FRAME_NO_DATA ) && ( st_fx->last_core != ACELP_CORE ) && !st_fx->Opt_AMR_WB )
     803             :         {
     804             :             /* force SID frame when switching from HQ core or AMR-WB IO mode into inactive frame in ACELP core when DTX is on */
     805           0 :             st_fx->core_brate = SID_2k40;
     806           0 :             move32();
     807             :         }
     808             : 
     809             :         {
     810           0 :             test();
     811           0 :             test();
     812           0 :             test();
     813           0 :             test();
     814           0 :             IF( ( EQ_16( st_fx->cng_type, FD_CNG ) && ( LE_32( st_fx->total_brate, ACELP_24k40 ) || ( ( st_fx->element_mode != EVS_MONO ) && LE_32( st_fx->total_brate, ACELP_32k ) ) ) ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) /* at highest bitrates, use exclusively LP_CNG */
     815             :             {
     816           0 :                 test();
     817           0 :                 test();
     818           0 :                 IF( EQ_16( st_fx->element_mode, EVS_MONO ) && ( EQ_32( st_fx->total_brate, ACELP_9k60 ) || EQ_32( st_fx->total_brate, ACELP_16k40 ) || EQ_32( st_fx->total_brate, ACELP_24k40 ) ) )
     819             :                 {
     820           0 :                     st_fx->codec_mode = MODE2;
     821           0 :                     move16();
     822             :                 }
     823             :             }
     824             :             ELSE
     825             :             {
     826           0 :                 st_fx->cng_type = LP_CNG;
     827           0 :                 move16();
     828           0 :                 IF( st_fx->codec_mode == MODE2 )
     829             :                 {
     830           0 :                     hTdCngEnc->lp_cng_mode2 = 1;
     831           0 :                     move16();
     832             :                 }
     833           0 :                 st_fx->codec_mode = MODE1;
     834           0 :                 move16();
     835             :             }
     836             :         }
     837             : 
     838             :         /* reset the bitstream (IVAS format signalling was already written) */
     839           0 :         IF( NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) && st_fx->hBstr != NULL )
     840             :         {
     841             : #ifdef HARM_PUSH_BIT
     842           0 :             reset_indices_enc_fx( st_fx->hBstr, st_fx->hBstr->nb_ind_tot );
     843             : #else
     844             :             reset_indices_enc_fx( st_fx->hBstr, MAX_NUM_INDICES );
     845             : #endif
     846             :         }
     847             :     }
     848             : 
     849             :     /*------------------------------------------------------------------------*
     850             :      * Reset counters when in active frame (not in SID or FRAME_NO_DATA frame)
     851             :      *------------------------------------------------------------------------*/
     852             :     /* NB core bit rate can be "-1"  at startup , so one can not use   core_brate_fx <=2400 */
     853        3100 :     test();
     854        3100 :     test();
     855        3100 :     IF( ( NE_32( st_fx->core_brate, SID_2k40 ) ) && ( NE_32( st_fx->core_brate, SID_1k75 ) ) && ( st_fx->core_brate != FRAME_NO_DATA ) )
     856             :     {
     857        3100 :         IF( hDtxEnc != NULL )
     858             :         {
     859        3100 :             hDtxEnc->cnt_SID = 0;
     860        3100 :             move16();
     861             : 
     862             :             /* change SID update rate */
     863             :             /* first SID update is only 8 (3) frames after the active speech end */
     864        3100 :             IF( !st_fx->Opt_AMR_WB )
     865             :             {
     866        3100 :                 hDtxEnc->max_SID = FIXED_SID_RATE;
     867        3100 :                 move16();
     868             :             }
     869             :             ELSE
     870             :             {
     871           0 :                 hDtxEnc->max_SID = 3;
     872           0 :                 move16(); /* first SID update is only 3 frames after the active speech end */
     873             :             }
     874             : 
     875        3100 :             IF( LT_16( hDtxEnc->interval_SID, hDtxEnc->max_SID ) )
     876             :             {
     877           0 :                 hDtxEnc->max_SID = hDtxEnc->interval_SID;
     878           0 :                 move16(); /* change SID update rate */
     879             :             }
     880             : 
     881        3100 :             hDtxEnc->cng_cnt = 0;
     882        3100 :             move16(); /* reset the counter of CNG frames for averaging */
     883             :         }
     884        3100 :         test();
     885        3100 :         IF( GE_16( st_fx->active_fr_cnt_fx, CNG_TYPE_HO ) && st_fx->Opt_AMR_WB == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) )
     886             :         {
     887        3100 :             IF( EQ_16( st_fx->element_mode, IVAS_SCE ) )
     888             :             {
     889             :             }
     890             :             ELSE
     891             :             {
     892        3100 :                 test();
     893        3100 :                 test();
     894        3100 :                 test();
     895        3100 :                 test();
     896        3100 :                 test();
     897        3100 :                 test();
     898        3100 :                 test();
     899        3100 :                 test();
     900        3100 :                 IF( EQ_16( st_fx->cng_type, LP_CNG ) && ( ( EQ_16( st_fx->input_bwidth, NB ) && GT_32( st_fx->bckr_tilt_lt, 589824l /*9.f Q16*/ ) ) || ( GT_16( st_fx->input_bwidth, NB ) && GT_32( st_fx->bckr_tilt_lt, 2949120l /*45.f Q16*/ ) ) ) )
     901             :                 {
     902           0 :                     st_fx->cng_type = FD_CNG;
     903           0 :                     move16();
     904             :                 }
     905        3100 :                 ELSE IF( EQ_16( st_fx->cng_type, FD_CNG ) && ( ( EQ_16( st_fx->input_bwidth, NB ) && LT_32( st_fx->bckr_tilt_lt, 131072l /*2.f Q16*/ ) ) || ( GT_16( st_fx->input_bwidth, NB ) && LT_32( st_fx->bckr_tilt_lt, 655360l /*10.f Q16*/ ) ) ) )
     906             :                 {
     907           3 :                     st_fx->cng_type = LP_CNG;
     908           3 :                     move16();
     909             :                 }
     910             :             }
     911        3100 :             st_fx->last_total_brate_cng = -1;
     912             :         }
     913           0 :         ELSE IF( st_fx->Opt_AMR_WB )
     914             :         {
     915           0 :             st_fx->cng_type = LP_CNG;
     916           0 :             move16();
     917             :         }
     918        3100 :         st_fx->active_fr_cnt_fx = add( st_fx->active_fr_cnt_fx, 1 );
     919        3100 :         st_fx->active_fr_cnt_fx = s_min( st_fx->active_fr_cnt_fx, 200 );
     920             :     }
     921             : 
     922             :     /*------------------------------------------------------------------------*
     923             :      * Update speech and background noise long-term energy
     924             :      *------------------------------------------------------------------------*/
     925        3100 :     IF( hDtxEnc != NULL )
     926             :     {
     927        3100 :         hDtxEnc->frame_ener_fx = L_deposit_l( 0 );
     928             : 
     929        3100 :         IF( st_fx->Opt_DTX_ON )
     930             :         {
     931           0 :             Q_speech2 = add( shl( Q_speech, 1 ), 7 );
     932           0 :             FOR( j = 0; j < 16; j++ )
     933             :             {
     934           0 :                 L_tmp = L_mult0( *speech, *speech ); /*2*Q_speech*/
     935           0 :                 speech++;
     936           0 :                 FOR( i = 1; i < L_FRAME / 16; i++ )
     937             :                 {
     938           0 :                     L_tmp = L_mac0_o( L_tmp, *speech, *speech, &Overflow ); /*2*Q_speech*/
     939           0 :                     speech++;
     940             :                 }
     941           0 :                 hDtxEnc->frame_ener_fx = L_add( hDtxEnc->frame_ener_fx, L_shr( L_tmp, Q_speech2 ) ); /*Q(-7) */
     942             :             }
     943             : 
     944             :             /* Active speech (voiced) */
     945             : 
     946           0 :             IF( EQ_16( st_fx->clas, VOICED_CLAS ) )
     947             :             {
     948           0 :                 alpha = ALPHA_ENER_SLOW_FX;
     949           0 :                 move16();
     950           0 :                 if ( GT_32( hDtxEnc->frame_ener_fx, hDtxEnc->lt_ener_voiced_fx ) )
     951             :                 {
     952           0 :                     alpha = ALPHA_ENER_FAST_FX; /*Q15 */
     953           0 :                     move16();
     954             :                 }
     955             : 
     956             :                 /*st_fx->lt_ener_voiced_fx = alpha * st_fx->lt_ener_voiced_fx + (1.0f-alpha) * st_fx->frame_ener_fx;*/
     957           0 :                 L_tmp = L_sub( hDtxEnc->lt_ener_voiced_fx, hDtxEnc->frame_ener_fx ); /*Q(-7)*/
     958           0 :                 L_tmp = Mult_32_16( L_tmp, alpha );                                  /*Q(-7)*/
     959           0 :                 hDtxEnc->lt_ener_voiced_fx = L_add( L_tmp, hDtxEnc->frame_ener_fx ); /*Q(-7)*/
     960             : 
     961           0 :                 hDtxEnc->VarDTX_cnt_voiced = add( hDtxEnc->VarDTX_cnt_voiced, 1 );
     962             : 
     963           0 :                 hDtxEnc->VarDTX_cnt_voiced = s_min( hDtxEnc->VarDTX_cnt_voiced, MIN_CNT );
     964             :             }
     965             :             /* Background noise */
     966           0 :             ELSE IF( !st_fx->Opt_AMR_WB )
     967             :             {
     968           0 :                 alpha = ALPHA_ENER_SLOW_FX; /*Q15 */
     969           0 :                 move16();
     970           0 :                 if ( LT_32( hDtxEnc->frame_ener_fx, hDtxEnc->lt_ener_noise_fx ) )
     971             :                 {
     972           0 :                     alpha = ALPHA_ENER_FAST_FX; /*Q15 */
     973           0 :                     move16();
     974             :                 }
     975             : 
     976             :                 /*st_fx->lt_ener_noise_fx = alpha * st_fx->lt_ener_noise_fx + (1.0f-alpha) * st_fx->frame_ener_fx;*/
     977           0 :                 L_tmp = L_sub( hDtxEnc->lt_ener_noise_fx, hDtxEnc->frame_ener_fx ); /*Q(-7)*/
     978           0 :                 L_tmp = Mult_32_16( L_tmp, alpha );                                 /*Q(-7)*/
     979           0 :                 hDtxEnc->lt_ener_noise_fx = L_add( L_tmp, hDtxEnc->frame_ener_fx ); /*Q(-7)*/
     980           0 :                 move32();
     981             : 
     982           0 :                 hDtxEnc->VarDTX_cnt_noise = add( hDtxEnc->VarDTX_cnt_noise, 1 );
     983             : 
     984           0 :                 hDtxEnc->VarDTX_cnt_noise = s_min( hDtxEnc->VarDTX_cnt_noise, MIN_CNT );
     985             :             }
     986             :         }
     987             :     }
     988             : 
     989             :     /* Update of the SID counter */
     990        3100 :     update_SID_cnt_fx( hDtxEnc, st_fx->core_brate, st_fx->Opt_AMR_WB );
     991             : 
     992             :     /* Update encoded bandwidth */
     993        3100 :     test();
     994        3100 :     test();
     995        3100 :     IF( st_fx->Opt_DTX_ON && ( st_fx->core_brate == SID_2k40 || st_fx->core_brate == FRAME_NO_DATA ) )
     996             :     {
     997             : 
     998           0 :         st_fx->bwidth = st_fx->last_bwidth;
     999           0 :         move16();
    1000           0 :         test();
    1001           0 :         IF( GT_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_total_brate_cng, -1 ) )
    1002             :         {
    1003           0 :             st_fx->bwidth = st_fx->last_bwidth_cng;
    1004           0 :             move16();
    1005             :         }
    1006             : 
    1007           0 :         test();
    1008           0 :         test();
    1009           0 :         IF( st_fx->Opt_RF_ON && ( EQ_32( st_fx->total_brate, ACELP_13k20 ) ) && ( EQ_16( st_fx->bwidth, NB ) ) )
    1010             :         {
    1011           0 :             st_fx->codec_mode = MODE1;
    1012           0 :             move16();
    1013           0 :             reset_rf_indices_fx( st_fx );
    1014           0 :             st_fx->Opt_RF_ON = 0;
    1015           0 :             move16();
    1016           0 :             st_fx->rf_mode = 0;
    1017           0 :             move16();
    1018             :         }
    1019             : 
    1020           0 :         test();
    1021           0 :         test();
    1022           0 :         IF( st_fx->Opt_RF_ON && NE_32( st_fx->total_brate, ACELP_13k20 ) )
    1023             :         {
    1024           0 :             reset_rf_indices_fx( st_fx );
    1025           0 :             move16();
    1026           0 :             st_fx->Opt_RF_ON = 0;
    1027           0 :             move16();
    1028           0 :             st_fx->rf_mode = 0;
    1029           0 :             move16();
    1030             :         }
    1031             : 
    1032             :         /* Set and limit the encoded bandwidth */
    1033           0 :         IF( EQ_16( st_fx->codec_mode, MODE2 ) )
    1034             :         {
    1035             :             Word16 n, bits_frame_nominal;
    1036             : 
    1037             :             UWord16 lsb;
    1038             :             Word16 tmpbandwidthMin;
    1039             : 
    1040           0 :             Mpy_32_16_ss( st_fx->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */
    1041           0 :             bits_frame_nominal = extract_l( L_shr( L_tmp, 3 ) );    /* Q0 */
    1042             : 
    1043           0 :             FOR( n = 0; n < FRAME_SIZE_NB; n++ )
    1044             :             {
    1045           0 :                 IF( EQ_16( FrameSizeConfig[n].frame_bits, bits_frame_nominal ) )
    1046             :                 {
    1047           0 :                     BREAK;
    1048             :                 }
    1049             :             }
    1050           0 :             if ( n == FRAME_SIZE_NB )
    1051             :             {
    1052           0 :                 assert( !"Bitrate not supported: not part of EVS" );
    1053             :             }
    1054           0 :             tmpbandwidthMin = FrameSizeConfig[n].bandwidth_min;
    1055           0 :             if ( EQ_16( st_fx->rf_mode, 1 ) )
    1056             :             {
    1057           0 :                 tmpbandwidthMin = WB;
    1058             :             }
    1059           0 :             st_fx->bwidth = s_max( s_min( st_fx->bwidth, FrameSizeConfig[n].bandwidth_max ), tmpbandwidthMin );
    1060             :         }
    1061             :     }
    1062             : 
    1063        3100 :     return;
    1064             : }
    1065             : 
    1066             : /*---------------------------------------------------------------------*
    1067             :  * update_SID_cnt()
    1068             :  *
    1069             :  * Update of the SID counter
    1070             :  *---------------------------------------------------------------------*/
    1071             : 
    1072     1132100 : static void update_SID_cnt_fx(
    1073             :     DTX_ENC_HANDLE hDtxEnc,  /* i/o: common DTX handle       */
    1074             :     const Word32 core_brate, /* i  : core coder core bitrate Q0*/
    1075             :     const Word16 Opt_AMR_WB  /* i  : AMR BW IO mode?         Q0*/
    1076             : )
    1077             : {
    1078             :     Word16 EstimatedSNR, delta, frac, exp;
    1079             :     Word32 L_tmp1, L_tmp2;
    1080             : 
    1081     1132100 :     test();
    1082     1132100 :     test();
    1083     1132100 :     IF( EQ_32( core_brate, SID_2k40 ) || EQ_32( core_brate, SID_1k75 ) || core_brate == FRAME_NO_DATA )
    1084             :     {
    1085             :         /* Adapt the SID interval */
    1086       34264 :         test();
    1087       34264 :         test();
    1088       34264 :         IF( hDtxEnc->var_SID_rate_flag != 0 && EQ_16( hDtxEnc->VarDTX_cnt_voiced, MIN_CNT ) && EQ_16( hDtxEnc->VarDTX_cnt_noise, MIN_CNT ) )
    1089             :         {
    1090             :             /* EstimatedSNR = 10.0f * (float)log10( (0.01f + st_fx->lt_ener_voiced) / (0.01f + st_fx->lt_ener_noise) ); */
    1091             : 
    1092           0 :             L_tmp1 = L_max( hDtxEnc->lt_ener_voiced_fx, 1 );
    1093           0 :             exp = norm_l( L_tmp1 );
    1094           0 :             frac = Log2_norm_lc( L_shl( L_tmp1, exp ) );
    1095           0 :             exp = sub( 30, exp );
    1096           0 :             L_tmp1 = L_Comp( exp, frac ); /*Q16*/
    1097           0 :             L_tmp2 = L_max( hDtxEnc->lt_ener_noise_fx, 1 );
    1098           0 :             exp = norm_l( L_tmp2 );
    1099           0 :             frac = Log2_norm_lc( L_shl( L_tmp2, exp ) );
    1100           0 :             exp = sub( 30, exp );
    1101           0 :             L_tmp1 = L_sub( L_tmp1, L_Comp( exp, frac ) ); /*Q16*/
    1102             :             /* 10 x Log10(a/b) = 10 x Log10(2) x [Log2(a) - Log2(b)] */
    1103             :             /* 10 x Log10(2) = ~3.0103 */
    1104           0 :             L_tmp1 = Mpy_32_16_1( L_tmp1, 24660 ); /* mult by 3.0103 / 4 in Q15 */
    1105           0 :             L_tmp1 = L_shl( L_tmp1, 2 + 8 );       /* mult by 4 and shift left 8 to go in Q24 */
    1106           0 :             EstimatedSNR = round_fx( L_tmp1 );     /* now in Q8 */
    1107           0 :             IF( GT_16( EstimatedSNR, SNR_H_FX ) )
    1108             :             {
    1109           0 :                 hDtxEnc->interval_SID = INT_H;
    1110           0 :                 move16();
    1111             :             }
    1112           0 :             ELSE IF( LT_16( EstimatedSNR, SNR_L_FX ) )
    1113             :             {
    1114           0 :                 hDtxEnc->interval_SID = INT_L;
    1115           0 :                 move16();
    1116             :             }
    1117             :             ELSE
    1118             :             {
    1119           0 :                 hDtxEnc->interval_SID = extract_h( L_mac( INT_L * 65536L - SNR_L_FX / 256 * 65536L * RATIO, ( 32768 / 256 ) * RATIO, EstimatedSNR ) );
    1120             :             }
    1121           0 :             hDtxEnc->interval_SID = s_min( s_max( hDtxEnc->interval_SID, INT_L ), INT_H );
    1122             : 
    1123           0 :             test();
    1124             : 
    1125           0 :             IF( Opt_AMR_WB == 0 || NE_16( hDtxEnc->max_SID, 3 ) )
    1126             :             {
    1127           0 :                 hDtxEnc->max_SID = hDtxEnc->interval_SID;
    1128           0 :                 move16(); /* change SID update rate */
    1129             :             }
    1130             :         }
    1131       34264 :         test();
    1132       34264 :         IF( hDtxEnc->cnt_SID != 0 )
    1133             :         {
    1134       28196 :             L_tmp1 = L_max( hDtxEnc->lt_ener_noise_fx, 1 );
    1135       28196 :             exp = norm_l( L_tmp1 );
    1136       28196 :             frac = Log2_norm_lc( L_shl( L_tmp1, exp ) );
    1137       28196 :             exp = sub( 30, exp );
    1138       28196 :             L_tmp1 = L_Comp( exp, frac ); /*Q16*/
    1139       28196 :             L_tmp2 = L_max( hDtxEnc->lt_ener_last_SID_fx, 1 );
    1140       28196 :             exp = norm_l( L_tmp2 );
    1141       28196 :             frac = Log2_norm_lc( L_shl( L_tmp2, exp ) );
    1142       28196 :             exp = sub( 30, exp );
    1143       28196 :             L_tmp1 = L_sub( L_tmp1, L_Comp( exp, frac ) ); /*Q16*/
    1144             :             /* 10 x Log10(a/b) = 10 x Log10(2) x [Log2(a) - Log2(b)] */
    1145             :             /* 10 x Log10(2) = ~3.0103 */
    1146       28196 :             L_tmp1 = Mpy_32_16_1( L_tmp1, 24660 ); /* mult by 3.0103 / 4 in Q15 */
    1147       28196 :             L_tmp1 = L_shl( L_tmp1, 2 + 8 );       /* mult by 4 and shift left 8 to go in Q24 */
    1148       28196 :             delta = round_fx( L_tmp1 );            /* now in Q8 */
    1149       28196 :             test();
    1150       28196 :             test();
    1151       28196 :             IF( LT_16( delta, LTE_VAR_FX ) && EQ_16( hDtxEnc->VarDTX_cnt_voiced, MIN_CNT ) && EQ_16( hDtxEnc->VarDTX_cnt_noise, MIN_CNT ) )
    1152             :             {
    1153             :                 /* Send SID frame, and reset lt_ener_noise */
    1154         135 :                 hDtxEnc->lt_ener_noise_fx = hDtxEnc->frame_ener_fx; /* Q(-7) */
    1155         135 :                 move32();
    1156             :             }
    1157             :         }
    1158             :         ELSE
    1159             :         {
    1160             :             /* If SID frame was sent, update long-term energy */
    1161        6068 :             hDtxEnc->lt_ener_last_SID_fx = hDtxEnc->lt_ener_noise_fx; /* Q(-7) */
    1162        6068 :             move32();
    1163             :         }
    1164       34264 :         hDtxEnc->cnt_SID = add( hDtxEnc->cnt_SID, 1 );
    1165             : 
    1166       34264 :         IF( hDtxEnc->var_SID_rate_flag )
    1167             :         {
    1168           0 :             test();
    1169           0 :             test();
    1170           0 :             test();
    1171             : 
    1172           0 :             IF( Opt_AMR_WB != 0 && EQ_16( hDtxEnc->max_SID, 3 ) && EQ_16( hDtxEnc->cnt_SID, 3 ) )
    1173             :             {
    1174             :                 /* set the size of CNG history buffer for averaging to DTX_HIST_SIZE frames */
    1175             :                 /* be sure that DTX_HIST_SIZE >= INT_L */
    1176           0 :                 hDtxEnc->cng_hist_size = 3;
    1177           0 :                 move16();
    1178             :             }
    1179           0 :             test();
    1180             :             /*else if ( st_fx->max_SID != 3 && st_fx->cnt_SID == DTX_HIST_SIZE )//compile error */
    1181           0 :             if ( NE_16( hDtxEnc->max_SID, 3 ) && EQ_16( hDtxEnc->cnt_SID, DTX_HIST_SIZE ) )
    1182             :             {
    1183             :                 /* set the size of CNG history buffer for averaging to 3 frames */
    1184           0 :                 hDtxEnc->cng_hist_size = DTX_HIST_SIZE;
    1185           0 :                 move16();
    1186             :             }
    1187             :         }
    1188       34264 :         test();
    1189       34264 :         IF( hDtxEnc->var_SID_rate_flag == 0 && GT_16( hDtxEnc->interval_SID, 1 ) )
    1190             :         {
    1191             :             /* set the size of CNG history buffer for averaging to interval_SID frames */
    1192       34264 :             hDtxEnc->cng_hist_size = hDtxEnc->interval_SID;
    1193       34264 :             move16();
    1194       34264 :             if ( GT_16( hDtxEnc->cng_hist_size, DTX_HIST_SIZE ) )
    1195             :             {
    1196           0 :                 hDtxEnc->cng_hist_size = DTX_HIST_SIZE;
    1197           0 :                 move16();
    1198             :             }
    1199             :         }
    1200       34264 :         IF( GE_16( hDtxEnc->cnt_SID, hDtxEnc->max_SID ) )
    1201             :         {
    1202             :             /* adaptive SID update interval */
    1203        3668 :             hDtxEnc->max_SID = hDtxEnc->interval_SID;
    1204        3668 :             move16();
    1205        3668 :             hDtxEnc->cnt_SID = 0;
    1206        3668 :             move16();
    1207             :         }
    1208             :     }
    1209             : 
    1210     1132100 :     return;
    1211             : }
    1212             : 
    1213             : 
    1214        1552 : void dtx_hangover_control_fx(
    1215             :     Encoder_State *st_fx,      /* i/o: encoder state structure                  */
    1216             :     const Word16 lsp_new_fx[M] /* i  : current frame LSPs                       Q15*/
    1217             : )
    1218             : {
    1219             :     Word16 ptr;
    1220             :     Word16 i, j, m;
    1221             :     Word16 tmp_lsp[/*max(DTX_HIST_SIZE,*/ HO_HIST_SIZE /*)*/ * M];
    1222             :     Word32 tmp_enr[/*max(DTX_HIST_SIZE,*/ HO_HIST_SIZE /*)*/];
    1223             :     Word16 tmp[/*max(DTX_HIST_SIZE,*/ HO_HIST_SIZE /*)*/ * M];
    1224             :     Word16 enr_new;
    1225             :     Word16 weights;
    1226             :     Word32 enr_est;
    1227             :     Word16 enr_est_log;
    1228             :     Word16 lsp_est[M];
    1229             :     Word16 Dlsp, Denr;
    1230             :     Word16 lsf_tmp[M];
    1231             :     Word32 C[M];
    1232             :     Word32 max_val[2];
    1233             :     Word16 max_idx[2];
    1234             :     Word16 ftmp_fx;
    1235             :     Word16 Dlsp_n2e, Denr_n2e;
    1236             :     Word16 exp, fra, exp2, fra2;
    1237             :     Word16 S_max;
    1238             :     Word16 S_tmp;
    1239             :     Word32 L_tmp;
    1240        1552 :     VAD_HANDLE hVAD = st_fx->hVAD;
    1241        1552 :     DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc;
    1242        1552 :     TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc;
    1243             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
    1244        1552 :     Flag Overflow = 0;
    1245             : #endif
    1246             : 
    1247             :     /* get current frame exc energy in log2 */
    1248        1552 :     exp = norm_l( hTdCngEnc->ho_ener_circ_fx[hTdCngEnc->ho_circ_ptr] );
    1249        1552 :     fra = Log2_norm_lc( L_shl( hTdCngEnc->ho_ener_circ_fx[hTdCngEnc->ho_circ_ptr], exp ) );
    1250        1552 :     exp = sub( sub( 30, exp ), 6 );
    1251        1552 :     L_tmp = L_Comp( exp, fra );              /*Q16*/
    1252        1552 :     enr_new = round_fx( L_shl( L_tmp, 8 ) ); /*Q8 */
    1253             : 
    1254        1552 :     if ( enr_new < 0 )
    1255             :     {
    1256         305 :         enr_new = 0;
    1257         305 :         move16(); /*Q8 */
    1258             :     }
    1259             : 
    1260             :     /* get energies and lsps of hangover frames  */
    1261        1552 :     ptr = sub( hTdCngEnc->ho_circ_ptr, sub( hTdCngEnc->burst_ho_cnt, 1 ) ); /*Q0*/
    1262        1552 :     IF( ptr < 0 )
    1263             :     {
    1264         474 :         ptr = add( hTdCngEnc->ho_circ_size, ptr ); /*Q0*/
    1265             :     }
    1266             : 
    1267        6106 :     FOR( i = 0; i < hTdCngEnc->burst_ho_cnt - 1; i++ )
    1268             :     {
    1269        4554 :         Copy( &( hTdCngEnc->ho_lsp_circ_fx[ptr * M] ), &( tmp_lsp[i * M] ), M ); /*Q15*/
    1270        4554 :         tmp_enr[i] = hTdCngEnc->ho_ener_circ_fx[ptr];                            /*Q6 */
    1271        4554 :         move32();
    1272             : 
    1273        4554 :         ptr = add( ptr, 1 );
    1274        4554 :         if ( EQ_16( ptr, hTdCngEnc->ho_circ_size ) )
    1275             :         {
    1276         474 :             ptr = 0;
    1277         474 :             move16();
    1278             :         }
    1279             :     }
    1280             : 
    1281             :     /* get estimated CNG energy and lsps assuming terminate hangover at current frame */
    1282        1552 :     ptr = sub( hTdCngEnc->burst_ho_cnt, 2 );
    1283        1552 :     enr_est = Mpy_32_16_1( tmp_enr[ptr], W_DTX_HO_FX[0] ); /*Q6 */
    1284        1552 :     weights = W_DTX_HO_FX[0];                              /*Q15 */
    1285        1552 :     move16();
    1286        1552 :     Copy( &( tmp_lsp[ptr * M] ), tmp, M );
    1287        1552 :     m = 1;
    1288        1552 :     move16();
    1289             : 
    1290        3466 :     FOR( i = 1; i < hTdCngEnc->burst_ho_cnt - 2; i++ )
    1291             :     {
    1292        1914 :         test();
    1293        1914 :         IF( LT_32( Mpy_32_16_1( tmp_enr[ptr - i], ONE_OVER_BUF_H_NRG_FX ), tmp_enr[ptr] ) &&
    1294             :             GT_32( tmp_enr[ptr - i], Mpy_32_16_1( tmp_enr[ptr], BUF_L_NRG_FX ) ) )
    1295             :         {
    1296         654 :             enr_est = L_add( enr_est, Mpy_32_16_1( tmp_enr[ptr - i], W_DTX_HO_FX[i] ) ); /*Q6 */
    1297         654 :             weights = add( weights, W_DTX_HO_FX[i] );                                    /*Q15 */
    1298         654 :             Copy( &tmp_lsp[( ptr - i ) * M], &tmp[m * M], M );                           /*Q15*/
    1299         654 :             m = add( m, 1 );
    1300             :         }
    1301             :     }
    1302             : 
    1303        1552 :     exp = norm_l( enr_est );
    1304        1552 :     fra = round_fx_sat( L_shl_sat( enr_est, exp ) ); /*Q6+exp-16*/
    1305        1552 :     exp2 = norm_s( weights );
    1306        1552 :     fra2 = shl( weights, exp2 ); /*Q15+exp2*/
    1307        1552 :     exp = sub( sub( exp, 16 ), exp2 );
    1308        1552 :     IF( GT_16( fra, fra2 ) )
    1309             :     {
    1310         489 :         fra = shr( fra, 1 );
    1311         489 :         exp = sub( exp, 1 );
    1312             :     }
    1313        1552 :     L_tmp = L_deposit_l( div_s( fra, fra2 ) ); /*Q6+exp*/
    1314        1552 :     enr_est = L_shr( L_tmp, exp );             /*Q6 */
    1315             : 
    1316        1552 :     if ( LT_32( enr_est, 64 ) )
    1317             :     {
    1318         310 :         enr_est = 64; /*Q6 */
    1319         310 :         move16();
    1320             :     }
    1321             : 
    1322        1552 :     exp = norm_l( enr_est );
    1323        1552 :     fra = Log2_norm_lc( L_shl( enr_est, exp ) );
    1324        1552 :     exp = sub( sub( 30, exp ), 6 );
    1325        1552 :     L_tmp = L_Comp( exp, fra );                      /*Q16*/
    1326        1552 :     enr_est_log = round_fx( L_shl( L_tmp, 8 ) );     /*Q8 */
    1327        1552 :     Denr_n2e = abs_s( sub( enr_new, enr_est_log ) ); /*Q8 */
    1328             : 
    1329        1552 :     IF( LT_16( m, 3 ) )
    1330             :     {
    1331        1385 :         enr_est = L_add( Mpy_32_16_1( enr_est, 26214 ), Mpy_32_16_1( hTdCngEnc->ho_ener_circ_fx[hTdCngEnc->ho_circ_ptr], 6554 ) ); /*Q6 */
    1332             :     }
    1333             :     ELSE
    1334             :     {
    1335         167 :         enr_est = L_add( Mpy_32_16_1( enr_est, 31130 ), Mpy_32_16_1( hTdCngEnc->ho_ener_circ_fx[hTdCngEnc->ho_circ_ptr], 1638 ) ); /*Q6 */
    1336             :     }
    1337             : 
    1338        1552 :     exp = norm_l( enr_est );
    1339        1552 :     fra = Log2_norm_lc( L_shl( enr_est, exp ) );
    1340        1552 :     exp = sub( sub( 30, exp ), 6 );
    1341        1552 :     L_tmp = L_Comp( exp, fra );                  /*Q16*/
    1342        1552 :     enr_est_log = round_fx( L_shl( L_tmp, 8 ) ); /*Q8 */
    1343             : 
    1344        1552 :     if ( enr_est_log < 0 )
    1345             :     {
    1346         315 :         enr_est_log = 0;
    1347         315 :         move16();
    1348             :     }
    1349             : 
    1350        1552 :     set32_fx( max_val, 0, 2 );
    1351        1552 :     set16_fx( max_idx, 0, 2 );
    1352             : 
    1353        3758 :     FOR( i = 0; i < m; i++ )
    1354             :     {
    1355        2206 :         IF( EQ_16( st_fx->L_frame, L_FRAME ) )
    1356             :         {
    1357        1150 :             lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_FX );
    1358        1150 :             ftmp_fx = 964;                                        /*6400.0f / ( M + 1 ) * 2.56*/
    1359        1150 :             move16();                                             /*QX2.56  */
    1360        1150 :             S_tmp = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */
    1361        1150 :             C[i] = L_mult0( S_tmp, S_tmp );                       /*QX6.5536 */
    1362             :         }
    1363             :         ELSE
    1364             :         {
    1365        1056 :             lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_16k );
    1366        1056 :             ftmp_fx = 1205;                                       /*8000.0f/ ( M + 1 ) * 2.56*/
    1367        1056 :             move16();                                             /*QX2.56 */
    1368        1056 :             S_tmp = sub( 20480, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */
    1369        1056 :             C[i] = L_mult0( S_tmp, S_tmp );                       /*QX6.5536 */
    1370             :         }
    1371             : 
    1372        2206 :         S_tmp = sub( lsf_tmp[0], ftmp_fx );  /*QX2.56 */
    1373        2206 :         C[i] = L_mac0( C[i], S_tmp, S_tmp ); /*QX6.5536       */
    1374       35296 :         FOR( j = 0; j < M - 1; j++ )
    1375             :         {
    1376       33090 :             S_tmp = sub( sub( lsf_tmp[j + 1], lsf_tmp[j] ), ftmp_fx ); /*QX2.56 */
    1377       33090 :             C[i] = L_mac0( C[i], S_tmp, S_tmp );                       /*QX6.5536 */
    1378             :         }
    1379             : 
    1380        2206 :         C[i] = Mpy_32_16_1( C[i], 1928 /*Q15*/ ); /*QX6.5536 */
    1381             : 
    1382        2206 :         IF( GT_32( C[i], max_val[0] ) )
    1383             :         {
    1384        1802 :             max_val[1] = max_val[0]; /*x6.5536*/
    1385        1802 :             move16();
    1386        1802 :             max_idx[1] = max_idx[0]; /*Q0*/
    1387        1802 :             move16();
    1388        1802 :             max_val[0] = C[i]; /*x6.5536*/
    1389        1802 :             move16();
    1390        1802 :             max_idx[0] = i;
    1391        1802 :             move16();
    1392             :         }
    1393         404 :         ELSE IF( GT_32( C[i], max_val[1] ) )
    1394             :         {
    1395         272 :             max_val[1] = C[i]; /*x6.5536*/
    1396         272 :             move16();
    1397         272 :             max_idx[1] = i;
    1398         272 :             move16();
    1399             :         }
    1400             :     }
    1401             : 
    1402        1552 :     IF( EQ_16( m, 1 ) )
    1403             :     {
    1404        1163 :         Copy( tmp, lsp_est, M ); /*Q15*/
    1405             :     }
    1406         389 :     ELSE IF( LT_16( m, 4 ) )
    1407             :     {
    1408        5559 :         FOR( i = 0; i < M; i++ )
    1409             :         {
    1410        5232 :             lsp_est[i] = 0; /*Q15 */
    1411        5232 :             move16();
    1412       17376 :             FOR( j = 0; j < m; j++ )
    1413             :             {
    1414       12144 :                 lsp_est[i] = add_o( lsp_est[i], tmp[j * M + i], &Overflow ); /*Q15 */
    1415             :             }
    1416             : 
    1417        5232 :             lsp_est[i] = sub( lsp_est[i], tmp[max_idx[0] * M + i] ); /*Q15 */
    1418        5232 :             S_tmp = div_s( 1, sub( m, 1 ) );                         /*Q15 */
    1419        5232 :             lsp_est[i] = mult_r( lsp_est[i], S_tmp );                /*Q15 */
    1420             :         }
    1421             :     }
    1422             :     ELSE
    1423             :     {
    1424        1054 :         FOR( i = 0; i < M; i++ )
    1425             :         {
    1426         992 :             lsp_est[i] = 0; /*Q15 */
    1427         992 :             move16();
    1428        5536 :             FOR( j = 0; j < m; j++ )
    1429             :             {
    1430        4544 :                 lsp_est[i] = add_o( lsp_est[i], tmp[j * M + i], &Overflow ); /*Q15 */
    1431             :             }
    1432             : 
    1433         992 :             lsp_est[i] = sub_o( lsp_est[i], add_o( tmp[max_idx[0] * M + i], tmp[max_idx[1] * M + i], &Overflow ), &Overflow ); /*Q15 */
    1434         992 :             S_tmp = div_s( 1, sub( m, 2 ) );                                                                                   /*Q15 */
    1435         992 :             lsp_est[i] = mult_r( lsp_est[i], S_tmp );                                                                          /*Q15 */
    1436             :         }
    1437             :     }
    1438             : 
    1439        1552 :     Dlsp_n2e = 0; /*Q15 */
    1440        1552 :     move16();
    1441       26384 :     FOR( i = 0; i < M; i++ )
    1442             :     {
    1443       24832 :         Dlsp_n2e = add_o( Dlsp_n2e, abs_s( sub( lsp_new_fx[i], lsp_est[i] ) ), &Overflow ); /*Q15 */
    1444       24832 :         lsp_est[i] = add( mult_r( 26214, lsp_est[i] ), mult_r( 6554, lsp_new_fx[i] ) );     /*Q15 */
    1445             :     }
    1446             : 
    1447             :     /* get deviation of CNG parameters between newly estimated and current state memory */
    1448        1552 :     Dlsp = 0;
    1449        1552 :     move16();
    1450        1552 :     S_max = 0;
    1451        1552 :     move16();
    1452             : 
    1453       26384 :     FOR( i = 0; i < M; i++ )
    1454             :     {
    1455       24832 :         S_tmp = abs_s( sub( hDtxEnc->lspCNG_fx[i], lsp_est[i] ) ); /*Q15 */
    1456       24832 :         Dlsp = add_o( Dlsp, S_tmp, &Overflow );                    /*Q15 */
    1457       24832 :         IF( GT_16( S_tmp, S_max ) )
    1458             :         {
    1459        7280 :             S_max = S_tmp; /*Q15 */
    1460             :         }
    1461             :     }
    1462             : 
    1463        1552 :     exp = norm_l( hTdCngEnc->lp_ener_fx );
    1464        1552 :     fra = Log2_norm_lc( L_shl( hTdCngEnc->lp_ener_fx, exp ) );
    1465        1552 :     exp = sub( sub( 30, exp ), 6 );
    1466        1552 :     L_tmp = L_Comp( exp, fra );                /*Q16*/
    1467        1552 :     S_tmp = round_fx( L_shl( L_tmp, 8 ) );     /*Q8 */
    1468        1552 :     Denr = abs_s( sub( S_tmp, enr_est_log ) ); /*Q8 */
    1469             : 
    1470             :     /* make decision if DTX hangover can be terminated */
    1471        1552 :     hVAD->hangover_terminate_flag = 0; /*Q0 */
    1472        1552 :     move16();
    1473             : 
    1474        1552 :     test();
    1475        1552 :     test();
    1476        1552 :     test();
    1477        1552 :     test();
    1478        1552 :     test();
    1479        1552 :     test();
    1480        1552 :     test();
    1481        1552 :     test();
    1482        1552 :     test();
    1483        1552 :     test();
    1484        1552 :     test();
    1485        1552 :     IF( ( LT_16( Dlsp, 13107 ) && LT_16( Denr, 359 ) && LT_16( S_max, 3277 ) && LT_16( Dlsp_n2e, 13107 ) && LT_16( Denr_n2e, 308 ) && st_fx->Opt_SC_VBR == 1 ) ||
    1486             :         ( LT_16( Dlsp, 13107 ) && LT_16( Denr, 205 ) && LT_16( S_max, 3277 ) && LT_16( Dlsp_n2e, 13107 ) && LT_16( Denr_n2e, 205 ) && st_fx->Opt_SC_VBR == 0 ) )
    1487             : 
    1488             :     {
    1489          48 :         hVAD->hangover_terminate_flag = 1; /*Q0   */
    1490          48 :         move16();
    1491             :     }
    1492             : 
    1493        1552 :     return;
    1494             : }
    1495             : 
    1496             : /*-------------------------------------------------------------------*
    1497             :  * td_cng_enc_init_fx()
    1498             :  *
    1499             :  *
    1500             :  *-------------------------------------------------------------------*/
    1501             : 
    1502           3 : void td_cng_enc_init_fx(
    1503             :     TD_CNG_ENC_HANDLE hTdCngEnc, /* i/o: DTX/TD CNG data handle              */
    1504             :     const Word16 Opt_DTX_ON,     /* i  : flag indicating DTX operation       Q0*/
    1505             :     const Word16 max_bwidth      /* i  : maximum encoded bandwidth           Q0*/
    1506             : )
    1507             : {
    1508             : 
    1509           3 :     hTdCngEnc->cng_seed = RANDOM_INITSEED;
    1510           3 :     hTdCngEnc->cng_ener_seed = RANDOM_INITSEED;
    1511           3 :     hTdCngEnc->cng_ener_seed1 = RANDOM_INITSEED;
    1512           3 :     hTdCngEnc->lp_ener_fx = 0;
    1513           3 :     hTdCngEnc->old_enr_index = -1;
    1514           3 :     hTdCngEnc->Enew_fx = 0;
    1515             : 
    1516           3 :     hTdCngEnc->lp_sp_enr_fx = 0;
    1517           3 :     hTdCngEnc->last_allow_cn_step = 0;
    1518           3 :     move16();
    1519           3 :     move32();
    1520           3 :     move16();
    1521           3 :     move16();
    1522           3 :     move32();
    1523           3 :     move16();
    1524           3 :     move16();
    1525             : 
    1526           3 :     IF( Opt_DTX_ON )
    1527             :     {
    1528           0 :         hTdCngEnc->cng_hist_ptr = -1;
    1529           0 :         move16();
    1530           0 :         set16_fx( hTdCngEnc->cng_lsp_hist_fx, 0, DTX_HIST_SIZE * M );
    1531           0 :         set16_fx( hTdCngEnc->cng_ener_hist_fx, 0, DTX_HIST_SIZE );
    1532             : 
    1533           0 :         hTdCngEnc->ho_hist_ptr = -1;
    1534           0 :         move16();
    1535           0 :         hTdCngEnc->ho_sid_bw = L_deposit_l( 0 );
    1536           0 :         set16_fx( hTdCngEnc->ho_lsp_hist_fx, 0, HO_HIST_SIZE * M );
    1537           0 :         set32_fx( hTdCngEnc->ho_ener_hist_fx, 0, HO_HIST_SIZE );
    1538           0 :         set32_fx( hTdCngEnc->ho_env_hist_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG );
    1539           0 :         hTdCngEnc->ho_hist_size = 0;
    1540           0 :         move16();
    1541           0 :         hTdCngEnc->act_cnt = 0;
    1542           0 :         move16();
    1543             :     }
    1544             : 
    1545           3 :     set16_fx( hTdCngEnc->ho_16k_lsp, 0, HO_HIST_SIZE );
    1546           3 :     hTdCngEnc->act_cnt2 = 0;
    1547           3 :     hTdCngEnc->num_ho = 0;
    1548           3 :     move16();
    1549           3 :     move16();
    1550             : 
    1551           3 :     hTdCngEnc->ho_circ_ptr = -1;
    1552           3 :     move16();
    1553           3 :     set16_fx( hTdCngEnc->ho_lsp_circ_fx, 0, HO_HIST_SIZE * M );
    1554           3 :     set32_fx( hTdCngEnc->ho_ener_circ_fx, 0, HO_HIST_SIZE );
    1555           3 :     set32_fx( hTdCngEnc->ho_env_circ_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG );
    1556           3 :     hTdCngEnc->ho_circ_size = 0;
    1557           3 :     hTdCngEnc->burst_ho_cnt = 0;
    1558           3 :     move16();
    1559           3 :     move16();
    1560             : 
    1561           3 :     hTdCngEnc->cng_buf_cnt = 0;
    1562             : 
    1563             : 
    1564           3 :     set32_fx( hTdCngEnc->lp_env_fx, 0, 20 );
    1565           3 :     set32_fx( hTdCngEnc->cng_res_env_fx, 0, 20 * 8 );
    1566           3 :     set16_fx( hTdCngEnc->exc_mem_fx, 0, 24 );
    1567           3 :     set16_fx( hTdCngEnc->exc_mem1_fx, 0, 30 );
    1568           3 :     set16_fx( hTdCngEnc->exc_mem2_fx, 0, 30 );
    1569           3 :     set32_fx( hTdCngEnc->old_env_fx, 0, NUM_ENV_CNG );
    1570             : 
    1571             :     /* SWB CNG/DTX */
    1572           3 :     hTdCngEnc->last_wb_cng_ener_fx = -1541; /* Q8 */
    1573           3 :     move16();
    1574           3 :     hTdCngEnc->last_shb_cng_ener_fx = -1541; /* Q8 */
    1575           3 :     move16();
    1576           3 :     hTdCngEnc->mov_wb_cng_ener_fx = -1541; /* Q8 */
    1577           3 :     move16();
    1578           3 :     hTdCngEnc->mov_shb_cng_ener_fx = -1541; /* Q8 */
    1579           3 :     move16();
    1580           3 :     hTdCngEnc->shb_cng_ini_cnt = 1;
    1581           3 :     move16();
    1582           3 :     hTdCngEnc->shb_NO_DATA_cnt = 0;
    1583           3 :     move16();
    1584           3 :     hTdCngEnc->last_SID_bwidth = s_min( max_bwidth, SWB );
    1585           3 :     hTdCngEnc->last_vad = 0;
    1586           3 :     move16();
    1587             : 
    1588           3 :     return;
    1589             : }
    1590             : 
    1591         148 : void td_cng_enc_init_ivas_fx(
    1592             :     TD_CNG_ENC_HANDLE hTdCngEnc, /* i/o: DTX/TD CNG data handle              */
    1593             :     const Word16 Opt_DTX_ON,     /* i  : flag indicating DTX operation       Q0*/
    1594             :     const Word16 max_bwidth      /* i  : maximum encoded bandwidth           Q0*/
    1595             : )
    1596             : {
    1597             : 
    1598         148 :     hTdCngEnc->cng_seed = RANDOM_INITSEED;
    1599         148 :     move16();
    1600         148 :     hTdCngEnc->cng_ener_seed = RANDOM_INITSEED;
    1601         148 :     move16();
    1602         148 :     hTdCngEnc->cng_ener_seed1 = RANDOM_INITSEED;
    1603         148 :     move16();
    1604         148 :     hTdCngEnc->lp_ener_fx = 0;
    1605         148 :     move16();
    1606         148 :     hTdCngEnc->old_enr_index = -1;
    1607         148 :     move16();
    1608         148 :     hTdCngEnc->Enew_fx = 0;
    1609         148 :     move16();
    1610             : 
    1611         148 :     hTdCngEnc->lp_sp_enr_fx = 0;
    1612         148 :     move16();
    1613         148 :     hTdCngEnc->last_allow_cn_step = 0;
    1614         148 :     move16();
    1615             : 
    1616         148 :     hTdCngEnc->CNG_att_fx = 0;
    1617         148 :     move16();
    1618             : 
    1619         148 :     IF( Opt_DTX_ON )
    1620             :     {
    1621         148 :         hTdCngEnc->cng_hist_ptr = -1;
    1622         148 :         move16();
    1623         148 :         set16_fx( hTdCngEnc->cng_lsp_hist_fx, 0, DTX_HIST_SIZE * M );
    1624         148 :         set16_fx( hTdCngEnc->cng_ener_hist_fx, 0, DTX_HIST_SIZE );
    1625         148 :         hTdCngEnc->ho_hist_ptr = -1;
    1626         148 :         move16();
    1627         148 :         hTdCngEnc->ho_sid_bw = 0;
    1628         148 :         move32();
    1629         148 :         set16_fx( hTdCngEnc->ho_lsp_hist_fx, 0, HO_HIST_SIZE * M );
    1630         148 :         set32_fx( hTdCngEnc->ho_ener_hist_fx, 0, HO_HIST_SIZE );
    1631         148 :         set32_fx( hTdCngEnc->ho_env_hist_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG );
    1632         148 :         hTdCngEnc->ho_hist_size = 0;
    1633         148 :         move16();
    1634         148 :         hTdCngEnc->act_cnt = 0;
    1635         148 :         move16();
    1636             :     }
    1637             : 
    1638         148 :     set16_fx( hTdCngEnc->ho_16k_lsp, 0, HO_HIST_SIZE );
    1639         148 :     hTdCngEnc->act_cnt2 = 0;
    1640         148 :     move16();
    1641         148 :     hTdCngEnc->num_ho = 0;
    1642         148 :     move16();
    1643             : 
    1644         148 :     hTdCngEnc->ho_circ_ptr = -1;
    1645         148 :     move16();
    1646         148 :     set16_fx( hTdCngEnc->ho_lsp_circ_fx, 0, HO_HIST_SIZE * M );
    1647         148 :     set32_fx( hTdCngEnc->ho_ener_circ_fx, 0, HO_HIST_SIZE );
    1648         148 :     set32_fx( hTdCngEnc->ho_env_circ_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG );
    1649         148 :     hTdCngEnc->ho_circ_size = 0;
    1650         148 :     move16();
    1651         148 :     hTdCngEnc->burst_ho_cnt = 0;
    1652         148 :     move16();
    1653         148 :     hTdCngEnc->cng_buf_cnt = 0;
    1654         148 :     move16();
    1655             : 
    1656         148 :     set32_fx( hTdCngEnc->lp_env_fx, 0, 20 );
    1657         148 :     set32_fx( hTdCngEnc->cng_res_env_fx, 0, 20 * 8 );
    1658         148 :     set16_fx( hTdCngEnc->exc_mem_fx, 0, 24 );
    1659         148 :     set16_fx( hTdCngEnc->exc_mem1_fx, 0, 30 );
    1660         148 :     set16_fx( hTdCngEnc->exc_mem2_fx, 0, 30 );
    1661         148 :     set32_fx( hTdCngEnc->old_env_fx, 0, NUM_ENV_CNG );
    1662         148 :     set16_fx( hTdCngEnc->cng_exc2_buf, 0, HO_HIST_SIZE * L_FFT );
    1663         148 :     set16_fx( hTdCngEnc->cng_Qexc_buf, Q15, HO_HIST_SIZE );
    1664             : 
    1665             :     /* SWB CNG/DTX */
    1666         148 :     hTdCngEnc->last_wb_cng_ener_fx = -1541; /* Q8 */
    1667         148 :     move16();
    1668         148 :     hTdCngEnc->last_shb_cng_ener_fx = -1541; /* Q8 */
    1669         148 :     move16();
    1670         148 :     hTdCngEnc->mov_wb_cng_ener_fx = -1541; /* Q8 */
    1671         148 :     move16();
    1672         148 :     hTdCngEnc->mov_shb_cng_ener_fx = -1541; /* Q8 */
    1673         148 :     move16();
    1674         148 :     hTdCngEnc->shb_cng_ini_cnt = 1;
    1675         148 :     move16();
    1676         148 :     hTdCngEnc->shb_NO_DATA_cnt = 0;
    1677         148 :     move16();
    1678         148 :     hTdCngEnc->last_SID_bwidth = s_min( max_bwidth, SWB );
    1679         148 :     move16();
    1680         148 :     hTdCngEnc->last_vad = 0;
    1681         148 :     move16();
    1682         148 :     hTdCngEnc->last_idx_ener = 0;
    1683         148 :     move16();
    1684             : 
    1685         148 :     return;
    1686             : }
    1687             : 
    1688             : /*-------------------------------------------------------------------*
    1689             :  * dtx_enc_init_fx()
    1690             :  *
    1691             :  * Initialize DTX parameters
    1692             :  *-------------------------------------------------------------------*/
    1693             : 
    1694         614 : void dtx_enc_init_fx(
    1695             :     Encoder_State *st,              /* i  : Encoder state handle              */
    1696             :     const Word16 var_SID_rate_flag, /* i  : flag for variable SID update rate Q0*/
    1697             :     const Word16 interval_SID       /* i  : interval for SID update           Q0*/
    1698             : )
    1699             : {
    1700             :     DTX_ENC_HANDLE hDtxEnc;
    1701         614 :     hDtxEnc = st->hDtxEnc;
    1702             : 
    1703         614 :     hDtxEnc->first_CNG = 0;
    1704         614 :     move16();
    1705         614 :     hDtxEnc->cnt_SID = 0;
    1706         614 :     move16();
    1707         614 :     hDtxEnc->max_SID = 2;
    1708         614 :     move16();
    1709         614 :     hDtxEnc->CNG_mode = -1;
    1710         614 :     move16();
    1711         614 :     Copy( st->lsp_old1_fx, hDtxEnc->lspCNG_fx, M );
    1712         614 :     hDtxEnc->VarDTX_cnt_voiced = 0;
    1713         614 :     move16();
    1714         614 :     hDtxEnc->VarDTX_cnt_noise = 0;
    1715         614 :     move16();
    1716         614 :     hDtxEnc->lt_ener_voiced_fx = 0;
    1717         614 :     move32();
    1718         614 :     hDtxEnc->lt_ener_noise_fx = 0;
    1719         614 :     move32();
    1720         614 :     hDtxEnc->frame_ener_fx = 0;
    1721         614 :     move32();
    1722         614 :     hDtxEnc->lt_ener_last_SID_fx = 0;
    1723         614 :     move32();
    1724         614 :     hDtxEnc->last_CNG_L_frame = L_FRAME;
    1725         614 :     move16();
    1726         614 :     hDtxEnc->var_SID_rate_flag = var_SID_rate_flag; /*Q0*/
    1727         614 :     move16();
    1728         614 :     hDtxEnc->last_active_brate = ACELP_7k20;
    1729         614 :     move32();
    1730         614 :     hDtxEnc->cng_cnt = 0;
    1731         614 :     move16();
    1732             : 
    1733         614 :     IF( hDtxEnc->var_SID_rate_flag )
    1734             :     {
    1735           3 :         hDtxEnc->interval_SID = 12;
    1736           3 :         move16();
    1737           3 :         hDtxEnc->cng_hist_size = DTX_HIST_SIZE;
    1738           3 :         move16();
    1739             :     }
    1740             :     ELSE
    1741             :     {
    1742         611 :         hDtxEnc->interval_SID = interval_SID;
    1743         611 :         move16();
    1744         611 :         if ( GE_16( hDtxEnc->interval_SID, DTX_HIST_SIZE ) )
    1745             :         {
    1746         611 :             hDtxEnc->cng_hist_size = hDtxEnc->interval_SID;
    1747         611 :             move16();
    1748             :         }
    1749             :     }
    1750         614 :     return;
    1751             : }

Generated by: LCOV version 1.14