psychopy.org | Reference | Downloads | Github

Massive sound lag using PsychoPy - Windows WASAPI for external sound card


#1

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): PsychoPy v3.0.0b10
**Standard Standalone? (y/n) y
**What are you trying to achieve?: Stream a sound

**What did you try to make it work?: Try out different settings for audio library, audio driver and audio device in Preferences

What specifically went wrong when you tried that?:

##### Running: D:\Experimente\task1.py #####
0.7472     ERROR     Requested audio device 'Yamaha Steinberg USB ASIO' that is not available on this hardware. The 'audioDevice' preference should be one of ['Line (2- Steinberg UR22mkII )']

##### Running: D:\Experimente\task1.py #####
Traceback (most recent call last):
  File "D:\Experimente\task1.py", line 80, in <module>
    sound_1 = sound.Sound('A', secs=-1, stereo=True)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\sound\backend_sounddevice.py", line 296, in __init__
    hamming=self.hamming)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\sound\backend_sounddevice.py", line 343, in setSound
    blockSize=self.blockSize)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\sound\backend_sounddevice.py", line 84, in getStream
    blockSize=blockSize)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\sound\backend_sounddevice.py", line 128, in _getStream
    device=defaultOutput)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\sound\backend_sounddevice.py", line 159, in __init__
    callback=self.callback)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\sounddevice.py", line 1373, in __init__
    **_remove_self(locals()))
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\sounddevice.py", line 696, in __init__
    extra_settings, samplerate)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\sounddevice.py", line 2488, in _get_stream_parameters
    device = _get_device_id(device, kind, raise_on_error=True)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\sounddevice.py", line 2634, in _get_device_id
    for id, name in matches))
ValueError: Multiple output devices found for 'Line (2- Steinberg UR22mkII )':
[3] Line (2- Steinberg UR22mkII ), MME
[7] Line (2- Steinberg UR22mkII ), Windows DirectSound
[10] Line (2- Steinberg UR22mkII ), Windows WASAPI

Looks like the sound card offers to many possibilities. Ideally, I would like to present the sound using exclusive mode via Windows WASAPI to have the least possible lag. So far, the sound shows a delay of 100 ms (with a jitter of about 50 ms). Presentation and Psychtoolbox were at 5 ms and 8 ms (without any measurable jitter), respectively.

@jon, @matthias.geier Could you please have a look?


#2

It appears that the problem is raised because different instances of the device have the same name. Calling the appropriate instance by its ID at least enabled me playing a sound:

sound.setDevice(10, kind='output')

But, I still did not manage to change the WasapiSetting without getting an error.

That’s what I added:

sound.setDevice(dev=10, kind='output')

wasapi_exclusive = sound.backend.sd.WasapiSettings(True)
sound.backend.sd.default.extra_settings= wasapi_exclusive

That’s what I get:

Traceback (most recent call last):
  File "D:\Experimente\task1.py", line 85, in <module>
    sound_1 = sound.Sound('A', secs=-1, stereo=True)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\sound\backend_sounddevice.py", line 296, in __init__
    hamming=self.hamming)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\sound\backend_sounddevice.py", line 343, in setSound
    blockSize=self.blockSize)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\sound\backend_sounddevice.py", line 84, in getStream
    blockSize=blockSize)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\sound\backend_sounddevice.py", line 128, in _getStream
    device=defaultOutput)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\sound\backend_sounddevice.py", line 159, in __init__
    callback=self.callback)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\sounddevice.py", line 1373, in __init__
    **_remove_self(locals()))
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\sounddevice.py", line 779, in __init__
    'Error opening {0}'.format(self.__class__.__name__))
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\sounddevice.py", line 2571, in _check
    raise PortAudioError(errormsg, err)
sounddevice.PortAudioError: Error opening OutputStream: Invalid device [PaErrorCode -9996]

#3

You can also use (part of) the host API in your device string.
You could e.g. try 'UR22mkII WASAPI'.
You can use any number of space-separated sub-strings, they only have to be in the right order.

At least that’s the behavior of the sounddevice module. I don’t know if the PsychoPy code changes that.


#4

What is the delay when you use WASAPI without the “exclusive” mode?

The “invalid device” error message was mentioned in a Github issue:

Are you using the right sampling rate?


#5

Thank you, I will try that. But shouldn’t this lead to the same result as setting the device by its identifier:

sound.setDevice(dev=10, kind='output')

The result for WASAPI without exclusive mode is about 70 ms. I get much better results using ASIO. But Neurobs-Presentation is using WASAPI shared mode.

I think so, the sound has 44100 Hz which should be default anyway. The problem also occured for a minimal example simply sending a parallel port trigger simultaneously to a sound generated by sound.Sound().


#6

Yes.

Please make sure. See the issue I linked above for how to check.