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.

36 lines
896B

  1. #pragma once
  2. #include <cstdint>
  3. #include <random>
  4. namespace SynthDevKit {
  5. class PinkNoise {
  6. public:
  7. PinkNoise (uint32_t seed) : rd { }, mt { rd() }, dist{ -1.0, 1.0 } {
  8. f0 = f1 = f2 = f3 = f4 = f5 = f6 = 0.0f;
  9. };
  10. void reset ( ) { };
  11. float stepValue ( ) {
  12. float white = dist(mt);
  13. f0 = 0.99886f * f0 + 0.0555179f * white;
  14. f1 = 0.99332f * f1 + 0.0750759f * white;
  15. f2 = 0.96900f * f2 + 0.1538520f * white;
  16. f3 = 0.86650f * f3 + 0.3104856f * white;
  17. f4 = 0.55000f * f4 + 0.5329522f * white;
  18. f5 = -0.7616 * f5 - 0.0168980f * white;
  19. float out = f0 + f1 + f2 + f3 + f4 + f5 + f6 + white * 0.5362f;
  20. out *= 0.55f;
  21. f6 = white * 0.115926f;
  22. return out;
  23. };
  24. private:
  25. std::random_device rd;
  26. std::mt19937 mt;
  27. std::uniform_real_distribution<double> dist;
  28. float f0, f1, f2, f3, f4, f5, f6;
  29. };
  30. }