Skip to content

Instantly share code, notes, and snippets.

@dariusk
Created November 19, 2015 03:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dariusk/416c0ac484a05cb22bd4 to your computer and use it in GitHub Desktop.
Save dariusk/416c0ac484a05cb22bd4 to your computer and use it in GitHub Desktop.
John Cage's 4'33" in the Web Audio API.
// John Cage's 4'33" with the Web Audio API
function makeSilence(e) {
var buflen = e.outputBuffer.length;
var dataL = e.outputBuffer.getChannelData(0);
var dataR = e.outputBuffer.getChannelData(1);
dataL.fill(0);
dataR.fill(0);
}
function InitAudio() {
var audioContext = window.AudioContext || window.webkitAudioContext;
var audioctx = new audioContext();
gainNode = audioctx.createGain();
gainNode.gain.value = 0.5;
jsNode = audioctx.createScriptProcessor(2048, 0, 2);
jsNode.onaudioprocess = makeSilence;
jsNode.connect(gainNode);
gainNode.connect(audioctx.destination);
}
InitAudio();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment