Created
August 21, 2015 23:37
-
-
Save chikoski/2ded11632b3daa08f0ea to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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