Chapter 5 - Recreating the beep Synth
Make it work in SuperCollider
The way to do this is to get your synth working in SuperCollider first before you save it as a SynthDef and start using it in Sonic Pi.
Let’s look at some simple sounds:
{SinOsc.ar(440, 0, 0.2)}.play;
This will give us a continuous sound.
You can assign this to a variable and invoke play on it:
(f = {SinOsc.ar(440, 0, 0.2)};
f.play;)
You don’t have to wrap it in a scope ie ( and ).
Similarly when we define Synths using SynthDef we have saved them as a compiled thing with:
(SynthDef("somesynth",{
...
super collider code
...
}).writeDefFile("/Users/gordonguthrie/.synthdefs"))
We can swap out the writeDefFile method with the add method like so:
(SynthDef("somesynth",{
...
super collider code
...
}).add;)
We can then create a new instance of it and assign it to a variable:
a = Synth.new("somesynth");
We can pass in different values in the call to create it:
a = Synth.new("somesynth", [note: 85, release: 6, pan: 0.3, amp: 0.3]);
(This is what happens when you use the play command in Sonic Pi.)
And we can control it. First invoke the synth with a long duration:
a = Synth.new("somesynth", [note: 64, release: 60]);
then while it is playing use set to control it:
a.set("note", 75);
a.set("amp", 0.5);
Unsurprisingly set is what Sonic Pi uses under the covers to control SuperCollider synths.
