Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* This file is part of FFmpeg. |
3 |
|
|
* |
4 |
|
|
* FFmpeg is free software; you can redistribute it and/or |
5 |
|
|
* modify it under the terms of the GNU Lesser General Public |
6 |
|
|
* License as published by the Free Software Foundation; either |
7 |
|
|
* version 2.1 of the License, or (at your option) any later version. |
8 |
|
|
* |
9 |
|
|
* FFmpeg is distributed in the hope that it will be useful, |
10 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 |
|
|
* Lesser General Public License for more details. |
13 |
|
|
* |
14 |
|
|
* You should have received a copy of the GNU Lesser General Public |
15 |
|
|
* License along with FFmpeg; if not, write to the Free Software |
16 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
17 |
|
|
*/ |
18 |
|
|
|
19 |
|
|
#undef ZERO |
20 |
|
|
#undef HALF |
21 |
|
|
#undef ONE |
22 |
|
|
#undef ftype |
23 |
|
|
#undef SAMPLE_FORMAT |
24 |
|
|
#if DEPTH == 32 |
25 |
|
|
#define SAMPLE_FORMAT float |
26 |
|
|
#define ftype float |
27 |
|
|
#define ONE 1.f |
28 |
|
|
#define HALF 0.5f |
29 |
|
|
#define ZERO 0.f |
30 |
|
|
#else |
31 |
|
|
#define SAMPLE_FORMAT double |
32 |
|
|
#define ftype double |
33 |
|
|
#define ONE 1.0 |
34 |
|
|
#define HALF 0.5 |
35 |
|
|
#define ZERO 0.0 |
36 |
|
|
#endif |
37 |
|
|
|
38 |
|
|
#define fn3(a,b) a##_##b |
39 |
|
|
#define fn2(a,b) fn3(a,b) |
40 |
|
|
#define fn(a) fn2(a, SAMPLE_FORMAT) |
41 |
|
|
|
42 |
|
✗ |
static ftype fn(fir_sample)(AudioRLSContext *s, ftype sample, ftype *delay, |
43 |
|
|
ftype *coeffs, ftype *tmp, int *offset) |
44 |
|
|
{ |
45 |
|
✗ |
const int order = s->order; |
46 |
|
|
ftype output; |
47 |
|
|
|
48 |
|
✗ |
delay[*offset] = sample; |
49 |
|
|
|
50 |
|
✗ |
memcpy(tmp, coeffs + order - *offset, order * sizeof(ftype)); |
51 |
|
|
|
52 |
|
|
#if DEPTH == 32 |
53 |
|
✗ |
output = s->fdsp->scalarproduct_float(delay, tmp, s->kernel_size); |
54 |
|
|
#else |
55 |
|
✗ |
output = s->fdsp->scalarproduct_double(delay, tmp, s->kernel_size); |
56 |
|
|
#endif |
57 |
|
|
|
58 |
|
✗ |
if (--(*offset) < 0) |
59 |
|
✗ |
*offset = order - 1; |
60 |
|
|
|
61 |
|
✗ |
return output; |
62 |
|
|
} |
63 |
|
|
|
64 |
|
✗ |
static ftype fn(process_sample)(AudioRLSContext *s, ftype input, ftype desired, int ch) |
65 |
|
|
{ |
66 |
|
✗ |
ftype *coeffs = (ftype *)s->coeffs->extended_data[ch]; |
67 |
|
✗ |
ftype *delay = (ftype *)s->delay->extended_data[ch]; |
68 |
|
✗ |
ftype *gains = (ftype *)s->gains->extended_data[ch]; |
69 |
|
✗ |
ftype *tmp = (ftype *)s->tmp->extended_data[ch]; |
70 |
|
✗ |
ftype *u = (ftype *)s->u->extended_data[ch]; |
71 |
|
✗ |
ftype *p = (ftype *)s->p->extended_data[ch]; |
72 |
|
✗ |
ftype *dp = (ftype *)s->dp->extended_data[ch]; |
73 |
|
✗ |
int *offsetp = (int *)s->offset->extended_data[ch]; |
74 |
|
✗ |
const int kernel_size = s->kernel_size; |
75 |
|
✗ |
const int order = s->order; |
76 |
|
✗ |
const ftype lambda = s->lambda; |
77 |
|
✗ |
int offset = *offsetp; |
78 |
|
✗ |
ftype g = lambda; |
79 |
|
|
ftype output, e; |
80 |
|
|
|
81 |
|
✗ |
delay[offset + order] = input; |
82 |
|
|
|
83 |
|
✗ |
output = fn(fir_sample)(s, input, delay, coeffs, tmp, offsetp); |
84 |
|
✗ |
e = desired - output; |
85 |
|
|
|
86 |
|
✗ |
for (int i = 0, pos = offset; i < order; i++, pos++) { |
87 |
|
✗ |
const int ikernel_size = i * kernel_size; |
88 |
|
|
|
89 |
|
✗ |
u[i] = ZERO; |
90 |
|
✗ |
for (int k = 0, pos = offset; k < order; k++, pos++) |
91 |
|
✗ |
u[i] += p[ikernel_size + k] * delay[pos]; |
92 |
|
|
|
93 |
|
✗ |
g += u[i] * delay[pos]; |
94 |
|
|
} |
95 |
|
|
|
96 |
|
✗ |
g = ONE / g; |
97 |
|
|
|
98 |
|
✗ |
for (int i = 0; i < order; i++) { |
99 |
|
✗ |
const int ikernel_size = i * kernel_size; |
100 |
|
|
|
101 |
|
✗ |
gains[i] = u[i] * g; |
102 |
|
✗ |
coeffs[i] = coeffs[order + i] = coeffs[i] + gains[i] * e; |
103 |
|
✗ |
tmp[i] = ZERO; |
104 |
|
✗ |
for (int k = 0, pos = offset; k < order; k++, pos++) |
105 |
|
✗ |
tmp[i] += p[ikernel_size + k] * delay[pos]; |
106 |
|
|
} |
107 |
|
|
|
108 |
|
✗ |
for (int i = 0; i < order; i++) { |
109 |
|
✗ |
const int ikernel_size = i * kernel_size; |
110 |
|
|
|
111 |
|
✗ |
for (int k = 0; k < order; k++) |
112 |
|
✗ |
dp[ikernel_size + k] = gains[i] * tmp[k]; |
113 |
|
|
} |
114 |
|
|
|
115 |
|
✗ |
for (int i = 0; i < order; i++) { |
116 |
|
✗ |
const int ikernel_size = i * kernel_size; |
117 |
|
|
|
118 |
|
✗ |
for (int k = 0; k < order; k++) |
119 |
|
✗ |
p[ikernel_size + k] = (p[ikernel_size + k] - (dp[ikernel_size + k] + dp[kernel_size * k + i]) * HALF) * lambda; |
120 |
|
|
} |
121 |
|
|
|
122 |
|
✗ |
switch (s->output_mode) { |
123 |
|
✗ |
case IN_MODE: output = input; break; |
124 |
|
✗ |
case DESIRED_MODE: output = desired; break; |
125 |
|
✗ |
case OUT_MODE: output = desired - output; break; |
126 |
|
✗ |
case NOISE_MODE: output = input - output; break; |
127 |
|
✗ |
case ERROR_MODE: break; |
128 |
|
|
} |
129 |
|
✗ |
return output; |
130 |
|
|
} |
131 |
|
|
|
132 |
|
✗ |
static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) |
133 |
|
|
{ |
134 |
|
✗ |
AudioRLSContext *s = ctx->priv; |
135 |
|
✗ |
AVFrame *out = arg; |
136 |
|
✗ |
const int start = (out->ch_layout.nb_channels * jobnr) / nb_jobs; |
137 |
|
✗ |
const int end = (out->ch_layout.nb_channels * (jobnr+1)) / nb_jobs; |
138 |
|
|
|
139 |
|
✗ |
for (int c = start; c < end; c++) { |
140 |
|
✗ |
const ftype *input = (const ftype *)s->frame[0]->extended_data[c]; |
141 |
|
✗ |
const ftype *desired = (const ftype *)s->frame[1]->extended_data[c]; |
142 |
|
✗ |
ftype *output = (ftype *)out->extended_data[c]; |
143 |
|
|
|
144 |
|
✗ |
for (int n = 0; n < out->nb_samples; n++) { |
145 |
|
✗ |
output[n] = fn(process_sample)(s, input[n], desired[n], c); |
146 |
|
✗ |
if (ctx->is_disabled) |
147 |
|
✗ |
output[n] = input[n]; |
148 |
|
|
} |
149 |
|
|
} |
150 |
|
|
|
151 |
|
✗ |
return 0; |
152 |
|
|
} |
153 |
|
|
|