LCOV - code coverage report
Current view: top level - lib_com - bitallocsum_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 26 26 100.0 %
Date: 2025-05-03 01:55:50 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             : #include <stdint.h>
       5             : #include "options.h" /* Compilation switches                   */
       6             : #include "cnst.h"    /* Common constants                       */
       7             : #include "prot_fx.h" /* Function prototypes                    */
       8             : 
       9             : /*--------------------------------------------------------------------------
      10             :  *  bitallocsum_fx()
      11             :  *
      12             :  *  Calculate the total number of bits allocated over frame
      13             :  *--------------------------------------------------------------------------*/
      14       10889 : void bitallocsum_fx(
      15             :     Word16 *R,             /* i  : bit-allocation vector                         Q0 */
      16             :     const Word16 nb_sfm,   /* i  : number of sub-vectors                         Q0 */
      17             :     Word16 *sum,           /* o  : total number of bits allocated                Q0 */
      18             :     Word16 *Rsubband,      /* o  : rate per subband                              Q3 */
      19             :     const Word16 num_bits, /* i  : number of bits                                Q0 */
      20             :     const Word16 length,   /* i  : length of spectrum (32 or 48 kHz samplerate)  Q0 */
      21             :     const Word16 *sfmsize  /* i  : band length                                   Q0 */
      22             : )
      23             : {
      24             :     Word16 i;
      25             :     Word16 total, tmp;
      26             :     Word16 diff;
      27             : 
      28       10889 :     total = 0;
      29       10889 :     move16();
      30      462809 :     FOR( i = 0; i < nb_sfm; i++ )
      31             :     {
      32      451920 :         tmp = extract_l( L_mult0( R[i], sfmsize[i] ) ); // Q0
      33      451920 :         Rsubband[i] = shl( tmp, 3 );                    // Q3
      34      451920 :         move16();
      35      451920 :         total = add( total, tmp );
      36             :     }
      37       10889 :     *sum = total;
      38       10889 :     move16();
      39             : 
      40       10889 :     IF( LE_16( length, L_FRAME32k ) )
      41             :     {
      42        1315 :         diff = sub( num_bits, *sum );
      43        1315 :         i = 0;
      44        1315 :         move16();
      45        8246 :         WHILE( diff > 0 )
      46             :         {
      47        6931 :             IF( R[i] > 0 )
      48             :             {
      49        5836 :                 Rsubband[i] = add( Rsubband[i], 8 );
      50        5836 :                 move16();
      51        5836 :                 diff = sub( diff, 1 );
      52        5836 :                 *sum = add( *sum, 1 );
      53        5836 :                 move16();
      54             :             }
      55        6931 :             i = add( i, 1 );
      56        6931 :             if ( GE_16( i, nb_sfm ) )
      57             :             {
      58           1 :                 i = 0;
      59           1 :                 move16();
      60             :             }
      61             :         }
      62             :     }
      63       10889 :     return;
      64             : }

Generated by: LCOV version 1.14