2 summary:: Buffer write demand ugen
3 categories:: UGens>Buffer, UGens>Demand
4 related:: Classes/Dbufrd
12 buffer number to write to (single channel buffer)
16 when phase exceeds number of frames in buffer, loops when set to 1 (default :1)
18 all inputs can be either demand ugen or any other ugen.
22 // alloc a single channel buffer
23 b = Buffer.alloc(s, 24, 1);
24 b.setn(0, { 210 } ! b.numFrames);
27 fork { loop { 0.5.wait; b.getn(0, b.numFrames, {|x| x.postln }) } };
29 // write demand sequence into a buffer
32 var read, write, readpos, writepos, writetrig;
34 writetrig = Dust.kr(1);
35 readpos = Dseries(0, 1, inf);
36 writepos = Dseq([Dseries(0, 3, 30), Dseries(0, 1, 30)], inf);
38 read = Dbufrd(b, readpos);
39 write = Dbufwr(Dseq([Dseries(1, 1, 16), Dwhite(1, 16, 8)], inf) * 60, b, writepos);
41 Demand.kr(writetrig, 0, write); // write on trigger
44 Demand.kr(Impulse.kr(16), 0, read).lag(0.01) * [1, 1.01]
50 // write into buffer with mouse clicks
53 var val = MouseY.kr(1000, 200, 1); // cursor y pos controls frequency
54 var pos = MouseX.kr(0, BufFrames.kr(b) - 1); // cursor x position controls buffer pos
55 var write = MouseButton.kr; // button controls write action
56 Demand.kr(write, 0, Dbufwr(val, b, pos, 1));
58 Duty.kr(Dseq([0.5, 0.75, 0.5, 1.0], inf) * 0.2, 0, Dbufrd(b, Dseries(0, 1, inf)))
63 // write demand sequence into a buffer
64 b.free; b = Buffer.alloc(s, 2, 1);
65 fork { loop { 0.5.wait; b.getn(0, b.numFrames, {|x| x.postln }) } };
70 var read, write, readpos, writepos, writetrig;
72 writetrig = Impulse.kr(2);
73 readpos = Dbufrd(b, 1); // first buffer val is position
74 writepos = Dbufrd(b, 0); // second buffer val is position
75 read = Dbufrd(b, readpos);
77 write = Dbufwr(read, b, writepos);
79 Demand.kr(writetrig, 0, write); // write on trigger