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"
21
/*----------------------------------------------------------------*
22
* splitting an integer into first most significant bits and
23
* remaining least significant bits
24
*---------------------------------------------------------------*/
27
int *index, /* (i) the value to split */
28
int *firstpart, /* (o) the value specified by most
30
int *rest, /* (o) the value specified by least
37
int bitno_firstpart, /* (i) number of bits in most
39
int bitno_total /* (i) number of bits in full range
42
int bitno_rest = bitno_total-bitno_firstpart;
44
*firstpart = *index>>(bitno_rest);
45
*rest = *index-(*firstpart<<(bitno_rest));
48
/*----------------------------------------------------------------*
49
* combining a value corresponding to msb's with a value
50
* corresponding to lsb's
51
*---------------------------------------------------------------*/
54
int *index, /* (i/o) the msb value in the
56
int rest, /* (i) the lsb value */
57
int bitno_rest /* (i) the number of bits in the
60
*index = *index<<bitno_rest;
64
/*----------------------------------------------------------------*
65
* packing of bits into bitstream, i.e., vector of bytes
66
*---------------------------------------------------------------*/
69
unsigned char **bitstream, /* (i/o) on entrance pointer to
70
place in bitstream to pack
71
new data, on exit pointer
72
to place in bitstream to
74
int index, /* (i) the value to pack */
75
int bitno, /* (i) the number of bits that the
76
value will fit within */
77
int *pos /* (i/o) write position in the
82
/* Clear the bits before starting in a new byte */
95
/* Jump to the next byte if end of this byte is reached*/
105
/* Insert index into the bitstream */
107
if (bitno <= posLeft) {
108
**bitstream |= (unsigned char)(index<<(posLeft-bitno));
112
**bitstream |= (unsigned char)(index>>(bitno-posLeft));
115
index-=((index>>(bitno-posLeft))<<(bitno-posLeft));
122
/*----------------------------------------------------------------*
123
* unpacking of bits from bitstream, i.e., vector of bytes
124
*---------------------------------------------------------------*/
127
unsigned char **bitstream, /* (i/o) on entrance pointer to
128
place in bitstream to
129
unpack new data from, on
130
exit pointer to place in
131
bitstream to unpack future
133
int *index, /* (o) resulting value */
134
int bitno, /* (i) number of bits used to
135
represent the value */
136
int *pos /* (i/o) read position in the
150
/* move forward in bitstream when the end of the
160
/* Extract bits to index */
162
if (BitsLeft>=bitno) {
163
*index+=((((**bitstream)<<(*pos)) & 0xFF)>>(8-bitno));
170
*index+=((((**bitstream)<<(*pos)) & 0xFF)>>
174
*index+=(((int)(((**bitstream)<<(*pos)) & 0xFF))<<