hengestone / meltysynth

A SoundFont synthesizer for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MeltySynth

MeltySynth is a SoundFont synthesizer written in C#. The purpose of this project is to provide a MIDI music playback functionality for any .NET applications without suffering from complicated dependencies. The codebase is lightweight and can be applied to any audio drivers which support streaming audio, such as SFML.Net, Silk.NET, OpenTK, and NAudio.

The entire code is heavily inspired by the following projects:

An example code to synthesize a simple chord:

// Create the synthesizer.
var sampleRate = 44100;
var synthesizer = new Synthesizer("TimGM6mb.sf2", sampleRate);

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

// The output buffer (3 seconds).
var left = new float[3 * sampleRate];
var right = new float[3 * sampleRate];

// Render the waveform.
synthesizer.Render(left, right);

Another example code to synthesize a MIDI file:

// Create the synthesizer.
var sampleRate = 44100;
var synthesizer = new Synthesizer("TimGM6mb.sf2", sampleRate);

// Read the MIDI file.
var midiFile = new MidiFile("flourish.mid");
var sequencer = new MidiFileSequencer(synthesizer);
sequencer.Play(midiFile, false);

// The output buffer.
var left = new float[(int)(sampleRate * midiFile.Length.TotalSeconds)];
var right = new float[(int)(sampleRate * midiFile.Length.TotalSeconds)];

// Render the waveform.
sequencer.Render(left, right);

Features

  • No dependencies other than .NET Core 3.1.
  • No memory allocation in the rendering process.
  • No unsafe code.

Installation

The NuGet package is available:

Install-Package MeltySynth

If you don't like DLLs, copy all the .cs files to your project.

Demo

Here is a demo song generated with Arachno SoundFont.

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

Demo video

Examples

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
    • Loop extension support
    • Performace optimization

License

MeltySynth is available under the MIT license.

References

About

A SoundFont synthesizer for .NET

License:Other


Languages

Language:C# 99.9%Language:Batchfile 0.1%