We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
3D spectrum analyzer (Read 3641 times)
3D spectrum analyzer
Dec 16th, 2007, 10:32pm
first post for me here, so first of all hi to all of you
i'm new to processing so let's go with the first question

i'm tryng to make a realtime 3D spectrum analyzer, something like this for those who are not in sound analysis:

i managed to draw a live input spectrum analyzer. now i think i have to repeat the spectrum line along the z axis, each line with the state of the previous one in the previous frame (ok i've been not so clear but i think you understand)

i think i have to use a class, but i've not found a good explanation of how it works.

anyway, this is the code:

import ddf.minim.*;
import ddf.minim.analysis.*;
import processing.opengl.*;

AudioInput stream;
FFT fft;

void setup()
size(800, 800, OPENGL);
stream = Minim.getLineIn(Minim.STEREO);
fft = new FFT(stream.bufferSize(), stream.sampleRate());

void draw()
camera(width, 0, (height/2.0) / tan(PI*60.0 / 360.0), width/2.0, height/2.0, 0, 0, 1, 0);


stroke(0, 255, 0, 128);

for(int i = 0; i < fft.specSize(); i=i+1)
line(i+150, height/2-(fft.getBand(i)*5), i+1+150, height/2-((fft.getBand(i+1)*5)));


void stop()

thanks for help

Re: 3D spectrum analyzer
Reply #1 - Dec 17th, 2007, 4:10am
I use LinkedList's heavily in my code,

so... Type is your class defining 1 spectrum line.

LinkedList<Type> b = new LinkedList();
//I know its complex, but I like to "reverse" my lists.
Adding an element:
b.add(element) //adds to end of list
if (b.size()>MAXIMUMZ)
b.poll(); //remove first element.

//Drawing loop:
translate(0,0,z)//Move to the farthest away line
for(Iterator<Type> itr = b.iterator(b.size()); itr.hasPrevious(); ){
itr.previous().draw(this); //object oriented method.
translate(0,0,-1) // move towards screen

If you haven't looked into setting your camera angle, you'll have to do that too if you want the stuff to turn out right...

of course, its very simple if you want to draw from you goin away too.
Re: 3D spectrum analyzer
Reply #2 - Dec 17th, 2007, 8:54am
thanks taifun, but i fear your solution is too advanced for me.
maybe a simple array of objects is enough, but i need a tutorial on class programming because it's not clear for me.

if you know a tutorial about classes or linked lists please let me know
Re: 3D spectrum analyzer
Reply #3 - Dec 17th, 2007, 2:38pm


private int modCount = 0;
private FFTLine[] spectralDisplay = new FFTLine[65];//change
public void addLine(FFTLine lin){
modCount = (modCount+1)%spectralDisplay.length;
public void drawLines(){
//modCount becomes the "front" of directional array
translate(0,0,-z);//Go to end/ front of line
for(int itr = 0; itr < spectralDisplay.length; itr++){
int actual = (modCount+itr)%spectralDisplay.length;
if (spectralDisplay[actual]!=null){
translate(0,0,1);//move for next line.

so, this should cause newly added lines to be drawn first...
Re: 3D spectrum analyzer
Reply #4 - Feb 12th, 2008, 3:47pm
I did something similar to this last year...

Essentially I had a spectrum object, which calculated and drew the line from the FFT values.  This object was then saved, and added to a list of spectrum objects.  It would then move back and fade out.  Essentially it was a particle system, but the particles were automatically generated spectrum lines.

I got an effect similar to this :
example file here : http://www.tenfiftyfour.com/aAVis/processing/motionblur_test/applicationwindows.rar
http://www.tenfiftyfour.com/aAVis/processing/motionblur_test/applicationmacosx.rar for mac users

That the sort of thing you're after ? Will try and dig up the source code if so.
Re: 3D spectrum analyzer
Reply #5 - Feb 19th, 2008, 1:32am
yes it's exactly what i tried to do
sadly i have not much time at the moment to work on it, but i'd like to study your code.
Re: 3D spectrum analyzer
Reply #6 - Feb 19th, 2008, 1:06pm

There ya go.

I'm sure there's a much better way to go about it - and I apologise if the code is a bit difficult to follow, Sort of a Frankenstien program this one, lots of little bits I added on to form the full monster.

Hope it helps.
Re: 3D spectrum analyzer
Reply #7 - Feb 19th, 2008, 3:10pm

i also did a 3d audio spectrum. this version is more intuitive to code, but less optimized. instead of array copying, a simple head location with modolus should be much faster. in this version, the incoming interpolated fft values are always put in array pos[0] and after a simple copy like array[n] = array[n-1] cycles all lists through the 3d array.

here's my applet and src : http://www.s373.net/x/audiosp3ctrum_applet


Re: 3D spectrum analyzer
Reply #8 - Feb 23rd, 2008, 1:08pm
really thanks to both, i'll study your codes and post here if i come out with something cool Wink
Page Index Toggle Pages: 1