Lines Matching full:bits
49 /* WATCHOUT: there are a few places where the code will not work unless uint32_t is >= 32 bits wide */
71 #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
75 uint32_t accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
78 unsigned bits; /* # of used bits in accum */
93 /* calculate total words needed to store 'bits_to_add' additional bits */
94 new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
108 FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
150 bw->words = bw->bits = 0;
167 bw->words = bw->bits = 0;
172 bw->words = bw->bits = 0;
182 fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
190 if(bw->bits > 0) {
192 for(j = 0; j < bw->bits; j++)
193 fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
204 FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
219 FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
231 return ((bw->bits & 7) == 0);
241 FLAC__ASSERT((bw->bits & 7) == 0);
243 if(bw->bits & 7)
245 /* if we have bits in the accumulator we have to flush those to the buffer first */
246 if(bw->bits) {
250 /* append bits as complete word to buffer, but don't change bw->accum or bw->bits */
251 bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
255 *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
267 inline FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
274 if(bits == 0)
276 /* slightly pessimistic size check but faster than "<= bw->words + (bw->bits+bits+FLAC__BITS_PER_WORD-1)/FLAC__BITS_PER_WORD" */
277 if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
280 if(bw->bits) {
281 n = flac_min(FLAC__BITS_PER_WORD - bw->bits, bits);
283 bits -= n;
284 bw->bits += n;
285 if(bw->bits == FLAC__BITS_PER_WORD) {
287 bw->bits = 0;
293 while(bits >= FLAC__BITS_PER_WORD) {
295 bits -= FLAC__BITS_PER_WORD;
298 if(bits > 0) {
300 bw->bits = bits;
305 inline FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
315 FLAC__ASSERT(bits <= 32);
316 if(bits == 0)
319 /* slightly pessimistic size check but faster than "<= bw->words + (bw->bits+bits+FLAC__BITS_PER_WORD-1)/FLAC__BITS_PER_WORD" */
320 if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
323 left = FLAC__BITS_PER_WORD - bw->bits;
324 if(bits < left) {
325 bw->accum <<= bits;
327 bw->bits += bits;
329 else if(bw->bits) { /* WATCHOUT: if bw->bits == 0, left==FLAC__BITS_PER_WORD and bw->accum<<=left is a NOP instead of setting to 0 */
331 bw->accum |= val >> (bw->bits = bits - left);
337 bw->bits = 0;
344 inline FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
346 /* zero-out unused bits */
347 if(bits < 32)
348 val &= (~(0xffffffff << bits));
350 return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
353 inline FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
356 if(bits > 32) {
358 FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
362 return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
419 unsigned bits, msbs, uval;
435 bits = 1 + k + msbs;
444 bits = 1 + q + k;
446 bits++;
448 return bits;
453 unsigned bits, msbs;
463 bits = 1 + k + msbs;
472 bits = 1 + q + k;
474 bits++;
476 return bits;
509 const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
529 if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current uint32_t */
530 /* ^^^ if bw->bits is 0 then we may have filled the buffer and have no free uint32_t to work in */
531 bw->bits = bw->bits + msbits + lsbits;
533 uval &= mask2; /* mask off unused top bits */
538 /* slightly pessimistic size check but faster than "<= bw->words + (bw->bits
540 if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 uint32_t*/ && !bitwriter_grow_(bw, msbits+lsbits))
545 if(bw->bits) {
546 left = FLAC__BITS_PER_WORD - bw->bits;
549 bw->bits += msbits;
556 bw->bits = 0;
567 bw->bits = msbits;
572 uval &= mask2; /* mask off unused top bits */
574 left = FLAC__BITS_PER_WORD - bw->bits;
578 bw->bits += lsbits;
581 /* if bw->bits == 0, left==FLAC__BITS_PER_WORD which will always
585 FLAC__ASSERT(bw->bits);
588 bw->accum |= uval >> (bw->bits = lsbits - left);
730 FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
776 FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
827 if(bw->bits & 7u)
828 return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
841 extern FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
842 extern FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
843 extern FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);