1 /*
2 * DCA ADPCM engine
3 * Copyright (C) 2017 Daniil Cherednik
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
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
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22
27
29
30 //assume we have DCA_ADPCM_COEFFS values before x
32 {
33 int n;
35 for (n = 0; n <
len; n++)
36 s +=
MUL64(x[n-j], x[n-k]);
38 }
39
41 {
42 int64_t err = 0;
44
45 err = corr[0];
46
51
54
57
62
66
69
71
73
75
76 return llabs(err);
77 }
78
80 {
83 int vq = -1;
84 int64_t err;
85 int64_t min_err = 1ll << 62;
86 int64_t corr[15];
87
91
94 if (err < min_err) {
95 min_err = err;
97 }
98 precalc_data++;
99 }
100
101 return vq;
102 }
103
105 {
108
109 int64_t signal_energy = 0;
110 int64_t error_energy = 0;
111
112 for (
i = 0;
i <
len;
i++) {
117 }
118
119 if (!error_energy)
120 return -1;
121
122 return signal_energy / error_energy;
123 }
124
126 {
130
132 int shift_bits;
133 uint64_t pg = 0;
134
137
138 // normalize input to simplify apply_filter
140
143 input_buffer2[
i] =
norm__(in[
i], shift_bits);
144 }
145
147
148 if (pred_vq < 0)
149 return -1;
150
152
153 // Greater than 10db (10*log(10)) prediction gain to use ADPCM.
154 // TODO: Tune it.
155 if (pg < 10)
156 return -1;
157
160
161 return pred_vq;
162 }
163
165 {
167
169 int id = 0;
174 if (j != k)
175 t *= 2;
176 (*data)[id++] = t;
177 }
178 }
180 }
181 }
182
187 {
192
194
195 for (
i = 0;
i <
len;
i++) {
197
199
201
203
205 }
206
208
209 return 0;
210 }
211
213 {
215 return -1;
216
218 if (!
s->private_data)
220
222 return 0;
223 }
224
226 {
228 return;
229
231 }