xxxxxxxxxx
35
let song;
let fft;
let mic;
function preload(){
song = loadSound('./beat.wav');
}
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB, 360, 100, 100, 100);
mic = new p5.AudioIn();
mic.start();
//song.loop();
fft = new p5.FFT(0.0, 256);
fft.setInput(mic);
}
function draw() {
blendMode(BLEND);
background(0);
blendMode(ADD);
noStroke();
fill(255);
let spectrum = fft.analyze();
for(let i = 0; i < spectrum.length; i++){
let x = map(i, 0, spectrum.length, width/2, width);
let h = map(i, 0, spectrum.length, 0, 360);
let diameter = map(spectrum[i], 0, 255, 0, height);
fill(h, 100, 100, 5);
circle(x, height/2, diameter);
x = map(i, 0, spectrum.length, width/2, 0);
circle(x, height/2, diameter);
}
}