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

Generated by: LCOV version 1.14