xxxxxxxxxx
78
let vocals;
let vocalfft;
let instrumentals;
let instrumentalfft;
let button;
function preload() {
vocals = loadSound("Music/Vocals.m4a");
vocalfft = new p5.FFT();
vocalfft.setInput(vocals);
instrumentals = loadSound("Music/Instrumentals.m4a");
instrumentalfft = new p5.FFT();
instrumentalfft.setInput(instrumentals);
}
function setup() {
colorMode(HSB);
createCanvas(700, 700);
vocals.play();
instrumentals.play();
pp = createButton("Pause/Play");
}
function draw() {
colorMode(HSB);
background(39, 100, 100);
noFill();
let spectrum = vocalfft.analyze();
for (let i = 1; i < spectrum.length; i++) {
let d = map(spectrum[i], 0, 100, 0, 200);
let e = map(spectrum[i], 0, 100, 0, height);
// circle(350,250,d);
strokeWeight(2);
// line(350, d, 450, d);
// circle(350, 350, d);
fill(25, 0, 100, 30);
stroke(39, 200, 150);
circle(650, 650, d);
}
let ispectrum = instrumentalfft.analyze();
for (let f = 1; f < ispectrum.length; f++) {
let a = map(ispectrum[f], 0, 100, 0, 200);
strokeWeight(0.05);
fill(30, 39, 100);
stroke(39, 100, 100);
strokeWeight(2);
circle(150, 150, a);
fill(255);
circle(350, 350, 150);
}
pp.mousePressed(pausePlay);
if (keyIsPressed && key == "i") {
if (instrumentals.isPlaying()) {
instrumentals.stop();
} else {
instrumentals.play();
}
}
function pausePlay() {
if (mouseIsPressed) {
if (vocals.isPlaying()) {
vocals.stop();
} else {
vocals.play();
}
}
}
}