(
SynthDef(\klank, {
	|out=0, i_freq|
	var klank, n, harm, amp, ring;

	harm = \harm.ir(Array.series(4, 1, 1).postln);
	amp = \amp.ir(Array.fill(4, 0, 0.5));
	ring = \ring.ir(Array.fill(4, 1));

	klank = Klank.ar(`[harm, amp, ring], {ClipNoise.ar(0.003)}.dup, i_freq);
	Out.ar(out, klank);
}).add;
)

Synth(\help_Klank, [\i_freq, 70, \harm,Array.geom(1, -1, 4), \amp]);




// -- overlap texture 2
(
SynthDef("help-KlankOverlapTexture2",
{|out = 0, freqs = #[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], rings = #[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], atk = 5, sus = 8, rel = 5, pan = 0|
    var e = EnvGen.kr(Env.linen(atk, sus, rel, 1, 4), doneAction: Done.freeSelf);
    var i = BrownNoise.ar(0.0012);
    var z = Klank.ar(
        `[freqs, nil, rings],     // specs
        i                    // input
    );
    Out.ar(out, Pan2.ar(z*e, pan));
}).add;

r = Routine{
    var sustain = 6, transition = 4, overlap = 5;
    var period = transition*2+sustain/overlap;
    0.5.wait;            // wait for the synthdef to be sent to the server
    inf.do {
        Synth("help-KlankOverlapTexture2", [
            \atk, transition,
            \sus, sustain,
            \rel, transition,
            \pan, 1.0.rand2,
            \freqs, {1000.0.linrand+80}.dup(12),
			\rings, {0.1.rrand(1)}.dup(12)
        ]);
        period.wait;
    }
};
r.play;
)



// -- overlap texture 3
(
SynthDef("help-KlankOverlapTexture3",
{|out = 0, freqs = #[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], rings = #[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], pan = 0|
    var e = EnvGen.kr(Env(#[1, 1, 0], #[18, 3]), doneAction: Done.freeSelf);
    var i = Decay.ar(Impulse.ar(Rand(0.2, 0.6)), 0.8, ClipNoise.ar(0.001));
    var z = Klank.ar(
        `[freqs, 2, rings],     // specs
        i                    // input
    );
    Out.ar(out, Pan2.ar(z*e, pan));
}).add;

r = Routine{
    0.5.wait;            // wait for the synthdef to be sent to the server
    inf.do {
        Synth("help-KlankOverlapTexture3", [
            \pan, 1.0.rand2,
            \freqs, {12000.0.linrand+80}.dup(12),
            \rings, {3.rrand(10)}.dup(12)
        ]);
        3.wait;
    }
};
r.play;
)

r.stop;