Skip to content

Commit d1d125f

Browse files
authored
Merge pull request #311 from panosl/bugfix/310
Find libsndfile.dylib on Apple M1
2 parents 1bd1529 + 008503e commit d1d125f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

soundfile.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import os as _os
1414
import sys as _sys
15+
from platform import machine as _machine
1516
from os import SEEK_SET, SEEK_CUR, SEEK_END
1617
from ctypes.util import find_library as _find_library
1718
from _soundfile import ffi as _ffi
@@ -159,8 +160,16 @@
159160
while not _os.path.isdir(_path):
160161
_path = _os.path.abspath(_os.path.join(_path, '..'))
161162

162-
_snd = _ffi.dlopen(_os.path.join(
163-
_path, '_soundfile_data', _libname))
163+
# Homebrew on Apple M1 uses a `/opt/homebrew/lib` instead of
164+
# `/usr/local/lib`. We are making sure we pick that up.
165+
if _sys.platform == 'darwin' and _machine() == 'arm64':
166+
_hbrew_path = '/opt/homebrew/lib/' if _os.path.isdir('/opt/homebrew/lib/') \
167+
else '/usr/local/lib/'
168+
_snd = _ffi.dlopen(_os.path.join(
169+
_hbrew_path, _libname))
170+
else:
171+
_snd = _ffi.dlopen(_os.path.join(
172+
_path, '_soundfile_data', _libname))
164173

165174
__libsndfile_version__ = _ffi.string(_snd.sf_version_string()).decode('utf-8', 'replace')
166175
if __libsndfile_version__.startswith('libsndfile-'):

0 commit comments

Comments
 (0)