我正在使用WebAudioAPI
and创建复音合成器WebMIDIAPI
。我的两个振荡器中的每一个都有一个增益节点,然后将其连接到主增益节点。
我想知道如何在发布后正确停止(并在必要时删除?)振荡器。我不确定是否有必要从阵列中调用oscillator.stop()
和振荡器。delete
如果我这样做,释放信封不起作用并且音符立即停止,如果我不这样做,释放信封确实有效,但音符有时可以继续播放。
编辑:似乎当该.stop()
功能未实现并且两个音符同时播放时,其中一个振荡器将始终保持打开状态。不知道是我的代码还是??
我的noteOff
功能代码如下:
/**
* Note is being released
*/
this.noteOff = function (frequency, velocity, note){
var now = this.context.currentTime;
// Get the release values
var osc1ReleaseVal = now + this.osc1Release;
var osc2ReleaseVal = now + this.osc2Release;
// Cancel scheduled values
this.oscGain.gain.cancelScheduledValues(now);
this.osc2Gain.gain.cancelScheduledValues(now);
// Set the value
this.oscGain.gain.setValueAtTime(this.oscGain.gain.value, now);
this.osc2Gain.gain.setValueAtTime(this.osc2Gain.gain.value, now);
// Release the note
this.oscGain.gain.linearRampToValueAtTime(0.0, osc1ReleaseVal);
this.osc2Gain.gain.linearRampToValueAtTime(0.0, osc2ReleaseVal);
// ----- IF I COMMENT THE `forEach` Loop the release works correctly but with side-effects!
// Stop the oscillators
this.oscillators[frequency].forEach(function (oscillator) {
oscillator.stop(now);
oscillator.disconnect();
delete oscillator;
});
};
任何帮助将不胜感激,谢谢!