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.

70 lines
2.3KB

  1. #pragma once
  2. #include "LookupTable.h"
  3. #include "BiquadParams.h"
  4. /**
  5. * This class creates objects and caches them.
  6. * Objects in the cache only stay alive as long as there is a reference to the object,
  7. * If all refs go away, the object will be deleted.
  8. *
  9. * All accessors return shared pointers to make the lifetime management easy.
  10. * Clients are free to use the shared_ptr directly, or may use the raw pointer,
  11. * as long as the client holds onto the reference.
  12. */
  13. template <typename T>
  14. class ObjectCache
  15. {
  16. public:
  17. static std::shared_ptr<LookupTableParams<T>> getBipolarAudioTaper();
  18. static std::shared_ptr<LookupTableParams<T>> getAudioTaper();
  19. static std::shared_ptr<LookupTableParams<T>> getSinLookup();
  20. /**
  21. * 2 ** x, not scaled or shifted in any manner, but tables
  22. * selected to span a "reasonable" range when used as frequencies
  23. (4 Hz to 40kHz)
  24. * Exp2 lookup is 2 ** x.
  25. * Domain = {2 .. 15(+)}
  26. * Range = {4 .. 40000}
  27. * accuracy = 1 cent (1V/octave)
  28. */
  29. static std::shared_ptr<LookupTableParams<T>> getExp2();
  30. static std::function<T(T)> getExp2Ex();
  31. static std::shared_ptr<LookupTableParams<T>> getExp2ExtendedLow();
  32. static std::shared_ptr<LookupTableParams<T>> getExp2ExtendedHigh();
  33. static std::shared_ptr<LookupTableParams<T>> getDb2Gain();
  34. /**
  35. * tanh, unscaled, from -5 to 5
  36. */
  37. static std::shared_ptr<LookupTableParams<T>> getTanh5();
  38. static std::shared_ptr<BiquadParams<float, 3>> get6PLPParams(float normalizedFc);
  39. private:
  40. /**
  41. * Cache uses weak pointers. This allows the cached objects to be
  42. * freed when the last client reference goes away.
  43. */
  44. static std::weak_ptr<LookupTableParams<T>> bipolarAudioTaper;
  45. static std::weak_ptr<LookupTableParams<T>> audioTaper;
  46. static std::weak_ptr<LookupTableParams<T>> sinLookupTable;
  47. static std::weak_ptr<LookupTableParams<T>> exp2;
  48. static std::weak_ptr<LookupTableParams<T>> exp2ExHigh;
  49. static std::weak_ptr<LookupTableParams<T>> exp2ExLow;
  50. static std::weak_ptr<LookupTableParams<T>> db2Gain;
  51. static std::weak_ptr<LookupTableParams<T>> tanh5;
  52. static std::weak_ptr< BiquadParams<float, 3>> lowpass64;
  53. static std::weak_ptr< BiquadParams<float, 3>> lowpass32;
  54. static std::weak_ptr< BiquadParams<float, 3>> lowpass16;
  55. };