[Interest] Ultra precise timing in Qt
Thiago Macieira
thiago.macieira at intel.com
Sat Apr 23 19:20:21 CEST 2016
On sábado, 23 de abril de 2016 18:06:38 PDT Nuno Santos wrote:
> So far I was using QElapsedTimer to measure this. One particular behaviour I
> observed was, once I started moving the virtual knobs and faders of the
> synth, it would start to get out of sync with the machine. My conclusion is
> that somehow, QElapsedTimer is tied to the event loop thus making it slower
> when other interactions are happening. Does this make sense? I haven’t
> looked to QElapsedTimer source code, i’m just guessing. Maybe I’m saying
> silly things.
Yeah, kinda... Your description above summarises to "the more code I add, the
more work needs to be done".
The use of QElapsedTimer does not have any further impact on the event loop
besides executing more code and is not any different from any other further
addition of code that causes a system call. On some OSes, getting the system
time is a very fast operation (Linux); on others, it might be slow.
> I search for options and started using mach_absolute_time. The problem seems
> to be solved now. I have the soft synth running with the arpeggiator
> enabled sending midi clock to the machine, and they keep their tempo
> constant, even when the controls are being used or the device is under
> stress.
>
> Does Qt provide any kind of cpu absolute clock for every platform? I
> couldn’t find it so far.
Yes, it's called QElapsedTimer.
> Does anyone know the equivalent to mach_absolute_time in Windows and Android
> (probably the same as linux).
On Windows, you use GetTickCount64 or QueryPerformanceCounter. On Android and
Linux, use clock_gettime for the CLOCK_MONOTONIC or CLOCK_MONOTONIC_COARSE.
Do you know how I know this? I looked into qelapsedtimer_win.cpp and
qelapsedtimer_unix.cpp.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Interest
mailing list