FFmpeg
Loading...
Searching...
No Matches
arls_template.c
Go to the documentation of this file.
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
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
64static 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
132static 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 = ff_slice_pos(out->ch_layout.nb_channels, jobnr, nb_jobs);
137 const int end = ff_slice_pos(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}
static ftype fn fir_sample(AudioAPContext *s, ftype sample, ftype *delay, ftype *coeffs, ftype *tmp, int *offset)
#define ftype
static ftype fn process_sample(AudioAPContext *s, ftype input, ftype desired, int ch)
#define ZERO
static int fn filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
@ NOISE_MODE
Definition af_aap.c:36
@ ERROR_MODE
Definition af_aap.c:37
@ IN_MODE
Definition af_aap.c:33
@ DESIRED_MODE
Definition af_aap.c:34
@ OUT_MODE
Definition af_aap.c:35
#define fn(a)
#define HALF
Definition bgmc.c:36
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define sample
#define ONE
Definition jrevdct.c:137
unsigned offset
Definition libaomenc.c:763
#define u(width, name, range_min, range_max)
Definition cbs_apv.c:68
const char * arg
Definition jacosubdec.c:65
static int ff_slice_pos(int total, int jobnr, int nb_jobs)
Compute the boundary index for a slice when work of size total is split into nb_jobs slices.
Definition filters.h:763
unsigned int pos
Definition spdifenc.c:431
An instance of a filter.
Definition avfilter.h:273
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
static uint8_t tmp[40]
Definition aes_ctr.c:52
static FILE * out
Definition movenc.c:55
static AVFormatContext * ctx
Definition movenc.c:49
const char * g
Definition vf_curves.c:128
static double c[64]