Last active
August 29, 2015 13:57
-
-
Save toruta39/9909779 to your computer and use it in GitHub Desktop.
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
function BrownNoise(audioContext) { | |
this.node = audioContext.createBufferSource(); | |
var bufferSize = 2 * audioContext.sampleRate, | |
buffer = audioContext.createBuffer(1, bufferSize, audioContext.sampleRate), | |
data = buffer.getChannelData(0); | |
lastOutput = 0; | |
for (var i = 0, len = data.length; i < len; i++) { | |
var white = Math.random() * 2 - 1; | |
data[i] = (lastOutput + white * 0.02) / 1.02; | |
lastOutput = data[i]; | |
data[i] *= 3.5; // Gain | |
} | |
this.node.buffer = buffer; | |
this.node.loop = true | |
} | |
var audioContext = new webkitAudioContext(), | |
noise = new BrownNoise(audioContext); | |
noise.node.connect(audioContext.destination); | |
noise.node.start(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment