Closed redned closed 12 years ago
Hey there!
A quick look reveals a few problems:
if(pressed.slice(0,1) == noteOffName){
this will never be true, slice creates a new array, which is a unique object. What you want is if(pressed[0] === noteOffName){
. Also probably a good idea to use triple equals.
volENV = new audioLib.ADSREnvelope(sampleRate, 200, 50, 1, 500, 250, 0);
discard the last two arguments and it should work. If you specify the those two, triggerGate will not react, because the ADSREnvelope assumes that you want a static envelope (i.e. the ADSREnvelope starts to oscillate), since you specified a static time for sustain and release.
volENV.triggerGate(false);
if you turn the oscillator immediately after the key is lifted, you never get to the release part. To get that as well, you need some kind of decay management. Otherwise this is ok, just combined with the way you're dealing with the oscillators makes it malfunction a bit.
osc1 = new audioLib.Oscillator(sampleRate, null);
and osc1 = new audioLib.generators.Note(sampleRate, noteOnName);
it's probably a better idea to keep the same oscillator instance all the time, since you only have one oscillator anyway. Just set the frequency to match the note whenever the key changes, and when the key is lifted, set the frequency to zero. Or even better, if you're making a mono synth, you can make the choice of never setting the frequency to zero, instead just release the gate for the envelope, and the sound will fade out.
Hope this helps!
Cheers, Jussi
That sorted it. Thanks a lot!
Hi. I'm having some problems getting the adsr envelope to work. The attack portion is working but only on the first key press. Any subsequent key press the envelope does not work.
Could you shed any light on where I am going wrong please. Cheers.