xxxxxxxxxx
27
let mic = new Tone.UserMedia();
let fft = new Tone.FFT(512);
mic.connect(fft);
mic.open();
function setup() {
createCanvas(400, 100);
}
function draw() {
background(255);
let frequencyData = fft.getValue();
noStroke();
fill(0);
beginShape();
vertex(0, height);
for (let i = 0; i < frequencyData.length; i++) {
let x = map(log(i), 0, log(frequencyData.length), 0, width);
let y = map(frequencyData[i], -127, 0, height, 0);
vertex(x, y);
}
vertex(width, height);
endShape();
}