1919 %
2020 %
2121 %
22-
22+
2323 checkPtbVersion();
24-
24+
2525 pth = fileparts(mfilename(' fullpath' ));
2626 addpath(fullfile(pth , ' subfun' ));
27-
27+
2828 % For octave: to avoid displaying messenging one screen at a time
2929 more off ;
30-
30+
3131 % check for OpenGL compatibility, abort otherwise:
3232 AssertOpenGL ;
33-
33+
3434 cfg = setDefaultsPTB(cfg );
35-
35+
3636 initKeyboard ;
3737 initDebug(cfg );
38-
38+
3939 % Mouse
4040 HideCursor ;
41-
41+
4242 %% Audio
4343 cfg = initAudio(cfg );
44-
44+
4545 %% Visual
46-
46+
4747 % Get the screen numbers and draw to the external screen if avaliable
4848 cfg.screen.idx = max(Screen(' Screens' ));
49-
49+
5050 cfg = openWindow(cfg );
51-
51+
5252 % window size info
5353 [cfg .screen .winWidth , cfg .screen .winHeight ] = WindowSize(cfg .screen .win );
54-
54+
5555 % Get the Center of the Screen
5656 cfg.screen.center = [cfg .screen .winRect(3 ), cfg .screen .winRect(4 )] / 2 ;
57-
57+
5858 % Computes the number of pixels per degree given the distance to screen and
5959 % monitor width
6060 % This assumes that the window fills the whole screen
6161 cfg.screen.FOV = computeFOV(cfg );
6262 cfg.screen.ppd = cfg .screen .winRect(3 ) / cfg .screen .FOV ;
63-
63+
6464 % Initialize visual parmaters for fixation cross or dot
6565 cfg = initFixation(cfg );
66-
66+
6767 %% Select specific text font, style and size
6868 initText(cfg );
69-
69+
7070 %% Timing
7171 % Query frame duration
7272 cfg.screen.ifi = Screen(' GetFlipInterval' , cfg .screen .win );
7373 cfg.screen.monitorRefresh = 1 / cfg .screen .ifi ;
74-
74+
7575 % Set priority for script execution to realtime priority:
7676 Priority(MaxPriority(cfg .screen .win ));
77-
77+
7878 %% Warm up some functions
7979 % Do dummy calls to GetSecs, WaitSecs, KbCheck to make sure
8080 % they are loaded and ready when we need them - without delays
8181 % in the wrong moment:
8282 KbCheck ;
8383 WaitSecs(0.1 );
8484 GetSecs ;
85-
85+
8686end
8787
8888function initDebug(cfg )
89-
89+
9090 % init PTB with different options in concordance to the debug Parameters
9191 Screen(' Preference' , ' SkipSyncTests' , 0 );
9292 if cfg .debug .do
93-
93+
9494 Screen(' Preference' , ' SkipSyncTests' , 2 );
9595 Screen(' Preference' , ' Verbosity' , 0 );
9696 Screen(' Preference' , ' SuppressAllWarnings' , 1 );
97-
97+
9898 fprintf(' \n\n\n\n ' );
9999 fprintf(' ########################################\n ' );
100100 fprintf(' ## DEBUG MODE. TIMING WILL BE OFF. ##\n ' );
101101 fprintf(' ########################################' );
102102 fprintf(' \n\n\n\n ' );
103-
103+
104104 testKeyboards(cfg );
105-
105+
106106 end
107-
107+
108108 if cfg .debug .transpWin
109109 PsychDebugWindowConfiguration ;
110110 end
111-
111+
112112end
113113
114114function initKeyboard
115-
115+
116116 % Make sure keyboard mapping is the same on all supported operating systems
117117 % Apple MacOS/X, MS-Windows and GNU/Linux:
118118 KbName(' UnifyKeyNames' );
119-
119+
120120 % Don't echo keypresses to Matlab window
121121 ListenChar(-1 );
122-
122+
123123end
124124
125125function cfg = initAudio(cfg )
126-
126+
127127 if cfg .audio .do
128-
128+
129129 InitializePsychSound(1 );
130-
130+
131131 cfg.audio.devIdx = [];
132132 cfg.audio.playbackMode = 1 ;
133-
133+
134134 if isfield(cfg .audio , ' useDevice' )
135-
135+
136136 % get audio device list
137137 audioDev = PsychPortAudio(' GetDevices' );
138-
138+
139139 % find output device to use
140140 idx = find( ...
141141 audioDev.NrInputChannels == cfg .audio .inputChannels && ...
142142 audioDev.NrOutputChannels == cfg .audio .channels && ...
143143 ~cellfun(@isempty , regexp({audioDev .HostAudioAPIName }, cfg .audio .deviceName )));
144-
144+
145145 % save device ID
146146 cfg.audio.devIdx = audioDev(idx ).DeviceIndex;
147-
147+
148148 % get device's sampling rate
149149 cfg.audio.fs = audioDev(idx ).DefaultSampleRate;
150-
150+
151151 end
152-
152+
153153 cfg.audio.pahandle = PsychPortAudio(' Open' , ...
154154 cfg .audio .devIdx , ...
155155 cfg .audio .playbackMode , ...
156156 cfg .audio .requestedLatency , ...
157157 cfg .audio .fs , ...
158158 cfg .audio .channels );
159-
159+
160160 % set initial PTB volume for safety (participants can adjust this manually
161161 % at the begining of the experiment)
162162 PsychPortAudio(' Volume' , cfg .audio .pahandle , cfg .audio .initVolume );
163-
163+
164164 cfg.audio.pushSize = cfg .audio .fs * 0.010 ; % ! push N ms only
165-
165+
166166 cfg.audio.requestOffsetTime = 1 ; % offset 1 sec
167167 cfg.audio.reqsSampleOffset = cfg .audio .requestOffsetTime * cfg .audio .fs ;
168-
168+
169169 end
170170end
171171
172172function cfg = openWindow(cfg )
173-
173+
174174 if cfg .debug .smallWin
175175 [cfg .screen .win , cfg .screen .winRect ] = ...
176176 Screen(' OpenWindow' , cfg .screen .idx , cfg .color .background , ...
@@ -179,36 +179,35 @@ function initDebug(cfg)
179179 [cfg .screen .win , cfg .screen .winRect ] = ...
180180 Screen(' OpenWindow' , cfg .screen .idx , cfg .color .background );
181181 end
182-
182+
183183 % Enable alpha-blending, set it to a blend equation useable for linear
184184 % superposition with alpha-weighted source.
185185 Screen(' BlendFunction' , cfg .screen .win , GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA );
186-
186+
187187end
188188
189189function cfg = initFixation(cfg )
190-
190+
191191 if strcmp(cfg .fixation .type , ' cross' )
192-
192+
193193 % Convert some values from degrees to pixels
194194 cfg.fixation = degToPix(' width' , cfg .fixation , cfg );
195-
195+
196196 % Prepare fixation cross
197197 cfg.fixation.xCoords = [-cfg .fixation .widthPix cfg .fixation .widthPix 0 0 ] + ...
198198 cfg .fixation .xDisplacement ;
199199 cfg.fixation.yCoords = [0 0 - cfg .fixation .widthPix cfg .fixation .widthPix ] + ...
200200 cfg .fixation .yDisplacement ;
201201 cfg.fixation.allCoords = [cfg .fixation .xCoords ; cfg .fixation .yCoords ];
202-
202+
203203 end
204-
205-
204+
206205end
207206
208207function initText(cfg )
209-
208+
210209 Screen(' TextFont' , cfg .screen .win , cfg .text .font );
211210 Screen(' TextSize' , cfg .screen .win , cfg .text .size );
212211 Screen(' TextStyle' , cfg .screen .win , cfg .text .style );
213-
212+
214213end
0 commit comments