History

avfilter/af_acrossover: add per output band gain

Paul B Mahol committed 5 years ago

Commit 0c8a0d31 parent 13df9bf2 files · +55 −8Browse files

Unified · Split

2 files
  1. doc/filters.texi +3 −0
  2. libavfilter/af_acrossover.c +52 −8
doc/filters.texi+3−0
@@ -554,6 +554,9 @@ Default is @var{4th}. · 553 unmodified lines
554554
555555 @item level
556556 Set input gain level. Allowed range is from 0 to 1. Default value is 1.
557+
558+@item gains
559+Set output gain for each band. Default value is 1 for all bands.
557560 @end table
558561
559562 @subsection Examples
libavfilter/af_acrossover.c+52−8
@@ -54,6 +54,7 @@ typedef struct AudioCrossoverContext { · 53 unmodified lines
5454 const AVClass *class;
5555
5656 char *splits_str;
57+ char *gains_str;
5758 int order_opt;
5859 float level_in;
5960
@@ -64,6 +65,8 @@ typedef struct AudioCrossoverContext { · 4 unmodified lines
6465 int nb_splits;
6566 float splits[MAX_SPLITS];
6667
68+ float gains[MAX_BANDS];
69+
6770 BiquadCoeffs lp[MAX_BANDS][20];
6871 BiquadCoeffs hp[MAX_BANDS][20];
6972 BiquadCoeffs ap[MAX_BANDS][20];
@@ -95,11 +98,47 @@ static const AVOption acrossover_options[] = { · 25 unmodified lines
9598 { "18th", "18th order (108 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=8}, 0, 0, AF, "m" },
9699 { "20th", "20th order (120 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=9}, 0, 0, AF, "m" },
97100 { "level", "set input gain", OFFSET(level_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, AF },
101+ { "gain", "set output bands gain", OFFSET(gains_str), AV_OPT_TYPE_STRING, {.str="1.f"}, 0, 0, AF },
98102 { NULL }
99103 };
100104
101105 AVFILTER_DEFINE_CLASS(acrossover);
102106
107+static int parse_gains(AVFilterContext *ctx)
108+{
109+ AudioCrossoverContext *s = ctx->priv;
110+ char *p, *arg, *saveptr = NULL;
111+ int i, ret = 0;
112+
113+ saveptr = NULL;
114+ p = s->gains_str;
115+ for (i = 0; i < MAX_BANDS; i++) {
116+ float gain;
117+ char c[3] = { 0 };
118+
119+ if (!(arg = av_strtok(p, " |", &saveptr)))
120+ break;
121+
122+ p = NULL;
123+
124+ if (av_sscanf(arg, "%f%2s", &gain, c) < 1) {
125+ av_log(ctx, AV_LOG_ERROR, "Invalid syntax for gain[%d].\n", i);
126+ ret = AVERROR(EINVAL);
127+ break;
128+ }
129+
130+ if (c[0] == 'd' && c[1] == 'B')
131+ s->gains[i] = expf(gain * M_LN10 / 20.f);
132+ else
133+ s->gains[i] = gain;
134+ }
135+
136+ for (; i < MAX_BANDS; i++)
137+ s->gains[i] = 1.f;
138+
139+ return ret;
140+}
141+
103142 static av_cold int init(AVFilterContext *ctx)
104143 {
105144 AudioCrossoverContext *s = ctx->priv;
@@ -138,6 +177,10 @@ static av_cold int init(AVFilterContext *ctx) · 32 unmodified lines
138177
139178 s->nb_splits = i;
140179
180+ ret = parse_gains(ctx);
181+ if (ret < 0)
182+ return ret;
183+
141184 for (i = 0; i <= s->nb_splits; i++) {
142185 AVFilterPad pad = { 0 };
143186 char *name;
@@ -349,6 +392,7 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, int jobnr, i · 205 unmodified lines
349392 const int end = (in->channels * (jobnr+1)) / nb_jobs; \
350393 const int nb_samples = in->nb_samples; \
351394 const int nb_outs = ctx->nb_outputs; \
395+ const int first_order = s->first_order; \
352396 \
353397 for (int ch = start; ch < end; ch++) { \
354398 const type *src = (const type *)in->extended_data[ch]; \
@@ -378,7 +422,7 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, int jobnr, i · 23 unmodified lines
378422 } \
379423 \
380424 for (int aband = band + 1; aband + 1 < nb_outs; aband++) { \
381− if (s->first_order) { \
425+ if (first_order) { \
382426 const type *asrc = (const type *)frames[band]->extended_data[ch]; \
383427 type *dst = (type *)frames[band]->extended_data[ch]; \
384428 type *ap = xover + nb_outs * 40 + (aband * nb_outs + band) * 20; \
@@ -387,7 +431,7 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, int jobnr, i · 2 unmodified lines
387431 biquad_process_## name(apc, ap, dst, asrc, nb_samples); \
388432 } \
389433 \
390− for (int f = s->first_order; f < s->ap_filter_count; f++) { \
434+ for (int f = first_order; f < s->ap_filter_count; f++) { \
391435 const type *asrc = (const type *)frames[band]->extended_data[ch]; \
392436 type *dst = (type *)frames[band]->extended_data[ch]; \
393437 type *ap = xover + nb_outs * 40 + (aband * nb_outs + band) * 20 + f * 2;\
@@ -398,12 +442,12 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, int jobnr, i · 4 unmodified lines
398442 } \
399443 } \
400444 \
401− for (int band = 0; band < nb_outs && s->first_order; band++) { \
402− if (band & 1) { \
403− type *dst = (type *)frames[band]->extended_data[ch]; \
404− s->fdsp->vector_## ff ##mul_scalar(dst, dst, -one, \
405− FFALIGN(nb_samples, sizeof(type))); \
406− } \
445+ for (int band = 0; band < nb_outs; band++) { \
446+ const type gain = s->gains[band] * ((band & 1 && first_order) ? -one : one); \
447+ type *dst = (type *)frames[band]->extended_data[ch]; \
448+ \
449+ s->fdsp->vector_## ff ##mul_scalar(dst, dst, gain, \
450+ FFALIGN(nb_samples, sizeof(type))); \
407451 } \
408452 } \
409453 \

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