LCOV - code coverage report
Current view: top level - lib_com - gs_gains.c (source / functions) Hit Total Coverage
Test: Coverage on main @ 6baab0c613aa6c7100498ed7b93676aa8198a493 Lines: 251 252 99.6 %
Date: 2025-05-29 08:28:55 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     1794864 : 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     1794864 :     StartBin = 0;
      74     1794864 :     NB_Qbins = 0;
      75    30679138 :     for ( i_band = 0; i_band < Mbands_gn; i_band++ )
      76             :     {
      77    28884274 :         StartBin += NB_Qbins;
      78    28884274 :         NB_Qbins = mfreq_bindiv_loc[i_band];
      79    28884274 :         if ( ReUseGain == 1 )
      80             :         {
      81    14250411 :             y_gain = Ener_per_bd_yQ[i_band];
      82             :         }
      83             :         else
      84             :         {
      85    14633863 :             y_gain = (float) pow( 10, ( Ener_per_bd_iQ[i_band] - Ener_per_bd_yQ[i_band] ) );
      86    14633863 :             Ener_per_bd_yQ[i_band] = y_gain;
      87             :         }
      88             : 
      89   493911026 :         for ( i = StartBin; i < NB_Qbins + StartBin; i++ )
      90             :         {
      91   465026752 :             exc_diffQ[i] *= y_gain;
      92             :         }
      93             :     }
      94             : 
      95     1794864 :     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     4559459 : 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     4559459 :     pt = exc_diff;
     119    13678377 :     for ( j = 0; j < 2; j++ )
     120             :     {
     121     9118918 :         y_gain4[j] = 0;
     122     9118918 :         etmp = 0.02f;
     123             : 
     124     9118918 :         pt = exc_diff + j * 8;
     125    82070262 :         for ( i = 0; i < 8; i++ )
     126             :         {
     127    72951344 :             etmp += ( *pt * *pt );
     128    72951344 :             pt++;
     129             :         }
     130             : 
     131             :         /* normalized to 16 bins to easy the quantization */
     132     9118918 :         y_gain4[j] = (float) log10( sqrt( 2 * etmp ) );
     133             :     }
     134             : 
     135    63826278 :     for ( j = 1; j < Mband - 2; j++ )
     136             :     {
     137    59266819 :         etmp = 0.01f;
     138             : 
     139    59266819 :         pt = exc_diff + j * 16;
     140  1007535923 :         for ( i = 0; i < 16; i++ )
     141             :         {
     142   948269104 :             etmp += ( *pt * *pt );
     143   948269104 :             pt++;
     144             :         }
     145             : 
     146    59266819 :         y_gain4[j + 1] = (float) log10( sqrt( etmp ) );
     147             :     }
     148             : 
     149     4559459 :     if ( Eflag == 1 )
     150             :     {
     151     4557122 :         etmp = 0.01f;
     152             : 
     153     4557122 :         pt = exc_diff + j * 16;
     154   150385026 :         for ( i = 0; i < 32; i++ )
     155             :         {
     156   145827904 :             etmp += ( *pt * *pt );
     157   145827904 :             pt++;
     158             :         }
     159             : 
     160     4557122 :         y_gain4[j + 1] = (float) log10( sqrt( etmp / 2 ) );
     161             :     }
     162             : 
     163     4559459 :     if ( L_frame == L_FRAME16k )
     164             :     {
     165     1592094 :         etmp = 0.01f;
     166             : 
     167    52539102 :         for ( i = 0; i < 32; i++ )
     168             :         {
     169    50947008 :             etmp += ( *pt * *pt );
     170    50947008 :             pt++;
     171             :         }
     172             : 
     173     1592094 :         y_gain4[j + 2] = (float) log10( sqrt( etmp / 2 ) );
     174             : 
     175    52539102 :         for ( i = 0; i < 32; i++ )
     176             :         {
     177    50947008 :             etmp += ( *pt * *pt );
     178    50947008 :             pt++;
     179             :         }
     180             : 
     181     1592094 :         y_gain4[j + 3] = (float) log10( sqrt( etmp / 2 ) );
     182             :     }
     183             : 
     184     4559459 :     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      885475 : 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      885475 :     Gain_off = 0.0f;
     211      885475 :     if ( coder_type == INACTIVE || coder_type == UNVOICED )
     212             :     {
     213      646437 :         if ( core_brate <= ACELP_5k00 && coder_type == UNVOICED )
     214             :         {
     215          44 :             Gain_off = 9.f;
     216             :         }
     217      646393 :         else if ( core_brate <= ACELP_7k20 )
     218             :         {
     219      547357 :             Gain_off = 8.f; /* 0 dB */
     220             :         }
     221       99036 :         else if ( core_brate <= ACELP_8k00 )
     222             :         {
     223        6824 :             Gain_off = 6.6f; /* ~-3.3 dB */
     224             :         }
     225       92212 :         else if ( core_brate <= ACELP_9k60 )
     226             :         {
     227        5756 :             Gain_off = 4.8f; /* ~-2.4 dB */
     228             :         }
     229       86456 :         else if ( core_brate <= ACELP_11k60 )
     230             :         {
     231       20068 :             Gain_off = 3.5f; /* ~-2.4 dB */
     232             :         }
     233       66388 :         else if ( core_brate <= ACELP_13k20 )
     234             :         {
     235       10784 :             Gain_off = 3.0f; /* ~-2.4 dB */
     236             :         }
     237             :     }
     238             : 
     239      885475 :     if ( coder_type != INACTIVE && coder_type != UNVOICED )
     240             :     {
     241     4063646 :         for ( i = 0; i < Mbands_gn; i++ )
     242             :         {
     243     3824608 :             Gain_out[i] = Gain_in[i] + mean_g;
     244             :         }
     245             :     }
     246             :     else
     247             :     {
     248             :         /*mimic ACELP decay of energy for low rates*/
     249      646437 :         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       31756 :             for ( i = 0; i < Mbands_gn; i++ )
     253             :             {
     254       29888 :                 Gain_out[i] += mean_g - i * ( Gain_off / 20.f ) / ( (float) Mbands_gn );
     255             :             }
     256             :         }
     257             :         else
     258             :         {
     259    11048809 :             for ( i = 0; i < Mbands_gn; i++ )
     260             :             {
     261    10404240 :                 Gain_out[i] = Gain_in[i] + mean_g - ( i * ( Gain_off / 20.f ) / ( (float) Mbands_gn ) );
     262             :             }
     263             :         }
     264             :     }
     265             : 
     266      885475 :     return;
     267             : }
     268             : 
     269             : 
     270             : /*-------------------------------------------------------------------*
     271             :  * gsc_gainQ()
     272             :  *
     273             :  * Quantization of the energy per band
     274             :  *-------------------------------------------------------------------*/
     275             : 
     276      388030 : 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      388030 :     int16_t i, idx_g = 0;
     292             :     float mean_4g[1], ftmp1;
     293      388030 :     int16_t Mbands_gn = MBANDS_GN;
     294             :     float y_gain_tmp3[MBANDS_GN];
     295             : 
     296      388030 :     if ( L_frame == L_FRAME16k )
     297             :     {
     298       19792 :         Mbands_gn = MBANDS_GN16k;
     299             :     }
     300             : 
     301      388030 :     mean_4g[0] = 0;
     302             : 
     303      388030 :     if ( ( coder_type == AUDIO || coder_type == INACTIVE ) && bwidth == NB )
     304             :     {
     305         302 :         ftmp1 = mean( y_gain4, 10 ) - 0.6f;
     306        5134 :         for ( i = 0; i < Mbands_gn; i++ )
     307             :         {
     308        4832 :             if ( y_gain4[i] < ftmp1 )
     309             :             {
     310         912 :                 y_gain_tmp2[i] = ftmp1;
     311             :             }
     312             :             else
     313             :             {
     314        3920 :                 y_gain_tmp2[i] = y_gain4[i];
     315             :             }
     316             :         }
     317             : 
     318             :         /* Quantized mean gain without clipping */
     319         302 :         mean_4g[0] = mean( y_gain_tmp2, 10 );
     320         302 :         idx_g = (int16_t) vquant( mean_4g, Gain_meanNB, mean_4g, Gain_mean_dicNB, 1, 64 );
     321         302 :         push_indice( hBstr, IND_MEAN_GAIN2, idx_g, 6 );
     322             : 
     323        5134 :         for ( i = 0; i < Mbands_gn; i++ )
     324             :         {
     325        4832 :             y_gain_tmp[i] = y_gain_tmp2[i] - mean_4g[0];
     326             :         }
     327             : 
     328         302 :         if ( y_gain_tmp[9] < -0.3f )
     329             :         {
     330           0 :             y_gain_tmp[9] = -0.3f;
     331             :         }
     332             : 
     333         302 :         set_f( y_gain_tmp + 10, 0.0f, MBANDS_GN - 10 );
     334         302 :         idx_g = (int16_t) vquant( y_gain_tmp, Mean_dic_NB, y_gain_tmp, Gain_dic1_NB, 3, 64 );
     335         302 :         push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
     336             : 
     337         302 :         if ( core_brate < ACELP_9k60 )
     338             :         {
     339         283 :             idx_g = vquant( y_gain_tmp + 3, Mean_dic_NB + 3, y_gain_tmp + 3, Gain_dic2_NB, 3, 32 );
     340         283 :             push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
     341             : 
     342         283 :             idx_g = vquant( y_gain_tmp + 6, Mean_dic_NB + 6, y_gain_tmp + 6, Gain_dic3_NB, 4, 16 );
     343         283 :             push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 4 );
     344             :         }
     345             :         else
     346             :         {
     347          19 :             idx_g = vquant( y_gain_tmp + 3, Mean_dic_NB + 3, y_gain_tmp + 3, Gain_dic2_NBHR, 3, 64 );
     348          19 :             push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
     349             : 
     350          19 :             idx_g = vquant( y_gain_tmp + 6, Mean_dic_NB + 6, y_gain_tmp + 6, Gain_dic3_NBHR, 4, 128 );
     351          19 :             push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 7 );
     352             :         }
     353             : 
     354         302 :         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           8 :             y_gain_tmp[10] = mean( y_gain_tmp + 6, 3 );
     358           8 :             y_gain_tmp[11] = mean( y_gain_tmp + 7, 3 );
     359           8 :             y_gain_tmp[12] = mean( y_gain_tmp + 8, 3 );
     360           8 :             y_gain_tmp[13] = mean( y_gain_tmp + 9, 3 );
     361           8 :             y_gain_tmp[14] = mean( y_gain_tmp + 10, 3 );
     362           8 :             y_gain_tmp[15] = mean( y_gain_tmp + 11, 3 );
     363             :         }
     364             :         else
     365             :         {
     366         294 :             set_f( y_gain_tmp + 10, 0, MBANDS_GN - 10 );
     367             :         }
     368             :     }
     369             :     else
     370             :     {
     371      387728 :         ftmp1 = mean( y_gain4, 16 );
     372     6630960 :         for ( i = 0; i < Mbands_gn; i++ )
     373             :         {
     374     6243232 :             if ( y_gain4[i] < ftmp1 - 0.6f )
     375             :             {
     376        6039 :                 y_gain_tmp2[i] = ftmp1 - .6f;
     377             :             }
     378     6237193 :             else if ( y_gain4[i] > ftmp1 + 0.6f )
     379             :             {
     380       56218 :                 y_gain_tmp2[i] = ftmp1 + 0.6f;
     381             :             }
     382             :             else
     383             :             {
     384     6180975 :                 y_gain_tmp2[i] = y_gain4[i];
     385             :             }
     386             :         }
     387             : 
     388      387728 :         mean_4g[0] = mean( y_gain_tmp2, 16 );
     389      387728 :         idx_g = vquant( mean_4g, mean_m, mean_4g, mean_gain_dic, 1, 64 );
     390      387728 :         push_indice( hBstr, IND_MEAN_GAIN2, idx_g, 6 );
     391             : 
     392             :         /* Subtraction of the average gain */
     393     6630960 :         for ( i = 0; i < Mbands_gn; i++ )
     394             :         {
     395     6243232 :             y_gain_tmp[i] = y_gain_tmp2[i] - mean_4g[0];
     396             :         }
     397             : 
     398      387728 :         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      309961 :             mvr2r( y_gain_tmp, y_gain_tmp2, 8 );
     408             : 
     409      309961 :             y_gain_tmp2[8] = y_gain_tmp[8];
     410      309961 :             y_gain_tmp2[9] = y_gain_tmp[10];
     411      309961 :             y_gain_tmp2[10] = y_gain_tmp[12];
     412      309961 :             y_gain_tmp2[11] = y_gain_tmp[14];
     413             : 
     414      309961 :             idx_g = 0;
     415      309961 :             idx_g = vquant( y_gain_tmp2, YGain_mean_LR, y_gain_tmp2, YGain_dic1_LR, 3, 32 );
     416      309961 :             push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
     417             : 
     418      309961 :             if ( !( coder_type == INACTIVE && tdm_LRTD_flag == 0 && idchan == 1 ) || core_brate_inp > GSC_LRES_GAINQ_LIMIT )
     419             :             {
     420      309939 :                 idx_g = vquant( y_gain_tmp2 + 3, YGain_mean_LR + 3, y_gain_tmp2 + 3, YGain_dic2_LR, 4, 32 );
     421      309939 :                 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      309939 :                 idx_g = vquant( y_gain_tmp2 + 7, YGain_mean_LR + 7, y_gain_tmp2 + 7, YGain_dic3_LR, 5, 32 );
     429      309939 :                 push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
     430             : 
     431      309939 :                 set_f( y_gain_tmp2 + 12, 0, MBANDS_GN - 12 );
     432             : 
     433             :                 /* Update to quantized vector */
     434      309939 :                 mvr2r( y_gain_tmp2, y_gain_tmp, 8 );
     435             : 
     436      309939 :                 mvr2r( y_gain_tmp2 + 8, y_gain_tmp3, 4 );
     437      309939 :                 set_f( y_gain_tmp + 8, 0, 8 );
     438      309939 :                 fft_rel( y_gain_tmp2 + 8, 4, 2 );
     439             : 
     440      309939 :                 mvr2r( y_gain_tmp2 + 8, y_gain_tmp + 8, 3 );
     441      309939 :                 y_gain_tmp[15] = y_gain_tmp2[11];
     442      309939 :                 ifft_rel( y_gain_tmp + 8, 8, 3 );
     443             : 
     444     2789451 :                 for ( i = 8; i < 16; i++ )
     445             :                 {
     446     2479512 :                     y_gain_tmp[i] *= 1.41f;
     447             :                 }
     448             : 
     449      309939 :                 y_gain_tmp[8] = y_gain_tmp3[0];
     450      309939 :                 y_gain_tmp[10] = y_gain_tmp3[1];
     451      309939 :                 y_gain_tmp[12] = y_gain_tmp3[2];
     452      309939 :                 y_gain_tmp[14] = y_gain_tmp3[3];
     453             :             }
     454             :             else
     455             :             {
     456          22 :                 mvr2r( y_gain_tmp2, y_gain_tmp, 3 );
     457          22 :                 set_f( y_gain_tmp + 3, 0.0f, MBANDS_GN16k - 3 );
     458             :             }
     459             :         }
     460             :         else
     461             :         {
     462       77767 :             if ( L_frame == L_FRAME )
     463             :             {
     464       57975 :                 idx_g = vquant( y_gain_tmp, YG_mean16, y_gain_tmp, YG_dicMR_1, 4, 64 );
     465       57975 :                 push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
     466             : 
     467       57975 :                 idx_g = vquant( y_gain_tmp + 4, YG_mean16 + 4, y_gain_tmp + 4, YG_dicMR_2, 4, 32 );
     468       57975 :                 push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
     469             : 
     470       57975 :                 idx_g = vquant( y_gain_tmp + 8, YG_mean16 + 8, y_gain_tmp + 8, YG_dicMR_3, 4, 32 );
     471       57975 :                 push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
     472             : 
     473       57975 :                 idx_g = vquant( y_gain_tmp + 12, YG_mean16 + 12, y_gain_tmp + 12, YG_dicMR_4, 4, 16 );
     474       57975 :                 push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 4 );
     475             :             }
     476             :             else
     477             :             {
     478       19792 :                 idx_g = vquant( y_gain_tmp, YG_mean16HR, y_gain_tmp, YG_dicHR_1, 4, 128 );
     479       19792 :                 push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 7 );
     480             : 
     481       19792 :                 idx_g = vquant( y_gain_tmp + 4, YG_mean16HR + 4, y_gain_tmp + 4, YG_dicHR_2, 4, 64 );
     482       19792 :                 push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
     483             : 
     484       19792 :                 idx_g = vquant( y_gain_tmp + 8, YG_mean16HR + 8, y_gain_tmp + 8, YG_dicHR_3, 4, 64 );
     485       19792 :                 push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
     486             : 
     487       19792 :                 idx_g = vquant( y_gain_tmp + 12, YG_mean16HR_16kHz, y_gain_tmp + 12, YG_dicHR_4_16kHz, 4, 64 );
     488       19792 :                 push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
     489             : 
     490       19792 :                 idx_g = vquant( y_gain_tmp + 16, YG_meanL2G_16kHz, y_gain_tmp + 16, YG_dicL2G_16kHz, 2, 8 );
     491       19792 :                 push_indice( hBstr, IND_Y_GAIN_HF, idx_g, 3 );
     492             :             }
     493             :         }
     494             :     }
     495             : 
     496      388030 :     GSC_gain_DQ( element_mode, ENC, coder_type, Mbands_gn, core_brate, mean_4g[0], y_gain_tmp, y_gainQ );
     497             : 
     498      388030 :     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      497445 : 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      497445 :     int16_t Mbands_gn = MBANDS_GN;
     520             :     float y_gain_tmp3[MBANDS_GN];
     521             : 
     522      497445 :     if ( st->L_frame == L_FRAME16k )
     523             :     {
     524       25776 :         Mbands_gn = MBANDS_GN16k;
     525             :     }
     526             : 
     527      497445 :     if ( ( coder_type == AUDIO || coder_type == INACTIVE ) && bwidth == NB )
     528             :     {
     529         302 :         idx_g = get_next_indice( st, 6 );
     530         302 :         VDQ_vec( &mean_4g, Gain_meanNB, Gain_mean_dicNB, idx_g, 1 );
     531             : 
     532         302 :         idx_g = get_next_indice( st, 6 );
     533         302 :         VDQ_vec( y_gainQ, Mean_dic_NB, Gain_dic1_NB, idx_g, 3 );
     534             : 
     535         302 :         if ( core_brate < ACELP_9k60 )
     536             :         {
     537         283 :             idx_g = get_next_indice( st, 5 );
     538         283 :             VDQ_vec( y_gainQ + 3, Mean_dic_NB + 3, Gain_dic2_NB, idx_g, 3 );
     539             : 
     540         283 :             idx_g = get_next_indice( st, 4 );
     541         283 :             VDQ_vec( y_gainQ + 6, Mean_dic_NB + 6, Gain_dic3_NB, idx_g, 4 );
     542             :         }
     543             :         else
     544             :         {
     545          19 :             idx_g = get_next_indice( st, 6 );
     546          19 :             VDQ_vec( y_gainQ + 3, Mean_dic_NB + 3, Gain_dic2_NBHR, idx_g, 3 );
     547             : 
     548          19 :             idx_g = get_next_indice( st, 7 );
     549          19 :             VDQ_vec( y_gainQ + 6, Mean_dic_NB + 6, Gain_dic3_NBHR, idx_g, 4 );
     550             :         }
     551             : 
     552         302 :         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           8 :             y_gainQ[10] = mean( y_gainQ + 6, 3 );
     556           8 :             y_gainQ[11] = mean( y_gainQ + 7, 3 );
     557           8 :             y_gainQ[12] = mean( y_gainQ + 8, 3 );
     558           8 :             y_gainQ[13] = mean( y_gainQ + 9, 3 );
     559           8 :             y_gainQ[14] = mean( y_gainQ + 10, 3 );
     560           8 :             y_gainQ[15] = mean( y_gainQ + 11, 3 );
     561             :         }
     562             :         else
     563             :         {
     564         294 :             set_f( y_gainQ + 10, 0, MBANDS_GN - 10 );
     565             :         }
     566             :     }
     567             :     else
     568             :     {
     569      497143 :         idx_g = get_next_indice( st, 6 );
     570      497143 :         VDQ_vec( &mean_4g, mean_m, mean_gain_dic, idx_g, 1 );
     571             : 
     572      497143 :         if ( core_brate < ACELP_9k60 )
     573             :         {
     574             :             /*--------------------------------------------------------------------------------------*
     575             :              * UQ of the first 8 bands and half of the last 8 bands
     576             :              *--------------------------------------------------------------------------------------*/
     577             : 
     578      372284 :             idx_g = get_next_indice( st, 5 );
     579      372284 :             VDQ_vec( y_gainQ, YGain_mean_LR, YGain_dic1_LR, idx_g, 3 );
     580             : 
     581      372284 :             if ( !( coder_type == INACTIVE && st->tdm_LRTD_flag == 0 && st->idchan == 1 ) || st->core_brate > GSC_LRES_GAINQ_LIMIT )
     582             :             {
     583      372262 :                 idx_g = get_next_indice( st, 5 );
     584      372262 :                 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      372262 :                 idx_g = get_next_indice( st, 5 );
     592      372262 :                 VDQ_vec( y_gainQ + 7, YGain_mean_LR + 7, YGain_dic3_LR, idx_g, 5 );
     593             : 
     594      372262 :                 mvr2r( y_gainQ + 8, y_gain_tmp3, 4 );
     595      372262 :                 set_f( y_gainQ + 12, 0.0f, 4 );
     596             : 
     597      372262 :                 fft_rel( y_gainQ + 8, 4, 2 );
     598             : 
     599      372262 :                 y_gainQ[15] = y_gainQ[11];
     600      372262 :                 y_gainQ[11] = 0.0f;
     601             : 
     602      372262 :                 ifft_rel( y_gainQ + 8, 8, 3 );
     603             : 
     604     3350358 :                 for ( i = 8; i < 16; i++ )
     605             :                 {
     606     2978096 :                     y_gainQ[i] *= 1.41f;
     607             :                 }
     608             : 
     609             :                 /*----------------------------------------------------------------------*
     610             :                  * Copy the true Q values in the specific bands
     611             :                  *----------------------------------------------------------------------*/
     612             : 
     613      372262 :                 y_gainQ[8] = y_gain_tmp3[0];
     614      372262 :                 y_gainQ[10] = y_gain_tmp3[1];
     615      372262 :                 y_gainQ[12] = y_gain_tmp3[2];
     616      372262 :                 y_gainQ[14] = y_gain_tmp3[3];
     617             :             }
     618             :             else
     619             :             {
     620          22 :                 set_f( y_gainQ + 3, 0.0f, MBANDS_GN16k - 3 );
     621             :             }
     622             :         }
     623             :         else
     624             :         {
     625      124859 :             if ( st->L_frame == L_FRAME )
     626             :             {
     627       99083 :                 idx_g = get_next_indice( st, 6 );
     628       99083 :                 VDQ_vec( y_gainQ, YG_mean16, YG_dicMR_1, idx_g, 4 );
     629             : 
     630       99083 :                 idx_g = get_next_indice( st, 5 );
     631       99083 :                 VDQ_vec( y_gainQ + 4, YG_mean16 + 4, YG_dicMR_2, idx_g, 4 );
     632             : 
     633       99083 :                 idx_g = get_next_indice( st, 5 );
     634       99083 :                 VDQ_vec( y_gainQ + 8, YG_mean16 + 8, YG_dicMR_3, idx_g, 4 );
     635             : 
     636       99083 :                 idx_g = get_next_indice( st, 4 );
     637       99083 :                 VDQ_vec( y_gainQ + 12, YG_mean16 + 12, YG_dicMR_4, idx_g, 4 );
     638             :             }
     639             :             else
     640             :             {
     641       25776 :                 idx_g = get_next_indice( st, 7 );
     642       25776 :                 VDQ_vec( y_gainQ, YG_mean16HR, YG_dicHR_1, idx_g, 4 );
     643             : 
     644       25776 :                 idx_g = get_next_indice( st, 6 );
     645       25776 :                 VDQ_vec( y_gainQ + 4, YG_mean16HR + 4, YG_dicHR_2, idx_g, 4 );
     646             : 
     647       25776 :                 idx_g = get_next_indice( st, 6 );
     648       25776 :                 VDQ_vec( y_gainQ + 8, YG_mean16HR + 8, YG_dicHR_3, idx_g, 4 );
     649             : 
     650       25776 :                 idx_g = get_next_indice( st, 6 );
     651       25776 :                 VDQ_vec( y_gainQ + 12, YG_mean16HR_16kHz, YG_dicHR_4_16kHz, idx_g, 4 );
     652             : 
     653       25776 :                 idx_g = get_next_indice( st, 3 );
     654       25776 :                 VDQ_vec( y_gainQ + 16, YG_meanL2G_16kHz, YG_dicL2G_16kHz, idx_g, 2 );
     655             :             }
     656             :         }
     657             :     }
     658             : 
     659      497445 :     mvr2r( y_gainQ, old_y_gain, Mbands_gn );
     660             : 
     661      497445 :     GSC_gain_DQ( st->element_mode, DEC, coder_type, Mbands_gn, core_brate, mean_4g, y_gainQ, y_gainQ );
     662             : 
     663      497445 :     return mean_4g;
     664             : }
     665             : 
     666             : 
     667             : /*-------------------------------------------------------------------*
     668             :  * VDQ_vec()
     669             :  *
     670             :  * Return the dequantized vector of index
     671             :  *-------------------------------------------------------------------*/
     672             : 
     673     2140371 : 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     2140371 :     j = index * vec_en;
     684     9157342 :     for ( i = 0; i < vec_en; i++ )
     685             :     {
     686     7016971 :         Qvec_out[i] = dic[j++];
     687             :     }
     688             : 
     689     9157342 :     for ( i = 0; i < vec_en; i++ )
     690             :     {
     691     7016971 :         Qvec_out[i] += mean_dic[i];
     692             :     }
     693             : 
     694     2140371 :     return index;
     695             : }

Generated by: LCOV version 1.14