JUCE Timers


#1

How precise are juce timers? Because I see system timers not being user.
If I set a timer for, say 34 milliSeconds, is it guranteed to fire at that interval?

Many Thanks,
Yogesh


#2

No, they’re not precise at all. (It explains why in the Timer class comments)

If you need millisecond accuracy the only way is to use a dedicated high-priority thread and wait() based on the millisecond counter.


#3

And don’t forget that sleeping is not accurate either as it is polled based on the system event rate, which for Windows95 is around 55ms, for XP is around 11ms. Unknown what it is for non-Windows OS’s…


#4

The reason I asked this question was:

I am working on a cross-platform video processing application that, chaches sevaral frames(100-300 depending on the main memory size) in the RAM and then plays them back at realtime(30 fps). I am using opengl to display frames. I use juce timers for my display callback.

On Mac OS(10.4.8 ) I see a seamless display, while on PC I see jerks during playback. This made me suspect, that MAC timers on JUCE are more precise
compared to PC Timers.

Any views or Ideas?

Regards,
Yogesh


#5

The timer code is the same on both platforms, but because the callbacks happen on the main event thread, they’re at the mercy of other events that might get called, and that’s unpredictable. For an application like yours, you should really use a dedicated thread to make sure it doesn’t get interrupted.


#6

Well Jules,
I used multimedia timer on Windows and that did the job.
Now smooth playback on windows as well
May be you could add some Utility classes using system timers, that
are more precise :smiley:

Regards,
Yogesh


#7

Well yes, multimedia timers use their own thread, so will be more accurate. I guess I could add some hi-res timers when I get chance. I’ll stick it in the to-do list.


#8