LCOV - code coverage report
Current view: top level - lib_enc - vlpc_2st_cod_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3ea8505de0a48ae0f5675c28be980f7a28fcc88e Lines: 58 62 93.5 %
Date: 2025-06-02 03:16:20 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      110983 : 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             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      34      110983 :     Flag Overflow = 0;
      35      110983 :     move32();
      36             : #endif
      37             : 
      38             : 
      39             :     /* 0 bit with true weighting: save 0.5 bit */
      40      110983 :     lsf_weight_2st( lsf, w, 1 ); /*w:0Q15*1.28*/
      41             : 
      42     1775728 :     FOR( i = 1; i < M; i++ )
      43             :     {
      44     1664745 :         x[i] = divide1616( shr( sub( lsf[i], lsfq[i] ), 2 ), w[i] ); /*5Q10*/
      45     1664745 :         move16();
      46             :     }
      47      110983 :     i = shr( sub( lsf[0], lsfq[0] ), 2 ); /*5Q10*/
      48      110983 :     IF( w[0] != 0 )
      49             :     {
      50      110983 :         i = shl( mult_r( i, 20972 ), 1 ); /*5Q10*1.28*/
      51      110983 :         i = divide1616( i, w[0] );        /*5Q10*/
      52             :     }
      53      110983 :     x[0] = i; /*5Q10*/
      54      110983 :     move16();
      55             : 
      56      110983 :     L_tmp = L_mult( x[0], x[0] );  /*10Q21*/
      57             :     BASOP_SATURATE_WARNING_OFF_EVS /* Allow saturate because we only need to know if the result is smaller than 8.0f */
      58     1775728 :     FOR( i = 1; i < M; i++ )
      59             :     {
      60     1664745 :         L_tmp = L_mac_o( L_tmp, x[i], x[i], &Overflow ); /*10Q21*/
      61             :     }
      62             :     BASOP_SATURATE_WARNING_ON_EVS
      63             : 
      64      110983 :     IF( LT_32( L_tmp, 16777216l /*8.0f Q21*/ ) ) /*tmp40 < 8.0f */
      65             :     {
      66          14 :         indx[0] = 0;
      67          14 :         move16();
      68          14 :         indx[1] = 0;
      69          14 :         move16();
      70             : 
      71             :         /* the following assignments are excluded from the complexity count
      72             :            due to temporaray change of the type of the return value
      73             :            (nbits -> wops) */
      74          14 :         nbits = 6; /* 2*(2+1) */
      75          14 :         move16();
      76          14 :         test();
      77          14 :         IF( ( mode == 0 ) || ( EQ_16( mode, 3 ) ) )
      78             :         {
      79          14 :             nbits = 10; /* 2*(2+3) */
      80          14 :             move16();
      81             :         }
      82           0 :         ELSE IF( EQ_16( mode, 1 ) )
      83             :         {
      84           0 :             nbits = 2; /* 2*1 */
      85           0 :             move16();
      86             :         }
      87             : 
      88          14 :         return nbits;
      89             :     }
      90             : 
      91             :     /* weighting from the 1st stage */
      92      110969 :     lsf_weight_2st( lsfq, w, mode );
      93             : 
      94             :     /* find lsf and scale the residual */
      95     1886473 :     FOR( i = 0; i < M; i++ )
      96             :     {
      97             :         /* limit to range [-32767+1024+2048;32767-1024-2048] to guarantee enough headroom in quantizer */
      98     1775504 :         x[i] = s_max( s_min( divide1616( shr( sub( lsf[i], lsfq[i] ), 2 ), w[i] ), 32767 - 1024 - 2048 ), -32767 + 1024 + 2048 ); /*5Q10*/
      99     1775504 :         move16();
     100             :     }
     101             : 
     102             :     /* quantize */
     103      110969 :     AVQ_cod_lpc_fx( x, xq, indx, 2 );
     104             : 
     105             :     /* quantized lsf */
     106     1886473 :     FOR( i = 0; i < M; i++ )
     107             :     {
     108             :         /*lsfq[i] += (w[i]*(float)xq[i]);*/
     109     1775504 :         lsfq[i] = add( lsfq[i], shl( mult_r( w[i], xq[i] ), 2 ) ); /*14Q1*1.28*/
     110     1775504 :         move16();
     111             :     }
     112             : 
     113             :     /* total number of bits using entropic code to index the quantizer number */
     114      110969 :     nbits = 0;
     115      110969 :     move16();
     116      332907 :     FOR( i = 0; i < 2; i++ )
     117             :     {
     118      221938 :         nq = indx[i];
     119      221938 :         move16();
     120             : 
     121             :         /*nbits += (2+(nq*4));*/
     122      221938 :         nbits = add( nbits, add( 2, shl( nq, 2 ) ) ); /* 2 bits to specify Q2,Q3,Q4,ext; nbits += (2+(nq*4)); */
     123      221938 :         IF( GT_16( nq, 6 ) )
     124             :         {
     125             :             /*nbits += nq-3;*/
     126       73750 :             nbits = add( nbits, sub( nq, 3 ) ); /* unary code (Q7=1110, ...) */
     127             :         }
     128      148188 :         ELSE IF( GT_16( nq, 4 ) )
     129             :         {
     130             :             /*nbits += nq-4;*/
     131       96577 :             nbits = add( nbits, sub( nq, 4 ) ); /* Q5=0, Q6=10 */
     132             :         }
     133       51611 :         ELSE IF( nq == 0 )
     134             :         {
     135             :             /*nbits += 3;*/
     136        1891 :             nbits = add( nbits, 3 ); /* Q0=110 */
     137             :         }
     138             :     } /*FOR (i=0; i<2; i++)*/
     139             : 
     140             :     /* reorder */
     141      110969 :     sort_fx( lsfq, 0, M - 1 );
     142      110969 :     IF( EQ_32( sr_core, 16000 ) )
     143             :     {
     144         528 :         gap = 102;
     145             :     }
     146      110441 :     ELSE IF( EQ_32( sr_core, 25600 ) )
     147             :     {
     148        7262 :         gap = 64;
     149             :     }
     150      103179 :     ELSE IF( EQ_32( sr_core, 32000 ) )
     151             :     {
     152      103179 :         gap = 51;
     153             :     }
     154             :     ELSE
     155             :     {
     156           0 :         gap = 34;
     157             :     }
     158      110969 :     move16();
     159      110969 :     reorder_lsf_fx( lsfq, gap, M, INT_FS_FX );
     160             : 
     161             : 
     162      110969 :     return nbits;
     163             : }

Generated by: LCOV version 1.14