RedGrain2			granular synthesis

superclass: RedGrain

Language side granulator built upon Task. Same as RedGrain but does not use OffsetOut. Should be less cpu intensive but might sound a bit more rough.

Class Methods

RedGrain2.new(server) - create granulator (stereo only for now)

Instance Methods

start(out) - starts the granulator playing on bus index out
stop - stops the granulator
pause - 
resume - 
delta_(sec) - set time between grains in seconds
buf_(buf) - select which buffer to get the grain source audio from
rate_(rate) - set grain playbackrate
pos_(percent) - set position in source buffer (1.0= end of buffer)
dur_(sec) - set grain duration in seconds
pan_(val) - set grain panning (-1 to 1)
amp_(val) - set grain amplitude
mute_(boolean) - silence grains
latency_(sec) - set bundle message latency

s.boot;

//-- prepare some buffers
~length= 1;		//segment lengths in seconds - should be the same for positions to scan correctly
~b1= RedBuffer(s, "sounds/a11wlk01.wav", 0.1, ~length);
~b2= RedBuffer(s, "sounds/a11wlk01.wav", 0.3, ~length);
~b3= RedBuffer(s, "sounds/a11wlk01.wav", 0.5, ~length);

//-- create and start the granulator object
r= RedGrain2(s);
r.buf_(~b1);
r.start;

//offset halfway into source buffer
r.pos_(0.5);

//switch buffer
r.buf_(~b2);

//cycle through buffers quickly 20 times
(
fork{
	20.do{|i| r.buf_([~b1, ~b2, ~b3].wrapAt(i)); 0.1.wait};
});

//cycle through buffers and randomise playback rate
(
fork{
	20.do{|i|
		r.buf_([~b1, ~b2, ~b3].wrapAt(i));
		r.rate_(2.0.rand2);
		0.1.wait;
	}
});

//now for something completely different
(
r.rate_(-1.7);
r.pos_(0);
r.dur_(0.2);
r.delta_({0.2.rrand(0.3)});	//delta can be a function
)

//and all of the controllers can be functions
(
r.buf_({[~b1, ~b2, ~b3].choose});
r.rate_({8.0.rand2});
r.pos_({0.1.rand});
r.dur_({0.05.rrand(0.15)});
r.pan_({1.0.rand2});
r.amp_({0.5.rrand(1.0)});
r.delta_({0.01.rrand(0.2)});
)

//quantise playbackrate
r.rate_({10.rand.round(5)});
r.rate_({10.rand.round(4)});
r.rate_({10.rand.round(3)});

//back to static amp and deltatime
r.amp_(0.3);
r.delta_(0.005);	//default
r.dur_(0.1);
r.buf_(~b1);
r.pos_(0);

//take out more and more and stop
(
fork{
	30.do{|i| r.delta_(r.delta*1.1); 0.2.wait};
	r.stop;
});