Wednesday, October 20, 2010

MultiMedia Timers

Tip - Multimedia timer services allow applications to schedule timer events with the greatest resolution (or accuracy) possible for the hardware platform.

Details - Multimedia timer services allow you to schedule timer events at a higher resolution than other timer services. Multimedia timer does not post any messages to message queues. Instead, it calls the specified callback function directly on a separate thread. Therefore, it is more accurate than the standard Win32 timer. The minimum interval that can achieve in Win32 timer is about 16 millisecond, but in multimedia timer, it is about 1 millisecond.
To use multimedia timers in your projects, you should include Mmsystem.h, and link it with Winmm.lib.
Different systems support different minimum values for the multimedia timer resolution. We can get these values like below. And we need to set the minimum resolution by calling timeBeginPeriod function.


  

Now that we set the resolution, let's create the timer. The multimedia timer equivalent of SetTimer, looks like this


 

If uPeriod_i is not in the range of the minimum and maximum event delays supported by the timer, the function returns an error. The callback function is declared like this



Eventually, we will need to destroy the timer. We can accomplish this by a call the function below,


Posted by - Shiju CK

No comments:

Post a Comment