LCOV - code coverage report
Current view: top level - lib_com - preemph_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 113 113 100.0 %
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             : #include <stdint.h>
       5             : #include "options.h" /* Compilation switches                   */
       6             : #include "prot_fx.h"
       7             : /*-------------------------------------------------------------*
       8             :  * preemph_copy_fx()
       9             :  *
      10             :  * Preemphasis: filtering through 1 - mu z^-1
      11             :  *-------------------------------------------------------------*/
      12     3766614 : void preemph_copy_fx(
      13             :     const Word16 x[], /* i  : input signal             Qx  */
      14             :     Word16 y[],       /* o  : output signal            Qx  */
      15             :     const Word16 mu,  /* i  : preemphasis coefficient  Q15 */
      16             :     const Word16 lg,  /* i  : vector size              Q0  */
      17             :     Word16 *mem       /* i/o: memory (x[-1])           Qx  */
      18             : )
      19             : {
      20             :     Word16 i, temp;
      21             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      22     3766614 :     Flag Overflow = 0;
      23     3766614 :     move32();
      24             : #endif
      25     3766614 :     temp = x[lg - 1]; /* Qx */
      26     3766614 :     move16();
      27   343311379 :     FOR( i = lg - 1; i > 0; i-- )
      28             :     {
      29   339544765 :         y[i] = msu_ro( L_deposit_h( x[i] ), x[i - 1], mu, &Overflow ); /* Qx */
      30   339544765 :         move16();
      31             :     }
      32     3766614 :     y[0] = msu_ro( L_deposit_h( x[0] ), *mem, mu, &Overflow ); /* Qx */
      33     3766614 :     move16();
      34             : 
      35     3766614 :     *mem = temp; /* Qx */
      36     3766614 :     move16();
      37     3766614 : }
      38             : 
      39     2840488 : void preemph_copy_32fx(
      40             :     const Word16 x[], /* i  : input signal             Qx  */
      41             :     Word32 y[],       /* o  : output signal            Qx  */
      42             :     const Word16 mu,  /* i  : preemphasis coefficient  Q15 */
      43             :     const Word16 lg,  /* i  : vector size              Q0  */
      44             :     Word16 *mem       /* i/o: memory (x[-1])           Qx  */
      45             : )
      46             : {
      47             :     Word16 i, temp;
      48             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      49     2840488 :     Flag Overflow = 0;
      50     2840488 :     move32();
      51             : #endif
      52     2840488 :     temp = x[lg - 1]; /* Qx */
      53     2840488 :     move16();
      54   482724019 :     FOR( i = lg - 1; i > 0; i-- )
      55             :     {
      56   479883531 :         y[i] = L_msu_o( L_deposit_h( x[i] ), x[i - 1], mu, &Overflow ); /* Qx+16 */
      57   479883531 :         move16();
      58             :     }
      59     2840488 :     y[0] = L_msu_o( L_deposit_h( x[0] ), *mem, mu, &Overflow ); /* Qx+16 */
      60     2840488 :     move16();
      61             : 
      62     2840488 :     *mem = temp; /* Qx */
      63     2840488 :     move16();
      64     2840488 : }
      65             : 
      66             : /*
      67             :  * E_UTIL_f_preemph2
      68             :  *
      69             :  * Parameters:
      70             :  *    shift          I: scale output
      71             :  *    signal       I/O: signal                          Qx/Qx+shift
      72             :  *    mu             I: preemphasis factor      Q15
      73             :  *    L              I: vector size
      74             :  *    mem          I/O: memory (x[-1])
      75             :  *
      76             :  * Function:
      77             :  *    Filtering through 1 - mu z^-1
      78             :  *
      79             :  * Returns:
      80             :  *    void
      81             :  */
      82      903126 : void E_UTIL_f_preemph2(
      83             :     Word16 shift,    /* Q0 */
      84             :     Word16 *signal,  /* Qx */
      85             :     const Word16 mu, /* Q15 */
      86             :     const Word16 lg, /* Q0 */
      87             :     Word16 *mem      /* Qx */
      88             : )
      89             : {
      90             :     Word16 i, temp;
      91             :     Word32 L_tmp;
      92             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      93      903126 :     Flag Overflow = 0;
      94      903126 :     move32();
      95             : #endif
      96      903126 :     temp = signal[lg - 1]; /* Qx */
      97      903126 :     move16();
      98             : 
      99   483525472 :     FOR( i = lg - 1; i > 0; i-- )
     100             :     {
     101   482622346 :         L_tmp = L_mult( signal[i], 16384 );                      /* Qx + 15 */
     102   482622346 :         L_tmp = L_msu0_o( L_tmp, signal[i - 1], mu, &Overflow ); /* Qx + 15 */
     103   482622346 :         L_tmp = L_shl_o( L_tmp, add( shift, 1 ), &Overflow );    /* Qx + shift + 16 */
     104   482622346 :         signal[i] = round_fx_o( L_tmp, &Overflow );              /* Qx + shift */
     105   482622346 :         move16();
     106             :     }
     107             : 
     108      903126 :     L_tmp = L_mult( signal[0], 16384 );                   /* Qx + 15 */
     109      903126 :     L_tmp = L_msu0_o( L_tmp, *mem, mu, &Overflow );       /* Qx + 15 */
     110      903126 :     L_tmp = L_shl_o( L_tmp, add( shift, 1 ), &Overflow ); /* Qx + shift + 16 */
     111      903126 :     signal[0] = round_fx_o( L_tmp, &Overflow );           /* Qx + shift */
     112      903126 :     move16();
     113             : 
     114      903126 :     *mem = temp; /* Qx */
     115      903126 :     move16();
     116             : 
     117      903126 :     return;
     118             : }
     119             : 
     120             : 
     121      215889 : Word16 E_UTIL_f_preemph3(
     122             :     Word16 *signal,  /* Qx */
     123             :     const Word16 mu, /* Q15 */
     124             :     const Word16 lg, /* Q0 */
     125             :     Word16 *mem,     /* Qx */
     126             :     Word16 bits      /* Q0 */
     127             : )
     128             : {
     129             :     Word16 i, QVal, mus, tmp_fixed, Q_new;
     130             :     Word32 L_tmp, L_maxloc;
     131             : 
     132             : 
     133      215889 :     QVal = shl( 1, sub( 15, bits ) ); /* Q15 - bits */
     134      215889 :     mus = shr( mu, bits );            /* Q15 - bits */
     135             : 
     136      215889 :     L_tmp = L_mult( signal[0], QVal ); /* Qx + Q16 - bits */
     137      215889 :     L_tmp = L_msu( L_tmp, *mem, mus ); /* Qx + Q16 - bits */
     138      215889 :     L_maxloc = L_abs( L_tmp );
     139             : 
     140   101749497 :     FOR( i = 1; i < lg; i++ )
     141             :     {
     142   101533608 :         L_tmp = L_mult( signal[i], QVal );          /* Qx + Q16 - bits */
     143   101533608 :         L_tmp = L_msu( L_tmp, signal[i - 1], mus ); /* Qx + Q16 - bits */
     144   101533608 :         L_tmp = L_abs( L_tmp );
     145   101533608 :         L_maxloc = L_max( L_tmp, L_maxloc );
     146             :     }
     147             : 
     148      215889 :     tmp_fixed = extract_h( L_maxloc ); /* Qx - bits */
     149             : 
     150      215889 :     Q_new = Q_MAX;
     151      215889 :     move16();
     152      215889 :     IF( tmp_fixed != 0 )
     153             :     {
     154      215145 :         Q_new = sub( norm_s( tmp_fixed ), bits );
     155      215145 :         Q_new = s_max( Q_new, 0 );
     156      215145 :         Q_new = s_min( Q_new, Q_MAX );
     157             :     }
     158             : 
     159      215889 :     tmp_fixed = signal[lg - 1]; /* Qx */
     160      215889 :     move16();
     161             : 
     162   101749497 :     FOR( i = lg - 1; i > 0; i-- )
     163             :     {
     164   101533608 :         L_tmp = L_mult( signal[i], QVal );          /* Qx + Q16 - bits */
     165   101533608 :         L_tmp = L_msu( L_tmp, signal[i - 1], mus ); /* Qx + Q16 - bits */
     166   101533608 :         L_tmp = L_shl( L_tmp, Q_new );              /* Qx + Q16 + Q_new - bits */
     167   101533608 :         signal[i] = round_fx( L_tmp );              /* Qx + Q_new - bits */
     168   101533608 :         move16();
     169             :     }
     170             : 
     171      215889 :     L_tmp = L_mult( signal[0], QVal ); /* Qx + Q16 - bits */
     172      215889 :     L_tmp = L_msu( L_tmp, *mem, mus ); /* Qx + Q16 - bits */
     173      215889 :     L_tmp = L_shl( L_tmp, Q_new );     /* Qx + Q16 + Q_new - bits */
     174      215889 :     signal[0] = round_fx( L_tmp );     /* Qx + Q_new - bits */
     175      215889 :     move16();
     176      215889 :     *mem = tmp_fixed;
     177      215889 :     move16();
     178             : 
     179      215889 :     return Q_new;
     180             : }
     181             : 
     182        3434 : Word16 E_UTIL_f_preemph3_ivas_fx(
     183             :     Word16 *signal,  /* Qx */
     184             :     const Word16 mu, /* Q15 */
     185             :     const Word16 lg, /* Q0 */
     186             :     Word16 *mem,     /* Qx */
     187             :     Word16 bits      /* Q0 */
     188             : )
     189             : {
     190             :     Word16 i, QVal, mus, tmp_fixed, Q_new;
     191             :     Word32 L_tmp, L_maxloc;
     192             : 
     193             : 
     194        3434 :     QVal = shl( 1, sub( 15, bits ) ); /* Q15 - bits */
     195        3434 :     mus = shr( mu, bits );            /* Q15 - bits */
     196             : 
     197        3434 :     L_tmp = L_mult( signal[0], QVal ); /* Qx + Q16 - bits */
     198        3434 :     L_tmp = L_msu( L_tmp, *mem, mus ); /* Qx + Q16 - bits */
     199        3434 :     L_maxloc = L_abs( L_tmp );
     200             : 
     201     2794047 :     FOR( i = 1; i < lg; i++ )
     202             :     {
     203     2790613 :         L_tmp = L_mult( signal[i], QVal );          /* Qx + Q16 - bits */
     204     2790613 :         L_tmp = L_msu( L_tmp, signal[i - 1], mus ); /* Qx + Q16 - bits */
     205     2790613 :         L_tmp = L_abs( L_tmp );
     206     2790613 :         L_maxloc = L_max( L_tmp, L_maxloc );
     207             :     }
     208             : 
     209        3434 :     tmp_fixed = extract_h( L_maxloc ); /* Qx - bits */
     210             : 
     211        3434 :     Q_new = Q_MAX;
     212        3434 :     move16();
     213        3434 :     IF( tmp_fixed != 0 )
     214             :     {
     215        2757 :         Q_new = sub( norm_s( tmp_fixed ), bits );
     216        2757 :         Q_new = s_max( Q_new, 0 );
     217        2757 :         Q_new = sub( s_min( Q_new, Q_MAX ), 1 );
     218             :     }
     219             : 
     220        3434 :     tmp_fixed = signal[lg - 1];
     221        3434 :     move16();
     222             : 
     223     2794047 :     FOR( i = sub( lg, 1 ); i > 0; i-- )
     224             :     {
     225     2790613 :         L_tmp = L_mult( signal[i], QVal );          /* Qx + Q16 - bits */
     226     2790613 :         L_tmp = L_msu( L_tmp, signal[i - 1], mus ); /* Qx + Q16 - bits */
     227     2790613 :         L_tmp = L_shl( L_tmp, Q_new );              /* Qx + Q16 + Q_new - bits */
     228     2790613 :         signal[i] = round_fx( L_tmp );              /* Qx + Q_new - bits */
     229     2790613 :         move16();
     230             :     }
     231             : 
     232        3434 :     L_tmp = L_mult( signal[0], QVal ); /* Qx + Q16 - bits */
     233        3434 :     L_tmp = L_msu( L_tmp, *mem, mus ); /* Qx + Q16 - bits */
     234        3434 :     L_tmp = L_shl( L_tmp, Q_new );     /* Qx + Q_new + Q16 - bits */
     235        3434 :     signal[0] = round_fx( L_tmp );     /* Qx + Q_new - bits */
     236        3434 :     move16();
     237        3434 :     *mem = tmp_fixed;
     238        3434 :     move16();
     239             : 
     240        3434 :     return Q_new;
     241             : }

Generated by: LCOV version 1.14