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.

153 lines
3.6KB

  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. /**
  9. * domain (x) = -1 .. +1
  10. */
  11. static void makeBipolarAudioTaper(LookupTableParams<T>& params);
  12. /**
  13. * domain (x) = 0..1
  14. */
  15. static void makeAudioTaper(LookupTableParams<T>& params);
  16. static double audioTaperKnee()
  17. {
  18. return -24;
  19. }
  20. /**
  21. * Factory methods for exp base 2
  22. * domain = 0..10
  23. * range = 20..20k (for now). but should be .001 to 1.0?
  24. */
  25. static void makeExp2(LookupTableParams<T>& params);
  26. static double exp2YMin()
  27. {
  28. return 4;
  29. }
  30. static double exp2YMax()
  31. {
  32. return 40000;
  33. }
  34. static double exp2XMin()
  35. {
  36. return std::log2(exp2YMin());
  37. }
  38. static double exp2XMax()
  39. {
  40. return std::log2(exp2YMax());
  41. }
  42. static void makeExp2ExLow(LookupTableParams<T>& params);
  43. static double exp2ExLowYMin()
  44. {
  45. return 2;
  46. }
  47. static double exp2ExLowYMax()
  48. {
  49. return 400;
  50. }
  51. static double exp2ExLowXMin()
  52. {
  53. return std::log2(exp2ExLowYMin());
  54. }
  55. static double exp2ExLowXMax()
  56. {
  57. return std::log2(exp2ExLowYMax());
  58. }
  59. static void makeExp2ExHigh(LookupTableParams<T>& params);
  60. static double exp2ExHighYMin()
  61. {
  62. return 400;
  63. }
  64. static double exp2ExHighYMax()
  65. {
  66. return 20000;
  67. }
  68. static double exp2ExHighXMin()
  69. {
  70. return std::log2(exp2ExHighYMin());
  71. }
  72. static double exp2ExHighXMax()
  73. {
  74. return std::log2(exp2ExHighYMax());
  75. }
  76. };
  77. template<typename T>
  78. inline void LookupTableFactory<T>::makeExp2(LookupTableParams<T>& params)
  79. {
  80. // 256 enough for one cent
  81. const int bins = 256;
  82. const T xMin = (T) std::log2(exp2YMin());
  83. const T xMax = (T) std::log2(exp2YMax());
  84. assert(xMin < xMax);
  85. LookupTable<T>::init(params, bins, xMin, xMax, [](double x) {
  86. return std::pow(2, x);
  87. });
  88. }
  89. // hit specs with 256 / 128 @200 crossover
  90. // try 800 ng - need 256/256
  91. // 400 need 256 / 128
  92. template<typename T>
  93. inline void LookupTableFactory<T>::makeExp2ExHigh(LookupTableParams<T>& params)
  94. {
  95. const int bins = 512;
  96. const T xMin = (T) std::log2(exp2ExHighYMin());
  97. const T xMax = (T) std::log2(exp2ExHighYMax());
  98. assert(xMin < xMax);
  99. LookupTable<T>::init(params, bins, xMin, xMax, [](double x) {
  100. return std::pow(2, x);
  101. });
  102. }
  103. template<typename T>
  104. inline void LookupTableFactory<T>::makeExp2ExLow(LookupTableParams<T>& params)
  105. {
  106. const int bins = 256;
  107. const T xMin = (T) std::log2(exp2ExLowYMin());
  108. const T xMax = (T) std::log2(exp2ExLowYMax());
  109. assert(xMin < xMax);
  110. LookupTable<T>::init(params, bins, xMin, xMax, [](double x) {
  111. return std::pow(2, x);
  112. });
  113. }
  114. template<typename T>
  115. inline void LookupTableFactory<T>::makeBipolarAudioTaper(LookupTableParams<T>& params)
  116. {
  117. const int bins = 32;
  118. std::function<double(double)> audioTaper = AudioMath::makeFunc_AudioTaper(audioTaperKnee());
  119. const T xMin = -1;
  120. const T xMax = 1;
  121. LookupTable<T>::init(params, bins, xMin, xMax, [audioTaper](double x) {
  122. return (x >= 0) ? audioTaper(x) : -audioTaper(-x);
  123. });
  124. }
  125. template<typename T>
  126. inline void LookupTableFactory<T>::makeAudioTaper(LookupTableParams<T>& params)
  127. {
  128. const int bins = 32;
  129. std::function<double(double)> audioTaper = AudioMath::makeFunc_AudioTaper(audioTaperKnee());
  130. const T xMin = 0;
  131. const T xMax = 1;
  132. LookupTable<T>::init(params, bins, xMin, xMax, [audioTaper](double x) {
  133. return audioTaper(x);
  134. });
  135. }