LCOV - code coverage report
Current view: top level - lib_com - residu_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ b9bfbe380d1c207f5198ba67a82398b3d313550e Lines: 57 58 98.3 %
Date: 2025-11-15 04:01:59 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : 
       5             : #include <stdint.h>
       6             : #include "options.h" /* Compilation switches                   */
       7             : #include "cnst.h"    /* Common constants                       */
       8             : #include "rom_com.h" /* Static table prototypes                */
       9             : #include "prot_fx.h"
      10             : 
      11             : /*--------------------------------------------------------------------*
      12             :  * residu_ivas_fx()
      13             :  *
      14             :  * Compute the LP residual by filtering the input speech through A(z)
      15             :  *--------------------------------------------------------------------*/
      16             : 
      17             : 
      18       93539 : void residu_ivas_fx(
      19             :     const Word16 *a, /* i  : LP filter coefficients           Q31-a_exp*/
      20             :     const Word16 a_exp,
      21             :     const Word16 m,  /* i  : order of LP filter               */
      22             :     const Word32 *x, /* i  : input signal (usually speech)    Qx*/
      23             :     Word32 *y,       /* o  : output signal (usually residual) Qx*/
      24             :     const Word16 l   /* i  : size of filtering                */
      25             : )
      26             : {
      27             :     Word32 s;
      28             :     Word16 i, j;
      29             : 
      30    26248867 :     FOR( i = 0; i < l; i++ )
      31             :     {
      32    26155328 :         s = x[i];
      33    26155328 :         move32();
      34   444640576 :         FOR( j = 1; j <= m; j++ )
      35             :         {
      36   418485248 :             s = L_add( s, L_shl( Mpy_32_16_1( x[i - j], a[j] ), sub( Q15, a_exp ) ) ); // Qx
      37             :         }
      38    26155328 :         y[i] = s;
      39    26155328 :         move32();
      40             :     }
      41             : 
      42       93539 :     return;
      43             : }
      44             : 
      45             : 
      46             : /*--------------------------------------------------------------------*
      47             :  * Residu3_lc_fx:
      48             :  *
      49             :  * Compute the LP residual by filtering the input speech through A(z)
      50             :  * Output is in Qx
      51             :  *
      52             :  * Optimized Version: Use when Past[0..m-1] is 0 & a[0] is 1 (in Q12)
      53             :  *--------------------------------------------------------------------*/
      54     2809952 : void Residu3_lc_fx(
      55             :     const Word16 a[], /* i  :   prediction coefficients                 Q12 */
      56             :     const Word16 m,   /* i  :   order of LP filter                      Q0  */
      57             :     const Word16 x[], /* i  :   input signal (usually speech)           Qx  */
      58             :     Word16 y[],       /* o  :   output signal (usually residual)        Qx  */
      59             :     const Word16 lg,  /* i  :   vector size                             Q0  */
      60             :     const Word16 shift )
      61             : {
      62             :     Word16 i, j;
      63             :     Word32 s;
      64             :     Word16 q;
      65             : 
      66     2809952 :     q = add( norm_s( a[0] ), 1 );
      67     2809952 :     if ( shift > 0 )
      68             :     {
      69      851549 :         q = add( q, shift );
      70             :     }
      71     2809952 :     *y++ = shl_sat( x[0], shift );
      72     2809952 :     move16();
      73             : 
      74    44959232 :     FOR( i = 1; i < m; i++ )
      75             :     {
      76    42149280 :         s = L_mult_sat( x[i], a[0] );
      77             :         /* Stop at i to Avoid Mults with Zeros */
      78   379343520 :         FOR( j = 1; j <= i; j++ )
      79             :         {
      80   337194240 :             s = L_mac_sat( s, x[i - j], a[j] );
      81             :         }
      82             : 
      83    42149280 :         s = L_shl_sat( s, q );
      84    42149280 :         *y++ = round_fx_sat( s );
      85             :     }
      86             : 
      87   113271616 :     FOR( ; i < lg; i++ )
      88             :     {
      89   110461664 :         s = L_mult_sat( x[i], a[0] );
      90  1877848288 :         FOR( j = 1; j <= m; j++ )
      91             :         {
      92  1767386624 :             s = L_mac_sat( s, x[i - j], a[j] );
      93             :         }
      94             : 
      95   110461664 :         s = L_shl_sat( s, q );
      96   110461664 :         *y++ = round_fx_sat( s );
      97             :     }
      98             : 
      99     2809952 :     return;
     100             : }
     101             : 
     102             : /*--------------------------------------------------------------------*
     103             :  * Residu3_10_fx:
     104             :  *
     105             :  * Compute the LP residual by filtering the input speech through A(z)
     106             :  * Output is in Qx
     107             :  *--------------------------------------------------------------------*/
     108     1295820 : void Residu3_10_fx(
     109             :     const Word16 a[], /* i :  prediction coefficients                 Q12 */
     110             :     const Word16 x[], /* i :  input signal (usually speech)           Qx  */
     111             :                       /*      (note that values x[-10..-1] are needed)    */
     112             :     Word16 y[],       /* o :  output signal (usually residual)        Qx  */
     113             :     const Word16 lg,  /* i :  vector size                             Q0  */
     114             :     const Word16 shift )
     115             : {
     116             :     Word16 i, j;
     117             :     Word32 s;
     118             :     Word64 s64;
     119             :     Word16 q;
     120     1295820 :     q = add( norm_s( a[0] ), 1 );
     121     1295820 :     if ( shift != 0 )
     122           0 :         q = add( q, shift );
     123   104961420 :     FOR( i = 0; i < lg; i++ )
     124             :     {
     125   103665600 :         s64 = 0;
     126  1243987200 :         FOR( j = 0; j <= 10; j++ )
     127             :         {
     128  1140321600 :             s64 = W_mac_16_16( s64, x[i - j], a[j] );
     129             :         }
     130   103665600 :         s = W_shl_sat_l( s64, q );
     131   103665600 :         y[i] = round_fx_sat( s );
     132             :     }
     133             : 
     134     1295820 :     return;
     135             : }
     136             : 
     137             : /*--------------------------------------------------------------------*
     138             :  * Residu3_fx:
     139             :  *
     140             :  * Compute the LP residual by filtering the input speech through A(z)
     141             :  * Output is in Qx
     142             :  *--------------------------------------------------------------------*/
     143    11002950 : void Residu3_fx(
     144             :     const Word16 a[], /* i :  prediction coefficients                 Q12 */
     145             :     const Word16 x[], /* i :  input signal (usually speech)           Qx  */
     146             :                       /*      (note that values x[-M..-1] are needed)     */
     147             :     Word16 y[],       /* o :  output signal (usually residual)        Qx  */
     148             :     const Word16 lg,  /* i :  vector size                             Q0  */
     149             :     const Word16 shift )
     150             : {
     151             :     Word16 i, j;
     152             :     Word64 s64;
     153             :     Word32 s32;
     154             :     Word16 q;
     155             : 
     156    11002950 :     q = add( norm_s( a[0] ), 1 );
     157    11002950 :     if ( shift != 0 )
     158             :     {
     159     1936363 :         q = add( q, shift );
     160             :     }
     161   873343550 :     FOR( i = 0; i < lg; i++ )
     162             :     {
     163   862340600 :         s64 = 0;
     164   862340600 :         move64();
     165 14659790200 :         FOR( j = 0; j <= 15; j++ )
     166             :         {
     167 13797449600 :             s64 = W_mac_16_16( s64, x[i - j], a[j] );
     168             :         }
     169   862340600 :         s64 = W_mac_16_16( s64, x[i - 16], a[16] );
     170   862340600 :         s32 = W_shl_sat_l( s64, q );
     171   862340600 :         y[i] = round_fx_sat( s32 );
     172   862340600 :         move16();
     173             :     }
     174             : 
     175    11002950 :     return;
     176             : }
     177             : 
     178             : /*==========================================================================*/
     179             : /* FUNCTION      :     void calc_residu()                                   */
     180             : /*--------------------------------------------------------------------------*/
     181             : /* PURPOSE       : Compute the LP residual by filtering the input through   */
     182             : /*                                                    A(z) in all subframes */
     183             : /*--------------------------------------------------------------------------*/
     184             : /* INPUT ARGUMENTS  :                                                       */
     185             : /* Word16 *speech          i  : weighted speech signal                  Qx  */
     186             : /* Word16 L_frame          i  : order of LP filter                      Q0  */
     187             : /* Word16 *p_Aq            i  : quantized LP filter coefficients        Q12 */
     188             : /*--------------------------------------------------------------------------*/
     189             : /* OUTPUT ARGUMENTS :                                                       */
     190             : /* Word16 *res             o  : residual signal                        Qx+1 */
     191             : /*--------------------------------------------------------------------------*/
     192             : /* INPUT/OUTPUT ARGUMENTS :                                                 */
     193             : /*--------------------------------------------------------------------------*/
     194             : /* RETURN ARGUMENTS :                                                       */
     195             : /*                     _ None                                               */
     196             : /*--------------------------------------------------------------------------*/
     197             : /* CALLED FROM :                                                            */
     198             : /*==========================================================================*/
     199             : 
     200      193792 : void calc_residu_fx(
     201             :     Encoder_State *st,    /* i/o: state structure                           */
     202             :     const Word16 *speech, /* i  : weighted speech signal                    Qx*/
     203             :     Word16 *res,          /* o  : residual signal                           Qx+1*/
     204             :     const Word16 *p_Aq    /* i  : quantized LP filter coefficients          Q12*/
     205             : )
     206             : {
     207             :     Word16 i_subfr;
     208             : 
     209     1061295 :     FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR )
     210             :     {
     211             :         /* calculate the residual signal */
     212      867503 :         Residu3_fx( p_Aq, &speech[i_subfr], &res[i_subfr], L_SUBFR, 1 );
     213             : 
     214             :         /* next subframe */
     215      867503 :         p_Aq += ( M + 1 );
     216             :     }
     217      193792 :     return;
     218             : }

Generated by: LCOV version 1.14