• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Getting accurate stimulus timing out of Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Getting accurate stimulus timing out of Cocoa


  • Subject: Getting accurate stimulus timing out of Cocoa
  • From: Michael Norris <email@hidden>
  • Date: Mon, 8 Nov 2004 12:30:12 +1300

Hi there

I've been contracted to do some Cocoa development for some psychology testing software. This software tests and records the delay between a stimulus being displayed and the participant pressing a key on the keyboard.

Ideally, the program should be able to measure this delay with millisecond accuracy, and should be able to largely rule out any computer-induced timing errors (or at least have a measureable, constant error). The simplest code model would look like this:

a) send a message to update an NSView (to display the stimulus)
b) get the current NSDate
c) the computer then actually goes through the process of drawing the NSView
-- time passes --
d) a key is pressed
e) the program receives a keyDown message
f) get the current NSDate again
g) compare the date from e) with the date from b) to measure the delay.


In this model, I can foresee two major problems with ensuring low-error measurements:

1) The delay between b) and c) is unknown. I have no idea how I could measure the delay between sending an update message to an NSView, and the computer actually getting round to redrawing the screen. At least this is being run on a laptop, so I don't have to worry about Vertical Retrace.
2) The delay between d) and f) is unknown. A key is pressed. That signal takes some time to travel down the USB, get processed by the kernel, then send a message to my program. How long does all that take, and how do I measure it? Maybe I need to have an idle loop that does timed keyboard-polling rather than leaving it up to the 'looser' event mechanism of Cocoa, which surely has greater code overhead.


I know with a multitasking OS like OS X, and an event-based runtime architecture like Cocoa, it's hard to get truly error-free measurements. But I'd really appreciate any feedback on how I could get this code as accurate as possible, or at least how I might approach measuring the errors.

Cheers
-mike

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: NSPanel is freezing
  • Next by Date: Problem loading sound
  • Previous by thread: Re: NSPanel is freezing
  • Next by thread: Problem loading sound
  • Index(es):
    • Date
    • Thread