-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReader_MRIsts_run1.m
108 lines (88 loc) · 3.42 KB
/
Reader_MRIsts_run1.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
% Elis_PIP
% The script is designed to use PsychToolBox and PsychPortAudio to present
% audio stimulus (.wav files).
% Modification of Elizabeth Bock's 2013 script by JC
%% DEFINE PARAMETERS FOR EXPERIMENT
clear mex
ISI = 0.650;
pulseLength = 0.002;
freq = 1000;
duration = 0.5;
sampleFreq = 44100;
dt = 1/sampleFreq;
t = [0:dt:duration];
s=sin(2*pi*freq*t);
ss = [s;s];
isDebug = 1; % this will be 1 for debug and 0 on the stim PC
%% INITIALIZE THE LOW_LATENCY PARALLEL PORT DRIVER
if ~isDebug
ioObj=io64;%create a parallel port handle
status=io64(ioObj);%if this returns '0' the port driver is loaded & ready
address=hex2dec('D010');%address of LPT1 in hex
io64(ioObj,address,0);
end
%% Initialize Audio Device
% Initialize driver, request low-latency preinit:
InitializePsychSound(1);
% Requested output frequency, may need adaptation on some audio-hw:
deviceid = [];
mode = [];
reqlatencyclass = 2;
freq = 44100; % Must set this. 96khz, 48khz, 44.1khz.
nChannels = 2;
% Open audio device for low-latency output:
%pahandle = PsychPortAudio('Open', deviceid, [], reqlatencyclass, freq, 2, buffersize, suggestedLatencySecs);
pahandle = PsychPortAudio('Open', deviceid, mode, reqlatencyclass, freq, nChannels);
% Fill buffer with data:
PsychPortAudio('FillBuffer', pahandle, ss);
% Perform one warmup trial, to get the sound hardware fully up and running,
% performing whatever lazy initialization only happens at real first use.
% This "useless" warmup will allow for lower latency for start of playback
% during actual use of the audio driver in the real trials:
PsychPortAudio('Start', pahandle, 1, 0, 1);
PsychPortAudio('Stop', pahandle, 1);
%% Initialize Visual Screen
[window, screenRect]=Screen('OpenWindow',0, [0 0 0]); %, [200 200 800 800]);%open a window for stimulus display
[ ifi nvalid stddev ]= Screen('GetFlipInterval', window, 100, 0.00005, 20);
%% Define stimulus (.wav files)
pip = 'TOTALSparsedTonesStimuli_complete_run1.wav';
ttl = 'TOTALSparsedTonesStimuli_MEG_TTL_run1.wav';
% load the sound file
sound1 = audioread(pip);
sound2 = audioread(ttl);
sound = [sound1 sound2]';
PsychPortAudio('FillBuffer', pahandle, sound);
%% Start trials
% Allow the subject to start when ready
DrawFormattedText(window, 'Press a key to begin','center','center',255*[1 1 1]); % black screen, white crosshair
[endON StimulusOnsetTime FlipTimestamp Missed Beampos] = Screen(window, 'Flip');
KbWait;
% place a crosshair on the screen
DrawFormattedText(window, '+','center','center',255*[1 1 1]); % black screen, white crosshair
Screen(window, 'Flip');
try
Priority(2);%raise priority for stimulus presentation
% init some mex functions
starttime = WaitSecs(.001);
% play the sound
PsychPortAudio('Start', pahandle, 1, 0, 1);
% io64(ioObj,address,1);
% WaitSecs(0.001);
% io64(ioObj,address,0);
% wait for the sound to finish
WaitSecs(size(sound,2)/freq);
% wait ISI before playing next stim
WaitSecs(ISI);
catch ME
Priority(0);%drop priority back to normal
disp(ME)
Screen('CloseAll');
clear mex;
return;
end
Priority(0);%drop priority back to normal
DrawFormattedText(window, 'Done','center','center',255*[1 1 1]); % black screen, white crosshair
Screen(window, 'Flip');
KbWait;
Screen('CloseAll');
clear mex;