LCOV - code coverage report
Current view: top level - lib_com - pred_lt4_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 633e3f2e309758d10805ef21e0436356fe719b7a Lines: 71 71 100.0 %
Date: 2025-08-23 01:22:27 Functions: 3 3 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" /* Function prototypes                    */
      10             : 
      11             : /*-------------------------------------------------------------------*
      12             :  * Function  pred_lt4:                                               *
      13             :  *           ~~~~~~~~~                                               *
      14             :  *-------------------------------------------------------------------*
      15             :  * Compute the result of long term prediction with fractional       *
      16             :  * interpolation of resolution 1/4.                                  *
      17             :  *                                                                   *
      18             :  * On return exc[0..L_subfr-1] contains the interpolated signal      *
      19             :  *   (adaptive codebook excitation)                                  *
      20             :  *-------------------------------------------------------------------*/
      21             : 
      22      543555 : void pred_lt4_ivas_fx(
      23             :     const Word16 excI[],   /* in : excitation buffer       Q_exc*/
      24             :     Word16 excO[],         /* out: excitation buffer       Q_exc*/
      25             :     const Word16 T0,       /* input : integer pitch lag    Q0*/
      26             :     Word16 frac,           /* input : fraction of lag      Q0*/
      27             :     const Word16 L_subfr,  /* input : subframe size        Q0*/
      28             :     const Word32 *win,     /* i  : interpolation window    Q31*/
      29             :     const Word16 nb_coef,  /* i  : nb of filter coef       Q0*/
      30             :     const Word16 up_sample /* i  : up_sample               Q0*/
      31             : )
      32             : {
      33             :     Word16 i, j;
      34             :     Word32 s;
      35             :     const Word16 *x0, *x1, *x2;
      36             :     const Word32 *c1, *c2;
      37             : #ifndef ISSUE_1836_replace_overflow_libcom
      38             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      39             :     Flag Overflow = 0;
      40             :     move32();
      41             : #endif
      42             : #endif
      43      543555 :     x0 = &excI[-T0];
      44             : 
      45      543555 :     frac = negate( frac );
      46             : 
      47      543555 :     IF( frac < 0 )
      48             :     {
      49      393083 :         frac = add( frac, up_sample ); /* Q0 */
      50      393083 :         x0--;
      51             :     }
      52             : 
      53    38638935 :     FOR( j = 0; j < L_subfr; j++ )
      54             :     {
      55    38095380 :         x1 = x0++;                       /* Q_exc */
      56    38095380 :         x2 = x1 + 1;                     /* Q_exc */
      57    38095380 :         c1 = ( &win[frac] );             /* Q14 */
      58    38095380 :         c2 = ( &win[up_sample - frac] ); /* Q14 */
      59             : 
      60             :         {
      61    38095380 :             Word64 s64 = 0;
      62    38095380 :             move64();
      63   647621460 :             FOR( i = 0; i < nb_coef; i++ )
      64             :             {
      65             :                 /*s += (*x1--) * (*c1) + (*x2++) * (*c2);*/
      66   609526080 :                 s64 = W_mac_32_32( s64, L_deposit_l( *x1-- ), ( *c1 ) ); /* Q_exc + Q32 */
      67   609526080 :                 s64 = W_mac_32_32( s64, L_deposit_l( *x2++ ), ( *c2 ) ); /* Q_exc + Q32 */
      68             : 
      69   609526080 :                 c1 += up_sample;
      70   609526080 :                 c2 += up_sample;
      71             :             }
      72    38095380 :             s = W_sat_l( W_shr( s64, 16 ) ); /* Q_exc + Q16 */
      73             :         }
      74             : 
      75             : #ifdef ISSUE_1836_replace_overflow_libcom
      76    38095380 :         excO[j] = round_fx_sat( s ); /* Q_exc */
      77             : #else
      78             :         excO[j] = round_fx_o( s, &Overflow );        /* Q_exc */
      79             : #endif
      80    38095380 :         move16();
      81             :     }
      82      543555 :     return;
      83             : }
      84             : 
      85        9143 : void pred_lt4(
      86             :     const Word16 excI[],   /* in : excitation buffer       Q_exc*/
      87             :     Word16 excO[],         /* out: excitation buffer       Q_exc*/
      88             :     const Word16 T0,       /* input : integer pitch lag    Q0*/
      89             :     Word16 frac,           /* input : fraction of lag      Q0*/
      90             :     const Word16 L_subfr,  /* input : subframe size        Q0*/
      91             :     const Word16 *win,     /* i  : interpolation window    Q14*/
      92             :     const Word16 nb_coef,  /* i  : nb of filter coef       Q0*/
      93             :     const Word16 up_sample /* i  : up_sample               Q0*/
      94             : )
      95             : {
      96             :     Word16 i, j;
      97             :     Word32 s;
      98             :     const Word16 *x0, *x1, *x2, *c1, *c2;
      99             : #ifndef ISSUE_1836_replace_overflow_libcom
     100             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     101             :     Flag Overflow = 0;
     102             :     move32();
     103             : #endif
     104             : #endif
     105        9143 :     x0 = &excI[-T0];
     106             : 
     107             : 
     108        9143 :     frac = negate( frac );
     109             : 
     110        9143 :     IF( frac < 0 )
     111             :     {
     112        6024 :         frac = add( frac, up_sample ); /* Q0 */
     113        6024 :         x0--;
     114             :     }
     115             : 
     116      604206 :     FOR( j = 0; j < L_subfr; j++ )
     117             :     {
     118      595063 :         x1 = x0++;                       /* Q_exc */
     119      595063 :         x2 = x1 + 1;                     /* Q_exc */
     120      595063 :         c1 = ( &win[frac] );             /* Q14 */
     121      595063 :         c2 = ( &win[up_sample - frac] ); /* Q14 */
     122             : 
     123             :         {
     124      595063 :             Word64 s64 = 0;
     125      595063 :             move64();
     126    10312371 :             FOR( i = 0; i < nb_coef; i++ )
     127             :             {
     128             :                 /*s += (*x1--) * (*c1) + (*x2++) * (*c2);*/
     129     9717308 :                 s64 = W_mac0_16_16( s64, ( *x1-- ), ( *c1 ) ); /* Q_exc + Q14 */
     130     9717308 :                 s64 = W_mac0_16_16( s64, ( *x2++ ), ( *c2 ) ); /* Q_exc + Q14 */
     131             : 
     132     9717308 :                 c1 += up_sample;
     133     9717308 :                 c2 += up_sample;
     134             :             }
     135      595063 :             s = W_sat_l( s64 ); /* Q_exc + Q14 */
     136             :         }
     137             : #ifdef ISSUE_1836_replace_overflow_libcom
     138             : #if ( INTERP_EXP != -1 )
     139      595063 :         s = L_shl_sat( s, INTERP_EXP + 1 ); /* Q_exc + Q15 */
     140             : #endif
     141             : 
     142      595063 :         excO[j] = round_fx_sat( s ); /* Q_exc */
     143      595063 :         move16();
     144             : #else
     145             : #if ( INTERP_EXP != -1 )
     146             :         s = L_shl_o( s, INTERP_EXP + 1, &Overflow ); /* Q_exc + Q15 */
     147             : #endif
     148             : 
     149             :         excO[j] = round_fx_o( s, &Overflow ); /* Q_exc */
     150             :         move16();
     151             : #endif
     152             :     }
     153        9143 :     return;
     154             : }
     155             : 
     156             : 
     157             : /*======================================================================*/
     158             : /* FUNCTION : pred_lt4_tc_fx() */
     159             : /*-----------------------------------------------------------------------*/
     160             : /* PURPOSE :   * adapt. search of the second impulse in the same subframe (when appears) */
     161             : /* On return, exc[0..L_subfr-1] contains the interpolated signal         */
     162             : /*   (adaptive codebook excitation)                                      */
     163             : /*                                                                       */
     164             : /*-----------------------------------------------------------------------*/
     165             : /*  INPUT ARGUMENTS :                                                    */
     166             : /* _ (Word16 []) exc  : excitation buffer             Q0                 */
     167             : /* _ (Word16) L_subfr : subframe size                 Q0                 */
     168             : /* _ (Word16 ) T0 : integer pitch lag                 Q0                 */
     169             : /* _ (Word16 ) frac : fraction of lag                 Q0                 */
     170             : /* _ (Word16 ) imp_pos : glottal impulse position     Q0                 */
     171             : /* _ (Word16 *) win : Interpolation window used       Q14                */
     172             : /*-----------------------------------------------------------------------*/
     173             : /* OUTPUT ARGUMENTS :                                                    */
     174             : /* _ (Word16 []) exc  : output excitation buffer      Q0                 */
     175             : /*-----------------------------------------------------------------------*/
     176             : /* INPUT OUTPUT ARGUMENTS                                                */
     177             : /* NONE                                                                                                                                  */
     178             : /*-----------------------------------------------------------------------*/
     179             : /* RETURN ARGUMENTS :                                                    */
     180             : /* NONE                                                                  */
     181             : /*=======================================================================*/
     182       13093 : void pred_lt4_tc_fx(
     183             :     Word16 exc[],         /* i/o: excitation buffer        Q0*/
     184             :     const Word16 T0,      /* i  : integer pitch lag        Q0*/
     185             :     Word16 frac,          /* i:   fraction of lag          Q0*/
     186             :     const Word16 *win,    /* i  : interpolation window     Q14*/
     187             :     const Word16 imp_pos, /* i  : glottal impulse position Q0*/
     188             :     const Word16 i_subfr  /* i  : subframe index           Q0*/
     189             : )
     190             : {
     191             :     Word16 i, j, k, l;
     192             :     const Word16 *x0;
     193             :     Word16 excO[L_SUBFR + 1];
     194             :     Word32 L_sum;
     195             :     Word16 excI[2 * L_SUBFR];
     196             : #ifndef ISSUE_1836_replace_overflow_libcom
     197             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     198             :     Flag Overflow = 0;
     199             :     move32();
     200             : #endif
     201             : #endif
     202       13093 :     Copy( exc + sub( i_subfr, L_SUBFR ), excI, L_SUBFR * 2 ); /* Q0 */
     203             : 
     204       13093 :     test();
     205       13093 :     IF( LT_16( add( T0, sub( imp_pos, L_IMPULSE2 ) ), L_SUBFR ) && LT_16( T0, L_SUBFR ) )
     206             :     {
     207        2030 :         set16_fx( &excI[L_SUBFR - T0], 0, T0 );
     208        2030 :         set16_fx( excO, 0, L_SUBFR + 1 );
     209        2030 :         x0 = excI + ( L_SUBFR - ( L_INTERPOL2 - 1 ) );
     210             : 
     211        2030 :         IF( frac > 0 )
     212             :         {
     213         985 :             frac = sub( frac, UP_SAMP ); /* Q0 */
     214         985 :             x0--;
     215             :         }
     216             : 
     217        2030 :         l = add( UP_SAMP - 1, frac ); /* Q0 */
     218       39114 :         FOR( j = T0; j < L_SUBFR + 1; j++ )
     219             :         {
     220       37084 :             k = l;
     221       37084 :             move16();
     222       37084 :             L_sum = L_mult( x0[0], win[k] ); /* Q15 */
     223     1186688 :             FOR( i = 1; i < 2 * L_INTERPOL2; i++ )
     224             :             {
     225             :                 /*
     226             :                  * Here, additions with UP_SAMP are not counted
     227             :                  ki* because, the window could easily be modified
     228             :                  * so that the values needed are contiguous.
     229             :                  */
     230     1149604 :                 k += UP_SAMP;
     231     1149604 :                 L_sum = L_mac( L_sum, x0[i], win[k] ); /* Q15 */
     232             :             }
     233             : #ifdef ISSUE_1836_replace_overflow_libcom
     234       37084 :             L_sum = L_shl_sat( L_sum, 1 );   /* Q16 */
     235       37084 :             excO[j] = round_fx_sat( L_sum ); /* Q0 */
     236             : #else
     237             :             L_sum = L_shl_o( L_sum, 1, &Overflow );                                                   /* Q16 */
     238             :             excO[j] = round_fx_o( L_sum, &Overflow );                                                 /* Q0 */
     239             : #endif
     240             : 
     241       37084 :             move16();
     242             : 
     243       37084 :             x0++;
     244             :         }
     245       37084 :         FOR( i = T0; i < L_SUBFR; i++ )
     246             :         {
     247             : #ifdef ISSUE_1836_replace_overflow_libcom
     248       35054 :             exc[i + i_subfr] = add_sat( exc[i + i_subfr], mult_r( PIT_SHARP_fx, excO[i] ) ); /* Q0 */
     249             : #else
     250             :             exc[i + i_subfr] = add_o( exc[i + i_subfr], mult_r( PIT_SHARP_fx, excO[i] ), &Overflow ); /* Q0 */
     251             : #endif
     252       35054 :             move16();
     253             :         }
     254             :     }
     255             : 
     256       13093 :     return;
     257             : }

Generated by: LCOV version 1.14