Understanding (gong) SynthDef / using it in sclang


SynthDefs like gong sound beautiful in FoxDot. I wanted to try them in SuperCollider, but going Synth("gong") produced just a low noise hum or growl. I tried to look at the source code in osc/scsyndef/gong.scd and it seems that In.kr(bus) is used to get frequency. In short, could not make sense of the parameter settings, and could not find any arguments in sclang like Synth("gong", [freq: xxx, rate: yyy]) that would make gong sound like it does in FoxDot. Could someone explain how gong or other synthdefs work in / (are generated by) FoxDot? I looked also at
/demo/12_synthdefs.py and it seems to me that FoxDot creates its own synthdefs with python code.

Gong is defined in FoxDot in file lib/SCLang/_SynthDefs.py

But what is the structure of the SynthDef generated by that code, in terms of sclang? And are there any hints for getting the argument settings that would make gong and other synthdefs work from sclang?


Iannis Zannos

Yes, most of the FoxDot synths are defined using Python and a weird API I wrote for creating SynthDefs a few years ago. The reason is to better manage how the effects can be applied to all of the SynthDefs - although there is probably a better way. Anyway, as you saw, all FoxDot synthdefs read in frequency values using the In.kr(bus) function. That’s to allow the frequency to be modulated, e.g. by the vibrato effect. To use the SynthDef using Synth("gong") you will have to delete or comment out the In.kr(bus) line, re-evaluate the code, and supply your own frequency value like so:

Synth("gong", [\freq, 200])

For some reason you can’t run it multiple times, but it’s probably because my SuperCollider is pretty rusty.

Hello Ryan,
thanks for replying. Removing the map works as a fix.
Actually, you can map any control such as freq to a bus by sending the message map to a synth. You have to be sure that the synth has already started for this to work. I added 2 modifications to make the synthdef useable for my purposes:

  1. Use Out.ar instead of ReplaceOut. This makes it possible to start multiple gongs synths
  2. Add an adsr envelope with gate control and doneAction 2. This makes it possible to release the synth in a manner that is also compatible to playing it in patterns (eg. with Pbind).

Here is the modified version:

{|amp=1, sus=1, pan=0, freq=0, vib=0, fmod=0, rate=0, bus=0, blur=1, beat_dur=1, atk=0.01, decay=0.01, rel=0.01, peak=1, level=0.8|
	var osc, env;
	sus = sus * blur;
	// This is the original version from FoxDot
	// perhaps In.kr could be substituted with a synth.map.
	// freq = In.kr(bus, 1);
	freq = [freq, freq+fmod];
	amp=(amp * 2.5);
	freq=(freq * 2);
			[0.501, 1, 0.8, 2.002, 3, 9.6, 2.49, 11, 2.571, 3.05, 6.242, 12.49, 13, 16, 24],
			[0.002, 0.02, 0.001, 0.008, 0.02, 0.004, 0.02, 0.04, 0.02, 0.005, 0.05, 0.05, 0.02, 0.03, 0.04],
			[1.2, 1.2, 1.2, 0.9, 0.9, 0.9, 0.25, 0.25, 0.25, 0.14, 0.14, 0.14, 0.07, 0.07, 0.07]
		SinOscFB.ar(20, 0, 10), freq, (freq * rate), 4
	) * amp);
	osc = HPF.ar(osc, 440);
	// add envelope with gate to play in patterns:
	osc = Mix(osc) * Env.adsr.kr(2, \gate.kr(1)); // * 0.5 
	osc = Pan2.ar(osc, pan);
	// ReplaceOut.ar(0, osc) // further synths are muted by this
	Out.ar(0, osc); // now can start multiple synths

Note: Since you mention that there might be a better way to apply effects,
I’d be interested in discussing avenues to find a better way to apply effects with you, as I have tested techniques for doing such stuff. Let me know per direct email if you are interested.



Instead of modifying the gong synthdef you can map another synth output to gong’s in.kr bus.

Yes, my modifications aim at making this more compatible with common usage in patterns etc.
I tried using a bus but it did not work. I will try again.

Thank you for the advice.