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.

35 lines
834B

  1. #include "util/math.hpp"
  2. #include "qwelk_common.h"
  3. using namespace rack;
  4. // TinyKnob::TinyKnob()
  5. // {
  6. // box.size = Vec(20, 20);
  7. // }
  8. byte minb(byte a, byte b) {return a < b ? a : b;}
  9. byte maxb(byte a, byte b) {return a > b ? a : b;}
  10. int clampi(int v, int l, int h) {return (v < l) ? l : ((v > h) ? h : v);}
  11. float slew(float v, float i, float sa, float min, float max, float shape)
  12. {
  13. float ret = v;
  14. if (i > v) {
  15. float s = max * powf(min / max, sa);
  16. ret += s * crossfade(1.0, (1 / 10.0) * (i - v), shape) / engineGetSampleRate();
  17. if (ret > i)
  18. ret = i;
  19. } else if (i < v) {
  20. float s = max * powf(min / max, sa);
  21. ret -= s * crossfade(1.0, (1 / 10.0) * (v - i), shape) / engineGetSampleRate();
  22. if (ret < i)
  23. ret = i;
  24. }
  25. return ret;
  26. }