Last active
October 25, 2016 14:55
-
-
Save MylesBorins/9ee7baca00160fdbe4929287a70351d2 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
// ADSR ~ Attack, Sustain, Decay, Release | |
var attackLevel = 1.0; | |
var releaseLevel = 0; | |
var attackTime = 0.001; | |
var decayTime = 0.2; | |
var susPercent = 0.2; | |
var releaseTime = 0.5; | |
var env, triOsc; | |
function setupAudio() { | |
env = new p5.Env(); | |
env.setADSR(attackTime, decayTime, susPercent, releaseTime); | |
env.setRange(attackLevel, releaseLevel); | |
triOsc = new p5.Oscillator('triangle'); | |
triOsc.amp(env); | |
triOsc.start(); | |
triOsc.freq(220); | |
} | |
function setup() { | |
var cnv = createCanvas(100, 100); | |
setupAudio(); | |
} | |
function keyPressed () { | |
if (key === 'A') { | |
triOsc.freq(220); | |
env.play(triOsc, 0, 0.2); | |
} | |
else if (key === 'S') { | |
triOsc.freq(330); | |
env.play(triOsc, 0, 0.2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment