| 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.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 |
#if defined(DISABLE_ENCODER) || defined(DISABLE_WIDEBAND) |
| 56 |
#define split_cb_search_shape_sign NULL |
| 57 |
#define noise_codebook_quant NULL |
| 58 |
#define pitch_search_3tap NULL |
| 59 |
#define forced_pitch_quant NULL |
| 60 |
#define sb_encoder_init NULL |
| 61 |
#define sb_encoder_destroy NULL |
| 62 |
#define sb_encode NULL |
| 63 |
#define sb_encoder_ctl NULL |
| 64 |
#define lsp_quant_high NULL |
| 65 |
#endif /* DISABLE_ENCODER */ |
| 66 |
|
| 67 |
#if defined(DISABLE_DECODER) || defined(DISABLE_WIDEBAND) |
| 68 |
#define noise_codebook_unquant NULL |
| 69 |
#define split_cb_shape_sign_unquant NULL |
| 70 |
#define lsp_unquant_high NULL |
| 71 |
#define sb_decoder_init NULL |
| 72 |
#define sb_decoder_destroy NULL |
| 73 |
#define sb_decode NULL |
| 74 |
#define sb_decoder_ctl NULL |
| 75 |
#endif /* DISABLE_DECODER */ |
| 76 |
|
| 77 |
EXPORT const SpeexMode * const speex_mode_list[SPEEX_NB_MODES] = {&speex_nb_mode, &speex_wb_mode, &speex_uwb_mode}; |
| 78 |
|
| 79 |
extern const signed char hexc_table[]; |
| 80 |
extern const signed char hexc_10_32_table[]; |
| 81 |
|
| 82 |
#ifndef DISABLE_WIDEBAND |
| 83 |
|
| 84 |
/* Split-VQ innovation for high-band wideband */ |
| 85 |
static const split_cb_params split_cb_high = { |
| 86 |
8, /*subvect_size*/ |
| 87 |
5, /*nb_subvect*/ |
| 88 |
hexc_table, /*shape_cb*/ |
| 89 |
7, /*shape_bits*/ |
| 90 |
1, |
| 91 |
}; |
| 92 |
|
| 93 |
|
| 94 |
/* Split-VQ innovation for high-band wideband */ |
| 95 |
static const split_cb_params split_cb_high_lbr = { |
| 96 |
10, /*subvect_size*/ |
| 97 |
4, /*nb_subvect*/ |
| 98 |
hexc_10_32_table, /*shape_cb*/ |
| 99 |
5, /*shape_bits*/ |
| 100 |
0, |
| 101 |
}; |
| 102 |
|
| 103 |
#endif |
| 104 |
|
| 105 |
|
| 106 |
static const SpeexSubmode wb_submode1 = { |
| 107 |
0, |
| 108 |
0, |
| 109 |
1, |
| 110 |
0, |
| 111 |
/*LSP quantization*/ |
| 112 |
lsp_quant_high, |
| 113 |
lsp_unquant_high, |
| 114 |
/*Pitch quantization*/ |
| 115 |
NULL, |
| 116 |
NULL, |
| 117 |
NULL, |
| 118 |
/*No innovation quantization*/ |
| 119 |
NULL, |
| 120 |
NULL, |
| 121 |
NULL, |
| 122 |
-1, |
| 123 |
36 |
| 124 |
}; |
| 125 |
|
| 126 |
|
| 127 |
static const SpeexSubmode wb_submode2 = { |
| 128 |
0, |
| 129 |
0, |
| 130 |
1, |
| 131 |
0, |
| 132 |
/*LSP quantization*/ |
| 133 |
lsp_quant_high, |
| 134 |
lsp_unquant_high, |
| 135 |
/*Pitch quantization*/ |
| 136 |
NULL, |
| 137 |
NULL, |
| 138 |
NULL, |
| 139 |
/*Innovation quantization*/ |
| 140 |
split_cb_search_shape_sign, |
| 141 |
split_cb_shape_sign_unquant, |
| 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 |
/*LSP quantization*/ |
| 158 |
lsp_quant_high, |
| 159 |
lsp_unquant_high, |
| 160 |
/*Pitch quantization*/ |
| 161 |
NULL, |
| 162 |
NULL, |
| 163 |
NULL, |
| 164 |
/*Innovation quantization*/ |
| 165 |
split_cb_search_shape_sign, |
| 166 |
split_cb_shape_sign_unquant, |
| 167 |
#ifdef DISABLE_WIDEBAND |
| 168 |
NULL, |
| 169 |
#else |
| 170 |
&split_cb_high, |
| 171 |
#endif |
| 172 |
-1, |
| 173 |
192 |
| 174 |
}; |
| 175 |
|
| 176 |
static const SpeexSubmode wb_submode4 = { |
| 177 |
0, |
| 178 |
0, |
| 179 |
1, |
| 180 |
1, |
| 181 |
/*LSP quantization*/ |
| 182 |
lsp_quant_high, |
| 183 |
lsp_unquant_high, |
| 184 |
/*Pitch quantization*/ |
| 185 |
NULL, |
| 186 |
NULL, |
| 187 |
NULL, |
| 188 |
/*Innovation quantization*/ |
| 189 |
split_cb_search_shape_sign, |
| 190 |
split_cb_shape_sign_unquant, |
| 191 |
#ifdef DISABLE_WIDEBAND |
| 192 |
NULL, |
| 193 |
#else |
| 194 |
&split_cb_high, |
| 195 |
#endif |
| 196 |
-1, |
| 197 |
352 |
| 198 |
}; |
| 199 |
|
| 200 |
|
| 201 |
/* Split-band wideband CELP mode*/ |
| 202 |
static const SpeexSBMode sb_wb_mode = { |
| 203 |
&speex_nb_mode, |
| 204 |
160, /*frameSize*/ |
| 205 |
40, /*subframeSize*/ |
| 206 |
8, /*lpcSize*/ |
| 207 |
#ifdef FIXED_POINT |
| 208 |
29491, 19661, /* gamma1, gamma2 */ |
| 209 |
#else |
| 210 |
0.9, 0.6, /* gamma1, gamma2 */ |
| 211 |
#endif |
| 212 |
QCONST16(.0002,15), /*lpc_floor*/ |
| 213 |
QCONST16(0.9f,15), |
| 214 |
{NULL, &wb_submode1, &wb_submode2, &wb_submode3, &wb_submode4, NULL, NULL, NULL}, |
| 215 |
3, |
| 216 |
{1, 8, 2, 3, 4, 5, 5, 6, 6, 7, 7}, |
| 217 |
{1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 4}, |
| 218 |
#ifndef DISABLE_VBR |
| 219 |
vbr_hb_thresh, |
| 220 |
#endif |
| 221 |
5 |
| 222 |
}; |
| 223 |
|
| 224 |
|
| 225 |
EXPORT const SpeexMode speex_wb_mode = { |
| 226 |
&sb_wb_mode, |
| 227 |
wb_mode_query, |
| 228 |
"wideband (sub-band CELP)", |
| 229 |
1, |
| 230 |
4, |
| 231 |
sb_encoder_init, |
| 232 |
sb_encoder_destroy, |
| 233 |
sb_encode, |
| 234 |
sb_decoder_init, |
| 235 |
sb_decoder_destroy, |
| 236 |
sb_decode, |
| 237 |
sb_encoder_ctl, |
| 238 |
sb_decoder_ctl, |
| 239 |
}; |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
/* "Ultra-wideband" mode stuff */ |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
/* Split-band "ultra-wideband" (32 kbps) CELP mode*/ |
| 248 |
static const SpeexSBMode sb_uwb_mode = { |
| 249 |
&speex_wb_mode, |
| 250 |
320, /*frameSize*/ |
| 251 |
80, /*subframeSize*/ |
| 252 |
8, /*lpcSize*/ |
| 253 |
#ifdef FIXED_POINT |
| 254 |
29491, 19661, /* gamma1, gamma2 */ |
| 255 |
#else |
| 256 |
0.9, 0.6, /* gamma1, gamma2 */ |
| 257 |
#endif |
| 258 |
QCONST16(.0002,15), /*lpc_floor*/ |
| 259 |
QCONST16(0.7f,15), |
| 260 |
{NULL, &wb_submode1, NULL, NULL, NULL, NULL, NULL, NULL}, |
| 261 |
1, |
| 262 |
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, |
| 263 |
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, |
| 264 |
#ifndef DISABLE_VBR |
| 265 |
vbr_uhb_thresh, |
| 266 |
#endif |
| 267 |
2 |
| 268 |
}; |
| 269 |
|
| 270 |
int wb_mode_query(const void *mode, int request, void *ptr) |
| 271 |
{ |
| 272 |
const SpeexSBMode *m = (const SpeexSBMode*)mode; |
| 273 |
|
| 274 |
switch (request) |
| 275 |
{ |
| 276 |
case SPEEX_MODE_FRAME_SIZE: |
| 277 |
*((int*)ptr)=2*m->frameSize; |
| 278 |
break; |
| 279 |
case SPEEX_SUBMODE_BITS_PER_FRAME: |
| 280 |
if (*((int*)ptr)==0) |
| 281 |
*((int*)ptr) = SB_SUBMODE_BITS+1; |
| 282 |
else if (m->submodes[*((int*)ptr)]==NULL) |
| 283 |
*((int*)ptr) = -1; |
| 284 |
else |
| 285 |
*((int*)ptr) = m->submodes[*((int*)ptr)]->bits_per_frame; |
| 286 |
break; |
| 287 |
default: |
| 288 |
speex_warning_int("Unknown wb_mode_query request: ", request); |
| 289 |
return -1; |
| 290 |
} |
| 291 |
return 0; |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
EXPORT const SpeexMode speex_uwb_mode = { |
| 296 |
&sb_uwb_mode, |
| 297 |
wb_mode_query, |
| 298 |
"ultra-wideband (sub-band CELP)", |
| 299 |
2, |
| 300 |
4, |
| 301 |
sb_encoder_init, |
| 302 |
sb_encoder_destroy, |
| 303 |
sb_encode, |
| 304 |
sb_decoder_init, |
| 305 |
sb_decoder_destroy, |
| 306 |
sb_decode, |
| 307 |
sb_encoder_ctl, |
| 308 |
sb_decoder_ctl, |
| 309 |
}; |
| 310 |
|
| 311 |
/* We have defined speex_lib_get_mode() as a macro in speex.h */ |
| 312 |
#undef speex_lib_get_mode |
| 313 |
|
| 314 |
EXPORT const SpeexMode * speex_lib_get_mode (int mode) |
| 315 |
{ |
| 316 |
if (mode < 0 || mode >= SPEEX_NB_MODES) return NULL; |
| 317 |
|
| 318 |
return speex_mode_list[mode]; |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
|