[Stk] How to properly use STK::ADSR
Nuno Santos
nunosantos at imaginando.net
Tue Apr 7 05:51:18 PDT 2009
Hi,
I'm trying to use Stk::ADSR to control the output of a sinewave in a
VST but only the release seems to work right.
What am I missing? My code is like this:
void VstXSynth::initProcess ()
{
sine = new SineWave();
adsr = new ADSR();
}
void VstXSynth::noteOn (VstInt32 note, VstInt32 velocity, VstInt32
delta)
{
currentNote = note;
currentVelocity = velocity;
currentDelta = delta;
noteIsOn = true;
adsr->keyOn();
adsr->setValue(1.0);
}
void VstXSynth::noteOff ()
{
noteIsOn = false;
adsr->keyOff();
}
void VstXSynth::processReplacing (float** inputs, float** outputs,
VstInt32 sampleFrames)
{
float* out1 = outputs[0];
float* out2 = outputs[1];
float computedSample;
float adsrValue;
float outputValue;
float baseFreq = freqtab[currentNote & 0x7f] * fScaler;
float vol = (float)(fVolume * (double)currentVelocity * midiScaler);
sine->setFrequency( baseFreq * 10);
for ( int i=0; i<sampleFrames; i++ )
{
computedSample = float(sine->tick());
adsrValue = float(adsr->tick());
outputValue = computedSample * adsrValue;
(*out1++) = outputValue;
(*out2++) = outputValue;
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ccrma-mail.stanford.edu/pipermail/stk/attachments/20090407/8294959b/attachment-0001.html
More information about the Stk
mailing list