{"id":18416780,"url":"https://github.com/fynv/pytinysoundfont","last_synced_at":"2025-07-19T00:36:29.027Z","repository":{"id":61034655,"uuid":"135905157","full_name":"fynv/pyTinySoundFont","owner":"fynv","description":"A Python port of TinySoundFont","archived":false,"fork":false,"pushed_at":"2022-10-16T10:45:55.000Z","size":599,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-22T18:41:08.976Z","etag":null,"topics":["sf2","soundfont","synthesizer"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fynv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-03T13:10:42.000Z","updated_at":"2023-08-07T11:29:26.000Z","dependencies_parsed_at":"2022-10-08T21:04:14.558Z","dependency_job_id":null,"html_url":"https://github.com/fynv/pyTinySoundFont","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fynv%2FpyTinySoundFont","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fynv%2FpyTinySoundFont/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fynv%2FpyTinySoundFont/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fynv%2FpyTinySoundFont/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fynv","download_url":"https://codeload.github.com/fynv/pyTinySoundFont/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247653159,"owners_count":20973775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["sf2","soundfont","synthesizer"],"created_at":"2024-11-06T04:07:16.874Z","updated_at":"2025-04-07T12:32:03.083Z","avatar_url":"https://github.com/fynv.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"pyTinySoundFont\n================\n\nThis is Python porting of TinySoundFont(https://github.com/schellingb/TinySoundFont)\n\nWe are still relying on C++ for some sample level tasks, so a building process is needed (see below).\n\n## Variations\n\nLatest commits in this repo try to use CFFI instead of CPython API, which is still problematic.\n\nThe branch [https://github.com/rdb/pytinysoundfont](https://github.com/rdb/pytinysoundfont) uses the CPython API, and releases to https://pypi.org/project/pyTinySoundFont/\n\n[https://github.com/fynv/wasm](https://github.com/fynv/wasm) has a WASM (wasmtime) based implementation, and releases to https://pypi.org/project/pyTinySoundFontWASM/\n\n## Functions\n\nThe \"class TinySoundFont\" interface defined in pyTinySoundFont/SF2SynthRT.py provides most of the original functions of TinySoundFont, with the following limitations:\n\n* Loading SF2 from memory is not implemented\n* \"Higher level channel based functions\" are not ported yet.\n* Real-time playback is not part of the project, which needs a separate solution.\n\nSee test/testRT.py for a use case.\n\nThe \"SynthNote()\" defined in pyTinySoundFont/SF2Synth.py provides a simple interface for single note synthesis. See test/test.py for a use case.\n\n\n## Building\n\nPrerequisites:\n\n* CMake 3.0+\n* Python3\n\n```\n$ mkdir build\n$ cd build\n$ cmake ..\n$ make\n$ make install\n```\n\n## Building Wheel\n\n```\n$ cd test\n$ python3 setup.py bdist_wheel\n```\n\n## Use cases\n\n### Realtime Synthesis\n\nPretty similar to the C version\n\n```Python\n\n\timport pyTinySoundFont as tsf\n\n\tg_TinySoundFont = tsf.TinySoundFont('florestan-subset.sf2')\n\n\tg_TinySoundFont.NoteOn(0,48,1.0) # C2\n\tg_TinySoundFont.NoteOn(0,52,1.0) # E2\n\n\t# We don't have an output device here, just open a file to simulate\n\twith open('dmp.raw','wb') as f:\n\t\tbuf =  tsf.F32Buf(512*2) # create a buffer of 512 samples, 2 channels\n\t\tfor i in range(200): # render 200 times to the buffer when notes are on\n\t\t\tg_TinySoundFont.Render(buf, 512, False)\n\t\t\tf.write(buf.to_s16(1.0))\n\t\t\n\t\tg_TinySoundFont.NoteOffAll()\n\n\t\tfor i in range(10): # render another 10 times after notes are off \n\t\t\tg_TinySoundFont.Render(buf, 512, False)\n\t\t\tf.write(buf.to_s16(1.0))\t\n\n```\n\n### Non-Realtime Synthesis\n\nThe 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.\n\n\n```Python\n\n\timport wave\n\timport pyTinySoundFont as tsf\n\n\tsf2= tsf.LoadSF2('florestan-subset.sf2')\n\tpresets = tsf.LoadPresets(sf2)\n\n\t# Render C5, required length is set to 2 seconds\n\t# The actual returned buffer will be a little longer than 2 seconds\n\t# There will some extra samples after the loop is ended\n\tres=tsf.SynthNote(sf2[1], presets[0], 60, 1.0, 44100*2)\n\n\t# Convert float32 to short16\n\twavS16=res[1].to_s16(1.0)\n\n\t# Here we write the generated samples to a wav file\n\t# We can also program to mix the samples with other buffer\n\twith wave.open('out.wav', mode='wb') as wavFile:\n\t\twavFile.setnchannels(2)\n\t\twavFile.setsampwidth(2)\n\t\twavFile.setframerate(44100)\n\t\twavFile.setnframes(len(wavS16)//4)\n\t\twavFile.writeframes(wavS16)\n\t\n```\n\n## License\n\npyTinySoundFont is available under the [MIT license](https://choosealicense.com/licenses/mit/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffynv%2Fpytinysoundfont","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffynv%2Fpytinysoundfont","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffynv%2Fpytinysoundfont/lists"}