Web音频离线上下文和分析器节点 [英] Web Audio Offline Context and Analyser Node

查看:71
本文介绍了Web音频离线上下文和分析器节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 offlineAudioContext 中的 Analyzer 节点进行频率分析?

Is it possible to use the Analyser node in the offlineAudioContext to do frequency analysis?

我发现 ScriptProcessor onaudioprocess 事件仍在 offlineAudioContext 这是我用来调用分析器的 getByteFrequencyData 的唯一事件源节点。如下所示:

I found out that ScriptProcessor 's onaudioprocess event still fires in the offlineAudioContext and this was the only event source I could use to call getByteFrequencyData of the Analyser Node. As below:

var offline = new offlineAudioContext(1, buffer.length, 44100);
var bufferSource = offline.createBufferSource();
bufferSource.buffer = buffer;

var analyser = offline.createAnalyser();
var scp = offline.createScriptProcessor(256, 0, 1);

bufferSource.connect(analyser);
scp.connect(offline.destination); // this is necessary for the script processor to start

var freqData = new Uint8Array(analyser.frequencyBinCount);
scp.onaudioprocess = function(){
    analyser.getByteFrequencyData(freqData);
    console.log(freqData);
   // freqData is always the same.
};

bufferSource.start(0);
offline.startRendering();

这里的问题是 freqData 数组是总是一样的,永远不会改变。好像它只是在分析缓冲区的一部分。

The problem here is that freqData array is always the same and never changes. Seem like as if it is only analysing one section of the buffer.

我在这里做错了吗?或者 Analyzer 不打算在 offlineContext 中使用。

Am I doing anything wrong here? Or the Analyser is not intended to be used in the offlineContext.

以下是使用相同代码的小提琴

And here is the fiddle with the same code.

推荐答案

分析器实际上不打算在offlineContext中使用;事实上,它最初被命名为RealtimeAnalyser。但更重要的是,现在您无法在脱机环境中从脚本处理器获得一致的功能。

The analyser isn't really intended to be used in the offlineContext; in fact, it was originally named "RealtimeAnalyser". But even more importantly, right now you won't get consistent functionality from script processors in offline contexts, either.

这篇关于Web音频离线上下文和分析器节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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