aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2023-11-05 15:52:46 +0100
committerPaul B Mahol <onemda@gmail.com>2023-11-05 16:00:29 +0100
commit44a0148fadc97798acf6c93016a14e7c956f0825 (patch)
treed3bf54b0b5fd9544886297808bb3a26264127186
parent799fad18280382e67b2a7d1834a7aed7e5f159d5 (diff)
downloadffmpeg-44a0148fadc97798acf6c93016a14e7c956f0825.tar.gz
avfilter/af_adynamicequalizer: do detection of threshold first
Makes better results in final output if multiple filters are cascaded at once.
-rw-r--r--libavfilter/adynamicequalizer_template.c29
-rw-r--r--libavfilter/af_adynamicequalizer.c2
2 files changed, 23 insertions, 8 deletions
diff --git a/libavfilter/adynamicequalizer_template.c b/libavfilter/adynamicequalizer_template.c
index d77570da83..c5830db215 100644
--- a/libavfilter/adynamicequalizer_template.c
+++ b/libavfilter/adynamicequalizer_template.c
@@ -158,25 +158,41 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n
const ftype fg = TAN(M_PI * tfrequency / sample_rate);
const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs;
const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
+ const int is_disabled = ctx->is_disabled;
const int detection = s->detection;
const int tftype = s->tftype;
const ftype *da = fn(s->da);
const ftype *dm = fn(s->dm);
+ if (detection > 0) {
+ for (int ch = start; ch < end; ch++) {
+ const ftype *src = (const ftype *)in->extended_data[ch];
+ ChannelContext *cc = &s->cc[ch];
+ ftype *tstate = fn(cc->tstate);
+
+ for (int n = 0; n < in->nb_samples; n++) {
+ ftype detect = fn(get_svf)(src[n], dm, da, tstate);
+ fn(cc->threshold) = FMAX(fn(cc->threshold), detect);
+ }
+ }
+ } else if (detection < 0) {
+ for (int ch = start; ch < end; ch++) {
+ ChannelContext *cc = &s->cc[ch];
+ fn(cc->threshold) = s->threshold;
+ }
+ }
+
for (int ch = start; ch < end; ch++) {
const ftype *src = (const ftype *)in->extended_data[ch];
ftype *dst = (ftype *)out->extended_data[ch];
ChannelContext *cc = &s->cc[ch];
- const ftype threshold = detection == 0 ? fn(cc->threshold) : s->threshold;
+ const ftype threshold = fn(cc->threshold);
ftype *fa = fn(cc->fa), *fm = fn(cc->fm);
ftype *fstate = fn(cc->fstate);
ftype *dstate = fn(cc->dstate);
ftype gain = fn(cc->gain);
const int init = cc->init;
- if (detection < 0)
- fn(cc->threshold) = threshold;
-
for (int n = 0; n < out->nb_samples; n++) {
ftype detect, v, listen, new_gain = ONE;
ftype k, g;
@@ -184,9 +200,6 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n
detect = listen = fn(get_svf)(src[n], dm, da, dstate);
detect = FABS(detect);
- if (detection > 0)
- fn(cc->threshold) = FMAX(fn(cc->threshold), detect);
-
switch (mode) {
case LISTEN:
break;
@@ -258,7 +271,7 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n
v = fn(get_svf)(src[n], fm, fa, fstate);
v = mode == -1 ? listen : v;
- dst[n] = ctx->is_disabled ? src[n] : v;
+ dst[n] = is_disabled ? src[n] : v;
}
fn(cc->gain) = gain;
diff --git a/libavfilter/af_adynamicequalizer.c b/libavfilter/af_adynamicequalizer.c
index 9bdd56f7a5..ae51bdd075 100644
--- a/libavfilter/af_adynamicequalizer.c
+++ b/libavfilter/af_adynamicequalizer.c
@@ -36,11 +36,13 @@ typedef struct ChannelContext {
double fa_double[3], fm_double[3];
double dstate_double[2];
double fstate_double[2];
+ double tstate_double[2];
double gain_double;
double threshold_double;
float fa_float[3], fm_float[3];
float dstate_float[2];
float fstate_float[2];
+ float tstate_float[2];
float gain_float;
float threshold_float;
int init;