LCOV - code coverage report
Current view: top level - lib_dec - lead_deindexing.c (source / functions) Hit Total Coverage
Test: Coverage on main @ fec202a8f89be4a2f278a9fc377bfb58b58fab11 Lines: 93 94 98.9 %
Date: 2025-09-14 08:49:17 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    51187197 : 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    51187197 :     set_s( setor_8p_temp_2, 0, 8 );
      78             : 
      79    51187197 :     element_a11 = 0,
      80    51187197 :     element_a12 = 0;
      81    51187197 :     if ( n < 2 )
      82             :     {
      83    50887197 :         for ( i = 0; i < 8; i++ )
      84             :         {
      85    45233064 :             x[i] = 0;
      86             :         }
      87             :     }
      88             :     else
      89             :     {
      90    45533064 :         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    45533064 :         if ( n <= 3 )
      99             :         {
     100    97302550 :             for ( i = 1; i < NB_LDQ3; i++ )
     101             :             {
     102    97302094 :                 if ( I < (int32_t) II3[i] )
     103             :                 {
     104    34872149 :                     break;
     105             :                 }
     106             :             }
     107    34872605 :             ka = AA3[i - 1];
     108             :         }
     109             :         else
     110             :         {
     111    41140711 :             for ( i = 1; i < NB_LDQ4; i++ )
     112             :             {
     113    41140696 :                 if ( I < (int32_t) II4[i] )
     114             :                 {
     115    10660444 :                     break;
     116             :                 }
     117             :             }
     118    10660459 :             ka = AA4[i - 1];
     119             :         }
     120             : 
     121             :         /*-------------------------------------------------------*
     122             :          * decode
     123             :          *-------------------------------------------------------*/
     124             : 
     125    45533064 :         a1 = vals_a[ka];
     126    45533064 :         a2 = vals_q[ka];
     127    45533064 :         k1 = a2[0];
     128    45533064 :         code_level = a2[1];
     129             : 
     130    45533064 :         offset = Is[ka];
     131    45533064 :         code_index = I - offset;
     132             : 
     133    45533064 :         sign_8p = code_index & ( ( 1 << k1 ) - 1 );
     134             : 
     135    45533064 :         code_index = code_index >> k1;
     136             : 
     137    45533064 :         m = 0;
     138    45533064 :         m1 = 0;
     139    45533064 :         m2 = 0;
     140             : 
     141    45533064 :         element_a10 = a1[0];
     142    45533064 :         switch ( code_level )
     143             :         {
     144       29420 :             case 4:
     145             : 
     146       29420 :                 m2 = 1; /*a2[4];*/
     147       29420 :                 i = code_index & 1;
     148       29420 :                 if ( i == 0 )
     149       21666 :                     setor_8p_temp_2[0] = 0;
     150             :                 else
     151        7754 :                     setor_8p_temp_2[0] = 1;
     152       29420 :                 code_index = code_index >> 1;
     153             :                 /* FALLTHRU */
     154     4325607 :             case 3:
     155             : 
     156     4325607 :                 m = a2[2];
     157     4325607 :                 m1 = a2[3];
     158     4325607 :                 l = select_table22[m1][m];
     159     4325607 :                 j = ( code_index * mult_avq_tab[l] ) >> shift_avq_tab[l];
     160     4325607 :                 code_index = code_index - j * l;
     161     4325607 :                 fcb_decode_pos( code_index, setor_8p_temp_1, m, m1 );
     162     4325607 :                 code_index = j;
     163     4325607 :                 element_a12 = a1[2];
     164             :                 /* FALLTHRU */
     165    34196640 :             case 2:
     166             : 
     167    34196640 :                 m = a2[2];
     168    34196640 :                 fcb_decode_pos( code_index, setor_8p_temp, 8, m );
     169    34196640 :                 element_a11 = a1[1];
     170             :         }
     171             : 
     172   409797576 :         for ( i = 0; i < 8; i++ )
     173             :         {
     174   364264512 :             x[i] = element_a10;
     175             :         }
     176             : 
     177   129057792 :         for ( i = 0; i < m; i++ )
     178             :         {
     179    83524728 :             x[setor_8p_temp[i]] = element_a11;
     180             :         }
     181             : 
     182    50202602 :         for ( i = 0; i < m1; i++ )
     183             :         {
     184     4669538 :             x[setor_8p_temp[setor_8p_temp_1[i]]] = element_a12;
     185             :         }
     186             : 
     187    45562484 :         for ( i = 0; i < m2; i++ )
     188             :         {
     189       29420 :             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    45533064 :         m1 = k1 - 1;
     196    45533064 :         m2 = 8;
     197    45533064 :         l = 1;
     198   409797576 :         for ( i = 0; i < 8; i++ )
     199             :         {
     200   364264512 :             l *= x[i];
     201             :         }
     202             :         /* if the signs are constrained and all components are non-zero  */
     203    45533064 :         if ( ( k1 == 7 ) && ( l > 0 ) )
     204             :         {
     205    23498256 :             m2 = 7;
     206             :         }
     207   386299320 :         for ( i = 0; i < m2; i++ )
     208             :         {
     209   340766256 :             if ( x[i] != 0 )
     210             :             {
     211   240638735 :                 if ( ( sign_8p >> m1 ) & 1 )
     212             :                 {
     213   122437146 :                     x[i] *= -1;
     214             :                 }
     215   240638735 :                 m1--;
     216             :             }
     217             :         }
     218             : 
     219             :         /*--------------------------------------------------------------------*
     220             :          * recover the sign of last element if needed
     221             :          *--------------------------------------------------------------------*/
     222    45533064 :         if ( k1 == 7 )
     223             :         {
     224    23925800 :             m1 = 0;
     225             : 
     226   215332200 :             for ( i = 0; i < 8; i++ )
     227             :             {
     228   191406400 :                 m1 += x[i];
     229             :             }
     230    23925800 :             if ( m1 & 3 )
     231             :             {
     232    11370712 :                 x[7] *= -1;
     233             :             }
     234             :         }
     235             :     }
     236             : 
     237    51187197 :     return;
     238             : }
     239             : 
     240             : 
     241             : /*-------------------------------------------------------------------*
     242             :  * fcb_decode_pos
     243             :  *
     244             :  * base function for decoding position index
     245             :  *-------------------------------------------------------------------*/
     246             : 
     247    38522247 : 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    38522247 :     k = index;
     259    38522247 :     l = 0;
     260    38522247 :     temp1 = pos_num;
     261    38522247 :     temp2 = pulse_num + 1;
     262             : 
     263    88194266 :     for ( i = 0; i < pos_num - 1; i++ )
     264             :     {
     265    49672019 :         select_table23 = select_table22[temp1];
     266    49672019 :         select_table24 = &select_table23[pulse_num - l];
     267             : 
     268    49672019 :         k = *select_table24 - k;
     269             : 
     270   155573101 :         while ( k <= ( *select_table24-- ) )
     271             :         {
     272   105901082 :             l++;
     273             :         }
     274    49672019 :         k = select_table23[temp2 - l] - k;
     275             : 
     276    49672019 :         pos_vector[i] = l - 1;
     277    49672019 :         temp1--;
     278             :     }
     279             : 
     280    38522247 :     pos_vector[i] = l + k;
     281             : 
     282    38522247 :     return;
     283             : }

Generated by: LCOV version 1.14