xxxxxxxxxx
69
let mSound;
let mFilterLow;
let mDelay;
let toggleEffects;
function preload() {
mSound = loadSound("./epic-hip-hop.mp3");
}
function setup() {
createCanvas(windowWidth, windowHeight);
toggleEffects = createCheckbox("bass filter-delay", 1);
toggleEffects.position(0, 10);
toggleEffects.mouseClicked(reconnect);
mFilterLow = new p5.Filter("bandpass");
mFilterLow.freq(80);
mFilterLow.res(6);
mFilterLow.amp(4.0);
mDelay = new p5.Delay();
mDelay.delayTime(0.33);
mDelay.feedback(0.8);
mSound.disconnect();
mFilterLow.disconnect();
mDelay.disconnect();
mSound.connect(mFilterLow);
mFilterLow.connect(mDelay);
mDelay.connect(p5.soundOut);
noFill();
}
function draw() {
background(220, 20, 120);
}
function mouseClicked() {
if (mSound.isPlaying()) {
mSound.pause();
} else {
mSound.play();
}
}
function reconnect(evt) {
evt.stopPropagation();
mSound.pause();
mSound.disconnect();
mFilterLow.disconnect();
mDelay.disconnect();
if (toggleEffects.checked()) {
mSound.connect(mFilterLow);
mFilterLow.connect(mDelay);
mDelay.connect(p5.soundOut);
} else {
mSound.connect(p5.soundOut);
}
mSound.play();
}