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 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 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); }