xxxxxxxxxx
// remember to add the sound library : p5.sound
var osc; // this is a variable which we will use for an oscillator
var env; // this is a variable which we wlll use for the envelope
var sequence = [50, 100, 150, 200, 100, 300, 250, 50, 100, 450, 350, 25];
var s = 0;
var speed = 6;
var fg = 255;
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
// take 0.1 seconds to get to level 1, then 0.5 seconds to get to level 0
env = new p5.Envelope(0.01, 1, 0.3, 0);
osc = new p5.Oscillator(); // make an oscillator
osc.setType('sine'); // options are 'sine', 'sawtooth', 'triangle', 'square'
osc.start(); // start it
osc.amp(0);
textSize(60);
}
function draw() {
background(255-fg);
stroke(fg);
fill(fg);
text(frameCount + ": " + s + ": " + sequence[s], width/2, height/2);
if(frameCount%speed==0) {
playit(sequence[s]); // play a note
s = (s+1) % sequence.length; // increment which note
fg = 255-fg; // flip the color
}
}
function mouseClicked()
{
//playit();
}
function playit(f)
{
osc.freq(f); // frequency to the argument
env.play(osc);
}