FFmpeg
Loading...
Searching...
No Matches
anlms_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 ONE
20#undef ftype
21#undef SAMPLE_FORMAT
22#if DEPTH == 32
23#define SAMPLE_FORMAT float
24#define ftype float
25#define ONE 1.f
26#else
27#define SAMPLE_FORMAT double
28#define ftype double
29#define ONE 1.0
30#endif
31
32#define fn3(a,b) a##_##b
33#define fn2(a,b) fn3(a,b)
34#define fn(a) fn2(a, SAMPLE_FORMAT)
35
37 ftype *coeffs, ftype *tmp, int *offset)
38{
39 const int order = s->order;
40 ftype output;
41
42 delay[*offset] = sample;
43
44 memcpy(tmp, coeffs + order - *offset, order * sizeof(ftype));
45
46#if DEPTH == 32
47 output = s->fdsp->scalarproduct_float(delay, tmp, s->kernel_size);
48#else
49 output = s->fdsp->scalarproduct_double(delay, tmp, s->kernel_size);
50#endif
51
52 if (--(*offset) < 0)
53 *offset = order - 1;
54
55 return output;
56}
57
59 ftype *delay, ftype *coeffs, ftype *tmp, int *offsetp)
60{
61 const int order = s->order;
62 const ftype leakage = s->leakage;
63 const ftype mu = s->mu;
64 const ftype a = ONE - leakage;
65 ftype sum, output, e, norm, b;
66 int offset = *offsetp;
67
68 delay[offset + order] = input;
69
70 output = fn(fir_sample)(s, input, delay, coeffs, tmp, offsetp);
71 e = desired - output;
72
73#if DEPTH == 32
74 sum = s->fdsp->scalarproduct_float(delay, delay, s->kernel_size);
75#else
76 sum = s->fdsp->scalarproduct_double(delay, delay, s->kernel_size);
77#endif
78 norm = s->eps + sum;
79 b = mu * e / norm;
80 if (s->anlmf)
81 b *= e * e;
82
83 memcpy(tmp, delay + offset, order * sizeof(ftype));
84
85#if DEPTH == 32
86 s->fdsp->vector_fmul_scalar(coeffs, coeffs, a, s->kernel_size);
87 s->fdsp->vector_fmac_scalar(coeffs, tmp, b, s->kernel_size);
88#else
89 s->fdsp->vector_dmul_scalar(coeffs, coeffs, a, s->kernel_size);
90 s->fdsp->vector_dmac_scalar(coeffs, tmp, b, s->kernel_size);
91#endif
92
93 memcpy(coeffs + order, coeffs, order * sizeof(ftype));
94
95 switch (s->output_mode) {
96 case IN_MODE: output = input; break;
97 case DESIRED_MODE: output = desired; break;
98 case OUT_MODE: output = desired - output; break;
99 case NOISE_MODE: output = input - output; break;
100 case ERROR_MODE: break;
101 }
102 return output;
103}
104
105static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
106{
107 AudioNLMSContext *s = ctx->priv;
108 AVFrame *out = arg;
109 const int start = ff_slice_pos(out->ch_layout.nb_channels, jobnr, nb_jobs);
110 const int end = ff_slice_pos(out->ch_layout.nb_channels, jobnr + 1, nb_jobs);
111
112 for (int c = start; c < end; c++) {
113 const ftype *input = (const ftype *)s->frame[0]->extended_data[c];
114 const ftype *desired = (const ftype *)s->frame[1]->extended_data[c];
115 ftype *delay = (ftype *)s->delay->extended_data[c];
116 ftype *coeffs = (ftype *)s->coeffs->extended_data[c];
117 ftype *tmp = (ftype *)s->tmp->extended_data[c];
118 int *offset = (int *)s->offset->extended_data[c];
119 ftype *output = (ftype *)out->extended_data[c];
120
121 for (int n = 0; n < out->nb_samples; n++) {
122 output[n] = fn(process_sample)(s, input[n], desired[n], delay, coeffs, tmp, offset);
123 if (ctx->is_disabled)
124 output[n] = input[n];
125 }
126 }
127
128 return 0;
129}
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)
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 s(width, name)
Definition cbs_vp9.c:198
#define sample
int a
#define b
Definition input.c:43
#define ONE
Definition jrevdct.c:137
unsigned offset
Definition libaomenc.c:763
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
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
static double c[64]