LCOV - code coverage report
Current view: top level - lib_dec - gs_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main @ fec202a8f89be4a2f278a9fc377bfb58b58fab11 Lines: 225 233 96.6 %
Date: 2025-09-14 08:49:17 Functions: 3 3 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 <math.h>
      39             : #include "options.h"
      40             : #ifdef DEBUGGING
      41             : #include "debug.h"
      42             : #endif
      43             : #include "cnst.h"
      44             : #include "rom_com.h"
      45             : #include "prot.h"
      46             : #include "ivas_prot.h"
      47             : #include "wmc_auto.h"
      48             : 
      49             : /*-------------------------------------------------------------------*
      50             :  * decod_audio()
      51             :  *
      52             :  * Decode audio (AC) frames
      53             :  *-------------------------------------------------------------------*/
      54             : 
      55      211433 : void decod_audio(
      56             :     Decoder_State *st,                  /* i/o: decoder static memory                     */
      57             :     float dct_epit[],                   /* o  : GSC excitation in DCT domain              */
      58             :     const float *Aq,                    /* i  : LP filter coefficient                     */
      59             :     float *tmp_noise,                   /* o  : long term temporary noise energy          */
      60             :     float *pitch_buf,                   /* o  : floating pitch values for each subframe   */
      61             :     float *voice_factors,               /* o  : voicing factors                           */
      62             :     float *exc,                         /* i/o: adapt. excitation exc                     */
      63             :     float *exc2,                        /* i/o: adapt. excitation/total exc               */
      64             :     float *bwe_exc,                     /* o  : excitation for SWB TBE                    */
      65             :     float *lsf_new,                     /* i  : ISFs at the end of the frame              */
      66             :     float *gain_buf,                    /* o  : floating pitch gain for each subframe     */
      67             :     const int16_t tdm_lp_reuse_flag,    /* i  : LPC reuse flag                            */
      68             :     const int16_t tdm_low_rate_mode,    /* i  : secondary channel low rate mode flag      */
      69             :     const int16_t tdm_Pitch_reuse_flag, /* i  : primary channel pitch reuse flag          */
      70             :     const float tdm_Pri_pitch_buf[]     /* i  : primary channel pitch buffer              */
      71             : )
      72             : {
      73             :     int16_t tmp_nb_bits_tot, pit_band_idx;
      74             :     GSC_DEC_HANDLE hGSCDec;
      75             :     float code[4 * L_SUBFR];
      76             :     int16_t Diff_len, nb_subfr, i;
      77             :     int16_t nb_frame_flg;
      78      211433 :     float Es_pred = 0.0f;
      79             :     int16_t Len, max_len;
      80             :     int16_t attack_flag;
      81             :     float low_pit;
      82             :     int16_t last_bin;
      83             :     int16_t nbits;
      84             :     float exc_wo_nf[L_FRAME16k];
      85             :     int16_t nb_bits; /* number of bits */
      86             :     int16_t indice;  /* parameter indices to read */
      87             : 
      88      211433 :     hGSCDec = st->hGSCDec;
      89             : 
      90             :     /*---------------------------------------------------------------*
      91             :      * Initialization
      92             :      *---------------------------------------------------------------*/
      93             : 
      94      211433 :     Diff_len = 0;
      95             : 
      96             :     /* decode GSC attack flag (used to reduce possible pre-echo) */
      97      211433 :     attack_flag = get_next_indice( st, 1 );
      98             : 
      99             :     /* decode GSC SWB speech flag */
     100      211433 :     if ( st->GSC_IVAS_mode >= 1 || ( st->coder_type != INACTIVE && ( ( st->element_mode == EVS_MONO && st->total_brate >= ACELP_13k20 ) ||
     101       54341 :                                                                      ( st->element_mode > EVS_MONO && st->total_brate > MIN_BRATE_GSC_NOISY_FLAG && st->bwidth >= SWB && !st->flag_ACELP16k ) ) ) )
     102             :     {
     103      112547 :         st->GSC_noisy_speech = get_next_indice( st, 1 );
     104             :     }
     105             : 
     106             :     /* safety check in case of bit errors */
     107      211433 :     if ( st->GSC_noisy_speech && st->bwidth < SWB && st->GSC_IVAS_mode == 0 )
     108             :     {
     109           0 :         st->BER_detect = 1;
     110           0 :         st->GSC_noisy_speech = 0;
     111             :     }
     112             : 
     113             :     /* set bit-allocation */
     114      211433 :     config_acelp1( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, st->inactive_coder_type_flag, -1, 1, &nb_bits, NULL, st->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode );
     115             : 
     116             :     /*---------------------------------------------------------------*
     117             :      * Decode energy dynamics
     118             :      *---------------------------------------------------------------*/
     119             : 
     120      211433 :     if ( st->GSC_IVAS_mode >= 1 || ( st->GSC_noisy_speech == 1 && st->GSC_IVAS_mode == 0 ) )
     121             :     {
     122      112475 :         nb_subfr = NB_SUBFR;
     123      112475 :         hGSCDec->cor_strong_limit = 0;
     124      112475 :         hGSCDec->noise_lev = NOISE_LEVEL_SP3;
     125             : 
     126      112475 :         if ( st->GSC_IVAS_mode >= 1 )
     127             :         {
     128      108843 :             if ( st->core_brate < GSC_L_RATE_STG && st->GSC_IVAS_mode < 3 )
     129             :             {
     130       26425 :                 nb_subfr = 2;
     131             :             }
     132      108843 :             hGSCDec->noise_lev = NOISE_LEVEL_SP2;
     133             : 
     134      108843 :             if ( st->GSC_IVAS_mode == 3 ) /* Music like */
     135             :             {
     136       81398 :                 hGSCDec->noise_lev = NOISE_LEVEL_SP0;
     137             :             }
     138       27445 :             else if ( st->GSC_noisy_speech == 0 ) /* speech like but not noisy */
     139             :             {
     140       24135 :                 hGSCDec->noise_lev = NOISE_LEVEL_SP3;
     141             :             }
     142             :         }
     143             :     }
     144             :     else
     145             :     {
     146       98958 :         if ( st->core_brate <= ACELP_8k00 )
     147             :         {
     148       47197 :             hGSCDec->noise_lev = get_next_indice( st, 2 ) + NOISE_LEVEL_SP2;
     149             :         }
     150             :         else
     151             :         {
     152       51761 :             hGSCDec->noise_lev = get_next_indice( st, 3 ) + NOISE_LEVEL_SP0;
     153             :         }
     154             : 
     155             :         /*---------------------------------------------------------------*
     156             :          * Decode number of subframes
     157             :          *---------------------------------------------------------------*/
     158             : 
     159       98958 :         if ( st->L_frame == L_FRAME16k && ( st->core_brate <= ACELP_13k20 || st->coder_type == INACTIVE ) )
     160             :         {
     161       25776 :             hGSCDec->cor_strong_limit = 0;
     162       25776 :             nb_subfr = 1;
     163             :         }
     164             :         else
     165             :         {
     166       73182 :             hGSCDec->cor_strong_limit = 1;
     167       73182 :             nb_subfr = SWNB_SUBFR;
     168       73182 :             if ( st->core_brate >= ACELP_9k60 )
     169             :             {
     170       18990 :                 nbits = 1;
     171             : 
     172       18990 :                 if ( st->L_frame == L_FRAME16k && st->core_brate >= MIN_RATE_4SBFR )
     173             :                 {
     174           0 :                     nbits = 2;
     175             :                 }
     176             : 
     177       18990 :                 nb_frame_flg = get_next_indice( st, nbits );
     178             : 
     179       18990 :                 if ( ( nb_frame_flg & 0x1 ) == 0 )
     180             :                 {
     181       18797 :                     nb_subfr = 2 * SWNB_SUBFR;
     182       18797 :                     hGSCDec->cor_strong_limit = 0;
     183             :                 }
     184         193 :                 else if ( st->L_frame == L_FRAME16k && st->core_brate >= MIN_RATE_4SBFR )
     185             :                 {
     186           0 :                     nb_subfr = 2 * SWNB_SUBFR; /* cor_strong already set to 1 */
     187             :                 }
     188             : 
     189       18990 :                 if ( ( nb_frame_flg >> 1 ) == 1 )
     190             :                 {
     191           0 :                     nb_subfr *= 2;
     192             :                 }
     193             :             }
     194             :         }
     195             :     }
     196             : 
     197      211433 :     if ( st->L_frame == L_FRAME16k && nb_subfr == NB_SUBFR )
     198             :     {
     199           0 :         nb_subfr = NB_SUBFR16k;
     200             :     }
     201             : 
     202             :     /*---------------------------------------------------------------*
     203             :      * Decode the last band where the adaptive (pitch) contribution is significant
     204             :      *---------------------------------------------------------------*/
     205             : 
     206      211433 :     if ( st->core_brate < CFREQ_BITRATE )
     207             :     {
     208      142679 :         if ( st->core_brate < ACELP_9k60 && st->coder_type == INACTIVE )
     209             :         {
     210        4540 :             nbits = 1;
     211             :         }
     212             :         else
     213             :         {
     214      138139 :             nbits = 3;
     215             :         }
     216             :     }
     217             :     else
     218             :     {
     219       68754 :         nbits = 4;
     220             :     }
     221             : 
     222      211433 :     if ( st->core_brate < ACELP_9k60 && st->coder_type != INACTIVE )
     223             :     {
     224       95408 :         pit_band_idx = 1;
     225             :     }
     226             :     else
     227             :     {
     228      116025 :         pit_band_idx = get_next_indice( st, nbits );
     229             :     }
     230             : 
     231      211433 :     if ( pit_band_idx != 0 )
     232             :     {
     233      187558 :         if ( st->core_brate < ACELP_9k60 )
     234             :         {
     235       98018 :             pit_band_idx = 7 + BAND1k2; /* At low rate, if pitch model is chosen, then for to be use on extented and constant frequency range */
     236             :         }
     237             :         else
     238             :         {
     239       89540 :             pit_band_idx += BAND1k2;
     240             :         }
     241             : 
     242             :         /* detect bit errors in the bitstream */
     243      187558 :         if ( pit_band_idx > 13 ) /* The maximum decodable index is 10 + BAND1k2 (3) = 13 */
     244             :         {
     245           0 :             pit_band_idx = 13;
     246           0 :             st->BER_detect = 1;
     247             :         }
     248             : 
     249      187558 :         Diff_len = (int16_t) ( mfreq_loc[pit_band_idx] / BIN_SIZE );
     250             :     }
     251             : 
     252      211433 :     hGSCDec->Last_GSC_pit_band_idx = pit_band_idx;
     253             : 
     254             :     /*--------------------------------------------------------------------------------------*
     255             :      * Decode adaptive (pitch) excitation contribution
     256             :      * Reset unvaluable part of the adaptive (pitch) excitation contribution
     257             :      *--------------------------------------------------------------------------------------*/
     258             : 
     259      211433 :     if ( pit_band_idx > BAND1k2 )
     260             :     {
     261             :         /*---------------------------------------------------------------*
     262             :          * Decode adaptive (pitch) excitation contribution
     263             :          *---------------------------------------------------------------*/
     264             : 
     265      187558 :         if ( !( st->GSC_IVAS_mode > 0 && st->L_frame / nb_subfr == 2 * L_SUBFR && st->GSC_IVAS_mode < 3 ) &&
     266      161133 :              ( ( st->core_brate >= MIN_RATE_FCB || st->GSC_noisy_speech ) &&
     267        6936 :                ( ( nb_subfr == NB_SUBFR && st->L_frame == L_FRAME ) || ( nb_subfr == NB_SUBFR16k && st->L_frame == L_FRAME16k ) ) ) )
     268             :         {
     269        4221 :             if ( st->element_mode > EVS_MONO )
     270             :             {
     271        3985 :                 nb_bits = 5;
     272             :             }
     273             :             else
     274             :             {
     275         236 :                 nb_bits = Es_pred_bits_tbl[BIT_ALLOC_IDX( st->core_brate, GENERIC, -1, -1 )];
     276             :             }
     277             : 
     278        4221 :             indice = get_next_indice( st, nb_bits );
     279        4221 :             Es_pred_dec( &Es_pred, indice, nb_bits, 0 );
     280             :         }
     281             : 
     282      187558 :         dec_pit_exc( st, st->L_frame, Aq, Es_pred, pitch_buf, code, exc, nb_subfr, gain_buf, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf );
     283             : 
     284      187558 :         if ( st->core_brate < ACELP_9k60 )
     285             :         {
     286       98018 :             minimum( pitch_buf, st->L_frame >> 6, &low_pit );
     287             : 
     288       98018 :             if ( low_pit < 64 )
     289             :             {
     290       48582 :                 pit_band_idx = 9 + BAND1k2;
     291       48582 :                 if ( st->bwidth == NB )
     292             :                 {
     293         119 :                     pit_band_idx = 7 + BAND1k2;
     294             :                 }
     295             :             }
     296       49436 :             else if ( low_pit < 128 )
     297             :             {
     298       35974 :                 pit_band_idx = 5 + BAND1k2;
     299             :             }
     300             :             else
     301             :             {
     302       13462 :                 pit_band_idx = 3 + BAND1k2;
     303             :             }
     304       98018 :             Diff_len = (int16_t) ( mfreq_loc[pit_band_idx] / BIN_SIZE );
     305       98018 :             hGSCDec->Last_GSC_pit_band_idx = pit_band_idx;
     306             :         }
     307             : 
     308             :         /*---------------------------------------------------------------*
     309             :          * DCT transform
     310             :          *---------------------------------------------------------------*/
     311             : 
     312      187558 :         edct( exc, dct_epit, st->L_frame, st->element_mode );
     313             : 
     314             :         /*---------------------------------------------------------------*
     315             :          * Reset unvaluable part of the adaptive (pitch) excitation contribution
     316             :          *---------------------------------------------------------------*/
     317             : 
     318      187558 :         max_len = st->L_frame - Diff_len;
     319             : 
     320      187558 :         if ( st->bwidth == NB )
     321             :         {
     322         298 :             max_len = 160 - Diff_len;
     323             :         }
     324             : 
     325      187558 :         Len = 80;
     326      187558 :         if ( max_len < 80 )
     327             :         {
     328       55546 :             Len = max_len;
     329             :         }
     330             : 
     331      187558 :         if ( st->core_brate == ACELP_8k00 && st->bwidth != NB )
     332             :         {
     333      109172 :             for ( i = 0; i < max_len; i++ )
     334             :             {
     335      108042 :                 dct_epit[i + Diff_len] = 0.0f;
     336             :             }
     337             :         }
     338             :         else
     339             :         {
     340    14193460 :             for ( i = 0; i < Len; i++ )
     341             :             {
     342    14007032 :                 dct_epit[i + Diff_len] *= sm_table[i];
     343             :             }
     344     8366960 :             for ( ; i < max_len; i++ )
     345             :             {
     346     8180532 :                 dct_epit[i + Diff_len] = 0.0f;
     347             :             }
     348             :         }
     349             : 
     350      187558 :         st->bfi_pitch = (int16_t) ( mean( pitch_buf, nb_subfr ) + 0.5f );
     351      187558 :         st->bfi_pitch_frame = st->L_frame;
     352      187558 :         Diff_len++;
     353      187558 :         st->bpf_off = 0;
     354             :     }
     355             :     else
     356             :     {
     357             :         /* No adaptive (pitch) excitation contribution */
     358       23875 :         st->bpf_off = 1;
     359             : 
     360       23875 :         set_f( dct_epit, 0.0f, st->L_frame );
     361             : 
     362       23875 :         if ( st->L_frame == L_FRAME16k )
     363             :         {
     364       13923 :             set_f( pitch_buf, (float) L_SUBFR16k, NB_SUBFR16k );
     365             :         }
     366             :         else
     367             :         {
     368        9952 :             set_f( pitch_buf, (float) L_SUBFR, NB_SUBFR );
     369             :         }
     370             : 
     371       23875 :         set_f( gain_buf, 0.f, NB_SUBFR16k );
     372             : 
     373       23875 :         st->bfi_pitch = L_SUBFR;
     374       23875 :         st->bfi_pitch_frame = st->L_frame;
     375       23875 :         st->lp_gainp = 0.0f;
     376       23875 :         st->lp_gainc = 0.0f;
     377       23875 :         st->tilt_code = 0;
     378       23875 :         pit_band_idx = 0;
     379       23875 :         Diff_len = 0;
     380             :     }
     381             : 
     382             :     /*--------------------------------------------------------------------------------------*
     383             :      * GSC decoder
     384             :      *--------------------------------------------------------------------------------------*/
     385             : 
     386             :     /* find the current total number of bits used */
     387      211433 :     tmp_nb_bits_tot = st->next_bit_pos;
     388             : 
     389      211433 :     if ( st->extl_brate_orig > 0 )
     390             :     {
     391             :         /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */
     392      207267 :         tmp_nb_bits_tot--;
     393             :     }
     394             : 
     395      211433 :     if ( st->coder_type == INACTIVE && st->core_brate <= ACELP_9k60 && st->idchan == 0 )
     396             :     {
     397        4648 :         tmp_nb_bits_tot += 5; /* for noisiness */
     398             :     }
     399             : 
     400      211433 :     if ( st->idchan == 1 )
     401             :     {
     402          41 :         tmp_nb_bits_tot += TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS;
     403          41 :         if ( st->tdm_LRTD_flag == 1 )
     404             :         {
     405          41 :             tmp_nb_bits_tot -= STEREO_BITS_TCA;
     406             :         }
     407             :     }
     408             : 
     409      211433 :     gsc_dec( st, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st->coder_type, &last_bin, lsf_new, exc_wo_nf, tmp_noise );
     410             : 
     411             :     /*--------------------------------------------------------------------------------------*
     412             :      * iDCT transform
     413             :      *--------------------------------------------------------------------------------------*/
     414             : 
     415      211433 :     edct( dct_epit, exc, st->L_frame, st->element_mode );
     416             : 
     417      211433 :     edct( exc_wo_nf, exc_wo_nf, st->L_frame, st->element_mode );
     418             : 
     419             :     /*----------------------------------------------------------------------*
     420             :      * Remove potential pre-echo in case an onset has been detected
     421             :      *----------------------------------------------------------------------*/
     422             : 
     423      211433 :     pre_echo_att( &hGSCDec->Last_frame_ener, exc, attack_flag, st->last_coder_type, st->L_frame );
     424             : 
     425             :     /*--------------------------------------------------------------------------------------*
     426             :      * Update BWE excitation
     427             :      *--------------------------------------------------------------------------------------*/
     428             : 
     429      211433 :     if ( st->hBWE_TD != NULL )
     430             :     {
     431      211433 :         if ( st->L_frame == L_FRAME16k )
     432             :         {
     433       25776 :             set_f( voice_factors, 0.0f, NB_SUBFR16k );
     434       25776 :             interp_code_4over2( exc, bwe_exc, st->L_frame );
     435             :         }
     436             :         else
     437             :         {
     438      185657 :             set_f( voice_factors, 0.0f, NB_SUBFR16k );
     439      185657 :             interp_code_5over2( exc, bwe_exc, L_FRAME );
     440             :         }
     441             :     }
     442             : 
     443             :     /*--------------------------------------------------------------------------------------*
     444             :      * Updates
     445             :      *--------------------------------------------------------------------------------------*/
     446             : 
     447      211433 :     mvr2r( exc, exc2, st->L_frame );
     448      211433 :     mvr2r( exc_wo_nf, exc, st->L_frame );
     449             : 
     450             :     /*--------------------------------------------------------------------------------------*
     451             :      * Channel aware mode parameters
     452             :      *--------------------------------------------------------------------------------------*/
     453             : 
     454      211433 :     set_f( st->tilt_code_dec, 0, NB_SUBFR16k );
     455             : 
     456      211433 :     return;
     457             : }
     458             : 
     459             : 
     460             : /*-------------------------------------------------------------------*
     461             :  * gsc_dec()
     462             :  *
     463             :  * Generic audio signal decoder
     464             :  *-------------------------------------------------------------------*/
     465             : 
     466      521353 : void gsc_dec(
     467             :     Decoder_State *st,          /* i/o: State structure                                       */
     468             :     float exc_dct_in[],         /* i/o: dct of pitch-only excitation / total excitation       */
     469             :     const int16_t pit_band_idx, /* i  : bin position of the cut-off frequency                 */
     470             :     const int16_t Diff_len,     /* i  : Lenght of the difference signal (before pure spectral)*/
     471             :     const int16_t bits_used,    /* i  : Number of bit used before frequency Q                 */
     472             :     const int16_t nb_subfr,     /* i  : Number of subframe considered                         */
     473             :     const int16_t coder_type,   /* i  : coding type                                           */
     474             :     int16_t *last_bin,          /* i  : last bin of bit allocation                            */
     475             :     const float *lsf_new,       /* i  : ISFs at the end of the frame                          */
     476             :     float *exc_wo_nf,           /* o  : excitation (in f domain) without noisefill            */
     477             :     float *tmp_noise            /* o  : long-term noise energy                                */
     478             : )
     479             : {
     480             :     int16_t i, j, bit, nb_subbands, pvq_len;
     481             :     GSC_DEC_HANDLE hGSCDec;
     482             :     int16_t bitallocation_band[MBANDS_GN_BITALLOC16k];
     483             :     int16_t bitallocation_exc[2];
     484             :     float Ener_per_bd_iQ[MBANDS_GN16k];
     485             :     int16_t max_ener_band[MBANDS_GN_BITALLOC16k];
     486             :     float exc_diffQ[L_FRAME16k];
     487             :     int16_t bits_per_bands[MBANDS_GN_BITALLOC16k]; /*Q3*/
     488             :     float concat_out[L_FRAME16k];
     489             :     int16_t npulses[NB_SFM];
     490             :     int16_t maxpulse[NB_SFM];
     491             :     float mean_gain;
     492      521353 :     int16_t Mbands_gn = 16;
     493             :     int16_t seed_init;
     494             :     float max_eq, max_eq_val;
     495             : 
     496      521353 :     hGSCDec = st->hGSCDec;
     497             : 
     498             :     /*--------------------------------------------------------------------------------------*
     499             :      * Initialization
     500             :      *--------------------------------------------------------------------------------------*/
     501             : 
     502      521353 :     bit = bits_used;
     503      521353 :     if ( coder_type == INACTIVE && ( st->tdm_LRTD_flag == 1 || st->element_mode == IVAS_SCE ) && st->core_brate <= GSC_LRES_GAINQ_LIMIT )
     504             :     {
     505      258360 :         bit += GSC_LRES_NB_NITS;
     506             :     }
     507             : 
     508      521353 :     if ( st->L_frame == L_FRAME16k )
     509             :     {
     510       26270 :         Mbands_gn = MBANDS_GN16k;
     511             :     }
     512             : 
     513      521353 :     set_f( exc_diffQ, 0.0f, st->L_frame );
     514      521353 :     set_f( Ener_per_bd_iQ, 0.0f, Mbands_gn );
     515             : 
     516             :     /*--------------------------------------------------------------------------------------*
     517             :      * Gain decoding
     518             :      *--------------------------------------------------------------------------------------*/
     519             : 
     520      521353 :     if ( st->bfi || st->BER_detect )
     521             :     {
     522             :         /* copy old gain */
     523       23914 :         mvr2r( hGSCDec->old_y_gain, Ener_per_bd_iQ, Mbands_gn );
     524       23914 :         mean_gain = st->lp_gainc / 10.0f;
     525      407526 :         for ( i = 0; i < Mbands_gn; i++ )
     526             :         {
     527      383612 :             Ener_per_bd_iQ[i] += mean_gain;
     528             :         }
     529             : 
     530       23914 :         st->lp_gainc *= 0.98f;
     531             :     }
     532             :     else
     533             :     {
     534      497439 :         i = 0;
     535     1704618 :         while ( i < SIZE_BRATE_INTERMED_TBL )
     536             :         {
     537     1704618 :             if ( st->core_brate <= brate_intermed_tbl[i] )
     538             :             {
     539      497439 :                 break;
     540             :             }
     541     1207179 :             i++;
     542             :         }
     543             : 
     544      497439 :         if ( st->element_mode > EVS_MONO && coder_type == AUDIO && st->core_brate <= STEREO_GSC_BIT_RATE_ALLOC && brate_intermed_tbl[i] == ACELP_9k60 ) /* Bit allocation is mapped to 8 kb/s instead of 9.6 kb/s in this case */
     545             :         {
     546       33698 :             i--;
     547             :         }
     548      497439 :         mean_gain = gsc_gaindec( st, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain, coder_type, st->bwidth );
     549             : 
     550      497439 :         st->lp_gainc = 10.0f * mean_gain;
     551             :     }
     552             : 
     553      521353 :     *tmp_noise = st->lp_gainc;
     554             : 
     555      521353 :     *last_bin = 0;
     556      521353 :     if ( st->core_brate == ACELP_8k00 && st->bwidth != NB )
     557             :     {
     558        1252 :         bitallocation_exc[0] = 0;
     559        1252 :         bitallocation_exc[1] = 0;
     560             :     }
     561             : 
     562      521353 :     set_s( bitallocation_band, 0, MBANDS_GN );
     563             : 
     564      521353 :     if ( st->bfi || st->BER_detect )
     565             :     {
     566       23914 :         max_eq = 1.0f;
     567             : 
     568             :         /*--------------------------------------------------------------------------------------*
     569             :          * Copy old spectrum
     570             :          * reduce spectral dynamic
     571             :          * save spectrum
     572             :          *--------------------------------------------------------------------------------------*/
     573             : 
     574       23914 :         if ( st->last_good == INACTIVE_CLAS || st->Last_GSC_noisy_speech_flag == 1 )
     575             :         {
     576     1907202 :             for ( i = 0; i < st->L_frame; i++ )
     577             :             {
     578     1899904 :                 hGSCDec->Last_GSC_spectrum[i] = 0.8f * own_random( &hGSCDec->seed_tcx ) / PCM16_TO_FLT_FAC + 0.2f * hGSCDec->Last_GSC_spectrum[i];
     579             :             }
     580             : 
     581        7298 :             mvr2r( hGSCDec->Last_GSC_spectrum, exc_diffQ, st->L_frame );
     582             :         }
     583             : 
     584       23914 :         mvr2r( hGSCDec->Last_GSC_spectrum, exc_diffQ, st->L_frame );
     585             : 
     586     6177514 :         for ( i = 0; i < st->L_frame; i++ )
     587             :         {
     588     6153600 :             hGSCDec->Last_GSC_spectrum[i] *= 0.75f;
     589             :         }
     590             :     }
     591             :     else
     592             :     {
     593             :         /*--------------------------------------------------------------------------------------*
     594             :          * PVQ decoder
     595             :          *--------------------------------------------------------------------------------------*/
     596             : 
     597      497439 :         bands_and_bit_alloc( hGSCDec->cor_strong_limit, hGSCDec->noise_lev, st->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, max_ener_band, bits_per_bands, &nb_subbands, NULL, NULL, &pvq_len, coder_type, st->bwidth, st->GSC_noisy_speech, st->L_frame, st->element_mode, st->GSC_IVAS_mode );
     598             : 
     599      497439 :         set_s( npulses, 0, NB_SFM );
     600             : 
     601      497439 :         if ( bit == 0 )
     602             :         {
     603        6409 :             set_zero( concat_out, L_FRAME16k );
     604             :         }
     605             :         else
     606             :         {
     607      491030 :             pvq_core_dec( st, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, bit, nb_subbands, bits_per_bands, NULL, npulses, maxpulse, ACELP_CORE );
     608             :         }
     609             : 
     610      497439 :         max_eq = 0.0f;
     611      497439 :         max_eq_val = 1.0f;
     612             : 
     613      497439 :         if ( ( ( st->core_brate < ACELP_7k20 && st->GSC_noisy_speech == 1 ) || st->core_brate < 6000 ) && coder_type <= UNVOICED )
     614             :         {
     615      279441 :             j = emaximum( concat_out, nb_subbands * 16, &max_eq );
     616      279441 :             max_eq = (float) ( max_eq_val / ( fabs( concat_out[j] ) + 0.01f ) );
     617      279441 :             max_eq = min( max_eq_val, max_eq );
     618             :         }
     619             : 
     620      497439 :         seed_init = 0;
     621     4165356 :         for ( j = 0; j < nb_subbands; j++ )
     622             :         {
     623     3667917 :             mvr2r( concat_out + j * 16, exc_diffQ + max_ener_band[j] * 16, 16 );
     624             : 
     625     3667917 :             if ( max_ener_band[j] > *last_bin )
     626             :             {
     627     2255520 :                 *last_bin = max_ener_band[j];
     628             :             }
     629             : 
     630     3667917 :             bitallocation_band[max_ener_band[j]] = 1;
     631             : 
     632     3667917 :             seed_init += npulses[j];
     633             :         }
     634             : 
     635      497439 :         if ( st->last_coder_type != AUDIO         /* First audio frame */
     636      365800 :              && st->last_coder_type != UNVOICED ) /* last_coder_type == INACTIVE is overwritten in update_dec to UNVOICED */
     637             :         {
     638     6599862 :             for ( j = 0; j < nb_subbands * 16; j++ )
     639             :             {
     640     6551424 :                 if ( concat_out[j] > 0 )
     641             :                 {
     642      693077 :                     seed_init = (int16_t) ( (int32_t) seed_init * 8 );
     643             :                 }
     644     6551424 :                 if ( concat_out[j] < 0 )
     645             :                 {
     646      680467 :                     seed_init = (int16_t) ( (int32_t) seed_init + 3 );
     647             :                 }
     648             :             }
     649             : 
     650       48438 :             hGSCDec->seed_tcx = seed_init;
     651             :         }
     652             : 
     653      497439 :         if ( st->core_brate == ACELP_8k00 && st->bwidth != NB )
     654             :         {
     655        1220 :             if ( exc_diffQ[L_FRAME8k - 2] != 0 )
     656             :             {
     657          39 :                 bitallocation_exc[0] = 1;
     658             :             }
     659             : 
     660        1220 :             if ( exc_diffQ[L_FRAME8k - 1] != 0 )
     661             :             {
     662          78 :                 bitallocation_exc[1] = 1;
     663             :             }
     664             :         }
     665             : 
     666      497439 :         mvr2r( exc_diffQ, hGSCDec->Last_GSC_spectrum, st->L_frame );
     667             : 
     668             :         /*--------------------------------------------------------------------------------------*
     669             :          * Skip adaptive (pitch) contribution frequency band (no noise added over the time contribution)
     670             :          * Find x pulses between 1.6-3.2kHz to code in the spectrum of the residual signal
     671             :          * Gain is based on the inter-correlation gain between the pulses found and residual signal
     672             :          *--------------------------------------------------------------------------------------*/
     673             : 
     674      497439 :         if ( st->GSC_IVAS_mode >= 1 && st->GSC_noisy_speech == 1 )
     675             :         {
     676      638830 :             for ( i = 64; i < st->L_frame; i++ )
     677             :             {
     678      635520 :                 exc_diffQ[i] *= max_eq;
     679             :             }
     680             :         }
     681      494129 :         else if ( ( ( st->core_brate < ACELP_7k20 && st->GSC_noisy_speech == 1 ) || st->core_brate < 6000 ) && coder_type <= UNVOICED )
     682             :         {
     683    71816337 :             for ( i = 0; i < L_FRAME; i++ )
     684             :             {
     685    71536896 :                 exc_diffQ[i] *= max_eq;
     686             :             }
     687             :         }
     688             :         else
     689             :         {
     690      214688 :             freq_dnw_scaling( hGSCDec->cor_strong_limit, coder_type, hGSCDec->noise_lev, st->core_brate, exc_diffQ, st->L_frame );
     691             :         }
     692             :     }
     693             : 
     694             :     /*--------------------------------------------------------------------------------------*
     695             :      * Estimate noise level
     696             :      *--------------------------------------------------------------------------------------*/
     697             : 
     698      521353 :     highband_exc_dct_in( st->core_brate, mfreq_bindiv_loc, *last_bin, Diff_len, hGSCDec->noise_lev, pit_band_idx, exc_diffQ, &hGSCDec->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st->last_coder_type, bitallocation_band, lsf_new, hGSCDec->last_exc_dct_in, &hGSCDec->last_ener, hGSCDec->last_bitallocation_band, bitallocation_exc, st->bfi, coder_type, st->bwidth, exc_wo_nf, st->GSC_noisy_speech, hGSCDec->lt_ener_per_band, st->L_frame, st->element_mode, st->GSC_IVAS_mode );
     699             : 
     700      521353 :     exc_dct_in[0] = 0;
     701             : 
     702      521353 :     return;
     703             : }
     704             : 
     705             : /*-------------------------------------------------------------------*
     706             :  * GSC_dec_init()
     707             :  *
     708             :  * Initialize GSC decoder state structure
     709             :  *-------------------------------------------------------------------*/
     710             : 
     711      166027 : void GSC_dec_init(
     712             :     GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle  */
     713             : )
     714             : {
     715      166027 :     hGSCDec->seed_tcx = 15687;
     716      166027 :     hGSCDec->cor_strong_limit = 1;
     717      166027 :     set_f( hGSCDec->old_y_gain, 0, MBANDS_GN );
     718      166027 :     hGSCDec->noise_lev = NOISE_LEVEL_SP0;
     719      166027 :     set_f( hGSCDec->Last_GSC_spectrum, 0.0f, L_FRAME16k );
     720      166027 :     hGSCDec->Last_GSC_pit_band_idx = 0;
     721             : 
     722      166027 :     set_f( hGSCDec->lt_ener_per_band, 1.0f, MBANDS_GN16k );
     723      166027 :     set_f( hGSCDec->last_exc_dct_in, 0, L_FRAME16k );
     724      166027 :     hGSCDec->last_ener = 0.0f;
     725      166027 :     set_s( hGSCDec->last_bitallocation_band, 0, 6 );
     726             : 
     727      166027 :     hGSCDec->Last_frame_ener = (float) MAX_32;
     728             : 
     729      166027 :     return;
     730             : }

Generated by: LCOV version 1.14