LCOV - code coverage report
Current view: top level - lib_com - weight_a_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ da9cc8ead0679b4682d329fdff98cf1616159273 Lines: 97 102 95.1 %
Date: 2025-10-13 22:24:20 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : #include <stdint.h>
       5             : #include "options.h" /* Compilation switches                   */
       6             : #include "rom_com.h" /* Static table prototypes                */
       7             : #include "prot_fx.h"
       8             : #include <assert.h>
       9             : 
      10             : /*------------------------------------------------------------------
      11             :  * weight_a_subfr()
      12             :  *
      13             :  * Weighting of LP filter coefficients for multiple subframes,
      14             :  * ap[i] = a[i] * (gamma^i)
      15             :  *------------------------------------------------------------------*/
      16             : 
      17     1324490 : void weight_a_subfr_fx(
      18             :     const Word16 nb_subfr, /* i  : number of subframes             Q0  */
      19             :     const Word16 *A,       /* i  : LP filter coefficients          Q12 */
      20             :     Word16 *Aw,            /* o  : weighted LP filter coefficients Q12 */
      21             :     const Word16 gamma,    /* i  : weighting factor                Q15 */
      22             :     const Word16 order     /* i  : order of LP filter              Q0  */
      23             : )
      24             : {
      25             :     Word16 k, orderp1;
      26             : 
      27             :     /* Smoothing aka spreading aka masking envelope generation */
      28     1324490 :     orderp1 = add( order, 1 );
      29     6788789 :     FOR( k = 0; k < nb_subfr; k++ )
      30             :     {
      31     5464299 :         weight_a_fx( &A[k * ( orderp1 )], &Aw[k * ( orderp1 )], gamma, order );
      32             :     }
      33             : 
      34     1324490 :     return;
      35             : }
      36             : 
      37             : /*==============================================================================*/
      38             : /* FUNCTION      :  void weight_a_lc_fx ( )                                                                             */
      39             : /*------------------------------------------------------------------------------*/
      40             : /* PURPOSE       : Weighting of LP filter coefficients, ap[i] = a[i] * (gamma^i)*/
      41             : /*------------------------------------------------------------------------------*/
      42             : /* INPUT ARGUMENTS  :                                                                                                                   */
      43             : /*              const Word16 a[],                          i:  LP filter coefficients           Q12 */
      44             : /*              const Word16 *gammatbl,            i:  weighting factor                 Q15 */
      45             : /*              const Word16 m                             i:  order of LP filter               Q0  */
      46             : /*------------------------------------------------------------------------------*/
      47             : /* OUTPUT ARGUMENTS :                                                                                                                   */
      48             : /*              Word16 ap[],                               o:  weighted LP filter coefficients  Q12 */
      49             : /*------------------------------------------------------------------------------*/
      50             : /* RETURN ARGUMENTS :                                                                                                                   */
      51             : /*------------------------------------------------------------------------------*/
      52             : /* CALLED FROM : TX/RX                                                                                                                  */
      53             : /*==============================================================================*/
      54       59076 : void weight_a_lc_fx(
      55             :     const Word16 a[],       /* i:  LP filter coefficients           Q12 */
      56             :     Word16 ap[],            /* o:  weighted LP filter coefficients  Q12 */
      57             :     const Word16 *gammatbl, /* i:  weighting factor                 Q15 */
      58             :     const Word16 m          /* i:  order of LP filter               Q0  */
      59             : )
      60             : {
      61             :     Word16 i;
      62             :     Word32 Amax;
      63             :     Word16 shift;
      64             :     const Word16 *ptr_gamma;
      65             : 
      66       59076 :     ptr_gamma = gammatbl;         /* Q15 */
      67       59076 :     Amax = L_mult( 16384, a[0] ); /* Q27 */
      68      945216 :     FOR( i = 1; i < m; i++ )
      69             :     {
      70      886140 :         Amax = L_max( Amax, L_abs( L_mult0( *ptr_gamma++, a[i] ) ) ); /* Q27 */
      71             :     }
      72       59076 :     Amax = L_max( Amax, L_abs( L_mult0( *ptr_gamma++, a[m] ) ) ); /* Q27 */
      73       59076 :     shift = norm_l( Amax );
      74       59076 :     ptr_gamma = gammatbl;                 /* Q15 */
      75       59076 :     ap[0] = shl( a[0], sub( shift, 1 ) ); /* Q11 + shift */
      76       59076 :     move16();
      77      945216 :     FOR( i = 1; i < m; i++ )
      78             :     {
      79      886140 :         ap[i] = round_fx( L_shl( L_mult0( a[i], *ptr_gamma++ ), shift ) ); /* Q11 + shift */
      80      886140 :         move16();
      81             :     }
      82       59076 :     ap[m] = round_fx( L_shl( L_mult0( a[m], *ptr_gamma++ ), shift ) ); /* Q11 + shift */
      83       59076 :     move16();
      84             : 
      85       59076 :     return;
      86             : }
      87             : 
      88             : /*------------------------------------------------------------------
      89             :  * weight_a:
      90             :  *
      91             :  * Weighting of LP filter coefficients, ap[i] = a[i] * (gamma^i)
      92             :  *------------------------------------------------------------------*/
      93    12099219 : void weight_a_fx(
      94             :     const Word16 a[],   /* i:  LP filter coefficients           Q12 */
      95             :     Word16 ap[],        /* o:  weighted LP filter coefficients  Q12 */
      96             :     const Word16 gamma, /* i:  weighting factor                 Q15 */
      97             :     const Word16 m      /* i:  order of LP filter               Q0  */
      98             : )
      99             : {
     100             :     Word16 i, fac;
     101             :     Word32 Amax;
     102             :     Word16 shift;
     103             : 
     104    12099219 :     fac = gamma; /* Q15 */
     105    12099219 :     move16();
     106    12099219 :     Amax = L_mult( 16384, a[0] ); /* Q27 */
     107   183282720 :     FOR( i = 1; i < m; i++ )
     108             :     {
     109   171183501 :         Amax = L_max( Amax, L_abs( L_mult0( fac, a[i] ) ) ); /* Q27 */
     110   171183501 :         fac = mult_r( fac, gamma );                          /* Q15 */
     111             :     }
     112    12099219 :     Amax = L_max( Amax, L_abs( L_mult0( fac, a[m] ) ) );
     113    12099219 :     shift = norm_l( Amax );
     114    12099219 :     fac = gamma; /* Q15 */
     115    12099219 :     move16();
     116    12099219 :     ap[0] = shl( a[0], sub( shift, 1 ) ); /* Q11 + shift */
     117    12099219 :     move16();
     118   183282720 :     FOR( i = 1; i < m; i++ )
     119             :     {
     120   171183501 :         ap[i] = round_fx_sat( L_shl( L_mult0( a[i], fac ), shift ) ); /* Q11 + shift */
     121   171183501 :         move16();
     122   171183501 :         fac = mult_r( fac, gamma ); /* Q15 */
     123             :     }
     124    12099219 :     ap[m] = round_fx( L_shl( L_mult0( a[m], fac ), shift ) ); /* Q11 + shift */
     125    12099219 :     move16();
     126             : 
     127    12099219 :     return;
     128             : }
     129             : 
     130             : /*
     131             :  * E_LPC_a_weight_inv
     132             :  *
     133             :  * Parameters:
     134             :  *    a              I: LP filter coefficients                  Q12
     135             :  *    ap             O: weighted LP filter coefficients Q12
     136             :  *    inv_gamma      I: inverse weighting factor                                Q14
     137             :  *    m              I: order of LP filter
     138             :  *
     139             :  * Function:
     140             :  *    Weighting of LP filter coefficients, ap[i] = a[i] * (inv_gamma^i).
     141             :  *
     142             :  * Returns:
     143             :  *    void
     144             :  */
     145       17444 : void E_LPC_a_weight_inv(
     146             :     const Word16 *a,        /* Q12 */
     147             :     Word16 *ap,             /* Q12 */
     148             :     const Word16 inv_gamma, /* Q14 */
     149             :     const Word16 m          /* Q0 */
     150             : )
     151             : {
     152             :     Word16 i;
     153             :     static const Word16 inv_gamma_tab_12k8[16] = { 17809, 19357, 21041, 22870, 24859, 27020, 29370, 31924,   /* Q14 */
     154             :                                                    17350, 18859, 20499, 22281, 24219, 26325, 28614, 31102 }; /* Q13 */
     155             :     static const Word16 inv_gamma_tab_16k[16] = { 17430, 18542, 19726, 20985, 22324, 23749, 25265, 26878,    /* Q14 */
     156             :                                                   14297, 15209, 16180, 17213, 18312, 19480, 20724, 22047 };  /* Q13 */
     157       17444 :     move16();
     158       17444 :     move16();
     159       17444 :     move16();
     160       17444 :     move16();
     161       17444 :     move16();
     162       17444 :     move16();
     163       17444 :     move16();
     164       17444 :     move16();
     165       17444 :     move16();
     166       17444 :     move16();
     167       17444 :     move16();
     168       17444 :     move16();
     169       17444 :     move16();
     170       17444 :     move16();
     171       17444 :     move16();
     172       17444 :     move16();
     173       17444 :     move16();
     174       17444 :     move16();
     175       17444 :     move16();
     176       17444 :     move16();
     177       17444 :     move16();
     178       17444 :     move16();
     179       17444 :     move16();
     180       17444 :     move16();
     181       17444 :     move16();
     182       17444 :     move16();
     183       17444 :     move16();
     184       17444 :     move16();
     185       17444 :     move16();
     186       17444 :     move16();
     187       17444 :     move16();
     188       17444 :     move16();
     189             : 
     190             :     const Word16 *inv_gamma_tab;
     191             :     Word32 L_tmp;
     192             :     Word32 Amax;
     193             :     Word16 shift;
     194             : 
     195             : 
     196       17444 :     IF( EQ_16( inv_gamma, 16384 /* 1 in Q14 */ ) )
     197             :     {
     198           0 :         FOR( i = 0; i <= m; i++ )
     199             :         {
     200           0 :             ap[i] = a[i]; /* Q12 */
     201           0 :             move16();
     202             :         }
     203           0 :         return;
     204             :     }
     205             : 
     206       17444 :     assert( inv_gamma == GAMMA1_INV || inv_gamma == GAMMA16k_INV );
     207       17444 :     assert( m == 16 );
     208             : 
     209       17444 :     inv_gamma_tab = inv_gamma_tab_12k8; /* Q14 */
     210       17444 :     if ( EQ_16( inv_gamma, GAMMA16k_INV ) )
     211             :     {
     212           0 :         inv_gamma_tab = inv_gamma_tab_16k; /* Q14 */
     213             :     }
     214             : 
     215             : 
     216       17444 :     Amax = L_mult( 16384, a[0] );
     217      156996 :     FOR( i = 1; i < 9; i++ )
     218             :     {
     219      139552 :         Amax = L_max( Amax, L_abs( L_mult( a[i], inv_gamma_tab[i - 1] ) ) ); /* Q27 */
     220             :     }
     221      156996 :     FOR( i = 9; i < 17; i++ )
     222             :     {
     223      139552 :         Amax = L_max( Amax, L_abs( L_shl( L_mult( a[i], inv_gamma_tab[i - 1] ), 1 ) ) ); /* Q27 */
     224             :     }
     225       17444 :     shift = norm_l( Amax );
     226       17444 :     ap[0] = shl( a[0], sub( shift, 1 ) ); /* Q11 + shift */
     227       17444 :     move16();
     228      156996 :     FOR( i = 1; i < 9; i++ )
     229             :     {
     230      139552 :         L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); /* Q27 */
     231      139552 :         ap[i] = round_fx( L_shl( L_tmp, shift ) );    /* Q11 + shift */
     232      139552 :         move16();
     233             :     }
     234       17444 :     shift = add( shift, 1 );
     235      156996 :     FOR( i = 9; i < 17; i++ )
     236             :     {
     237      139552 :         L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); /* Q26 */
     238      139552 :         ap[i] = round_fx( L_shl( L_tmp, shift ) );    /* Q11 + shift */
     239      139552 :         move16();
     240             :     }
     241             : 
     242             : 
     243       17444 :     return;
     244             : }

Generated by: LCOV version 1.14