pyTinySoundFont
This is Python porting of TinySoundFont(https://github.com/schellingb/TinySoundFont)
We are still relying on C++ for some sample level tasks, so a building process is needed (see below).
The "class TinySoundFont" interface defined in pyTinySoundFont/SF2SynthRT.py provides most of the original functions of TinySoundFont, with the following limitations:
- Loading SF2 from memory is not implemented
- "Higher level channel based functions" are not ported yet.
- Real-time playback is not part of the project, which needs a separate solution.
See test/testRT.py for a use case.
The "SynthNote()" defined in pyTinySoundFont/SF2Synth.py provides a simple interface for single note synthesis. See test/test.py for a use case.
Building with CMake
Prerequisites:
- CMake 3.0+
- Python3
You can simply run CMake to generate makefiles/project files for your system and build. You can set CMAKE_INSTALL_PREFIX to /test so that the test scripts can find pyTinySoundFont.
Building with Setuptools
$ python3 setup.py build
$ python3 setup.py install
Use cases
Realtime Synthesis
Pretty similar to the C version
import pyTinySoundFont as tsf
g_TinySoundFont = tsf.TinySoundFont('florestan-subset.sf2')
g_TinySoundFont.NoteOn(0,48,1.0) # C2
g_TinySoundFont.NoteOn(0,52,1.0) # E2
# We don't have an output device here, just open a file to simulate
with open('dmp.raw','wb') as f:
buf = bytes(512 * 4 * 2) # create a buffer of 512 samples
for i in range(200): # render 200 times to the buffer when notes are on
g_TinySoundFont.Render(buf, 512, False)
f.write(buf)
g_TinySoundFont.NoteOffAll()
for i in range(10): # render another 10 times after notes are off
g_TinySoundFont.Render(buf, 512, False)
f.write(buf)
Non-Realtime Synthesis
The use case is that sometimes we just want to render some preprogrammed notes to a buffer as soon as possible, and we don't need immediate play-back. In that case, we can render 1 note each time then blend them together. Bellow example shows how to render a single note.
import wave
import pyTinySoundFont as tsf
sf2= tsf.LoadSF2('florestan-subset.sf2')
presets = tsf.LoadPresets(sf2)
# Render C5, required length is set to 2 seconds
# The actual returned buffer will be a little longer than 2 seconds
# There will some extra samples after the loop is ended
res=tsf.SynthNote(sf2[1], presets[0], 60, 1.0, 44100*2)
# Utility to convert float32 to short16
wavS16=tsf.F32ToS16(res[1], 1.0)
# Here we write the generated samples to a wav file
# We can also program to mix the samples with other buffer
with wave.open('out.wav', mode='wb') as wavFile:
wavFile.setnchannels(2)
wavFile.setsampwidth(2)
wavFile.setframerate(44100)
wavFile.setnframes(len(wavS16)//4)
wavFile.writeframes(wavS16)
License
pyTinySoundFont is available under the MIT license.
Metadata
Release files for pyTinySoundFont 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyTinySoundFont-0.0.1.tar.gz | 528.5 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| pyTinySoundFont-0.0.1-cp39-abi3-macosx_10_9_universal2.whl | CPython 3.9 | abi3 | macOS 10.9+ universal2 (ARM64, x86-64) | Details |
| pyTinySoundFont-0.0.1-cp32-abi3-win_amd64.whl | CPython 3.2 | abi3 | Windows x86-64 | Details |
| pyTinySoundFont-0.0.1-cp32-abi3-win32.whl | CPython 3.2 | abi3 | Windows x86-32 | Details |
| pyTinySoundFont-0.0.1-cp32-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.2 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| pyTinySoundFont-0.0.1-cp32-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.whl | CPython 3.2 | abi3 | Linux glibc 2.5+ x86-64 | Details |
| pyTinySoundFont-0.0.1-cp32-abi3-manylinux_2_5_i686.manylinux1_i686.whl | CPython 3.2 | abi3 | Linux glibc 2.5+ x86-32 | Details |
| pyTinySoundFont-0.0.1-cp32-abi3-macosx_10_9_x86_64.whl | CPython 3.2 | abi3 | macOS 10.9+ x86-64 | Details |
| pyTinySoundFont-0.0.1-cp32-abi3-macosx_10_6_intel.whl | CPython 3.2 | abi3 | macOS 10.6+ Intel (x86-64, i386) | Details |
Total release size: 802.1 kB
Release files / pyTinySoundFont-0.0.1.tar.gz
| Download URL | pyTinySoundFont-0.0.1.tar.gz |
|---|---|
| Size | 528.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
56748b0446c01e5c1eb371eac3782f689de99893c873ff8c7dc71704b414946f
|
|
BLAKE2b-256 checksum How to use checksums |
98b907d7b56aff8b54dbbb247f57ef6c51e1a9ade37f46e9f20ff8b1d479c106
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.7
|
Release files / pyTinySoundFont-0.0.1-cp39-abi3-macosx_10_9_universal2.whl
| Download URL | pyTinySoundFont-0.0.1-cp39-abi3-macosx_10_9_universal2.whl |
|---|---|
| Size | 28.5 kB |
| Tags | CPython 3.9 abi3 macOS 10.9+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
700d187efe9516e9416b43a61fe5cd63842e06cc63963ba70fc5c56c4eb60e0a
|
|
BLAKE2b-256 checksum How to use checksums |
f4fa18f2475deeda57f9acd8d29cfd27c0229abe04b60f0e8d1b180227e342f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.7
|
Release files / pyTinySoundFont-0.0.1-cp32-abi3-win_amd64.whl
| Download URL | pyTinySoundFont-0.0.1-cp32-abi3-win_amd64.whl |
|---|---|
| Size | 25.6 kB |
| Tags | CPython 3.2 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
157ad733ef2c1fa8606697d7151968c9b7a0c8b6f43253347d113487d7abef55
|
|
BLAKE2b-256 checksum How to use checksums |
be64484137f30e353d2a99fa19b93400c8a0dc88368b125dddbe9eeb8594b744
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.8.10
|
Release files / pyTinySoundFont-0.0.1-cp32-abi3-win32.whl
| Download URL | pyTinySoundFont-0.0.1-cp32-abi3-win32.whl |
|---|---|
| Size | 24.9 kB |
| Tags | CPython 3.2 Windows x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
4920ad52ea37cf2ddeb40ae7cae098ea7b5f7c9a5027bc7f3c447084f6d46576
|
|
BLAKE2b-256 checksum How to use checksums |
5a7e32607e2b8c71c6ca5fdff19b7b9d136f2184d42fdcd1541c789f861a1e2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.8.10
|
Release files / pyTinySoundFont-0.0.1-cp32-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | pyTinySoundFont-0.0.1-cp32-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 54.2 kB |
| Tags | CPython 3.2 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
ecdff02f5a3fab17be9523e3263db7532b65c8a43050c55877aa4904f0598e31
|
|
BLAKE2b-256 checksum How to use checksums |
f71a83f29146516cb23bafddbb82378254645b451c7b74d48f0f3d1a3e2a6f2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
|
Release files / pyTinySoundFont-0.0.1-cp32-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.whl
| Download URL | pyTinySoundFont-0.0.1-cp32-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.whl |
|---|---|
| Size | 46.9 kB |
| Tags | CPython 3.2 Linux glibc 2.5+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
59693e6c3ced60c9290cd2df23a516a7dfdedaf3e5247f7977930fd745ed161f
|
|
BLAKE2b-256 checksum How to use checksums |
47bbeac20e6336d8b8fdb215aee7087d687fbe60ce385a57d45790594a6c3ea0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
|
Release files / pyTinySoundFont-0.0.1-cp32-abi3-manylinux_2_5_i686.manylinux1_i686.whl
| Download URL | pyTinySoundFont-0.0.1-cp32-abi3-manylinux_2_5_i686.manylinux1_i686.whl |
|---|---|
| Size | 45.6 kB |
| Tags | CPython 3.2 Linux glibc 2.5+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
a383cb1defba5aff75bc3ec4b4d5dc3a1b05e9833cb3c09aa5f1227cfd2b8ac4
|
|
BLAKE2b-256 checksum How to use checksums |
884fc46e06303340ffca1e4078c3de58b0b744c7937a2d2bdff027d138cafd98
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
|
Release files / pyTinySoundFont-0.0.1-cp32-abi3-macosx_10_9_x86_64.whl
| Download URL | pyTinySoundFont-0.0.1-cp32-abi3-macosx_10_9_x86_64.whl |
|---|---|
| Size | 22.0 kB |
| Tags | CPython 3.2 abi3 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
098c0fda33995c9a35b9e35ac29bcc5aa5265f1d560f246f32f392cc7b1e8fb8
|
|
BLAKE2b-256 checksum How to use checksums |
7f5730e703bb0f02b7473adc6108850970e6c543ce667f495600de3163e92c3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.7
|
Release files / pyTinySoundFont-0.0.1-cp32-abi3-macosx_10_6_intel.whl
| Download URL | pyTinySoundFont-0.0.1-cp32-abi3-macosx_10_6_intel.whl |
|---|---|
| Size | 25.9 kB |
| Tags | CPython 3.2 abi3 macOS 10.6+ Intel (x86-64, i386) |
|
SHA-256 checksum How to use checksums |
d5c1dfd7e427f5eac025e72986a5f76f2373feeb18ecf38b41823cf69bdea8c9
|
|
BLAKE2b-256 checksum How to use checksums |
f58f6809258139d1a9fe1f14615186ef489bae2c1517e6af22eb494a9d18fd5d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.7
|