I’m using PsychoPy Standalone 1.90.2 on Windows 7 and working on an auditory experiment. However, I have long-standing issues with crackling noises on different hardware whenever I want to play two sounds simultaneously.
In the very simple minimal example I have attached, a wave file and a PsychoPy beep are played at the same time. Removing either the wave or the beep shows that they both work perfectly when isolated.
However, when the beep onset is between 0.22 and 0.61, an annoying crackling sound appears. For onsets <= 0.21 s and >= 0.62 s, there is no crackling.
In case it helps, I have visualized the wave file using Matlab:
I found out that the crackling does not occur if I set the audio library in the preferences to [u'pyo', u'pygame'] instead of the default [u'sounddevice', u'pyo', u'pygame', ].
However, using pyo, loops are randomly cancelled if I use condition files, and “the sounddevice library looks like the way of the future”, so it would be great to find a fix for the minimal example above. Does anyone have a clear sound here using the sounddevice library?
Moreover, I thought that maybe mixing a wave file with a PsychoPy tone might cause the problems due to different sound properties (e.g., sampling rate), which is why I created a simple 0.5 s beep using Matlab (see link below). If you replace the ‘A’ with ‘Beep.wav’ in the minimal example uploaded before, the crackling still occurs.
Added up like in PsychoPy with a beep onset of 0.5 s, the two waves look like this. I don’t see a problem (e.g., clipping) here:
In PsychoPy3 Beta 11, the crackling can be fixed by changing line 192 in C:\Program Files (x86)\PsychoPy3\Lib\site-packages\psychopy\sound\backend_sounddevice.py from for thisSound in self.sounds: to for thisSound in self.sounds.copy():
In PsychoPy 2 1.90.2, however, this change (line 185 in this case) produces the following error:
From cffi callback <function callback_ptr at 0x1554F170>:
Traceback (most recent call last):
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\sounddevice.py", line 1008, in callback_ptr
return _wrap_callback(callback, data, frames, time, status)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\sounddevice.py", line 2773, in _wrap_callback
callback(*args)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\sound\backend_sounddevice.py", line 185, in callback
for thisSound in self.sounds.copy():
AttributeError: 'list' object has no attribute 'copy'
Hi @TorgeMS, yes if this fix is to be implemented in PsychoPy with Python 2, we may need some additional code, because list.copy() is only available in Python 3. You could instead try the following with a Python 2 module called “copy”. Insert import copy with the imports at the top of the file, and change line 185 to:
@TorgeMS, I meant the fix just to be written for the backend_sounddevice.py file in PsychoPy. Did you write the code in an experiment file? If you do not have the copy module in your standalone distribution, you can add the module using these guidelines. Bear in mind, this will not be an officially tested version, so use with care.
Yes, I wrote it in the experiment file because I wanted to change the program files as little as possible. Is it necessary? The copy module is at C:\Program Files (x86)\PsychoPy2\Lib\copy.py, so I thought it should be found there.
@TorgeMS yes that was a fix for the PsychoPy source code. The copy module is not needed in your experiment code. If you are happy using PsychoPy3 Beta 11, then that may be a better option.