diff options
author | Paul B Mahol <onemda@gmail.com> | 2023-11-08 14:31:50 +0100 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2023-11-17 00:17:54 +0100 |
commit | 08e97dae205d10806a0360bfc62f654d629dda93 (patch) | |
tree | e70399bfe0e7fe00c3e85448d4369e72b50a689e /libavfilter/af_adynamicequalizer.c | |
parent | 82be1e5c0d828eef0b69307a61bc14f5b23ed595 (diff) |
avfilter/af_adynamicequalizer: add adaptive detection mode
Diffstat (limited to 'libavfilter/af_adynamicequalizer.c')
-rw-r--r-- | libavfilter/af_adynamicequalizer.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/libavfilter/af_adynamicequalizer.c b/libavfilter/af_adynamicequalizer.c index 1926ae8ec1..611e542c1b 100644 --- a/libavfilter/af_adynamicequalizer.c +++ b/libavfilter/af_adynamicequalizer.c @@ -29,6 +29,7 @@ enum DetectionModes { DET_DISABLED, DET_OFF, DET_ON, + DET_ADAPTIVE, NB_DMODES, }; @@ -50,6 +51,8 @@ typedef struct ChannelContext { double detect_double; double threshold_log_double; double new_threshold_log_double; + double log_sum_double; + double sum_double; float fa_float[3], fm_float[3]; float dstate_float[2]; float fstate_float[2]; @@ -58,6 +61,14 @@ typedef struct ChannelContext { float detect_float; float threshold_log_float; float new_threshold_log_float; + float log_sum_float; + float sum_float; + void *dqueue; + void *queue; + int position; + int size; + int front; + int back; int detection; int init; } ChannelContext; @@ -86,6 +97,7 @@ typedef struct AudioDynamicEqualizerContext { int dftype; int precision; int format; + int nb_channels; int (*filter_prepare)(AVFilterContext *ctx); int (*filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs); @@ -140,6 +152,7 @@ static int config_input(AVFilterLink *inlink) s->cc = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->cc)); if (!s->cc) return AVERROR(ENOMEM); + s->nb_channels = inlink->ch_layout.nb_channels; switch (s->format) { case AV_SAMPLE_FMT_DBLP: @@ -152,6 +165,14 @@ static int config_input(AVFilterLink *inlink) break; } + for (int ch = 0; ch < s->nb_channels; ch++) { + ChannelContext *cc = &s->cc[ch]; + cc->queue = av_calloc(inlink->sample_rate, sizeof(double)); + cc->dqueue = av_calloc(inlink->sample_rate, sizeof(double)); + if (!cc->queue || !cc->dqueue) + return AVERROR(ENOMEM); + } + return 0; } @@ -189,6 +210,11 @@ static av_cold void uninit(AVFilterContext *ctx) { AudioDynamicEqualizerContext *s = ctx->priv; + for (int ch = 0; ch < s->nb_channels; ch++) { + ChannelContext *cc = &s->cc[ch]; + av_freep(&cc->queue); + av_freep(&cc->dqueue); + } av_freep(&s->cc); } @@ -226,6 +252,7 @@ static const AVOption adynamicequalizer_options[] = { { "disabled", 0, 0, AV_OPT_TYPE_CONST, {.i64=DET_DISABLED}, 0, 0, FLAGS, "auto" }, { "off", 0, 0, AV_OPT_TYPE_CONST, {.i64=DET_OFF}, 0, 0, FLAGS, "auto" }, { "on", 0, 0, AV_OPT_TYPE_CONST, {.i64=DET_ON}, 0, 0, FLAGS, "auto" }, + { "adaptive", 0, 0, AV_OPT_TYPE_CONST, {.i64=DET_ADAPTIVE}, 0, 0, FLAGS, "auto" }, { "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" }, |