xxxxxxxxxx
45
let mSound;
let mFilter;
let mAmp;
function preload() {
mSound = loadSound("./epic-hip-hop.mp3");
}
function setup() {
createCanvas(windowWidth, windowHeight);
mFilter = new p5.Filter("bandpass");
mFilter.res(4);
mAmp = new p5.Amplitude();
mSound.disconnect();
mFilter.disconnect();
mSound.connect(mFilter);
mFilter.connect(p5.soundOut);
mFilter.connect(mAmp);
strokeWeight(2);
stroke(0);
noFill();
}
function draw() {
background(220, 20, 120, 20);
let mFreq = map(mouseX, 0, width, 50, 2000, true);
mFilter.freq(mFreq);
let d = map(mAmp.getLevel(), 0, 1, 5, height);
ellipse(width / 2, height / 2, d, d);
}
function mouseClicked() {
if (mSound.isPlaying()) {
mSound.pause();
} else {
mSound.play();
}
}