[FFmpeg-cvslog] avfilter/af_acrossover: add precision option

Paul B Mahol git at videolan.org
Sat May 14 15:09:42 EEST 2022


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sat May 14 14:10:07 2022 +0200| [e6f0cec88041449475f37b82b76699d2f7b5b124] | committer: Paul B Mahol

avfilter/af_acrossover: add precision option

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e6f0cec88041449475f37b82b76699d2f7b5b124
---

 doc/filters.texi            | 16 ++++++++++++++++
 libavfilter/af_acrossover.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 59 insertions(+), 1 deletion(-)

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.
+
+ at item precision
+Set which precision to use when processing samples.
+
+ at table @option
+ at item auto
+Auto pick internal sample format depending on other filters.
+
+ at item float
+Always use single-floating point precision sample format.
+
+ at item double
+Always use double-floating point precision sample format.
+ at 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,
 };



More information about the ffmpeg-cvslog mailing list