DISTRHO Plugin Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
925B

  1. /**
  2. * One-pole LPF for smooth parameter changes
  3. *
  4. * https://www.musicdsp.org/en/latest/Filters/257-1-pole-lpf-for-smooth-parameter-changes.html
  5. */
  6. #ifndef C_PARAM_SMOOTH_H
  7. #define C_PARAM_SMOOTH_H
  8. #include <math.h>
  9. #define TWO_PI 6.283185307179586476925286766559f
  10. class CParamSmooth {
  11. public:
  12. CParamSmooth(float smoothingTimeMs, float samplingRate)
  13. : t(smoothingTimeMs)
  14. {
  15. setSampleRate(samplingRate);
  16. }
  17. ~CParamSmooth() { }
  18. void setSampleRate(float samplingRate) {
  19. if (samplingRate != fs) {
  20. fs = samplingRate;
  21. a = exp(-TWO_PI / (t * 0.001f * samplingRate));
  22. b = 1.0f - a;
  23. z = 0.0f;
  24. }
  25. }
  26. inline void flush() {
  27. z = 0.0f;
  28. }
  29. inline float process(float in) {
  30. return z = (in * b) + (z * a);
  31. }
  32. private:
  33. float a, b, t, z;
  34. double fs = 0.0;
  35. };
  36. #endif // #ifndef C_PARAM_SMOOTH_H