LCOV - code coverage report
Current view: top level - lib_enc - sig_clas_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 215 267 80.5 %
Date: 2025-05-03 01:55:50 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : 
       5             : #include <stdint.h>
       6             : #include "options.h" /* Compilation switches                   */
       7             : #include "cnst.h"    /* Common constants                       */
       8             : //#include "prot_fx.h"       /* Function prototypes                    */
       9             : #include "rom_com.h"
      10             : #include "prot_fx.h"     /* Function prototypes                    */
      11             : #include "prot_fx_enc.h" /* Function prototypes                    */
      12             : 
      13             : /*---------------------------------------------------------------------*
      14             :  * Local constants
      15             :  *---------------------------------------------------------------------*/
      16             : 
      17             : #define K_COR_FX 23405  /* Q13    2.857 */
      18             : #define C_COR_FX -10535 /* Q13   -1.286 */
      19             : 
      20             : #define K_EE_FX 1365 /* Q15  0.04167 */
      21             : #define C_EE_FX 0
      22             : 
      23             : #define K_ZC_FX -1311 /* Q15   -0.04 */
      24             : #define C_ZC_FX 19661 /* Q13    2.4  */
      25             : 
      26             : #define K_RELE_FX 1638  /* Q15    0.05 */
      27             : #define C_RELE_FX 14746 /* Q15    0.45 */
      28             : 
      29             : #define K_PC_FX -2341 /* Q15 -0.07143*/
      30             : #define C_PC_FX 30425 /* Q1   1.857  */
      31             : 
      32             : #define K_SNR_FX 3541   /* Q15 .1111    */
      33             : #define C_SNR_FX -10921 /* Q15 -0.3333f */
      34             : 
      35             : 
      36             : #define THRES_EEN 514206 /* 251.077 =>  (10^(1/(K_EE*10)))  Q11*/
      37             : 
      38             : /*-------------------------------------------------------------------*
      39             :  * signal_clas_fx()
      40             :  *
      41             :  * classification state machine for FEC
      42             :  * TC frames selection
      43             :  *-------------------------------------------------------------------*/
      44             : 
      45     1114310 : Word16 signal_clas_fx(                       /* o  : classification for current frames              */
      46             :                        Encoder_State *st,    /* i/o: encoder state structure                           */
      47             :                        const Word16 *speech, /* i  : pointer to speech signal for E computation in Qx */
      48             :                        const Word32 *ee,     /* i  : lf/hf E ration for 2 half-frames in Q6            */
      49             :                        const Word16 relE,    /* i  : frame relative E to the long term average in Q8   */
      50             :                        const Word16 L_look,  /* i  : look-ahead                                        */
      51             :                        Word16 *clas_mod      /* o  : class flag for NOOP detection                     */
      52             : )
      53             : {
      54             :     Word32 Ltmp;
      55             :     Word16 mean_voi2, een, corn, zcn, relEn, pcn, fmerit1;
      56             :     Word16 i, clas, pc, zc, lo, lo2, hi, hi2, exp_ee, frac_ee;
      57             :     Word16 tmp16, tmpS;
      58             :     const Word16 *pt1;
      59             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      60     1114310 :     Flag Overflow = 0;
      61     1114310 :     move32();
      62             : #endif
      63             : 
      64             :     /*----------------------------------------------------------------*
      65             :      * Calculate average voicing
      66             :      * Calculate average spectral tilt
      67             :      * Calculate zero-crossing rate
      68             :      * Calculate pitch stability
      69             :      *----------------------------------------------------------------*/
      70             : 
      71             :     /* average voicing on second half-frame and look-ahead */
      72     1114310 :     Ltmp = L_mult( st->voicing_fx[1], 16384 ); /* Q15*Q14->Q30 */
      73     1114310 :     mean_voi2 = mac_r( Ltmp, st->voicing_fx[2], 16384 );
      74             : 
      75             :     /* average spectral tilt in dB */
      76     1114310 :     lo = L_Extract_lc( ee[0], &hi );
      77     1114310 :     lo2 = L_Extract_lc( ee[1], &hi2 );
      78     1114310 :     Ltmp = L_mult( lo, lo2 ); /* Q5*Q5->Q11 */
      79             : 
      80     1114310 :     test();
      81     1114310 :     test();
      82     1114310 :     IF( LT_32( Ltmp, 2048 ) )
      83             :     {
      84      111697 :         een = 0;
      85      111697 :         move16();
      86             :     }
      87     1002613 :     ELSE IF( GT_32( Ltmp, THRES_EEN ) || hi > 0 || hi2 > 0 )
      88             :     {
      89      712515 :         een = 512;
      90      712515 :         move16();
      91             :     }
      92             :     ELSE
      93             :     {
      94             :         /* mean_ee2 = 0.5f * 20.0f * (float)log10( tmp ); */
      95             :         /* een = K_EE_ENC * mean_ee2 + C_EE_ENC; */
      96      290098 :         exp_ee = norm_l( Ltmp );
      97      290098 :         frac_ee = Log2_norm_lc( L_shl( Ltmp, exp_ee ) );
      98      290098 :         exp_ee = sub( 30 - 11, exp_ee );
      99      290098 :         Ltmp = Mpy_32_16( exp_ee, frac_ee, LG10 ); /* Ltmp Q14 */
     100      290098 :         een = round_fx( L_shl( Ltmp, 16 - 5 ) );   /* Q14 -> Q9 */
     101      290098 :         een = mac_r( C_EE_FX, een, K_EE_FX );
     102             :     }
     103             : 
     104             :     /* compute zero crossing rate */
     105     1114310 :     pt1 = speech + sub( L_look, 1 );
     106     1114310 :     tmpS = shr( *pt1, 15 ); /* sets 'tmpS to -1 if *pt1 < 0 */
     107     1114310 :     Ltmp = L_deposit_l( 0 );
     108   286377670 :     FOR( i = 0; i < L_FRAME; i++ )
     109             :     {
     110   285263360 :         tmp16 = add( 1, tmpS );
     111   285263360 :         pt1++;
     112   285263360 :         tmpS = shr( *pt1, 15 ); /* pt1 >=0 ---> 0 OTHERWISE -1   */
     113   285263360 :         Ltmp = L_msu0( Ltmp, tmpS, tmp16 );
     114             :     }
     115     1114310 :     zc = extract_l( Ltmp );
     116             : 
     117             :     /* compute pitch stability */
     118     1114310 :     pc = add( abs_s( sub( st->pitch[1], st->pitch[0] ) ), abs_s( sub( st->pitch[2], st->pitch[1] ) ) );
     119     1114310 :     st->tdm_pc = pc;
     120     1114310 :     move16();
     121             :     /*-----------------------------------------------------------------*
     122             :      * Transform parameters to the range <0:1>
     123             :      * Compute the merit function
     124             :      *-----------------------------------------------------------------*/
     125             : 
     126             :     /* corn = K_COR * mean_voi2 + C_COR */
     127     1114310 :     Ltmp = L_mult( C_COR_FX, 32767 );
     128     1114310 :     corn = round_fx( L_shl( L_mac( Ltmp, mean_voi2, K_COR_FX ), -4 ) ); /*Q13+Q13*Q15 =>Q13->Q9*/
     129             :     /* Limit [0, 1] */
     130     1114310 :     corn = s_max( corn, 0 );
     131     1114310 :     corn = s_min( corn, 512 );
     132             : 
     133     1114310 :     Ltmp = L_mult( C_ZC_FX, 4 );                                   /*Q13*Q2 -> Q16*/
     134     1114310 :     zcn = round_fx( L_shl( L_mac( Ltmp, zc, K_ZC_FX ), 16 - 7 ) ); /*Q0*Q15 + Q16*/
     135             :     /* Limit [0, 1] */
     136     1114310 :     zcn = s_max( zcn, 0 );
     137     1114310 :     zcn = s_min( zcn, 512 );
     138             : 
     139     1114310 :     Ltmp = L_mult( C_RELE_FX, 256 );                                /*Q15*Q8 ->Q24*/
     140     1114310 :     relEn = round_fx( L_shl( L_mac( Ltmp, relE, K_RELE_FX ), 1 ) ); /*relE in Q8 but relEn in Q9*/
     141             :     /* Limit [0.5, 1] */
     142     1114310 :     relEn = s_max( relEn, 256 );
     143     1114310 :     relEn = s_min( relEn, 512 );
     144             : 
     145     1114310 :     Ltmp = L_mult( C_PC_FX, 2 );                                   /*Q14*Q1 -> Q16*/
     146     1114310 :     pcn = round_fx( L_shl( L_mac( Ltmp, pc, K_PC_FX ), 16 - 7 ) ); /*Q16 + Q0*Q15*/
     147             :     /* Limit [0, 1] */
     148     1114310 :     pcn = s_max( pcn, 0 );
     149     1114310 :     pcn = s_min( pcn, 512 );
     150             : 
     151     1114310 :     Ltmp = L_mult( een, 10923 );
     152     1114310 :     Ltmp = L_mac( Ltmp, corn, 21845 );
     153     1114310 :     Ltmp = L_mac( Ltmp, zcn, 10923 );
     154     1114310 :     Ltmp = L_mac( Ltmp, relEn, 10923 );
     155     1114310 :     Ltmp = L_mac( Ltmp, pcn, 10923 );
     156             : 
     157     1114310 :     fmerit1 = round_fx_o( L_shl_o( Ltmp, 16 - 10 - 1, &Overflow ), &Overflow ); /* fmerit1 ->Q15 */
     158             : 
     159             :     /*-----------------------------------------------------------------*
     160             :      * FEC classification
     161             :      *-----------------------------------------------------------------*/
     162             : 
     163     1114310 :     st->fmerit_dt = sub( st->prev_fmerit, fmerit1 ); /*Q15*/
     164     1114310 :     move16();
     165     1114310 :     st->prev_fmerit = fmerit1;
     166     1114310 :     move16();
     167             : 
     168             :     /* FEC classification */
     169     1114310 :     test();
     170     1114310 :     test();
     171     1114310 :     IF( st->localVAD == 0 || EQ_16( st->coder_type, UNVOICED ) || LT_16( relE, -1536 ) )
     172             :     {
     173      533110 :         clas = UNVOICED_CLAS;
     174      533110 :         *clas_mod = clas;
     175      533110 :         move16();
     176      533110 :         move16();
     177             :     }
     178             :     ELSE
     179             :     {
     180      581200 :         SWITCH( st->last_clas )
     181             :         {
     182      441869 :             case VOICED_CLAS:
     183             :             case ONSET:
     184             :             case VOICED_TRANSITION:
     185             : 
     186      441869 :                 IF( LT_16( fmerit1, 16056 ) ) /*0.49f*/
     187             :                 {
     188       20356 :                     clas = UNVOICED_CLAS;
     189       20356 :                     move16();
     190             :                 }
     191      421513 :                 ELSE IF( LT_16( fmerit1, 21626 ) ) /*0.66*/
     192             :                 {
     193       54542 :                     clas = VOICED_TRANSITION;
     194       54542 :                     move16();
     195             :                 }
     196             :                 ELSE
     197             :                 {
     198      366971 :                     clas = VOICED_CLAS;
     199      366971 :                     move16();
     200             :                 }
     201      441869 :                 IF( LT_16( fmerit1, 14745 /* 0.45f*/ ) )
     202             :                 {
     203       13086 :                     *clas_mod = UNVOICED_CLAS;
     204       13086 :                     move16();
     205             :                 }
     206      428783 :                 ELSE IF( LT_16( fmerit1, 21626 /* 0.66f*/ ) )
     207             :                 {
     208       61812 :                     *clas_mod = VOICED_TRANSITION;
     209       61812 :                     move16();
     210             :                 }
     211             :                 ELSE
     212             :                 {
     213      366971 :                     *clas_mod = VOICED_CLAS;
     214      366971 :                     move16();
     215             :                 }
     216      441869 :                 BREAK;
     217             : 
     218      139331 :             case UNVOICED_CLAS:
     219             :             case UNVOICED_TRANSITION:
     220      139331 :                 IF( GT_16( fmerit1, 20643 ) ) /*0.63*/
     221             :                 {
     222       56111 :                     clas = ONSET;
     223       56111 :                     move16();
     224             :                 }
     225       83220 :                 ELSE IF( GT_16( fmerit1, 19169 ) ) /*0.585*/
     226             :                 {
     227       11620 :                     clas = UNVOICED_TRANSITION;
     228       11620 :                     move16();
     229             :                 }
     230             :                 ELSE
     231             :                 {
     232       71600 :                     clas = UNVOICED_CLAS;
     233       71600 :                     move16();
     234             :                 }
     235      139331 :                 *clas_mod = clas;
     236      139331 :                 move16();
     237             : 
     238      139331 :                 BREAK;
     239             : 
     240           0 :             default:
     241           0 :                 clas = UNVOICED_CLAS;
     242           0 :                 *clas_mod = clas;
     243           0 :                 move16();
     244           0 :                 move16();
     245           0 :                 BREAK;
     246             :         }
     247             :     }
     248             :     /* Onset classification */
     249             : 
     250             :     /* tc_cnt == -1: frame after TC frame in continuous block of GC/VC frames */
     251             :     /* tc_cnt ==  0: UC frame */
     252             :     /* tc_cnt ==  1: onset/transition frame, coded by GC coder type */
     253             :     /* tc_cnt ==  2: frame after onset/transition frame, coded by TC coder type */
     254             : 
     255     1114310 :     if ( clas == 0 )
     256             :     {
     257      625066 :         st->tc_cnt = 0;
     258      625066 :         move16();
     259             :     }
     260             : 
     261     1114310 :     test();
     262     1114310 :     IF( GE_16( clas, VOICED_TRANSITION ) && st->tc_cnt >= 0 )
     263             :     {
     264      139647 :         st->tc_cnt = add( st->tc_cnt, 1 );
     265      139647 :         move16();
     266             :     }
     267             : 
     268     1114310 :     if ( GT_16( st->tc_cnt, 2 ) )
     269             :     {
     270       38419 :         st->tc_cnt = -1;
     271       38419 :         move16();
     272             :     }
     273     1114310 :     return clas;
     274             : }
     275             : /*-------------------------------------------------------------------*
     276             :  * select_TC_fx()
     277             :  *
     278             :  * Select TC coder type for appropriate frames which is in general VOICED_TRANSITION,
     279             :  * VOICED_CLAS or ONSET frames following UNVOICED_CLAS frames
     280             :  *-------------------------------------------------------------------*/
     281             : 
     282     1114310 : void select_TC_fx(
     283             :     const Word16 codec_mode, /* i  : codec mode                      */
     284             :     const Word16 tc_cnt,     /* i  : TC frame counter                */
     285             :     Word16 *coder_type,      /* i/o: coder type                      */
     286             :     const Word16 localVAD    /* i  : VAD without hangover            */
     287             : )
     288             : {
     289     1114310 :     IF( EQ_16( codec_mode, MODE1 ) )
     290             :     {
     291             :         /*---------------------------------------------------------------------*
     292             :          * Select TC coder type for appropriate frames which is in general VOICED_TRANSITION,
     293             :          * VOICED_CLAS or ONSET frames following UNVOICED_CLAS frames
     294             :          *---------------------------------------------------------------------*/
     295     1113260 :         test();
     296     1113260 :         IF( localVAD != 0 && GE_16( tc_cnt, 1 ) )
     297             :         {
     298      101145 :             IF( EQ_16( tc_cnt, 1 ) )
     299             :             {
     300             :                 /* onset/transition frame is always coded using GC coder type */
     301       56072 :                 *coder_type = GENERIC;
     302       56072 :                 move16();
     303             :             }
     304             :             ELSE
     305             :             {
     306             :                 /* frame after onset/transition frame is coded by TC coder type */
     307       45073 :                 *coder_type = TRANSITION;
     308       45073 :                 move16();
     309             :             }
     310             :         }
     311             :     }
     312             : 
     313     1114310 :     return;
     314             : }
     315             : 
     316             : /*-------------------------------------------------------------------*
     317             :  * coder_type_modif_fx()
     318             :  *
     319             :  * Coder type modification
     320             :  *-------------------------------------------------------------------*/
     321             : 
     322        3100 : void coder_type_modif_fx(
     323             :     Encoder_State *st, /* i/o: encoder state structure                     */
     324             :     const Word16 relE  /* i  : frame relative E to the long term average Q8*/
     325             : )
     326             : {
     327             :     Word16 unmod_coder_type, vbr_generic_ho;
     328             : 
     329        3100 :     SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR;
     330             : 
     331             : 
     332        3100 :     IF( st->Opt_SC_VBR )
     333             :     {
     334           0 :         vbr_generic_ho = hSC_VBR->vbr_generic_ho;
     335           0 :         move16();
     336             :     }
     337             :     ELSE
     338             :     {
     339        3100 :         vbr_generic_ho = -1;
     340        3100 :         move16();
     341             :     }
     342             : 
     343        3100 :     IF( EQ_16( st->codec_mode, MODE1 ) )
     344             :     {
     345             :         /*---------------------------------------------------------------------*
     346             :          * Coder type modification
     347             :          *
     348             :          * Prevent UC coder type in certain conditions
     349             :          * Prevent VC coder type in certain conditions
     350             :          * Select TC coder type in appropriate frames
     351             :          *---------------------------------------------------------------------*/
     352             : 
     353             :         /* At higher rates, use GC coding instead of UC coding to improve quality */
     354        2050 :         test();
     355        2050 :         test();
     356        2050 :         test();
     357        2050 :         test();
     358        2050 :         test();
     359        2050 :         if ( ( st->element_mode == 0 && GT_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) ) ||
     360        1957 :              ( st->element_mode > 0 && GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) )
     361             :         {
     362          93 :             st->coder_type = GENERIC;
     363          93 :             move16();
     364             :         }
     365             : 
     366             :         /* Prevent UC coding on mixed content at 9.6 kb/s */
     367        2050 :         test();
     368        2050 :         test();
     369        2050 :         if ( GE_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) && st->audio_frame_cnt != 0 )
     370             :         {
     371           0 :             st->coder_type = GENERIC;
     372           0 :             move16();
     373             :         }
     374             : 
     375        2050 :         unmod_coder_type = st->coder_type;
     376        2050 :         move16();
     377             : 
     378             :         /* Enforce GC coder type on inactive signal (this can be later overwritten to INACTIVE) */
     379        2050 :         test();
     380        2050 :         test();
     381        2050 :         test();
     382        2050 :         test();
     383        2050 :         test();
     384        2050 :         test();
     385        2050 :         test();
     386        2110 :         if ( st->localVAD == 0 && ( (
     387         120 :                                         EQ_16( st->coder_type, UNVOICED ) && ( ( st->Opt_SC_VBR == 0 ) || ( ( EQ_16( st->Opt_SC_VBR, 1 ) ) && vbr_generic_ho == 0 && GT_16( st->last_coder_type, UNVOICED ) ) ) ) ||
     388         120 :                                     EQ_16( st->coder_type, TRANSITION ) || EQ_16( st->coder_type, VOICED ) )
     389             : 
     390             :         )
     391             :         {
     392           0 :             st->coder_type = GENERIC;
     393           0 :             move16();
     394             :         }
     395             : 
     396        2050 :         test();
     397        2050 :         test();
     398        2050 :         IF( EQ_16( st->Opt_SC_VBR, 1 ) )
     399             :         {
     400           0 :             test();
     401           0 :             if ( EQ_16( st->coder_type, GENERIC ) && EQ_16( unmod_coder_type, UNVOICED ) )
     402             :             {
     403           0 :                 hSC_VBR->vbr_generic_ho = 1;
     404           0 :                 move16();
     405             :             }
     406             : 
     407           0 :             if ( GT_16( st->coder_type, UNVOICED ) )
     408             :             {
     409           0 :                 hSC_VBR->vbr_generic_ho = 0;
     410           0 :                 move16();
     411             :             }
     412             :         } //_DIFF_FLOAT_FIX_ see below
     413             :           // PMT("Verify if EVS or IVAS is right about last_7k2_coder_type update")
     414        2050 :         hSC_VBR->last_7k2_coder_type = st->coder_type;
     415        2050 :         move16();
     416        2050 :         test();
     417        2050 :         if ( st->localVAD == 0 && EQ_16( st->coder_type, UNVOICED ) )
     418             :         {
     419           0 :             hSC_VBR->last_7k2_coder_type = GENERIC;
     420           0 :             move16();
     421             :         }
     422             :         //}  closing bracket here in IVAS float, but not in EVS float. currently affects BE for switching bitrate on Linux 20220929 _DIFF_FLOAT_FIX_ !!
     423             : 
     424        2050 :         IF( st->element_mode == 0 )
     425             :         {
     426             :             /* At higher rates and with 16kHz core, allow only GC and TC coder type */
     427        2050 :             test();
     428        2050 :             test();
     429             :             // test();
     430        2050 :             if ( GT_32( st->total_brate, ACELP_16k40 ) && NE_16( st->coder_type, GENERIC ) && NE_16( st->coder_type, TRANSITION ) )
     431             :             {
     432             :                 /* onset/transition frame is always coded using GC mode */
     433         556 :                 st->coder_type = GENERIC;
     434         556 :                 move16();
     435             :             }
     436             :         }
     437             :         ELSE /*IVAS*/
     438             :         {
     439             :             /* At higher bitrates, disable UC and VC coder type; note that IC coder type is classified later */
     440           0 :             test();
     441           0 :             test();
     442           0 :             test();
     443           0 :             if ( ( GT_32( st->total_brate, MAX_VOICED_BRATE ) && EQ_16( st->coder_type, VOICED ) ) ||
     444           0 :                  ( GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) )
     445             :             {
     446           0 :                 st->coder_type = GENERIC;
     447           0 :                 move16();
     448             :             }
     449             :         }
     450             : 
     451             :         /* Patch for certain low-level signals for which the gain quantizer sometimes goes out of its dynamic range */
     452        2050 :         test();
     453        2050 :         test();
     454        2050 :         test();
     455        2050 :         if ( EQ_16( st->coder_type, VOICED ) && st->input_bwidth == 0 && LT_16( relE, -2560 ) && LE_32( st->total_brate, ACELP_8k00 ) )
     456             :         {
     457           0 :             st->coder_type = GENERIC;
     458           0 :             move16();
     459             :         }
     460             :     }
     461             : 
     462        3100 :     return;
     463             : }
     464     1107383 : void coder_type_modif_ivas_fx(
     465             :     Encoder_State *st, /* i/o: encoder state structure                     */
     466             :     const Word16 relE  /* i  : frame relative E to the long term average   */
     467             : )
     468             : {
     469             :     Word16 unmod_coder_type, vbr_generic_ho;
     470             : 
     471     1107383 :     SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR;
     472             : 
     473             : 
     474     1107383 :     IF( st->Opt_SC_VBR )
     475             :     {
     476           0 :         vbr_generic_ho = hSC_VBR->vbr_generic_ho;
     477           0 :         move16();
     478             :     }
     479             :     ELSE
     480             :     {
     481     1107383 :         vbr_generic_ho = -1;
     482     1107383 :         move16();
     483             :     }
     484             : 
     485     1107383 :     IF( EQ_16( st->codec_mode, MODE1 ) )
     486             :     {
     487             :         /*---------------------------------------------------------------------*
     488             :          * Coder type modification
     489             :          *
     490             :          * Prevent UC coder type in certain conditions
     491             :          * Prevent VC coder type in certain conditions
     492             :          * Select TC coder type in appropriate frames
     493             :          *---------------------------------------------------------------------*/
     494             : 
     495             :         /* At higher rates, use GC coding instead of UC coding to improve quality */
     496     1107383 :         test();
     497     1107383 :         test();
     498     1107383 :         test();
     499     1107383 :         test();
     500     1107383 :         test();
     501     1107383 :         if ( ( st->element_mode == 0 && GT_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) ) ||
     502     1107383 :              ( st->element_mode > 0 && GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) )
     503             :         {
     504       67983 :             st->coder_type = GENERIC;
     505       67983 :             move16();
     506             :         }
     507             : 
     508             :         /* Prevent UC coding on mixed content at 9.6 kb/s */
     509     1107383 :         test();
     510     1107383 :         test();
     511     1107383 :         if ( GE_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) && st->audio_frame_cnt != 0 )
     512             :         {
     513        2341 :             st->coder_type = GENERIC;
     514        2341 :             move16();
     515             :         }
     516             : 
     517     1107383 :         unmod_coder_type = st->coder_type;
     518     1107383 :         move16();
     519             : 
     520             :         /* Enforce GC coder type on inactive signal (this can be later overwritten to INACTIVE) */
     521     1107383 :         test();
     522     1107383 :         test();
     523     1107383 :         test();
     524     1107383 :         test();
     525     1107383 :         test();
     526     1107383 :         test();
     527     1107383 :         test();
     528     1276405 :         if ( st->localVAD == 0 && ( (
     529      338044 :                                         EQ_16( st->coder_type, UNVOICED ) && ( ( st->Opt_SC_VBR == 0 ) || ( ( EQ_16( st->Opt_SC_VBR, 1 ) ) && vbr_generic_ho == 0 && GT_16( st->last_coder_type, UNVOICED ) ) ) ) ||
     530      336954 :                                     EQ_16( st->coder_type, TRANSITION ) || EQ_16( st->coder_type, VOICED ) )
     531             : 
     532             :         )
     533             :         {
     534         545 :             st->coder_type = GENERIC;
     535         545 :             move16();
     536             :         }
     537             : 
     538     1107383 :         if ( EQ_16( st->Opt_SC_VBR, 1 ) )
     539             :         {
     540           0 :             test();
     541           0 :             if ( EQ_16( st->coder_type, GENERIC ) && EQ_16( unmod_coder_type, UNVOICED ) )
     542             :             {
     543           0 :                 hSC_VBR->vbr_generic_ho = 1;
     544           0 :                 move16();
     545             :             }
     546             : 
     547           0 :             if ( GT_16( st->coder_type, UNVOICED ) )
     548             :             {
     549           0 :                 hSC_VBR->vbr_generic_ho = 0;
     550           0 :                 move16();
     551             :             }
     552             : 
     553           0 :             hSC_VBR->last_7k2_coder_type = st->coder_type;
     554           0 :             move16();
     555           0 :             test();
     556           0 :             if ( st->localVAD == 0 && EQ_16( st->coder_type, UNVOICED ) )
     557             :             {
     558           0 :                 hSC_VBR->last_7k2_coder_type = GENERIC;
     559           0 :                 move16();
     560             :             }
     561             :         }
     562             : 
     563     1107383 :         IF( st->element_mode == 0 )
     564             :         {
     565             :             /* At higher rates and with 16kHz core, allow only GC and TC coder type */
     566           0 :             test();
     567           0 :             test();
     568           0 :             if ( GT_32( st->total_brate, ACELP_16k40 ) && NE_16( st->coder_type, GENERIC ) && NE_16( st->coder_type, TRANSITION ) )
     569             :             {
     570             :                 /* onset/transition frame is always coded using GC mode */
     571           0 :                 st->coder_type = GENERIC;
     572           0 :                 move16();
     573             :             }
     574             :         }
     575             :         ELSE /*IVAS*/
     576             :         {
     577             :             /* At higher bitrates, disable UC and VC coder type; note that IC coder type is classified later */
     578     1107383 :             test();
     579     1107383 :             test();
     580     1107383 :             test();
     581     1902862 :             if ( ( GT_32( st->total_brate, MAX_VOICED_BRATE ) && EQ_16( st->coder_type, VOICED ) ) ||
     582     1494822 :                  ( GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) )
     583             :             {
     584      311904 :                 st->coder_type = GENERIC;
     585      311904 :                 move16();
     586             :             }
     587             :         }
     588             : 
     589             :         /* Patch for certain low-level signals for which the gain quantizer sometimes goes out of its dynamic range */
     590     1107383 :         test();
     591     1107383 :         test();
     592     1107383 :         test();
     593     1107383 :         if ( EQ_16( st->coder_type, VOICED ) && EQ_16( st->input_bwidth, NB ) && LT_16( relE, -2560 ) && LE_32( st->total_brate, ACELP_8k00 ) )
     594             :         {
     595           0 :             st->coder_type = GENERIC;
     596           0 :             move16();
     597             :         }
     598             :     }
     599             : 
     600     1107383 :     return;
     601             : }

Generated by: LCOV version 1.14