Skip to content

A SoundFont MIDI synthesizer written in pure Odinlang

License

Notifications You must be signed in to change notification settings

sinshu/odinysynth

Repository files navigation

OdinySynth

OdinySynth is a SoundFont MIDI synthesizer written in pure Odin, ported from MeltySynth.

Demo

This is a demo video to show the synthesizer running on raylib's audio stream in real-time.

https://www.youtube.com/watch?v=edil47gQD1o

Youtube video

Features

  • Suitable for both real-time and offline synthesis.
  • Support for standard MIDI files.
  • No dependencies other than the core library.

Examples

An example code to synthesize a simple chord:

using odinysynth

// Load the SoundFont.
soundfont, _ := new_soundfont("TimGM6mb.sf2")
defer destroy(&soundfont)

// Create the synthesizer.
settings := new_synthesizer_settings(44100)
synthesizer, _ := new_synthesizer(&soundfont, &settings)
defer destroy(&synthesizer)

// Play some notes (middle C, E, G).
note_on(&synthesizer, 0, 60, 100)
note_on(&synthesizer, 0, 64, 100)
note_on(&synthesizer, 0, 67, 100)

// The output buffer (3 seconds).
sample_count := 3 * settings.sample_rate
left := make([]f32, sample_count)
defer delete(left)
right := make([]f32, sample_count)
defer delete(right)

// Render the waveform.
render(&synthesizer, left[:], right[:])

Another example code to synthesize a MIDI file:

using odinysynth

// Load the SoundFont.
soundfont, _ := new_soundfont("TimGM6mb.sf2")
defer destroy(&soundfont)

// Create the synthesizer.
settings := new_synthesizer_settings(44100)
synthesizer, _ := new_synthesizer(&soundfont, &settings)
defer destroy(&synthesizer)

// Load the MIDI file.
midi_file, _ := new_midi_file("flourish.mid")
defer destroy(&midi_file)

// Create the sequencer.
sequencer := new_midi_file_sequencer(&synthesizer)

// Play the MIDI file.
play(&sequencer, &midi_file, false)

// The output buffer.
sample_count := int(f64(settings.sample_rate) * get_length(&midi_file))
left := make([]f32, sample_count)
defer delete(left)
right := make([]f32, sample_count)
defer delete(right)

// Render the waveform.
render(&sequencer, left[:], right[:])

Todo

  • Wave synthesis
    • SoundFont reader
    • Waveform generator
    • Envelope generator
    • Low-pass filter
    • Vibrato LFO
    • Modulation LFO
  • MIDI message processing
    • Note on/off
    • Bank selection
    • Modulation
    • Volume control
    • Pan
    • Expression
    • Hold pedal
    • Program change
    • Pitch bend
    • Tuning
  • Effects
    • Reverb
    • Chorus
  • Other things
    • Standard MIDI file support
    • Performace optimization

License

OdinySynth is available under the MIT license.

About

A SoundFont MIDI synthesizer written in pure Odinlang

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages