[TTBlue-devel] [427] branches/active: New TTOperator class: performs basic mathematical operations
Status: Alpha
Brought to you by:
tap
From: <ti...@gr...> - 2008-05-18 01:02:11
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; } #msg dt { float: left; width: 6em; font-weight: bold; } #msg dt:after { content:':';} #msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; } #msg dl a { font-weight: bold} #msg dl a:link { color:#fc3; } #msg dl a:active { color:#ff0; } #msg dl a:visited { color:#cc6; } h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; } #msg ul, pre { overflow: auto; } #header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; } #patch { width: 100%; } #patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;} #patch .propset h4, #patch .binary h4 {margin:0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;} #patch .propset .diff, #patch .binary .diff {padding:10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, .info {color:#888;background:#fff;} --></style> <title>[427] branches/active: New TTOperator class: performs basic mathematical operations on audio signals.</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>427</dd> <dt>Author</dt> <dd>tim</dd> <dt>Date</dt> <dd>2008-05-18 01:02:13 +0000 (Sun, 18 May 2008)</dd> </dl> <h3>Log Message</h3> <pre>New TTOperator class: performs basic mathematical operations on audio signals.</pre> <h3>Added Paths</h3> <ul> <li><a href="#branchesactiveincludesunitsTTOperatorh">branches/active/includes/units/TTOperator.h</a></li> <li><a href="#branchesactivesourceunitsTTOperatorcpp">branches/active/source/units/TTOperator.cpp</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="branchesactiveincludesunitsTTOperatorh"></a> <div class="addfile"><h4>Added: branches/active/includes/units/TTOperator.h (0 => 427)</h4> <pre class="diff"><span> <span class="info">--- branches/active/includes/units/TTOperator.h (rev 0) +++ branches/active/includes/units/TTOperator.h 2008-05-18 01:02:13 UTC (rev 427) </span><span class="lines">@@ -0,0 +1,52 @@ </span><ins>+/* + * TTBlue Operator Object + * Copyright © 2008, Timothy Place + * + * License: This code is licensed under the terms of the GNU LGPL + * http://www.gnu.org/licenses/lgpl.html + */ + +#ifndef __TT_OPERATOR_H__ +#define __TT_OPERATOR_H__ + + +#include "TTAudioObject.h" + +/** TTOperator performs basic mathematical operations on an input signal, + or a pair of input signals */ +TTCLASS TTOperator : public TTAudioObject { +private: + TTSymbol& attrOperator; ///< The type of calculation to perform. + TTFloat64 attrOperand; ///< The right-hand value of the calculation. + + /** setter for the operator attribute. */ + TTErr setOperator(const TTAttribute&, const TTValue& newValue); + + /** setter for the operand attribute. */ + TTErr setOperand(const TTAttribute&, const TTValue& newValue); + + /** A standard audio processing method as used by TTBlue objects. + Performs the mathematical operation with a constant as defined using the + operand attribute. */ + TTErr processAddConstant(TTAudioSignal& in, TTAudioSignal& out); + TTErr processSubtractConstant(TTAudioSignal& in, TTAudioSignal& out); + TTErr processMultiplyConstant(TTAudioSignal& in, TTAudioSignal& out); + TTErr processDivideConstant(TTAudioSignal& in, TTAudioSignal& out); + + /** An audio processing method that uses a second input signal to define the operand. */ + TTErr processAddSignal(TTAudioSignal& in1, TTAudioSignal& in2, TTAudioSignal& out, TTAudioSignal&); + TTErr processSubtractSignal(TTAudioSignal& in1, TTAudioSignal& in2, TTAudioSignal& out, TTAudioSignal&); + TTErr processMultiplySignal(TTAudioSignal& in1, TTAudioSignal& in2, TTAudioSignal& out, TTAudioSignal&); + TTErr processDivideSignal(TTAudioSignal& in1, TTAudioSignal& in2, TTAudioSignal& out, TTAudioSignal&); + +public: + + /** Constructor. */ + TTOperator(TTUInt8 newMaxNumChannels); + + /** Destructor. */ + ~TTOperator(); +}; + + +#endif // __TT_OPERATOR_H__ </ins><span class="cx">Property changes on: branches/active/includes/units/TTOperator.h </span><span class="cx">___________________________________________________________________ </span><span class="cx">Name: svn:executable </span><span class="cx"> + * </span></span></pre></div> <a id="branchesactivesourceunitsTTOperatorcpp"></a> <div class="addfile"><h4>Added: branches/active/source/units/TTOperator.cpp (0 => 427)</h4> <pre class="diff"><span> <span class="info">--- branches/active/source/units/TTOperator.cpp (rev 0) +++ branches/active/source/units/TTOperator.cpp 2008-05-18 01:02:13 UTC (rev 427) </span><span class="lines">@@ -0,0 +1,280 @@ </span><ins>+/* + * TTBlue Operator Object + * Copyright © 2008, Timothy Place + * + * License: This code is licensed under the terms of the GNU LGPL + * http://www.gnu.org/licenses/lgpl.html + */ + +#include "TTOperator.h" + + +TTOperator::TTOperator(TTUInt8 newMaxNumChannels) + : TTAudioObject("audio.operator", newMaxNumChannels), attrOperator(TT("")) +{ + registerAttribute(TT("operator"), kTypeSymbol, &attrOperator, (TTSetterMethod)&TTOperator::setOperator); + registerAttribute(TT("operand"), kTypeFloat64, &attrOperand, (TTSetterMethod)&TTOperator::setOperand); + + // Set Defaults... + setAttributeValue(TT("operator"), 1.0); + setAttributeValue(TT("operand"), TT("+")); +} + + +TTOperator::~TTOperator() +{ + ; +} + + +TTErr TTOperator::setOperator(const TTAttribute&, const TTValue& newValue) +{ + attrOperator = newValue; + if(attrOperator == TT("+")){ + setProcess((TTProcessMethod)&TTOperator::processAddConstant); + setProcessWithSidechain((TTProcessWithSidechainMethod)&TTOperator::processAddSignal); + } + else if(attrOperator == TT("-")){ + setProcess((TTProcessMethod)&TTOperator::processSubtractConstant); + setProcessWithSidechain((TTProcessWithSidechainMethod)&TTOperator::processSubtractSignal); + } + else if(attrOperator == TT("*")){ + setProcess((TTProcessMethod)&TTOperator::processMultiplyConstant); + setProcessWithSidechain((TTProcessWithSidechainMethod)&TTOperator::processMultiplySignal); + } + else if(attrOperator == TT("/")){ + setProcess((TTProcessMethod)&TTOperator::processDivideConstant); + setProcessWithSidechain((TTProcessWithSidechainMethod)&TTOperator::processDivideSignal); + } + else + return kTTErrGeneric; + + return kTTErrNone; +} + + +TTErr TTOperator::setOperand(const TTAttribute&, const TTValue& newValue) +{ + attrOperand = newValue; + return kTTErrNone; +} + + + +TTErr TTOperator::processAddConstant(TTAudioSignal& in, TTAudioSignal& out) +{ + short vs; + TTSampleValue *inSample, + *outSample; + short numchannels = TTAudioSignal::getMinChannelCount(in, out); + short channel; + + for(channel=0; channel<numchannels; channel++){ + inSample = in.sampleVectors[channel]; + outSample = out.sampleVectors[channel]; + vs = in.getVectorSize(); + while(vs--) + *outSample++ = attrOperand + *inSample++; + } + return kTTErrNone; +} + + +TTErr TTOperator::processSubtractConstant(TTAudioSignal& in, TTAudioSignal& out) +{ + short vs; + TTSampleValue *inSample, + *outSample; + short numchannels = TTAudioSignal::getMinChannelCount(in, out); + short channel; + + for(channel=0; channel<numchannels; channel++){ + inSample = in.sampleVectors[channel]; + outSample = out.sampleVectors[channel]; + vs = in.getVectorSize(); + while(vs--) + *outSample++ = attrOperand - *inSample++; + } + return kTTErrNone; +} + + +TTErr TTOperator::processMultiplyConstant(TTAudioSignal& in, TTAudioSignal& out) +{ + short vs; + TTSampleValue *inSample, + *outSample; + short numchannels = TTAudioSignal::getMinChannelCount(in, out); + short channel; + + for(channel=0; channel<numchannels; channel++){ + inSample = in.sampleVectors[channel]; + outSample = out.sampleVectors[channel]; + vs = in.getVectorSize(); + while(vs--) + *outSample++ = attrOperand * *inSample++; + } + return kTTErrNone; +} + + +TTErr TTOperator::processDivideConstant(TTAudioSignal& in, TTAudioSignal& out) +{ + short vs; + TTSampleValue *inSample, + *outSample; + short numchannels = TTAudioSignal::getMinChannelCount(in, out); + short channel; + + for(channel=0; channel<numchannels; channel++){ + inSample = in.sampleVectors[channel]; + outSample = out.sampleVectors[channel]; + vs = in.getVectorSize(); + while(vs--) + *outSample++ = attrOperand / *inSample++; + } + return kTTErrNone; +} + + + + +TTErr TTOperator::processAddSignal(TTAudioSignal& in1, TTAudioSignal& in2, TTAudioSignal& out, TTAudioSignal&) +{ + short vs; + TTSampleValue *in1Sample, + *in2Sample, + *outSample; + short numChannels; + short channel; + + if(in2.getNumChannels() == 1){ // If the operand signal is one only channel, then we apply that to all channels of in1 + numChannels = in2.getNumChannels(); + for(channel=0; channel<numChannels; channel++){ + in1Sample = in1.sampleVectors[channel]; + in2Sample = in2.sampleVectors[0]; + outSample = out.sampleVectors[channel]; + vs = in1.getVectorSize(); + while(vs--) + *outSample++ = *in1Sample++ + *in2Sample++; + } + } + else{ // Otherwise we apply channel 1 to channel 1, channel 2 to channel 2, etc. + numChannels = TTAudioSignal::getMinChannelCount(in1, out); + for(channel=0; channel<numChannels; channel++){ + in1Sample = in1.sampleVectors[channel]; + in2Sample = in2.sampleVectors[channel]; + outSample = out.sampleVectors[channel]; + vs = in1.getVectorSize(); + while(vs--) + *outSample++ = *in1Sample++ + *in2Sample++; + } + } + return kTTErrNone; +} + + +TTErr TTOperator::processSubtractSignal(TTAudioSignal& in1, TTAudioSignal& in2, TTAudioSignal& out, TTAudioSignal&) +{ + short vs; + TTSampleValue *in1Sample, + *in2Sample, + *outSample; + short numChannels; + short channel; + + if(in2.getNumChannels() == 1){ // If the operand signal is one only channel, then we apply that to all channels of in1 + numChannels = in2.getNumChannels(); + for(channel=0; channel<numChannels; channel++){ + in1Sample = in1.sampleVectors[channel]; + in2Sample = in2.sampleVectors[0]; + outSample = out.sampleVectors[channel]; + vs = in1.getVectorSize(); + while(vs--) + *outSample++ = *in1Sample++ - *in2Sample++; + } + } + else{ // Otherwise we apply channel 1 to channel 1, channel 2 to channel 2, etc. + numChannels = TTAudioSignal::getMinChannelCount(in1, out); + for(channel=0; channel<numChannels; channel++){ + in1Sample = in1.sampleVectors[channel]; + in2Sample = in2.sampleVectors[channel]; + outSample = out.sampleVectors[channel]; + vs = in1.getVectorSize(); + while(vs--) + *outSample++ = *in1Sample++ - *in2Sample++; + } + } + return kTTErrNone; +} + + +TTErr TTOperator::processMultiplySignal(TTAudioSignal& in1, TTAudioSignal& in2, TTAudioSignal& out, TTAudioSignal&) +{ + short vs; + TTSampleValue *in1Sample, + *in2Sample, + *outSample; + short numChannels; + short channel; + + if(in2.getNumChannels() == 1){ // If the operand signal is one only channel, then we apply that to all channels of in1 + numChannels = in2.getNumChannels(); + for(channel=0; channel<numChannels; channel++){ + in1Sample = in1.sampleVectors[channel]; + in2Sample = in2.sampleVectors[0]; + outSample = out.sampleVectors[channel]; + vs = in1.getVectorSize(); + while(vs--) + *outSample++ = *in1Sample++ * *in2Sample++; + } + } + else{ // Otherwise we apply channel 1 to channel 1, channel 2 to channel 2, etc. + numChannels = TTAudioSignal::getMinChannelCount(in1, out); + for(channel=0; channel<numChannels; channel++){ + in1Sample = in1.sampleVectors[channel]; + in2Sample = in2.sampleVectors[channel]; + outSample = out.sampleVectors[channel]; + vs = in1.getVectorSize(); + while(vs--) + *outSample++ = *in1Sample++ * *in2Sample++; + } + } + return kTTErrNone; +} + + +TTErr TTOperator::processDivideSignal(TTAudioSignal& in1, TTAudioSignal& in2, TTAudioSignal& out, TTAudioSignal&) +{ + short vs; + TTSampleValue *in1Sample, + *in2Sample, + *outSample; + short numChannels; + short channel; + + if(in2.getNumChannels() == 1){ // If the operand signal is one only channel, then we apply that to all channels of in1 + numChannels = in2.getNumChannels(); + for(channel=0; channel<numChannels; channel++){ + in1Sample = in1.sampleVectors[channel]; + in2Sample = in2.sampleVectors[0]; + outSample = out.sampleVectors[channel]; + vs = in1.getVectorSize(); + while(vs--) + *outSample++ = *in1Sample++ / *in2Sample++; + } + } + else{ // Otherwise we apply channel 1 to channel 1, channel 2 to channel 2, etc. + numChannels = TTAudioSignal::getMinChannelCount(in1, out); + for(channel=0; channel<numChannels; channel++){ + in1Sample = in1.sampleVectors[channel]; + in2Sample = in2.sampleVectors[channel]; + outSample = out.sampleVectors[channel]; + vs = in1.getVectorSize(); + while(vs--) + *outSample++ = *in1Sample++ / *in2Sample++; + } + } + return kTTErrNone; +} + </ins><span class="cx">Property changes on: branches/active/source/units/TTOperator.cpp </span><span class="cx">___________________________________________________________________ </span><span class="cx">Name: svn:executable </span><span class="cx"> + * </span></span></pre> </div> </div> </body> </html> |