LCOV - code coverage report
Current view: top level - lib_enc - find_uv_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ 57b3a0619c6acf2354f43c9b971cc11e014725cb Lines: 440 533 82.6 %
Date: 2025-10-22 22:22:21 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : #include <stdint.h>
       5             : #include "options.h" /* Compilation switches                   */
       6             : #include "cnst.h"    /* Common constants                       */
       7             : //#include "prot_fx.h"        /* Function prototypes                    */
       8             : #include "rom_com.h"     /* Function prototypes                    */
       9             : #include "prot_fx.h"     /* Function prototypes                    */
      10             : #include "prot_fx_enc.h" /* Function prototypes                    */
      11             : 
      12             : /*-------------------------------------------------------------------*
      13             :  * Local constants
      14             :  *-------------------------------------------------------------------*/
      15             : 
      16             : #define L_ENR ( NB_SSF + 2 )
      17             : 
      18             : 
      19             : /*-------------------------------------------------------------------*
      20             :  * find_ener_decrease_fx()
      21             :  *
      22             :  * Find maximum energy ration between short subblocks in case
      23             :  * energy is trailing off after a spike
      24             :  *-------------------------------------------------------------------*/
      25             : 
      26       20785 : static Word16 find_ener_decrease_fx(                            /* o  : maximum energy ratio                                                            Q10*/
      27             :                                      const Word16 ind_deltaMax, /* i  : index of the beginning of maximum energy search         Q0*/
      28             :                                      const Word32 *pt_enr_ssf   /* i  : Pointer to the energy buffer                                            Qx*/
      29             : )
      30             : {
      31             :     Word16 i, j, end, flag;
      32             :     Word16 wtmp0, wtmp1;
      33             :     Word32 maxEnr, minEnr;
      34             :     Word16 dE2, exp0, exp1;
      35             : 
      36       20785 :     dE2 = 0;
      37       20785 :     move16();
      38             : 
      39       20785 :     j = ind_deltaMax + 2;
      40       20785 :     move16();
      41       20785 :     end = j + L_ENR;
      42       20785 :     move16();
      43       20785 :     maxEnr = L_add( pt_enr_ssf[j], 0 );
      44       20785 :     j = add( j, 1 );
      45       20785 :     flag = 0;
      46       20785 :     move16();
      47      207850 :     FOR( i = j; i < end; i++ )
      48             :     {
      49      187065 :         test();
      50      187065 :         IF( ( GT_32( pt_enr_ssf[i], maxEnr ) ) && ( flag == 0 ) )
      51             :         {
      52        8220 :             maxEnr = L_add( pt_enr_ssf[i], 0 ); /*Qx*/
      53        8220 :             j = add( j, 1 );
      54             :         }
      55             :         ELSE
      56             :         {
      57      178845 :             flag = 1;
      58      178845 :             move16();
      59             :         }
      60             :     }
      61             : 
      62       20785 :     minEnr = L_add( maxEnr, 0 );
      63      199630 :     FOR( i = j; i < end; i++ )
      64             :     {
      65      178845 :         minEnr = L_min( minEnr, pt_enr_ssf[i] ); /* Qx */
      66             :     }
      67             : 
      68             : 
      69       20785 :     minEnr = L_add_sat( minEnr, 100000 );
      70       20785 :     exp0 = norm_l( minEnr );
      71       20785 :     wtmp0 = extract_h( L_shl( minEnr, exp0 ) );
      72       20785 :     exp1 = sub( norm_l( maxEnr ), 1 );
      73       20785 :     wtmp1 = extract_h( L_shl( maxEnr, exp1 ) );
      74       20785 :     wtmp1 = div_s( wtmp1, wtmp0 );
      75       20785 :     dE2 = shr_r_sat( wtmp1, add( sub( exp1, exp0 ), 15 - 10 ) ); /*Q10*/
      76             : 
      77       20785 :     return dE2;
      78             : }
      79             : 
      80             : /*-------------------------------------------------------------------*
      81             :  * find_uv_fx()
      82             :  *
      83             :  * Decision about coder type
      84             :  *-------------------------------------------------------------------*/
      85             : 
      86        3100 : Word16 find_uv_fx(                           /* o  : coding type                                                                                                        */
      87             :                    Encoder_State *st_fx,     /* i/o: encoder state structure                                                                            */
      88             :                    const Word16 *T_op_fr,    /* i  : pointer to adjusted fractional pitch (4 val.)                                      Q6*/
      89             :                    const Word16 *voicing_fr, /* i  : refined correlation for each subframes                                                     Q15*/
      90             :                    const Word16 *speech,     /* i  : pointer to speech signal for E computation                                         Q_new*/
      91             :                    const Word32 *ee,         /* i  : lf/hf Energy ratio for present frame                                                       Q6*/
      92             :                    const Word16 corr_shift,  /* i  : normalized correlation correction in noise                                         Q15*/
      93             :                    const Word16 relE,        /* i  : relative frame energy                                                                                      Q8*/
      94             :                    const Word16 Etot,        /* i  : total energy                                                                                                       Q8*/
      95             :                    const Word32 hp_E[],      /* i  : energy in HF                                                                                                       Q_new + Q_SCALE*/
      96             :                    const Word16 Q_new,
      97             :                    Word16 *flag_spitch, /* i/o: flag to indicate very short stable pitch and high correlation           Q0*/
      98             :                    const Word16 shift,
      99             :                    const Word16 last_core_orig /* i  : original last core                                                                                       Q0*/
     100             : )
     101             : {
     102             :     Word16 coder_type, i;
     103             :     Word32 mean_ee, dE1, fac_32;
     104             :     const Word16 *pt_speech;
     105             :     Word32 L_tmp, enr_ssf[2 * NB_SSF + 2 * NB_SSF + 2], E_min_th;
     106             :     Word16 dE2;
     107             :     Word16 ind_deltaMax, tmp_offset_flag;
     108             :     Word32 Ltmp0, *pt_enr_ssf, *pt_enr_ssf1, dE2_th;
     109             :     Word16 exp0, exp1, Q_in;
     110             :     Word16 wtmp0, wtmp1;
     111             :     Word16 fac, mean_voi3, dE3;
     112             :     Word16 relE_thres;
     113             :     Word16 mean_voi3_offset;
     114             :     Word16 voicing_m, dpit1, dpit2, dpit3;
     115             :     Word16 ee0_th, ee1_th, voi_th, nb_cond, flag_low_relE;
     116        3100 :     NOISE_EST_HANDLE hNoiseEst = st_fx->hNoiseEst;
     117        3100 :     SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
     118             :     Word16 Last_Resort;
     119             :     Word16 vadnoise;
     120             : 
     121        3100 :     IF( hSC_VBR != NULL )
     122             :     {
     123        3100 :         Last_Resort = hSC_VBR->Last_Resort; /* Q0 */
     124        3100 :         vadnoise = hSC_VBR->vadnoise_fx;
     125        3100 :         move16();
     126        3100 :         move16();
     127             :     }
     128             :     ELSE
     129             :     {
     130           0 :         Last_Resort = 0;
     131           0 :         vadnoise = 0;
     132           0 :         move16();
     133           0 :         move16();
     134             :     }
     135             : 
     136        3100 :     Q_in = sub( Q_new, 1 );
     137             : 
     138             :     /*-----------------------------------------------------------------*
     139             :      * Detect sudden energy increases to catch voice and music
     140             :      * temporal events (dE1)
     141             :      *
     142             :      * - Find maximum energy per short subblocks.
     143             :      *   Two subblock sets are used shifted by half the subblock length
     144             :      * - Find maximum energy ratio between adjacent subblocks
     145             :      *-----------------------------------------------------------------*/
     146             : 
     147             :     /* Find maximum energy per short subblocks  */
     148        3100 :     pt_speech = speech - SSF; /* Q_new */
     149        3100 :     pt_enr_ssf = enr_ssf + 2 * NB_SSF;
     150       58900 :     FOR( i = 0; i < 2 * ( NB_SSF + 1 ); i++ )
     151             :     {
     152       55800 :         emaximum_fx( Q_in, pt_speech, SSF, pt_enr_ssf );
     153       55800 :         pt_speech += ( SSF / 2 );
     154       55800 :         pt_enr_ssf++;
     155             :     }
     156             : 
     157        3100 :     dE1 = 0;
     158        3100 :     move16();
     159        3100 :     ind_deltaMax = 0;
     160        3100 :     move16();
     161        3100 :     pt_enr_ssf = enr_ssf + 2 * NB_SSF;
     162        3100 :     pt_enr_ssf1 = pt_enr_ssf + 2;
     163             : 
     164             :     /* Test on energy increase between adjacent sub-subframes */
     165        3100 :     exp1 = 0;
     166        3100 :     move16();
     167       52700 :     FOR( i = 0; i < 2 * NB_SSF; i++ )
     168             :     {
     169             :         /*fac = *pt_enr_ssf1 / (*pt_enr_ssf + 1);*/
     170       49600 :         Ltmp0 = L_max( *pt_enr_ssf, 1 );
     171       49600 :         exp0 = norm_l( Ltmp0 );
     172       49600 :         wtmp0 = extract_h( L_shl( Ltmp0, exp0 ) );
     173       49600 :         exp1 = sub( norm_l( *pt_enr_ssf1 ), 1 );
     174       49600 :         wtmp1 = extract_h( L_shl( *pt_enr_ssf1, exp1 ) );
     175       49600 :         fac = div_s( wtmp1, wtmp0 );
     176       49600 :         fac_32 = L_shr_sat( L_deposit_l( fac ), add( sub( exp1, exp0 ), 15 - 13 ) ); /* fac32 in Q13*/
     177             : 
     178       49600 :         if ( GT_32( fac_32, dE1 ) )
     179             :         {
     180       10465 :             ind_deltaMax = i;
     181       10465 :             move16();
     182             :         }
     183             : 
     184       49600 :         dE1 = L_max( dE1, fac_32 ); /* Q13 */
     185             : 
     186       49600 :         pt_enr_ssf++;
     187       49600 :         pt_enr_ssf1++;
     188             :     }
     189             : 
     190             :     /*-----------------------------------------------------------------*
     191             :      * Average spectral tilt
     192             :      * Average voicing (normalized correlation)
     193             :      *-----------------------------------------------------------------*/
     194             : 
     195             :     /*mean_ee = 1.0f/3.0f * (st->ee_old + ee[0] + ee[1]); */            /* coefficients take into account the position of the window */
     196        3100 :     mean_ee = L_add_sat( L_add_sat( st_fx->ee_old_fx, ee[0] ), ee[1] ); /* Q6 */
     197        3100 :     mean_ee = Mult_32_16( mean_ee, 10923 /* 1/3 in Q15 */ );            /*Q6*/
     198             : 
     199             :     /* mean_voi3 = 1.0f/3.0f * (voicing[0] + voicing[1] + voicing[2]);*/
     200        3100 :     Ltmp0 = L_mult( st_fx->voicing_fx[0], 10923 /* 1/3 in Q15 */ );               /* Q31 */
     201        3100 :     Ltmp0 = L_mac( Ltmp0, st_fx->voicing_fx[1], 10923 /* 1/3 in Q15 */ );         /* Q31 */
     202        3100 :     mean_voi3 = mac_r_sat( Ltmp0, st_fx->voicing_fx[2], 10923 /* 1/3 in Q15 */ ); /*Q15*/
     203             :     /*-----------------------------------------------------------------*
     204             :      * Total frame energy difference (dE3)
     205             :      *-----------------------------------------------------------------*/
     206             : 
     207        3100 :     dE3 = sub( Etot, hNoiseEst->Etot_last_fx ); /*Q8*/
     208             : 
     209             :     /*-----------------------------------------------------------------*
     210             :      * Energy decrease after spike (dE2)
     211             :      *-----------------------------------------------------------------*/
     212             : 
     213             :     /* set different thresholds and conditions for NB and WB input */
     214        3100 :     dE2_th = 30 << 10;
     215        3100 :     move32();
     216        3100 :     nb_cond = 1;
     217        3100 :     move16(); /* no additional condition for WB input */
     218        3100 :     IF( EQ_16( st_fx->input_bwidth, NB ) )
     219             :     {
     220           0 :         dE2_th = 21 << 10;
     221           0 :         move32();
     222           0 :         if ( GE_16( add_sat( mean_voi3, corr_shift ), 22282 /* 0.68 in Q15 */ ) ) /*( mean_voi3 + corr_shift ) >= 0.68f*/
     223             :         {
     224           0 :             nb_cond = 0;
     225           0 :             move16();
     226             :         }
     227             :     }
     228             : 
     229             :     /* calcualte maximum energy decrease */
     230        3100 :     dE2 = 0;
     231        3100 :     move16(); /* Test on energy decrease after an energy spike  */
     232        3100 :     pt_enr_ssf = enr_ssf + 2 * NB_SSF;
     233             : 
     234        3100 :     test();
     235        3100 :     IF( GT_32( dE1, 30 << 13 ) && nb_cond ) /*>30 Q13*/
     236             :     {
     237          80 :         IF( LT_16( sub( shl( NB_SSF, 1 ), ind_deltaMax ), L_ENR ) )
     238             :         {
     239          57 :             st_fx->old_ind_deltaMax = ind_deltaMax; /* Q0 */
     240          57 :             move16();
     241          57 :             Copy32( pt_enr_ssf, st_fx->old_enr_ssf_fx, 2 * NB_SSF ); /* Qx */
     242             :         }
     243             :         ELSE
     244             :         {
     245          23 :             st_fx->old_ind_deltaMax = -1;
     246          23 :             move16();
     247          23 :             dE2 = find_ener_decrease_fx( ind_deltaMax, pt_enr_ssf ); /*Q10*/
     248             : 
     249          23 :             if ( GT_32( dE2, dE2_th ) )
     250             :             {
     251           2 :                 st_fx->spike_hyst = 0;
     252           2 :                 move16();
     253             :             }
     254             :         }
     255             :     }
     256             :     ELSE
     257             :     {
     258        3020 :         IF( st_fx->old_ind_deltaMax >= 0 )
     259             :         {
     260          57 :             Copy32( st_fx->old_enr_ssf_fx, enr_ssf, 2 * NB_SSF );            /* Qx */
     261          57 :             dE2 = find_ener_decrease_fx( st_fx->old_ind_deltaMax, enr_ssf ); /* Q10 */
     262             : 
     263          57 :             if ( GT_32( dE2, dE2_th ) )
     264             :             {
     265           3 :                 st_fx->spike_hyst = 1;
     266           3 :                 move16();
     267             :             }
     268             :         }
     269             : 
     270        3020 :         st_fx->old_ind_deltaMax = -1;
     271        3020 :         move16();
     272             :     }
     273             : 
     274             :     /*-----------------------------------------------------------------*
     275             :      * Detection of voiced offsets (tmp_offset_flag)
     276             :      *-----------------------------------------------------------------*/
     277             : 
     278        3100 :     tmp_offset_flag = 1;
     279        3100 :     move16();
     280             : 
     281        3100 :     IF( NE_16( st_fx->input_bwidth, NB ) )
     282             :     {
     283        3100 :         ee0_th = 154; /*2.4 in Q6 */
     284        3100 :         move16();
     285        3100 :         voi_th = 24248; /*0.74f Q15 */
     286        3100 :         move16();
     287             :     }
     288             :     ELSE
     289             :     {
     290           0 :         ee0_th = 627; /*9.8f Q6 */
     291           0 :         move16();
     292           0 :         voi_th = 24904; /*0.76f Q15*/
     293           0 :         move16();
     294             :     }
     295             : 
     296        3100 :     test();
     297        3100 :     test();
     298        3100 :     test();
     299        6063 :     if ( ( EQ_16( st_fx->last_coder_type_raw, UNVOICED ) ) ||                              /* previous frame was unvoiced  */
     300        4005 :          ( ( LT_32( ee[0], ee0_th ) ) && ( GT_32( hp_E[0], L_shl( E_MIN_FX, Q_new ) ) ) && /* energy is concentrated in high frequencies provided that some energy is present in HF */
     301         496 :            ( LT_16( add_sat( st_fx->voicing_fx[0], corr_shift ), voi_th ) ) ) )            /* normalized correlation is low */
     302             :     {
     303         322 :         tmp_offset_flag = 0;
     304         322 :         move16();
     305             :     }
     306             : 
     307             :     /*-----------------------------------------------------------------*
     308             :      * Decision about UC
     309             :      *-----------------------------------------------------------------*/
     310             : 
     311             :     /* SC-VBR - set additional parameters and thresholds for SC-VBR */
     312        3100 :     mean_voi3_offset = 0;
     313        3100 :     move16();
     314        3100 :     flag_low_relE = 0;
     315        3100 :     move16();
     316        3100 :     ee1_th = 608; /*9.5 Q6*/
     317        3100 :     move16();
     318        3100 :     IF( st_fx->Opt_SC_VBR || ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) /* Allow the low energy flag for the secondary channel */
     319             :     {
     320           0 :         ee1_th = 544; /*8.5f Q6*/
     321           0 :         move16();
     322             : 
     323             :         /* SC-VBR - determine the threshold on relative energy as a function of lp_noise */
     324           0 :         IF( NE_16( st_fx->input_bwidth, NB ) )
     325             :         {
     326             :             /*relE_thres = 0.700f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16) */
     327           0 :             L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 22938 /* 0.7 in Q15 */, st_fx->lp_noise_fx ); // Q24
     328           0 :             if ( Last_Resort == 0 )
     329             :             {
     330             :                 /*relE_thres = 0.650f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16)*/
     331           0 :                 L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 21299 /* 0.650f in Q15 */, st_fx->lp_noise_fx ); // Q24
     332             :             }
     333           0 :             relE_thres = round_fx( L_tmp );
     334             :         }
     335             :         ELSE
     336             :         {
     337             : 
     338             :             /*relE_thres = 0.60f * st->lp_noise - 28.2f; (lp_noise in Q8, constant Q8<<16)*/
     339           0 :             L_tmp = L_mac( -473117491 /* 28.2f in Q24 */, 19661 /* 0.6f in Q15 */, st_fx->lp_noise_fx ); // Q24
     340           0 :             relE_thres = round_fx( L_tmp );
     341             :         }
     342           0 :         relE_thres = s_max( relE_thres, -6400 /* -25.0f in Q8 */ ); /* Q8 */
     343             : 
     344             :         /* SC-VBR = set flag on low relative energy */
     345           0 :         if ( LT_16( relE, relE_thres ) )
     346             :         {
     347           0 :             flag_low_relE = 1;
     348           0 :             move16();
     349             :         }
     350             : 
     351             :         /* SC-VBR - correction of voicing threshold for NB inputs (important only in noisy conditions) */
     352           0 :         test();
     353           0 :         if ( EQ_16( st_fx->input_bwidth, NB ) && LT_16( vadnoise, 20 << 8 ) ) /* vadnoise in Q8, constant Q0<<8 */
     354             :         {
     355           0 :             mean_voi3_offset = 1638; /*0.05f Q15*/
     356           0 :             move16();
     357             :         }
     358             :     }
     359             : 
     360             :     /* make decision whether frame is unvoiced */
     361        3100 :     E_min_th = L_shl( E_MIN_FX, Q_new );
     362        3100 :     coder_type = GENERIC;
     363        3100 :     move16();
     364        3100 :     IF( EQ_16( st_fx->input_bwidth, NB ) )
     365             :     {
     366           0 :         test();
     367           0 :         test();
     368           0 :         test();
     369           0 :         test();
     370           0 :         test();
     371           0 :         test();
     372           0 :         test();
     373           0 :         test();
     374           0 :         test();
     375           0 :         test();
     376           0 :         test();
     377           0 :         if ( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22282 /* 0.68 in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low  */
     378           0 :                ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 /* 0.79 in Q15 */ ) ) &&               /* normalized correlation low on look-ahead - onset detection */
     379           0 :                ( LT_32( ee[0], 640 /* 10.0f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) &&                     /* energy concentrated in high frequencies provided that some energy is present in HF...  */
     380           0 :                ( LT_32( ee[1], ee1_th ) ) && ( GT_32( hp_E[1], E_min_th ) ) &&                                    /* ... biased towards look-ahead to detect onsets  */
     381           0 :                ( tmp_offset_flag == 0 ) &&                                                                        /* Take care of voiced offsets */
     382             :                /*( st_fx->music_hysteresis_fx == 0 ) &&*/                                                         /*  ... and in segment after AUDIO frames   */
     383           0 :                ( LE_32( dE1, 237568 /* 29.0f in Q13 */ ) ) &&                                                     /* Avoid on sharp energy spikes  */
     384           0 :                ( LE_32( st_fx->old_dE1_fx, 237568 /* 29.0f in Q13 */ ) ) &&                                       /*   + one frame hysteresis   */
     385           0 :                ( st_fx->spike_hyst < 0 ) ) ||                                                                     /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */
     386             :              flag_low_relE )                                                                                      /* low relative frame energy (only for SC-VBR) */
     387             :         {
     388           0 :             coder_type = UNVOICED;
     389           0 :             move16();
     390             :         }
     391             :     }
     392             :     ELSE
     393             :     {
     394        3100 :         test();
     395        3100 :         test();
     396        3100 :         test();
     397        3100 :         test();
     398        3100 :         test();
     399        3100 :         test();
     400        3100 :         test();
     401        3100 :         test();
     402        3100 :         test();
     403        3100 :         test();
     404        3100 :         test();
     405        3100 :         test();
     406        4033 :         if ( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22774 /* 0.695f in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low  */
     407        1769 :                ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 /* 0.8 in Q15 */ ) ) &&                  /* normalized correlation low on look-ahead - onset detection */
     408        1369 :                ( LT_32( ee[0], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) &&                        /* energy concentrated in high frequencies provided that some energy is present in HF...  */
     409         478 :                ( LT_32( ee[1], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) &&                        /* ... biased towards look-ahead to detect onsets  */
     410         158 :                ( tmp_offset_flag == 0 ) &&                                                                          /* Take care of voiced offsets */
     411             :                /*( st_fx->music_hysteresis_fx == 0 ) &&  */                                                         /*  ... and in segment after AUDIO frames   */
     412         306 :                ( LE_32( dE1, 245760 /* 30.0f in Q13 */ ) ) &&                                                       /* Avoid on sharp energy spikes  */
     413         148 :                ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) &&                                         /*   + one frame hysteresis   */
     414         138 :                ( st_fx->spike_hyst < 0 ) )                                                                          /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */
     415        2963 :              || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) ) )                    /* low relative frame energy (only for SC-VBR) */
     416             :         {
     417         137 :             coder_type = UNVOICED;
     418         137 :             move16();
     419             :         }
     420             :     }
     421             : 
     422             :     /*-----------------------------------------------------------------*
     423             :      * Decision about VC
     424             :      *-----------------------------------------------------------------*/
     425        3100 :     if ( st_fx->Opt_SC_VBR )
     426             :     {
     427           0 :         hSC_VBR->set_ppp_generic = 0;
     428             :     }
     429        3100 :     move16();
     430             : 
     431        3100 :     test();
     432        3100 :     test();
     433        3100 :     IF( EQ_16( st_fx->localVAD, 1 ) && EQ_16( coder_type, GENERIC ) && NE_16( last_core_orig, AMR_WB_CORE ) )
     434             :     {
     435        2858 :         dpit1 = abs_s( sub( T_op_fr[1], T_op_fr[0] ) ); // Q6
     436        2858 :         dpit2 = abs_s( sub( T_op_fr[2], T_op_fr[1] ) ); // Q6
     437        2858 :         dpit3 = abs_s( sub( T_op_fr[3], T_op_fr[2] ) ); // Q6
     438             : 
     439        2858 :         test();
     440        2858 :         test();
     441        2858 :         test();
     442        2858 :         test();
     443        2858 :         test();
     444        2858 :         test();
     445        2858 :         test();
     446        2858 :         test();
     447        2858 :         test();
     448        2858 :         IF( ( GT_16( voicing_fr[0], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 1st sf.  */
     449             :             ( GT_16( voicing_fr[1], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 2st sf.  */
     450             :             ( GT_16( voicing_fr[2], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 3st sf.  */
     451             :             ( GT_16( voicing_fr[3], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 4st sf.  */
     452             :             ( GT_32( mean_ee, 256 /* 4.0f in Q6 */ ) ) &&           /* energy concentrated in low frequencies  */
     453             :             ( LT_16( dpit1, 3 << 6 ) ) &&
     454             :             ( LT_16( dpit2, 3 << 6 ) ) &&
     455             :             ( LT_16( dpit3, 3 << 6 ) ) )
     456             :         {
     457        1387 :             coder_type = VOICED;
     458        1387 :             move16();
     459             :         }
     460        1471 :         ELSE IF( st_fx->Opt_SC_VBR && EQ_16( st_fx->input_bwidth, NB ) && LT_16( vadnoise, 20 << 8 ) )
     461             :         {
     462           0 :             test();
     463           0 :             test();
     464           0 :             test();
     465           0 :             test();
     466           0 :             test();
     467           0 :             test();
     468           0 :             test();
     469           0 :             IF( GT_16( voicing_fr[0], 8192 /* 0.25 in Q15 */ ) &&     /* normalized correlation high in 1st sf.  */
     470             :                 ( GT_16( voicing_fr[1], 8192 /* 0.25 in Q15 */ ) ) && /* normalized correlation high in 2st sf.  */
     471             :                 ( GT_16( voicing_fr[2], 8192 /* 0.25 in Q15 */ ) ) && /* normalized correlation high in 3st sf.  */
     472             :                 ( GT_16( voicing_fr[3], 8192 /* 0.25 in Q15 */ ) ) && /* normalized correlation high in 4st sf.  */
     473             :                 ( GT_32( mean_ee, 64 ) ) &&                           /* energy concentrated in low frequencies  */
     474             :                 ( LT_16( dpit1, 5 << 6 ) ) &&
     475             :                 ( LT_16( dpit2, 5 << 6 ) ) &&
     476             :                 ( LT_16( dpit3, 5 << 6 ) ) )
     477             :             {
     478           0 :                 hSC_VBR->set_ppp_generic = 1;
     479           0 :                 move16();
     480           0 :                 coder_type = VOICED;
     481           0 :                 move16();
     482             :             }
     483             :         }
     484             : 
     485             :         /* set VOICED mode for frames with very stable pitch and high correlation
     486             :            and avoid to switch to AUDIO/MUSIC later                              */
     487        2858 :         voicing_m = mac_r( L_mac( L_mac( L_mult( voicing_fr[3], 8192 /* 0.25 in Q15 */ ), voicing_fr[2], 8192 /* 0.25 in Q15 */ ), voicing_fr[1], 8192 /* 0.25 in Q15 */ ), voicing_fr[0], 8192 /* 0.25 in Q15 */ );
     488        2858 :         test();
     489        2858 :         test();
     490        2858 :         test();
     491        2858 :         test();
     492        2858 :         test();
     493        2858 :         IF( *flag_spitch || ( LE_16( dpit1, 3 << 6 ) && LE_16( dpit2, 3 << 6 ) && LE_16( dpit3, 3 << 6 ) &&
     494             :                               GT_16( voicing_m, 31130 /* 0.95f in Q15 */ ) && GT_16( st_fx->voicing_sm_fx, 31785 /* 0.97f in Q15 */ ) ) )
     495             :         {
     496          48 :             coder_type = VOICED;
     497          48 :             move16();
     498          48 :             *flag_spitch = 1;
     499          48 :             move16(); /*to avoid switch to AUDIO/MUSIC later*/
     500             :         }
     501             :     }
     502             : 
     503             :     /*-----------------------------------------------------------------*
     504             :      * Channel-aware mode - set RF mode and total bitrate
     505             :      *-----------------------------------------------------------------*/
     506             : 
     507        3100 :     st_fx->rf_mode = st_fx->Opt_RF_ON; /* Q0 */
     508        3100 :     move16();
     509             : 
     510        3100 :     IF( EQ_16( coder_type, GENERIC ) )
     511             :     {
     512        1576 :         test();
     513        1576 :         test();
     514        1576 :         test();
     515        1576 :         test();
     516        1576 :         IF( ( LT_16( voicing_fr[0], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 2st sf.  */
     517             :             ( LT_16( voicing_fr[1], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 2st sf.  */
     518             :             ( LT_16( voicing_fr[2], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 3rd sf.  */
     519             :             ( LT_16( voicing_fr[3], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 4th sf.  */
     520             :             ( GT_16( vadnoise, 25 << 8 ) ) )                      /* when speech is clean */
     521             : 
     522             :         {
     523           0 :             st_fx->rf_mode = 0;
     524           0 :             move16();
     525             :             /* Current frame cannot be compressed to pack the partial redundancy;*/
     526             : 
     527           0 :             if ( st_fx->rf_mode != st_fx->Opt_RF_ON )
     528             :             {
     529           0 :                 core_coder_mode_switch_fx( st_fx, st_fx->last_total_brate, 0, shift );
     530             :             }
     531             :         }
     532             :     }
     533             : 
     534             :     /*-----------------------------------------------------------------*
     535             :      * Updates
     536             :      *-----------------------------------------------------------------*/
     537             : 
     538             :     /* update spike hysteresis parameters */
     539        3100 :     test();
     540        3100 :     if ( st_fx->spike_hyst >= 0 && LT_16( st_fx->spike_hyst, 2 ) )
     541             :     {
     542           7 :         st_fx->spike_hyst = add( st_fx->spike_hyst, 1 ); /* Q0 */
     543             :     }
     544             : 
     545             :     /* reset spike hysteresis */
     546        3100 :     test();
     547        3100 :     test();
     548        3100 :     test();
     549        3146 :     if ( ( GT_16( st_fx->spike_hyst, 1 ) ) &&
     550          89 :          ( GT_16( dE3, 5 << 8 ) ||                                                              /* energy increases               */
     551          61 :            ( GT_16( relE, -3328 ) && ( GT_16( add_sat( mean_voi3, corr_shift ), 22774 ) ) ) ) ) /* normalized correlation is high */
     552             :     {
     553           5 :         st_fx->spike_hyst = -1;
     554           5 :         move16();
     555             :     }
     556             : 
     557             :     /* update tilt parameters */
     558        3100 :     st_fx->ee_old_fx = ee[1];
     559        3100 :     move32(); /*Q6*/
     560        3100 :     st_fx->old_dE1_fx = dE1;
     561        3100 :     move32(); /*Q13*/
     562             : 
     563             :     /* save the raw coder_type for various modules later in the codec (the reason is that e.g. UNVOICED is lost at higher rates) */
     564        3100 :     st_fx->coder_type_raw = coder_type;
     565        3100 :     move16();
     566             : 
     567        3100 :     return coder_type;
     568             : }
     569             : 
     570             : /*-------------------------------------------------------------------*
     571             :  * find_uv()
     572             :  *
     573             :  * Decision about coder type
     574             :  *-------------------------------------------------------------------*/
     575     1136964 : Word16 find_uv_ivas_fx(                                       /* o  : coding type                                                   */
     576             :                         Encoder_State *st_fx,                 /* i/o: encoder state structure                                       */
     577             :                         const Word16 *T_op_fr,                /* i  : pointer to adjusted fractional pitch (4 val.)                                     Q6*/
     578             :                         const Word16 *voicing_fr,             /* i  : refined correlation for each subframes                                            Q15*/
     579             :                         const Word16 *speech,                 /* i  : pointer to speech signal for E computation                                        Q_new*/
     580             :                         const Word32 *ee,                     /* i  : lf/hf Energy ratio for present frame                                                      Q6*/
     581             :                         Word32 *dE1X,                         /* o  : sudden energy increase for S/M classifier                     Q13*/
     582             :                         const Word16 corr_shift,              /* i  : normalized correlation correction in noise                                        Q15*/
     583             :                         const Word16 relE,                    /* i  : relative frame energy                                                                                     Q8*/
     584             :                         const Word16 Etot,                    /* i  : total energy                                                                                                      Q8*/
     585             :                         const Word32 hp_E[],                  /* i  : energy in HF                                                                                                      q_hp_E*/
     586             :                         Word16 *flag_spitch,                  /* i/o: flag to indicate very short stable pitch and high correlation Q0*/
     587             :                         const Word16 last_core_orig,          /* i  : original last core                                            Q0*/
     588             :                         STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure                                   */
     589             :                         const Word16 Q_new,
     590             :                         const Word16 q_hp_E )
     591             : {
     592             :     Word16 coder_type, i;
     593             :     Word32 mean_ee, dE1, fac_32;
     594             :     const Word16 *pt_speech;
     595             :     Word32 L_tmp, enr_ssf[2 * NB_SSF + 2 * NB_SSF + 2], E_min_th;
     596             :     Word16 dE2;
     597             :     Word16 ind_deltaMax, tmp_offset_flag;
     598             :     Word32 Ltmp0, *pt_enr_ssf, *pt_enr_ssf1, dE2_th;
     599             :     Word16 exp0, exp1;
     600             :     Word16 wtmp0, wtmp1;
     601             :     Word16 fac, mean_voi3, dE3;
     602             :     Word16 relE_thres;
     603             :     Word16 mean_voi3_offset;
     604             :     Word16 voicing_m, dpit1, dpit2, dpit3;
     605             :     Word16 ee0_th, ee1_th, voi_th, nb_cond, flag_low_relE;
     606     1136964 :     NOISE_EST_HANDLE hNoiseEst = st_fx->hNoiseEst;
     607     1136964 :     SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
     608             :     Word16 Last_Resort;
     609             :     Word16 vadnoise;
     610             : 
     611     1136964 :     IF( hSC_VBR != NULL )
     612             :     {
     613           0 :         Last_Resort = hSC_VBR->Last_Resort; /* Q0 */
     614           0 :         move16();
     615           0 :         vadnoise = hSC_VBR->vadnoise_fx; /* Q8 */
     616           0 :         move16();
     617             :     }
     618             :     ELSE
     619             :     {
     620     1136964 :         Last_Resort = 0;
     621     1136964 :         move16();
     622     1136964 :         vadnoise = 0;
     623     1136964 :         move16();
     624             :     }
     625             : 
     626             :     /*-----------------------------------------------------------------*
     627             :      * Detect sudden energy increases to catch voice and music
     628             :      * temporal events (dE1)
     629             :      *
     630             :      * - Find maximum energy per short subblocks.
     631             :      *   Two subblock sets are used shifted by half the subblock length
     632             :      * - Find maximum energy ratio between adjacent subblocks
     633             :      *-----------------------------------------------------------------*/
     634             : 
     635             :     /* Find maximum energy per short subblocks  */
     636     1136964 :     pt_speech = speech - SSF;
     637     1136964 :     pt_enr_ssf = enr_ssf + 2 * NB_SSF;
     638    21602316 :     FOR( i = 0; i < 2 * ( NB_SSF + 1 ); i++ )
     639             :     {
     640    20465352 :         emaximum_fx( Q_new, pt_speech, SSF, pt_enr_ssf );
     641    20465352 :         pt_speech += ( SSF / 2 );
     642    20465352 :         pt_enr_ssf++;
     643             :     }
     644             : 
     645     1136964 :     dE1 = 0;
     646     1136964 :     move16();
     647     1136964 :     ind_deltaMax = 0;
     648     1136964 :     move16();
     649     1136964 :     pt_enr_ssf = enr_ssf + 2 * NB_SSF;
     650     1136964 :     pt_enr_ssf1 = pt_enr_ssf + 2;
     651             : 
     652             :     /* Test on energy increase between adjacent sub-subframes */
     653     1136964 :     exp1 = 0;
     654     1136964 :     move16();
     655    19328388 :     FOR( i = 0; i < 2 * NB_SSF; i++ )
     656             :     {
     657             :         /*fac = *pt_enr_ssf1 / (*pt_enr_ssf + 1);*/
     658    18191424 :         Ltmp0 = L_max( *pt_enr_ssf, 1 );
     659    18191424 :         exp0 = norm_l( Ltmp0 );
     660    18191424 :         wtmp0 = extract_h( L_shl( Ltmp0, exp0 ) );
     661    18191424 :         exp1 = sub( norm_l( *pt_enr_ssf1 ), 1 );
     662    18191424 :         wtmp1 = extract_h( L_shl( *pt_enr_ssf1, exp1 ) );
     663    18191424 :         fac = div_s( wtmp1, wtmp0 );
     664    18191424 :         fac_32 = L_shr_sat( L_deposit_l( fac ), add( sub( exp1, exp0 ), 15 - 13 ) ); /* fac32 in Q13*/
     665             : 
     666    18191424 :         if ( GT_32( fac_32, dE1 ) )
     667             :         {
     668     3544533 :             ind_deltaMax = i;
     669     3544533 :             move16();
     670             :         }
     671             : 
     672    18191424 :         dE1 = L_max( dE1, fac_32 ); /* Q13 */
     673             : 
     674    18191424 :         pt_enr_ssf++;
     675    18191424 :         pt_enr_ssf1++;
     676             :     }
     677             : 
     678     1136964 :     IF( hStereoClassif != NULL )
     679             :     {
     680      786051 :         IF( st_fx->idchan == 0 )
     681             :         {
     682      422855 :             hStereoClassif->dE1_ch1_fx = dE1; /* Q13 */
     683      422855 :             move32();
     684      422855 :             hStereoClassif->dE1_ch1_e = 31 - Q13;
     685      422855 :             move16();
     686             :         }
     687             :         ELSE
     688             :         {
     689      363196 :             hStereoClassif->dE1_ch2_fx = dE1; /* Q13 */
     690      363196 :             move32();
     691      363196 :             hStereoClassif->dE1_ch2_e = 31 - Q13;
     692      363196 :             move16();
     693             :         }
     694             :     }
     695             : 
     696     1136964 :     if ( dE1X != NULL )
     697             :     {
     698     1136964 :         *dE1X = dE1; /* Q13 */
     699     1136964 :         move32();
     700             :     }
     701             : 
     702             :     /*-----------------------------------------------------------------*
     703             :      * Average spectral tilt
     704             :      * Average voicing (normalized correlation)
     705             :      *-----------------------------------------------------------------*/
     706             : 
     707             :     /*mean_ee = 1.0f/3.0f * (st->ee_old + ee[0] + ee[1]); */            /* coefficients take into account the position of the window */
     708     1136964 :     mean_ee = L_add_sat( L_add_sat( st_fx->ee_old_fx, ee[0] ), ee[1] ); /* Q6 */
     709     1136964 :     mean_ee = Mult_32_16( mean_ee, 10923 );                             /*Q6*/
     710             : 
     711             :     /* mean_voi3 = 1.0f/3.0f * (voicing[0] + voicing[1] + voicing[2]);*/
     712     1136964 :     Ltmp0 = L_mult( st_fx->voicing_fx[0], 10923 /* 1/3 in Q15 */ );               /* Q31 */
     713     1136964 :     Ltmp0 = L_mac( Ltmp0, st_fx->voicing_fx[1], 10923 /* 1/3 in Q15 */ );         /* Q31 */
     714     1136964 :     mean_voi3 = mac_r_sat( Ltmp0, st_fx->voicing_fx[2], 10923 /* 1/3 in Q15 */ ); /*Q15*/
     715             :     /*-----------------------------------------------------------------*
     716             :      * Total frame energy difference (dE3)
     717             :      *-----------------------------------------------------------------*/
     718             : 
     719     1136964 :     dE3 = sub( Etot, extract_h( hNoiseEst->Etot_last_32fx ) ); /*Q8*/
     720             : 
     721             :     /*-----------------------------------------------------------------*
     722             :      * Energy decrease after spike (dE2)
     723             :      *-----------------------------------------------------------------*/
     724             : 
     725             :     /* set different thresholds and conditions for NB and WB input */
     726     1136964 :     dE2_th = 30 << 10;
     727     1136964 :     move32();
     728     1136964 :     nb_cond = 1;
     729     1136964 :     move16(); /* no additional condition for WB input */
     730     1136964 :     IF( st_fx->input_bwidth == NB )
     731             :     {
     732        4290 :         dE2_th = 21 << 10;
     733        4290 :         move32();
     734        4290 :         if ( GE_16( add_sat( mean_voi3, corr_shift ), 22282 ) ) /*( mean_voi3 + corr_shift ) >= 0.68f*/
     735             :         {
     736        2880 :             nb_cond = 0;
     737        2880 :             move16();
     738             :         }
     739             :     }
     740             : 
     741             :     /* calcualte maximum energy decrease */
     742     1136964 :     dE2 = 0;
     743     1136964 :     move16(); /* Test on energy decrease after an energy spike  */
     744     1136964 :     pt_enr_ssf = enr_ssf + 2 * NB_SSF;
     745             : 
     746     1136964 :     test();
     747     1136964 :     IF( GT_32( dE1, 30 << 13 ) && nb_cond ) /*>30 Q13*/
     748             :     {
     749       19731 :         IF( LT_16( sub( shl( NB_SSF, 1 ), ind_deltaMax ), L_ENR ) )
     750             :         {
     751        8268 :             st_fx->old_ind_deltaMax = ind_deltaMax; /* Q0 */
     752        8268 :             move16();
     753        8268 :             Copy32( pt_enr_ssf, st_fx->old_enr_ssf_fx, 2 * NB_SSF ); /* Qx */
     754             :         }
     755             :         ELSE
     756             :         {
     757       11463 :             st_fx->old_ind_deltaMax = -1;
     758       11463 :             move16();
     759       11463 :             dE2 = find_ener_decrease_fx( ind_deltaMax, pt_enr_ssf ); /*Q10*/
     760             : 
     761       11463 :             if ( GT_32( dE2, dE2_th ) )
     762             :             {
     763         148 :                 st_fx->spike_hyst = 0;
     764         148 :                 move16();
     765             :             }
     766             :         }
     767             :     }
     768             :     ELSE
     769             :     {
     770     1117233 :         IF( st_fx->old_ind_deltaMax >= 0 )
     771             :         {
     772        9242 :             Copy32( st_fx->old_enr_ssf_fx, enr_ssf, 2 * NB_SSF );            /* Qx */
     773        9242 :             dE2 = find_ener_decrease_fx( st_fx->old_ind_deltaMax, enr_ssf ); /* Q10 */
     774             : 
     775        9242 :             if ( GT_32( dE2, dE2_th ) )
     776             :             {
     777         111 :                 st_fx->spike_hyst = 1;
     778         111 :                 move16();
     779             :             }
     780             :         }
     781             : 
     782     1117233 :         st_fx->old_ind_deltaMax = -1;
     783     1117233 :         move16();
     784             :     }
     785             : 
     786             :     /*-----------------------------------------------------------------*
     787             :      * Detection of voiced offsets (tmp_offset_flag)
     788             :      *-----------------------------------------------------------------*/
     789             : 
     790     1136964 :     tmp_offset_flag = 1;
     791     1136964 :     move16();
     792             : 
     793     1136964 :     IF( st_fx->input_bwidth != NB )
     794             :     {
     795     1132674 :         ee0_th = 154; /*2.4 in Q6 */
     796     1132674 :         move16();
     797     1132674 :         voi_th = 24248; /*0.74f Q15 */
     798     1132674 :         move16();
     799             :     }
     800             :     ELSE
     801             :     {
     802        4290 :         ee0_th = 627; /*9.8f Q6 */
     803        4290 :         move16();
     804        4290 :         voi_th = 24904; /*0.76f Q15*/
     805        4290 :         move16();
     806             :     }
     807             : 
     808     1136964 :     E_min_th = L_shl( E_MIN_IVAS_FX_Q31, sub( q_hp_E, Q31 ) );
     809             : 
     810     1136964 :     test();
     811     1136964 :     test();
     812     1136964 :     test();
     813     1136964 :     IF( ( EQ_16( st_fx->last_coder_type_raw, UNVOICED ) ) ||              /* previous frame was unvoiced  */
     814             :         ( ( LT_32( ee[0], ee0_th ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy is concentrated in high frequencies provided that some energy is present in HF */
     815             :           ( LT_16( add_sat( st_fx->voicing_fx[0], corr_shift ), voi_th ) ) ) )
     816             :     /* normalized correlation is low */
     817             :     {
     818      132136 :         tmp_offset_flag = 0;
     819      132136 :         move16();
     820             :     }
     821             : 
     822             :     /*-----------------------------------------------------------------*
     823             :      * Decision about UC
     824             :      *-----------------------------------------------------------------*/
     825             : 
     826             :     /* SC-VBR - set additional parameters and thresholds for SC-VBR */
     827     1136964 :     mean_voi3_offset = 0;
     828     1136964 :     move16();
     829     1136964 :     flag_low_relE = 0;
     830     1136964 :     move16();
     831     1136964 :     ee1_th = 608; /*9.5 Q6*/
     832     1136964 :     move16();
     833     1136964 :     test();
     834     1136964 :     test();
     835     1136964 :     IF( st_fx->Opt_SC_VBR || ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) /* Allow the low energy flag for the secondary channel */
     836             :     {
     837        3811 :         ee1_th = 544; /*8.5f Q6*/
     838        3811 :         move16();
     839             : 
     840             :         /* SC-VBR - determine the threshold on relative energy as a function of lp_noise */
     841        3811 :         IF( st_fx->input_bwidth != NB )
     842             :         {
     843             :             /*relE_thres = 0.700f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16) */
     844        3811 :             L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 22938 /* 0.7 in Q15 */, extract_h( st_fx->lp_noise_32fx ) ); // Q24
     845        3811 :             IF( Last_Resort == 0 )
     846             :             {
     847             :                 /*relE_thres = 0.650f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16)*/
     848        3811 :                 L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 21299 /* 0.650f in Q15 */, extract_h( st_fx->lp_noise_32fx ) ); // Q24
     849             :             }
     850        3811 :             relE_thres = round_fx( L_tmp );
     851             :         }
     852             :         ELSE
     853             :         {
     854             : 
     855             :             /*relE_thres = 0.60f * st->lp_noise - 28.2f; (lp_noise in Q8, constant Q8<<16)*/
     856           0 :             L_tmp = L_mac( -473117491 /* 28.2f in Q24 */, 19661 /* 0.6f in Q15 */, extract_h( st_fx->lp_noise_32fx ) ); // Q24
     857           0 :             relE_thres = round_fx( L_tmp );
     858             :         }
     859        3811 :         relE_thres = s_max( relE_thres, -6400 /* -25.0f in Q8 */ ); /* Q8 */
     860             : 
     861             :         /* SC-VBR = set flag on low relative energy */
     862        3811 :         if ( LT_16( relE, relE_thres ) )
     863             :         {
     864         332 :             flag_low_relE = 1;
     865         332 :             move16();
     866             :         }
     867             : 
     868             :         /* SC-VBR - correction of voicing threshold for NB inputs (important only in noisy conditions) */
     869        3811 :         test();
     870        3811 :         if ( st_fx->input_bwidth == NB && LT_16( vadnoise, 20 << 8 ) ) /* vadnoise in Q8, constant Q0<<8 */
     871             :         {
     872           0 :             mean_voi3_offset = 1638; /*0.05f Q15*/
     873           0 :             move16();
     874             :         }
     875             :     }
     876             : 
     877             :     /* make decision whether frame is unvoiced */
     878     1136964 :     coder_type = GENERIC;
     879     1136964 :     move16();
     880     1136964 :     IF( st_fx->input_bwidth == NB )
     881             :     {
     882        4290 :         test();
     883        4290 :         test();
     884        4290 :         test();
     885        4290 :         test();
     886        4290 :         test();
     887        4290 :         test();
     888        4290 :         test();
     889        4290 :         test();
     890        4290 :         test();
     891        4290 :         test();
     892        4290 :         IF( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22282 /* 0.68 in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low  */
     893             :               ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 /* 0.79 in Q15 */ ) ) &&               /* normalized correlation low on look-ahead - onset detection */
     894             :               ( LT_32( ee[0], 640 /* 10.0f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) &&                     /* energy concentrated in high frequencies provided that some energy is present in HF...  */
     895             :               ( LT_32( ee[1], ee1_th ) ) && ( GT_32( hp_E[1], E_min_th ) ) &&                                    /* ... biased towards look-ahead to detect onsets  */
     896             :               ( tmp_offset_flag == 0 ) &&                                                                        /* Take care of voiced offsets */
     897             :               /*( st_fx->music_hysteresis_fx == 0 ) &&*/                                                         /*  ... and in segment after AUDIO frames   */
     898             :               ( LE_32( dE1, 237568 /* 29.0f in Q13 */ ) ) &&                                                     /* Avoid on sharp energy spikes  */
     899             :               ( LE_32( st_fx->old_dE1_fx, 237568 /* 29.0f in Q13 */ ) ) &&                                       /*   + one frame hysteresis   */
     900             :               ( st_fx->spike_hyst < 0 ) ) ||                                                                     /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */
     901             :             flag_low_relE )
     902             :         /* low relative frame energy (only for SC-VBR) */
     903             :         {
     904         119 :             coder_type = UNVOICED;
     905         119 :             move16();
     906             :         }
     907             :     }
     908             :     ELSE
     909             :     {
     910     1132674 :         test();
     911     1132674 :         test();
     912     1132674 :         test();
     913     1132674 :         test();
     914     1132674 :         test();
     915     1132674 :         test();
     916     1132674 :         test();
     917     1132674 :         test();
     918     1132674 :         test();
     919     1724913 :         if ( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22774 /* 0.695f in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low  */
     920             :                /*( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 ) ) && */                     /* normalized correlation low on look-ahead - onset detection */
     921      968547 :                ( LT_32( ee[0], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) &&                        /* energy concentrated in high frequencies provided that some energy is present in HF...  */
     922      238596 :                ( LT_32( ee[1], 397 /* 6.2f in Q16 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) &&                       /* ... biased towards look-ahead to detect onsets  */
     923       85905 :                ( tmp_offset_flag == 0 ) &&                                                                          /* Take care of voiced offsets */
     924             :                /*( st_fx->music_hysteresis_fx == 0 ) &&  */                                                         /*  ... and in segment after AUDIO frames   */
     925      168366 :                ( LE_32( dE1, 245760 /* 30.0f in Q13 */ ) ) &&                                                       /* Avoid on sharp energy spikes  */
     926       82461 :                ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) &&                                         /*   + one frame hysteresis   */
     927       79955 :                ( st_fx->spike_hyst < 0 ) )                                                                          /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */
     928     1052993 :              || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) ) )                    /* low relative frame energy (only for SC-VBR) */
     929             :         {
     930       79961 :             coder_type = UNVOICED;
     931       79961 :             move16();
     932             :         }
     933             :     }
     934             : 
     935             :     /*-----------------------------------------------------------------*
     936             :      * Decision about VC
     937             :      *-----------------------------------------------------------------*/
     938     1136964 :     if ( st_fx->Opt_SC_VBR )
     939             :     {
     940           0 :         hSC_VBR->set_ppp_generic = 0;
     941             :     }
     942     1136964 :     move16();
     943             : 
     944     1136964 :     test();
     945     1136964 :     test();
     946     1136964 :     IF( EQ_16( st_fx->localVAD, 1 ) && EQ_16( coder_type, GENERIC ) && NE_16( last_core_orig, AMR_WB_CORE ) )
     947             :     {
     948      902409 :         dpit1 = abs_s( sub( T_op_fr[1], T_op_fr[0] ) ); /* Q6 */
     949      902409 :         dpit2 = abs_s( sub( T_op_fr[2], T_op_fr[1] ) ); /* Q6 */
     950      902409 :         dpit3 = abs_s( sub( T_op_fr[3], T_op_fr[2] ) ); /* Q6 */
     951             : 
     952      902409 :         test();
     953      902409 :         test();
     954      902409 :         test();
     955      902409 :         test();
     956      902409 :         test();
     957      902409 :         test();
     958      902409 :         test();
     959      902409 :         test();
     960      902409 :         test();
     961      902409 :         IF( ( GT_16( voicing_fr[0], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 1st sf.  */
     962             :             ( GT_16( voicing_fr[1], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 2st sf.  */
     963             :             ( GT_16( voicing_fr[2], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 3st sf.  */
     964             :             ( GT_16( voicing_fr[3], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 4st sf.  */
     965             :             ( GT_32( mean_ee, 256 /* 4.0f in Q6 */ ) ) &&           /* energy concentrated in low frequencies  */
     966             :             ( LT_16( dpit1, 3 << 6 ) ) &&
     967             :             ( LT_16( dpit2, 3 << 6 ) ) &&
     968             :             ( LT_16( dpit3, 3 << 6 ) ) )
     969             :         {
     970      377820 :             coder_type = VOICED;
     971      377820 :             move16();
     972             :         }
     973      524589 :         ELSE IF( st_fx->Opt_SC_VBR && st_fx->input_bwidth == NB && LT_16( vadnoise, 20 << 8 ) )
     974             :         {
     975           0 :             test();
     976           0 :             test();
     977           0 :             test();
     978           0 :             test();
     979           0 :             test();
     980           0 :             test();
     981           0 :             test();
     982           0 :             IF( GT_16( voicing_fr[0], 8192 /* 0.25 in Q15 */ ) &&     /* normalized correlation high in 1st sf.  */
     983             :                 ( GT_16( voicing_fr[1], 8192 /* 0.25 in Q15 */ ) ) && /* normalized correlation high in 2st sf.  */
     984             :                 ( GT_16( voicing_fr[2], 8192 /* 0.25 in Q15 */ ) ) && /* normalized correlation high in 3st sf.  */
     985             :                 ( GT_16( voicing_fr[3], 8192 /* 0.25 in Q15 */ ) ) && /* normalized correlation high in 4st sf.  */
     986             :                 ( GT_32( mean_ee, 64 /* 1.0f in Q6 */ ) ) &&          /* energy concentrated in low frequencies  */
     987             :                 ( LT_16( dpit1, 5 << 6 ) ) &&
     988             :                 ( LT_16( dpit2, 5 << 6 ) ) &&
     989             :                 ( LT_16( dpit3, 5 << 6 ) ) )
     990             :             {
     991           0 :                 hSC_VBR->set_ppp_generic = 1;
     992           0 :                 move16();
     993           0 :                 coder_type = VOICED;
     994           0 :                 move16();
     995             :             }
     996             :         }
     997             : 
     998             :         /* set VOICED mode for frames with very stable pitch and high correlation
     999             :            and avoid to switch to AUDIO/MUSIC later                              */
    1000      902409 :         voicing_m = mac_r( L_mac( L_mac( L_mult( voicing_fr[3], 8192 /* 0.25 in Q15 */ ), voicing_fr[2], 8192 /* 0.25 in Q15 */ ), voicing_fr[1], 8192 /* 0.25 in Q15 */ ), voicing_fr[0], 8192 /* 0.25 in Q15 */ ); /* Q15 */
    1001      902409 :         test();
    1002      902409 :         test();
    1003      902409 :         test();
    1004      902409 :         test();
    1005      902409 :         test();
    1006      902409 :         IF( *flag_spitch || ( LE_16( dpit1, 3 << 6 ) && LE_16( dpit2, 3 << 6 ) && LE_16( dpit3, 3 << 6 ) &&
    1007             :                               GT_16( voicing_m, 31130 /* 0.95f in Q15 */ ) && GT_16( st_fx->voicing_sm_fx, 31785 /* 0.97f in Q15 */ ) ) )
    1008             :         {
    1009       39458 :             coder_type = VOICED;
    1010       39458 :             move16();
    1011       39458 :             *flag_spitch = 1;
    1012       39458 :             move16(); /*to avoid switch to AUDIO/MUSIC later*/
    1013             :         }
    1014             :     }
    1015             : 
    1016             :     /*-----------------------------------------------------------------*
    1017             :      * Channel-aware mode - set RF mode and total bitrate
    1018             :      *-----------------------------------------------------------------*/
    1019             : 
    1020     1136964 :     st_fx->rf_mode = st_fx->Opt_RF_ON; /* Q0 */
    1021     1136964 :     move16();
    1022             : 
    1023     1136964 :     IF( EQ_16( coder_type, GENERIC ) )
    1024             :     {
    1025      673843 :         test();
    1026      673843 :         test();
    1027      673843 :         test();
    1028      673843 :         test();
    1029      673843 :         IF( ( LT_16( voicing_fr[0], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 2st sf.  */
    1030             :             ( LT_16( voicing_fr[1], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 2st sf.  */
    1031             :             ( LT_16( voicing_fr[2], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 3rd sf.  */
    1032             :             ( LT_16( voicing_fr[3], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 4th sf.  */
    1033             :             ( GT_16( vadnoise, 25 << 8 ) ) )                      /* when speech is clean */
    1034             : 
    1035             :         {
    1036           0 :             st_fx->rf_mode = 0;
    1037           0 :             move16();
    1038             :             /* Current frame cannot be compressed to pack the partial redundancy;*/
    1039             : 
    1040           0 :             IF( NE_16( st_fx->rf_mode, st_fx->Opt_RF_ON ) )
    1041             :             {
    1042           0 :                 core_coder_mode_switch_ivas_fx( st_fx, st_fx->last_total_brate, 0 );
    1043             :             }
    1044             :         }
    1045             :     }
    1046             : 
    1047             :     /*-----------------------------------------------------------------*
    1048             :      * UNCLR classifier
    1049             :      *-----------------------------------------------------------------*/
    1050             : 
    1051     1136964 :     IF( hStereoClassif != NULL )
    1052             :     {
    1053      786051 :         test();
    1054      786051 :         test();
    1055      786051 :         test();
    1056      786051 :         test();
    1057      786051 :         test();
    1058      786051 :         IF( st_fx->element_mode > EVS_MONO && ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, UNVOICED ) || coder_type == INACTIVE || st_fx->localVAD == 0 ) && LT_16( hStereoClassif->unclr_sw_enable_cnt[st_fx->idchan], MAX_UV_CNT ) )
    1059             :         {
    1060      494269 :             hStereoClassif->unclr_sw_enable_cnt[st_fx->idchan] = add( hStereoClassif->unclr_sw_enable_cnt[st_fx->idchan], 1 );
    1061      494269 :             move16();
    1062             :         }
    1063             :         ELSE
    1064             :         {
    1065      291782 :             hStereoClassif->unclr_sw_enable_cnt[st_fx->idchan] = 0;
    1066      291782 :             move16();
    1067             :         }
    1068             :     }
    1069             : 
    1070             :     /*-----------------------------------------------------------------*
    1071             :      * Updates
    1072             :      *-----------------------------------------------------------------*/
    1073             : 
    1074             :     /* update spike hysteresis parameters */
    1075     1136964 :     test();
    1076     1136964 :     if ( st_fx->spike_hyst >= 0 && LT_16( st_fx->spike_hyst, 2 ) )
    1077             :     {
    1078         407 :         st_fx->spike_hyst = add( st_fx->spike_hyst, 1 ); /* Q0 */
    1079         407 :         move16();
    1080             :     }
    1081             : 
    1082             :     /* reset spike hysteresis */
    1083     1136964 :     test();
    1084     1136964 :     test();
    1085     1136964 :     test();
    1086     1140237 :     if ( ( GT_16( st_fx->spike_hyst, 1 ) ) &&
    1087        6407 :          ( GT_16( dE3, 5 << 8 ) ||                                                                                                /* energy increases               */
    1088        5284 :            ( GT_16( relE, -3328 /* 13 in Q8 */ ) && ( GT_16( add_sat( mean_voi3, corr_shift ), 22774 /* 0.695 in Q15 */ ) ) ) ) ) /* normalized correlation is high */
    1089             :     {
    1090         248 :         st_fx->spike_hyst = -1;
    1091         248 :         move16();
    1092             :     }
    1093             : 
    1094             :     /* update tilt parameters */
    1095     1136964 :     st_fx->ee_old_fx = ee[1];
    1096     1136964 :     move32(); /*Q6*/
    1097     1136964 :     st_fx->old_dE1_fx = dE1;
    1098     1136964 :     move32(); /*Q13*/
    1099             : 
    1100             :     /* save the raw coder_type for various modules later in the codec (the reason is that e.g. UNVOICED is lost at higher rates) */
    1101     1136964 :     st_fx->coder_type_raw = coder_type; /* Q0 */
    1102     1136964 :     move16();
    1103             : 
    1104     1136964 :     return coder_type;
    1105             : }

Generated by: LCOV version 1.14