我正在尝试使用处理器节点here构建一些东西。几乎我在调试它时所做的任何事情都会使chrome崩溃。特别是标签。每当我启动开发工具,并且100%的时间我在onaudioprocess节点中放置一个断点,选项卡死了,我必须找到该选项卡的chrome助手进程,或者强制退出chrome才能重新开始。它基本上暂时阻碍了我的发展。这是一个已知的问题吗?我需要采取某些预防措施来防止chrome崩溃吗?实时方面的web音频api是不是就是不可调试的?
发布于 2017-10-14 17:46:07
如果看不到你的代码,就很难诊断出问题。
运行此代码片段会使浏览器选项卡崩溃吗?
let audioCtx = new (window.AudioContext || window.webkitAudioContext)();
function onPlay() {
let scriptProcessor = audioCtx.createScriptProcessor(4096, 2, 2);
scriptProcessor.onaudioprocess = onAudioProcess;
scriptProcessor.connect(audioCtx.destination);
let oscillator = audioCtx.createOscillator();
oscillator.type = "sawtooth";
oscillator.frequency.value = 220;
oscillator.connect(scriptProcessor);
oscillator.start();
}
function onAudioProcess(event) {
let { inputBuffer, outputBuffer } = event;
for (let channel = 0; channel < outputBuffer.numberOfChannels; channel++) {
let inputData = inputBuffer.getChannelData(channel);
let outputData = outputBuffer.getChannelData(channel);
for (let sample = 0; sample < inputBuffer.length; sample++) {
outputData[sample] = inputData[sample];
// Add white noise to oscillator.
outputData[sample] += ((Math.random() * 2) - 1) * 0.2;
// Un-comment the following line to crash the browser tab.
// console.log(sample);
}
}
}<button type="button" onclick="onPlay()">Play</button>
如果它崩溃了,那就是你的本地开发环境中的其他东西导致了你的问题,因为它为我完美地运行着。
如果不是,那么也许您正在onaudioprocess事件处理程序中执行console.log() (或其他一些繁重的操作)?请记住,此事件处理程序每次被调用时都会处理数千个音频样本,因此您需要小心处理它。例如,尝试取消注释上面代码片段中的console.log()行-浏览器选项卡将崩溃。
https://stackoverflow.com/questions/46556390
复制相似问题