diff options
author | Paul B Mahol <onemda@gmail.com> | 2023-11-05 11:47:38 +0100 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2023-11-05 16:00:28 +0100 |
commit | 799fad18280382e67b2a7d1834a7aed7e5f159d5 (patch) | |
tree | 3696aa0074718ad2126aff1fd287d0f810a000e7 | |
parent | f9fdaa2ca92f1d111c5797e202ea48e6c3eb914f (diff) | |
download | ffmpeg-799fad18280382e67b2a7d1834a7aed7e5f159d5.tar.gz |
avfilter/af_adynamicequalizer: always start filtering from unit gain
-rw-r--r-- | libavfilter/adynamicequalizer_template.c | 18 | ||||
-rw-r--r-- | 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; } |