| @@ -26,6 +26,7 @@ · 25 unmodified lines |
| 26 | 26 | #undef FMIN |
| 27 | 27 | #undef CLIP |
| 28 | 28 | #undef SAMPLE_FORMAT |
| 29 | +#undef EPSILON |
| 29 | 30 | #undef FABS |
| 30 | 31 | #if DEPTH == 32 |
| 31 | 32 | #define SAMPLE_FORMAT float |
| @@ -39,6 +40,7 @@ · 7 unmodified lines |
| 39 | 40 | #define CLIP av_clipf |
| 40 | 41 | #define FABS fabsf |
| 41 | 42 | #define ftype float |
| 43 | +#define EPSILON (1.f / (1 << 22)) |
| 42 | 44 | #else |
| 43 | 45 | #define SAMPLE_FORMAT double |
| 44 | 46 | #define SQRT sqrt |
| @@ -51,6 +53,7 @@ · 6 unmodified lines |
| 51 | 53 | #define CLIP av_clipd |
| 52 | 54 | #define FABS fabs |
| 53 | 55 | #define ftype double |
| 56 | +#define EPSILON (1.0 / (1LL << 51)) |
| 54 | 57 | #endif |
| 55 | 58 | |
| 56 | 59 | #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 | 150 | const ftype range = s->range; |
| 148 | 151 | const ftype tfrequency = FMIN(s->tfrequency, sample_rate * 0.5); |
| 149 | 152 | const ftype release = s->release_coef; |
| 150 | | − const ftype irelease = ONE - release; |
| 151 | 153 | const ftype attack = s->attack_coef; |
| 152 | | − const ftype iattack = ONE - attack; |
| 153 | 154 | const ftype tqfactor = s->tqfactor; |
| 154 | 155 | const ftype itqfactor = ONE / tqfactor; |
| 155 | 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 | 199 | detect = ONE; |
| 199 | 200 | } |
| 200 | 201 | |
| 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; |
| 205 | 209 | } |
| 206 | 210 | } |
| 207 | 211 | |