Hi all,
I've been using Psychtoolboox for creating a gif-like image sequence within a window. Code seems to work fine until around 15th loop. After that Screen('Flip') command starts to get delayed for 150 ms and animation slows down. If i add a little pause time (couple of seconds) before the animation loop starts, then Screen('Flip') starts to function with the same amount of delay without the un-delayed Flips.
This is a representation of image flow:
sam1 (ISI: 85ms) -> sam2 (Target: 185ms) ->sam1 (ISI: 85ms)-> sam3 (Target: 185ms)
I'm using 'printtime' matrice for checking Flip delays. I've used tic & toc for measuring Flip delays, i had the same problem. I've tried to synchronize Flips by using when arguments however it did not solve the problem. I've Flipped screens without two stimulus durations (without adding samduration&samlatency into when argument of Screen(Flip)) then there was no delay in Flipping -at least it was not 150ms-, but the images sometimes lose their order of Flipping.
Does this problem stem from using DrawTexture command and .jpg images? Would i experience the same problem If I used FillRect command and manually create all the images within Matlab?
Here is my code;
-------------
close all;
sca;
PsychDefaultSetup(2);
KbName('UnifyKeyNames');
%%Window
screens=Screen('Screens');
screenNumber=max(screens);
white=WhiteIndex(screenNumber);
black=BlackIndex(screenNumber);
grey=white/2;
%OpenWindow%
PsychImaging('PrepareConfiguration');
PsychImaging('AddTask', 'General', 'UseFastOffscreenWindows');
[window,windowrect]=PsychImaging('OpenWindow',screenNumber,white);
[Xcenter,Ycenter]=RectCenter(windowrect);
%RefreshRate
ifi=Screen('GetFlipInterval',window);
toppriorityLevel=MaxPriority(window,'Screen');
numFrames=round(numSecs/ifi);
waitframes=1;
screenwait=(waitframes-0.5)*ifi;
HideCursor();
%%Import Jpg Images%%
SAM1="sam1.jpg";SAM1copy="sam1 - Copy.jpg";
SAM2="sam2.jpg";SAM3="sam3.jpg";
%%Read JPGs & Convert into Textures%%
SAMfirst=imread(SAM1,'jpg');SAMfirstcopy=imread(SAM1copy,'jpg');
SAMsecond=imread(SAM2,'jpg');SAMthird=imread(SAM3,'jpg');
%%Make Texture%%
samfirstTEXT=Screen('MakeTexture',window,SAMfirst);
samfirstTEXTcopy=Screen('MakeTexture',window,SAMfirstcopy);
samsecondTEXT=Screen('MakeTexture',window,SAMsecond);
samthirdTEXT=Screen('MakeTexture',window,SAMthird);
%%Durations%%
trainingduration=120;
samlatency=0.085;
samduration=0.185;
%%KeyCodes%%
switchkey=KbName('space');
escapekey=KbName('ESCAPE');
%%%Response & Timer Sheets%%%
response_sheet=zeros(1,100);
time_sheet=zeros(1,100);
%%Flip Interval Sheet%%
printtime=nan(240,6);
%%%KbQueue Initiate%%
experiment_start=GetSecs;
KbQueueCreate;
KbQueueStart;
%%Loop & Response Iteration Marker%%
i=0;
sheetmarker=0;
%%Loop Start Timer%%
samtimer=tic;
vb=Screen('Flip',window);
Priority(toppriorityLevel);
while toc(samtimer)<trainingduration
i=i+1;
Screen('DrawTexture',window,samfirstTEXT);
Screen('DrawingFinished',window,2);
vb2=Screen('Flip',window,vb+samduration+screenwait);
a=vb2-vb;
printtime(i,1)=a;
Screen('DrawTexture',window,samsecondTEXT);
Screen('DrawingFinished',window,2);
vb3=Screen('Flip', window,vb2+samlatency+screenwait);
b=vb3-vb2;
printtime(i,2)=b;
Screen('DrawTexture',window,samfirstTEXTcopy);
Screen('DrawingFinished',window,2);
vb4=Screen('Flip',window,vb3+samduration+screenwait);
wth=vb4-experiment_start;
c=vb4-vb3;
printtime(i,3)=c;
Screen('DrawTexture',window,samthirdTEXT);
Screen('DrawingFinished',window,2);
vb=Screen('Flip',window,vb4+samlatency+screenwait);
d=vb-vb4;
printtime(i,4)=d;
%%%%%Keyboard Input Check, Response & Reaction Time Save%%%%%%
[pressed, firstPress]=KbQueueCheck();
if pressed
firstPress(find(firstPress==0))=NaN; %#ok<FNDSB>
reactiontimevector=firstPress-experiment_start;
reactiontimes=reactiontimevector(reactiontimevector>0.05);
[endtime, Index]=min(firstPress);
thekeys=KbName(Index);
if KbName(thekeys)==switchkey
sheetmarker=sheetmarker+1;
response_sheet(1,sheetmarker)=1;
time_sheet(1,sheetmarker)=min(reactiontimes);
elseif KbName(thekeys)==escapekey
break;
KbQueueFlush;
end
end
end
Priority(0);
toc(samtimer);
ShowCursor;
KbQueueFlush;
sca;