LCOV - code coverage report
Current view: top level - lib_dec - er_scale_syn.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 8834b716eb6d7dfb881d5c69dd21cb18e1692722 Lines: 29 35 82.9 %
Date: 2025-07-09 08:36:12 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             : #include <math.h>
      40             : #include "prot.h"
      41             : #include "cnst.h"
      42             : #include "wmc_auto.h"
      43             : 
      44             : 
      45             : /*----------------------------------------------------------------------------------*
      46             :  * Damping_fact()
      47             :  *
      48             :  *  Estimate damping factor
      49             :  *----------------------------------------------------------------------------------*/
      50             : 
      51       52137 : float Damping_fact(
      52             :     const int16_t coder_type,
      53             :     const int16_t nbLostCmpt,
      54             :     int16_t last_good,
      55             :     float stab_fac,
      56             :     float *lp_gainp,
      57             :     const int16_t core )
      58             : {
      59             :     float alpha, gain;
      60             : 
      61       52137 :     if ( core == ACELP_CORE )
      62             :     {
      63       17613 :         alpha = ALPHA_VT;                                        /* rapid convergence to 0 */
      64       17613 :         if ( ( coder_type == UNVOICED ) && ( nbLostCmpt <= 3 ) ) /* Clear unvoiced last good frame   */
      65             :         {
      66        9678 :             alpha = ALPHA_UU;
      67             :         }
      68        7935 :         else if ( last_good == UNVOICED_CLAS )
      69             :         {
      70           0 :             if ( nbLostCmpt == 1 )
      71             :             {
      72             :                 /* If stable, do not decrease the energy, pitch gain = 0 */
      73           0 :                 alpha = stab_fac * ( 1.0f - 2.0f * ALPHA_U ) + 2.0f * ALPHA_U; /* [0.8, 1.0] */
      74             :             }
      75           0 :             else if ( nbLostCmpt == 2 )
      76             :             {
      77           0 :                 alpha = ALPHA_U * 1.5f; /* 0.6 */
      78             :             }
      79             :             else
      80             :             {
      81           0 :                 alpha = ALPHA_U; /* 0.4 go rapidly to CNG gain, pitch gain = 0 */
      82             :             }
      83             :         }
      84        7935 :         else if ( last_good == UNVOICED_TRANSITION )
      85             :         {
      86           0 :             alpha = ALPHA_UT;
      87             :         }
      88        7935 :         else if ( ( last_good == ONSET ) && ( nbLostCmpt <= 3 ) && ( coder_type == GENERIC ) )
      89             :         {
      90         276 :             alpha = 0.8f;
      91             :         }
      92        7659 :         else if ( ( ( last_good == VOICED_CLAS ) || ( last_good == ONSET ) ) && ( nbLostCmpt <= 3 ) )
      93             :         {
      94        2331 :             alpha = ALPHA_V; /* constant for the first 3 erased frames */
      95             :         }
      96       17613 :         if ( last_good >= VOICED_CLAS )
      97             :         {
      98       17364 :             if ( nbLostCmpt == 1 ) /* if first erased frame in a block, reset harmonic gain */
      99             :             {
     100        9021 :                 gain = (float) sqrt( *lp_gainp ); /* move pitch gain towards 1 for voiced to remove energy fluctuations */
     101             : 
     102        9021 :                 if ( gain > 0.98f )
     103             :                 {
     104        1599 :                     gain = 0.98f;
     105             :                 }
     106        7422 :                 else if ( gain < 0.85f )
     107             :                 {
     108        2907 :                     gain = 0.85f;
     109             :                 }
     110        9021 :                 alpha *= gain;
     111             :             }
     112        8343 :             else if ( nbLostCmpt == 2 )
     113             :             {
     114        2820 :                 alpha = ( 0.6f + 0.35f * stab_fac ) * *lp_gainp;
     115             :             }
     116             :             else
     117             :             {
     118        5523 :                 *lp_gainp *= ( 0.7f + 0.2f * stab_fac );
     119        5523 :                 alpha = *lp_gainp;
     120             :             }
     121             :         }
     122             :     }
     123             :     else
     124             :     {
     125       34524 :         if ( nbLostCmpt < 2 )
     126             :         {
     127       20865 :             alpha = ( 0.7f + 0.3f * stab_fac );
     128             :         }
     129       13659 :         else if ( nbLostCmpt == 2 )
     130             :         {
     131        6051 :             alpha = ( 0.45f + 0.4f * stab_fac );
     132             :         }
     133             :         else
     134             :         {
     135        7608 :             alpha = 0.35f + 0.4f * stab_fac;
     136             :         }
     137             :     }
     138             : 
     139       52137 :     return alpha;
     140             : }

Generated by: LCOV version 1.14