1

I'm porting some audio playback code from iOS to wp8 (don't ask why), and I'm encountering some troubles with timers on my wp8 device. After some cursory research, I decided to go with QueryPerformanceCounter as a good-enough parallel to the MachAbsoluteTime stuff on iOS. However, since my device (Nokia Lumia 920) is dual core, QPC encounters problems, and my deltas often end up negative or ridiculously high. I need my playback loop to run every 10ms, but these spurious timer results are throwing my code off.

I looked into somehow giving my loop processor affinity, but I can't find a way to do so, since I can either use tasks or the threadpool instead of explicit thread creation on wp8. Any suggestions? Is there another timer I can use, or is there a way to give tasks or threadpool workitems proc affinity?

HarryHippo
  • 267
  • 1
  • 2
  • 9
  • This thread was posted in 2009 -- have there been any updates/breakthroughs since then, though? http://stackoverflow.com/questions/1825720/c-high-precision-time-measurement-in-windows – HarryHippo Oct 01 '13 at 17:16
  • WAG, but the Stopwatch class calls down into QueryPerformanceCounter and I've never had issues with weird deltas. But I haven't ever used it in a WP app, so I'm not sure if that holds. You can try switching out calls to use an instance of Stopwatch and see if that works. –  Oct 01 '13 at 18:09
  • If the Stopwatch class calls QPC, I shouldn't get any different results. There is a lack of tick synchronization between the different cores which is the root cause of this issue. – HarryHippo Oct 01 '13 at 23:05
  • 1
    Or, it may call QPC *correctly*. I can't test this for you (not set up for WP dev), so you can do one of the following: 1) claim it can't work, not even try, and continue to wait for other answers, or 2) prototype it out and see if it works any better. Or, in other words, you can sit on your hands or try something else that may or may not work. Your choice. –  Oct 02 '13 at 13:50
  • So, from the link that I posted: "If you have a threaded application running on a multicore computer QueryPerformanceCounter can (and will) return different values depending on which core the code is executing on. See this MSDN article. (rdtsc has the same problem)." – HarryHippo Oct 02 '13 at 20:08
  • I appreciate the help, but it looks like the underlying problem is simply calling QPC in a threaded application on a multicore phone, which is exactly what I'm doing. – HarryHippo Oct 02 '13 at 20:11
  • (I have tested QPC on a non multicore device and seen viable results) – HarryHippo Oct 02 '13 at 20:17
  • I've used Stopwatch on a multimultucore device and it returned expected results :/ –  Oct 02 '13 at 20:23
  • Was it Windows Phone? The fact that I'm working with Windows seems to be the root cause of all my problems – HarryHippo Oct 02 '13 at 20:26
  • The question, and perhaps even your question, could have already been answered if you had taken ten minutes to try it out. I said it was a wild-ass guess, but sometimes those work out. Anyhow, good luck. –  Oct 03 '13 at 13:29
  • The Stopwatch class requires a managed assembly that isn't available to WinRT components. I can't try it. Even if I could, it wouldn't matter. Also -- I tagged Windows Phone in the question so I could get answers that pertain to, you know, Windows Phone. – HarryHippo Oct 03 '13 at 16:41
  • Hey, you get what you paid for with wild-ass guesses. However, I did check the API reference to [make sure it was available on the windows phone](http://msdn.microsoft.com/en-us/library/windowsphone/develop/System.Diagnostics.Stopwatch(v=vs.105).aspx). Usually when I have a WAG I try not to waste time with it :/ Maybe my assumption that if it exists within the WP API reference it is therefore available to WP apps is incorrect? –  Oct 03 '13 at 18:46
  • No, you were right that it is available for WP8, but only through C# -- I need my timing done in a C++/CX runtime component. Which doesn't support the managed assembly required to call Stopwatch stuff. The API ref for WP is somewhat incomplete and clashes with their desktop dev portal sometimes. – HarryHippo Oct 03 '13 at 21:41
  • Sorry dude. +1 and good luck! –  Oct 04 '13 at 00:16
  • Haha thanks, it's definitely an uphill struggle. – HarryHippo Oct 04 '13 at 23:43

0 Answers0