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.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.h')
-rw-r--r-- | lib/rbcodec/codecs/libspeex/speex/speex.h | 428 |
1 files changed, 428 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libspeex/speex/speex.h b/lib/rbcodec/codecs/libspeex/speex/speex.h new file mode 100644 index 0000000000..086d492670 --- /dev/null +++ b/lib/rbcodec/codecs/libspeex/speex/speex.h | |||
@@ -0,0 +1,428 @@ | |||
1 | /* Copyright (C) 2002-2006 Jean-Marc Valin*/ | ||
2 | /** | ||
3 | @file speex.h | ||
4 | @brief Describes the different modes of the codec | ||
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 SPEEX_H | ||
37 | #define SPEEX_H | ||
38 | /** @defgroup Codec Speex encoder and decoder | ||
39 | * This is the Speex codec itself. | ||
40 | * @{ | ||
41 | */ | ||
42 | |||
43 | #include "speex_bits.h" | ||
44 | #include "speex_types.h" | ||
45 | |||
46 | #ifdef __cplusplus | ||
47 | extern "C" { | ||
48 | #endif | ||
49 | |||
50 | /* Values allowed for *ctl() requests */ | ||
51 | |||
52 | /** Set enhancement on/off (decoder only) */ | ||
53 | #define SPEEX_SET_ENH 0 | ||
54 | /** Get enhancement state (decoder only) */ | ||
55 | #define SPEEX_GET_ENH 1 | ||
56 | |||
57 | /*Would be SPEEX_SET_FRAME_SIZE, but it's (currently) invalid*/ | ||
58 | /** Obtain frame size used by encoder/decoder */ | ||
59 | #define SPEEX_GET_FRAME_SIZE 3 | ||
60 | |||
61 | /** Set quality value */ | ||
62 | #define SPEEX_SET_QUALITY 4 | ||
63 | /** Get current quality setting */ | ||
64 | /* #define SPEEX_GET_QUALITY 5 -- Doesn't make much sense, does it? */ | ||
65 | |||
66 | /** Set sub-mode to use */ | ||
67 | #define SPEEX_SET_MODE 6 | ||
68 | /** Get current sub-mode in use */ | ||
69 | #define SPEEX_GET_MODE 7 | ||
70 | |||
71 | /** Set low-band sub-mode to use (wideband only)*/ | ||
72 | #define SPEEX_SET_LOW_MODE 8 | ||
73 | /** Get current low-band mode in use (wideband only)*/ | ||
74 | #define SPEEX_GET_LOW_MODE 9 | ||
75 | |||
76 | /** Set high-band sub-mode to use (wideband only)*/ | ||
77 | #define SPEEX_SET_HIGH_MODE 10 | ||
78 | /** Get current high-band mode in use (wideband only)*/ | ||
79 | #define SPEEX_GET_HIGH_MODE 11 | ||
80 | |||
81 | /** Set VBR on (1) or off (0) */ | ||
82 | #define SPEEX_SET_VBR 12 | ||
83 | /** Get VBR status (1 for on, 0 for off) */ | ||
84 | #define SPEEX_GET_VBR 13 | ||
85 | |||
86 | /** Set quality value for VBR encoding (0-10) */ | ||
87 | #define SPEEX_SET_VBR_QUALITY 14 | ||
88 | /** Get current quality value for VBR encoding (0-10) */ | ||
89 | #define SPEEX_GET_VBR_QUALITY 15 | ||
90 | |||
91 | /** Set complexity of the encoder (0-10) */ | ||
92 | #define SPEEX_SET_COMPLEXITY 16 | ||
93 | /** Get current complexity of the encoder (0-10) */ | ||
94 | #define SPEEX_GET_COMPLEXITY 17 | ||
95 | |||
96 | /** Set bit-rate used by the encoder (or lower) */ | ||
97 | #define SPEEX_SET_BITRATE 18 | ||
98 | /** Get current bit-rate used by the encoder or decoder */ | ||
99 | #define SPEEX_GET_BITRATE 19 | ||
100 | |||
101 | /** Define a handler function for in-band Speex request*/ | ||
102 | #define SPEEX_SET_HANDLER 20 | ||
103 | |||
104 | /** Define a handler function for in-band user-defined request*/ | ||
105 | #define SPEEX_SET_USER_HANDLER 22 | ||
106 | |||
107 | /** Set sampling rate used in bit-rate computation */ | ||
108 | #define SPEEX_SET_SAMPLING_RATE 24 | ||
109 | /** Get sampling rate used in bit-rate computation */ | ||
110 | #define SPEEX_GET_SAMPLING_RATE 25 | ||
111 | |||
112 | /** Reset the encoder/decoder memories to zero*/ | ||
113 | #define SPEEX_RESET_STATE 26 | ||
114 | |||
115 | /** Get VBR info (mostly used internally) */ | ||
116 | #define SPEEX_GET_RELATIVE_QUALITY 29 | ||
117 | |||
118 | /** Set VAD status (1 for on, 0 for off) */ | ||
119 | #define SPEEX_SET_VAD 30 | ||
120 | |||
121 | /** Get VAD status (1 for on, 0 for off) */ | ||
122 | #define SPEEX_GET_VAD 31 | ||
123 | |||
124 | /** Set Average Bit-Rate (ABR) to n bits per seconds */ | ||
125 | #define SPEEX_SET_ABR 32 | ||
126 | /** Get Average Bit-Rate (ABR) setting (in bps) */ | ||
127 | #define SPEEX_GET_ABR 33 | ||
128 | |||
129 | /** Set DTX status (1 for on, 0 for off) */ | ||
130 | #define SPEEX_SET_DTX 34 | ||
131 | /** Get DTX status (1 for on, 0 for off) */ | ||
132 | #define SPEEX_GET_DTX 35 | ||
133 | |||
134 | /** Set submode encoding in each frame (1 for yes, 0 for no, setting to no breaks the standard) */ | ||
135 | #define SPEEX_SET_SUBMODE_ENCODING 36 | ||
136 | /** Get submode encoding in each frame */ | ||
137 | #define SPEEX_GET_SUBMODE_ENCODING 37 | ||
138 | |||
139 | /*#define SPEEX_SET_LOOKAHEAD 38*/ | ||
140 | /** Returns the lookahead used by Speex */ | ||
141 | #define SPEEX_GET_LOOKAHEAD 39 | ||
142 | |||
143 | /** Sets tuning for packet-loss concealment (expected loss rate) */ | ||
144 | #define SPEEX_SET_PLC_TUNING 40 | ||
145 | /** Gets tuning for PLC */ | ||
146 | #define SPEEX_GET_PLC_TUNING 41 | ||
147 | |||
148 | /** Sets the max bit-rate allowed in VBR mode */ | ||
149 | #define SPEEX_SET_VBR_MAX_BITRATE 42 | ||
150 | /** Gets the max bit-rate allowed in VBR mode */ | ||
151 | #define SPEEX_GET_VBR_MAX_BITRATE 43 | ||
152 | |||
153 | /** Turn on/off input/output high-pass filtering */ | ||
154 | #define SPEEX_SET_HIGHPASS 44 | ||
155 | /** Get status of input/output high-pass filtering */ | ||
156 | #define SPEEX_GET_HIGHPASS 45 | ||
157 | |||
158 | /** Get "activity level" of the last decoded frame, i.e. | ||
159 | how much damage we cause if we remove the frame */ | ||
160 | #define SPEEX_GET_ACTIVITY 47 | ||
161 | |||
162 | |||
163 | /* Preserving compatibility:*/ | ||
164 | /** Equivalent to SPEEX_SET_ENH */ | ||
165 | #define SPEEX_SET_PF 0 | ||
166 | /** Equivalent to SPEEX_GET_ENH */ | ||
167 | #define SPEEX_GET_PF 1 | ||
168 | |||
169 | |||
170 | |||
171 | |||
172 | /* Values allowed for mode queries */ | ||
173 | /** Query the frame size of a mode */ | ||
174 | #define SPEEX_MODE_FRAME_SIZE 0 | ||
175 | |||
176 | /** Query the size of an encoded frame for a particular sub-mode */ | ||
177 | #define SPEEX_SUBMODE_BITS_PER_FRAME 1 | ||
178 | |||
179 | |||
180 | |||
181 | /** Get major Speex version */ | ||
182 | #define SPEEX_LIB_GET_MAJOR_VERSION 1 | ||
183 | /** Get minor Speex version */ | ||
184 | #define SPEEX_LIB_GET_MINOR_VERSION 3 | ||
185 | /** Get micro Speex version */ | ||
186 | #define SPEEX_LIB_GET_MICRO_VERSION 5 | ||
187 | /** Get extra Speex version */ | ||
188 | #define SPEEX_LIB_GET_EXTRA_VERSION 7 | ||
189 | /** Get Speex version string */ | ||
190 | #define SPEEX_LIB_GET_VERSION_STRING 9 | ||
191 | |||
192 | /*#define SPEEX_LIB_SET_ALLOC_FUNC 10 | ||
193 | #define SPEEX_LIB_GET_ALLOC_FUNC 11 | ||
194 | #define SPEEX_LIB_SET_FREE_FUNC 12 | ||
195 | #define SPEEX_LIB_GET_FREE_FUNC 13 | ||
196 | |||
197 | #define SPEEX_LIB_SET_WARNING_FUNC 14 | ||
198 | #define SPEEX_LIB_GET_WARNING_FUNC 15 | ||
199 | #define SPEEX_LIB_SET_ERROR_FUNC 16 | ||
200 | #define SPEEX_LIB_GET_ERROR_FUNC 17 | ||
201 | */ | ||
202 | |||
203 | /** Number of defined modes in Speex */ | ||
204 | #define SPEEX_NB_MODES 3 | ||
205 | |||
206 | /** modeID for the defined narrowband mode */ | ||
207 | #define SPEEX_MODEID_NB 0 | ||
208 | |||
209 | /** modeID for the defined wideband mode */ | ||
210 | #define SPEEX_MODEID_WB 1 | ||
211 | |||
212 | /** modeID for the defined ultra-wideband mode */ | ||
213 | #define SPEEX_MODEID_UWB 2 | ||
214 | |||
215 | struct SpeexMode; | ||
216 | |||
217 | |||
218 | /* Prototypes for mode function pointers */ | ||
219 | |||
220 | /** Encoder state initialization function */ | ||
221 | typedef void *(*encoder_init_func)(const struct SpeexMode *mode); | ||
222 | |||
223 | /** Encoder state destruction function */ | ||
224 | typedef void (*encoder_destroy_func)(void *st); | ||
225 | |||
226 | /** Main encoding function */ | ||
227 | typedef int (*encode_func)(void *state, void *in, SpeexBits *bits); | ||
228 | |||
229 | /** Function for controlling the encoder options */ | ||
230 | typedef int (*encoder_ctl_func)(void *state, int request, void *ptr); | ||
231 | |||
232 | /** Decoder state initialization function */ | ||
233 | typedef void *(*decoder_init_func)(const struct SpeexMode *mode); | ||
234 | |||
235 | /** Decoder state destruction function */ | ||
236 | typedef void (*decoder_destroy_func)(void *st); | ||
237 | |||
238 | /** Main decoding function */ | ||
239 | typedef int (*decode_func)(void *state, SpeexBits *bits, void *out); | ||
240 | |||
241 | /** Function for controlling the decoder options */ | ||
242 | typedef int (*decoder_ctl_func)(void *state, int request, void *ptr); | ||
243 | |||
244 | |||
245 | /** Query function for a mode */ | ||
246 | typedef int (*mode_query_func)(const void *mode, int request, void *ptr); | ||
247 | |||
248 | /** Struct defining a Speex mode */ | ||
249 | typedef struct SpeexMode { | ||
250 | /** Pointer to the low-level mode data */ | ||
251 | const void *mode; | ||
252 | |||
253 | /** Pointer to the mode query function */ | ||
254 | mode_query_func query; | ||
255 | |||
256 | /** The name of the mode (you should not rely on this to identify the mode)*/ | ||
257 | const char *modeName; | ||
258 | |||
259 | /**ID of the mode*/ | ||
260 | int modeID; | ||
261 | |||
262 | /**Version number of the bitstream (incremented every time we break | ||
263 | bitstream compatibility*/ | ||
264 | int bitstream_version; | ||
265 | |||
266 | #ifndef SPEEX_DISABLE_ENCODER | ||
267 | /** Pointer to encoder initialization function */ | ||
268 | encoder_init_func enc_init; | ||
269 | |||
270 | /** Pointer to encoder destruction function */ | ||
271 | encoder_destroy_func enc_destroy; | ||
272 | |||
273 | /** Pointer to frame encoding function */ | ||
274 | encode_func enc; | ||
275 | #endif | ||
276 | |||
277 | /** Pointer to decoder initialization function */ | ||
278 | decoder_init_func dec_init; | ||
279 | |||
280 | /** Pointer to decoder destruction function */ | ||
281 | decoder_destroy_func dec_destroy; | ||
282 | |||
283 | /** Pointer to frame decoding function */ | ||
284 | decode_func dec; | ||
285 | |||
286 | #ifndef SPEEX_DISABLE_ENCODER | ||
287 | /** ioctl-like requests for encoder */ | ||
288 | encoder_ctl_func enc_ctl; | ||
289 | #endif | ||
290 | |||
291 | /** ioctl-like requests for decoder */ | ||
292 | decoder_ctl_func dec_ctl; | ||
293 | |||
294 | } SpeexMode; | ||
295 | |||
296 | /** | ||
297 | * Returns a handle to a newly created Speex encoder state structure. For now, | ||
298 | * the "mode" argument can be &nb_mode or &wb_mode . In the future, more modes | ||
299 | * may be added. Note that for now if you have more than one channels to | ||
300 | * encode, you need one state per channel. | ||
301 | * | ||
302 | * @param mode The mode to use (either speex_nb_mode or speex_wb.mode) | ||
303 | * @return A newly created encoder state or NULL if state allocation fails | ||
304 | */ | ||
305 | void *speex_encoder_init(const SpeexMode *mode); | ||
306 | |||
307 | /** Frees all resources associated to an existing Speex encoder state. | ||
308 | * @param state Encoder state to be destroyed */ | ||
309 | void speex_encoder_destroy(void *state); | ||
310 | |||
311 | /** Uses an existing encoder state to encode one frame of speech pointed to by | ||
312 | "in". The encoded bit-stream is saved in "bits". | ||
313 | @param state Encoder state | ||
314 | @param in Frame that will be encoded with a +-2^15 range. This data MAY be | ||
315 | overwritten by the encoder and should be considered uninitialised | ||
316 | after the call. | ||
317 | @param bits Bit-stream where the data will be written | ||
318 | @return 0 if frame needs not be transmitted (DTX only), 1 otherwise | ||
319 | */ | ||
320 | int speex_encode(void *state, float *in, SpeexBits *bits); | ||
321 | |||
322 | /** Uses an existing encoder state to encode one frame of speech pointed to by | ||
323 | "in". The encoded bit-stream is saved in "bits". | ||
324 | @param state Encoder state | ||
325 | @param in Frame that will be encoded with a +-2^15 range | ||
326 | @param bits Bit-stream where the data will be written | ||
327 | @return 0 if frame needs not be transmitted (DTX only), 1 otherwise | ||
328 | */ | ||
329 | int speex_encode_int(void *state, spx_int16_t *in, SpeexBits *bits); | ||
330 | |||
331 | /** Used like the ioctl function to control the encoder parameters | ||
332 | * | ||
333 | * @param state Encoder state | ||
334 | * @param request ioctl-type request (one of the SPEEX_* macros) | ||
335 | * @param ptr Data exchanged to-from function | ||
336 | * @return 0 if no error, -1 if request in unknown, -2 for invalid parameter | ||
337 | */ | ||
338 | int speex_encoder_ctl(void *state, int request, void *ptr); | ||
339 | |||
340 | |||
341 | /** Returns a handle to a newly created decoder state structure. For now, | ||
342 | * the mode argument can be &nb_mode or &wb_mode . In the future, more modes | ||
343 | * may be added. Note that for now if you have more than one channels to | ||
344 | * decode, you need one state per channel. | ||
345 | * | ||
346 | * @param mode Speex mode (one of speex_nb_mode or speex_wb_mode) | ||
347 | * @return A newly created decoder state or NULL if state allocation fails | ||
348 | */ | ||
349 | void *speex_decoder_init(const SpeexMode *mode); | ||
350 | |||
351 | /** Frees all resources associated to an existing decoder state. | ||
352 | * | ||
353 | * @param state State to be destroyed | ||
354 | */ | ||
355 | void speex_decoder_destroy(void *state); | ||
356 | |||
357 | /** Uses an existing decoder state to decode one frame of speech from | ||
358 | * bit-stream bits. The output speech is saved written to out. | ||
359 | * | ||
360 | * @param state Decoder state | ||
361 | * @param bits Bit-stream from which to decode the frame (NULL if the packet was lost) | ||
362 | * @param out Where to write the decoded frame | ||
363 | * @return return status (0 for no error, -1 for end of stream, -2 corrupt stream) | ||
364 | */ | ||
365 | int speex_decode(void *state, SpeexBits *bits, float *out); | ||
366 | |||
367 | /** Uses an existing decoder state to decode one frame of speech from | ||
368 | * bit-stream bits. The output speech is saved written to out. | ||
369 | * | ||
370 | * @param state Decoder state | ||
371 | * @param bits Bit-stream from which to decode the frame (NULL if the packet was lost) | ||
372 | * @param out Where to write the decoded frame | ||
373 | * @return return status (0 for no error, -1 for end of stream, -2 corrupt stream) | ||
374 | */ | ||
375 | int speex_decode_int(void *state, SpeexBits *bits, spx_int16_t *out); | ||
376 | |||
377 | /** Used like the ioctl function to control the encoder parameters | ||
378 | * | ||
379 | * @param state Decoder state | ||
380 | * @param request ioctl-type request (one of the SPEEX_* macros) | ||
381 | * @param ptr Data exchanged to-from function | ||
382 | * @return 0 if no error, -1 if request in unknown, -2 for invalid parameter | ||
383 | */ | ||
384 | int speex_decoder_ctl(void *state, int request, void *ptr); | ||
385 | |||
386 | |||
387 | /** Query function for mode information | ||
388 | * | ||
389 | * @param mode Speex mode | ||
390 | * @param request ioctl-type request (one of the SPEEX_* macros) | ||
391 | * @param ptr Data exchanged to-from function | ||
392 | * @return 0 if no error, -1 if request in unknown, -2 for invalid parameter | ||
393 | */ | ||
394 | int speex_mode_query(const SpeexMode *mode, int request, void *ptr); | ||
395 | |||
396 | /** Functions for controlling the behavior of libspeex | ||
397 | * @param request ioctl-type request (one of the SPEEX_LIB_* macros) | ||
398 | * @param ptr Data exchanged to-from function | ||
399 | * @return 0 if no error, -1 if request in unknown, -2 for invalid parameter | ||
400 | */ | ||
401 | int speex_lib_ctl(int request, void *ptr); | ||
402 | |||
403 | /** Default narrowband mode */ | ||
404 | extern const SpeexMode speex_nb_mode; | ||
405 | |||
406 | /** Default wideband mode */ | ||
407 | extern const SpeexMode speex_wb_mode; | ||
408 | |||
409 | /** Default "ultra-wideband" mode */ | ||
410 | extern const SpeexMode speex_uwb_mode; | ||
411 | |||
412 | /** List of all modes available */ | ||
413 | extern const SpeexMode * const speex_mode_list[SPEEX_NB_MODES]; | ||
414 | |||
415 | /** Obtain one of the modes available */ | ||
416 | const SpeexMode * speex_lib_get_mode (int mode); | ||
417 | |||
418 | #ifndef WIN32 | ||
419 | /* We actually override the function in the narrowband case so that we can avoid linking in the wideband stuff */ | ||
420 | #define speex_lib_get_mode(mode) ((mode)==SPEEX_MODEID_NB ? &speex_nb_mode : speex_lib_get_mode (mode)) | ||
421 | #endif | ||
422 | |||
423 | #ifdef __cplusplus | ||
424 | } | ||
425 | #endif | ||
426 | |||
427 | /** @}*/ | ||
428 | #endif | ||