LCOV - code coverage report
Current view: top level - lib_dec - dec4t64.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 170 356 47.8 %
Date: 2025-05-23 08:37:30 Functions: 9 16 56.2 %

          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 "ivas_prot.h"
      45             : #include "rom_com.h"
      46             : #include "wmc_auto.h"
      47             : 
      48             : /*-------------------------------------------------------------------*
      49             :  * Local function prototypes
      50             :  *-------------------------------------------------------------------*/
      51             : 
      52             : static void add_pulses( const int16_t pos[], const int16_t nb_pulse, const int16_t track, float code[] );
      53             : static void dec_1p_N1( const int32_t index, const int16_t N, const int16_t offset, int16_t pos[] );
      54             : static void dec_2p_2N1( const int32_t index, const int16_t N, const int16_t offset, int16_t pos[] );
      55             : static void dec_3p_3N1( const int32_t index, const int16_t N, const int16_t offset, int16_t pos[] );
      56             : static void dec_4p_4N1( const int32_t index, const int16_t N, const int16_t offset, int16_t pos[] );
      57             : static void dec_4p_4N( const int32_t index, const int16_t N, const int16_t offset, int16_t pos[] );
      58             : static void dec_5p_5N( const int32_t index, const int16_t N, const int16_t offset, int16_t pos[] );
      59             : static void dec_6p_6N2( const int32_t index, const int16_t N, const int16_t offset, int16_t pos[] );
      60             : static void fcb_decode_PI( int32_t code_index, int16_t sector_6p[], const int16_t pulse_num );
      61             : 
      62             : 
      63             : /*----------------------------------------------------------------------------------*
      64             :  * dec_acelp_4t64()
      65             :  *
      66             :  * 20, 36       bits algebraic codebook decoder.
      67             :  * 4 tracks x 16 positions per track = 64 samples.
      68             :  *
      69             :  * 20 bits --> 4 pulses in a frame of 64 samples.
      70             :  * 36 bits --> 8 pulses in a frame of 64 samples.
      71             :  *
      72             :  * All pulses can have two (2) possible amplitudes: +1 or -1.
      73             :  * Each pulse can have sixteen (16) possible positions.
      74             :  *
      75             :  * See cod4t64.c for more details of the algebraic code.
      76             :  *----------------------------------------------------------------------------------*/
      77             : 
      78      191295 : void dec_acelp_4t64(
      79             :     Decoder_State *st,       /* i/o: decoder state structure                 */
      80             :     int16_t nbbits,          /* i  : number of bits per codebook             */
      81             :     float code[],            /* o  : algebraic (fixed) codebook excitation   */
      82             :     const int16_t Opt_AMR_WB /* i  : flag indicating AMR-WB IO mode          */
      83             : )
      84             : {
      85             :     int16_t i, k, pos[7];
      86             :     int32_t L_index;
      87             :     int16_t ind1[NB_TRACK_FCB_4T], ind2[NB_TRACK_FCB_4T];
      88             :     PulseConfig config;
      89             :     int16_t indexing_indices[6], wordcnt, bitcnt;
      90             : 
      91      191295 :     if ( !Opt_AMR_WB )
      92             :     {
      93      191295 :         switch ( nbbits )
      94             :         {
      95        2055 :             case 20:
      96        2055 :                 config.nb_pulse = 4;
      97        2055 :                 break;
      98             : 
      99        6831 :             case 28:
     100        6831 :                 config.nb_pulse = 6;
     101        6831 :                 break;
     102             : 
     103      182349 :             case 36:
     104      182349 :                 config.nb_pulse = 8;
     105      182349 :                 break;
     106             : 
     107           0 :             case 43:
     108           0 :                 config.nb_pulse = 10;
     109           0 :                 break;
     110             : 
     111           0 :             case 50:
     112           0 :                 config.nb_pulse = 12;
     113           0 :                 break;
     114             : 
     115          60 :             case 62:
     116          60 :                 config.nb_pulse = 16;
     117          60 :                 break;
     118             : 
     119             : 
     120           0 :             case 87:
     121           0 :                 config.nb_pulse = 26;
     122           0 :                 break;
     123             :         }
     124      191295 :         config.bits = nbbits;
     125      191295 :         config.codetrackpos = TRACKPOS_FIXED_FIRST;
     126             : 
     127             : 
     128      191295 :         wordcnt = nbbits >> 4;
     129      191295 :         bitcnt = nbbits & 15;
     130      565059 :         for ( i = 0; i < wordcnt; i++ )
     131             :         {
     132      373764 :             indexing_indices[i] = get_next_indice( st, 16 );
     133             :         }
     134      191295 :         if ( bitcnt )
     135             :         {
     136      191295 :             indexing_indices[i] = get_next_indice( st, bitcnt );
     137             :         }
     138      191295 :         D_ACELP_indexing( code, config, NB_TRACK_FCB_4T, indexing_indices, &st->BER_detect );
     139             :     }
     140             :     else
     141             :     {
     142           0 :         for ( i = 0; i < L_SUBFR; i++ )
     143             :         {
     144           0 :             code[i] = 0.0f;
     145             :         }
     146             : 
     147           0 :         if ( nbbits == 20 )
     148             :         {
     149           0 :             for ( k = 0; k < NB_TRACK_FCB_4T; k++ )
     150             :             {
     151           0 :                 L_index = get_next_indice( st, 5 );
     152           0 :                 dec_1p_N1( L_index, 4, 0, pos );
     153           0 :                 add_pulses( pos, 1, k, code );
     154             :             }
     155             :         }
     156           0 :         else if ( nbbits == 36 )
     157             :         {
     158           0 :             for ( k = 0; k < NB_TRACK_FCB_4T; k++ )
     159             :             {
     160           0 :                 L_index = get_next_indice( st, 9 );
     161           0 :                 dec_2p_2N1( L_index, 4, 0, pos );
     162           0 :                 add_pulses( pos, 2, k, code );
     163             :             }
     164             :         }
     165           0 :         else if ( nbbits == 44 ) /* AMR-WB pulse indexing */
     166             :         {
     167           0 :             for ( k = 0; k < NB_TRACK_FCB_4T - 2; k++ )
     168             :             {
     169           0 :                 L_index = get_next_indice( st, 13 );
     170           0 :                 dec_3p_3N1( L_index, 4, 0, pos );
     171           0 :                 add_pulses( pos, 3, k, code );
     172             :             }
     173             : 
     174           0 :             for ( k = 2; k < NB_TRACK_FCB_4T; k++ )
     175             :             {
     176           0 :                 L_index = get_next_indice( st, 9 );
     177           0 :                 dec_2p_2N1( L_index, 4, 0, pos );
     178           0 :                 add_pulses( pos, 2, k, code );
     179             :             }
     180             :         }
     181           0 :         else if ( nbbits == 52 ) /* AMR-WB pulse indexing */
     182             :         {
     183           0 :             for ( k = 0; k < NB_TRACK_FCB_4T; k++ )
     184             :             {
     185           0 :                 L_index = get_next_indice( st, 13 );
     186           0 :                 dec_3p_3N1( L_index, 4, 0, pos );
     187           0 :                 add_pulses( pos, 3, k, code );
     188             :             }
     189             :         }
     190           0 :         else if ( nbbits == 64 ) /* AMR-WB pulse indexing */
     191             :         {
     192           0 :             for ( k = 0; k < NB_TRACK_FCB_4T; k++ )
     193             :             {
     194           0 :                 ind1[k] = get_next_indice( st, 2 );
     195             :             }
     196             : 
     197           0 :             for ( k = 0; k < NB_TRACK_FCB_4T; k++ )
     198             :             {
     199           0 :                 ind2[k] = get_next_indice( st, 14 );
     200             :             }
     201             : 
     202           0 :             for ( k = 0; k < NB_TRACK_FCB_4T; k++ )
     203             :             {
     204           0 :                 L_index = ( ( ind1[k] << 14 ) + ind2[k] );
     205           0 :                 dec_4p_4N( L_index, 4, 0, pos );
     206           0 :                 add_pulses( pos, 4, k, code );
     207             :             }
     208             :         }
     209           0 :         else if ( nbbits == 72 )
     210             :         {
     211           0 :             for ( k = 0; k < NB_TRACK_FCB_4T - 2; k++ )
     212             :             {
     213           0 :                 ind1[k] = get_next_indice( st, 10 );
     214             :             }
     215             : 
     216           0 :             for ( k = 2; k < NB_TRACK_FCB_4T; k++ )
     217             :             {
     218           0 :                 ind1[k] = get_next_indice( st, 2 );
     219             :             }
     220             : 
     221           0 :             for ( k = 0; k < NB_TRACK_FCB_4T - 2; k++ )
     222             :             {
     223           0 :                 ind2[k] = get_next_indice( st, 10 );
     224             :             }
     225             : 
     226           0 :             for ( k = 2; k < NB_TRACK_FCB_4T; k++ )
     227             :             {
     228           0 :                 ind2[k] = get_next_indice( st, 14 );
     229             :             }
     230             : 
     231           0 :             for ( k = 0; k < NB_TRACK_FCB_4T - 2; k++ )
     232             :             {
     233           0 :                 L_index = ( ( ind1[k] << 10 ) + ind2[k] );
     234           0 :                 dec_5p_5N( L_index, 4, 0, pos );
     235           0 :                 add_pulses( pos, 5, k, code );
     236             :             }
     237             : 
     238           0 :             for ( k = 2; k < NB_TRACK_FCB_4T; k++ )
     239             :             {
     240           0 :                 L_index = ( ( ind1[k] << 14 ) + ind2[k] );
     241           0 :                 dec_4p_4N( L_index, 4, 0, pos );
     242           0 :                 add_pulses( pos, 4, k, code );
     243             :             }
     244             :         }
     245           0 :         else if ( nbbits == 88 )
     246             :         {
     247           0 :             for ( k = 0; k < NB_TRACK_FCB_4T; k++ )
     248             :             {
     249           0 :                 ind1[k] = get_next_indice( st, 11 );
     250             :             }
     251             : 
     252           0 :             for ( k = 0; k < NB_TRACK_FCB_4T; k++ )
     253             :             {
     254           0 :                 ind2[k] = get_next_indice( st, 11 );
     255             :             }
     256             : 
     257           0 :             for ( k = 0; k < NB_TRACK_FCB_4T; k++ )
     258             :             {
     259           0 :                 L_index = ( ( ind1[k] << 11 ) + ind2[k] );
     260           0 :                 dec_6p_6N2( L_index, 4, 0, pos );
     261           0 :                 add_pulses( pos, 6, k, code );
     262             :             }
     263             :         }
     264             :     }
     265             : 
     266      191295 :     return;
     267             : }
     268             : 
     269             : /*-------------------------------------------------------*
     270             :  * add_pulses()
     271             :  *
     272             :  * Add decoded pulses to the codeword
     273             :  *-------------------------------------------------------*/
     274             : 
     275      535533 : static void add_pulses(
     276             :     const int16_t pos[],    /* i  : pulse position     */
     277             :     const int16_t nb_pulse, /* i  : nb. of pulses      */
     278             :     const int16_t track,    /* i  : no. of the tracks  */
     279             :     float code[]            /* i/o: decoded codevector */
     280             : )
     281             : {
     282             :     int16_t i, k;
     283             : 
     284     1668363 :     for ( k = 0; k < nb_pulse; k++ )
     285             :     {
     286     1132830 :         i = ( ( pos[k] & ( NB_POS_FCB_4T - 1 ) ) * NB_TRACK_FCB_4T ) + track;
     287     1132830 :         if ( ( pos[k] & NB_POS_FCB_4T ) == 0 )
     288             :         {
     289      569325 :             code[i] += 1.0f;
     290             :         }
     291             :         else
     292             :         {
     293      563505 :             code[i] -= 1.0f;
     294             :         }
     295             :     }
     296             : 
     297      535533 :     return;
     298             : }
     299             : 
     300             : /*-------------------------------------------------------*
     301             :  * dec_1p_N1()
     302             :  *
     303             :  * Decode 1 pulse with N+1 bits
     304             :  *-------------------------------------------------------*/
     305             : 
     306      136440 : void dec_1p_N1(
     307             :     const int32_t index,  /* i  : quantization index    */
     308             :     const int16_t N,      /* i  : nb. of bits           */
     309             :     const int16_t offset, /* i  : pulse position offset */
     310             :     int16_t pos[]         /* o  : pulse position        */
     311             : )
     312             : {
     313             :     int16_t i, pos1;
     314             :     int32_t mask;
     315             : 
     316      136440 :     mask = ( ( 1 << N ) - 1 );
     317             : 
     318      136440 :     pos1 = (int16_t) ( index & mask ) + offset;
     319             : 
     320      136440 :     i = (int16_t) ( index >> N ) & 1;
     321             : 
     322      136440 :     if ( i == 1 )
     323             :     {
     324       67530 :         pos1 += NB_POS_FCB_4T;
     325             :     }
     326             : 
     327      136440 :     pos[0] = pos1;
     328             : 
     329      136440 :     return;
     330             : }
     331             : 
     332             : /*-------------------------------------------------------*
     333             :  * dec_2p_2N1()
     334             :  *
     335             :  * Decode 2 pulses with 2*N+1 bits:
     336             :  *-------------------------------------------------------*/
     337             : 
     338      200889 : void dec_2p_2N1(
     339             :     const int32_t index,  /* i  : quantization index    */
     340             :     const int16_t N,      /* i  : nb. of bits           */
     341             :     const int16_t offset, /* i  : pulse position offset */
     342             :     int16_t pos[]         /* o  : pulse position        */
     343             : )
     344             : {
     345             :     int16_t i, pos1, pos2;
     346             :     int32_t mask;
     347             : 
     348      200889 :     mask = ( ( 1 << N ) - 1 );
     349             : 
     350      200889 :     pos1 = (int16_t) ( ( index >> N ) & mask ) + offset;
     351      200889 :     i = (int16_t) ( index >> ( 2 * N ) ) & 1;
     352      200889 :     pos2 = (int16_t) ( index & mask ) + offset;
     353      200889 :     if ( ( pos2 - pos1 ) < 0 )
     354             :     {
     355       96279 :         if ( i == 1 )
     356             :         {
     357       46629 :             pos1 += NB_POS_FCB_4T;
     358             :         }
     359             :         else
     360             :         {
     361       49650 :             pos2 += NB_POS_FCB_4T;
     362             :         }
     363             :     }
     364             :     else
     365             :     {
     366      104610 :         if ( i == 1 )
     367             :         {
     368       52143 :             pos1 += NB_POS_FCB_4T;
     369       52143 :             pos2 += NB_POS_FCB_4T;
     370             :         }
     371             :     }
     372             : 
     373      200889 :     pos[0] = pos1;
     374      200889 :     pos[1] = pos2;
     375             : 
     376      200889 :     return;
     377             : }
     378             : 
     379             : /*-------------------------------------------------------*
     380             :  * dec_3p_3N1()
     381             :  *
     382             :  * Decode 3 pulses with 3*N+1 bits:
     383             :  *-------------------------------------------------------*/
     384             : 
     385           0 : static void dec_3p_3N1(
     386             :     const int32_t index,  /* i  : quantization index    */
     387             :     const int16_t N,      /* i  : nb. of bits           */
     388             :     const int16_t offset, /* i  : pulse position offset */
     389             :     int16_t pos[]         /* o  : pulse position        */
     390             : )
     391             : {
     392             :     int16_t j;
     393             :     int32_t idx, mask;
     394             : 
     395           0 :     mask = ( ( 1 << ( ( 2 * N ) - 1 ) ) - 1 );
     396           0 :     idx = index & mask;
     397           0 :     j = offset;
     398             : 
     399           0 :     if ( ( ( index >> ( ( 2 * N ) - 1 ) ) & 1 ) == 1 )
     400             :     {
     401           0 :         j += ( 1 << ( N - 1 ) );
     402             :     }
     403             : 
     404           0 :     dec_2p_2N1( idx, N - 1, j, pos );
     405           0 :     mask = ( ( 1 << ( N + 1 ) ) - 1 );
     406           0 :     idx = ( index >> ( 2 * N ) ) & mask;
     407           0 :     dec_1p_N1( idx, N, offset, pos + 2 );
     408             : 
     409           0 :     return;
     410             : }
     411             : 
     412             : /*-------------------------------------------------------*
     413             :  * dec_4p_4N1()
     414             :  *
     415             :  * Decode 4 pulses with 4*N+1 bits:
     416             :  *-------------------------------------------------------*/
     417             : 
     418           0 : static void dec_4p_4N1(
     419             :     const int32_t index,  /* i  : quantization index    */
     420             :     const int16_t N,      /* i  : nb. of bits           */
     421             :     const int16_t offset, /* i  : pulse position offset */
     422             :     int16_t pos[]         /* o  : pulse position        */
     423             : )
     424             : {
     425             :     int16_t j;
     426             :     int32_t mask, idx;
     427             : 
     428           0 :     mask = ( ( 1 << ( ( 2 * N ) - 1 ) ) - 1 );
     429           0 :     idx = index & mask;
     430           0 :     j = offset;
     431             : 
     432           0 :     if ( ( ( index >> ( ( 2 * N ) - 1 ) ) & 1 ) == 1 )
     433             :     {
     434           0 :         j += ( 1 << ( N - 1 ) );
     435             :     }
     436             : 
     437           0 :     dec_2p_2N1( idx, N - 1, j, pos );
     438           0 :     mask = ( ( 1 << ( ( 2 * N ) + 1 ) ) - 1 );
     439           0 :     idx = ( index >> ( 2 * N ) ) & mask;
     440           0 :     dec_2p_2N1( idx, N, offset, pos + 2 );
     441             : 
     442           0 :     return;
     443             : }
     444             : 
     445             : /*-------------------------------------------------------*
     446             :  * dec_4p_4N()
     447             :  *
     448             :  * Decode 4 pulses with 4*N bits:
     449             :  *-------------------------------------------------------*/
     450             : 
     451           0 : static void dec_4p_4N(
     452             :     const int32_t index,  /* i  : quantization index    */
     453             :     const int16_t N,      /* i  : nb. of bits           */
     454             :     const int16_t offset, /* i  : pulse position offset */
     455             :     int16_t pos[]         /* o  : pulse position        */
     456             : )
     457             : {
     458             :     int16_t j, n_1;
     459             : 
     460           0 :     n_1 = N - 1;
     461           0 :     j = offset + ( 1 << n_1 );
     462           0 :     switch ( ( index >> ( ( 4 * N ) - 2 ) ) & 3 )
     463             :     {
     464           0 :         case 0:
     465             :         {
     466           0 :             if ( ( ( index >> ( ( 4 * n_1 ) + 1 ) ) & 1 ) == 0 )
     467             :             {
     468           0 :                 dec_4p_4N1( index, n_1, offset, pos );
     469             :             }
     470             :             else
     471             :             {
     472           0 :                 dec_4p_4N1( index, n_1, j, pos );
     473             :             }
     474           0 :             break;
     475             :         }
     476           0 :         case 1:
     477             :         {
     478           0 :             dec_1p_N1( ( index >> ( ( 3 * n_1 ) + 1 ) ), n_1, offset, pos );
     479           0 :             dec_3p_3N1( index, n_1, j, pos + 1 );
     480           0 :             break;
     481             :         }
     482           0 :         case 2:
     483             :         {
     484           0 :             dec_2p_2N1( ( index >> ( ( 2 * n_1 ) + 1 ) ), n_1, offset, pos );
     485           0 :             dec_2p_2N1( index, n_1, j, pos + 2 );
     486           0 :             break;
     487             :         }
     488           0 :         case 3:
     489             :         {
     490           0 :             dec_3p_3N1( ( index >> ( n_1 + 1 ) ), n_1, offset, pos );
     491           0 :             dec_1p_N1( index, n_1, j, pos + 3 );
     492           0 :             break;
     493             :         }
     494             :     }
     495             : 
     496           0 :     return;
     497             : }
     498             : 
     499             : /*-------------------------------------------------------*
     500             :  * dec_5p_5N()
     501             :  *
     502             :  * Decode 5 pulses with 5*N bits:
     503             :  *-------------------------------------------------------*/
     504             : 
     505           0 : static void dec_5p_5N(
     506             :     const int32_t index,  /* i  : quantization index    */
     507             :     const int16_t N,      /* i  : nb. of bits           */
     508             :     const int16_t offset, /* i  : pulse position offset */
     509             :     int16_t pos[]         /* o  : pulse position        */
     510             : )
     511             : {
     512             :     int16_t j, n_1;
     513             :     int32_t idx;
     514             : 
     515           0 :     n_1 = N - 1;
     516           0 :     j = offset + ( 1 << n_1 );
     517           0 :     idx = ( index >> ( ( 2 * N ) + 1 ) );
     518             : 
     519           0 :     if ( ( ( index >> ( ( 5 * N ) - 1 ) ) & 1 ) == 0 )
     520             :     {
     521           0 :         dec_3p_3N1( idx, n_1, offset, pos );
     522           0 :         dec_2p_2N1( index, N, offset, pos + 3 );
     523             :     }
     524             :     else
     525             :     {
     526           0 :         dec_3p_3N1( idx, n_1, j, pos );
     527           0 :         dec_2p_2N1( index, N, offset, pos + 3 );
     528             :     }
     529             : 
     530           0 :     return;
     531             : }
     532             : 
     533             : /*-------------------------------------------------------*
     534             :  * dec_6p_6N2()
     535             :  *
     536             :  * Decode 6 pulses with 6*N+2 bits:
     537             :  *-------------------------------------------------------*/
     538             : 
     539           0 : static void dec_6p_6N2(
     540             :     const int32_t index,  /* i  : quantization index    */
     541             :     const int16_t N,      /* i  : nb. of bits           */
     542             :     const int16_t offset, /* i  : pulse position offset */
     543             :     int16_t pos[]         /* o  : pulse position        */
     544             : )
     545             : {
     546             :     int16_t j, n_1, offsetA, offsetB;
     547             : 
     548           0 :     n_1 = N - 1;
     549           0 :     j = offset + ( 1 << n_1 );
     550           0 :     offsetA = offsetB = j;
     551           0 :     if ( ( ( index >> ( ( 6 * N ) - 5 ) ) & 1 ) == 0 )
     552             :     {
     553           0 :         offsetA = offset;
     554             :     }
     555             :     else
     556             :     {
     557           0 :         offsetB = offset;
     558             :     }
     559             : 
     560           0 :     switch ( ( index >> ( ( 6 * N ) - 4 ) ) & 3 )
     561             :     {
     562           0 :         case 0:
     563             :         {
     564           0 :             dec_5p_5N( index >> N, n_1, offsetA, pos );
     565           0 :             dec_1p_N1( index, n_1, offsetA, pos + 5 );
     566           0 :             break;
     567             :         }
     568             : 
     569           0 :         case 1:
     570             :         {
     571           0 :             dec_5p_5N( index >> N, n_1, offsetA, pos );
     572           0 :             dec_1p_N1( index, n_1, offsetB, pos + 5 );
     573           0 :             break;
     574             :         }
     575             : 
     576           0 :         case 2:
     577             :         {
     578           0 :             dec_4p_4N( index >> ( ( 2 * n_1 ) + 1 ), n_1, offsetA, pos );
     579           0 :             dec_2p_2N1( index, n_1, offsetB, pos + 4 );
     580           0 :             break;
     581             :         }
     582             : 
     583           0 :         case 3:
     584             :         {
     585           0 :             dec_3p_3N1( index >> ( ( 3 * n_1 ) + 1 ), n_1, offset, pos );
     586           0 :             dec_3p_3N1( index, n_1, j, pos + 3 );
     587           0 :             break;
     588             :         }
     589             :     }
     590             : 
     591           0 :     return;
     592             : }
     593             : 
     594             : /*---------------------------------------------------------------------*
     595             :  * fcb_decode_class_all_p()
     596             :  *
     597             :  * Get the position number and the pulse number on every position
     598             :  *---------------------------------------------------------------------*/
     599             : 
     600             : /*! r: The index of pulse positions */
     601      198204 : static int32_t fcb_decode_class_all_p(
     602             :     int32_t *code_index,     /* i  : fcb index information                              */
     603             :     int16_t sector_6p_num[], /* o  : Number of pulses for each position                 */
     604             :     const int16_t pulse_num, /* i  : Number of pulses on a track.                       */
     605             :     int16_t *pos_num         /* o  : Number of positions which have pulses on the track.*/
     606             : )
     607             : {
     608             :     int16_t i, j, k;
     609             :     int32_t mn9;
     610             :     int16_t pulse_pos_num;
     611      418740 :     for ( i = 1; i <= pulse_num; i++ )
     612             :     {
     613      417600 :         if ( ( *code_index ) < PI_offset[pulse_num][i] )
     614             :         {
     615      197064 :             break;
     616             :         }
     617             :     }
     618             : 
     619      198204 :     ( *code_index ) -= PI_offset[pulse_num][i - 1];
     620             : 
     621      198204 :     pulse_pos_num = pulse_num - i + 2;
     622      198204 :     j = (int16_t) ( ( *code_index ) >> pulse_pos_num );
     623             : 
     624      198204 :     k = (int16_t) ( j / PI_select_table[16][pulse_pos_num] );
     625      198204 :     mn9 = j - k * PI_select_table[16][pulse_pos_num];
     626      198204 :     if ( ( pulse_pos_num < pulse_num ) && ( pulse_pos_num > 1 ) )
     627             :     {
     628       60156 :         for ( i = 0; i < pulse_pos_num; i++ )
     629             :         {
     630       40104 :             sector_6p_num[i] = 1;
     631             :         }
     632       20052 :         sector_6p_num[k]++;
     633             :     }
     634             :     else
     635             :     {
     636      178152 :         if ( pulse_pos_num == 1 )
     637             :         {
     638        1140 :             sector_6p_num[0] = (int16_t) pulse_num;
     639             :         }
     640             :         else
     641             :         {
     642      708048 :             for ( i = 0; i < pulse_num; i++ )
     643             :             {
     644      531036 :                 sector_6p_num[i] = 1;
     645             :             }
     646             :         }
     647             :     }
     648             : 
     649      198204 :     *pos_num = pulse_pos_num;
     650             : 
     651      198204 :     return mn9;
     652             : }
     653             : 
     654             : /*---------------------------------------------------------------------*
     655             :  * fcb_decode_position()
     656             :  *
     657             :  * Decode the pulse position not same to the others
     658             :  *---------------------------------------------------------------------*/
     659             : 
     660      198204 : static void fcb_decode_position(
     661             :     int32_t index,        /* i  : position index information        */
     662             :     int16_t pos_vector[], /* o  : the positon vector                */
     663             :     const int16_t pos_num /* i  : number of positions               */
     664             : )
     665             : {
     666             :     int16_t i, l;
     667             :     int32_t k;
     668             :     int16_t temp;
     669             : 
     670      198204 :     k = index;
     671      198204 :     l = 0;
     672      198204 :     temp = pos_num;
     673      572280 :     for ( i = 0; i < pos_num - 1; i++ )
     674             :     {
     675      374076 :         k = PI_select_table[16 - l][temp] - k;
     676             : 
     677     1290198 :         for ( ; PI_select_table[16 - l][temp] >= k; l += 2 )
     678             :         {
     679             :             ;
     680             :         }
     681             : 
     682      374076 :         if ( k > PI_select_table[17 - l][temp] )
     683             :         {
     684      207867 :             l--;
     685             :         }
     686             : 
     687      374076 :         k = PI_select_table[17 - l][temp--] - k;
     688      374076 :         pos_vector[i] = (int16_t) ( l - 1 );
     689             :     }
     690      198204 :     pos_vector[i] = (int16_t) ( l + k );
     691             : 
     692      198204 :     return;
     693             : }
     694             : 
     695             : /*---------------------------------------------------------------------*
     696             :  * fcb_decode_PI()
     697             :  *
     698             :  * decode fcb pulse index
     699             :  *---------------------------------------------------------------------*/
     700             : 
     701             : /*! r: return pulse position number */
     702      198204 : static void fcb_decode_PI(
     703             :     int32_t code_index,     /* i  : fcb index information          */
     704             :     int16_t sector_6p[],    /* o  : decoded pulse position         */
     705             :     const int16_t pulse_num /* i  : pulse number for the track     */
     706             : )
     707             : {
     708             :     int16_t i, l;
     709             :     int32_t mn9;
     710             :     int16_t pulse_pos_num;
     711             :     int16_t sector_6p_temp[7], sector_6p_num_temp[7];
     712             :     int16_t *sector_6p_ptr0;
     713             :     int16_t *sector_6p_ptr1;
     714             : 
     715             :     /*get the position number and the pulse number on every position */
     716      198204 :     mn9 = fcb_decode_class_all_p( &code_index, sector_6p_num_temp, pulse_num, &pulse_pos_num );
     717             : 
     718             :     /* rebuild the vector*/
     719             :     /* decode the pulse position not same to the others*/
     720      198204 :     fcb_decode_position( mn9, sector_6p_temp, pulse_pos_num );
     721      770484 :     for ( i = pulse_pos_num - 1; i >= 0; i-- )
     722             :     {
     723      572280 :         sector_6p_temp[i] += ( ( code_index & 0x1 ) << 4 );
     724      572280 :         code_index = code_index >> 1;
     725             :     }
     726             : 
     727             :     /* decode the pulse position maybe some pulse position same to other pulse */
     728      198204 :     sector_6p_ptr0 = &sector_6p[pulse_num];
     729      198204 :     sector_6p_ptr1 = &sector_6p_temp[pulse_pos_num];
     730      770484 :     for ( i = 0; i < pulse_pos_num; i++ )
     731             :     {
     732      572280 :         sector_6p_ptr1--;
     733     1166892 :         for ( l = 0; l < sector_6p_num_temp[pulse_pos_num - 1 - i]; l++ )
     734             :         {
     735      594612 :             *--sector_6p_ptr0 = *sector_6p_ptr1;
     736             :         }
     737             :     }
     738             : 
     739      198204 :     return;
     740             : }
     741             : 
     742             : /*---------------------------------------------------------------------*
     743             :  * Read FCB index                                                      *
     744             :  *---------------------------------------------------------------------*/
     745             : 
     746       99102 : void D_ACELP_decode_43bit(
     747             :     uint16_t idxs[],
     748             :     float code[],
     749             :     int16_t *pulsestrack )
     750             : {
     751             :     int32_t ps[8];
     752             :     int16_t pos[7];
     753             :     int32_t joint_index;
     754       99102 :     int32_t joint_offset = 3611648; /*offset for 3 pulses per track*/
     755             : 
     756       99102 :     set_f( code, 0.0f, L_SUBFR );
     757             : 
     758       99102 :     ps[3] = idxs[0] & 0x1ff;
     759       99102 :     ps[2] = ( ( idxs[1] & 3 ) << 7 ) + ( idxs[0] >> 9 );
     760       99102 :     joint_index = ( ( idxs[2] << 16 ) + idxs[1] ) >> 2;
     761             : 
     762       99102 :     if ( joint_index >= joint_offset )
     763             :     {
     764       82623 :         joint_index = joint_index - joint_offset;
     765             :     }
     766             : 
     767       99102 :     ps[0] = joint_index / 5472;
     768       99102 :     ps[1] = joint_index - ps[0] * 5472;
     769       99102 :     fcb_decode_PI( ps[0], pos, 3 );
     770       99102 :     add_pulses( pos, pulsestrack[0], 0, code );
     771       99102 :     fcb_decode_PI( ps[1], pos, 3 );
     772       99102 :     add_pulses( pos, pulsestrack[1], 1, code );
     773             : 
     774       99102 :     dec_2p_2N1( ps[2], 4, 0, pos );
     775       99102 :     add_pulses( pos, pulsestrack[2], 2, code );
     776       99102 :     dec_2p_2N1( ps[3], 4, 0, pos );
     777       99102 :     add_pulses( pos, pulsestrack[3], 3, code );
     778             : 
     779       99102 :     return;
     780             : }
     781             : 
     782             : /*-------------------------------------------------------*
     783             :  * dec_1p_N1()
     784             :  *
     785             :  * Decode 1 pulse with N+1 bits
     786             :  *-------------------------------------------------------*/
     787             : 
     788           0 : static void dec_1p_N1_L_subfr(
     789             :     const int32_t index,  /* i  : quantization index    */
     790             :     const int16_t nb_pos, /* i  : number of positions   */
     791             :     const int16_t N,      /* i  : nb. of bits           */
     792             :     int16_t pos[]         /* o  : pulse position        */
     793             : )
     794             : {
     795             :     int16_t i, pos1;
     796             :     int32_t mask;
     797             : 
     798           0 :     mask = ( ( 1 << N ) - 1 );
     799           0 :     pos1 = (int16_t) ( index & mask );
     800           0 :     i = (int16_t) ( index >> N ) & 1;
     801             : 
     802           0 :     if ( i == 1 )
     803             :     {
     804           0 :         pos1 += nb_pos;
     805             :     }
     806             : 
     807           0 :     pos[0] = pos1;
     808             : 
     809           0 :     return;
     810             : }
     811             : 
     812             : /*-------------------------------------------------------*
     813             :  * add_pulses()
     814             :  *
     815             :  * Add decoded pulses to the codeword
     816             :  *-------------------------------------------------------*/
     817             : 
     818           0 : static void add_pulses_L_subfr(
     819             :     const int16_t nb_pos,   /* i  : number of positions */
     820             :     const int16_t pos[],    /* i  : pulse position      */
     821             :     const int16_t nb_pulse, /* i  : nb. of pulses       */
     822             :     const int16_t track,    /* i  : no. of the tracks   */
     823             :     float code[]            /* i/o: decoded codevector  */
     824             : )
     825             : {
     826             :     int16_t i, k;
     827             : 
     828           0 :     for ( k = 0; k < nb_pulse; k++ )
     829             :     {
     830           0 :         i = ( ( pos[k] & ( nb_pos - 1 ) ) * NB_TRACK_FCB_4T ) + track;
     831           0 :         if ( ( pos[k] & nb_pos ) == 0 )
     832             :         {
     833           0 :             code[i] += 1.0f;
     834             :         }
     835             :         else
     836             :         {
     837           0 :             code[i] -= 1.0f;
     838             :         }
     839             :     }
     840             : 
     841           0 :     return;
     842             : }
     843             : 
     844             : /*----------------------------------------------------------------------------------*
     845             :  * dec_acelp_fast()
     846             :  *
     847             :  * fast algebraic codebook decoder
     848             :  *----------------------------------------------------------------------------------*/
     849             : 
     850       84369 : void dec_acelp_fast(
     851             :     Decoder_State *st,       /* i/o: decoder state structure                 */
     852             :     const int16_t cdk_index, /* i  : codebook index                          */
     853             :     float code[],            /* o  : algebraic (fixed) codebook excitation   */
     854             :     const int16_t L_subfr    /* i  : subframe length                         */
     855             : )
     856             : {
     857             :     int16_t k, pos[7], skip_track;
     858             :     int32_t L_index;
     859             :     PulseConfig config;
     860             : 
     861       84369 :     skip_track = -1;
     862       84369 :     set_f( code, 0.0f, L_subfr );
     863             : 
     864       84369 :     if ( L_subfr == L_SUBFR )
     865             :     {
     866       72393 :         config = PulseConfTable[cdk_index];
     867             : 
     868       72393 :         if ( cdk_index == 2 )
     869             :         {
     870       25980 :             dec_acelp_2t32( st, code );
     871             :         }
     872       46413 :         else if ( config.nb_pulse == 2 )
     873             :         {
     874             :             /* 10 bits,  2 pulses, 4 tracks  1010 (used only even tracks) */
     875       12366 :             for ( k = 0; k < NB_TRACK_FCB_4T - 1; k += 2 )
     876             :             {
     877        8244 :                 L_index = get_next_indice( st, 5 );
     878        8244 :                 dec_1p_N1( L_index, 4, 0, pos );
     879        8244 :                 add_pulses( pos, 1, k, code );
     880             :             }
     881             :         }
     882       42291 :         else if ( config.nb_pulse == 3 )
     883             :         {
     884       38283 :             if ( config.codetrackpos == TRACKPOS_FIXED_FIRST )
     885             :             {
     886             :                 /* 15 bits,  3 pulses, 4 tracks  1110 fixed track to first  ? */
     887      145020 :                 for ( k = 0; k < NB_TRACK_FCB_4T - 1; k++ )
     888             :                 {
     889      108765 :                     L_index = get_next_indice( st, 5 );
     890      108765 :                     dec_1p_N1( L_index, 4, 0, pos );
     891      108765 :                     add_pulses( pos, 1, k, code );
     892             :                 }
     893             :             }
     894        2028 :             else if ( config.codetrackpos == TRACKPOS_FREE_THREE )
     895             :             {
     896             :                 /* 17 bits,  3 pulses, 4 tracks  (used all tracks) - 1110, 1101, 1011, 0111 */
     897        2028 :                 skip_track = get_next_indice( st, 2 );
     898       10140 :                 for ( k = 0; k < NB_TRACK_FCB_4T; k++ )
     899             :                 {
     900        8112 :                     if ( k != skip_track )
     901             :                     {
     902        6084 :                         L_index = get_next_indice( st, 5 );
     903        6084 :                         dec_1p_N1( L_index, 4, 0, pos );
     904        6084 :                         add_pulses( pos, 1, k, code );
     905             :                     }
     906             :                 }
     907             :             }
     908             :         }
     909             :         else
     910             :         {
     911        4008 :             if ( config.bits == 20 )
     912             :             {
     913        1323 :                 skip_track = -1;
     914             :             }
     915        2685 :             else if ( config.codetrackpos == TRACKPOS_FIXED_FIRST )
     916             :             {
     917        1617 :                 skip_track = 0;
     918             :             }
     919        1068 :             else if ( config.codetrackpos == TRACKPOS_FREE_ONE )
     920             :             {
     921        1068 :                 skip_track = get_next_indice( st, 2 );
     922             :             }
     923             : 
     924       20040 :             for ( k = 0; k < NB_TRACK_FCB_4T; k++ )
     925             :             {
     926       16032 :                 if ( k == skip_track )
     927             :                 {
     928        2685 :                     L_index = get_next_indice( st, 9 );
     929        2685 :                     dec_2p_2N1( L_index, 4, 0, pos );
     930        2685 :                     add_pulses( pos, 2, k, code );
     931             :                 }
     932             :                 else
     933             :                 {
     934       13347 :                     L_index = get_next_indice( st, 5 );
     935       13347 :                     dec_1p_N1( L_index, 4, 0, pos );
     936       13347 :                     add_pulses( pos, 1, k, code );
     937             :                 }
     938             :             }
     939             :         }
     940             :     }
     941             :     else /* L_subfr == 2*L_SUBFR */
     942             :     {
     943       11976 :         config.bits = cdk_index;
     944             : 
     945       11976 :         if ( cdk_index == 14 )
     946             :         {
     947             :             /* 14 bits, 2 pulses, 2 tracks: 11 (used all tracks) */
     948             :             int16_t index, i0, i1;
     949             : 
     950       11976 :             index = get_next_indice( st, 14 );
     951             : 
     952       11976 :             i0 = ( ( index >> 7 ) & ( NB_POS_FCB_2T_128 - 1 ) ) * NB_TRACK_FCB_2T;
     953       11976 :             i1 = ( ( index & ( NB_POS_FCB_2T_128 - 1 ) ) * NB_TRACK_FCB_2T ) + 1;
     954             : 
     955       11976 :             code[i0] = -1.0f;
     956       11976 :             if ( ( index & 0x2000 ) == 0 )
     957             :             {
     958        6174 :                 code[i0] = 1.0f;
     959             :             }
     960             : 
     961       11976 :             code[i1] = -1.0f;
     962       11976 :             if ( ( index & 0x40 ) == 0 )
     963             :             {
     964        6003 :                 code[i1] = 1.0f;
     965             :             }
     966             :         }
     967           0 :         else if ( cdk_index == 12 )
     968             :         {
     969             :             /* 12 bits, 2 pulses, 4 tracks: 1010 (used only even tracks) */
     970           0 :             for ( k = 0; k < NB_TRACK_FCB_4T - 1; k += 2 )
     971             :             {
     972           0 :                 L_index = get_next_indice( st, 6 );
     973           0 :                 dec_1p_N1_L_subfr( L_index, NB_POS_FCB_4T_128, 5, pos );
     974           0 :                 add_pulses_L_subfr( NB_POS_FCB_4T_128, pos, 1, k, code );
     975             :             }
     976             :         }
     977           0 :         else if ( cdk_index == 18 )
     978             :         {
     979             :             /* 18 bits, 3 pulses, 4 tracks: 1110 (used first three tracks) */
     980           0 :             for ( k = 0; k < NB_TRACK_FCB_4T - 1; k++ )
     981             :             {
     982           0 :                 L_index = get_next_indice( st, 6 );
     983           0 :                 dec_1p_N1_L_subfr( L_index, NB_POS_FCB_4T_128, 5, pos );
     984           0 :                 add_pulses_L_subfr( NB_POS_FCB_4T_128, pos, 1, k, code );
     985             :             }
     986             :         }
     987           0 :         else if ( cdk_index == 20 )
     988             :         {
     989             :             /* 20 bits, 3 pulses, 4 tracks (used all tracks): 1110, 1101, 1011, 0111 */
     990           0 :             skip_track = get_next_indice( st, 2 );
     991           0 :             for ( k = 0; k < NB_TRACK_FCB_4T; k++ )
     992             :             {
     993           0 :                 if ( k != skip_track )
     994             :                 {
     995           0 :                     L_index = get_next_indice( st, 6 );
     996           0 :                     dec_1p_N1_L_subfr( L_index, NB_POS_FCB_4T_128, 5, pos );
     997           0 :                     add_pulses_L_subfr( NB_POS_FCB_4T_128, pos, 1, k, code );
     998             :                 }
     999             :             }
    1000             :         }
    1001           0 :         else if ( cdk_index == 24 )
    1002             :         {
    1003             :             /* 24 bits, 4 pulses, 4 tracks: 1111 */
    1004           0 :             for ( k = 0; k < NB_TRACK_FCB_4T; k++ )
    1005             :             {
    1006           0 :                 L_index = get_next_indice( st, 6 );
    1007           0 :                 dec_1p_N1_L_subfr( L_index, NB_POS_FCB_4T_128, 5, pos );
    1008           0 :                 add_pulses_L_subfr( NB_POS_FCB_4T_128, pos, 1, k, code );
    1009             :             }
    1010             :         }
    1011             :     }
    1012             : 
    1013       84369 :     return;
    1014             : }

Generated by: LCOV version 1.14