1 /*
2 * Copyright (C) 2016 foo86
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
22
25
28 const int8_t hf_vq[1024][32],
30 ptrdiff_t sb_start, ptrdiff_t sb_end,
31 ptrdiff_t ofs, ptrdiff_t
len)
32 {
34
35 for (
i = sb_start;
i < sb_end;
i++) {
36 const int8_t *
coeff = hf_vq[vq_index[
i]];
38 for (j = 0; j <
len; j++)
40 }
41 }
42
45 ptrdiff_t sb_start, ptrdiff_t sb_end,
46 ptrdiff_t ofs, ptrdiff_t
len)
47 {
49
50 for (
i = sb_start;
i < sb_end;
i++) {
52 for (j = 0; j <
len; j++)
54 }
55 }
56
58 const float *filter_coeff, ptrdiff_t npcmblocks,
59 int dec_select)
60 {
61 // Select decimation factor
62 int factor = 64 << dec_select;
63 int ncoeffs = 8 >> dec_select;
64 int nlfesamples = npcmblocks >> (dec_select + 1);
66
67 for (
i = 0;
i < nlfesamples;
i++) {
68 // One decimated sample generates 64 or 128 interpolated ones
69 for (j = 0; j <
factor / 2; j++) {
72
73 for (k = 0; k < ncoeffs; k++) {
74 a += filter_coeff[ j * ncoeffs + k] * lfe_samples[-k];
75 b += filter_coeff[255 - j * ncoeffs - k] * lfe_samples[-k];
76 }
77
79 pcm_samples[
factor / 2 + j] =
b;
80 }
81
82 lfe_samples++;
84 }
85 }
86
88 const float *filter_coeff, ptrdiff_t npcmblocks)
89 {
91 }
92
94 const float *filter_coeff, ptrdiff_t npcmblocks)
95 {
97 }
98
100 float *hist, ptrdiff_t
len)
101 {
102 float prev = *hist;
104
105 for (
i = 0;
i <
len;
i++) {
106 float a = 0.25f *
src[
i] + 0.75f * prev;
107 float b = 0.75f *
src[
i] + 0.25f * prev;
111 }
112
113 *hist = prev;
114 }
115
118 float *pcm_samples,
121 float *hist1,
int *
offset,
float *hist2,
122 const float *filter_coeff, ptrdiff_t npcmblocks,
124 {
127
128 for (j = 0; j < npcmblocks; j++) {
129 // Load in one sample from each subband
130 for (
i = 0;
i < 32;
i++) {
132 input[
i] = -subband_samples_lo[
i][j];
133 else
134 input[
i] = subband_samples_lo[
i][j];
135 }
136
137 // One subband sample generates 32 interpolated ones
139 hist2, filter_coeff,
141 pcm_samples += 32;
142 }
143 }
144
147 float *pcm_samples,
150 float *hist1,
int *
offset,
float *hist2,
151 const float *filter_coeff, ptrdiff_t npcmblocks,
153 {
156
157 if (!subband_samples_hi)
159
160 for (j = 0; j < npcmblocks; j++) {
161 // Load in one sample from each subband
162 if (subband_samples_hi) {
163 // Full 64 subbands, first 32 are residual coded
164 for (
i = 0;
i < 32;
i++) {
166 input[
i] = -subband_samples_lo[
i][j] - subband_samples_hi[
i][j];
167 else
168 input[
i] = subband_samples_lo[
i][j] + subband_samples_hi[
i][j];
169 }
170 for (
i = 32;
i < 64;
i++) {
172 input[
i] = -subband_samples_hi[
i][j];
173 else
174 input[
i] = subband_samples_hi[
i][j];
175 }
176 } else {
177 // Only first 32 subbands
178 for (
i = 0;
i < 32;
i++) {
180 input[
i] = -subband_samples_lo[
i][j];
181 else
182 input[
i] = subband_samples_lo[
i][j];
183 }
184 }
185
186 // One subband sample generates 64 interpolated ones
188 hist2, filter_coeff,
190 pcm_samples += 64;
191 }
192 }
193
195 const int32_t *filter_coeff, ptrdiff_t npcmblocks)
196 {
197 // Select decimation factor
198 int nlfesamples = npcmblocks >> 1;
200
201 for (
i = 0;
i < nlfesamples;
i++) {
202 // One decimated sample generates 64 interpolated ones
203 for (j = 0; j < 32; j++) {
206
207 for (k = 0; k < 8; k++) {
208 a += (int64_t)filter_coeff[ j * 8 + k] * lfe_samples[-k];
209 b += (int64_t)filter_coeff[255 - j * 8 - k] * lfe_samples[-k];
210 }
211
214 }
215
216 lfe_samples++;
217 pcm_samples += 64;
218 }
219 }
220
223 {
226
227 for (
i = 0;
i <
len;
i++) {
228 int64_t
a = INT64_C(2097471) *
src[
i] + INT64_C(6291137) * prev;
229 int64_t
b = INT64_C(6291137) *
src[
i] + INT64_C(2097471) * prev;
233 }
234
235 *hist = prev;
236 }
237
244 const int32_t *filter_coeff, ptrdiff_t npcmblocks)
245 {
248
249 for (j = 0; j < npcmblocks; j++) {
250 // Load in one sample from each subband
251 for (
i = 0;
i < 32;
i++)
252 input[
i] = subband_samples_lo[
i][j];
253
254 // One subband sample generates 32 interpolated ones
256 hist2, filter_coeff,
258 pcm_samples += 32;
259 }
260 }
261
268 const int32_t *filter_coeff, ptrdiff_t npcmblocks)
269 {
272
273 if (!subband_samples_hi)
275
276 for (j = 0; j < npcmblocks; j++) {
277 // Load in one sample from each subband
278 if (subband_samples_hi) {
279 // Full 64 subbands, first 32 are residual coded
280 for (
i = 0;
i < 32;
i++)
281 input[
i] = subband_samples_lo[
i][j] + subband_samples_hi[
i][j];
282 for (
i = 32;
i < 64;
i++)
283 input[
i] = subband_samples_hi[
i][j];
284 } else {
285 // Only first 32 subbands
286 for (
i = 0;
i < 32;
i++)
287 input[
i] = subband_samples_lo[
i][j];
288 }
289
290 // One subband sample generates 64 interpolated ones
292 hist2, filter_coeff,
294 pcm_samples += 64;
295 }
296 }
297
299 {
301
304 }
305
308 {
310
311 for (
i = 0;
i <
len;
i++) {
315 }
316 }
317
319 {
321
324 }
325
327 {
329
332 }
333
335 {
337
340 }
341
343 {
345
347 dst[
i] =
mul16(dst[
i], scale_inv);
348 }
349
351 {
353
356 }
357
359 {
361
364 }
365
368 {
370
375
376 for (
i = 0;
i < 8;
i++,
src0--) {
380 }
381
382 for (
i = 0;
i <
len;
i++) {
385 }
386 }
387
389 const float *
coeff, ptrdiff_t ofs, ptrdiff_t
len)
390 {
391 float SW0 =
coeff[0];
392 float SW1 =
coeff[1];
393 float SW2 =
coeff[2];
394 float SW3 =
coeff[3];
395
400
401 float AL1 =
coeff[8];
402 float AL2 =
coeff[9];
403
405
406 // Short window and 8 point forward MDCT
407 for (
i = 0;
i <
len;
i++) {
409
410 float a =
src[-4] * SW0 -
src[-1] * SW3;
411 float b =
src[-3] * SW1 -
src[-2] * SW2;
412 float c =
src[ 2] * SW1 +
src[ 1] * SW2;
413 float d =
src[ 3] * SW0 +
src[ 0] * SW3;
414
419 }
420
421 // Aliasing cancellation for high frequencies
422 for (
i = 12;
i <
len - 1;
i++) {
431 }
432 }
433
435 const float iir[5][4], float hist[5][2],
437 {
440
441 for (
i = 0;
i < 64;
i++) {
443
444 for (j = 0; j <
factor; j++) {
445 for (k = 0; k < 5; k++) {
446 tmp = hist[k][0] * iir[k][0] + hist[k][1] * iir[k][1] + res;
447 res = hist[k][0] * iir[k][2] + hist[k][1] * iir[k][3] +
tmp;
448
449 hist[k][0] = hist[k][1];
451 }
452
454 res = 0;
455 }
456 }
457 }
458
460 {
463
469
474
476
482
484
487
488 #if ARCH_X86
490 #endif
491 }