LCOV - code coverage report
Current view: top level - lib_enc - vad_param_updt_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ cede165d26d1b794bfc5f5f6f9ec19d4d64a9a3b Lines: 81 87 93.1 %
Date: 2025-11-01 03:16:20 Functions: 1 1 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 <stdlib.h>
       7             : #include "options.h"       /* Compilation switches                   */
       8             : #include "cnst.h"          /* Common constants                       */
       9             : #include "ivas_stat_enc.h" /* Function prototypes                    */
      10             : #include "prot_fx.h"       /* Function prototypes                    */
      11             : #include "prot_fx_enc.h"   /* Function prototypes                    */
      12             : 
      13             : /*-------------------------------------------------------------------*
      14             :  * vad_param_updt()
      15             :  *
      16             :  * Update parameters used by VAD
      17             :  *--------------------------------------------------------------------*/
      18             : 
      19     1189822 : void vad_param_updt_fx(
      20             :     Encoder_State *st_fx,             /* i/o: state structure                        */
      21             :     const Word16 old_pitch1,          /* i  : OL pitch value from last frame      Q0 */
      22             :     const Word16 corr_shift,          /* i  : correlation shift                   Q15*/
      23             :     const Word16 corr_shiftR,         /* i  : correlation shift                   Q15 */
      24             :     const Word16 Az[],                /* i:  a coeffs                             Q12 */
      25             :     FRONT_VAD_ENC_HANDLE hFrontVad[], /* i/o: front-VAD handles                     */
      26             :     const Word16 n_channels           /* i  : number of channels                    */
      27             : )
      28             : {
      29             :     Word16 voice_tmp, pitch_tmp;
      30             :     Word32 L_tmp;
      31             :     Word16 refl[M + 1];
      32             :     Word16 tmp1, tmp2;
      33             :     Word16 tmp_active_flag;
      34             :     Word16 i, ini_frame, corr_shift_temp[2];
      35             :     VAD_HANDLE hVAD;
      36     1189822 :     DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc;
      37             : 
      38     1189822 :     corr_shift_temp[0] = corr_shift;  /*Q15*/
      39     1189822 :     corr_shift_temp[1] = corr_shiftR; /*Q15*/
      40     1189822 :     move16();
      41     1189822 :     move16();
      42             : 
      43     1189822 :     hVAD = st_fx->hVAD;
      44     1189822 :     ini_frame = st_fx->ini_frame;
      45     1189822 :     move16();
      46             : 
      47     1189822 :     IF( hFrontVad != NULL )
      48             :     {
      49       49758 :         hVAD = hFrontVad[0]->hVAD;
      50       49758 :         ini_frame = hFrontVad[0]->ini_frame;
      51       49758 :         move16();
      52             :     }
      53     2411612 :     FOR( i = 0; i < n_channels; i++ )
      54             :     {
      55     1221790 :         if ( EQ_16( i, 1 ) )
      56             :         {
      57       31968 :             hVAD = hFrontVad[1]->hVAD;
      58             :         }
      59     1221790 :         IF( !st_fx->Opt_AMR_WB )
      60             :         {
      61             :             /* fix explanation, after function dtx_fx,  the "vad_flag"  parameter can not be used for SID scheduling purposes any longer
      62             :                as  dtx_fx  can  schedules active  frames even if the initial analyzed  vad_flag is  0  )
      63             :                in the worst case without the fix an active frame could be classified as SID frame,   quite/very  unlikley though
      64             :              */
      65     1221790 :             tmp_active_flag = 0;
      66     1221790 :             move16();
      67     1221790 :             test();
      68     1221790 :             if ( ( NE_32( st_fx->core_brate, (Word32) SID_2k40 ) ) && ( st_fx->core_brate != 0 ) ) /* Note,  core_brate_fx can be -1 */
      69             :             {
      70     1170462 :                 tmp_active_flag = 1;
      71     1170462 :                 move16(); /* reqires active coding according  to dtx_fx logic  */
      72             :             }
      73     1221790 :             test();
      74     1221790 :             test();
      75     1221790 :             IF( ( st_fx->Opt_DTX_ON != 0 ) && ( tmp_active_flag == 0 ) && ( GT_16( ini_frame, 3 ) ) )
      76             : 
      77             : 
      78             :             {
      79             :                 /* update the counter of consecutive inactive frames in DTX */
      80       51222 :                 hVAD->consec_inactive = add( hVAD->consec_inactive, 1 );
      81       51222 :                 move16();
      82       51222 :                 if ( GT_16( hVAD->consec_inactive, 5 ) )
      83             :                 {
      84       43247 :                     hVAD->consec_inactive = 5;
      85       43247 :                     move16();
      86             :                 }
      87             : 
      88       51222 :                 IF( EQ_16( hVAD->consec_inactive, 5 ) )
      89             :                 {
      90             :                     /* compute spectral tilt parameter */
      91       44549 :                     a2rc_fx( &Az[1], refl, M ); /* cast to kill MSVC warning */
      92             :                     /* i: Az   in Q12 */
      93             :                     /* o: refl in Q15 */
      94             : 
      95       44549 :                     IF( EQ_16( hVAD->spectral_tilt_reset, 1 ) )
      96             :                     {
      97         551 :                         hVAD->spectral_tilt_reset = 0;
      98         551 :                         move16();
      99         551 :                         hVAD->running_avg_fx = refl[0];
     100         551 :                         move16(); /*Q15*/
     101         551 :                         hVAD->ra_deltasum_fx = 0;
     102         551 :                         move16(); /*Q15*/
     103             :                     }
     104             : 
     105             :                     /* st_fx->ra_deltasum_fx += (0.80f * st_fx->running_avg_fx + 0.20f * refl[0]) - st_fx->running_avg_fx;
     106             :                        st_fx->running_avg_fx = 0.80f * st_fx->running_avg_fx + 0.20f * refl[0]; */
     107       44549 :                     tmp1 = mult( 6553, hVAD->running_avg_fx ); /* = -0.80f * st_fx->running_avg_fx + st_fx->running_avg_fx*/
     108       44549 :                     tmp2 = mult( 6553, refl[0] );
     109       44549 :                     hVAD->ra_deltasum_fx = add( hVAD->ra_deltasum_fx, sub( tmp2, tmp1 ) );
     110       44549 :                     move16();
     111             : 
     112       44549 :                     tmp1 = mult( 26214, hVAD->running_avg_fx ); /* (0.8 in Q15 * Q15) = Q(30 - 15)*/
     113       44549 :                     hVAD->running_avg_fx = add( tmp1, tmp2 );
     114       44549 :                     move16();
     115             : 
     116       44549 :                     IF( GT_16( abs_s( hVAD->ra_deltasum_fx ), 6553 ) ) /*0.2 in Q15*/
     117             :                     {
     118         240 :                         hVAD->spectral_tilt_reset = 1;
     119         240 :                         move16();
     120         240 :                         hVAD->running_avg_fx = 0;
     121         240 :                         move16();
     122         240 :                         hVAD->ra_deltasum_fx = 0;
     123         240 :                         move16();
     124         240 :                         hVAD->trigger_SID = 1;
     125         240 :                         move16();
     126             :                     }
     127             :                 }
     128             :             }
     129             :             ELSE
     130             :             {
     131     1170568 :                 hVAD->trigger_SID = 0;
     132     1170568 :                 move16();
     133     1170568 :                 hVAD->consec_inactive = 0;
     134     1170568 :                 move16();
     135             :             }
     136             : 
     137     1221790 :             IF( EQ_16( hVAD->trigger_SID, 1 ) )
     138             :             {
     139         844 :                 IF( GE_16( hDtxEnc->cng_cnt, 8 ) )
     140             :                 {
     141             :                     /* Declare SID frame due to spectral tilt changes */
     142           0 :                     hDtxEnc->cnt_SID = 1;
     143           0 :                     move16();
     144           0 :                     st_fx->core_brate = SID_2k40;
     145           0 :                     move32();
     146           0 :                     hVAD->trigger_SID = 0;
     147           0 :                     move16();
     148             :                 }
     149         844 :                 ELSE IF( EQ_32( st_fx->core_brate, SID_2k40 ) )
     150             :                 {
     151             :                     /* SID fame has already been declared before */
     152         220 :                     hVAD->trigger_SID = 0;
     153         220 :                     move16();
     154             :                 }
     155             :             }
     156             :         }
     157             : 
     158             :         /* (voicing[0] + voicing[1] + voicing[2]) / 3  + corr_shift */
     159     1221790 :         L_tmp = L_mult( st_fx->voicing_fx[0], 10923 );
     160     1221790 :         L_tmp = L_mac( L_tmp, st_fx->voicing_fx[1], 10923 );
     161     1221790 :         L_tmp = L_mac( L_tmp, st_fx->voicing_fx[2], 10923 );   /*Q15 */
     162     1221790 :         L_tmp = L_mac_sat( L_tmp, corr_shift_temp[i], 32767 ); /*Q15 */
     163     1221790 :         voice_tmp = round_fx_sat( L_tmp );                     /*Q15 */
     164             : 
     165             :         /* abs(pitch[0] - *pitO) + abs(pitch[1] - pitch[0]) + abs(pitch[2] - pitch[1]) */
     166     1221790 :         pitch_tmp = abs_s( sub( st_fx->pitch[0], old_pitch1 ) );                        /*Q0 */
     167     1221790 :         pitch_tmp = add( pitch_tmp, abs_s( sub( st_fx->pitch[1], st_fx->pitch[0] ) ) ); /*Q0 */
     168     1221790 :         pitch_tmp = add( pitch_tmp, abs_s( sub( st_fx->pitch[2], st_fx->pitch[1] ) ) ); /*Q0 */
     169             : 
     170             : 
     171             :         /*    if( (voicing[0] + voicing[1] + voicing[2]) / 3 + corr_shift > 0.65 &&
     172             :                 (short)(abs(pitch[0] - st->pitO) + abs(pitch[1] - pitch[0]) + abs(pitch[2] - pitch[1])) / 3 < 14 )
     173             :             {
     174             :                 (st->voiced_burst)++;
     175             :             } else {
     176             :                 st->voiced_burst = 0;
     177             :             } */
     178             : 
     179     1221790 :         hVAD->voiced_burst = add( hVAD->voiced_burst, 1 );
     180     1221790 :         move16();
     181     1221790 :         test();
     182     1221790 :         if ( ( LE_16( voice_tmp, 21299 ) )   /* 0.65 in Q15 */
     183      682039 :              || ( GE_16( pitch_tmp, 42 ) ) ) /*3*14 = 42   Q0 */
     184             :         {
     185      674721 :             hVAD->voiced_burst = 0;
     186      674721 :             move16();
     187             :         }
     188             :     }
     189             : 
     190             : 
     191     1189822 :     return;
     192             : }

Generated by: LCOV version 1.14