Skip to content

Kotlin Multiplatform library for sample-based synthesis to play MIDI files.

License

Notifications You must be signed in to change notification settings

lemcoder/MikroSoundFont

Repository files navigation

Kotlin Multiplatform SoundFont library

Kotlin
GitHub License

⚠️ This library is NOT ready for production use.⚠️

Library for sample-based synthesis to play MIDI files. The library is split in two modules:

  • Midi module: Allows to read and write standard MIDI files and parsing/encoding MIDI messages. Can generate F32 audio data from MIDI messages.
  • SoundFont module: Allows to load .sf2 files from filesystem and from memory. Is basically a KMP wrapper around TinySoundFont library.

The goal of this library is to allow operations on MIDI files and generating audio in Kotlin Multiplatform projects. The library has batteries-included so no configuration is required.

Non goals:

  • Audio file export (such as WAV or MP3)
  • Base File I/O operations
  • Audio format conversion
  • Resampling, mixing etc...

Platform support:

Android iOS Mingw X64 Linux X64 MacOs Wasm JS
✔️ ✔️ ✔️ ✔️ ✔️ ✖️

Installation

This library is stored on Maven Central repository. To add library to Your project paste the following snippet in your TOML file.

[versions]
mikrosoundfont = "<latest_version>"

[libraries]
mikrosoundfont-midi = { module = "io.github.lemcoder.mikrosoundfont:midi", version.ref = "mikrosoundfont" }  
mikrosoundfont-soundfont = { module = "io.github.lemcoder.mikrosoundfont:soundfont", version.ref = "mikrosoundfont" }

Usage

val midiBuffer // .mid file bytes  
val sfBuffer   // .sf2 file bytes
    
val midiMessages = MidiFileParser(midiBuffer).parse().getMessages()    
val soundFont = MikroSoundFont.load(sfBuffer)  

val sampleRate = 44_100
val audioBytes = MidiSequencer(soundFont, 44_100).apply {   
	loadMidiEvents(midiMessages)  
}.generate()

// use audioBytes (e.g. write to .wav file)

License

This project is licensed under the Apache 2.0 License - see the LICENSE.md file for details

Useful resources:

About

Kotlin Multiplatform library for sample-based synthesis to play MIDI files.

Resources

License

Stars

Watchers

Forks