Audio Reactive Sphere

Hey all

I made this, mostly as a learning exercise in working with FBO’s and shaders.

You can take a look at the source here

As it was an exercise I would greatly appreciate any comments on my approach. In particular I am not sure how I got the audio data was the best way to do it. I use ofGetSoundSpectrum() the get the raw data, map that to the bark scale the use ofPath to make an interpolated curve, which I then pass as a texture to the shader. I feel like using ofPath is overkill, but I am still kinda new to this whole thing.

Thanks for taking a look

1 Like

What do you think? What is the best way to get a nice curve for a series of points?

Thanks arturo!

this is really nice. just got hold of the latest oF, and am doing visuals more and more lately for people, but i use jitter [as in max 6]. but it seems the best way to go really in terms of heavy duty visuals.

have taken your file and going to have a gander at it. thanks very much indeed. looks really good.

Hey thanks! Let me know if you have any questions or anything, im glad its finding some use :slight_smile:

alright man,

i have come back again to oF [is this good or bad for my vitamin D deficiency? ;)]
and got hold of your code again also thanks for adding some extra files in to mess around with. but am running into a problem under xcode 4.6 and mountian lion.
i have built it under 10.6sdk but there are still problems
it did run great under snow leopard, but problems happen under 10.8

here is a screenshot of the audio_sphere one. i ran into other problems as well with the other ones. they all have screenshots of what is wrong.

but other than that, i really appreciate all of this

![]( Shot 2013-02-01 at 15.37.32.png)

![]( Shot 2013-02-01 at 15.39.46.png)

![]( Shot 2013-02-01 at 15.45.58.png)

Hey leed. Copy ‘audio_sphere’ folder project and paste inside ‘/of_0073/apps/myApps/’

Thanks Dorald, I just tried with a version from git and that worked for me, let us know how you go leed.

It’s running like a dog though for some reason, ill try figure out whats going on.

I’m not sure why it is running so slow, I’m pretty sure this would run at 150 fps+ when i published it. The verts are more or less static, and only ~360k which is less than the dejong thing, and the shaders for this are a lot simpler. Instead it runs at ~8fps :confused:

[edit] dropping res to 250 gives less verts and better fps

aye, i realised that it was not a folder deep, but 2. silly mistakes i need to get used to.
but it is really running slow. stuck a fps monitor on, and the sphere one is going at about 15fps.
but am having trouble with the other ones still.

for the sphere one, you can also comment out/delete the line


approx line 359.

What did you set res at? 250? (line 49) you end up with roughly (res * 2)^2 verts, the more verts the slower it will be. Knowing what I know now there is probably a better way to do it.

For the attractor one, a couple of things might be up:

  1. I built it in a subdirectory of myApps, so the paths are off. This is my mistake. It is fixable manually but its a bit of a pain, I have put a new version up on github that has been built in myApps. You might be able to get away with putting it in a sub directory, e.g. myApps/pete/attractor_field/ but not sure.

  2. can you make sure the addons and oF stuff are being found correctly? In xcode if you click the grey arrows in the project navigator make sure none of the file names are in red.

Again this is probably a side effect of me being silly and having it in a subdirectory. If they are red, right click the folder (eg ofxBlur, ofxOpenCv etc), click delete, click remove references, then in finder navigate to your oF addons folder and drag the addon to xcode project navigator and put it under the addons section. I think if you check out the new version from github the addons should turn up as expected (assuming u have them installed).

I’m not sure what is up with the parallel reduction one, as its a really simple one. it should be runnable from the myApps directory.

Thanks for sticking with this.


got hold and tried the new, updated files and all is working good. again, thank you for your assistance and help, and more so for the shared files to play with.

i do have a vj gig this weekend and was going to edit your sphere patch some for it, still dont know whether to or not. need to put osc in and some other things. just so you know that i might use it.
will send pictures and anyone who asks about the sphere to you.

hey cool, glad its working.

I’m pretty open to making changes so it can be used more interactively, though getting it running by the weekend might be a stretch.

I also dont really know what is required in terms of signal flow. I assume you would get a line out from the dj mixer and plug it in to your machine and the reactive stuff would work off that? How would you like to see OSC added to it?

A shortcoming in oF (imo) is that there’s not a lot of middle ground for audio, so its either playing a static sound file with ofSoundPlayer which has a the nice ofGetSoundSpectrum(), or opening a device w/ofSoundStream and reading the raw audio data which can get kinda involved pretty quickly. It’s either really low level or really high level.

What would be nice is something like ofSoundStream that has getSoundSpectrum() or some equivalent, so you could get a line in from the mixer to your audio device, open that in the oF app and go from there. Am open to suggestions here.

oh i was going to do the osc and audio in stuff. i have everything-ish of what i need for it so will get with trying to something for the sphere one.
though my time is scarce right now, but im willing to get this done. could even put the sphere example as a full working suite later on with connectivity for vjs on github afterwards? a bit like a dev page.

for the audio, you could do a simple ‘whatever audio interface is plugged, that will be the main one’ type thing. much like the microphone input.
but ill look into this today, i need an oF project to take apart. just got to pick up a 20m vga cable today, then im free for my vitamin D levels to drop more in oF :wink:

right, got my cable, and a few ideas.
im gonna look into ofxUI and ofxOSC for the audio sphere

ill be doing the osc in lemur

im trying out openframeworks and want to make something like this, trying your example i get a few errors

i have no clue what assermacros.h is.
hope somebody can help me resolve these problems, i would like to test this code out.

it might be simpler to copy the code of the ofApp.cpp and ofApp.h of the example to a new project and see what happens then …

thanks, tried it the first time but since my new files are called ofapps testapps didn’t work, fixed the problem now it works fine ty for code and quick reaction

great !you can use the project generator to import and old project and it gets updated to the new vs

i don’t fully understand how the sphere is build, mainly because i never did this and the variables have difficult names i don’t know what they do maybe somebody can explain this to me a bit.
also what does normal, tcord and vertex do in this code?

void testApp::buildSphereMesh(int radius, int res, ofMesh & sphereMesh) {

int n = res * 2;
float ndiv2=(float)n/2;

 Original code by Paul Bourke
 A more efficient contribution by Federico Dosil (below)
 Draw a point for zero radius spheres
 Use CCW facet ordering

float theta2 = TWO_PI;
float phi1 = -HALF_PI;
float phi2 = HALF_PI;
//    float r = 1.f; // normalize the verts
float r = radius;


int i, j;
float theta1 = 0.f;
float jdivn,j1divn,idivn,dosdivn,unodivn=1/(float)n,t1,t2,t3,cost1,cost2,cte1,cte3;
cte3 = (theta2-theta1)/n;
cte1 = (phi2-phi1)/ndiv2;
dosdivn = 2*unodivn;
ofVec3f e,p,e2,p2;

if (n < 0){
    n = -n;
    ndiv2 = -ndiv2;
if (n < 4) {n = 4; ndiv2=(float)n/2;}
if(r <= 0) r = -r;


ofVec3f vert, normal;
ofVec2f tcoord;

for (j=0;j<ndiv2;j++) {
    t1 = t2;
    t2 += cte1;
    t3 = theta1 - cte3;
    cost1 = cost2;
    cost2 = cos(t2);
    e.y = sin(t1);
    e2.y = sin(t2);
    p.y = r * e.y;
    p2.y = r * e2.y;
    for (i=0;i<=n;i++) {
        t3 += cte3;
        e.x = cost1 * cos(t3);
        e.z = cost1 * sin(t3);
        p.x = r * e.x;
        p.z = r * e.z;
        normal.set( e.x, e.y, e.z );
        tcoord.set( idivn, jdivn);
        vert.set( p.x, p.y, p.z );
        e2.x = cost2 * cos(t3);
        e2.z = cost2 * sin(t3);
        p2.x = r * e2.x;
        p2.z = r * e2.z;
        normal.set(e2.x, e2.y, e2.z);
        tcoord.set(idivn, j1divn);
        vert.set(p2.x, p2.y, p2.z);
        idivn += unodivn;

Anyone have any luck getting this example working in the Visual Studio?

I’d love to work into this patch for a gig next weekend, but I’m getting the following errors…