From 6cdd114a8a9559de6dd5a9f6714a908d79f9c10f Mon Sep 17 00:00:00 2001 From: Matthias Geier Date: Tue, 1 Oct 2024 21:21:16 +0200 Subject: [PATCH 1/2] DOC: describe the SD_ENABLE_ASIO environment variable --- doc/installation.rst | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/doc/installation.rst b/doc/installation.rst index b29b3a8..85ccff1 100644 --- a/doc/installation.rst +++ b/doc/installation.rst @@ -47,15 +47,35 @@ ASIO Support ------------ Installing the ``sounddevice`` module with ``pip`` (on Windows) -will provide PortAudio_ DLLs *without* ASIO support +will provide two PortAudio_ DLLs, with and without ASIO support. +By default, the DLL *without* ASIO support is loaded (because of the problems mentioned in `issue #496`__). -To enable ASIO support, download the file -`libportaudio64bit-asio.dll`__ or libportaudio32bit-asio.dll__ -and rename/move it as described in the next section. +To load the DLL *with* ASIO support, the environment variable ``SD_ENABLE_ASIO`` +has to be set *before* importing the ``sounddevice`` module, +for example like this: + +.. code:: python + + import os + + # Set environment variable before importing sounddevice. Value is not important. + os.environ["SD_ENABLE_ASIO"] = "1" + + import sounddevice as sd + + print(sd.query_hostapis()) __ https://github.com/spatialaudio/python-sounddevice/issues/496 -__ https://github.com/spatialaudio/portaudio-binaries/raw/master/libportaudio64bit-asio.dll -__ https://github.com/spatialaudio/portaudio-binaries/raw/master/libportaudio32bit-asio.dll + +.. note:: + + This will only work if the ``sounddevice`` module has been installed via ``pip``. + This will not work with the ``conda`` package (see below). + +.. note:: + + This will not work if a custom ``portaudio.dll`` is present in the ``%PATH%`` + (as described in the following section). Custom PortAudio Library From 00ef17cc8f3217128381a22135364460b5824e1a Mon Sep 17 00:00:00 2001 From: Matthias Geier Date: Tue, 1 Oct 2024 21:22:53 +0200 Subject: [PATCH 2/2] CI: load ASIO DLL --- .github/workflows/sounddevice-data.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sounddevice-data.yml b/.github/workflows/sounddevice-data.yml index a790098..3b1aecb 100644 --- a/.github/workflows/sounddevice-data.yml +++ b/.github/workflows/sounddevice-data.yml @@ -33,8 +33,22 @@ jobs: working-directory: git-repo run: | python -m pip install . - - name: Run tests + - name: Import module run: | python -m sounddevice python -c "import sounddevice as sd; print(sd._libname)" python -c "import sounddevice as sd; print(sd.get_portaudio_version())" + python -c "import sounddevice as sd; print(sd.query_hostapis())" + python -c "import sounddevice as sd; assert 'asio' not in sd._libname" + python -c "import sounddevice as sd; assert not any(a['name'] == 'ASIO' for a in sd.query_hostapis())" + - name: Import module (using the ASIO DLL) + if: startsWith(matrix.os, 'windows') + env: + SD_ENABLE_ASIO: 1 + run: | + python -m sounddevice + python -c "import sounddevice as sd; print(sd._libname)" + python -c "import sounddevice as sd; print(sd.get_portaudio_version())" + python -c "import sounddevice as sd; print(sd.query_hostapis())" + python -c "import sounddevice as sd; assert 'asio' in sd._libname" + python -c "import sounddevice as sd; assert any(a['name'] == 'ASIO' for a in sd.query_hostapis())"