LCOV - code coverage report
Current view: top level - lib_dec - dlpc_avq.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 102 105 97.1 %
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             : #include "prot.h"
      40             : #include "ivas_prot.h"
      41             : #include "wmc_auto.h"
      42             : 
      43             : /*------------------------------------------------------------------*
      44             :  * dlpc_avq()
      45             :  *
      46             :  * Variable bitrate multiple LPC un-quantizer
      47             :  *------------------------------------------------------------------*/
      48             : 
      49      315900 : int16_t dlpc_avq(
      50             :     int16_t *index,       /* i  : Quantization indices        */
      51             :     float *LSF_Q,         /* o  : Quantized LSF vectors       */
      52             :     const int16_t numlpc, /* i  : Number of sets of lpc       */
      53             :     const int32_t sr_core /* i  : internal sampling rate      */
      54             : )
      55             : {
      56             :     int16_t i, nbi, last;
      57             :     int16_t *p_index, q_type;
      58             : 
      59             :     /* Last LPC index */
      60      315900 :     if ( numlpc == 1 )
      61             :     {
      62      309789 :         last = 0;
      63             :     }
      64             :     else
      65             :     {
      66        6111 :         last = M;
      67             :     }
      68             : 
      69      315900 :     p_index = index;
      70             : 
      71             :     /* Decode last LPC */
      72     5370300 :     for ( i = 0; i < M; i++ )
      73             :     {
      74     5054400 :         LSF_Q[last + i] = 0.0f;
      75             :     }
      76             : 
      77      315900 :     vlpc_1st_dec( p_index[0], &LSF_Q[last], sr_core );
      78      315900 :     p_index++;
      79      315900 :     vlpc_2st_dec( &LSF_Q[last], &p_index[0], 0, sr_core );
      80      315900 :     nbi = 2 + p_index[0] + p_index[1];
      81      315900 :     p_index += nbi;
      82             : 
      83             :     /* Decode intermediate LPC (512 framing) */
      84             : 
      85      315900 :     if ( numlpc == 2 )
      86             :     {
      87        6111 :         q_type = p_index[0];
      88        6111 :         p_index++;
      89             : 
      90        6111 :         if ( q_type == 0 )
      91             :         {
      92             : 
      93       57477 :             for ( i = 0; i < M; i++ )
      94             :             {
      95       54096 :                 LSF_Q[i] = 0.0f;
      96             :             }
      97        3381 :             vlpc_1st_dec( p_index[0], &LSF_Q[0], sr_core );
      98        3381 :             p_index++;
      99        3381 :             vlpc_2st_dec( &LSF_Q[0], &p_index[0], 0, sr_core );
     100             :         }
     101        2730 :         else if ( q_type == 1 )
     102             :         {
     103       46410 :             for ( i = 0; i < M; i++ )
     104             :             {
     105       43680 :                 LSF_Q[i] = LSF_Q[M + i];
     106             :             }
     107             : 
     108        2730 :             vlpc_2st_dec( &LSF_Q[0], &p_index[0], 3, sr_core );
     109             :         }
     110             : 
     111        6111 :         nbi = 2 + p_index[0] + p_index[1];
     112        6111 :         p_index += nbi;
     113             :     }
     114             : 
     115      315900 :     return (int16_t) ( p_index - index );
     116             : }
     117             : 
     118             : /*------------------------------------------------------------------*
     119             :  * unary_decode()
     120             :  *
     121             :  *
     122             :  *------------------------------------------------------------------*/
     123             : 
     124      519408 : static int16_t unary_decode(
     125             :     Decoder_State *st,
     126             :     int16_t *ind )
     127             : {
     128             :     int16_t start_bit_pos;
     129             : 
     130      519408 :     start_bit_pos = st->next_bit_pos;
     131             : 
     132             :     /* Index bits */
     133      519408 :     *ind = 0;
     134             : 
     135     1168497 :     while ( get_next_indice_1( st ) && !st->BER_detect )
     136             :     {
     137      649089 :         *ind += 1;
     138             :     }
     139             : 
     140      519408 :     if ( *ind != 0 )
     141             :     {
     142      370572 :         *ind += 1;
     143             :     }
     144             : 
     145      519408 :     return st->next_bit_pos - start_bit_pos;
     146             : }
     147             : 
     148             : 
     149             : /*------------------------------------------------------------------*
     150             :  * pack4bits()
     151             :  *
     152             :  *
     153             :  *------------------------------------------------------------------*/
     154             : 
     155     3789912 : static int16_t pack4bits(
     156             :     int16_t nbits,
     157             :     Decoder_State *st,
     158             :     int16_t *prm )
     159             : {
     160             :     int16_t i;
     161             : 
     162     3789912 :     i = 0;
     163             : 
     164    10865631 :     while ( nbits > 4 )
     165             :     {
     166     7075719 :         prm[i] = get_next_indice( st, 4 );
     167     7075719 :         nbits -= 4;
     168     7075719 :         i++;
     169             :     }
     170     3789912 :     prm[i] = get_next_indice( st, nbits );
     171     3789912 :     i++;
     172             : 
     173     3789912 :     return ( i );
     174             : }
     175             : 
     176             : 
     177             : /*------------------------------------------------------------------*
     178             :  * decode_lpc_avq()
     179             :  *
     180             :  *
     181             :  *------------------------------------------------------------------*/
     182             : 
     183     1913424 : int16_t decode_lpc_avq(
     184             :     Decoder_State *st,            /* i/o: decoder state structure     */
     185             :     const int16_t numlpc,         /* i  : Number of sets of lpc       */
     186             :     int16_t *param_lpc,           /* o  : lpc parameters              */
     187             :     const int16_t ch,             /* i  : channel                     */
     188             :     const int16_t element_mode,   /* i  : element mode                */
     189             :     const int16_t sns_low_br_mode /* i  : SNS low-bitrate mode        */
     190             : )
     191             : {
     192             :     int16_t k, j;
     193             :     int16_t nb, qn1, qn2, avqBits, q_type;
     194             :     int16_t start_bit_pos;
     195     1913424 :     int16_t stereo_mode = 0;
     196             : 
     197     1913424 :     j = 0;
     198     1913424 :     start_bit_pos = st->next_bit_pos;
     199             : 
     200     3869445 :     for ( k = 0; k < numlpc; k++ )
     201             :     {
     202             :         /* Decode quantizer type */
     203             : 
     204     1956021 :         if ( k == 0 )
     205             :         {
     206     1913424 :             q_type = 0;
     207     1913424 :             nb = 0;
     208             :         }
     209             :         else
     210             :         {
     211       42597 :             nb = 1;
     212       42597 :             q_type = get_next_indice( st, nb );
     213       42597 :             param_lpc[j++] = q_type;
     214             :         }
     215             : 
     216     1956021 :         if ( element_mode == IVAS_CPE_MDCT && k == 0 )
     217             :         {
     218     1597524 :             if ( ch == 0 )
     219             :             {
     220      885693 :                 stereo_mode = param_lpc[j];
     221             :             }
     222             :             else
     223             :             {
     224      711831 :                 stereo_mode = ch;
     225             :             }
     226     1597524 :             param_lpc[j++] = stereo_mode;
     227             :         }
     228             : 
     229             :         /* Decode quantization indices */
     230             : 
     231     1956021 :         if ( q_type == 0 )
     232             :         {
     233             :             /* Absolute quantizer with 1st stage stochastic codebook */
     234     1930323 :             if ( element_mode == IVAS_CPE_MDCT )
     235             :             {
     236     1611042 :                 if ( stereo_mode != 3 )
     237             :                 {
     238     1059981 :                     param_lpc[j++] = get_next_indice( st, SNS_ABS_QUANT_BITS );
     239             :                 }
     240             :                 else
     241             :                 {
     242      551061 :                     param_lpc[j++] = get_next_indice( st, 1 ) - 2;
     243             :                 }
     244             :             }
     245             :             else
     246             :             {
     247      319281 :                 param_lpc[j++] = get_next_indice( st, LPC_ABS_QUANT_BITS );
     248             :             }
     249             :         }
     250             : 
     251             :         /*
     252             :          * 2nd stage decoding is skipped if:
     253             :          *   - we are in low bitrate mode and no joint SNS coding is used
     254             :          *   - OR the side-SNS-is-zero flag is set for joint SNS
     255             :          */
     256     1956021 :         if ( element_mode != IVAS_CPE_MDCT || ( !( sns_low_br_mode && ( stereo_mode == 0 || stereo_mode == 1 ) ) && !( q_type == 0 && param_lpc[j - 1] == -2 ) ) )
     257             :         {
     258             :             /* 2 bits to specify Q2,Q3,Q4,ext */
     259     1894956 :             qn1 = 2 + get_next_indice( st, 2 );
     260     1894956 :             qn2 = 2 + get_next_indice( st, 2 );
     261             : 
     262             :             /* Unary code */
     263             :             /* Q5 = 0, Q6=10, Q0=110, Q7=1110, ... */
     264             : 
     265     1894956 :             if ( qn1 > 4 )
     266             :             {
     267      237249 :                 nb = unary_decode( st, &qn1 );
     268             : 
     269      237249 :                 if ( nb == 1 )
     270      119454 :                     qn1 += 5;
     271      117795 :                 else if ( nb == 2 )
     272       80661 :                     qn1 += 4;
     273       37134 :                 else if ( nb == 3 )
     274       34191 :                     qn1 = 0;
     275             :                 else
     276        2943 :                     qn1 += 3;
     277             :             }
     278             : 
     279     1894956 :             if ( qn2 > 4 )
     280             :             {
     281      282159 :                 nb = unary_decode( st, &qn2 );
     282             : 
     283      282159 :                 if ( nb == 1 )
     284       29382 :                     qn2 += 5;
     285      252777 :                 else if ( nb == 2 )
     286       14910 :                     qn2 += 4;
     287      237867 :                 else if ( nb == 3 )
     288      237420 :                     qn2 = 0;
     289             :                 else
     290         447 :                     qn2 += 3;
     291             :             }
     292             : 
     293             :             /* check for potential bit errors */
     294     1894956 :             if ( qn1 > NB_SPHERE || qn2 > NB_SPHERE )
     295             :             {
     296           0 :                 qn1 = 0;
     297           0 :                 qn2 = 0;
     298           0 :                 st->BER_detect = 1;
     299             :             }
     300             : 
     301     1894956 :             param_lpc[j] = qn1;
     302     1894956 :             j++;
     303     1894956 :             param_lpc[j] = qn2;
     304     1894956 :             j++;
     305             : 
     306             :             /* Decode Split-by-2 algebraic VQ */
     307     1894956 :             avqBits = 4 * qn1;
     308     1894956 :             pack4bits( avqBits, st, &param_lpc[j] );
     309     1894956 :             j += qn1;
     310             : 
     311     1894956 :             avqBits = 4 * qn2;
     312     1894956 :             pack4bits( avqBits, st, &param_lpc[j] );
     313     1894956 :             j += qn2;
     314             :         }
     315             :         else
     316             :         {
     317       61065 :             param_lpc[j++] = 0;
     318       61065 :             param_lpc[j++] = 0;
     319             :         }
     320             :     }
     321             : 
     322     1913424 :     return st->next_bit_pos - start_bit_pos;
     323             : }

Generated by: LCOV version 1.14