To be able to produce audio on more than two channels (including for EEG experimetns where a 3rd channel may serve to deliver timing pulses) we sometimes use a MOTU sound card with PyAudio. Drew's memory tone project, for example, used that approach.
Drew recommended the following for background reading: http://www.ondrejhavlicek.com/2016/10/playing-sound-with-low-latency-and-jitter-in-opensesame/ which discusses the issues.
The key points are:
- if necessary, install MOTU drivers from https://motu.com/download
- on a windows machine, the standard DirectSound is too slow and you should use generic ASIO (ASIO4all) instead.
- After installing ASIO4all you need to restart the computer.
- Normal PyAudio does not work with ASIO, so you need a special build which you can get from here and install using a command like "
python -m pip
PyAudio-0.2.11-cp38-cp38-win_amd64.whl --upgrade". You need the numbers after cp to match your python version and you want the amd64 files if you are running 64 bit Windows.
Using the MOTU output channels > 2 to produce EEG sync trigger pulses.
In clickTrainLibrary.py we created a
class pyaudioHardware(soundHardware) which can be used to access the MOTU and play audio using channel 3 for a sync pulse.
# load stimulus object module
import ClickTrainLibrary as stimulatorModule
# select output hardware, then type of clickTrain
devIdx must be set to the correct number for the MOTU with > 2 output channels on the ASIO API. So change the value as necessary.
stimulatorModule.soundPlayer.listAvailablePyaudioDevices() lists the available device indeces.
If all is correctly set up, instantiating the tone object and playing it will produce a pure tone beep on both the phones output on the MOTU front panel and the MainOut L and R on the back, and at the same time it will produce a square wave out of AnalogOut 1 on the back (which maps onto logical channel 3 for the PyAudio). So to get the sync trigger you need to connect AnalogOut 1 to the appropriate trigger in.
To connect to EEGO trigger inputs:
Connect a 6.35mm jack to the back of MOTU at phones output channel 1 – the channel responsible for trigger outputs.
Use a 3.5mm to 25 pin trigger cable to connect MOTU output channel 1 to the 25 pin trigger cable that goes into EEGO.
Turn on the EEGO software on the EEG laptop/computer and begin a session. If triggers are being outputted from MOTU channel 3, they should be visible on the bottom of the EEG signal display (seen as the yellow markers), as shown in the picture below. If MOTU’s not outputting a third pulse and/or the EEG Trigger cable is connected incorrectly, these yellow triggers will not be seen.
Please note that there’s some delay before these triggers appear on the EEG screen, they are not the best for matching your trigger and stimulus time. Minimal delay before the onscreen triggers pop up is expected.