Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does a web audio oscillator only play a note once?

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))
like image 964
aaaidan Avatar asked Oct 27 '12 00:10

aaaidan


1 Answers

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.

like image 100
Oskar Eriksson Avatar answered Sep 27 '22 23:09

Oskar Eriksson