Last active
June 21, 2018 09:28
-
-
Save toruta39/9909222 to your computer and use it in GitHub Desktop.
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
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