| 1 |
/* Copyright (C) 2002-2006 Jean-Marc Valin */ |
| 2 |
/** |
| 3 |
@file modes.h |
| 4 |
@brief Describes the different modes of the codec |
| 5 |
*/ |
| 6 |
/* |
| 7 |
Redistribution and use in source and binary forms, with or without |
| 8 |
modification, are permitted provided that the following conditions |
| 9 |
are met: |
| 10 |
|
| 11 |
- Redistributions of source code must retain the above copyright |
| 12 |
notice, this list of conditions and the following disclaimer. |
| 13 |
|
| 14 |
- Redistributions in binary form must reproduce the above copyright |
| 15 |
notice, this list of conditions and the following disclaimer in the |
| 16 |
documentation and/or other materials provided with the distribution. |
| 17 |
|
| 18 |
- Neither the name of the Xiph.org Foundation nor the names of its |
| 19 |
contributors may be used to endorse or promote products derived from |
| 20 |
this software without specific prior written permission. |
| 21 |
|
| 22 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 |
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 |
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 |
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR |
| 26 |
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 27 |
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 28 |
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 29 |
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 30 |
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 31 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 32 |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 |
|
| 34 |
*/ |
| 35 |
|
| 36 |
#ifndef MODES_H |
| 37 |
#define MODES_H |
| 38 |
|
| 39 |
#include "speex/speex.h" |
| 40 |
#include "arch.h" |
| 41 |
|
| 42 |
#define NB_SUBMODES 16 |
| 43 |
#define NB_SUBMODE_BITS 4 |
| 44 |
|
| 45 |
#define SB_SUBMODES 8 |
| 46 |
#define SB_SUBMODE_BITS 3 |
| 47 |
|
| 48 |
/* Used internally, NOT TO BE USED in applications */ |
| 49 |
/** Used internally*/ |
| 50 |
#define SPEEX_GET_PI_GAIN 100 |
| 51 |
/** Used internally*/ |
| 52 |
#define SPEEX_GET_EXC 101 |
| 53 |
/** Used internally*/ |
| 54 |
#define SPEEX_GET_INNOV 102 |
| 55 |
/** Used internally*/ |
| 56 |
#define SPEEX_GET_DTX_STATUS 103 |
| 57 |
/** Used internally*/ |
| 58 |
#define SPEEX_SET_INNOVATION_SAVE 104 |
| 59 |
/** Used internally*/ |
| 60 |
#define SPEEX_SET_WIDEBAND 105 |
| 61 |
|
| 62 |
/** Used internally*/ |
| 63 |
#define SPEEX_GET_STACK 106 |
| 64 |
|
| 65 |
|
| 66 |
/** Quantizes LSPs */ |
| 67 |
typedef void (*lsp_quant_func)(spx_lsp_t *, spx_lsp_t *, int, SpeexBits *); |
| 68 |
|
| 69 |
/** Decodes quantized LSPs */ |
| 70 |
typedef void (*lsp_unquant_func)(spx_lsp_t *, int, SpeexBits *); |
| 71 |
|
| 72 |
|
| 73 |
/** Long-term predictor quantization */ |
| 74 |
typedef int (*ltp_quant_func)(spx_word16_t *, spx_word16_t *, spx_coef_t *, spx_coef_t *, |
| 75 |
spx_coef_t *, spx_sig_t *, const void *, int, int, spx_word16_t, |
| 76 |
int, int, SpeexBits*, char *, spx_word16_t *, spx_word16_t *, int, int, int, spx_word32_t *); |
| 77 |
|
| 78 |
/** Long-term un-quantize */ |
| 79 |
typedef void (*ltp_unquant_func)(spx_word16_t *, spx_word32_t *, int, int, spx_word16_t, const void *, int, int *, |
| 80 |
spx_word16_t *, SpeexBits*, char*, int, int, spx_word16_t, int); |
| 81 |
|
| 82 |
|
| 83 |
/** Innovation quantization function */ |
| 84 |
typedef void (*innovation_quant_func)(spx_word16_t *, spx_coef_t *, spx_coef_t *, spx_coef_t *, const void *, int, int, |
| 85 |
spx_sig_t *, spx_word16_t *, SpeexBits *, char *, int, int); |
| 86 |
|
| 87 |
/** Innovation unquantization function */ |
| 88 |
typedef void (*innovation_unquant_func)(spx_sig_t *, const void *, int, SpeexBits*, char *, spx_uint32_t *); |
| 89 |
|
| 90 |
/** Description of a Speex sub-mode (wither narrowband or wideband */ |
| 91 |
typedef struct SpeexSubmode { |
| 92 |
int lbr_pitch; /**< Set to -1 for "normal" modes, otherwise encode pitch using a global pitch and allowing a +- lbr_pitch variation (for low not-rates)*/ |
| 93 |
int forced_pitch_gain; /**< Use the same (forced) pitch gain for all sub-frames */ |
| 94 |
int have_subframe_gain; /**< Number of bits to use as sub-frame innovation gain */ |
| 95 |
int double_codebook; /**< Apply innovation quantization twice for higher quality (and higher bit-rate)*/ |
| 96 |
/*LSP functions*/ |
| 97 |
lsp_quant_func lsp_quant; /**< LSP quantization function */ |
| 98 |
lsp_unquant_func lsp_unquant; /**< LSP unquantization function */ |
| 99 |
|
| 100 |
/*Long-term predictor functions*/ |
| 101 |
ltp_quant_func ltp_quant; /**< Long-term predictor (pitch) quantizer */ |
| 102 |
ltp_unquant_func ltp_unquant; /**< Long-term predictor (pitch) un-quantizer */ |
| 103 |
const void *ltp_params; /**< Pitch parameters (options) */ |
| 104 |
|
| 105 |
/*Quantization of innovation*/ |
| 106 |
innovation_quant_func innovation_quant; /**< Innovation quantization */ |
| 107 |
innovation_unquant_func innovation_unquant; /**< Innovation un-quantization */ |
| 108 |
const void *innovation_params; /**< Innovation quantization parameters*/ |
| 109 |
|
| 110 |
spx_word16_t comb_gain; /**< Gain of enhancer comb filter */ |
| 111 |
|
| 112 |
int bits_per_frame; /**< Number of bits per frame after encoding*/ |
| 113 |
} SpeexSubmode; |
| 114 |
|
| 115 |
/** Struct defining the encoding/decoding mode*/ |
| 116 |
typedef struct SpeexNBMode { |
| 117 |
int frameSize; /**< Size of frames used for encoding */ |
| 118 |
int subframeSize; /**< Size of sub-frames used for encoding */ |
| 119 |
int lpcSize; /**< Order of LPC filter */ |
| 120 |
int pitchStart; /**< Smallest pitch value allowed */ |
| 121 |
int pitchEnd; /**< Largest pitch value allowed */ |
| 122 |
|
| 123 |
spx_word16_t gamma1; /**< Perceptual filter parameter #1 */ |
| 124 |
spx_word16_t gamma2; /**< Perceptual filter parameter #2 */ |
| 125 |
spx_word16_t lpc_floor; /**< Noise floor for LPC analysis */ |
| 126 |
|
| 127 |
const SpeexSubmode *submodes[NB_SUBMODES]; /**< Sub-mode data for the mode */ |
| 128 |
int defaultSubmode; /**< Default sub-mode to use when encoding */ |
| 129 |
int quality_map[11]; /**< Mode corresponding to each quality setting */ |
| 130 |
} SpeexNBMode; |
| 131 |
|
| 132 |
|
| 133 |
/** Struct defining the encoding/decoding mode for SB-CELP (wideband) */ |
| 134 |
typedef struct SpeexSBMode { |
| 135 |
const SpeexMode *nb_mode; /**< Embedded narrowband mode */ |
| 136 |
int frameSize; /**< Size of frames used for encoding */ |
| 137 |
int subframeSize; /**< Size of sub-frames used for encoding */ |
| 138 |
int lpcSize; /**< Order of LPC filter */ |
| 139 |
spx_word16_t gamma1; /**< Perceptual filter parameter #1 */ |
| 140 |
spx_word16_t gamma2; /**< Perceptual filter parameter #1 */ |
| 141 |
spx_word16_t lpc_floor; /**< Noise floor for LPC analysis */ |
| 142 |
spx_word16_t folding_gain; |
| 143 |
|
| 144 |
const SpeexSubmode *submodes[SB_SUBMODES]; /**< Sub-mode data for the mode */ |
| 145 |
int defaultSubmode; /**< Default sub-mode to use when encoding */ |
| 146 |
int low_quality_map[11]; /**< Mode corresponding to each quality setting */ |
| 147 |
int quality_map[11]; /**< Mode corresponding to each quality setting */ |
| 148 |
#ifndef DISABLE_VBR |
| 149 |
const float (*vbr_thresh)[11]; |
| 150 |
#endif |
| 151 |
int nb_modes; |
| 152 |
} SpeexSBMode; |
| 153 |
|
| 154 |
int speex_encode_native(void *state, spx_word16_t *in, SpeexBits *bits); |
| 155 |
int speex_decode_native(void *state, SpeexBits *bits, spx_word16_t *out); |
| 156 |
|
| 157 |
int nb_mode_query(const void *mode, int request, void *ptr); |
| 158 |
int wb_mode_query(const void *mode, int request, void *ptr); |
| 159 |
|
| 160 |
#endif |