#pragma once #include "LookupTable.h" /** * This class creates objects and caches them. * Objects in the cache only stay alive as long as there is a reference to the object, * If all refs go away, the object will be deleted. * * All accessors return shared pointers to make the lifetime management easy. * Clients are free to use the shared_ptr directly, or may use the raw pointer, * as long as the client holds onto the reference. */ template class ObjectCache { public: static std::shared_ptr> getBipolarAudioTaper(); static std::shared_ptr> getSinLookup(); /** * 2 ** x, not scaled or shifted in any manner, but tables * selected to span a "reasonable" range when used as frequencies (4 Hz to 40kHz) * Exp2 lookup is 2 ** x. * Domain = {2 .. 15(+)} * Range = {4 .. 40000} * accuracy = 1 cent (1V/octave) */ static std::shared_ptr> getExp2(); static std::shared_ptr> getDb2Gain(); /** * tanh, unscaled, from -5 to 5 */ static std::shared_ptr> getTanh5(); private: /** * Cache uses weak pointers. This allows the cached objects to be * freed when the last client reference goes away. */ static std::weak_ptr> bipolarAudioTaper; static std::weak_ptr> sinLookupTable; static std::weak_ptr> exp2; static std::weak_ptr> db2Gain; static std::weak_ptr> tanh5; };