LCOV - code coverage report
Current view: top level - lib_com - fine_gain_bits_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 4c82f1d24d39d0296b18d775f18a006f4c7d024b Lines: 64 66 97.0 %
Date: 2025-05-17 01:59:02 Functions: 4 4 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" /* Compilation switches                   */
       7             : #include "rom_com.h" /* Static table prototypes                */
       8             : #include "prot_fx.h" /* Function prototypes                    */
       9             : #include "ivas_prot_fx.h"
      10             : 
      11             : 
      12             : /*--------------------------------------------------------------------------
      13             :  * subband_gain_bits()
      14             :  *
      15             :  * HQ core encoder
      16             :  *--------------------------------------------------------------------------*/
      17         397 : static void subband_gain_bits_fx(
      18             :     const Word16 *Rk,     /* i  : bit allocation per band Q3 */
      19             :     const Word16 N,       /* i  : number of bands         */
      20             :     Word16 *bits,         /* o  : gain bits per band      */
      21             :     const Word16 *sfmsize /* i  : Size of bands           */
      22             : )
      23             : {
      24             :     Word16 i, b, tot;
      25             :     Word16 bps;
      26             : 
      27         397 :     tot = 0;
      28         397 :     move16();
      29             : 
      30       15720 :     FOR( i = 0; i < N; i++ )
      31             :     {
      32             :         /*bps = (short)(Rk[i]*((word16)min(32767, ceil(32767.0f/sfmsize[i]);  inexact C-integer division approx. */
      33       15323 :         bps = extract_l( L_shr( L_mult0( Rk[i], inv_tbl_fx[sfmsize[i]] ), 18 ) ); /* 3+15 */
      34       15323 :         if ( EQ_32( L_shl( L_mult0( sfmsize[i], add( bps, 1 ) ), 3 ), Rk[i] ) )
      35             :         {
      36        3578 :             bps = add( bps, 1 );
      37             :         }
      38             : 
      39       15323 :         bps = s_min( 7, bps );
      40       15323 :         b = fine_gain_bits[bps];
      41       15323 :         move16();
      42       15323 :         bits[i] = b;
      43       15323 :         move16();
      44       15323 :         tot = add( tot, b );
      45             :     }
      46             : 
      47         397 :     if ( tot == 0 )
      48             :     {
      49             :         /* If no gain bits were assigned, use one bit anyway for potential PVQ overage */
      50          11 :         bits[0] = 1;
      51          11 :         move16();
      52             :     }
      53             : 
      54         397 :     return;
      55             : }
      56             : 
      57             : /*--------------------------------------------------------------------------*
      58             :  * assign_gain_bits()
      59             :  *
      60             :  * Assign gain adjustment bits and update bit budget
      61             :  *--------------------------------------------------------------------------*/
      62             : 
      63       20957 : Word16 assign_gain_bits_fx(                           /* o  : Number of assigned gain bits          */
      64             :                             const Word16 core,        /* i  : HQ core                               */
      65             :                             const Word16 BANDS,       /* i  : Number of bands                       */
      66             :                             const Word16 *band_width, /* i  : Sub band bandwidth                    */
      67             :                             Word16 *Rk,               /* i/o: Bit allocation/Adjusted bit alloc. Q3 */
      68             :                             Word16 *gain_bits_array,  /* o  : Assigned gain bits                    */
      69             :                             Word16 *Rcalc             /* o  : Bit budget for shape quantizer     Q3 */
      70             : )
      71             : {
      72             :     Word16 gain_bits_tot;
      73             :     Word16 i;
      74             : 
      75             :     /* Allocate gain bits for every subband used, based on bit rate and bandwidth */
      76       20957 :     IF( EQ_16( core, HQ_CORE ) )
      77             :     {
      78         397 :         subband_gain_bits_fx( Rk, BANDS, gain_bits_array, band_width );
      79             :     }
      80             :     ELSE
      81             :     {
      82       20560 :         set16_fx( gain_bits_array, 0, BANDS );
      83             :     }
      84             : 
      85             :     /* Re-adjust bit budget for gain quantization */
      86       20957 :     gain_bits_tot = 0;
      87       20957 :     move16();
      88       20957 :     *Rcalc = 0;
      89       20957 :     move16();
      90      183032 :     FOR( i = 0; i < BANDS; i++ )
      91             :     {
      92      162075 :         IF( Rk[i] > 0 )
      93             :         {
      94      140766 :             Rk[i] = sub( Rk[i], shl( gain_bits_array[i], 3 ) );
      95      140766 :             move16();
      96      140766 :             gain_bits_tot = add( gain_bits_tot, gain_bits_array[i] );
      97      140766 :             *Rcalc = add( *Rcalc, Rk[i] );
      98      140766 :             move16();
      99             :         }
     100             :     }
     101             : 
     102       20957 :     return gain_bits_tot;
     103             : }
     104             : 
     105        6102 : static void ivas_subband_gain_bits_fx(
     106             :     const Word16 *Rk,     /* i  : bit allocation per band Q3 */
     107             :     const Word16 N,       /* i  : number of bands         */
     108             :     Word16 *bits,         /* o  : gain bits per band      */
     109             :     const Word16 *sfmsize /* i  : Size of bands           */
     110             : )
     111             : {
     112             :     Word16 i, b, tot;
     113             :     Word16 bps;
     114             : 
     115        6102 :     tot = 0;
     116        6102 :     move16();
     117             : 
     118      251164 :     FOR( i = 0; i < N; i++ )
     119             :     {
     120             :         /*bps = (short)(Rk[i]*((word16)min(32767, ceil(32767.0f/sfmsize[i]);  inexact C-integer division approx. */
     121      245062 :         bps = extract_l( L_shr( L_mult0( Rk[i], fg_inv_tbl_fx[sfmsize[i] >> 3] ), 18 ) ); /* 3+15 */
     122      245062 :         if ( EQ_32( L_shl( L_mult0( sfmsize[i], add( bps, 1 ) ), 3 ), Rk[i] ) )
     123             :         {
     124           0 :             bps = add( bps, 1 );
     125             :         }
     126             : 
     127      245062 :         bps = s_min( 7, bps );
     128      245062 :         b = fine_gain_bits[bps];
     129      245062 :         move16();
     130      245062 :         bits[i] = b;
     131      245062 :         move16();
     132      245062 :         tot = add( tot, b );
     133             :     }
     134             : 
     135        6102 :     if ( tot == 0 )
     136             :     {
     137             :         /* If no gain bits were assigned, use one bit anyway for potential PVQ overage */
     138        1240 :         bits[0] = 1;
     139        1240 :         move16();
     140             :     }
     141             : 
     142        6102 :     return;
     143             : }
     144             : 
     145        6102 : Word16 ivas_assign_gain_bits_fx(                           /* o  : Number of assigned gain bits          */
     146             :                                  const Word16 core,        /* i  : HQ core                               */
     147             :                                  const Word16 BANDS,       /* i  : Number of bands                       */
     148             :                                  const Word16 *band_width, /* i  : Sub band bandwidth                    */
     149             :                                  Word16 *Rk,               /* i/o: Bit allocation/Adjusted bit alloc. Q3 */
     150             :                                  Word16 *gain_bits_array,  /* o  : Assigned gain bits                    */
     151             :                                  Word16 *Rcalc             /* o  : Bit budget for shape quantizer     Q3 */
     152             : )
     153             : {
     154             :     Word16 gain_bits_tot;
     155             :     Word16 i;
     156             : 
     157             :     /* Allocate gain bits for every subband used, based on bit rate and bandwidth */
     158        6102 :     IF( EQ_16( core, HQ_CORE ) )
     159             :     {
     160        6102 :         ivas_subband_gain_bits_fx( Rk, BANDS, gain_bits_array, band_width );
     161             :     }
     162             :     ELSE
     163             :     {
     164           0 :         set16_fx( gain_bits_array, 0, BANDS );
     165             :     }
     166             : 
     167             :     /* Re-adjust bit budget for gain quantization */
     168        6102 :     gain_bits_tot = 0;
     169        6102 :     move16();
     170        6102 :     *Rcalc = 0;
     171        6102 :     move16();
     172      251164 :     FOR( i = 0; i < BANDS; i++ )
     173             :     {
     174      245062 :         IF( Rk[i] > 0 )
     175             :         {
     176      127171 :             Rk[i] = sub( Rk[i], shl( gain_bits_array[i], 3 ) );
     177      127171 :             move16();
     178      127171 :             gain_bits_tot = add( gain_bits_tot, gain_bits_array[i] );
     179      127171 :             *Rcalc = add( *Rcalc, Rk[i] );
     180      127171 :             move16();
     181             :         }
     182             :     }
     183             : 
     184        6102 :     return gain_bits_tot;
     185             : }

Generated by: LCOV version 1.14