Add SF3 (OGG Vorbis compressed) SoundFont support and Android 15+ compatibilty via 16KB ELF page alignment#2
Open
Von-Cheam wants to merge 1 commit intolemcoder:masterfrom
Open
Conversation
SF3 support: include stb_vorbis.c in native build and JNI layer, enabling transparent loading of SF3 (OGG Vorbis compressed) SoundFont files alongside existing SF2 support. 16KB alignment: add -Wl,-z,max-page-size=16384 linker flag to CMakeLists.txt so the built .so passes Android 15+ 16KB page size requirements (). The resulting binary is backwards-compatible with 4KB devices.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR, which was generated with the use of AI, adds two independent features to MikroSoundFont's Android native library:
.sf3SoundFont files (which use OGG Vorbis compression for sample data) alongside existing.sf2supportSF3 Support
SF3 is an extension of the SF2 format where sample data is compressed with OGG Vorbis, typically reducing file sizes by 5–10×. The SF3 format is widely used (e.g., by MuseScore's default SoundFonts) and is structurally identical to SF2 except for the sample encoding.
Changes
native/src/stb_vorbis.c(new file): Sean Barrett's stb_vorbis public-domain OGG Vorbis decoder. This is a single-file, header-only C library with no external dependenciesnative/src/tsf.c: Added#include "stb_vorbis.c"before the TinySoundFont include, which enables theTSF_SUPPORT_OGGcompile-time path already present intsf.h, specificallytsf_decode_ogg()andtsf_decode_sf3_samples(), which detect SF3 compression flags in SoundFontshdrrecords and decode OGG-compressed samples at load timesoundfont/src/androidMain/cpp/mikro_sound_font_jni.c: Added matching#include "stb_vorbis.c"in the JNI layerThe Kotlin API is unchanged —
MikroSoundFont.loadSoundFont(ByteArray)handles SF3 files transparently, as the format detection and decompression happen entirely in the C layer.Testing
Tested with:
.sf2files (regression — no change in behaviour).sf3file (197 presets, successful load and playback)16KB ELF Page Alignment
Android 15+ (API 35+) requires support for devices with 16KB memory page sizes. Native
.solibrary files must have their ELF LOAD segments aligned to 16KB boundaries on these devices, or the app displays a compatibility warning dialog on every launch and cannot be distributed via to Google Play.The current release (v0.3.0) builds
libmikroSoundFontJNI.sowith the default 4KB LOAD segment alignment, which blocks distribution via Google Play and triggers the following runtime warning on Android 15+ devices:Changes
soundfont/src/androidMain/cpp/CMakeLists.txt: Addedtarget_link_options(mikroSoundFontJNI PRIVATE "-Wl,-z,max-page-size=16384"), which instructs the linker to align LOAD segments to 16KB boundariesThe resulting
.sois backwards-compatible with 4KB page-size devices — 16KB alignment is a superset of 4KB alignment, so no conditional compilation or separate builds are needed.AI
Claude Opus 4.6, via Claude Code, was used to implement the features added in this PR. All changes made were reviewed, and all testing carried-out, by a human.
Build Changes
gradle/libs.versions.toml: Version updated to0.3.0-sf3to distinguish from the upstream releasesettings.gradle.kts: Minor build configuration updatessoundfont/build.gradle.kts: Build configuration updates for the native compilation pipeline