diff options
author | Sean Bartell <wingedtachikoma@gmail.com> | 2011-06-25 21:32:25 -0400 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2012-04-25 22:13:20 +0200 |
commit | f40bfc9267b13b54e6379dfe7539447662879d24 (patch) | |
tree | 9b20069d5e62809ff434061ad730096836f916f2 /lib/rbcodec/codecs/libspeex/nb_celp.h | |
parent | a0009907de7a0107d49040d8a180f140e2eff299 (diff) | |
download | rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.tar.gz rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.zip |
Add codecs to librbcodec.
Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97
Reviewed-on: http://gerrit.rockbox.org/137
Reviewed-by: Nils Wallménius <nils@rockbox.org>
Tested-by: Nils Wallménius <nils@rockbox.org>
Diffstat (limited to 'lib/rbcodec/codecs/libspeex/nb_celp.h')
-rw-r--r-- | lib/rbcodec/codecs/libspeex/nb_celp.h | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libspeex/nb_celp.h b/lib/rbcodec/codecs/libspeex/nb_celp.h new file mode 100644 index 0000000000..30edbefaeb --- /dev/null +++ b/lib/rbcodec/codecs/libspeex/nb_celp.h | |||
@@ -0,0 +1,205 @@ | |||
1 | /* Copyright (C) 2002-2006 Jean-Marc Valin */ | ||
2 | /** | ||
3 | @file nb_celp.h | ||
4 | @brief Narrowband CELP encoder/decoder | ||
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 NB_CELP_H | ||
37 | #define NB_CELP_H | ||
38 | |||
39 | #include "modes.h" | ||
40 | #include "speex/speex_bits.h" | ||
41 | #include "speex/speex_callbacks.h" | ||
42 | #include "vbr.h" | ||
43 | #include "filters.h" | ||
44 | |||
45 | #ifdef VORBIS_PSYCHO | ||
46 | #include "vorbis_psy.h" | ||
47 | #endif | ||
48 | |||
49 | /**Structure representing the full state of the narrowband encoder*/ | ||
50 | typedef struct EncState { | ||
51 | const SpeexMode *mode; /**< Mode corresponding to the state */ | ||
52 | int first; /**< Is this the first frame? */ | ||
53 | int frameSize; /**< Size of frames */ | ||
54 | int subframeSize; /**< Size of sub-frames */ | ||
55 | int nbSubframes; /**< Number of sub-frames */ | ||
56 | int windowSize; /**< Analysis (LPC) window length */ | ||
57 | int lpcSize; /**< LPC order */ | ||
58 | int min_pitch; /**< Minimum pitch value allowed */ | ||
59 | int max_pitch; /**< Maximum pitch value allowed */ | ||
60 | |||
61 | spx_word32_t cumul_gain; /**< Product of previously used pitch gains (Q10) */ | ||
62 | int bounded_pitch; /**< Next frame should not rely on previous frames for pitch */ | ||
63 | int ol_pitch; /**< Open-loop pitch */ | ||
64 | int ol_voiced; /**< Open-loop voiced/non-voiced decision */ | ||
65 | int *pitch; | ||
66 | |||
67 | #ifdef VORBIS_PSYCHO | ||
68 | VorbisPsy *psy; | ||
69 | float *psy_window; | ||
70 | float *curve; | ||
71 | float *old_curve; | ||
72 | #endif | ||
73 | |||
74 | spx_word16_t gamma1; /**< Perceptual filter: A(z/gamma1) */ | ||
75 | spx_word16_t gamma2; /**< Perceptual filter: A(z/gamma2) */ | ||
76 | spx_word16_t lpc_floor; /**< Noise floor multiplier for A[0] in LPC analysis*/ | ||
77 | char *stack; /**< Pseudo-stack allocation for temporary memory */ | ||
78 | spx_word16_t *winBuf; /**< Input buffer (original signal) */ | ||
79 | spx_word16_t *excBuf; /**< Excitation buffer */ | ||
80 | spx_word16_t *exc; /**< Start of excitation frame */ | ||
81 | spx_word16_t *swBuf; /**< Weighted signal buffer */ | ||
82 | spx_word16_t *sw; /**< Start of weighted signal frame */ | ||
83 | const spx_word16_t *window; /**< Temporary (Hanning) window */ | ||
84 | const spx_word16_t *lagWindow; /**< Window applied to auto-correlation */ | ||
85 | spx_lsp_t *old_lsp; /**< LSPs for previous frame */ | ||
86 | spx_lsp_t *old_qlsp; /**< Quantized LSPs for previous frame */ | ||
87 | spx_mem_t *mem_sp; /**< Filter memory for signal synthesis */ | ||
88 | spx_mem_t *mem_sw; /**< Filter memory for perceptually-weighted signal */ | ||
89 | spx_mem_t *mem_sw_whole; /**< Filter memory for perceptually-weighted signal (whole frame)*/ | ||
90 | spx_mem_t *mem_exc; /**< Filter memory for excitation (whole frame) */ | ||
91 | spx_mem_t *mem_exc2; /**< Filter memory for excitation (whole frame) */ | ||
92 | spx_mem_t mem_hp[2]; /**< High-pass filter memory */ | ||
93 | spx_word32_t *pi_gain; /**< Gain of LPC filter at theta=pi (fe/2) */ | ||
94 | spx_word16_t *innov_rms_save; /**< If non-NULL, innovation RMS is copied here */ | ||
95 | |||
96 | #ifndef DISABLE_VBR | ||
97 | VBRState *vbr; /**< State of the VBR data */ | ||
98 | float vbr_quality; /**< Quality setting for VBR encoding */ | ||
99 | float relative_quality; /**< Relative quality that will be needed by VBR */ | ||
100 | spx_int32_t vbr_enabled; /**< 1 for enabling VBR, 0 otherwise */ | ||
101 | spx_int32_t vbr_max; /**< Max bit-rate allowed in VBR mode */ | ||
102 | int vad_enabled; /**< 1 for enabling VAD, 0 otherwise */ | ||
103 | int dtx_enabled; /**< 1 for enabling DTX, 0 otherwise */ | ||
104 | int dtx_count; /**< Number of consecutive DTX frames */ | ||
105 | spx_int32_t abr_enabled; /**< ABR setting (in bps), 0 if off */ | ||
106 | float abr_drift; | ||
107 | float abr_drift2; | ||
108 | float abr_count; | ||
109 | #endif /* #ifndef DISABLE_VBR */ | ||
110 | |||
111 | int complexity; /**< Complexity setting (0-10 from least complex to most complex) */ | ||
112 | spx_int32_t sampling_rate; | ||
113 | int plc_tuning; | ||
114 | int encode_submode; | ||
115 | const SpeexSubmode * const *submodes; /**< Sub-mode data */ | ||
116 | int submodeID; /**< Activated sub-mode */ | ||
117 | int submodeSelect; /**< Mode chosen by the user (may differ from submodeID if VAD is on) */ | ||
118 | int isWideband; /**< Is this used as part of the embedded wideband codec */ | ||
119 | int highpass_enabled; /**< Is the input filter enabled */ | ||
120 | } EncState; | ||
121 | |||
122 | /**Structure representing the full state of the narrowband decoder*/ | ||
123 | typedef struct DecState { | ||
124 | const SpeexMode *mode; /**< Mode corresponding to the state */ | ||
125 | int first; /**< Is this the first frame? */ | ||
126 | int count_lost; /**< Was the last frame lost? */ | ||
127 | int frameSize; /**< Size of frames */ | ||
128 | int subframeSize; /**< Size of sub-frames */ | ||
129 | int nbSubframes; /**< Number of sub-frames */ | ||
130 | int lpcSize; /**< LPC order */ | ||
131 | int min_pitch; /**< Minimum pitch value allowed */ | ||
132 | int max_pitch; /**< Maximum pitch value allowed */ | ||
133 | spx_int32_t sampling_rate; | ||
134 | |||
135 | spx_word16_t last_ol_gain; /**< Open-loop gain for previous frame */ | ||
136 | |||
137 | char *stack; /**< Pseudo-stack allocation for temporary memory */ | ||
138 | /* Size calculated from maximum values of frameSize, max_pitch and | ||
139 | * subframeSize, being respectively 160, 144 and 40 */ | ||
140 | spx_word16_t excBuf[500]; /**< Excitation buffer */ | ||
141 | spx_word16_t *exc; /**< Start of excitation frame */ | ||
142 | spx_lsp_t old_qlsp[10]; /**< Quantized LSPs for previous frame */ | ||
143 | spx_coef_t interp_qlpc[10]; /**< Interpolated quantized LPCs */ | ||
144 | spx_mem_t mem_sp[10]; /**< Filter memory for synthesis signal */ | ||
145 | spx_mem_t mem_hp[2]; /**< High-pass filter memory */ | ||
146 | spx_word32_t pi_gain[4]; /**< Gain of LPC filter at theta=pi (fe/2) */ | ||
147 | spx_word16_t *innov_save; /** If non-NULL, innovation is copied here */ | ||
148 | |||
149 | spx_word16_t level; | ||
150 | spx_word16_t max_level; | ||
151 | spx_word16_t min_level; | ||
152 | |||
153 | /* This is used in packet loss concealment */ | ||
154 | int last_pitch; /**< Pitch of last correctly decoded frame */ | ||
155 | spx_word16_t last_pitch_gain; /**< Pitch gain of last correctly decoded frame */ | ||
156 | spx_word16_t pitch_gain_buf[3]; /**< Pitch gain of last decoded frames */ | ||
157 | int pitch_gain_buf_idx; /**< Tail of the buffer */ | ||
158 | spx_int32_t seed; /** Seed used for random number generation */ | ||
159 | |||
160 | int encode_submode; | ||
161 | const SpeexSubmode * const *submodes; /**< Sub-mode data */ | ||
162 | int submodeID; /**< Activated sub-mode */ | ||
163 | int lpc_enh_enabled; /**< 1 when LPC enhancer is on, 0 otherwise */ | ||
164 | SpeexCallback speex_callbacks[SPEEX_MAX_CALLBACKS]; | ||
165 | |||
166 | SpeexCallback user_callback; | ||
167 | |||
168 | /*Vocoder data*/ | ||
169 | spx_word16_t voc_m1; | ||
170 | spx_word32_t voc_m2; | ||
171 | spx_word16_t voc_mean; | ||
172 | int voc_offset; | ||
173 | |||
174 | int dtx_enabled; | ||
175 | int isWideband; /**< Is this used as part of the embedded wideband codec */ | ||
176 | int highpass_enabled; /**< Is the input filter enabled */ | ||
177 | } DecState; | ||
178 | |||
179 | /** Initializes encoder state*/ | ||
180 | void *nb_encoder_init(const SpeexMode *m); | ||
181 | |||
182 | /** De-allocates encoder state resources*/ | ||
183 | void nb_encoder_destroy(void *state); | ||
184 | |||
185 | /** Encodes one frame*/ | ||
186 | int nb_encode(void *state, void *in, SpeexBits *bits); | ||
187 | |||
188 | |||
189 | /** Initializes decoder state*/ | ||
190 | void *nb_decoder_init(const SpeexMode *m); | ||
191 | |||
192 | /** De-allocates decoder state resources*/ | ||
193 | void nb_decoder_destroy(void *state); | ||
194 | |||
195 | /** Decodes one frame*/ | ||
196 | int nb_decode(void *state, SpeexBits *bits, void *out); | ||
197 | |||
198 | /** ioctl-like function for controlling a narrowband encoder */ | ||
199 | int nb_encoder_ctl(void *state, int request, void *ptr); | ||
200 | |||
201 | /** ioctl-like function for controlling a narrowband decoder */ | ||
202 | int nb_decoder_ctl(void *state, int request, void *ptr); | ||
203 | |||
204 | |||
205 | #endif | ||