History

avfilter/af_acrossover: add even more orders

Paul B Mahol committed 5 years ago

Commit cc747001 parent bc529ea2 files · +41 −17Browse files

Unified · Split

2 files
  1. doc/filters.texi +15 −1
  2. libavfilter/af_acrossover.c +26 −16
doc/filters.texi+15−1
@@ -523,7 +523,21 @@ The filter accepts the following options: · 522 unmodified lines
523523 Set split frequencies. Those must be positive and increasing.
524524
525525 @item order
526−Set filter order, can be @var{2nd}, @var{4th} or @var{8th}.
526+Set filter order. Availabe values are:
527+
528+@table @samp
529+@item 2nd
530+@item 4th
531+@item 6th
532+@item 8th
533+@item 10th
534+@item 12th
535+@item 14th
536+@item 16th
537+@item 18th
538+@item 20th
539+@end table
540+
527541 Default is @var{4th}.
528542 @end table
529543
libavfilter/af_acrossover.c+26−16
@@ -45,8 +45,8 @@ typedef struct BiquadContext { · 44 unmodified lines
4545 } BiquadContext;
4646
4747 typedef struct CrossoverChannel {
48− BiquadContext lp[MAX_BANDS][16];
49− BiquadContext hp[MAX_BANDS][16];
48+ BiquadContext lp[MAX_BANDS][20];
49+ BiquadContext hp[MAX_BANDS][20];
5050 } CrossoverChannel;
5151
5252 typedef struct AudioCrossoverContext {
@@ -71,12 +71,17 @@ typedef struct AudioCrossoverContext { · 18 unmodified lines
7171
7272 static const AVOption acrossover_options[] = {
7373 { "split", "set split frequencies", OFFSET(splits_str), AV_OPT_TYPE_STRING, {.str="500"}, 0, 0, AF },
74− { "order", "set order", OFFSET(order_opt), AV_OPT_TYPE_INT, {.i64=1}, 0, 4, AF, "m" },
74+ { "order", "set order", OFFSET(order_opt), AV_OPT_TYPE_INT, {.i64=1}, 0, 9, AF, "m" },
7575 { "2nd", "2nd order", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "m" },
7676 { "4th", "4th order", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "m" },
77− { "8th", "8th order", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "m" },
78− { "12th", "12th order", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "m" },
79− { "16th", "16th order", 0, AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, AF, "m" },
77+ { "6th", "6th order", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "m" },
78+ { "8th", "8th order", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "m" },
79+ { "10th", "10th order", 0, AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, AF, "m" },
80+ { "12th", "12th order", 0, AV_OPT_TYPE_CONST, {.i64=5}, 0, 0, AF, "m" },
81+ { "14th", "14th order", 0, AV_OPT_TYPE_CONST, {.i64=6}, 0, 0, AF, "m" },
82+ { "16th", "16th order", 0, AV_OPT_TYPE_CONST, {.i64=7}, 0, 0, AF, "m" },
83+ { "18th", "18th order", 0, AV_OPT_TYPE_CONST, {.i64=8}, 0, 0, AF, "m" },
84+ { "20th", "20th order", 0, AV_OPT_TYPE_CONST, {.i64=9}, 0, 0, AF, "m" },
8085 { NULL }
8186 };
8287
@@ -169,12 +174,10 @@ static void set_hp(BiquadContext *b, double fc, double q, double sr) · 86 unmodified lines
169174
170175 static void calc_q_factors(int order, double *q)
171176 {
172− int num = 1, den = 4 * order;
177+ double n = order / 2.;
173178
174− for (int i = 0; i < order; i++) {
175− q[i] = fabs(1. / (2. * cos(num * M_PI / den)));
176− num += 2;
177− }
179+ for (int i = 0; i < n / 2; i++)
180+ q[i] = 1. / (-2. * cos(M_PI * (2. * (i + 1) + n - 1.) / (2. * n)));
178181 }
179182
180183 static int config_input(AVFilterLink *inlink)
@@ -182,20 +185,27 @@ static int config_input(AVFilterLink *inlink) · 1 unmodified line
182185 AVFilterContext *ctx = inlink->dst;
183186 AudioCrossoverContext *s = ctx->priv;
184187 int sample_rate = inlink->sample_rate;
185− double q[16] = { 0.5 };
188+ int first_order;
189+ double q[16];
186190
187191 s->xover = av_calloc(inlink->channels, sizeof(*s->xover));
188192 if (!s->xover)
189193 return AVERROR(ENOMEM);
190194
191− s->order = FFMAX(2, s->order_opt * 4);
195+ s->order = (s->order_opt + 1) * 2;
192196 s->filter_count = s->order / 2;
193− calc_q_factors(s->filter_count / 2, q + (s->order == 2));
197+ first_order = s->filter_count & 1;
198+ calc_q_factors(s->order, q);
194199
195200 for (int ch = 0; ch < inlink->channels; ch++) {
196201 for (int band = 0; band <= s->nb_splits; band++) {
197− for (int n = 0; n < s->filter_count; n++) {
198− const int idx = (n + (s->order == 2)) / 2;
202+ if (first_order) {
203+ set_lp(&s->xover[ch].lp[band][0], s->splits[band], 0.5, sample_rate);
204+ set_hp(&s->xover[ch].hp[band][0], s->splits[band], 0.5, sample_rate);
205+ }
206+
207+ for (int n = first_order; n < s->filter_count; n++) {
208+ const int idx = s->filter_count / 2 - ((n + first_order) / 2 - first_order) - 1;
199209
200210 set_lp(&s->xover[ch].lp[band][n], s->splits[band], q[idx], sample_rate);
201211 set_hp(&s->xover[ch].hp[band][n], s->splits[band], q[idx], sample_rate);

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