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 843B

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