Pass a class as an argument

hey everyone,

today I am looking for the best way to convert a sine to a saw wave,

when using wavetable

~sin = Env([-0.8,0,0.8],[1,1],[8,-8]).asSignal(1025);
	~sin = ~tf.asWavetableNoWrap;

this does not sound like the SinOsc class (more buzzy)

is there a way to do it that keep the quality of the waveform?

I am a bit reticent to use Select class as it uses volume modulation I would prefer pass the class as an argument in my pattern but it is not allowed

not trying to slide from one to the other but to have them both available in the same synth
(or is it more conventional to make 2 synths?)

thanks a lot =D

Yes, do it this way.

A SynthDef’s structure is fixed. One SynthDef where you choose the structure per note – nope, it doesn’t work that way.


really ? haha ok thanks a lot James

Yes, really.

The point might not be emphasized strongly enough in the tutorial, but SynthDef structures are set in stone. You can replace a SynthDef with a completely new definition, and this can have a different structure. You can’t write one SynthDef where the design changes dynamically.

This question comes up a lot:

  • “I’m passing a synth argument for the number of channels and it’s complaining” – changing the number of channels changes the synth structure, so nope.

  • “I’m passing an array argument and the synth doesn’t adjust to the size of the array” – same thing.

  • “I want to pass in an oscillator at runtime” – changing the structure…

  • “I have a pvcollect synth and I want it to adjust to different buffer sizes” – nope.

You can get the result, just in a different way. The following will sound exactly the same as “passing in an oscillator,” but the SynthDefs are static. It’s totally idiomatic for SC.

	{ |freq| },
	{ |freq| },
	{ |freq|, Rand(0.1, 0.5)) },
	{ |freq|, 0, Rand(0.1, 0.5)) },
	{ |freq|, freq, 1) }
].do { |oscillator, i|
	SynthDef(("synth" ++ i).asSymbol, { |out, freq = 440, decay = 0.1, pan = 0, amp = 0.1|
		var eg =, decay), doneAction: 2);
		var sig = oscillator.value(freq);,, pan, eg * amp));

var defnames = Array.fill(5, { |i| ("synth" ++ i).asSymbol });

p = Pbind(
	\instrument, Prand(defnames, inf),
	\freq, Pstutter(Pwhite(5, 20, inf).asStream, Pexprand(200, 800, inf)),
	\dur, 0.1,
	\amp, 0.1,



oh where can I find this tutorial please

I’m referring to the Getting Started tutorial, which is almost the first thing you see in the help browser window.


1 Like