LCOV - code coverage report
Current view: top level - lib_com - gs_gains.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 196 252 77.8 %
Date: 2025-05-23 08:37:30 Functions: 6 6 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             :  * Local function prototypes
      50             :  *-------------------------------------------------------------------*/
      51             : 
      52             : static int16_t VDQ_vec( float *Qvec_out, const float *mean_dic, const float *dic, const int16_t index, const int16_t vec_en );
      53             : 
      54             : /*-------------------------------------------------------------------*
      55             :  * Comp_and_apply_gain()
      56             :  *
      57             :  * Compute and apply the quantized per band gain
      58             :  *-------------------------------------------------------------------*/
      59             : 
      60      182610 : void Comp_and_apply_gain(
      61             :     float exc_diffQ[],      /* i/o: Quantized excitation              */
      62             :     float Ener_per_bd_iQ[], /* o  : Target ener per band              */
      63             :     float Ener_per_bd_yQ[], /* o  : Ener per band for norm vector     */
      64             :     int16_t Mbands_gn,      /* i  : number of bands                   */
      65             :     const int16_t ReUseGain /* i  : Reuse the gain in Ener_per_bd_yQ  */
      66             : )
      67             : {
      68             :     int16_t i, i_band;
      69             :     int16_t StartBin, NB_Qbins;
      70             :     float y_gain;
      71             : 
      72             :     /* Recreate excitation for local synthesis and decoder */
      73      182610 :     StartBin = 0;
      74      182610 :     NB_Qbins = 0;
      75     3145688 :     for ( i_band = 0; i_band < Mbands_gn; i_band++ )
      76             :     {
      77     2963078 :         StartBin += NB_Qbins;
      78     2963078 :         NB_Qbins = mfreq_bindiv_loc[i_band];
      79     2963078 :         if ( ReUseGain == 1 )
      80             :         {
      81     1468993 :             y_gain = Ener_per_bd_yQ[i_band];
      82             :         }
      83             :         else
      84             :         {
      85     1494085 :             y_gain = (float) pow( 10, ( Ener_per_bd_iQ[i_band] - Ener_per_bd_yQ[i_band] ) );
      86     1494085 :             Ener_per_bd_yQ[i_band] = y_gain;
      87             :         }
      88             : 
      89    51045830 :         for ( i = StartBin; i < NB_Qbins + StartBin; i++ )
      90             :         {
      91    48082752 :             exc_diffQ[i] *= y_gain;
      92             :         }
      93             :     }
      94             : 
      95      182610 :     return;
      96             : }
      97             : 
      98             : 
      99             : /*------------------------------------------------------------------*
     100             :  * Ener_per_band_comp()
     101             :  *
     102             :  * Compute the energy per band in log domain for quantization purposes
     103             :  * Loops are decomposed to accomodate the PVQ quantization
     104             :  *------------------------------------------------------------------*/
     105             : 
     106      578847 : void Ener_per_band_comp(
     107             :     const float exc_diff[], /* i  : target signal               */
     108             :     float y_gain4[],        /* o  : Energy per band to quantize */
     109             :     const int16_t Mband,    /* i  : Max band                    */
     110             :     const int16_t Eflag,    /* i  : flag of highest band        */
     111             :     const int16_t L_frame   /* i  : frame length                */
     112             : )
     113             : {
     114             :     float etmp;
     115             :     const float *pt;
     116             :     int16_t i, j;
     117             : 
     118      578847 :     pt = exc_diff;
     119     1736541 :     for ( j = 0; j < 2; j++ )
     120             :     {
     121     1157694 :         y_gain4[j] = 0;
     122     1157694 :         etmp = 0.02f;
     123             : 
     124     1157694 :         pt = exc_diff + j * 8;
     125    10419246 :         for ( i = 0; i < 8; i++ )
     126             :         {
     127     9261552 :             etmp += ( *pt * *pt );
     128     9261552 :             pt++;
     129             :         }
     130             : 
     131             :         /* normalized to 16 bins to easy the quantization */
     132     1157694 :         y_gain4[j] = (float) log10( sqrt( 2 * etmp ) );
     133             :     }
     134             : 
     135     8103510 :     for ( j = 1; j < Mband - 2; j++ )
     136             :     {
     137     7524663 :         etmp = 0.01f;
     138             : 
     139     7524663 :         pt = exc_diff + j * 16;
     140   127919271 :         for ( i = 0; i < 16; i++ )
     141             :         {
     142   120394608 :             etmp += ( *pt * *pt );
     143   120394608 :             pt++;
     144             :         }
     145             : 
     146     7524663 :         y_gain4[j + 1] = (float) log10( sqrt( etmp ) );
     147             :     }
     148             : 
     149      578847 :     if ( Eflag == 1 )
     150             :     {
     151      578650 :         etmp = 0.01f;
     152             : 
     153      578650 :         pt = exc_diff + j * 16;
     154    19095450 :         for ( i = 0; i < 32; i++ )
     155             :         {
     156    18516800 :             etmp += ( *pt * *pt );
     157    18516800 :             pt++;
     158             :         }
     159             : 
     160      578650 :         y_gain4[j + 1] = (float) log10( sqrt( etmp / 2 ) );
     161             :     }
     162             : 
     163      578847 :     if ( L_frame == L_FRAME16k )
     164             :     {
     165      228540 :         etmp = 0.01f;
     166             : 
     167     7541820 :         for ( i = 0; i < 32; i++ )
     168             :         {
     169     7313280 :             etmp += ( *pt * *pt );
     170     7313280 :             pt++;
     171             :         }
     172             : 
     173      228540 :         y_gain4[j + 2] = (float) log10( sqrt( etmp / 2 ) );
     174             : 
     175     7541820 :         for ( i = 0; i < 32; i++ )
     176             :         {
     177     7313280 :             etmp += ( *pt * *pt );
     178     7313280 :             pt++;
     179             :         }
     180             : 
     181      228540 :         y_gain4[j + 3] = (float) log10( sqrt( etmp / 2 ) );
     182             :     }
     183             : 
     184      578847 :     return;
     185             : }
     186             : 
     187             : 
     188             : /*-------------------------------------------------------------------*
     189             :  * GSC_gain_DQ()
     190             :  *
     191             :  * Form the final vector after gain quantization/Dequantization
     192             :  * Common to both encoder and decoder
     193             :  *-------------------------------------------------------------------*/
     194             : 
     195       90525 : static void GSC_gain_DQ(
     196             :     const int16_t element_mode, /* i  : element mode                            */
     197             :     const int16_t enc_dec,      /* i  : encoder/decoder flag                    */
     198             :     const int16_t coder_type,   /* i  : Coder type                              */
     199             :     const int16_t Mbands_gn,    /* i  : Number of band                          */
     200             :     const int32_t core_brate,   /* i  : Core bitrate                            */
     201             :     const float mean_g,         /* i  : Average gain                            */
     202             :     const float *Gain_in,       /* i  : Unquantized gain vector                 */
     203             :     float *Gain_out             /* o  : Level adjusted unquantized gain vector  */
     204             : )
     205             : {
     206             :     float Gain_off;
     207             :     int16_t i;
     208             : 
     209             :     /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */
     210       90525 :     Gain_off = 0.0f;
     211       90525 :     if ( coder_type == INACTIVE || coder_type == UNVOICED )
     212             :     {
     213       46573 :         if ( core_brate <= ACELP_5k00 && coder_type == UNVOICED )
     214             :         {
     215          32 :             Gain_off = 9.f;
     216             :         }
     217       46541 :         else if ( core_brate <= ACELP_7k20 )
     218             :         {
     219       29943 :             Gain_off = 8.f; /* 0 dB */
     220             :         }
     221       16598 :         else if ( core_brate <= ACELP_8k00 )
     222             :         {
     223          52 :             Gain_off = 6.6f; /* ~-3.3 dB */
     224             :         }
     225       16546 :         else if ( core_brate <= ACELP_9k60 )
     226             :         {
     227        1375 :             Gain_off = 4.8f; /* ~-2.4 dB */
     228             :         }
     229       15171 :         else if ( core_brate <= ACELP_11k60 )
     230             :         {
     231         646 :             Gain_off = 3.5f; /* ~-2.4 dB */
     232             :         }
     233       14525 :         else if ( core_brate <= ACELP_13k20 )
     234             :         {
     235        1479 :             Gain_off = 3.0f; /* ~-2.4 dB */
     236             :         }
     237             :     }
     238             : 
     239       90525 :     if ( coder_type != INACTIVE && coder_type != UNVOICED )
     240             :     {
     241      747184 :         for ( i = 0; i < Mbands_gn; i++ )
     242             :         {
     243      703232 :             Gain_out[i] = Gain_in[i] + mean_g;
     244             :         }
     245             :     }
     246             :     else
     247             :     {
     248             :         /*mimic ACELP decay of energy for low rates*/
     249       46573 :         if ( element_mode == EVS_MONO && enc_dec == DEC )
     250             :         {
     251             :             /* This is to keep EVS mono bit-exact with the standard (there might be a small desynchronization between encoder and decoder but there is no real quality or interop. issue) */
     252         306 :             for ( i = 0; i < Mbands_gn; i++ )
     253             :             {
     254         288 :                 Gain_out[i] += mean_g - i * ( Gain_off / 20.f ) / ( (float) Mbands_gn );
     255             :             }
     256             :         }
     257             :         else
     258             :         {
     259      812453 :             for ( i = 0; i < Mbands_gn; i++ )
     260             :             {
     261      765898 :                 Gain_out[i] = Gain_in[i] + mean_g - ( i * ( Gain_off / 20.f ) / ( (float) Mbands_gn ) );
     262             :             }
     263             :         }
     264             :     }
     265             : 
     266       90525 :     return;
     267             : }
     268             : 
     269             : 
     270             : /*-------------------------------------------------------------------*
     271             :  * gsc_gainQ()
     272             :  *
     273             :  * Quantization of the energy per band
     274             :  *-------------------------------------------------------------------*/
     275             : 
     276       22806 : float gsc_gainQ(
     277             :     BSTR_ENC_HANDLE hBstr,       /* i/o: encoder bitstream handle     */
     278             :     const int16_t element_mode,  /* i  : element mode                 */
     279             :     const int16_t idchan,        /* i  : channel ID                   */
     280             :     const float y_gain4[],       /* i  : Energy per band              */
     281             :     float y_gainQ[],             /* o  : quantized energy per band    */
     282             :     const int32_t core_brate,    /* i  : Core rate                    */
     283             :     const int16_t coder_type,    /* i  : coding type                  */
     284             :     const int16_t bwidth,        /* i  : input signal bandwidth       */
     285             :     const int16_t L_frame,       /* i  : frame length                 */
     286             :     const int16_t tdm_LRTD_flag, /* i  : LRTD stereo mode flag        */
     287             :     const int32_t core_brate_inp /* i  : true core bitrate            */
     288             : )
     289             : {
     290             :     float y_gain_tmp[MBANDS_GN16k], y_gain_tmp2[MBANDS_GN16k];
     291       22806 :     int16_t i, idx_g = 0;
     292             :     float mean_4g[1], ftmp1;
     293       22806 :     int16_t Mbands_gn = MBANDS_GN;
     294             :     float y_gain_tmp3[MBANDS_GN];
     295             : 
     296       22806 :     if ( L_frame == L_FRAME16k )
     297             :     {
     298        2637 :         Mbands_gn = MBANDS_GN16k;
     299             :     }
     300             : 
     301       22806 :     mean_4g[0] = 0;
     302             : 
     303       22806 :     if ( ( coder_type == AUDIO || coder_type == INACTIVE ) && bwidth == NB )
     304             :     {
     305           0 :         ftmp1 = mean( y_gain4, 10 ) - 0.6f;
     306           0 :         for ( i = 0; i < Mbands_gn; i++ )
     307             :         {
     308           0 :             if ( y_gain4[i] < ftmp1 )
     309             :             {
     310           0 :                 y_gain_tmp2[i] = ftmp1;
     311             :             }
     312             :             else
     313             :             {
     314           0 :                 y_gain_tmp2[i] = y_gain4[i];
     315             :             }
     316             :         }
     317             : 
     318             :         /* Quantized mean gain without clipping */
     319           0 :         mean_4g[0] = mean( y_gain_tmp2, 10 );
     320           0 :         idx_g = (int16_t) vquant( mean_4g, Gain_meanNB, mean_4g, Gain_mean_dicNB, 1, 64 );
     321           0 :         push_indice( hBstr, IND_MEAN_GAIN2, idx_g, 6 );
     322             : 
     323           0 :         for ( i = 0; i < Mbands_gn; i++ )
     324             :         {
     325           0 :             y_gain_tmp[i] = y_gain_tmp2[i] - mean_4g[0];
     326             :         }
     327             : 
     328           0 :         if ( y_gain_tmp[9] < -0.3f )
     329             :         {
     330           0 :             y_gain_tmp[9] = -0.3f;
     331             :         }
     332             : 
     333           0 :         set_f( y_gain_tmp + 10, 0.0f, MBANDS_GN - 10 );
     334           0 :         idx_g = (int16_t) vquant( y_gain_tmp, Mean_dic_NB, y_gain_tmp, Gain_dic1_NB, 3, 64 );
     335           0 :         push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
     336             : 
     337           0 :         if ( core_brate < ACELP_9k60 )
     338             :         {
     339           0 :             idx_g = vquant( y_gain_tmp + 3, Mean_dic_NB + 3, y_gain_tmp + 3, Gain_dic2_NB, 3, 32 );
     340           0 :             push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
     341             : 
     342           0 :             idx_g = vquant( y_gain_tmp + 6, Mean_dic_NB + 6, y_gain_tmp + 6, Gain_dic3_NB, 4, 16 );
     343           0 :             push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 4 );
     344             :         }
     345             :         else
     346             :         {
     347           0 :             idx_g = vquant( y_gain_tmp + 3, Mean_dic_NB + 3, y_gain_tmp + 3, Gain_dic2_NBHR, 3, 64 );
     348           0 :             push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
     349             : 
     350           0 :             idx_g = vquant( y_gain_tmp + 6, Mean_dic_NB + 6, y_gain_tmp + 6, Gain_dic3_NBHR, 4, 128 );
     351           0 :             push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 7 );
     352             :         }
     353             : 
     354           0 :         if ( core_brate <= ACELP_9k60 && coder_type == INACTIVE )
     355             :         {
     356             :             /* Some energy is needed in high band for stat_noise_uv_enc() to be functional in inactive speech */
     357           0 :             y_gain_tmp[10] = mean( y_gain_tmp + 6, 3 );
     358           0 :             y_gain_tmp[11] = mean( y_gain_tmp + 7, 3 );
     359           0 :             y_gain_tmp[12] = mean( y_gain_tmp + 8, 3 );
     360           0 :             y_gain_tmp[13] = mean( y_gain_tmp + 9, 3 );
     361           0 :             y_gain_tmp[14] = mean( y_gain_tmp + 10, 3 );
     362           0 :             y_gain_tmp[15] = mean( y_gain_tmp + 11, 3 );
     363             :         }
     364             :         else
     365             :         {
     366           0 :             set_f( y_gain_tmp + 10, 0, MBANDS_GN - 10 );
     367             :         }
     368             :     }
     369             :     else
     370             :     {
     371       22806 :         ftmp1 = mean( y_gain4, 16 );
     372      392976 :         for ( i = 0; i < Mbands_gn; i++ )
     373             :         {
     374      370170 :             if ( y_gain4[i] < ftmp1 - 0.6f )
     375             :             {
     376        1461 :                 y_gain_tmp2[i] = ftmp1 - .6f;
     377             :             }
     378      368709 :             else if ( y_gain4[i] > ftmp1 + 0.6f )
     379             :             {
     380         582 :                 y_gain_tmp2[i] = ftmp1 + 0.6f;
     381             :             }
     382             :             else
     383             :             {
     384      368127 :                 y_gain_tmp2[i] = y_gain4[i];
     385             :             }
     386             :         }
     387             : 
     388       22806 :         mean_4g[0] = mean( y_gain_tmp2, 16 );
     389       22806 :         idx_g = vquant( mean_4g, mean_m, mean_4g, mean_gain_dic, 1, 64 );
     390       22806 :         push_indice( hBstr, IND_MEAN_GAIN2, idx_g, 6 );
     391             : 
     392             :         /* Subtraction of the average gain */
     393      392976 :         for ( i = 0; i < Mbands_gn; i++ )
     394             :         {
     395      370170 :             y_gain_tmp[i] = y_gain_tmp2[i] - mean_4g[0];
     396             :         }
     397             : 
     398       22806 :         if ( core_brate < ACELP_9k60 )
     399             :         {
     400             :             /* prediction and quantization of the average gain */
     401             : 
     402             :             /*--------------------------------------------------------------------------------------*
     403             :              * Quantization of the first 8 bands
     404             :              * Keep only 4 bands out of the last 8 bands
     405             :              *--------------------------------------------------------------------------------------*/
     406             : 
     407       14663 :             mvr2r( y_gain_tmp, y_gain_tmp2, 8 );
     408             : 
     409       14663 :             y_gain_tmp2[8] = y_gain_tmp[8];
     410       14663 :             y_gain_tmp2[9] = y_gain_tmp[10];
     411       14663 :             y_gain_tmp2[10] = y_gain_tmp[12];
     412       14663 :             y_gain_tmp2[11] = y_gain_tmp[14];
     413             : 
     414       14663 :             idx_g = 0;
     415       14663 :             idx_g = vquant( y_gain_tmp2, YGain_mean_LR, y_gain_tmp2, YGain_dic1_LR, 3, 32 );
     416       14663 :             push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
     417             : 
     418       14663 :             if ( !( coder_type == INACTIVE && tdm_LRTD_flag == 0 && idchan == 1 ) || core_brate_inp > GSC_LRES_GAINQ_LIMIT )
     419             :             {
     420       14663 :                 idx_g = vquant( y_gain_tmp2 + 3, YGain_mean_LR + 3, y_gain_tmp2 + 3, YGain_dic2_LR, 4, 32 );
     421       14663 :                 push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
     422             : 
     423             :                 /*----------------------------------------------------------------------*
     424             :                  * Vector quantization of the first 8 bands + quantization of the 4 bands out of the last 8
     425             :                  * Interpolation of the last 4 bands Q to create bands 8-16
     426             :                  *----------------------------------------------------------------------*/
     427             : 
     428       14663 :                 idx_g = vquant( y_gain_tmp2 + 7, YGain_mean_LR + 7, y_gain_tmp2 + 7, YGain_dic3_LR, 5, 32 );
     429       14663 :                 push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
     430             : 
     431       14663 :                 set_f( y_gain_tmp2 + 12, 0, MBANDS_GN - 12 );
     432             : 
     433             :                 /* Update to quantized vector */
     434       14663 :                 mvr2r( y_gain_tmp2, y_gain_tmp, 8 );
     435             : 
     436       14663 :                 mvr2r( y_gain_tmp2 + 8, y_gain_tmp3, 4 );
     437       14663 :                 set_f( y_gain_tmp + 8, 0, 8 );
     438       14663 :                 fft_rel( y_gain_tmp2 + 8, 4, 2 );
     439             : 
     440       14663 :                 mvr2r( y_gain_tmp2 + 8, y_gain_tmp + 8, 3 );
     441       14663 :                 y_gain_tmp[15] = y_gain_tmp2[11];
     442       14663 :                 ifft_rel( y_gain_tmp + 8, 8, 3 );
     443             : 
     444      131967 :                 for ( i = 8; i < 16; i++ )
     445             :                 {
     446      117304 :                     y_gain_tmp[i] *= 1.41f;
     447             :                 }
     448             : 
     449       14663 :                 y_gain_tmp[8] = y_gain_tmp3[0];
     450       14663 :                 y_gain_tmp[10] = y_gain_tmp3[1];
     451       14663 :                 y_gain_tmp[12] = y_gain_tmp3[2];
     452       14663 :                 y_gain_tmp[14] = y_gain_tmp3[3];
     453             :             }
     454             :             else
     455             :             {
     456           0 :                 mvr2r( y_gain_tmp2, y_gain_tmp, 3 );
     457           0 :                 set_f( y_gain_tmp + 3, 0.0f, MBANDS_GN16k - 3 );
     458             :             }
     459             :         }
     460             :         else
     461             :         {
     462        8143 :             if ( L_frame == L_FRAME )
     463             :             {
     464        5506 :                 idx_g = vquant( y_gain_tmp, YG_mean16, y_gain_tmp, YG_dicMR_1, 4, 64 );
     465        5506 :                 push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
     466             : 
     467        5506 :                 idx_g = vquant( y_gain_tmp + 4, YG_mean16 + 4, y_gain_tmp + 4, YG_dicMR_2, 4, 32 );
     468        5506 :                 push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
     469             : 
     470        5506 :                 idx_g = vquant( y_gain_tmp + 8, YG_mean16 + 8, y_gain_tmp + 8, YG_dicMR_3, 4, 32 );
     471        5506 :                 push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
     472             : 
     473        5506 :                 idx_g = vquant( y_gain_tmp + 12, YG_mean16 + 12, y_gain_tmp + 12, YG_dicMR_4, 4, 16 );
     474        5506 :                 push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 4 );
     475             :             }
     476             :             else
     477             :             {
     478        2637 :                 idx_g = vquant( y_gain_tmp, YG_mean16HR, y_gain_tmp, YG_dicHR_1, 4, 128 );
     479        2637 :                 push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 7 );
     480             : 
     481        2637 :                 idx_g = vquant( y_gain_tmp + 4, YG_mean16HR + 4, y_gain_tmp + 4, YG_dicHR_2, 4, 64 );
     482        2637 :                 push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
     483             : 
     484        2637 :                 idx_g = vquant( y_gain_tmp + 8, YG_mean16HR + 8, y_gain_tmp + 8, YG_dicHR_3, 4, 64 );
     485        2637 :                 push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
     486             : 
     487        2637 :                 idx_g = vquant( y_gain_tmp + 12, YG_mean16HR_16kHz, y_gain_tmp + 12, YG_dicHR_4_16kHz, 4, 64 );
     488        2637 :                 push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
     489             : 
     490        2637 :                 idx_g = vquant( y_gain_tmp + 16, YG_meanL2G_16kHz, y_gain_tmp + 16, YG_dicL2G_16kHz, 2, 8 );
     491        2637 :                 push_indice( hBstr, IND_Y_GAIN_HF, idx_g, 3 );
     492             :             }
     493             :         }
     494             :     }
     495             : 
     496       22806 :     GSC_gain_DQ( element_mode, ENC, coder_type, Mbands_gn, core_brate, mean_4g[0], y_gain_tmp, y_gainQ );
     497             : 
     498       22806 :     return mean_4g[0];
     499             : }
     500             : 
     501             : /*-------------------------------------------------------------------*
     502             :  * gsc_gaindec()
     503             :  *
     504             :  * Generic signal frequency band decoding and application
     505             :  *-------------------------------------------------------------------*/
     506             : 
     507             : /*! r: average frequency gain */
     508       67719 : float gsc_gaindec(
     509             :     Decoder_State *st,        /* i/o: decoder state structure   */
     510             :     float y_gainQ[],          /* o  : quantized gain per band   */
     511             :     const int32_t core_brate, /* i  : core used                 */
     512             :     float old_y_gain[],       /* i/o: AR gain quantizer for low rate */
     513             :     const int16_t coder_type, /* i  : coding type               */
     514             :     const int16_t bwidth      /* i  : input signal bandwidth    */
     515             : )
     516             : {
     517             :     int16_t idx_g, i;
     518             :     float mean_4g;
     519       67719 :     int16_t Mbands_gn = MBANDS_GN;
     520             :     float y_gain_tmp3[MBANDS_GN];
     521             : 
     522       67719 :     if ( st->L_frame == L_FRAME16k )
     523             :     {
     524        7872 :         Mbands_gn = MBANDS_GN16k;
     525             :     }
     526             : 
     527       67719 :     if ( ( coder_type == AUDIO || coder_type == INACTIVE ) && bwidth == NB )
     528             :     {
     529           0 :         idx_g = get_next_indice( st, 6 );
     530           0 :         VDQ_vec( &mean_4g, Gain_meanNB, Gain_mean_dicNB, idx_g, 1 );
     531             : 
     532           0 :         idx_g = get_next_indice( st, 6 );
     533           0 :         VDQ_vec( y_gainQ, Mean_dic_NB, Gain_dic1_NB, idx_g, 3 );
     534             : 
     535           0 :         if ( core_brate < ACELP_9k60 )
     536             :         {
     537           0 :             idx_g = get_next_indice( st, 5 );
     538           0 :             VDQ_vec( y_gainQ + 3, Mean_dic_NB + 3, Gain_dic2_NB, idx_g, 3 );
     539             : 
     540           0 :             idx_g = get_next_indice( st, 4 );
     541           0 :             VDQ_vec( y_gainQ + 6, Mean_dic_NB + 6, Gain_dic3_NB, idx_g, 4 );
     542             :         }
     543             :         else
     544             :         {
     545           0 :             idx_g = get_next_indice( st, 6 );
     546           0 :             VDQ_vec( y_gainQ + 3, Mean_dic_NB + 3, Gain_dic2_NBHR, idx_g, 3 );
     547             : 
     548           0 :             idx_g = get_next_indice( st, 7 );
     549           0 :             VDQ_vec( y_gainQ + 6, Mean_dic_NB + 6, Gain_dic3_NBHR, idx_g, 4 );
     550             :         }
     551             : 
     552           0 :         if ( core_brate <= ACELP_9k60 && coder_type == INACTIVE )
     553             :         {
     554             :             /* Some energy is needed in high band for stat_noise_uv_enc to be functional in inactive speech */
     555           0 :             y_gainQ[10] = mean( y_gainQ + 6, 3 );
     556           0 :             y_gainQ[11] = mean( y_gainQ + 7, 3 );
     557           0 :             y_gainQ[12] = mean( y_gainQ + 8, 3 );
     558           0 :             y_gainQ[13] = mean( y_gainQ + 9, 3 );
     559           0 :             y_gainQ[14] = mean( y_gainQ + 10, 3 );
     560           0 :             y_gainQ[15] = mean( y_gainQ + 11, 3 );
     561             :         }
     562             :         else
     563             :         {
     564           0 :             set_f( y_gainQ + 10, 0, MBANDS_GN - 10 );
     565             :         }
     566             :     }
     567             :     else
     568             :     {
     569       67719 :         idx_g = get_next_indice( st, 6 );
     570       67719 :         VDQ_vec( &mean_4g, mean_m, mean_gain_dic, idx_g, 1 );
     571             : 
     572       67719 :         if ( core_brate < ACELP_9k60 )
     573             :         {
     574             :             /*--------------------------------------------------------------------------------------*
     575             :              * UQ of the first 8 bands and half of the last 8 bands
     576             :              *--------------------------------------------------------------------------------------*/
     577             : 
     578       43629 :             idx_g = get_next_indice( st, 5 );
     579       43629 :             VDQ_vec( y_gainQ, YGain_mean_LR, YGain_dic1_LR, idx_g, 3 );
     580             : 
     581       43629 :             if ( !( coder_type == INACTIVE && st->tdm_LRTD_flag == 0 && st->idchan == 1 ) || st->core_brate > GSC_LRES_GAINQ_LIMIT )
     582             :             {
     583       43629 :                 idx_g = get_next_indice( st, 5 );
     584       43629 :                 VDQ_vec( y_gainQ + 3, YGain_mean_LR + 3, YGain_dic2_LR, idx_g, 4 );
     585             : 
     586             :                 /*----------------------------------------------------------------------*
     587             :                  * Interpolation of the last 4 Q bands to create bands 8-16
     588             :                  * And scaling
     589             :                  *----------------------------------------------------------------------*/
     590             : 
     591       43629 :                 idx_g = get_next_indice( st, 5 );
     592       43629 :                 VDQ_vec( y_gainQ + 7, YGain_mean_LR + 7, YGain_dic3_LR, idx_g, 5 );
     593             : 
     594       43629 :                 mvr2r( y_gainQ + 8, y_gain_tmp3, 4 );
     595       43629 :                 set_f( y_gainQ + 12, 0.0f, 4 );
     596             : 
     597       43629 :                 fft_rel( y_gainQ + 8, 4, 2 );
     598             : 
     599       43629 :                 y_gainQ[15] = y_gainQ[11];
     600       43629 :                 y_gainQ[11] = 0.0f;
     601             : 
     602       43629 :                 ifft_rel( y_gainQ + 8, 8, 3 );
     603             : 
     604      392661 :                 for ( i = 8; i < 16; i++ )
     605             :                 {
     606      349032 :                     y_gainQ[i] *= 1.41f;
     607             :                 }
     608             : 
     609             :                 /*----------------------------------------------------------------------*
     610             :                  * Copy the true Q values in the specific bands
     611             :                  *----------------------------------------------------------------------*/
     612             : 
     613       43629 :                 y_gainQ[8] = y_gain_tmp3[0];
     614       43629 :                 y_gainQ[10] = y_gain_tmp3[1];
     615       43629 :                 y_gainQ[12] = y_gain_tmp3[2];
     616       43629 :                 y_gainQ[14] = y_gain_tmp3[3];
     617             :             }
     618             :             else
     619             :             {
     620           0 :                 set_f( y_gainQ + 3, 0.0f, MBANDS_GN16k - 3 );
     621             :             }
     622             :         }
     623             :         else
     624             :         {
     625       24090 :             if ( st->L_frame == L_FRAME )
     626             :             {
     627       16218 :                 idx_g = get_next_indice( st, 6 );
     628       16218 :                 VDQ_vec( y_gainQ, YG_mean16, YG_dicMR_1, idx_g, 4 );
     629             : 
     630       16218 :                 idx_g = get_next_indice( st, 5 );
     631       16218 :                 VDQ_vec( y_gainQ + 4, YG_mean16 + 4, YG_dicMR_2, idx_g, 4 );
     632             : 
     633       16218 :                 idx_g = get_next_indice( st, 5 );
     634       16218 :                 VDQ_vec( y_gainQ + 8, YG_mean16 + 8, YG_dicMR_3, idx_g, 4 );
     635             : 
     636       16218 :                 idx_g = get_next_indice( st, 4 );
     637       16218 :                 VDQ_vec( y_gainQ + 12, YG_mean16 + 12, YG_dicMR_4, idx_g, 4 );
     638             :             }
     639             :             else
     640             :             {
     641        7872 :                 idx_g = get_next_indice( st, 7 );
     642        7872 :                 VDQ_vec( y_gainQ, YG_mean16HR, YG_dicHR_1, idx_g, 4 );
     643             : 
     644        7872 :                 idx_g = get_next_indice( st, 6 );
     645        7872 :                 VDQ_vec( y_gainQ + 4, YG_mean16HR + 4, YG_dicHR_2, idx_g, 4 );
     646             : 
     647        7872 :                 idx_g = get_next_indice( st, 6 );
     648        7872 :                 VDQ_vec( y_gainQ + 8, YG_mean16HR + 8, YG_dicHR_3, idx_g, 4 );
     649             : 
     650        7872 :                 idx_g = get_next_indice( st, 6 );
     651        7872 :                 VDQ_vec( y_gainQ + 12, YG_mean16HR_16kHz, YG_dicHR_4_16kHz, idx_g, 4 );
     652             : 
     653        7872 :                 idx_g = get_next_indice( st, 3 );
     654        7872 :                 VDQ_vec( y_gainQ + 16, YG_meanL2G_16kHz, YG_dicL2G_16kHz, idx_g, 2 );
     655             :             }
     656             :         }
     657             :     }
     658             : 
     659       67719 :     mvr2r( y_gainQ, old_y_gain, Mbands_gn );
     660             : 
     661       67719 :     GSC_gain_DQ( st->element_mode, DEC, coder_type, Mbands_gn, core_brate, mean_4g, y_gainQ, y_gainQ );
     662             : 
     663       67719 :     return mean_4g;
     664             : }
     665             : 
     666             : 
     667             : /*-------------------------------------------------------------------*
     668             :  * VDQ_vec()
     669             :  *
     670             :  * Return the dequantized vector of index
     671             :  *-------------------------------------------------------------------*/
     672             : 
     673      302838 : static int16_t VDQ_vec(
     674             :     float *Qvec_out,       /* o  : Quanitzed vector */
     675             :     const float *mean_dic, /* i  : average codebook */
     676             :     const float *dic,      /* i  : codebook         */
     677             :     const int16_t index,   /* i  : index of codebook*/
     678             :     const int16_t vec_en   /* i  : vector length    */
     679             : )
     680             : {
     681             :     int16_t i, j;
     682             : 
     683      302838 :     j = index * vec_en;
     684     1295289 :     for ( i = 0; i < vec_en; i++ )
     685             :     {
     686      992451 :         Qvec_out[i] = dic[j++];
     687             :     }
     688             : 
     689     1295289 :     for ( i = 0; i < vec_en; i++ )
     690             :     {
     691      992451 :         Qvec_out[i] += mean_dic[i];
     692             :     }
     693             : 
     694      302838 :     return index;
     695             : }

Generated by: LCOV version 1.14