Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebAudio oscillator "click"

Whenever I try a simple oscillator (check this example. It is not mine, but it shows the same problem) I hear a "click" when it starts and when it ends.

How can I bypass this issue?

like image 870
pistacchio Avatar asked Oct 05 '15 12:10

pistacchio


1 Answers

To stop the click, you need to ramp the oscillator up smoothly instead of instantaneously starting it. Something like the following:

var osc = context.createOscillator();
var gain = context.createGain();
osc.connect(gain);
gain.gain.setValueAtTime(0, context.currentTime);
gain.gain.linearRampToValueAtTime(1, context.currentTime + <some small time>);

osc.start();
...
// To stop the oscillator, ramp the gain down.
gain.gain.linearRampToValueAtTime(0, endTime - <small time>);
osc.stop(endTime);
like image 149
Raymond Toy Avatar answered Nov 05 '22 11:11

Raymond Toy