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.

52 lines
1014B

  1. #pragma once
  2. #include "dsp/digital.hpp"
  3. #include "engine.hpp"
  4. float LERP(const float _amount, const float _inA, const float _inB);
  5. struct TriggerGenerator
  6. {
  7. float time = 0.0;
  8. float triggerTime = 0.001;
  9. bool process()
  10. {
  11. time += rack::engineGetSampleTime();
  12. return time < triggerTime;
  13. }
  14. void trigger()
  15. {
  16. // Keep the previous pulseTime if the existing pulse would be held longer than the currently requested one.
  17. if (time + triggerTime >= triggerTime)
  18. {
  19. time = 0.0;
  20. }
  21. }
  22. };
  23. struct TriggerGenWithSchmitt
  24. {
  25. TriggerGenerator trigGen;
  26. rack::SchmittTrigger schmitt;
  27. bool process(bool _trigger)
  28. {
  29. if(schmitt.process(_trigger ? 2.0f : 0.0f)) trigGen.trigger();
  30. return trigGen.process();
  31. }
  32. };
  33. struct HysteresisGate
  34. {
  35. bool state = false;
  36. float trueBound = 1.0f;
  37. float falseBound = 0.98f;
  38. bool process(float input)
  39. {
  40. if(input > trueBound) state = true;
  41. else if(input < falseBound) state = false;
  42. return state;
  43. }
  44. bool getState() {return state;}
  45. };