Skip to content

Instantly share code, notes, and snippets.

@toruta39
Last active August 29, 2015 13:57
Show Gist options
  • Save toruta39/9909779 to your computer and use it in GitHub Desktop.
Save toruta39/9909779 to your computer and use it in GitHub Desktop.
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