Created
January 24, 2016 06:49
-
-
Save whichlight/eee45b71014440806ff5 to your computer and use it in GitHub Desktop.
white noise generator in javascript
This file contains 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 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