我喜欢网络音频 API。可能性非常大。话虽如此,它仍处于早期阶段。最让我担心的是,我不知道如何释放不再需要的缓冲区/声音。因为我将混合来自通过 websocket 连接的音乐家 / DJ / 主持人的现场声音,所以声音缓冲区总是带有新的声音。
以下代码模拟连续加载新缓冲区的播放。我需要网络音频 api 来添加效果混合,这样每个人都可以通过他的表演听到现场结果。
不幸的是,这段代码吃掉了整个内存并导致移动和桌面 safari 崩溃。我不知道在播放这些大缓冲区后如何释放它们,我不再需要它们。我真的需要在内存中加载新的大数据。有人知道吗?否则我会卡在播放的前 8 个文件无法再加载。
var context = new webkitAudioContext();
var total=0;
function onTouchStart(){
setInterval(function(){
total+=10;
source = context.createBufferSource();
source.connect(context.destination); // simulates loading large file
source.buffer=context.createBuffer(1, 10*1024*1024, context.sampleRate);
source.noteOn(0);
source.noteOff(0); // acording to w3c spec resources should be deleted immediately.
// making source property and call delete or =null will release nether source or buffer i am desperate.
console.log(total,'mb'); //
},1000);
}
document.addEventListener( "touchstart", onTouchStart );
document.addEventListener( "click", onTouchStart );