2 /******************************************************************
4 iLBC Speech Coder ANSI-C Source Code
8 Copyright (C) The Internet Society (2004).
11 ******************************************************************/
16 #include "iLBC_define.h"
17 #include "constants.h"
22 /*----------------------------------------------------------------*
23 * splitting an integer into first most significant bits and
24 * remaining least significant bits
25 *---------------------------------------------------------------*/
28 int *index
, /* (i) the value to split */
29 int *firstpart
, /* (o) the value specified by most
31 int *rest
, /* (o) the value specified by least
33 int bitno_firstpart
, /* (i) number of bits in most
35 int bitno_total
/* (i) number of bits in full range
38 int bitno_rest
= bitno_total
-bitno_firstpart
;
42 *firstpart
= *index
>>(bitno_rest
);
43 *rest
= *index
-(*firstpart
<<(bitno_rest
));
46 /*----------------------------------------------------------------*
47 * combining a value corresponding to msb's with a value
48 * corresponding to lsb's
49 *---------------------------------------------------------------*/
52 int *index
, /* (i/o) the msb value in the
54 int rest
, /* (i) the lsb value */
55 int bitno_rest
/* (i) the number of bits in the
58 *index
= *index
<<bitno_rest
;
62 /*----------------------------------------------------------------*
63 * packing of bits into bitstream, i.e., vector of bytes
64 *---------------------------------------------------------------*/
67 unsigned char **bitstream
, /* (i/o) on entrance pointer to
68 place in bitstream to pack
69 new data, on exit pointer
70 to place in bitstream to
72 int index
, /* (i) the value to pack */
73 int bitno
, /* (i) the number of bits that the
74 value will fit within */
75 int *pos
/* (i/o) write position in the
80 /* Clear the bits before starting in a new byte */
88 /* Jump to the next byte if end of this byte is reached*/
100 /* Insert index into the bitstream */
102 if (bitno
<= posLeft
) {
103 **bitstream
|= (unsigned char)(index
<<(posLeft
-bitno
));
107 **bitstream
|= (unsigned char)(index
>>(bitno
-posLeft
));
110 index
-=((index
>>(bitno
-posLeft
))<<(bitno
-posLeft
));
117 /*----------------------------------------------------------------*
118 * unpacking of bits from bitstream, i.e., vector of bytes
119 *---------------------------------------------------------------*/
122 unsigned char **bitstream
, /* (i/o) on entrance pointer to
123 place in bitstream to
124 unpack new data from, on
125 exit pointer to place in
126 bitstream to unpack future
128 int *index
, /* (o) resulting value */
129 int bitno
, /* (i) number of bits used to
130 represent the value */
131 int *pos
/* (i/o) read position in the
140 /* move forward in bitstream when the end of the
150 /* Extract bits to index */
154 if (BitsLeft
>=bitno
) {
155 *index
+=((((**bitstream
)<<(*pos
)) & 0xFF)>>(8-bitno
));
162 *index
+=((((**bitstream
)<<(*pos
)) & 0xFF)>>
166 *index
+=(((int)(((**bitstream
)<<(*pos
)) & 0xFF))<<