Sequencer in VSTi — hiRes Timer or sample rate counter?

I’m currently working on a sequencer built into a drum machine VSTi that I’m writing

My plan is to be able to switch between the host MIDI clock and an internal clock, tho right now I’m focusing on the internal clock

I’m currently basing the sequencer clock by calculating the samples per PPQN and then incrementing a counter in my audio buffer to that variable

It works well, but I wanted to see what other people do since this is my first time making a sequencer

So do you prefer to use a hiRes timer or calculate it based on the sample rate (or some other method) to increment your sequencer?

hiRes Timer: portability issues, only use this if it is being provided by JUCE, because: here be dragons …

Sample-buffer counting: truly portable and most flexible of the options.

IMHO, you’re on the right track, don’t change a thing, sample/sequencer event accuracy is important …

1 Like

Counting audio samples is the most accurate timing source you have, as that is actually tied to the real time via the DAC’s quartz. You know for sure that something you output every x samples will be heard every x samples.

With a HiRes timer not so much, as what you measure with it is only what time it is when your process function is called. But not what time it is when the user actually hears the output! In theory, a host call you only once a second, and then you’ll have a hard time deriving any precise timing from that. Let alone when you’re processing offline (then the hires timer will have absolutely nothing to do with actual “audible” time).

So regarding any timing-related issues, always always always use the audio sample clock as the single source of truth!

6 Likes

Thanks for the replies, that’s really helpful information! @hugoderwolf that’s really good to know about the hires timer

I stuck with the sample clock for the internal sequencer PPQN clock and it stays very steady. It fell out of sink just slightly when I was using the DAW’s tempo clock, but I switched to basing the PPQN on the AudioPlayHead that’s received from the host DAW and it seems to be very tight and in sync with the host now :slight_smile:

thanks for the advice!

1 Like

Could this answer be helpful to you?