LCOV - code coverage report
Current view: top level - lib_dec - gain_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 198 234 84.6 %
Date: 2025-05-23 08:37:30 Functions: 6 8 75.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      386250 : 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      386250 :     if ( !no_ltp )
      62             :     {
      63      380247 :         switch ( nb_bits )
      64             :         {
      65      327402 :             case 5:
      66      327402 :                 *Es_pred = Es_pred_qua_5b[enr_idx];
      67      327402 :                 break;
      68       51033 :             case 4:
      69       51033 :                 *Es_pred = Es_pred_qua_4b[enr_idx];
      70       51033 :                 break;
      71        1812 :             case 3:
      72        1812 :                 *Es_pred = Es_pred_qua_3b[enr_idx];
      73        1812 :                 break;
      74           0 :             default:
      75           0 :                 *Es_pred = Es_pred_qua_5b[enr_idx];
      76           0 :                 break;
      77             :         }
      78             :     }
      79             :     else
      80             :     {
      81        6003 :         *Es_pred = Es_pred_qua_4b_no_ltp[enr_idx];
      82             :     }
      83             : 
      84      386250 :     return;
      85             : }
      86             : 
      87             : 
      88             : /*--------------------------------------------------------------------------*
      89             :  * lp_gain_updt()
      90             :  *
      91             :  * Update of LP pitch and code gains (FEC)
      92             :  *-------------------------------------------------------------------------*/
      93             : 
      94     1818756 : 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     1818756 :     if ( L_frame == L_FRAME )
     104             :     {
     105      783876 :         if ( i_subfr == 0 )
     106             :         {
     107      195969 :             *lp_gainp = 0.1f * gain_pit;
     108      195969 :             *lp_gainc = 0.1f * norm_gain_code;
     109             :         }
     110      587907 :         else if ( i_subfr == L_SUBFR )
     111             :         {
     112      195969 :             *lp_gainp += 0.2f * gain_pit;
     113      195969 :             *lp_gainc += 0.2f * norm_gain_code;
     114             :         }
     115      391938 :         else if ( i_subfr == 2 * L_SUBFR )
     116             :         {
     117      195969 :             *lp_gainp += 0.3f * gain_pit;
     118      195969 :             *lp_gainc += 0.3f * norm_gain_code;
     119             :         }
     120             :         else /* i_subfr == 3*L_SUBFR */
     121             :         {
     122      195969 :             *lp_gainp += 0.4f * gain_pit;
     123      195969 :             *lp_gainc += 0.4f * norm_gain_code;
     124             :         }
     125             :     }
     126             :     else
     127             :     {
     128     1034880 :         if ( i_subfr == 0 )
     129             :         {
     130      206976 :             *lp_gainp = ( 1.0f / 15.0f ) * gain_pit;
     131      206976 :             *lp_gainc = ( 1.0f / 15.0f ) * norm_gain_code;
     132             :         }
     133      827904 :         else if ( i_subfr == L_SUBFR )
     134             :         {
     135      206976 :             *lp_gainp += ( 2.0f / 15.0f ) * gain_pit;
     136      206976 :             *lp_gainc += ( 2.0f / 15.0f ) * norm_gain_code;
     137             :         }
     138      620928 :         else if ( i_subfr == 2 * L_SUBFR )
     139             :         {
     140      206976 :             *lp_gainp += ( 3.0f / 15.0f ) * gain_pit;
     141      206976 :             *lp_gainc += ( 3.0f / 15.0f ) * norm_gain_code;
     142             :         }
     143      413952 :         else if ( i_subfr == 3 * L_SUBFR )
     144             :         {
     145      206976 :             *lp_gainp += ( 4.0f / 15.0f ) * gain_pit;
     146      206976 :             *lp_gainc += ( 4.0f / 15.0f ) * norm_gain_code;
     147             :         }
     148             :         else /* i_subfr == 4*L_SUBFR */
     149             :         {
     150      206976 :             *lp_gainp += ( 5.0f / 15.0f ) * gain_pit;
     151      206976 :             *lp_gainc += ( 5.0f / 15.0f ) * norm_gain_code;
     152             :         }
     153             :     }
     154             : 
     155     1818756 :     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       58674 : 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       58674 :     *gain_pit = 0;
     181             : 
     182             :     /*----------------------------------------------------------------*
     183             :      * find number of bits for gain dequantization
     184             :      *----------------------------------------------------------------*/
     185             : 
     186       58674 :     nBits = st->acelp_cfg.gains_mode[i_subfr / L_SUBFR];
     187             : 
     188             :     /*-----------------------------------------------------------------*
     189             :      * calculate the predicted gain code
     190             :      *-----------------------------------------------------------------*/
     191             : 
     192       58674 :     Ecode = ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR;
     193       58674 :     *gain_inov = 1.0f / (float) sqrt( Ecode );
     194       58674 :     Ei = 10 * (float) log10( Ecode );
     195       58674 :     gcode0 = (float) pow( 10, 0.05 * ( Es_pred - Ei ) );
     196             : 
     197             :     /*------------------------------------------------------------------------------------------*
     198             :      * Select the gain quantization table and dequantize the gain
     199             :      *------------------------------------------------------------------------------------------*/
     200             : 
     201       58674 :     index = get_next_indice( st, nBits );
     202             : 
     203       58674 :     if ( nBits > 3 )
     204             :     {
     205        4131 :         *gain_code = gain_dequant( index, G_CODE_MIN, G_CODE_MAX, nBits );
     206             :     }
     207             :     else /* nBits == 3 */
     208             :     {
     209       54543 :         *gain_code = tbl_gain_code_tc[index];
     210             :     }
     211             : 
     212             :     /*-----------------------------------------------------------------*
     213             :      * decode normalized codebook gain
     214             :      *-----------------------------------------------------------------*/
     215             : 
     216       58674 :     *gain_code *= gcode0;
     217       58674 :     *norm_gain_code = *gain_code / *gain_inov;
     218             : 
     219       58674 :     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           0 : 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           0 :     *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           0 :     if ( core_brate < ACELP_12k65 )
     251             :     {
     252           0 :         nbits = 6;
     253           0 :         t_qua_gain = t_qua_gain6b;
     254             :     }
     255             :     else
     256             :     {
     257           0 :         nbits = 7;
     258           0 :         t_qua_gain = t_qua_gain7b;
     259             :     }
     260             : 
     261             :     /*-----------------------------------------------------------------*
     262             :      * predicted code gain
     263             :      *-----------------------------------------------------------------*/
     264             : 
     265             :     /* start with predicting code energy in dB */
     266           0 :     gcode0 = MEAN_ENER;
     267           0 :     for ( i = 0; i < GAIN_PRED_ORDER; i++ )
     268             :     {
     269           0 :         gcode0 += pred_gain[i] * past_qua_en[i];
     270             :     }
     271           0 :     gcode0 += (float) ( 20.0 * log10( *gain_inov ) );
     272             : 
     273             :     /* convert from energy in dB to gain */
     274           0 :     gcode0 = (float) pow( 10.0, gcode0 / 20.0 );
     275             : 
     276             :     /*-----------------------------------------------------------------*
     277             :      * Decode pitch gain
     278             :      *-----------------------------------------------------------------*/
     279             : 
     280           0 :     index = get_next_indice( st, nbits );
     281           0 :     *gain_pit = t_qua_gain[index * 2];
     282             : 
     283             :     /*-----------------------------------------------------------------*
     284             :      * Decode code gain
     285             :      *-----------------------------------------------------------------*/
     286             : 
     287           0 :     qua_en = t_qua_gain[index * 2 + 1];
     288           0 :     *gain_code = qua_en * gcode0;
     289             : 
     290             :     /*-----------------------------------------------------------------*
     291             :      * update table of past quantized energies
     292             :      *-----------------------------------------------------------------*/
     293             : 
     294           0 :     for ( i = GAIN_PRED_ORDER - 1; i > 0; i-- )
     295             :     {
     296           0 :         past_qua_en[i] = past_qua_en[i - 1];
     297             :     }
     298           0 :     past_qua_en[0] = (float) ( 20.0 * log10( qua_en ) );
     299             : 
     300             :     /*-----------------------------------------------------------------*
     301             :      * Normalized code gain
     302             :      *-----------------------------------------------------------------*/
     303             : 
     304           0 :     *norm_gain_code = *gain_code / *gain_inov;
     305             : 
     306           0 :     return;
     307             : }
     308             : 
     309             : /*--------------------------------------------------------------------------*
     310             :  * gain_dec_mless()
     311             :  *
     312             :  * Decoding of pitch and codebook gains without updating long term energies
     313             :  *-------------------------------------------------------------------------*/
     314             : 
     315     1524198 : 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     1524198 :     nBits = st->acelp_cfg.gains_mode[i_subfr / L_SUBFR];
     338             : 
     339     1524198 :     if ( ( tc_subfr == 3 * L_SUBFR && i_subfr == 3 * L_SUBFR && L_frame == L_FRAME ) ||
     340        5208 :          ( tc_subfr == 4 * L_SUBFR && i_subfr == 4 * L_SUBFR && L_frame == L_FRAME16k ) )
     341             :     {
     342             :         /* decode pitch gain */
     343       10500 :         index = get_next_indice( st, nBits >> 1 );
     344       10500 :         Ei = ( G_PITCH_MAX_TC192 - G_PITCH_MIN_TC192 ) / ( ( 1 << ( nBits >> 1 ) ) - 1 ); /* set quantization step */
     345       10500 :         *gain_pit = usdequant( index, G_PITCH_MIN_TC192, Ei );
     346             : 
     347             :         /* calculate the predicted gain code */
     348       10500 :         Ecode = ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR;
     349       10500 :         *gain_inov = 1.0f / (float) sqrt( Ecode );
     350       10500 :         Ei = 10 * (float) log10( Ecode );
     351       10500 :         gcode0 = (float) pow( 10, 0.05 * ( Es_pred - Ei ) );
     352             : 
     353             :         /* decode normalized codebook gain */
     354       10500 :         index = get_next_indice( st, ( nBits + 1 ) >> 1 );
     355       10500 :         *gain_code = gain_dequant( index, G_CODE_MIN_TC192, G_CODE_MAX_TC192, ( nBits + 1 ) >> 1 );
     356       10500 :         *gain_code *= gcode0;
     357             :     }
     358             :     else
     359             :     {
     360     1513698 :         switch ( nBits )
     361             :         {
     362        2214 :             case 7:
     363             :             {
     364        2214 :                 qua_table = gain_qua_mless_7b;
     365        2214 :                 break;
     366             :             }
     367     1509864 :             case 6:
     368             :             {
     369     1509864 :                 qua_table = gain_qua_mless_6b;
     370             : 
     371     1509864 :                 if ( st->element_mode > EVS_MONO )
     372             :                 {
     373     1501263 :                     qua_table = gain_qua_mless_6b_stereo;
     374             :                 }
     375             : 
     376     1509864 :                 break;
     377             :             }
     378        1620 :             case 5:
     379             :             {
     380        1620 :                 qua_table = gain_qua_mless_5b;
     381        1620 :                 break;
     382             :             }
     383           0 :             default:
     384             :             {
     385           0 :                 qua_table = gain_qua_mless_6b;
     386           0 :                 break;
     387             :             }
     388             :         }
     389             : 
     390     1513698 :         if ( coder_type == INACTIVE && nBits == 6 )
     391             :         {
     392       15735 :             nBits--;
     393             :         }
     394             : 
     395     1513698 :         index = get_next_indice( st, nBits );
     396             : 
     397     1513698 :         *gain_pit = qua_table[index * 2];
     398     1513698 :         Ecode = ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR;
     399     1513698 :         *gain_inov = 1.0f / (float) sqrt( Ecode );
     400     1513698 :         Ei = 10 * (float) log10( Ecode );
     401             : 
     402             :         /*-----------------------------------------------------------------*
     403             :          * calculate the predicted gain code
     404             :          *-----------------------------------------------------------------*/
     405             : 
     406     1513698 :         gcode0 = (float) pow( 10, 0.05 * ( Es_pred - Ei ) );
     407             : 
     408             :         /*-----------------------------------------------------------------*
     409             :          * decode normalized codebook gain
     410             :          *-----------------------------------------------------------------*/
     411             : 
     412     1513698 :         *gain_code = qua_table[index * 2 + 1] * gcode0;
     413             :     }
     414             : 
     415     1524198 :     *norm_gain_code = *gain_code / *gain_inov;
     416             : 
     417     1524198 :     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       51396 : 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       51396 :     const float *b, *cdbk = 0;
     442             : 
     443       51396 :     Ecode = ( dotp( code, code, L_subfr ) + 0.01f ) / L_subfr;
     444       51396 :     *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       51396 :     nBits = st->acelp_cfg.gains_mode[i_subfr / L_subfr];
     452             : 
     453       51396 :     ctype = 2 * ( coder_type - 1 );
     454             : 
     455             :     /*-----------------------------------------------------------------*
     456             :      * calculate prediction of gcode
     457             :      * search for the best codeword
     458             :      *-----------------------------------------------------------------*/
     459             : 
     460       51396 :     if ( i_subfr == 0 )
     461             :     {
     462       15843 :         b = b_1sfr;
     463       15843 :         n_pred = 2;
     464             : 
     465       15843 :         switch ( nBits )
     466             :         {
     467        6348 :             case 8:
     468             :             {
     469        6348 :                 cdbk = gp_gamma_1sfr_8b;
     470        6348 :                 break;
     471             :             }
     472        1305 :             case 7:
     473             :             {
     474        1305 :                 cdbk = gp_gamma_1sfr_7b;
     475        1305 :                 break;
     476             :             }
     477        8190 :             case 6:
     478             :             {
     479        8190 :                 cdbk = gp_gamma_1sfr_6b;
     480        8190 :                 break;
     481             :             }
     482             :         }
     483             : 
     484             :         /* calculate predicted gain */
     485       15843 :         aux[0] = 1.0f;
     486       15843 :         aux[1] = ctype;
     487       15843 :         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       15843 :         index = get_next_indice( st, nBits );
     491       15843 :         *gain_pit = cdbk[index * 2];
     492       15843 :         *gain_code = cdbk[index * 2 + 1] * gcode0;
     493       15843 :         gains_mem[0] = *gain_code;
     494       15843 :         gains_mem[3] = *gain_pit;
     495             :     }
     496       35553 :     else if ( i_subfr == L_SUBFR || L_subfr == 2 * L_SUBFR )
     497             :     {
     498       15843 :         b = b_2sfr;
     499       15843 :         n_pred = 4;
     500             : 
     501       15843 :         switch ( nBits )
     502             :         {
     503        6342 :             case 7:
     504             :             {
     505        6342 :                 cdbk = gp_gamma_2sfr_7b;
     506        6342 :                 break;
     507             :             }
     508        9501 :             case 6:
     509             :             {
     510        9501 :                 cdbk = gp_gamma_2sfr_6b;
     511        9501 :                 break;
     512             :             }
     513             :         }
     514             : 
     515             :         /* calculate predicted gain */
     516       15843 :         aux[0] = 1.0f;
     517       15843 :         aux[1] = ctype;
     518       15843 :         aux[2] = (float) log10( gains_mem[0] );
     519       15843 :         aux[3] = gains_mem[3];
     520       15843 :         gcode0 = (float) pow( 10, dotp( b, aux, n_pred ) );
     521             : 
     522             :         /* retrieve the codebook index and calculate both gains */
     523       15843 :         index = get_next_indice( st, nBits );
     524       15843 :         *gain_pit = cdbk[index * 2];
     525       15843 :         *gain_code = cdbk[index * 2 + 1] * gcode0;
     526       15843 :         gains_mem[1] = *gain_code;
     527       15843 :         gains_mem[4] = *gain_pit;
     528             :     }
     529       19710 :     else if ( i_subfr == 2 * L_SUBFR )
     530             :     {
     531        9855 :         b = b_3sfr;
     532        9855 :         n_pred = 6;
     533             : 
     534        9855 :         switch ( nBits )
     535             :         {
     536           6 :             case 7:
     537             :             {
     538           6 :                 cdbk = gp_gamma_3sfr_7b;
     539           6 :                 break;
     540             :             }
     541        9849 :             case 6:
     542             :             {
     543        9849 :                 cdbk = gp_gamma_3sfr_6b;
     544        9849 :                 break;
     545             :             }
     546             :         }
     547             : 
     548             :         /* calculate predicted gain */
     549        9855 :         aux[0] = 1.0f;
     550        9855 :         aux[1] = ctype;
     551        9855 :         aux[2] = (float) log10( gains_mem[0] );
     552        9855 :         aux[3] = (float) log10( gains_mem[1] );
     553        9855 :         aux[4] = gains_mem[3];
     554        9855 :         aux[5] = gains_mem[4];
     555        9855 :         gcode0 = (float) pow( 10, dotp( b, aux, n_pred ) );
     556             : 
     557             :         /* retrieve the codebook index and calculate both gains */
     558        9855 :         index = get_next_indice( st, nBits );
     559        9855 :         *gain_pit = cdbk[index * 2];
     560        9855 :         *gain_code = cdbk[index * 2 + 1] * gcode0;
     561             : 
     562        9855 :         gains_mem[2] = *gain_code;
     563        9855 :         gains_mem[5] = *gain_pit;
     564             :     }
     565        9855 :     else if ( i_subfr == 3 * L_SUBFR )
     566             :     {
     567        9855 :         b = b_4sfr;
     568        9855 :         n_pred = 8;
     569             : 
     570        9855 :         switch ( nBits )
     571             :         {
     572           0 :             case 7:
     573             :             {
     574           0 :                 cdbk = gp_gamma_4sfr_7b;
     575           0 :                 break;
     576             :             }
     577        9855 :             case 6:
     578             :             {
     579        9855 :                 cdbk = gp_gamma_4sfr_6b;
     580        9855 :                 break;
     581             :             }
     582             :         }
     583             : 
     584             :         /* calculate predicted gain */
     585        9855 :         aux[0] = 1.0f;
     586        9855 :         aux[1] = ctype;
     587        9855 :         aux[2] = (float) log10( gains_mem[0] );
     588        9855 :         aux[3] = (float) log10( gains_mem[1] );
     589        9855 :         aux[4] = (float) log10( gains_mem[2] );
     590        9855 :         aux[5] = gains_mem[3];
     591        9855 :         aux[6] = gains_mem[4];
     592        9855 :         aux[7] = gains_mem[5];
     593        9855 :         gcode0 = (float) pow( 10, dotp( b, aux, n_pred ) );
     594             : 
     595             :         /* retrieve the codebook index and calculate both gains */
     596        9855 :         index = get_next_indice( st, nBits );
     597        9855 :         *gain_pit = cdbk[index * 2];
     598        9855 :         *gain_code = cdbk[index * 2 + 1] * gcode0;
     599             :     }
     600             : 
     601       51396 :     *norm_gain_code = *gain_code / *gain_inov;
     602             : 
     603       51396 :     return;
     604             : }
     605             : 
     606             : /*--------------------------------------------------------------------------*
     607             :  * gain_dec_SQ()
     608             :  *
     609             :  * Decoding of pitch and codebook gains using scalar quantizers
     610             :  *-------------------------------------------------------------------------*/
     611             : 
     612      137919 : 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      137919 :     nBits = st->acelp_cfg.gains_mode[i_subfr / L_SUBFR];
     631             : 
     632             :     /*-----------------------------------------------------------------*
     633             :      * decode pitch gain
     634             :      *-----------------------------------------------------------------*/
     635             : 
     636      137919 :     index = get_next_indice( st, nBits >> 1 );
     637             :     /*Ei = (G_PITCH_MAX - G_PITCH_MIN) / ((1 << (nBits>>1)) - 1);*/ /* set quantization step */
     638      137919 :     tmp16 = div_s( 1, ( ( 1 << ( nBits >> 1 ) ) - 1 ) );            /* Q15*/
     639      137919 :     Ei = (float) mult_r( (int16_t) ( G_PITCH_MAX * 8192.0f + 0.5f ), tmp16 ) / 8192.0f;
     640             : 
     641      137919 :     *gain_pit = usdequant( index, G_PITCH_MIN, Ei );
     642             : 
     643             :     /*-----------------------------------------------------------------*
     644             :      * calculate the predicted gain code
     645             :      *-----------------------------------------------------------------*/
     646             : 
     647      137919 :     Ecode = ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR;
     648      137919 :     *gain_inov = 1.0f / (float) sqrt( Ecode );
     649      137919 :     Ei = 10 * (float) log10( Ecode );
     650      137919 :     gcode0 = (float) pow( 10, 0.05 * ( Es_pred - Ei ) );
     651             : 
     652             :     /*-----------------------------------------------------------------*
     653             :      * decode normalized codebook gain
     654             :      *-----------------------------------------------------------------*/
     655             : 
     656      137919 :     index = get_next_indice( st, ( nBits + 1 ) >> 1 );
     657      137919 :     *gain_code = gain_dequant( index, G_CODE_MIN, G_CODE_MAX, ( nBits + 1 ) >> 1 );
     658      137919 :     *gain_code *= gcode0;
     659      137919 :     *norm_gain_code = *gain_code / *gain_inov;
     660             : 
     661      137919 :     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           0 : 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           0 :     stepSize = ( topBound - lowBound ) / ( (float) ( 1 << bits ) );
     688             : 
     689             :     /*-----------------------------------------------------------------*
     690             :      * Gaussian codebook gain
     691             :      *-----------------------------------------------------------------*/
     692             : 
     693           0 :     enr = (float) index * stepSize + lowBound; /* quantized codebook gain in dB */
     694           0 :     gain = (float) pow( 10.0f, enr / 20.0f );
     695             : 
     696           0 :     *norm_gain_code = gain / gain_inov;
     697             : 
     698           0 :     return gain;
     699             : }

Generated by: LCOV version 1.14