Files
sunny9898/task8/wk9/wk9_example_4/wk9_example_4.pde
louiscklaw 5637fbf94f update,
2025-02-01 02:07:58 +08:00

27 lines
655 B
Plaintext

// Based on example at https://processing.org/reference/libraries/sound/FFT.html
import processing.sound.*;
SoundFile song;
FFT fft;
int bands = 512;
float[] spectrum = new float[bands];
int scale = 20;
void setup() {
size(512, 360);
background(255);
song = new SoundFile(this, "vibraphon.aiff");
song.loop();
fft = new FFT(this, bands);
fft.input(song);
}
void draw() {
background(255);
fft.analyze(spectrum);
for(int i = 0; i < bands; i++){
// The result of the FFT is normalized
// draw the line for frequency band i scaling it up to get more amplitude
line( i, height, i, height - spectrum[i]*height*scale );
}
}