Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dynamically create a WebAudio buffer (with noise) and play it!
var AudioContext = AudioContext || webkitAudioContext || mozAudioContext;
var context = new AudioContext();
var node = context.createBufferSource()
, buffer = context.createBuffer(1, 4096, context.sampleRate)
, data = buffer.getChannelData(0);
for (var i = 0; i < 4096; i++) {
data[i] = Math.random();
}
node.buffer = buffer;
node.loop = true;
node.connect(context.destination);
node.start(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment