LCOV - code coverage report
Current view: top level - lib_enc - vad_param_updt.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 43 46 93.5 %
Date: 2025-05-23 08:37:30 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : /*====================================================================================
      34             :     EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
      35             :   ====================================================================================*/
      36             : 
      37             : #include <stdint.h>
      38             : #include "options.h"
      39             : #ifdef DEBUGGING
      40             : #include "debug.h"
      41             : #endif
      42             : #include <math.h>
      43             : #include "cnst.h"
      44             : #include "prot.h"
      45             : #include "wmc_auto.h"
      46             : 
      47             : /*-------------------------------------------------------------------*
      48             :  * vad_param_updt()
      49             :  *
      50             :  * Update parameters used by the VAD or DTX
      51             :  *--------------------------------------------------------------------*/
      52             : 
      53     1185802 : void vad_param_updt(
      54             :     Encoder_State *st,                /* i/o: encoder state structure               */
      55             :     const float corr_shift,           /* i  : correlation shift                     */
      56             :     const float corr_shiftR,          /* i  : correlation shift                     */
      57             :     const float A[],                  /* i  : A(z) unquantized for the 4 subframes  */
      58             :     const int16_t old_pitch1,         /* i  : previous frame OL pitch[1]            */
      59             :     FRONT_VAD_ENC_HANDLE hFrontVad[], /* i/o: front-VAD handles                     */
      60             :     const int16_t n_channels          /* i  : number of channels                    */
      61             : )
      62             : {
      63             :     float refl[M + 1];
      64             :     int16_t tmp_active_flag;
      65             :     VAD_HANDLE hVAD;
      66             :     int16_t i;
      67             :     int16_t ini_frame;
      68             :     float corr_shift_temp[2];
      69             : 
      70     1185802 :     corr_shift_temp[0] = corr_shift;
      71     1185802 :     corr_shift_temp[1] = corr_shiftR;
      72             : 
      73     1185802 :     if ( hFrontVad != NULL )
      74             :     {
      75       49758 :         hVAD = hFrontVad[0]->hVAD;
      76       49758 :         ini_frame = hFrontVad[0]->ini_frame;
      77             :     }
      78             :     else
      79             :     {
      80     1136044 :         hVAD = st->hVAD;
      81     1136044 :         ini_frame = st->ini_frame;
      82             :     }
      83             : 
      84     2403572 :     for ( i = 0; i < n_channels; i++ )
      85             :     {
      86     1217770 :         if ( i == 1 )
      87             :         {
      88       31968 :             hVAD = hFrontVad[1]->hVAD;
      89             :         }
      90             : 
      91     1217770 :         if ( !st->Opt_AMR_WB )
      92             :         {
      93             :             /* fix explanation: after function dtx_fx, the "vad_flag"
      94             :                parameter can not be used for SID scheduling purposes any
      95             :                longer as dtx_fx can schedules active frames even if the
      96             :                initial analyzed vad_flag is 0 ) in the worst case without
      97             :                the fix an active frame could be classified as SID frame,
      98             :                quite/very unlikley though
      99             :             */
     100     1217770 :             tmp_active_flag = 0;
     101             : 
     102     1217770 :             if ( ( st->core_brate != SID_2k40 ) && ( st->core_brate != 0 ) ) /* Note,  core_brate_fx can be -1 */
     103             :             {
     104     1161052 :                 tmp_active_flag = 1; /* requires active coding according  to dtx_fx logic  */
     105             :             }
     106             : 
     107     1217770 :             if ( st->Opt_DTX_ON != 0 && tmp_active_flag == 0 && ini_frame > 3 )
     108             : 
     109             :             {
     110             :                 /* update the counter of consecutive inactive frames in DTX */
     111       56628 :                 hVAD->consec_inactive++;
     112       56628 :                 if ( hVAD->consec_inactive > 5 )
     113             :                 {
     114       48200 :                     hVAD->consec_inactive = 5;
     115             :                 }
     116             : 
     117       56628 :                 if ( hVAD->consec_inactive == 5 )
     118             :                 {
     119             :                     /* compute spectral tilt parameter */
     120       49596 :                     a2rc( &A[1], refl, M );
     121             : 
     122       49596 :                     if ( hVAD->spectral_tilt_reset == 1 )
     123             :                     {
     124         889 :                         hVAD->spectral_tilt_reset = 0;
     125         889 :                         hVAD->running_avg = refl[0];
     126         889 :                         hVAD->ra_deltasum = 0;
     127             :                     }
     128             : 
     129       49596 :                     hVAD->ra_deltasum += ( 0.80f * hVAD->running_avg + 0.20f * refl[0] ) - hVAD->running_avg;
     130       49596 :                     hVAD->running_avg = 0.80f * hVAD->running_avg + 0.20f * refl[0];
     131             : 
     132       49596 :                     if ( fabs( hVAD->ra_deltasum ) > 0.2f )
     133             :                     {
     134         584 :                         hVAD->spectral_tilt_reset = 1;
     135         584 :                         hVAD->running_avg = 0;
     136         584 :                         hVAD->ra_deltasum = 0;
     137         584 :                         hVAD->trigger_SID = 1;
     138             :                     }
     139             :                 }
     140             :             }
     141             :             else
     142             :             {
     143     1161142 :                 hVAD->trigger_SID = 0;
     144     1161142 :                 hVAD->consec_inactive = 0;
     145             :             }
     146             : 
     147     1217770 :             if ( hVAD->trigger_SID == 1 )
     148             :             {
     149        2525 :                 if ( st->hDtxEnc->cng_cnt >= 8 )
     150             :                 {
     151             :                     /* Declare SID frame due to spectral tilt changes */
     152           0 :                     st->hDtxEnc->cnt_SID = 1;
     153           0 :                     st->core_brate = SID_2k40;
     154           0 :                     hVAD->trigger_SID = 0;
     155             :                 }
     156        2525 :                 else if ( st->core_brate == SID_2k40 )
     157             :                 {
     158             :                     /* SID fame has already been declared before */
     159         517 :                     hVAD->trigger_SID = 0;
     160             :                 }
     161             :             }
     162             :         }
     163             : 
     164     1217770 :         if ( ( st->voicing[0] + st->voicing[1] + st->voicing[2] ) / 3 + corr_shift_temp[i] > 0.65 &&
     165      681247 :              (int16_t) ( abs( st->pitch[0] - old_pitch1 ) + abs( st->pitch[1] - st->pitch[0] ) + abs( st->pitch[2] - st->pitch[1] ) ) / 3 < 14 )
     166             :         {
     167      546832 :             ( hVAD->voiced_burst )++;
     168             :         }
     169             :         else
     170             :         {
     171      670938 :             hVAD->voiced_burst = 0;
     172             :         }
     173             :     }
     174             : 
     175     1185802 :     return;
     176             : }

Generated by: LCOV version 1.14