2015-10-05 62 views

回答

5

要停止點擊,您需要平穩地上升振盪器,而不是立即啓動它。類似如下:

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);