2 summary:: Allocate a buffer local to the synth
3 categories:: UGens>Buffer
4 related:: Classes/Buffer, Classes/SetBuf, Classes/ClearBuf
7 private:: categories, new1
10 Allocate a local buffer
12 number of frames (default: 1)
13 argument:: numChannels
14 number of channels for multiple channel buffers (default: 1)
15 returns:: a new buffer – the ugen outputs its buffer number and can thus be used in any other ugen that requires a buffer number input.
18 Allocates a new buffer from a given list of values
20 The list may be two-dimensional for numChannels > 1.
21 It is then reshaped into the buffer's current format by flattening.
22 returns:: a new buffer
24 Since newFrom is called by the as message, one may thus convert an array to a LocalBuf:
26 [1, 2, 3].as(LocalBuf)
31 set the buffer slots with a list of values.
33 If list is smaller than numFrames, it will only set
34 part of the buffer. The list may be two-dimensional for numChannels > 1.
35 offset is the starting index (default: 0)
37 SynthDef permits a maximum of 65536 (2**16) unique constant values in one definition. A very large array of distinct values can corrupt the SynthDef's binary format. If you need a large buffer to be pre-initialized with signal data, it is strongly recommended to use link::Classes/Buffer:: instead.
40 If the buffer is large but holds a smaller number of unique values, e.g. code::Array.fill(88200, { #[0, 0.25, 0.5, 0.75, 1.0].choose })::, this is no problem. SynthDef compacts the large array for the list of constants.
43 SynthDef(\bigLocalBuf, {
44 LocalBuf(88200).set(Array.fill(88200, { #[0, 0.25, 0.5, 0.75, 1.0].choose }))
47 SynthDescLib.at(\bigLocalBuf).constants;
48 // prints: FloatArray[ 1, 88200, 0, 0.75, 0.5, 0.25 ]
52 set the buffer slot to zero.
54 This is important when randomly acessing buffer slots
55 (e.g. with a BufRd) or not overwriting them. Clear is not an efficient real time operation
56 for larger buffers, so it should be only used when really needed - but then it is essential:
57 a LocalBuf is "created" in each new synth, and it may reuse old space. So if an older
58 synth has already ended, this part of memory may be the same as the new synth's.
67 in = WhiteNoise.ar(0.1.dup);
68 chain = FFT({LocalBuf(2048, 1)}.dup, in);
69 chain = PV_BrickWall(chain, SinOsc.kr([0.1, 0.11]));
70 IFFT(chain) // inverse FFT
74 // spawn some FFT based synths:
76 SynthDef(\fftgrain, { |out, sustain = 1, rate = 0.2|
78 in = WhiteNoise.ar(0.1).dup;
79 chain = FFT({LocalBuf(128, 1)}.dup, in);
80 chain = PV_BrickWall(chain,
81 SinOsc.kr(rate * XLine.kr(1, 15 * [1, 1.6], sustain), Rand(0, pi))
83 Out.ar(out, IFFT(chain) * XLine.kr(1, 0.001, sustain, doneAction: 2)) // inverse FFT
89 \instrument, \fftgrain,
90 \rate, Pwhite().linexp(0, 1, 0.01, 300),
91 \legato, Pwhite(1, 3.0, inf),
92 \dur, Prand([0.2, 1, 1.2], inf)
99 var buf = LocalBuf.newFrom((0..5).scramble);
100 var freq = IndexL.kr(buf, MouseX.kr(0, BufFrames.kr(buf))).poll * 100 + 40;
101 Saw.ar(freq * [1, 1.1]) * 0.1
108 var buf1 = LocalBuf.newFrom((0..5).scramble);
109 var buf2 = LocalBuf.newFrom((0..5).scramble - 1);
110 var buf3 = LocalBuf.newFrom((0..5).scramble + 1);
111 var index = DetectIndex.kr([buf1, buf2], SinOsc.kr([0.85, 0.8], 0, 6).trunc).poll;
112 var freq = IndexL.kr([buf2, buf3], index).poll * 40 + 40;
120 // mouse x controls discrete pitch in dorian mode
131 [0, 2, 3.2, 5, 7, 9, 10].as(LocalBuf),
132 MouseX.kr(0, 15), // mouse indexes into scale
133 12, // 12 notes per octave
135 72 // offset by 72 notes
137 + LFNoise1.kr([3,3], 0.04) // add some low freq stereo detuning
138 ).midicps, // convert midi notes to hertz
143 + RLPF.ar(LFPulse.ar([48,55].midicps, 0.15),
144 SinOsc.kr(0.1, 0, 10, 72).midicps, 0.1, 0.1);
146 // add some 70's euro-space-rock echo
147 CombN.ar(mix, 0.31, 0.31, 2, 1, mix)
155 var list = Wavetable.sineFill(512, 1.0 / [1, 10, 3, 10, 5, 6, 10]);
157 buf = LocalBuf.newFrom(list);
159 XLine.kr(2000, 200 + {30.0.rand}.dup, 10) + SinOsc.ar(Line.kr(2, 300, 10),
165 // see how not clearing the buffer accesses old data:
166 // slowly overwrite data with noise
169 var buf = LocalBuf(2048, 2);
170 BufWr.ar(WhiteNoise.ar(1.dup), buf, LFNoise0.ar(530).range(0, BufFrames.kr(buf)));
171 PlayBuf.ar(2, buf, MouseX.kr(1, 2), loop: 1) * 0.1
175 // avoid this (unless you like the glitch) by clearing buffer first:
178 var buf = LocalBuf(2048, 2).clear;
179 BufWr.ar(WhiteNoise.ar(1.dup), buf, LFNoise0.ar(530).range(0, BufFrames.kr(buf)));
180 PlayBuf.ar(2, buf, MouseX.kr(1, 2), loop: 1) * 0.1
185 // BufCombC stereo (needs no clearing, because delay is filled by ugen)
188 var z = Decay.ar(Dust.ar(1.dup, 0.1), 0.3, WhiteNoise.ar);
189 BufCombC.ar(LocalBuf(SampleRate.ir, 2), z, XLine.kr(0.0001, 0.01, 20), 0.2);
196 var in, chain, n = 4;
197 in = WhiteNoise.ar(0.1.dup(n));
198 chain = FFT({LocalBuf(2048, 1)}.dup(n), in);
199 chain = PV_BrickWall(chain, LFNoise2.kr(2.dup(n)));
200 Splay.ar(IFFT(chain)) // inverse FFT