linux: shared memory interface - link with librt
[supercollider.git] / HelpSource / Classes / PlayBuf.schelp
blob0e9b0cef9fc9da403c148488e131ed184741191a
1 class:: PlayBuf
2 summary:: Sample playback oscillator.
3 related:: Classes/RecordBuf, Classes/DiskIn, Classes/BufRd
4 categories::  UGens>Buffer
7 Description::
8 Plays back a sample resident in memory.
10 classmethods::
12 method::ar, kr
14 argument::numChannels
15 Number of channels that the buffer will be. This must be a fixed
16 integer. The architechture of the SynthDef cannot change after it
17 is compiled.
19 argument::bufnum
20 The index of the buffer to use.
21 warning::
22 If you supply a bufnum of a buffer with a differing number of channels
23 than the one specified in this PlayBuf, it will fail silently.
26 argument::rate
27 1.0 is the server's sample rate, 2.0 is one octave up, 0.5 is one
28 octave down -1.0 is backwards normal rateā€¦ etc. Interpolation
29 is cubic.
32 argument::trigger
33 A trigger causes a jump to the startPos. A trigger occurs when a
34 signal changes from negative value to positive value.
36 argument::startPos
37 Sample frame to start playback.
39 argument::loop
40 1 means true, 0 means false. This is modulateable.
42 argument:: doneAction
43 an integer representing an action to be executed when the buffer is finished playing. This can be used to free the enclosing synth, etc. See link::Reference/UGen-doneActions:: for more detail. code::doneAction:: is only evaluated if loop is 0.
45 Examples::
47 code::
48 s.boot // Boot the server, if you need to
50 // read a whole sound into memory
51 // note: not *that* columbia, the first one
52 b = Buffer.read(s, Help.dir +/+ "sounds/a11wlk01.wav"); // remember to free the buffer later.
54 SynthDef(\help_PlayBuf, {| out = 0, bufnum = 0 |
55         Out.ar(out,
56                 PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum), doneAction:2)
57         )
58 }).play(s, [\out, 0, \bufnum, b]);
61 In the above example, note how the code::doneAction:2:: causes the synth to free itself when the buffer reaches its end.
63 Note again that the number of channels must be fixed for the SynthDef. It cannot vary depending on which buffer you use.
65 code::
66 // loop is true
67 SynthDef(\help_PlayBuf, {| out = 0, bufnum = 0 |
68         Out.ar(out,
69                 PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum), loop: 1.0)
70         )
71 }).play(s, [\out, 0, \bufnum, b]);
74 // trigger one shot on each pulse
75 SynthDef(\help_PlayBuf, {| out = 0, bufnum = 0 |
76         var trig;
77         trig = Impulse.kr(2.0);
78         Out.ar(out,
79                 PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum), trig, 0, 0)
80         )
81 }).play(s, [\out, 0, \bufnum, b]);
84 // trigger one shot on each pulse
85 SynthDef(\help_PlayBuf, {| out = 0, bufnum = 0 |
86         var trig;
87         trig = Impulse.kr(XLine.kr(0.1, 100, 30));
88         Out.ar(out,
89                 PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum), trig, 5000, 0)
90         )
91 }).play(s, [\out, 0, \bufnum, b]);
94 // mouse control of trigger rate and startpos
95 SynthDef(\help_PlayBuf, { arg out=0, bufnum=0;
96         var trig;
97         trig = Impulse.kr(MouseY.kr(0.5, 200, 1));
98         Out.ar(out,
99                 PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum), trig, MouseX.kr(0, BufFrames.kr(bufnum)), 1)
100         )
101 }).play(s, [\out, 0, \bufnum, b]);
104 // accelerating pitch
105 SynthDef(\help_PlayBuf, {| out = 0, bufnum = 0 |
106         var rate;
107         rate = XLine.kr(0.1, 100, 60);
108         Out.ar(out,
109                 PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum)*rate, 1.0, 0.0, 1.0)
110         )
111 }).play(s, [\out, 0, \bufnum, b]);
114 // sine wave control of playback rate. negative rate plays backwards
115 SynthDef(\help_PlayBuf, {| out = 0, bufnum = 0 |
116         var rate;
117         rate = FSinOsc.kr(XLine.kr(0.2, 8, 30), 0, 3, 0.6);
118         Out.ar(out,
119                 PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum) * rate, 1, 0, 1)
120         )
121 }).play(s, [\out, 0, \bufnum, b]);
124 // zig zag around sound
125 SynthDef(\help_PlayBuf, {| out = 0, bufnum = 0 |
126         var rate;
127         rate = LFNoise2.kr(XLine.kr(1, 20, 60), 2);
128         Out.ar(out,
129                 PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum) * rate, 1, 0, 1)
130         )
131 }).play(s, [\out, 0, \bufnum, b]);
133 b.free;