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