Skip to content

Commit 123ad4c

Browse files
committed
add play sound and time stamps
1 parent 7bda078 commit 123ad4c

File tree

2 files changed

+18
-82
lines changed

2 files changed

+18
-82
lines changed

ALocalizer.m

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -9,90 +9,8 @@
99

1010
for blocks = 1:numBlocks
1111

12-
timeLogger.block(blocks).startTime = GetSecs - experimentStartTime; % Get the start time of the block
13-
timeLogger.block(blocks).condition = condition(blocks); % Get the condition of the block (motion or static)
14-
timeLogger.block(blocks).names = names(blocks); % Get the name of the block
15-
16-
responseCount=0;
17-
1812
for iEvent = 1: numEventsPerBlock
1913

20-
Sound=[];
21-
22-
if isTarget(blocks,iEvent)==0
23-
24-
if strcmp(directions(blocks,iEvent),'S')
25-
Sound= soundData.S;
26-
elseif strcmp(directions(blocks,iEvent),'U')
27-
Sound= soundData.U;
28-
elseif strcmp(directions(blocks,iEvent),'D')
29-
Sound= soundData.D;
30-
elseif strcmp(directions(blocks,iEvent),'R')
31-
Sound= soundData.R;
32-
elseif strcmp(directions(blocks,iEvent),'L')
33-
Sound= soundData.L;
34-
end
35-
36-
elseif isTarget(blocks,iEvent)==1
37-
38-
if strcmp(directions(blocks,iEvent),'S')
39-
Sound= soundData.S_T;
40-
elseif strcmp(directions(blocks,iEvent),'U')
41-
Sound= soundData.U_T;
42-
elseif strcmp(directions(blocks,iEvent),'D')
43-
Sound= soundData.D_T;
44-
elseif strcmp(directions(blocks,iEvent),'R')
45-
Sound= soundData.R_T;
46-
elseif strcmp(directions(blocks,iEvent),'L')
47-
Sound= soundData.L_T;
48-
end
49-
50-
end
51-
52-
eventOnsets(blocks,iEvent)=GetSecs-experimentStartTime;
53-
54-
PsychPortAudio('FillBuffer',phandle,Sound);
55-
playTime(blocks,1) = PsychPortAudio('Start',phandle);
56-
57-
%length(playedAudio)/freq
58-
59-
while GetSecs() <= eventOnsets(blocks,iEvent)+ experimentStartTime + (length(Sound)/freq)
60-
61-
if strcmp(device,'Scanner')
62-
[sbutton,secs] = TakeSerialButton(SerPor);
63-
%[sbutton,secs] = MT_TakeSerialButtonPerFrame(SerPor);
64-
%responseKey(end+1)= sbutton;
65-
if sbutton~= 0
66-
responseTime(end+1)= secs - experimentStartTime;
67-
68-
%%%%%%%%%%%%%%%%%%%%%
69-
% while you are pressing, wait till it is
70-
% released
71-
while sbutton ~= 0
72-
[sbutton,secs]= TakeSerialButton(Cfg.SerPor);
73-
end
74-
%%%%%%%%%%%%%%%%%%%%%
75-
76-
responseCount = responseCount + 1;
77-
end
78-
79-
80-
81-
elseif strcmp(device,'PC')
82-
83-
[keyIsDown, secs, ~ ] = KbCheck();
84-
85-
if keyIsDown
86-
responseTime(end+1)= secs - experimentStartTime;
87-
while keyIsDown ==1
88-
[keyIsDown , ~] = KbCheck();
89-
end
90-
91-
responseCount = responseCount + 1;
92-
end
93-
end
94-
95-
end
9614

9715
eventEnds(blocks,iEvent)=GetSecs-experimentStartTime;
9816
eventDurations(blocks,iEvent)=eventEnds(blocks,iEvent)-eventOnsets(blocks,iEvent);

subfun/doAudMot.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,21 @@
5252
end
5353

5454
end
55+
56+
% Start the sound presentation
57+
PsychPortAudio('FillBuffer',phandle,sound);
58+
playTime = PsychPortAudio('Start',phandle);
59+
onset = playtime;
60+
61+
% Draw the fixation cross
62+
color = expParameters.fixationCrossColor;
63+
% If this frame shows a target we change the color
64+
if GetSecs < (onset+targetDuration) && isTarget==1
65+
color = expParameters.fixationCrossColorTarget;
66+
end
67+
drawFixationCross(cfg, expParameters, color)
68+
69+
% Get the end time
70+
[~, ~, ~, stopTime} = PsychPortAudio('Stop',phandle);
71+
72+
duration = stopTime - onset;

0 commit comments

Comments
 (0)