function Gparams = setupGParams(Gparams)

%% Get information about participant and session
Gparams.subjectNumber = input('Participant number: ');
if isempty(Gparams.subjectNumber) 
    Gparams.subjectNumber = 0; 
end

Gparams.sessionNumber = input('Session number: ');
if isempty(Gparams.sessionNumber) 
    Gparams.sessionNumber = 0; 
end

Gparams.datetime = datestr(now);

%% Set up data path
Gparams.DataPath    = ['../Data/subj-', num2str(Gparams.subjectNumber) '/'];

if (~exist(Gparams.DataPath))
    mkdir(Gparams.DataPath);
end

%% Set up Psychtoolbox Screen
KbName('UnifyKeyNames');

allScreens              = Screen('Screens');
Gparams.screenNumber    = allScreens(1);
Gparams.white           = WhiteIndex(Gparams.screenNumber);
Gparams.black           = BlackIndex(Gparams.screenNumber);
Gparams.background      = Gparams.black; % set background color
[Gparams.pWindow,Gparams.rectWindow] = Screen('OpenWindow', Gparams.screenNumber, Gparams.background);

[Gparams.ScreenResX, Gparams.ScreenResY] = Screen('WindowSize', Gparams.pWindow);
% optional: check if resolution is correct
Gparams.frameDuration   = Screen('GetFlipInterval',Gparams.pWindow);
Gparams.frameRate       = 1/Gparams.frameDuration;
% optional: check if refresh rate is correct
Screen('BlendFunction', Gparams.pWindow, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

[Gparams.center(1), Gparams.center(2)] = RectCenter(Gparams.rectWindow);
% include a slack for Flip 'when' management
Gparams.flipLag  = Gparams.frameDuration / 2;

Gparams.cancel = false;

Screen('TextSize',Gparams.pWindow,16);
Screen('TextFont',Gparams.pWindow,'Helvatica');
Screen('TextColor',Gparams.pWindow,Gparams.white);


%% Set up Audio
InitializePsychSound(1);  % request low latency mode

Gparams.audio           = [];
Gparams.audio.freq      = 44100;
Gparams.audio.h         = PsychPortAudio('Open', [], 1, [], Gparams.audio.freq, 2, [], []);

Gparams.sound = setupSounds(Gparams);


%% Set up general experiment parameters
%Gparams.DistToScreen    = .57;		% in meters
%Gparams.ScreenWidth     = .53;		% in meters
Gparams.DistToScreen    = .53;		% in meters
Gparams.ScreenWidth     = .531;		% in meters

% Fixation dot parameters
Gparams.fixation.dotsize         = deg2pix(0.2,Gparams); % fixation dot
Gparams.fixation.circlesize      = deg2pix(0.6,Gparams); % circle around fixation dot
Gparams.fixation.color           = [255 0 0];

% Response parameters
Gparams.arrow.eccentricity  = deg2pix(2,Gparams);
Gparams.arrow.size          = deg2pix(3,Gparams);

Gparams.responseKeys.left       = KbName('j');
Gparams.responseKeys.right      = KbName('k');
Gparams.responseKeys.conf1      = KbName('1!');
Gparams.responseKeys.conf2      = KbName('2@');
Gparams.responseKeys.conf3      = KbName('3#');
Gparams.responseKeys.conf4      = KbName('4$');
Gparams.responseKeys.escape     = KbName('Escape');

RestrictKeysForKbCheck([Gparams.responseKeys.left ...
                        Gparams.responseKeys.right...
                        Gparams.responseKeys.conf1...
                        Gparams.responseKeys.conf2...
                        Gparams.responseKeys.conf3...
                        Gparams.responseKeys.conf4...
                        Gparams.responseKeys.escape]);

% Stimulus parameters
Gparams.dots.standard                   = 0.70;
Gparams.dots.relative_coherence         = [30 20 10 5 2.5 1.25 -1.25 -2.5 -5 -10 -20 -30] / 100;
Gparams.dots.relative_coherence_easy    = [30 20 10 5 2.5 1.25 -1.25 -2.5 -5 -10 -20 -30] / 100;
Gparams.dots.relative_coherence_medium  = [30 10 5 2.5 1.25 .625 -.625 -1.25 -2.5 -5 -10 -30] / 100;
Gparams.dots.relative_coherence_hard    = [20 5 2.5 1.25 .625 .3215 -.3215 -.625 -1.25 -2.5 -5 -20] / 100;
Gparams.dots.radius            = deg2pix(12,Gparams); %keep constant
Gparams.dots.nseq              = 3; %interleave three variants of the stimulus
Gparams.dots.color             = [255 255 255]; % always 100% dot contrast
Gparams.dots.speed             = deg2pix(11.5,Gparams); % speed of the dots in degrees/second
Gparams.dots.size              = deg2pix(0.2,Gparams); %size of each dot in degrees
Gparams.dots.density           = 1.7; % dot density in dots per degree^2
Gparams.dots.nDots             = round(Gparams.dots.density*pi*pix2deg(Gparams.dots.radius,Gparams)^2); %number of dots in the circle, calculated from density (can also just be a fixed nr, eg. 500

% Timing
Gparams.timing.previewMappingTime           = 3;  % How many seconds preview of the response mapping at the start of the block
Gparams.timing.maxPreviewMappingFrame       = ceil(Gparams.timing.previewMappingTime / Gparams.frameDuration);
Gparams.timing.viewingtime                  = .750;
Gparams.timing.nframes                      = ceil(Gparams.timing.viewingtime*Gparams.frameRate); %number of frames the stimulus is displayed
Gparams.timing.isi                          = .25;
Gparams.timing.itiDirectionOnly             = 1;
Gparams.timing.iti                          = .5;
Gparams.timing.responseTimeDirectionOnly    = 2;
Gparams.timing.responseTime                 = 4;


