【发布时间】:2017-08-10 02:16:05
【问题描述】:
我正在创建很多这样的 WebAudio 乐器对象:
var context = new AudioContext();
Inst = function (id, param){
var inst = {
id = id,
param = param
}
inst.osc = context.createOscillator();
inst.gain = context.createGain();
inst.osc.connect(inst.gain);
inst.gain.connect(context.destination)
inst.gain.gain.value = 0;
inst.osc.start();
inst.playTone = function () {
inst.gain.gain.setTargetAtTime(1, context.currentTime, 0.1);
}
inst.stopTone = function () {
inst.gain.gain.setTargetAtTime(0, context.currentTime, 0.1);
}
instList[id] = inst;
}
如您所见,我只是提高和降低音量。在inst. 函数中使用.start() 和.stop() 是有问题的,因为.stop 会杀死振荡器,并且用户将与这些对象重复交互。
我想知道,AudioContext 中可以处理的振荡器数量是否有上限?如果我启动一大堆振荡器并且从不停止它们,是否会出现一些潜在的性能问题?
(旁注:如果这是推荐的方法,我愿意接受有关如何每次动态创建新振荡器的建议......我还没有弄清楚,毕竟我不确定它是需要。)
【问题讨论】:
标签: javascript performance web-audio-api