LCOV - code coverage report
Current view: top level - lib_enc - cod4t64_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ 43b7b28dcb1471ff5d355252c4b8f37ee7ecc268 Lines: 218 630 34.6 %
Date: 2025-11-02 02:02:47 Functions: 8 14 57.1 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : 
       5             : #include <stdint.h>
       6             : #include "options.h"     /* VMR-WB compilation switches            */
       7             : #include "cnst.h"        /* Common constants                       */
       8             : #include "rom_enc.h"     /* Encoder static table prototypes        */
       9             : #include "prot_fx.h"     /* Function prototypes                    */
      10             : #include "rom_com.h"     /* Static table prototypes                */
      11             : #include "prot_fx_enc.h" /* Function prototypes                    */
      12             : 
      13             : 
      14             : /*-------------------------------------------------------------------*
      15             :  * Local constants
      16             :  *-------------------------------------------------------------------*/
      17             : 
      18             : #define STEP   4
      19             : #define MSIZE  256
      20             : #define NB_MAX 8
      21             : 
      22             : /*-------------------------------------------------------------------*
      23             :  * Local function prototypes
      24             :  *-------------------------------------------------------------------*/
      25             : 
      26             : static Word16 quant_1p_N1_fx( const Word16 pos, const Word16 N );
      27             : static Word16 quant_3p_3N1_fx( const Word16 pos1, const Word16 pos2, const Word16 pos3, const Word16 N );
      28             : static Word32 quant_4p_4N_fx( const Word16 pos[], const Word16 N );
      29             : static Word32 quant_5p_5N_fx( const Word16 pos[], const Word16 N );
      30             : static Word32 quant_6p_6N_2_fx( const Word16 pos[], const Word16 N );
      31             : 
      32             : 
      33             : static Word32 fcb_encode_position_fx( const Word16 pos_vector[], Word32 n, const Word32 pos_num, const Word32 flag );
      34             : static Word32 fcb_encode_class_fx( const Word32 sector_6p_num[], const Word32 pulse_num, const Word32 pulse_pos_num );
      35             : static Word32 fcb_encode_PI_fx( const Word16 v[], const Word32 pulse_num );
      36             : static Word32 pre_process_fx( const Word16 v[], Word16 sector_6p[], Word32 sector_6p_num[], Word32 *pulse_pos_num );
      37             : 
      38             : /*---------------------------------------------------------------------*
      39             :  * ACELP_4t64()
      40             :  *
      41             :  * 20, 36, 44, 52, 64, 72, 88 bits algebraic codebook.
      42             :  * 4 tracks x 16 positions per track = 64 samples.
      43             :  *
      44             :  * 20 bits --> 4 pulses in a frame of 64 samples.
      45             :  * 36 bits --> 8 pulses in a frame of 64 samples.
      46             :  * 44 bits 13 + 9 + 13 + 9 --> 10 pulses in a frame of 64 samples.
      47             :  * 52 bits 13 + 13 + 13 + 13 --> 12 pulses in a frame of 64 samples.
      48             :  * 64 bits 2 + 2 + 2 + 2 + 14 + 14 + 14 + 14 -->
      49             :  *                               16 pulses in a frame of 64 samples.
      50             :  * 72 bits 10 + 2 + 10 + 2 + 10 + 14 + 10 + 14 -->
      51             :  *                               18 pulses in a frame of 64 samples.
      52             :  * 88 bits 11 + 11 + 11 + 11 + 11 + 11 + 11 + 11 -->
      53             :  *                               24 pulses in a frame of 64 samples.
      54             :  * All pulses can have two (2) possible amplitudes: +1 or -1.
      55             :  * Each pulse can have sixteen (16) possible positions.
      56             :  *---------------------------------------------------------------------*/
      57             : 
      58       64653 : Word16 acelp_4t64_fx(
      59             :     BSTR_ENC_HANDLE hBstr,   /* i/o: encoder bitstream handle                      */
      60             :     Word16 dn[],             /* i  : corr. between target and h[].                 */
      61             :     const Word16 cn[],       /* i  : residual after long term prediction            Q_new*/
      62             :     const Word16 H[],        /* i  : impulse response of weighted synthesis filter  Q12*/
      63             :     Word16 R[],              /* i  : autocorrelation values                        */
      64             :     const Word16 acelpautoc, /* i  : autocorrealtion flag                           */
      65             :     Word16 code[],           /* o  : algebraic (fixed) codebook excitation          Q9*/
      66             :     Word16 y[],              /* o  : filtered fixed codebook excitation             Q9*/
      67             :     Word16 nbbits,           /* i  : number of bits per codebook                    */
      68             :     const Word16 cmpl_flag,  /* i  : complexity reduction flag                      */
      69             :     const Word16 Opt_AMR_WB, /* i  : flag indicating AMR-WB IO mode                 */
      70             :     const Word16 element_mode )
      71             : {
      72             :     Word16 i, k, index, track;
      73             :     Word32 L_index;
      74             :     Word16 ind[NPMAXPT * NB_TRACK_FCB_4T + 32]; /* VE3: why +32 ???*/
      75       64653 :     Word16 codvec[NB_PULSE_MAX + 4] = { 0 };
      76       64653 :     Word16 saved_bits = 0;
      77             : 
      78             :     PulseConfig config;
      79             :     Word16 indexing_indices[6], wordcnt, bitcnt;
      80             : 
      81       64653 :     set16_fx( codvec, 0, NB_PULSE_MAX + 4 );
      82       64653 :     SWITCH( nbbits )
      83             :     {
      84             : 
      85         684 :         case 20: /* EVS/AMR-WB pulse indexing: 20 bits, 4 pulses, 4 tracks  */
      86         684 :             config.nbiter = 4;
      87         684 :             move16(); /* 4x12x16=768 loop                                        */
      88         684 :             config.alp = 16384;
      89         684 :             move16(); /* 2 in Q13*/
      90         684 :             config.nb_pulse = 4;
      91         684 :             move16();
      92         684 :             config.fixedpulses = 0;
      93         684 :             move16();
      94         684 :             config.nbpos[0] = 4;
      95         684 :             move16();
      96         684 :             config.nbpos[1] = 8;
      97         684 :             move16();
      98         684 :             BREAK;
      99             : 
     100        2306 :         case 28: /* EVS pulse indexing: 28 bits, 6 pulses, 4 tracks     */
     101        2306 :             config.nbiter = 4;
     102        2306 :             move16();          /* 4x20x16=1280 loops                                  */
     103        2306 :             config.alp = 8192; /*1 in Q13*/
     104        2306 :             move16();          /* coeff FOR sign setting                              */
     105        2306 :             config.nb_pulse = 6;
     106        2306 :             move16();
     107        2306 :             config.fixedpulses = 0;
     108        2306 :             move16();
     109        2306 :             config.nbpos[0] = 6;
     110        2306 :             move16();
     111        2306 :             config.nbpos[1] = 6;
     112        2306 :             move16();
     113        2306 :             config.nbpos[2] = 8;
     114        2306 :             move16();
     115        2306 :             BREAK;
     116             : 
     117       61642 :         case 36: /* EVS/AMR-WB pulse indexing: 36 bits, 8 pulses, 4 tracks  */
     118       61642 :             config.nbiter = 4;
     119       61642 :             move16();          /* 4x20x16=1280 loops                                      */
     120       61642 :             config.alp = 8192; /*1 in Q13*/
     121       61642 :             move16();          /* coeff FOR sign setting                                  */
     122       61642 :             config.nb_pulse = 8;
     123       61642 :             move16();
     124       61642 :             config.fixedpulses = 2;
     125       61642 :             move16();
     126       61642 :             config.nbpos[0] = 4;
     127       61642 :             move16();
     128       61642 :             config.nbpos[1] = 8;
     129       61642 :             move16();
     130       61642 :             config.nbpos[2] = 8;
     131       61642 :             move16();
     132       61642 :             BREAK;
     133             : 
     134           0 :         case 43: /* EVS pulse indexing:    43 bits, 10 pulses, 4 tracks */
     135             :         case 44: /* AMR-WB pulse indexing: 44 bits, 10 pulses, 4 tracks */
     136           0 :             config.nbiter = 4;
     137           0 :             move16();          /* 4x26x16=1664 loops                                  */
     138           0 :             config.alp = 8192; /*1 in Q13*/
     139           0 :             move16();
     140           0 :             config.nb_pulse = 10;
     141           0 :             move16();
     142           0 :             config.fixedpulses = 2;
     143           0 :             move16();
     144           0 :             config.nbpos[0] = 4;
     145           0 :             move16();
     146           0 :             config.nbpos[1] = 6;
     147           0 :             move16();
     148           0 :             config.nbpos[2] = 8;
     149           0 :             move16();
     150           0 :             config.nbpos[3] = 8;
     151           0 :             move16();
     152           0 :             BREAK;
     153             : 
     154           0 :         case 50: /* EVS pulse indexing:    50 bits, 12 pulses, 4 tracks */
     155             :         case 52: /* AMR-WB pulse indexing: 52 bits, 12 pulses, 4 tracks */
     156           0 :             config.nbiter = 4;
     157           0 :             move16();          /* 4x26x16=1664 loops                                  */
     158           0 :             config.alp = 8192; /*1 in Q13*/
     159           0 :             move16();
     160           0 :             config.nb_pulse = 12;
     161           0 :             move16();
     162           0 :             config.fixedpulses = 4;
     163           0 :             move16();
     164           0 :             config.nbpos[0] = 4;
     165           0 :             move16();
     166           0 :             config.nbpos[1] = 6;
     167           0 :             move16();
     168           0 :             config.nbpos[2] = 8;
     169           0 :             move16();
     170           0 :             config.nbpos[3] = 8;
     171           0 :             move16();
     172           0 :             BREAK;
     173             : 
     174          21 :         case 62: /* EVS pulse indexing:    62 bits, 16 pulses, 4 tracks */
     175             :         case 64: /* AMR-WB pulse indexing: 64 bits, 16 pulses, 4 tracks */
     176          21 :             config.nbiter = 3;
     177          21 :             move16();          /* 3x36x16=1728 loops                                  */
     178          21 :             config.alp = 6554; /*.8f in Q13*/
     179          21 :             move16();
     180          21 :             config.nb_pulse = 16;
     181          21 :             move16();
     182          21 :             config.fixedpulses = 4;
     183          21 :             move16();
     184          21 :             config.nbpos[0] = 4;
     185          21 :             move16();
     186          21 :             config.nbpos[1] = 4;
     187          21 :             move16();
     188          21 :             config.nbpos[2] = 6;
     189          21 :             move16();
     190          21 :             config.nbpos[3] = 6;
     191          21 :             move16();
     192          21 :             config.nbpos[4] = 8;
     193          21 :             move16();
     194          21 :             config.nbpos[5] = 8;
     195          21 :             move16();
     196          21 :             BREAK;
     197             : 
     198           0 :         case 72: /* AMR-WB pulse indexing: 72 bits, 18 pulses, 4 tracks */
     199           0 :             config.nbiter = 3;
     200           0 :             move16();          /* 3x35x16=1680 loops                                  */
     201           0 :             config.alp = 6144; /*.75f in Q13*/
     202           0 :             move16();
     203           0 :             config.nb_pulse = 18;
     204           0 :             move16();
     205           0 :             config.fixedpulses = 4;
     206           0 :             move16();
     207           0 :             config.nbpos[0] = 2;
     208           0 :             move16();
     209           0 :             config.nbpos[1] = 3;
     210           0 :             move16();
     211           0 :             config.nbpos[2] = 4;
     212           0 :             move16();
     213           0 :             config.nbpos[3] = 5;
     214           0 :             move16();
     215           0 :             config.nbpos[4] = 6;
     216           0 :             move16();
     217           0 :             config.nbpos[5] = 7;
     218           0 :             move16();
     219           0 :             config.nbpos[6] = 8;
     220           0 :             move16();
     221           0 :             BREAK;
     222             : 
     223           0 :         case 88: /* AMR-WB pulse indexing: 88 bits, 24 pulses, 4 tracks */
     224           0 :             config.nbiter = 2;
     225           0 :             move16();          /* 2x53x16=1696 loop                                   */
     226           0 :             config.alp = 4096; /*.5f in Q13*/
     227           0 :             move16();
     228           0 :             config.nb_pulse = 24;
     229           0 :             move16();
     230           0 :             config.fixedpulses = 4;
     231           0 :             move16();
     232           0 :             config.nbpos[0] = 2;
     233           0 :             move16();
     234           0 :             config.nbpos[1] = 2;
     235           0 :             move16();
     236           0 :             config.nbpos[2] = 3;
     237           0 :             move16();
     238           0 :             config.nbpos[3] = 4;
     239           0 :             move16();
     240           0 :             config.nbpos[4] = 5;
     241           0 :             move16();
     242           0 :             config.nbpos[5] = 6;
     243           0 :             move16();
     244           0 :             config.nbpos[6] = 7;
     245           0 :             move16();
     246           0 :             config.nbpos[7] = 8;
     247           0 :             move16();
     248           0 :             config.nbpos[8] = 8;
     249           0 :             move16();
     250           0 :             config.nbpos[9] = 8;
     251           0 :             move16();
     252           0 :             BREAK;
     253             : 
     254           0 :         case 87: /* EVS pulse indexing:   87 bits, 26 pulses, 4 tracks  */
     255           0 :             config.nbiter = 1;
     256           0 :             move16();
     257           0 :             config.alp = 4096; /*.5f in Q13*/
     258           0 :             move16();
     259           0 :             config.nb_pulse = 26;
     260           0 :             move16();
     261           0 :             config.fixedpulses = 4;
     262           0 :             move16();
     263           0 :             config.nbpos[0] = 4;
     264           0 :             move16();
     265           0 :             config.nbpos[1] = 6;
     266           0 :             move16();
     267           0 :             config.nbpos[2] = 6;
     268           0 :             move16();
     269           0 :             config.nbpos[3] = 8;
     270           0 :             move16();
     271           0 :             config.nbpos[4] = 8;
     272           0 :             move16();
     273           0 :             config.nbpos[5] = 8;
     274           0 :             move16();
     275           0 :             config.nbpos[6] = 8;
     276           0 :             move16();
     277           0 :             config.nbpos[7] = 8;
     278           0 :             move16();
     279           0 :             config.nbpos[8] = 8;
     280           0 :             move16();
     281           0 :             config.nbpos[9] = 8;
     282           0 :             move16();
     283           0 :             config.nbpos[10] = 8;
     284           0 :             move16();
     285           0 :             BREAK;
     286             :     }
     287             : 
     288             :     /* reduce the number of iterations as a compromise between the performance and complexity */
     289       64653 :     if ( cmpl_flag > 0 )
     290             :     {
     291       61151 :         config.nbiter = cmpl_flag;
     292       61151 :         move16();
     293             :     }
     294             : 
     295       64653 :     config.codetrackpos = TRACKPOS_FIXED_FIRST;
     296       64653 :     move16();
     297       64653 :     config.bits = nbbits;
     298       64653 :     move16();
     299             : 
     300       64653 :     IF( acelpautoc )
     301             :     {
     302       61001 :         E_ACELP_4tsearchx_fx( dn, cn, R, code, &config, ind, element_mode );
     303             :         /* Generate weighted code */
     304       61001 :         E_ACELP_weighted_code( code, H, 12, y );
     305             :     }
     306             :     ELSE
     307             :     {
     308        3652 :         E_ACELP_4tsearch_fx( dn, cn, H, code, &config, ind, y, 0 );
     309      237380 :         FOR( i = 0; i < L_SUBFR; i++ )
     310             :         {
     311      233728 :             y[i] = shr( y[i], 3 );
     312      233728 :             move16(); /*Q9              */
     313             :         }
     314             :     }
     315             : 
     316             :     /*-----------------------------------------------------------------*
     317             :      * Indexing
     318             :      *-----------------------------------------------------------------*/
     319             : 
     320       64653 :     IF( !Opt_AMR_WB )
     321             :     {
     322       64653 :         saved_bits = E_ACELP_indexing_fx( code, &config, NB_TRACK_FCB_4T, indexing_indices );
     323             : 
     324       64653 :         saved_bits = 0;
     325       64653 :         move16();
     326             : 
     327       64653 :         wordcnt = shr( nbbits, 4 );
     328       64653 :         bitcnt = s_and( nbbits, 15 );
     329      190990 :         FOR( i = 0; i < wordcnt; i++ )
     330             :         {
     331      126337 :             push_indice( hBstr, IND_ALG_CDBK_4T64, indexing_indices[i], 16 );
     332             :         }
     333       64653 :         IF( bitcnt )
     334             :         {
     335       64653 :             push_indice( hBstr, IND_ALG_CDBK_4T64, indexing_indices[i], bitcnt );
     336             :         }
     337             :     }
     338             :     ELSE
     339             :     {
     340             :         /* AMR-WB pulse indexing */
     341             : 
     342           0 :         IF( EQ_16( nbbits, 20 ) )
     343             :         {
     344           0 :             FOR( track = 0; track < NB_TRACK_FCB_4T; track++ )
     345             :             {
     346           0 :                 k = i_mult2( track, NPMAXPT );
     347           0 :                 index = quant_1p_N1_fx( ind[k], 4 );
     348           0 :                 push_indice( hBstr, IND_ALG_CDBK_4T64, index, 5 );
     349             :             }
     350             :         }
     351           0 :         ELSE IF( EQ_16( nbbits, 36 ) )
     352             :         {
     353           0 :             FOR( track = 0; track < NB_TRACK_FCB_4T; track++ )
     354             :             {
     355             : 
     356           0 :                 k = i_mult2( track, NPMAXPT ); /* k = track * NPMAXPT;*/
     357           0 :                 index = quant_2p_2N1_fx( ind[k], ind[k + 1], 4 );
     358           0 :                 push_indice( hBstr, IND_ALG_CDBK_4T64, index, 9 );
     359             :             }
     360             :         }
     361           0 :         ELSE IF( EQ_16( nbbits, 44 ) ) /* AMR-WB pulse indexing */
     362             :         {
     363           0 :             FOR( track = 0; track < ( NB_TRACK_FCB_4T - 2 ); track++ )
     364             :             {
     365           0 :                 k = i_mult2( track, NPMAXPT );
     366           0 :                 index = quant_3p_3N1_fx( ind[k], ind[k + 1], ind[k + 2], 4 );
     367           0 :                 push_indice( hBstr, IND_ALG_CDBK_4T64, index, 13 );
     368             :             }
     369             : 
     370           0 :             FOR( track = 2; track < NB_TRACK_FCB_4T; track++ )
     371             :             {
     372           0 :                 k = i_mult2( track, NPMAXPT );
     373           0 :                 index = quant_2p_2N1_fx( ind[k], ind[k + 1], 4 );
     374           0 :                 push_indice( hBstr, IND_ALG_CDBK_4T64, index, 9 );
     375             :             }
     376             :         }
     377           0 :         ELSE IF( EQ_16( nbbits, 52 ) ) /* AMR-WB pulse indexing */
     378             :         {
     379           0 :             FOR( track = 0; track < NB_TRACK_FCB_4T; track++ )
     380             :             {
     381           0 :                 k = i_mult2( track, NPMAXPT );
     382           0 :                 index = quant_3p_3N1_fx( ind[k], ind[k + 1], ind[k + 2], 4 );
     383           0 :                 push_indice( hBstr, IND_ALG_CDBK_4T64, index, 13 );
     384             :             }
     385             :         }
     386           0 :         ELSE IF( EQ_16( nbbits, 64 ) ) /* AMR-WB pulse indexing */
     387             :         {
     388           0 :             FOR( track = 0; track < NB_TRACK_FCB_4T; track++ )
     389             :             {
     390           0 :                 k = i_mult2( track, NPMAXPT );
     391           0 :                 L_index = quant_4p_4N_fx( &ind[k], 4 );
     392           0 :                 index = extract_l( L_shr( L_index, 14 ) & 3 );
     393           0 :                 logic16();
     394           0 :                 push_indice( hBstr, IND_ALG_CDBK_4T64_1, index, 2 );
     395             :             }
     396             : 
     397           0 :             FOR( track = 0; track < NB_TRACK_FCB_4T; track++ )
     398             :             {
     399           0 :                 k = i_mult2( track, NPMAXPT );
     400           0 :                 L_index = quant_4p_4N_fx( &ind[k], 4 );
     401           0 :                 index = extract_l( L_index & 0x3FFF );
     402           0 :                 logic16();
     403           0 :                 push_indice( hBstr, IND_ALG_CDBK_4T64_2, index, 14 );
     404             :             }
     405             :         }
     406           0 :         ELSE IF( EQ_16( nbbits, 72 ) )
     407             :         {
     408           0 :             FOR( track = 0; track < ( NB_TRACK_FCB_4T - 2 ); track++ )
     409             :             {
     410           0 :                 k = i_mult2( track, NPMAXPT );
     411           0 :                 L_index = quant_5p_5N_fx( &ind[k], 4 );
     412           0 :                 index = extract_l( L_shr( L_index, 10 ) & 0x03FF );
     413           0 :                 logic16();
     414           0 :                 push_indice( hBstr, IND_ALG_CDBK_4T64_1, index, 10 );
     415             :             }
     416             : 
     417           0 :             FOR( track = 2; track < NB_TRACK_FCB_4T; track++ )
     418             :             {
     419           0 :                 k = i_mult2( track, NPMAXPT );
     420           0 :                 L_index = quant_4p_4N_fx( &ind[k], 4 );
     421           0 :                 index = extract_l( L_shr( L_index, 14 ) & 3 );
     422           0 :                 logic16();
     423           0 :                 push_indice( hBstr, IND_ALG_CDBK_4T64_1, index, 2 );
     424             :             }
     425             : 
     426           0 :             FOR( track = 0; track < ( NB_TRACK_FCB_4T - 2 ); track++ )
     427             :             {
     428           0 :                 k = i_mult2( track, NPMAXPT );
     429           0 :                 L_index = quant_5p_5N_fx( &ind[k], 4 );
     430           0 :                 index = extract_l( L_index & 0x03FF );
     431           0 :                 logic16();
     432           0 :                 push_indice( hBstr, IND_ALG_CDBK_4T64_2, index, 10 );
     433             :             }
     434             : 
     435           0 :             FOR( track = 2; track < NB_TRACK_FCB_4T; track++ )
     436             :             {
     437           0 :                 k = i_mult2( track, NPMAXPT );
     438           0 :                 L_index = quant_4p_4N_fx( &ind[k], 4 );
     439           0 :                 index = extract_l( L_index & 0x3FFF );
     440           0 :                 logic16();
     441           0 :                 push_indice( hBstr, IND_ALG_CDBK_4T64_2, index, 14 );
     442             :             }
     443             :         }
     444           0 :         ELSE IF( EQ_16( nbbits, 88 ) )
     445             :         {
     446           0 :             FOR( track = 0; track < NB_TRACK_FCB_4T; track++ )
     447             :             {
     448           0 :                 k = i_mult2( track, NPMAXPT );
     449           0 :                 L_index = quant_6p_6N_2_fx( &ind[k], 4 );
     450           0 :                 index = extract_l( L_shr( L_index, 11 ) & 0x07FF );
     451           0 :                 logic16();
     452           0 :                 push_indice( hBstr, IND_ALG_CDBK_4T64_1, index, 11 );
     453             :             }
     454             : 
     455           0 :             FOR( track = 0; track < NB_TRACK_FCB_4T; track++ )
     456             :             {
     457           0 :                 k = i_mult2( track, NPMAXPT );
     458           0 :                 L_index = quant_6p_6N_2_fx( &ind[k], 4 );
     459           0 :                 index = extract_l( L_index & 0x07FF );
     460           0 :                 logic16();
     461           0 :                 push_indice( hBstr, IND_ALG_CDBK_4T64_2, index, 11 );
     462             :             }
     463             :         }
     464             :     }
     465             : 
     466       64653 :     return saved_bits;
     467             : }
     468             : 
     469             : 
     470             : /*---------------------------------------------------------------------*
     471             :  *encode class for 3p 4p 5p 6p/track                                   *
     472             :  *---------------------------------------------------------------------*/
     473             : 
     474             : /* o:   comfort noise gain factor */
     475        7415 : static Word32 fcb_encode_cl_fx(
     476             :     const Word32 buffer[],  /* i  : pulses on a track                         */
     477             :     const Word32 pulse_num, /* i  : pulses number on a track                  */
     478             :     const Word32 pos_num    /* i  : number of the position which have pulse   */
     479             : )
     480             : {
     481             :     Word32 i, k;
     482             :     Word32 temp1, temp2;
     483             : 
     484        7415 :     temp1 = L_sub( L_add( pos_num, pulse_num ), 1 );
     485        7415 :     temp2 = L_add( pulse_num, 0 );
     486             : 
     487        7415 :     k = L_sub( PI_select_table[temp1][pulse_num], 1 );
     488        7415 :     temp1 = L_sub( temp1, 1 );
     489             : 
     490       15206 :     FOR( i = 0; i < pulse_num; i++ )
     491             :     {
     492        7791 :         k = L_sub( k, PI_select_table[temp1 - buffer[i]][temp2--] );
     493        7791 :         temp1 = L_sub( temp1, 1 );
     494             :     }
     495             : 
     496        7415 :     return k;
     497             : }
     498             : 
     499             : 
     500             : /*---------------------------------------------------------------------*
     501             :  *encode fcb pulse index                                               *
     502             :  *---------------------------------------------------------------------*/
     503             : 
     504             : /* o:   return index of the  pulse on a track */
     505       67412 : static Word32 fcb_encode_PI_fx(
     506             :     const Word16 v[],      /* i  : pulse on a track                  Q9  */
     507             :     const Word32 pulse_num /* i  : number of the pulse on a track        */
     508             : )
     509             : {
     510             :     Word16 sector_p[7];
     511             :     Word32 pulse_pos_num;
     512             :     Word32 sector_p_num[7];
     513             :     Word32 code_index;
     514             :     Word32 sign;
     515             : 
     516             :     /*order the pulse position*/
     517       67412 :     sign = pre_process_fx( v, sector_p, sector_p_num, &pulse_pos_num );
     518             : 
     519             :     /*encode the position*/
     520       67412 :     code_index = fcb_encode_position_fx( sector_p, 16, pulse_pos_num, 1 );
     521             :     /*encode the class and compute class offset*/
     522       67412 :     code_index = L_add( code_index, fcb_encode_class_fx( sector_p_num, pulse_num, pulse_pos_num ) );
     523             : 
     524       67412 :     code_index = L_add( PI_offset[pulse_num][( ( pulse_num + 1L ) - pulse_pos_num )], L_add( L_shl( code_index, extract_l( pulse_pos_num ) ), sign ) );
     525             : 
     526       67412 :     return code_index;
     527             : }
     528             : 
     529             : 
     530             : /*---------------------------------------------------------------------*
     531             :  *encode the class and compute class offset                            *
     532             :  *---------------------------------------------------------------------*/
     533             : 
     534             : /* o:   class offset        */
     535       67412 : static Word32 fcb_encode_class_fx(
     536             :     const Word32 sector_6p_num[], /* i  : position which have pulse on a track             */
     537             :     const Word32 pulse_num,       /* i  : pulse number on a track                          */
     538             :     const Word32 pulse_pos_num    /* i  : number of position which have pulse on a track   */
     539             : )
     540             : {
     541             :     Word32 i, j, k;
     542             :     Word32 mn9_offet;
     543             :     Word32 vector_class[6];
     544             :     Word32 *vector_class_ptr;
     545             : 
     546       67412 :     mn9_offet = L_deposit_l( 0 );
     547             : 
     548       67412 :     IF( LT_32( pulse_pos_num, pulse_num ) )
     549             :     {
     550        7415 :         vector_class_ptr = vector_class;
     551       21869 :         FOR( i = 0; i < pulse_pos_num; i++ )
     552             :         {
     553       22245 :             FOR( j = 0; j < ( sector_6p_num[i] - 1 ); j++ )
     554             :             {
     555             : 
     556        7791 :                 *vector_class_ptr++ = i;
     557        7791 :                 move32();
     558             :             }
     559             :         }
     560        7415 :         k = fcb_encode_cl_fx( vector_class, L_sub( pulse_num, pulse_pos_num ), pulse_pos_num );
     561       10944 :         FOR( i = 0; i < k; i++ )
     562             :         {
     563        3529 :             mn9_offet = L_add( mn9_offet, PI_factor[pulse_pos_num] );
     564             :         }
     565             :     }
     566       67412 :     return mn9_offet;
     567             : }
     568             : 
     569             : 
     570             : /*---------------------------------------------------------------------*
     571             :  *encode the position                                                  *
     572             :  *---------------------------------------------------------------------*/
     573             : 
     574             : /* o:   return index of the positions which have pulse*/
     575       67412 : static Word32 fcb_encode_position_fx(
     576             :     const Word16 pos_vector[], /* i:   position of the pulse on a track              */
     577             :     Word32 n,
     578             :     const Word32 pos_num, /* i:   the number of position which have pulse   */
     579             :     const Word32 flag )
     580             : {
     581             :     Word32 i;
     582             :     Word32 mmm1;
     583             :     Word32 temp2;
     584       67412 :     mmm1 = L_sub( PI_select_table[n][pos_num], 1 );
     585       67412 :     temp2 = pos_num;
     586       67412 :     move16();
     587             : 
     588       67412 :     IF( flag ) /* no decrease */
     589             :     {
     590       67412 :         move16(); /*ptr init*/
     591      261857 :         FOR( i = 0; i < pos_num; i++ )
     592             :         {
     593             :             /*mmm1 -= PI_select_table_fx[sub(n,pos_vector[i]-1)][temp2--];*/
     594      194445 :             mmm1 = L_sub( mmm1, PI_select_table[n - ( pos_vector[i] + 1 )][temp2--] );
     595             :         }
     596             :     }
     597             :     ELSE
     598             :     {
     599           0 :         move16(); /*ptr init*/
     600           0 :         FOR( i = 0; i < pos_num; i++ )
     601             :         {
     602             :             /*mmm1 -= PI_select_table_fx[n-pos_vector[i]-1][temp2--];*/
     603           0 :             mmm1 = L_sub( mmm1, PI_select_table[n - ( pos_vector[i] + 1 )][temp2--] );
     604           0 :             n = L_sub( n, 1 );
     605             :         }
     606             :     }
     607             : 
     608       67412 :     return mmm1;
     609             : }
     610             : 
     611             : 
     612             : /*------------------------------------------------------------*
     613             :  * quant_1p_N1
     614             :  *
     615             :  * Quantization of 1 pulse with N+1 bits:
     616             :  *-------------------------------------------------------------*/
     617             : 
     618             : /* o  : return N+1 bits             */
     619           0 : static Word16 quant_1p_N1_fx(
     620             :     const Word16 pos, /* i  : position of the pulse       */
     621             :     const Word16 N    /* i  : number of bits FOR position */
     622             : )
     623             : {
     624             :     Word16 mask;
     625             :     Word16 index;
     626             : 
     627             : 
     628           0 :     mask = sub( shl( 1, N ), 1 ); /* mask = ((1<<N)-1) */
     629             : 
     630           0 :     index = s_and( pos, mask );
     631           0 :     IF( s_and( pos, NB_POS_FCB_4T ) != 0 )
     632             :     {
     633           0 :         index = add( index, shl( 1, N ) ); /* index += 1 << N */
     634             :     }
     635             : 
     636           0 :     return index;
     637             : }
     638             : 
     639             : 
     640             : /*------------------------------------------------------------*
     641             :  * quant_2p_2N1_fx
     642             :  *
     643             :  * Quantization of 2 pulses with 2*N+1 bits:
     644             : 
     645             : 
     646             :  *-------------------------------------------------------------*/
     647             : 
     648             : /* o:  return (2*N)+1 bits         */
     649       68363 : Word16 quant_2p_2N1_fx(
     650             :     const Word16 pos1, /* i  : position of the pulse 1     */
     651             :     const Word16 pos2, /* i  : position of the pulse 2     */
     652             :     const Word16 N     /* i  : number of bits FOR position */
     653             : )
     654             : {
     655             :     Word16 mask, tmp;
     656             :     Word16 index;
     657             : 
     658       68363 :     mask = sub( shl( 1, N ), 1 ); /* mask = ((1<<N)-1) */
     659             : 
     660             :     /*----------------------------------------------------------------*
     661             :      * sign of 1st pulse == sign of 2th pulse
     662             :      *----------------------------------------------------------------*/
     663             : 
     664       68363 :     logic16();
     665       68363 :     logic16();
     666       68363 :     IF( ( ( pos2 ^ pos1 ) & NB_POS_FCB_4T ) == 0 )
     667             :     {
     668       35663 :         IF( LE_16( pos1, pos2 ) ) /* ((pos1 - pos2) <= 0) */
     669             :         {
     670             :             /* index = ((pos1 & mask) << N) + (pos2 & mask) */
     671       35464 :             index = add( shl( s_and( pos1, mask ), N ), s_and( pos2, mask ) );
     672             :         }
     673             :         ELSE
     674             :         {
     675             :             /* index = ((pos2 & mask) << N) + (pos1 & mask) */
     676         199 :             index = add( shl( s_and( pos2, mask ), N ), s_and( pos1, mask ) );
     677             :         }
     678       35663 :         logic16();
     679       35663 :         IF( ( pos1 & NB_POS_FCB_4T ) != 0 )
     680             :         {
     681       18132 :             tmp = shl( N, 1 );
     682       18132 :             index = add( index, shl( 1, tmp ) ); /* index += 1 << (2*N) */
     683             :         }
     684             :     }
     685             :     /*----------------------------------------------------------------*
     686             :      * sign of 1st pulse != sign of 2th pulse
     687             :      *----------------------------------------------------------------*/
     688             :     ELSE
     689             :     {
     690       32700 :         IF( LE_16( s_and( pos1, mask ), s_and( pos2, mask ) ) )
     691             :         {
     692             :             /* index = ((pos2 & mask) << N) + (pos1 & mask); */
     693       32483 :             index = add( shl( s_and( pos2, mask ), N ), s_and( pos1, mask ) );
     694       32483 :             IF( s_and( pos2, NB_POS_FCB_4T ) != 0 )
     695             :             {
     696       15922 :                 tmp = shl( N, 1 ); /* index += 1 << (2*N); */
     697       15922 :                 index = add( index, shl( 1, tmp ) );
     698             :             }
     699             :         }
     700             :         ELSE
     701             :         {
     702             :             /* index = ((pos1 & mask) << N) + (pos2 & mask); */
     703         217 :             index = add( shl( s_and( pos1, mask ), N ), s_and( pos2, mask ) );
     704         217 :             IF( s_and( pos1, NB_POS_FCB_4T ) != 0 )
     705             :             {
     706          97 :                 tmp = shl( N, 1 );
     707          97 :                 index = add( index, shl( 1, tmp ) ); /* index += 1 << (2*N) */
     708             :             }
     709             :         }
     710             :     }
     711             : 
     712       68363 :     return index;
     713             : }
     714             : 
     715             : 
     716             : /*---------------------------------------------------------------------*
     717             :  * Quantization of 3 pulses with 3*N+1 bits:                           *
     718             :  *---------------------------------------------------------------------*/
     719             : 
     720             : /*  o  : return (3*N)+1 bits         */
     721           0 : static Word16 quant_3p_3N1_fx(
     722             :     const Word16 pos1, /*  i  : position of the pulse 1     */
     723             :     const Word16 pos2, /*  i  : position of the pulse 2     */
     724             :     const Word16 pos3, /*  i  : position of the pulse 3     */
     725             :     const Word16 N     /*  i  : number of bits for position */
     726             : )
     727             : {
     728             :     Word16 nb_pos;
     729             :     Word16 index;
     730             : 
     731           0 :     nb_pos = shl( 1, sub( N, 1 ) ); /* nb_pos = (1<<(N-1)); */
     732             : 
     733             :     /*-------------------------------------------------------*
     734             :      * Quantization of 3 pulses with 3*N+1 bits:             *
     735             :      *-------------------------------------------------------*/
     736             : 
     737           0 :     logic16();
     738           0 :     logic16();
     739           0 :     logic16();
     740           0 :     logic16();
     741           0 :     IF( ( ( pos1 ^ pos2 ) & nb_pos ) == 0 )
     742             :     {
     743           0 :         index = quant_2p_2N1_fx( pos1, pos2, sub( N, 1 ) ); /* index = quant_2p_2N1_fx(pos1, pos2, (N-1)); */
     744             :         /* index += (pos1 & nb_pos) << N; */
     745           0 :         index = add( index, shl( (Word16) ( pos1 & nb_pos ), N ) );
     746           0 :         logic16();
     747             :         /* index += quant_1p_N1_fx(pos3, N) << (2*N); */
     748           0 :         index = add( index, shl( quant_1p_N1_fx( pos3, N ), shl( N, 1 ) ) );
     749             :     }
     750           0 :     ELSE IF( ( ( pos1 ^ pos3 ) & nb_pos ) == 0 )
     751             :     {
     752           0 :         index = quant_2p_2N1_fx( pos1, pos3, sub( N, 1 ) ); /* index = quant_2p_2N1_fx(pos1, pos3, (N-1)); */
     753           0 :         index = add( index, shl( (Word16) ( pos1 & nb_pos ), N ) );
     754           0 :         logic16();
     755             :         /* index += (pos1 & nb_pos) << N; */
     756           0 :         index = add( index, shl( quant_1p_N1_fx( pos2, N ), shl( N, 1 ) ) );
     757             :         /* index += quant_1p_N1_fx(pos2, N) <<
     758             :          * (2*N); */
     759             :     }
     760             :     ELSE
     761             :     {
     762           0 :         index = quant_2p_2N1_fx( pos2, pos3, sub( N, 1 ) ); /* index = quant_2p_2N1_fx(pos2, pos3, (N-1)); */
     763             :         /* index += (pos2 & nb_pos) << N;                      */
     764           0 :         index = add( index, shl( (Word16) ( pos2 & nb_pos ), N ) );
     765           0 :         logic16();
     766             :         /* index += quant_1p_N1_fx(pos1, N) << (2*N);      */
     767           0 :         index = add( index, shl( quant_1p_N1_fx( pos1, N ), shl( N, 1 ) ) );
     768             :     }
     769           0 :     return ( index );
     770             : }
     771             : 
     772             : 
     773             : /*---------------------------------------------------------------------*
     774             :  * Quantization of 4 pulses with 4*N+1 bits:                           *
     775             :  *---------------------------------------------------------------------*/
     776             : 
     777             : /*  o  : return (4*N)+1 bits         */
     778           0 : static Word32 quant_4p_4N1_fx(
     779             :     const Word16 pos1, /*  i  : position of the pulse 1     */
     780             :     const Word16 pos2, /*  i  : position of the pulse 2     */
     781             :     const Word16 pos3, /*  i  : position of the pulse 3     */
     782             :     const Word16 pos4, /*  i  : position of the pulse 4     */
     783             :     const Word16 N     /*  i  : number of bits for position */
     784             : )
     785             : {
     786             :     Word16 nb_pos;
     787             :     Word32 index;
     788             : 
     789           0 :     nb_pos = shl( 1, sub( N, 1 ) ); /* nb_pos = (1<<(N-1));  */
     790             : 
     791             :     /*-------------------------------------------------------*
     792             :      * Quantization of 4 pulses with 4*N+1 bits:             *
     793             :      *-------------------------------------------------------*/
     794             : 
     795           0 :     logic16();
     796           0 :     logic16();
     797           0 :     logic16();
     798           0 :     logic16();
     799           0 :     IF( ( ( pos1 ^ pos2 ) & nb_pos ) == 0 )
     800             :     {
     801           0 :         index = quant_2p_2N1_fx( pos1, pos2, sub( N, 1 ) ); /* index = quant_2p_2N1_fx(pos1, pos2, (N-1)); */
     802             :         /* index += (pos1 & nb_pos) << N;      */
     803           0 :         index = L_add( index, L_shl( L_deposit_l( (Word16) ( pos1 & nb_pos ) ), N ) );
     804           0 :         logic16();
     805             :         /* index += quant_2p_2N1_fx(pos3, pos4, N) << (2*N); */
     806           0 :         index = L_add( index, L_shl( quant_2p_2N1_fx( pos3, pos4, N ), shl( N, 1 ) ) );
     807             :     }
     808           0 :     ELSE IF( ( ( pos1 ^ pos3 ) & nb_pos ) == 0 )
     809             :     {
     810           0 :         index = quant_2p_2N1_fx( pos1, pos3, sub( N, 1 ) );
     811             :         /* index += (pos1 & nb_pos) << N; */
     812           0 :         index = L_add( index, L_shl( L_deposit_l( (Word16) ( pos1 & nb_pos ) ), N ) );
     813           0 :         logic16();
     814             :         /* index += quant_2p_2N1_fx(pos2, pos4, N) << (2*N); */
     815           0 :         index = L_add( index, L_shl( quant_2p_2N1_fx( pos2, pos4, N ), shl( N, 1 ) ) );
     816             :     }
     817             :     ELSE
     818             :     {
     819           0 :         index = quant_2p_2N1_fx( pos2, pos3, sub( N, 1 ) );
     820             :         /* index += (pos2 & nb_pos) << N; */
     821           0 :         index = L_add( index, L_shl( L_deposit_l( (Word16) ( pos2 & nb_pos ) ), N ) );
     822           0 :         logic16();
     823             :         /* index += quant_2p_2N1_fx(pos1, pos4, N) << (2*N); */
     824           0 :         index = L_add( index, L_shl( quant_2p_2N1_fx( pos1, pos4, N ), shl( N, 1 ) ) );
     825             :     }
     826             : 
     827           0 :     return ( index );
     828             : }
     829             : 
     830             : 
     831             : /*---------------------------------------------------------------------*
     832             :  * Quantization of 4 pulses with 4*N bits:                             *
     833             :  *---------------------------------------------------------------------*/
     834             : 
     835             : /*  o  : return 4*N bits             */
     836           0 : static Word32 quant_4p_4N_fx(
     837             :     const Word16 pos[], /*  i  : position of the pulse 1..4  */
     838             :     const Word16 N      /*  i  : number of bits for position */
     839             : )
     840             : {
     841             :     Word16 i, j, k, nb_pos, n_1, tmp;
     842             :     Word16 posA[4], posB[4];
     843             :     Word32 index;
     844             : 
     845           0 :     n_1 = sub( N, 1 );
     846           0 :     move16();
     847           0 :     nb_pos = shl( 1, n_1 ); /* nb_pos = (1<<n_1); */
     848             : 
     849           0 :     i = 0;
     850           0 :     move16();
     851           0 :     j = 0;
     852           0 :     move16();
     853           0 :     FOR( k = 0; k < 4; k++ )
     854             :     {
     855           0 :         logic16();
     856           0 :         IF( ( pos[k] & nb_pos ) == 0 )
     857             :         {
     858           0 :             posA[i++] = pos[k];
     859           0 :             move16();
     860             :         }
     861             :         ELSE
     862             :         {
     863           0 :             posB[j++] = pos[k];
     864           0 :             move16();
     865             :         }
     866             :     }
     867             : 
     868           0 :     SWITCH( i )
     869             :     {
     870           0 :         case 0:
     871           0 :             tmp = sub( shl( N, 2 ), 3 ); /* index = 1 << ((4*N)-3); */
     872           0 :             index = L_shl( 1L, tmp );
     873             :             /* index += quant_4p_4N1_fx(posB[0], posB[1], posB[2], posB[3], n_1); */
     874           0 :             index = L_add( index, quant_4p_4N1_fx( posB[0], posB[1], posB[2], posB[3], n_1 ) );
     875           0 :             BREAK;
     876           0 :         case 1:
     877             :             /* index = quant_1p_N1_fx(posA[0], n_1) << ((3*n_1)+1); */
     878           0 :             tmp = add( extract_l( L_shr( L_mult( 3, n_1 ), 1 ) ), 1 );
     879           0 :             index = L_shl( quant_1p_N1_fx( posA[0], n_1 ), tmp );
     880             :             /* index += quant_3p_3N1_fx(posB[0], posB[1], posB[2], n_1); */
     881           0 :             index = L_add( index, quant_3p_3N1_fx( posB[0], posB[1], posB[2], n_1 ) );
     882           0 :             BREAK;
     883           0 :         case 2:
     884           0 :             tmp = add( shl( n_1, 1 ), 1 ); /* index = quant_2p_2N1_fx(posA[0], posA[1], n_1) << ((2*n_1)+1); */
     885           0 :             index = L_shl( quant_2p_2N1_fx( posA[0], posA[1], n_1 ), tmp );
     886             :             /* index += quant_2p_2N1_fx(posB[0], posB[1], n_1); */
     887           0 :             index = L_add( index, quant_2p_2N1_fx( posB[0], posB[1], n_1 ) );
     888           0 :             BREAK;
     889           0 :         case 3:
     890             :             /* index = quant_3p_3N1_fx(posA[0], posA[1], posA[2], n_1) << N; */
     891           0 :             index = L_shl( quant_3p_3N1_fx( posA[0], posA[1], posA[2], n_1 ), N );
     892           0 :             index = L_add( index, quant_1p_N1_fx( posB[0], n_1 ) ); /* index += quant_1p_N1_fx(posB[0], n_1); */
     893           0 :             BREAK;
     894           0 :         case 4:
     895           0 :             index = quant_4p_4N1_fx( posA[0], posA[1], posA[2], posA[3], n_1 );
     896           0 :             BREAK;
     897           0 :         default:
     898           0 :             index = 0;
     899           0 :             move32();
     900           0 :             fprintf( stderr, "Error in function quant_4p_4N_fx\n" );
     901             :     }
     902           0 :     tmp = sub( shl( N, 2 ), 2 ); /* index += (i & 3) << ((4*N)-2); */
     903           0 :     index = L_add( index, L_shl( ( L_deposit_l( i ) & ( 3L ) ), tmp ) );
     904           0 :     logic16();
     905             : 
     906           0 :     return ( index );
     907             : }
     908             : 
     909             : 
     910             : /*  o  : return 5*N bits             */
     911           0 : static Word32 quant_5p_5N_fx(
     912             :     const Word16 pos[], /*  i  : position of the pulse 1..5  */
     913             :     const Word16 N )    /*  i  : number of bits for position */
     914             : {
     915             :     Word16 i, j, k, nb_pos, n_1, tmp;
     916             :     Word16 posA[5], posB[5];
     917             :     Word32 index, tmp2;
     918             : 
     919           0 :     n_1 = sub( N, 1 );
     920           0 :     nb_pos = shl( 1, n_1 ); /* nb_pos = (1<<n_1); */
     921             : 
     922           0 :     i = 0;
     923           0 :     move16();
     924           0 :     j = 0;
     925           0 :     move16();
     926           0 :     FOR( k = 0; k < 5; k++ )
     927             :     {
     928           0 :         logic16();
     929           0 :         IF( ( pos[k] & nb_pos ) == 0 )
     930             :         {
     931           0 :             posA[i++] = pos[k];
     932           0 :             move16();
     933             :         }
     934             :         ELSE
     935             :         {
     936           0 :             posB[j++] = pos[k];
     937           0 :             move16();
     938             :         }
     939             :     }
     940             : 
     941           0 :     SWITCH( i )
     942             :     {
     943           0 :         case 0:
     944           0 :             tmp = sub( extract_l( L_shr( L_mult( 5, N ), 1 ) ), 1 ); /* ((5*N)-1)) */
     945           0 :             index = L_shl( 1L, tmp );                                /* index = 1 << ((5*N)-1); */
     946           0 :             tmp = add( shl( N, 1 ), 1 );                             /* index += quant_3p_3N1_fx(posB[0], posB[1], posB[2], n_1) << ((2*N)+1);*/
     947           0 :             tmp2 = L_shl( quant_3p_3N1_fx( posB[0], posB[1], posB[2], n_1 ), tmp );
     948           0 :             index = L_add( index, tmp2 );
     949           0 :             index = L_add( index, quant_2p_2N1_fx( posB[3], posB[4], N ) ); /* index += quant_2p_2N1_fx(posB[3], posB[4], N); */
     950           0 :             BREAK;
     951           0 :         case 1:
     952           0 :             tmp = sub( extract_l( L_shr( L_mult( 5, N ), 1 ) ), 1 ); /* index = 1 << ((5*N)-1); */
     953           0 :             index = L_shl( 1L, tmp );
     954           0 :             tmp = add( shl( N, 1 ), 1 ); /* index += quant_3p_3N1_fx(posB[0], posB[1], posB[2], n_1) <<((2*N)+1);  */
     955           0 :             tmp2 = L_shl( quant_3p_3N1_fx( posB[0], posB[1], posB[2], n_1 ), tmp );
     956           0 :             index = L_add( index, tmp2 );
     957           0 :             index = L_add( index, quant_2p_2N1_fx( posB[3], posA[0], N ) ); /* index += quant_2p_2N1_fx(posB[3], posA[0], N); */
     958           0 :             BREAK;
     959           0 :         case 2:
     960           0 :             tmp = sub( extract_l( L_shr( L_mult( 5, N ), 1 ) ), 1 ); /* ((5*N)-1)) */
     961           0 :             index = L_shl( 1L, tmp );                                /* index = 1 << ((5*N)-1); */
     962           0 :             tmp = add( shl( N, 1 ), 1 );                             /* index += quant_3p_3N1_fx(posB[0], posB[1], posB[2], n_1) << ((2*N)+1);  */
     963           0 :             tmp2 = L_shl( quant_3p_3N1_fx( posB[0], posB[1], posB[2], n_1 ), tmp );
     964           0 :             index = L_add( index, tmp2 );
     965           0 :             index = L_add( index, quant_2p_2N1_fx( posA[0], posA[1], N ) ); /* index += quant_2p_2N1_fx(posA[0], posA[1], N); */
     966           0 :             BREAK;
     967           0 :         case 3:
     968           0 :             tmp = add( shl( N, 1 ), 1 ); /* index = quant_3p_3N1_fx(posA[0], posA[1], posA[2], n_1) << ((2*N)+1);  */
     969           0 :             index = L_shl( quant_3p_3N1_fx( posA[0], posA[1], posA[2], n_1 ), tmp );
     970           0 :             index = L_add( index, quant_2p_2N1_fx( posB[0], posB[1], N ) ); /* index += quant_2p_2N1_fx(posB[0], posB[1], N); */
     971           0 :             BREAK;
     972           0 :         case 4:
     973           0 :             tmp = add( shl( N, 1 ), 1 ); /* index = quant_3p_3N1_fx(posA[0], posA[1], posA[2], n_1) << ((2*N)+1);  */
     974           0 :             index = L_shl( quant_3p_3N1_fx( posA[0], posA[1], posA[2], n_1 ), tmp );
     975           0 :             index = L_add( index, quant_2p_2N1_fx( posA[3], posB[0], N ) ); /* index += quant_2p_2N1_fx(posA[3], posB[0], N); */
     976           0 :             BREAK;
     977           0 :         case 5:
     978           0 :             tmp = add( shl( N, 1 ), 1 ); /* index = quant_3p_3N1_fx(posA[0], posA[1], posA[2], n_1) << ((2*N)+1);  */
     979           0 :             index = L_shl( quant_3p_3N1_fx( posA[0], posA[1], posA[2], n_1 ), tmp );
     980           0 :             index = L_add( index, quant_2p_2N1_fx( posA[3], posA[4], N ) ); /* index += quant_2p_2N1_fx(posA[3], posA[4], N); */
     981           0 :             BREAK;
     982           0 :         default:
     983           0 :             index = 0;
     984           0 :             move32();
     985           0 :             fprintf( stderr, "Error in function quant_5p_5N_fx\n" );
     986             :     }
     987             : 
     988           0 :     return ( index );
     989             : }
     990             : 
     991             : 
     992             : /*  o  : return (6*N)-2 bits         */
     993           0 : static Word32 quant_6p_6N_2_fx(
     994             :     const Word16 pos[], /*  i  : position of the pulse 1..6  */
     995             :     const Word16 N )    /*  i  : number of bits for position */
     996             : {
     997             :     Word16 i, j, k, nb_pos, n_1;
     998             :     Word16 posA[6], posB[6];
     999             :     Word32 index;
    1000             : 
    1001             :     /* !!  N and n_1 are constants -> it doesn't need to be operated by Basic Operators */
    1002             : 
    1003           0 :     n_1 = sub( N, 1 );
    1004           0 :     nb_pos = shl( 1, n_1 ); /* nb_pos = (1<<n_1); */
    1005             : 
    1006           0 :     i = 0;
    1007           0 :     move16();
    1008           0 :     j = 0;
    1009           0 :     move16();
    1010           0 :     FOR( k = 0; k < 6; k++ )
    1011             :     {
    1012           0 :         logic16();
    1013           0 :         IF( ( pos[k] & nb_pos ) == 0 )
    1014             :         {
    1015           0 :             posA[i++] = pos[k];
    1016           0 :             move16();
    1017             :         }
    1018             :         ELSE
    1019             :         {
    1020           0 :             posB[j++] = pos[k];
    1021           0 :             move16();
    1022             :         }
    1023             :     }
    1024             : 
    1025           0 :     SWITCH( i )
    1026             :     {
    1027           0 :         case 0:
    1028           0 :             index = L_shl( 1L, sub( i_mult( 6, N ), 5 ) );                   /* index = 1 << ((6*N)-5); */
    1029           0 :             index = L_add( index, L_shl( quant_5p_5N_fx( posB, n_1 ), N ) ); /* index += quant_5p_5N_fx(posB, n_1) << N; */
    1030           0 :             index = L_add( index, quant_1p_N1_fx( posB[5], n_1 ) );          /* index += quant_1p_N1_fx(posB[5], n_1); */
    1031           0 :             BREAK;
    1032           0 :         case 1:
    1033           0 :             index = L_shl( 1L, sub( i_mult( 6, N ), 5 ) );                   /* index = 1 << ((6*N)-5); */
    1034           0 :             index = L_add( index, L_shl( quant_5p_5N_fx( posB, n_1 ), N ) ); /* index += quant_5p_5N_fx(posB, n_1) << N; */
    1035           0 :             index = L_add( index, quant_1p_N1_fx( posA[0], n_1 ) );          /* index += quant_1p_N1_fx(posA[0], n_1); */
    1036           0 :             BREAK;
    1037           0 :         case 2:
    1038           0 :             index = L_shl( 1L, sub( i_mult( 6, N ), 5 ) ); /* index = 1 << ((6*N)-5); */
    1039             :             /* index += quant_4p_4N_fx(posB, n_1) << ((2*n_1)+1); */
    1040           0 :             index = L_add( index, L_shl( quant_4p_4N_fx( posB, n_1 ), ( add( shl( n_1, 1 ), 1 ) ) ) );
    1041           0 :             index = L_add( index, quant_2p_2N1_fx( posA[0], posA[1], n_1 ) ); /* index += quant_2p_2N1_fx(posA[0], posA[1], n_1); */
    1042           0 :             BREAK;
    1043           0 :         case 3:
    1044           0 :             index = L_shl( quant_3p_3N1_fx( posA[0], posA[1], posA[2], n_1 ), ( add( i_mult( 3, n_1 ), 1 ) ) ); /* index = quant_3p_3N1_fx(posA[0], posA[1], posA[2], n_1) << ((3*n_1)+1); */
    1045           0 :             index = L_add( index, quant_3p_3N1_fx( posB[0], posB[1], posB[2], n_1 ) );                          /* index += quant_3p_3N1_fx(posB[0], posB[1], posB[2], n_1); */
    1046           0 :             BREAK;
    1047           0 :         case 4:
    1048           0 :             i = 2;
    1049           0 :             move16();
    1050           0 :             index = L_shl( quant_4p_4N_fx( posA, n_1 ), ( add( shl( n_1, 1 ), 1 ) ) ); /* index = quant_4p_4N_fx(posA, n_1) << ((2*n_1)+1); */
    1051           0 :             index = L_add( index, quant_2p_2N1_fx( posB[0], posB[1], n_1 ) );          /* index += quant_2p_2N1_fx(posB[0], posB[1], n_1); */
    1052           0 :             BREAK;
    1053           0 :         case 5:
    1054           0 :             i = 1;
    1055           0 :             move16();
    1056           0 :             index = L_shl( quant_5p_5N_fx( posA, n_1 ), N );        /* index = quant_5p_5N_fx(posA, n_1) << N; */
    1057           0 :             index = L_add( index, quant_1p_N1_fx( posB[0], n_1 ) ); /* index += quant_1p_N1_fx(posB[0], n_1); */
    1058           0 :             BREAK;
    1059           0 :         case 6:
    1060           0 :             i = 0;
    1061           0 :             move16();
    1062           0 :             index = L_shl( quant_5p_5N_fx( posA, n_1 ), N );        /* index = quant_5p_5N_fx(posA, n_1) << N; */
    1063           0 :             index = L_add( index, quant_1p_N1_fx( posA[5], n_1 ) ); /* index += quant_1p_N1_fx(posA[5], n_1); */
    1064           0 :             BREAK;
    1065           0 :         default:
    1066           0 :             index = 0;
    1067           0 :             fprintf( stderr, "Error in function quant_6p_6N_2_fx\n" );
    1068             :     }
    1069           0 :     index = L_add( index, L_shl( ( L_deposit_l( i ) & 3L ), sub( i_mult( 6, N ), 4 ) ) );
    1070           0 :     logic16(); /* index += (i & 3) << ((6*N)-4); */
    1071             : 
    1072           0 :     return ( index );
    1073             : }
    1074             : 
    1075             : 
    1076             : /*---------------------------------------------------------------------*
    1077             :  *order the pulse position                                             *
    1078             :  *---------------------------------------------------------------------*/
    1079             : 
    1080             : /* o:   return sign value of pulse on a track              */
    1081       67412 : static Word32 pre_process_fx(
    1082             :     const Word16 v[],        /* i  : the pulse vector                  Q9                 */
    1083             :     Word16 pos_vector[],     /* o  : position of the pulse on a track                     */
    1084             :     Word32 pos_vector_num[], /* o  : the pulse number on the position which have pulse Q0 */
    1085             :     Word32 *pulse_pos_num    /* i  : the number of position which have pulse              */
    1086             : )
    1087             : {
    1088             :     Word16 j, k;
    1089             :     Word32 sign;
    1090             : 
    1091       67412 :     sign = L_deposit_l( 0 );
    1092       67412 :     j = 0;
    1093       67412 :     move16();
    1094     1146004 :     FOR( k = 0; k < 64; k += 4 ){
    1095     1078592 :         IF( v[k] ){
    1096      194445 :             pos_vector[j] = shr( k, 2 );
    1097      194445 :     move16();
    1098      194445 :     pos_vector_num[j] = L_shr( abs_s( v[k] ), 9 ); /* Q9: 512 -> 1, Q0 */
    1099      194445 :     move32();
    1100      194445 :     IF( v[k] > 0 )
    1101             :     {
    1102       97065 :         sign = L_shl( sign, 1 );
    1103             :     }
    1104             :     ELSE
    1105             :     {
    1106       97380 :         sign = L_add( L_shl( sign, 1 ), 1 );
    1107             :     }
    1108      194445 :     j = add( j, 1 );
    1109             : }
    1110             : }
    1111       67412 : *pulse_pos_num = L_deposit_l( j );
    1112       67412 : move32();
    1113             : 
    1114       67412 : return sign;
    1115             : }
    1116             : 
    1117             : 
    1118             : /*--------------------------------------------------------------------------*
    1119             :  * E_ACELP_code43bit_fx
    1120             :  *
    1121             :  * Fixed bit-length arithmetic coding of pulses
    1122             :  * v - (input) pulse vector
    1123             :  * s - (output) encoded state
    1124             :  * n - (output) range of possible states (0...n-1)
    1125             :  * p - (output) number of pulses found
    1126             :  * len - (input) length of pulse vector
    1127             :  * trackstep - (input) step between tracks
    1128             :  *--------------------------------------------------------------------------*/
    1129             : 
    1130       33706 : Word16 E_ACELP_code43bit_fx(
    1131             :     const Word16 code[], /*Q9*/
    1132             :     UWord32 *ps,
    1133             :     Word16 *p,
    1134             :     UWord16 idxs[] )
    1135             : {
    1136             :     Word16 i, j, k, track;
    1137             :     Word16 ind[32];
    1138             : 
    1139             :     Word16 tmp;
    1140             :     Word32 L_tmp;
    1141             :     Word32 joint_index;
    1142             :     static const Word32 joint_offset = 3611648; /*offset for 3 pulses per track*/
    1143       33706 :     move32();
    1144       33706 :     Word16 saved_bits = 0;
    1145       33706 :     move16();
    1146      101118 :     FOR( track = 0; track < 2; track++ )
    1147             :     {
    1148       67412 :         ps[track] = fcb_encode_PI_fx( code + track, 3 );
    1149       67412 :         move32();
    1150       67412 :         p[track] = 3;
    1151       67412 :         move16();
    1152             :     }
    1153             : 
    1154      101118 :     FOR( track = 2; track < NB_TRACK_FCB_4T; track++ )
    1155             :     {
    1156       67412 :         i = j = i_mult2( track, NPMAXPT );
    1157             : 
    1158     1124993 :         FOR( k = track; k < 64; k += 4 )
    1159             :         {
    1160     1060252 :             IF( code[k] )
    1161             :             {
    1162      132153 :                 tmp = shr( k, 2 );
    1163      132153 :                 IF( code[k] < 0 )
    1164             :                 {
    1165       66556 :                     tmp = add( tmp, 16 );
    1166             :                 }
    1167      132153 :                 ind[j] = tmp;
    1168      132153 :                 move16();
    1169      132153 :                 IF( GT_16( abs_s( code[k] ), 512 /*Q9*/ ) )
    1170             :                 {
    1171        2671 :                     ind[j + 1] = tmp;
    1172        2671 :                     move16();
    1173        2671 :                     BREAK;
    1174             :                 }
    1175      129482 :                 j = add( j, 1 );
    1176             :             }
    1177             :         }
    1178       67412 :         ps[track] = quant_2p_2N1_fx( ind[i], ind[i + 1], 4 );
    1179       67412 :         move32();
    1180       67412 :         p[track] = 2;
    1181       67412 :         move16();
    1182             :     }
    1183             :     /* joint_index = ps[0]*5472 + ps[1]; */
    1184       33706 :     L_tmp = L_shl( ps[0], 12 );
    1185       33706 :     L_tmp = L_add( L_tmp, L_shl( ps[0], 10 ) );
    1186       33706 :     L_tmp = L_add( L_tmp, L_shl( ps[0], 8 ) );
    1187       33706 :     L_tmp = L_add( L_tmp, L_shl( ps[0], 6 ) );
    1188       33706 :     L_tmp = L_add( L_tmp, L_shl( ps[0], 5 ) );
    1189       33706 :     joint_index = L_add( L_tmp, ps[1] );
    1190       33706 :     L_tmp = L_sub( joint_index, joint_offset );
    1191       33706 :     if ( L_tmp >= 0 )
    1192             :     {
    1193       28309 :         joint_index = L_add( joint_index, joint_offset );
    1194             :     }
    1195       33706 :     if ( L_tmp < 0 )
    1196             :     {
    1197        5397 :         saved_bits = add( saved_bits, 1 );
    1198             :     }
    1199       33706 :     idxs[0] = extract_l( L_add( L_shl( ps[2], 9 ), ps[3] ) );
    1200       33706 :     idxs[1] = extract_l( L_add( L_shl( joint_index, 2 ), L_shr( ps[2], 7 ) ) );
    1201       33706 :     idxs[2] = extract_l( L_shr( joint_index, 14 ) );
    1202       33706 :     move16();
    1203       33706 :     move16();
    1204       33706 :     move16();
    1205       33706 :     return saved_bits;
    1206             : }

Generated by: LCOV version 1.14