|
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 | 32 | cfg.color.background = [127 127 27]; |
| 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 = false; |
| 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 |
|
|
166 | 212 | function cfg = devSandbox_initPTB(cfg) |
167 | 213 |
|
168 | 214 | % Shorter version of `initPTB.m` |
| 215 | + |
| 216 | + if cfg.screen.do |
169 | 217 |
|
170 | 218 | % Skip the PTB sync test |
171 | 219 | Screen('Preference', 'SkipSyncTests', 2); |
|
184 | 232 |
|
185 | 233 | % Get the size of the on screen window |
186 | 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; |
187 | 238 |
|
188 | 239 | % Query the frame duration |
189 | 240 | cfg.screen.ifi = Screen('GetFlipInterval', cfg.screen.win); |
| 241 | + |
| 242 | + % Get monitor refresh rate |
| 243 | + cfg.screen.monitorRefresh = 1 / cfg.screen.ifi; |
190 | 244 |
|
191 | 245 | % Set up alpha-blending for smooth (anti-aliased) lines |
192 | 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) |
193 | 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 |
194 | 266 | end |
195 | 267 |
|
| 268 | +function cfg = devSandbox_computePpd (cfg) |
| 269 | + |
| 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 |
| 272 | + |
| 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; |
| 275 | + |
| 276 | +end |
| 277 | + |
| 278 | + |
196 | 279 | function devSandbox_cleanUp |
197 | 280 |
|
198 | 281 | % A wrapper function to close all windows, ports, show mouse cursor, close keyboard queues |
|
0 commit comments