rockbox/lib/rbcodec/codecs/libspeex/modes.c
Sean Bartell cadb3627fc Add rbcodecplatform.h and rbcodecconfig.h.
librbcodec users must provide these two files when the library is built.
rbcodecconfig.h provides configuration #defines and basic types, and
will be included by public librbcodec headers, so it must not conflict
with the user's code. rbcodecplatform.h provides various OS functions,
and will only be included by source files and private headers. This
system is intended to provide maximum flexibility for use on embedded
systems, where no operating system headers are included. Unix systems
can just copy rbcodecconfig-example.h and rbcodecplatform-unix.h with
minimal changes.

Change-Id: I350a2274d173da391fd1ca00c4202e9760d91def
Reviewed-on: http://gerrit.rockbox.org/143
Reviewed-by: Nils Wallménius <nils@rockbox.org>
Tested-by: Nils Wallménius <nils@rockbox.org>
2012-05-03 14:49:35 +02:00

486 lines
10 KiB
C

/* Copyright (C) 2002-2006 Jean-Marc Valin
File: modes.c
Describes the different modes of the codec
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include "config-speex.h"
#endif
#include "modes.h"
#include "ltp.h"
#include "quant_lsp.h"
#include "cb_search.h"
#include "sb_celp.h"
#include "nb_celp.h"
#include "vbr.h"
#include "arch.h"
#ifndef FIXED_POINT
#include <math.h>
#endif
#ifndef NULL
#define NULL 0
#endif
/* Extern declarations for all codebooks we use here */
extern const signed char gain_cdbk_nb[];
extern const signed char gain_cdbk_lbr[];
extern const signed char exc_5_256_table[];
extern const signed char exc_5_64_table[];
extern const signed char exc_8_128_table[];
extern const signed char exc_10_32_table[];
extern const signed char exc_10_16_table[];
extern const signed char exc_20_32_table[];
/* Parameters for Long-Term Prediction (LTP)*/
static const ltp_params ltp_params_nb = {
gain_cdbk_nb,
7,
7
};
/* Parameters for Long-Term Prediction (LTP)*/
static const ltp_params ltp_params_vlbr = {
gain_cdbk_lbr,
5,
0
};
/* Parameters for Long-Term Prediction (LTP)*/
static const ltp_params ltp_params_lbr = {
gain_cdbk_lbr,
5,
7
};
/* Parameters for Long-Term Prediction (LTP)*/
static const ltp_params ltp_params_med = {
gain_cdbk_lbr,
5,
7
};
/* Split-VQ innovation parameters for very low bit-rate narrowband */
static const split_cb_params split_cb_nb_vlbr = {
10, /*subvect_size*/
4, /*nb_subvect*/
exc_10_16_table, /*shape_cb*/
4, /*shape_bits*/
0,
};
/* Split-VQ innovation parameters for very low bit-rate narrowband */
static const split_cb_params split_cb_nb_ulbr = {
20, /*subvect_size*/
2, /*nb_subvect*/
exc_20_32_table, /*shape_cb*/
5, /*shape_bits*/
0,
};
/* Split-VQ innovation parameters for low bit-rate narrowband */
static const split_cb_params split_cb_nb_lbr = {
10, /*subvect_size*/
4, /*nb_subvect*/
exc_10_32_table, /*shape_cb*/
5, /*shape_bits*/
0,
};
/* Split-VQ innovation parameters narrowband */
static const split_cb_params split_cb_nb = {
5, /*subvect_size*/
8, /*nb_subvect*/
exc_5_64_table, /*shape_cb*/
6, /*shape_bits*/
0,
};
/* Split-VQ innovation parameters narrowband */
static const split_cb_params split_cb_nb_med = {
8, /*subvect_size*/
5, /*nb_subvect*/
exc_8_128_table, /*shape_cb*/
7, /*shape_bits*/
0,
};
/* Split-VQ innovation for low-band wideband */
static const split_cb_params split_cb_sb = {
5, /*subvect_size*/
8, /*nb_subvect*/
exc_5_256_table, /*shape_cb*/
8, /*shape_bits*/
0,
};
/* 2150 bps "vocoder-like" mode for comfort noise */
static const SpeexSubmode nb_submode1 = {
0,
1,
0,
0,
#ifndef SPEEX_DISABLE_ENCODER
/* LSP quantization */
lsp_quant_lbr,
lsp_unquant_lbr,
/* No pitch quantization */
forced_pitch_quant,
forced_pitch_unquant,
NULL,
/* No innovation quantization (noise only) */
noise_codebook_quant,
noise_codebook_unquant,
#else
/* LSP quantization */
NULL,
lsp_unquant_lbr,
/* No pitch quantization */
NULL,
forced_pitch_unquant,
NULL,
/* No innovation quantization (noise only) */
NULL,
noise_codebook_unquant,
#endif
NULL,
-1,
43
};
/* 3.95 kbps very low bit-rate mode */
static const SpeexSubmode nb_submode8 = {
0,
1,
0,
0,
#ifndef SPEEX_DISABLE_ENCODER
/*LSP quantization*/
lsp_quant_lbr,
lsp_unquant_lbr,
/*No pitch quantization*/
forced_pitch_quant,
forced_pitch_unquant,
NULL,
/*Innovation quantization*/
split_cb_search_shape_sign,
split_cb_shape_sign_unquant,
&split_cb_nb_ulbr,
#else
/*LSP quantization*/
NULL,
lsp_unquant_lbr,
/*No pitch quantization*/
NULL,
forced_pitch_unquant,
NULL,
/*Innovation quantization*/
NULL,
split_cb_shape_sign_unquant,
&split_cb_nb_ulbr,
#endif
QCONST16(.5,15),
79
};
/* 5.95 kbps very low bit-rate mode */
static const SpeexSubmode nb_submode2 = {
0,
0,
0,
0,
#ifndef SPEEX_DISABLE_ENCODER
/*LSP quantization*/
lsp_quant_lbr,
lsp_unquant_lbr,
/*No pitch quantization*/
pitch_search_3tap,
pitch_unquant_3tap,
&ltp_params_vlbr,
/*Innovation quantization*/
split_cb_search_shape_sign,
split_cb_shape_sign_unquant,
&split_cb_nb_vlbr,
#else
/*LSP quantization*/
NULL,
lsp_unquant_lbr,
/*No pitch quantization*/
NULL,
pitch_unquant_3tap,
&ltp_params_vlbr,
/*Innovation quantization*/
NULL,
split_cb_shape_sign_unquant,
&split_cb_nb_vlbr,
#endif
QCONST16(.6,15),
119
};
/* 8 kbps low bit-rate mode */
static const SpeexSubmode nb_submode3 = {
-1,
0,
1,
0,
#ifndef SPEEX_DISABLE_ENCODER
/*LSP quantization*/
lsp_quant_lbr,
lsp_unquant_lbr,
/*Pitch quantization*/
pitch_search_3tap,
pitch_unquant_3tap,
&ltp_params_lbr,
/*Innovation quantization*/
split_cb_search_shape_sign,
split_cb_shape_sign_unquant,
&split_cb_nb_lbr,
#else
/*LSP quantization*/
NULL,
lsp_unquant_lbr,
/*Pitch quantization*/
NULL,
pitch_unquant_3tap,
&ltp_params_lbr,
/*Innovation quantization*/
NULL,
split_cb_shape_sign_unquant,
&split_cb_nb_lbr,
#endif
QCONST16(.55,15),
160
};
/* 11 kbps medium bit-rate mode */
static const SpeexSubmode nb_submode4 = {
-1,
0,
1,
0,
#ifndef SPEEX_DISABLE_ENCODER
/*LSP quantization*/
lsp_quant_lbr,
lsp_unquant_lbr,
/*Pitch quantization*/
pitch_search_3tap,
pitch_unquant_3tap,
&ltp_params_med,
/*Innovation quantization*/
split_cb_search_shape_sign,
split_cb_shape_sign_unquant,
&split_cb_nb_med,
#else
/*LSP quantization*/
NULL,
lsp_unquant_lbr,
/*Pitch quantization*/
NULL,
pitch_unquant_3tap,
&ltp_params_med,
/*Innovation quantization*/
NULL,
split_cb_shape_sign_unquant,
&split_cb_nb_med,
#endif
QCONST16(.45,15),
220
};
/* 15 kbps high bit-rate mode */
static const SpeexSubmode nb_submode5 = {
-1,
0,
3,
0,
#ifndef SPEEX_DISABLE_ENCODER
/*LSP quantization*/
lsp_quant_nb,
lsp_unquant_nb,
/*Pitch quantization*/
pitch_search_3tap,
pitch_unquant_3tap,
&ltp_params_nb,
/*Innovation quantization*/
split_cb_search_shape_sign,
split_cb_shape_sign_unquant,
&split_cb_nb,
#else
/*LSP quantization*/
NULL,
lsp_unquant_nb,
/*Pitch quantization*/
NULL,
pitch_unquant_3tap,
&ltp_params_nb,
/*Innovation quantization*/
NULL,
split_cb_shape_sign_unquant,
&split_cb_nb,
#endif
QCONST16(.3,15),
300
};
/* 18.2 high bit-rate mode */
static const SpeexSubmode nb_submode6 = {
-1,
0,
3,
0,
#ifndef SPEEX_DISABLE_ENCODER
/*LSP quantization*/
lsp_quant_nb,
lsp_unquant_nb,
/*Pitch quantization*/
pitch_search_3tap,
pitch_unquant_3tap,
&ltp_params_nb,
/*Innovation quantization*/
split_cb_search_shape_sign,
split_cb_shape_sign_unquant,
&split_cb_sb,
#else
/*LSP quantization*/
NULL,
lsp_unquant_nb,
/*Pitch quantization*/
NULL,
pitch_unquant_3tap,
&ltp_params_nb,
/*Innovation quantization*/
NULL,
split_cb_shape_sign_unquant,
&split_cb_sb,
#endif
QCONST16(.2,15),
364
};
/* 24.6 kbps high bit-rate mode */
static const SpeexSubmode nb_submode7 = {
-1,
0,
3,
1,
#ifndef SPEEX_DISABLE_ENCODER
/*LSP quantization*/
lsp_quant_nb,
lsp_unquant_nb,
/*Pitch quantization*/
pitch_search_3tap,
pitch_unquant_3tap,
&ltp_params_nb,
/*Innovation quantization*/
split_cb_search_shape_sign,
split_cb_shape_sign_unquant,
&split_cb_nb,
#else
/*LSP quantization*/
NULL,
lsp_unquant_nb,
/*Pitch quantization*/
NULL,
pitch_unquant_3tap,
&ltp_params_nb,
/*Innovation quantization*/
NULL,
split_cb_shape_sign_unquant,
&split_cb_nb,
#endif
QCONST16(.1,15),
492
};
/* Default mode for narrowband */
static const SpeexNBMode nb_mode = {
160, /*frameSize*/
40, /*subframeSize*/
10, /*lpcSize*/
17, /*pitchStart*/
144, /*pitchEnd*/
#ifdef FIXED_POINT
29491, 19661, /* gamma1, gamma2 */
#else
0.9, 0.6, /* gamma1, gamma2 */
#endif
QCONST16(.0002,15), /*lpc_floor*/
{NULL, &nb_submode1, &nb_submode2, &nb_submode3, &nb_submode4, &nb_submode5, &nb_submode6, &nb_submode7,
&nb_submode8, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
5,
{1, 8, 2, 3, 3, 4, 4, 5, 5, 6, 7}
};
/* Default mode for narrowband */
const SpeexMode speex_nb_mode = {
&nb_mode,
nb_mode_query,
"narrowband",
0,
4,
#ifndef SPEEX_DISABLE_ENCODER
&nb_encoder_init,
&nb_encoder_destroy,
&nb_encode,
&nb_decoder_init,
&nb_decoder_destroy,
&nb_decode,
&nb_encoder_ctl,
&nb_decoder_ctl,
#else
/* NULL,
NULL,
NULL, */
&nb_decoder_init,
&nb_decoder_destroy,
&nb_decode,
/* NULL, */
&nb_decoder_ctl,
#endif
};
int speex_mode_query(const SpeexMode *mode, int request, void *ptr)
{
return mode->query(mode->mode, request, ptr);
}