I am trying to understand Web Audio API timing and scheduling methods.
But i still have not understood the Oscillator Node's stop()
method completely.
Here i'm trying to schedule to play 4 oscillator with tempo of 120 BPM.
But it seems like as soon as the stop()
method kicks in on the release time, it stops all the oscillators.
Here is the code:
var context = new webkitAudioContext();
var now = context.currentTime;
var tempo = 120;
var releaseTime = 0.5;
var secondsPerBeat = 60.0 / tempo;
for(var i = 0; i < 4; i++){
var now = context.currentTime;
var osc = context.createOscillator();
osc.connect(context.destination);
osc.start(now + (i*secondsPerBeat));
var now = context.currentTime;
osc.stop(now + releaseTime);
}
Why is that happening and how i can prevent this?
Thanks