summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libspeex/modes.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/libspeex/modes.c')
-rw-r--r--lib/rbcodec/codecs/libspeex/modes.c484
1 files changed, 484 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libspeex/modes.c b/lib/rbcodec/codecs/libspeex/modes.c
new file mode 100644
index 0000000000..d1046f1cfb
--- /dev/null
+++ b/lib/rbcodec/codecs/libspeex/modes.c
@@ -0,0 +1,484 @@
1/* Copyright (C) 2002-2006 Jean-Marc Valin
2 File: modes.c
3
4 Describes the different 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
49#ifndef NULL
50#define NULL 0
51#endif
52
53
54/* Extern declarations for all codebooks we use here */
55extern const signed char gain_cdbk_nb[];
56extern const signed char gain_cdbk_lbr[];
57extern const signed char exc_5_256_table[];
58extern const signed char exc_5_64_table[];
59extern const signed char exc_8_128_table[];
60extern const signed char exc_10_32_table[];
61extern const signed char exc_10_16_table[];
62extern const signed char exc_20_32_table[];
63
64
65/* Parameters for Long-Term Prediction (LTP)*/
66static const ltp_params ltp_params_nb = {
67 gain_cdbk_nb,
68 7,
69 7
70};
71
72/* Parameters for Long-Term Prediction (LTP)*/
73static const ltp_params ltp_params_vlbr = {
74 gain_cdbk_lbr,
75 5,
76 0
77};
78
79/* Parameters for Long-Term Prediction (LTP)*/
80static const ltp_params ltp_params_lbr = {
81 gain_cdbk_lbr,
82 5,
83 7
84};
85
86/* Parameters for Long-Term Prediction (LTP)*/
87static const ltp_params ltp_params_med = {
88 gain_cdbk_lbr,
89 5,
90 7
91};
92
93/* Split-VQ innovation parameters for very low bit-rate narrowband */
94static 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*/
99 0,
100};
101
102/* Split-VQ innovation parameters for very low bit-rate narrowband */
103static 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*/
108 0,
109};
110
111/* Split-VQ innovation parameters for low bit-rate narrowband */
112static 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*/
117 0,
118};
119
120
121/* Split-VQ innovation parameters narrowband */
122static 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*/
127 0,
128};
129
130/* Split-VQ innovation parameters narrowband */
131static 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*/
136 0,
137};
138
139/* Split-VQ innovation for low-band wideband */
140static 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*/
145 0,
146};
147
148
149
150/* 2150 bps "vocoder-like" mode for comfort noise */
151static const SpeexSubmode nb_submode1 = {
152 0,
153 1,
154 0,
155 0,
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,
180 -1,
181 43
182};
183
184/* 3.95 kbps very low bit-rate mode */
185static const SpeexSubmode nb_submode8 = {
186 0,
187 1,
188 0,
189 0,
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),
216 79
217};
218
219/* 5.95 kbps very low bit-rate mode */
220static const SpeexSubmode nb_submode2 = {
221 0,
222 0,
223 0,
224 0,
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),
251 119
252};
253
254/* 8 kbps low bit-rate mode */
255static const SpeexSubmode nb_submode3 = {
256 -1,
257 0,
258 1,
259 0,
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),
286 160
287};
288
289/* 11 kbps medium bit-rate mode */
290static const SpeexSubmode nb_submode4 = {
291 -1,
292 0,
293 1,
294 0,
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),
321 220
322};
323
324/* 15 kbps high bit-rate mode */
325static const SpeexSubmode nb_submode5 = {
326 -1,
327 0,
328 3,
329 0,
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),
356 300
357};
358
359/* 18.2 high bit-rate mode */
360static const SpeexSubmode nb_submode6 = {
361 -1,
362 0,
363 3,
364 0,
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),
391 364
392};
393
394/* 24.6 kbps high bit-rate mode */
395static const SpeexSubmode nb_submode7 = {
396 -1,
397 0,
398 3,
399 1,
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),
426 492
427};
428
429
430/* Default mode for narrowband */
431static 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},
445 5,
446 {1, 8, 2, 3, 3, 4, 4, 5, 5, 6, 7}
447};
448
449
450/* Default mode for narrowband */
451const SpeexMode speex_nb_mode = {
452 &nb_mode,
453 nb_mode_query,
454 "narrowband",
455 0,
456 4,
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
476};
477
478
479
480int speex_mode_query(const SpeexMode *mode, int request, void *ptr)
481{
482 return mode->query(mode->mode, request, ptr);
483}
484