Audio onset latency jitter

Hello,

I am setting up a new linux laptop for a study that needs low latency audio precision and we’re experiencing variable jitter in the audio playback onset latency. I’m testing by recording audio signal output (phones) from the PTB computer as a physio channel on my EEG bioamplifier and marking the onset with a TTL trigger output from my IO card to the amp. Sometimes there is a small delay in the audio playback onset that is stable across trials, which would be fine if it were consistent (my PTB-INFO says it should be ~5ms). However, sometimes the audio onset appears anywhere from 10ms before or after the TTL (~20ms variable range). Often there starts to be a pattern (each trial gets slightly longer delay), but sometimes the pattern is not consistent. Below/attached are two example images of 10 trials of the audio signal (a 50ms burst of white noise). I tried using the internal sound card and an external usb sound card with similar results. Also tried different reqlatenyclass (inputs 1, 2 or 4) argument with PsychPortAudio(Open).

 

Linux (Ubuntu 14.04); Dell Latitute e5550, Intel Core i5, 64-bit

PTB 3.0.12; Matlab R2015b 64-bit; IO card (MCC, USB-1024LS)

Sound cards: External USB (Behringer Xenyx Q802usb),  Internal (Intel Broadwell-U Audio controller, HDA Intel PCH: ALC3235 Analog)

Attachments: audio file (wnprobe.wav – to execute code), 2 jpg of 10 audio signals (y-axis: each trial plotted separately; x-axis = time in ms, 0= TTL and intended audio onset)


Code and output below. We’ve been using PTB on Windows for years with great low latency precision, but the IO card and sound card issues have always been a pain. We are hoping to transition our lab to linux since it’s supposed to play better with PTB. Any advice would be greatly appreciated!

 

%Test Audio Playback Onset Latency Linux

%Play 50ms burst of white noise (wav file). Repeat 10 times, 2 sec apart.

%With bioamplifier simultaneously record:

%1. Audio channel output from phones jack out of mixer (attenuated, to amplifier).

%2. Event code markers of sound onset (TTL from IO card port B to amplifier).

 

%Setup DIO card

DIO = DaqFind; %get device index

PortB = 4; %MCC 1024LS IO card, use port B to send event code trigger to amplifier

DaqDConfigPort(DIO,PortB,0); %Output

SoundEvent = 1; %Event code to trigger amplifier

DaqDOut(DIO, PortB, 0); %initialize DIO with 0

 

%Force GetSecs and WaitSecs into memory to avoid latency later on:

GetSecs;

WaitSecs(0.1);

 

%load white noise

[y] = psychwavread('wnprobe.wav');  %assumes file is in path, 50ms broadband white noise

freq = 44100; % a frequency of 44100 Hz

noise = y'; %transpose

reqlatencyclass = 4;  %for low latency - used 2 on PC, try 1 or 4 too

modePlay = 1; % audio play back only

nchannels = 2; % 2 sound channels for stereo capture

 

InitializePsychSound(1);  %1=set for low-latency

%SoundCardDevices = PsychPortAudio('GetDevices'); %Get sound card devices if not using default

%Index = not(cellfun('isempty',strfind({SoundCardDevices.DeviceName},'USB Audio CODEC: USB Audio'))); %Replace string with sound card name if not default

%SoundCardID = SoundCardDevices(Index).DeviceIndex; %Get sound card deviceID for PsychPortAudio(Open)

PsychPortAudio('Verbosity', 10);

 

%SoundCard = PsychPortAudio('Open', SoundCardID, modePlay, reqlatencyclass,freq, nchannels); %assign external usb sound card

SoundCard = PsychPortAudio('Open', [], modePlay, reqlatencyclass, freq, nchannels); %use [] default sound card (internal)

PsychPortAudio('FillBuffer', SoundCard, noise);

 

Priority(2);

 

%Play audio 10 times

Now = GetSecs;

for i=1:10

    PsychPortAudio('Start', SoundCard, 1, Now);

    Now = WaitSecs('UntilTime', Now);

    DaqDOut(DIO, PortB, SoundEvent); %send TTL trigger to mark sound onset

    WaitSecs(.005);

    DaqDOut(DIO, PortB, 0); %reset holdvalue 0

    PsychPortAudio('Stop', SoundCard, 1);

    Now = Now+2; %Play 2sec apart

end

 

Priority(0);

PsychPortAudio('Close', SoundCard); % Close SoundCard

 

>> TestAudioPlayLatency
PTB-INFO: Trying to suspend potentially running PulseAudio server.
PTB-DEBUG: PortAudio says: PaOSS BuildDeviceList: Total number of devices found: 0
PTB-DEBUG: PortAudio says: BuildDeviceList: Ignoring ALSA plugin device cards of type unknown
PTB-DEBUG: PortAudio says: BuildDeviceList: Found plugin sysdefault of type unknown
PTB-DEBUG: PortAudio says: BuildDeviceList: Found plugin front of type unknown
PTB-DEBUG: PortAudio says: BuildDeviceList: Found plugin rear of type unknown
PTB-DEBUG: PortAudio says: BuildDeviceList: Found plugin center_lfe of type unknown
PTB-DEBUG: PortAudio says: BuildDeviceList: Found plugin side of type unknown
PTB-DEBUG: PortAudio says: BuildDeviceList: Found plugin surround40 of type unknown
PTB-DEBUG: PortAudio says: BuildDeviceList: Found plugin surround41 of type unknown
PTB-DEBUG: PortAudio says: BuildDeviceList: Found plugin surround50 of type unknown
PTB-DEBUG: PortAudio says: BuildDeviceList: Found plugin surround51 of type unknown
PTB-DEBUG: PortAudio says: BuildDeviceList: Found plugin surround71 of type unknown
PTB-DEBUG: PortAudio says: BuildDeviceList: Found plugin iec958 of type unknown
PTB-DEBUG: PortAudio says: BuildDeviceList: Found plugin spdif of type unknown
PTB-DEBUG: PortAudio says: BuildDeviceList: Found plugin hdmi of type unknown
PTB-DEBUG: PortAudio says: BuildDeviceList: Ignoring ALSA plugin device dmix of type unknown
PTB-DEBUG: PortAudio says: BuildDeviceList: Ignoring ALSA plugin device dsnoop of type unknown
PTB-DEBUG: PortAudio says: BuildDeviceList: Found plugin modem of type unknown
PTB-DEBUG: PortAudio says: BuildDeviceList: Found plugin phoneline of type unknown
PTB-DEBUG: PortAudio says: BuildDeviceList: Ignoring ALSA plugin device hw of type hw
PTB-DEBUG: PortAudio says: BuildDeviceList: Ignoring ALSA plugin device plughw of type plug
PTB-DEBUG: PortAudio says: BuildDeviceList: Ignoring ALSA plugin device plug of type plug
PTB-DEBUG: PortAudio says: BuildDeviceList: Ignoring ALSA plugin device shm of type shm
PTB-DEBUG: PortAudio says: BuildDeviceList: Ignoring ALSA plugin device tee of type file
PTB-DEBUG: PortAudio says: BuildDeviceList: Ignoring ALSA plugin device file of type file
PTB-DEBUG: PortAudio says: BuildDeviceList: Ignoring ALSA plugin device null of type null
PTB-DEBUG: PortAudio says: BuildDeviceList: Found plugin pulse of type pulse
PTB-DEBUG: PortAudio says: BuildDeviceList: Found plugin rawbluetooth of type bluetooth
PTB-DEBUG: PortAudio says: BuildDeviceList: Found plugin bluetooth of type plug
PTB-DEBUG: PortAudio says: BuildDeviceList: Ignoring ALSA plugin device default of type pulse
PTB-DEBUG: PortAudio says: BuildDeviceList: Adding device HDA Intel HDMI: HDMI 0 (hw:0,3)
PTB-DEBUG: PortAudio says: BuildDeviceList: Adding device HDA Intel HDMI: HDMI 1 (hw:0,7)
PTB-DEBUG: PortAudio says: BuildDeviceList: Adding device HDA Intel HDMI: HDMI 2 (hw:0,8)
PTB-DEBUG: PortAudio says: BuildDeviceList: Adding device HDA Intel PCH: ALC3235 Analog (hw:1,0)
PTB-DEBUG: PortAudio says: BuildDeviceList: Adding device USB Audio CODEC: USB Audio (hw:2,0)
PTB-DEBUG: PortAudio says: BuildDeviceList: Adding device hdmi
PTB-DEBUG: PortAudio says: BuildDeviceList: Device pulse doesn't support mmap
PTB-INFO: Using specially modified PortAudio engine, based on offical version: PortAudio V19-devel
PTB-INFO: Choosing deviceIndex 3 [HDA Intel PCH: ALC3235 Analog (hw:1,0)] as default audio device.
PTB-DEBUG: PortAudio says: AlsaOpen: Opening device hw:1,0
PTB-DEBUG: PortAudio says: AlsaOpen: Opening device hw:1,0
PTB-DEBUG: PortAudio says: PaAlsaStream_Configure: Playback period size: 55, latency: 0.004989
PTB-INFO: New audio device with handle 0 opened as PortAudio stream:
PTB-INFO: For 2 channels Playback: Audio subsystem is ALSA, Audio device name is HDA Intel PCH: ALC3235 Analog (hw:1,0)
PTB-INFO: Real samplerate 44100.000000 Hz. Input latency 0.000000 msecs, Output latency 4.988662 msecs.
PTB-INFO: Display ':0' : X-Screen 0 : Assigning primary output as 0 with RandR-CRTC 0 and GPU-CRTC 0.
PTB-DEBUG: PortAudio says: PaUnixThread_New: Waited for 5.03063e-05 seconds for stream to start
PTB-DEBUG: PortAudio says: Stopping callback
PTB-DEBUG: PortAudio says: PaUnixThread_Terminate: Joining thread 260396800
PTB-DEBUG: PortAudio says: Setting callbackResult to paComplete
PTB-DEBUG: PortAudio says: CallbackThreadFunc: Thread 260396800 exiting
 PTB-DEBUG: PortAudio says: OnExit: Stopping ALSA handles
PTB-DEBUG: PortAudio says: OnExit: Stoppage
PTB-INFO: Trying to resume potentially suspended PulseAudio server.

>> 

 

Thank you for any advice or guidance!

 Jesse Kaye, MS

 

Doctoral Student in Clinical Psychology

University of Wisconsin - Madison