xxxxxxxxxx
32
let synth;
function setup() {
let cnv = createCanvas(400, 400);
cnv.mousePressed(playSound);
background(240, 228, 66);
fill(0, 114, 178);
textSize(80);
textAlign(CENTER);
text('click me', width/2, height/2);
synth = new p5.MonoSynth();
}
function playSound() {
userStartAudio();
let note = random(['C4', 'D#4', "F4", "G4", "A#4"]);
// note velocity (volume, from 0 to 1)
let velocity = random();
// time from now until it plays (in seconds)
let time = 0;
// note duration (in seconds)
let dur = 1/2;
synth.play(note, velocity, time, dur);
}