1 /* Copyright (C) 2002-2006 Jean-Marc Valin
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
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.
36 #include "config-speex.h"
41 #include "quant_lsp.h"
42 #include "cb_search.h"
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
= {
72 /* Parameters for Long-Term Prediction (LTP)*/
73 static const ltp_params ltp_params_vlbr
= {
79 /* Parameters for Long-Term Prediction (LTP)*/
80 static const ltp_params ltp_params_lbr
= {
86 /* Parameters for Long-Term Prediction (LTP)*/
87 static const ltp_params ltp_params_med
= {
93 /* Split-VQ innovation parameters for very low bit-rate narrowband */
94 static const split_cb_params split_cb_nb_vlbr
= {
97 exc_10_16_table
, /*shape_cb*/
102 /* Split-VQ innovation parameters for very low bit-rate narrowband */
103 static const split_cb_params split_cb_nb_ulbr
= {
106 exc_20_32_table
, /*shape_cb*/
111 /* Split-VQ innovation parameters for low bit-rate narrowband */
112 static const split_cb_params split_cb_nb_lbr
= {
115 exc_10_32_table
, /*shape_cb*/
121 /* Split-VQ innovation parameters narrowband */
122 static const split_cb_params split_cb_nb
= {
125 exc_5_64_table
, /*shape_cb*/
130 /* Split-VQ innovation parameters narrowband */
131 static const split_cb_params split_cb_nb_med
= {
134 exc_8_128_table
, /*shape_cb*/
139 /* Split-VQ innovation for low-band wideband */
140 static const split_cb_params split_cb_sb
= {
143 exc_5_256_table
, /*shape_cb*/
150 /* 2150 bps "vocoder-like" mode for comfort noise */
151 static const SpeexSubmode nb_submode1
= {
156 #ifndef SPEEX_DISABLE_ENCODER
157 /* LSP quantization */
160 /* No pitch quantization */
162 forced_pitch_unquant
,
164 /* No innovation quantization (noise only) */
165 noise_codebook_quant
,
166 noise_codebook_unquant
,
168 /* LSP quantization */
171 /* No pitch quantization */
173 forced_pitch_unquant
,
175 /* No innovation quantization (noise only) */
177 noise_codebook_unquant
,
184 /* 3.95 kbps very low bit-rate mode */
185 static const SpeexSubmode nb_submode8
= {
190 #ifndef SPEEX_DISABLE_ENCODER
194 /*No pitch quantization*/
196 forced_pitch_unquant
,
198 /*Innovation quantization*/
199 split_cb_search_shape_sign
,
200 split_cb_shape_sign_unquant
,
206 /*No pitch quantization*/
208 forced_pitch_unquant
,
210 /*Innovation quantization*/
212 split_cb_shape_sign_unquant
,
219 /* 5.95 kbps very low bit-rate mode */
220 static const SpeexSubmode nb_submode2
= {
225 #ifndef SPEEX_DISABLE_ENCODER
229 /*No pitch quantization*/
233 /*Innovation quantization*/
234 split_cb_search_shape_sign
,
235 split_cb_shape_sign_unquant
,
241 /*No pitch quantization*/
245 /*Innovation quantization*/
247 split_cb_shape_sign_unquant
,
254 /* 8 kbps low bit-rate mode */
255 static const SpeexSubmode nb_submode3
= {
260 #ifndef SPEEX_DISABLE_ENCODER
264 /*Pitch quantization*/
268 /*Innovation quantization*/
269 split_cb_search_shape_sign
,
270 split_cb_shape_sign_unquant
,
276 /*Pitch quantization*/
280 /*Innovation quantization*/
282 split_cb_shape_sign_unquant
,
289 /* 11 kbps medium bit-rate mode */
290 static const SpeexSubmode nb_submode4
= {
295 #ifndef SPEEX_DISABLE_ENCODER
299 /*Pitch quantization*/
303 /*Innovation quantization*/
304 split_cb_search_shape_sign
,
305 split_cb_shape_sign_unquant
,
311 /*Pitch quantization*/
315 /*Innovation quantization*/
317 split_cb_shape_sign_unquant
,
324 /* 15 kbps high bit-rate mode */
325 static const SpeexSubmode nb_submode5
= {
330 #ifndef SPEEX_DISABLE_ENCODER
334 /*Pitch quantization*/
338 /*Innovation quantization*/
339 split_cb_search_shape_sign
,
340 split_cb_shape_sign_unquant
,
346 /*Pitch quantization*/
350 /*Innovation quantization*/
352 split_cb_shape_sign_unquant
,
359 /* 18.2 high bit-rate mode */
360 static const SpeexSubmode nb_submode6
= {
365 #ifndef SPEEX_DISABLE_ENCODER
369 /*Pitch quantization*/
373 /*Innovation quantization*/
374 split_cb_search_shape_sign
,
375 split_cb_shape_sign_unquant
,
381 /*Pitch quantization*/
385 /*Innovation quantization*/
387 split_cb_shape_sign_unquant
,
394 /* 24.6 kbps high bit-rate mode */
395 static const SpeexSubmode nb_submode7
= {
400 #ifndef SPEEX_DISABLE_ENCODER
404 /*Pitch quantization*/
408 /*Innovation quantization*/
409 split_cb_search_shape_sign
,
410 split_cb_shape_sign_unquant
,
416 /*Pitch quantization*/
420 /*Innovation quantization*/
422 split_cb_shape_sign_unquant
,
430 /* Default mode for narrowband */
431 static const SpeexNBMode nb_mode
= {
438 29491, 19661, /* gamma1, gamma2 */
440 0.9, 0.6, /* gamma1, gamma2 */
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
= {
457 #ifndef SPEEX_DISABLE_ENCODER
480 int speex_mode_query(const SpeexMode
*mode
, int request
, void *ptr
)
482 return mode
->query(mode
->mode
, request
, ptr
);