LCOV - code coverage report
Current view: top level - lib_enc - vlpc_2st_cod_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ e95243e9e67ddeb69dddf129509de1b3d95b402e Lines: 56 60 93.3 %
Date: 2025-09-14 03:13:15 Functions: 1 1 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"
       7             : #include "cnst.h"
       8             : #include "options.h"
       9             : //#include "prot_fx.h"
      10             : #include "prot_fx.h"     /* Function prototypes                    */
      11             : #include "prot_fx_enc.h" /* Function prototypes                    */
      12             : #include "basop_util.h"
      13             : 
      14             : /*------------------------------------------------------------------*
      15             :  * vlpc_2st_cod_fx()
      16             :  *
      17             :  *
      18             :  *------------------------------------------------------------------*/
      19             : 
      20      111007 : Word16 vlpc_2st_cod_fx(                      /* output: number of allocated bits                                    */
      21             :                         const Word16 *lsf,   /* i  : normalized vector to quantize  (14Q1*1.28) */
      22             :                         Word16 *lsfq,        /* i/o: i:1st stage   o:1st+2nd stage  (14Q1*1.28) */
      23             :                         Word16 *indx,        /* o  : index[] (4 bits per words)   Q0 */
      24             :                         const Word16 mode,   /* i  : 0=abs, >0=rel                   */
      25             :                         const Word32 sr_core /* i  : internal sampling rate          */
      26             : )
      27             : {
      28             :     Word16 i, nbits;
      29             :     Word16 w[M], x[M];
      30             :     Word16 nq, xq[M];
      31             :     Word32 L_tmp;
      32             :     Word16 gap;
      33             : #ifndef ISSUE_1867_replace_overflow_libenc
      34             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      35             :     Flag Overflow = 0;
      36             :     move32();
      37             : #endif
      38             : #endif
      39             : 
      40             : 
      41             :     /* 0 bit with true weighting: save 0.5 bit */
      42      111007 :     lsf_weight_2st( lsf, w, 1 ); /*w:0Q15*1.28*/
      43             : 
      44     1776112 :     FOR( i = 1; i < M; i++ )
      45             :     {
      46     1665105 :         x[i] = divide1616( shr( sub( lsf[i], lsfq[i] ), 2 ), w[i] ); /*5Q10*/
      47     1665105 :         move16();
      48             :     }
      49      111007 :     i = shr( sub( lsf[0], lsfq[0] ), 2 ); /*5Q10*/
      50      111007 :     IF( w[0] != 0 )
      51             :     {
      52      111007 :         i = shl( mult_r( i, 20972 ), 1 ); /*5Q10*1.28*/
      53      111007 :         i = divide1616( i, w[0] );        /*5Q10*/
      54             :     }
      55      111007 :     x[0] = i; /*5Q10*/
      56      111007 :     move16();
      57             : 
      58      111007 :     L_tmp = L_mult( x[0], x[0] );  /*10Q21*/
      59             :     BASOP_SATURATE_WARNING_OFF_EVS /* Allow saturate because we only need to know if the result is smaller than 8.0f */
      60     1776112 :     FOR( i = 1; i < M; i++ )
      61             :     {
      62             : #ifdef ISSUE_1867_replace_overflow_libenc
      63     1665105 :         L_tmp = L_mac_sat( L_tmp, x[i], x[i] ); /*10Q21*/
      64             : #else
      65             :         L_tmp = L_mac_o( L_tmp, x[i], x[i], &Overflow ); /*10Q21*/
      66             : #endif
      67             :     }
      68             :     BASOP_SATURATE_WARNING_ON_EVS
      69             : 
      70      111007 :     IF( LT_32( L_tmp, 16777216l /*8.0f Q21*/ ) ) /*tmp40 < 8.0f */
      71             :     {
      72          14 :         indx[0] = 0;
      73          14 :         move16();
      74          14 :         indx[1] = 0;
      75          14 :         move16();
      76             : 
      77             :         /* the following assignments are excluded from the complexity count
      78             :            due to temporaray change of the type of the return value
      79             :            (nbits -> wops) */
      80          14 :         nbits = 6; /* 2*(2+1) */
      81          14 :         move16();
      82          14 :         test();
      83          14 :         IF( ( mode == 0 ) || ( EQ_16( mode, 3 ) ) )
      84             :         {
      85          14 :             nbits = 10; /* 2*(2+3) */
      86          14 :             move16();
      87             :         }
      88           0 :         ELSE IF( EQ_16( mode, 1 ) )
      89             :         {
      90           0 :             nbits = 2; /* 2*1 */
      91           0 :             move16();
      92             :         }
      93             : 
      94          14 :         return nbits;
      95             :     }
      96             : 
      97             :     /* weighting from the 1st stage */
      98      110993 :     lsf_weight_2st( lsfq, w, mode );
      99             : 
     100             :     /* find lsf and scale the residual */
     101     1886881 :     FOR( i = 0; i < M; i++ )
     102             :     {
     103             :         /* limit to range [-32767+1024+2048;32767-1024-2048] to guarantee enough headroom in quantizer */
     104     1775888 :         x[i] = s_max( s_min( divide1616( shr( sub( lsf[i], lsfq[i] ), 2 ), w[i] ), 32767 - 1024 - 2048 ), -32767 + 1024 + 2048 ); /*5Q10*/
     105     1775888 :         move16();
     106             :     }
     107             : 
     108             :     /* quantize */
     109      110993 :     AVQ_cod_lpc_fx( x, xq, indx, 2 );
     110             : 
     111             :     /* quantized lsf */
     112     1886881 :     FOR( i = 0; i < M; i++ )
     113             :     {
     114             :         /*lsfq[i] += (w[i]*(float)xq[i]);*/
     115     1775888 :         lsfq[i] = add( lsfq[i], shl( mult_r( w[i], xq[i] ), 2 ) ); /*14Q1*1.28*/
     116     1775888 :         move16();
     117             :     }
     118             : 
     119             :     /* total number of bits using entropic code to index the quantizer number */
     120      110993 :     nbits = 0;
     121      110993 :     move16();
     122      332979 :     FOR( i = 0; i < 2; i++ )
     123             :     {
     124      221986 :         nq = indx[i];
     125      221986 :         move16();
     126             : 
     127             :         /*nbits += (2+(nq*4));*/
     128      221986 :         nbits = add( nbits, add( 2, shl( nq, 2 ) ) ); /* 2 bits to specify Q2,Q3,Q4,ext; nbits += (2+(nq*4)); */
     129      221986 :         IF( GT_16( nq, 6 ) )
     130             :         {
     131             :             /*nbits += nq-3;*/
     132       73762 :             nbits = add( nbits, sub( nq, 3 ) ); /* unary code (Q7=1110, ...) */
     133             :         }
     134      148224 :         ELSE IF( GT_16( nq, 4 ) )
     135             :         {
     136             :             /*nbits += nq-4;*/
     137       96600 :             nbits = add( nbits, sub( nq, 4 ) ); /* Q5=0, Q6=10 */
     138             :         }
     139       51624 :         ELSE IF( nq == 0 )
     140             :         {
     141             :             /*nbits += 3;*/
     142        1892 :             nbits = add( nbits, 3 ); /* Q0=110 */
     143             :         }
     144             :     } /*FOR (i=0; i<2; i++)*/
     145             : 
     146             :     /* reorder */
     147      110993 :     sort_fx( lsfq, 0, M - 1 );
     148      110993 :     IF( EQ_32( sr_core, 16000 ) )
     149             :     {
     150         528 :         gap = 102;
     151             :     }
     152      110465 :     ELSE IF( EQ_32( sr_core, 25600 ) )
     153             :     {
     154        7286 :         gap = 64;
     155             :     }
     156      103179 :     ELSE IF( EQ_32( sr_core, 32000 ) )
     157             :     {
     158      103179 :         gap = 51;
     159             :     }
     160             :     ELSE
     161             :     {
     162           0 :         gap = 34;
     163             :     }
     164      110993 :     move16();
     165      110993 :     reorder_lsf_fx( lsfq, gap, M, INT_FS_FX );
     166             : 
     167             : 
     168      110993 :     return nbits;
     169             : }

Generated by: LCOV version 1.14