|
23 | 23 | % Init the structure that will contain PTB setup |
24 | 24 | cfg = struct; |
25 | 25 |
|
| 26 | + %% Visual |
| 27 | + |
| 28 | + % set to false if no visual stimulation |
| 29 | + cfg.screen.do = true; |
| 30 | + |
26 | 31 | % Set the PTB window background manually |
27 | | - cfg.color.background = [127 127 27]; |
| 32 | + cfg.color.background = [127 127 127]; |
| 33 | + |
| 34 | + % Set monitor parameters if you care about visual angle |
| 35 | + cfg.visualAngle.do = true; |
| 36 | + cfg.screen.monitorWidth = 21.5; % cm |
| 37 | + cfg.screen.monitorDistance = 30; % cm |
28 | 38 |
|
29 | 39 | % Init PTB, see the Sub-Functions below |
30 | 40 | cfg = devSandbox_initPTB(cfg); |
31 | 41 |
|
| 42 | + % OUTPUT: |
| 43 | + % |
| 44 | + % cfg.screen.idx % Screen number where to draw, external screen if avaliable |
| 45 | + % cfg.screen.win % The onscreen window whose content should be shown at flip time |
| 46 | + % cfg.screen.winRect % The onscreen window size in pixels coordinates |
| 47 | + % cfg.screen.winWidth |
| 48 | + % cfg.screen.winHeight |
| 49 | + % cfg.screen.center % Center of the screen window |
| 50 | + % cfg.screen.ifi % Frame duration |
| 51 | + % cfg.screen.monitorRefresh % Monitor refresh rate |
| 52 | + |
| 53 | + % Compute pixels per degrees |
| 54 | + cfg = devSandbox_computePpd(cfg); |
| 55 | + |
| 56 | + % OUTPUT: |
| 57 | + % |
| 58 | + % cfg.screen.ppd % The number of pixels per degree given the distance to screen |
| 59 | + |
| 60 | + %% Auditory |
| 61 | + % Set AUDIO |
| 62 | + |
| 63 | + % set to false if no auditory stimulation |
| 64 | + cfg.audio.do = true; |
| 65 | + |
| 66 | + % Set audio freq. and nb. of channels of your audio file input |
| 67 | + cfg.audio.fs = 44100; |
| 68 | + cfg.audio.channels = 2; |
| 69 | + |
| 70 | + % Init Audio, see the Sub-Functions below |
| 71 | + cfg = devSandbox_initAudio(cfg); |
| 72 | + |
| 73 | + % OUTPUT: |
| 74 | + % |
| 75 | + % cfg.audio.pahandle |
| 76 | + |
32 | 77 | %% |
33 | 78 | % ------------------------------------------------------------------------- |
34 | 79 | % -------------------------- SET YOUR VARS HERE --------------------------- |
35 | 80 | % ------------------------------------------------------------------------- |
36 | 81 |
|
37 | | - % Define black and white |
38 | | - white = WhiteIndex(cfg.screen.idx); |
39 | | - grey = white / 2; |
40 | | - inc = white - grey; |
41 | | - |
42 | 82 | % Grating size in pixels |
43 | 83 | gratingSizePix = 600; |
44 | 84 |
|
|
66 | 106 | % ------------------------------------------------------------------------- |
67 | 107 | % ------------------------------ PLAYGROUND ------------------------------- |
68 | 108 | % ------------------------------------------------------------------------- |
| 109 | + |
| 110 | + % Define black and white |
| 111 | + white = WhiteIndex(cfg.screen.idx); |
| 112 | + grey = white / 2; |
| 113 | + inc = white - grey; |
| 114 | + |
69 | 115 | % Define Half-Size of the grating image. |
70 | 116 | textureSize = gratingSizePix / 2; |
71 | 117 |
|
|
167 | 213 |
|
168 | 214 | % Shorter version of `initPTB.m` |
169 | 215 |
|
170 | | - % Skip the PTB sync test |
171 | | - Screen('Preference', 'SkipSyncTests', 2); |
| 216 | + if cfg.screen.do |
| 217 | + |
| 218 | + % Skip the PTB sync test |
| 219 | + Screen('Preference', 'SkipSyncTests', 2); |
172 | 220 |
|
173 | | - % Open a transparent window |
174 | | - PsychDebugWindowConfiguration; |
| 221 | + % Open a transparent window |
| 222 | + PsychDebugWindowConfiguration; |
175 | 223 |
|
176 | | - % Here we call some default settings for setting up Psychtoolbox |
177 | | - PsychDefaultSetup(2); |
| 224 | + % Here we call some default settings for setting up Psychtoolbox |
| 225 | + PsychDefaultSetup(2); |
178 | 226 |
|
179 | | - % Get the screen numbers and draw to the external screen if avaliable |
180 | | - cfg.screen.idx = max(Screen('Screens')); |
| 227 | + % Get the screen numbers and draw to the external screen if avaliable |
| 228 | + cfg.screen.idx = max(Screen('Screens')); |
181 | 229 |
|
182 | | - % Open an on screen window |
183 | | - [cfg.screen.win, cfg.screen.winRect] = Screen('OpenWindow', cfg.screen.idx, cfg.color.background); |
| 230 | + % Open an on screen window |
| 231 | + [cfg.screen.win, cfg.screen.winRect] = Screen('OpenWindow', cfg.screen.idx, cfg.color.background); |
| 232 | + |
| 233 | + % Get the size of the on screen window |
| 234 | + [cfg.screen.winWidth, cfg.screen.winHeight] = WindowSize(cfg.screen.win); |
| 235 | + |
| 236 | + % Get the Center of the Screen |
| 237 | + cfg.screen.center = [cfg.screen.winRect(3), cfg.screen.winRect(4)] / 2; |
| 238 | + |
| 239 | + % Query the frame duration |
| 240 | + cfg.screen.ifi = Screen('GetFlipInterval', cfg.screen.win); |
| 241 | + |
| 242 | + % Get monitor refresh rate |
| 243 | + cfg.screen.monitorRefresh = 1 / cfg.screen.ifi; |
| 244 | + |
| 245 | + % Set up alpha-blending for smooth (anti-aliased) lines |
| 246 | + Screen('BlendFunction', cfg.screen.win, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA'); |
| 247 | + |
| 248 | + end |
| 249 | + |
| 250 | +end |
| 251 | + |
| 252 | +function cfg = devSandbox_initAudio(cfg) |
| 253 | + |
| 254 | + if cfg.audio.do |
| 255 | + |
| 256 | + InitializePsychSound(1); |
| 257 | + |
| 258 | + cfg.audio.pahandle = PsychPortAudio('Open', ... |
| 259 | + [], ... |
| 260 | + [], ... |
| 261 | + [], ... |
| 262 | + cfg.audio.fs, ... |
| 263 | + cfg.audio.channels); |
| 264 | + |
| 265 | + end |
| 266 | +end |
184 | 267 |
|
185 | | - % Get the size of the on screen window |
186 | | - [cfg.screen.winWidth, cfg.screen.winHeight] = WindowSize(cfg.screen.win); |
| 268 | +function cfg = devSandbox_computePpd (cfg) |
187 | 269 |
|
188 | | - % Query the frame duration |
189 | | - cfg.screen.ifi = Screen('GetFlipInterval', cfg.screen.win); |
| 270 | + % Computes the number of pixels per degree given the distance to screen and |
| 271 | + % monitor width. This assumes that the window fills the whole screen |
190 | 272 |
|
191 | | - % Set up alpha-blending for smooth (anti-aliased) lines |
192 | | - Screen('BlendFunction', cfg.screen.win, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA'); |
| 273 | + cfg.screen.FOV = 180 / pi * 2 * atan(cfg.screen.monitorWidth / (2 * cfg.screen.monitorDistance)); |
| 274 | + cfg.screen.ppd = cfg.screen.winWidth / cfg.screen.FOV; |
193 | 275 |
|
194 | 276 | end |
195 | 277 |
|
|
0 commit comments