LCOV - code coverage report
Current view: top level - lib_enc - corr_xh_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 574a190e3c6896c6c4ed10d7f23649709a0c4347 Lines: 45 69 65.2 %
Date: 2025-06-27 02:59:36 Functions: 2 3 66.7 %

          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"
       6             : #include "cnst.h"
       7             : //#include "prot_fx.h"
       8             : #include "prot_fx.h"     /* Function prototypes                    */
       9             : #include "prot_fx_enc.h" /* Function prototypes                    */
      10             : 
      11             : /*-------------------------------------------------------------------*
      12             :  * local constants
      13             :  * -----------------------------------------------------------------*/
      14             : 
      15             : #define NB_TRACK 4
      16             : #define STEP     NB_TRACK
      17             : 
      18             : /*-------------------------------------------------------------------*
      19             :  * corr_xh_fx:
      20             :  *
      21             :  * Compute the correlation between the target signal and the impulse
      22             :  * response of the weighted synthesis filter.
      23             :  *
      24             :  *   y[i]=sum(j=i,l-1) x[j]*h[j-i], i=0,l-1
      25             :  *-------------------------------------------------------------------*/
      26        2996 : void corr_xh_fx(
      27             :     const Word16 x[], /* i  : target signal                                   Qx*/
      28             :     Word16 dn[],      /* o  : correlation between x[] and h[]                 Qdn = Qx+j-1*/
      29             :     const Word16 h[]  /* i  : impulse response (of weighted synthesis filter) Q14*/
      30             : )
      31             : {
      32             :     Word16 i, j, k;
      33             :     Word32 L_tmp, y32[L_SUBFR], L_maxloc, L_tot;
      34             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      35        2996 :     Flag Overflow = 0;
      36        2996 :     move16();
      37             : #endif
      38             : 
      39             :     /* first keep the result on 32 bits and find absolute maximum */
      40        2996 :     L_tot = L_deposit_l( 1 );
      41             : 
      42       14980 :     FOR( k = 0; k < NB_TRACK; k++ )
      43             :     {
      44       11984 :         L_maxloc = L_deposit_l( 0 );
      45      203728 :         FOR( i = k; i < L_SUBFR; i += STEP )
      46             :         {
      47      191744 :             L_tmp = L_mac( 1L, x[i], h[0] ); /* 1 -> to avoid null dn[] Qx+15*/
      48     6231680 :             FOR( j = i; j < L_SUBFR - 1; j++ )
      49             :             {
      50     6039936 :                 L_tmp = L_mac_o( L_tmp, x[j + 1], h[j + 1 - i], &Overflow ); /*Qx+15*/
      51             :             }
      52             : 
      53      191744 :             y32[i] = L_tmp; /*Qx+15*/
      54      191744 :             move32();
      55      191744 :             L_tmp = L_abs( L_tmp );
      56      191744 :             L_maxloc = L_max( L_tmp, L_maxloc ); /*Qx+15*/
      57             :         }
      58             :         /* tot += 3*max / 8 */
      59       11984 :         L_maxloc = L_shr( L_maxloc, 2 );
      60       11984 :         L_tot = L_add_o( L_tot, L_maxloc, &Overflow );             /* +max/4 */
      61       11984 :         L_tot = L_add_o( L_tot, L_shr( L_maxloc, 1 ), &Overflow ); /* +max/8 */
      62             :     }
      63             : 
      64             :     /* Find the number of right shifts to do on y32[] so that    */
      65             :     /* 6.0 x sumation of max of dn[] in each track not saturate. */
      66             : 
      67        2996 :     j = sub( norm_l( L_tot ), 4 ); /* 4 -> 16 x tot */
      68             : 
      69      194740 :     FOR( i = 0; i < L_SUBFR; i++ )
      70             :     {
      71      191744 :         dn[i] = round_fx( L_shl( y32[i], j ) ); /*Qx+15+j-16*/
      72             :     }
      73        2996 :     return;
      74             : }
      75             : 
      76           0 : void corr_hh_ivas_fx(
      77             :     const Word16 *h, /* i  : target signal                                  e(norm_s(h1[0])+1) */
      78             :     Word16 *y,       /* o  : correlation between x[] and h[]                Q_new + 1 */
      79             :     Word16 *Qy,
      80             :     const Word16 L_subfr /* i  : length of the subframe                          Q0*/
      81             : )
      82             : {
      83             :     Word16 i, j, k;
      84             :     Word32 L_tmp, y32[L_SUBFR * 2], L_maxloc, L_tot;
      85             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      86           0 :     Flag Overflow = 0;
      87           0 :     move16();
      88             : #endif
      89             : 
      90             :     /* first keep the result on 32 bits and find absolute maximum */
      91           0 :     L_tot = L_deposit_l( 1 );
      92             : 
      93           0 :     FOR( k = 0; k < NB_TRACK; k++ )
      94             :     {
      95           0 :         L_maxloc = L_deposit_l( 0 );
      96           0 :         FOR( i = k; i < L_subfr; i += STEP )
      97             :         {
      98           0 :             L_tmp = L_mac( 1L, shr( h[i], 3 ), shr( h[0], 3 ) ); /* 1 -> to avoid null dn[] */ // 2*(15 - norm_s(h[0]) -3) - 1
      99           0 :             FOR( j = i; j < L_subfr - 1; j++ )
     100             :             {
     101           0 :                 L_tmp = L_mac_o( L_tmp, shr( h[j + 1], 3 ), shr( h[j + 1 - i], 3 ), &Overflow ); // 2*(15 - norm_s(h[0]) -3) - 1
     102             :             }
     103             : 
     104           0 :             y32[i] = L_tmp; // 2*(15 - norm_s(h[0]) -3) - 1
     105           0 :             move32();
     106           0 :             L_tmp = L_abs( L_tmp );
     107           0 :             L_maxloc = L_max( L_tmp, L_maxloc ); // 2*(15 - norm_s(h[0]) -3) - 1
     108             :         }
     109             :         /* tot += 3*max / 8 */
     110           0 :         L_maxloc = L_shr( L_maxloc, 2 );
     111           0 :         L_tot = L_add_o( L_tot, L_maxloc, &Overflow );             /* +max/4 */
     112           0 :         L_tot = L_add_o( L_tot, L_shr( L_maxloc, 1 ), &Overflow ); /* +max/8 */
     113             :     }
     114             : 
     115             :     /* Find the number of right shifts to do on y32[] so that    */
     116             :     /* 6.0 x sumation of max of dn[] in each track not saturate. */
     117             : 
     118           0 :     j = sub( norm_l( L_tot ), 4 ); /* 4 -> 16 x tot */
     119             : 
     120           0 :     FOR( i = 0; i < L_subfr; i++ )
     121             :     {
     122           0 :         y[i] = round_fx( L_shl( y32[i], j ) ); // 2*(15 - norm_s(h[0])) - 1 +j - 16
     123           0 :         move16();
     124             :     }
     125             : 
     126           0 :     *Qy = sub( add( shl( sub( 15 - 3, norm_s( h[0] ) ), 1 ), j ), 17 ); // h scaled down by 3 to avoid saturation while accumulating Ltmp
     127           0 :     move16();
     128           0 :     return;
     129             : }
     130             : 
     131      211510 : void corr_xh_ivas_fx(
     132             :     const Word16 x[], /* i  : target signal                                   Qx*/
     133             :     const Word16 Qx,
     134             :     Word16 dn[], /* o  : correlation between x[] and h[]                 Qdn*/
     135             :     Word16 *Qdn,
     136             :     const Word16 h[],    /* i  : impulse response (of weighted synthesis filter) (Q14 - norm_s(h[0]))*/
     137             :     const Word16 L_subfr /* i  : length of the subframe                          Q0*/
     138             : )
     139             : {
     140             :     Word16 i, j, k;
     141             :     Word32 L_tmp, y32[L_SUBFR * 2], L_maxloc, L_tot;
     142             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     143      211510 :     Flag Overflow = 0;
     144      211510 :     move16();
     145             : #endif
     146             : 
     147             :     /* first keep the result on 32 bits and find absolute maximum */
     148      211510 :     L_tot = L_deposit_l( 0 );
     149             : 
     150     1057550 :     FOR( k = 0; k < NB_TRACK; k++ )
     151             :     {
     152      846040 :         L_maxloc = L_deposit_l( 0 );
     153    14648280 :         FOR( i = k; i < L_subfr; i += STEP )
     154             :         {
     155    13802240 :             L_tmp = L_mac( 0, x[i], h[0] ); // Qx+(14 - norm_s(h[0])) + 1
     156   465571200 :             FOR( j = i; j < L_subfr - 1; j++ )
     157             :             {
     158   451768960 :                 L_tmp = L_mac_o( L_tmp, x[j + 1], h[j + 1 - i], &Overflow ); // Qx+(14 - norm_s(h[0])) + 1
     159             :             }
     160             : 
     161    13802240 :             y32[i] = L_tmp; // Qx+(14 - norm_s(h[0])) + 1
     162    13802240 :             move32();
     163    13802240 :             L_tmp = L_abs( L_tmp );
     164    13802240 :             L_maxloc = L_max( L_tmp, L_maxloc ); // Qx+(14 - norm_s(h[0])) +1
     165             :         }
     166             :         /* tot += 3*max / 8 */
     167      846040 :         L_maxloc = L_shr( L_maxloc, 2 );
     168      846040 :         L_tot = L_add_o( L_tot, L_maxloc, &Overflow );             /* +max/4 */
     169      846040 :         L_tot = L_add_o( L_tot, L_shr( L_maxloc, 1 ), &Overflow ); /* +max/8 */
     170             :     }
     171             : 
     172             :     /* Find the number of right shifts to do on y32[] so that    */
     173             :     /* 6.0 x sumation of max of dn[] in each track not saturate. */
     174             : 
     175      211510 :     j = sub( norm_l( L_tot ), 4 ); /* 4 -> 16 x tot */
     176             : 
     177    14013750 :     FOR( i = 0; i < L_subfr; i++ )
     178             :     {
     179    13802240 :         dn[i] = round_fx( L_shl( y32[i], j ) ); // Qx+(14 - norm_s(h[0])) + 1 +j - 16
     180    13802240 :         move16();
     181             :     }
     182             : 
     183      211510 :     *Qdn = sub( add( add( Qx, add( sub( 14, norm_s( h[0] ) ), 1 ) ), j ), 16 );
     184      211510 :     move16();
     185      211510 :     return;
     186             : }

Generated by: LCOV version 1.14