LCOV - code coverage report
Current view: top level - lib_dec - er_scale_syn_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ da9cc8ead0679b4682d329fdff98cf1616159273 Lines: 39 45 86.7 %
Date: 2025-10-13 22:24: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             : /*This file is up to date with trunk rev 36531*/
       6             : 
       7             : #include <stdint.h>
       8             : #include "options.h"
       9             : #include "prot_fx.h"
      10             : #include "basop_util.h"
      11             : #include "cnst.h"
      12             : 
      13             : /*----------------------------------------------------------------------------------*
      14             :  * Damping_fact_fx()
      15             :  *
      16             :  *  Estimate damping factor
      17             :  *----------------------------------------------------------------------------------*/
      18             : 
      19             : /*This BASOP version was ported based on trunk rev. 27621 and updated based on trunk rev. 29287, re-updated based on trunk rev. 32244  */
      20       13807 : Word16 Damping_fact_fx( /* o : damping factor                                       */ /*Q14*/
      21             :                         const Word16 coder_type,                                       /* i : coding type in last good received frame              */
      22             :                         const Word16 nbLostCmpt,                                       /* i : counter of consecutive bfi frames                    */
      23             :                         const Word16 last_good,                                        /* i : last good frame class                                */
      24             :                         const Word16 stab_fac,
      25             :                         /* i : ISF stability factor                                 */ /*Q15*/
      26             :                         Word32 *lp_gainp,
      27             :                         /*i/o: damped pitch gain                                    */ /*2Q29 Word32!*/
      28             :                         const Word16 core                                              /* i : current coding mode                                  */
      29             : )
      30             : {
      31             :     Word16 alpha; /*Q14*/
      32             :     Word16 gain;  /*Q14*/
      33             :     Word32 lp_tmp;
      34             :     Word16 s_gainp;
      35             :     Word32 gain32;
      36             : 
      37             : 
      38       13807 :     IF( core == ACELP_CORE )
      39             :     {
      40        5100 :         alpha = mult_r( _ALPHA_VT_FX, 16384 ); /* rapid convergence to 0 */ /*Q14*/
      41        5100 :         test();
      42        5100 :         test();
      43        5100 :         test();
      44        5100 :         test();
      45        5100 :         test();
      46        5100 :         IF( ( EQ_16( coder_type, UNVOICED ) ) && ( LE_16( nbLostCmpt, 3 ) ) ) /* Clear unvoiced last good frame   */
      47             :         {
      48        2557 :             alpha = mult_r( _ALPHA_UU_FX, 16384 ); /*Q14*/
      49             :         }
      50        2543 :         ELSE IF( EQ_16( last_good, UNVOICED_CLAS ) )
      51             :         {
      52           0 :             IF( EQ_16( nbLostCmpt, 1 ) )
      53             :             {
      54             :                 /* If stable, do not decrease the energy, pitch gain = 0 */
      55             :                 /* * (1.0f - 2.0f*_ALPHA_U_FX) + 2.0f*MODE2_ALPHA_U; */                    /* [0.8, 1.0] */
      56           0 :                 alpha = add( mult_r( stab_fac, sub( 16384, _ALPHA_U_FX ) ), _ALPHA_U_FX ); /*Q14*/
      57             :             }
      58           0 :             ELSE IF( EQ_16( nbLostCmpt, 2 ) )
      59             :             {
      60             :                 /*alpha = _ALPHA_U_FX * 1.5f;*/                    /* 0.6 */
      61           0 :                 alpha = mult_r( _ALPHA_U_FX, 24576 /*1.5f Q14*/ ); /*Q14*/
      62             :             }
      63             :             ELSE
      64             :             {
      65           0 :                 alpha = mult_r( _ALPHA_U_FX, 16384 ); /*Q14*/ /* 0.4 go rapidly to CNG gain, pitch gain = 0 Q14*/
      66             :             }
      67             :         }
      68        2543 :         ELSE IF( EQ_16( last_good, UNVOICED_TRANSITION ) )
      69             :         {
      70           0 :             alpha = mult_r( _ALPHA_UT_FX, 16384 ); /*Q14*/
      71             :         }
      72        2543 :         ELSE IF( ( EQ_16( last_good, ONSET ) ) && ( LE_16( nbLostCmpt, 3 ) ) && ( EQ_16( coder_type, GENERIC ) ) )
      73             :         {
      74          53 :             alpha = 13107 /*0.8f Q14*/; /*Q14*/
      75             :         }
      76        2490 :         ELSE IF( ( ( EQ_16( last_good, VOICED_CLAS ) ) || ( EQ_16( last_good, ONSET ) ) ) && ( LE_16( nbLostCmpt, 3 ) ) )
      77             :         {
      78         616 :             alpha = mult_r( _ALPHA_V_FX, 16384 ); /* constant for the first 3 erased frames Q14*/
      79             :         }
      80             : 
      81        5100 :         IF( GE_16( last_good, VOICED_CLAS ) )
      82             :         {
      83        4939 :             lp_tmp = *lp_gainp; /*Q29*/
      84        4939 :             move32();
      85             : 
      86        4939 :             IF( EQ_16( nbLostCmpt, 1 ) ) /* if first erased frame in a block, reset harmonic gain */
      87             :             {
      88             :                 /*lp_gainp_E = 1;*/ /*For sqrt, because *lp_gain is Q14 */
      89             : 
      90             :                 /*gain = (float)sqrt( *lp_gainp );*/ /* move pitch gain towards 1 for voiced to remove energy fluctuations */
      91             :                 /*BASOP_Util_Sqrt_MantExp(lp_gainp,&lp_gainp_E);*/
      92        2362 :                 s_gainp = 31 - 29;
      93        2362 :                 move16();
      94        2362 :                 gain32 = Sqrt32( lp_tmp, &s_gainp ); /*Q31-s_gainp*/
      95             : 
      96        2362 :                 gain = round_fx_sat( L_shl_sat( gain32, s_gainp ) ); /* Q15*/
      97        2362 :                 gain = s_min( gain, 32113 /*0.98f Q15*/ );           /*Q15*/
      98        2362 :                 gain = s_max( gain, 27853 /*0.85f Q15*/ );           /*Q15*/
      99        2362 :                 alpha = mult_r( alpha, gain );                       /*Q14*/
     100             :             }
     101        2577 :             ELSE IF( EQ_16( nbLostCmpt, 2 ) )
     102             :             {
     103             :                 /*0.6  + 0.35*stab_fac*/
     104         735 :                 alpha = mult_r( mac_r( 1288490240l /*0.6f Q31*/, 11469 /*0.35f Q15*/, stab_fac ), round_fx( L_shl( lp_tmp, 1 ) ) ); /*Q14*/
     105             :             }
     106             :             ELSE
     107             :             {
     108             :                 /*0.7 + 0.2*stab_fac*/
     109        1842 :                 lp_tmp = Mpy_32_16_1( lp_tmp, mac_r( 1503238528l /*0.7f Q31*/, 6554 /*0.2f Q15*/, stab_fac ) ); /*2Q29*/
     110        1842 :                 alpha = round_fx( L_shl( lp_tmp, 1 ) );                                                         /*1Q14*/
     111             :             }
     112        4939 :             *lp_gainp = lp_tmp; /*store Q29*/
     113        4939 :             move32();
     114             :         }
     115             :     }
     116             :     ELSE
     117             :     {
     118        8707 :         alpha = mac_r( 375809632l /*0.35f Q30*/, 6554 /*0.4f Q14*/, stab_fac ); /*Q14*/
     119        8707 :         IF( LT_16( nbLostCmpt, 2 ) )
     120             :         {
     121        4949 :             alpha = mac_r( 751619264l /*0.70f Q30*/, 4915 /*0.3f Q14*/, stab_fac ); /*Q14*/
     122             :         }
     123        8707 :         IF( EQ_16( nbLostCmpt, 2 ) )
     124             :         {
     125        1526 :             alpha = mac_r( 483183808l /*0.45f Q30*/, 6554 /*0.4f Q14*/, stab_fac ); /*Q14*/
     126             :         }
     127             :     }
     128       13807 :     return alpha;
     129             : }

Generated by: LCOV version 1.14