(
SynthDef(\noiseCrackle, { // play // 

/* A noise generator based on a chaotic function.
Class Methods
Crackle.ar(chaosParam: 1.5, mul: 1.0, add: 0.0)
Crackle.kr(chaosParam: 1.5, mul: 1.0, add: 0.0)

Arguments:

chaosParam - A parameter of the chaotic function with useful values
from just below 1.0 to just above 2.0. Towards 2.0 the sound crackles.

mul	- Output will be multiplied by this value.
add	- This value will be added to the output.     *********************/

// TODO:
// expand on more arguments?

	arg out = 0, amp = 0.9, gate = 1, lpfa=1, hpfa=1, fadeTime=1;
	var sig, par, lpf, hpf, env;

	par = LFNoise1.kr(0.09).range(1.9,2.02);
	
	sig = Crackle.ar(par);

	lpf = RLPF.ar(
		in: sig,
		freq: Lag3.kr(LFNoise0.kr(0.08).exprange(50,10000),10),
		rq:0.8,
		mul: lpfa);

	hpf = RHPF.ar(
		in:   sig,
		freq: Lag3.kr(LFNoise0.kr(0.065).exprange(50,10000),10),
		rq:   0.8,
		mul: hpfa);
	hpf = DelayN.ar(in:hpf, delaytime:0.11);

	sig = lpf + hpf;

	// a fade-in/out envelope
	env = EnvGen.kr( Env([0, 1, 0], [fadeTime, fadeTime], \sin, 1),
        gate, doneAction: Done.freeSelf);
	
	sig = sig * env * amp;
	
	Out.ar(out, sig);
}).add;
);




