TTErr TukeyWindow::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; int badSampleCount = 0; TTAudioObjectBasePtr windowObject = NULL; TTAudioSignalPtr input = NULL; TTAudioSignalPtr output = NULL; int N = 128; TTValue v; TTFloat64 testAlpha = 0.5; // setup windowObject TTObjectBaseInstantiate(TT("WindowFunction"), &windowObject, TTValue(1)); windowObject->setAttributeValue(TT("function"), TT("tukey")); windowObject->setAttributeValue(TT("mode"), TT("apply")); // set the value for alpha windowObject->setAttributeValue(TT("alpha"), testAlpha); TTTestLog("alpha was set to %.10f for test", testAlpha); // create 1 channel audio signal objects TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1); TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1); input->allocWithVectorSize(N); output->allocWithVectorSize(N); // create a signal to be transformed and then process it) input->fill(1.0); windowObject->process(input, output); // now test the output for (int n=0; n<N; n++) { TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], sTukeyWindowCoefficients128[n]); badSampleCount += result; if (result) TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], sTukeyWindowCoefficients128[n]); } TTTestAssertion("Produces correct window coefficients", badSampleCount == 0, testAssertionCount, errorCount); if (badSampleCount) TTTestLog("badSampleCount is %i", badSampleCount); TTObjectBaseRelease(&input); TTObjectBaseRelease(&output); TTObjectBaseRelease(&windowObject); // wrap up test results and pass back to whoever called test return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
TTErr TTAudioObjectBase::defaultCalculateMethod(const TTFloat64& x, TTFloat64& y, TTPtr data) { TTAudioSignalPtr in; TTAudioSignalPtr out; TTErr err; TTObjectBaseInstantiate(kTTSym_audiosignal, &in, 1); TTObjectBaseInstantiate(kTTSym_audiosignal, &out, 1); in->allocWithVectorSize(1); out->allocWithVectorSize(1); in->mSampleVectors[0][0] = x; err = process(in, out); y = out->mSampleVectors[0][0]; TTObjectBaseRelease(&in); TTObjectBaseRelease(&out); return err; }
TTErr TTGain::test(TTValue& returnedTestInfo) { // preliminary setup int errorCount = 0; int testAssertionCount = 0; TTTestLog("Testing Parameter value conversions"); // N test assertions // Test 1: trival value conversion this->setAttributeValue(TT("midiGain"), 100); TTTestAssertion("midi gain of 100 == linear gain of 1.", TTTestFloatEquivalence(this->mGain, 1.0), testAssertionCount, errorCount); // Test 2: trival value conversion this->setAttributeValue(TT("midiGain"), 99); TTTestAssertion("midi gain of 99 != linear gain of 1.", TTTestFloatEquivalence(this->mGain, 1.0, false), testAssertionCount, errorCount); // Test 3: audio test // set the input signals 1 // apply -6 dB gain // check that the signals are properly scaled TTAudioSignalPtr input = NULL; TTAudioSignalPtr output = NULL; // create 1 channel audio signal objects TTObjectInstantiate(kTTSym_audiosignal, &input, 1); TTObjectInstantiate(kTTSym_audiosignal, &output, 1); input->allocWithVectorSize(64); output->allocWithVectorSize(64); for (int i=0; i<64; i++) input->mSampleVectors[0][i] = 1.0; this->setAttributeValue(TT("gain"), -6.0); this->process(input, output); TTSampleValuePtr samples = output->mSampleVectors[0]; int validSampleCount = 0; for (int i=0; i<64; i++) { validSampleCount += TTTestFloatEquivalence(0.5011872336272722, samples[i]); } TTTestAssertion("accumulated audio error at gain = -6 dB", validSampleCount == 64, testAssertionCount, errorCount); TTTestLog("Numbe of bad samples: %i", 64-validSampleCount); TTObjectRelease(&input); TTObjectRelease(&output); // Wrap up the test results to pass back to whoever called this test return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
TTErr TTSmoothPolynomialFunction::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; int badSampleCount = 0; TTAudioSignalPtr input = NULL; TTAudioSignalPtr output = NULL; int N = 128; TTValue v; TTFloat64 inputSignal1[128] = { 0.0000000000000000e+00, 7.8740157480314960e-03, 1.5748031496062992e-02, 2.3622047244094488e-02, 3.1496062992125984e-02, 3.9370078740157480e-02, 4.7244094488188976e-02, 5.5118110236220472e-02, 6.2992125984251968e-02, 7.0866141732283464e-02, 7.8740157480314960e-02, 8.6614173228346455e-02, 9.4488188976377951e-02, 1.0236220472440945e-01, 1.1023622047244094e-01, 1.1811023622047244e-01, 1.2598425196850394e-01, 1.3385826771653545e-01, 1.4173228346456693e-01, 1.4960629921259844e-01, 1.5748031496062992e-01, 1.6535433070866143e-01, 1.7322834645669291e-01, 1.8110236220472442e-01, 1.8897637795275590e-01, 1.9685039370078741e-01, 2.0472440944881889e-01, 2.1259842519685040e-01, 2.2047244094488189e-01, 2.2834645669291340e-01, 2.3622047244094488e-01, 2.4409448818897639e-01, 2.5196850393700787e-01, 2.5984251968503935e-01, 2.6771653543307089e-01, 2.7559055118110237e-01, 2.8346456692913385e-01, 2.9133858267716534e-01, 2.9921259842519687e-01, 3.0708661417322836e-01, 3.1496062992125984e-01, 3.2283464566929132e-01, 3.3070866141732286e-01, 3.3858267716535434e-01, 3.4645669291338582e-01, 3.5433070866141730e-01, 3.6220472440944884e-01, 3.7007874015748032e-01, 3.7795275590551181e-01, 3.8582677165354329e-01, 3.9370078740157483e-01, 4.0157480314960631e-01, 4.0944881889763779e-01, 4.1732283464566927e-01, 4.2519685039370081e-01, 4.3307086614173229e-01, 4.4094488188976377e-01, 4.4881889763779526e-01, 4.5669291338582679e-01, 4.6456692913385828e-01, 4.7244094488188976e-01, 4.8031496062992124e-01, 4.8818897637795278e-01, 4.9606299212598426e-01, 5.0393700787401574e-01, 5.1181102362204722e-01, 5.1968503937007871e-01, 5.2755905511811019e-01, 5.3543307086614178e-01, 5.4330708661417326e-01, 5.5118110236220474e-01, 5.5905511811023623e-01, 5.6692913385826771e-01, 5.7480314960629919e-01, 5.8267716535433067e-01, 5.9055118110236215e-01, 5.9842519685039375e-01, 6.0629921259842523e-01, 6.1417322834645671e-01, 6.2204724409448819e-01, 6.2992125984251968e-01, 6.3779527559055116e-01, 6.4566929133858264e-01, 6.5354330708661412e-01, 6.6141732283464572e-01, 6.6929133858267720e-01, 6.7716535433070868e-01, 6.8503937007874016e-01, 6.9291338582677164e-01, 7.0078740157480313e-01, 7.0866141732283461e-01, 7.1653543307086609e-01, 7.2440944881889768e-01, 7.3228346456692917e-01, 7.4015748031496065e-01, 7.4803149606299213e-01, 7.5590551181102361e-01, 7.6377952755905509e-01, 7.7165354330708658e-01, 7.7952755905511806e-01, 7.8740157480314965e-01, 7.9527559055118113e-01, 8.0314960629921262e-01, 8.1102362204724410e-01, 8.1889763779527558e-01, 8.2677165354330706e-01, 8.3464566929133854e-01, 8.4251968503937003e-01, 8.5039370078740162e-01, 8.5826771653543310e-01, 8.6614173228346458e-01, 8.7401574803149606e-01, 8.8188976377952755e-01, 8.8976377952755903e-01, 8.9763779527559051e-01, 9.0551181102362199e-01, 9.1338582677165359e-01, 9.2125984251968507e-01, 9.2913385826771655e-01, 9.3700787401574803e-01, 9.4488188976377951e-01, 9.5275590551181100e-01, 9.6062992125984248e-01, 9.6850393700787396e-01, 9.7637795275590555e-01, 9.8425196850393704e-01, 9.9212598425196852e-01, 1.0000000000000000e+00 }; TTFloat64 expectedSignal1[128] = { 0.0000000000000000e+00, 4.8244209039635314e-06, 3.8138443955198070e-05, 1.2718493906995618e-04, 2.9786651631526754e-04, 5.7476731875201535e-04, 9.8117481527801352e-04, 1.5391015934710839e-03, 2.2693071524321311e-03, 3.1913196956282223e-03, 4.3234579237356610e-03, 5.6828528274830668e-03, 7.2854694804944482e-03, 9.1461288321322883e-03, 1.1278529500340605e-02, 1.3695269564488044e-02, 1.6407868358210953e-02, 1.9426788262256446e-02, 2.2761456497325496e-02, 2.6420286916916010e-02, 3.0410701800165873e-02, 3.4739153644696097e-02, 3.9411146959453816e-02, 4.4431260057555426e-02, 4.9803166849129596e-02, 5.5529658634160470e-02, 6.1612665895330529e-02, 6.8053280090863921e-02, 7.4851775447369331e-02, 8.2007630752683164e-02, 8.9519551148712656e-02, 9.7385489924278826e-02, 1.0560267030795963e-01, 1.1416760726093299e-01, 1.2307612926982006e-01, 1.3232340013952798e-01, 1.4190394078609317e-01, 1.5181165102952443e-01, 1.6203983138664596e-01, 1.7258120486394016e-01, 1.8342793875039137e-01, 1.9457166641032828e-01, 2.0600350907626741e-01, 2.1771409764175598e-01, 2.2969359445421497e-01, 2.4193171510778244e-01, 2.5441775023615654e-01, 2.6714058730543810e-01, 2.8008873240697457e-01, 2.9325033205020234e-01, 3.0661319495549044e-01, 3.2016481384698270e-01, 3.3389238724544185e-01, 3.4778284126109205e-01, 3.6182285138646236e-01, 3.7599886428922880e-01, 3.9029711960505920e-01, 4.0470367173045396e-01, 4.1920441161559163e-01, 4.3378508855717035e-01, 4.4843133199125074e-01, 4.6312867328610041e-01, 4.7786256753503586e-01, 4.9261841534926576e-01, 5.0738158465073435e-01, 5.2213743246496436e-01, 5.3687132671389948e-01, 5.5156866800874915e-01, 5.6621491144282976e-01, 5.8079558838440848e-01, 5.9529632826954604e-01, 6.0970288039494136e-01, 6.2400113571077132e-01, 6.3817714861353769e-01, 6.5221715873890806e-01, 6.6610761275455821e-01, 6.7983518615301786e-01, 6.9338680504450978e-01, 7.0674966794979754e-01, 7.1991126759302526e-01, 7.3285941269456178e-01, 7.4558224976384357e-01, 7.5806828489221756e-01, 7.7030640554578467e-01, 7.8228590235824358e-01, 7.9399649092373314e-01, 8.0542833358967236e-01, 8.1657206124960879e-01, 8.2741879513605987e-01, 8.3796016861335465e-01, 8.4818834897047601e-01, 8.5809605921390641e-01, 8.6767659986047230e-01, 8.7692387073018008e-01, 8.8583239273906678e-01, 8.9439732969204044e-01, 9.0261451007572102e-01, 9.1048044885128654e-01, 9.1799236924731620e-01, 9.2514822455263168e-01, 9.3194671990913625e-01, 9.3838733410466979e-01, 9.4447034136584040e-01, 9.5019683315087100e-01, 9.5556873994244551e-01, 9.6058885304054709e-01, 9.6526084635530474e-01, 9.6958929819983375e-01, 9.7357971308308588e-01, 9.7723854350267647e-01, 9.8057321173774348e-01, 9.8359213164178971e-01, 9.8630473043551437e-01, 9.8872147049965875e-01, 9.9085387116786894e-01, 9.9271453051950509e-01, 9.9431714717251651e-01, 9.9567654207626521e-01, 9.9680868030437164e-01, 9.9773069284756843e-01, 9.9846089840652841e-01, 9.9901882518472185e-01, 9.9942523268124717e-01, 9.9970213348368553e-01, 9.9987281506093062e-01, 9.9996186155604327e-01, 9.9999517557909634e-01, 1.0000000000000000e+00 }; // setup Function this->setAttributeValue(TT("function"), TT("smoothPolynomial")); // create 1 channel audio signal objects TTObjectInstantiate(kTTSym_audiosignal, &input, 1); TTObjectInstantiate(kTTSym_audiosignal, &output, 1); input->allocWithVectorSize(N); output->allocWithVectorSize(N); // create a signal to be transformed and then process it) input->clear(); for (int i=0; i<N; i++) input->mSampleVectors[0][i] = inputSignal1[i]; this->process(input, output); // now test the output for (int n=0; n<N; n++) { TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedSignal1[n]); badSampleCount += result; if (result) TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedSignal1[n]); } TTTestAssertion("Produces correct function values", badSampleCount == 0, testAssertionCount, errorCount); if (badSampleCount) TTTestLog("badSampleCount is %i", badSampleCount); TTObjectRelease(&input); TTObjectRelease(&output); // wrap up test results and pass back to whoever called test return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
TTErr RosenbergGlottalPulseWindow::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; TTAudioObjectBasePtr windowObject = NULL; TTAudioSignalPtr input = NULL; TTAudioSignalPtr output = NULL; int N = 101; TTValue v, aReturnWeDontCareAbout; // create the object, keep the default ratio parameter TTObjectBaseInstantiate(TT("WindowFunction"), &windowObject, TTValue(1)); windowObject->setAttributeValue(TT("function"), TT("rosenbergGlottalPulse")); windowObject->setAttributeValue(TT("mode"), TT("apply")); // create 1 channel audio signal objects TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1); TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1); input->allocWithVectorSize(N); output->allocWithVectorSize(N); // create a signal to be transformed, and then process it input->fill(1.0); windowObject->process(input, output); // now test the output int badSampleCount = 0; for (int n=0; n<N; n++) { TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedResult1[n]); badSampleCount += result; if (result) TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedResult1[n]); } TTTestAssertion("Produces correct window shape for with default ratio attribute", badSampleCount == 0, testAssertionCount, errorCount); if (badSampleCount) TTTestLog("badSampleCount is %i", badSampleCount); v.resize(2); v.set(0, TT("ratio")); v.set(1, 0.8); windowObject->sendMessage(TT("setParameter"), v, aReturnWeDontCareAbout); // Again create a signal to be transformed, and then process it input->fill(1.0); windowObject->process(input, output); // now test the output badSampleCount = 0; for (int n=0; n<N; n++) { TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedResult2[n]); badSampleCount += result; if (result) TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedResult2[n]); } TTTestAssertion("Produces correct window shape for with ratio set to 0.8", badSampleCount == 0, testAssertionCount, errorCount); if (badSampleCount) TTTestLog("badSampleCount is %i", badSampleCount); TTObjectBaseRelease(&input); TTObjectBaseRelease(&output); TTObjectBaseRelease(&windowObject); // Wrap up the test results to pass back to whoever called this test return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
TTErr TTSpatSnap::testAudioProcessing(int& aTestAssertionCount, int& anErrorCount, TTValue& aReturnedTestInfo) { TTAudioSignalPtr input = NULL; TTAudioSignalPtr output = NULL; // create audio signal objects TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 7); TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 5); input->allocWithVectorSize(64); output->allocWithVectorSize(64); for (TTInt16 sample=0; sample<64; sample++) input->mSampleVectors[0][sample] = 1.0; for (TTInt16 sample=0; sample<64; sample++) input->mSampleVectors[1][sample] = 2.0; for (TTInt16 sample=0; sample<64; sample++) input->mSampleVectors[2][sample] = 4.0; for (TTInt16 sample=0; sample<64; sample++) input->mSampleVectors[3][sample] = 8.0; for (TTInt16 sample=0; sample<64; sample++) input->mSampleVectors[4][sample] = 16.0; for (TTInt16 sample=0; sample<64; sample++) input->mSampleVectors[5][sample] = 32.0; for (TTInt16 sample=0; sample<64; sample++) input->mSampleVectors[6][sample] = 64.0; this->process(input, output); // Test processed audio TTTestLog(""); // Sink 1 receieves signal fra source 2, 6 and 7: Expected value equals 2. + 32. +64. = 98. int validSampleCount = 0; TTSampleValuePtr samples = output->mSampleVectors[0]; for (int i=0; i<64; i++) { validSampleCount += TTTestFloatEquivalence(98., samples[i]); } TTTestAssertion("Correct audio signal processed to sink 1", validSampleCount == 64, aTestAssertionCount, anErrorCount); TTTestLog("Number of bad samples: %i", 64-validSampleCount); // Sink 2 receieves signal fra source 3: Expected value equals 4. validSampleCount = 0; samples = output->mSampleVectors[1]; for (int i=0; i<64; i++) { validSampleCount += TTTestFloatEquivalence(4., samples[i]); } TTTestAssertion("Correct audio signal processed to sink 2", validSampleCount == 64, aTestAssertionCount, anErrorCount); TTTestLog("Number of bad samples: %i", 64-validSampleCount); // Sink 3 receieves signal fra source 4: Expected value equals 8. validSampleCount = 0; samples = output->mSampleVectors[2]; for (int i=0; i<64; i++) { validSampleCount += TTTestFloatEquivalence(8., samples[i]); } TTTestAssertion("Correct audio signal processed to sink 3", validSampleCount == 64, aTestAssertionCount, anErrorCount); TTTestLog("Number of bad samples: %i", 64-validSampleCount); // Sink 4 receieves signal fra source 5: Expected value equals 16. validSampleCount = 0; samples = output->mSampleVectors[3]; for (int i=0; i<64; i++) { validSampleCount += TTTestFloatEquivalence(16., samples[i]); } TTTestAssertion("Correct audio signal processed to sink 4", validSampleCount == 64, aTestAssertionCount, anErrorCount); TTTestLog("Number of bad samples: %i", 64-validSampleCount); // Sink 5 receieves signal fra source 1: Expected value equals 1. validSampleCount = 0; samples = output->mSampleVectors[4]; for (int i=0; i<64; i++) { validSampleCount += TTTestFloatEquivalence(1., samples[i]); } TTTestAssertion("Correct audio signal processed to sink 5", validSampleCount == 64, aTestAssertionCount, anErrorCount); TTTestLog("Number of bad samples: %i", 64-validSampleCount); TTObjectBaseRelease(&input); TTObjectBaseRelease(&output); return kTTErrNone; }
TTErr TTRamp::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; int badSampleCount = 0; int badSampleCountTotal = 0; TTAudioSignalPtr output = NULL; // create 1 channel audio signal objects TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1); output->allocWithVectorSize(64); // setup the generator this->setAttributeValue(TT("destinationValue"), 1.0); this->setAttributeValue(TT("startValue"), 0.0); this->setAttributeValue(TT("mode"), TT("sample")); this->setAttributeValue(TT("rampTime"), 64000.0/sr); this->process(output); // created with Octave: sig = linspace(0,1,64) TTFloat64 expectedSignalTest1[64] = { 0.0000000000000000e+00, 1.5873015873015872e-02, 3.1746031746031744e-02, 4.7619047619047616e-02, 6.3492063492063489e-02, 7.9365079365079361e-02, 9.5238095238095233e-02, 1.1111111111111110e-01, 1.2698412698412698e-01, 1.4285714285714285e-01, 1.5873015873015872e-01, 1.7460317460317459e-01, 1.9047619047619047e-01, 2.0634920634920634e-01, 2.2222222222222221e-01, 2.3809523809523808e-01, 2.5396825396825395e-01, 2.6984126984126983e-01, 2.8571428571428570e-01, 3.0158730158730157e-01, 3.1746031746031744e-01, 3.3333333333333331e-01, 3.4920634920634919e-01, 3.6507936507936506e-01, 3.8095238095238093e-01, 3.9682539682539680e-01, 4.1269841269841268e-01, 4.2857142857142855e-01, 4.4444444444444442e-01, 4.6031746031746029e-01, 4.7619047619047616e-01, 4.9206349206349204e-01, 5.0793650793650791e-01, 5.2380952380952384e-01, 5.3968253968253965e-01, 5.5555555555555558e-01, 5.7142857142857140e-01, 5.8730158730158732e-01, 6.0317460317460314e-01, 6.1904761904761907e-01, 6.3492063492063489e-01, 6.5079365079365081e-01, 6.6666666666666663e-01, 6.8253968253968256e-01, 6.9841269841269837e-01, 7.1428571428571430e-01, 7.3015873015873012e-01, 7.4603174603174605e-01, 7.6190476190476186e-01, 7.7777777777777779e-01, 7.9365079365079361e-01, 8.0952380952380953e-01, 8.2539682539682535e-01, 8.4126984126984128e-01, 8.5714285714285710e-01, 8.7301587301587302e-01, 8.8888888888888884e-01, 9.0476190476190477e-01, 9.2063492063492058e-01, 9.3650793650793651e-01, 9.5238095238095233e-01, 9.6825396825396826e-01, 9.8412698412698407e-01, 1.0000000000000000e+00 }; for (int i=0; i<64; i++) { TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][i], expectedSignalTest1[i]); badSampleCount += result; if (result) //TTTestLog("BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, output->mSampleVectors[0][i], expectedSignalTest1[i]); std::cout << "BAD SAMPLE @ n=" << i << " ( value=" << output->mSampleVectors[0][i] << " expected=" << expectedSignalTest1[i] << " )\n"; } TTTestAssertion("Test 1: Produces correct ramp from 0 to 1 when a positive Frequency is defined", badSampleCount == 0, testAssertionCount, errorCount); if (badSampleCount) //TTTestLog("badSampleCount is %i", badSampleCount); std::cout << "badSampleCount is " << badSampleCount << "\n"; badSampleCountTotal += badSampleCount; //reinitializing for next test badSampleCount = 0; // Second test: now the ramp goes from 1 to 0 // setup the generator this->setAttributeValue(TT("startValue"), 1.0); this->setAttributeValue(TT("destinationValue"), 0.0); this->setAttributeValue(TT("mode"), TT("sample")); this->setAttributeValue(TT("rampTime"), 64000.0/sr); this->process(output); // created with Octave: linspace(1,0,64) TTFloat64 expectedSignalTest2[64] = { 1.0000000000000000e+00, 9.8412698412698418e-01, 9.6825396825396826e-01, 9.5238095238095233e-01, 9.3650793650793651e-01, 9.2063492063492069e-01, 9.0476190476190477e-01, 8.8888888888888884e-01, 8.7301587301587302e-01, 8.5714285714285721e-01, 8.4126984126984128e-01, 8.2539682539682535e-01, 8.0952380952380953e-01, 7.9365079365079372e-01, 7.7777777777777779e-01, 7.6190476190476186e-01, 7.4603174603174605e-01, 7.3015873015873023e-01, 7.1428571428571430e-01, 6.9841269841269837e-01, 6.8253968253968256e-01, 6.6666666666666674e-01, 6.5079365079365081e-01, 6.3492063492063489e-01, 6.1904761904761907e-01, 6.0317460317460325e-01, 5.8730158730158732e-01, 5.7142857142857140e-01, 5.5555555555555558e-01, 5.3968253968253976e-01, 5.2380952380952384e-01, 5.0793650793650791e-01, 4.9206349206349209e-01, 4.7619047619047616e-01, 4.6031746031746035e-01, 4.4444444444444442e-01, 4.2857142857142860e-01, 4.1269841269841268e-01, 3.9682539682539686e-01, 3.8095238095238093e-01, 3.6507936507936511e-01, 3.4920634920634919e-01, 3.3333333333333337e-01, 3.1746031746031744e-01, 3.0158730158730163e-01, 2.8571428571428570e-01, 2.6984126984126988e-01, 2.5396825396825395e-01, 2.3809523809523814e-01, 2.2222222222222221e-01, 2.0634920634920639e-01, 1.9047619047619047e-01, 1.7460317460317465e-01, 1.5873015873015872e-01, 1.4285714285714290e-01, 1.2698412698412698e-01, 1.1111111111111116e-01, 9.5238095238095233e-02, 7.9365079365079416e-02, 6.3492063492063489e-02, 4.7619047619047672e-02, 3.1746031746031744e-02, 1.5873015873015928e-02, 0.0000000000000000e+00 }; for (int i=0; i<64; i++) { TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][i], expectedSignalTest2[i]); badSampleCount += result; if (result) //TTTestLog("BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, output->mSampleVectors[0][i], expectedSignalTest2[i]); std::cout << "BAD SAMPLE @ n=" << i << " ( value=" << output->mSampleVectors[0][i] << " expected=" << expectedSignalTest2[i] << " )\n"; } TTTestAssertion("Test 2: Produces correct ramp from 1 to 0 when a negative Frequency is defined", badSampleCount == 0, testAssertionCount, errorCount); if (badSampleCount) //TTTestLog("badSampleCount is %i", badSampleCount); std::cout << "badSampleCount is " << badSampleCount << "\n"; badSampleCountTotal += badSampleCount; //reinitializing for next test badSampleCount = 0; // Finish // // Total number of bad samples: if (badSampleCountTotal) TTTestLog("badSampleCountTotal is %i", badSampleCountTotal); TTObjectBaseRelease(&output); // Wrap up the test results to pass back to whoever called this test return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
TTErr KaiserWindow::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; int badSampleCount = 0; TTAudioObjectBasePtr windowObject = NULL; TTAudioSignalPtr input = NULL; TTAudioSignalPtr output = NULL; int N = 128; TTValue v, aReturnWeDontCareAbout; // create the object and set the beta parameter TTObjectBaseInstantiate(TT("WindowFunction"), &windowObject, TTValue(1)); windowObject->setAttributeValue(TT("function"), TT("kaiser")); windowObject->setAttributeValue(TT("mode"), TT("apply")); v.resize(2); v[0] = TT("beta"); v[1] = 6.0; windowObject->sendMessage(TT("setParameter"), v, aReturnWeDontCareAbout); TTTestAssertion("Internal intermediate value 1 (zeroth-order bessel fn of the first kind, taken of beta = 6.0) is correct.", TTTestFloatEquivalence(((KaiserWindow*)((WindowFunction*)windowObject)->mFunctionObject)->mBesselIOofBeta, 67.2344069764780), testAssertionCount, errorCount); // change the alpha parameter and test Bessel function again v.resize(2); v[0] = TT("alpha"); v[1] = 2.0; windowObject->sendMessage(TT("setParameter"), v, aReturnWeDontCareAbout); TTTestAssertion("Internal intermediate value 2 (zeroth-order bessel fn of the first kind, taken of alpha = 2) is correct.", TTTestFloatEquivalence(((KaiserWindow*)((WindowFunction*)windowObject)->mFunctionObject)->mBesselIOofBeta, 87.10851065339077), testAssertionCount, errorCount); // added 4/26 by Wolek // change the beta parameter and try applying the window v.resize(2); v[0] = TT("beta"); v[1] = 3.0 * kTTPi; windowObject->sendMessage(TT("setParameter"), v, aReturnWeDontCareAbout); TTTestAssertion("Internal intermediate value 2 (zeroth-order bessel fn of the first kind, taken of beta = 3 * pi) is correct.", TTTestFloatEquivalence(((KaiserWindow*)((WindowFunction*)windowObject)->mFunctionObject)->mBesselIOofBeta, 1633.090522058824), testAssertionCount, errorCount); // added 4/26 by Wolek // create 1 channel audio signal objects TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1); TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1); input->allocWithVectorSize(N); output->allocWithVectorSize(N); // create a signal to be transformed, and then process it input->fill(1.0); windowObject->process(input, output); // now test the output for (int n=0; n<N; n++) { TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], sKaiserB3PiWindowCoefficients128[n]); badSampleCount += result; if (result) TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], sKaiserB3PiWindowCoefficients128[n]); } TTTestAssertion("Produces correct window shape for beta = 3 pi", badSampleCount == 0, testAssertionCount, errorCount); if (badSampleCount) TTTestLog("badSampleCount is %i", badSampleCount); TTObjectBaseRelease(&input); TTObjectBaseRelease(&output); TTObjectBaseRelease(&windowObject); // Wrap up the test results to pass back to whoever called this test return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
TTErr TTLinearFunction::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; int badSampleCount = 0; TTAudioSignalPtr input = NULL; TTAudioSignalPtr output = NULL; int N = 128; TTValue v; TTFloat64 expectedSignalTest1[128] = { 0.0000000000000000e+00, 7.8740157480314960e-03, 1.5748031496062992e-02, 2.3622047244094488e-02, 3.1496062992125984e-02, 3.9370078740157480e-02, 4.7244094488188976e-02, 5.5118110236220472e-02, 6.2992125984251968e-02, 7.0866141732283464e-02, 7.8740157480314960e-02, 8.6614173228346455e-02, 9.4488188976377951e-02, 1.0236220472440945e-01, 1.1023622047244094e-01, 1.1811023622047244e-01, 1.2598425196850394e-01, 1.3385826771653545e-01, 1.4173228346456693e-01, 1.4960629921259844e-01, 1.5748031496062992e-01, 1.6535433070866143e-01, 1.7322834645669291e-01, 1.8110236220472442e-01, 1.8897637795275590e-01, 1.9685039370078741e-01, 2.0472440944881889e-01, 2.1259842519685040e-01, 2.2047244094488189e-01, 2.2834645669291340e-01, 2.3622047244094488e-01, 2.4409448818897639e-01, 2.5196850393700787e-01, 2.5984251968503935e-01, 2.6771653543307089e-01, 2.7559055118110237e-01, 2.8346456692913385e-01, 2.9133858267716534e-01, 2.9921259842519687e-01, 3.0708661417322836e-01, 3.1496062992125984e-01, 3.2283464566929132e-01, 3.3070866141732286e-01, 3.3858267716535434e-01, 3.4645669291338582e-01, 3.5433070866141730e-01, 3.6220472440944884e-01, 3.7007874015748032e-01, 3.7795275590551181e-01, 3.8582677165354329e-01, 3.9370078740157483e-01, 4.0157480314960631e-01, 4.0944881889763779e-01, 4.1732283464566927e-01, 4.2519685039370081e-01, 4.3307086614173229e-01, 4.4094488188976377e-01, 4.4881889763779526e-01, 4.5669291338582679e-01, 4.6456692913385828e-01, 4.7244094488188976e-01, 4.8031496062992124e-01, 4.8818897637795278e-01, 4.9606299212598426e-01, 5.0393700787401574e-01, 5.1181102362204722e-01, 5.1968503937007871e-01, 5.2755905511811019e-01, 5.3543307086614178e-01, 5.4330708661417326e-01, 5.5118110236220474e-01, 5.5905511811023623e-01, 5.6692913385826771e-01, 5.7480314960629919e-01, 5.8267716535433067e-01, 5.9055118110236215e-01, 5.9842519685039375e-01, 6.0629921259842523e-01, 6.1417322834645671e-01, 6.2204724409448819e-01, 6.2992125984251968e-01, 6.3779527559055116e-01, 6.4566929133858264e-01, 6.5354330708661412e-01, 6.6141732283464572e-01, 6.6929133858267720e-01, 6.7716535433070868e-01, 6.8503937007874016e-01, 6.9291338582677164e-01, 7.0078740157480313e-01, 7.0866141732283461e-01, 7.1653543307086609e-01, 7.2440944881889768e-01, 7.3228346456692917e-01, 7.4015748031496065e-01, 7.4803149606299213e-01, 7.5590551181102361e-01, 7.6377952755905509e-01, 7.7165354330708658e-01, 7.7952755905511806e-01, 7.8740157480314965e-01, 7.9527559055118113e-01, 8.0314960629921262e-01, 8.1102362204724410e-01, 8.1889763779527558e-01, 8.2677165354330706e-01, 8.3464566929133854e-01, 8.4251968503937003e-01, 8.5039370078740162e-01, 8.5826771653543310e-01, 8.6614173228346458e-01, 8.7401574803149606e-01, 8.8188976377952755e-01, 8.8976377952755903e-01, 8.9763779527559051e-01, 9.0551181102362199e-01, 9.1338582677165359e-01, 9.2125984251968507e-01, 9.2913385826771655e-01, 9.3700787401574803e-01, 9.4488188976377951e-01, 9.5275590551181100e-01, 9.6062992125984248e-01, 9.6850393700787396e-01, 9.7637795275590555e-01, 9.8425196850393704e-01, 9.9212598425196852e-01, 1.0000000000000000e+00 }; // setup Function this->setAttributeValue(TT("function"), TT("linear")); // create 1 channel audio signal objects TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1); TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1); input->allocWithVectorSize(N); output->allocWithVectorSize(N); // create a signal to be transformed and then process it) input->clear(); for (int i=0; i<N; i++) input->mSampleVectors[0][i] = expectedSignalTest1[i]; this->process(input, output); // now test the output for (int n=0; n<N; n++) { TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedSignalTest1[n]); badSampleCount += result; if (result) TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedSignalTest1[n]); } TTTestAssertion("Produces correct function values", badSampleCount == 0, testAssertionCount, errorCount); if (badSampleCount) TTTestLog("badSampleCount is %i", badSampleCount); TTObjectBaseRelease(&input); TTObjectBaseRelease(&output); // wrap up test results and pass back to whoever called test return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
TTErr TTHalfbandLinear33::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; int badSampleCount = 0; TTAudioSignalPtr input = NULL; TTAudioSignalPtr output = NULL; // create 1 channel audio signal objects TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1); TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1); input->allocWithVectorSize(128); output->allocWithVectorSize(128); // create an impulse input->clear(); // set all samples to zero input->mSampleVectors[0][0] = 1.0; // set the first sample to 1 // setup the filter //this->setAttributeValue(TT("linearGain"), 0.5); //this->setAttributeValue(TT("delayInSamples"), 1); this->process(input, output); /// The following values are not necsessarily to be trusted. They were calculated from this filter unit itself at a time when the filter was assumed to work. As such, if this test fails in the future, it should be considered an indication that something has changed in the code or compiler that causes the calculated impulse response to differ from earlier results, but this test is not able to say anything meaningful about whether the old or new behaviour is to be trusted (or eventually none of them). TTFloat64 expectedImpulseResponse[128] = { 0.0000000000000000e+00, -1.4033886144341021e-03, 0.0000000000000000e+00, 2.8696648020251339e-03, 0.0000000000000000e+00, -5.7985191818626753e-03, 0.0000000000000000e+00, 1.0903029954258413e-02, 0.0000000000000000e+00, -1.9971682303392909e-02, 0.0000000000000000e+00, 3.7485281415763530e-02, 0.0000000000000000e+00, -7.9701634061165733e-02, 0.0000000000000000e+00, 2.9216925395010418e-01, 5.0000000000000000e-01, 3.4369037427197169e-01, 0.0000000000000000e+00, -1.3023893952773802e-01, 0.0000000000000000e+00, 8.6104042704043690e-02, 0.0000000000000000e+00, -6.5831676403848585e-02, 0.0000000000000000e+00, 5.3364446243041895e-02, 0.0000000000000000e+00, -4.4382106227734967e-02, 0.0000000000000000e+00, 3.7295412888824341e-02, 0.0000000000000000e+00, -3.1244797047627053e-02, 0.0000000000000000e+00, 2.6798062990289070e-02, 0.0000000000000000e+00, -2.2131648330448058e-02, 0.0000000000000000e+00, 1.8346990400433229e-02, 0.0000000000000000e+00, -1.5243355223767449e-02, 0.0000000000000000e+00, 1.2680069280636953e-02, 0.0000000000000000e+00, -1.0553809725476822e-02, 0.0000000000000000e+00, 8.7857616982298780e-03, 0.0000000000000000e+00, -7.3136670275350379e-03, 0.0000000000000000e+00, 6.0882749139391252e-03, 0.0000000000000000e+00, -5.0669324833186669e-03, 0.0000000000000000e+00, 4.2169077154520593e-03, 0.0000000000000000e+00, -3.5095610771282738e-03, 0.0000000000000000e+00, 2.9209172646183241e-03, 0.0000000000000000e+00, -2.4310262000329379e-03, 0.0000000000000000e+00, 2.0233040542710959e-03, 0.0000000000000000e+00, -1.6839620729024551e-03, 0.0000000000000000e+00, 1.4015316044449066e-03, 0.0000000000000000e+00, -1.1664674133319290e-03, 0.0000000000000000e+00, 9.7082783948693727e-04, 0.0000000000000000e+00, -8.0800107046215914e-04, 0.0000000000000000e+00, 6.7248368858447154e-04, 0.0000000000000000e+00, -5.5969525911386462e-04, 0.0000000000000000e+00, 4.6582363007229645e-04, 0.0000000000000000e+00, -3.8769606747829008e-04, 0.0000000000000000e+00, 3.2267198896539023e-04, 0.0000000000000000e+00, -2.6855369234410987e-04, 0.0000000000000000e+00, 2.2351207385297981e-04, 0.0000000000000000e+00, -1.8602480145583968e-04, 0.0000000000000000e+00, 1.5482486591515381e-04, 0.0000000000000000e+00, -1.2885775959743082e-04, 0.0000000000000000e+00, 1.0724583623124941e-04, 0.0000000000000000e+00, -8.9258647845389630e-05, 0.0000000000000000e+00, 7.4288256705464873e-05, 0.0000000000000000e+00, -6.1828687935307859e-05, 0.0000000000000000e+00, 5.1458828369187624e-05, 0.0000000000000000e+00, -4.2828193604805050e-05, 0.0000000000000000e+00, 3.5645082207555665e-05, 0.0000000000000000e+00, -2.9666716680464188e-05, 0.0000000000000000e+00, 2.4691037980432186e-05, 0.0000000000000000e+00, -2.0549876250725695e-05, 0.0000000000000000e+00, 1.7103266952687490e-05, 0.0000000000000000e+00, -1.4234720291507337e-05, 0.0000000000000000e+00, 1.1847284050344966e-05, 0.0000000000000000e+00, -9.8602667629068172e-06, 0.0000000000000000e+00, 8.2065104729977065e-06, 0.0000000000000000e+00, -6.8301209047192577e-06, 0.0000000000000000e+00, 5.6845783267542965e-06, 0.0000000000000000e+00, -4.7311652610242063e-06 }; //TTTestLog("\nRESULTING VALUES"); for (int i=0; i<128; i++) { TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][i], expectedImpulseResponse[i]); //TTTestLog("%.16e,", output->mSampleVectors[0][i]); badSampleCount += result; if (result) TTTestLog("BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, output->mSampleVectors[0][i], expectedImpulseResponse[i]); } TTTestAssertion("Produces correct impulse response for a delay of 1 sample and alpha = 0.5", badSampleCount == 0, testAssertionCount, errorCount); if (badSampleCount) TTTestLog("badSampleCount is %i", badSampleCount); TTObjectBaseRelease(&input); TTObjectBaseRelease(&output); // Wrap up the test results to pass back to whoever called this test return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
TTErr TTSvf::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; int badSampleCount = 0; TTAudioSignalPtr input = NULL; TTAudioSignalPtr output = NULL; // create 1 channel audio signal objects TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1); TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1); input->allocWithVectorSize(128); output->allocWithVectorSize(128); // create an impulse input->clear(); // set all samples to zero input->mSampleVectors[0][0] = 1.0; // set the first sample to 1 // setup the filter //this->setAttributeValue(TT("linearGain"), 0.5); //this->setAttributeValue(TT("delayInSamples"), 1); this->process(input, output); /// The following values are not necsessarily to be trusted. They were calculated from this filter unit itself at a time when the filter was assumed to work. As such, if this test fails in the future, it should be considered an indication that something has changed in the code or compiler that causes the calculated impulse response to differ from earlier results, but this test is not able to say anything meaningful about whether the old or new behaviour is to be trusted (or eventually none of them). TTFloat64 expectedImpulseResponse[128] = { 5.0000000000000000e+05, 5.0087319869171590e+17, 5.0174842408388438e+29, 5.0262517884414260e+41, 5.0350346564490692e+53, 5.0438328716326373e+65, 5.0526464608097724e+77, 5.0614754508449776e+89, 5.0703198686496978e+101, 5.0791797411824051e+113, 5.0880550954486772e+125, 5.0969459585012814e+137, 5.1058523574402592e+149, 5.1147743194130052e+161, 5.1237118716143473e+173, 5.1326650412866394e+185, 5.1416338557198395e+197, 5.1506183422515868e+209, 5.1596185282672929e+221, 5.1686344412002213e+233, 5.1776661085315740e+245, 5.1867135577905743e+257, 5.1957768165545460e+269, 5.2048559124490098e+281, 5.2139508731477499e+293, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305, 5.2230617263729118e+305 }; //TTTestLog("\nRESULTING VALUES"); for (int i=0; i<128; i++) { TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][i], expectedImpulseResponse[i]); //TTTestLog("%.16e,", output->mSampleVectors[0][i]); badSampleCount += result; if (result) TTTestLog("BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, output->mSampleVectors[0][i], expectedImpulseResponse[i]); } TTTestAssertion("Produces correct impulse response for a delay of 1 sample and alpha = 0.5", badSampleCount == 0, testAssertionCount, errorCount); if (badSampleCount) TTTestLog("badSampleCount is %i", badSampleCount); TTObjectBaseRelease(&input); TTObjectBaseRelease(&output); // Wrap up the test results to pass back to whoever called this test return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
TTErr TTAudioGraphGenerator::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; int badSampleCount = 0; // TTAudioSignalPtr input = NULL; TTAudioSignalPtr output = NULL; TTAudioGraphPreprocessData mInitData; // TTAudioSignalPtr mAudioSignal = NULL; TTAudioGraphObjectPtr obj0 = NULL; TTAudioGraphObjectPtr obj1 = NULL; TTAudioGraphObjectPtr obj2 = NULL; TTAudioGraphObjectPtr obj3 = NULL; TTAudioGraphObjectPtr obj4 = NULL; TTAudioGraphObjectPtr obj5 = NULL; TTAudioGraphObjectPtr obj6 = NULL; TTAudioGraphObjectPtr obj7 = NULL; // TTAudioGraphObjectPtr obj8 = NULL; TTAudioGraphObjectPtr obj9 = NULL; TTAudioGraphObjectPtr obj10 = NULL; // TTAudioGraphObjectPtr obj11 = NULL; TTAudioGraphObjectPtr obj12 = NULL; TTAudioGraphObjectPtr obj13 = NULL; TTValue audioObjectArguments; memset(&mInitData, 0, sizeof(mInitData)); audioObjectArguments.setSize(3); // Create the Graph audioObjectArguments.set(0, TT("thru")); // <<-- THIS IS THE SINK ON WHICH WE WILL PULL audioObjectArguments.set(1, 1); // <<-- NUMBER OF INLETS audioObjectArguments.set(2, 1); TTObjectInstantiate(TT("audio.object"), (TTObjectPtr*)&obj0, audioObjectArguments); obj0->mKernel->setAttributeValue(TT("maxNumChannels"), 0); obj0->mKernel->setAttributeValue(TT("mute"), 0); obj0->mKernel->setAttributeValue(TT("bypass"), 0); obj0->mKernel->setAttributeValue(TT("sampleRate"), 44100u); audioObjectArguments.set(0, TT("audio.join")); audioObjectArguments.set(1, 2); audioObjectArguments.set(2, 1); TTObjectInstantiate(TT("audio.object"), (TTObjectPtr*)&obj1, audioObjectArguments); obj1->mKernel->setAttributeValue(TT("maxNumChannels"), 1); obj1->mKernel->setAttributeValue(TT("mute"), 0); obj1->mKernel->setAttributeValue(TT("bypass"), 0); obj1->mKernel->setAttributeValue(TT("sampleRate"), 44100u); audioObjectArguments.set(0, TT("gain")); audioObjectArguments.set(1, 1); audioObjectArguments.set(2, 1); TTObjectInstantiate(TT("audio.object"), (TTObjectPtr*)&obj2, audioObjectArguments); //obj2->mKernel->setAttributeValue(TT("midiGain"), 86.639865); obj2->mKernel->setAttributeValue(TT("maxNumChannels"), 0); obj2->mKernel->setAttributeValue(TT("interpolated"), 0); obj2->mKernel->setAttributeValue(TT("mute"), 0); obj2->mKernel->setAttributeValue(TT("bypass"), 0); //obj2->mKernel->setAttributeValue(TT("gain"), -6.000000); //obj2->mKernel->setAttributeValue(TT("linearGain"), 0.501187); obj2->mKernel->setAttributeValue(TT("linearGain"), 0.25); obj2->mKernel->setAttributeValue(TT("sampleRate"), 44100u); audioObjectArguments.set(0, TT("audio.split")); audioObjectArguments.set(1, 1); audioObjectArguments.set(2, 2); TTObjectInstantiate(TT("audio.object"), (TTObjectPtr*)&obj3, audioObjectArguments); obj3->mKernel->setAttributeValue(TT("maxNumChannels"), 1); TTValue v(1,1); obj3->mKernel->setAttributeValue(TT("groups"), v); obj3->mKernel->setAttributeValue(TT("mute"), 0); obj3->mKernel->setAttributeValue(TT("bypass"), 0); obj3->mKernel->setAttributeValue(TT("sampleRate"), 44100u); audioObjectArguments.set(0, TT("audio.generator")); audioObjectArguments.set(1, 0); audioObjectArguments.set(2, 1); TTObjectInstantiate(TT("audio.object"), (TTObjectPtr*)&obj4, audioObjectArguments); obj4->mKernel->setAttributeValue(TT("maxNumChannels"), 2); obj4->mKernel->setAttributeValue(TT("mute"), 0); obj4->mKernel->setAttributeValue(TT("bypass"), 0); obj4->mKernel->setAttributeValue(TT("vectorSize"), 64); obj4->mKernel->setAttributeValue(TT("sampleRate"), 44100u); obj4->addAudioFlag(kTTAudioGraphGenerator); obj4->setOutputNumChannels(0, 2); obj3->connectAudio(obj4, 0, 0); obj2->connectAudio(obj3, 0, 0); // TTObjectInstantiate(TT("graph.object"), (TTObjectPtr*)&obj8, TTValue(TT("plugtastic.parameter"))); // ((PlugtasticParameter*)obj8->mKernel)->setOwner(obj8); // obj8->mKernel->setAttributeValue(TT("rangeTop"), 24.000000); // obj8->mKernel->setAttributeValue(TT("bypass"), 0); // obj8->mKernel->setAttributeValue(TT("name"), TT("gain")); // obj8->mKernel->setAttributeValue(TT("style"), TT("decibels")); // obj8->mKernel->setAttributeValue(TT("default"), -6.000000); // obj8->mKernel->setAttributeValue(TT("value"), 0.000000); // obj8->mKernel->setAttributeValue(TT("rangeBottom"), -96.000000); // obj2->connect(obj8); obj1->connectAudio(obj2, 0, 0); audioObjectArguments.set(0, TT("gain")); audioObjectArguments.set(1, 1); audioObjectArguments.set(2, 1); TTObjectInstantiate(TT("audio.object"), (TTObjectPtr*)&obj9, audioObjectArguments); // obj9->mKernel->setAttributeValue(TT("midiGain"), 86.639865); obj9->mKernel->setAttributeValue(TT("maxNumChannels"), 0); obj9->mKernel->setAttributeValue(TT("interpolated"), 0); obj9->mKernel->setAttributeValue(TT("mute"), 0); obj9->mKernel->setAttributeValue(TT("bypass"), 0); // obj9->mKernel->setAttributeValue(TT("gain"), -6.000000); // obj9->mKernel->setAttributeValue(TT("linearGain"), 0.501187); obj9->mKernel->setAttributeValue(TT("linearGain"), 0.25); obj9->mKernel->setAttributeValue(TT("sampleRate"), 44100u); obj9->connectAudio(obj3, 1, 0); // TTObjectInstantiate(TT("graph.object"), (TTObjectPtr*)&obj11, TTValue(TT("plugtastic.parameter"))); // ((PlugtasticParameter*)obj11->mKernel)->setOwner(obj11); // obj11->mKernel->setAttributeValue(TT("rangeTop"), 24.000000); // obj11->mKernel->setAttributeValue(TT("bypass"), 0); // obj11->mKernel->setAttributeValue(TT("name"), TT("gain")); // obj11->mKernel->setAttributeValue(TT("style"), TT("decibels")); // obj11->mKernel->setAttributeValue(TT("default"), -6.000000); // obj11->mKernel->setAttributeValue(TT("value"), 0.000000); // obj11->mKernel->setAttributeValue(TT("rangeBottom"), -96.000000); // obj9->connect(obj11); obj1->connectAudio(obj9, 0, 1); obj0->connectAudio(obj1, 0, 0); // SET UP SOME AUDIO AND PULL ON THE GRAPH // obj4 is the source // obj0 is the sink TTSampleValue chan1input[64] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; TTSampleValue chan2input[64] = {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}; TTSampleValue chan1output[64]; TTSampleValue chan2output[64]; mInitData.vectorSize = 64; TTTestLog("Processing First Pull"); TTAudioGraphGeneratorPtr(obj4->getUnitGenerator())->mBuffer->setVector64Copy(0, 64, chan1input); TTAudioGraphGeneratorPtr(obj4->getUnitGenerator())->mBuffer->setVector64Copy(1, 64, chan2input); obj0->lockProcessing(); obj0->preprocess(mInitData); obj0->process(output, 0); obj0->unlockProcessing(); output->getVectorCopy(0, 64, chan1output); output->getVectorCopy(1, 64, chan2output); // CHECK THE RESULTS for (int i=0; i<64; i++) { TTBoolean result = TTTestFloatEquivalence(chan1output[i], chan1input[i] * 0.25); badSampleCount += !result; if (!result) TTTestLog("CHAN1 BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, chan1output[i], chan1input[i] * 0.25); result = TTTestFloatEquivalence(chan2output[i], chan2input[i] * 0.25); badSampleCount += !result; if (!result) TTTestLog("CHAN2 BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, chan2output[i], chan2input[i] * 0.25); } TTTestAssertion("Produces correct results for first pull", badSampleCount == 0, testAssertionCount, errorCount); if (badSampleCount) TTTestLog("badSampleCount is %i", badSampleCount); TTTestLog("Processing Second Pull"); TTAudioGraphGeneratorPtr(obj4->getUnitGenerator())->mBuffer->setVector64Copy(0, 64, chan1input); TTAudioGraphGeneratorPtr(obj4->getUnitGenerator())->mBuffer->setVector64Copy(1, 64, chan2input); obj0->lockProcessing(); obj0->preprocess(mInitData); obj0->process(output, 64); obj0->unlockProcessing(); output->getVectorCopy(0, 64, chan1output); output->getVectorCopy(1, 64, chan2output); // CHECK THE RESULTS for (int i=0; i<64; i++) { TTBoolean result = TTTestFloatEquivalence(chan1output[i], chan1input[i] * 0.25); badSampleCount += !result; if (!result) TTTestLog("CHAN1 BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, chan1output[i], chan1input[i] * 0.25); result = TTTestFloatEquivalence(chan2output[i], chan2input[i] * 0.25); badSampleCount += !result; if (!result) TTTestLog("CHAN2 BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, chan2output[i], chan2input[i] * 0.25); } TTTestAssertion("Produces correct results for second pull", badSampleCount == 0, testAssertionCount, errorCount); if (badSampleCount) TTTestLog("badSampleCount is %i", badSampleCount); // FREE MEMORY FROM OUR GRAPH TTObjectRelease((TTObjectPtr*)&obj0); TTObjectRelease((TTObjectPtr*)&obj1); TTObjectRelease((TTObjectPtr*)&obj2); TTObjectRelease((TTObjectPtr*)&obj3); TTObjectRelease((TTObjectPtr*)&obj4); TTObjectRelease((TTObjectPtr*)&obj5); TTObjectRelease((TTObjectPtr*)&obj6); TTObjectRelease((TTObjectPtr*)&obj7); // TTObjectRelease((TTObjectPtr*)&obj8); TTObjectRelease((TTObjectPtr*)&obj9); TTObjectRelease((TTObjectPtr*)&obj10); // TTObjectRelease((TTObjectPtr*)&obj11); TTObjectRelease((TTObjectPtr*)&obj12); TTObjectRelease((TTObjectPtr*)&obj13); // Wrap up the test results to pass back to whoever called this test return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
TTErr TTHalfband9::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; int badSampleCount = 0; TTAudioSignalPtr input = NULL; TTAudioSignalPtr output = NULL; // create 1 channel audio signal objects TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1); TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1); input->allocWithVectorSize(128); output->allocWithVectorSize(128); // create an impulse input->clear(); // set all samples to zero input->mSampleVectors[0][0] = 1.0; // set the first sample to 1 // setup the filter //this->setAttributeValue(TT("linearGain"), 0.5); //this->setAttributeValue(TT("delayInSamples"), 1); this->process(input, output); /// The following values are not necsessarily to be trusted. They were calculated from this filter unit itself at a time when the filter was assumed to work. As such, if this test fails in the future, it should be considered an indication that something has changed in the code or compiler that causes the calculated impulse response to differ from earlier results, but this test is not able to say anything meaningful about whether the old or new behaviour is to be trusted (or eventually none of them). TTFloat64 expectedImpulseResponse[128] = { 8.7103045030879483e-03, 6.5442805786156327e-02, 2.1752960418473016e-01, 4.0159114675452823e-01, 4.0353211792457022e-01, 1.2030853381927020e-01, -1.8246245365496197e-01, -1.6374428214620290e-01, 7.3759595434999117e-02, 1.3557578188789043e-01, -2.9480119034157672e-02, -1.0385906449486471e-01, 1.1768051181853019e-02, 7.8235267984828785e-02, -4.6970087126678179e-03, -5.8706586396073894e-02, 1.8747000302069827e-03, 4.4013161078726402e-02, -7.4824100988214021e-04, -3.2990420653853873e-02, 2.9864218340860499e-04, 2.4727036940893864e-02, -1.1919575486409350e-04, -1.8533241881956156e-02, 4.7574082755266522e-05, 1.3890873825360833e-02, -1.8988036545967643e-05, -1.0411360218772368e-02, 7.5786123658265979e-06, 7.8034260100494678e-03, -3.0248185615325640e-06, -5.8487511897430174e-03, 1.2072826644949055e-06, 4.3837014883001159e-03, -4.8185747420545896e-07, -3.2856310826633872e-03, 1.9232167600518332e-07, 2.4626155853971947e-03, -7.6760513308280766e-08, -1.8457566806100649e-03, 3.0637089514506656e-08, 1.3834143437329480e-03, -1.2228048165209913e-08, -1.0368838246887998e-03, 4.8805276317090555e-09, 7.7715549991975530e-04, -1.9479437471995521e-09, -5.8248634675791178e-04, 7.7747430781886294e-10, 4.3657973750991743e-04, -3.1030993589390189e-10, -3.2722117568094997e-04, 1.2385265383832053e-10, 2.4525576570440455e-04, -4.9432770557625903e-11, -1.8382181558415425e-04, 1.9729886516544118e-11, 1.3777641389022791e-04, -7.8747037150572516e-12, -1.0326489358256396e-04, 3.1429962127728598e-12, 7.7398140549037774e-05, -1.2544503959705767e-12, -5.8010732908556275e-05, 5.0068332553363524e-13, 4.3479663835796007e-05, -1.9983555609105167e-13, -3.2588472382409617e-05, 7.9759495556712181e-14, 2.4425408076516508e-05, -3.1834060243826912e-14, -1.8307104202478260e-05, 1.2705789881620152e-14, 1.3721370108965461e-05, -5.0712066032225982e-15, -1.0284313432908937e-05, 2.0240486150152843e-15, 7.7082027484415434e-06, -8.0784971240215606e-16, -5.7773802790718454e-06, 3.2243353889171191e-16, 4.3302082182200926e-06, -1.2869149472504737e-16, -3.2455373036571498e-06, 5.1364076055775978e-17, 2.4325648695387360e-06, -2.0500720072451300e-17, -1.8232333480949888e-06, 8.1823631565498873e-18, 1.3665328654672198e-06, -3.2657909863192238e-18, -1.0242309764426052e-06, 1.3034609393725535e-18, 7.6767205503389109e-07, -5.2024469036363035e-19, -5.7537840353823865e-07, 2.0764299847898359e-19, 4.3125225815807068e-07, -8.2875646048798849e-20, -3.2322817301236335e-07, 3.3077795824167722e-20, 2.4226296756135623e-07, -1.3202196649436381e-20, -1.8157868141459877e-07, 5.2693352754490783e-21, 1.3609516087477989e-07, -2.1031268494457227e-21, -1.0200477649268290e-07, 8.3941186385839346e-22, 7.6453669332855475e-08, -3.3503080300264441e-22, -5.7302841645625260e-08, 1.3371938590986161e-22, 4.2949091774362909e-08, -5.3370836376407339e-23, -3.2190802956164986e-08, 2.1301669583177287e-23, 2.4127350594668349e-08, -8.5020426479852997e-24, -1.8083706936752792e-08, 3.3933832700722577e-24, 1.3553931472551566e-08, -1.3543862921382747e-24, -1.0158816386769628e-08, 5.4057030471922016e-25, 7.6141413721247876e-09, -2.1575547245305183e-25, -5.7068802730017340e-09 }; //TTTestLog("\nRESULTING VALUES"); for (int i=0; i<128; i++) { TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][i], expectedImpulseResponse[i]); //TTTestLog("%.16e,", output->mSampleVectors[0][i]); badSampleCount += result; if (result) TTTestLog("BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, output->mSampleVectors[0][i], expectedImpulseResponse[i]); } TTTestAssertion("Produces correct impulse response for a delay of 1 sample and alpha = 0.5", badSampleCount == 0, testAssertionCount, errorCount); if (badSampleCount) TTTestLog("badSampleCount is %i", badSampleCount); TTObjectBaseRelease(&input); TTObjectBaseRelease(&output); // Wrap up the test results to pass back to whoever called this test return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }