LCOV - code coverage report
Current view: top level - lib_com - fine_gain_bits_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ bf9ba511f19a231c475b8e110fdaeacf18aa32c4 Lines: 65 66 98.5 %
Date: 2025-07-11 02:46:47 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         785 : 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         785 :     tot = 0;
      28         785 :     move16();
      29             : 
      30       31088 :     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       30303 :         bps = extract_l( L_shr( L_mult0( Rk[i], inv_tbl_fx[sfmsize[i]] ), 18 ) ); /* 3+15 */
      34       30303 :         if ( EQ_32( L_shl( L_mult0( sfmsize[i], add( bps, 1 ) ), 3 ), Rk[i] ) )
      35             :         {
      36        7093 :             bps = add( bps, 1 );
      37             :         }
      38             : 
      39       30303 :         bps = s_min( 7, bps );
      40       30303 :         b = fine_gain_bits[bps];
      41       30303 :         move16();
      42       30303 :         bits[i] = b;
      43       30303 :         move16();
      44       30303 :         tot = add( tot, b );
      45             :     }
      46             : 
      47         785 :     if ( tot == 0 )
      48             :     {
      49             :         /* If no gain bits were assigned, use one bit anyway for potential PVQ overage */
      50          19 :         bits[0] = 1;
      51          19 :         move16();
      52             :     }
      53             : 
      54         785 :     return;
      55             : }
      56             : 
      57             : /*--------------------------------------------------------------------------*
      58             :  * assign_gain_bits()
      59             :  *
      60             :  * Assign gain adjustment bits and update bit budget
      61             :  *--------------------------------------------------------------------------*/
      62             : 
      63       21350 : 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       21350 :     IF( EQ_16( core, HQ_CORE ) )
      77             :     {
      78         785 :         subband_gain_bits_fx( Rk, BANDS, gain_bits_array, band_width );
      79             :     }
      80             :     ELSE
      81             :     {
      82       20565 :         set16_fx( gain_bits_array, 0, BANDS );
      83             :     }
      84             : 
      85             :     /* Re-adjust bit budget for gain quantization */
      86       21350 :     gain_bits_tot = 0;
      87       21350 :     move16();
      88       21350 :     *Rcalc = 0;
      89       21350 :     move16();
      90      198445 :     FOR( i = 0; i < BANDS; i++ )
      91             :     {
      92      177095 :         IF( Rk[i] > 0 )
      93             :         {
      94      153547 :             Rk[i] = sub( Rk[i], shl( gain_bits_array[i], 3 ) );
      95      153547 :             move16();
      96      153547 :             gain_bits_tot = add( gain_bits_tot, gain_bits_array[i] );
      97      153547 :             *Rcalc = add( *Rcalc, Rk[i] );
      98      153547 :             move16();
      99             :         }
     100             :     }
     101             : 
     102       21350 :     return gain_bits_tot;
     103             : }
     104             : 
     105       12408 : 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       12408 :     tot = 0;
     116       12408 :     move16();
     117             : 
     118      513236 :     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      500828 :         bps = extract_l( L_shr( L_mult0( Rk[i], fg_inv_tbl_fx[sfmsize[i] >> 3] ), 18 ) ); /* 3+15 */
     122      500828 :         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      500828 :         bps = s_min( 7, bps );
     128      500828 :         b = fine_gain_bits[bps];
     129      500828 :         move16();
     130      500828 :         bits[i] = b;
     131      500828 :         move16();
     132      500828 :         tot = add( tot, b );
     133             :     }
     134             : 
     135       12408 :     if ( tot == 0 )
     136             :     {
     137             :         /* If no gain bits were assigned, use one bit anyway for potential PVQ overage */
     138        2502 :         bits[0] = 1;
     139        2502 :         move16();
     140             :     }
     141             : 
     142       12408 :     return;
     143             : }
     144             : 
     145       35081 : 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       35081 :     IF( EQ_16( core, HQ_CORE ) )
     159             :     {
     160       12408 :         ivas_subband_gain_bits_fx( Rk, BANDS, gain_bits_array, band_width );
     161             :     }
     162             :     ELSE
     163             :     {
     164       22673 :         set16_fx( gain_bits_array, 0, BANDS );
     165             :     }
     166             : 
     167             :     /* Re-adjust bit budget for gain quantization */
     168       35081 :     gain_bits_tot = 0;
     169       35081 :     move16();
     170       35081 :     *Rcalc = 0;
     171       35081 :     move16();
     172      698715 :     FOR( i = 0; i < BANDS; i++ )
     173             :     {
     174      663634 :         IF( Rk[i] > 0 )
     175             :         {
     176      402849 :             Rk[i] = sub( Rk[i], shl( gain_bits_array[i], 3 ) );
     177      402849 :             move16();
     178      402849 :             gain_bits_tot = add( gain_bits_tot, gain_bits_array[i] );
     179      402849 :             *Rcalc = add( *Rcalc, Rk[i] );
     180      402849 :             move16();
     181             :         }
     182             :     }
     183             : 
     184       35081 :     return gain_bits_tot;
     185             : }

Generated by: LCOV version 1.14