Created
November 7, 2023 17:55
-
-
Save nrrb/cf3933ea654c3c337b3c0801f90d91a3 to your computer and use it in GitHub Desktop.
Scrolling Spectrogram in Processing using Sound library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.sound.*; | |
FFT fft; | |
AudioIn in; | |
int bands = 512; | |
float[] spectrum = new float[bands]; | |
void setup() { | |
size(512, 600); | |
background(255); | |
// Create an Input stream which is routed into the Amplitude analyzer | |
fft = new FFT(this, bands); | |
in = new AudioIn(this, 0); | |
// start the Audio Input | |
in.start(); | |
// patch the AudioIn | |
fft.input(in); | |
} | |
void draw() { | |
if(frameCount % height == 0) { | |
background(255); | |
} | |
fft.analyze(spectrum); | |
stroke(0, 0, 0, 10); | |
for(int i = 0; i < bands; i++){ | |
// The result of the FFT is normalized | |
line(i, (height + frameCount)%height, i, (height + frameCount)%height - spectrum[i]*height*100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment