#include "asserts.h" #include "ObjectCache.h" extern int _numLookupParams; template static void testBipolar() { assertEQ(_numLookupParams, 0); auto test = ObjectCache::getBipolarAudioTaper(); assertEQ(_numLookupParams, 1); auto test2 = ObjectCache::getBipolarAudioTaper(); assertEQ(_numLookupParams, 1); test.reset(); assertEQ(_numLookupParams, 1); test2.reset(); assertEQ(_numLookupParams, 0); { // simple test that bipolar audio scalers use cached lookups, and they work AudioMath::ScaleFun f = AudioMath::makeBipolarAudioScaler(3, 4); assertEQ(f(0, -5, 0), 3.); assertEQ(_numLookupParams, 1); } assertEQ(_numLookupParams, 0); // make again test = ObjectCache::getBipolarAudioTaper(); assertEQ(_numLookupParams, 1); } template static void testSin() { assertEQ(_numLookupParams, 0); auto test = ObjectCache::getSinLookup(); assertEQ(_numLookupParams, 1); auto test2 = ObjectCache::getSinLookup(); assertEQ(_numLookupParams, 1); test.reset(); assertEQ(_numLookupParams, 1); test2.reset(); assertEQ(_numLookupParams, 0); { // // simple test that bipolar audio scalers use cached lookups, and they work AudioMath::ScaleFun f = AudioMath::makeBipolarAudioScaler(3, 4); assertEQ(f(0, -5, 0), 3.); assertEQ(_numLookupParams, 1); } assertEQ(_numLookupParams, 0); // make again test = ObjectCache::getSinLookup(); assertEQ(_numLookupParams, 1); } template static void testExp2() { assertEQ(_numLookupParams, 0); auto test = ObjectCache::getExp2(); assertEQ(_numLookupParams, 1); auto test2 = ObjectCache::getExp2(); assertEQ(_numLookupParams, 1); test.reset(); assertEQ(_numLookupParams, 1); test2.reset(); assertEQ(_numLookupParams, 0); { auto test3 = ObjectCache::getExp2(); const double x = LookupTable::lookup(*test3, (T)3.2); const double y = std::pow(2, 3.2); assertClose(x, y, .001); assertEQ(_numLookupParams, 1); } assertEQ(_numLookupParams, 0); // make again test = ObjectCache::getExp2(); assertEQ(_numLookupParams, 1); } template static void testExp2b() { { // make sure exp2 is really 1V/octave auto ex2 = ObjectCache::getExp2(); const T a = LookupTable::lookup(*ex2, 5); const T b = LookupTable::lookup(*ex2, 6); assertClose(b / a, 2, .001); } } template static void testDb2Gain() { assertEQ(_numLookupParams, 0); auto test = ObjectCache::getDb2Gain(); assertEQ(_numLookupParams, 1); auto test2 = ObjectCache::getDb2Gain(); assertEQ(_numLookupParams, 1); test.reset(); assertEQ(_numLookupParams, 1); test2.reset(); assertEQ(_numLookupParams, 0); { auto test3 = ObjectCache::getDb2Gain(); const double x = LookupTable::lookup(*test3, (T) -12); const double y = AudioMath::gainFromDb(-12); assertClose(x, y, .1); assertEQ(_numLookupParams, 1); } assertEQ(_numLookupParams, 0); // make again test = ObjectCache::getDb2Gain(); assertEQ(_numLookupParams, 1); } template static void testDb2Gain2() { assertEQ(_numLookupParams, 0); auto test = ObjectCache::getDb2Gain(); // .1 db from -80 to +20 for (double db = -80; db < 20; db += .1) { const double x = LookupTable::lookup(*test, (T) db); const double y = AudioMath::gainFromDb(db); assertClose(x, y, .2); } } template static void testTanh5() { auto test = ObjectCache::getTanh5(); auto test2 = ObjectCache::getTanh5(); assertEQ(_numLookupParams, 1); for (double x = -5; x <= 5; x += .1) { const double y = LookupTable::lookup(*test, (T) x); const double y0 = std::tanh(x); assertClose(y, y0, .01); } } template static void test() { testBipolar(); testSin(); testExp2(); testExp2b(); testDb2Gain(); testDb2Gain2(); testTanh5(); } void testObjectCache() { assertEQ(_numLookupParams, 0); test(); test(); assertEQ(_numLookupParams, 0); }