WDM-KS support in PortAudio from PyPi install
Hello there!
I'm using sounddevice on Windows 10, having installed it with pip.
If you install the sounddevice module with pip on macOS or Windows, the PortAudio library (with ASIO support on Windows) will be installed automagically.
I'm using a Scarlett 6i6 external sound module and it seems that I can only open the MME devices, not the WDS-KS ones.
Using query_devices(), I get:
1 Microphone (USB Audio 2.0), MME (2 in, 0 out)
4 Speakers (USB Audio 2.0), MME (0 in, 2 out)
8 Microphone (USB Audio 2.0), Windows DirectSound (2 in, 0 out)
14 Speakers (USB Audio 2.0), Windows WASAPI (0 in, 12 out)
18 Microphone (USB Audio 2.0), Windows WASAPI (6 in, 0 out
25 Speakers (Scarlett 6i6 USB), Windows WDM-KS (0 in, 12 out)
26 Microphone (Scarlett 6i6 USB), Windows WDM-KS (6 in, 0 out)
If I set sounddevice.default.device = (USB Audio 2.0), MME, everything works. But if I set sounddevice.default.device = scarlett , I get
sounddevice.PortAudioError: Error opening Stream: Invalid device [PaErrorCode -9996]
I understand that this error is coming directly from the PortAudio library. Does the PortAudio library for Windows that comes with sounddevice support WDM-KS?
Thank you.
You should check which DLL is actually used, e.g. by looking at sd._libname.
Does the PortAudio library for Windows that comes with sounddevice support WDM-KS?
Yes, see https://github.com/spatialaudio/portaudio-binaries.
The device list contains WDM-KS entries, so it is supported. That doesn't necessarily mean it also works ...
Hi, I have exactly the same problem on Windows 10, using sounddevice 0.4.2 installed via pip with the following PortAudio version:
(1246976, 'PortAudio V19.7.0-devel, revision 147dd722548358763a8b649b3e4b41dfffbcfbb6')
C:\Users\Manuel\Anaconda3\envs\looper\lib\site-packages\_sounddevice_data\portaudio-binaries\libportaudio64bit.dll'
This issue also occurred on pip's sounddevice 0.4.1 using PortAudio V19.6. The PortAudio dll from conda-forge does not have this problem (but lacks ASIO support...)
I hope this information helps. If there is any additional information that could help you, please let me know ....
Thanks @blattm! It's good to know that the DLL from conda-forge doesn't have the same problem.
The way the DLLs are created is different, so it is possible that the behavior is different as well.
The DLL bundled with the sounddevice module uses cross-compilation with https://github.com/mxe/mxe to create the DLLs.
Maybe this should be reported to https://github.com/PortAudio/portaudio?
I'm not a Windows user and I have no clue about Windows (nor MinGW), so I cannot really do anything.
Hi,
So the work around I currently use is to to take the version of sounddevice from pip if I plan to use ASIO, and the version from anaconda when I plan to use WDM-KS. But this requires two virtual environments. In case of distributing a program as an executable (e.g. via pyinstaller), two different executables are required.
However, a potentially better workaround just came to my mind. @mgeier, do you know if there is a way to manually choose the dll to use? It would then be possible (for either sounddevice or the programmer using it) to include both dlls and offer an ASIO and WDM-KS mode.
Of course, solving the underlying problem related to MinGW and PortAudio would be better, but I assume that's not happening soon.
do you know if there is a way to manually choose the dll to use?
There is currently no simple way to do this, see #130.
As a work-around, you could probably monkey-patch find_library(), similar to how it is done here: https://github.com/spatialaudio/python-sounddevice/blob/d353fbf6c751a7a91169c614df8f905f2c55821c/doc/fake__sounddevice.py#L17.
I found the answer. The sampling frequency "fs" had to match the default sampling frequency for that device in Windows.
This works for me.
REF: https://stackoverflow.com/questions/57467633/why-do-i-get-a-invalid-device-error-when-recording-a-device-using-wasapi-and-t