(
SynthDef("variablesine", { arg freq;
	var f, g, osc;
//	f = LFSaw.kr(0.4, 0, 24, LFSaw.kr([8,7.23], 0, 3, 80)).midicps; // glissando function
//	osc = CombN.ar(SinOsc.ar(f, 0, 0.04), 0.2, 0.2, 4) // echoing sine wave
//	osc = SinOsc.ar(freq);
//	osc = RLPF.ar(LFPulse.ar(SinOsc.kr(0.2, 0, 10, 21), 0.1), 100, 0.1).clip2(0.4);
	osc = RLPF.ar(LFPulse.ar(SinOsc.kr(freq, 0, 10, 21), 0.1), 100, 0.1).clip2(0.4);
	Out.ar(0, osc);
}).writeDefFile;
s.sendSynthDef("variablesine");
)

(
SynthDef("def", { arg freq;
	var f, g, osc;
//	osc = CombL.ar(
//		RLPF.ar(LFPulse.ar(FSinOsc.kr(0.05,0,80,160),0,0.4,0.05), 
//		   FSinOsc.kr([0.6,0.7],0,3600,4000), 0.2),
//		0.3, [0.2,0.25], 2);
	osc = CombL.ar(
		RLPF.ar(LFPulse.ar(FSinOsc.kr(freq,0,80,160),0,0.4,0.05), 
		   FSinOsc.kr([0.6,0.7],0,3600,4000), 0.2),
		0.3, [0.2,0.25], 2);
	Out.ar(0, osc);
}).writeDefFile;
s.sendSynthDef("def");
)

(
SynthDef("scratchy", { arg freq;
	var f, g, osc;
	osc = RHPF.ar(BrownNoise.ar([0.5,0.5], -0.49).max(0) * 20, 5000, 1);
	Out.ar(0, osc);
}).writeDefFile;
s.sendSynthDef("scratchy");
)

(
SynthDef("sprinkler", { arg freq;
	var f, g, osc;
	osc = BPZ2.ar(WhiteNoise.ar(LFPulse.kr(MouseX.kr(0.2,50), 0, 0.25, 0.1)));
	Out.ar(0, osc);
}).writeDefFile;
s.sendSynthDef("sprinkler");
)

Synth("variablesine", [\freq, 0.4]);

(
s.sendMsg("/s_new", "sprinkler", 1003, 1, 0, "freq", 0.6);
s.sendMsg("/s_new", "def", 1001, 1, 0, "freq", 0.4);
s.sendMsg("/s_new", "def", 1002, 1, 0, "freq", 10.7);
s.sendMsg("/s_new", "variablesine", 1003, 1, 0, "freq", 0.4);
)

// Free the nodes
(
s.sendMsg("/n_free", 1000);
s.sendMsg("/n_free", 1001);
s.sendMsg("/n_free", 1002);
s.sendMsg("/n_free", 1003);
)