I apologise in advance for my only basic understanding of psychtoolbox - I have a lot to learn! I have a script that reads digital inputs from a digital I/O device (NI USB 6501) using a while loop. When it receives an input, it should break out of the while loop to play a sound using PsychPortAudio. This process should be repeated 10 times before it moves to the next part of the code.
My problem is controlling the visual stimuli (the screen textures) displaying during this period. I present a fixation cross before the audio section and I want this to remain on the screen whilst the sounds are playing. Only after it has played its 10 sounds and left that loop should it display the next screen texture. However, on the first trial, it shows the fixation for a few audio presentations before the screen goes black and the windows loading cursor appears whilst the rest of the audio section plays out, and the next texture appears prematurely. For subsequent trials, the next texture appears sometimes almost straight away after the audio section starts.
I am sure I have done something silly - but my understanding was once I had flipped the screen to a texture, it should stay on the screen until I flip again? The audio presentation section is of a variable duration depending on how quickly the digital inputs arrive so I can’t pre-set the duration of the initial fixation stimulus to be shown. I attempted a clunky solution with FinishedBeeps which doesn’t work. I am running PTB 3.0.19 on Windows 10.
Here is the relevant section, simplified:
% display fixation cross
DrawFormattedText(window, ‘+’, ‘center’, ‘center’, black);
Screen(‘Flip’, window);
WaitSecs(4)
%% I/O audio section
FinishedBeeps = 0;
r = read(dq);
for beat=1:10
r.(‘Dev1_port0/line1’)=0;
while r.(‘Dev1_port0/line1’)==0
r = read(dq); %goes to 1 if input detected
end
%input detected
WaitSecs(0.100);
beeptime = PsychPortAudio(‘Start’, pahandle,1);
write(dq,0); % output a logic 1 on port 0, line 0.
WaitSecs(0.02);
write(dq,1); % output a logic 0 on port 0, line 0.
end
FinishedBeeps = 1;
% I/O audio section end
% display new visual stimulus, only once I/O audio section finished
if FinishedBeeps == 1
WaitSecs(2)
DrawFormattedText(window, 'synchronous: up arrow ',‘center’,300,black); %participants give response here
DrawFormattedText(window, ‘NOT synchronous: down arrow’,‘center’,500,black);
Screen(‘Flip’, window);
KbCheck