Skip to content

Instantly share code, notes, and snippets.

@nick-thompson
Last active December 10, 2015 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nick-thompson/4480973 to your computer and use it in GitHub Desktop.
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.
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);
@ketting00
Copy link

It's not working. I can't detect any data passing. I grab data from the audio element though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment