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.
IndexProgramming Questions & HelpSound,  Music Libraries › Csound, OscP5 and MovieMaker
Page Index Toggle Pages: 1
Csound, OscP5 and MovieMaker (Read 756 times)
Csound, OscP5 and MovieMaker
Sep 8th, 2008, 8:45pm
 
Hi Folks:

I am trying to make a movie using Csound and Processing.  Csound generates sound events, some of which are accompanied by an OSC message to Processing.  On the Processing side, every message received will draw a circle whose width is related to the osc param passed in from csound.

It looks great on screen, but doesn't once I introduce the moviemaker class.  I know I should expect latency when generating video, so I'm wondering what my options are in generating accurately-timed video from osc messages. I don't need it to render correctly in realtime, I just want the video to come out with correct timing.  My processing code is below.  If I leave the MovieMaker lines commented out, the onscreen rendering is correct.  If I uncomment them, the timing is off and the graphics drawn in my OSCMessage handler seem to be cached and drawn all at once, every 8 messages or so.  Does that make sense?

import processing.video.*;
import oscP5.*;
import netP5.*;

MovieMaker mm;  
OscP5 oscP5;
NetAddress myRemoteLocation;
int index = 0;
void setup() {
 size(720, 480);
 frameRate(25);
 OscProperties properties = new OscProperties();
//  mm = new MovieMaker(this, width, height, "drawing.mov");
 properties.setRemoteAddress("localhost",12000);
 properties.setListeningPort(12000);
 properties.setDatagramSize(1024);
 oscP5 = new OscP5(this,properties);
 background(0);  
}


void draw() {
//  mm.addFrame();
 
}

/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
   OscArgument arg = theOscMessage.get(0);
   int i = arg.intValue() * 10;
 int x = int(random(width));
 int y = int(random(height));
 ellipse(x, y, i, i);
}

-=-=-
I'm a programmer, so I dug into the Processing source.  I wonder if my best option is to some slave Processing's view of time (it's system time in most spots I saw in the code) to Csound's view of time?  It's kind of analogous to a Clock Source in MIDI or Digital Audio..  
Thoughts?  Thanks people!
Re: Csound, OscP5 and MovieMaker
Reply #1 - Sep 8th, 2008, 10:48pm
 
What I'd do is create two states for your app -- one the "listen to OSC messages in realtime and record what I hear" state, and the other the "render the movie" state. Then you'll have your app do them in sequence, so it can take its time on the movie rendering w/out worrying about missing OSC messages.

So, I see you're listening for OSC messages that assign variables x, y, and i. I'd create arrays of ints up top --

int[] x;
int[] y;
int[] i;
int TOTAL_NUMBER_OF_FRAMES = (whatever you want);

-- and then in your setup function, initialize them all:

x = new int[TOTAL_NUMBER_OF_FRAMES];
y = new int[TOTAL_NUMBER_OF_FRAMES];
i = new int[TOTAL_NUMBER_OF_FRAMES];

Then, in the "listen" mode of your app, you'll use these functions:

void drawListen() { // listen mode
// nothing!
}

void oscEvent(OscMessage theOscMessage) { // listen mode
 OscArgument arg = theOscMessage.get(0);
 i[frameCount] = arg.intValue() * 10;
 x[frameCount] = int(random(width));
 y[frameCount] = int(random(height));
}

Then, create ANOTHER draw function for drawing mode, which will be something like:

void drawRender() { // render mode
 ellipse(x[frameCount], y[frameCount], i[frameCount], i[frameCount]);
 mm.addFrame();
}

So now you have two different draw() functions -- one for when you want to just record OSC as fast as possible, and another for when you want to actually render the movie.

Now you just need a way to switch between them. So your new draw() function is:

void draw() {
 if (frameCount < TOTAL_NUMBER_OF_FRAMES) {
   drawListen();
 } else {
   drawRender();
 }
 
 if (frameCount > (TOTAL_NUMBER_OF_FRAMES*2)) {
   mm.finish();
   exit();
 }    
}

There's a lot more you could do to, for instance, sync the beginning of the "listen mode" w/ the start of whatever OSC performance you're using... but this should get you started.

Let me know if that makes sense!
Re: Csound, OscP5 and MovieMaker
Reply #2 - Sep 9th, 2008, 12:37am
 
P.S. Don't literally use that code. There is almost certainly a spot somewhere where an array gets accessed out-of-bounds or something. But I think the concept is sound.
Re: Csound, OscP5 and MovieMaker
Reply #3 - Nov 15th, 2008, 11:44pm
 
Thanks for the nudge Robin - I wasn't sure if I was missing some other way to do it.  I built my own Csound event cache and have a rudimentary experiment up at

http://www.vimeo.com/2172394

Once I finish experimenting and get a solid bit of code in place, I'll post it and likely write it up for the Csound journal.  Anyone who's curious can write me for the bit of code I do have at

ben at listenfaster.com

Thanks again -
b
Page Index Toggle Pages: 1