LCOV - code coverage report
Current view: top level - lib_com - residu_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 633e3f2e309758d10805ef21e0436356fe719b7a Lines: 52 58 89.7 %
Date: 2025-08-23 01:22:27 Functions: 4 5 80.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       63660 : 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    18282540 :     FOR( i = 0; i < l; i++ )
      31             :     {
      32    18218880 :         s = x[i];
      33    18218880 :         move32();
      34   309720960 :         FOR( j = 1; j <= m; j++ )
      35             :         {
      36   291502080 :             s = L_add( s, L_shl( Mpy_32_16_1( x[i - j], a[j] ), sub( Q15, a_exp ) ) ); // Qx
      37             :         }
      38    18218880 :         y[i] = s;
      39    18218880 :         move32();
      40             :     }
      41             : 
      42       63660 :     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      474243 : 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             : #ifndef ISSUE_1836_replace_overflow_libcom
      66             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      67             :     Flag Overflow = 0;
      68             :     move16();
      69             : #endif
      70             : #endif
      71             : 
      72      474243 :     q = add( norm_s( a[0] ), 1 );
      73      474243 :     if ( shift > 0 )
      74             :     {
      75        8504 :         q = add( q, shift );
      76             :     }
      77             : #ifdef ISSUE_1836_replace_overflow_libcom
      78      474243 :     *y++ = shl_sat( x[0], shift );
      79      474243 :     move16();
      80             : 
      81     7587888 :     FOR( i = 1; i < m; i++ )
      82             :     {
      83     7113645 :         s = L_mult_sat( x[i], a[0] );
      84             :         /* Stop at i to Avoid Mults with Zeros */
      85    64022805 :         FOR( j = 1; j <= i; j++ )
      86             :         {
      87    56909160 :             s = L_mac_sat( s, x[i - j], a[j] );
      88             :         }
      89             : 
      90     7113645 :         s = L_shl_sat( s, q );
      91     7113645 :         *y++ = round_fx_sat( s );
      92             :     }
      93             : 
      94    23237907 :     FOR( ; i < lg; i++ )
      95             :     {
      96    22763664 :         s = L_mult_sat( x[i], a[0] );
      97   386982288 :         FOR( j = 1; j <= m; j++ )
      98             :         {
      99   364218624 :             s = L_mac_sat( s, x[i - j], a[j] );
     100             :         }
     101             : 
     102    22763664 :         s = L_shl_sat( s, q );
     103    22763664 :         *y++ = round_fx_sat( s );
     104             :     }
     105             : 
     106             : #else
     107             :     *y++ = shl_o( x[0], shift, &Overflow );
     108             :     move16();
     109             : 
     110             :     FOR( i = 1; i < m; i++ )
     111             :     {
     112             :         s = L_mult_o( x[i], a[0], &Overflow );
     113             :         /* Stop at i to Avoid Mults with Zeros */
     114             :         FOR( j = 1; j <= i; j++ )
     115             :         {
     116             :             s = L_mac_o( s, x[i - j], a[j], &Overflow );
     117             :         }
     118             : 
     119             :         s = L_shl_o( s, q, &Overflow );
     120             :         *y++ = round_fx_o( s, &Overflow );
     121             :     }
     122             : 
     123             :     FOR( ; i < lg; i++ )
     124             :     {
     125             :         s = L_mult_o( x[i], a[0], &Overflow );
     126             :         FOR( j = 1; j <= m; j++ )
     127             :         {
     128             :             s = L_mac_o( s, x[i - j], a[j], &Overflow );
     129             :         }
     130             : 
     131             :         s = L_shl_o( s, q, &Overflow );
     132             :         *y++ = round_fx_o( s, &Overflow );
     133             :     }
     134             : 
     135             : #endif
     136      474243 : }
     137             : 
     138             : /*--------------------------------------------------------------------*
     139             :  * Residu3_10_fx:
     140             :  *
     141             :  * Compute the LP residual by filtering the input speech through A(z)
     142             :  * Output is in Qx
     143             :  *--------------------------------------------------------------------*/
     144      408188 : void Residu3_10_fx(
     145             :     const Word16 a[], /* i :  prediction coefficients                 Q12 */
     146             :     const Word16 x[], /* i :  input signal (usually speech)           Qx  */
     147             :                       /*      (note that values x[-10..-1] are needed)    */
     148             :     Word16 y[],       /* o :  output signal (usually residual)        Qx  */
     149             :     const Word16 lg,  /* i :  vector size                             Q0  */
     150             :     const Word16 shift )
     151             : {
     152             :     Word16 i, j;
     153             :     Word32 s;
     154             :     Word64 s64;
     155             :     Word16 q;
     156      408188 :     q = add( norm_s( a[0] ), 1 );
     157      408188 :     if ( shift != 0 )
     158           0 :         q = add( q, shift );
     159    33063228 :     FOR( i = 0; i < lg; i++ )
     160             :     {
     161    32655040 :         s64 = 0;
     162   391860480 :         FOR( j = 0; j <= 10; j++ )
     163             :         {
     164   359205440 :             s64 = W_mac_16_16( s64, x[i - j], a[j] );
     165             :         }
     166    32655040 :         s = W_shl_sat_l( s64, q );
     167    32655040 :         y[i] = round_fx_sat( s );
     168             :     }
     169      408188 : }
     170             : /*--------------------------------------------------------------------*
     171             :  * Residu3_fx:
     172             :  *
     173             :  * Compute the LP residual by filtering the input speech through A(z)
     174             :  * Output is in Qx
     175             :  *--------------------------------------------------------------------*/
     176      824072 : void Residu3_fx(
     177             :     const Word16 a[], /* i :  prediction coefficients                 Q12 */
     178             :     const Word16 x[], /* i :  input signal (usually speech)           Qx  */
     179             :                       /*      (note that values x[-M..-1] are needed)     */
     180             :     Word16 y[],       /* o :  output signal (usually residual)        Qx  */
     181             :     const Word16 lg,  /* i :  vector size                             Q0  */
     182             :     const Word16 shift )
     183             : {
     184             :     Word16 i, j;
     185             :     Word64 s64;
     186             :     Word32 s32;
     187             :     Word16 q;
     188             : #ifndef ISSUE_1836_replace_overflow_libcom
     189             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     190             :     Flag Overflow = 0;
     191             :     move16();
     192             : #endif
     193             : #endif
     194      824072 :     q = add( norm_s( a[0] ), 1 );
     195      824072 :     if ( shift != 0 )
     196             :     {
     197      804805 :         q = add( q, shift );
     198             :     }
     199    86158692 :     FOR( i = 0; i < lg; i++ )
     200             :     {
     201    85334620 :         s64 = 0;
     202    85334620 :         move64();
     203  1450688540 :         FOR( j = 0; j <= 15; j++ )
     204             :         {
     205  1365353920 :             s64 = W_mac_16_16( s64, x[i - j], a[j] );
     206             :         }
     207    85334620 :         s64 = W_mac_16_16( s64, x[i - 16], a[16] );
     208    85334620 :         s32 = W_shl_sat_l( s64, q );
     209             : #ifdef ISSUE_1836_replace_overflow_libcom
     210    85334620 :         y[i] = round_fx_sat( s32 );
     211             : #else
     212             :         y[i] = round_fx_o( s32, &Overflow );
     213             : #endif
     214    85334620 :         move16();
     215             :     }
     216      824072 : }
     217             : /*==========================================================================*/
     218             : /* FUNCTION      :      void calc_residu()                                                                          */
     219             : /*--------------------------------------------------------------------------*/
     220             : /* PURPOSE       : Compute the LP residual by filtering the input through       */
     221             : /*                                                                                                      A(z) in all subframes   */
     222             : /*--------------------------------------------------------------------------*/
     223             : /* INPUT ARGUMENTS  :                                                                                                           */
     224             : /* Word16 *speech          i  : weighted speech signal                  Qx  */
     225             : /* Word16 L_frame          i  : order of LP filter                                              Q0  */
     226             : /* Word16 *p_Aq            i  : quantized LP filter coefficients        Q12 */
     227             : /*--------------------------------------------------------------------------*/
     228             : /* OUTPUT ARGUMENTS :                                                                                                           */
     229             : /* Word16 *res             o  : residual signal                        Qx+1 */
     230             : /*--------------------------------------------------------------------------*/
     231             : /* INPUT/OUTPUT ARGUMENTS :                                                                                                     */
     232             : /*--------------------------------------------------------------------------*/
     233             : /* RETURN ARGUMENTS :                                                                                                           */
     234             : /*                                       _ None                                                                                                 */
     235             : /*--------------------------------------------------------------------------*/
     236             : /* CALLED FROM :                                                                                                                        */
     237             : /*==========================================================================*/
     238             : 
     239           0 : void calc_residu_fx(
     240             :     Encoder_State *st,    /* i/o: state structure                           */
     241             :     const Word16 *speech, /* i  : weighted speech signal                    Qx*/
     242             :     Word16 *res,          /* o  : residual signal                           Qx+1*/
     243             :     const Word16 *p_Aq    /* i  : quantized LP filter coefficients          Q12*/
     244             : )
     245             : {
     246             :     Word16 i_subfr;
     247             : 
     248           0 :     FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR )
     249             :     {
     250             :         /* calculate the residual signal */
     251           0 :         Residu3_fx( p_Aq, &speech[i_subfr], &res[i_subfr], L_SUBFR, 1 );
     252             : 
     253             :         /* next subframe */
     254           0 :         p_Aq += ( M + 1 );
     255             :     }
     256           0 :     return;
     257             : }

Generated by: LCOV version 1.14