Lines Matching refs:bits

48 EXPORT void speex_bits_init(SpeexBits *bits)  in speex_bits_init()  argument
50 bits->chars = (char*)speex_alloc(MAX_CHARS_PER_FRAME); in speex_bits_init()
51 if (!bits->chars) in speex_bits_init()
54 bits->buf_size = MAX_CHARS_PER_FRAME; in speex_bits_init()
56 bits->owner=1; in speex_bits_init()
58 speex_bits_reset(bits); in speex_bits_init()
61 EXPORT void speex_bits_init_buffer(SpeexBits *bits, void *buff, int buf_size) in speex_bits_init_buffer() argument
63 bits->chars = (char*)buff; in speex_bits_init_buffer()
64 bits->buf_size = buf_size; in speex_bits_init_buffer()
66 bits->owner=0; in speex_bits_init_buffer()
68 speex_bits_reset(bits); in speex_bits_init_buffer()
71 EXPORT void speex_bits_set_bit_buffer(SpeexBits *bits, void *buff, int buf_size) in speex_bits_set_bit_buffer() argument
73 bits->chars = (char*)buff; in speex_bits_set_bit_buffer()
74 bits->buf_size = buf_size; in speex_bits_set_bit_buffer()
76 bits->owner=0; in speex_bits_set_bit_buffer()
78 bits->nbBits=buf_size<<LOG2_BITS_PER_CHAR; in speex_bits_set_bit_buffer()
79 bits->charPtr=0; in speex_bits_set_bit_buffer()
80 bits->bitPtr=0; in speex_bits_set_bit_buffer()
81 bits->overflow=0; in speex_bits_set_bit_buffer()
85 EXPORT void speex_bits_destroy(SpeexBits *bits) in speex_bits_destroy() argument
87 if (bits->owner) in speex_bits_destroy()
88 speex_free(bits->chars); in speex_bits_destroy()
92 EXPORT void speex_bits_reset(SpeexBits *bits) in speex_bits_reset() argument
95 bits->chars[0]=0; in speex_bits_reset()
96 bits->nbBits=0; in speex_bits_reset()
97 bits->charPtr=0; in speex_bits_reset()
98 bits->bitPtr=0; in speex_bits_reset()
99 bits->overflow=0; in speex_bits_reset()
102 EXPORT void speex_bits_rewind(SpeexBits *bits) in speex_bits_rewind() argument
104 bits->charPtr=0; in speex_bits_rewind()
105 bits->bitPtr=0; in speex_bits_rewind()
106 bits->overflow=0; in speex_bits_rewind()
109 EXPORT void speex_bits_read_from(SpeexBits *bits, char *chars, int len) in speex_bits_read_from() argument
113 if (nchars > bits->buf_size) in speex_bits_read_from()
116 if (bits->owner) in speex_bits_read_from()
118 char *tmp = (char*)speex_realloc(bits->chars, nchars); in speex_bits_read_from()
121 bits->buf_size=nchars; in speex_bits_read_from()
122 bits->chars=tmp; in speex_bits_read_from()
124 nchars=bits->buf_size; in speex_bits_read_from()
129 nchars=bits->buf_size; in speex_bits_read_from()
139 bits->chars[i]=HTOLS(chars[i]); in speex_bits_read_from()
141 bits->nbBits=nchars<<LOG2_BITS_PER_CHAR; in speex_bits_read_from()
142 bits->charPtr=0; in speex_bits_read_from()
143 bits->bitPtr=0; in speex_bits_read_from()
144 bits->overflow=0; in speex_bits_read_from()
147 static void speex_bits_flush(SpeexBits *bits) in speex_bits_flush() argument
149 int nchars = ((bits->nbBits+BITS_PER_CHAR-1)>>LOG2_BITS_PER_CHAR); in speex_bits_flush()
150 if (bits->charPtr>0) in speex_bits_flush()
151 SPEEX_MOVE(bits->chars, &bits->chars[bits->charPtr], nchars-bits->charPtr); in speex_bits_flush()
152 bits->nbBits -= bits->charPtr<<LOG2_BITS_PER_CHAR; in speex_bits_flush()
153 bits->charPtr=0; in speex_bits_flush()
156 EXPORT void speex_bits_read_whole_bytes(SpeexBits *bits, char *chars, int nbytes) in speex_bits_read_whole_bytes() argument
161 if (((bits->nbBits+BITS_PER_CHAR-1)>>LOG2_BITS_PER_CHAR)+nchars > bits->buf_size) in speex_bits_read_whole_bytes()
164 if (bits->owner) in speex_bits_read_whole_bytes()
166 char *tmp = (char*)speex_realloc(bits->chars, (bits->nbBits>>LOG2_BITS_PER_CHAR)+nchars+1); in speex_bits_read_whole_bytes()
169 bits->buf_size=(bits->nbBits>>LOG2_BITS_PER_CHAR)+nchars+1; in speex_bits_read_whole_bytes()
170 bits->chars=tmp; in speex_bits_read_whole_bytes()
172 nchars=bits->buf_size-(bits->nbBits>>LOG2_BITS_PER_CHAR)-1; in speex_bits_read_whole_bytes()
177 nchars=bits->buf_size; in speex_bits_read_whole_bytes()
181 speex_bits_flush(bits); in speex_bits_read_whole_bytes()
182 pos=bits->nbBits>>LOG2_BITS_PER_CHAR; in speex_bits_read_whole_bytes()
184 bits->chars[pos+i]=HTOLS(chars[i]); in speex_bits_read_whole_bytes()
185 bits->nbBits+=nchars<<LOG2_BITS_PER_CHAR; in speex_bits_read_whole_bytes()
188 EXPORT int speex_bits_write(SpeexBits *bits, char *chars, int max_nbytes) in speex_bits_write() argument
195 bitPtr=bits->bitPtr; in speex_bits_write()
196 charPtr=bits->charPtr; in speex_bits_write()
197 nbBits=bits->nbBits; in speex_bits_write()
198 speex_bits_insert_terminator(bits); in speex_bits_write()
199 bits->bitPtr=bitPtr; in speex_bits_write()
200 bits->charPtr=charPtr; in speex_bits_write()
201 bits->nbBits=nbBits; in speex_bits_write()
203 if (max_nchars > ((bits->nbBits+BITS_PER_CHAR-1)>>LOG2_BITS_PER_CHAR)) in speex_bits_write()
204 max_nchars = ((bits->nbBits+BITS_PER_CHAR-1)>>LOG2_BITS_PER_CHAR); in speex_bits_write()
207 chars[i]=HTOLS(bits->chars[i]); in speex_bits_write()
211 EXPORT int speex_bits_write_whole_bytes(SpeexBits *bits, char *chars, int max_nbytes) in speex_bits_write_whole_bytes() argument
215 if (max_nchars > ((bits->nbBits)>>LOG2_BITS_PER_CHAR)) in speex_bits_write_whole_bytes()
216 max_nchars = ((bits->nbBits)>>LOG2_BITS_PER_CHAR); in speex_bits_write_whole_bytes()
218 chars[i]=HTOLS(bits->chars[i]); in speex_bits_write_whole_bytes()
220 if (bits->bitPtr>0) in speex_bits_write_whole_bytes()
221 bits->chars[0]=bits->chars[max_nchars]; in speex_bits_write_whole_bytes()
223 bits->chars[0]=0; in speex_bits_write_whole_bytes()
224 bits->charPtr=0; in speex_bits_write_whole_bytes()
225 bits->nbBits &= (BITS_PER_CHAR-1); in speex_bits_write_whole_bytes()
229 EXPORT void speex_bits_pack(SpeexBits *bits, int data, int nbBits) in speex_bits_pack() argument
233 if (bits->charPtr+((nbBits+bits->bitPtr)>>LOG2_BITS_PER_CHAR) >= bits->buf_size) in speex_bits_pack()
236 if (bits->owner) in speex_bits_pack()
238 int new_nchars = ((bits->buf_size+5)*3)>>1; in speex_bits_pack()
239 char *tmp = (char*)speex_realloc(bits->chars, new_nchars); in speex_bits_pack()
242 bits->buf_size=new_nchars; in speex_bits_pack()
243 bits->chars=tmp; in speex_bits_pack()
258 bits->chars[bits->charPtr] |= bit<<(BITS_PER_CHAR-1-bits->bitPtr); in speex_bits_pack()
259 bits->bitPtr++; in speex_bits_pack()
261 if (bits->bitPtr==BITS_PER_CHAR) in speex_bits_pack()
263 bits->bitPtr=0; in speex_bits_pack()
264 bits->charPtr++; in speex_bits_pack()
265 bits->chars[bits->charPtr] = 0; in speex_bits_pack()
267 bits->nbBits++; in speex_bits_pack()
272 EXPORT int speex_bits_unpack_signed(SpeexBits *bits, int nbBits) in speex_bits_unpack_signed() argument
274 unsigned int d=speex_bits_unpack_unsigned(bits,nbBits); in speex_bits_unpack_signed()
283 EXPORT unsigned int speex_bits_unpack_unsigned(SpeexBits *bits, int nbBits) in speex_bits_unpack_unsigned() argument
286 if ((bits->charPtr<<LOG2_BITS_PER_CHAR)+bits->bitPtr+nbBits>bits->nbBits) in speex_bits_unpack_unsigned()
287 bits->overflow=1; in speex_bits_unpack_unsigned()
288 if (bits->overflow) in speex_bits_unpack_unsigned()
293 d |= (bits->chars[bits->charPtr]>>(BITS_PER_CHAR-1 - bits->bitPtr))&1; in speex_bits_unpack_unsigned()
294 bits->bitPtr++; in speex_bits_unpack_unsigned()
295 if (bits->bitPtr==BITS_PER_CHAR) in speex_bits_unpack_unsigned()
297 bits->bitPtr=0; in speex_bits_unpack_unsigned()
298 bits->charPtr++; in speex_bits_unpack_unsigned()
305 EXPORT unsigned int speex_bits_peek_unsigned(SpeexBits *bits, int nbBits) in speex_bits_peek_unsigned() argument
311 if ((bits->charPtr<<LOG2_BITS_PER_CHAR)+bits->bitPtr+nbBits>bits->nbBits) in speex_bits_peek_unsigned()
312 bits->overflow=1; in speex_bits_peek_unsigned()
313 if (bits->overflow) in speex_bits_peek_unsigned()
316 bitPtr=bits->bitPtr; in speex_bits_peek_unsigned()
317 charPtr=bits->charPtr; in speex_bits_peek_unsigned()
318 chars = bits->chars; in speex_bits_peek_unsigned()
334 EXPORT int speex_bits_peek(SpeexBits *bits) in speex_bits_peek() argument
336 if ((bits->charPtr<<LOG2_BITS_PER_CHAR)+bits->bitPtr+1>bits->nbBits) in speex_bits_peek()
337 bits->overflow=1; in speex_bits_peek()
338 if (bits->overflow) in speex_bits_peek()
340 return (bits->chars[bits->charPtr]>>(BITS_PER_CHAR-1 - bits->bitPtr))&1; in speex_bits_peek()
343 EXPORT void speex_bits_advance(SpeexBits *bits, int n) in speex_bits_advance() argument
345 if (((bits->charPtr<<LOG2_BITS_PER_CHAR)+bits->bitPtr+n>bits->nbBits) || bits->overflow){ in speex_bits_advance()
346 bits->overflow=1; in speex_bits_advance()
349 bits->charPtr += (bits->bitPtr+n) >> LOG2_BITS_PER_CHAR; /* divide by BITS_PER_CHAR */ in speex_bits_advance()
350 bits->bitPtr = (bits->bitPtr+n) & (BITS_PER_CHAR-1); /* modulo by BITS_PER_CHAR */ in speex_bits_advance()
353 EXPORT int speex_bits_remaining(SpeexBits *bits) in speex_bits_remaining() argument
355 if (bits->overflow) in speex_bits_remaining()
358 return bits->nbBits-((bits->charPtr<<LOG2_BITS_PER_CHAR)+bits->bitPtr); in speex_bits_remaining()
361 EXPORT int speex_bits_nbytes(SpeexBits *bits) in speex_bits_nbytes() argument
363 return ((bits->nbBits+BITS_PER_CHAR-1)>>LOG2_BITS_PER_CHAR); in speex_bits_nbytes()
366 EXPORT void speex_bits_insert_terminator(SpeexBits *bits) in speex_bits_insert_terminator() argument
368 if (bits->bitPtr) in speex_bits_insert_terminator()
369 speex_bits_pack(bits, 0, 1); in speex_bits_insert_terminator()
370 while (bits->bitPtr) in speex_bits_insert_terminator()
371 speex_bits_pack(bits, 1, 1); in speex_bits_insert_terminator()