Precise timing in Min?
Hello, I looked and I haven't seen this already addressed somewhere.
I'm writing an object that's supposed to play a sequence of audio pulses with critical timing accuracy.
So far I've been assuming that every perform() takes the same physical time, and so I use:playhead += lib::math::samples_to_milliseconds(dsp_vec_size, samplerate())
to compute my current time.
The problem is, I also do some other computation in perform() (sending and receiving to/from a LibTorch model), so the resulting clicks are not equidistant.
(i've played with all combinations of Overdrive/Interrupt, same behaviour...)
Is there a way to create a parallel thread with perfect timing accuracy that I can anchor my playhead to?
perhaps using a timer<> like in min.note.make, would that be sample-accurate though?
oops, scratch this, my code was wrong :) .. perform() does in fact take the same physical time, as it should.
for reference, here's some code to trigger a click every second:auto vec_size = input.frame_count();
double buf_ms = lib::math::samples_to_milliseconds(vec_size, samplerate());
playhead += buf_ms;
for (int c = 0; c < output.channel_count(); c++) {
auto out = output.samples(c);
for (int i = 0; i < output.frame_count(); i++) {
out[i] = 0.;
}
if (playhead >= seconds * 1000. - buf_ms) {
int ratio = (seconds * 1000. - playhead) * vec_size / buf_ms;
seconds++;
out[ratio] = -1.;
cout << "seconds: " << seconds << " ratio " << ratio << endl;
}
}
this keeps working even if I add back all the other fancy stuff I had in perform(). yay!