javascript - ScriptProcessorNode Skipping -
i have following javascript code:
var audio = null; try { window.audiocontext = window.audiocontext || window.webkitaudiocontext; audio = new audiocontext(); } catch (e) { alert("web audio api not supported in browser"); } var scriptnode = audio.createscriptprocessor(1024, 0, 1); var pos = 0.0; scriptnode.onaudioprocess = function(audioprocessingevent) { var output = audioprocessingevent.outputbuffer; (var channel = 0; channel < output.numberofchannels; channel++) { var data = output.getchanneldata(channel); (var = 0; < data.length; i++) { data[i] = math.sin(pos); pos += 2.0 * 3.14159 * 440.0 / audio.samplerate; while (pos >= 2.0 * 3.14159) { pos -= 2.0 * 3.14159; } } } } scriptnode.connect(audio.destination); i trying access audio loop of web-audio, in way low-level audio streaming api work in c. code supposed play 440 hz tone continuously until page closed. code play tone, after second or 2 sound skips repeatedly, suggesting i've run out of buffer space , script isn't being called each buffer period.
i'm sure solution simple, what's causing skipping? how can script run continuously?
edit: skipping goes away if refresh page. browser bug?
increase buffer size of scriptprocessor node 1024 larger. or use 0 let browser choose value you.
note scriptprocessors deprecated, replacement isn't yet available. replacement should behave better.
Comments
Post a Comment