Skip to content

Instantly share code, notes, and snippets.

@kasthor
Created March 20, 2021 06:12
Show Gist options
  • Save kasthor/c6cfd07eb6f119b8a8a207fedcfcde58 to your computer and use it in GitHub Desktop.
Save kasthor/c6cfd07eb6f119b8a8a207fedcfcde58 to your computer and use it in GitHub Desktop.
let fft, mic, waveform, spectrum;
function setupAudio(){
userStartAudio();
mic = new p5.AudioIn();
mic.start();
fft = new p5.FFT(0, 2048);
fft.setInput(mic);
}
function updateAudio(){
spectrum = fft.analyze();
waveform = fft.waveform();
}
function setup() {
createCanvas(windowWidth, windowHeight);
setupAudio();
background(30);
}
function draw(){
updateAudio();
colorMode(RGB)
background(30, 1);
stroke(255);
noFill();
colorMode(HSB, 255)
translate(width/2, height/2)
rotate(frameCount);
for(let i = 0; i < spectrum.length; i++ ){
let x = map(i, 0, spectrum.length,0, width/2);
let y = map(spectrum[i], 0, 255, height/2, 0);
stroke(spectrum[i], 255, 200);
line(x, height/2, x,y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment