Skip to content

Commit e5cdea1

Browse files
Merge pull request #11 from Remi-Gau/remi-fix_onset_time
fix onset time
2 parents fee86f3 + 9554957 commit e5cdea1

File tree

6 files changed

+298
-133
lines changed

6 files changed

+298
-133
lines changed

audioLocTranslational.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
% Safety loop: close the screen if code crashes
3131
try
3232

33-
%% Init the experiment
34-
[cfg] = initPTB(cfg);
35-
3633
% % % REFACTOR THIS FUNCTION % % %
3734

3835
[cfg] = loadAudioFiles(cfg);
3936

4037
% % % REFACTOR THIS FUNCTION % % %
4138

39+
%% Init the experiment
40+
[cfg] = initPTB(cfg);
41+
4242
[el] = eyeTracker('Calibration', cfg);
4343

4444
% % % REFACTOR THIS FUNCTION % % %
@@ -51,7 +51,7 @@
5151
logFile.extraColumns = cfg.extraColumns;
5252
logFile = saveEventsFile('open', cfg, logFile);
5353

54-
disp(cfg);
54+
% disp(cfg);
5555

5656
% Show experiment instruction
5757
standByScreen(cfg);
@@ -71,14 +71,14 @@
7171

7272
%% For Each Block
7373

74-
for iBlock = 1:cfg.numBlocks
74+
for iBlock = 1:cfg.design.nbBlocks
7575

7676
fprintf('\n - Running Block %.0f \n', iBlock);
7777

7878
eyeTracker('StartRecording', cfg);
7979

8080
% For each event in the block
81-
for iEvent = 1:cfg.numEventsPerBlock
81+
for iEvent = 1:cfg.design.nbEventsPerBlock
8282

8383
% Check for experiment abortion from operator
8484
checkAbort(cfg, cfg.keyboard.keyboard);

initEnv.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
persistent cacheval % speeds up repeated calls
7878

7979
if isempty (cacheval)
80-
cacheval = (exist ("OCTAVE_VERSION", "builtin") > 0);
80+
cacheval = (exist ('OCTAVE_VERSION', 'builtin') > 0);
8181
end
8282

8383
retval = cacheval;
@@ -86,7 +86,7 @@
8686
function addDependencies()
8787

8888
pth = fileparts(mfilename('fullpath'));
89-
addpath(fullfile(pth, 'lib', 'CPP_BIDS', 'src'));
89+
addpath(genpath(fullfile(pth, 'lib', 'CPP_BIDS', 'src')));
9090
addpath(fullfile(pth, 'lib', 'CPP_PTB'));
9191
addpath(genpath(fullfile(pth, 'lib', 'CPP_PTB', 'src')));
9292
addpath(fullfile(pth, 'subfun'));

setParameters.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@
3434

3535
%% Experiment Design
3636

37+
% cfg.design.motionType = 'translation';
38+
% cfg.design.motionType = 'radial';
39+
cfg.design.motionType = 'translation';
3740
cfg.design.names = {'static', 'motion'};
3841
cfg.design.possibleDirections = [-1 1]; % 1 motion , -1 static %NOT IN USE AT THE MOMENT
39-
cfg.design.nbBlocks = size(cfg.design.names, 2); % TO CHECK
40-
cfg.design.nbRepetitions = 1; % AT THE MOMENT IT IS NOT SET IN THE MAIN SCRIPT
42+
cfg.design.nbBlocks = size(cfg.design.names, 2); % TO CHECK
43+
cfg.design.nbRepetitions = 4; % AT THE MOMENT IT IS NOT SET IN THE MAIN SCRIPT
4144
cfg.design.nbEventsPerBlock = 12;
4245

4346
%% Timing
@@ -78,7 +81,7 @@
7881
cfg.fixation.yDisplacement = 0;
7982

8083
cfg.target.maxNbPerBlock = 2;
81-
cfg.target.duration = 0.05; % In secs
84+
cfg.target.duration = 0.5; % In secs
8285

8386
cfg.extraColumns = {'direction', 'speed', 'target', 'event', 'block', 'keyName'};
8487

subfun/doAudMot.m

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
function [onset, duration] = doAudMot(cfg, thisEvent, phandle)
2-
1+
function [onset, duration] = doAudMot(cfg, thisEvent)
2+
33
% Play the auditopry stimulation of moving in 4 directions or static noise bursts
44
%
55
% DIRECTIONS
@@ -13,19 +13,19 @@
1313
% Output:
1414
% -
1515
%
16-
16+
1717
%% Get parameters
18-
18+
1919
sound = [];
20-
20+
2121
direction = thisEvent.direction(1);
2222
isTarget = thisEvent.target(1);
2323
targetDuration = cfg.target.duration;
24-
24+
2525
soundData = cfg.soundData;
26-
26+
2727
% if isTarget == 0
28-
28+
2929
if direction == -1
3030
sound = soundData.S;
3131
elseif direction == 90
@@ -37,7 +37,7 @@
3737
elseif direction == 180
3838
sound = soundData.L;
3939
end
40-
40+
4141
% elseif isTarget == 1
4242
%
4343
% if direction == -1
@@ -53,21 +53,44 @@
5353
% end
5454
%
5555
% end
56-
56+
5757
% Start the sound presentation
58-
PsychPortAudio('FillBuffer', phandle, sound);
59-
playTime = PsychPortAudio('Start', phandle);
60-
onset = playTime;
61-
58+
PsychPortAudio('FillBuffer', cfg.audio.pahandle, sound);
59+
PsychPortAudio('Start', cfg.audio.pahandle);
60+
onset = GetSecs;
61+
62+
% draw first fixation and get a first visual time stamp
63+
% ideally we would want to synch that first time stamp and the sound start
6264
thisFixation.fixation = cfg.fixation;
6365
thisFixation.screen = cfg.screen;
64-
if GetSecs < (onset + targetDuration) && isTarget == 1
66+
if isTarget == 1
6567
thisFixation.fixation.color = cfg.fixation.colorTarget;
6668
end
6769
drawFixation(thisFixation);
68-
70+
vbl = Screen('Flip', cfg.screen.win);
71+
72+
while 1
73+
74+
% set default cross cross color but update if target time is not
75+
% finished
76+
thisFixation.fixation.color = cfg.fixation.color;
77+
if GetSecs < (onset + targetDuration) && isTarget == 1
78+
thisFixation.fixation.color = cfg.fixation.colorTarget;
79+
end
80+
81+
drawFixation(thisFixation);
82+
vbl = Screen('Flip', cfg.screen.win, vbl + cfg.screen.ifi);
83+
84+
status = PsychPortAudio('GetStatus', cfg.audio.pahandle);
85+
if ~status.Active
86+
break;
87+
end
88+
89+
end
90+
6991
% Get the end time
70-
% [~, ~, ~, stopTime] = PsychPortAudio('Stop',phandle);
71-
72-
% duration = stopTime - onset;
73-
duration = onset + 1.2;
92+
waitForEndOfPlayback = 1; % hard coding that will need to be moved out
93+
[onset, ~, ~, estStopTime] = PsychPortAudio('Stop', cfg.audio.pahandle, ...
94+
waitForEndOfPlayback);
95+
96+
duration = estStopTime - onset;

0 commit comments

Comments
 (0)