|
1 | | -## Build from Source |
| 1 | +# pysfizz |
| 2 | +Python bindings for [sfizz](https://github.com/sfztools/sfizz), a sample-based synthesizer for the [SFZ](https://sfzformat.com) virtual instrument format. |
2 | 3 |
|
3 | | -### Prerequisites |
4 | | -- Python 3.9 or higher with development headers |
5 | | -- CMake 3.15 or higher |
6 | | -- C++17 compatible compiler |
| 4 | +## Installation |
| 5 | +### From PyPI |
| 6 | +Prebuilt wheels are available for Python 3.9–3.13 on Linux, macOS, and Windows. |
| 7 | +```bash |
| 8 | +pip install pysfizz |
| 9 | +``` |
| 10 | +### From source (development only) |
7 | 11 |
|
8 | | -### Build Steps |
9 | | -1. Clone the repository & initialize submodules: |
| 12 | +**Requires:** Git, CMake 3.15+, C++17 compatible compiler, Python 3.9+ with development headers |
10 | 13 | ```bash |
11 | 14 | git clone https://github.com/tiianhk/pysfizz.git |
12 | 15 | cd pysfizz |
13 | 16 | git submodule update --init --recursive |
| 17 | +pip install . |
14 | 18 | ``` |
15 | | -2. Build the Python module: |
16 | | -```bash |
17 | | -cmake -B build -DCMAKE_BUILD_TYPE=Release |
18 | | -cmake --build build --config Release --parallel |
19 | | -``` |
20 | | -3. Test the Python module: |
21 | | -```bash |
22 | | -python -c "import pysfizz; print('pysfizz imported successfully!')" |
| 19 | + |
| 20 | +## Example |
| 21 | +```python |
| 22 | +import pysfizz |
| 23 | +import soundfile as sf |
| 24 | + |
| 25 | +# load an instrument |
| 26 | +synth = pysfizz.Synth(sample_rate=48000, block_size=1024) |
| 27 | +synth.load_sfz_file("path/to/your/sfz/file.sfz") |
| 28 | + |
| 29 | +# print the list of MIDI notes that have SFZ regions |
| 30 | +print(synth.playable_keys) |
| 31 | + |
| 32 | +# single note offline systhesis |
| 33 | +pitch = 60 # MIDI note number, integer in [0, 127] |
| 34 | +vel = 127 # MIDI velocity, integer in [0, 127] |
| 35 | +note_dur = 1 # seconds, key pressed at t=0 and released after this duration |
| 36 | +render_dur = 2 # seconds, total rendered duration |
| 37 | +audio = synth.render_note(pitch, vel, note_dur, render_dur) # np.ndarray of shape (2, num_samples) |
| 38 | +sf.write("output.wav", audio.T, synth.get_sample_rate()) |
23 | 39 | ``` |
| 40 | + |
| 41 | +## Resources |
| 42 | +[SFZ instruments](https://sfzinstruments.github.io) |
| 43 | + |
| 44 | +## License and dependencies |
| 45 | + |
| 46 | +`pysfizz` is under the [BSD 2-Clause License](./LICENSE). |
| 47 | + |
| 48 | +It includes the following dependencies as Git submodules under the `external/` directory: |
| 49 | +- [sfizz](https://github.com/sfztools/sfizz) — BSD 2-Clause License |
| 50 | +- [nanobind](https://github.com/wjakob/nanobind) — BSD 3-Clause License |
0 commit comments