xxxxxxxxxx
115
let song, sfft, vfft, mic;
let filter;
let size; //size of voice ellipse
let pos; //position
function preload() {
song = loadSound("prototype.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();
filter = new p5.BandPass();
song.connect(filter);
mic.connect(filter);
}
function draw() {
background(255);
sfft.analyze();
let freq = (int)(sfft.getCentroid());
vfft.analyze()
let voice = (int)(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);
size = map(voice, 0, 4000, 0, 1000);
pos = map(voice, 2300, 3500, 200, 399);
// console.log(freq);
// console.log(voice);
// // fill(0, 0, 100, 50);
// // ellipse(400, 400, size);
//note C:
if (freq > 500 && freq < 540) {
// filter.res(0);
// filter.res(1200);
noStroke();
fill(0, 119, 255, 80);
ellipse(400, 400, 500);
}
// if (voice >2000 && voice < 2400){
// //C = map(voice, 0, 2400, 0, 500);
if (voice > 1000 && voice < 2400) {
fill(0, 119, 255, x);
ellipse(400, 400, size);
}
// if (voice < 2300 && voice > 1000){
// fill(0, 0, 100, 80);
// ellipse(400, pos, size);
// }if (voice > 2400 && voice < 3500){
// fill(0, 0, 100, 80);
// ellipse(400, 400, size, 500);
// }
//note E:
if (freq > 600 && freq < 670) {
noStroke();
// filter.res(400);
// filter.res(1150);
fill(255, 77, 77, 80);
ellipse(400, 400, 700);
}
//on pitch
if (voice > 2500 && voice < 4000) {
fill(255, 77, 77, 80);
ellipse(400, 400, size);
}
// }if (voice < 3500 && voice > 2300){ //flat
// fill(100, 0, 0, 80);
// ellipse(400, 400, size);
// }if(voice > 4000){
// fill(100, 0, 0, 80);
// ellipse(400, 400, size, 500);
// }
//note G
console.log(freq);
if (freq > 690 && freq < 797) {
noStroke();
// filter.res(400);
// filter.res(1150);
fill(255,255,0, 100);
ellipse(400, 400, 500);
}
}