LCOV - code coverage report
Current view: top level - lib_dec - lsf_msvq_ma_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 79 79 100.0 %
Date: 2025-05-23 08:37:30 Functions: 4 4 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 "cnst.h"
      43             : #include "prot.h"
      44             : #include "rom_com.h"
      45             : #include "basop_proto_func.h"
      46             : #include "wmc_auto.h"
      47             : 
      48             : /*---------------------------------------------------------------------*
      49             :  * lsf_msvq_ma_decprm()
      50             :  *
      51             :  *
      52             :  *---------------------------------------------------------------------*/
      53             : 
      54      326406 : int16_t lsf_msvq_ma_decprm(
      55             :     Decoder_State *st,
      56             :     int16_t *param_lpc )
      57             : {
      58             :     int16_t i, nbits_lpc, bits_midlpc;
      59             :     int16_t bits0[MAX_VQ_STAGES], bits1[MAX_VQ_STAGES], stages0, stages1, stages,
      60             :         levels0[MAX_VQ_STAGES], levels1[MAX_VQ_STAGES], *bits;
      61             :     int16_t predmode, mode_lvq, mode_lvq_p, safety_net;
      62             : 
      63      326406 :     bits_midlpc = MIDLSF_NBITS;
      64             : 
      65      326406 :     if ( st->sr_core == INT_FS_16k && st->coder_type == UNVOICED )
      66             :     {
      67       11628 :         find_pred_mode( &predmode, GENERIC, 1 - st->narrowBand /*st->bwidth*/, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate );
      68             :     }
      69             :     else
      70             :     {
      71      314778 :         if ( st->core == TCX_20_CORE )
      72             :         {
      73      313848 :             find_pred_mode( &predmode, AUDIO, 1 - st->narrowBand /*st->bwidth*/, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate );
      74             :         }
      75             :         else
      76             :         {
      77         930 :             find_pred_mode( &predmode, st->coder_type, 1 - st->narrowBand /*st->bwidth*/, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate );
      78             :         }
      79             :     }
      80             : 
      81      326406 :     lsf_allocate( ENDLSF_NBITS - ( predmode >> 1 ), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, bits0, bits1 );
      82             : 
      83      326406 :     nbits_lpc = 0;
      84             : 
      85      326406 :     if ( predmode == 2 )
      86             :     {
      87             :         /* there is choice between SN and AR prediction */
      88      108009 :         safety_net = get_next_indice( st, 1 );
      89             : 
      90      108009 :         if ( safety_net == 1 )
      91             :         {
      92       36792 :             stages = stages0;
      93       36792 :             bits = bits0;
      94             :         }
      95             :         else
      96             :         {
      97       71217 :             stages = stages1;
      98       71217 :             bits = bits1;
      99             :         }
     100      108009 :         *param_lpc = safety_net;
     101      108009 :         param_lpc++;
     102      108009 :         nbits_lpc++;
     103             :     }
     104             :     else
     105             :     {
     106      218397 :         stages = stages1;
     107      218397 :         bits = bits1;
     108             :     }
     109             : 
     110      581595 :     for ( i = 0; i < stages - 1; i++ )
     111             :     {
     112      255189 :         *param_lpc = get_next_indice( st, bits[i] );
     113      255189 :         param_lpc++;
     114      255189 :         nbits_lpc += bits[i];
     115             :     }
     116      326406 :     *param_lpc = get_next_indice( st, LEN_INDICE );
     117      326406 :     param_lpc++;
     118      326406 :     nbits_lpc += LEN_INDICE;
     119             : 
     120             : 
     121      326406 :     *param_lpc = get_next_indice( st, bits[i] - LEN_INDICE );
     122      326406 :     param_lpc++;
     123      326406 :     nbits_lpc += bits[i] - LEN_INDICE;
     124             : 
     125      326406 :     if ( st->coder_type != VOICED && st->core == ACELP_CORE && st->acelp_cfg.midLpc )
     126             :     {
     127             : 
     128        1008 :         *param_lpc = get_next_indice( st, bits_midlpc );
     129        1008 :         nbits_lpc += bits_midlpc;
     130             :     }
     131             : 
     132      326406 :     return nbits_lpc;
     133             : }
     134             : 
     135             : 
     136             : /*---------------------------------------------------------------------*
     137             :  * lsf_bctcvq_decprm()
     138             :  *
     139             :  *
     140             :  *---------------------------------------------------------------------*/
     141             : 
     142         804 : int16_t lsf_bctcvq_decprm(
     143             :     Decoder_State *st,
     144             :     int16_t *param_lpc )
     145             : {
     146             :     int16_t i, nbits_lpc, num_par;
     147             :     const int16_t *bits1;
     148             : 
     149         804 :     num_par = 10;
     150         804 :     bits1 = BC_TCVQ_BIT_ALLOC_40B;
     151             : 
     152         804 :     nbits_lpc = 0;
     153             : 
     154        8844 :     for ( i = 0; i < num_par; i++ )
     155             :     {
     156        8040 :         *param_lpc = get_next_indice( st, bits1[i] );
     157        8040 :         param_lpc++;
     158        8040 :         nbits_lpc += bits1[i];
     159             :     }
     160             : 
     161         804 :     return nbits_lpc;
     162             : }
     163             : 
     164             : 
     165             : /*---------------------------------------------------------------------*
     166             :  * D_lsf_tcxlpc()
     167             :  *
     168             :  *
     169             :  *---------------------------------------------------------------------*/
     170             : 
     171             : /*! r: number of indices */
     172       50958 : int16_t D_lsf_tcxlpc(
     173             :     const int16_t indices[],  /* i  : VQ indices        */
     174             :     float lsf_q[],            /* o  : quantized lsf     */
     175             :     Word16 lsp_q_ind[],       /* o  : quantized lsp (w/o MA prediction) */
     176             :     const int16_t narrowband, /* i  : narrowband flag   */
     177             :     const int16_t cdk,        /* i  : codebook selector */
     178             :     const float mem_MA[]      /* i  : MA memory         */
     179             : )
     180             : {
     181             :     int16_t i, NumIndices;
     182             :     float pred[M16k];
     183             :     const float *means;
     184             :     Word16 lsf_q_ind[M16k];
     185             :     float lsf_rem_q[M];
     186             :     Word16 lsf_rem_q_ind[M];
     187             : 
     188       50958 :     NumIndices = 1;
     189             : 
     190       50958 :     msvq_dec( lsf_codebook[narrowband][cdk], lsf_dims, lsf_offs, TCXLPC_NUMSTAGES, M, M, indices + NumIndices, 0, NULL, lsf_q, lsf_q_ind );
     191             : 
     192       50958 :     NumIndices += TCXLPC_NUMSTAGES;
     193             : 
     194       50958 :     if ( indices[0] )
     195             :     {
     196             :         /* Only add contribution if flag is enabled */
     197             : 
     198             : 
     199       14013 :         msvq_dec( lsf_ind_codebook[narrowband][cdk], lsf_ind_dims, lsf_ind_offs, TCXLPC_IND_NUMSTAGES, M, M, indices + NumIndices, 0, NULL, lsf_rem_q, lsf_rem_q_ind );
     200       14013 :         NumIndices += TCXLPC_IND_NUMSTAGES;
     201             : 
     202             :         /* Add to MA-removed vector */
     203      238221 :         for ( i = 0; i < M; ++i )
     204             :         {
     205      224208 :             lsf_q_ind[i] = add( lsf_q_ind[i], lsf_rem_q_ind[i] );
     206             :         }
     207             :     }
     208             : 
     209             :     /* Inter-frame prediction */
     210       50958 :     means = lsf_means[narrowband];
     211             : 
     212      866286 :     for ( i = 0; i < M; ++i )
     213             :     {
     214      815328 :         pred[i] = means[i] + MU_MA * mem_MA[i];
     215             :     }
     216             : 
     217             :     /* Add prediction */
     218      866286 :     for ( i = 0; i < M; ++i )
     219             :     {
     220      815328 :         lsf_q[i] += pred[i];
     221      815328 :         lsf_q_ind[i] = add( lsf_q_ind[i], LSFM( means[i] ) );
     222             :     }
     223       50958 :     reorder_lsf( lsf_q, TCXLPC_LSF_GAP, M, INT_FS_12k8 );
     224             : 
     225       50958 :     basop_reorder_lsf( lsf_q_ind, LSF_GAP_VAL( TCXLPC_LSF_GAP ), M, INT_FS_FX );
     226             : 
     227       50958 :     if ( lsp_q_ind )
     228             :     {
     229       50958 :         basop_lsf2lsp( lsf_q_ind, lsp_q_ind );
     230             :     }
     231             : 
     232       50958 :     return NumIndices;
     233             : }
     234             : 
     235             : 
     236             : /*---------------------------------------------------------------------*
     237             :  * dec_lsf_tcxlpc()
     238             :  *
     239             :  *
     240             :  *---------------------------------------------------------------------*/
     241             : 
     242             : /*! r: number of bits read */
     243       50958 : int16_t dec_lsf_tcxlpc(
     244             :     Decoder_State *st,        /* i/o: Decoder state       */
     245             :     int16_t **indices,        /* o  : Ptr to VQ indices   */
     246             :     const int16_t narrowband, /* i  : narrowband flag     */
     247             :     const int16_t cdk         /* i  : codebook selector   */
     248             : )
     249             : {
     250             :     int16_t i, start_bit_pos;
     251             :     float lsf_q_ignored[M];
     252             :     Word16 lsf_q_ind[M];
     253             :     int16_t *flag;
     254             : 
     255       50958 :     flag = *indices; /* Save pointer */
     256       50958 :     *flag = 0;       /* Set flag to disabled */
     257       50958 :     ++*indices;
     258             : 
     259       50958 :     start_bit_pos = st->next_bit_pos;
     260             : 
     261      203832 :     for ( i = 0; i < TCXLPC_NUMSTAGES; ++i )
     262             :     {
     263      152874 :         **indices = get_next_indice( st, lsf_numbits[i] );
     264      152874 :         ++*indices;
     265             :     }
     266             : 
     267             :     /* Decode independent lsf */
     268       50958 :     msvq_dec( lsf_codebook[narrowband][cdk], lsf_dims, lsf_offs, TCXLPC_NUMSTAGES, M, M, flag + 1, 0, NULL, lsf_q_ignored, lsf_q_ind );
     269             : 
     270             :     /* Update flag */
     271       50958 :     *flag = lsf_ind_is_active( lsf_q_ind, lsf_means[narrowband], narrowband, cdk );
     272             : 
     273       50958 :     if ( *flag )
     274             :     {
     275       28026 :         for ( i = 0; i < TCXLPC_IND_NUMSTAGES; ++i )
     276             :         {
     277       14013 :             **indices = get_next_indice( st, lsf_ind_numbits[i] );
     278       14013 :             ++*indices;
     279             :         }
     280             :     }
     281             : 
     282       50958 :     return st->next_bit_pos - start_bit_pos;
     283             : }

Generated by: LCOV version 1.14