1 title:: Non-Realtime Synthesis
2 summary:: Non-realtime synthesis with binary files of OSC commands
3 categories:: Server, OpenSoundControl
4 related:: Classes/Score
6 SuperCollider 3 supports non-realtime synthesis through the use of binary files of OSC commands.
8 First create an OSC command file (i.e. a score)
10 f = File("Cmds.osc","w");
12 // start a sine oscillator at 0.2 seconds.
13 c = [ 0.2, [\s_new, \NRTsine, 1001, 0, 0]].asRawOSC;
14 f.write(c.size); // each bundle is preceeded by a 32 bit size.
15 f.write(c); // write the bundle data.
17 // stop sine oscillator at 3.0 seconds.
18 c = [ 3.0, [\n_free, 1001]].asRawOSC;
22 // scsynth stops processing immediately after the last command, so here is
23 // a do-nothing command to mark the end of the command stream.
24 c = [ 3.2, [0]].asRawOSC;
30 // the 'NRTsine' SynthDef
32 SynthDef("NRTsine",{ arg freq = 440;
34 SinOsc.ar(freq, 0, 0.2)
39 then on the command line (i.e. in Terminal):
41 ./scsynth -N Cmds.osc _ NRTout.aiff 44100 AIFF int16
43 The command line arguments are:
45 -N <cmd-filename> <input-filename> <output-filename> <sample-rate> <header-format> <sample-format> <...other scsynth arguments>
47 If you do not need an input sound file, then put "_" for the file name as in the example above.
49 For details on other valid arguments to the scsynth app see Server-Architecture.
51 This could be executed in SC as:
53 "./scsynth -N Cmds.osc _ NRTout.aiff 44100 AIFF int16 -o 1".unixCmd; // -o 1 is mono output
55 A more powerful option is to use the link::Classes/Score:: object, which has convenience methods to create OSC command files and do nrt synthesis.
60 [0.0, [ \s_new, \NRTsine, 1000, 0, 0, \freq, 1413 ]],
61 [0.1, [ \s_new, \NRTsine, 1001, 0, 0, \freq, 712 ]],
62 [0.2, [ \s_new, \NRTsine, 1002, 0, 0, \freq, 417 ]],
63 [0.3, [ \s_new, \NRTsine, 1003, 0, 0, \freq, 1238 ]],
64 [0.4, [ \s_new, \NRTsine, 1004, 0, 0, \freq, 996 ]],
65 [0.5, [ \s_new, \NRTsine, 1005, 0, 0, \freq, 1320 ]],
66 [0.6, [ \s_new, \NRTsine, 1006, 0, 0, \freq, 864 ]],
67 [0.7, [ \s_new, \NRTsine, 1007, 0, 0, \freq, 1033 ]],
68 [0.8, [ \s_new, \NRTsine, 1008, 0, 0, \freq, 1693 ]],
69 [0.9, [ \s_new, \NRTsine, 1009, 0, 0, \freq, 410 ]],
70 [1.0, [ \s_new, \NRTsine, 1010, 0, 0, \freq, 1349 ]],
71 [1.1, [ \s_new, \NRTsine, 1011, 0, 0, \freq, 1449 ]],
72 [1.2, [ \s_new, \NRTsine, 1012, 0, 0, \freq, 1603 ]],
73 [1.3, [ \s_new, \NRTsine, 1013, 0, 0, \freq, 333 ]],
74 [1.4, [ \s_new, \NRTsine, 1014, 0, 0, \freq, 678 ]],
75 [1.5, [ \s_new, \NRTsine, 1015, 0, 0, \freq, 503 ]],
76 [1.6, [ \s_new, \NRTsine, 1016, 0, 0, \freq, 820 ]],
77 [1.7, [ \s_new, \NRTsine, 1017, 0, 0, \freq, 1599 ]],
78 [1.8, [ \s_new, \NRTsine, 1018, 0, 0, \freq, 968 ]],
79 [1.9, [ \s_new, \NRTsine, 1019, 0, 0, \freq, 1347 ]],
85 You can then use code::Score.write:: to convert the above to the OSC command file as follows:
87 Score.write(x, "score-test.osc");
88 "./scsynth -N score-test.osc _ score-test.aiff 44100 AIFF int16 -o 1".unixCmd;
90 Score also provides methods to do nrt synthesis directly:
95 [0.1, [\s_new, \NRTsine, 1000, 0, 0, \freq, 440]],
96 [0.2, [\s_new, \NRTsine, 1001, 0, 0, \freq, 660]],
97 [0.3, [\s_new, \NRTsine, 1002, 0, 0, \freq, 220]],
100 o = ServerOptions.new.numOutputBusChannels = 1; // mono output
101 Score.recordNRT(g, "help-oscFile.osc", "helpNRT.aiff", options: o); // synthesize