xxxxxxxxxx
34
let mic;
let fft; // fft is = dividing sound into 1024 frequencies
function setup() {
createCanvas(1024, 400);
mic = new p5.AudioIn();
mic.start();
fft = new p5.FFT();
fft.setInput(mic);
}
function draw() {
background(255)
// let level = mic.getLevel();
// if(level > 0.1) background(random(255));
// ellipse(width/2,height/2, level *300, level * 100);
let bins = fft.analyze();
// 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();
}
// how did bin becomes the wave?
// --> the wave and the frequency time to each other so the wave is bigger
// eventually add up will be max to 1 and min is -1