Mercurial > libavcodec.hg
comparison qcelpdec.c @ 8150:4da8fc62ae00 libavcodec
Cosmetics
author | reynaldo |
---|---|
date | Sun, 16 Nov 2008 00:57:06 +0000 |
parents | f27d01aff4af |
children | e2c068cb210a |
comparison
equal
deleted
inserted
replaced
8149:415b7d14ff75 | 8150:4da8fc62ae00 |
---|---|
16 * | 16 * |
17 * You should have received a copy of the GNU Lesser General Public | 17 * You should have received a copy of the GNU Lesser General Public |
18 * License along with FFmpeg; if not, write to the Free Software | 18 * License along with FFmpeg; if not, write to the Free Software |
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 */ | 20 */ |
21 | |
21 /** | 22 /** |
22 * @file qcelpdec.c | 23 * @file qcelpdec.c |
23 * QCELP decoder | 24 * QCELP decoder |
24 * @author Reynaldo H. Verdejo Pinochet | 25 * @author Reynaldo H. Verdejo Pinochet |
25 */ | 26 */ |
36 #include "celp_filters.h" | 37 #include "celp_filters.h" |
37 | 38 |
38 #undef NDEBUG | 39 #undef NDEBUG |
39 #include <assert.h> | 40 #include <assert.h> |
40 | 41 |
41 static void weighted_vector_sumf(float *out, | 42 static void weighted_vector_sumf(float *out, const float *in_a, |
42 const float *in_a, | 43 const float *in_b, float weight_coeff_a, |
43 const float *in_b, | 44 float weight_coeff_b, int length) |
44 float weight_coeff_a, | 45 { |
45 float weight_coeff_b, | 46 int i; |
46 int length) { | 47 |
47 int i; | 48 for(i=0; i<length; i++) |
48 | |
49 for (i = 0; i < length; i++) | |
50 out[i] = weight_coeff_a * in_a[i] | 49 out[i] = weight_coeff_a * in_a[i] |
51 + weight_coeff_b * in_b[i]; | 50 + weight_coeff_b * in_b[i]; |
52 } | 51 } |
53 | 52 |
54 /** | 53 /** |
203 * - between 16 and 139 otherwise | 202 * - between 16 and 139 otherwise |
204 * @param pfrac per-subframe boolean array, 1 if the lag is fractional, 0 otherwise | 203 * @param pfrac per-subframe boolean array, 1 if the lag is fractional, 0 otherwise |
205 * | 204 * |
206 * @return filter output vector | 205 * @return filter output vector |
207 */ | 206 */ |
208 static const float *do_pitchfilter(float memory[303], | 207 static const float *do_pitchfilter(float memory[303], const float v_in[160], |
209 const float v_in[160], | 208 const float gain[4], const uint8_t *lag, |
210 const float gain[4], | 209 const uint8_t pfrac[4]) |
211 const uint8_t *lag, | 210 { |
212 const uint8_t pfrac[4]) { | |
213 int i, j; | 211 int i, j; |
214 float *v_lag, *v_out; | 212 float *v_lag, *v_out; |
215 const float *v_len; | 213 const float *v_len; |
216 | 214 |
217 v_out = memory + 143; // Output vector starts at memory[143]. | 215 v_out = memory + 143; // Output vector starts at memory[143]. |
218 | 216 |
219 for (i = 0; i < 4; i++) | 217 for(i=0; i<4; i++) |
220 if (gain[i]) { | 218 { |
219 if(gain[i]) | |
220 { | |
221 v_lag = memory + 143 + 40 * i - lag[i]; | 221 v_lag = memory + 143 + 40 * i - lag[i]; |
222 for (v_len = v_in + 40; v_in < v_len; v_in++) { | 222 for(v_len=v_in+40; v_in<v_len; v_in++) |
223 if (pfrac[i]) { // If it is a fractional lag... | 223 { |
224 for (j = 0, *v_out = 0.; j < 4; j++) | 224 if(pfrac[i]) // If it is a fractional lag... |
225 { | |
226 for(j=0, *v_out=0.; j<4; j++) | |
225 *v_out += qcelp_hammsinc_table[j] * (v_lag[j-4] + v_lag[3-j]); | 227 *v_out += qcelp_hammsinc_table[j] * (v_lag[j-4] + v_lag[3-j]); |
226 } else | 228 }else |
227 *v_out = *v_lag; | 229 *v_out = *v_lag; |
228 | 230 |
229 *v_out = *v_in + gain[i] * *v_out; | 231 *v_out = *v_in + gain[i] * *v_out; |
230 | 232 |
231 v_lag++; | 233 v_lag++; |
232 v_out++; | 234 v_out++; |
233 } | 235 } |
234 } else { | 236 }else |
237 { | |
235 memcpy(v_out, v_in, 40 * sizeof(float)); | 238 memcpy(v_out, v_in, 40 * sizeof(float)); |
236 v_in += 40; | 239 v_in += 40; |
237 v_out += 40; | 240 v_out += 40; |
238 } | 241 } |
242 } | |
239 | 243 |
240 memmove(memory, memory + 160, 143 * sizeof(float)); | 244 memmove(memory, memory + 160, 143 * sizeof(float)); |
241 return memory + 143; | 245 return memory + 143; |
242 } | 246 } |
243 | 247 |
250 * @param q the context | 254 * @param q the context |
251 * @param curr_lspf LSP frequencies vector of the current frame | 255 * @param curr_lspf LSP frequencies vector of the current frame |
252 * @param lpc float vector for the resulting LPC | 256 * @param lpc float vector for the resulting LPC |
253 * @param subframe_num frame number in decoded stream | 257 * @param subframe_num frame number in decoded stream |
254 */ | 258 */ |
255 void interpolate_lpc(QCELPContext *q, | 259 void interpolate_lpc(QCELPContext *q, const float *curr_lspf, float *lpc, |
256 const float *curr_lspf, | 260 const int subframe_num) |
257 float *lpc, | 261 { |
258 const int subframe_num) { | |
259 float interpolated_lspf[10]; | 262 float interpolated_lspf[10]; |
260 float weight; | 263 float weight; |
261 | 264 |
262 if (q->framerate >= RATE_QUARTER) { | 265 if(q->framerate >= RATE_QUARTER) |
263 weight = 0.25 * (subframe_num + 1); | 266 weight = 0.25 * (subframe_num + 1); |
264 } else if (q->framerate == RATE_OCTAVE && !subframe_num) { | 267 else if(q->framerate == RATE_OCTAVE && !subframe_num) |
265 weight = 0.625; | 268 weight = 0.625; |
266 } else { | 269 else |
267 weight = 1.0; | 270 weight = 1.0; |
271 | |
272 if(weight != 1.0) | |
273 { | |
274 weighted_vector_sumf(interpolated_lspf, curr_lspf, q->prev_lspf, | |
275 weight, 1.0 - weight, 10); | |
276 qcelp_lspf2lpc(interpolated_lspf, lpc); | |
277 }else if(q->framerate >= RATE_QUARTER || (q->framerate == I_F_Q && !subframe_num)) | |
278 qcelp_lspf2lpc(curr_lspf, lpc); | |
279 } | |
280 | |
281 static int buf_size2framerate(const int buf_size) | |
282 { | |
283 switch(buf_size) | |
284 { | |
285 case 35: | |
286 return RATE_FULL; | |
287 case 17: | |
288 return RATE_HALF; | |
289 case 8: | |
290 return RATE_QUARTER; | |
291 case 4: | |
292 return RATE_OCTAVE; | |
293 case 1: | |
294 return SILENCE; | |
268 } | 295 } |
269 | 296 |
270 if (weight != 1.0) { | |
271 weighted_vector_sumf(interpolated_lspf, curr_lspf, q->prev_lspf, weight, 1.0 - weight, 10); | |
272 qcelp_lspf2lpc(interpolated_lspf, lpc); | |
273 } else if (q->framerate >= RATE_QUARTER || (q->framerate == I_F_Q && !subframe_num)) | |
274 qcelp_lspf2lpc(curr_lspf, lpc); | |
275 } | |
276 | |
277 static int buf_size2framerate(const int buf_size) { | |
278 switch (buf_size) { | |
279 case 35: | |
280 return RATE_FULL; | |
281 case 17: | |
282 return RATE_HALF; | |
283 case 8: | |
284 return RATE_QUARTER; | |
285 case 4: | |
286 return RATE_OCTAVE; | |
287 case 1: | |
288 return SILENCE; | |
289 } | |
290 return -1; | 297 return -1; |
291 } | 298 } |
292 | 299 |
293 static void warn_insufficient_frame_quality(AVCodecContext *avctx, | 300 static void warn_insufficient_frame_quality(AVCodecContext *avctx, |
294 const char *message) { | 301 const char *message) |
295 av_log(avctx, AV_LOG_WARNING, "Frame #%d, IFQ: %s\n", avctx->frame_number, message); | 302 { |
303 av_log(avctx, AV_LOG_WARNING, "Frame #%d, IFQ: %s\n", avctx->frame_number, | |
304 message); | |
296 } | 305 } |
297 | 306 |
298 AVCodec qcelp_decoder = | 307 AVCodec qcelp_decoder = |
299 { | 308 { |
300 .name = "qcelp", | 309 .name = "qcelp", |