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
✔️ ✔️ ✔️

Features

This library is in early stage. Full set of features as well as documentation is yet to be released.


Installation

⚠️ This library is not YET available on Maven Central ⚠️ For now use the msf.zip file provided in releases and unpack it in local maven repository.

To add library to Your project paste the following snippet in your TOML file.

[versions]
mikrosoundfont = "<latest_version>"

[libraries]
mikrosoundfont-midi = { module = "pl.lemanski.mikrosoundfont:midi", version.ref = "mikrosoundfont" }  
mikrosoundfont-soundFont = { module = "pl.lemanski.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)

Useful resources:

About

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

Resources

License

Stars

Watchers

Forks