Skip to content

Commit

Permalink
Merge branch 'master' into CI-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-hld committed Jan 29, 2024
2 parents 773f096 + 4862288 commit 1a91a50
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 24 deletions.
42 changes: 27 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
# SAFpy

[![Python application](https://github.com/chris-hld/SAFpy/actions/workflows/python-safpy.yml/badge.svg)](https://github.com/chris-hld/SAFpy/actions/workflows/python-safpy.yml)

This is a Python binding / wrapper for
https://github.com/leomccormack/Spatial_Audio_Framework

So far, there are a bunch of functions exposed, please feel free to
add/contribute more if needed!


Prerequisites
Quickstart
---
1. Compile SAF, see instructions in its docs
2. Install numpy and CFFI, e.g. `conda install numpy cffi`
3. Now we need to build *safpy*, which creates the module.
Running `pip install -e .` builds it automatically
1. Clone SAFpy, SAF is provided as a submodule, and change to the folder

(you can also build manually, e.g., for debugging, with
`python safpy_build.py`)
```git clone --recursive https://github.com/chris-hld/SAFpy && cd SAFpy```

By default, it assumes SAF in a folder parallel to safpy. You can simply adapt
the variable `saf_path` in `safpy_build.py` if needed.
2. Go to the SAF folder and compile SAF, see instructions in its [docs](https://github.com/leomccormack/Spatial_Audio_Framework/blob/master/README.md).
For example with

Install
---
`pip install -e . `
```cmake -S . -B build -DSAF_PERFORMANCE_LIB=SAF_USE_OPEN_BLAS_AND_LAPACKE && cmake --build ./build```

Test
---
`pytest -vvv`
3. Install numpy and CFFI (in the environment you want to use), e.g. `conda install numpy cffi`
4. Now we need to build *safpy*, which creates the module.
Running (in the environment you want to use)

```pip install -e .```,

with `.` in the SAFpy folder, builds it automatically and installs any potentially missing Python dependencies.

6. (Optional) Test if everything works, run `pytest -vvv` in the SAFpy folder.


By default, SAF is assumed in a subdirectory, which is also obtained by `git submodule update --init --recursive `.
In case you want to use a different location, you can simply adapt the variable `saf_path` in `safpy_build.py` if needed.
There you also have access to change the SAF performance library options, in case the default is not working for you.

You can also build SAFpy manually, e.g., for debugging, with
`python safpy_build.py`.

If in trouble you can also have a look at the CI steps [here](https://github.com/chris-hld/SAFpy/blob/master/.github/workflows/python-safpy.yml).

Usage
---
Expand Down
33 changes: 24 additions & 9 deletions safpy_build.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
import os.path
import sys
from cffi import FFI
ffibuilder = FFI()

home_dir = os.path.expanduser('~')
this_dir = os.path.abspath(os.path.dirname(__file__))
# define saf_path here, assumes SAF parallel to safpy by default.
saf_path = os.path.join(this_dir, ".", "Spatial_Audio_Framework")
saf_performance_lib = ["openblas", "lapacke"]

# Populate these
c_header_source = ""
include_dirs = []
libraries = []
library_dirs = []

saf_performance_lib = []
extra_link_args = []

# Sensible default, please adjust if needed.
# In case of doubt, you can also check numpy.show_config() for its BLAS
if sys.platform == "darwin":
print("SAFPY using default Apple Accelerate")
extra_link_args.extend(['-Wl,-framework', '-Wl,Accelerate'])
else:
print("SAFPY using default OpenBLAS/LAPACKE")
saf_performance_lib.extend(["openblas", "lapacke"])


# cdef() expects a single string declaring the C types, functions and
# globals needed to use the shared object. It must be in valid C syntax.
Expand Down Expand Up @@ -171,13 +190,6 @@
""")

# Populate these
c_header_source = ""
include_dirs = []
libraries = []
library_dirs = []


# set_source() gives the name of the python extension module to
# produce, and some C source code as a string. This C code needs
# to make the declarated functions, types and globals available,
Expand All @@ -194,10 +206,13 @@
print(f"include_dirs: {include_dirs}")
print(f"libraries: {libraries}")
print(f"library_dirs: {library_dirs}")
print(f"extra_link_args: {extra_link_args}")



ffibuilder.set_source("_safpy", c_header_source, include_dirs=include_dirs,
libraries=libraries, library_dirs=library_dirs)
libraries=libraries, library_dirs=library_dirs,
extra_link_args=extra_link_args)

if __name__ == "__main__":
ffibuilder.compile(verbose=True)

0 comments on commit 1a91a50

Please sign in to comment.