Skip to content

Instantly share code, notes, and snippets.

@JustGoscha
Last active June 8, 2018 10:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JustGoscha/10104318 to your computer and use it in GitHub Desktop.
Save JustGoscha/10104318 to your computer and use it in GitHub Desktop.
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