PsychPortAudio only lets me use sampling frequency 48000

Hi there,

I am trying to play some sound through a 6 channel USB audio output device.

  • Psychtoolbox version: ‘3.0.18 - Flavor: beta - Corresponds to SVN Revision 12862’
  • Operating system: Microsoft Windows 10 Education version 10.0.19043 Build 19043

When I run the following
InitializePsychSound(1);
pahandle = PsychPortAudio(‘Open’, , , 2, 2210, 6, 0);

i.e., trying to set up to play sound at sampling frequency (fs) 2210 over 6 channels, I get the following error

pahandle = PsychPortAudio(‘Open’, , , 2, Fs, num_chans, 0);
PTB-ERROR: Desired audio parameters for device -1 unsupported by audio device: Invalid sample rate
PTB-ERROR: Seems the requested audio sample rate 2205.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.
Error using PsychPortAudio
Usage:

pahandle = PsychPortAudio(‘Open’ [, deviceid][, mode][, reqlatencyclass][, freq][, channels][, buffersize][, suggestedLatency][,
selectchannels][, specialFlags=0]);

When I change the sampling frequency to 48000 the above command runs fine, no error. I tried other sampling frequencies like 41100 and 1000 and so far nothing works except 48k.

On my other computer using the same USB sound device

  • Psychtoolbox version: '3.0.17 - Flavor: beta - Corresponds to SVN Revision 12153
  • Operating system: mac os Catalina version 10.15.7

It lets me play sounds with whatever frequency I want…

Does anyone know how I can get it to allow me to play at whatever fs on my PC? Or why it is giving this error?

I’m not sure which driver information for the USB sound device might be relevant or how to find it, so let me know if there is something I can look up that will help.

Thank you so much for your help!

HDJ

That most likely means that your USB sound card doesn’t support those other sampling rates. 48000 is the most common one supported by hardware, followed by 44100, 32000 and multiples of those.

Some sound systems like macOS CoreAudio or Linux PulseAudio will pretend other sampling rates are supported and use software resampling from your rate to the actual rate at which the device is running. This is comfy, but also has various downsides like increased latency, reduced timing precision, and potential low level changes to your signal, e.g., additional filtering, phase shifts, etc. due to resampling / resampling artifacts.

The Windows WASAPI sound system used on Windows 10 for your settings will not support such non-native rates and bail. It is conceivable that the rates would work for reqlatencyclass 0 – high latency, no timing precision at all – as the MME sound system might do resampling.

In general I’d advice against using non-native sampling rates if you care about latency/timing precision/fidelity of the signal for optimal control over the output. Rather resample your signal in Matlab/Octave/Python from 2200 Hz to 48000 Hz, so you are in control of what happens at the output.

-mario

Thanks Mario - that is really interesting to know what my mac was probably doing behind the scenes in terms of resampling. I have remade my stimuli at 48k and they are playing just fine - thanks for the tip.

I had another question I was wondering if you might help me with, its another problem I am getting on this Windows computer and wasn’t getting on my mac:

I want to play two sounds, the first one, a one second pause, and then the other one.

I had thought it might be a good idea to load both sounds into separate buffers ahead of time (earlier in the code) and then play them separately when it came to it. This worked ok on mac, but when I try to initialise the second audio buffer on my PC with the following code:

PsychPortAudio(‘Close’);

% % Audio
InitializePsychSound(1); %inidializes sound driver…the 1 pushes for low latency

% Initialise two sound buffers for the two sounds
pahandle1 = PsychPortAudio(‘Open’, , , 2, Fs, num_chans, 0); % for the first played sound
pahandle2 = PsychPortAudio(‘Open’, , , 2, Fs, num_chans, 0); % for the second played sound

I get the following output/ error:

PsychPortAudio(‘Close’);

% % Audio
InitializePsychSound(1); %inidializes sound driver…the 1 pushes for low latency

% Initialise two sound buffers for the two sounds
pahandle1 = PsychPortAudio(‘Open’, , , 2, Fs, num_chans, 0); % for the first played sound
pahandle2 = PsychPortAudio(‘Open’, , , 2, Fs, num_chans, 0); % for the second played sound
PTB-INFO: Using modified PortAudio V19.7.0-devel, revision unknown
PTB-INFO: Using modified PortAudio V19.7.0-devel, revision unknown
PTB-INFO: New audio device -1 with handle 0 opened as PortAudio stream:
PTB-INFO: For 6 channels Playback: Audio subsystem is Windows WASAPI, Audio device name is Speakers (USB Sound Device )
PTB-INFO: Real samplerate 48000.000000 Hz. Input latency 0.000000 msecs, Output latency 10.000000 msecs.
PTB-ERROR: Failed to open audio device -1. PortAudio reports this error: Invalid device
PTB-ERROR: Desired audio parameters likely unsupported by audio device.
PTB-ERROR: This could be, e.g., due to an unsupported combination of audio sample rate, audio channel count/allocation, or audio sample format.
Error in function Open: Usage error
Failed to open PortAudio audio device due to unsupported combination of audio parameters.
Error using PsychPortAudio
Usage:

pahandle = PsychPortAudio(‘Open’ [, deviceid][, mode][, reqlatencyclass][, freq][, channels][, buffersize][, suggestedLatency][,
selectchannels][, specialFlags=0]);

Seems like it was happy to open the first one but not the second, which worked on my mac.

I tried changing the device numbers to different values, but couldn’t find anything that worked.

I wondered if I needed the actual device number (I presume -1 is just ‘default’ sound)? So I looked at the output from:

devices = PsychPortAudio(‘GetDevices’);

And I got this, but was then not sure what to do with it (sorry about lack of table formatting):

0 2 ‘MME’ ‘Microsoft Sound Mapper - Input’ 2 0 0.0900000000000000 0.180000000000000 0.0900000000000000 0.180000000000000 44100
1 2 ‘MME’ 'Microphone (USB Sound Device ’ 2 0 0.0900000000000000 0.180000000000000 0.0900000000000000 0.180000000000000 44100
2 2 ‘MME’ ‘Line (USB Sound Device )’ 2 0 0.0900000000000000 0.180000000000000 0.0900000000000000 0.180000000000000 44100
3 2 ‘MME’ ‘Stereo Mix (Realtek High Defini’ 2 0 0.0900000000000000 0.180000000000000 0.0900000000000000 0.180000000000000 44100
4 2 ‘MME’ ‘SPDIF Interface (USB Sound Devi’ 2 0 0.0900000000000000 0.180000000000000 0.0900000000000000 0.180000000000000 44100
5 2 ‘MME’ ‘Microsoft Sound Mapper - Output’ 0 2 0.0900000000000000 0.180000000000000 0.0900000000000000 0.180000000000000 44100
6 2 ‘MME’ 'Speakers (USB Sound Device ’ 0 8 0.0900000000000000 0.180000000000000 0.0900000000000000 0.180000000000000 44100
7 2 ‘MME’ 'Speakers / Headphones (Realtek ’ 0 2 0.0900000000000000 0.180000000000000 0.0900000000000000 0.180000000000000 44100
8 13 ‘Windows WASAPI’ ‘Speakers (USB Sound Device )’ 0 6 0 0 0.00300000000000000 0.0100000000000000 48000
9 13 ‘Windows WASAPI’ ‘Speakers / Headphones (Realtek High Definition Audio)’ 0 2 0 0 0.00300000000000000 0.0100000000000000 48000
10 13 ‘Windows WASAPI’ ‘Line (USB Sound Device )’ 2 0 0.00300000000000000 0.0100000000000000 0 0 44100
11 13 ‘Windows WASAPI’ ‘Stereo Mix (Realtek High Definition Audio)’ 2 0 0.00300000000000000 0.0100000000000000 0 0 48000
12 13 ‘Windows WASAPI’ ‘Microphone (USB Sound Device )’ 2 0 0.00300000000000000 0.0100000000000000 0 0 48000
13 13 ‘Windows WASAPI’ ‘SPDIF Interface (USB Sound Device )’ 2 0 0.00300000000000000 0.0100000000000000 0 0 48000
14 11 ‘Windows WDM-KS’ ‘Speakers (USB Sound Device)’ 0 8 0.0100000000000000 0.0853333333333333 0.0100000000000000 0.0853333333333333 44100
15 11 ‘Windows WDM-KS’ ‘Microphone (USB Sound Device)’ 2 0 0.0100000000000000 0.0853333333333333 0.0100000000000000 0.0853333333333333 44100
16 11 ‘Windows WDM-KS’ ‘Line In (Realtek HD Audio Line input)’ 2 0 0.0100000000000000 0.0400000000000000 0.0100000000000000 0.0400000000000000 44100
17 11 ‘Windows WDM-KS’ ‘Speakers (Realtek HD Audio output)’ 0 2 0.0100000000000000 0.0400000000000000 0.0100000000000000 0.0400000000000000 44100
18 11 ‘Windows WDM-KS’ ‘Stereo Mix (Realtek HD Audio Stereo input)’ 2 0 0.0100000000000000 0.0400000000000000 0.0100000000000000 0.0400000000000000 48000
19 11 ‘Windows WDM-KS’ ‘Microphone (Realtek HD Audio Mic input)’ 2 0 0.0100000000000000 0.0400000000000000 0.0100000000000000 0.0400000000000000 44100

Any help would be very much appreciated (again!)

Thank you!

HDJ

Maybe somebody else will give free advice or you find something related on the forum already, but more advice from myself requires your lab buying a paid support membership for up to 30 minutes of paid advice. This is something any lab which uses PTB should have anyway, irrespective of need for support, as this is what keeps the lights on for PTB. Way too few labs do this and this will end badly…

help PsychPaidSupportAndServices

Edit: I should also mention that if you participate in our currently running user survey (see announcements category of the forum), you will get a discount code after survey completion for a slightly reduced price for such a support membership.

best,
-mario

Hi Mario,

Oh I am very sorry, I thought this was a peer-to-peer help forum. I will contact you directly if I am able to get funds for a paid help session.

Thank you for your initial help,

Harriet

It is both, a peer-to-peer help forum and also the way to get paid support from myself, although I sometimes answer very trivial and quick to answer questions or questions and issues of critical importance to the majority of the community for free. It just so happens that most of your peers are not very inclined to answer anything for free much of the time.

You’ve used up what i was willing to answer to you for free, but if you’d buy paid support, this forum would still be the best place to ask away.

-mario