iggy wave

dog
“Now I Wanna Be Your Dog” as a 3d landscape. I was using the minim library in processing to visualize the sound level data stream, then exporting out to rhino. Many thanks to the proxyarch team for help with the code.

 

EDIT:
Added link to processing app, see it in action (loud rock music will begin playing…so turn it up!)

 

http://gracefulspoon.com/processingapps/singlewave/index.html

 

processingapp


import processing.dxf.*;
import ddf.minim.analysis.*;
import ddf.minim.*;
FFT fftLin;
FFT fftLog;

Waveform myRects;

Minim minim;
AudioPlayer groove;

boolean record;

void setup(){
size(1000, 500, P3D);
noStroke();
minim = new Minim(this);
groove = minim.loadFile(”groove.mp3″);
groove.loop();
background(255);

fftLog = new FFT(groove.bufferSize(), groove.sampleRate());
fftLog.logAverages(22, 4); //adjust spacing here

float w = float(width/fftLog.avgSize());
float x = w;
float y = 0;
float z = 50;
float radius = 10;
myRects = new Waveform(x,y,z,radius);
}

void draw(){
background(0);
directionalLight(126,126,126,sin(radians(frameCount)),cos(radians(frameCount)),1);
ambientLight(102,102,102);

float zoom = 1000;
PVector foc = new PVector(myRects.x*0.5, myRects.y*0.5, 0);
PVector cam = new PVector(zoom*sin(radians(frameCount)), zoom*cos(radians(frameCount)), -zoom);
camera(foc.x+cam.x,foc.y+cam.y,foc.z+cam.z,foc.x,foc.y,foc.z,0,0,1);

//play the song
fftLog.forward(groove.mix);

myRects.update();

if(record){
beginRaw(DXF, “output.dxf”);
}
// DXF will export the stuff drawn between here.

myRects.plotTrace();

if(record){
endRaw();
record = false;
println(”Done DXF~!”);
}
}

void stop() {
// always close Minim audio classes when you finish with them
groove.close();
// always stop Minim before exiting
minim.stop();
super.stop();
}

class Waveform{
float x,y,z;
float radius;

PVector[] pts = new PVector[fftLog.avgSize()];

PVector[] trace = new PVector[0];

Waveform(float incomingX, float incomingY, float incomingZ, float incomingRadius){
x = incomingX;
y = incomingY;
z = incomingZ;
radius = incomingRadius;
}

void update(){
plot();
}

void plot(){
for(int i = 0; i < fftLog.avgSize(); i++){
int w = int(width/fftLog.avgSize());

x = i*w;
y = frameCount*5;
z = height/4-fftLog.getAvg(i)*10;

stroke(0);
point(x, y, z);
pts[i] = new PVector(x, y, z);

trace = (PVector[]) expand(trace, trace.length+1);
trace[trace.length-1] = new PVector(pts[i].x, pts[i].y, pts[i].z);

}
}

void plotTrace(){
/*
//drawing points
for(int i=0; i stroke(255,0,0);
//locator(trace[i].x, trace[i].y, trace[i].z, 1);
point(trace[i].x, trace[i].y, trace[i].z);
}
*/
//drawing poly surface

fill(255,20); noStroke();
//stroke(0,255,255,5);
int inc = fftLog.avgSize();

for(int i=1; i if(i%inc != 0){
beginShape(TRIANGLE_STRIP);
vertex(trace[i].x, trace[i].y, trace[i].z);
vertex(trace[i-1].x, trace[i-1].y, trace[i-1].z);
vertex(trace[i+inc].x, trace[i+inc].y, trace[i+inc].z);
vertex(trace[i-1+inc].x, trace[i-1+inc].y, trace[i-1+inc].z);
endShape(CLOSE);
}
}

//draw splines
int skip = 5;
stroke(255, 20); noFill();
for(int i=0; i beginShape();

for(int j=0; j curveVertex(trace[i+j].x, trace[i+j].y, trace[i+j].z);
}
endShape();
}
}
}

void keyPressed() {
// use a key press so that it doesn’t make a million files
if (key == ‘r’) record = true;
}

void locator(float x, float y, float z, float sc){
line(x-sc,y,z,x+sc,y,z);
line(x,y-sc,z,x,y+sc,z);
line(x,y,z-sc,x,y,z+sc);
}

8 Responses to “iggy wave”

  1. curiouser Says:

    beautiful. I am getting an unexpected character (\) at the groove.mp3 file line. I have the newest minim lib and renamed my audio file appropriately. Any ideas? write back at gabriel at gabrielmathews dot com…

    Thanks!

  2. admin Says:

    Thanks for the comment. So, what I hope is happening here is one of two things:

    Thing 1: When you copy text from a doc file or website or whatever into the processing app it converts all the quotation marks into a character set that processing can’t recognize (Processing only knows vertical quotation marks, whereas notepad uses a different character for an opening and a closing mark). The solution would be to simply retype each quotation mark in processing.
    Thing 2: Whatever the mp3 file is called, make sure you change it to the more generic “groove.mp3.” It could be that processing can’t find the file so double check that it is in the same root folder as the processing file.

    If neither of those get it working, let me know,
    best,
    John

  3. Phil Says:

    Hey John,

    I just stumbled accross your page, and i thought this looked amazing, so i wanted to try it out.

    but im getting an error:

    processing.app.debug.RunnerException: unexpected token: i

    on the first line of this setion:

    for(int i=1; i if(i%inc != 0){
    beginShape(TRIANGLE_STRIP);
    vertex(trace[i].x, trace[i].y, trace[i].z);
    vertex(trace[i-1].x, trace[i-1].y, trace[i-1].z);
    vertex(trace[i+inc].x, trace[i+inc].y, trace[i+inc].z);
    vertex(trace[i-1+inc].x, trace[i-1+inc].y, trace[i-1+inc].z);
    endShape(CLOSE);
    }

    appologies if this is a silly question, im very new to processing, just playing around really.

    Cheers,
    Phil.

  4. John Locke Says:

    Hi Phil,
    One of the vagaries of processing is that it doesn’t like to copy and paste text and that’s most likely what’s going on here. Anyway, a better way to share code is probably to actually link to the processing app, so that’s here: http://gracefulspoon.com/processingapps/singlewave/index.html the code should remain formatted and provide a better means to investigate. Let me know if it’s still not working for you. best, john

  5. Phil Says:

    That’s working perfectly now, thanks so much for your help!
    Phil.

  6. Alex Hinds Says:

    Hi,
    I’m just trying processing for the fisrt time and i’m not sure why but when it gets to
    Waveform myRects;
    is says it cant find it. Why is this happening?

    Thanks,
    Alex

  7. Alex Says:

    Hi, I’ve been trying to find out how to create your image above and I’m having few problems, it keeps coming up with the following error message and when i hit play the screen is blank white. Do you know what i can do to fix it?

    Exception in thread “Animation Thread” java.lang.NullPointerException
    at ddf.minim.javasound.JSMinim.getAudioInputStream(JSMinim.java:604)
    at ddf.minim.javasound.JSMinim.getAudioRecordingStream(JSMinim.java:200)
    at ddf.minim.Minim.loadFile(Minim.java:357)
    at ddf.minim.Minim.loadFile(Minim.java:341)
    at sketch_mar01a.setup(sketch_mar01a.java:45)
    at processing.core.PApplet.handleDraw(PApplet.java:1402)
    at processing.core.PApplet.run(PApplet.java:1327)
    at java.lang.Thread.run(Thread.java:619)

    Thanks, Alex

  8. John Locke Says:

    Hi Alex, looks like either the minim library isn’t loaded into processing or you’re missing an audio file named “groove.mp3″ in your data folder. If that doesn’t help, try to download a .rar with the processing file and mp3 from here: gracefulspoon.com/processingapps/waveform_landscape04.rar If that still doesn’t work let me know.
    best, John

reply