Showing the changes to LEAF/Src_cpp/leaf-filter.cpp (1 of 8 files). Show all
Unified · Split
| @@ -20,7 +20,44 @@ · 19 unmodified lines | ||
| 20 | 20 | #include "../Inc/leaf-wavetables.h" |
| 21 | 21 | #include "../leaf.h" |
| 22 | 22 | |
| 23 | −#endif | |
| 23 | +#endif | |
| 24 | + | |
| 25 | +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ OnePole Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // | |
| 26 | +void tAllpass_init(tAllpass* const f, float initDelay, uint32_t maxDelay) | |
| 27 | +{ | |
| 28 | + f->gain = 0.7f; | |
| 29 | + | |
| 30 | + f->lastOut = 0.0f; | |
| 31 | + | |
| 32 | + tDelayL_init(&f->delay, initDelay, maxDelay); | |
| 33 | +} | |
| 34 | + | |
| 35 | +void tAllpass_setDelay(tAllpass* const f, float delay) | |
| 36 | +{ | |
| 37 | + tDelayL_setDelay(&f->delay, delay); | |
| 38 | +} | |
| 39 | + | |
| 40 | +void tAllpass_free(tAllpass* const f) | |
| 41 | +{ | |
| 42 | + leaf_free(&f->delay); | |
| 43 | + leaf_free(f); | |
| 44 | +} | |
| 45 | + | |
| 46 | +void tAllpass_setGain(tAllpass* const f, float gain) | |
| 47 | +{ | |
| 48 | + f->gain = gain; | |
| 49 | +} | |
| 50 | + | |
| 51 | +float tAllpass_tick(tAllpass* const f, float input) | |
| 52 | +{ | |
| 53 | + float s1 = (-f->gain) * f->lastOut + input; | |
| 54 | + | |
| 55 | + float s2 = tDelayL_tick(&f->delay, s1) + (f->gain) * input; | |
| 56 | + | |
| 57 | + f->lastOut = s2; | |
| 58 | + | |
| 59 | + return f->lastOut; | |
| 60 | +} | |
| 24 | 61 | |
| 25 | 62 | void tButterworth_init(tButterworth* const f, int N, float f1, float f2) |
| 26 | 63 | { |
| @@ -239,12 +276,12 @@ void tTwoZeroSampleRateChanged(tTwoZero* const f) · 212 unmodified lines | ||
| 239 | 276 | } |
| 240 | 277 | |
| 241 | 278 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ OnePole Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // |
| 242 | −void tOnePole_init(tOnePole* const f, float thePole) | |
| 279 | +void tOnePole_init(tOnePole* const f, float freq) | |
| 243 | 280 | { |
| 244 | 281 | f->gain = 1.0f; |
| 245 | 282 | f->a0 = 1.0; |
| 246 | 283 | |
| 247 | − tOnePole_setPole(f, thePole); | |
| 284 | + tOnePole_setFreq(f, freq); | |
| 248 | 285 | |
| 249 | 286 | f->lastIn = 0.0f; |
| 250 | 287 | f->lastOut = 0.0f; |
| @@ -280,8 +317,11 @@ void tOnePole_setPole(tOnePole* const f, float thePole) · 29 unmodified lines | ||
| 280 | 317 | |
| 281 | 318 | void tOnePole_setFreq (tOnePole* const f, float freq) |
| 282 | 319 | { |
| 283 | − f->a1 = expf(-2.0 * PI * freq); | |
| 284 | − f->b0 = 1.0f - f->a1; | |
| 320 | + f->b0 = freq * TWO_PI * leaf.invSampleRate; | |
| 321 | + | |
| 322 | + f->b0 = LEAF_clip(0.0f, f->b0, 1.0f); | |
| 323 | + | |
| 324 | + f->a1 = 1.0f - f->b0; | |
| 285 | 325 | } |
| 286 | 326 | |
| 287 | 327 | void tOnePole_setCoefficients(tOnePole* const f, float b0, float a1) |
| @@ -300,7 +340,7 @@ void tOnePole_setGain(tOnePole* const f, float gain) · 12 unmodified lines | ||
| 300 | 340 | float tOnePole_tick(tOnePole* const f, float input) |
| 301 | 341 | { |
| 302 | 342 | float in = input * f->gain; |
| 303 | − float out = (f->b0 * in) - (f->a1 * f->lastOut); | |
| 343 | + float out = (f->b0 * in) + (f->a1 * f->lastOut); | |
| 304 | 344 | |
| 305 | 345 | f->lastIn = in; |
| 306 | 346 | f->lastOut = out; |