const AVClass *class;
char *splits_str;
+ char *gains_str;
int order_opt;
float level_in;
int first_order;
int ap_filter_count;
int nb_splits;
- float *splits;
+ float splits[MAX_SPLITS];
+
+ float gains[MAX_BANDS];
BiquadCoeffs lp[MAX_BANDS][20];
BiquadCoeffs hp[MAX_BANDS][20];
static const AVOption acrossover_options[] = {
{ "split", "set split frequencies", OFFSET(splits_str), AV_OPT_TYPE_STRING, {.str="500"}, 0, 0, AF },
- { "order", "set order", OFFSET(order_opt), AV_OPT_TYPE_INT, {.i64=1}, 0, 9, AF, "m" },
- { "2nd", "2nd order", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "m" },
- { "4th", "4th order", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "m" },
- { "6th", "6th order", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "m" },
- { "8th", "8th order", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "m" },
- { "10th", "10th order", 0, AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, AF, "m" },
- { "12th", "12th order", 0, AV_OPT_TYPE_CONST, {.i64=5}, 0, 0, AF, "m" },
- { "14th", "14th order", 0, AV_OPT_TYPE_CONST, {.i64=6}, 0, 0, AF, "m" },
- { "16th", "16th order", 0, AV_OPT_TYPE_CONST, {.i64=7}, 0, 0, AF, "m" },
- { "18th", "18th order", 0, AV_OPT_TYPE_CONST, {.i64=8}, 0, 0, AF, "m" },
- { "20th", "20th order", 0, AV_OPT_TYPE_CONST, {.i64=9}, 0, 0, AF, "m" },
+ { "order", "set filter order", OFFSET(order_opt), AV_OPT_TYPE_INT, {.i64=1}, 0, 9, AF, "m" },
+ { "2nd", "2nd order (12 dB/8ve)", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "m" },
+ { "4th", "4th order (24 dB/8ve)", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "m" },
+ { "6th", "6th order (36 dB/8ve)", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "m" },
+ { "8th", "8th order (48 dB/8ve)", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "m" },
+ { "10th", "10th order (60 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, AF, "m" },
+ { "12th", "12th order (72 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=5}, 0, 0, AF, "m" },
+ { "14th", "14th order (84 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=6}, 0, 0, AF, "m" },
+ { "16th", "16th order (96 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=7}, 0, 0, AF, "m" },
+ { "18th", "18th order (108 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=8}, 0, 0, AF, "m" },
+ { "20th", "20th order (120 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=9}, 0, 0, AF, "m" },
{ "level", "set input gain", OFFSET(level_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, AF },
+ { "gain", "set output bands gain", OFFSET(gains_str), AV_OPT_TYPE_STRING, {.str="1.f"}, 0, 0, AF },
{ NULL }
};
AVFILTER_DEFINE_CLASS(acrossover);
+static int parse_gains(AVFilterContext *ctx)
+{
+ AudioCrossoverContext *s = ctx->priv;
+ char *p, *arg, *saveptr = NULL;
+ int i, ret = 0;
+
+ saveptr = NULL;
+ p = s->gains_str;
+ for (i = 0; i < MAX_BANDS; i++) {
+ float gain;
+ char c[3] = { 0 };
+
+ if (!(arg = av_strtok(p, " |", &saveptr)))
+ break;
+
+ p = NULL;
+
+ if (av_sscanf(arg, "%f%2s", &gain, c) < 1) {
+ av_log(ctx, AV_LOG_ERROR, "Invalid syntax for gain[%d].\n", i);
+ ret = AVERROR(EINVAL);
+ break;
+ }
+
+ if (c[0] == 'd' && c[1] == 'B')
+ s->gains[i] = expf(gain * M_LN10 / 20.f);
+ else
+ s->gains[i] = gain;
+ }
+
+ for (; i < MAX_BANDS; i++)
+ s->gains[i] = 1.f;
+
+ return ret;
+}
+
static av_cold int init(AVFilterContext *ctx)
{
AudioCrossoverContext *s = ctx->priv;
if (!s->fdsp)
return AVERROR(ENOMEM);
- s->splits = av_calloc(MAX_SPLITS, sizeof(*s->splits));
- if (!s->splits)
- return AVERROR(ENOMEM);
-
p = s->splits_str;
for (i = 0; i < MAX_SPLITS; i++) {
float freq;
s->nb_splits = i;
+ ret = parse_gains(ctx);
+ if (ret < 0)
+ return ret;
+
for (i = 0; i <= s->nb_splits; i++) {
AVFilterPad pad = { 0 };
char *name;
const int end = (in->channels * (jobnr+1)) / nb_jobs; \
const int nb_samples = in->nb_samples; \
const int nb_outs = ctx->nb_outputs; \
+ const int first_order = s->first_order; \
\
for (int ch = start; ch < end; ch++) { \
const type *src = (const type *)in->extended_data[ch]; \
} \
\
for (int aband = band + 1; aband + 1 < nb_outs; aband++) { \
- if (s->first_order) { \
+ if (first_order) { \
const type *asrc = (const type *)frames[band]->extended_data[ch]; \
type *dst = (type *)frames[band]->extended_data[ch]; \
type *ap = xover + nb_outs * 40 + (aband * nb_outs + band) * 20; \
biquad_process_## name(apc, ap, dst, asrc, nb_samples); \
} \
\
- for (int f = s->first_order; f < s->ap_filter_count; f++) { \
+ for (int f = first_order; f < s->ap_filter_count; f++) { \
const type *asrc = (const type *)frames[band]->extended_data[ch]; \
type *dst = (type *)frames[band]->extended_data[ch]; \
type *ap = xover + nb_outs * 40 + (aband * nb_outs + band) * 20 + f * 2;\
} \
} \
\
- for (int band = 0; band < nb_outs && s->first_order; band++) { \
- if (band & 1) { \
- type *dst = (type *)frames[band]->extended_data[ch]; \
- s->fdsp->vector_## ff ##mul_scalar(dst, dst, -one, \
- FFALIGN(nb_samples, sizeof(type))); \
- } \
+ for (int band = 0; band < nb_outs; band++) { \
+ const type gain = s->gains[band] * ((band & 1 && first_order) ? -one : one); \
+ type *dst = (type *)frames[band]->extended_data[ch]; \
+ \
+ s->fdsp->vector_## ff ##mul_scalar(dst, dst, gain, \
+ FFALIGN(nb_samples, sizeof(type))); \
} \
} \
\
int i;
av_freep(&s->fdsp);
- av_freep(&s->splits);
av_frame_free(&s->xover);
for (i = 0; i < ctx->nb_outputs; i++)
{ NULL }
};
-AVFilter ff_af_acrossover = {
+const AVFilter ff_af_acrossover = {
.name = "acrossover",
.description = NULL_IF_CONFIG_SMALL("Split audio into per-bands streams."),
.priv_size = sizeof(AudioCrossoverContext),