close all;
clearvars;
PsychDefaultSetup(2);
AssertOpenGL;
Screen('Preference','SkipSyncTests', 1);
screens = Screen('Screens');
screenNumber = max(screens);
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, black);
ifi = Screen('GetFlipInterval', window);
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
[screenXpixels, screenYpixels] = Screen('WindowSize', window);
[xCenter, yCenter] = RectCenter(windowRect);
Screen('TextFont', window, 'Ariel');
Screen('TextSize', window, 36);
line1 = 'Hello and Thanks for your participation';
line2 = '\n\n\n\n In this experiment you''ll see a fixation cross and
you''ll hear a "BEEP" sound at different time intervals';
line3 = '\n\n You can freely choose when you want to perform the movement
AFTER the "BEEP"';
line4= '\n\n\n\n\n\n When you are ready .... lets start';
Screen('TextSize', window, 20);
DrawFormattedText(window, [line1 line2 line3 line4],...
'center', screenYpixels * 0.25, white);
Screen('Flip', window);
KbStrokeWait;
fixCrossDimPix = 40;
xCoords = [-fixCrossDimPix fixCrossDimPix 0 0];
yCoords = [0 0 -fixCrossDimPix fixCrossDimPix];
allCoords = [xCoords; yCoords];
lineWidthPix = 4;
Screen('DrawLines', window, allCoords,...
lineWidthPix, white, [xCenter yCenter], 2);
Screen('Flip', window);
InitializePsychSound(1);
nrchannels = 2;
freq = 48000;
repetitions = 1;
beepLengthSecs = 0.2 ;
beepPauseTime = WaitSecs(randi([1, 5]));
startCue = WaitSecs(5);
waitForDeviceStart = 1 ;
pahandle = PsychPortAudio('Open', [], 1, 1, freq, nrchannels);
PsychPortAudio('Volume', pahandle, 0.5);
myBeep = MakeBeep(500, beepLengthSecs, freq);
PsychPortAudio('FillBuffer', pahandle, [myBeep; myBeep]);
PsychPortAudio('Start', pahandle, repetitions, startCue,
waitForDeviceStart);
WaitSecs(randi([10, 15]));
PsychPortAudio('Start', pahandle, repetitions, startCue,
waitForDeviceStart);
WaitSecs(randi([10, 15]));
PsychPortAudio('Start', pahandle, repetitions, startCue,
waitForDeviceStart);
WaitSecs(randi([10, 15]));
PsychPortAudio('Start', pahandle, repetitions, startCue,
waitForDeviceStart);
WaitSecs(randi([10, 15]));
PsychPortAudio('Close', pahandle);
sca;