History

avfilter/af_asdr: add fltp sample format support

Paul B Mahol committed 3 years ago

Commit 80fdf511 parent 37b48371 file · +36 −28Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/af_asdr.c+36−28
@@ -31,36 +31,42 @@ typedef struct AudioSDRContext { · 30 unmodified lines
3131 double *sum_uv;
3232
3333 AVFrame *cache[2];
34−} AudioSDRContext;
35−
36−static int sdr(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
37−{
38− AudioSDRContext *s = ctx->priv;
39− AVFrame *u = s->cache[0];
40− AVFrame *v = s->cache[1];
41− const int channels = u->ch_layout.nb_channels;
42− const int start = (channels * jobnr) / nb_jobs;
43− const int end = (channels * (jobnr+1)) / nb_jobs;
44− const int nb_samples = u->nb_samples;
45−
46− for (int ch = start; ch < end; ch++) {
47− const double *const us = (double *)u->extended_data[ch];
48− const double *const vs = (double *)v->extended_data[ch];
49− double sum_uv = 0.;
50− double sum_u = 0.;
51−
52− for (int n = 0; n < nb_samples; n++) {
53− sum_u += us[n] * us[n];
54− sum_uv += (us[n] - vs[n]) * (us[n] - vs[n]);
55− }
5634
57− s->sum_uv[ch] += sum_uv;
58− s->sum_u[ch] += sum_u;
59− }
35+ int (*filter)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
36+} AudioSDRContext;
6037
61− return 0;
38+#define SDR_FILTER(name, type) \
39+static int sdr_##name(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)\
40+{ \
41+ AudioSDRContext *s = ctx->priv; \
42+ AVFrame *u = s->cache[0]; \
43+ AVFrame *v = s->cache[1]; \
44+ const int channels = u->ch_layout.nb_channels; \
45+ const int start = (channels * jobnr) / nb_jobs; \
46+ const int end = (channels * (jobnr+1)) / nb_jobs; \
47+ const int nb_samples = u->nb_samples; \
48+ \
49+ for (int ch = start; ch < end; ch++) { \
50+ const type *const us = (type *)u->extended_data[ch]; \
51+ const type *const vs = (type *)v->extended_data[ch]; \
52+ double sum_uv = 0.; \
53+ double sum_u = 0.; \
54+ \
55+ for (int n = 0; n < nb_samples; n++) { \
56+ sum_u += us[n] * us[n]; \
57+ sum_uv += (us[n] - vs[n]) * (us[n] - vs[n]); \
58+ } \
59+ \
60+ s->sum_uv[ch] += sum_uv; \
61+ s->sum_u[ch] += sum_u; \
62+ } \
63+ \
64+ return 0; \
6265 }
6366
67+SDR_FILTER(fltp, float)
68+SDR_FILTER(dblp, double)
69+
6470 static int activate(AVFilterContext *ctx)
6571 {
6672 AudioSDRContext *s = ctx->priv;
@@ -84,7 +90,7 @@ static int activate(AVFilterContext *ctx) · 17 unmodified lines
8490 }
8591
8692 if (!ctx->is_disabled)
87− ff_filter_execute(ctx, sdr, NULL, NULL,
93+ ff_filter_execute(ctx, s->filter, NULL, NULL,
8894 FFMIN(outlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
8995
9096 av_frame_free(&s->cache[1]);
@@ -120,6 +126,7 @@ static int config_output(AVFilterLink *outlink) · 29 unmodified lines
120126 AudioSDRContext *s = ctx->priv;
121127
122128 s->channels = inlink->ch_layout.nb_channels;
129+ s->filter = inlink->format == AV_SAMPLE_FMT_FLTP ? sdr_fltp : sdr_dblp;
123130
124131 s->sum_u = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->sum_u));
125132 s->sum_uv = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->sum_uv));
@@ -173,5 +180,6 @@ const AVFilter ff_af_asdr = { · 47 unmodified lines
173180 AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,
174181 FILTER_INPUTS(inputs),
175182 FILTER_OUTPUTS(outputs),
176− FILTER_SINGLE_SAMPLEFMT(AV_SAMPLE_FMT_DBLP),
183+ FILTER_SAMPLEFMTS(AV_SAMPLE_FMT_FLTP,
184+ AV_SAMPLE_FMT_DBLP),
177185 };

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t