spandsp 0.0.6
bitstream.c File Reference
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "spandsp/telephony.h"
#include "spandsp/bitstream.h"
#include "spandsp/private/bitstream.h"

Functions

void bitstream_put (bitstream_state_t *s, uint8_t **c, uint32_t value, int bits)
 Put a chunk of bits into the output buffer.
void bitstream_emit (bitstream_state_t *s, uint8_t **c)
 Emit any residual bits to the output buffer, without actually flushing them. This is useful for getting the buffer fully up to date, ready for things like CRC calculations, while allowing bitstream_put() to be used to continue the message later.
void bitstream_flush (bitstream_state_t *s, uint8_t **c)
 Flush any residual bits to the output buffer.
uint32_t bitstream_get (bitstream_state_t *s, const uint8_t **c, int bits)
 Get a chunk of bits from the input buffer.
bitstream_state_tbitstream_init (bitstream_state_t *s, int lsb_first)
 Initialise a bitstream context.
int bitstream_release (bitstream_state_t *s)
int bitstream_free (bitstream_state_t *s)

Function Documentation

◆ bitstream_emit()

void bitstream_emit ( bitstream_state_t * s,
uint8_t ** c )

Emit any residual bits to the output buffer, without actually flushing them. This is useful for getting the buffer fully up to date, ready for things like CRC calculations, while allowing bitstream_put() to be used to continue the message later.

Parameters
sA pointer to the bitstream context.
cA pointer to the bitstream output buffer.

References bitstream_state_s::bitstream, bitstream_state_s::lsb_first, and bitstream_state_s::residue.

Referenced by bitstream_flush().

◆ bitstream_flush()

void bitstream_flush ( bitstream_state_t * s,
uint8_t ** c )

Flush any residual bits to the output buffer.

Parameters
sA pointer to the bitstream context.
cA pointer to the bitstream output buffer.

References bitstream_state_s::bitstream, bitstream_emit(), and bitstream_state_s::residue.

◆ bitstream_get()

uint32_t bitstream_get ( bitstream_state_t * s,
const uint8_t ** c,
int bits )

Get a chunk of bits from the input buffer.

Parameters
sA pointer to the bitstream context.
cA pointer to the bitstream input buffer.
bitsThe number of bits of value to be grabbed. 1 to 25 bits is valid.
Returns
The value retrieved from the input buffer.

References bitstream_state_s::bitstream, bitstream_state_s::lsb_first, and bitstream_state_s::residue.

◆ bitstream_init()

bitstream_state_t * bitstream_init ( bitstream_state_t * s,
int direction )

Initialise a bitstream context.

Parameters
sA pointer to the bitstream context.
lsb_firstTRUE if the bit stream is LSB first, else its MSB first.
Returns
A pointer to the bitstream context.

References bitstream_state_s::bitstream, bitstream_state_s::lsb_first, and bitstream_state_s::residue.

Referenced by g726_init().

◆ bitstream_put()

void bitstream_put ( bitstream_state_t * s,
uint8_t ** c,
uint32_t value,
int bits )

Put a chunk of bits into the output buffer.

Parameters
sA pointer to the bitstream context.
cA pointer to the bitstream output buffer.
valueThe value to be pushed into the output buffer.
bitsThe number of bits of value to be pushed. 1 to 25 bits is valid.

References bitstream_state_s::bitstream, bitstream_state_s::lsb_first, and bitstream_state_s::residue.