[TTBlue-devel] [429] branches/active: Initial TTPulseSub class (ported from version 0.3).
Status: Alpha
Brought to you by:
tap
From: <ti...@gr...> - 2008-05-18 01:05:05
|
<!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>[429] branches/active: Initial TTPulseSub class (ported from version 0.3).</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>429</dd> <dt>Author</dt> <dd>tim</dd> <dt>Date</dt> <dd>2008-05-18 01:05:07 +0000 (Sun, 18 May 2008)</dd> </dl> <h3>Log Message</h3> <pre>Initial TTPulseSub class (ported from version 0.3). It's doubtful that this works yet, as it is untested. Particularly w/r/t multichannel operation. But it should be close.</pre> <h3>Added Paths</h3> <ul> <li><a href="#branchesactiveincludesunitsTTPulseSubh">branches/active/includes/units/TTPulseSub.h</a></li> <li><a href="#branchesactivesourceunitsTTPulseSubcpp">branches/active/source/units/TTPulseSub.cpp</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="branchesactiveincludesunitsTTPulseSubh"></a> <div class="addfile"><h4>Added: branches/active/includes/units/TTPulseSub.h (0 => 429)</h4> <pre class="diff"><span> <span class="info">--- branches/active/includes/units/TTPulseSub.h (rev 0) +++ branches/active/includes/units/TTPulseSub.h 2008-05-18 01:05:07 UTC (rev 429) </span><span class="lines">@@ -0,0 +1,58 @@ </span><ins>+/* + * TTBlue Pulse-based Envelope Substitution + * Copyright © 2004, Timothy Place + * + * License: This code is licensed under the terms of the GNU LGPL + * http://www.gnu.org/licenses/lgpl.html + */ + +#ifndef __TT_PULSESUB_H__ +#define __TT_PULSESUB_H__ + +#include "TTAudioObject.h" +#include "TTPhasor.h" +#include "TTAdsr.h" +#include "TTOperator.h" + + +/** TTPulseSub generates a repeating ADSR envelope which is then applied to the gain of an input signal. + */ +TTCLASS TTPulseSub : public TTAudioObject { +private: + TTFloat64 attrAttack; + TTFloat64 attrDecay; + TTFloat64 attrSustain; + TTFloat64 attrRelease; + TTBoolean attrTrigger; + TTSymbol& attrMode; + + TTOperator* offset; + TTPhasor* phasor; + TTAdsr* env_gen; + TTOperator* scaler; + TTAudioSignal* sig1; + TTAudioSignal* sig2; + + + TTErr updateSr(); + + TTErr setTrigger(const TTAttribute&, const TTValue& newValue); + TTErr setAttack(const TTAttribute&, const TTValue& newValue); + TTErr setDecay(const TTAttribute&, const TTValue& newValue); + TTErr setSustain(const TTAttribute&, const TTValue& newValue); + TTErr setRelease(const TTAttribute&, const TTValue& newValue); + TTErr setMode(const TTAttribute&, const TTValue& newValue); + + TTErr processAudio(TTAudioSignal& in, TTAudioSignal& out); + + + +public: + TTPulseSub(TTUInt8 newMaxNumChannels); + ~TTPulseSub(); + + +}; + +#endif // __TT_PULSESUB_H__ + </ins></span></pre></div> <a id="branchesactivesourceunitsTTPulseSubcpp"></a> <div class="addfile"><h4>Added: branches/active/source/units/TTPulseSub.cpp (0 => 429)</h4> <pre class="diff"><span> <span class="info">--- branches/active/source/units/TTPulseSub.cpp (rev 0) +++ branches/active/source/units/TTPulseSub.cpp 2008-05-18 01:05:07 UTC (rev 429) </span><span class="lines">@@ -0,0 +1,120 @@ </span><ins>+/* + * TTBlue Pulse-based Envelope Substitution + * Copyright © 2004, Timothy Place + * + * License: This code is licensed under the terms of the GNU LGPL + * http://www.gnu.org/licenses/lgpl.html + */ + +#include "TTPulseSub.h" + +TTPulseSub::TTPulseSub(TTUInt8 newMaxNumChannels) + : TTAudioObject("audio.pulsesub", newMaxNumChannels), attrMode(TT("linear")) +{ + registerAttribute(TT("attack"), kTypeFloat64, &attrAttack, (TTSetterMethod)&TTPulseSub::setAttack); + registerAttribute(TT("decay"), kTypeFloat64, &attrDecay, (TTSetterMethod)&TTPulseSub::setDecay); + registerAttribute(TT("release"), kTypeFloat64, &attrRelease, (TTSetterMethod)&TTPulseSub::setRelease); + registerAttribute(TT("sustain"), kTypeFloat64, &attrSustain, (TTSetterMethod)&TTPulseSub::setSustain); + registerAttribute(TT("trigger"), kTypeBoolean, &attrTrigger, (TTSetterMethod)&TTPulseSub::setTrigger); + registerAttribute(TT("mode"), kTypeSymbol, &attrMode, (TTSetterMethod)&TTPulseSub::setTrigger); + + // registerMessage -- numChans + // registerMessage -- sr + + env_gen = new TTAdsr(newMaxNumChannels); + phasor = new TTPhasor(newMaxNumChannels); + offset = new TTOperator(newMaxNumChannels); + offset->setAttributeValue(TT("operator"), TT("+")); + scaler = new TTOperator(newMaxNumChannels); + scaler->setAttributeValue(TT("operator"), TT("*")); + sig1 = new TTAudioSignal(1); + sig2 = new TTAudioSignal(1); + + setAttributeValue(TT("attack"), 50.); + setAttributeValue(TT("decay"), 100.); + setAttributeValue(TT("sustain_db"), -6.); + setAttributeValue(TT("release"), 500.); + setAttributeValue(TT("mode"), TT("linear")); // <-- sets the process method +} + +TTPulseSub::~TTPulseSub() +{ + delete offset; + delete phasor; + delete env_gen; + delete scaler; +} + + +TTErr TTPulseSub::updateSr() +{ + phasor->setAttributeValue(TT("sr"), sr); + offset->setAttributeValue(TT("sr"), sr); + env_gen->setAttributeValue(TT("sr"), sr); + scaler->setAttributeValue(TT("sr"), sr); + return kTTErrNone; +} + + +// TODO: what about the vectorsize issues? + + +TTErr TTPulseSub::setAttack(const TTAttribute&, const TTValue& newValue) +{ + attrAttack = newValue; + return env_gen->setAttributeValue(TT("attack"), newValue); +} + +TTErr TTPulseSub::setDecay(const TTAttribute&, const TTValue& newValue) +{ + attrDecay = newValue; + return env_gen->setAttributeValue(TT("decay"), attrTrigger); +} + + +TTErr TTPulseSub::setSustain(const TTAttribute&, const TTValue& newValue) +{ + attrSustain = newValue; + return env_gen->setAttributeValue(TT("sustain"), newValue); +} + +TTErr TTPulseSub::setRelease(const TTAttribute&, const TTValue& newValue) +{ + attrRelease = newValue; + return env_gen->setAttributeValue(TT("release"), newValue); +} + + +TTErr TTPulseSub::setMode(const TTAttribute&, const TTValue& newValue) +{ + attrMode = newValue; + return env_gen->setAttributeValue(TT("mode"), newValue); +} + +TTErr TTPulseSub::setTrigger(const TTAttribute&, const TTValue& newValue) +{ + attrTrigger = newValue; + return env_gen->setAttributeValue(TT("trigger"), newValue); +} + + +// TODO: make multichannel +TTErr TTPulseSub::processAudio(TTAudioSignal& in, TTAudioSignal& out) +{ + TTSampleValue* inSample; + TTSampleValue* outSample; + TTUInt16 vs = in.getVectorSize(); + + inSample = in.sampleVectors[0]; + outSample = out.sampleVectors[0]; + + sig1->setVectorSize(vs); + sig2->setVectorSize(vs); + + phasor->process(*sig1); // ramp wave, stored in a temporary vector + offset->process(*sig1, *sig2); // offset the ramp wave, effectively altering the duty cycle + env_gen->process(*sig2, *sig1); // generate the envelope, reusing the temp[0] vector + scaler->process(in, *sig1, out); // apply the envelope to the input vector + + return kTTErrNone; +} </ins></span></pre> </div> </div> </body> </html> |