Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WDM-KS support in PortAudio from PyPi install #286

Open
leonardopsantos opened this issue Oct 29, 2020 · 6 comments
Open

WDM-KS support in PortAudio from PyPi install #286

leonardopsantos opened this issue Oct 29, 2020 · 6 comments

Comments

@leonardopsantos
Copy link

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.

@mgeier
Copy link
Member

mgeier commented Oct 30, 2020

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 ...

@blattm
Copy link
Contributor

blattm commented Jul 23, 2021

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 ....

@mgeier
Copy link
Member

mgeier commented Jul 25, 2021

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.

@blattm
Copy link
Contributor

blattm commented Dec 4, 2021

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.

@mgeier
Copy link
Member

mgeier commented Dec 6, 2021

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:

ctypes.util.find_library = new_find_library
.

@thsno02
Copy link

thsno02 commented Jun 14, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants