Web Audio Api,实时更新循环缓冲区数据,在 Firefox 中不可能? [英] Web Audio Api, updating looping buffer data in real time, impossible in Firefox?

查看:18
本文介绍了Web Audio Api,实时更新循环缓冲区数据,在 Firefox 中不可能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在播放循环缓冲区时尝试更改底层缓冲区数据时遇到问题.

I am running into an issue when trying to change the underlying buffer data while a looping buffer is being played back.

bufferData = audioContext.bufferSourceNode.buffer.getChannelData(0);
bufferData[100] = newValue;

这种行为似乎在大多数浏览器中都能正常工作——我已经在 Chrome、Safari、Opera、Edge 中测试过,一切都很好——但这在 Firefox 中似乎是不可能的.这似乎是一个错误.我阅读了 2015 年的 StackOverflow 问题这种更新缓冲区的方式不应该这样做......"这种事情应该如何在firefox中实现?

This kind of behavior seems to work fine in most browsers—I've tested in Chrome, Safari, Opera, Edge, all working fine—but this doesn't seem to be possible in Firefox. This seems like a bug. I read in this StackOverflow question from 2015 that this way of updating a buffer "should not be done this way ..." How should this sort of thing be achieved in firefox?

尝试的解决方法:

tempBufferData = bufferSourceNode.buffer.getChannelData(0);
bufferSourceNode.stop();
bufferSourceNode.disconnect();
buffer = audioContext.createNewBuffer();
tempBufferData[10] = newValue;
buffer.copyToChannel(tempBufferData);
bufferSourceNode.buffer = buffer;
bufferSourceNode.connect(gainNode);
bufferSourceNode.start(audioContext.currentTime);

每次更新缓冲区时停止当前缓冲区、断开连接、创建新的bufferSourceNode和新缓冲区以及重新连接节点的方法感觉很繁重.到目前为止,在我对该方法的测试中,引入了很多故障/爆裂.有没有一种改进的方法来做到这一点?

The method of stopping the current buffer, disconnecting, creating a new bufferSourceNode and new buffer, and reconnecting the nodes every time the buffer is updated feels onerous. In my testing of that method so far, there is quite a lot of glitchiness/popping introduced. Is there a refined method for doing this?

以下是需要这种更新缓冲区的具体示例:一个演示,其中您可以绘制一个循环的波形,每次更改绘图时都会更新. 似乎除了在 Firefox 中工作.

Here is a concrete example of the need for this kind of updating buffer: a demo in which you can draw a waveform that is looped, that updates every time you change the drawing. Seems to work except in firefox.

推荐答案

我不认为这就是您希望的答案,因为这需要一些额外的工作,但我认为您应该这样做' 在 Firefox 中执行此操作(即 Web 音频 API 规范旨在用于此类任务的方式)是使用 AudioWorklet.

I don't think this is the answer you were hoping for as it'll be a fair bit of extra work, but I think the way you 'should' do this in Firefox (that is, the way the web audio API spec intended for these kinds of tasks) is to use an AudioWorklet.

https://developer.mozilla.org/en-US/docs/Web/API/AudioWorklet

这篇关于Web Audio Api,实时更新循环缓冲区数据,在 Firefox 中不可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆