Skip to content

Commit 9cab2ea

Browse files
committed
add more skills to this stand alone (audio and ppd calculator)
1 parent 3ad912c commit 9cab2ea

File tree

1 file changed

+89
-6
lines changed

1 file changed

+89
-6
lines changed

dev/devSandbox.m

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,62 @@
2323
% Init the structure that will contain PTB setup
2424
cfg = struct;
2525

26+
%% Visual
27+
28+
% set to false if no visual stimulation
29+
cfg.screen.do = true;
30+
2631
% Set the PTB window background manually
2732
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
2838

2939
% Init PTB, see the Sub-Functions below
3040
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+
3277
%%
3378
% -------------------------------------------------------------------------
3479
% -------------------------- SET YOUR VARS HERE ---------------------------
3580
% -------------------------------------------------------------------------
3681

37-
% Define black and white
38-
white = WhiteIndex(cfg.screen.idx);
39-
grey = white / 2;
40-
inc = white - grey;
41-
4282
% Grating size in pixels
4383
gratingSizePix = 600;
4484

@@ -66,6 +106,12 @@
66106
% -------------------------------------------------------------------------
67107
% ------------------------------ PLAYGROUND -------------------------------
68108
% -------------------------------------------------------------------------
109+
110+
% Define black and white
111+
white = WhiteIndex(cfg.screen.idx);
112+
grey = white / 2;
113+
inc = white - grey;
114+
69115
% Define Half-Size of the grating image.
70116
textureSize = gratingSizePix / 2;
71117

@@ -166,6 +212,8 @@
166212
function cfg = devSandbox_initPTB(cfg)
167213

168214
% Shorter version of `initPTB.m`
215+
216+
if cfg.screen.do
169217

170218
% Skip the PTB sync test
171219
Screen('Preference', 'SkipSyncTests', 2);
@@ -184,15 +232,50 @@
184232

185233
% Get the size of the on screen window
186234
[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;
187238

188239
% Query the frame duration
189240
cfg.screen.ifi = Screen('GetFlipInterval', cfg.screen.win);
241+
242+
% Get monitor refresh rate
243+
cfg.screen.monitorRefresh = 1 / cfg.screen.ifi;
190244

191245
% Set up alpha-blending for smooth (anti-aliased) lines
192246
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)
193253

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
194266
end
195267

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+
196279
function devSandbox_cleanUp
197280

198281
% A wrapper function to close all windows, ports, show mouse cursor, close keyboard queues

0 commit comments

Comments
 (0)