我正在使用
我想知道如何在发行后正确停止(并在必要时删除?)振荡器。我不确定是否需要调用
如果这样做,释放包络不起作用,音符会立即停止。如果不这样做,释放包络确实起作用,但是音符有时会一直播放下去。
编辑:当未实现
以下是我的
WebAudioAPI
和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;
});
};
非常感谢您的帮助!如有需要,敬请指教。
oscillator.stop()
放入一个setTimeout
函数中,时间设置为osc1ReleaseVal
和osc2ReleaseVal
,但没有起作用... 我想我需要考虑添加其他东西。 - Alistair Hughes