diff options
author | Sean Bartell <wingedtachikoma@gmail.com> | 2011-06-25 21:32:25 -0400 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2012-04-25 22:13:20 +0200 |
commit | f40bfc9267b13b54e6379dfe7539447662879d24 (patch) | |
tree | 9b20069d5e62809ff434061ad730096836f916f2 /lib/rbcodec/codecs/libspeex/speex/speex_bits.h | |
parent | a0009907de7a0107d49040d8a180f140e2eff299 (diff) | |
download | rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.tar.gz rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.zip |
Add codecs to librbcodec.
Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97
Reviewed-on: http://gerrit.rockbox.org/137
Reviewed-by: Nils Wallménius <nils@rockbox.org>
Tested-by: Nils Wallménius <nils@rockbox.org>
Diffstat (limited to 'lib/rbcodec/codecs/libspeex/speex/speex_bits.h')
-rw-r--r-- | lib/rbcodec/codecs/libspeex/speex/speex_bits.h | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libspeex/speex/speex_bits.h b/lib/rbcodec/codecs/libspeex/speex/speex_bits.h new file mode 100644 index 0000000000..fee2893380 --- /dev/null +++ b/lib/rbcodec/codecs/libspeex/speex/speex_bits.h | |||
@@ -0,0 +1,184 @@ | |||
1 | /* Copyright (C) 2002 Jean-Marc Valin */ | ||
2 | /** | ||
3 | @file speex_bits.h | ||
4 | @brief Handles bit packing/unpacking | ||
5 | */ | ||
6 | /* | ||
7 | Redistribution and use in source and binary forms, with or without | ||
8 | modification, are permitted provided that the following conditions | ||
9 | are met: | ||
10 | |||
11 | - Redistributions of source code must retain the above copyright | ||
12 | notice, this list of conditions and the following disclaimer. | ||
13 | |||
14 | - Redistributions in binary form must reproduce the above copyright | ||
15 | notice, this list of conditions and the following disclaimer in the | ||
16 | documentation and/or other materials provided with the distribution. | ||
17 | |||
18 | - Neither the name of the Xiph.org Foundation nor the names of its | ||
19 | contributors may be used to endorse or promote products derived from | ||
20 | this software without specific prior written permission. | ||
21 | |||
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR | ||
26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | |||
34 | */ | ||
35 | |||
36 | #ifndef BITS_H | ||
37 | #define BITS_H | ||
38 | /** @defgroup SpeexBits SpeexBits: Bit-stream manipulations | ||
39 | * This is the structure that holds the bit-stream when encoding or decoding | ||
40 | * with Speex. It allows some manipulations as well. | ||
41 | * @{ | ||
42 | */ | ||
43 | |||
44 | #ifdef __cplusplus | ||
45 | extern "C" { | ||
46 | #endif | ||
47 | |||
48 | /** Bit-packing data structure representing (part of) a bit-stream. */ | ||
49 | typedef struct SpeexBits { | ||
50 | char *chars; /**< "raw" data */ | ||
51 | int nbBits; /**< Total number of bits stored in the stream*/ | ||
52 | int charPtr; /**< Position of the byte "cursor" */ | ||
53 | int bitPtr; /**< Position of the bit "cursor" within the current char */ | ||
54 | int owner; /**< Does the struct "own" the "raw" buffer (member "chars") */ | ||
55 | int overflow;/**< Set to one if we try to read past the valid data */ | ||
56 | int buf_size;/**< Allocated size for buffer */ | ||
57 | int reserved1; /**< Reserved for future use */ | ||
58 | void *reserved2; /**< Reserved for future use */ | ||
59 | } SpeexBits; | ||
60 | |||
61 | /** Initializes and allocates resources for a SpeexBits struct */ | ||
62 | void speex_bits_init(SpeexBits *bits); | ||
63 | |||
64 | /** Initializes SpeexBits struct using a pre-allocated buffer*/ | ||
65 | /* Rockbox: unused | ||
66 | void speex_bits_init_buffer(SpeexBits *bits, void *buff, int buf_size); | ||
67 | */ | ||
68 | |||
69 | /** Sets the bits in a SpeexBits struct to use data from an existing buffer (for decoding without copying data) */ | ||
70 | void speex_bits_set_bit_buffer(SpeexBits *bits, void *buff, int buf_size); | ||
71 | |||
72 | /** Frees all resources associated to a SpeexBits struct. Right now this does nothing since no resources are allocated, but this could change in the future.*/ | ||
73 | void speex_bits_destroy(SpeexBits *bits); | ||
74 | |||
75 | /** Resets bits to initial value (just after initialization, erasing content)*/ | ||
76 | void speex_bits_reset(SpeexBits *bits); | ||
77 | |||
78 | /** Rewind the bit-stream to the beginning (ready for read) without erasing the content */ | ||
79 | /* Rockbox: unused | ||
80 | void speex_bits_rewind(SpeexBits *bits); | ||
81 | */ | ||
82 | |||
83 | /** Initializes the bit-stream from the data in an area of memory */ | ||
84 | void speex_bits_read_from(SpeexBits *bits, char *bytes, int len); | ||
85 | |||
86 | /** Append bytes to the bit-stream | ||
87 | * | ||
88 | * @param bits Bit-stream to operate on | ||
89 | * @param bytes pointer to the bytes what will be appended | ||
90 | * @param len Number of bytes of append | ||
91 | */ | ||
92 | void speex_bits_read_whole_bytes(SpeexBits *bits, char *bytes, int len); | ||
93 | |||
94 | /** Write the content of a bit-stream to an area of memory | ||
95 | * | ||
96 | * @param bits Bit-stream to operate on | ||
97 | * @param bytes Memory location where to write the bits | ||
98 | * @param max_len Maximum number of bytes to write (i.e. size of the "bytes" buffer) | ||
99 | * @return Number of bytes written to the "bytes" buffer | ||
100 | */ | ||
101 | int speex_bits_write(SpeexBits *bits, char *bytes, int max_len); | ||
102 | |||
103 | /** Like speex_bits_write, but writes only the complete bytes in the stream. Also removes the written bytes from the stream */ | ||
104 | int speex_bits_write_whole_bytes(SpeexBits *bits, char *bytes, int max_len); | ||
105 | |||
106 | /** Append bits to the bit-stream | ||
107 | * @param bits Bit-stream to operate on | ||
108 | * @param data Value to append as integer | ||
109 | * @param nbBits number of bits to consider in "data" | ||
110 | */ | ||
111 | void speex_bits_pack(SpeexBits *bits, int data, int nbBits); | ||
112 | |||
113 | /** Interpret the next bits in the bit-stream as a signed integer | ||
114 | * | ||
115 | * @param bits Bit-stream to operate on | ||
116 | * @param nbBits Number of bits to interpret | ||
117 | * @return A signed integer represented by the bits read | ||
118 | */ | ||
119 | /* Rockbox: unused | ||
120 | int speex_bits_unpack_signed(SpeexBits *bits, int nbBits); | ||
121 | */ | ||
122 | |||
123 | /** Interpret the next bits in the bit-stream as an unsigned integer | ||
124 | * | ||
125 | * @param bits Bit-stream to operate on | ||
126 | * @param nbBits Number of bits to interpret | ||
127 | * @return An unsigned integer represented by the bits read | ||
128 | */ | ||
129 | unsigned int speex_bits_unpack_unsigned(SpeexBits *bits, int nbBits); | ||
130 | |||
131 | /** Returns the number of bytes in the bit-stream, including the last one even if it is not "full" | ||
132 | * | ||
133 | * @param bits Bit-stream to operate on | ||
134 | * @return Number of bytes in the stream | ||
135 | */ | ||
136 | /* Rockbox: unused | ||
137 | int speex_bits_nbytes(SpeexBits *bits); | ||
138 | */ | ||
139 | |||
140 | /** Same as speex_bits_unpack_unsigned, but without modifying the cursor position | ||
141 | * | ||
142 | * @param bits Bit-stream to operate on | ||
143 | * @param nbBits Number of bits to look for | ||
144 | * @return Value of the bits peeked, interpreted as unsigned | ||
145 | */ | ||
146 | /* Rockbox: unused | ||
147 | unsigned int speex_bits_peek_unsigned(SpeexBits *bits, int nbBits); | ||
148 | */ | ||
149 | |||
150 | /** Get the value of the next bit in the stream, without modifying the | ||
151 | * "cursor" position | ||
152 | * | ||
153 | * @param bits Bit-stream to operate on | ||
154 | * @return Value of the bit peeked (one bit only) | ||
155 | */ | ||
156 | int speex_bits_peek(SpeexBits *bits); | ||
157 | |||
158 | /** Advances the position of the "bit cursor" in the stream | ||
159 | * | ||
160 | * @param bits Bit-stream to operate on | ||
161 | * @param n Number of bits to advance | ||
162 | */ | ||
163 | void speex_bits_advance(SpeexBits *bits, int n); | ||
164 | |||
165 | /** Returns the number of bits remaining to be read in a stream | ||
166 | * | ||
167 | * @param bits Bit-stream to operate on | ||
168 | * @return Number of bits that can still be read from the stream | ||
169 | */ | ||
170 | int speex_bits_remaining(SpeexBits *bits); | ||
171 | |||
172 | /** Insert a terminator so that the data can be sent as a packet while auto-detecting | ||
173 | * the number of frames in each packet | ||
174 | * | ||
175 | * @param bits Bit-stream to operate on | ||
176 | */ | ||
177 | void speex_bits_insert_terminator(SpeexBits *bits); | ||
178 | |||
179 | #ifdef __cplusplus | ||
180 | } | ||
181 | #endif | ||
182 | |||
183 | /* @} */ | ||
184 | #endif | ||