History

avfilter/af_adynamicequalizer: simplify calculations

Paul B Mahol committed 3 years ago

Commit 889c2521 parent e52676e2 files · +11 −7Browse files

Unified · Split

2 files
  1. libavfilter/adynamicequalizer_template.c +10 −6
  2. libavfilter/af_adynamicequalizer.c +1 −1
libavfilter/adynamicequalizer_template.c+10−6
@@ -26,6 +26,7 @@ · 25 unmodified lines
2626 #undef FMIN
2727 #undef CLIP
2828 #undef SAMPLE_FORMAT
29+#undef EPSILON
2930 #undef FABS
3031 #if DEPTH == 32
3132 #define SAMPLE_FORMAT float
@@ -39,6 +40,7 @@ · 7 unmodified lines
3940 #define CLIP av_clipf
4041 #define FABS fabsf
4142 #define ftype float
43+#define EPSILON (1.f / (1 << 22))
4244 #else
4345 #define SAMPLE_FORMAT double
4446 #define SQRT sqrt
@@ -51,6 +53,7 @@ · 6 unmodified lines
5153 #define CLIP av_clipd
5254 #define FABS fabs
5355 #define ftype double
56+#define EPSILON (1.0 / (1LL << 51))
5457 #endif
5558
5659 #define fn3(a,b) a##_##b
@@ -147,9 +150,7 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n · 90 unmodified lines
147150 const ftype range = s->range;
148151 const ftype tfrequency = FMIN(s->tfrequency, sample_rate * 0.5);
149152 const ftype release = s->release_coef;
150− const ftype irelease = ONE - release;
151153 const ftype attack = s->attack_coef;
152− const ftype iattack = ONE - attack;
153154 const ftype tqfactor = s->tqfactor;
154155 const ftype itqfactor = ONE / tqfactor;
155156 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 · 42 unmodified lines
198199 detect = ONE;
199200 }
200201
201− if ((direction == 0 && detect > state[4]) || (direction == 1 && detect < state[4])) {
202− detect = iattack * detect + attack * state[4];
203− } else {
204− detect = irelease * detect + release * state[4];
202+ {
203+ ftype delta = detect - state[4];
204+
205+ if (delta > EPSILON)
206+ detect = state[4] + attack * delta;
207+ else if (delta < -EPSILON)
208+ detect = state[4] + release * delta;
205209 }
206210 }
207211
libavfilter/af_adynamicequalizer.c+1−1
@@ -76,7 +76,7 @@ static int query_formats(AVFilterContext *ctx) · 75 unmodified lines
7676
7777 static double get_coef(double x, double sr)
7878 {
79− return exp(-1000. / (x * sr));
79+ return 1.0 - exp(-1000. / (x * sr));
8080 }
8181
8282 typedef struct ThreadData {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t