TITLE:: BufGrainB
summary:: Granular synthesis with sound sampled in a buffer and user supplied envelope
categories:: Libraries>JoshUGens, UGens>GranularSynthesis
related:: Classes/BufGrain, Classes/BufGrainI

DESCRIPTION::


CLASSMETHODS::

METHOD:: ar


ARGUMENT:: trigger
A kr or ar trigger to start a new grain. If ar, grains after the start of the synth are sample accurate. The following args are polled at grain creation time.

ARGUMENT:: dur
Size of the grain.

ARGUMENT:: sndbuf
The buffer holding an audio signal.

ARGUMENT:: rate
The playback rate of the sampled sound.

ARGUMENT:: pos
The playback position for the grain to start with (0 is beginning, 1 is end of file).

ARGUMENT:: envbuf
A buffer with a stored signal to be used for the envelope of the grain.

ARGUMENT:: interp
The kind of interpolation for the sampled sound in the grain (1 - none, 2 - linear, 4 - cubic).

ARGUMENT:: mul


ARGUMENT:: add




INSTANCEMETHODS::


EXAMPLES::

code::
s.boot;

(
SynthDef(\buf_grain_test, {arg gate = 1, sndbuf, amp = 1, envbuf;
	Out.ar(0,
		BufGrainB.ar(Impulse.kr(10), 0.2, sndbuf, MouseX.kr(0.5, 8), PinkNoise.kr.range(0, 1),
			envbuf, 2,
			EnvGen.kr(
				Env([0, 1, 0], [1, 1], \sin, 1),
				gate,
				levelScale: amp,
				doneAction: 2)
		)
	)
}).add;
)

s.sendMsg(\b_allocRead, x = s.bufferAllocator.alloc(1), Platform.resourceDir +/+ "sounds/a11wlk01-44_1.aiff");
z = Env([0, 1, 0], [1, 1], [10, -10]).asSignal(1024);
s.sendMsg(\b_alloc, b = s.bufferAllocator.alloc(1), 1024, 1, [\b_setn, b, 0, 1024] ++ z)
s.sendMsg(\s_new, \buf_grain_test, a=s.nextNodeID, 0, 1, \amp, 0.2, \sndbuf, x, \envbuf, b);
s.sendMsg(\n_set, a, \gate, 0);
s.sendMsg(\b_free, b);
s.sendMsg(\b_free, x);

::
