SynthDef save OSC?

Just started out a day ago and already have a question. If I understood it all right the sc-script is interpreted to OSC codes. How can I save the resulting OSC in a file?
The idea is to take a SynthDef and write it to the memory of a microprocessor (esp8266). When the processor wakes up from deep sleep or gets some input it send the SynthDef to the server and makes it “beep”. Then cleans up afterwards.
EDIT: Sorry, not clear. I know how to write a single def to file, but how do I write a whole script to file?

You can get the binary format of synth defs in memory like this:

s.boot();

x = SynthDef('test', { Out.ar(0, DC.ar(0).poll) });

x.asBytes; // binary sc format for synth defs (same as scsynth files to disk)
s.sendMsg('/d_recv', x.asBytes); // message to send it (as a blob).

y = Synth('test');
y.free();

Or you can write them to disk and ask the server to read those files:

x = SynthDef('test2', { Out.ar(0, DC.ar(0.001).poll) });
x.store();
s.sendMsg('/d_load', Platform.userAppSupportDir +/+ "synthdefs" +/+ "test2.scsyndef");

y = Synth('test2');
y.free();

the format is the same for both commands.

1 Like

SynthDef asBytes gives you the data and “/d_recv” is the command. There are examples of that in NRT synthesis help files.

1 Like