LCOV - code coverage report
Current view: top level - lib_dec - gain_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main @ fec202a8f89be4a2f278a9fc377bfb58b58fab11 Lines: 228 234 97.4 %
Date: 2025-09-14 08:49:17 Functions: 8 8 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : /*====================================================================================
      34             :     EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
      35             :   ====================================================================================*/
      36             : 
      37             : #include <stdint.h>
      38             : #include "options.h"
      39             : #ifdef DEBUGGING
      40             : #include "debug.h"
      41             : #endif
      42             : #include <math.h>
      43             : #include "cnst.h"
      44             : #include "rom_com.h"
      45             : #include "prot.h"
      46             : #include "wmc_auto.h"
      47             : 
      48             : /*---------------------------------------------------------------------*
      49             :  * Es_pred_dec()
      50             :  *
      51             :  * Decoding of scaled predicted innovation energy to be used in all subframes
      52             :  *---------------------------------------------------------------------*/
      53             : 
      54     2534899 : void Es_pred_dec(
      55             :     float *Es_pred,        /* o  : predicted scaled innovation energy  */
      56             :     const int16_t enr_idx, /* i  : indice                              */
      57             :     const int16_t nb_bits, /* i  : number of bits                      */
      58             :     const int16_t no_ltp   /* i  : no LTP flag                         */
      59             : )
      60             : {
      61     2534899 :     if ( !no_ltp )
      62             :     {
      63     2501216 :         switch ( nb_bits )
      64             :         {
      65     2172796 :             case 5:
      66     2172796 :                 *Es_pred = Es_pred_qua_5b[enr_idx];
      67     2172796 :                 break;
      68      309834 :             case 4:
      69      309834 :                 *Es_pred = Es_pred_qua_4b[enr_idx];
      70      309834 :                 break;
      71       18586 :             case 3:
      72       18586 :                 *Es_pred = Es_pred_qua_3b[enr_idx];
      73       18586 :                 break;
      74           0 :             default:
      75           0 :                 *Es_pred = Es_pred_qua_5b[enr_idx];
      76           0 :                 break;
      77             :         }
      78             :     }
      79             :     else
      80             :     {
      81       33683 :         *Es_pred = Es_pred_qua_4b_no_ltp[enr_idx];
      82             :     }
      83             : 
      84     2534899 :     return;
      85             : }
      86             : 
      87             : 
      88             : /*--------------------------------------------------------------------------*
      89             :  * lp_gain_updt()
      90             :  *
      91             :  * Update of LP pitch and code gains (FEC)
      92             :  *-------------------------------------------------------------------------*/
      93             : 
      94    11957050 : void lp_gain_updt(
      95             :     const int16_t i_subfr,      /* i  :  subframe number            */
      96             :     const float gain_pit,       /* i  : Decoded gain pitch          */
      97             :     const float norm_gain_code, /* i  : Normalised gain code        */
      98             :     float *lp_gainp,            /* i/o: LP-filtered pitch gain(FEC) */
      99             :     float *lp_gainc,            /* i/o: LP-filtered code gain (FEC) */
     100             :     const int16_t L_frame       /* i  : length of the frame         */
     101             : )
     102             : {
     103    11957050 :     if ( L_frame == L_FRAME )
     104             :     {
     105     5151060 :         if ( i_subfr == 0 )
     106             :         {
     107     1287765 :             *lp_gainp = 0.1f * gain_pit;
     108     1287765 :             *lp_gainc = 0.1f * norm_gain_code;
     109             :         }
     110     3863295 :         else if ( i_subfr == L_SUBFR )
     111             :         {
     112     1287765 :             *lp_gainp += 0.2f * gain_pit;
     113     1287765 :             *lp_gainc += 0.2f * norm_gain_code;
     114             :         }
     115     2575530 :         else if ( i_subfr == 2 * L_SUBFR )
     116             :         {
     117     1287765 :             *lp_gainp += 0.3f * gain_pit;
     118     1287765 :             *lp_gainc += 0.3f * norm_gain_code;
     119             :         }
     120             :         else /* i_subfr == 3*L_SUBFR */
     121             :         {
     122     1287765 :             *lp_gainp += 0.4f * gain_pit;
     123     1287765 :             *lp_gainc += 0.4f * norm_gain_code;
     124             :         }
     125             :     }
     126             :     else
     127             :     {
     128     6805990 :         if ( i_subfr == 0 )
     129             :         {
     130     1361198 :             *lp_gainp = ( 1.0f / 15.0f ) * gain_pit;
     131     1361198 :             *lp_gainc = ( 1.0f / 15.0f ) * norm_gain_code;
     132             :         }
     133     5444792 :         else if ( i_subfr == L_SUBFR )
     134             :         {
     135     1361198 :             *lp_gainp += ( 2.0f / 15.0f ) * gain_pit;
     136     1361198 :             *lp_gainc += ( 2.0f / 15.0f ) * norm_gain_code;
     137             :         }
     138     4083594 :         else if ( i_subfr == 2 * L_SUBFR )
     139             :         {
     140     1361198 :             *lp_gainp += ( 3.0f / 15.0f ) * gain_pit;
     141     1361198 :             *lp_gainc += ( 3.0f / 15.0f ) * norm_gain_code;
     142             :         }
     143     2722396 :         else if ( i_subfr == 3 * L_SUBFR )
     144             :         {
     145     1361198 :             *lp_gainp += ( 4.0f / 15.0f ) * gain_pit;
     146     1361198 :             *lp_gainc += ( 4.0f / 15.0f ) * norm_gain_code;
     147             :         }
     148             :         else /* i_subfr == 4*L_SUBFR */
     149             :         {
     150     1361198 :             *lp_gainp += ( 5.0f / 15.0f ) * gain_pit;
     151     1361198 :             *lp_gainc += ( 5.0f / 15.0f ) * norm_gain_code;
     152             :         }
     153             :     }
     154             : 
     155    11957050 :     return;
     156             : }
     157             : 
     158             : 
     159             : /*---------------------------------------------------------------------*
     160             :  * gain_dec_tc()
     161             :  *
     162             :  * Decoding of pitch and codebook gains and updating long term energies
     163             :  *---------------------------------------------------------------------*/
     164             : 
     165      402823 : void gain_dec_tc(
     166             :     Decoder_State *st,     /* i/o: decoder state structure             */
     167             :     const int16_t i_subfr, /* i  : subframe number                     */
     168             :     const float Es_pred,   /* i  :  predicted scaled innov. energy     */
     169             :     const float *code,     /* i  : algebraic code excitation           */
     170             :     float *gain_pit,       /* o  : pitch gain                          */
     171             :     float *gain_code,      /* o  : Quantized codeebook gain            */
     172             :     float *gain_inov,      /* o  : unscaled innovation gain            */
     173             :     float *norm_gain_code  /* o  : norm. gain of the codebook excit.   */
     174             : )
     175             : {
     176             :     int16_t index, nBits;
     177             :     float Ecode, gcode0;
     178             :     float Ei;
     179             : 
     180      402823 :     *gain_pit = 0;
     181             : 
     182             :     /*----------------------------------------------------------------*
     183             :      * find number of bits for gain dequantization
     184             :      *----------------------------------------------------------------*/
     185             : 
     186      402823 :     nBits = st->acelp_cfg.gains_mode[i_subfr / L_SUBFR];
     187             : 
     188             :     /*-----------------------------------------------------------------*
     189             :      * calculate the predicted gain code
     190             :      *-----------------------------------------------------------------*/
     191             : 
     192      402823 :     Ecode = ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR;
     193      402823 :     *gain_inov = 1.0f / (float) sqrt( Ecode );
     194      402823 :     Ei = 10 * (float) log10( Ecode );
     195      402823 :     gcode0 = (float) pow( 10, 0.05 * ( Es_pred - Ei ) );
     196             : 
     197             :     /*------------------------------------------------------------------------------------------*
     198             :      * Select the gain quantization table and dequantize the gain
     199             :      *------------------------------------------------------------------------------------------*/
     200             : 
     201      402823 :     index = get_next_indice( st, nBits );
     202             : 
     203      402823 :     if ( nBits > 3 )
     204             :     {
     205       38697 :         *gain_code = gain_dequant( index, G_CODE_MIN, G_CODE_MAX, nBits );
     206             :     }
     207             :     else /* nBits == 3 */
     208             :     {
     209      364126 :         *gain_code = tbl_gain_code_tc[index];
     210             :     }
     211             : 
     212             :     /*-----------------------------------------------------------------*
     213             :      * decode normalized codebook gain
     214             :      *-----------------------------------------------------------------*/
     215             : 
     216      402823 :     *gain_code *= gcode0;
     217      402823 :     *norm_gain_code = *gain_code / *gain_inov;
     218             : 
     219      402823 :     return;
     220             : }
     221             : 
     222             : /*---------------------------------------------------------------------*
     223             :  * gain_dec_amr_wb()
     224             :  *
     225             :  * Decoding of pitch and fixed codebook gains (used also in AMR-WB IO mode)
     226             :  *---------------------------------------------------------------------*/
     227             : 
     228       23740 : void gain_dec_amr_wb(
     229             :     Decoder_State *st,        /* i/o: decoder state structure               */
     230             :     const int32_t core_brate, /* i  : core bitrate                          */
     231             :     float *gain_pit,          /* o  : Quantized pitch gain                  */
     232             :     float *gain_code,         /* o  : Quantized codeebook gain              */
     233             :     float *past_qua_en,       /* i/o: gain quantization memory (4 words)    */
     234             :     float *gain_inov,         /* o  : unscaled innovation gain              */
     235             :     const float *code,        /* i  : algebraic code excitation             */
     236             :     float *norm_gain_code     /* o  : norm. gain of the codebook excitation */
     237             : )
     238             : {
     239             :     int16_t i, index;
     240             :     int16_t nbits;
     241             :     float gcode0, qua_en;
     242             :     const float *t_qua_gain;
     243             : 
     244       23740 :     *gain_inov = 1.0f / (float) sqrt( ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR );
     245             : 
     246             :     /*-----------------------------------------------------------------*
     247             :      * Select the gain quantization table
     248             :      *-----------------------------------------------------------------*/
     249             : 
     250       23740 :     if ( core_brate < ACELP_12k65 )
     251             :     {
     252        4064 :         nbits = 6;
     253        4064 :         t_qua_gain = t_qua_gain6b;
     254             :     }
     255             :     else
     256             :     {
     257       19676 :         nbits = 7;
     258       19676 :         t_qua_gain = t_qua_gain7b;
     259             :     }
     260             : 
     261             :     /*-----------------------------------------------------------------*
     262             :      * predicted code gain
     263             :      *-----------------------------------------------------------------*/
     264             : 
     265             :     /* start with predicting code energy in dB */
     266       23740 :     gcode0 = MEAN_ENER;
     267      118700 :     for ( i = 0; i < GAIN_PRED_ORDER; i++ )
     268             :     {
     269       94960 :         gcode0 += pred_gain[i] * past_qua_en[i];
     270             :     }
     271       23740 :     gcode0 += (float) ( 20.0 * log10( *gain_inov ) );
     272             : 
     273             :     /* convert from energy in dB to gain */
     274       23740 :     gcode0 = (float) pow( 10.0, gcode0 / 20.0 );
     275             : 
     276             :     /*-----------------------------------------------------------------*
     277             :      * Decode pitch gain
     278             :      *-----------------------------------------------------------------*/
     279             : 
     280       23740 :     index = get_next_indice( st, nbits );
     281       23740 :     *gain_pit = t_qua_gain[index * 2];
     282             : 
     283             :     /*-----------------------------------------------------------------*
     284             :      * Decode code gain
     285             :      *-----------------------------------------------------------------*/
     286             : 
     287       23740 :     qua_en = t_qua_gain[index * 2 + 1];
     288       23740 :     *gain_code = qua_en * gcode0;
     289             : 
     290             :     /*-----------------------------------------------------------------*
     291             :      * update table of past quantized energies
     292             :      *-----------------------------------------------------------------*/
     293             : 
     294       94960 :     for ( i = GAIN_PRED_ORDER - 1; i > 0; i-- )
     295             :     {
     296       71220 :         past_qua_en[i] = past_qua_en[i - 1];
     297             :     }
     298       23740 :     past_qua_en[0] = (float) ( 20.0 * log10( qua_en ) );
     299             : 
     300             :     /*-----------------------------------------------------------------*
     301             :      * Normalized code gain
     302             :      *-----------------------------------------------------------------*/
     303             : 
     304       23740 :     *norm_gain_code = *gain_code / *gain_inov;
     305             : 
     306       23740 :     return;
     307             : }
     308             : 
     309             : /*--------------------------------------------------------------------------*
     310             :  * gain_dec_mless()
     311             :  *
     312             :  * Decoding of pitch and codebook gains without updating long term energies
     313             :  *-------------------------------------------------------------------------*/
     314             : 
     315    10074217 : void gain_dec_mless(
     316             :     Decoder_State *st,        /* i/o: decoder state structure               */
     317             :     const int16_t L_frame,    /* i  : length of the frame                   */
     318             :     const int16_t coder_type, /* i  : coding type                           */
     319             :     const int16_t i_subfr,    /* i  : subframe number                       */
     320             :     const int16_t tc_subfr,   /* i  : TC subframe index                     */
     321             :     const float *code,        /* i  : algebraic code excitation             */
     322             :     const float Es_pred,      /* i  : predicted scaled innov. energy        */
     323             :     float *gain_pit,          /* o  : Quantized pitch gain                  */
     324             :     float *gain_code,         /* o  : Quantized codeebook gain              */
     325             :     float *gain_inov,         /* o  : unscaled innovation gain              */
     326             :     float *norm_gain_code     /* o  : norm. gain of the codebook excitation */
     327             : )
     328             : {
     329             :     int16_t index, nBits;
     330             :     float gcode0, Ei, Ecode;
     331             :     const float *qua_table;
     332             : 
     333             :     /*-----------------------------------------------------------------*
     334             :      * decode pitch gain
     335             :      *-----------------------------------------------------------------*/
     336             : 
     337    10074217 :     nBits = st->acelp_cfg.gains_mode[i_subfr / L_SUBFR];
     338             : 
     339    10074217 :     if ( ( tc_subfr == 3 * L_SUBFR && i_subfr == 3 * L_SUBFR && L_frame == L_FRAME ) ||
     340       34272 :          ( tc_subfr == 4 * L_SUBFR && i_subfr == 4 * L_SUBFR && L_frame == L_FRAME16k ) )
     341             :     {
     342             :         /* decode pitch gain */
     343       65873 :         index = get_next_indice( st, nBits >> 1 );
     344       65873 :         Ei = ( G_PITCH_MAX_TC192 - G_PITCH_MIN_TC192 ) / ( ( 1 << ( nBits >> 1 ) ) - 1 ); /* set quantization step */
     345       65873 :         *gain_pit = usdequant( index, G_PITCH_MIN_TC192, Ei );
     346             : 
     347             :         /* calculate the predicted gain code */
     348       65873 :         Ecode = ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR;
     349       65873 :         *gain_inov = 1.0f / (float) sqrt( Ecode );
     350       65873 :         Ei = 10 * (float) log10( Ecode );
     351       65873 :         gcode0 = (float) pow( 10, 0.05 * ( Es_pred - Ei ) );
     352             : 
     353             :         /* decode normalized codebook gain */
     354       65873 :         index = get_next_indice( st, ( nBits + 1 ) >> 1 );
     355       65873 :         *gain_code = gain_dequant( index, G_CODE_MIN_TC192, G_CODE_MAX_TC192, ( nBits + 1 ) >> 1 );
     356       65873 :         *gain_code *= gcode0;
     357             :     }
     358             :     else
     359             :     {
     360    10008344 :         switch ( nBits )
     361             :         {
     362        5180 :             case 7:
     363             :             {
     364        5180 :                 qua_table = gain_qua_mless_7b;
     365        5180 :                 break;
     366             :             }
     367     9992037 :             case 6:
     368             :             {
     369     9992037 :                 qua_table = gain_qua_mless_6b;
     370             : 
     371     9992037 :                 if ( st->element_mode > EVS_MONO )
     372             :                 {
     373     9908368 :                     qua_table = gain_qua_mless_6b_stereo;
     374             :                 }
     375             : 
     376     9992037 :                 break;
     377             :             }
     378       11127 :             case 5:
     379             :             {
     380       11127 :                 qua_table = gain_qua_mless_5b;
     381       11127 :                 break;
     382             :             }
     383           0 :             default:
     384             :             {
     385           0 :                 qua_table = gain_qua_mless_6b;
     386           0 :                 break;
     387             :             }
     388             :         }
     389             : 
     390    10008344 :         if ( coder_type == INACTIVE && nBits == 6 )
     391             :         {
     392       44030 :             nBits--;
     393             :         }
     394             : 
     395    10008344 :         index = get_next_indice( st, nBits );
     396             : 
     397    10008344 :         *gain_pit = qua_table[index * 2];
     398    10008344 :         Ecode = ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR;
     399    10008344 :         *gain_inov = 1.0f / (float) sqrt( Ecode );
     400    10008344 :         Ei = 10 * (float) log10( Ecode );
     401             : 
     402             :         /*-----------------------------------------------------------------*
     403             :          * calculate the predicted gain code
     404             :          *-----------------------------------------------------------------*/
     405             : 
     406    10008344 :         gcode0 = (float) pow( 10, 0.05 * ( Es_pred - Ei ) );
     407             : 
     408             :         /*-----------------------------------------------------------------*
     409             :          * decode normalized codebook gain
     410             :          *-----------------------------------------------------------------*/
     411             : 
     412    10008344 :         *gain_code = qua_table[index * 2 + 1] * gcode0;
     413             :     }
     414             : 
     415    10074217 :     *norm_gain_code = *gain_code / *gain_inov;
     416             : 
     417    10074217 :     return;
     418             : }
     419             : 
     420             : /*--------------------------------------------------------------------------*
     421             :  * gain_dec_lbr()
     422             :  *
     423             :  * Decoding of pitch and codebook gains in ACELP at 6.6 and 7.5 kbps
     424             :  *-------------------------------------------------------------------------*/
     425             : 
     426      231470 : void gain_dec_lbr(
     427             :     Decoder_State *st,        /* i/o: decoder state structure                          */
     428             :     const int16_t coder_type, /* i  : coding type                                      */
     429             :     const int16_t i_subfr,    /* i  : subframe index                                   */
     430             :     const float *code,        /* i  : algebraic excitation                             */
     431             :     float *gain_pit,          /* o  : quantized pitch gain                             */
     432             :     float *gain_code,         /* o  : quantized codebook gain                          */
     433             :     float *gain_inov,         /* o  : gain of the innovation (used for normalization)  */
     434             :     float *norm_gain_code,    /* o  : norm. gain of the codebook excitation            */
     435             :     float gains_mem[],        /* i/o: pitch gain and code gain from previous subframes */
     436             :     const int16_t L_subfr     /* i  : subframe length                                  */
     437             : )
     438             : {
     439             :     int16_t index, nBits, n_pred, ctype;
     440             :     float gcode0, aux[10], Ecode;
     441      231470 :     const float *b, *cdbk = 0;
     442             : 
     443      231470 :     Ecode = ( dotp( code, code, L_subfr ) + 0.01f ) / L_subfr;
     444      231470 :     *gain_inov = 1.0f / (float) sqrt( Ecode );
     445             : 
     446             :     /*-----------------------------------------------------------------*
     447             :      * select the codebook, size and number of bits
     448             :      * set the gains searching range
     449             :      *-----------------------------------------------------------------*/
     450             : 
     451      231470 :     nBits = st->acelp_cfg.gains_mode[i_subfr / L_subfr];
     452             : 
     453      231470 :     ctype = 2 * ( coder_type - 1 );
     454             : 
     455             :     /*-----------------------------------------------------------------*
     456             :      * calculate prediction of gcode
     457             :      * search for the best codeword
     458             :      *-----------------------------------------------------------------*/
     459             : 
     460      231470 :     if ( i_subfr == 0 )
     461             :     {
     462       71334 :         b = b_1sfr;
     463       71334 :         n_pred = 2;
     464             : 
     465       71334 :         switch ( nBits )
     466             :         {
     467       30385 :             case 8:
     468             :             {
     469       30385 :                 cdbk = gp_gamma_1sfr_8b;
     470       30385 :                 break;
     471             :             }
     472        6405 :             case 7:
     473             :             {
     474        6405 :                 cdbk = gp_gamma_1sfr_7b;
     475        6405 :                 break;
     476             :             }
     477       34544 :             case 6:
     478             :             {
     479       34544 :                 cdbk = gp_gamma_1sfr_6b;
     480       34544 :                 break;
     481             :             }
     482             :         }
     483             : 
     484             :         /* calculate predicted gain */
     485       71334 :         aux[0] = 1.0f;
     486       71334 :         aux[1] = ctype;
     487       71334 :         gcode0 = (float) pow( 10, dotp( b, aux, n_pred ) - 0.5f * (float) log10( Ecode ) );
     488             : 
     489             :         /* retrieve the codebook index and calculate both gains */
     490       71334 :         index = get_next_indice( st, nBits );
     491       71334 :         *gain_pit = cdbk[index * 2];
     492       71334 :         *gain_code = cdbk[index * 2 + 1] * gcode0;
     493       71334 :         gains_mem[0] = *gain_code;
     494       71334 :         gains_mem[3] = *gain_pit;
     495             :     }
     496      160136 :     else if ( i_subfr == L_SUBFR || L_subfr == 2 * L_SUBFR )
     497             :     {
     498       71334 :         b = b_2sfr;
     499       71334 :         n_pred = 4;
     500             : 
     501       71334 :         switch ( nBits )
     502             :         {
     503       30354 :             case 7:
     504             :             {
     505       30354 :                 cdbk = gp_gamma_2sfr_7b;
     506       30354 :                 break;
     507             :             }
     508       40980 :             case 6:
     509             :             {
     510       40980 :                 cdbk = gp_gamma_2sfr_6b;
     511       40980 :                 break;
     512             :             }
     513             :         }
     514             : 
     515             :         /* calculate predicted gain */
     516       71334 :         aux[0] = 1.0f;
     517       71334 :         aux[1] = ctype;
     518       71334 :         aux[2] = (float) log10( gains_mem[0] );
     519       71334 :         aux[3] = gains_mem[3];
     520       71334 :         gcode0 = (float) pow( 10, dotp( b, aux, n_pred ) );
     521             : 
     522             :         /* retrieve the codebook index and calculate both gains */
     523       71334 :         index = get_next_indice( st, nBits );
     524       71334 :         *gain_pit = cdbk[index * 2];
     525       71334 :         *gain_code = cdbk[index * 2 + 1] * gcode0;
     526       71334 :         gains_mem[1] = *gain_code;
     527       71334 :         gains_mem[4] = *gain_pit;
     528             :     }
     529       88802 :     else if ( i_subfr == 2 * L_SUBFR )
     530             :     {
     531       44401 :         b = b_3sfr;
     532       44401 :         n_pred = 6;
     533             : 
     534       44401 :         switch ( nBits )
     535             :         {
     536          47 :             case 7:
     537             :             {
     538          47 :                 cdbk = gp_gamma_3sfr_7b;
     539          47 :                 break;
     540             :             }
     541       44354 :             case 6:
     542             :             {
     543       44354 :                 cdbk = gp_gamma_3sfr_6b;
     544       44354 :                 break;
     545             :             }
     546             :         }
     547             : 
     548             :         /* calculate predicted gain */
     549       44401 :         aux[0] = 1.0f;
     550       44401 :         aux[1] = ctype;
     551       44401 :         aux[2] = (float) log10( gains_mem[0] );
     552       44401 :         aux[3] = (float) log10( gains_mem[1] );
     553       44401 :         aux[4] = gains_mem[3];
     554       44401 :         aux[5] = gains_mem[4];
     555       44401 :         gcode0 = (float) pow( 10, dotp( b, aux, n_pred ) );
     556             : 
     557             :         /* retrieve the codebook index and calculate both gains */
     558       44401 :         index = get_next_indice( st, nBits );
     559       44401 :         *gain_pit = cdbk[index * 2];
     560       44401 :         *gain_code = cdbk[index * 2 + 1] * gcode0;
     561             : 
     562       44401 :         gains_mem[2] = *gain_code;
     563       44401 :         gains_mem[5] = *gain_pit;
     564             :     }
     565       44401 :     else if ( i_subfr == 3 * L_SUBFR )
     566             :     {
     567       44401 :         b = b_4sfr;
     568       44401 :         n_pred = 8;
     569             : 
     570       44401 :         switch ( nBits )
     571             :         {
     572           7 :             case 7:
     573             :             {
     574           7 :                 cdbk = gp_gamma_4sfr_7b;
     575           7 :                 break;
     576             :             }
     577       44394 :             case 6:
     578             :             {
     579       44394 :                 cdbk = gp_gamma_4sfr_6b;
     580       44394 :                 break;
     581             :             }
     582             :         }
     583             : 
     584             :         /* calculate predicted gain */
     585       44401 :         aux[0] = 1.0f;
     586       44401 :         aux[1] = ctype;
     587       44401 :         aux[2] = (float) log10( gains_mem[0] );
     588       44401 :         aux[3] = (float) log10( gains_mem[1] );
     589       44401 :         aux[4] = (float) log10( gains_mem[2] );
     590       44401 :         aux[5] = gains_mem[3];
     591       44401 :         aux[6] = gains_mem[4];
     592       44401 :         aux[7] = gains_mem[5];
     593       44401 :         gcode0 = (float) pow( 10, dotp( b, aux, n_pred ) );
     594             : 
     595             :         /* retrieve the codebook index and calculate both gains */
     596       44401 :         index = get_next_indice( st, nBits );
     597       44401 :         *gain_pit = cdbk[index * 2];
     598       44401 :         *gain_code = cdbk[index * 2 + 1] * gcode0;
     599             :     }
     600             : 
     601      231470 :     *norm_gain_code = *gain_code / *gain_inov;
     602             : 
     603      231470 :     return;
     604             : }
     605             : 
     606             : /*--------------------------------------------------------------------------*
     607             :  * gain_dec_SQ()
     608             :  *
     609             :  * Decoding of pitch and codebook gains using scalar quantizers
     610             :  *-------------------------------------------------------------------------*/
     611             : 
     612      815063 : void gain_dec_SQ(
     613             :     Decoder_State *st,     /* i/o: decoder state structure               */
     614             :     const int16_t i_subfr, /* i  : subframe number                       */
     615             :     const float *code,     /* i  : algebraic code excitation             */
     616             :     const float Es_pred,   /* i  : predicted scaled innov. energy        */
     617             :     float *gain_pit,       /* o  : Quantized pitch gain                  */
     618             :     float *gain_code,      /* o  : Quantized codeebook gain              */
     619             :     float *gain_inov,      /* o  : unscaled innovation gain              */
     620             :     float *norm_gain_code  /* o  : norm. gain of the codebook excitation */
     621             : )
     622             : {
     623             :     int16_t index, nBits;
     624             :     float gcode0, Ei, Ecode;
     625             :     int16_t tmp16;
     626             :     /*-----------------------------------------------------------------*
     627             :      * get number of bits
     628             :      *-----------------------------------------------------------------*/
     629             : 
     630      815063 :     nBits = st->acelp_cfg.gains_mode[i_subfr / L_SUBFR];
     631             : 
     632             :     /*-----------------------------------------------------------------*
     633             :      * decode pitch gain
     634             :      *-----------------------------------------------------------------*/
     635             : 
     636      815063 :     index = get_next_indice( st, nBits >> 1 );
     637             :     /*Ei = (G_PITCH_MAX - G_PITCH_MIN) / ((1 << (nBits>>1)) - 1);*/ /* set quantization step */
     638      815063 :     tmp16 = div_s( 1, ( ( 1 << ( nBits >> 1 ) ) - 1 ) );            /* Q15*/
     639      815063 :     Ei = (float) mult_r( (int16_t) ( G_PITCH_MAX * 8192.0f + 0.5f ), tmp16 ) / 8192.0f;
     640             : 
     641      815063 :     *gain_pit = usdequant( index, G_PITCH_MIN, Ei );
     642             : 
     643             :     /*-----------------------------------------------------------------*
     644             :      * calculate the predicted gain code
     645             :      *-----------------------------------------------------------------*/
     646             : 
     647      815063 :     Ecode = ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR;
     648      815063 :     *gain_inov = 1.0f / (float) sqrt( Ecode );
     649      815063 :     Ei = 10 * (float) log10( Ecode );
     650      815063 :     gcode0 = (float) pow( 10, 0.05 * ( Es_pred - Ei ) );
     651             : 
     652             :     /*-----------------------------------------------------------------*
     653             :      * decode normalized codebook gain
     654             :      *-----------------------------------------------------------------*/
     655             : 
     656      815063 :     index = get_next_indice( st, ( nBits + 1 ) >> 1 );
     657      815063 :     *gain_code = gain_dequant( index, G_CODE_MIN, G_CODE_MAX, ( nBits + 1 ) >> 1 );
     658      815063 :     *gain_code *= gcode0;
     659      815063 :     *norm_gain_code = *gain_code / *gain_inov;
     660             : 
     661      815063 :     return;
     662             : }
     663             : 
     664             : 
     665             : /*-------------------------------------------------*
     666             :  * gain_dec_gaus()
     667             :  *
     668             :  * Decoding of gains for Gaussian codebook
     669             :  *-------------------------------------------------*/
     670             : 
     671             : /*! r: quantized codebook gain */
     672         984 : float gain_dec_gaus(
     673             :     const int16_t index,   /* i  : quantization index              */
     674             :     const int16_t bits,    /* i  : number of bits to quantize      */
     675             :     const float lowBound,  /* i  : lower bound of quantizer (dB)   */
     676             :     const float topBound,  /* i  : upper bound of quantizer (dB)   */
     677             :     const float gain_inov, /* i  : unscaled innovation gain        */
     678             :     float *norm_gain_code  /* o  : gain of normalized gaus. excit. */
     679             : )
     680             : {
     681             :     float gain, enr, stepSize;
     682             : 
     683             :     /*-----------------------------------------------------------------*
     684             :      * quantize linearly the log E
     685             :      *-----------------------------------------------------------------*/
     686             : 
     687         984 :     stepSize = ( topBound - lowBound ) / ( (float) ( 1 << bits ) );
     688             : 
     689             :     /*-----------------------------------------------------------------*
     690             :      * Gaussian codebook gain
     691             :      *-----------------------------------------------------------------*/
     692             : 
     693         984 :     enr = (float) index * stepSize + lowBound; /* quantized codebook gain in dB */
     694         984 :     gain = (float) pow( 10.0f, enr / 20.0f );
     695             : 
     696         984 :     *norm_gain_code = gain / gain_inov;
     697             : 
     698         984 :     return gain;
     699             : }

Generated by: LCOV version 1.14