void MyTrig::next(int inNumSamples)
{
Samp *out = ZOUT(0);
//create a pointer to the output
Samp *trig = ZIN(0);
//create a pointer to the first (trigger)
input
Samp dur = ZIN0(1);//create a pointer to the second (dur) input
Samp sr = SampleRate();
Samp prevtrig = m_prevtrig; //create variable to store last value
Samp level = mLevel;
unsigned long counter = mCounter;
LOOP(inNumSamples, //do this for the given number of samples
Samp curtrig = ZXP(trig); //get
the current input value from the input buffer
Samp zout;
if (counter > 0) { //as
long as counter is larger than zero,
zout = --counter ? level : 0.f; //count
down one and assign the value of level to zout
//if level
is nil, use zero (float) instead
} else {
if (curtrig > 0.f && prevtrig <= 0.f) { //if there is a crossing into positive
counter = (long)(dur * sr + .5f); //set
the counter to the specified counts
if (counter < 1) counter = 1; //make
sure nothing goes wrong
level = curtrig; //the
output level will be as high as the
//trigger
at this point
zout = level;//assign that level to the output
} else {
zout = 0.f;//no trigger, zero output
}
}
prevtrig = curtrig; //remember the last
input value
ZXP(out) = zout; //write the value of zout to the output buffer
);
m_prevtrig = prevtrig;
mCounter = counter;
mLevel = level;
}
This page was created by SimpleText2Html 1.0.3 on 14-Aug-101.