Skip to content

Instantly share code, notes, and snippets.

@whichlight
Created January 24, 2016 06:49
Show Gist options
  • Save whichlight/eee45b71014440806ff5 to your computer and use it in GitHub Desktop.
Save whichlight/eee45b71014440806ff5 to your computer and use it in GitHub Desktop.
white noise generator in javascript
var whiteNoiseGen = function(){
var bufferSize = 4096; //Math.pow(2,13); //between 8 & 14
//make this a global var so it isnt garbage collected
whiteNoise = context.createScriptProcessor(bufferSize, 0, 2);
whiteNoise.onaudioprocess = function(e) {
var outputBuffer = e.outputBuffer;
for (var channel = 0; channel < outputBuffer.numberOfChannels; channel++) {
var outputData = outputBuffer.getChannelData(channel);
for (var i = 0; i < bufferSize; i++) {
outputData[i] = Math.random()*2-1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment