psychtoolbox doing things in the 'background' when flipping to screen for set interval

5 views (last 30 days)
Hi,
My apologies, I don't have extensive coding experience.
I'm trying to get precise timings for an fmri experiment in psychtoolbox. Does anyone know of a way to get psychtoolbox to keep running things in the 'background' whilst you present something on the screen for a set amount of time, rather than waiting until the stimulus has been presented, and then continue with the calculations?
for example, say i present a stimulus to the screen for 200ms;
onset = GetSecs;
waitTime = 0.2;
while GetSecs - onset < waitTime;
DrawFormattedText(window, fixation, 'center', 'center', fixation_colour);
Screen('Flip', window);
end
but i also wanted to generate the next stimulus for stimulus presentation (this can't be pre-generated outside of the loop due to a value changing on each iteration of the loop dependent on pp performance) in the background without this affecting the 200ms presentation time. the stimulus generation currently takes about 50ms, and so my total time for this loop is 250ms. Is there away to get psychtoolbox to flip the stimulus to the screen for 200ms, and then whilst it's waiting for this to complete, generate the next stimulus, without affecting the overall loop time?
for example, i currently have: (this takes approximately 250ms, rather than the 200ms i desire
onset = GetSecs;
waitTime = 0.2;
y = 0;
while GetSecs - onset < waitTime;
DrawFormattedText(window, fixation, 'center', 'center', fixation_colour);
Screen('Flip', window);
while y < 1; %i've included this so that it only generates this once despite the 1:numFrames clause.
distances_target = RFP_generator(phi,C,A); %generate new stimulus.
sn = Screen('MakeTexture', window, distances_target);
y = y + 1;
end
end
Thanks in advance!

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!