Logo Search packages:      
Sourcecode: randomsound version File versions  Download package

int bitbuffer_add_bits ( BitBuffer  buf,
const BitField  bits,
int  count 
)

Store some bits into a buffer.

Store count of bits out of bits into buf.

This routine works least-significant-bit first so if you are only storing one bit, make sure it's in bit zero of the BitField.

Parameters:
buf The BitBuffer to add to.
bits The BitField to find the bits in.
count The number of bits to add to buf.
Returns:
The number of bits actually added.

Definition at line 57 of file bitbuffer.c.

{
  int bits_to_add = MIN(MIN(8, count), bitbuffer_free_space(buf));
  int i;
  for (i = 0; i < bits_to_add; ++i) {
    BitField subfield = buf->bits[BYTE_FOR_BIT(buf->nextfree)];
    if (bits & (1<<SHIFT_FOR_BIT(i)))
      subfield |= (1<<SHIFT_FOR_BIT(buf->nextfree));
    else
      subfield &= ~(1<<SHIFT_FOR_BIT(buf->nextfree));
    buf->bits[BYTE_FOR_BIT(buf->nextfree++)] = subfield;
    if (buf->nextfree == buf->size)
      buf->nextfree = 0;
  }
  buf->bitsused += bits_to_add;
  return bits_to_add;
}


Generated by  Doxygen 1.6.0   Back to index