LCOV - code coverage report
Current view: top level - lib_dec - lead_deindexing.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 93 94 98.9 %
Date: 2025-05-23 08:37:30 Functions: 2 2 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 "rom_dec.h"
      46             : #include "wmc_auto.h"
      47             : 
      48             : /*-------------------------------------------------------------------*
      49             :  * Local function prototypes
      50             :  *-------------------------------------------------------------------*/
      51             : 
      52             : static void fcb_decode_pos( const int16_t index, int16_t pos_vector[], const int16_t pulse_num, const int16_t pos_num );
      53             : 
      54             : 
      55             : /*-------------------------------------------------------------------*
      56             :  * re8_decode_base_index
      57             :  *
      58             :  * Decode RE8 base index
      59             :  *-------------------------------------------------------------------*/
      60             : 
      61     5602956 : void re8_decode_base_index(
      62             :     const int16_t n, /* i  : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */
      63             :     uint16_t I,      /* i  : index of c (pointer to unsigned 16-bit word)                     */
      64             :     int16_t *x       /* o  : point in RE8 (8-dimensional integer vector)                      */
      65             : )
      66             : {
      67             :     int16_t i, j, k1, l, m, m1, m2;
      68             :     int16_t setor_8p_temp[8], setor_8p_temp_1[8], setor_8p_temp_2[8];
      69             :     int16_t sign_8p;
      70             :     int16_t code_level;
      71             :     const int16_t *a1, *a2;
      72             :     int16_t ka;
      73             :     uint16_t offset;
      74             :     int16_t code_index;
      75             :     int16_t element_a10, element_a11, element_a12;
      76             : 
      77     5602956 :     set_s( setor_8p_temp_2, 0, 8 );
      78             : 
      79     5602956 :     element_a11 = 0,
      80     5602956 :     element_a12 = 0;
      81     5602956 :     if ( n < 2 )
      82             :     {
      83     7005528 :         for ( i = 0; i < 8; i++ )
      84             :         {
      85     6227136 :             x[i] = 0;
      86             :         }
      87             :     }
      88             :     else
      89             :     {
      90     4824564 :         if ( I > 65519L )
      91             :         {
      92           0 :             I = 0;
      93             :         }
      94             :         /*-------------------------------------------------------------------*
      95             :          * search for the identifier ka of the absolute leader (table-lookup)
      96             :          * Q2 is a subset of Q3 - the two cases are considered in the same branch
      97             :          *-------------------------------------------------------------------*/
      98     4824564 :         if ( n <= 3 )
      99             :         {
     100    10197768 :             for ( i = 1; i < NB_LDQ3; i++ )
     101             :             {
     102    10197762 :                 if ( I < (int32_t) II3[i] )
     103             :                 {
     104     3762261 :                     break;
     105             :                 }
     106             :             }
     107     3762267 :             ka = AA3[i - 1];
     108             :         }
     109             :         else
     110             :         {
     111     4126128 :             for ( i = 1; i < NB_LDQ4; i++ )
     112             :             {
     113     4126128 :                 if ( I < (int32_t) II4[i] )
     114             :                 {
     115     1062297 :                     break;
     116             :                 }
     117             :             }
     118     1062297 :             ka = AA4[i - 1];
     119             :         }
     120             : 
     121             :         /*-------------------------------------------------------*
     122             :          * decode
     123             :          *-------------------------------------------------------*/
     124             : 
     125     4824564 :         a1 = vals_a[ka];
     126     4824564 :         a2 = vals_q[ka];
     127     4824564 :         k1 = a2[0];
     128     4824564 :         code_level = a2[1];
     129             : 
     130     4824564 :         offset = Is[ka];
     131     4824564 :         code_index = I - offset;
     132             : 
     133     4824564 :         sign_8p = code_index & ( ( 1 << k1 ) - 1 );
     134             : 
     135     4824564 :         code_index = code_index >> k1;
     136             : 
     137     4824564 :         m = 0;
     138     4824564 :         m1 = 0;
     139     4824564 :         m2 = 0;
     140             : 
     141     4824564 :         element_a10 = a1[0];
     142     4824564 :         switch ( code_level )
     143             :         {
     144        2610 :             case 4:
     145             : 
     146        2610 :                 m2 = 1; /*a2[4];*/
     147        2610 :                 i = code_index & 1;
     148        2610 :                 if ( i == 0 )
     149        1998 :                     setor_8p_temp_2[0] = 0;
     150             :                 else
     151         612 :                     setor_8p_temp_2[0] = 1;
     152        2610 :                 code_index = code_index >> 1;
     153             :                 /* FALLTHRU */
     154      444642 :             case 3:
     155             : 
     156      444642 :                 m = a2[2];
     157      444642 :                 m1 = a2[3];
     158      444642 :                 l = select_table22[m1][m];
     159      444642 :                 j = ( code_index * mult_avq_tab[l] ) >> shift_avq_tab[l];
     160      444642 :                 code_index = code_index - j * l;
     161      444642 :                 fcb_decode_pos( code_index, setor_8p_temp_1, m, m1 );
     162      444642 :                 code_index = j;
     163      444642 :                 element_a12 = a1[2];
     164             :                 /* FALLTHRU */
     165     3554694 :             case 2:
     166             : 
     167     3554694 :                 m = a2[2];
     168     3554694 :                 fcb_decode_pos( code_index, setor_8p_temp, 8, m );
     169     3554694 :                 element_a11 = a1[1];
     170             :         }
     171             : 
     172    43421076 :         for ( i = 0; i < 8; i++ )
     173             :         {
     174    38596512 :             x[i] = element_a10;
     175             :         }
     176             : 
     177    13445547 :         for ( i = 0; i < m; i++ )
     178             :         {
     179     8620983 :             x[setor_8p_temp[i]] = element_a11;
     180             :         }
     181             : 
     182     5306877 :         for ( i = 0; i < m1; i++ )
     183             :         {
     184      482313 :             x[setor_8p_temp[setor_8p_temp_1[i]]] = element_a12;
     185             :         }
     186             : 
     187     4827174 :         for ( i = 0; i < m2; i++ )
     188             :         {
     189        2610 :             x[setor_8p_temp[setor_8p_temp_1[setor_8p_temp_2[0]]]] = 6;
     190             :         }
     191             : 
     192             :         /*--------------------------------------------------------------------*
     193             :          * add the sign of all elemnt ( except the last one in some case )
     194             :          *--------------------------------------------------------------------*/
     195     4824564 :         m1 = k1 - 1;
     196     4824564 :         m2 = 8;
     197     4824564 :         l = 1;
     198    43421076 :         for ( i = 0; i < 8; i++ )
     199             :         {
     200    38596512 :             l *= x[i];
     201             :         }
     202             :         /* if the signs are constrained and all components are non-zero  */
     203     4824564 :         if ( ( k1 == 7 ) && ( l > 0 ) )
     204             :         {
     205     2504622 :             m2 = 7;
     206             :         }
     207    40916454 :         for ( i = 0; i < m2; i++ )
     208             :         {
     209    36091890 :             if ( x[i] != 0 )
     210             :             {
     211    25325925 :                 if ( ( sign_8p >> m1 ) & 1 )
     212             :                 {
     213    13050360 :                     x[i] *= -1;
     214             :                 }
     215    25325925 :                 m1--;
     216             :             }
     217             :         }
     218             : 
     219             :         /*--------------------------------------------------------------------*
     220             :          * recover the sign of last element if needed
     221             :          *--------------------------------------------------------------------*/
     222     4824564 :         if ( k1 == 7 )
     223             :         {
     224     2547417 :             m1 = 0;
     225             : 
     226    22926753 :             for ( i = 0; i < 8; i++ )
     227             :             {
     228    20379336 :                 m1 += x[i];
     229             :             }
     230     2547417 :             if ( m1 & 3 )
     231             :             {
     232     1155102 :                 x[7] *= -1;
     233             :             }
     234             :         }
     235             :     }
     236             : 
     237     5602956 :     return;
     238             : }
     239             : 
     240             : 
     241             : /*-------------------------------------------------------------------*
     242             :  * fcb_decode_pos
     243             :  *
     244             :  * base function for decoding position index
     245             :  *-------------------------------------------------------------------*/
     246             : 
     247     3999336 : static void fcb_decode_pos(
     248             :     const int16_t index,     /* i  : Index to decoder    */
     249             :     int16_t pos_vector[],    /* o  : Position vector     */
     250             :     const int16_t pulse_num, /* i  : Number of pulses    */
     251             :     const int16_t pos_num    /* i  : Number of positions */
     252             : )
     253             : {
     254             :     int16_t i, k, l;
     255             :     int16_t temp1, temp2;
     256             :     const int16_t *select_table23, *select_table24;
     257             : 
     258     3999336 :     k = index;
     259     3999336 :     l = 0;
     260     3999336 :     temp1 = pos_num;
     261     3999336 :     temp2 = pulse_num + 1;
     262             : 
     263     9103296 :     for ( i = 0; i < pos_num - 1; i++ )
     264             :     {
     265     5103960 :         select_table23 = select_table22[temp1];
     266     5103960 :         select_table24 = &select_table23[pulse_num - l];
     267             : 
     268     5103960 :         k = *select_table24 - k;
     269             : 
     270    15902502 :         while ( k <= ( *select_table24-- ) )
     271             :         {
     272    10798542 :             l++;
     273             :         }
     274     5103960 :         k = select_table23[temp2 - l] - k;
     275             : 
     276     5103960 :         pos_vector[i] = l - 1;
     277     5103960 :         temp1--;
     278             :     }
     279             : 
     280     3999336 :     pos_vector[i] = l + k;
     281             : 
     282     3999336 :     return;
     283             : }

Generated by: LCOV version 1.14