summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2022-05-14 14:10:07 +0200
committerPaul B Mahol <onemda@gmail.com>2022-05-14 14:11:52 +0200
commite6f0cec88041449475f37b82b76699d2f7b5b124 (patch)
tree4a9312ad144677c73cdb50eea03ab0fea2f8895e
parent8b64d8d9aa7fede94ab531b7be3f73cd2f3c448c (diff)
avfilter/af_acrossover: add precision option
-rw-r--r--doc/filters.texi16
-rw-r--r--libavfilter/af_acrossover.c44
2 files changed, 59 insertions, 1 deletions
diff --git a/doc/filters.texi b/doc/filters.texi
index 45ebcccf1c..b6cbdc85cc 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -557,6 +557,22 @@ Set input gain level. Allowed range is from 0 to 1. Default value is 1.
@item gains
Set output gain for each band. Default value is 1 for all bands.
+
+@item precision
+Set which precision to use when processing samples.
+
+@table @option
+@item auto
+Auto pick internal sample format depending on other filters.
+
+@item float
+Always use single-floating point precision sample format.
+
+@item double
+Always use double-floating point precision sample format.
+@end table
+
+Default value is @code{auto}.
@end table
@subsection Examples
diff --git a/libavfilter/af_acrossover.c b/libavfilter/af_acrossover.c
index 8888518095..417e857133 100644
--- a/libavfilter/af_acrossover.c
+++ b/libavfilter/af_acrossover.c
@@ -58,6 +58,7 @@ typedef struct AudioCrossoverContext {
char *gains_str;
int order_opt;
float level_in;
+ int precision;
int order;
int filter_count;
@@ -99,11 +100,52 @@ static const AVOption acrossover_options[] = {
{ "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 },
+ { "precision", "set processing precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, AF, "precision" },
+ { "auto", "set auto processing precision", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision" },
+ { "float", "set single-floating point processing precision", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision" },
+ { "double","set double-floating point processing precision", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision" },
{ NULL }
};
AVFILTER_DEFINE_CLASS(acrossover);
+static int query_formats(AVFilterContext *ctx)
+{
+ AudioCrossoverContext *s = ctx->priv;
+ static const enum AVSampleFormat auto_sample_fmts[] = {
+ AV_SAMPLE_FMT_FLTP,
+ AV_SAMPLE_FMT_DBLP,
+ AV_SAMPLE_FMT_NONE
+ };
+ enum AVSampleFormat sample_fmts[] = {
+ AV_SAMPLE_FMT_FLTP,
+ AV_SAMPLE_FMT_NONE
+ };
+ const enum AVSampleFormat *sample_fmts_list = sample_fmts;
+ int ret = ff_set_common_all_channel_counts(ctx);
+ if (ret < 0)
+ return ret;
+
+ switch (s->precision) {
+ case 0:
+ sample_fmts_list = auto_sample_fmts;
+ break;
+ case 1:
+ sample_fmts[0] = AV_SAMPLE_FMT_FLTP;
+ break;
+ case 2:
+ sample_fmts[0] = AV_SAMPLE_FMT_DBLP;
+ break;
+ default:
+ break;
+ }
+ ret = ff_set_common_formats_from_list(ctx, sample_fmts_list);
+ if (ret < 0)
+ return ret;
+
+ return ff_set_common_all_samplerates(ctx);
+}
+
static int parse_gains(AVFilterContext *ctx)
{
AudioCrossoverContext *s = ctx->priv;
@@ -586,7 +628,7 @@ const AVFilter ff_af_acrossover = {
.uninit = uninit,
FILTER_INPUTS(inputs),
.outputs = NULL,
- FILTER_SAMPLEFMTS(AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_DBLP),
+ FILTER_QUERY_FUNC(query_formats),
.flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS |
AVFILTER_FLAG_SLICE_THREADS,
};