FS#8961 - Anti-Aliased Fonts.
[kugel-rb/myfork.git] / apps / codecs / libspeex / modes.c
blob20ea287344b03fbf5efe137bf5d1da9ca4041118
1 /* Copyright (C) 2002-2006 Jean-Marc Valin
2 File: modes.c
4 Describes the different modes of the codec
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
10 - Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
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.
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.
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.
35 #ifdef HAVE_CONFIG_H
36 #include "config-speex.h"
37 #endif
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>
49 #ifndef NULL
50 #define NULL 0
51 #endif
54 /* Extern declarations for all codebooks we use here */
55 extern const signed char gain_cdbk_nb[];
56 extern const signed char gain_cdbk_lbr[];
57 extern const signed char exc_5_256_table[];
58 extern const signed char exc_5_64_table[];
59 extern const signed char exc_8_128_table[];
60 extern const signed char exc_10_32_table[];
61 extern const signed char exc_10_16_table[];
62 extern const signed char exc_20_32_table[];
65 /* Parameters for Long-Term Prediction (LTP)*/
66 static const ltp_params ltp_params_nb = {
67 gain_cdbk_nb,
72 /* Parameters for Long-Term Prediction (LTP)*/
73 static const ltp_params ltp_params_vlbr = {
74 gain_cdbk_lbr,
79 /* Parameters for Long-Term Prediction (LTP)*/
80 static const ltp_params ltp_params_lbr = {
81 gain_cdbk_lbr,
86 /* Parameters for Long-Term Prediction (LTP)*/
87 static const ltp_params ltp_params_med = {
88 gain_cdbk_lbr,
93 /* Split-VQ innovation parameters for very low bit-rate narrowband */
94 static const split_cb_params split_cb_nb_vlbr = {
95 10, /*subvect_size*/
96 4, /*nb_subvect*/
97 exc_10_16_table, /*shape_cb*/
98 4, /*shape_bits*/
102 /* Split-VQ innovation parameters for very low bit-rate narrowband */
103 static const split_cb_params split_cb_nb_ulbr = {
104 20, /*subvect_size*/
105 2, /*nb_subvect*/
106 exc_20_32_table, /*shape_cb*/
107 5, /*shape_bits*/
111 /* Split-VQ innovation parameters for low bit-rate narrowband */
112 static const split_cb_params split_cb_nb_lbr = {
113 10, /*subvect_size*/
114 4, /*nb_subvect*/
115 exc_10_32_table, /*shape_cb*/
116 5, /*shape_bits*/
121 /* Split-VQ innovation parameters narrowband */
122 static const split_cb_params split_cb_nb = {
123 5, /*subvect_size*/
124 8, /*nb_subvect*/
125 exc_5_64_table, /*shape_cb*/
126 6, /*shape_bits*/
130 /* Split-VQ innovation parameters narrowband */
131 static const split_cb_params split_cb_nb_med = {
132 8, /*subvect_size*/
133 5, /*nb_subvect*/
134 exc_8_128_table, /*shape_cb*/
135 7, /*shape_bits*/
139 /* Split-VQ innovation for low-band wideband */
140 static const split_cb_params split_cb_sb = {
141 5, /*subvect_size*/
142 8, /*nb_subvect*/
143 exc_5_256_table, /*shape_cb*/
144 8, /*shape_bits*/
150 /* 2150 bps "vocoder-like" mode for comfort noise */
151 static const SpeexSubmode nb_submode1 = {
156 #ifndef SPEEX_DISABLE_ENCODER
157 /* LSP quantization */
158 lsp_quant_lbr,
159 lsp_unquant_lbr,
160 /* No pitch quantization */
161 forced_pitch_quant,
162 forced_pitch_unquant,
163 NULL,
164 /* No innovation quantization (noise only) */
165 noise_codebook_quant,
166 noise_codebook_unquant,
167 #else
168 /* LSP quantization */
169 NULL,
170 lsp_unquant_lbr,
171 /* No pitch quantization */
172 NULL,
173 forced_pitch_unquant,
174 NULL,
175 /* No innovation quantization (noise only) */
176 NULL,
177 noise_codebook_unquant,
178 #endif
179 NULL,
184 /* 3.95 kbps very low bit-rate mode */
185 static const SpeexSubmode nb_submode8 = {
190 #ifndef SPEEX_DISABLE_ENCODER
191 /*LSP quantization*/
192 lsp_quant_lbr,
193 lsp_unquant_lbr,
194 /*No pitch quantization*/
195 forced_pitch_quant,
196 forced_pitch_unquant,
197 NULL,
198 /*Innovation quantization*/
199 split_cb_search_shape_sign,
200 split_cb_shape_sign_unquant,
201 &split_cb_nb_ulbr,
202 #else
203 /*LSP quantization*/
204 NULL,
205 lsp_unquant_lbr,
206 /*No pitch quantization*/
207 NULL,
208 forced_pitch_unquant,
209 NULL,
210 /*Innovation quantization*/
211 NULL,
212 split_cb_shape_sign_unquant,
213 &split_cb_nb_ulbr,
214 #endif
215 QCONST16(.5,15),
219 /* 5.95 kbps very low bit-rate mode */
220 static const SpeexSubmode nb_submode2 = {
225 #ifndef SPEEX_DISABLE_ENCODER
226 /*LSP quantization*/
227 lsp_quant_lbr,
228 lsp_unquant_lbr,
229 /*No pitch quantization*/
230 pitch_search_3tap,
231 pitch_unquant_3tap,
232 &ltp_params_vlbr,
233 /*Innovation quantization*/
234 split_cb_search_shape_sign,
235 split_cb_shape_sign_unquant,
236 &split_cb_nb_vlbr,
237 #else
238 /*LSP quantization*/
239 NULL,
240 lsp_unquant_lbr,
241 /*No pitch quantization*/
242 NULL,
243 pitch_unquant_3tap,
244 &ltp_params_vlbr,
245 /*Innovation quantization*/
246 NULL,
247 split_cb_shape_sign_unquant,
248 &split_cb_nb_vlbr,
249 #endif
250 QCONST16(.6,15),
254 /* 8 kbps low bit-rate mode */
255 static const SpeexSubmode nb_submode3 = {
260 #ifndef SPEEX_DISABLE_ENCODER
261 /*LSP quantization*/
262 lsp_quant_lbr,
263 lsp_unquant_lbr,
264 /*Pitch quantization*/
265 pitch_search_3tap,
266 pitch_unquant_3tap,
267 &ltp_params_lbr,
268 /*Innovation quantization*/
269 split_cb_search_shape_sign,
270 split_cb_shape_sign_unquant,
271 &split_cb_nb_lbr,
272 #else
273 /*LSP quantization*/
274 NULL,
275 lsp_unquant_lbr,
276 /*Pitch quantization*/
277 NULL,
278 pitch_unquant_3tap,
279 &ltp_params_lbr,
280 /*Innovation quantization*/
281 NULL,
282 split_cb_shape_sign_unquant,
283 &split_cb_nb_lbr,
284 #endif
285 QCONST16(.55,15),
289 /* 11 kbps medium bit-rate mode */
290 static const SpeexSubmode nb_submode4 = {
295 #ifndef SPEEX_DISABLE_ENCODER
296 /*LSP quantization*/
297 lsp_quant_lbr,
298 lsp_unquant_lbr,
299 /*Pitch quantization*/
300 pitch_search_3tap,
301 pitch_unquant_3tap,
302 &ltp_params_med,
303 /*Innovation quantization*/
304 split_cb_search_shape_sign,
305 split_cb_shape_sign_unquant,
306 &split_cb_nb_med,
307 #else
308 /*LSP quantization*/
309 NULL,
310 lsp_unquant_lbr,
311 /*Pitch quantization*/
312 NULL,
313 pitch_unquant_3tap,
314 &ltp_params_med,
315 /*Innovation quantization*/
316 NULL,
317 split_cb_shape_sign_unquant,
318 &split_cb_nb_med,
319 #endif
320 QCONST16(.45,15),
324 /* 15 kbps high bit-rate mode */
325 static const SpeexSubmode nb_submode5 = {
330 #ifndef SPEEX_DISABLE_ENCODER
331 /*LSP quantization*/
332 lsp_quant_nb,
333 lsp_unquant_nb,
334 /*Pitch quantization*/
335 pitch_search_3tap,
336 pitch_unquant_3tap,
337 &ltp_params_nb,
338 /*Innovation quantization*/
339 split_cb_search_shape_sign,
340 split_cb_shape_sign_unquant,
341 &split_cb_nb,
342 #else
343 /*LSP quantization*/
344 NULL,
345 lsp_unquant_nb,
346 /*Pitch quantization*/
347 NULL,
348 pitch_unquant_3tap,
349 &ltp_params_nb,
350 /*Innovation quantization*/
351 NULL,
352 split_cb_shape_sign_unquant,
353 &split_cb_nb,
354 #endif
355 QCONST16(.3,15),
359 /* 18.2 high bit-rate mode */
360 static const SpeexSubmode nb_submode6 = {
365 #ifndef SPEEX_DISABLE_ENCODER
366 /*LSP quantization*/
367 lsp_quant_nb,
368 lsp_unquant_nb,
369 /*Pitch quantization*/
370 pitch_search_3tap,
371 pitch_unquant_3tap,
372 &ltp_params_nb,
373 /*Innovation quantization*/
374 split_cb_search_shape_sign,
375 split_cb_shape_sign_unquant,
376 &split_cb_sb,
377 #else
378 /*LSP quantization*/
379 NULL,
380 lsp_unquant_nb,
381 /*Pitch quantization*/
382 NULL,
383 pitch_unquant_3tap,
384 &ltp_params_nb,
385 /*Innovation quantization*/
386 NULL,
387 split_cb_shape_sign_unquant,
388 &split_cb_sb,
389 #endif
390 QCONST16(.2,15),
394 /* 24.6 kbps high bit-rate mode */
395 static const SpeexSubmode nb_submode7 = {
400 #ifndef SPEEX_DISABLE_ENCODER
401 /*LSP quantization*/
402 lsp_quant_nb,
403 lsp_unquant_nb,
404 /*Pitch quantization*/
405 pitch_search_3tap,
406 pitch_unquant_3tap,
407 &ltp_params_nb,
408 /*Innovation quantization*/
409 split_cb_search_shape_sign,
410 split_cb_shape_sign_unquant,
411 &split_cb_nb,
412 #else
413 /*LSP quantization*/
414 NULL,
415 lsp_unquant_nb,
416 /*Pitch quantization*/
417 NULL,
418 pitch_unquant_3tap,
419 &ltp_params_nb,
420 /*Innovation quantization*/
421 NULL,
422 split_cb_shape_sign_unquant,
423 &split_cb_nb,
424 #endif
425 QCONST16(.1,15),
430 /* Default mode for narrowband */
431 static const SpeexNBMode nb_mode = {
432 160, /*frameSize*/
433 40, /*subframeSize*/
434 10, /*lpcSize*/
435 17, /*pitchStart*/
436 144, /*pitchEnd*/
437 #ifdef FIXED_POINT
438 29491, 19661, /* gamma1, gamma2 */
439 #else
440 0.9, 0.6, /* gamma1, gamma2 */
441 #endif
442 QCONST16(.0002,15), /*lpc_floor*/
443 {NULL, &nb_submode1, &nb_submode2, &nb_submode3, &nb_submode4, &nb_submode5, &nb_submode6, &nb_submode7,
444 &nb_submode8, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
446 {1, 8, 2, 3, 3, 4, 4, 5, 5, 6, 7}
450 /* Default mode for narrowband */
451 const SpeexMode speex_nb_mode = {
452 &nb_mode,
453 nb_mode_query,
454 "narrowband",
457 #ifndef SPEEX_DISABLE_ENCODER
458 &nb_encoder_init,
459 &nb_encoder_destroy,
460 &nb_encode,
461 &nb_decoder_init,
462 &nb_decoder_destroy,
463 &nb_decode,
464 &nb_encoder_ctl,
465 &nb_decoder_ctl,
466 #else
467 NULL,
468 NULL,
469 NULL,
470 &nb_decoder_init,
471 &nb_decoder_destroy,
472 &nb_decode,
473 NULL,
474 &nb_decoder_ctl,
475 #endif
480 int speex_mode_query(const SpeexMode *mode, int request, void *ptr)
482 return mode->query(mode->mode, request, ptr);