[visionegg] Re: timing in vision egg

Hi Joyca,

It's within a single "go loop" that the Vision Egg is able to maintain 
timing accuracy, but your code starts a "go loop" each time you want to 
display a new stimulus.  The go loop itself is lasting the duration you 
specify. Because your program doesn't clear the screen after the go 
loop finishes, the last frame drawn is displayed for too long -- the 
duration it takes for the next go loop to start.  In this case, an 
image must be read in from file, so it takes a while.  The simplest 
solution is to pre-load all your images like this:  (This would 
minimize the wait, although it still may not be absolutely temporally 
precise because multiple go loops are still spawned.)

*****************************************************
preloaded_stimulus_list = []
for i in range(0, len(photoX)):
     texture = TextureFromFile(photoX[i])
     stimulus = TextureStimulus(texture = texture,
                            size    = texture.orig.size,
                            shrink_texture_ok=1)
     preloaded_stimulus_list.append( stimulus )

viewport = Viewport(screen=screen)
p = Presentation(go_duration=(0.5,'seconds'),viewports=[viewport])

for i in range(0, len(photoX)):
     viewport.parameters.stimuli = [preloaded_stimulus_list[i]]
     p.go()
*****************************************************

The "ultimate" way would be to do everything in a single go loop, 
thereby ensuring timing across all your images.  This requires a 
Controller to select the image used.

*****************************************************
duration_per_image = 0.5 # seconds
num_images = len(photoX)

# Create list of stimuli
preloaded_stimulus_list = [] # empty at first
for i in range(num_images):
     # Read the texture file
     texture = TextureFromFile(photoX[i])

     # Load the texture to OpenGL, prepare for display
     stimulus = TextureStimulus(texture = texture,
                         size    = texture.orig.size,
                         shrink_texture_ok=1)

     # Add to list of stimuli
     preloaded_stimulus_list.append( stimulus )

def image_selector( t ):
     i = int(t/duration_per_image)
     return [ preloaded_stimulus_list[i] ]

viewport = Viewport(screen=screen)
p = Presentation(go_duration=(duration_per_image * 
num_images,'seconds'),viewports=[viewport])
p.add_controller(viewport,'stimuli', 
FunctionController(during_go_func=image_selector) )
p.go()
*****************************************************

Hopefully this helps.

Cheers!
Andrew

On Thursday, November 21, 2002, at 09:08  PM, Joyca Lacroix wrote:

> L.S.
>
> Currently I'm working on a psychological experiment in which I present 
> (timed) images of faces (tif format). I'm trying to present the images 
> in a sequence, every image for 1 second. Because I have only just 
> begun using vision egg I took one of the demo's in the VisionEgg 
> folder as a strating point (texture.py).
> I notice that when I present the pictures, the timing becomes less and 
> less precise (after a few images the presentation takes up to 2 sec. 
> and this delay becomes larger and larger)
> here is part of my code:
> ************************************************
> for i in range(0, len(photoX)):
>     texture = TextureFromFile(photoX[i])
>     stimulus = TextureStimulus(texture = texture,
>                            size    = texture.orig.size,
>                            shrink_texture_ok=1)
>     viewport = Viewport(screen=screen,
>                     stimuli=[stimulus])
>     p = Presentation(go_duration=(0.5,'seconds'),viewports=[viewport])
>
>     p.go()
> *****************************************************
>
> Can you help me get the timing more precise? (the problem is not my 
> videocard)
>
> Thank you in anticipation
> Greetings, J.L.
>
> j.lacroix@xxxxxxxxxxxxx
> ======================================
> The Vision Egg mailing list
> Archives: http://www.freelists.org/archives/visionegg
> Website: http://www.visionegg.org/mailinglist.html

======================================
The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html

Other related posts: