Skip to content

Instantly share code, notes, and snippets.

@toruta39
Last active June 21, 2018 09:28
Show Gist options
  • Save toruta39/9909222 to your computer and use it in GitHub Desktop.
Save toruta39/9909222 to your computer and use it in GitHub Desktop.
function WhiteNoise(audioContext) {
this.node = audioContext.createBufferSource();
var bufferSize = 2 * audioContext.sampleRate,
buffer = audioContext.createBuffer(1, bufferSize, audioContext.sampleRate),
data = buffer.getChannelData(0);
for (var i = 0, len = data.length; i < len; i++) {
data[i] = Math.random() * 2 - 1;
}
this.node.buffer = buffer;
this.node.loop = true;
}
var audioContext = new webkitAudioContext(),
noise = new WhiteNoise(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