Hey. Kind of new to SuperCollider, sorry if the question is silly.
I’m experimenting with granular synthesis in order to read and mangle a loop contained in a buffer.
Basically, the idea is to read the buffer with a BufGrain
, sweep through the buffer by moving the pos
parameter and add some noise to the pos
for some jitter. Here is what I’ve got so far:
(
b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
//b = Buffer.read(s, Platform.userHomeDir +/+ "portishead.wav");
SynthDef(\kali, { |out=0, buf, tempo=1, rate=1, scale=1, density=10, scatter=0, mul=1, add=0|
Out.ar(out,
Pan2.ar(
BufGrain.ar(
trigger: Impulse.kr(density),
dur: 1/density * 2,
sndbuf: buf,
rate: rate,
pos: Sweep.kr(Impulse.kr(tempo/(scale*4)), tempo/(scale*4)) + PinkNoise.kr(mul:scatter),
mul: mul,
add: add,
)
)
)
}).add;
a = Synth(\kali, [
\buf, b,
\rate, 1,
\density, 10,
\scatter, 0,
\tempo, 1,
\scale, 2,
\rate, 1,
]);
)
This code does the trick, but here is the thing: the loop playback should be synchronized with a global tempo, and reading here and there, I suspect my synth will drift out of sync sooner or later.
I think there is an approach by moving the “sweep” code out of the synth, and pass it through a parameter pos
, like this:
SynthDef(\grain, { |out=0, buf, pos=0, rate=1, density=10, scatter=0, mul=1, add=0|
Out.ar(out,
Pan2.ar(
BufGrain.ar(
trigger: Impulse.kr(density),
dur: 1/density * 2,
sndbuf: buf,
rate: rate,
pos: PinkNoise.kr(mul:scatter, add:pos),
mul: mul,
add: add,
)
)
)
}).add;
Now, here is where I’m stuck: how do I generate a stream of pos
value in sync with a TempoClock
? I guess it must be something with Routine
or Task
, but I’m having troubles wrapping my head around this one…