32 lines
856 B
Plaintext
32 lines
856 B
Plaintext
import processing.sound.*;
|
|
SoundFile song;
|
|
Amplitude analyzer;
|
|
float[] history;
|
|
int index = 0;
|
|
// enlarge the bars
|
|
float scale = 1; // for beat.aiff
|
|
//float scale = 4; // for vibraphon.aiff
|
|
|
|
void setup() {
|
|
size(640, 360);
|
|
song = new SoundFile(this, "beat.aiff");
|
|
//song = new SoundFile(this, "vibraphon.aiff");
|
|
song.loop();
|
|
analyzer = new Amplitude(this);
|
|
analyzer.input(song);
|
|
// create an empty array of size equals width
|
|
history = new float[width];
|
|
}
|
|
|
|
void draw() {
|
|
background(255);
|
|
// update (shift array to the left)
|
|
for (int i=0; i<width-1; i++)
|
|
history[i] = history[i+1];
|
|
// save current amplitude at the last position
|
|
history[width-1] = analyzer.analyze();
|
|
// draw all recorded amplitude values
|
|
for (int i=0; i<width; i++)
|
|
line(i, height/2-history[i]*height*scale, i, height/2+history[i]*height*scale);
|
|
}
|