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.

38 lines
944B

  1. #pragma once
  2. #include <cmath>
  3. #include <functional>
  4. class AudioMath
  5. {
  6. public:
  7. static const double Pi;
  8. static const double Pi_2; // Pi / 2
  9. static const double Ln2;
  10. static const double Ln10;
  11. static const double E;
  12. static bool closeTo(double x, double y, double tolerance)
  13. {
  14. const bool ret = std::abs(x - y) < tolerance;
  15. return ret;
  16. }
  17. static double db(double g)
  18. {
  19. return 20 * log(g) / Ln10;
  20. }
  21. /**
  22. * Returns a function that generates one period of sin for x = {0..1}.
  23. * Range (output) is -1 to 1.
  24. */
  25. static std::function<double(double)> makeFunc_Sin();
  26. /*
  27. * Returns a function that generates an exponential defined by two points
  28. * At input = xMin, output will be yMin.
  29. * At input = xMax, output will be yMax.
  30. */
  31. static std::function<double(double)> makeFunc_Exp(double xMin, double xMax, double yMin, double yMax);
  32. };