Hi,
you can take a look at miSCellaneous_lib’s Buffer Granulation tutorial. Chapter “2. Granulation driven by language”, Ex. 2a, covers time-stretching with Pbind. I’m using PLx proxy patterns in order to have easy GUI control. You could instead use Pdefn, live coding is possible with both variants – see “PLx suite” and “PLx and live coding with Strings”.
Concerning time-stretching in combination with Pbind: In Ex.2a, the position is calculated in the language, this might cause unwanted jumps when the region is changed. An alternative and maybe better – because more flexible – method is described in Ex.3b, where the position in the buffer is controlled by a separate LFO.
Concerning slicing/rolls, I’m adding some examples from my sound synthesis course which employ Pdup and need no extension installed. No time-stretching and live-coding yet built in here but that can easily be done with the techniques mentioned before.
Hope that helps, best
Daniel
// fixed-length Envelope
b = Buffer.read(s, Platform.resourceDir +/+ "sounds" +/+ "a11wlk01-44_1.aiff");
b.play
(
SynthDef(\playBuf_1, { |out, buf, att = 0.01, rel = 0.5, rate = 1,
amp = 0.1, pos = 0.5, pan = 0|
var sig = PlayBuf.ar(1, buf, rate * BufRateScale.kr(b), startPos: pos * BufFrames.kr(b));
var env = EnvGen.ar(Env.perc(att, rel, amp), doneAction: 2);
OffsetOut.ar(out, Pan2.ar(sig * env, pan))
}).add
)
(
// template
p = Pbind(
\instrument, \playBuf_1,
\buf, b,
\dur, Pexprand(0.005, 0.5),
// release depending on duration of Events
\rel, Pkey(\dur) * 1.5,
\rate, Pwhite(0.2, 2),
\pos, Pwhite(0.3, 0.7),
\pan, Pwhite(-0.8, 0.8),
\amp, 2
);
// play with Pdup
q = Pdup(Pwhite(1, 4), p).play
)
q.stop
// chords
(
// template
p = Pbind(
\instrument, \playBuf_1,
\buf, b,
\dur, Pexprand(0.005, 0.5),
// release depending on duration of Events
\rel, Pkey(\dur) * 1.5,
\rate, Pwhite(0.5, 2) * [0.6, 0.75, 1, 1.3],
\pos, Pwhite(0.3, 0.8),
\pan, Pwhite(-0.8, 0.8) * [-1, 1],
\amp, 1
);
// play with Pdup
q = Pdup(Pwhite(1, 4), p).play
)
q.stop
// sustained Envelope (Env.asr)
(
SynthDef(\playBuf_2, { |out, buf, att = 0.01, rel = 0.5, gate = 1, rate = 1,
amp = 0.1, pos = 0.5, pan = 0|
var sig = PlayBuf.ar(1, buf, rate * BufRateScale.kr(b), startPos: pos * BufFrames.kr(b));
var env = EnvGen.ar(Env.asr(att, amp, rel), gate, doneAction: 2);
OffsetOut.ar(out, Pan2.ar(sig * env, pan))
}).add
)
(
// template
p = Pbind(
\instrument, \playBuf_2,
\buf, b,
\dur, Pexprand(0.005, 0.4),
// release immer kurz
\rel, 0.01,
// legato determines when gate 0 is sent (default = 0.8)
\legato, Pwhite(0.1, 1.7),
\rate, Pwhite(0.2, 2) * Pfunc { [1, rrand(1.1, 1.7)] },
\pos, Pwhite(0.3, 0.7),
\pan, Pwhite(-0.8, 0.8) * [-1, 1],
\amp, 1
);
// play with Pdup
q = Pdup(Pwhite(1, 4), p).play
)
q.stop