LCOV - code coverage report
Current view: top level - lib_com - residu_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ 3fe45f3a13339b229bdd4169e742797bb5eb1c89 Lines: 57 58 98.3 %
Date: 2025-10-25 03:16:37 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       79428 : 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    22335172 :     FOR( i = 0; i < l; i++ )
      31             :     {
      32    22255744 :         s = x[i];
      33    22255744 :         move32();
      34   378347648 :         FOR( j = 1; j <= m; j++ )
      35             :         {
      36   356091904 :             s = L_add( s, L_shl( Mpy_32_16_1( x[i - j], a[j] ), sub( Q15, a_exp ) ) ); // Qx
      37             :         }
      38    22255744 :         y[i] = s;
      39    22255744 :         move32();
      40             :     }
      41             : 
      42       79428 :     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     2222210 : 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     2222210 :     q = add( norm_s( a[0] ), 1 );
      67     2222210 :     if ( shift > 0 )
      68             :     {
      69      683379 :         q = add( q, shift );
      70             :     }
      71     2222210 :     *y++ = shl_sat( x[0], shift );
      72     2222210 :     move16();
      73             : 
      74    35555360 :     FOR( i = 1; i < m; i++ )
      75             :     {
      76    33333150 :         s = L_mult_sat( x[i], a[0] );
      77             :         /* Stop at i to Avoid Mults with Zeros */
      78   299998350 :         FOR( j = 1; j <= i; j++ )
      79             :         {
      80   266665200 :             s = L_mac_sat( s, x[i - j], a[j] );
      81             :         }
      82             : 
      83    33333150 :         s = L_shl_sat( s, q );
      84    33333150 :         *y++ = round_fx_sat( s );
      85             :     }
      86             : 
      87    89334370 :     FOR( ; i < lg; i++ )
      88             :     {
      89    87112160 :         s = L_mult_sat( x[i], a[0] );
      90  1480906720 :         FOR( j = 1; j <= m; j++ )
      91             :         {
      92  1393794560 :             s = L_mac_sat( s, x[i - j], a[j] );
      93             :         }
      94             : 
      95    87112160 :         s = L_shl_sat( s, q );
      96    87112160 :         *y++ = round_fx_sat( s );
      97             :     }
      98             : 
      99     2222210 :     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     1014660 : 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     1014660 :     q = add( norm_s( a[0] ), 1 );
     121     1014660 :     if ( shift != 0 )
     122           0 :         q = add( q, shift );
     123    82187460 :     FOR( i = 0; i < lg; i++ )
     124             :     {
     125    81172800 :         s64 = 0;
     126   974073600 :         FOR( j = 0; j <= 10; j++ )
     127             :         {
     128   892900800 :             s64 = W_mac_16_16( s64, x[i - j], a[j] );
     129             :         }
     130    81172800 :         s = W_shl_sat_l( s64, q );
     131    81172800 :         y[i] = round_fx_sat( s );
     132             :     }
     133             : 
     134     1014660 :     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     9281120 : 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     9281120 :     q = add( norm_s( a[0] ), 1 );
     157     9281120 :     if ( shift != 0 )
     158             :     {
     159     1578223 :         q = add( q, shift );
     160             :     }
     161   733193885 :     FOR( i = 0; i < lg; i++ )
     162             :     {
     163   723912765 :         s64 = 0;
     164   723912765 :         move64();
     165 12306517005 :         FOR( j = 0; j <= 15; j++ )
     166             :         {
     167 11582604240 :             s64 = W_mac_16_16( s64, x[i - j], a[j] );
     168             :         }
     169   723912765 :         s64 = W_mac_16_16( s64, x[i - 16], a[16] );
     170   723912765 :         s32 = W_shl_sat_l( s64, q );
     171   723912765 :         y[i] = round_fx_sat( s32 );
     172   723912765 :         move16();
     173             :     }
     174             : 
     175     9281120 :     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      158757 : 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      868331 :     FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR )
     210             :     {
     211             :         /* calculate the residual signal */
     212      709574 :         Residu3_fx( p_Aq, &speech[i_subfr], &res[i_subfr], L_SUBFR, 1 );
     213             : 
     214             :         /* next subframe */
     215      709574 :         p_Aq += ( M + 1 );
     216             :     }
     217      158757 :     return;
     218             : }

Generated by: LCOV version 1.14