TTErr TTLowpassTwoPole::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; // Wrap up the test results to pass back to whoever called this test return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
TTErr TTHighpassLinkwitzRiley4::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; // Wrap up the test results to pass back to whoever called this test return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
TTErr TTScoreTest::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; TTScoreTestMain(errorCount, testAssertionCount); return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
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 TTDictionaryTest::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; TTDictionaryTestBasic(errorCount, testAssertionCount); TTDictionaryTestValue(errorCount, testAssertionCount); return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
// The main test method TTErr TTInterpolateTest::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; TestLinear(errorCount, testAssertionCount); TestCosine(errorCount, testAssertionCount); TestCubic(errorCount, testAssertionCount); return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
TTErr TTStringTest::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; TTStringTestBasic(errorCount, testAssertionCount); TTStringTestNumeric(errorCount, testAssertionCount); TTStringTestStream(errorCount, testAssertionCount); TTStringTestParsing(errorCount, testAssertionCount); return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
TTErr TTNodeLibTest::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; TTNodeLibTestAddressParsing(errorCount, testAssertionCount); TTNodeLibTestAddressMethods(errorCount, testAssertionCount); TTNodeLibTestAddressItem(errorCount, testAssertionCount); TTNodeLibTestAddressComparison(errorCount, testAssertionCount); TTNodeLibTestMiscellaneous(errorCount, testAssertionCount); return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
TTErr TTSpatSnap::test(TTValue& aReturnedTestInfo) { // preliminary setup int errorCount = 0; int testAssertionCount = 0; // Attributes and messages TTSpatSnap::testSourceAndSinkCountSetterAndGetter(testAssertionCount, errorCount, aReturnedTestInfo); TTSpatSnap::testSourcePositionSetterAndGetter(testAssertionCount, errorCount, aReturnedTestInfo); TTSpatSnap::testSinkPositionSetterAndGetter(testAssertionCount, errorCount, aReturnedTestInfo); // Inspect matrix coefficients TTSpatSnap::testMatrixCoefficients(testAssertionCount, errorCount, aReturnedTestInfo); // Test audio processing TTSpatSnap::testAudioProcessing(testAssertionCount, errorCount, aReturnedTestInfo); // Wrap up the test results to pass back to whoever called this test return TTTestFinish(testAssertionCount, errorCount, aReturnedTestInfo); }
TTErr TTSoundfile::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; // assemble the full path of the target sound file TTString testSoundPath = TTFoundationBinaryPath; int pos = testSoundPath.find_last_of('/'); testSoundPath = testSoundPath.substr(0,pos+1); testSoundPath += TESTFILE; std::cout << "We will be using the following path for testing: " << testSoundPath << "\n"; { TTTestLog("\n"); TTTestLog("Testing TTSoundfile Basics..."); // TEST 0: instantiate the object to a pointer // ** REMOVED ** // TEST 1: set the filepath TTBoolean result1 = { this->setFilePath(TT(testSoundPath)) == kTTErrNone }; TTTestAssertion("setFilePath operates successfully", result1, testAssertionCount, errorCount); // TEST 2: reports correct number of channels TTColumnID return2 = this->getNumChannels(); TTBoolean result2 = { return2 == TESTNUMCHANNELS }; TTTestAssertion("reports the correct number of channels", result2, testAssertionCount, errorCount); if(!result2) { TTTestLog("Expected a value of %i, but returned value was %i", TESTNUMCHANNELS, return2); } // TEST 3: reports correct sample rate TTFloat64 return3 = this->getSampleRate(); TTBoolean result3 = TTTestFloatEquivalence(return3, TESTSAMPLERATE, true, 0.0000001); TTTestAssertion("reports the correct sample rate", result3, testAssertionCount, errorCount); if(!result3) { TTTestLog("Expected a value of %f, but returned value was %f", TESTSAMPLERATE, return3); } // TEST 4: reports correct duration in samples TTRowID return4 = this->getLengthInSamples(); TTBoolean result4 = { return4 == TESTDURATIONINSAMPLES }; TTTestAssertion("reports the correct duration in samples", result4, testAssertionCount, errorCount); if(!result4) { TTTestLog("Expected a value of %i, but returned value was %i", TESTDURATIONINSAMPLES, return4); } // TEST 5: reports correct duration in seconds TTFloat64 return5 = this->getLengthInSeconds(); TTBoolean result5 = TTTestFloatEquivalence(return5, TESTDURATIONINSECONDS, true, 0.0000001); TTTestAssertion("reports the correct duration in seconds", result5, testAssertionCount, errorCount); if(!result5) { TTTestLog("Expected a value of %f, but returned value was %f", TESTDURATIONINSECONDS, return5); } TTTestLog("\n"); TTTestLog("Testing TTSoundfile Metadata..."); // TEST 6: reports correct title from metadata TTSymbol return6 = this->getTitle(); TTTestLog("Expected metadata title:"); TTTestLog(TESTTITLE); TTTestLog("Returned metadata title:"); TTTestLog(return6.c_str()); // TEST 7: reports correct artist from metadata TTSymbol return7 = this->getArtist(); TTTestLog("Expected metadata artist:"); TTTestLog(TESTARTIST); TTTestLog("Returned metadata artist:"); TTTestLog(return7.c_str()); // TEST 8: reports correct title from metadata TTSymbol return8 = this->getDate(); TTTestLog("Expected metadata date:"); TTTestLog(TESTDATE); TTTestLog("Returned metadata date:"); TTTestLog(return8.c_str()); // TEST 9: reports correct artist from metadata TTSymbol return9 = this->getAnnotation(); TTTestLog("Expected metadata comment:"); TTTestLog(TESTANNOTATION); TTTestLog("Returned metadata comment:"); TTTestLog(return9.c_str()); TTTestLog("\n"); TTTestLog("Testing peek method on first 10 sample values..."); TTSampleValue return10; TTErr error10; for (int channel=0;channel<return2;channel++) { TTTestLog("Channel %i", channel); for (int sample=0;sample<10;sample++) { error10 = this->peek(sample,channel,return10); if (error10 == kTTErrNone) { TTTestLog("peek sample %i returned the value %f", sample, return10); } else { TTTestLog("peek returned an error for sample %i", sample); } } } TTTestLog("\n"); TTTestLog("Testing peeki between samples 2 & 3..."); TTSampleValue return11; TTErr error11; TTFloat64 floatIndex; for (int channel=0;channel<return2;channel++) { TTTestLog("Channel %i", channel); for (int sample=0;sample<11;sample++) { floatIndex = 2 + sample*0.1; error11 = this->peeki(floatIndex,channel,return11); if (error11 == kTTErrNone) { TTTestLog("peek sample %f returned the value %f", floatIndex, return11); } else { TTTestLog("peek returned an error for sample %f", floatIndex); } } } } return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
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 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); }
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 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 TTSoundfileLoader::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; // assemble the full path of the target sound file TTString testSoundPath = TTFoundationBinaryPath; int pos = testSoundPath.find_last_of('/'); testSoundPath = testSoundPath.substr(0,pos+1); testSoundPath += TESTFILE; std::cout << "We will be using the following path for testing: " << testSoundPath << "\n"; try { TTTestLog("\n"); TTTestLog("Testing TTSoundfileLoader Basics..."); // TEST 0: establish our objects & pointers TTObject* testTargetMatrix = new TTObject("samplematrix"); TTObject* testNonSampleMatrix = new TTObject("delay"); TTObjectBase* objectBasePtrToSampleMatrix; TTObjectBase* ptrToNonSampleMatrix; // TEST 1: set the filepath TTBoolean result1 = { this->setFilePath(TT(testSoundPath)) == kTTErrNone }; TTTestAssertion("setFilePath operates successfully", result1, testAssertionCount, errorCount); // TEST 2: set up the samplematrix first int channelsSend = 1; // compiler complained about TTInt32 being ambiguous here int lengthSend = 22050; // compiler complained about TTInt32 being ambiguous here testTargetMatrix->set("numChannels", channelsSend); testTargetMatrix->set("lengthInSamples", lengthSend); TTInt32 channelsReturn, lengthReturn; testTargetMatrix->get("numChannels", channelsReturn); testTargetMatrix->get("lengthInSamples", lengthReturn); // now for the actual test TTBoolean result2a = { channelsSend == channelsReturn }; TTTestAssertion("numChannels attribute set successfully", result2a, testAssertionCount, errorCount); TTBoolean result2b = { lengthSend == lengthReturn }; TTTestAssertion("lengthInSamples attribute set successfully", result2b, testAssertionCount, errorCount); // // TEST 3: set the target via an objectBasePtr objectBasePtrToSampleMatrix = testTargetMatrix->instance(); // is there a better syntax for this? TTBoolean result3 = { this->setTargetMatrix(objectBasePtrToSampleMatrix) == kTTErrNone }; TTTestAssertion("setTargetMatrix via ObjectBasePtr operates successfully", result3, testAssertionCount, errorCount); // TEST 4: set the target to a non-SampleMatrix, should FAIL ptrToNonSampleMatrix = testNonSampleMatrix->instance(); TTBoolean result4 = { this->setTargetMatrix(ptrToNonSampleMatrix) == kTTErrInvalidValue }; TTTestAssertion("setTargetMatrix returns error when not a SampleMatrix", result4, testAssertionCount, errorCount); // TEST 5: copy samplevalues until samplematrix is filled TTBoolean result5 = { this->copyUntilFilled() == kTTErrNone }; TTTestAssertion("copyUntilFilled operates successfully", result5, testAssertionCount, errorCount); // releasing objects objectBasePtrToSampleMatrix = NULL; ptrToNonSampleMatrix = NULL; delete testTargetMatrix; delete testNonSampleMatrix; // TEST 6: use TTSampleMatrix's load message, then compare 5 random sample values for equivalence // create a new TTSampleMatrix TTObject newTargetMatrix("samplematrix"); // set the length and channel count newTargetMatrix.set("numChannels", TESTNUMCHANNELS); newTargetMatrix.set("lengthInSamples", TESTDURATIONINSAMPLES); // prepare necessary TTValues TTValue loadInput6 = TT(testSoundPath); // we cannot pass the naked TTString, it needs to be part of a TTValue TTValue aReturnWeDontCareAbout6; // send message TTBoolean result6a = { newTargetMatrix.send("load", loadInput6, aReturnWeDontCareAbout6) == kTTErrNone }; TTTestAssertion("TTSampleMatrix load operates successfully", result6a, testAssertionCount, errorCount); // now let's test some values! int randomIndex6, randomChannel6; TTSampleValue testValueSoundFile6; TTBoolean result6b = true; for (int i = 0; i<10; i++) { randomIndex6 = lengthReturn * TTRandom64(); randomChannel6 = i % TESTNUMCHANNELS; //std::cout << "let's look at index " << randomIndex6 << " & channel " << randomChannel6 << "\n"; TTValue peekInput6(randomIndex6); peekInput6.append(randomChannel6); TTValue peekOutput6; this->peek(randomIndex6,randomChannel6,testValueSoundFile6); newTargetMatrix.send("peek",peekInput6,peekOutput6); //std::cout << "Does " << testValueSoundFile6 << " = " << double(peekOutput6) << " ?\n"; if (result6b) // allows test to keep variable false once it is false result6b = TTTestFloatEquivalence(testValueSoundFile6, double(peekOutput6), true, 0.0000001); } TTTestAssertion("comparing values @ 10 random indexes for equivalence", result6b, testAssertionCount, errorCount); // TEST 7: now use TTBuffer's load message, and again compare 5 random sample values for equivalence // create a new TTBuffer with convenience syntax TTAudioBuffer aBufferByAnyOtherName(TESTNUMCHANNELS, TESTDURATIONINSAMPLES); // prepare necessary TTValues TTValue loadInput7 = TT(testSoundPath); // we cannot pass the naked TTString, it needs to be part of a TTValue // send message TTBoolean result7a = { aBufferByAnyOtherName.load(loadInput7) == kTTErrNone }; TTTestAssertion("TTBuffer load operates successfully", result7a, testAssertionCount, errorCount); // setup pointer to samplematrix TTSampleMatrixPtr myMatrix7; // check out samplematrix TTBoolean result7b = { aBufferByAnyOtherName.checkOutMatrix(myMatrix7) == kTTErrNone }; TTTestAssertion("TTBuffer checks out SampleMatrix successfully", result7b, testAssertionCount, errorCount); TTValue testChannel, testSample; myMatrix7->getNumChannels(testChannel); myMatrix7->getLengthInSamples(testSample); //std::cout << "Samplematrix has " << int(testChannel) << " channels & " << int(testSample) << " samples\n"; // now let's test some values! int randomIndex7, randomChannel7; double testValueSoundFile7, testValueSampleMatrix7; TTBoolean result7c = true; for (int i = 0; i<10; i++) { randomIndex7 = lengthReturn * TTRandom64(); randomChannel7 = i % TESTNUMCHANNELS; //std::cout << "let's look at index " << randomIndex7 << " & channel " << randomChannel7 << "\n"; this->peek(randomIndex7,randomChannel7,testValueSoundFile7); myMatrix7->peek(randomIndex7,randomChannel7,testValueSampleMatrix7); //std::cout << "Does " << testValueSoundFile7 << " = " << testValueSampleMatrix7 << " ?\n"; if (result7c) // allows test to keep variable false once it is false result7c = TTTestFloatEquivalence(testValueSoundFile7, testValueSampleMatrix7, true, 0.0000001); } TTTestAssertion("comparing values @ 10 random indexes for equivalence", result7c, testAssertionCount, errorCount); // check in samplematrix TTBoolean result7d = { aBufferByAnyOtherName.checkInMatrix(myMatrix7) == kTTErrNone }; TTTestAssertion("TTBuffer checks in SampleMatrix successfully", result7d, testAssertionCount, errorCount); // TEST 8: use optional load parameters to copy samples 5 to 15 from channel 0 // resize aBufferByAnyOtherName.set("numChannels", 1); aBufferByAnyOtherName.set("lengthInSamples", 10); // prepare necessary TTValues int copyChannel8 = 0; // first channel int startIndex8 = 5; // start @ sample 5 int endIndex8 = 15; // end @ sample 15 TTValue loadInput8 = TT(testSoundPath); // we cannot pass the naked TTString, it needs to be part of a TTValue loadInput8.append(copyChannel8); loadInput8.append(startIndex8); loadInput8.append(endIndex8); // send message TTBoolean result8a = { aBufferByAnyOtherName.load(loadInput8) == kTTErrNone }; TTTestAssertion("TTBuffer load operates successfully w optional parameters", result8a, testAssertionCount, errorCount); // setup pointer to samplematrix TTSampleMatrixPtr myMatrix8; // check out samplematrix TTBoolean result8b = { aBufferByAnyOtherName.checkOutMatrix(myMatrix8) == kTTErrNone }; TTTestAssertion("TTBuffer checks out SampleMatrix successfully", result8b, testAssertionCount, errorCount); // now let's test some values! double testValueSoundFile8, testValueSampleMatrix8; TTBoolean result8c = true; for (int i = 0; i<10; i++) { //std::cout << "let's look at index " << i << "\n"; this->peek(i+startIndex8,copyChannel8,testValueSoundFile8); myMatrix8->peek(i,copyChannel8,testValueSampleMatrix8); //std::cout << "Does " << testValueSoundFile8 << " = " << testValueSampleMatrix8 << " ?\n"; if (result8c) // allows test to keep variable false once it is false result8c = TTTestFloatEquivalence(testValueSoundFile8, testValueSampleMatrix8, true, 0.0000001); } TTTestAssertion("comparing all 10 copied values for equivalence", result8c, testAssertionCount, errorCount); // check in samplematrix TTBoolean result8d = { aBufferByAnyOtherName.checkInMatrix(myMatrix8) == kTTErrNone }; TTTestAssertion("TTBuffer checks in SampleMatrix successfully", result8d, testAssertionCount, errorCount); // TEST 9: load soundfile into buffer/samplematrix with different sample rate TTValue testChannel9in = 2; TTValue testSampleRate9in = 88200; TTValue testLengthSec9in = 0.25; aBufferByAnyOtherName.set("numChannels", testChannel9in); aBufferByAnyOtherName.set("sampleRate", testSampleRate9in); aBufferByAnyOtherName.set("lengthInSeconds", testLengthSec9in); TTValue loadInput9 = TT(testSoundPath); // we cannot pass the naked TTString, it needs to be part of a TTValue // send message TTBoolean result9a = { aBufferByAnyOtherName.load(loadInput9) == kTTErrNone }; TTTestAssertion("TTBuffer load operates successfully when sample rates differ", result9a, testAssertionCount, errorCount); // setup pointer to samplematrix TTSampleMatrixPtr myMatrix9; // check out samplematrix TTBoolean result9b = { aBufferByAnyOtherName.checkOutMatrix(myMatrix9) == kTTErrNone }; TTTestAssertion("TTBuffer checks out SampleMatrix successfully", result9b, testAssertionCount, errorCount); TTValue testChannel9, testSampleCount9, testSampleRate9; myMatrix9->getAttributeValue("numChannels", testChannel9); myMatrix9->getAttributeValue("lengthInSamples", testSampleCount9); myMatrix9->getAttributeValue("sampleRate", testSampleRate9); /*std::cout << "Samplematrix has " << TTInt32(testChannel9) << " channels & " << TTInt32(testSampleCount9) << " samples @ " << TTInt32(testSampleRate9) << " Hz\n";*/ // check out samplematrix TTBoolean result9c = { TTInt32(testChannel9) == TTInt32(testChannel9in) && TTInt32(testSampleRate9) == TTInt32(testSampleRate9in) && TTInt32(testSampleCount9) == (TTInt32(testSampleRate9in) * TTFloat64(testLengthSec9in)) }; TTTestAssertion("SampleMatrix has same attributes set via TTBuffer", result9c, testAssertionCount, errorCount); // let's test some values int randomIndex9, randomChannel9; TTSampleValue testSoundFileValue9, testSampleMatrixValue9; TTBoolean result9d = true; for (int i = 0; i<10; i++) { randomIndex9 = int(testSampleCount9) * TTRandom64(); randomChannel9 = i % TESTNUMCHANNELS; //std::cout << "let's look at index " << randomIndex9 << " & channel " << randomChannel9 << "\n"; this->peeki(float(randomIndex9)/2.0, randomChannel9, testSoundFileValue9); myMatrix9->peek(randomIndex9, randomChannel9, testSampleMatrixValue9); //std::cout << "Does " << testSoundFileValue9 << " = " << testSampleMatrixValue9 << " ?\n"; if (result9d) // allows test to keep variable false once it is false result9d = TTTestFloatEquivalence(testSoundFileValue9, testSampleMatrixValue9, true, 0.0000001); } TTTestAssertion("comparing values @ 10 random indexes for equivalence", result9d, testAssertionCount, errorCount); // check in samplematrix TTBoolean result9e = { aBufferByAnyOtherName.checkInMatrix(myMatrix9) == kTTErrNone }; TTTestAssertion("TTBuffer checks in SampleMatrix successfully", result9e, testAssertionCount, errorCount); // TEST 10: use resizeThenLoad message and test that TTSampleMatrix conforms to sound file loaded TTAudioBuffer bufferForTest10(1,1); // start by making the buffer really tiny TTValue loadInput10 = TT(testSoundPath); // send message TTBoolean result10a = { bufferForTest10.resizeThenLoad(loadInput10) == kTTErrNone }; TTTestAssertion("TTBuffer resizeThenLoad operates successfully", result10a, testAssertionCount, errorCount); // setup pointer to samplematrix TTSampleMatrixPtr myMatrix10; // check out samplematrix TTBoolean result10b = { bufferForTest10.checkOutMatrix(myMatrix10) == kTTErrNone }; TTTestAssertion("TTBuffer checks out SampleMatrix successfully", result10b, testAssertionCount, errorCount); // do some more tests here TTValue testChannel10, testLengthSec10, testLengthSample10; myMatrix10->getAttributeValue("numChannels", testChannel10); myMatrix10->getAttributeValue("lengthInSeconds", testLengthSec10); myMatrix10->getAttributeValue("lengthInSamples", testLengthSample10); /*std::cout << "Samplematrix has " << TTInt32(testChannel10) << " channels & " << TTInt32(testLengthSample10) << " samples and is " << TTFloat64(testLengthSec10) << " secs long\n";*/ TTBoolean result10c = { TTInt32(testChannel10) == TESTNUMCHANNELS && TTInt32(testLengthSample10) == TESTDURATIONINSAMPLES }; TTTestAssertion("TTBuffer.resizeThenLoad results in properly sized TTSampleMatrix", result10c, testAssertionCount, errorCount); // check in samplematrix TTBoolean result10e = { bufferForTest10.checkInMatrix(myMatrix10) == kTTErrNone }; TTTestAssertion("TTBuffer checks in SampleMartix successfully", result10e, testAssertionCount, errorCount); } catch (...) { TTTestAssertion("FAILED to run tests -- likely that necessary objects did not instantiate", 0, testAssertionCount, errorCount); } return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
TTErr TemperatureDataspace::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; // Create dataspace object and set to temperature try { TTObject myDataspace("dataspace"); myDataspace.set(TT("dataspace"), TT("temperature")); TTValue v; TTValue expected; /************************************************/ /* */ /* Test conversions to neutral unit */ /* */ /************************************************/ // Kelvin => Kelvin myDataspace.set(TT("inputUnit"), TT("Kelvin")); myDataspace.set(TT("outputUnit"), TT("Kelvin")); v = TTValue(256.); expected = TTValue(256.); myDataspace.send(TT("convert"), v, v); TTTestAssertion("Kelvin to Kelvin", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Celsius => Kelvin // Expected value according to Google search: "0 Celsius to Kelvin" myDataspace.set(TT("inputUnit"), TT("Celsius")); myDataspace.set(TT("outputUnit"), TT("Kelvin")); v = TTValue(0.); expected = TTValue(273.15); myDataspace.send(TT("convert"), v, v); TTTestAssertion("Celsius to Kelvin", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Fahrenheit => Kelvin // Expected value according to Google search: "32 Farhenheit to Kelvin" myDataspace.set(TT("inputUnit"), TT("Fahrenheit")); myDataspace.set(TT("outputUnit"), TT("Kelvin")); v = TTValue(32.); expected = TTValue(273.15); myDataspace.send(TT("convert"), v, v); TTTestAssertion("Fahrenheit to Kelvin", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); /************************************************/ /* */ /* Test conversions from neutral unit */ /* */ /************************************************/ // Kelvin => Celsius // Expected value according to Google search: "0 Celsius to Kelvin" myDataspace.set(TT("inputUnit"), TT("Kelvin")); myDataspace.set(TT("outputUnit"), TT("Celsius")); v = TTValue(273.15); expected = TTValue(0.0); myDataspace.send(TT("convert"), v, v); TTTestAssertion("Kelvin to Celsius", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Fahrenheit => Kelvin // Expected value according to Google search: "32 Farhenheit to Kelvin" myDataspace.set(TT("inputUnit"), TT("Kelvin")); myDataspace.set(TT("outputUnit"), TT("Fahrenheit")); v = TTValue(273.15); expected = TTValue(32.0); myDataspace.send(TT("convert"), v, v); TTTestAssertion("Kelvin to Fahrenheit", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); } catch (...) { TTLogMessage("TemperatureDataspace::test TOTAL FAILURE"); errorCount = 1; testAssertionCount = 1; } 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 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 TimeDataspace::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; // Create dataspace object and set to time TTObjectBasePtr myDataspace = NULL; TTErr err; err = TTObjectBaseInstantiate(TT("dataspace"), (TTObjectBasePtr*)&myDataspace, kTTValNONE); myDataspace->setAttributeValue(TT("dataspace"), TT("time")); TTValue v; TTValue expected; /************************************************/ /* */ /* Test conversions to neutral unit */ /* */ /************************************************/ // Second to second myDataspace->setAttributeValue(TT("inputUnit"), TT("second")); myDataspace->setAttributeValue(TT("outputUnit"), TT("second")); v = TTValue(256.); expected = TTValue(256.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Second to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Millisecond => second myDataspace->setAttributeValue(TT("inputUnit"), TT("millisecond")); myDataspace->setAttributeValue(TT("outputUnit"), TT("second")); v = TTValue(1234.5); expected = TTValue(1.2345); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Millisecond to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Sample => second // We need to find the sample rate myDataspace->setAttributeValue(TT("inputUnit"), TT("sample")); myDataspace->setAttributeValue(TT("outputUnit"), TT("second")); TTValue globalSampleRate; ttEnvironment->getAttributeValue(kTTSym_sampleRate, globalSampleRate); v = TTValue(1.23*TTFloat64(globalSampleRate)); expected = TTValue(1.23); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Sample to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Rate (Hz) => second myDataspace->setAttributeValue(TT("inputUnit"), TT("Hz")); myDataspace->setAttributeValue(TT("outputUnit"), TT("second")); v = TTValue(4.); expected = TTValue(0.25); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Frequency (Hz) to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Beats per minute => second myDataspace->setAttributeValue(TT("inputUnit"), TT("bpm")); myDataspace->setAttributeValue(TT("outputUnit"), TT("second")); v = TTValue(120.); expected = TTValue(0.5); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Beats per minute to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // MIDI => second (2 tests at MIDI notes 57 and 69) myDataspace->setAttributeValue(TT("inputUnit"), TT("midi")); myDataspace->setAttributeValue(TT("outputUnit"), TT("second")); v = TTValue(57.); expected = TTValue(1./220.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("MIDI note 57 to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); v = TTValue(69.); expected = TTValue(1./440.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("MIDI note 69 to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // cents => second (2 tests at cents values 5700 and 6900) myDataspace->setAttributeValue(TT("inputUnit"), TT("cents")); myDataspace->setAttributeValue(TT("outputUnit"), TT("second")); v = TTValue(5700.); expected = TTValue(1./220.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Cent value 5700 to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); v = TTValue(6900.); expected = TTValue(1./440.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Cent value 6900 to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Bark => second myDataspace->setAttributeValue(TT("inputUnit"), TT("bark")); myDataspace->setAttributeValue(TT("outputUnit"), TT("second")); v = TTValue(5.0); expected = TTValue(0.001785990780318596); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Bark to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Mel => second myDataspace->setAttributeValue(TT("inputUnit"), TT("mel")); myDataspace->setAttributeValue(TT("outputUnit"), TT("second")); v = TTValue(1000.0); expected = TTValue(0.0009999781840186604); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Mel to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // speed => seconds // Rather than checking this, there are tests for speed <=> midi further down /************************************************/ /* */ /* Test conversions from neutral unit */ /* */ /************************************************/ // Second => Millisecond myDataspace->setAttributeValue(TT("inputUnit"), TT("second")); myDataspace->setAttributeValue(TT("outputUnit"), TT("millisecond")); v = TTValue(1.2345); expected = TTValue(1234.5); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Second to millisecond", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Second => sample // We need to find the sample rate myDataspace->setAttributeValue(TT("inputUnit"), TT("second")); myDataspace->setAttributeValue(TT("outputUnit"), TT("sample")); ttEnvironment->getAttributeValue(kTTSym_sampleRate, globalSampleRate); v = TTValue(192000./TTFloat64(globalSampleRate)); expected = TTValue(192000.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Second to sample", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Second => rate (Hz) myDataspace->setAttributeValue(TT("inputUnit"), TT("second")); myDataspace->setAttributeValue(TT("outputUnit"), TT("Hz")); v = TTValue(0.25); expected = TTValue(4.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Second to frequency (Hz)", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Second => Beats per minute myDataspace->setAttributeValue(TT("inputUnit"), TT("second")); myDataspace->setAttributeValue(TT("outputUnit"), TT("bpm")); v = TTValue(0.5); expected = TTValue(120.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Seconds to beats per minute", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Second => MIDI (2 tests at MIDI notes 57 and 69) myDataspace->setAttributeValue(TT("inputUnit"), TT("second")); myDataspace->setAttributeValue(TT("outputUnit"), TT("midi")); v = TTValue(1./220.); expected = TTValue(57.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Second to MIDI note 57", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); v = TTValue(1./440.); expected = TTValue(69.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Second to MIDI note 69", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Second => cents (2 tests at cent values 5700 and 6900) myDataspace->setAttributeValue(TT("inputUnit"), TT("second")); myDataspace->setAttributeValue(TT("outputUnit"), TT("cents")); v = TTValue(1./220.); expected = TTValue(5700.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Second to cent value 5700", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); v = TTValue(1./440.); expected = TTValue(6900.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Second to cent value 6900", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Second => Bark myDataspace->setAttributeValue(TT("inputUnit"), TT("second")); myDataspace->setAttributeValue(TT("outputUnit"), TT("bark")); v = TTValue(0.001785990780318596); expected = TTValue(5.0); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Seconds to bark scale", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Second => Mel myDataspace->setAttributeValue(TT("inputUnit"), TT("second")); myDataspace->setAttributeValue(TT("outputUnit"), TT("mel")); v = TTValue(0.001); expected = TTValue(999.9855371396243); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Seconds to mel scale", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Second => Speed // Rather than checking this, there are tests for speed <=> midi further down /************************************************/ /* */ /* Tests bypassing neutral unit */ /* - where this helps predict expected result */ /* */ /************************************************/ // Speed => MIDI (tests for Speed = 0.5, 1.0 and 2) myDataspace->setAttributeValue(TT("inputUnit"), TT("speed")); myDataspace->setAttributeValue(TT("outputUnit"), TT("midi")); v = TTValue(0.5); expected = TTValue(-12.0); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("0.5 speed to MIDI", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); v = TTValue(1.0); expected = TTValue(0.0); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("1.0 speed to MIDI", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); v = TTValue(2.0); expected = TTValue(12.0); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("2.0 speed to MIDI", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // MIDI => Speed (tests for Speed = 0.5, 1.0 and 2)*/ myDataspace->setAttributeValue(TT("inputUnit"), TT("midi")); myDataspace->setAttributeValue(TT("outputUnit"), TT("speed")); v = TTValue(-12.0); expected = TTValue(0.5); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("-12 MIDI to speed", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); v = TTValue(0.0); expected = TTValue(1.0); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("0 MIDI to speed", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); v = TTValue(12.0); expected = TTValue(2.0); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("12 MIDI to speed", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Hz => Mel myDataspace->setAttributeValue(TT("inputUnit"), TT("Hz")); myDataspace->setAttributeValue(TT("outputUnit"), TT("mel")); v = TTValue(1000.0); expected = TTValue(999.9855371396243); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Hz to mel scale", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Mel => Hz myDataspace->setAttributeValue(TT("inputUnit"), TT("mel")); myDataspace->setAttributeValue(TT("outputUnit"), TT("Hz")); v = TTValue(999.9855371396243); expected = TTValue(1000.0); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("mel scale to Hz", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); 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 SpeedDataspace::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; // Create dataspace object and set to temperature try { TTObject myDataspace("dataspace"); myDataspace.set(TT("dataspace"), TT("speed")); TTValue v; TTValue expected; /************************************************/ /* */ /* Test conversions to neutral unit */ /* */ /************************************************/ // meterPerSecond => meterPerSecond myDataspace.set(TT("inputUnit"), TT("m/s")); myDataspace.set(TT("outputUnit"), TT("m/s")); v = TTValue(256.); expected = TTValue(256.); myDataspace.send(TT("convert"), v, v); TTTestAssertion("m/s to m/s", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // kilometerPerHour => meterPerSecond // Trivial conversion: 36 km/h = (36000 m) / (60*60 s) = 10 m/s myDataspace.set(TT("inputUnit"), TT("kmph")); myDataspace.set(TT("outputUnit"), TT("m/s")); v = TTValue(36.); expected = TTValue(10.0); myDataspace.send(TT("convert"), v, v); TTTestAssertion("kmph to m/s", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // milesPerHour => meterPerSecond // Expected value according to Google search: "50 miles per hour to m/s" myDataspace.set(TT("inputUnit"), TT("mph")); myDataspace.set(TT("outputUnit"), TT("m/s")); v = TTValue(50.); expected = TTValue(22.35200); myDataspace.send(TT("convert"), v, v); TTTestAssertion("miles per hour to m/s", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // knot => meterPerSecond // Expected value according to Google search: "45 knot to m/s" // This is a somewhat rough estimate, with limited precision myDataspace.set(TT("inputUnit"), TT("kn")); myDataspace.set(TT("outputUnit"), TT("m/s")); v = TTValue(45.); expected = TTValue(23.15); myDataspace.send(TT("convert"), v, v); TTTestAssertion("knot to m/s", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected), true, 0.1), testAssertionCount, errorCount); // footPerSecond => meterPerSecond // Expected value according to Google search: "20 foot per second to m/s" myDataspace.set(TT("inputUnit"), TT("ft/s")); myDataspace.set(TT("outputUnit"), TT("m/s")); v = TTValue(20.); expected = TTValue(6.09600); myDataspace.send(TT("convert"), v, v); TTTestAssertion("foot per hour to m/s", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); /************************************************/ /* */ /* Test conversions from neutral unit */ /* */ /************************************************/ // meterPerSecond =>kilometerPerHour myDataspace.set(TT("inputUnit"), TT("m/s")); myDataspace.set(TT("outputUnit"), TT("kmph")); v = TTValue(10.); expected = TTValue(36.0); myDataspace.send(TT("convert"), v, v); TTTestAssertion("m/s to kmph", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // milesPerHour => meterPerSecond // Expected value according to Google search: "50 miles per hour to m/s" myDataspace.set(TT("inputUnit"), TT("m/s")); myDataspace.set(TT("outputUnit"), TT("mph")); v = TTValue(22.35200); expected = TTValue(50.); myDataspace.send(TT("convert"), v, v); TTTestAssertion("m/s to miles per hour", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected), true, 0.00001), testAssertionCount, errorCount); // knot => meterPerSecond // Expected value according to Google search: "45 knot to m/s" // This is a somewhat rough estimate, with limited precision myDataspace.set(TT("inputUnit"), TT("m/s")); myDataspace.set(TT("outputUnit"), TT("kn")); v = TTValue(23.15); expected = TTValue(45.); myDataspace.send(TT("convert"), v, v); TTTestAssertion("m/s to knot", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected), true, 0.1), testAssertionCount, errorCount); // footPerSecond => meterPerSecond // Expected value according to Google search: "20 foot per second to m/s" myDataspace.set(TT("inputUnit"), TT("m/s")); myDataspace.set(TT("outputUnit"), TT("ft/s")); v = TTValue(6.09600); expected = TTValue(20.); myDataspace.send(TT("convert"), v, v); TTTestAssertion("m/s to foot per hour", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected), true, 0.00001), testAssertionCount, errorCount); } catch (...) { TTLogMessage("SpeedDataspace::test TOTAL FAILURE"); errorCount = 1; testAssertionCount = 1; } 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 TTBuffer::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; //int badSampleCount = 0; // *** Tim's old list (we'll get there) *** // TODO: test filling with sine wave // TODO: test scaling (applying gain) // TODO: test normalizing (with optional arg, and also without an optional arg) this->init(1,"myFirstBuffer"); this->setAttributeValue("lengthInSamples", 50); TTTestLog("\nTest checkout of first SampleMatrix..."); // TEST 1: checking out a matrix returns something TTSampleMatrixPtr myFirstCheckOut = NULL; this->checkOutMatrix(myFirstCheckOut); TTBoolean result1 = { myFirstCheckOut != NULL }; TTTestAssertion("checkOutMatrix returns a valid pointer", result1, testAssertionCount, errorCount); // TEST 2: how many channels does this matrix have? TTInt32 test2expect = 1; TTInt32 test2return = 0; myFirstCheckOut->getAttributeValue("numChannels", test2return); TTBoolean result2 = { test2expect == test2return }; TTTestAssertion("numChannels is set properly", result2, testAssertionCount, errorCount); if(!result2) { TTTestLog("Expected a value of %i, but returned value was %i", test2expect, test2return); } // TEST 3: what is the user count? TTInt32 test3expect = 1; TTInt32 test3return = 0; myFirstCheckOut->getAttributeValue("userCount", test3return); TTBoolean result3 = { test2expect == test3return }; TTTestAssertion("userCount reports proper value", result3, testAssertionCount, errorCount); if(!result3) { TTTestLog("Expected a value of %i, but returned value was %i", test3expect, test3return); } // TEST 4: what is the buffer stage? TTBoolean test4expect = true; TTBoolean test4return = false; test4return = myFirstCheckOut->isBufferPoolStage(kSM_Active); TTBoolean result4 = { test4expect == test4return }; TTTestAssertion("bufferPoolStage reports proper value", result4, testAssertionCount, errorCount); if(!result4) { TTTestLog("Expected a value of %i, but returned value was %i", test4expect, test4return); } TTTestLog("\nTest second checkout of first SampleMatrix..."); // TEST 5: checking out a matrix returns something TTSampleMatrixPtr myFirstCheckOut2 = NULL; this->checkOutMatrix(myFirstCheckOut2); TTBoolean result5 = { myFirstCheckOut == myFirstCheckOut2 }; TTTestAssertion("checkOutMatrix returns the same pointer", result5, testAssertionCount, errorCount); // TEST 6: what is the user count after 2 checkouts? TTInt32 test6expect = 2; TTInt32 test6return = 0; myFirstCheckOut->getAttributeValue("userCount", test6return); TTBoolean result6 = { test6expect == test6return }; TTTestAssertion("userCount reports proper value after second checkout", result6, testAssertionCount, errorCount); if(!result6) { TTTestLog("Expected a value of %i, but returned value was %i", test6expect, test6return); } TTTestLog("\nTest if changing lengthInSamples attribute spawns new SampleMatrix..."); // TEST 7: changing length at TTBuffer should spawn a new matrix TTSampleMatrixPtr mySecondCheckOut = NULL; this->setAttributeValue("lengthInSamples", 100); this->checkOutMatrix(mySecondCheckOut); TTBoolean result7 = { mySecondCheckOut != myFirstCheckOut }; TTTestAssertion("checkOutMatrix returns pointer to different SampleMatrix", result7, testAssertionCount, errorCount); // TEST 8: what is the user count on new checkout? TTInt32 test8expect = 1; TTInt32 test8return = 0; mySecondCheckOut->getAttributeValue("userCount", test8return); TTBoolean result8 = { test8expect == test8return }; TTTestAssertion("userCount reports proper value", result8, testAssertionCount, errorCount); if(!result8) { TTTestLog("Expected a value of %i, but returned value was %i", test8expect, test8return); } TTTestLog("\nRepeat with numChannels attribute..."); // TEST 9: changing numChannels at TTBuffer should spawn a new matrix TTSampleMatrixPtr myThirdCheckOut = NULL; this->setAttributeValue("numChannels", 2); this->checkOutMatrix(myThirdCheckOut); TTBoolean result9 = { mySecondCheckOut != myThirdCheckOut && myFirstCheckOut != myThirdCheckOut}; TTTestAssertion("checkOutMatrix returns pointer to different SampleMatrix", result9, testAssertionCount, errorCount); // TEST 10: what is the user count on new checkout? TTInt32 test10expect = 1; TTInt32 test10return = 0; myThirdCheckOut->getAttributeValue("userCount", test10return); TTBoolean result10 = { test10expect == test10return }; TTTestAssertion("userCount reports proper value", result10, testAssertionCount, errorCount); if(!result10) { TTTestLog("Expected a value of %i, but returned value was %i", test10expect, test10return); } /******/ TTTestLog("\nAt this point, 3 SampleMatrix objects are checked out via 4 pointers:"); TTTestLog("myFirstCheckOut: userCount %i, Active %i, Becoming Idle %i", myFirstCheckOut->getUserCount(), myFirstCheckOut->isBufferPoolStage(kSM_Active), myFirstCheckOut->isBufferPoolStage(kSM_BecomingIdle)); TTTestLog("myFirstCheckOut2: userCount %i, Active %i, Becoming Idle %i", myFirstCheckOut2->getUserCount(), myFirstCheckOut2->isBufferPoolStage(kSM_Active), myFirstCheckOut2->isBufferPoolStage(kSM_BecomingIdle)); TTTestLog("mySecondCheckOut: userCount %i, Active %i, Becoming Idle %i", mySecondCheckOut->getUserCount(), mySecondCheckOut->isBufferPoolStage(kSM_Active), mySecondCheckOut->isBufferPoolStage(kSM_BecomingIdle)); TTTestLog("myThirdCheckOut: userCount %i, Active %i, Becoming Idle %i", myThirdCheckOut->getUserCount(), myThirdCheckOut->isBufferPoolStage(kSM_Active), myThirdCheckOut->isBufferPoolStage(kSM_BecomingIdle)); /******/ TTTestLog("\nTesting check in process..."); // TEST 11: checking out a matrix returns NULL pointer this->checkInMatrix(myFirstCheckOut); TTBoolean result11 = { myFirstCheckOut == NULL }; TTTestAssertion("checkInMatrix(myFirstCheckOut) resets pointer to NULL", result11, testAssertionCount, errorCount); // TEST 12: second pointer to first matrix is still valid TTBoolean result12 = { myFirstCheckOut2 != NULL }; TTTestAssertion("myFirstCheckOut2 is still a valid pointer", result12, testAssertionCount, errorCount); // TEST 13: poke/peek a sample into first matrix TTSampleValue test13expect = TTRandom64(); myFirstCheckOut2->poke(10,0,test13expect); TTSampleValue test13return; myFirstCheckOut2->peek(10,0,test13return); TTBoolean result13 = TTTestFloatEquivalence(test13expect,test13return); TTTestAssertion("poke/peek sample value still works", result13, testAssertionCount, errorCount); if(!result13) { TTTestLog("Expected a value of %i, but returned value was %i", test13expect, test13return); } // TEST 14: checking out a matrix returns NULL pointer this->checkInMatrix(myFirstCheckOut2); TTBoolean result14 = { myFirstCheckOut2 == NULL }; TTTestAssertion("checkInMatrix(myFirstCheckOut2) resets pointer to NULL", result14, testAssertionCount, errorCount); // TEST 15: checking out a matrix returns NULL pointer this->checkInMatrix(mySecondCheckOut); TTBoolean result15 = { mySecondCheckOut == NULL }; TTTestAssertion("checkInMatrix(mySecondCheckOut) resets pointer to NULL", result15, testAssertionCount, errorCount); // TEST 16: checking out a matrix returns NULL pointer this->checkInMatrix(myThirdCheckOut); TTBoolean result16 = { myThirdCheckOut == NULL }; TTTestAssertion("checkInMatrix(myThirdCheckOut) resets pointer to NULL", result16, testAssertionCount, errorCount); // The following is effectively taken care of through check in... //TTObjectRelease(&myFirstCheckOut); //TTObjectRelease(&mySecondCheckOut); //TTObjectRelease(&myThirdCheckOut); // Wrap up the test results to pass back to whoever called this 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 ColorDataspace::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; // Create dataspace object and set to angle TTObjectBasePtr myDataspace = NULL; TTErr err; err = TTObjectBaseInstantiate(TT("dataspace"), (TTObjectBasePtr*)&myDataspace, kTTValNONE); myDataspace->setAttributeValue(TT("dataspace"), TT("color")); TTValue v; TTValue expected; /************************************************/ /* */ /* Test conversions to neutral unit */ /* */ /************************************************/ // rgb => rgb myDataspace->setAttributeValue(TT("inputUnit"), TT("rgb")); myDataspace->setAttributeValue(TT("outputUnit"), TT("rgb")); v.setSize(3); v.set(0, TTFloat64(124.2)); v.set(1, TTFloat64(162.9)); v.set(2, TTFloat64(13.163)); expected.setSize(3); expected.set(0, TTFloat64(124.2)); expected.set(1, TTFloat64(162.9)); expected.set(2, TTFloat64(13.163)); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("rgb to rgb", TTTestFloat64ArrayEquivalence(v, expected), testAssertionCount, errorCount); // cmy => rgb myDataspace->setAttributeValue(TT("inputUnit"), TT("cmy")); myDataspace->setAttributeValue(TT("outputUnit"), TT("rgb")); v.setSize(3); v.set(0, TTFloat64(255.)); v.set(1, TTFloat64(127.5)); v.set(2, TTFloat64(0.)); expected.setSize(3); expected.set(0, TTFloat64(0.)); expected.set(1, TTFloat64(0.5)); expected.set(2, TTFloat64(1.0)); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("cmy to rgb", TTTestFloat64ArrayEquivalence(v, expected), testAssertionCount, errorCount); // hsl => rgb myDataspace->setAttributeValue(TT("inputUnit"), TT("hsl")); myDataspace->setAttributeValue(TT("outputUnit"), TT("rgb")); v.setSize(3); v.set(0, TTFloat64(120.)); v.set(1, TTFloat64(100.)); v.set(2, TTFloat64(50.)); expected.setSize(3); expected.set(0, TTFloat64(0.)); expected.set(1, TTFloat64(1.0)); expected.set(2, TTFloat64(0.)); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("hsl to rgb", TTTestFloat64ArrayEquivalence(v, expected), testAssertionCount, errorCount); // rgb8 => rgb myDataspace->setAttributeValue(TT("inputUnit"), TT("rgb8")); myDataspace->setAttributeValue(TT("outputUnit"), TT("rgb")); v.setSize(3); v.set(0, TTFloat64(255.)); v.set(1, TTFloat64(127.5)); v.set(2, TTFloat64(0.)); expected.setSize(3); expected.set(0, TTFloat64(1.)); expected.set(1, TTFloat64(0.5)); expected.set(2, TTFloat64(0.0)); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("rgb8 to rgb", TTTestFloat64ArrayEquivalence(v, expected), testAssertionCount, errorCount); // hsv => rgb myDataspace->setAttributeValue(TT("inputUnit"), TT("hsv")); myDataspace->setAttributeValue(TT("outputUnit"), TT("rgb")); v.setSize(3); v.set(0, TTFloat64(120.)); v.set(1, TTFloat64(100.)); v.set(2, TTFloat64(100.)); expected.setSize(3); expected.set(0, TTFloat64(0.)); expected.set(1, TTFloat64(1.0)); expected.set(2, TTFloat64(0.)); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("hsv to rgb", TTTestFloat64ArrayEquivalence(v, expected), testAssertionCount, errorCount); /************************************************/ /* */ /* Test conversions from neutral unit */ /* */ /************************************************/ // rgb => cmy myDataspace->setAttributeValue(TT("inputUnit"), TT("rgb")); myDataspace->setAttributeValue(TT("outputUnit"), TT("cmy")); v.setSize(3); v.set(0, TTFloat64(0.)); v.set(1, TTFloat64(0.5)); v.set(2, TTFloat64(1.)); expected.setSize(3); expected.set(0, TTFloat64(255.)); expected.set(1, TTFloat64(127.5)); expected.set(2, TTFloat64(0.0)); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("rgb to cmy", TTTestFloat64ArrayEquivalence(v, expected), testAssertionCount, errorCount); // rgb => hsl myDataspace->setAttributeValue(TT("inputUnit"), TT("rgb")); myDataspace->setAttributeValue(TT("outputUnit"), TT("hsl")); v.setSize(3); v.set(0, TTFloat64(0.)); v.set(1, TTFloat64(1.)); v.set(2, TTFloat64(0.)); expected.setSize(3); expected.set(0, TTFloat64(120.)); expected.set(1, TTFloat64(100.0)); expected.set(2, TTFloat64(50.)); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("rgb to hsl", TTTestFloat64ArrayEquivalence(v, expected), testAssertionCount, errorCount); // rgb => rgb8 myDataspace->setAttributeValue(TT("inputUnit"), TT("rgb")); myDataspace->setAttributeValue(TT("outputUnit"), TT("rgb8")); v.setSize(3); v.set(0, TTFloat64(1.)); v.set(1, TTFloat64(0.5)); v.set(2, TTFloat64(0.)); expected.setSize(3); expected.set(0, TTFloat64(255.)); expected.set(1, TTFloat64(127.5)); expected.set(2, TTFloat64(0.0)); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("rgb to rgb8", TTTestFloat64ArrayEquivalence(v, expected), testAssertionCount, errorCount); // rgb => hsv myDataspace->setAttributeValue(TT("inputUnit"), TT("rgb")); myDataspace->setAttributeValue(TT("outputUnit"), TT("hsv")); v.setSize(3); v.set(0, TTFloat64(0.)); v.set(1, TTFloat64(1.)); v.set(2, TTFloat64(0.)); expected.setSize(3); expected.set(0, TTFloat64(120.)); expected.set(1, TTFloat64(100.0)); expected.set(2, TTFloat64(100.)); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("rgb to hsv", TTTestFloat64ArrayEquivalence(v, expected), testAssertionCount, errorCount); return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
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 TTSampleMatrix::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; // for tests TTInt16 numChannels = 2; TTUInt32 numSamples = 50000; // TODO: xcode says this is ambiguous when signed? TTFloat32 duration = 1500; int test9Index = 10; int test10Index = 11; TTInt32 test1Return, test2Return, test7Return; TTFloat32 test3Return, test6Return; TTSampleValue test9Return, test10Return, test11Return, test12return, test13return; TTTestLog("Test resizing of the SampleMatrix..."); // TEST 1: can we set the number of channels? this->setAttributeValue("numChannels", numChannels); this->getAttributeValue("numChannels", test1Return); TTBoolean result = { numChannels == test1Return }; TTTestAssertion("numChannels is set properly", result, testAssertionCount, errorCount); if(!result) { TTTestLog("Expected a value of %i, but returned value was %i", numChannels, test1Return); } // TEST 2: can we set the number of samples? //this->setAttributeValue("lengthInSamples", numSamples); // TODO: xcode says this is ambiguous? this->setLengthInSamples(numSamples); this->getAttributeValue("lengthInSamples", test2Return); TTBoolean result2 = { numSamples == test2Return }; TTTestAssertion("lengthInSamples is set properly", result2, testAssertionCount, errorCount); if(!result2) { TTTestLog("Expected a value of %i, but returned value was %i", numSamples, test2Return); } // TEST 3: is the length in sec computed properly after setting length in samples? TTFloat32 computedDuration3 = (numSamples / this->mSampleRate); this->getAttributeValue("lengthInSeconds", test3Return); TTBoolean result3 = TTTestFloatEquivalence(computedDuration3, test3Return); TTTestAssertion("after lengthInSamples is set, lengthInSeconds is correct", result3, testAssertionCount, errorCount); if(!result3) { TTTestLog("Expected a value of %f, but returned value was %f", computedDuration3, test3Return); } // TEST 4: is the matrix of samples the expected size? (lifted from TTMatrix.test.cpp) TTUInt32 computedDataSize4 = sizeof(TTFloat64) * numChannels * numSamples; TTBoolean result4 = { computedDataSize4 == this->mDataSize }; TTTestAssertion("correct amount of data storage calculated", result4, testAssertionCount, errorCount); if(!result4) { TTTestLog("Expected a value of %i, but returned value was %i", computedDataSize4, this->mDataSize); } // TEST 5: Is the component stride right? (lifted from TTMatrix.test.cpp) TTBoolean result5 = { sizeof(TTFloat64) == this->mComponentStride }; TTTestAssertion("correct byte-stride between values calculated", result5, testAssertionCount, errorCount); if(!result5) { TTTestLog("Expected a value of %i, but returned value was %i", sizeof(TTFloat64), this->mComponentStride); } // TEST 6: can we set the length in seconds? this->setAttributeValue("lengthInSeconds", duration); this->getAttributeValue("lengthInSeconds", test6Return); TTBoolean result6 = TTTestFloatEquivalence(duration, test6Return); TTTestAssertion("lengthInSeconds is set properly", result6, testAssertionCount, errorCount); if(!result6) { TTTestLog("Expected a value of %f, but returned value was %f", duration, test6Return); } // TEST 7: is the length in samples computed properly after setting length in ms? TTUInt32 computedSamples7 = TTUInt32(duration * this->mSampleRate); this->getAttributeValue("lengthInSamples", test7Return); TTBoolean result7 = { computedSamples7 == test7Return }; TTTestAssertion("after lengthInSeconds is set, lengthInSamples is correct", result7, testAssertionCount, errorCount); if(!result7) { TTTestLog("Expected a value of %i, but returned value was %i", computedSamples7, test7Return); } // TEST 8 (REPEAT TEST 4 WITH NEW SIZE): is the matrix of samples the expected size? TTUInt32 computedDataSize8 = sizeof(TTFloat64) * numChannels * test7Return; TTBoolean result8 = { computedDataSize8 == this->mDataSize }; TTTestAssertion("correct amount of data storage calculated with new length", result8, testAssertionCount, errorCount); if(!result8) { TTTestLog("Expected a value of %i, but returned value was %i", computedDataSize8, this->mDataSize); } // TEST 9 & 10: set the value of two consecutive samples TTSampleValue pokeValue9 = TTRandom64(); TTSampleValue pokeValue10 = TTRandom64(); this->poke(test9Index, 0, pokeValue9); this->poke(test10Index, 0, pokeValue10); this->peek(test9Index, 0, test9Return); this->peek(test10Index, 0, test10Return); TTBoolean result9 = { pokeValue9 == test9Return }; TTTestAssertion("set value one of two consecutive samples", result9, testAssertionCount, errorCount); if(!result9) { TTTestLog("Expected a value of %f, but returned value was %f", pokeValue9, test9Return); } TTBoolean result10 = { pokeValue10 == test10Return }; TTTestAssertion("set value two of two consecutive samples", result10, testAssertionCount, errorCount); if(!result10) { TTTestLog("Expected a value of %f, but returned value was %f", pokeValue10, test10Return); } // TEST 10a: confirm that pulling value via "peek" message works too TTValue input(test10Index); input.append(0); TTValue output; this->sendMessage("peek", input, output); TTBoolean result10a = { TTTestFloatEquivalence(pokeValue10, TTSampleValue(output)) }; TTTestAssertion("set value two of two consecutive samples", result10a, testAssertionCount, errorCount); if(!result10a) { TTTestLog("Expected a value of %f, but returned value was %f", pokeValue10, TTSampleValue(output)); } // TEST 11: test for interpolation between two consecutive samples TTFloat64 computedInterpFraction = TTRandom64(); TTFloat64 computedInterpIndex = test9Index + computedInterpFraction; TTSampleValue computedInterpValue11 = (computedInterpFraction * pokeValue10) + ((1.0 - computedInterpFraction) * pokeValue9); this->peeki(computedInterpIndex, 0, test11Return); TTBoolean result11 = TTTestFloatEquivalence(computedInterpValue11, test11Return); TTTestAssertion("interpolate between two consecutive samples", result11, testAssertionCount, errorCount); if(!result11) { TTTestLog("Expected a value of %f, but returned value was %f", computedInterpValue11, test11Return); } // TODO: inbounds testing on hold until sorted out at TTMatrix parent class // TEST 12 & 13: test whether out of bounds indices produce errors at head TTInt32 computedIndex12 = -1; // 1 before the head TTInt32 computedIndex13 = 0; // the head TTErr test12Err = this->peek(computedIndex12, 0, test12return); TTErr test13Err = this->peek(computedIndex13, 0, test13return); TTBoolean result12 = { test12Err == kTTErrOutOfBounds }; TTBoolean result13 = { test13Err == kTTErrNone }; TTTestAssertion("peeking sample before index 0 produces an error", result12, testAssertionCount, errorCount); if(!result12) { TTTestLog("Expected a value of %i, but returned value was %i", kTTErrOutOfBounds, test12Err); } TTTestAssertion("peeking sample at index 0 produces no error", result13, testAssertionCount, errorCount); if(!result13) { TTTestLog("Expected a value of %i, but returned value was %i", kTTErrNone, test13Err); } // TEST 14 & 15: test whether out of bounds indices produce errors at tail TTInt32 computedIndex14 = test7Return; // should be latest size in samples TTInt32 computedIndex15 = test7Return - 1; // the tail is actually one less TTErr test14Err = this->poke(computedIndex14, 0, test12return); TTErr test15Err = this->poke(computedIndex15, 0, test13return); TTBoolean result14 = { test14Err == kTTErrOutOfBounds }; TTBoolean result15 = { test15Err == kTTErrNone }; TTTestAssertion("poking sample after index max produces an error", result14, testAssertionCount, errorCount); if(!result14) { TTTestLog("Expected a value of %i, but returned value was %i", kTTErrOutOfBounds, test14Err); } TTTestAssertion("poking sample at index max produces no error", result15, testAssertionCount, errorCount); if(!result15) { TTTestLog("Expected a value of %i, but returned value was %i", kTTErrNone, test15Err); } // TEST 16 & 17: incrementing & decrementing userCount TTUInt16 test16expect = 4; TTUInt16 test17expect = 2; this->incrementUserCount(); this->incrementUserCount(); this->incrementUserCount(); this->incrementUserCount(); TTUInt16 test16return = this->mUserCount; this->decrementUserCount(); this->decrementUserCount(); TTUInt16 test17return = this->mUserCount; TTBoolean result16 = { test16expect == test16return }; TTBoolean result17 = { test17expect == test17return }; TTTestAssertion("incrementing userCount produces expected results", result16, testAssertionCount, errorCount); if(!result16) { TTTestLog("Expected a value of %i, but returned value was %i", test16expect, test16return); } TTTestAssertion("decrementing userCount produces expected results", result17, testAssertionCount, errorCount); if(!result17) { TTTestLog("Expected a value of %i, but returned value was %i", test17expect, test17return); } // TEST 18 & 19: setting & testing bufferPoolStage TTBoolean test18expect = true; TTBoolean test19expect = false; this->setBufferPoolStage(kSM_Active); TTBoolean test18return = this->isBufferPoolStage(kSM_Active); TTBoolean test19return = this->isBufferPoolStage(kSM_BecomingIdle); TTBoolean result18 = { test18expect == test18return }; TTBoolean result19 = { test19expect == test19return }; TTTestAssertion("reports bufferPoolStage as active", result18, testAssertionCount, errorCount); if(!result18) { TTTestLog("Expected a value of %i, but returned value was %i", test18expect, test18return); } TTTestAssertion("reports bufferPoolStage as NOT becoming idle", result19, testAssertionCount, errorCount); if(!result19) { TTTestLog("Expected a value of %i, but returned value was %i", test19expect, test19return); } /* int badSampleCount = 0; TTAudioObjectBasePtr samplematrixObject = NULL; TTAudioSignalPtr input = NULL; TTAudioSignalPtr output = NULL; // TODO: test filling with sine wave // TODO: test scaling (applying gain) // TODO: test normalizing (with optional arg, and also without an optional arg) TTObjectBaseInstantiate("samplematrix", &samplematrixObject, kTTVal1); TTObjectBaseRelease(&input); TTObjectBaseRelease(&output); TTObjectBaseRelease(&samplematrixObject); */ // Wrap up the test results to pass back to whoever called this test return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }