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 @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 69 69 100.0 %
Date: 2025-05-03 01:55:50 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             : #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        2987 : 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        2987 :     Flag Overflow = 0;
      36        2987 :     move16();
      37             : #endif
      38             : 
      39             :     /* first keep the result on 32 bits and find absolute maximum */
      40        2987 :     L_tot = L_deposit_l( 1 );
      41             : 
      42       14935 :     FOR( k = 0; k < NB_TRACK; k++ )
      43             :     {
      44       11948 :         L_maxloc = L_deposit_l( 0 );
      45      203116 :         FOR( i = k; i < L_SUBFR; i += STEP )
      46             :         {
      47      191168 :             L_tmp = L_mac( 1L, x[i], h[0] ); /* 1 -> to avoid null dn[] Qx+15*/
      48     6212960 :             FOR( j = i; j < L_SUBFR - 1; j++ )
      49             :             {
      50     6021792 :                 L_tmp = L_mac_o( L_tmp, x[j + 1], h[j + 1 - i], &Overflow ); /*Qx+15*/
      51             :             }
      52             : 
      53      191168 :             y32[i] = L_tmp; /*Qx+15*/
      54      191168 :             move32();
      55      191168 :             L_tmp = L_abs( L_tmp );
      56      191168 :             L_maxloc = L_max( L_tmp, L_maxloc ); /*Qx+15*/
      57             :         }
      58             :         /* tot += 3*max / 8 */
      59       11948 :         L_maxloc = L_shr( L_maxloc, 2 );
      60       11948 :         L_tot = L_add_o( L_tot, L_maxloc, &Overflow );             /* +max/4 */
      61       11948 :         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        2987 :     j = sub( norm_l( L_tot ), 4 ); /* 4 -> 16 x tot */
      68             : 
      69      194155 :     FOR( i = 0; i < L_SUBFR; i++ )
      70             :     {
      71      191168 :         dn[i] = round_fx( L_shl( y32[i], j ) ); /*Qx+15+j-16*/
      72             :     }
      73        2987 :     return;
      74             : }
      75             : 
      76      400416 : 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      400416 :     Flag Overflow = 0;
      87      400416 :     move16();
      88             : #endif
      89             : 
      90             :     /* first keep the result on 32 bits and find absolute maximum */
      91      400416 :     L_tot = L_deposit_l( 1 );
      92             : 
      93     2002080 :     FOR( k = 0; k < NB_TRACK; k++ )
      94             :     {
      95     1601664 :         L_maxloc = L_deposit_l( 0 );
      96    27228288 :         FOR( i = k; i < L_subfr; i += STEP )
      97             :         {
      98    25626624 :             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   832865280 :             FOR( j = i; j < L_subfr - 1; j++ )
     100             :             {
     101   807238656 :                 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    25626624 :             y32[i] = L_tmp; // 2*(15 - norm_s(h[0]) -3) - 1
     105    25626624 :             move32();
     106    25626624 :             L_tmp = L_abs( L_tmp );
     107    25626624 :             L_maxloc = L_max( L_tmp, L_maxloc ); // 2*(15 - norm_s(h[0]) -3) - 1
     108             :         }
     109             :         /* tot += 3*max / 8 */
     110     1601664 :         L_maxloc = L_shr( L_maxloc, 2 );
     111     1601664 :         L_tot = L_add_o( L_tot, L_maxloc, &Overflow );             /* +max/4 */
     112     1601664 :         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      400416 :     j = sub( norm_l( L_tot ), 4 ); /* 4 -> 16 x tot */
     119             : 
     120    26027040 :     FOR( i = 0; i < L_subfr; i++ )
     121             :     {
     122    25626624 :         y[i] = round_fx( L_shl( y32[i], j ) ); // 2*(15 - norm_s(h[0])) - 1 +j - 16
     123    25626624 :         move16();
     124             :     }
     125             : 
     126      400416 :     *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      400416 :     move16();
     128      400416 :     return;
     129             : }
     130             : 
     131      209990 : 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) (Q15 - 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      209990 :     Flag Overflow = 0;
     144      209990 :     move16();
     145             : #endif
     146             : 
     147             :     /* first keep the result on 32 bits and find absolute maximum */
     148      209990 :     L_tot = L_deposit_l( 0 );
     149             : 
     150     1049950 :     FOR( k = 0; k < NB_TRACK; k++ )
     151             :     {
     152      839960 :         L_maxloc = L_deposit_l( 0 );
     153    14549272 :         FOR( i = k; i < L_subfr; i += STEP )
     154             :         {
     155    13709312 :             L_tmp = L_mac( 0, x[i], h[0] ); // Qx+(15 - norm_s(h[0]))
     156   462829568 :             FOR( j = i; j < L_subfr - 1; j++ )
     157             :             {
     158   449120256 :                 L_tmp = L_mac_o( L_tmp, x[j + 1], h[j + 1 - i], &Overflow ); // Qx+(15 - norm_s(h[0]))
     159             :             }
     160             : 
     161    13709312 :             y32[i] = L_tmp; // Qx+(15 - norm_s(h[0]))
     162    13709312 :             move32();
     163    13709312 :             L_tmp = L_abs( L_tmp );
     164    13709312 :             L_maxloc = L_max( L_tmp, L_maxloc ); // Qx+(15 - norm_s(h[0]))
     165             :         }
     166             :         /* tot += 3*max / 8 */
     167      839960 :         L_maxloc = L_shr( L_maxloc, 2 );
     168      839960 :         L_tot = L_add_o( L_tot, L_maxloc, &Overflow );             /* +max/4 */
     169      839960 :         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      209990 :     j = sub( norm_l( L_tot ), 4 ); /* 4 -> 16 x tot */
     176             : 
     177    13919302 :     FOR( i = 0; i < L_subfr; i++ )
     178             :     {
     179    13709312 :         dn[i] = round_fx( L_shl( y32[i], j ) ); // Qx+(15 - norm_s(h[0])) +j - 16
     180    13709312 :         move16();
     181             :     }
     182             : 
     183      209990 :     *Qdn = sub( add( add( Qx, sub( 15, norm_s( h[0] ) ) ), j ), 16 );
     184      209990 :     move16();
     185      209990 :     return;
     186             : }

Generated by: LCOV version 1.14