コード例 #1
0
ファイル: TTDataTypedMethods.cpp プロジェクト: EQ4/JamomaCore
TTBoolean TTData::clipValue()
{
	//bool	didClipAll = false;
	
	// the code regarding didClipAll is supposed to return true when every member of the list has been clipped to its limit
	// that way ramping can be terminated prematurely if it was trying to ramp to something out of range
	// however, this code as it is doesn't work, and it doesn't buy us much anyway
	// so I'm just commenting it out for the time being [TAP]
	
	if (mRangeClipmode != kTTSym_none) {
		
		if (mRangeClipmode == kTTSym_low)
			mValue.cliplow(TTFloat64(mRangeBounds[0]));
		else if (mRangeClipmode == kTTSym_high)
			mValue.cliphigh(TTFloat64(mRangeBounds[1]));
		else if (mRangeClipmode == kTTSym_both)
			mValue.clip(TTFloat64(mRangeBounds[0]), TTFloat64(mRangeBounds[1]));
		else if (mRangeClipmode == kTTSym_wrap)
			mValue.wrap(TTFloat64(mRangeBounds[0]), TTFloat64(mRangeBounds[1]));
		//else if (mRangeClipmode == kTTSym_wrap)
            //mValue.clipwrap(TTFloat64(mRangeBounds[0]), TTFloat64(mRangeBounds[1]));
		else if (mRangeClipmode == kTTSym_fold)
			mValue.fold(TTFloat64(mRangeBounds[0]), TTFloat64(mRangeBounds[1]));
	}
	
	return false;
}
コード例 #2
0
ファイル: TTSampleMatrix.cpp プロジェクト: RWelsh/JamomaDSP
TTErr TTSampleMatrix::normalize(const TTValue& aValue)
{
	TTFloat64			normalizeTo = 1.0;
	TTRowID				m = mLengthInSamples; // mFrameLength
	TTColumnID			n = mNumChannels; // mNumChannels
	TTSampleValuePtr	samples = (TTSampleValuePtr)getLockedPointer();
	TTFloat64			peakValue = 0.0;
	TTFloat64			scalar;
	
	if (aValue.getSize() && TTFloat64(aValue) > 0.0)
		normalizeTo = aValue;
	
	for (int k=0; k<m*n; k++) {
		TTFloat64 magnitude = abs(samples[k]);
		
		if (magnitude > peakValue)
			peakValue = magnitude;
	}
	
	scalar = normalizeTo / peakValue;
	
	for (int k=0; k<m*n; k++)
		samples[k] *= scalar;
		
	releaseLockedPointer();
	return kTTErrNone;
}
コード例 #3
0
TTErr TTLowpassTwoPole::setResonance(const TTValue& newValue)
{
	mResonance = TTClip(TTFloat64(newValue), 0.001, 100.0);
	mNegOneOverResonance = -1.0/mResonance;
	calculateCoefficients();
	
	return kTTErrNone;
}
コード例 #4
0
ファイル: TTExpression.cpp プロジェクト: EQ4/JamomaCore
void TTExpression::parse(TTValue& toParse)
{
    // parse address
    if (toParse.size() > 0) {
        
        if (toParse[0].type() == kTypeSymbol) {
            
            mAddress = toParse[0];
            
            // parse operator
            if (toParse.size() > 1) {
                
                if (toParse[1].type() == kTypeSymbol) {
                    
                    mOperator = toParse[1];
                    
                    // we need to use word instead of sign because < and > symbol make trouble for XmlFormat parsing
                    if (mOperator == TTSymbol("=="))
                        mOperator = TTSymbol("equal");
                    
                    else if (mOperator == TTSymbol("!="))
                        mOperator = TTSymbol("different");
                    
                    else if (mOperator == TTSymbol(">"))
                        mOperator = TTSymbol("greaterThan");
                    
                    else if (mOperator == TTSymbol(">="))
                        mOperator = TTSymbol("greaterThanOrEqual");
                    
                    else if (mOperator == TTSymbol("<"))
                        mOperator = TTSymbol("lowerThan");
                    
                    else if (mOperator == TTSymbol("<="))
                        mOperator = TTSymbol("lowerThanOrEqual");
                    
                    // parse value
                    if (toParse.size() > 2) {
                        
                        mValue.copyFrom(toParse, 2);
                        
                        // convert to TTFloat64 for comparison purpose (see in evaluate method)
                        if (mValue.size())
                        {
                            if (mValue[0].type() != kTypeSymbol)
                            {
                                for (TTElementIter it = mValue.begin(); it != mValue.end(); it++)
                                    *it = TTFloat64(TTElement(*it));
                            }
                        }
                    }
                }
            }
        }
    }
}
コード例 #5
0
ファイル: TTExpression.cpp プロジェクト: EQ4/JamomaCore
TTBoolean TTExpression::evaluate(const TTValue& value)
{
    TTValue toCompare = value;
    
    // convert to TTFloat64 to have the same type than mValue (see in parse method)
    if (toCompare.size())
    {
        if (toCompare[0].type() != kTypeSymbol)
        {
            for (TTElementIter it = toCompare.begin(); it != toCompare.end(); it++)
                *it = TTFloat64(TTElement(*it));
        }
    }
    
    if (mOperator == kTTSymEmpty)
        return YES;
    
    if (mOperator == TTSymbol("equal"))
        return toCompare == mValue;
    
    if (mOperator == TTSymbol("different"))
        return toCompare != mValue;
    
    if (mOperator == TTSymbol("greaterThan"))
        return toCompare > mValue;
    
    if (mOperator == TTSymbol("greaterThanOrEqual"))
        return toCompare >= mValue;
    
    if (mOperator == TTSymbol("lowerThan"))
        return toCompare < mValue;
    
    if (mOperator == TTSymbol("lowerThanOrEqual"))
        return toCompare <= mValue;
    
    return NO;
}
コード例 #6
0
void CelsiusUnit::convertToNeutral(const TTValue& input, TTValue& output)
{
//	output.setSize(1);
//	*output = atom_getfloat(inputAtoms) + 273.15;
	output = TTFloat64(input) + 273.15;
}
コード例 #7
0
ファイル: TTSampleMatrix.cpp プロジェクト: RWelsh/JamomaDSP
TTErr TTSampleMatrix::setLength(const TTValue& newLength)
{
	TTValue v(TTFloat64(newLength) * mSampleRate * 0.001, mNumChannels);
	
	return setDimensions(v);
}
コード例 #8
0
void CelsiusUnit::convertFromNeutral(const TTValue& input, TTValue& output)
{
//	output.setSize(1);
//	atom_setfloat(*outputAtoms, *input - 273.15);
	output = TTFloat64(input) - 273.15;
}
コード例 #9
0
ファイル: TTSampleMatrix.cpp プロジェクト: RWelsh/JamomaDSP
TTErr TTSampleMatrix::fill(const TTValue& value, TTValue& unusedOutput)
{
	TTSymbol	fillAlgorithm = value;

	if (fillAlgorithm == kTTSym_sine) {
		for (TTUInt16 channel=0; channel<mNumChannels; channel++) {
			for (TTUInt64 i=0; i<mLengthInSamples; i++)
				set2d(i+1, channel+1, sin(kTTTwoPi * (i / (TTFloat64(mLengthInSamples) - 1.0))));
		}
	}
	else if (fillAlgorithm == kTTSym_sineMod) {							// (modulator version: ranges from 0.0 to 1.0, rather than -1.0 to 1.0)
		for (TTUInt16 channel=0; channel<mNumChannels; channel++) {
			for (TTUInt64 i=0; i<mLengthInSamples; i++)
				set2d(i+1, channel+1, 0.5 + (0.5 * sin(kTTTwoPi * (i / (TTFloat64(mLengthInSamples) - 1.0)))));
		}
	}
	else if (fillAlgorithm == kTTSym_cosine) {
		for (TTUInt16 channel=0; channel<mNumChannels; channel++) {
			for (TTUInt64 i=0; i<mLengthInSamples; i++)
				set2d(i+1, channel+1, cos(kTTTwoPi * (i / (TTFloat64(mLengthInSamples) - 1.0))));
		}
	}
	else if (fillAlgorithm == kTTSym_cosineMod) {
		for (TTUInt16 channel=0; channel<mNumChannels; channel++) {
			for (TTUInt64 i=0; i<mLengthInSamples; i++)
				set2d(i+1, channel+1, 0.5 + (0.5 * cos(kTTTwoPi * (i / (TTFloat64(mLengthInSamples) - 1.0)))));
		}
	}
	else if (fillAlgorithm == kTTSym_ramp) {
		for (TTUInt16 channel=0; channel<mNumChannels; channel++) {
			for (TTUInt64 i=0; i<mLengthInSamples; i++)
				set2d(i+1, channel+1, -1.0 + (2.0 * (float(i) / mLengthInSamples)));
		}
	}
	else if (fillAlgorithm == kTTSym_rampMod) {
		for (TTUInt16 channel=0; channel<mNumChannels; channel++) {
			for (TTUInt64 i=0; i<mLengthInSamples; i++)
				set2d(i+1, channel+1, float(i) / mLengthInSamples);
		}
	}
	else if (fillAlgorithm == kTTSym_sawtooth) {
		for (TTUInt16 channel=0; channel<mNumChannels; channel++) {
			for (TTUInt64 i=0; i<mLengthInSamples; i++)
				set2d(mLengthInSamples-i, channel+1, -1.0 + (2.0 * (float(i) / mLengthInSamples)));
		}
	}
	else if (fillAlgorithm == kTTSym_sawtoothMod) {
		for (TTUInt16 channel=0; channel<mNumChannels; channel++) {
			for (TTUInt64 i=0; i<mLengthInSamples; i++)
				set2d(mLengthInSamples-i, channel+1, float(i) / mLengthInSamples);
		}
	}
	else if (fillAlgorithm == kTTSym_triangle) {
		for (TTUInt16 channel=0; channel<mNumChannels; channel++) {
			for (TTUInt32 i=0; i < mLengthInSamples/2; i++) {
				set2d(i+1, channel+1, -1.0 + (4.0 * (float(i) / mLengthInSamples)));
				set2d(mLengthInSamples-i, channel+1, -1.0 + (4.0 * (float(i) / mLengthInSamples)));
			}
		}
	}
	else if (fillAlgorithm == kTTSym_triangleMod) {
		for (TTUInt16 channel=0; channel<mNumChannels; channel++) {
			for (TTUInt32 i=0; i < mLengthInSamples/2; i++) {
				set2d(i+1, channel+1, -1.0 + (4.0 * (float(i) / mLengthInSamples)));
				set2d(mLengthInSamples-i, channel+1, -1.0 + (4.0 * (float(i) / mLengthInSamples)));
			}
		}
	}

	return kTTErrNone;
}
コード例 #10
0
TTErr TTSampleMatrix::setLengthInSeconds(const TTValue& newLength)
{
	TTValue newLengthInSamples = TTFloat64(newLength) * mSampleRate;
	return setRowCount(newLengthInSamples);
}
コード例 #11
0
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);
}
コード例 #12
0
void FahrenheitUnit::convertToNeutral(const TTValue& input, TTValue& output)
{
//	output.setSize(1);
//	*output = (atom_getfloat(inputAtoms) + 459.67) / 1.8;
	output = (TTFloat64(input) + 459.67) / 1.8;
}
コード例 #13
0
void DegreeUnit::convertToNeutral(const TTValue& input, TTValue& output)
{
	output = TTFloat64(input) * kDegreesToRadians;
}
コード例 #14
0
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);
}
コード例 #15
0
void InchUnit::convertToNeutral(const TTValue& input, TTValue& output)
{
//	output.setSize(1);
//	*output = atom_getfloat(inputAtoms) / 39.37;
	output = TTFloat64(input) / 39.37;
}
コード例 #16
0
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);
}
コード例 #17
0
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);
}
コード例 #18
0
void DegreeUnit::convertFromNeutral(const TTValue& input, TTValue& output)
{
	output = TTFloat64(input) * kRadiansToDegrees;
}
コード例 #19
0
void CentimeterUnit::convertToNeutral(const TTValue& input, TTValue& output)
{
//	output.setSize(1);
//	*output = atom_getfloat(inputAtoms) * 0.01;
	output = TTFloat64(input) * 0.01;
}
コード例 #20
0
TTErr TTSampleMatrix::fill(const TTValue& value, TTValue& unusedOutput)
{
	TTSymbol		fillAlgorithm = value;
	TTSampleValue	tempSample = 0.;
	TTRowID		tempIndex = 0;

	if (fillAlgorithm == kTTSym_sine) {
		for (TTColumnID channel=0; channel<mNumChannels; channel++) {
			for (TTRowID i=0; i<mLengthInSamples; i++)
				set2d(i, channel, sin(kTTTwoPi * (i / (TTFloat64(mLengthInSamples) - 1.0))));
		}
	}
	else if (fillAlgorithm == kTTSym_sineMod) {							// (modulator version: ranges from 0.0 to 1.0, rather than -1.0 to 1.0)
		for (TTColumnID channel=0; channel<mNumChannels; channel++) {
			for (TTRowID i=0; i<mLengthInSamples; i++)
				set2d(i, channel, 0.5 + (0.5 * sin(kTTTwoPi * (i / (TTFloat64(mLengthInSamples) - 1.0)))));
		}
	}
	else if (fillAlgorithm == kTTSym_cosine) {
		for (TTColumnID channel=0; channel<mNumChannels; channel++) {
			for (TTRowID i=0; i<mLengthInSamples; i++)
				set2d(i, channel, cos(kTTTwoPi * (i / (TTFloat64(mLengthInSamples) - 1.0))));
		}
	}
	else if (fillAlgorithm == kTTSym_cosineMod) {
		for (TTColumnID channel=0; channel<mNumChannels; channel++) {
			for (TTRowID i=0; i<mLengthInSamples; i++)
				set2d(i, channel, 0.5 + (0.5 * cos(kTTTwoPi * (i / (TTFloat64(mLengthInSamples) - 1.0)))));
		}
	}
	else if (fillAlgorithm == kTTSym_ramp) {
		for (TTColumnID channel=0; channel<mNumChannels; channel++) {
			for (TTRowID i=0; i<mLengthInSamples; i++)
				set2d(i, channel, -1.0 + (2.0 * (float(i) / mLengthInSamples)));
		}
	}
	else if (fillAlgorithm == kTTSym_rampMod) {
		for (TTColumnID channel=0; channel<mNumChannels; channel++) {
			for (TTRowID i=0; i<mLengthInSamples; i++)
				set2d(i, channel, float(i) / mLengthInSamples);
		}
	}
	else if (fillAlgorithm == kTTSym_sawtooth) {
		for (TTColumnID channel=0; channel<mNumChannels; channel++) {
			for (TTRowID i=0; i<mLengthInSamples; i++)
				set2d(mLengthInSamples-i, channel, -1.0 + (2.0 * (float(i) / mLengthInSamples)));
		}
	}
	else if (fillAlgorithm == kTTSym_sawtoothMod) {
		for (TTColumnID channel=0; channel<mNumChannels; channel++) {
			for (TTRowID i=0; i<mLengthInSamples; i++)
				set2d(mLengthInSamples-i, channel, float(i) / mLengthInSamples);
		}
	}
	else if (fillAlgorithm == kTTSym_triangle) {
		for (TTColumnID channel=0; channel<mNumChannels; channel++) {
			tempIndex = 3*mLengthInSamples/4;
			for (TTRowID i=0; i < mLengthInSamples/4; i++) {
				tempSample = -1.0 + (4.0 * (float(i) / mLengthInSamples));
				set2d(i+tempIndex, channel, tempSample);
				set2d(tempIndex-i, channel, tempSample);
			}
			tempIndex = mLengthInSamples/2;
			for (TTRowID i=0; i < mLengthInSamples/4; i++) {
				tempSample = 4.0 * (float(i) / mLengthInSamples);
				set2d(i, channel, tempSample);
				set2d(tempIndex-i, channel, tempSample);
			}
		}
	}
	else if (fillAlgorithm == kTTSym_triangleMod) {
		for (TTColumnID channel=0; channel<mNumChannels; channel++) {
			for (TTRowID i=0; i < mLengthInSamples/2; i++) {
				set2d(i, channel, -1.0 + (4.0 * (float(i) / mLengthInSamples)));
				set2d(mLengthInSamples-i, channel, -1.0 + (4.0 * (float(i) / mLengthInSamples)));
			}
		}
	}

	return kTTErrNone;
}
コード例 #21
0
void CentimeterUnit::convertFromNeutral(const TTValue& input, TTValue& output)
{
//	output.setSize(1);
//	atom_setfloat(*outputAtoms, *input * 100.0);
	output = TTFloat64(input) * 100.0;
}
コード例 #22
0
void FahrenheitUnit::convertFromNeutral(const TTValue& input, TTValue& output)
{
//	output.setSize(1);
//	atom_setfloat(*outputAtoms, (*input * 1.8) - 459.67);
	output = TTFloat64(input) * 1.8 - 459.67;
}
コード例 #23
0
void InchUnit::convertFromNeutral(const TTValue& input, TTValue& output)
{
//	output.setSize(1);
//	atom_setfloat(*outputAtoms, (*input * 39.37));
	output = TTFloat64(input) * 39.37;
}
コード例 #24
0
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);
}