Openframeworks and Supercollider via osc
These last days I»ve been learning a little bit of Supercollider, which as you may know, is a software-language for synthesize sound in real time.
I may use Supercollider instead of Puredata for dealing with the installation»s sound, so these last two days I»ve been learning how to load sound files in supercollider and how to make them play from Openframeworks using OSC.
Thanks to Mark Nguyen (check his sound particles) who gave me some important help, information and good code ;), and thanks to the tutorial that Thor Magnusson (from ixi-software) made, I could end up making a basic program that communicates Openframeworks and Supercollider using OSC.
This is a video running the code:
Here is Supercollider code:
//SETUP
(
// read file into buffers
b = Buffer.read(s, "sounds/bomb.wav");
c = Buffer.read(s, "sounds/bomb3.wav");
// OSC
NetAddr.localAddr; // retrieve the current IP and port
NetAddr.langPort; // retrieve the current IP and port
// Play buffer
SynthDef(playBuf,{ arg out = 0, bufnum;
var signal;
// It is very important the 3th argument (doneAction:2) of playBuf,
// it will free the Synth. If we don"t use it we will saturate sc, becuase
// we are creating a new synth each time the ball bounce.
signal = PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum), doneAction:2);
Out.ar(out, signal ! 2)
}).load(s);
// Receive OSC and play the sound
o = OSCresponder.new(nil, "/collision", { |time, resp, msg|
if(msg[1] == "true" && msg[2] == 0){
x = Synth(playBuf, [ufnum, b.bufnum]); // we pass in the number of the buffer
};
if(msg[1] == "true" && msg[2] == 1){
x = Synth(playBuf, [ufnum, c.bufnum]); // we pass in the number of the buffer
};
}).add;
)
(
// Clean
o.remove; // remove the OSCresponder when you are done.
b.free; // free the buffer
c.free; // free the buffer
)
And here is Openframeworks code:
_