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

Generated by: LCOV version 1.14