[FFmpeg-cvslog] avfilter/af_adynamicequalizer: simplify calculations
Paul B Mahol
git at videolan.org
Sun Jul 9 12:52:08 EEST 2023
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Thu Jul 6 16:47:02 2023 +0200| [889c2529cc6ef65bb4c4f10aa79ca7ca0070a1aa] | committer: Paul B Mahol
avfilter/af_adynamicequalizer: simplify calculations
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=889c2529cc6ef65bb4c4f10aa79ca7ca0070a1aa
---
libavfilter/adynamicequalizer_template.c | 16 ++++++++++------
libavfilter/af_adynamicequalizer.c | 2 +-
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/libavfilter/adynamicequalizer_template.c b/libavfilter/adynamicequalizer_template.c
index 4f7d58c939..ee9f4a1d5f 100644
--- a/libavfilter/adynamicequalizer_template.c
+++ b/libavfilter/adynamicequalizer_template.c
@@ -26,6 +26,7 @@
#undef FMIN
#undef CLIP
#undef SAMPLE_FORMAT
+#undef EPSILON
#undef FABS
#if DEPTH == 32
#define SAMPLE_FORMAT float
@@ -39,6 +40,7 @@
#define CLIP av_clipf
#define FABS fabsf
#define ftype float
+#define EPSILON (1.f / (1 << 22))
#else
#define SAMPLE_FORMAT double
#define SQRT sqrt
@@ -51,6 +53,7 @@
#define CLIP av_clipd
#define FABS fabs
#define ftype double
+#define EPSILON (1.0 / (1LL << 51))
#endif
#define fn3(a,b) a##_##b
@@ -147,9 +150,7 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n
const ftype range = s->range;
const ftype tfrequency = FMIN(s->tfrequency, sample_rate * 0.5);
const ftype release = s->release_coef;
- const ftype irelease = ONE - release;
const ftype attack = s->attack_coef;
- const ftype iattack = ONE - attack;
const ftype tqfactor = s->tqfactor;
const ftype itqfactor = ONE / tqfactor;
const ftype fg = TAN(M_PI * tfrequency / sample_rate);
@@ -198,10 +199,13 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n
detect = ONE;
}
- if ((direction == 0 && detect > state[4]) || (direction == 1 && detect < state[4])) {
- detect = iattack * detect + attack * state[4];
- } else {
- detect = irelease * detect + release * state[4];
+ {
+ ftype delta = detect - state[4];
+
+ if (delta > EPSILON)
+ detect = state[4] + attack * delta;
+ else if (delta < -EPSILON)
+ detect = state[4] + release * delta;
}
}
diff --git a/libavfilter/af_adynamicequalizer.c b/libavfilter/af_adynamicequalizer.c
index 5a2c8efb2a..2a76827ada 100644
--- a/libavfilter/af_adynamicequalizer.c
+++ b/libavfilter/af_adynamicequalizer.c
@@ -76,7 +76,7 @@ static int query_formats(AVFilterContext *ctx)
static double get_coef(double x, double sr)
{
- return exp(-1000. / (x * sr));
+ return 1.0 - exp(-1000. / (x * sr));
}
typedef struct ThreadData {
More information about the ffmpeg-cvslog
mailing list