- From: lonce <lonce.wyse@zwhome.org>
- Date: Tue, 19 Feb 2013 18:11:08 +0800
- To: public-audio@w3.org
Hi -
What might cause callbacks to onaudioprocess() for
ScriptProcessorNode to suddenly cease?
I have the simplest architecture:
ScriptProcessorNode (generating random noise) -> Gain node ->
audioContext.destination
When left to run, I get anywhere from 150 to 1500 successsive callbacks
to onaudioprocess(), and then it just quits (leaving a dirty buffer for
the gain node to read)
You can hear/see it here:
http://animatedsoundworks.com/jsaSound/ (select "JS Node Test" from the
drop-down menu, and hit "play" and let it run)
You can see the callbacks to onaudioprocess() logged in the console
window. Sometime in the first minute, they just stop.
The core code:
// ScriptProcessor to generate noise
var noiseNode =
config.audioContext.createScriptProcessor(config.k_bufferLength, 1, 1);
noiseNode.onaudioprocess = function (e) {
var outBuffer = e.outputBuffer.getChannelData(0);
for (var i = 0; i < outBuffer.length; i += 1) {
outBuffer[i] = Math.random() * 2 - 1;
}
}
var gainLevelNode = config.audioContext.createGainNode();
// Connect graph
noiseNode.connect(gainLevelNode);
gainLevelNode.connect(config.audioContext.destination);
gainLevelNode.gain.value = .1;
To "start" and "stop" the sound, I just set the gain level.
If I am not doing something properly, I would be glad to know about it!
Thanks,
- lonce
Received on Tuesday, 19 February 2013 10:12:01 UTC