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 @ 574a190e3c6896c6c4ed10d7f23649709a0c4347 Lines: 321 381 84.3 %
Date: 2025-06-27 02:59:36 Functions: 5 5 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        3100 : 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        3100 :     Flag Overflow = 0;
      61        3100 :     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        3100 :     Ltmp = L_mult( st->voicing_fx[1], 16384 ); /* Q15*Q14->Q30 */
      73        3100 :     mean_voi2 = mac_r( Ltmp, st->voicing_fx[2], 16384 );
      74             : 
      75             :     /* average spectral tilt in dB */
      76        3100 :     lo = L_Extract_lc( ee[0], &hi );
      77        3100 :     lo2 = L_Extract_lc( ee[1], &hi2 );
      78        3100 :     Ltmp = L_mult( lo, lo2 ); /* Q5*Q5->Q11 */
      79             : 
      80        3100 :     test();
      81        3100 :     test();
      82        3100 :     IF( LT_32( Ltmp, 2048 ) )
      83             :     {
      84         457 :         een = 0;
      85         457 :         move16();
      86             :     }
      87        2643 :     ELSE IF( GT_32( Ltmp, THRES_EEN ) || hi > 0 || hi2 > 0 )
      88             :     {
      89        2160 :         een = 512;
      90        2160 :         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         483 :         exp_ee = norm_l( Ltmp );
      97         483 :         frac_ee = Log2_norm_lc( L_shl( Ltmp, exp_ee ) );
      98         483 :         exp_ee = sub( 30 - 11, exp_ee );
      99         483 :         Ltmp = Mpy_32_16( exp_ee, frac_ee, LG10 ); /* Ltmp Q14 */
     100         483 :         een = round_fx( L_shl( Ltmp, 16 - 5 ) );   /* Q14 -> Q9 */
     101         483 :         een = mac_r( C_EE_FX, een, K_EE_FX );
     102             :     }
     103             :     /* compute zero crossing rate */
     104        3100 :     pt1 = speech + sub( L_look, 1 );
     105        3100 :     tmpS = shr( *pt1, 15 ); /* sets 'tmpS to -1 if *pt1 < 0 */
     106        3100 :     Ltmp = L_deposit_l( 0 );
     107      796700 :     FOR( i = 0; i < L_FRAME; i++ )
     108             :     {
     109      793600 :         tmp16 = add( 1, tmpS );
     110      793600 :         pt1++;
     111      793600 :         tmpS = shr( *pt1, 15 ); /* pt1 >=0 ---> 0 OTHERWISE -1   */
     112      793600 :         Ltmp = L_msu0( Ltmp, tmpS, tmp16 );
     113             :     }
     114        3100 :     zc = extract_l( Ltmp );
     115             : 
     116             :     /* compute pitch stability */
     117        3100 :     pc = add( abs_s( sub( st->pitch[1], st->pitch[0] ) ), abs_s( sub( st->pitch[2], st->pitch[1] ) ) );
     118        3100 :     st->tdm_pc = pc;
     119        3100 :     move16();
     120             :     /*-----------------------------------------------------------------*
     121             :      * Transform parameters to the range <0:1>
     122             :      * Compute the merit function
     123             :      *-----------------------------------------------------------------*/
     124             : 
     125             :     /* corn = K_COR * mean_voi2 + C_COR */
     126        3100 :     Ltmp = L_mult( C_COR_FX, 32767 );
     127        3100 :     corn = round_fx( L_shl( L_mac( Ltmp, mean_voi2, K_COR_FX ), -4 ) ); /*Q13+Q13*Q15 =>Q13->Q9*/
     128             :     /* Limit [0, 1] */
     129        3100 :     corn = s_max( corn, 0 );
     130        3100 :     corn = s_min( corn, 512 );
     131             : 
     132        3100 :     Ltmp = L_mult( C_ZC_FX, 4 );                                   /*Q13*Q2 -> Q16*/
     133        3100 :     zcn = round_fx( L_shl( L_mac( Ltmp, zc, K_ZC_FX ), 16 - 7 ) ); /*Q0*Q15 + Q16*/
     134             :     /* Limit [0, 1] */
     135        3100 :     zcn = s_max( zcn, 0 );
     136        3100 :     zcn = s_min( zcn, 512 );
     137             : 
     138        3100 :     Ltmp = L_mult( C_RELE_FX, 256 );                                /*Q15*Q8 ->Q24*/
     139        3100 :     relEn = round_fx( L_shl( L_mac( Ltmp, relE, K_RELE_FX ), 1 ) ); /*relE in Q8 but relEn in Q9*/
     140             :     /* Limit [0.5, 1] */
     141        3100 :     relEn = s_max( relEn, 256 );
     142        3100 :     relEn = s_min( relEn, 512 );
     143             : 
     144        3100 :     Ltmp = L_mult( C_PC_FX, 2 );                                   /*Q14*Q1 -> Q16*/
     145        3100 :     pcn = round_fx( L_shl( L_mac( Ltmp, pc, K_PC_FX ), 16 - 7 ) ); /*Q16 + Q0*Q15*/
     146             :     /* Limit [0, 1] */
     147        3100 :     pcn = s_max( pcn, 0 );
     148        3100 :     pcn = s_min( pcn, 512 );
     149             : 
     150        3100 :     Ltmp = L_mult( een, 10923 );
     151        3100 :     Ltmp = L_mac( Ltmp, corn, 21845 );
     152        3100 :     Ltmp = L_mac( Ltmp, zcn, 10923 );
     153        3100 :     Ltmp = L_mac( Ltmp, relEn, 10923 );
     154        3100 :     Ltmp = L_mac( Ltmp, pcn, 10923 );
     155             : 
     156        3100 :     fmerit1 = round_fx_o( L_shl_o( Ltmp, 16 - 10 - 1, &Overflow ), &Overflow ); /* fmerit1 ->Q15 */
     157             : 
     158             :     /*-----------------------------------------------------------------*
     159             :      * FEC classification
     160             :      *-----------------------------------------------------------------*/
     161             : 
     162        3100 :     st->fmerit_dt = sub( st->prev_fmerit, fmerit1 ); /*Q15*/
     163        3100 :     move16();
     164        3100 :     st->prev_fmerit = fmerit1;
     165        3100 :     move16();
     166             : 
     167             :     /* FEC classification */
     168        3100 :     test();
     169        3100 :     test();
     170        3100 :     IF( st->localVAD == 0 || EQ_16( st->coder_type, UNVOICED ) || LT_16( relE, -1536 ) )
     171             :     {
     172        1404 :         clas = UNVOICED_CLAS;
     173        1404 :         *clas_mod = clas;
     174        1404 :         move16();
     175        1404 :         move16();
     176             :     }
     177             :     ELSE
     178             :     {
     179        1696 :         SWITCH( st->last_clas )
     180             :         {
     181        1431 :             case VOICED_CLAS:
     182             :             case ONSET:
     183             :             case VOICED_TRANSITION:
     184             : 
     185        1431 :                 IF( LT_16( fmerit1, 16056 ) ) /*0.49f*/
     186             :                 {
     187          24 :                     clas = UNVOICED_CLAS;
     188          24 :                     move16();
     189             :                 }
     190        1407 :                 ELSE IF( LT_16( fmerit1, 21626 ) ) /*0.66*/
     191             :                 {
     192         126 :                     clas = VOICED_TRANSITION;
     193         126 :                     move16();
     194             :                 }
     195             :                 ELSE
     196             :                 {
     197        1281 :                     clas = VOICED_CLAS;
     198        1281 :                     move16();
     199             :                 }
     200        1431 :                 IF( LT_16( fmerit1, 14745 /* 0.45f*/ ) )
     201             :                 {
     202          18 :                     *clas_mod = UNVOICED_CLAS;
     203          18 :                     move16();
     204             :                 }
     205        1413 :                 ELSE IF( LT_16( fmerit1, 21626 /* 0.66f*/ ) )
     206             :                 {
     207         132 :                     *clas_mod = VOICED_TRANSITION;
     208         132 :                     move16();
     209             :                 }
     210             :                 ELSE
     211             :                 {
     212        1281 :                     *clas_mod = VOICED_CLAS;
     213        1281 :                     move16();
     214             :                 }
     215        1431 :                 BREAK;
     216             : 
     217         265 :             case UNVOICED_CLAS:
     218             :             case UNVOICED_TRANSITION:
     219         265 :                 IF( GT_16( fmerit1, 20643 ) ) /*0.63*/
     220             :                 {
     221         131 :                     clas = ONSET;
     222         131 :                     move16();
     223             :                 }
     224         134 :                 ELSE IF( GT_16( fmerit1, 19169 ) ) /*0.585*/
     225             :                 {
     226          40 :                     clas = UNVOICED_TRANSITION;
     227          40 :                     move16();
     228             :                 }
     229             :                 ELSE
     230             :                 {
     231          94 :                     clas = UNVOICED_CLAS;
     232          94 :                     move16();
     233             :                 }
     234         265 :                 *clas_mod = clas;
     235         265 :                 move16();
     236             : 
     237         265 :                 BREAK;
     238             : 
     239           0 :             default:
     240           0 :                 clas = UNVOICED_CLAS;
     241           0 :                 *clas_mod = clas;
     242           0 :                 move16();
     243           0 :                 move16();
     244           0 :                 BREAK;
     245             :         }
     246             :     }
     247             :     /* Onset classification */
     248             : 
     249             :     /* tc_cnt == -1: frame after TC frame in continuous block of GC/VC frames */
     250             :     /* tc_cnt ==  0: UC frame */
     251             :     /* tc_cnt ==  1: onset/transition frame, coded by GC coder type */
     252             :     /* tc_cnt ==  2: frame after onset/transition frame, coded by TC coder type */
     253             : 
     254        3100 :     if ( clas == 0 )
     255             :     {
     256        1522 :         st->tc_cnt = 0;
     257        1522 :         move16();
     258             :     }
     259             : 
     260        3100 :     test();
     261        3100 :     IF( GE_16( clas, VOICED_TRANSITION ) && st->tc_cnt >= 0 )
     262             :     {
     263         376 :         st->tc_cnt = add( st->tc_cnt, 1 );
     264         376 :         move16();
     265             :     }
     266             : 
     267        3100 :     if ( GT_16( st->tc_cnt, 2 ) )
     268             :     {
     269         122 :         st->tc_cnt = -1;
     270         122 :         move16();
     271             :     }
     272        3100 :     return clas;
     273             : }
     274             : 
     275     1111194 : Word16 signal_clas_ivas_fx(                       /* o  : classification for current frames              */
     276             :                             Encoder_State *st,    /* i/o: encoder state structure                           */
     277             :                             const Word16 *speech, /* i  : pointer to speech signal for E computation in Qx */
     278             :                             const Word32 *ee,     /* i  : lf/hf E ration for 2 half-frames in Q6            */
     279             :                             const Word16 relE,    /* i  : frame relative E to the long term average in Q8   */
     280             :                             const Word16 L_look,  /* i  : look-ahead                                        */
     281             :                             Word16 *clas_mod      /* o  : class flag for NOOP detection                     */
     282             : )
     283             : {
     284             :     Word32 Ltmp;
     285             :     Word16 mean_voi2, een, corn, zcn, relEn, pcn, fmerit1;
     286             :     Word16 i, clas, pc, zc, exp_ee;
     287             :     Word16 tmp16, tmpS;
     288             :     const Word16 *pt1;
     289             :     Word64 tmp64;
     290             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     291     1111194 :     Flag Overflow = 0;
     292     1111194 :     move32();
     293             : #endif
     294             : 
     295             :     /*----------------------------------------------------------------*
     296             :      * Calculate average voicing
     297             :      * Calculate average spectral tilt
     298             :      * Calculate zero-crossing rate
     299             :      * Calculate pitch stability
     300             :      *----------------------------------------------------------------*/
     301             : 
     302             :     /* average voicing on second half-frame and look-ahead */
     303     1111194 :     Ltmp = L_mult( st->voicing_fx[1], 16384 ); /* Q15*Q14->Q30 */
     304     1111194 :     mean_voi2 = mac_r( Ltmp, st->voicing_fx[2], 16384 );
     305             : 
     306             :     /* average spectral tilt in dB */
     307     1111194 :     tmp64 = W_mult0_32_32( ee[0], ee[1] );
     308     1111194 :     exp_ee = W_norm( tmp64 );
     309     1111194 :     Ltmp = W_extract_h( W_shl( tmp64, exp_ee ) ); // Q = Q6+Q6 + exp_ee - 32
     310     1111194 :     exp_ee = sub( 31, sub( add( Q12, exp_ee ), 32 ) );
     311     1111194 :     IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( Ltmp, exp_ee, ONE_IN_Q31, 0 ), -1 ) )
     312             :     {
     313      106431 :         een = 0;
     314      106431 :         move16();
     315             :     }
     316             :     ELSE
     317             :     {
     318             :         /* mean_ee2 = 0.5f * 20.0f * (float)log10( tmp ); */
     319             :         /* een = K_EE_ENC * mean_ee2 + C_EE_ENC; */
     320     1004763 :         Ltmp = BASOP_Util_Log10( Ltmp, exp_ee );                            // Q25
     321     1004763 :         Ltmp = Mpy_32_32( Ltmp, 671088640 /*20.f in Q25*/ );                // Q25 + Q25 -Q31 = Q19 * 0.5 = Q20
     322     1004763 :         een = extract_l( L_shl( Mpy_32_16_1( Ltmp, K_EE_FX ), Q9 - Q20 ) ); // Q9
     323             : 
     324     1004763 :         IF( GT_16( een, 512 ) )
     325             :         {
     326      711865 :             een = 512;
     327      711865 :             move16();
     328             :         }
     329      292898 :         ELSE IF( een < 0 )
     330             :         {
     331           0 :             een = 0;
     332           0 :             move16();
     333             :         }
     334             :     }
     335             :     /* compute zero crossing rate */
     336     1111194 :     pt1 = speech + sub( L_look, 1 );
     337     1111194 :     tmpS = shr( *pt1, 15 ); /* sets 'tmpS to -1 if *pt1 < 0 */
     338     1111194 :     Ltmp = L_deposit_l( 0 );
     339   285576858 :     FOR( i = 0; i < L_FRAME; i++ )
     340             :     {
     341   284465664 :         tmp16 = add( 1, tmpS );
     342   284465664 :         pt1++;
     343   284465664 :         tmpS = shr( *pt1, 15 ); /* pt1 >=0 ---> 0 OTHERWISE -1   */
     344   284465664 :         Ltmp = L_msu0( Ltmp, tmpS, tmp16 );
     345             :     }
     346     1111194 :     zc = extract_l( Ltmp );
     347             : 
     348             :     /* compute pitch stability */
     349     1111194 :     pc = add( abs_s( sub( st->pitch[1], st->pitch[0] ) ), abs_s( sub( st->pitch[2], st->pitch[1] ) ) );
     350     1111194 :     st->tdm_pc = pc;
     351     1111194 :     move16();
     352             :     /*-----------------------------------------------------------------*
     353             :      * Transform parameters to the range <0:1>
     354             :      * Compute the merit function
     355             :      *-----------------------------------------------------------------*/
     356             : 
     357             :     /* corn = K_COR * mean_voi2 + C_COR */
     358     1111194 :     Ltmp = L_mult( C_COR_FX, 32767 );
     359     1111194 :     corn = round_fx( L_shl( L_mac( Ltmp, mean_voi2, K_COR_FX ), -4 ) ); /*Q13+Q13*Q15 =>Q13->Q9*/
     360             :     /* Limit [0, 1] */
     361     1111194 :     corn = s_max( corn, 0 );
     362     1111194 :     corn = s_min( corn, 512 );
     363             : 
     364     1111194 :     Ltmp = L_mult( C_ZC_FX, 4 );                                   /*Q13*Q2 -> Q16*/
     365     1111194 :     zcn = round_fx( L_shl( L_mac( Ltmp, zc, K_ZC_FX ), 16 - 7 ) ); /*Q0*Q15 + Q16*/
     366             :     /* Limit [0, 1] */
     367     1111194 :     zcn = s_max( zcn, 0 );
     368     1111194 :     zcn = s_min( zcn, 512 );
     369             : 
     370     1111194 :     Ltmp = L_mult( C_RELE_FX, 256 );                                /*Q15*Q8 ->Q24*/
     371     1111194 :     relEn = round_fx( L_shl( L_mac( Ltmp, relE, K_RELE_FX ), 1 ) ); /*relE in Q8 but relEn in Q9*/
     372             :     /* Limit [0.5, 1] */
     373     1111194 :     relEn = s_max( relEn, 256 );
     374     1111194 :     relEn = s_min( relEn, 512 );
     375             : 
     376     1111194 :     Ltmp = L_mult( C_PC_FX, 2 );                                   /*Q14*Q1 -> Q16*/
     377     1111194 :     pcn = round_fx( L_shl( L_mac( Ltmp, pc, K_PC_FX ), 16 - 7 ) ); /*Q16 + Q0*Q15*/
     378             :     /* Limit [0, 1] */
     379     1111194 :     pcn = s_max( pcn, 0 );
     380     1111194 :     pcn = s_min( pcn, 512 );
     381             : 
     382     1111194 :     Ltmp = L_mult( een, 10923 );
     383     1111194 :     Ltmp = L_mac( Ltmp, corn, 21845 );
     384     1111194 :     Ltmp = L_mac( Ltmp, zcn, 10923 );
     385     1111194 :     Ltmp = L_mac( Ltmp, relEn, 10923 );
     386     1111194 :     Ltmp = L_mac( Ltmp, pcn, 10923 );
     387             : 
     388     1111194 :     fmerit1 = round_fx_o( L_shl_o( Ltmp, 16 - 10 - 1, &Overflow ), &Overflow ); /* fmerit1 ->Q15 */
     389             : 
     390             :     /*-----------------------------------------------------------------*
     391             :      * FEC classification
     392             :      *-----------------------------------------------------------------*/
     393             : 
     394     1111194 :     st->fmerit_dt = sub( st->prev_fmerit, fmerit1 ); /*Q15*/
     395     1111194 :     move16();
     396     1111194 :     st->prev_fmerit = fmerit1;
     397     1111194 :     move16();
     398             : 
     399             :     /* FEC classification */
     400     1111194 :     test();
     401     1111194 :     test();
     402     1111194 :     IF( st->localVAD == 0 || EQ_16( st->coder_type, UNVOICED ) || LT_16( relE, -1536 ) )
     403             :     {
     404      535307 :         clas = UNVOICED_CLAS;
     405      535307 :         *clas_mod = clas;
     406      535307 :         move16();
     407      535307 :         move16();
     408             :     }
     409             :     ELSE
     410             :     {
     411      575887 :         SWITCH( st->last_clas )
     412             :         {
     413      437850 :             case VOICED_CLAS:
     414             :             case ONSET:
     415             :             case VOICED_TRANSITION:
     416             : 
     417      437850 :                 IF( LT_16( fmerit1, 16056 ) ) /*0.49f*/
     418             :                 {
     419       20141 :                     clas = UNVOICED_CLAS;
     420       20141 :                     move16();
     421             :                 }
     422      417709 :                 ELSE IF( LT_16( fmerit1, 21626 ) ) /*0.66*/
     423             :                 {
     424       53557 :                     clas = VOICED_TRANSITION;
     425       53557 :                     move16();
     426             :                 }
     427             :                 ELSE
     428             :                 {
     429      364152 :                     clas = VOICED_CLAS;
     430      364152 :                     move16();
     431             :                 }
     432      437850 :                 IF( LT_16( fmerit1, 14745 /* 0.45f*/ ) )
     433             :                 {
     434       12824 :                     *clas_mod = UNVOICED_CLAS;
     435       12824 :                     move16();
     436             :                 }
     437      425026 :                 ELSE IF( LT_16( fmerit1, 21626 /* 0.66f*/ ) )
     438             :                 {
     439       60874 :                     *clas_mod = VOICED_TRANSITION;
     440       60874 :                     move16();
     441             :                 }
     442             :                 ELSE
     443             :                 {
     444      364152 :                     *clas_mod = VOICED_CLAS;
     445      364152 :                     move16();
     446             :                 }
     447      437850 :                 BREAK;
     448             : 
     449      138037 :             case UNVOICED_CLAS:
     450             :             case UNVOICED_TRANSITION:
     451      138037 :                 IF( GT_16( fmerit1, 20643 ) ) /*0.63*/
     452             :                 {
     453       55827 :                     clas = ONSET;
     454       55827 :                     move16();
     455             :                 }
     456       82210 :                 ELSE IF( GT_16( fmerit1, 19169 ) ) /*0.585*/
     457             :                 {
     458       11661 :                     clas = UNVOICED_TRANSITION;
     459       11661 :                     move16();
     460             :                 }
     461             :                 ELSE
     462             :                 {
     463       70549 :                     clas = UNVOICED_CLAS;
     464       70549 :                     move16();
     465             :                 }
     466      138037 :                 *clas_mod = clas;
     467      138037 :                 move16();
     468             : 
     469      138037 :                 BREAK;
     470             : 
     471           0 :             default:
     472           0 :                 clas = UNVOICED_CLAS;
     473           0 :                 *clas_mod = clas;
     474           0 :                 move16();
     475           0 :                 move16();
     476           0 :                 BREAK;
     477             :         }
     478             :     }
     479             :     /* Onset classification */
     480             : 
     481             :     /* tc_cnt == -1: frame after TC frame in continuous block of GC/VC frames */
     482             :     /* tc_cnt ==  0: UC frame */
     483             :     /* tc_cnt ==  1: onset/transition frame, coded by GC coder type */
     484             :     /* tc_cnt ==  2: frame after onset/transition frame, coded by TC coder type */
     485             : 
     486     1111194 :     if ( clas == 0 )
     487             :     {
     488      625997 :         st->tc_cnt = 0;
     489      625997 :         move16();
     490             :     }
     491             : 
     492     1111194 :     test();
     493     1111194 :     IF( GE_16( clas, VOICED_TRANSITION ) && st->tc_cnt >= 0 )
     494             :     {
     495      138978 :         st->tc_cnt = add( st->tc_cnt, 1 );
     496      138978 :         move16();
     497             :     }
     498             : 
     499     1111194 :     if ( GT_16( st->tc_cnt, 2 ) )
     500             :     {
     501       38232 :         st->tc_cnt = -1;
     502       38232 :         move16();
     503             :     }
     504     1111194 :     return clas;
     505             : }
     506             : 
     507             : /*-------------------------------------------------------------------*
     508             :  * select_TC_fx()
     509             :  *
     510             :  * Select TC coder type for appropriate frames which is in general VOICED_TRANSITION,
     511             :  * VOICED_CLAS or ONSET frames following UNVOICED_CLAS frames
     512             :  *-------------------------------------------------------------------*/
     513             : 
     514     1114294 : void select_TC_fx(
     515             :     const Word16 codec_mode, /* i  : codec mode                      */
     516             :     const Word16 tc_cnt,     /* i  : TC frame counter                */
     517             :     Word16 *coder_type,      /* i/o: coder type                      */
     518             :     const Word16 localVAD    /* i  : VAD without hangover            */
     519             : )
     520             : {
     521     1114294 :     IF( EQ_16( codec_mode, MODE1 ) )
     522             :     {
     523             :         /*---------------------------------------------------------------------*
     524             :          * Select TC coder type for appropriate frames which is in general VOICED_TRANSITION,
     525             :          * VOICED_CLAS or ONSET frames following UNVOICED_CLAS frames
     526             :          *---------------------------------------------------------------------*/
     527     1113244 :         test();
     528     1113244 :         IF( localVAD != 0 && GE_16( tc_cnt, 1 ) )
     529             :         {
     530      100916 :             IF( EQ_16( tc_cnt, 1 ) )
     531             :             {
     532             :                 /* onset/transition frame is always coded using GC coder type */
     533       55918 :                 *coder_type = GENERIC;
     534       55918 :                 move16();
     535             :             }
     536             :             ELSE
     537             :             {
     538             :                 /* frame after onset/transition frame is coded by TC coder type */
     539       44998 :                 *coder_type = TRANSITION;
     540       44998 :                 move16();
     541             :             }
     542             :         }
     543             :     }
     544             : 
     545     1114294 :     return;
     546             : }
     547             : 
     548             : /*-------------------------------------------------------------------*
     549             :  * coder_type_modif_fx()
     550             :  *
     551             :  * Coder type modification
     552             :  *-------------------------------------------------------------------*/
     553             : 
     554        3100 : void coder_type_modif_fx(
     555             :     Encoder_State *st, /* i/o: encoder state structure                     */
     556             :     const Word16 relE  /* i  : frame relative E to the long term average Q8*/
     557             : )
     558             : {
     559             :     Word16 unmod_coder_type, vbr_generic_ho;
     560             : 
     561        3100 :     SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR;
     562             : 
     563             : 
     564        3100 :     IF( st->Opt_SC_VBR )
     565             :     {
     566           0 :         vbr_generic_ho = hSC_VBR->vbr_generic_ho;
     567           0 :         move16();
     568             :     }
     569             :     ELSE
     570             :     {
     571        3100 :         vbr_generic_ho = -1;
     572        3100 :         move16();
     573             :     }
     574             : 
     575        3100 :     IF( EQ_16( st->codec_mode, MODE1 ) )
     576             :     {
     577             :         /*---------------------------------------------------------------------*
     578             :          * Coder type modification
     579             :          *
     580             :          * Prevent UC coder type in certain conditions
     581             :          * Prevent VC coder type in certain conditions
     582             :          * Select TC coder type in appropriate frames
     583             :          *---------------------------------------------------------------------*/
     584             : 
     585             :         /* At higher rates, use GC coding instead of UC coding to improve quality */
     586        2050 :         test();
     587        2050 :         test();
     588        2050 :         test();
     589        2050 :         test();
     590        2050 :         test();
     591        2050 :         if ( ( st->element_mode == 0 && GT_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) ) ||
     592        1960 :              ( st->element_mode > 0 && GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) )
     593             :         {
     594          90 :             st->coder_type = GENERIC;
     595          90 :             move16();
     596             :         }
     597             : 
     598             :         /* Prevent UC coding on mixed content at 9.6 kb/s */
     599        2050 :         test();
     600        2050 :         test();
     601        2050 :         if ( GE_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) && st->audio_frame_cnt != 0 )
     602             :         {
     603           0 :             st->coder_type = GENERIC;
     604           0 :             move16();
     605             :         }
     606             : 
     607        2050 :         unmod_coder_type = st->coder_type;
     608        2050 :         move16();
     609             : 
     610             :         /* Enforce GC coder type on inactive signal (this can be later overwritten to INACTIVE) */
     611        2050 :         test();
     612        2050 :         test();
     613        2050 :         test();
     614        2050 :         test();
     615        2050 :         test();
     616        2050 :         test();
     617        2050 :         test();
     618        2109 :         if ( st->localVAD == 0 && ( (
     619         118 :                                         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 ) ) ) ) ||
     620         118 :                                     EQ_16( st->coder_type, TRANSITION ) || EQ_16( st->coder_type, VOICED ) )
     621             : 
     622             :         )
     623             :         {
     624           0 :             st->coder_type = GENERIC;
     625           0 :             move16();
     626             :         }
     627             : 
     628        2050 :         test();
     629        2050 :         test();
     630        2050 :         IF( EQ_16( st->Opt_SC_VBR, 1 ) )
     631             :         {
     632           0 :             test();
     633           0 :             if ( EQ_16( st->coder_type, GENERIC ) && EQ_16( unmod_coder_type, UNVOICED ) )
     634             :             {
     635           0 :                 hSC_VBR->vbr_generic_ho = 1;
     636           0 :                 move16();
     637             :             }
     638             : 
     639           0 :             if ( GT_16( st->coder_type, UNVOICED ) )
     640             :             {
     641           0 :                 hSC_VBR->vbr_generic_ho = 0;
     642           0 :                 move16();
     643             :             }
     644             :         } //_DIFF_FLOAT_FIX_ see below
     645             :           // PMT("Verify if EVS or IVAS is right about last_7k2_coder_type update")
     646        2050 :         hSC_VBR->last_7k2_coder_type = st->coder_type;
     647        2050 :         move16();
     648        2050 :         test();
     649        2050 :         if ( st->localVAD == 0 && EQ_16( st->coder_type, UNVOICED ) )
     650             :         {
     651           0 :             hSC_VBR->last_7k2_coder_type = GENERIC;
     652           0 :             move16();
     653             :         }
     654             :         //}  closing bracket here in IVAS float, but not in EVS float. currently affects BE for switching bitrate on Linux 20220929 _DIFF_FLOAT_FIX_ !!
     655             : 
     656        2050 :         IF( st->element_mode == 0 )
     657             :         {
     658             :             /* At higher rates and with 16kHz core, allow only GC and TC coder type */
     659        2050 :             test();
     660        2050 :             test();
     661             :             // test();
     662        2050 :             if ( GT_32( st->total_brate, ACELP_16k40 ) && NE_16( st->coder_type, GENERIC ) && NE_16( st->coder_type, TRANSITION ) )
     663             :             {
     664             :                 /* onset/transition frame is always coded using GC mode */
     665         556 :                 st->coder_type = GENERIC;
     666         556 :                 move16();
     667             :             }
     668             :         }
     669             :         ELSE /*IVAS*/
     670             :         {
     671             :             /* At higher bitrates, disable UC and VC coder type; note that IC coder type is classified later */
     672           0 :             test();
     673           0 :             test();
     674           0 :             test();
     675           0 :             if ( ( GT_32( st->total_brate, MAX_VOICED_BRATE ) && EQ_16( st->coder_type, VOICED ) ) ||
     676           0 :                  ( GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) )
     677             :             {
     678           0 :                 st->coder_type = GENERIC;
     679           0 :                 move16();
     680             :             }
     681             :         }
     682             : 
     683             :         /* Patch for certain low-level signals for which the gain quantizer sometimes goes out of its dynamic range */
     684        2050 :         test();
     685        2050 :         test();
     686        2050 :         test();
     687        2050 :         if ( EQ_16( st->coder_type, VOICED ) && st->input_bwidth == 0 && LT_16( relE, -2560 ) && LE_32( st->total_brate, ACELP_8k00 ) )
     688             :         {
     689           0 :             st->coder_type = GENERIC;
     690           0 :             move16();
     691             :         }
     692             :     }
     693             : 
     694        3100 :     return;
     695             : }
     696     1107383 : void coder_type_modif_ivas_fx(
     697             :     Encoder_State *st, /* i/o: encoder state structure                     */
     698             :     const Word16 relE  /* i  : frame relative E to the long term average   */
     699             : )
     700             : {
     701             :     Word16 unmod_coder_type, vbr_generic_ho;
     702             : 
     703     1107383 :     SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR;
     704             : 
     705             : 
     706     1107383 :     IF( st->Opt_SC_VBR )
     707             :     {
     708           0 :         vbr_generic_ho = hSC_VBR->vbr_generic_ho;
     709           0 :         move16();
     710             :     }
     711             :     ELSE
     712             :     {
     713     1107383 :         vbr_generic_ho = -1;
     714     1107383 :         move16();
     715             :     }
     716             : 
     717     1107383 :     IF( EQ_16( st->codec_mode, MODE1 ) )
     718             :     {
     719             :         /*---------------------------------------------------------------------*
     720             :          * Coder type modification
     721             :          *
     722             :          * Prevent UC coder type in certain conditions
     723             :          * Prevent VC coder type in certain conditions
     724             :          * Select TC coder type in appropriate frames
     725             :          *---------------------------------------------------------------------*/
     726             : 
     727             :         /* At higher rates, use GC coding instead of UC coding to improve quality */
     728     1107383 :         test();
     729     1107383 :         test();
     730     1107383 :         test();
     731     1107383 :         test();
     732     1107383 :         test();
     733     1107383 :         if ( ( st->element_mode == 0 && GT_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) ) ||
     734     1107383 :              ( st->element_mode > 0 && GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) )
     735             :         {
     736       67289 :             st->coder_type = GENERIC;
     737       67289 :             move16();
     738             :         }
     739             : 
     740             :         /* Prevent UC coding on mixed content at 9.6 kb/s */
     741     1107383 :         test();
     742     1107383 :         test();
     743     1107383 :         if ( GE_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) && st->audio_frame_cnt != 0 )
     744             :         {
     745        2271 :             st->coder_type = GENERIC;
     746        2271 :             move16();
     747             :         }
     748             : 
     749     1107383 :         unmod_coder_type = st->coder_type;
     750     1107383 :         move16();
     751             : 
     752             :         /* Enforce GC coder type on inactive signal (this can be later overwritten to INACTIVE) */
     753     1107383 :         test();
     754     1107383 :         test();
     755     1107383 :         test();
     756     1107383 :         test();
     757     1107383 :         test();
     758     1107383 :         test();
     759     1107383 :         test();
     760     1274582 :         if ( st->localVAD == 0 && ( (
     761      334398 :                                         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 ) ) ) ) ||
     762      333348 :                                     EQ_16( st->coder_type, TRANSITION ) || EQ_16( st->coder_type, VOICED ) )
     763             : 
     764             :         )
     765             :         {
     766         525 :             st->coder_type = GENERIC;
     767         525 :             move16();
     768             :         }
     769             : 
     770     1107383 :         if ( EQ_16( st->Opt_SC_VBR, 1 ) )
     771             :         {
     772           0 :             test();
     773           0 :             if ( EQ_16( st->coder_type, GENERIC ) && EQ_16( unmod_coder_type, UNVOICED ) )
     774             :             {
     775           0 :                 hSC_VBR->vbr_generic_ho = 1;
     776           0 :                 move16();
     777             :             }
     778             : 
     779           0 :             if ( GT_16( st->coder_type, UNVOICED ) )
     780             :             {
     781           0 :                 hSC_VBR->vbr_generic_ho = 0;
     782           0 :                 move16();
     783             :             }
     784             : 
     785           0 :             hSC_VBR->last_7k2_coder_type = st->coder_type;
     786           0 :             move16();
     787           0 :             test();
     788           0 :             if ( st->localVAD == 0 && EQ_16( st->coder_type, UNVOICED ) )
     789             :             {
     790           0 :                 hSC_VBR->last_7k2_coder_type = GENERIC;
     791           0 :                 move16();
     792             :             }
     793             :         }
     794             : 
     795     1107383 :         IF( st->element_mode == 0 )
     796             :         {
     797             :             /* At higher rates and with 16kHz core, allow only GC and TC coder type */
     798           0 :             test();
     799           0 :             test();
     800           0 :             if ( GT_32( st->total_brate, ACELP_16k40 ) && NE_16( st->coder_type, GENERIC ) && NE_16( st->coder_type, TRANSITION ) )
     801             :             {
     802             :                 /* onset/transition frame is always coded using GC mode */
     803           0 :                 st->coder_type = GENERIC;
     804           0 :                 move16();
     805             :             }
     806             :         }
     807             :         ELSE /*IVAS*/
     808             :         {
     809             :             /* At higher bitrates, disable UC and VC coder type; note that IC coder type is classified later */
     810     1107383 :             test();
     811     1107383 :             test();
     812     1107383 :             test();
     813     1902488 :             if ( ( GT_32( st->total_brate, MAX_VOICED_BRATE ) && EQ_16( st->coder_type, VOICED ) ) ||
     814     1494018 :                  ( GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) )
     815             :             {
     816      312278 :                 st->coder_type = GENERIC;
     817      312278 :                 move16();
     818             :             }
     819             :         }
     820             : 
     821             :         /* Patch for certain low-level signals for which the gain quantizer sometimes goes out of its dynamic range */
     822     1107383 :         test();
     823     1107383 :         test();
     824     1107383 :         test();
     825     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 ) )
     826             :         {
     827           0 :             st->coder_type = GENERIC;
     828           0 :             move16();
     829             :         }
     830             :     }
     831             : 
     832     1107383 :     return;
     833             : }

Generated by: LCOV version 1.14