Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
500 views
in Technique[技术] by (71.8m points)

javascript - Web Audio Offline Context and Analyser Node

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

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();

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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...