Sounddevice and sound presentation

Dear Psychopy community,

I am moving from PTB3 to Psychopy and I have some questions regarding the presentation of auditory stimuli in this nice toolbox.

Whereas I have the feeling that the presentation of visual stimuli is quite developed in Psychopy, I find a little bit confusing what is the best way to present auditory stimuli. As far as I have understood, Pygame is the most reliable audio library at the moment, however there is a problem with the latency in the form of a huge temporal bias. I think having a systematic presentation bias in time is not a major issue that can be corrected by shifting the presentation time of the stimulus, however what I dont know is how variable is the presentation time. Does any of you have experience in programing EEG experiments (where high temporal precision is required) in Psychopy using the different audiolibraries? I would be very grateful if you could share how good/bad are the temporal latencies that you are achieving and what setup you are using (windows, linux, mac, special soundcard, etc). (I am sorry I did not have the opportunity yet to plug in an oscilloscope to evaluate the timings)

At this moment I am running some tests using sounddevice (in a macbook pro, Mojave, Python 3) but I found some issues that I dont know how to solve:
1 I need to recreate the pure tone each time that I want to play it, otherwise I can only play it once.
2 The sound is reproduced many times with a not very nice crackling sound on top of it (it does not sound very clean…).
These two problems are not present if I use the Pygame library instead :S. Is there any way to use sounddevice (that in theory provides a more precise and accurate timing) without these issues.

Thank you very much.

1 Like

Hi,

In a test run today with BlackBoxToolkit equipment. Using PsychoPy2 1.84 in Windows 10 running on the latest Mac Mini, we found a rather constant lag of 177 ms (min 168, max 186, sd 4 ms) between the stim.play() onset and recorded actual onset of auditory stimulus. Unfortunately I don’t have the information about the library we used at hand. We’ll do more testing in the following days and I can post the results here.

All the best,

Grega

1 Like

Thanks Grega,

it looks like you are getting a pretty systematic temporal bias, which is a good thing, easy to correct. I would appreciate if you post more benchmarking results on the audio performance of psychopy. Importantly it would be good to know what audio library you are using (for instance, pygame is completely not recommended for experiments):

In principle, if you import psychopy preferences:

from psychopy.preferences import prefs

and then you run:

prefs.general['audioLib'] 

you should be able to see what audio library you are using.

Thanks again!
(We are in the process of buying the blackbox toolkit so I will post my results as well as soon as they will be available).

Hi, I checked the specific settings, which were:

PsychoPy2     : v1.85.4 
audio library : ['pyo', 'pygame']
audio driver  : ['Primary Sound', 'ASIO', 'Audigy']
audio device  : default

At the script onset the report was:

pyo version 0.8.7 (uses single precision)

In the next week, we’ll upgrade to v1.90 and check timing of audio stimuli with different audio drivers, recheck timing events with mBBTKv2, its response pad and opto sensor, as well as the Cedrus response pad with the opto sensor. Once we compile them all, I’ll post the results at the forum.

All the best,

Grega

P.S.: A side note. When using Cedrus response pad with the pyxid2 library, the sound gets distorted. The only way we got it to work was not to use PsychoPy objects but rather use pygame library directly by:

import pygame

pygame.init()
pygame.mixer.init()

aStim = pygame.mixer.Sound('test.wav')
aStim.play()

We’ll see about the timing.

1 Like