LCOV - code coverage report
Current view: top level - lib_dec - er_scale_syn_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 41 47 87.2 %
Date: 2025-05-03 01:55:50 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       13303 : 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             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      37       13303 :     Flag Overflow = 0;
      38       13303 :     move16();
      39             : #endif
      40             : 
      41             : 
      42       13303 :     IF( core == ACELP_CORE )
      43             :     {
      44        4816 :         alpha = mult_r( _ALPHA_VT_FX, 16384 ); /* rapid convergence to 0 */ /*Q14*/
      45        4816 :         test();
      46        4816 :         test();
      47        4816 :         test();
      48        4816 :         test();
      49        4816 :         test();
      50        4816 :         IF( ( EQ_16( coder_type, UNVOICED ) ) && ( LE_16( nbLostCmpt, 3 ) ) ) /* Clear unvoiced last good frame   */
      51             :         {
      52        2434 :             alpha = mult_r( _ALPHA_UU_FX, 16384 ); /*Q14*/
      53             :         }
      54        2382 :         ELSE IF( EQ_16( last_good, UNVOICED_CLAS ) )
      55             :         {
      56           0 :             IF( EQ_16( nbLostCmpt, 1 ) )
      57             :             {
      58             :                 /* If stable, do not decrease the energy, pitch gain = 0 */
      59             :                 /* * (1.0f - 2.0f*_ALPHA_U_FX) + 2.0f*MODE2_ALPHA_U; */                    /* [0.8, 1.0] */
      60           0 :                 alpha = add( mult_r( stab_fac, sub( 16384, _ALPHA_U_FX ) ), _ALPHA_U_FX ); /*Q14*/
      61             :             }
      62           0 :             ELSE IF( EQ_16( nbLostCmpt, 2 ) )
      63             :             {
      64             :                 /*alpha = _ALPHA_U_FX * 1.5f;*/                    /* 0.6 */
      65           0 :                 alpha = mult_r( _ALPHA_U_FX, 24576 /*1.5f Q14*/ ); /*Q14*/
      66             :             }
      67             :             ELSE
      68             :             {
      69           0 :                 alpha = mult_r( _ALPHA_U_FX, 16384 ); /*Q14*/ /* 0.4 go rapidly to CNG gain, pitch gain = 0 Q14*/
      70             :             }
      71             :         }
      72        2382 :         ELSE IF( EQ_16( last_good, UNVOICED_TRANSITION ) )
      73             :         {
      74           0 :             alpha = mult_r( _ALPHA_UT_FX, 16384 ); /*Q14*/
      75             :         }
      76        2382 :         ELSE IF( ( EQ_16( last_good, ONSET ) ) && ( LE_16( nbLostCmpt, 3 ) ) && ( EQ_16( coder_type, GENERIC ) ) )
      77             :         {
      78          52 :             alpha = 13107 /*0.8f Q14*/; /*Q14*/
      79             :         }
      80        2330 :         ELSE IF( ( ( EQ_16( last_good, VOICED_CLAS ) ) || ( EQ_16( last_good, ONSET ) ) ) && ( LE_16( nbLostCmpt, 3 ) ) )
      81             :         {
      82         577 :             alpha = mult_r( _ALPHA_V_FX, 16384 ); /* constant for the first 3 erased frames Q14*/
      83             :         }
      84             : 
      85        4816 :         IF( GE_16( last_good, VOICED_CLAS ) )
      86             :         {
      87        4767 :             lp_tmp = *lp_gainp; /*Q29*/
      88        4767 :             move32();
      89             : 
      90        4767 :             IF( EQ_16( nbLostCmpt, 1 ) ) /* if first erased frame in a block, reset harmonic gain */
      91             :             {
      92             :                 /*lp_gainp_E = 1;*/ /*For sqrt, because *lp_gain is Q14 */
      93             : 
      94             :                 /*gain = (float)sqrt( *lp_gainp );*/ /* move pitch gain towards 1 for voiced to remove energy fluctuations */
      95             :                 /*BASOP_Util_Sqrt_MantExp(lp_gainp,&lp_gainp_E);*/
      96        2224 :                 s_gainp = 31 - 29;
      97        2224 :                 move16();
      98        2224 :                 gain32 = Sqrt32( lp_tmp, &s_gainp ); /*Q31-s_gainp*/
      99             : 
     100        2224 :                 gain = round_fx_o( L_shl_o( gain32, s_gainp, &Overflow ), &Overflow ); /* Q15*/
     101        2224 :                 gain = s_min( gain, 32113 /*0.98f Q15*/ );                             /*Q15*/
     102        2224 :                 gain = s_max( gain, 27853 /*0.85f Q15*/ );                             /*Q15*/
     103        2224 :                 alpha = mult_r( alpha, gain );                                         /*Q14*/
     104             :             }
     105        2543 :             ELSE IF( EQ_16( nbLostCmpt, 2 ) )
     106             :             {
     107             :                 /*0.6  + 0.35*stab_fac*/
     108         715 :                 alpha = mult_r( mac_r( 1288490240l /*0.6f Q31*/, 11469 /*0.35f Q15*/, stab_fac ), round_fx( L_shl( lp_tmp, 1 ) ) ); /*Q14*/
     109             :             }
     110             :             ELSE
     111             :             {
     112             :                 /*0.7 + 0.2*stab_fac*/
     113        1828 :                 lp_tmp = Mpy_32_16_1( lp_tmp, mac_r( 1503238528l /*0.7f Q31*/, 6554 /*0.2f Q15*/, stab_fac ) ); /*2Q29*/
     114        1828 :                 alpha = round_fx( L_shl( lp_tmp, 1 ) );                                                         /*1Q14*/
     115             :             }
     116        4767 :             *lp_gainp = lp_tmp; /*store Q29*/
     117        4767 :             move32();
     118             :         }
     119             :     }
     120             :     ELSE
     121             :     {
     122        8487 :         alpha = mac_r( 375809632l /*0.35f Q30*/, 6554 /*0.4f Q14*/, stab_fac ); /*Q14*/
     123        8487 :         IF( LT_16( nbLostCmpt, 2 ) )
     124             :         {
     125        4624 :             alpha = mac_r( 751619264l /*0.70f Q30*/, 4915 /*0.3f Q14*/, stab_fac ); /*Q14*/
     126             :         }
     127        8487 :         IF( EQ_16( nbLostCmpt, 2 ) )
     128             :         {
     129        1454 :             alpha = mac_r( 483183808l /*0.45f Q30*/, 6554 /*0.4f Q14*/, stab_fac ); /*Q14*/
     130             :         }
     131             :     }
     132       13303 :     return alpha;
     133             : }

Generated by: LCOV version 1.14