Last active
December 10, 2015 19:19
-
-
Save nick-thompson/4480973 to your computer and use it in GitHub Desktop.
Testing the load on the browser using many ScriptProcessor nodes. Chrome Canary v26.0.1367.0 suggests that around 15 ScriptProcessor nodes performing simple functions is enough to noticeably disrupt the audio output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var context = new webkitAudioContext() | |
, source = context.createOscillator() | |
, through = context.createScriptProcessor(1024, 1, 1) | |
, count = 0; | |
// The most basic of ScriptProcessing functions, copying the input buffer | |
// directly into the output buffer. | |
through.onaudioprocess = function (e) { | |
var input = e.inputBuffer.getChannelData(0) | |
, output = e.outputBuffer.getChannelData(0); | |
for (var i = 0; i < output.length; i++) { | |
output[i] = input[i]; | |
} | |
}; | |
// Make the connections | |
source.connect(through); | |
through.connect(context.destination); | |
// Start it up | |
source.start(0); | |
// Every second, route an additional ScriptProcessor into the node graph | |
// to test the event loop. These additional ScriptProcessors do not route | |
// any output into the output buffers so that you can hear exactly when the | |
// load becomes overbearing. | |
setInterval(function () { | |
console.log(++count); | |
var next = context.createScriptProcessor(1024, 1, 1) | |
, fn = function (e) { | |
var input = e.inputBuffer.getChannelData(0); | |
for (var i = 0; i < input.length; i++) { | |
input[i] += 0.01; | |
} | |
}; | |
window.fns = window.fns || []; | |
window.fns.push(fn); | |
next.onaudioprocess = fn; | |
source.connect(next); | |
next.connect(context.destination); | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's not working. I can't detect any data passing. I grab data from the audio element though.