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.

55 lines
874B

  1. #pragma once
  2. #include "util/math.hpp"
  3. namespace rack {
  4. inline float sinc(float x) {
  5. if (x == 0.f)
  6. return 1.f;
  7. x *= M_PI;
  8. return sinf(x) / x;
  9. }
  10. inline float quadraticBipolar(float x) {
  11. float x2 = x*x;
  12. return (x >= 0.f) ? x2 : -x2;
  13. }
  14. inline float cubic(float x) {
  15. return x*x*x;
  16. }
  17. inline float quarticBipolar(float x) {
  18. float y = x*x*x*x;
  19. return (x >= 0.f) ? y : -y;
  20. }
  21. inline float quintic(float x) {
  22. // optimal with --fast-math
  23. return x*x*x*x*x;
  24. }
  25. inline float sqrtBipolar(float x) {
  26. return (x >= 0.f) ? sqrtf(x) : -sqrtf(-x);
  27. }
  28. /** This is pretty much a scaled sinh */
  29. inline float exponentialBipolar(float b, float x) {
  30. const float a = b - 1.f / b;
  31. return (powf(b, x) - powf(b, -x)) / a;
  32. }
  33. inline float gainToDb(float gain) {
  34. return log10f(gain) * 20.f;
  35. }
  36. inline float dbToGain(float db) {
  37. return powf(10.f, db / 20.f);
  38. }
  39. } // namespace rack