xxxxxxxxxx
49
let song, sfft, vfft, mic;
function preload() {
song = loadSound("attempt1.mp3");
}
function setup() {
createCanvas(800, 800);
sfft = new p5.FFT();
vfft = new p5.FFT();
song.play();
mic = new p5.AudioIn();
sfft.setInput(song);
vfft.setInput(mic);
mic.start();
}
function draw() {
background(255);
sfft.analyze();
let freq = sfft.getCentroid();
vfft.analyze()
let voice = vfft.getCentroid();
// let vol = mic.getLevel();
// let x = (int)(map(vol, 0, 0.001, 0, 10));
// //puts volume on a scale of 0 - 100
// console.log(x);
fill(0, 0, 100, 80);
ellipse(400, 400, freq);
fill(0, 0, 100, 50);
ellipse(400, 400, voice);
console.log(freq);
console.log(voice);
}