LCOV - code coverage report
Current view: top level - lib_com - residu_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 61 62 98.4 %
Date: 2025-05-03 01:55:50 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       71115 : 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    20198475 :     FOR( i = 0; i < l; i++ )
      31             :     {
      32    20127360 :         s = x[i];
      33    20127360 :         move32();
      34   342165120 :         FOR( j = 1; j <= m; j++ )
      35             :         {
      36   322037760 :             s = L_add( s, L_shl( Mpy_32_16_1( x[i - j], a[j] ), sub( Q15, a_exp ) ) ); // Qx
      37             :         }
      38    20127360 :         y[i] = s;
      39    20127360 :         move32();
      40             :     }
      41             : 
      42       71115 :     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     2153671 : 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             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      66     2153671 :     Flag Overflow = 0;
      67     2153671 :     move16();
      68             : #endif
      69             : 
      70     2153671 :     q = add( norm_s( a[0] ), 1 );
      71     2153671 :     if ( shift > 0 )
      72             :     {
      73      677529 :         q = add( q, shift );
      74             :     }
      75     2153671 :     *y++ = shl_o( x[0], shift, &Overflow );
      76     2153671 :     move16();
      77             : 
      78    34458736 :     FOR( i = 1; i < m; i++ )
      79             :     {
      80    32305065 :         s = L_mult_o( x[i], a[0], &Overflow );
      81             :         /* Stop at i to Avoid Mults with Zeros */
      82   290745585 :         FOR( j = 1; j <= i; j++ )
      83             :         {
      84   258440520 :             s = L_mac_o( s, x[i - j], a[j], &Overflow );
      85             :         }
      86             : 
      87    32305065 :         s = L_shl_o( s, q, &Overflow );
      88    32305065 :         *y++ = round_fx_o( s, &Overflow );
      89             :     }
      90             : 
      91    84989783 :     FOR( ; i < lg; i++ )
      92             :     {
      93    82836112 :         s = L_mult_o( x[i], a[0], &Overflow );
      94  1408213904 :         FOR( j = 1; j <= m; j++ )
      95             :         {
      96  1325377792 :             s = L_mac_o( s, x[i - j], a[j], &Overflow );
      97             :         }
      98             : 
      99    82836112 :         s = L_shl_o( s, q, &Overflow );
     100    82836112 :         *y++ = round_fx_o( s, &Overflow );
     101             :     }
     102     2153671 : }
     103             : 
     104             : /*--------------------------------------------------------------------*
     105             :  * Residu3_10_fx:
     106             :  *
     107             :  * Compute the LP residual by filtering the input speech through A(z)
     108             :  * Output is in Qx
     109             :  *--------------------------------------------------------------------*/
     110      967708 : void Residu3_10_fx(
     111             :     const Word16 a[], /* i :  prediction coefficients                 Q12 */
     112             :     const Word16 x[], /* i :  input signal (usually speech)           Qx  */
     113             :                       /*      (note that values x[-10..-1] are needed)    */
     114             :     Word16 y[],       /* o :  output signal (usually residual)        Qx  */
     115             :     const Word16 lg,  /* i :  vector size                             Q0  */
     116             :     const Word16 shift )
     117             : {
     118             :     Word16 i, j;
     119             :     Word32 s;
     120             :     Word64 s64;
     121             :     Word16 q;
     122      967708 :     q = add( norm_s( a[0] ), 1 );
     123      967708 :     if ( shift != 0 )
     124           0 :         q = add( q, shift );
     125    78384348 :     FOR( i = 0; i < lg; i++ )
     126             :     {
     127    77416640 :         s64 = 0;
     128   928999680 :         FOR( j = 0; j <= 10; j++ )
     129             :         {
     130   851583040 :             s64 = W_mac_16_16( s64, x[i - j], a[j] );
     131             :         }
     132    77416640 :         s = W_shl_sat_l( s64, q );
     133    77416640 :         y[i] = round_fx_sat( s );
     134             :     }
     135      967708 : }
     136             : /*--------------------------------------------------------------------*
     137             :  * Residu3_fx:
     138             :  *
     139             :  * Compute the LP residual by filtering the input speech through A(z)
     140             :  * Output is in Qx
     141             :  *--------------------------------------------------------------------*/
     142     9080514 : void Residu3_fx(
     143             :     const Word16 a[], /* i :  prediction coefficients                 Q12 */
     144             :     const Word16 x[], /* i :  input signal (usually speech)           Qx  */
     145             :                       /*      (note that values x[-M..-1] are needed)     */
     146             :     Word16 y[],       /* o :  output signal (usually residual)        Qx  */
     147             :     const Word16 lg,  /* i :  vector size                             Q0  */
     148             :     const Word16 shift )
     149             : {
     150             :     Word16 i, j;
     151             :     Word64 s64;
     152             :     Word32 s32;
     153             :     Word16 q;
     154             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     155     9080514 :     Flag Overflow = 0;
     156     9080514 :     move16();
     157             : #endif
     158     9080514 :     q = add( norm_s( a[0] ), 1 );
     159     9080514 :     IF( shift != 0 )
     160             :     {
     161     1528288 :         q = add( q, shift );
     162             :     }
     163   715838710 :     FOR( i = 0; i < lg; i++ )
     164             :     {
     165   706758196 :         s64 = 0;
     166   706758196 :         move64();
     167 12014889332 :         FOR( j = 0; j <= 15; j++ )
     168             :         {
     169 11308131136 :             s64 = W_mac_16_16( s64, x[i - j], a[j] );
     170             :         }
     171   706758196 :         s64 = W_mac_16_16( s64, x[i - 16], a[16] );
     172   706758196 :         s32 = W_shl_sat_l( s64, q );
     173   706758196 :         y[i] = round_fx_o( s32, &Overflow );
     174   706758196 :         move16();
     175             :     }
     176     9080514 : }
     177             : /*==========================================================================*/
     178             : /* FUNCTION      :      void calc_residu()                                                                          */
     179             : /*--------------------------------------------------------------------------*/
     180             : /* PURPOSE       : Compute the LP residual by filtering the input through       */
     181             : /*                                                                                                      A(z) in all subframes   */
     182             : /*--------------------------------------------------------------------------*/
     183             : /* INPUT ARGUMENTS  :                                                                                                           */
     184             : /* Word16 *speech          i  : weighted speech signal                  Qx  */
     185             : /* Word16 L_frame          i  : order of LP filter                                              Q0  */
     186             : /* Word16 *p_Aq            i  : quantized LP filter coefficients        Q12 */
     187             : /*--------------------------------------------------------------------------*/
     188             : /* OUTPUT ARGUMENTS :                                                                                                           */
     189             : /* Word16 *res             o  : residual signal                        Qx+1 */
     190             : /*--------------------------------------------------------------------------*/
     191             : /* INPUT/OUTPUT ARGUMENTS :                                                                                                     */
     192             : /*--------------------------------------------------------------------------*/
     193             : /* RETURN ARGUMENTS :                                                                                                           */
     194             : /*                                       _ None                                                                                                 */
     195             : /*--------------------------------------------------------------------------*/
     196             : /* CALLED FROM :                                                                                                                        */
     197             : /*==========================================================================*/
     198             : 
     199      157969 : void calc_residu_fx(
     200             :     Encoder_State *st,    /* i/o: state structure                           */
     201             :     const Word16 *speech, /* i  : weighted speech signal                    Qx*/
     202             :     Word16 *res,          /* o  : residual signal                           Qx+1*/
     203             :     const Word16 *p_Aq    /* i  : quantized LP filter coefficients          Q12*/
     204             : )
     205             : {
     206             :     Word16 i_subfr;
     207             : 
     208      864251 :     FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR )
     209             :     {
     210             :         /* calculate the residual signal */
     211      706282 :         Residu3_fx( p_Aq, &speech[i_subfr], &res[i_subfr], L_SUBFR, 1 );
     212             : 
     213             :         /* next subframe */
     214      706282 :         p_Aq += ( M + 1 );
     215             :     }
     216      157969 :     return;
     217             : }

Generated by: LCOV version 1.14