When I successfully create a tone with a Web Audio oscillator (with noteOn
), then call its noteOff
function, subsequent calls to noteOn
doesn't play the tone again. I seem to have to create a new oscillator to play a new note. Why is this?
var ctx = new webkitAudioContext();
var osc = ctx.createOscillator();
osc.connect(ctx.destination);
osc.start(0); // tone is heard (previously noteOn(0))
// ... some time later
osc.stop(0); // tone falls silent (previously noteOff(0))
// ... some time later
osc.start(0); // no effect! (previously noteOn(0))
Simply put - the API is designed that way, and optimised for that kind of use. One doesn't have much choice except creating a new oscillator per note.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With