clear all; close all;

LoadPsychHID;

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);

PsychHID('KbQueueCreate')
PsychHID('KbQueueStart')

keyIsDown = 0;

while ~keyIsDown
    
    PsychPortAudio('SetLoop',Gparams.audio.h, Gparams.sound.tonepos(1,1), Gparams.sound.tonepos(1,2));
    PsychPortAudio('Start', Gparams.audio.h);

    WaitSecs(1);
    
    PsychPortAudio('SetLoop',Gparams.audio.h, Gparams.sound.tonepos(2,1), Gparams.sound.tonepos(2,2));
    PsychPortAudio('Start', Gparams.audio.h);
    
    WaitSecs(1);
    
    [keyIsDown, ~, ~, ~, ~] = PsychHID('KbQueueCheck');
    
end