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.

minblep.hpp 785B

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #include "math.hpp"
  3. namespace rack {
  4. // Pre-made minBLEP samples in minBLEP.cpp
  5. extern const float minblep_16_32[];
  6. template<int ZERO_CROSSINGS>
  7. struct MinBLEP {
  8. float buf[2*ZERO_CROSSINGS] = {};
  9. int pos = 0;
  10. const float *minblep;
  11. int oversample;
  12. /** Places a discontinuity with magnitude dx at -1 < p <= 0 relative to the current frame */
  13. void jump(float p, float dx) {
  14. if (p <= -1 || 0 < p)
  15. return;
  16. for (int j = 0; j < 2*ZERO_CROSSINGS; j++) {
  17. float minblepIndex = ((float)j - p) * oversample;
  18. int index = (pos + j) % (2*ZERO_CROSSINGS);
  19. buf[index] += dx * (-1.0 + interpf(minblep, minblepIndex));
  20. }
  21. }
  22. float shift() {
  23. float v = buf[pos];
  24. buf[pos] = 0.0;
  25. pos = (pos + 1) % (2*ZERO_CROSSINGS);
  26. return v;
  27. }
  28. };
  29. } // namespace rack