xxxxxxxxxx
31
let soundFile1;
let soundFile2;
let loopStart = 0.5;
let loopDuration = 0.2;
function preload() {
soundFormats("ogg", "mp3");
soundFile1 = loadSound("kotoish-short.mp3");
soundFile2 = loadSound("kotoish-short.mp3");
}
function setup() {
let cnv = createCanvas(100, 100);
cnv.mousePressed(canvasPressed);
background(220);
fill('black')
text("tap to play, release to stop playback", 10, 20, width - 20);
}
// this function is controlling the start of the sounds
function canvasPressed() {
soundFile1.loop(0, 1, 0.7, loopStart);
soundFile2.loop(2 * Math.random(), 0.5, 0.7, loopStart);
background(0, 200, 50);
}
function mouseReleased() {
soundFile1.setLoop(false);
soundFile2.setLoop(false);
background(220);
}