Turns out there's a really easy solution with the PsychPortAudio(‘OpenSlave’) function if the buffer is created with 6 channels with three filled with actual audio and three with the response target.
How to eliminate a ~1 sec lag between the participant response and EEG trigger
4 views (last 30 days)
Show older comments
Hi! I have an auditory task where participants were asked to response whenever there's an oddball/target sound. The stimulus length is about 2-3 seconds long. I attached the response trigger with an empty sound, but somehow the trigger only appears with a lag, persumably waiting for the target sound to stop playing. My code is:
trigResponse = attach_trigger([],trig_spchResp,fs); % attach trigger for response
PsychPortAudio('FillBuffer',Stim_Buf,trigResponse);
PsychPortAudio('Start',Stim_Buf,1,0,0,inf,0);
I tried moving the attach_trigger line to right after opening the buffer, which is outside the expeirmental loop, but that didn't seem to have made a big difference. I was wondering if there's a function that can force pscychtoolbox to directly send the empty sound when there's a response without waiting for the previous sound or is there a better way to attach the response trigger?
Thank you!
0 Comments
Accepted Answer
More Answers (1)
Jack
on 29 Mar 2023
Hi,
It sounds like you are experiencing some latency between the onset of the response trigger and the actual delivery of the trigger due to the length of the target sound. One possible solution to this issue is to use a separate audio channel to deliver the response trigger, which would allow the trigger to be delivered independently of the target sound.
Here is an example of how you could modify your code to use a separate audio channel for the trigger:
% Open audio device for target sound
Stim_Dev = PsychPortAudio('Open', Stim_AudioDevice, [], [], fs, Stim_nChannels);
% Open audio device for response trigger
Trig_Dev = PsychPortAudio('Open', Trig_AudioDevice, [], [], fs, Trig_nChannels);
% Attach trigger for response
trigResponse = attach_trigger([],trig_spchResp,fs);
% Load target sound into buffer
PsychPortAudio('FillBuffer', Stim_Dev, target_sound);
% Start playing target sound
PsychPortAudio('Start', Stim_Dev, 1, 0, 0, inf, 0);
% Wait for response
response_time = GetSecs() + response_timeout;
while GetSecs() < response_time
if response_detected
% Deliver response trigger
PsychPortAudio('FillBuffer', Trig_Dev, trigResponse);
PsychPortAudio('Start', Trig_Dev, 1, 0, 0, inf, 0);
break;
end
end
% Stop playing sounds
PsychPortAudio('Stop', [Stim_Dev Trig_Dev], 1, 0);
% Close audio devices
PsychPortAudio('Close', [Stim_Dev Trig_Dev]);
In this code, we open a separate audio device for the response trigger using the PsychPortAudio('Open') function, and then use the PsychPortAudio('FillBuffer') and PsychPortAudio('Start') functions to deliver the trigger independently of the target sound. Note that we wait for the response using a while loop that checks for a response condition, and then immediately deliver the trigger using the separate audio channel. Finally, we stop playing all sounds and close both audio devices.
I hope this helps!
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!