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.

51 lines
1.6KB

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