From 9cab2eab6d14cc3e1a297a7c2be7b0ecc99be1da Mon Sep 17 00:00:00 2001 From: marcobarilari Date: Thu, 10 Sep 2020 18:07:46 +0200 Subject: [PATCH 1/5] add more skills to this stand alone (audio and ppd calculator) --- dev/devSandbox.m | 95 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 6 deletions(-) diff --git a/dev/devSandbox.m b/dev/devSandbox.m index 29165b3..07e1450 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]; + + % 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 = false; + + % 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; @@ -166,6 +212,8 @@ function cfg = devSandbox_initPTB(cfg) % Shorter version of `initPTB.m` + + if cfg.screen.do % Skip the PTB sync test Screen('Preference', 'SkipSyncTests', 2); @@ -184,15 +232,50 @@ % 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 +function cfg = devSandbox_computePpd (cfg) + + % Computes the number of pixels per degree given the distance to screen and + % monitor width. This assumes that the window fills the whole screen + + cfg.screen.FOV = 180 / pi * 2 * atan(cfg.screen.monitorWidth / (2 * cfg.screen.monitorDistance)); + cfg.screen.ppd = cfg.screen.winWidth / cfg.screen.FOV; + +end + + function devSandbox_cleanUp % A wrapper function to close all windows, ports, show mouse cursor, close keyboard queues From 7662e8c733ecbcdee423f4cebc129bfa33390f53 Mon Sep 17 00:00:00 2001 From: marcobarilari Date: Thu, 10 Sep 2020 18:09:02 +0200 Subject: [PATCH 2/5] mh fix --- dev/devSandbox.m | 99 ++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/dev/devSandbox.m b/dev/devSandbox.m index 07e1450..848d2b9 100644 --- a/dev/devSandbox.m +++ b/dev/devSandbox.m @@ -24,13 +24,13 @@ cfg = struct; %% Visual - + % set to false if no visual stimulation - cfg.screen.do = true; - + cfg.screen.do = true; + % Set the PTB window background manually cfg.color.background = [127 127 27]; - + % Set monitor parameters if you care about visual angle cfg.visualAngle.do = true; cfg.screen.monitorWidth = 21.5; % cm @@ -38,42 +38,42 @@ % 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.winWidth % cfg.screen.winHeight - % cfg.screen.center % Center of the screen window - % cfg.screen.ifi % Frame duration - % cfg.screen.monitorRefresh % Monitor refresh rate - + % 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 = false; - - % Set audio freq. and nb. of channels of your audio file input + + % 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 - + % + % cfg.audio.pahandle + %% % ------------------------------------------------------------------------- % -------------------------- SET YOUR VARS HERE --------------------------- @@ -106,12 +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; @@ -212,39 +212,39 @@ function cfg = devSandbox_initPTB(cfg) % Shorter version of `initPTB.m` - + if cfg.screen.do - % Skip the PTB sync test - Screen('Preference', 'SkipSyncTests', 2); + % Skip the PTB sync test + Screen('Preference', 'SkipSyncTests', 2); + + % Open a transparent window + PsychDebugWindowConfiguration; + + % Here we call some default settings for setting up Psychtoolbox + PsychDefaultSetup(2); - % Open a transparent window - PsychDebugWindowConfiguration; + % Get the screen numbers and draw to the external screen if avaliable + cfg.screen.idx = max(Screen('Screens')); - % Here we call some default settings for setting up Psychtoolbox - PsychDefaultSetup(2); + % Open an on screen window + [cfg.screen.win, cfg.screen.winRect] = Screen('OpenWindow', cfg.screen.idx, cfg.color.background); - % Get the screen numbers and draw to the external screen if avaliable - cfg.screen.idx = max(Screen('Screens')); + % Get the size of the on screen window + [cfg.screen.winWidth, cfg.screen.winHeight] = WindowSize(cfg.screen.win); - % Open an on screen window - [cfg.screen.win, cfg.screen.winRect] = Screen('OpenWindow', cfg.screen.idx, cfg.color.background); + % Get the Center of the Screen + cfg.screen.center = [cfg.screen.winRect(3), cfg.screen.winRect(4)] / 2; - % 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); - % Query the frame duration - cfg.screen.ifi = Screen('GetFlipInterval', cfg.screen.win); - - % Get monitor refresh rate - cfg.screen.monitorRefresh = 1 / cfg.screen.ifi; + % 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'); - % Set up alpha-blending for smooth (anti-aliased) lines - Screen('BlendFunction', cfg.screen.win, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA'); - end end @@ -261,7 +261,7 @@ [], ... cfg.audio.fs, ... cfg.audio.channels); - + end end @@ -269,12 +269,11 @@ % Computes the number of pixels per degree given the distance to screen and % monitor width. This assumes that the window fills the whole screen - + cfg.screen.FOV = 180 / pi * 2 * atan(cfg.screen.monitorWidth / (2 * cfg.screen.monitorDistance)); cfg.screen.ppd = cfg.screen.winWidth / cfg.screen.FOV; - -end +end function devSandbox_cleanUp From a535e97b58fae5f80bf3d6ee48b43383f000654e Mon Sep 17 00:00:00 2001 From: marcobarilari Date: Thu, 10 Sep 2020 18:14:15 +0200 Subject: [PATCH 3/5] minor fix --- dev/devSandbox.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dev/devSandbox.m b/dev/devSandbox.m index 848d2b9..cd01299 100644 --- a/dev/devSandbox.m +++ b/dev/devSandbox.m @@ -1,4 +1,4 @@ -function devSandbox + function devSandbox % This script is a stand-alone function that can be useful as a sandbox to % develop the PTB audio/visual stimulation of your experiment. No input/output @@ -29,7 +29,7 @@ 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; @@ -61,7 +61,7 @@ % Set AUDIO % set to false if no auditory stimulation - cfg.audio.do = false; + cfg.audio.do = true; % Set audio freq. and nb. of channels of your audio file input cfg.audio.fs = 44100; From c8bdf3b9540080eba57e02ec714ae1031b9b3381 Mon Sep 17 00:00:00 2001 From: marcobarilari Date: Thu, 10 Sep 2020 18:19:21 +0200 Subject: [PATCH 4/5] mh fix --- dev/devSandbox.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/devSandbox.m b/dev/devSandbox.m index cd01299..637830a 100644 --- a/dev/devSandbox.m +++ b/dev/devSandbox.m @@ -1,4 +1,4 @@ - function devSandbox +function devSandbox % This script is a stand-alone function that can be useful as a sandbox to % develop the PTB audio/visual stimulation of your experiment. No input/output From 4a996e89d84f06cd76f68dbe37b7d878702b0fae Mon Sep 17 00:00:00 2001 From: marcobarilari Date: Thu, 10 Sep 2020 18:24:47 +0200 Subject: [PATCH 5/5] mh fix --- tests/test_setDefaultsPTB.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 = {[], [], []};