Sonix Midi Synthesizer
MIDI synthesizer for converting MIDI to audio using SoundFont files.
What is MIDI Synthesis?
MIDI is a note description format - it says "play note C4 for 500ms" but doesn't contain actual audio. A synthesizer converts MIDI to audio using instrument samples from a SoundFont file.
Use it for:
Generating reference tracks from note sequences
Creating practice audio from lesson data
Converting MIDI files to audio
When to Use
| Scenario | Use This? | Why |
|---|---|---|
| Generate reference audio | Yes | From lesson notes |
| Convert MIDI to audio | Yes | Core use case |
| Play audio file | No | Use SonixPlayer |
| Real-time MIDI playback | No | Not supported yet |
Quick Start
Kotlin
val synth = SonixMidiSynthesizer.create(soundFontPath = "/path/to/soundfont.sf2")
// Synthesize from MIDI file
synth.synthesize(midiPath = "input.mid", outputPath = "output.wav")
// Or synthesize from notes (timing in milliseconds)
val notes = listOf(
MidiNote(note = 60, startTime = 0f, endTime = 500f), // C4 at 0-500ms
MidiNote(note = 62, startTime = 500f, endTime = 1000f) // D4 at 500-1000ms
)
synth.synthesizeFromNotes(notes = notes, outputPath = "output.wav")
synth.release() // Optional - synth is statelessSwift
let synth = SonixMidiSynthesizer.create(soundFontPath: "/path/to/soundfont.sf2")
// Synthesize from MIDI file
synth.synthesize(midiPath: "input.mid", outputPath: "output.wav")
// Or synthesize from notes
let notes = [
MidiNote(note: 60, startTime: 0, endTime: 500), // C4 at 0-500ms
MidiNote(note: 62, startTime: 500, endTime: 1000) // D4 at 500-1000ms
]
synth.synthesizeFromNotes(notes: notes, outputPath: "output.wav")Builder Pattern (Advanced)
Kotlin
val synth = SonixMidiSynthesizer.Builder()
.soundFontPath("/path/to/soundfont.sf2")
.sampleRate(48000)
.onError { error -> println("Error: $error") }
.build()Swift
let synth = SonixMidiSynthesizer.Builder()
.soundFontPath(path: "/path/to/soundfont.sf2")
.sampleRate(rate: 48000)
.build()SoundFont Files
SoundFont (.sf2 or .sf3) files contain instrument samples:
Use high-quality SoundFonts for better audio
File size affects memory usage
SF3 format is compressed (smaller files)
Platform Notes
iOS/Android
Uses FluidSynth library for synthesis
Runs synchronously (consider background thread for large files)
Output is always WAV format
Common Pitfalls
Missing SoundFont: Must provide valid .sf2 or .sf3 file
Large MIDI files: Synthesis time scales with MIDI duration
Note timing: MidiNote times are in milliseconds (not seconds)
Output format: Always outputs WAV; use SonixEncoder to convert
See also
For lesson-specific synthesis
For converting WAV to MP3/M4A
For note specification format