annotate qcelpdec.c @ 8096:eb55481f35fa libavcodec

OKed parts of the QCELP decoder patch by Kenan Gillet, kenan.gillet gmail com
author vitor
date Thu, 30 Oct 2008 22:37:18 +0000
parents
children cd756806be02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8096
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
1 /*
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
2 * QCELP decoder
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
3 * Copyright (c) 2007 Reynaldo H. Verdejo Pinochet
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
4 *
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
5 * This file is part of FFmpeg.
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
6 *
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
11 *
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
15 * Lesser General Public License for more details.
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
16 *
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
20 */
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
21 /**
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
22 * @file qcelpdec.c
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
23 * QCELP decoder
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
24 * @author Reynaldo H. Verdejo Pinochet
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
25 */
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
26
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
27 #include <stddef.h>
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
28
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
29 #include "avcodec.h"
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
30 #include "bitstream.h"
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
31
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
32 #include "qcelp.h"
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
33 #include "qcelpdata.h"
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
34
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
35 #include "celp_math.h"
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
36 #include "celp_filters.h"
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
37
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
38 #undef NDEBUG
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
39 #include <assert.h>
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
40
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
41 /**
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
42 * Apply filter in pitch-subframe steps.
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
43 *
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
44 * @param memory buffer for the previous state of the filter
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
45 * - must be able to contain 303 elements
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
46 * - the 143 first elements are from the previous state
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
47 * - the next 160 are for output
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
48 * @param v_in input filter vector
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
49 * @param gain per-subframe gain array, each element is between 0.0 and 2.0
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
50 * @param lag per-subframe lag array, each element is
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
51 * - between 16 and 143 if its corresponding pfrac is 0,
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
52 * - between 16 and 139 otherwise
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
53 * @param pfrac per-subframe boolean array, 1 if the lag is fractional, 0 otherwise
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
54 *
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
55 * @return filter output vector
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
56 */
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
57 static const float *do_pitchfilter(float memory[303],
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
58 const float v_in[160],
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
59 const float gain[4],
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
60 const uint8_t *lag,
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
61 const uint8_t pfrac[4]) {
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
62 int i, j;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
63 float *v_lag, *v_out;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
64 const float *v_len;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
65
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
66 v_out = memory + 143; // Output vector starts at memory[143].
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
67
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
68 for (i = 0; i < 4; i++)
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
69 if (gain[i]) {
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
70 v_lag = memory + 143 + 40 * i - lag[i];
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
71 for (v_len = v_in + 40; v_in < v_len; v_in++) {
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
72 if (pfrac[i]) { // If it is a fractional lag...
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
73 for (j = 0, *v_out = 0.; j < 4; j++)
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
74 *v_out += qcelp_hammsinc_table[j] * (v_lag[j-4] + v_lag[3-j]);
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
75 } else
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
76 *v_out = *v_lag;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
77
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
78 *v_out = *v_in + gain[i] * *v_out;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
79
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
80 v_lag++;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
81 v_out++;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
82 }
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
83 } else {
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
84 memcpy(v_out, v_in, 40 * sizeof(float));
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
85 v_in += 40;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
86 v_out += 40;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
87 }
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
88
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
89 memmove(memory, memory + 160, 143 * sizeof(float));
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
90 return memory + 143;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
91 }
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
92
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
93 static void warn_insufficient_frame_quality(AVCodecContext *avctx,
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
94 const char *message) {
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
95 av_log(avctx, AV_LOG_WARNING, "Frame #%d, IFQ: %s\n", avctx->frame_number, message);
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
96 }