Firefox Web Audio API实时更新AudioBuffer/AudioBufferSourceNode [英] Firefox Web Audio API on-the-fly update AudioBuffer / AudioBufferSourceNode

查看:48
本文介绍了Firefox Web Audio API实时更新AudioBuffer/AudioBufferSourceNode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过以编程方式填充 AudioBuffer 来创建1s音频片段. AudioBufferSourceNode 启用了循环.在Chrome和Firefox中可以正常播放.

I'm creating a 1s audio snippet by programmatically filling a AudioBuffer. The AudioBufferSourceNode has looping enabled. It plays back just fine in Chrome and Firefox.

现在,我想动态更新AudioBuffer并立即(或在下一个循环中)拾取新的音频.在Chrome中,只需获取频道数据( getChannelData(0))并将其写入即可完美地实现此目的.Chrome会即时更新正在播放的音频.Firefox不断重复播放原始缓冲区.实际上,在Firefox中,需要先将 AudioBuffer 分配给 AudioBufferSourceNode ( source.buffer = buffer ).

Now I want to dynamically update the AudioBuffer and have the new audio picked up immediately (or at the next loop). In Chrome this works perfectly by simply getting the channel data (getChannelData(0)) and writing to it. Chrome updates the playing audio on-the-fly. Firefox keeps playing the original buffer over and over again. In fact in Firefox the AudioBuffer needs to be written before assigning it to the AudioBufferSourceNode (source.buffer = buffer).

推荐答案

这不应以这种方式完成.您正在尝试跨线程边界更新对象.

This should not be done this way. You're trying to update an object across a thread boundary.

Chrome的一个错误是我们当前不实施内存保护(即您可以更新AudioBuffer的内容,它将更改循环缓冲区的声音).FF当前有另一个错误,该错误使您可以多次设置.buffer.这些都应该修复.

Chrome has a bug where we don't currently implement the memory protection (i.e. you can update the contents of the AudioBuffer and it will change what the looping buffer sounds like). FF currently has a different bug, where it allows you to set the .buffer more than once. These should both get fixed.

要解决此问题,您需要循环每个缓冲区,直到获得下一个缓冲区,然后在它们之间进行淡入淡出.无论如何,循环1s缓冲区确实不是您真正想要的吗?(除非是噪音.)

To address this scenario, you need to loop each buffer until you get then next one, then cross-fade between them. It's unlikely just looping a 1s buffer is really what you want anyway? (unless it's noise.)

这篇关于Firefox Web Audio API实时更新AudioBuffer/AudioBufferSourceNode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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