oneShot: free the responder before running user func (avoid error)
[supercollider.git] / HelpSource / Classes / TGrains.schelp
blob47d313a3c6b01bb55d9e052534824f8e94f10443
1 class:: TGrains
2 summary:: Buffer granulator.
3 categories::  UGens>Buffer, UGens>Generators>Granular
5 Description::
6 Triggers generate grains from a buffer. Each grain has a Hanning envelope
7 formula::
8 (sin2(x) for x from 0 to π)
9 ::
10 and is panned between two channels of multiple outputs.
12 classmethods::
14 method::ar
16 argument::numChannels
17 Number of output channels.
19 argument::trigger
20 At each trigger, the following arguments are sampled and used as
21 the arguments of a new grain. A trigger occurs when a signal
22 changes from non-positive to positive value.
24 If the trigger is audio rate then the grains will start with
25 sample accuracy.
27 argument::bufnum
28 The index of the buffer to use. It must be a one channel (mono)
29 buffer.
31 argument::rate
32 1.0 is normal, 2.0 is one octave up, 0.5 is one octave down -1.0
33 is backwards normal rate… etc.
35 argument::centerPos
36 The position in the buffer in seconds at which the grain envelope
37 will reach maximum amplitude.
39 argument::dur
40 Duration of the grain in seconds.
42 argument::pan
43 A value from -1 to 1. Determines where to pan the output in the
44 same manner as 
45 link::Classes/PanAz:: .
47 argument::amp
48 Amplitude of the grain.
50 argument::interp
51 1, 2, or 4. Determines whether the grain uses (1) no
52 interpolation, (2) linear interpolation, or (4) cubic
53 interpolation.
56 Examples::
58 code::
60 s = Server.internal;
61 Server.default = s;
62 s.boot;
65 s.sendMsg(\b_allocRead, 10, "sounds/a11wlk01.wav");
69         var b = 10, trate, dur, rate;
70         trate = MouseY.kr(2,200,1);
71         dur = 4 / trate;
72         rate = Dseq([10, 1, 1, 0.5, 0.5, 0.2, 0.1], inf);
73         TGrains.ar(2, Impulse.ar(trate), b, rate, MouseX.kr(0,BufDur.kr(b)), dur, Dseq([-1, 1], inf), 0.1, 2);
74 }.scope(zoom: 4);
79         var b = 10, trate, dur, clk, pos, pan;
80         trate = MouseY.kr(8,120,1);
81         dur = 12 / trate;
82         clk = Impulse.kr(trate);
83         pos = MouseX.kr(0,BufDur.kr(b)) + TRand.kr(0, 0.01, clk);
84         pan = WhiteNoise.kr(0.6);
85         TGrains.ar(2, clk, b, 1, pos, dur, pan, 0.1);
86 }.scope(zoom: 4);
89 // 4 channels
92         var b = 10, trate, dur, clk, pos, pan;
93         trate = MouseY.kr(8,120,1);
94         dur = 12 / trate;
95         clk = Impulse.kr(trate);
96         pos = MouseX.kr(0,BufDur.kr(b)) + TRand.kr(0, 0.01, clk);
97         pan = WhiteNoise.kr(0.6);
98         TGrains.ar(4, clk, b, 1, pos, dur, pan, 0.1);
99 }.scope(4, zoom: 4);
104         var b = 10, trate, dur, clk, pos, pan;
105         trate = MouseY.kr(8,120,1);
106         dur = 4 / trate;
107         clk = Dust.kr(trate);
108         pos = MouseX.kr(0,BufDur.kr(b)) + TRand.kr(0, 0.01, clk);
109         pan = WhiteNoise.kr(0.6);
110         TGrains.ar(2, clk, b, 1, pos, dur, pan, 0.1);
111 }.scope(zoom: 4);
118         var b = 10, trate, dur, clk, pos, pan;
119         trate = LinExp.kr(LFTri.kr(MouseY.kr(0.1,2,1)),-1,1,8,120);
120         dur = 12 / trate;
121         clk = Impulse.ar(trate);
122         pos = MouseX.kr(0,BufDur.kr(b));
123         pan = WhiteNoise.kr(0.6);
124         TGrains.ar(2, clk, b, 1, pos, dur, pan, 0.1);
125 }.scope(zoom: 4);
131         var b = 10, trate, dur, clk, pos, pan;
132         trate = 12;
133         dur = MouseY.kr(0.2,24,1) / trate;
134         clk = Impulse.kr(trate);
135         pos = MouseX.kr(0,BufDur.kr(b)) + TRand.kr(0, 0.01, clk);
136         pan = WhiteNoise.kr(0.6);
137         TGrains.ar(2, clk, b, 1, pos, dur, pan, 0.1);
138 }.scope(zoom: 4);
143         var b = 10, trate, dur, clk, pos, pan;
144         trate = 100;
145         dur = 8 / trate;
146         clk = Impulse.kr(trate);
147         pos = Integrator.kr(BrownNoise.kr(0.001));
148         pan = WhiteNoise.kr(0.6);
149         TGrains.ar(2, clk, b, 1, pos, dur, pan, 0.1);
150 }.scope(zoom: 4);
155         var b = 10, trate, dur, clk, pos, pan;
156         trate = MouseY.kr(1,400,1);
157         dur = 8 / trate;
158         clk = Impulse.kr(trate);
159         pos = MouseX.kr(0,BufDur.kr(b));
160         pan = WhiteNoise.kr(0.8);
161         TGrains.ar(2, clk, b, 2 ** WhiteNoise.kr(2), pos, dur, pan, 0.1);
162 }.scope(zoom: 4);
168         var b = 10, trate, dur;
169         trate = MouseY.kr(2,120,1);
170         dur = 1.2 / trate;
171         TGrains.ar(2, Impulse.ar(trate), b, (1.2 ** WhiteNoise.kr(3).round(1)), MouseX.kr(0,BufDur.kr(b)), dur, WhiteNoise.kr(0.6), 0.1);
172 }.scope(zoom: 4);
176 // demand ugens as inputs
179         var trate, dur, z, d;
180         trate = MouseX.kr(1, 100, 1);
181         d = { Dwhite(0.1, 0.2, 1) };
182         z = { 
183                 Drand([Dgeom(0.1, 1 + d.value, Diwhite(20, 40)), Dgeom(1, 1 - d.value, Diwhite(20, 40))]) 
184         };
185         TGrains.ar(2, 
186                 Impulse.ar(trate),
187                 bufnum: 10, 
188                 rate: Dseq([1, 1, z.value, 0.5, 0.5, 0.2, 0.1, 0.1, 0.1, 0.1], inf) * 2 + 1, 
189                 centerPos: Dseq(z.dup(8), inf),
190                 dur: Dseq([1, d.value, 1, z.value, 0.5, 0.5, 0.1, z.value] * 2, inf) / trate,
191                 pan: Dseq([1, 1, 1, 0.5, 0.2, 0.1, 0, 0, 0], inf) * 2 - 1,
192                 amp: Dseq([1, 0, z.value, 0, 2, 1.0, 1, 0.1, 0.1], inf)
193         );
194 }.scope(zoom: 4);