Reaction time to sound in for loop with Windows

Dear all,

I recently had this problem. In a reaction time experiment I was running I noticed that the response time to the very first trial of the experiment was always much faster than any successive reaction time. In addition, this first reaction time was (unfortunately) the only "veridical" (it was a simple sound detection experiment and I was expecting reactions of about 200-300 ms). The rest of reaction times was too slow to be veridical.

Equipment: a pc with windows 7 or 10 (the problem does not occur with mac as far as I know).

Here a simplified version of the code: run the script and respond as fast as possible to the onset of the tone by pressing the "y" key. In my two pcs, the very first reaction time is usually ~0.2-0.3 sec, the remaining ones are longer (~0.7-0.8 sec) no matter what I do.

Does anybody knows what is happening here? I'm lost.

Thank you all in advance,
m
yKey = KbName('y');
InitializePsychSound;
pahandle = PsychPortAudio('Open', [], [], 0, 44100, 1);
for trial = 1:6
    WaitSecs(3);
    stimulus = MakeBeep(1000, 1, 44100);
    PsychPortAudio('FillBuffer', pahandle, stimulus);
    timeElapsed = 0;
    t0 = GetSecs;
    PsychPortAudio('Start', pahandle);
    [touch, rispRT, kbCode] = KbCheck;
    while ~kbCode(yKey) & timeElapsed < 2.0
        [touch, rispRT, kbCode] = KbCheck;
        timeElapsed = rispRT - t0;
    end
    timeElapsed
end
The best advice i can give you after looking at the code is to read our demos, look  at the examples given in the Intro PDF slides, e.g, the ECVP 2013 tutorials, in our PsychDocumentation folder and for answers to similar questions on the forum, as well as the help . That code is exactly how you won't get reliable/good timing or accurate reaction times on any OS and the proper approaches are definitely documented in our demos and docu for getting properly timed audio stimuli and precise audio onset timestamps which are useable for RT measurements.

Apart from that i assume your Windows machine doesn't have a native ASIO capable soundcard as strongly recommended, which is why its timing will probably be off by hundreds of milliseconds even if your code would be ok. It's just that OSX or Linux will give much better accuracy even in the worst case of broken code, so you probably don't notice large errors when you run it on OSX.

-mario