Ah, yes, you’re right! I guess these three might be a good option:
// 1: days since 1970
log(365*2500) /// ... 14 bits, good enough for a very long time
// 2: seconds Since Midnight
log2(60*60*24) // ... 17 bits
// 3: a Sample Counter synced to the seconds-counter
This example achieves it for now:
(
s.makeBundle(s.latency, {
{
var rawSeconds = Date.localtime.rawSeconds + s.latency;
var daysSince1970 = (rawSeconds / 86400);
var secondsSinceMidnight = (rawSeconds % 86400);
var samps = Phasor.ar(0.0, 1.0, 0, SampleRate.ir) + ((rawSeconds%1.0)*SampleRate.ir);
daysSince1970 = Phasor.ar(0.0, 1/(SampleRate.ir*86400), 0, inf) + daysSince1970;
secondsSinceMidnight = (Phasor.ar(0, SampleRate.ir.reciprocal, 0, 86400) + secondsSinceMidnight) % 86400;
[secondsSinceMidnight, samps]
}.plot(4, separately:true);
});
)
Comparing scheduled sclang-scheduled Synth’s that play an impulse with the Phasor-based scheduling:
SynthDef("dirac", { arg out, amp=0.1;
var u;
u = Impulse.ar(0);
FreeSelf.kr(u);
Out.ar(out, u * amp);
}).add;
)
(
Tdef(\scheduler, {
var delta;
loop {
delta = absdif(Date.localtime.rawSeconds%1, 1);
s.makeBundle(delta, {Synth(\dirac, [\out, 1, \amp, 0.5]) });
1.wait
}
}).play;
s.makeBundle(s.latency, {
{
var delta = (Date.localtime.rawSeconds%1.0) + s.latency;
var phasor = Phasor.ar(0.0, 1.0, 0, SampleRate.ir) + (delta*SampleRate.ir);
HPZ1.ar(phasor % SampleRate.ir) < 0.0;
}.play
})
)
This gives me a ~5msec difference
Which should be good for now :~)
Thank you for the help!