Hey there,
I want to make a SynthDef from a function that was suggested in the Flucoma Tutorial
The function plays slices of a Buffer.
~play_slice = {
|buf, slice, index, vol|
{
var startsamp = Index.kr(slice, index),
stopsamp = Index.kr(slice, index +1),
phs = Phasor.ar(0, BufRateScale.ir(buf), startsamp, stopsamp),
sig = BufRd.ar(1, buf, phs),
dursec =( stopsamp - startsamp)/BufSampleRate.ir(buf),
env = EnvGen.kr(Env([0, 1, 1, 0], [0.03, dursec - 0.06, 0.03]), doneAction:2);
sig.dup * env * \amp.kr(vol);
}.play
};
In order to play it as a Pbindef, I would also like to turn it into a SynthDef. I tried this
SynthDef(\playSlice, {
|buf, index=0, vol=1|
var startsamp, stopsamp, phs, sig, dursec, env;
startsamp = Index.kr(NamedControl.kr(\slice, (0..100)), index);
stopsamp = Index.kr(NamedControl.kr(\slice, (0..100)), index + 1);
phs = Phasor.ar(0, BufRateScale.ir(buf), startsamp, stopsamp);
sig = BufRd.ar(1, buf, phs);
dursec = (stopsamp - startsamp)/BufSampleRate.ir(buf);
env = EnvGen.kr(Env([0, 1, 1, 0], [0.03, dursec - 0.06, 0.03]), doneAction:2);
sig = Pan2.ar(sig * env * \amp.kr(vol), \pan.kr(0));
Out.ar(\out.kr(0), sig);
}).add;
When I execute the code I get this error
ERROR: SynthDef: could not write def: DoesNotUnderstandError
Before I make a Pbindef, I run the FluCoMa AmpSlicer and thus create the ~slice Buffer, which I provide to the Pbindef.
(
var buf = ~buffers[\lecture][0];
~slice = Buffer.new(s);
FluidBufAmpSlice.process(s, buf, indices: ~slice, fastRampUp: 300, fastRampDown: 900 ,slowRampUp: 3000,slowRampDown: 2000, onThreshold: 10,offThreshold: 5,floor: -40,minSliceLength: 4410,highPassFreq: 20)
)
Pbindef(\slice, \instrument, \playSlice, \buf, ~buffers[\lecture][0], \slice, ~slice, \index, Pseq((0..~slice.numFrames), inf), \amp, Pwhite(0,1, 0.9, inf), \dur, 2 );
I suspect I am providing a wrong initial value for \slice in the SynthDef. But how can I make this work? Or is it just not possible. The ~playSlice Funktion works, though.
thanks for the attention