Skip to content

Instantly share code, notes, and snippets.

@chikoski
Created August 21, 2015 23:37
Show Gist options
  • Save chikoski/2ded11632b3daa08f0ea to your computer and use it in GitHub Desktop.
Save chikoski/2ded11632b3daa08f0ea to your computer and use it in GitHub Desktop.
var max = {
};
var elm = {
freq: document.querySelector("#freq"),
attack: document.querySelector("#attack"),
decay: document.querySelector("#decay"),
sustain: document.querySelector("#sustain"),
release: document.querySelector("#release"),
play: document.querySelector("#play")
};
var context = new AudioContext();
var oscillator = context.createOscillator();
oscillator.frequency.value = 146.832;
var envelope = context.createGain();
var gain = context.createGain();
gain.gain.value = 0;
var filter = context.createBiquadFilter();
filter.type = "lowpass";
filter.frequency.value = 440;
oscillator.connect(envelope);
envelope.connect(gain);
gain.connect(filter);
filter.connect(context.destination);
oscillator.start();
var playing = false;
elm.play.addEventListener("click", event =>{
if(playing){
gain.gain.value = 0;
}else{
gain.gain.value = 0.75;
envelope.gain.value = 0;
envelope.gain.linearRampToValueAtTime(0.8, context.currentTime + 1400);
}
playing = !playing;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment