LCOV - code coverage report
Current view: top level - lib_dec - gaus_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 7 56 12.5 %
Date: 2025-05-23 08:37:30 Functions: 1 4 25.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 void gaus_dec2v( Decoder_State *st, float *code, const int16_t lg, const int16_t nb_bits );
      53             : 
      54             : static void dec_2pos( int16_t index, int16_t *ind1, int16_t *ind2, float *sign1, float *sign2, const int16_t n );
      55             : 
      56             : 
      57             : /*---------------------------------------------------------------------*
      58             :  * gaus_dec()
      59             :  *
      60             :  * no adaptive excitation constructed
      61             :  * - decode the codebook indices,
      62             :  * - find the excitation
      63             :  *---------------------------------------------------------------------*/
      64             : 
      65           0 : void gaus_dec(
      66             :     Decoder_State *st,     /* i/o: decoder state structure                     */
      67             :     const int16_t i_subfr, /* i  :   subframe index                            */
      68             :     float *code,           /* o  :   unvoiced excitation                       */
      69             :     float *norm_gain_code, /* o  :   gain of the normalized gaussian excitation*/
      70             :     float *lp_gainp,       /* i/o: LP-filtered pitch gain (FEC)                */
      71             :     float *lp_gainc,       /* i/o: LP-filtered code gain (FEC)                 */
      72             :     float *gain_inov,      /* o  :   unscaled innovation gain                  */
      73             :     float *tilt_code,      /* o  :   synthesis excitation spectrum tilt        */
      74             :     float *voice_fac,      /* o  :   estimated voicing factor                  */
      75             :     float *gain_pit,       /* o  :   pitch gain                                */
      76             :     float *pt_pitch,       /* o  :   floating pitch buffer                     */
      77             :     float *exc,            /* o  :   excitation signal frame                   */
      78             :     float *gain_code,      /* o  :   gain of the gaussian excitation           */
      79             :     float *exc2            /* o  : Scaled excitation signal frame              */
      80             : )
      81             : {
      82             :     int16_t i, idx, nb_bits;
      83             : 
      84             :     /*----------------------------------------------------------------*
      85             :      * Decode Gaussian excitation
      86             :      *----------------------------------------------------------------*/
      87             : 
      88           0 :     nb_bits = st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR];
      89             : 
      90           0 :     gaus_dec2v( st, code, L_SUBFR, nb_bits >> 1 );
      91             : 
      92             :     /*-----------------------------------------------------------------*
      93             :      * Decode gain of Gaussian excitation and normalized Gaussian excitation
      94             :      *-----------------------------------------------------------------*/
      95             : 
      96           0 :     *gain_inov = 1.0f / (float) sqrt( ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR );
      97             : 
      98           0 :     nb_bits = st->acelp_cfg.gains_mode[i_subfr / L_SUBFR];
      99           0 :     idx = get_next_indice( st, nb_bits );
     100             : 
     101             :     /* safety check in case of bit errors */
     102           0 :     if ( idx > 78 && st->element_mode == EVS_MONO )
     103             :     {
     104           0 :         idx = 78;
     105           0 :         st->BER_detect = 1;
     106             :     }
     107             : 
     108           0 :     *gain_code = gain_dec_gaus( idx, nb_bits, -30.0f, 190.0f, *gain_inov, norm_gain_code );
     109             : 
     110             :     /* update LP filtered gains for the case of frame erasures */
     111           0 :     lp_gain_updt( i_subfr, 0.0f, *norm_gain_code, lp_gainp, lp_gainc, L_FRAME ); /* supposes that gain_dec_gaus() is used for ACELP@12k8 only */
     112             : 
     113             :     /*-----------------------------------------------------------------*
     114             :      * Updates
     115             :      *-----------------------------------------------------------------*/
     116             : 
     117           0 :     *tilt_code = 0.0f;
     118           0 :     *voice_fac = -1.0f;          /* only unvoiced              */
     119           0 :     *gain_pit = 0.0f;            /* needed for BASS postfitler */
     120           0 :     *pt_pitch = (float) L_SUBFR; /* floating pitch buffer      */
     121             : 
     122             :     /*-----------------------------------------------------------------*
     123             :      * Construct scaled excitation
     124             :      *-----------------------------------------------------------------*/
     125             : 
     126           0 :     set_f( &exc2[i_subfr], 0, L_SUBFR );
     127           0 :     for ( i = 0; i < L_SUBFR; i++ )
     128             :     {
     129           0 :         exc[i + i_subfr] = *gain_code * code[i];
     130             :     }
     131             : 
     132           0 :     return;
     133             : }
     134             : 
     135             : /*-----------------------------------------------------*
     136             :  * gaus_dec2v()
     137             :  *
     138             :  * decoder of Gaussian Codebook for unvoiced
     139             :  * consisting of addition of 2 Gaussian vectors
     140             :  *
     141             :  * One Gaussian vector of 190 values
     142             :  *-----------------------------------------------------*/
     143             : 
     144           0 : static void gaus_dec2v(
     145             :     Decoder_State *st,    /* i/o: decoder state structure     */
     146             :     float *code,          /* o  : decoded gaussian codevector */
     147             :     const int16_t lg,     /* i  : codevector length           */
     148             :     const int16_t nb_bits /* i  : nb ob bits per track (max 6)*/
     149             : )
     150             : {
     151             :     int16_t i, ind1, ind2, idx, index_delta;
     152             :     int16_t nvec, step;
     153             :     float sign1, sign2;
     154             :     float *pt1, *pt2;
     155             :     float gaus_dico2[190];
     156             :     float delta;
     157             : 
     158           0 :     nvec = 1 << nb_bits;
     159           0 :     step = 0x80 >> nb_bits;
     160             : 
     161           0 :     idx = get_next_indice( st, 2 * nb_bits + 1 );
     162           0 :     index_delta = get_next_indice( st, 3 );
     163             : 
     164           0 :     dec_2pos( idx, &ind1, &ind2, &sign1, &sign2, nvec );
     165             : 
     166           0 :     delta = STEP_DELTA * (float) ( index_delta );
     167           0 :     if ( delta > 0.0f )
     168             :     {
     169           0 :         gaus_dico2[0] = gaus_dico[0];
     170           0 :         for ( i = 1; i < 190; i++ )
     171             :         {
     172           0 :             gaus_dico2[i] = ( gaus_dico[i] - delta * gaus_dico[i - 1] ) / ( 1 + delta * delta );
     173             :         }
     174             :     }
     175             :     else
     176             :     {
     177           0 :         for ( i = 0; i < 190; i++ )
     178             :         {
     179           0 :             gaus_dico2[i] = gaus_dico[i];
     180             :         }
     181             :     }
     182             : 
     183           0 :     pt1 = &gaus_dico2[ind1 * step];
     184           0 :     pt2 = &gaus_dico2[ind2 * step];
     185             : 
     186           0 :     for ( i = 0; i < lg; i++ )
     187             :     {
     188           0 :         code[i] = pt1[i] * sign1 + pt2[i] * sign2;
     189             :     }
     190             : 
     191           0 :     return;
     192             : }
     193             : 
     194             : /*-----------------------------------------------------*
     195             :  * dec_2pos()
     196             :  *
     197             :  * Decode the codevectors positions and signs
     198             :  *-----------------------------------------------------*/
     199             : 
     200           0 : static void dec_2pos(
     201             :     int16_t index,  /* i  : quantization index    */
     202             :     int16_t *ind1,  /* o  : 1st vector index      */
     203             :     int16_t *ind2,  /* o  : 2nd vector index      */
     204             :     float *sign1,   /* o  : 1st vector sign       */
     205             :     float *sign2,   /* o  : 2nd vector sign       */
     206             :     const int16_t n /* i  : nb. of vectors in cb. */
     207             : )
     208             : {
     209             :     int16_t i;
     210             : 
     211           0 :     i = index & 1;
     212           0 :     if ( i == 0 )
     213             :     {
     214           0 :         *sign1 = 1.0f;
     215             :     }
     216             :     else
     217             :     {
     218           0 :         *sign1 = -1.0f;
     219             :     }
     220             : 
     221           0 :     index = index >> 1;
     222             : 
     223           0 :     *ind1 = index / n;
     224           0 :     *ind2 = index - ( *ind1 * n );
     225           0 :     if ( *ind1 > *ind2 )
     226             :     {
     227           0 :         *sign2 = -*sign1;
     228             :     }
     229             :     else
     230             :     {
     231           0 :         *sign2 = *sign1;
     232             :     }
     233             : 
     234           0 :     return;
     235             : }
     236             : 
     237             : 
     238             : /*-----------------------------------------------------*
     239             :  * gaus_L2_dec :
     240             :  *
     241             :  * decoder of Gaussian Codebook for unvoiced as Layer 2
     242             :  *
     243             :  * One Gaussian vector
     244             :  *-----------------------------------------------------*/
     245             : 
     246       24000 : void gaus_L2_dec(
     247             :     float *code, /* o  :   decoded gaussian codevector */
     248             :     float tilt_code,
     249             :     const float *Aq,
     250             :     float formant_enh_num,
     251             :     int16_t *seed_acelp /* i/o: random seed */
     252             : )
     253             : {
     254             :     int16_t i;
     255             : 
     256             :     /*Generate white gaussian noise using central limit theorem method (N only 4 as E_util_random is not purely uniform)*/
     257     1560000 :     for ( i = 0; i < L_SUBFR; i++ )
     258             :     {
     259     1536000 :         code[i] = (float) ( own_random( seed_acelp ) ) / ( 1 << 15 );
     260     1536000 :         code[i] += (float) ( own_random( seed_acelp ) ) / ( 1 << 15 );
     261     1536000 :         code[i] += (float) ( own_random( seed_acelp ) ) / ( 1 << 15 );
     262             :     }
     263             : 
     264             :     /*Shape the gaussian excitation*/
     265       24000 :     cb_shape( 1, 0, 0, 1, 0, formant_enh_num, FORMANT_SHARPENING_G2, Aq, code, tilt_code, 0, L_SUBFR );
     266             : 
     267       24000 :     return;
     268             : }

Generated by: LCOV version 1.14