javascript - Web Audio API getFloatFrequencyData function setting Float32Array argument data to array of -Infinity values -


i'm playing around web audio api in chrome (60.0.3112.90) possibly build sound wave of given file via filerreader, audiocontext, createscriptprocessor, , createanalyser. have following code:

const visualize = analyser => {   analyser.fftsize = 256;   let bufferlength = analyser.frequencybincount;   let dataarray = new float32array(bufferlength);   analyser.getfloatfrequencydata(dataarray); }      loadaudio(file){   // creating filereader convert audio file arraybuffer   const filereader = new filereader();    navigator.getusermedia = (navigator.getusermedia ||                       navigator.webkitgetusermedia ||                       navigator.mozgetusermedia ||                       navigator.msgetusermedia);    filereader.addeventlistener('loadend', () => {     const filearraybuffer = filereader.result;      let audioctx = new (window.audiocontext || window.webkitaudiocontext)();     let processor = audioctx.createscriptprocessor(4096, 1, 1);     let analyser = audioctx.createanalyser();      analyser.connect(processor);     let data = new float32array(analyser.frequencybincount);      let soundbuffer;     let soundsource = audioctx.createbuffersource();      // loading audio track buffer     audioctx.decodeaudiodata(        filearraybuffer,        buffer => {         soundbuffer = buffer;         soundsource.buffer = soundbuffer;          soundsource.connect(analyser);         soundsource.connect(audioctx.destination);          processor.onaudioprocess = () => {           // data becomes array of -infinity values after call below           analyser.getfloatfrequencydata(data);         };          visuaulize(analyser);       },       error => 'error decoding audio data: ' + error.err     );   });    filereader.readasarraybuffer(file); } 

upon loading file, way analyser.getfloatfrequencydata(data). upon reading web audio api docs, says parameter is:

the float32array frequency domain data copied to.  sample silent, value -infinity. 

in case, have both mp3 , wav file i'm using test , after invoking analyser.getfloatfrequency(data), both files end giving me data becomes array of `-infinity' values.

this may due ignorance web audio's api, question why both files, contain loud audio, giving me array represents silent samples?

the web audio analysernode designed work in realtime. (it used called realtimeanalyser.) web audio doesn't have ability analysis on buffers; take @ library, dsp.js.


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -