diff --git a/dev/devSandbox.m b/dev/devSandbox.m index 29165b3..637830a 100644 --- a/dev/devSandbox.m +++ b/dev/devSandbox.m @@ -23,22 +23,62 @@ % Init the structure that will contain PTB setup cfg = struct; + %% Visual + + % set to false if no visual stimulation + cfg.screen.do = true; + % Set the PTB window background manually - cfg.color.background = [127 127 27]; + cfg.color.background = [127 127 127]; + + % Set monitor parameters if you care about visual angle + cfg.visualAngle.do = true; + cfg.screen.monitorWidth = 21.5; % cm + cfg.screen.monitorDistance = 30; % cm % Init PTB, see the Sub-Functions below cfg = devSandbox_initPTB(cfg); + % OUTPUT: + % + % cfg.screen.idx % Screen number where to draw, external screen if avaliable + % cfg.screen.win % The onscreen window whose content should be shown at flip time + % cfg.screen.winRect % The onscreen window size in pixels coordinates + % cfg.screen.winWidth + % cfg.screen.winHeight + % cfg.screen.center % Center of the screen window + % cfg.screen.ifi % Frame duration + % cfg.screen.monitorRefresh % Monitor refresh rate + + % Compute pixels per degrees + cfg = devSandbox_computePpd(cfg); + + % OUTPUT: + % + % cfg.screen.ppd % The number of pixels per degree given the distance to screen + + %% Auditory + % Set AUDIO + + % set to false if no auditory stimulation + cfg.audio.do = true; + + % Set audio freq. and nb. of channels of your audio file input + cfg.audio.fs = 44100; + cfg.audio.channels = 2; + + % Init Audio, see the Sub-Functions below + cfg = devSandbox_initAudio(cfg); + + % OUTPUT: + % + % cfg.audio.pahandle + %% % ------------------------------------------------------------------------- % -------------------------- SET YOUR VARS HERE --------------------------- % ------------------------------------------------------------------------- - % Define black and white - white = WhiteIndex(cfg.screen.idx); - grey = white / 2; - inc = white - grey; - % Grating size in pixels gratingSizePix = 600; @@ -66,6 +106,12 @@ % ------------------------------------------------------------------------- % ------------------------------ PLAYGROUND ------------------------------- % ------------------------------------------------------------------------- + + % Define black and white + white = WhiteIndex(cfg.screen.idx); + grey = white / 2; + inc = white - grey; + % Define Half-Size of the grating image. textureSize = gratingSizePix / 2; @@ -167,29 +213,65 @@ % Shorter version of `initPTB.m` - % Skip the PTB sync test - Screen('Preference', 'SkipSyncTests', 2); + if cfg.screen.do + + % Skip the PTB sync test + Screen('Preference', 'SkipSyncTests', 2); - % Open a transparent window - PsychDebugWindowConfiguration; + % Open a transparent window + PsychDebugWindowConfiguration; - % Here we call some default settings for setting up Psychtoolbox - PsychDefaultSetup(2); + % Here we call some default settings for setting up Psychtoolbox + PsychDefaultSetup(2); - % Get the screen numbers and draw to the external screen if avaliable - cfg.screen.idx = max(Screen('Screens')); + % Get the screen numbers and draw to the external screen if avaliable + cfg.screen.idx = max(Screen('Screens')); - % Open an on screen window - [cfg.screen.win, cfg.screen.winRect] = Screen('OpenWindow', cfg.screen.idx, cfg.color.background); + % Open an on screen window + [cfg.screen.win, cfg.screen.winRect] = Screen('OpenWindow', cfg.screen.idx, cfg.color.background); + + % Get the size of the on screen window + [cfg.screen.winWidth, cfg.screen.winHeight] = WindowSize(cfg.screen.win); + + % Get the Center of the Screen + cfg.screen.center = [cfg.screen.winRect(3), cfg.screen.winRect(4)] / 2; + + % Query the frame duration + cfg.screen.ifi = Screen('GetFlipInterval', cfg.screen.win); + + % Get monitor refresh rate + cfg.screen.monitorRefresh = 1 / cfg.screen.ifi; + + % Set up alpha-blending for smooth (anti-aliased) lines + Screen('BlendFunction', cfg.screen.win, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA'); + + end + +end + +function cfg = devSandbox_initAudio(cfg) + + if cfg.audio.do + + InitializePsychSound(1); + + cfg.audio.pahandle = PsychPortAudio('Open', ... + [], ... + [], ... + [], ... + cfg.audio.fs, ... + cfg.audio.channels); + + end +end - % Get the size of the on screen window - [cfg.screen.winWidth, cfg.screen.winHeight] = WindowSize(cfg.screen.win); +function cfg = devSandbox_computePpd (cfg) - % Query the frame duration - cfg.screen.ifi = Screen('GetFlipInterval', cfg.screen.win); + % Computes the number of pixels per degree given the distance to screen and + % monitor width. This assumes that the window fills the whole screen - % Set up alpha-blending for smooth (anti-aliased) lines - Screen('BlendFunction', cfg.screen.win, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA'); + cfg.screen.FOV = 180 / pi * 2 * atan(cfg.screen.monitorWidth / (2 * cfg.screen.monitorDistance)); + cfg.screen.ppd = cfg.screen.winWidth / cfg.screen.FOV; end diff --git a/tests/test_setDefaultsPTB.m b/tests/test_setDefaultsPTB.m index 7db37ed..b7aefc3 100644 --- a/tests/test_setDefaultsPTB.m +++ b/tests/test_setDefaultsPTB.m @@ -65,7 +65,7 @@ function test_setDefaultsPtbAudio() 'color', struct( ... 'background', [0 0 0]), ... 'text', struct('font', 'Courier New', 'size', 18, 'style', 1)); - + expectedCFG.screen.monitorWidth = 42; expectedCFG.screen.monitorDistance = 134; expectedCFG.screen.resolution = {[], [], []};