*/
#include "libavutil/channel_layout.h"
+#include "libavutil/ffmath.h"
#include "libavutil/opt.h"
#include "avfilter.h"
#include "audio.h"
double range;
double strength;
+ double slope;
double level_in;
double level_out;
double a0, a1, a2;
double b0, b1, b2;
- double i1, i2;
- double o1, o2;
+ double w1, w2;
} CrossfeedContext;
static int query_formats(AVFilterContext *ctx)
{
AVFilterContext *ctx = inlink->dst;
CrossfeedContext *s = ctx->priv;
- double A = exp(s->strength * -30 / 40 * log(10.));
+ double A = ff_exp10(s->strength * -30 / 40);
double w0 = 2 * M_PI * (1. - s->range) * 2100 / inlink->sample_rate;
double alpha;
- alpha = sin(w0) / 2 * sqrt(2 * (1 / 0.5 - 1) + 2);
+ alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->slope - 1) + 2);
s->a0 = (A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) * alpha;
s->a1 = -2 * ((A - 1) + (A + 1) * cos(w0));
const double b0 = s->b0;
const double b1 = s->b1;
const double b2 = s->b2;
- const double a1 = s->a1;
- const double a2 = s->a2;
+ const double a1 = -s->a1;
+ const double a2 = -s->a2;
AVFrame *out;
double *dst;
int n;
for (n = 0; n < out->nb_samples; n++, src += 2, dst += 2) {
double mid = (src[0] + src[1]) * level_in * .5;
double side = (src[0] - src[1]) * level_in * .5;
- double oside = side * b0 + s->i1 * b1 + s->i2 * b2 - s->o1 * a1 - s->o2 * a2;
+ double oside = side * b0 + s->w1;
- s->i2 = s->i1;
- s->i1 = side;
- s->o2 = s->o1;
- s->o1 = oside;
+ s->w1 = b1 * side + s->w2 + a1 * oside;
+ s->w2 = b2 * side + a2 * oside;
- dst[0] = (mid + oside) * level_out;
- dst[1] = (mid - oside) * level_out;
+ if (ctx->is_disabled) {
+ dst[0] = src[0];
+ dst[1] = src[1];
+ } else {
+ dst[0] = (mid + oside) * level_out;
+ dst[1] = (mid - oside) * level_out;
+ }
}
if (out != in)
return ff_filter_frame(outlink, out);
}
+static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
+ char *res, int res_len, int flags)
+{
+ int ret;
+
+ ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
+ if (ret < 0)
+ return ret;
+
+ return config_input(ctx->inputs[0]);
+}
+
#define OFFSET(x) offsetof(CrossfeedContext, x)
-#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
static const AVOption crossfeed_options[] = {
{ "strength", "set crossfeed strength", OFFSET(strength), AV_OPT_TYPE_DOUBLE, {.dbl=.2}, 0, 1, FLAGS },
{ "range", "set soundstage wideness", OFFSET(range), AV_OPT_TYPE_DOUBLE, {.dbl=.5}, 0, 1, FLAGS },
+ { "slope", "set curve slope", OFFSET(slope), AV_OPT_TYPE_DOUBLE, {.dbl=.5}, .01, 1, FLAGS },
{ "level_in", "set level in", OFFSET(level_in), AV_OPT_TYPE_DOUBLE, {.dbl=.9}, 0, 1, FLAGS },
{ "level_out", "set level out", OFFSET(level_out), AV_OPT_TYPE_DOUBLE, {.dbl=1.}, 0, 1, FLAGS },
{ NULL }
{ NULL }
};
-AVFilter ff_af_crossfeed = {
+const AVFilter ff_af_crossfeed = {
.name = "crossfeed",
.description = NULL_IF_CONFIG_SMALL("Apply headphone crossfeed filter."),
.query_formats = query_formats,
.priv_class = &crossfeed_class,
.inputs = inputs,
.outputs = outputs,
+ .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,
+ .process_command = process_command,
};