Use CACHEALIGN_BITS to calculate CACHEALIGN_SIZE instead of directly setting it.
[maemo-rb.git] / apps / codecs / libspeex / modes_wb.c
blob7fac15b8526d2c8ba30ce69ca1d7dfe55e285fbb
1 /* Copyright (C) 2002-2007 Jean-Marc Valin
2 File: modes.c
4 Describes the wideband 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>
48 #include "os_support.h"
51 #ifndef NULL
52 #define NULL 0
53 #endif
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
61 extern const signed char hexc_table[];
62 extern const signed char hexc_10_32_table[];
64 #ifndef DISABLE_WIDEBAND
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*/
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*/
85 #endif
88 static const SpeexSubmode wb_submode1 = {
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,
114 static const SpeexSubmode wb_submode2 = {
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
152 static const SpeexSubmode wb_submode3 = {
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
189 static const SpeexSubmode wb_submode4 = {
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
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},
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
251 const SpeexMode speex_wb_mode = {
252 &sb_wb_mode,
253 wb_mode_query,
254 "wideband (sub-band CELP)",
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
280 /* "Ultra-wideband" mode stuff */
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},
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
307 #endif
309 int wb_mode_query(const void *mode, int request, void *ptr)
311 const SpeexSBMode *m = (const SpeexSBMode*)mode;
313 switch (request)
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;
330 return 0;
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)",
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
361 #endif
363 /* We have defined speex_lib_get_mode() as a macro in speex.h */
364 #undef speex_lib_get_mode
366 const SpeexMode * speex_lib_get_mode (int mode)
368 if (mode < 0 || mode >= SPEEX_NB_MODES) return NULL;
370 return speex_mode_list[mode];