This is a quick little audio visualizer I put together with Processing and the ESS Sound Library. The audio spectrum is analyzed with an FFT and spectrum bands are plotted as vertical bars. The Waveform is drawn over the bars in white, adding a lot of interest to the image. To create the fading effect of the object a transparent, white rectangle is drawn over the whole sketch instead of using a background. Previous frames are left on the screen and are slowly covered up by white.
To create an interesting color scheme each bar is colored based on its own height and its neighbors. Combined with the overlapping shapes a broad range of tones and hues is created.
The code isn’t perfect but I’ll share it anyway. You can see some more examples and learn more about the library on the ESS home page. Let me know if I can clarify anything.
import krister.Ess.*; FFT fft; AudioInput input; int bufferSize=256; void setup() { size(1300,400); stroke(0); noFill(); smooth(); frameRate(30); Ess.start(this); input=new AudioInput(bufferSize); fft=new FFT(bufferSize*2); input.start(); fft.damp(.3); fft.equalizer(true); fft.limits(.005,.01); background(255); } void draw() { pushStyle(); noStroke(); fill(255,50); rect(0,0,width,height); popStyle(); renderSpectrum(50, height/2, 5, 400); } public void audioInputData(AudioInput input) { fft.getSpectrum(input); } void renderSpectrum(int X, int Y, int S, int A) { pushStyle(); noStroke(); for (int i=1; i<(width-2*X)/S; i++) { float v=fft.spectrum[i]; fill((v-fft.spectrum[i-1])*200,v*200,(v-fft.spectrum[i+1])*600,30); rect((i*S)+X,Y+v*(A/2),3,v*-A); } popStyle(); pushStyle(); stroke(255,200); strokeWeight(2); noFill(); int interp=max(0,(((millis()-input.bufferStartTime)/input.duration)*input.size)); beginShape(); for (int i=0;i<(width-2*X)/S;i++) { float pos=Y; if (i+interp+1<input.buffer2.length) { pos-=input.buffer2[i+interp]*A*2; } curveVertex(X+i*S,pos); } endShape(); popStyle(); } void keyPressed() { if (key=='s') { saveFrame("waveform-####.png"); } }
If your not getting any errors it’s probably an issue with your audio input. The script checks for the default audio input. My computer has in internal microphone. Check the sound settings in your system preferences and make sure it’s picking something up and the input volume is turned up.
If your still not getting anything you can try scaling up the signal within processing by increasing the fourth parameter of the renderSpectrum function (currently 400) within the draw loop. Other than than that it might help to yell at your computer.
Thanks. It was my audio input.
For others having a problem with this example:
for the ESS library – make sure you restart processing after you extracted
for the audio input in windows – turn on/unmute stereo mix as input, in volume settings.
proudly powered by wordpress v2.8 & jquery javascript library.
View all resources in the colophon.
website & all work creative commons by-nc anthony mattox (2007-09)
pragmatically validated xhtml 1.0 transitional & css thanks w3c
Some Random Dude
[...] Audio spectrum visualization in Processing by Anthony Mattox. [...]