Unsupported Audio Parameters in PTB Sound Library

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2020.2.10
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?: I’m trying to set any sound file dynamically in a loop with the PTB sound library.

What did you try to make it work?: I have an experiment I haven’t worked on in many years that I’m trying to tweak for a new context. In the experiment, the path for a sound component is set dynamically as a part of a loop (using “set every repeat”). When I try to run an experiment using this format and the new PTB library, the experiment doesn’t run, giving me the error above. I created a toy version with just the loop that’s causing me problems, and it still breaks; I also created a toy version with a completely different set of stimuli, and it still breaks. It works fine with the pyo, pygame, and sounddevice libraries. None of my sound files I’m using are 48000 Hz; they’re all 44100 Hz. The files work fine when the filenames are not updated dynamically (when they’re “constant”), and, oddly, they work fine when they’re set dynamically by a Code component in a different Routine (which is a setup I have in a slightly different study using identical stimuli).

I was hoping to switch to using the PTB library, because I’m getting some odd other errors when I use the other libraries (I’m trying to provide audio feedback that updates as a result of button presses and it’s throwing a different error for only certain sound files, unrelated to the ones triggering the error here), but this experiment mostly seems haunted.

I’ve put in a request to update PsychoPy on my system to the latest version, but my university requires tech support to update any software, so it might take some time.

What specifically went wrong when you tried that?:

pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
PTB-ERROR: Desired audio parameters for device -1 unsupported by audio device: Invalid sample rate
PTB-ERROR: Seems the requested audio sample rate 48000.000000 Hz is not supported by this combo of hardware and sound driver.
Error in function Open: Usage error
Failed to open PortAudio audio device due to unsupported combination of audio parameters.
PsychPortAudio:Open: Usage:

pahandle = PsychPortAudio(‘Open’ [, deviceid][, mode][, reqlatencyclass][, freq][, channels][, buffersize][, suggestedLatency][, selectchannels][, specialFlags=0]);
PTB-ERROR: Desired audio parameters for device -1 unsupported by audio device: Invalid sample rate
PTB-ERROR: Seems the requested audio sample rate 48000.000000 Hz is not supported by this combo of hardware and sound driver.
Error in function Open: Usage error
Failed to open PortAudio audio device due to unsupported combination of audio parameters.
PsychPortAudio:Open: Usage:

pahandle = PsychPortAudio(‘Open’ [, deviceid][, mode][, reqlatencyclass][, freq][, channels][, buffersize][, suggestedLatency][, selectchannels][, specialFlags=0]);
3.7074 WARNING User requested fullscreen with size [1024 768], but screen is actually [1920, 1080]. Using actual size
Traceback (most recent call last):
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py”, line 231, in init
channels=channels,
File “C:\Program Files\PsychoPy3\lib\site-packages\psychtoolbox\audio.py”, line 107, in init
flags)
Exception: Failed to open PortAudio audio device due to unsupported combination of audio parameters.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “C:\Users\ccheffne\Box\Research\UB\Tools\A1-Washington\VerP03\A1P03b_lastrun.py”, line 95, in
name=‘speechsound’)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py”, line 334, in init
hamming=self.hamming)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py”, line 428, in setSound
_SoundBase.setSound(self, value, secs, octave, hamming, log)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound_base.py”, line 179, in setSound
hamming=hamming)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound_base.py”, line 213, in _setSndFromNote
self._setSndFromFreq(thisFreq, secs, hamming=hamming)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound_base.py”, line 229, in _setSndFromFreq
self._setSndFromArray(outArr)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py”, line 500, in _setSndFromArray
self.track = audio.Slave(self.stream.handle, data=self.sndArr,
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py”, line 582, in stream
blockSize=self.blockSize)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py”, line 143, in getStream
blockSize=blockSize)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py”, line 189, in _getStream
device=defaultOutput)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py”, line 252, in init
channels=channels,
File “C:\Program Files\PsychoPy3\lib\site-packages\psychtoolbox\audio.py”, line 107, in init
flags)
Exception: Failed to open PortAudio audio device due to unsupported combination of audio parameters.

My thoughts.

  1. If all of your sound files are 44100 Hz then might there be a video file with a 48000 Hz bit rate that is causing the issue.

  2. If it works when the files are constant then there could be a bug that 48000 Hz is used as the default audio stream if no audio files are set. You could try setting one “demo” sound file as constant to get the audio stream right. If this works you could stop it playing by setting its volume to zero or setting its start time to after the end of the routine.

Thanks for the speedy response!

If all of your sound files are 44100 Hz then might there be a video file with a 48000 Hz bit rate that is causing the issue.

I thought the same thing, but getting rid of the video components didn’t help, and my toy experiments don’t have video at all.

If it works when the files are constant then there could be a bug that 48000 Hz is used as the default audio stream if no audio files are set. You could try setting one “demo” sound file as constant to get the audio stream right. If this works you could stop it playing by setting its volume to zero or setting its start time to after the end of the routine.

A clever idea. That idea didn’t work with a new sound component in the same routine, but it did work if I created a new routine that included one of the sounds that was going to be played later on, even when I set the volume to 0. A kludgy workaround, but I’ll take it!

1 Like