LCOV - code coverage report
Current view: top level - lib_com - weight_a_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 633e3f2e309758d10805ef21e0436356fe719b7a Lines: 36 102 35.3 %
Date: 2025-08-23 01:22:27 Functions: 2 4 50.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           0 : 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           0 :     orderp1 = add( order, 1 );
      29           0 :     FOR( k = 0; k < nb_subfr; k++ )
      30             :     {
      31           0 :         weight_a_fx( &A[k * ( orderp1 )], &Aw[k * ( orderp1 )], gamma, order );
      32             :     }
      33             : 
      34           0 :     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       59556 : 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       59556 :     ptr_gamma = gammatbl;         /* Q15 */
      67       59556 :     Amax = L_mult( 16384, a[0] ); /* Q27 */
      68      952896 :     FOR( i = 1; i < m; i++ )
      69             :     {
      70      893340 :         Amax = L_max( Amax, L_abs( L_mult0( *ptr_gamma++, a[i] ) ) ); /* Q27 */
      71             :     }
      72       59556 :     Amax = L_max( Amax, L_abs( L_mult0( *ptr_gamma++, a[m] ) ) ); /* Q27 */
      73       59556 :     shift = norm_l( Amax );
      74       59556 :     ptr_gamma = gammatbl;                 /* Q15 */
      75       59556 :     ap[0] = shl( a[0], sub( shift, 1 ) ); /* Q11 + shift */
      76       59556 :     move16();
      77      952896 :     FOR( i = 1; i < m; i++ )
      78             :     {
      79      893340 :         ap[i] = round_fx( L_shl( L_mult0( a[i], *ptr_gamma++ ), shift ) ); /* Q11 + shift */
      80      893340 :         move16();
      81             :     }
      82       59556 :     ap[m] = round_fx( L_shl( L_mult0( a[m], *ptr_gamma++ ), shift ) ); /* Q11 + shift */
      83       59556 :     move16();
      84             : 
      85       59556 :     return;
      86             : }
      87             : 
      88             : /*------------------------------------------------------------------
      89             :  * weight_a:
      90             :  *
      91             :  * Weighting of LP filter coefficients, ap[i] = a[i] * (gamma^i)
      92             :  *------------------------------------------------------------------*/
      93     3354694 : 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             : #ifndef ISSUE_1836_replace_overflow_libcom__remnant
     104             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     105             :     Flag Overflow;
     106             :     Overflow = 0;
     107             :     move32();
     108             : #endif
     109             : #endif
     110             : 
     111     3354694 :     fac = gamma; /* Q15 */
     112     3354694 :     move16();
     113     3354694 :     Amax = L_mult( 16384, a[0] ); /* Q27 */
     114    48776848 :     FOR( i = 1; i < m; i++ )
     115             :     {
     116    45422154 :         Amax = L_max( Amax, L_abs( L_mult0( fac, a[i] ) ) ); /* Q27 */
     117    45422154 :         fac = mult_r( fac, gamma );                          /* Q15 */
     118             :     }
     119     3354694 :     Amax = L_max( Amax, L_abs( L_mult0( fac, a[m] ) ) );
     120     3354694 :     shift = norm_l( Amax );
     121     3354694 :     fac = gamma; /* Q15 */
     122     3354694 :     move16();
     123     3354694 :     ap[0] = shl( a[0], sub( shift, 1 ) ); /* Q11 + shift */
     124     3354694 :     move16();
     125    48776848 :     FOR( i = 1; i < m; i++ )
     126             :     {
     127             : #ifdef ISSUE_1836_replace_overflow_libcom__remnant
     128    45422154 :         ap[i] = round_fx_sat( L_shl( L_mult0( a[i], fac ), shift ) ); /* Q11 + shift */
     129             : #else
     130             :         ap[i] = round_fx_o( L_shl( L_mult0( a[i], fac ), shift ), &Overflow ); /* Q11 + shift */
     131             : #endif
     132    45422154 :         move16();
     133    45422154 :         fac = mult_r( fac, gamma ); /* Q15 */
     134             :     }
     135     3354694 :     ap[m] = round_fx( L_shl( L_mult0( a[m], fac ), shift ) ); /* Q11 + shift */
     136     3354694 :     move16();
     137             : 
     138     3354694 :     return;
     139             : }
     140             : 
     141             : /*
     142             :  * E_LPC_a_weight_inv
     143             :  *
     144             :  * Parameters:
     145             :  *    a              I: LP filter coefficients                  Q12
     146             :  *    ap             O: weighted LP filter coefficients Q12
     147             :  *    inv_gamma      I: inverse weighting factor                                Q14
     148             :  *    m              I: order of LP filter
     149             :  *
     150             :  * Function:
     151             :  *    Weighting of LP filter coefficients, ap[i] = a[i] * (inv_gamma^i).
     152             :  *
     153             :  * Returns:
     154             :  *    void
     155             :  */
     156           0 : void E_LPC_a_weight_inv(
     157             :     const Word16 *a,        /* Q12 */
     158             :     Word16 *ap,             /* Q12 */
     159             :     const Word16 inv_gamma, /* Q14 */
     160             :     const Word16 m          /* Q0 */
     161             : )
     162             : {
     163             :     Word16 i;
     164             :     static const Word16 inv_gamma_tab_12k8[16] = { 17809, 19357, 21041, 22870, 24859, 27020, 29370, 31924,   /* Q14 */
     165             :                                                    17350, 18859, 20499, 22281, 24219, 26325, 28614, 31102 }; /* Q13 */
     166             :     static const Word16 inv_gamma_tab_16k[16] = { 17430, 18542, 19726, 20985, 22324, 23749, 25265, 26878,    /* Q14 */
     167             :                                                   14297, 15209, 16180, 17213, 18312, 19480, 20724, 22047 };  /* Q13 */
     168           0 :     move16();
     169           0 :     move16();
     170           0 :     move16();
     171           0 :     move16();
     172           0 :     move16();
     173           0 :     move16();
     174           0 :     move16();
     175           0 :     move16();
     176           0 :     move16();
     177           0 :     move16();
     178           0 :     move16();
     179           0 :     move16();
     180           0 :     move16();
     181           0 :     move16();
     182           0 :     move16();
     183           0 :     move16();
     184           0 :     move16();
     185           0 :     move16();
     186           0 :     move16();
     187           0 :     move16();
     188           0 :     move16();
     189           0 :     move16();
     190           0 :     move16();
     191           0 :     move16();
     192           0 :     move16();
     193           0 :     move16();
     194           0 :     move16();
     195           0 :     move16();
     196           0 :     move16();
     197           0 :     move16();
     198           0 :     move16();
     199           0 :     move16();
     200             : 
     201             :     const Word16 *inv_gamma_tab;
     202             :     Word32 L_tmp;
     203             :     Word32 Amax;
     204             :     Word16 shift;
     205             : 
     206             : 
     207           0 :     IF( EQ_16( inv_gamma, 16384 /* 1 in Q14 */ ) )
     208             :     {
     209           0 :         FOR( i = 0; i <= m; i++ )
     210             :         {
     211           0 :             ap[i] = a[i]; /* Q12 */
     212           0 :             move16();
     213             :         }
     214           0 :         return;
     215             :     }
     216             : 
     217           0 :     assert( inv_gamma == GAMMA1_INV || inv_gamma == GAMMA16k_INV );
     218           0 :     assert( m == 16 );
     219             : 
     220           0 :     inv_gamma_tab = inv_gamma_tab_12k8; /* Q14 */
     221           0 :     if ( EQ_16( inv_gamma, GAMMA16k_INV ) )
     222             :     {
     223           0 :         inv_gamma_tab = inv_gamma_tab_16k; /* Q14 */
     224             :     }
     225             : 
     226             : 
     227           0 :     Amax = L_mult( 16384, a[0] );
     228           0 :     FOR( i = 1; i < 9; i++ )
     229             :     {
     230           0 :         Amax = L_max( Amax, L_abs( L_mult( a[i], inv_gamma_tab[i - 1] ) ) ); /* Q27 */
     231             :     }
     232           0 :     FOR( i = 9; i < 17; i++ )
     233             :     {
     234           0 :         Amax = L_max( Amax, L_abs( L_shl( L_mult( a[i], inv_gamma_tab[i - 1] ), 1 ) ) ); /* Q27 */
     235             :     }
     236           0 :     shift = norm_l( Amax );
     237           0 :     ap[0] = shl( a[0], sub( shift, 1 ) ); /* Q11 + shift */
     238           0 :     move16();
     239           0 :     FOR( i = 1; i < 9; i++ )
     240             :     {
     241           0 :         L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); /* Q27 */
     242           0 :         ap[i] = round_fx( L_shl( L_tmp, shift ) );    /* Q11 + shift */
     243           0 :         move16();
     244             :     }
     245           0 :     shift = add( shift, 1 );
     246           0 :     FOR( i = 9; i < 17; i++ )
     247             :     {
     248           0 :         L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); /* Q26 */
     249           0 :         ap[i] = round_fx( L_shl( L_tmp, shift ) );    /* Q11 + shift */
     250           0 :         move16();
     251             :     }
     252             : 
     253             : 
     254           0 :     return;
     255             : }

Generated by: LCOV version 1.14