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.

32 lines
568B

  1. #include "PulseGate.hpp"
  2. #include <engine.hpp>
  3. #include <iostream>
  4. #include <limits>
  5. #include <cmath>
  6. PulseGate::PulseGate(float pulseDuration) :
  7. m_pulseDuration(pulseDuration)
  8. {
  9. }
  10. void PulseGate::reset()
  11. {
  12. m_current = 0.f;
  13. m_pulse = false;
  14. }
  15. bool PulseGate::process(bool gate)
  16. {
  17. m_current += 1.f / static_cast<float>(rack::engineGetSampleRate());
  18. if (gate)
  19. {
  20. m_current = 0.f;
  21. m_pulse = true;
  22. }
  23. if (m_current > m_pulseDuration || std::abs(m_current - m_pulseDuration) < std::numeric_limits<float>::epsilon())
  24. {
  25. m_pulse = false;
  26. }
  27. return m_pulse;
  28. }