xxxxxxxxxx
49
let mic; // mic variable
let fft; //
function setup() {
createCanvas(400, 400);
mic = new p5.AudioIn(); //use p5 audio
mic.start() //start recording
fft = new p5.FFT(); //new object
fft.setInput(mic); //feed mic into fft
}
function draw() {
/*
background(220);
let level = mic.getLevel();
if (level>0.3) background(random(255));
ellipse(width/2,height/2,level*100,level*100) //visualize sound
console.log(level);
*/
/*
let bins = fft.analyze(); //1024 containers
for(let b = 0; b<bins.length; b++){
let bin = bins[b];
line(b,0,b,bin);
}
*/
/*
background(255);
let bins = fft.analyze(); //1024 containers; 0 to 22KHz
for(let b = 0; b<bins.length; b++){
let bin = bins[b];
line(b,height-bin,b,height);
}
*/
let wave = fft.waveform();
beginShape();
for(let w = 0; w<wave.length; w++){
let y = wave[w] * 200 +height/2;
vertex(w,y)
}
endShape();
}