javascript - Web audio - Analyser frequency data not 0 during silence -
i create sounds using oscillator nodes , want draw frequency visualization on canvas. when oscillator playing, visualization looks (standard oscillator settings, see code below). http://i58.tinypic.com/wtvwgz.png
after oscillator stopped playing (complete silence!), get. exact result changes run run, values maintain changing after stop. http://i62.tinypic.com/2duji81.png
i don't understand why frequency info not 0 bins, when sound not playing.
tested on firefox 30.0 , iron 34.0.1850.0 (chrome)
here's sample code:
<!doctype html> <html> <head> <title></title> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <script type="text/javascript"> window.onload = function () { var ctx = document.getelementbyid("canvas").getcontext("2d"); var audiocontext = new (window.audiocontext || window.webkitaudiocontext || window.mozaudiocontext)(); var analyser = audiocontext.createanalyser(); analyser.fftsize = 512; analyser.connect(audiocontext.destination); var frequencybins = new uint8array(analyser.frequencybincount); var osc = audiocontext.createoscillator(); osc.connect(analyser); osc.start(audiocontext.currenttime + 2); osc.stop(audiocontext.currenttime + 4); var width = 512; var height = 100; var value, h, w; function draw() { ctx.clearrect(0, 0, width, height); (var = 0; < frequencybins.length; i++) { value = frequencybins[i]; h = height * (value / 255); w = width / frequencybins.length; ctx.fillrect(i * w, height - 1, w, -h); } }; function animate() { analyser.getbytefrequencydata(frequencybins); draw(); requestanimationframe(animate); } requestanimationframe(animate); }; </script> </head> <body> <canvas id="canvas" width="512" height="100"></canvas> </body> </html>
it's not noise floor. happens sound buffers too. it's bug.
javascript html5 web-audio
No comments:
Post a Comment