[FFmpeg-cvslog] avfilter/af_adynamicequalizer: always start filtering from unit gain
Paul B Mahol
git at videolan.org
Sun Nov 5 16:53:28 EET 2023
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sun Nov 5 11:47:38 2023 +0100| [799fad18280382e67b2a7d1834a7aed7e5f159d5] | committer: Paul B Mahol
avfilter/af_adynamicequalizer: always start filtering from unit gain
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=799fad18280382e67b2a7d1834a7aed7e5f159d5
---
libavfilter/adynamicequalizer_template.c | 18 +++++++++---------
libavfilter/af_adynamicequalizer.c | 7 +++++++
2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/libavfilter/adynamicequalizer_template.c b/libavfilter/adynamicequalizer_template.c
index 617ab95b09..d77570da83 100644
--- a/libavfilter/adynamicequalizer_template.c
+++ b/libavfilter/adynamicequalizer_template.c
@@ -149,6 +149,8 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n
const ftype ratio = s->ratio;
const ftype range = s->range;
const ftype tfrequency = FMIN(s->tfrequency, sample_rate * 0.5);
+ const int mode = s->mode;
+ const int power = (mode == CUT_BELOW || mode == CUT_ABOVE) ? -1 : 1;
const ftype release = s->release_coef;
const ftype attack = s->attack_coef;
const ftype tqfactor = s->tqfactor;
@@ -158,7 +160,6 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n
const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
const int detection = s->detection;
const int tftype = s->tftype;
- const int mode = s->mode;
const ftype *da = fn(s->da);
const ftype *dm = fn(s->dm);
@@ -171,6 +172,7 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n
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;
@@ -189,23 +191,20 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n
case LISTEN:
break;
case CUT_BELOW:
- if (detect < threshold)
- new_gain = ONE / CLIP(ONE + makeup + (threshold - detect) * ratio, ONE, range);
- break;
- case CUT_ABOVE:
- if (detect > threshold)
- new_gain = ONE / CLIP(ONE + makeup + (detect - threshold) * ratio, ONE, range);
- break;
case BOOST_BELOW:
if (detect < threshold)
new_gain = CLIP(ONE + makeup + (threshold - detect) * ratio, ONE, range);
break;
+ case CUT_ABOVE:
case BOOST_ABOVE:
if (detect > threshold)
new_gain = CLIP(ONE + makeup + (detect - threshold) * ratio, ONE, range);
break;
}
+ if (power < 0)
+ new_gain = ONE / new_gain;
+
if (mode > LISTEN) {
ftype delta = new_gain - gain;
@@ -215,7 +214,7 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n
new_gain = gain + release * delta;
}
- if (gain != new_gain) {
+ if (gain != new_gain || !init) {
gain = new_gain;
switch (tftype) {
@@ -263,6 +262,7 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n
}
fn(cc->gain) = gain;
+ cc->init = 1;
}
return 0;
diff --git a/libavfilter/af_adynamicequalizer.c b/libavfilter/af_adynamicequalizer.c
index 04c7734c3e..9bdd56f7a5 100644
--- a/libavfilter/af_adynamicequalizer.c
+++ b/libavfilter/af_adynamicequalizer.c
@@ -43,6 +43,7 @@ typedef struct ChannelContext {
float fstate_float[2];
float gain_float;
float threshold_float;
+ int init;
} ChannelContext;
typedef struct AudioDynamicEqualizerContext {
@@ -132,6 +133,12 @@ static int config_input(AVFilterLink *inlink)
break;
}
+ for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
+ ChannelContext *cc = &s->cc[ch];
+ cc->gain_float = 1.f;
+ cc->gain_double = 1.0;
+ }
+
return 0;
}
More information about the ffmpeg-cvslog
mailing list