diff options
Diffstat (limited to 'lib/rbcodec/codecs/libspeex/modes_wb.c')
-rw-r--r-- | lib/rbcodec/codecs/libspeex/modes_wb.c | 374 |
1 files changed, 374 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libspeex/modes_wb.c b/lib/rbcodec/codecs/libspeex/modes_wb.c new file mode 100644 index 0000000000..93922afa2f --- /dev/null +++ b/lib/rbcodec/codecs/libspeex/modes_wb.c | |||
@@ -0,0 +1,374 @@ | |||
1 | /* Copyright (C) 2002-2007 Jean-Marc Valin | ||
2 | File: modes.c | ||
3 | |||
4 | Describes the wideband modes of the codec | ||
5 | |||
6 | Redistribution and use in source and binary forms, with or without | ||
7 | modification, are permitted provided that the following conditions | ||
8 | are met: | ||
9 | |||
10 | - Redistributions of source code must retain the above copyright | ||
11 | notice, this list of conditions and the following disclaimer. | ||
12 | |||
13 | - Redistributions in binary form must reproduce the above copyright | ||
14 | notice, this list of conditions and the following disclaimer in the | ||
15 | documentation and/or other materials provided with the distribution. | ||
16 | |||
17 | - Neither the name of the Xiph.org Foundation nor the names of its | ||
18 | contributors may be used to endorse or promote products derived from | ||
19 | this software without specific prior written permission. | ||
20 | |||
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
22 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
24 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR | ||
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
26 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
27 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
28 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
29 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
30 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
32 | |||
33 | */ | ||
34 | |||
35 | #ifdef HAVE_CONFIG_H | ||
36 | #include "config-speex.h" | ||
37 | #endif | ||
38 | |||
39 | #include "modes.h" | ||
40 | #include "ltp.h" | ||
41 | #include "quant_lsp.h" | ||
42 | #include "cb_search.h" | ||
43 | #include "sb_celp.h" | ||
44 | #include "nb_celp.h" | ||
45 | #include "vbr.h" | ||
46 | #include "arch.h" | ||
47 | #include <math.h> | ||
48 | #include "os_support.h" | ||
49 | |||
50 | |||
51 | #ifndef NULL | ||
52 | #define NULL 0 | ||
53 | #endif | ||
54 | |||
55 | #ifndef ROCKBOX_VOICE_CODEC | ||
56 | const SpeexMode * const speex_mode_list[SPEEX_NB_MODES] = {&speex_nb_mode, &speex_wb_mode, &speex_uwb_mode}; | ||
57 | #else | ||
58 | const SpeexMode * const speex_mode_list[SPEEX_NB_MODES] = {&speex_nb_mode, &speex_wb_mode, NULL}; | ||
59 | #endif | ||
60 | |||
61 | extern const signed char hexc_table[]; | ||
62 | extern const signed char hexc_10_32_table[]; | ||
63 | |||
64 | #ifndef DISABLE_WIDEBAND | ||
65 | |||
66 | /* Split-VQ innovation for high-band wideband */ | ||
67 | static const split_cb_params split_cb_high = { | ||
68 | 8, /*subvect_size*/ | ||
69 | 5, /*nb_subvect*/ | ||
70 | hexc_table, /*shape_cb*/ | ||
71 | 7, /*shape_bits*/ | ||
72 | 1, | ||
73 | }; | ||
74 | |||
75 | |||
76 | /* Split-VQ innovation for high-band wideband */ | ||
77 | static const split_cb_params split_cb_high_lbr = { | ||
78 | 10, /*subvect_size*/ | ||
79 | 4, /*nb_subvect*/ | ||
80 | hexc_10_32_table, /*shape_cb*/ | ||
81 | 5, /*shape_bits*/ | ||
82 | 0, | ||
83 | }; | ||
84 | |||
85 | #endif | ||
86 | |||
87 | |||
88 | static const SpeexSubmode wb_submode1 = { | ||
89 | 0, | ||
90 | 0, | ||
91 | 1, | ||
92 | 0, | ||
93 | /*LSP quantization*/ | ||
94 | #ifndef SPEEX_DISABLE_ENCODER | ||
95 | lsp_quant_high, | ||
96 | lsp_unquant_high, | ||
97 | #else | ||
98 | NULL, | ||
99 | lsp_unquant_high, | ||
100 | #endif | ||
101 | /*Pitch quantization*/ | ||
102 | NULL, | ||
103 | NULL, | ||
104 | NULL, | ||
105 | /*No innovation quantization*/ | ||
106 | NULL, | ||
107 | NULL, | ||
108 | NULL, | ||
109 | -1, | ||
110 | 36 | ||
111 | }; | ||
112 | |||
113 | |||
114 | static const SpeexSubmode wb_submode2 = { | ||
115 | 0, | ||
116 | 0, | ||
117 | 1, | ||
118 | 0, | ||
119 | #ifndef SPEEX_DISABLE_ENCODER | ||
120 | /*LSP quantization*/ | ||
121 | lsp_quant_high, | ||
122 | lsp_unquant_high, | ||
123 | /*Pitch quantization*/ | ||
124 | NULL, | ||
125 | NULL, | ||
126 | NULL, | ||
127 | /*Innovation quantization*/ | ||
128 | split_cb_search_shape_sign, | ||
129 | split_cb_shape_sign_unquant, | ||
130 | #else | ||
131 | /*LSP quantization*/ | ||
132 | NULL, | ||
133 | lsp_unquant_high, | ||
134 | /*Pitch quantization*/ | ||
135 | NULL, | ||
136 | NULL, | ||
137 | NULL, | ||
138 | /*Innovation quantization*/ | ||
139 | NULL, | ||
140 | split_cb_shape_sign_unquant, | ||
141 | #endif | ||
142 | #ifdef DISABLE_WIDEBAND | ||
143 | NULL, | ||
144 | #else | ||
145 | &split_cb_high_lbr, | ||
146 | #endif | ||
147 | -1, | ||
148 | 112 | ||
149 | }; | ||
150 | |||
151 | |||
152 | static const SpeexSubmode wb_submode3 = { | ||
153 | 0, | ||
154 | 0, | ||
155 | 1, | ||
156 | 0, | ||
157 | #ifndef SPEEX_DISABLE_ENCODER | ||
158 | /*LSP quantization*/ | ||
159 | lsp_quant_high, | ||
160 | lsp_unquant_high, | ||
161 | /*Pitch quantization*/ | ||
162 | NULL, | ||
163 | NULL, | ||
164 | NULL, | ||
165 | /*Innovation quantization*/ | ||
166 | split_cb_search_shape_sign, | ||
167 | split_cb_shape_sign_unquant, | ||
168 | #else | ||
169 | /*LSP quantization*/ | ||
170 | NULL, | ||
171 | lsp_unquant_high, | ||
172 | /*Pitch quantization*/ | ||
173 | NULL, | ||
174 | NULL, | ||
175 | NULL, | ||
176 | /*Innovation quantization*/ | ||
177 | NULL, | ||
178 | split_cb_shape_sign_unquant, | ||
179 | #endif | ||
180 | #ifdef DISABLE_WIDEBAND | ||
181 | NULL, | ||
182 | #else | ||
183 | &split_cb_high, | ||
184 | #endif | ||
185 | -1, | ||
186 | 192 | ||
187 | }; | ||
188 | |||
189 | static const SpeexSubmode wb_submode4 = { | ||
190 | 0, | ||
191 | 0, | ||
192 | 1, | ||
193 | 1, | ||
194 | #ifndef SPEEX_DISABLE_ENCODER | ||
195 | /*LSP quantization*/ | ||
196 | lsp_quant_high, | ||
197 | lsp_unquant_high, | ||
198 | /*Pitch quantization*/ | ||
199 | NULL, | ||
200 | NULL, | ||
201 | NULL, | ||
202 | /*Innovation quantization*/ | ||
203 | split_cb_search_shape_sign, | ||
204 | split_cb_shape_sign_unquant, | ||
205 | #else | ||
206 | /*LSP quantization*/ | ||
207 | NULL, | ||
208 | lsp_unquant_high, | ||
209 | /*Pitch quantization*/ | ||
210 | NULL, | ||
211 | NULL, | ||
212 | NULL, | ||
213 | /*Innovation quantization*/ | ||
214 | NULL, | ||
215 | split_cb_shape_sign_unquant, | ||
216 | #endif | ||
217 | #ifdef DISABLE_WIDEBAND | ||
218 | NULL, | ||
219 | #else | ||
220 | &split_cb_high, | ||
221 | #endif | ||
222 | -1, | ||
223 | 352 | ||
224 | }; | ||
225 | |||
226 | |||
227 | /* Split-band wideband CELP mode*/ | ||
228 | static const SpeexSBMode sb_wb_mode = { | ||
229 | &speex_nb_mode, | ||
230 | 160, /*frameSize*/ | ||
231 | 40, /*subframeSize*/ | ||
232 | 8, /*lpcSize*/ | ||
233 | #ifdef FIXED_POINT | ||
234 | 29491, 19661, /* gamma1, gamma2 */ | ||
235 | #else | ||
236 | 0.9, 0.6, /* gamma1, gamma2 */ | ||
237 | #endif | ||
238 | QCONST16(.0002,15), /*lpc_floor*/ | ||
239 | QCONST16(0.9f,15), | ||
240 | {NULL, &wb_submode1, &wb_submode2, &wb_submode3, &wb_submode4, NULL, NULL, NULL}, | ||
241 | 3, | ||
242 | {1, 8, 2, 3, 4, 5, 5, 6, 6, 7, 7}, | ||
243 | {1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 4}, | ||
244 | #ifndef DISABLE_VBR | ||
245 | vbr_hb_thresh, | ||
246 | #endif | ||
247 | 5 | ||
248 | }; | ||
249 | |||
250 | |||
251 | const SpeexMode speex_wb_mode = { | ||
252 | &sb_wb_mode, | ||
253 | wb_mode_query, | ||
254 | "wideband (sub-band CELP)", | ||
255 | 1, | ||
256 | 4, | ||
257 | #ifndef SPEEX_DISABLE_ENCODER | ||
258 | &sb_encoder_init, | ||
259 | &sb_encoder_destroy, | ||
260 | &sb_encode, | ||
261 | &sb_decoder_init, | ||
262 | &sb_decoder_destroy, | ||
263 | &sb_decode, | ||
264 | &sb_encoder_ctl, | ||
265 | &sb_decoder_ctl, | ||
266 | #else | ||
267 | /* NULL, | ||
268 | NULL, | ||
269 | NULL, */ | ||
270 | &sb_decoder_init, | ||
271 | &sb_decoder_destroy, | ||
272 | &sb_decode, | ||
273 | /* NULL, */ | ||
274 | &sb_decoder_ctl, | ||
275 | #endif | ||
276 | }; | ||
277 | |||
278 | |||
279 | |||
280 | /* "Ultra-wideband" mode stuff */ | ||
281 | |||
282 | |||
283 | |||
284 | #ifndef ROCKBOX_VOICE_CODEC | ||
285 | /* Split-band "ultra-wideband" (32 kbps) CELP mode*/ | ||
286 | static const SpeexSBMode sb_uwb_mode = { | ||
287 | &speex_wb_mode, | ||
288 | 320, /*frameSize*/ | ||
289 | 80, /*subframeSize*/ | ||
290 | 8, /*lpcSize*/ | ||
291 | #ifdef FIXED_POINT | ||
292 | 29491, 19661, /* gamma1, gamma2 */ | ||
293 | #else | ||
294 | 0.9, 0.6, /* gamma1, gamma2 */ | ||
295 | #endif | ||
296 | QCONST16(.0002,15), /*lpc_floor*/ | ||
297 | QCONST16(0.7f,15), | ||
298 | {NULL, &wb_submode1, NULL, NULL, NULL, NULL, NULL, NULL}, | ||
299 | 1, | ||
300 | {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, | ||
301 | {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, | ||
302 | #ifndef DISABLE_VBR | ||
303 | vbr_uhb_thresh, | ||
304 | #endif | ||
305 | 2 | ||
306 | }; | ||
307 | #endif | ||
308 | |||
309 | int wb_mode_query(const void *mode, int request, void *ptr) | ||
310 | { | ||
311 | const SpeexSBMode *m = (const SpeexSBMode*)mode; | ||
312 | |||
313 | switch (request) | ||
314 | { | ||
315 | case SPEEX_MODE_FRAME_SIZE: | ||
316 | *((int*)ptr)=2*m->frameSize; | ||
317 | break; | ||
318 | case SPEEX_SUBMODE_BITS_PER_FRAME: | ||
319 | if (*((int*)ptr)==0) | ||
320 | *((int*)ptr) = SB_SUBMODE_BITS+1; | ||
321 | else if (m->submodes[*((int*)ptr)]==NULL) | ||
322 | *((int*)ptr) = -1; | ||
323 | else | ||
324 | *((int*)ptr) = m->submodes[*((int*)ptr)]->bits_per_frame; | ||
325 | break; | ||
326 | default: | ||
327 | speex_warning_int("Unknown wb_mode_query request: ", request); | ||
328 | return -1; | ||
329 | } | ||
330 | return 0; | ||
331 | } | ||
332 | |||
333 | |||
334 | #ifndef ROCKBOX_VOICE_CODEC | ||
335 | const SpeexMode speex_uwb_mode = { | ||
336 | &sb_uwb_mode, | ||
337 | wb_mode_query, | ||
338 | "ultra-wideband (sub-band CELP)", | ||
339 | 2, | ||
340 | 4, | ||
341 | #ifndef SPEEX_DISABLE_ENCODER | ||
342 | &sb_encoder_init, | ||
343 | &sb_encoder_destroy, | ||
344 | &sb_encode, | ||
345 | &sb_decoder_init, | ||
346 | &sb_decoder_destroy, | ||
347 | &sb_decode, | ||
348 | &sb_encoder_ctl, | ||
349 | &sb_decoder_ctl, | ||
350 | #else | ||
351 | /* NULL, | ||
352 | NULL, | ||
353 | NULL, */ | ||
354 | &sb_decoder_init, | ||
355 | &sb_decoder_destroy, | ||
356 | &sb_decode, | ||
357 | /* NULL, */ | ||
358 | &sb_decoder_ctl, | ||
359 | #endif | ||
360 | }; | ||
361 | #endif | ||
362 | |||
363 | /* We have defined speex_lib_get_mode() as a macro in speex.h */ | ||
364 | #undef speex_lib_get_mode | ||
365 | |||
366 | const SpeexMode * speex_lib_get_mode (int mode) | ||
367 | { | ||
368 | if (mode < 0 || mode >= SPEEX_NB_MODES) return NULL; | ||
369 | |||
370 | return speex_mode_list[mode]; | ||
371 | } | ||
372 | |||
373 | |||
374 | |||