// init buffer b
a= Array.fill(40,{arg i; if(i.odd,{if(0.6.coin,{[0,exprand(0.005,0.05)]}, {[8,rrand(0.1,1.0),9,2*rrand(0,12)]})},{[rrand(1,6),[exprand(0.1,1.0),rrand(0.1,1.0),exprand(0.01,0.2)].choose]}); }).flatten;
b=Buffer.sendCollection(s, a, 1);



Ndef(\innoiz1).play
Ndef(\innoiz1).fadeTime = 5;

( // def the task function
~instruct = {
	inf.do {
		a = Array.fill(30, {
			arg i;
			if( i.odd,
				{ if( 0.6.coin,
					{ [0,exprand(0.005,0.05)] },
					{ [8, rrand(0.1,1.0), 9, 2*rrand(0,12)] } )
				},
				{ [rrand(1,6),
					[exprand(0.1,1.0),rrand(0.1,1.0),exprand(0.01,0.2)].choose
				] }
			);
		}).flatten;
		b.sendCollection(a);	
		exprand(0.01,1).wait;
	}
}
)
(

// continuously change/fill buffer with instructions
t=Task(~instruct).play;

// stop filling
t.stop;


(// play Instructions with PitchShift and more
Ndef(\innoiz1, {

	var snd;
	snd = Instruction.ar(b.bufnum);
	snd = PitchShift.ar(in: snd,
		//windowSize: 1/7.55,
		windowSize: 0.3,
		//pitchRatio: 2,
		pitchRatio: LFNoise1.kr([0.5,1]).exprange(0.2,4),
		pitchDispersion: 0.05,
		timeDispersion: 0.44 );
	snd = snd * (LFPulse.ar(LFNoise1.kr(1).range(1,16)).range(LFNoise1.kr(0.2).range(0.8,1),1));
	
	snd = Splay.ar(snd,
		spread: LFNoise2.kr(LFNoise0.kr(LFNoise0.kr(0.1,1)).range(0.1,10)).range(0,1),
		center: LFNoise1.kr(LFNoise0.kr(LFNoise0.kr(0.1,1)).range(0.1,10)).range(-1,1));

	//snd = LPF.ar(snd, 10000);
	snd = BHiShelf.ar(snd, 3000, 1, db:12);
	snd = BLowShelf.ar(snd, 500, 1, db:12);
	snd = HPF.ar(snd, 20);
	//snd = BPF.ar(snd, LFNoise1.kr(0.1).exprange(100,10000), 1);
	snd = snd.clip2(0.9);
	//snd = snd * LFPulse.kr(LFNoise0.kr(0.2).exprange(0.1,1), width:0.05);
	snd = (CombN.ar(snd, 1, [0.55,0.77] * LFNoise1.kr(0.1).range(0.99,1.01), 2, mul:0.1)) + snd;
	

	snd;

})
)


