Speex  1.2~beta4
speex.h
Go to the documentation of this file.
1 /* Copyright (C) 2002-2006 Jean-Marc Valin*/
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 
43 #include "speex/speex_bits.h"
44 #include "speex/speex_types.h"
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 /* Values allowed for *ctl() requests */
51 
53 #define SPEEX_SET_ENH 0
54 
55 #define SPEEX_GET_ENH 1
56 
57 /*Would be SPEEX_SET_FRAME_SIZE, but it's (currently) invalid*/
59 #define SPEEX_GET_FRAME_SIZE 3
60 
62 #define SPEEX_SET_QUALITY 4
63 
64 /* #define SPEEX_GET_QUALITY 5 -- Doesn't make much sense, does it? */
65 
67 #define SPEEX_SET_MODE 6
68 
69 #define SPEEX_GET_MODE 7
70 
72 #define SPEEX_SET_LOW_MODE 8
73 
74 #define SPEEX_GET_LOW_MODE 9
75 
77 #define SPEEX_SET_HIGH_MODE 10
78 
79 #define SPEEX_GET_HIGH_MODE 11
80 
82 #define SPEEX_SET_VBR 12
83 
84 #define SPEEX_GET_VBR 13
85 
87 #define SPEEX_SET_VBR_QUALITY 14
88 
89 #define SPEEX_GET_VBR_QUALITY 15
90 
92 #define SPEEX_SET_COMPLEXITY 16
93 
94 #define SPEEX_GET_COMPLEXITY 17
95 
97 #define SPEEX_SET_BITRATE 18
98 
99 #define SPEEX_GET_BITRATE 19
100 
102 #define SPEEX_SET_HANDLER 20
103 
105 #define SPEEX_SET_USER_HANDLER 22
106 
108 #define SPEEX_SET_SAMPLING_RATE 24
109 
110 #define SPEEX_GET_SAMPLING_RATE 25
111 
113 #define SPEEX_RESET_STATE 26
114 
116 #define SPEEX_GET_RELATIVE_QUALITY 29
117 
119 #define SPEEX_SET_VAD 30
120 
122 #define SPEEX_GET_VAD 31
123 
125 #define SPEEX_SET_ABR 32
126 
127 #define SPEEX_GET_ABR 33
128 
130 #define SPEEX_SET_DTX 34
131 
132 #define SPEEX_GET_DTX 35
133 
135 #define SPEEX_SET_SUBMODE_ENCODING 36
136 
137 #define SPEEX_GET_SUBMODE_ENCODING 37
138 
139 /*#define SPEEX_SET_LOOKAHEAD 38*/
141 #define SPEEX_GET_LOOKAHEAD 39
142 
144 #define SPEEX_SET_PLC_TUNING 40
145 
146 #define SPEEX_GET_PLC_TUNING 41
147 
149 #define SPEEX_SET_VBR_MAX_BITRATE 42
150 
151 #define SPEEX_GET_VBR_MAX_BITRATE 43
152 
154 #define SPEEX_SET_HIGHPASS 44
155 
156 #define SPEEX_GET_HIGHPASS 45
157 
160 #define SPEEX_GET_ACTIVITY 47
161 
162 
163 /* Preserving compatibility:*/
165 #define SPEEX_SET_PF 0
166 
167 #define SPEEX_GET_PF 1
168 
169 
170 
171 
172 /* Values allowed for mode queries */
174 #define SPEEX_MODE_FRAME_SIZE 0
175 
177 #define SPEEX_SUBMODE_BITS_PER_FRAME 1
178 
179 
180 
182 #define SPEEX_LIB_GET_MAJOR_VERSION 1
183 
184 #define SPEEX_LIB_GET_MINOR_VERSION 3
185 
186 #define SPEEX_LIB_GET_MICRO_VERSION 5
187 
188 #define SPEEX_LIB_GET_EXTRA_VERSION 7
189 
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 
204 #define SPEEX_NB_MODES 3
205 
207 #define SPEEX_MODEID_NB 0
208 
210 #define SPEEX_MODEID_WB 1
211 
213 #define SPEEX_MODEID_UWB 2
214 
215 struct SpeexMode;
216 
217 
218 /* Prototypes for mode function pointers */
219 
221 typedef void *(*encoder_init_func)(const struct SpeexMode *mode);
222 
224 typedef void (*encoder_destroy_func)(void *st);
225 
227 typedef int (*encode_func)(void *state, void *in, SpeexBits *bits);
228 
230 typedef int (*encoder_ctl_func)(void *state, int request, void *ptr);
231 
233 typedef void *(*decoder_init_func)(const struct SpeexMode *mode);
234 
236 typedef void (*decoder_destroy_func)(void *st);
237 
239 typedef int (*decode_func)(void *state, SpeexBits *bits, void *out);
240 
242 typedef int (*decoder_ctl_func)(void *state, int request, void *ptr);
243 
244 
246 typedef int (*mode_query_func)(const void *mode, int request, void *ptr);
247 
249 typedef struct SpeexMode {
251  const void *mode;
252 
255 
257  const char *modeName;
258 
260  int modeID;
261 
265 
268 
271 
274 
277 
280 
283 
286 
289 
290 } SpeexMode;
291 
301 void *speex_encoder_init(const SpeexMode *mode);
302 
305 void speex_encoder_destroy(void *state);
306 
316 int speex_encode(void *state, float *in, SpeexBits *bits);
317 
325 int speex_encode_int(void *state, spx_int16_t *in, SpeexBits *bits);
326 
334 int speex_encoder_ctl(void *state, int request, void *ptr);
335 
336 
345 void *speex_decoder_init(const SpeexMode *mode);
346 
351 void speex_decoder_destroy(void *state);
352 
361 int speex_decode(void *state, SpeexBits *bits, float *out);
362 
371 int speex_decode_int(void *state, SpeexBits *bits, spx_int16_t *out);
372 
380 int speex_decoder_ctl(void *state, int request, void *ptr);
381 
382 
390 int speex_mode_query(const SpeexMode *mode, int request, void *ptr);
391 
397 int speex_lib_ctl(int request, void *ptr);
398 
400 extern const SpeexMode speex_nb_mode;
401 
403 extern const SpeexMode speex_wb_mode;
404 
406 extern const SpeexMode speex_uwb_mode;
407 
409 extern const SpeexMode * const speex_mode_list[SPEEX_NB_MODES];
410 
412 const SpeexMode * speex_lib_get_mode (int mode);
413 
414 #ifndef WIN32
415 /* We actually override the function in the narrowband case so that we can avoid linking in the wideband stuff */
416 #define speex_lib_get_mode(mode) ((mode)==SPEEX_MODEID_NB ? &speex_nb_mode : speex_lib_get_mode (mode))
417 #endif
418 
419 #ifdef __cplusplus
420 }
421 #endif
422 
424 #endif