I’m using a single Phasor, which loops between 0 and 1, to simultaneously index many buffers (with potentially different sampling rates) and use the indexed values to control other UGens.
Each set of buffers contains information for a certain amount of time, say 1 second, which matches how long it takes for the Phasor to loop. During that time, I prepare the next set of buffers so that they’re ready to be loaded and indexed when the previous ones are finished, (hopefully) seamlessly moving from one to the next without any clicks or hiccups.
I understand that the loading and setting of the new buffers is a language-side job, so my question is: what’s the best way to make sure that synth.set
-ing the new buffers happens exactly when the Phasor loops back to 0?
I tried using Changed.ar
as so:
SynthDef(\timePhasor, {
|out = 3, dur = 1, loopPoint = 1, t_manualTrig = 0, startPoint = 0|
var sig = Phasor.ar(
t_manualTrig,
1/(dur*SampleRate.ir()),
startPoint,
//set loopPoint to 1 for looping, inf for no looping
loopPoint,
startPoint
);
var trigStart = Changed.ar(sig, 0.01);
SendTrig.ar(trigStart, 0, sig);
Out.ar(out, sig.clip(0, 1));
}).add;
and, while it sort of works, the value of sig
when the message is sent changes ever so slightly every time, e.g. 2.2455536964117e-005, 2.2437186999014e-005, 2.2418837033911e-005
etc.
Is there a better way to hot-swap the buffers so that the last sample of the previous buffer is reliably followed by the first sample of the next buffer?