xxxxxxxxxx
69
let mSound;
let mFilterHigh;
let mReverb;
let toggleEffects;
function preload() {
mSound = loadSound("./epic-hip-hop.mp3");
}
function setup() {
createCanvas(windowWidth, windowHeight);
toggleEffects = createCheckbox("hi-hat filter-reverb", 1);
toggleEffects.position(0, 10);
toggleEffects.mouseClicked(reconnect);
mFilterHigh = new p5.Filter("bandpass");
mFilterHigh.freq(9000);
mFilterHigh.res(6);
mFilterHigh.amp(6.0);
mReverb = new p5.Reverb();
mReverb.set(2, 10, true);
mReverb.drywet(1.0);
mSound.disconnect();
mFilterHigh.disconnect();
mReverb.disconnect();
mSound.connect(mFilterHigh);
mFilterHigh.connect(mReverb);
mReverb.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();
mFilterHigh.disconnect();
mReverb.disconnect();
if (toggleEffects.checked()) {
mSound.connect(mFilterHigh);
mFilterHigh.connect(mReverb);
mReverb.connect(p5.soundOut);
} else {
mSound.connect(p5.soundOut);
}
mSound.play();
}