如何控制输出增益?

时间:2016-09-21 15:14:00

标签: javascript web-audio

我创建了一个带振荡器的音频上下文但我无法控制输出的增益,即使使用gainNode.gain.value

var AudioContext = window.AudioContext || window.webkitAudioContext;  
var audioctx = new AudioContext();
var gainNode = audioctx.createGain();

var oscillator = audioctx.createOscillator(); 
var oscillator2 = audioctx.createOscillator();

oscillator.connect(audioctx.destination);
oscillator.start(0);
gainNode.connect(audioctx.destination);
gainNode.gain.value = 0;

1 个答案:

答案 0 :(得分:1)

您需要将振荡器连接到增益节点,而不是目标:

oscillator.connect(gainNode);
oscillator.start(0);
gainNode.connect(audioctx.destination);
gainNode.gain.value = 0;