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.

64 lines
1.5KB

  1. #pragma once
  2. #include "LookupTable.h"
  3. // TODO: this class should not be templatized. the functions should
  4. template<typename T>
  5. class LookupTableFactory
  6. {
  7. public:
  8. static void makeBipolarAudioTaper(LookupTableParams<T>& params);
  9. static double audioTaperKnee()
  10. {
  11. return -24;
  12. }
  13. /**
  14. * Factory methods for exp base 2
  15. * domain = 0..10
  16. * range = 20..20k (for now). but should be .001 to 1.0?
  17. */
  18. static void makeExp2(LookupTableParams<T>& params);
  19. static double expYMin()
  20. {
  21. return 4;
  22. }
  23. static double expYMax()
  24. {
  25. return 40000;
  26. }
  27. static double expXMin()
  28. {
  29. return std::log2(expYMin());
  30. }
  31. static double expXMax()
  32. {
  33. return std::log2(expYMax());
  34. }
  35. };
  36. template<typename T>
  37. inline void LookupTableFactory<T>::makeExp2(LookupTableParams<T>& params)
  38. {
  39. // 128 not enough for one cent
  40. const int bins = 256;
  41. const T xMin = (T) std::log2(expYMin());
  42. const T xMax = (T) std::log2(expYMax());
  43. assert(xMin < xMax);
  44. LookupTable<T>::init(params, bins, xMin, xMax, [](double x) {
  45. return std::pow(2, x);
  46. });
  47. }
  48. template<typename T>
  49. inline void LookupTableFactory<T>::makeBipolarAudioTaper(LookupTableParams<T>& params)
  50. {
  51. const int bins = 32;
  52. std::function<double(double)> audioTaper = AudioMath::makeFunc_AudioTaper(audioTaperKnee());
  53. const T xMin = -1;
  54. const T xMax = 1;
  55. LookupTable<T>::init(params, bins, xMin, xMax, [audioTaper](double x) {
  56. return (x >= 0) ? audioTaper(x) : -audioTaper(-x);
  57. });
  58. }