Timing problems using Time::getMillisecondCounter()

Hi everybody,

I’m working on an arpeggiator for a synthesizer. I have to implement a timer which starts when pressing a key on the midi controller in order to process my arpeggiator.
When I implemented a new timer (I used the function Time::getMillisecondCounter()) I played and stopped the host and printed in a text file the time the host sent and the time my timer sent each time function processBlock was called. I realized that both timers ran “parallel” with the same increments of time each cycle, but after 5 or 6 cycles they lose the relation.

This is a part of the text file in milliseconds, with the “changes” in the increments underlined. The first column represents the time the host sent when playing and the second the time the timer calculated through Time::getMillisecondCounter() measured since the plugin started.

TimeHost: 505.034 TimeChrono: 3860.000000
TimeHost: 510.839 TimeChrono: 3865.000000
TimeHost: 516.644 TimeChrono: 3870.000000
TimeHost: 522.449 TimeChrono: 3880.000000

TimeHost: 528.254 TimeChrono: 3885.000000
TimeHost: 534.059 TimeChrono: 3890.000000
TimeHost: 539.864 TimeChrono: 3895.000000
TimeHost: 545.669 TimeChrono: 3900.000000
TimeHost: 551.474 TimeChrono: 3905.000000
TimeHost: 557.279 TimeChrono: 3915.000000

What’s happening there?. Is it possible to have another timer running in a perfect parallel motion with the processBlock function? If not, how can I measure time in a precise way for my purpose?

Thanks,

Oscar

You’re making some dodgy assumptions there - you can’t assume that the processBlock function will be called with any precision - it could be called at any time before the block is required. And the millisecond counter’s clock is entirely separate from the audio clock, so they definitely can’t be expected to stay in sync!

Then, are we always limited by the process block’s timing precision to do any calculation inside a plugin? (since it’s the only func that connects the host with the plugin, right?)

Cheers :slight_smile:

Yes, pretty much!

Thanks!