spandsp 0.0.6

bitstream.h
Go to the documentation of this file.
1/*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * bitstream.h - Bitstream composition and decomposition routines.
5 *
6 * Written by Steve Underwood <steveu@coppice.org>
7 *
8 * Copyright (C) 2006 Steve Underwood
9 *
10 * All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 2.1,
14 * as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26/*! \file */
27
28#if !defined(_SPANDSP_BITSTREAM_H_)
29#define _SPANDSP_BITSTREAM_H_
30
31/*! \page bitstream_page Bitstream composition and decomposition
32\section bitstream_page_sec_1 What does it do?
33
34\section bitstream_page_sec_2 How does it work?
35*/
36
37/*! Bitstream handler state */
38 typedef struct bitstream_state_s bitstream_state_t;
39
40#if defined(__cplusplus)
41 extern "C"
42{
43#endif
44
45/*! \brief Put a chunk of bits into the output buffer.
46 \param s A pointer to the bitstream context.
47 \param c A pointer to the bitstream output buffer.
48 \param value The value to be pushed into the output buffer.
49 \param bits The number of bits of value to be pushed. 1 to 25 bits is valid. */
50SPAN_DECLARE(void) bitstream_put(bitstream_state_t *s, uint8_t **c, uint32_t value, int bits);
51
52/*! \brief Get a chunk of bits from the input buffer.
53 \param s A pointer to the bitstream context.
54 \param c A pointer to the bitstream input buffer.
55 \param bits The number of bits of value to be grabbed. 1 to 25 bits is valid.
56 \return The value retrieved from the input buffer. */
57SPAN_DECLARE(uint32_t) bitstream_get(bitstream_state_t *s, const uint8_t **c, int bits);
58
59/*! \brief Emit any residual bits to the output buffer, without actually flushing them.
60 This is useful for getting the buffer fully up to date, ready for things
61 like CRC calculations, while allowing bitstream_put() to be used to continue
62 the message later.
63 \param s A pointer to the bitstream context.
64 \param c A pointer to the bitstream output buffer. */
65SPAN_DECLARE(void) bitstream_emit(bitstream_state_t *s, uint8_t **c);
66
67/*! \brief Flush any residual bits to the output buffer.
68 \param s A pointer to the bitstream context.
69 \param c A pointer to the bitstream output buffer. */
70SPAN_DECLARE(void) bitstream_flush(bitstream_state_t *s, uint8_t **c);
71
72/*! \brief Initialise a bitstream context.
73 \param s A pointer to the bitstream context.
74 \param lsb_first TRUE if the bit stream is LSB first, else its MSB first.
75 \return A pointer to the bitstream context. */
76SPAN_DECLARE(bitstream_state_t *) bitstream_init(bitstream_state_t *s, int direction);
77
78SPAN_DECLARE(int) bitstream_release(bitstream_state_t *s);
79
80SPAN_DECLARE(int) bitstream_free(bitstream_state_t *s);
81
82#if defined(__cplusplus)
83}
84#endif
85
86#endif
87/*- End of file ------------------------------------------------------------*/
bitstream_state_t
struct bitstream_state_s bitstream_state_t
Definition bitstream.h:38
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 getti...
Definition bitstream.c:75
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.
Definition bitstream.c:42
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.
Definition bitstream.c:102
bitstream_flush
void bitstream_flush(bitstream_state_t *s, uint8_t **c)
Flush any residual bits to the output buffer.
Definition bitstream.c:90
bitstream_init
bitstream_state_t * bitstream_init(bitstream_state_t *s, int direction)
Initialise a bitstream context.
Definition bitstream.c:131
bitstream_state_s
Definition private/bitstream.h:31