我已经用振荡器创建了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;

最佳答案

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

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

07-28 10:56