History

avfilter/af_acrossover: add even more orders

Paul B Mahol committed 5 years ago

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

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

Unified · Split

libavfilter/af_acrossover.c+26−16
@@ -45,8 +45,8 @@ typedef struct BiquadContext { · 44 unmodified lines
45} BiquadContext;45} BiquadContext;
46 46
47typedef struct CrossoverChannel {47typedef struct CrossoverChannel {
48 BiquadContext lp[MAX_BANDS][16];48 BiquadContext lp[MAX_BANDS][20];
49 BiquadContext hp[MAX_BANDS][16];49 BiquadContext hp[MAX_BANDS][20];
50} CrossoverChannel;50} CrossoverChannel;
51 51
52typedef struct AudioCrossoverContext {52typedef struct AudioCrossoverContext {
@@ -71,12 +71,17 @@ typedef struct AudioCrossoverContext { · 18 unmodified lines
71 71
72static const AVOption acrossover_options[] = {72static const AVOption acrossover_options[] = {
73 { "split", "set split frequencies", OFFSET(splits_str), AV_OPT_TYPE_STRING, {.str="500"}, 0, 0, AF },73 { "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" },
75 { "2nd", "2nd order", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "m" },75 { "2nd", "2nd order", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "m" },
76 { "4th", "4th order", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "m" },76 { "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" },77 { "6th", "6th 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" },78 { "8th", "8th 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" },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" },
80 { NULL }85 { NULL }
81};86};
82 87
@@ -169,12 +174,10 @@ static void set_hp(BiquadContext *b, double fc, double q, double sr) · 86 unmodified lines
169 174
170static void calc_q_factors(int order, double *q)175static void calc_q_factors(int order, double *q)
171{176{
172 int num = 1, den = 4 * order;177 double n = order / 2.;
173 178
174 for (int i = 0; i < order; i++) {179 for (int i = 0; i < n / 2; i++)
175 q[i] = fabs(1. / (2. * cos(num * M_PI / den)));180 q[i] = 1. / (-2. * cos(M_PI * (2. * (i + 1) + n - 1.) / (2. * n)));
176 num += 2;
177 }
178}181}
179 182
180static int config_input(AVFilterLink *inlink)183static int config_input(AVFilterLink *inlink)
@@ -182,20 +185,27 @@ static int config_input(AVFilterLink *inlink) · 1 unmodified line
182 AVFilterContext *ctx = inlink->dst;185 AVFilterContext *ctx = inlink->dst;
183 AudioCrossoverContext *s = ctx->priv;186 AudioCrossoverContext *s = ctx->priv;
184 int sample_rate = inlink->sample_rate;187 int sample_rate = inlink->sample_rate;
185 double q[16] = { 0.5 };188 int first_order;
189 double q[16];
186 190
187 s->xover = av_calloc(inlink->channels, sizeof(*s->xover));191 s->xover = av_calloc(inlink->channels, sizeof(*s->xover));
188 if (!s->xover)192 if (!s->xover)
189 return AVERROR(ENOMEM);193 return AVERROR(ENOMEM);
190 194
191 s->order = FFMAX(2, s->order_opt * 4);195 s->order = (s->order_opt + 1) * 2;
192 s->filter_count = s->order / 2;196 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);
194 199
195 for (int ch = 0; ch < inlink->channels; ch++) {200 for (int ch = 0; ch < inlink->channels; ch++) {
196 for (int band = 0; band <= s->nb_splits; band++) {201 for (int band = 0; band <= s->nb_splits; band++) {
197 for (int n = 0; n < s->filter_count; n++) {202 if (first_order) {
198 const int idx = (n + (s->order == 2)) / 2;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;
199 209
200 set_lp(&s->xover[ch].lp[band][n], s->splits[band], q[idx], sample_rate);210 set_lp(&s->xover[ch].lp[band][n], s->splits[band], q[idx], sample_rate);
201 set_hp(&s->xover[ch].hp[band][n], s->splits[band], q[idx], sample_rate);211 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