annotate qcelpdec.c @ 8123:cd756806be02 libavcodec

More OKed parts of the QCELP decoder patch by Kenan Gillet, kenan.gillet gmail com
author vitor
date Sun, 09 Nov 2008 12:00:47 +0000
parents eb55481f35fa
children 3b5256153553
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
8123
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
41 static void weighted_vector_sumf(float *out,
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
42 const float *in_a,
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
43 const float *in_b,
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
44 float weight_coeff_a,
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
45 float weight_coeff_b,
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
46 int length) {
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
47 int i;
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
48
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
49 for (i = 0; i < length; i++)
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
50 out[i] = weight_coeff_a * in_a[i]
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
51 + weight_coeff_b * in_b[i];
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
52 }
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
53
8096
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
54 /**
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
55 * Apply filter in pitch-subframe steps.
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
56 *
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
57 * @param memory buffer for the previous state of the filter
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
58 * - must be able to contain 303 elements
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
59 * - the 143 first elements are from the previous state
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
60 * - the next 160 are for output
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
61 * @param v_in input filter vector
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
62 * @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
63 * @param lag per-subframe lag array, each element is
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
64 * - between 16 and 143 if its corresponding pfrac is 0,
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
65 * - between 16 and 139 otherwise
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
66 * @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
67 *
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
68 * @return filter output vector
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
69 */
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
70 static const float *do_pitchfilter(float memory[303],
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
71 const float v_in[160],
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
72 const float gain[4],
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
73 const uint8_t *lag,
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
74 const uint8_t pfrac[4]) {
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
75 int i, j;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
76 float *v_lag, *v_out;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
77 const float *v_len;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
78
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
79 v_out = memory + 143; // Output vector starts at memory[143].
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
80
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
81 for (i = 0; i < 4; i++)
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
82 if (gain[i]) {
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
83 v_lag = memory + 143 + 40 * i - lag[i];
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
84 for (v_len = v_in + 40; v_in < v_len; v_in++) {
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
85 if (pfrac[i]) { // If it is a fractional lag...
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
86 for (j = 0, *v_out = 0.; j < 4; j++)
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
87 *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
88 } else
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
89 *v_out = *v_lag;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
90
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
91 *v_out = *v_in + gain[i] * *v_out;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
92
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
93 v_lag++;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
94 v_out++;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
95 }
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
96 } else {
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
97 memcpy(v_out, v_in, 40 * sizeof(float));
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
98 v_in += 40;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
99 v_out += 40;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
100 }
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
101
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
102 memmove(memory, memory + 160, 143 * sizeof(float));
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
103 return memory + 143;
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
104 }
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
105
8123
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
106 static int buf_size2framerate(const int buf_size) {
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
107 switch (buf_size) {
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
108 case 35:
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
109 return RATE_FULL;
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
110 case 17:
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
111 return RATE_HALF;
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
112 case 8:
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
113 return RATE_QUARTER;
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
114 case 4:
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
115 return RATE_OCTAVE;
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
116 case 1:
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
117 return SILENCE;
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
118 }
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
119 return -1;
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
120 }
cd756806be02 More OKed parts of the QCELP decoder
vitor
parents: 8096
diff changeset
121
8096
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
122 static void warn_insufficient_frame_quality(AVCodecContext *avctx,
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
123 const char *message) {
eb55481f35fa OKed parts of the QCELP decoder
vitor
parents:
diff changeset
124 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
125 }