Yako
Yako

Reputation: 191

Delphi timer more precise than milliseconds

I've got a program in Delphi which takes in frames from an external application in 25 hertz (25 times per seconds) and then converts it to 60 hertz (60 frames per second) by creating 1-2 extra frames. I need to output these extra frames by continuously building a frame buffer and outputting the frames from here from a separate thread. The problem is that 1000/60 is 16.66667 which means I can't just send the frames in a "interval" on 16 or 17 milliseconds, I need it to be more precise. How do I do this in Delphi/Windows?

Upvotes: 2

Views: 3114

Answers (2)

David Heffernan
David Heffernan

Reputation: 613013

You probably need to make use of both of the following:

  1. The high resolution timer. This is available through the QueryPerformanceCounter Win32 function, and also wrapped by the Delphi TStopwatch type.
  2. A waitable timer. This allows you to set a due date in the future and have your thread block, and be woken at the due date.

Both of these have higher resolution than the GUI timer, and should suffice for your needs. Read an overview here: http://msdn.microsoft.com/en-gb/library/windows/desktop/ms644900.aspx

Upvotes: 2

Remy Lebeau
Remy Lebeau

Reputation: 596547

Use a multimedia timer via the Win32 API timeSetEvent() or CreateTimerQueueTimer() function.

Upvotes: 2

Related Questions