-
Notifications
You must be signed in to change notification settings - Fork 1
/
RunExpTest_FullExperiment.m
301 lines (249 loc) · 10.7 KB
/
RunExpTest_FullExperiment.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
global EXPWIN GREY Calib
InitExp;
ISI=Constants.ISI_MIN;
[pahandle, buffer]=LoadSoundSchedule(wavfilenames,Constants.audiodir);
[AudioStimList,CorrectLocation]=generateTrials(Constants);
%else keep all the wavs but set a range
if(Constants.AudioStimulusHeldConstant==Constants.LOW)
%rng=10:-1:2;
rng=length(wavfilenames):-1:2;
constantStim=1;
elseif(Constants.AudioStimulusHeldConstant==Constants.HIGH)
%rng=1:9;
rng=1:(length(wavfilenames)-1);
constantStim=length(wavfilenames);
end
while(training)
trial=trial+1;
animate_fix=0;
%animate_fix=1; % if we want each trial
PsychPortAudio('UseSchedule', pahandle, 1);
%we need to determine the appropriate sound to play for this trial
if(Constants.AudioStimulusHeldConstant==Constants.LOW)
if(AudioStimList(trial)==Constants.LOW)
PsychPortAudio('AddToSchedule', pahandle, buffer(constantStim), 1);
elseif(AudioStimList(trial)==Constants.HIGH)
PsychPortAudio('AddToSchedule', pahandle, buffer(rng(StepStimulus(trial))), 1);
end
elseif(Constants.AudioStimulusHeldConstant==Constants.HIGH)
if(AudioStimList(trial)==Constants.LOW)
PsychPortAudio('AddToSchedule', pahandle, buffer(rng(StepStimulus(trial))), 1);
elseif(AudioStimList(trial)==Constants.HIGH)
PsychPortAudio('AddToSchedule', pahandle, buffer(constantStim), 1);
end
end
%end
%display fix %& wait for fixation
InitAV;
disp(['Start' num2str(trial) ', step size: ' num2str( StepStimulus(trial)) ])
VisStimInit=0;
%No listening during real experiment
%moviename=[Constants.imagedir 'listen_' Constants.fixpoint_img '.mp4'];
%rect=FixationSquare;
%PlayMovieBegin;
while(~finished)
drawQuestionMark;
if(animate_fix)
Screen('DrawTexture', EXPWIN, blockTex, bRect, FixationSquare);
end
if(Constants.UseEyeTracker)
[left_xyTMP, right_xyTMP, left_pupilTMP, right_pupilTMP, ...
left_validityTMP, right_validityTMP, emptyset]=...
GetEyeData(ScreenTime(end-1), ScreenTime(end));
else
UseMouse;
end
if(~emptyset)
left_xy(end+1,:)=left_xyTMP(end,:);
right_xy(end+1,:)=right_xyTMP(end,:);
left_pupil(end+1,:)=left_pupilTMP(end,:);
right_pupil(end+1,:)=right_pupilTMP(end,:);
left_validity(end+1,:)=left_validityTMP(end,:);
right_validity(end+1,:)=right_validityTMP(end,:);
EyeTime(end+1)=ScreenTime(end);
EyeInsideLR(end+1,1)=EyeInAOI_Median(right_xy(end,:),...
left_xy(end,:),Calib,LeftChoiceSquare,Constants.AOI_border);
EyeInsideLR(end,2)=EyeInAOI_Median(right_xy(end,:),...
left_xy(end,:),Calib,RightChoiceSquare,Constants.AOI_border);
EyeInsideLR(end,3)=0;
AllEyeData= [AllEyeData; zeros(size(left_xyTMP,1),1)+EyeTime(end) ...
left_xyTMP right_xyTMP left_pupilTMP right_pupilTMP ...
left_validityTMP right_validityTMP];
%if(animate_fix)
% playFixAnimation
% animate_fix=0;
% keyboard
%end
if(length(EyeInsideLR)>Constants.FixThresh)
%LOOKING AT LEFT SIDE AOI
if(EyeInsideLR(end,1)==1 & EyeInsideLR(end,2)==0)
%don´t chnage if we are in a nonvisble trial
if(Constants.LRvisible ~= 2); %2=right only visible
if(sum(EyeInsideLR(end-Constants.FixThresh:end,1))>=Constants.FixThresh)
%evaluate if we are correct
if(CorrectLocation(trial)==Constants.LEFT)
if(animate_fix)
%playFixAnimation
playFlashAnimation
animate_fix=0;
end
moviename=[Constants.imagedir VidDirList(fn).name];
rect=LeftChoiceSquare;
PlayMovie
finished=1;
trialScore(trial)=1;
else
%if(animate_fix)
% playFixAnimation
% animate_fix=0;
%end
Screen('DrawTexture', EXPWIN, ...
blockTex_Incorrect, ...
bRect_Incorrect, LeftChoiceSquare);
%display incorrect X
finished=1;
Screen(EXPWIN,'Flip');
WaitSecs(Constants.IncorrectTimeOut);
end
end
end
%LOOKING AT RIGHT SIDE AOI
elseif(EyeInsideLR(end,1)==0 & EyeInsideLR(end,2)==1)
if(Constants.LRvisible ~= 1); %1=left only visible
if(sum(EyeInsideLR(end-Constants.FixThresh:end,2))>=Constants.FixThresh)
%evaluate if we are correct
if(CorrectLocation(trial)==Constants.RIGHT)
if(animate_fix)
%playFixAnimation
playFlashAnimation
animate_fix=0;
end
moviename=[Constants.imagedir VidDirList(fn).name]; rect=RightChoiceSquare;
PlayMovie
finished=1;
trialScore(trial)=1;
else
if(animate_fix)
%playFixAnimation
playFlashAnimation
animate_fix=0;
end
Screen('DrawTexture', EXPWIN, blockTex_Incorrect, ...
bRect_Incorrect, RightChoiceSquare);
%display incorrect X
finished=1;
Screen(EXPWIN,'Flip');
WaitSecs(Constants.IncorrectTimeOut);
end
end
end
end
end
if(Constants.showGaze & ~finished)
drawGazeCursorNoPoll_EXP
end
ScreenTime(end+1)=Screen(EXPWIN,'Flip');
time_now=GetSecs-t1;
else
time_now=GetSecs-t1;
ScreenTime(end+1)=Screen(EXPWIN,'Flip');
end
if( (finished == 0) & time_now>Constants.trialTime)
finished=1;
DrawTimeOutMask;
end
if(~VisStimInit)
VisStimInit=1;
VisStimAppearTime=ScreenTime(end);
end
FlushEvents;
[~,~,keyCode,~] = KbCheck;
if( find(keyCode)== 80 ) % press 'P' button
disp('Starting attention movie......')
PlayAttentionMovie
end
if(CheckEsc)
training=0;
finished=1;
ESC_PRESSED=1;
end
Recalibrate;
PauseCheck;
end
%wait ISI
Screen('FillRect',EXPWIN,GREY);
Screen(EXPWIN,'Flip');
WaitSecs(ISI);
lxy=[left_xy_PRE; left_xy ];
rxy=[right_xy_PRE; right_xy];
lp=[left_pupil_PRE; left_pupil];
rp=[right_pupil_PRE; right_pupil];
lv=[left_validity_PRE; left_validity];
rv=[right_validity_PRE; right_validity];
eTime=[EyeTime_PRE'; EyeTime'];
eAOI=[EyeInsideLR_PRE; EyeInsideLR];
EyeData(trial).leye_xypv=[lxy lp lv];
EyeData(trial).reye_xypv=[rxy rp rv];
EyeData(trial).AOI=eAOI;
EyeData(trial).time=eTime;
TrialData(trial).AudioPlayTime=AudioPlayTime;
TrialData(trial).VisStimAppearTime=VisStimAppearTime;
%reset & add more trials
if(trial==length(AudioStimList))
[tL,cL]=generateTrials(Constants);
AudioStimList=[AudioStimList; tL];
CorrectLocation=[CorrectLocation cL];
end
%examine ongoing performance if 3 in a row correct move 1
%if 1 fail move down
TimeSinceLastStep=trial-TrialNumAtStep;
%by default assume step stays same then evaluate for change
StepStimulus(trial+1)=StepStimulus(trial);
if(trial>2)
if(trialScore(end)==0) %step down
if(StepStimulus(trial)>1)
disp('down')
StepStimulus(trial+1)=StepStimulus(trial)-1;
end
elseif(sum(trialScore(end-2:end))==3 & TimeSinceLastStep>2);
if(StepStimulus(trial)<length(rng))
disp('up')
StepStimulus(trial+1)=StepStimulus(trial)+1;
TrialNumAtStep=trial;
end
end
end
%here we should insert rules for ending test
EvalPerformance;
%rules to make training=0,
%1) if on lowest step, stop after 10 trials
%2)if on highest step, stop after 10 trials
%3) if 15 reversals
save(Constants.savefile,'Calib', 'trialScore','AudioStimList','CorrectLocation',...
'Constants','EyeData','StepStimulus', 'PerfCode', ...
'ReversalCount','TrialData')
end %training & trial +1
% Stop playback:
PsychPortAudio('Stop', pahandle);
% Delete all dynamic audio buffers:
PsychPortAudio('DeleteBuffer');
% Close audio device, shutdown driver:
PsychPortAudio('Close');
if(~ESC_PRESSED)
if(Constants.UseEyeTracker)
EyeErrorTestEnd=TestEyeTrackerError(Calib,mOrder,Constants);
end
Screen('FillRect',EXPWIN,GREY);
Screen(EXPWIN,'Flip');
WaitSecs(2);
if(Constants.UseEyeTracker)
save(Constants.savefile,'Calib', 'trialScore','AudioStimList','CorrectLocation',...
'EyeErrorTestEnd','Constants','EyeData','StepStimulus', 'PerfCode', ...
'ReversalCount','TrialData')
else
save(Constants.savefile,'Calib', 'trialScore','AudioStimList','CorrectLocation',...
'Constants','EyeData','StepStimulus', 'PerfCode', ...
'ReversalCount','TrialData')
end
end
Screen('CloseAll')