History

avfilter/af_adynamicequalizer: simplify calculations

Paul B Mahol committed 3 years ago

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

Showing the changes to libavfilter (2 of 2 files). Show all

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
26#undef FMIN26#undef FMIN
27#undef CLIP27#undef CLIP
28#undef SAMPLE_FORMAT28#undef SAMPLE_FORMAT
29#undef EPSILON
29#undef FABS30#undef FABS
30#if DEPTH == 3231#if DEPTH == 32
31#define SAMPLE_FORMAT float32#define SAMPLE_FORMAT float
@@ -39,6 +40,7 @@ · 7 unmodified lines
39#define CLIP av_clipf40#define CLIP av_clipf
40#define FABS fabsf41#define FABS fabsf
41#define ftype float42#define ftype float
43#define EPSILON (1.f / (1 << 22))
42#else44#else
43#define SAMPLE_FORMAT double45#define SAMPLE_FORMAT double
44#define SQRT sqrt46#define SQRT sqrt
@@ -51,6 +53,7 @@ · 6 unmodified lines
51#define CLIP av_clipd53#define CLIP av_clipd
52#define FABS fabs54#define FABS fabs
53#define ftype double55#define ftype double
56#define EPSILON (1.0 / (1LL << 51))
54#endif57#endif
55 58
56#define fn3(a,b) a##_##b59#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
147 const ftype range = s->range;150 const ftype range = s->range;
148 const ftype tfrequency = FMIN(s->tfrequency, sample_rate * 0.5);151 const ftype tfrequency = FMIN(s->tfrequency, sample_rate * 0.5);
149 const ftype release = s->release_coef;152 const ftype release = s->release_coef;
150 const ftype irelease = ONE - release;
151 const ftype attack = s->attack_coef;153 const ftype attack = s->attack_coef;
152 const ftype iattack = ONE - attack;
153 const ftype tqfactor = s->tqfactor;154 const ftype tqfactor = s->tqfactor;
154 const ftype itqfactor = ONE / tqfactor;155 const ftype itqfactor = ONE / tqfactor;
155 const ftype fg = TAN(M_PI * tfrequency / sample_rate);156 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
198 detect = ONE;199 detect = ONE;
199 }200 }
200 201
201 if ((direction == 0 && detect > state[4]) || (direction == 1 && detect < state[4])) {202 {
202 detect = iattack * detect + attack * state[4];203 ftype delta = detect - state[4];
203 } else {204
204 detect = irelease * detect + release * state[4];205 if (delta > EPSILON)
206 detect = state[4] + attack * delta;
207 else if (delta < -EPSILON)
208 detect = state[4] + release * delta;
205 }209 }
206 }210 }
207 211
libavfilter/af_adynamicequalizer.c+1−1
@@ -76,7 +76,7 @@ static int query_formats(AVFilterContext *ctx) · 75 unmodified lines
76 76
77static double get_coef(double x, double sr)77static double get_coef(double x, double sr)
78{78{
79 return exp(-1000. / (x * sr));79 return 1.0 - exp(-1000. / (x * sr));
80}80}
81 81
82typedef struct ThreadData {82typedef 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