0

If you have a function definition:

{ SinOsc.ar(440, 0, 0.2) }.play;

The equivalent is:

SynthDef.new("SinOsc", { Out.ar(0, SinOsc.ar(440, 0, 0.2)) }).play;

for stereo, you simply say:

SynthDef.new("SinOsc", { Out.ar([0,1], SinOsc.ar(440, 0, 0.2)) }).play;

What if you want to do this:

{ [ Mix( [ SinOsc.ar(440, 0, 0.2) ] ),  Mix( [ Saw.ar(662,0.2) ] ) ] }.play;

What would be the SynthDef equivalent? Besides, is there a more elegant way to define the function above?

Dionysis
  • 804
  • 8
  • 25
Rithesh
  • 199
  • 7

2 Answers2

3

The SynthDef equivalent is just to wrap it in a synthdef (and add an Out.ar), very similar to what you already wrote:

 { [ Mix( [ SinOsc.ar(440, 0, 0.2) ] ), Mix( [ Saw.ar(662,0.2) ] ) ] }.play;

 SynthDef("crazycats", { Out.ar(0, [ Mix( [ SinOsc.ar(440, 0, 0.2) ] ), Mix( [ Saw.ar(662,0.2) ] ) ]) }).add;
 Synth("crazycats");

In your question you wrote SynthDef(...).play which isn't really the right thing to do. That's why I wrote two lines above - one line to define the SynthDef, one to instantiate it.

And you don't need those Mix objects since there's only one oscillator in each, so simplify

 { [ Mix( [ SinOsc.ar(440, 0, 0.2) ] ), Mix( [ Saw.ar(662,0.2) ] ) ] }.play;

to

 { [ SinOsc.ar(440, 0, 0.2), Saw.ar(662,0.2) ] }.play;

so the synthdef is better as

 SynthDef("crazycats", { Out.ar(0, [ SinOsc.ar(440, 0, 0.2) , Saw.ar(662,0.2) ]) }).add;
 Synth("crazycats");
Dan Stowell
  • 4,618
  • 2
  • 20
  • 30
  • Thankyou! That cleared a few things for me. But why am I getting an error on this: ( SynthDef("crazycats", { Out.ar(0, [ SinOsc.ar(440, 0, 0.2) , Saw.ar(662,0.2) ]) }); Synth("crazycats"); ) *** ERROR: SynthDef crazycats not found FAILURE IN SERVER /s_new SynthDef not found – Rithesh Jan 09 '16 at 17:22
0

So, declaring a stereo out, such as:

{ [ SinOsc.ar( 440, 0, 0.2), Saw.ar( 662, 0.2) ] }.play;

can be rewritten using SynthDef as:

SynthDef( "crazy cats", Out.ar( 0, [ SinOsc.ar( 440, 0, 0.2), Saw.ar( 662, 0.2) ] ) ).add;

Synth("crazy cats");

The advantage here being that, now we have the synth defined in the server. So, we may just assign the synth called "crazy cats" to any variable and use it. This is however not the case with functions, as every time you call it, it is being re-evaluated.

Thanks to @Dan S for the answer!

Rithesh
  • 199
  • 7