xxxxxxxxxx
49
let mMic;
let isMicOn;
let mDelays = [];
let NUM_DELAYS = 4;
let DELAY_TIME = 0.01;
function setup() {
createCanvas(windowWidth, windowHeight);
mMic = new p5.AudioIn();
isMicOn = false;
for (let i = 0; i < NUM_DELAYS; i++) {
let mDelay = new p5.Delay();
mDelay.disconnect();
mDelay.delayTime(DELAY_TIME);
if (i > 0) {
mDelays[i - 1].connect(mDelay);
}
mDelays.push(mDelay);
}
mMic.disconnect();
mMic.connect(mDelays[0]);
mDelays[mDelays.length - 1].connect(p5.soundOut);
noLoop();
}
function draw() {
background(220, 20, 120);
}
function mouseClicked() {
if (isMicOn) {
mMic.stop();
background(220, 20, 120);
} else {
mMic.start();
background(20, 220, 120);
}
isMicOn = !isMicOn;
}