Q: timing of SDL events

Hi

I am using SDL to program psychological experiment apps under win32. In this
domain accurate measurements of reactiontimes is often critical to
experimental results.
SDL_WaitEvent waits 10 ms between polls in the eventqueue. This delay is
unacceptable for me. So I can use SDL_PollEvent.
My question is:
Is there anything in SDL_PollEvent or the SDL eventsystem that delays in the
arrival time for events?
If so, I should consider using a OS specific method.
Preferrably I want to recieve events as fast as possible after the interrupt
is recieved by the OS.

Thanx

-Martin_________________________________________________________________
F? alle de nye og sjove ikoner med MSN Messenger http://messenger.msn.dk/

Hi Martin,

You may want to search the archives on this issue if no one speaks up.

Last time this conversation came out it was pointed out that the finest
resolution current OS’s can even deal with scheduling is 10ms. Not sure if
those are the right terms but basicly the issue was that if you put in a
delay, it would basicly get rounded off to the nearest 10ms and this was
caused by the OS and not SDL.

Someone did a big study of using loops in cunjunction with delays to get the
most accurate amount of delay and even posted graphs somewhere (check the
archives if no one speaks up with more details hehe).

but! I think a simple and nice work around for you might be to do code like
this (this would be for 7ms delay):

Uint32 Stop;

Stop=SDL_GetTicks()+7;

while(SDL_GetTicks()<Stop);> ----- Original Message -----

From: mala-sdl@hotmail.com (Martin Lange)
To:
Sent: Thursday, March 17, 2005 10:32 AM
Subject: [SDL] Q: timing of SDL events

Hi

I am using SDL to program psychological experiment apps under win32. In
this
domain accurate measurements of reactiontimes is often critical to
experimental results.
SDL_WaitEvent waits 10 ms between polls in the eventqueue. This delay is
unacceptable for me. So I can use SDL_PollEvent.
My question is:
Is there anything in SDL_PollEvent or the SDL eventsystem that delays in
the
arrival time for events?
If so, I should consider using a OS specific method.
Preferrably I want to recieve events as fast as possible after the
interrupt
is recieved by the OS.

Thanx

-Martin


F? alle de nye og sjove ikoner med MSN Messenger http://messenger.msn.dk/


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hi,

I am using SDL to program psychological experiment apps under win32. In
this domain accurate measurements of reactiontimes is often critical to
experimental results.
SDL_WaitEvent waits 10 ms between polls in the eventqueue. This delay is
unacceptable for me. So I can use SDL_PollEvent.
My question is:
Is there anything in SDL_PollEvent or the SDL eventsystem that delays in
the arrival time for events?
If so, I should consider using a OS specific method. Preferrably I want
to recieve events as fast as possible after the interrupt is recieved by
the OS.

If reaction time is critical, then You should use OS specific API. Also
probably best would be some real-time or almost real-time operating system
(i’m biased but i think BeOS could be used, and it has easy to use API.
Also QNX could be a good choice from what i’ve heard :).

SDL_PollEvents doesn’t wait in theory, but it may depend on platform
implementation. Even if it’s implemented to work as fast as possible
there’s still additional code to execute (wrapping OS API) so it will
always be slower than os native API (not much, but for some very specific
things it may be too much).

Regards
ahwayakchih

Current Linux systems with 2.6.x kernels can actually do waits as low as
1-2ms. So, for example, SDL_Delay(1) can result in only a 1 or 2 ms
delay, vs. 10ms on older 2.4.x kernels.

Windows XP systems also seem able to do 1-2 ms waits. Not sure about OSX.
The differences in timing is amazing. In an application I’m working on
(Stella), the system hogs the CPU at a minimum of 60% all the time when
using a 2.4.x kernel. The same code, running under the exact same
conditions, normally runs at 6-10% CPU time on Linux kernel 2.6.x and
WinXP.

When the application is paused, the CPU usage still hovers around 50% on
the older systems, and in the newer systems it drops below 1%.

SteveOn March 17, 2005 03:59 pm, Alan Wolfe wrote:

Hi Martin,

You may want to search the archives on this issue if no one speaks up.

Last time this conversation came out it was pointed out that the finest
resolution current OS’s can even deal with scheduling is 10ms. Not
sure if those are the right terms but basicly the issue was that if you
put in a delay, it would basicly get rounded off to the nearest 10ms
and this was caused by the OS and not SDL.

SDL_WaitEvent waits 10 ms between polls in the eventqueue. This delay
is unacceptable for me.

Are you sure you read that right? I have, and have helped, friends
running many types of psychological (mostly cognitive psychology –
really the only place computers are used in psychology) experiments. Do
you realize 10ms occurs 100 times in a single second?

What is your experiment reading that requires more granularity than
that?On Mar 17, 2005, at 1:32 PM, Martin Lange wrote:

Donny Viszneki wrote:

SDL_WaitEvent waits 10 ms between polls in the eventqueue. This delay
is unacceptable for me.

Are you sure you read that right? I have, and have helped, friends
running many types of psychological (mostly cognitive psychology –
really the only place computers are used in psychology) experiments.
Do you realize 10ms occurs 100 times in a single second?

What is your experiment reading that requires more granularity than that?

10 msec precision is not a big issue when measuring reaction times
(the standard deviation of rt in humans is at least 100msec),
but latencies of 10 milliseconds or more (which happen in standard
Linux kernel, especially when X window is running)
make it very difficult, if not impossible, to do do subliminal
presentation of images.
There you need frame-by-frame control to be sure that the stimuli are
presented for a precise number of millisec.
(at 50 ms, a stimulus can be invisible, and be visible when presented 60
ms or more).

Latencies, and lack of precision, is also problematic when you
synchronise the PC with an external equipment (e.g. an
electroencephalogram system) that must be syncrhonised at the millisecond.

When using audio, a delay a fraction of a millisecond between the
right and the left hear change the perceived location of the sound.
Therefore you sometimes need to able to synchronise sounds at the sample
level. Few audio libraries allow that…

SDL (or even pygame) is fine for many psychology experiments, but cannot
be used, alone, for all of them.

Christophe Pallier
http://www.pallier.org> On Mar 17, 2005, at 1:32 PM, Martin Lange wrote:

Well, now this is not really a psychological mailing list, but still… A
short answer.

I am part experimental psychological and part computer scientist (or what
the english term is).
My current job is programming libraries for use at my university. So what
the granularity should be is not really up to me, since the libraries is
used by other scientists. I just want it as good as possible.

Reaction times is really many things. For example we want subjects to hit
space when a line has reached a ceartain point on the screen. The line is
growing steadily. In this case reaction times is very precise, because the
subject knows in advance when they want to hit the key. If we want to
regsiter the time or the line length, then 10 ms. can be way off. At least
compared to optimum.

Also our eyetracker system has a granularity of 2 ms, so if we want to
synchronize keypresses with it, then 10 ms. is also suboptimal.

E-prime, a commercial experiment enviroment, brags that the have
"millisecond precision". This is actually verified by a third party. So 10
ms is really far from what is possible.
Of cousre this only works when all othe processes is terminated or sleeping
and E-prime runs at “Realtime priority”, which is not really realtime on
win32.

I am not really concerned with overhead from SDL to directinput, since this
is probably less than a microsecond. But any sleep like ops would be
annoing.

But thanks for the replies. I think I have to do a couple of tests, with
external analog equepment to
really find the answer to this (off) topic.

-Martin>From: Christophe Pallier

Reply-To: “A list for developers using the SDL library.
(includesSDL-announce)”
To: "A list for developers using the SDL library. (includes
SDL-announce)"
Subject: Re: [SDL] Q: timing of SDL events
Date: Fri, 18 Mar 2005 09:52:29 +0100

Donny Viszneki wrote:

On Mar 17, 2005, at 1:32 PM, Martin Lange wrote:

SDL_WaitEvent waits 10 ms between polls in the eventqueue. This delay is
unacceptable for me.

Are you sure you read that right? I have, and have helped, friends running
many types of psychological (mostly cognitive psychology – really the
only place computers are used in psychology) experiments. Do you realize
10ms occurs 100 times in a single second?

What is your experiment reading that requires more granularity than that?

10 msec precision is not a big issue when measuring reaction times (the
standard deviation of rt in humans is at least 100msec),
but latencies of 10 milliseconds or more (which happen in standard Linux
kernel, especially when X window is running)
make it very difficult, if not impossible, to do do subliminal
presentation of images.
There you need frame-by-frame control to be sure that the stimuli are
presented for a precise number of millisec.
(at 50 ms, a stimulus can be invisible, and be visible when presented 60 ms
or more).

Latencies, and lack of precision, is also problematic when you synchronise
the PC with an external equipment (e.g. an electroencephalogram system)
that must be syncrhonised at the millisecond.

When using audio, a delay a fraction of a millisecond between the right
and the left hear change the perceived location of the sound.
Therefore you sometimes need to able to synchronise sounds at the sample
level. Few audio libraries allow that…

SDL (or even pygame) is fine for many psychology experiments, but cannot be
used, alone, for all of them.

Christophe Pallier
http://www.pallier.org


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Find det, du s?ger p? MSN S?g http://search.msn.dk