1
我正在構建一個簡單的合成器與WebMIDI控制。增益節點對振盪器沒有影響,整個時間都處於滿量程。另外當我彈奏和絃時,頻率是正確的,但是存在顫動和尖銳的效果。使用我的MIDI控制器時以及使用控制檯啓動和停止合成器時存在這些問題。多個振盪器尖叫,增益沒有影響WebAudio
這是我的合成器的代碼:
var synth = {
voices: {},
start: function (note, vol) {
this.voices[note] = {
gain: audio.createGain(),
osc: audio.createOscillator()
}
this.voices[note].gain.connect(audio.destination);
this.voices[note].osc.frequency.value = noteToFreq(note);
this.voices[note].osc.connect(this.voices[note].gain);
this.voices[note].osc.start(0);
this.voices[note].gain.gain.setTargetAtTime(vol, audio.currentTime, 0.5);
},
stop: function (note) {
this.voices[note].gain.gain.setTargetAtTime(0, audio.currentTime, 2);
this.voices[note].osc.stop(audio.currentTime + 2);
}
}