Skip to content

Commit 21da369

Browse files
committed
Load user-provided PortAudio name/path from environ's SD_PORTAUDIO
1 parent 4aa98dc commit 21da369

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

sounddevice.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,28 @@
6060

6161
try:
6262
for _libname in (
63-
'portaudio', # Default name on POSIX systems
64-
'bin\\libportaudio-2.dll', # DLL from conda-forge
65-
'lib/libportaudio.dylib', # dylib from anaconda
66-
):
63+
_os.environ.get('SD_PORTAUDIO', ''), # User-provided PortAudio name/path
64+
'portaudio', # Default name on POSIX systems
65+
'bin\\libportaudio-2.dll', # DLL from conda-forge
66+
'lib/libportaudio.dylib', # dylib from anaconda
67+
):
6768
_libname = _find_library(_libname)
6869
if _libname is not None:
69-
break
70+
try:
71+
_lib = _ffi.dlopen(_libname)
72+
# Basic check for the loaded PortAudio binary
73+
assert('PortAudio' in _ffi.string(_lib.Pa_GetVersionText()).decode())
74+
except (AttributeError, AssertionError, OSError):
75+
# Continue checking other libraries on
76+
# AttributeError: Pa_GetVersionText() not available in binary
77+
# AssertionError: 'PortAudio' not found in lib's version text
78+
# OSError: library could not be opened by ffi
79+
pass
80+
else:
81+
# Exit loop and use _lib if assertion is successful
82+
break
7083
else:
7184
raise OSError('PortAudio library not found')
72-
_lib = _ffi.dlopen(_libname)
7385
except OSError:
7486
if _platform.system() == 'Darwin':
7587
_libname = 'libportaudio.dylib'

0 commit comments

Comments
 (0)