Getting Started with spessasynth_lib
spessasynth_lib vs spessasynth_core
There are two similar libraries: spessasynth_lib and spessasynth_core:
core is the main library that contains all the MIDI, SF2 and DLS parsing, as well as the synthesis engine with its effects. It can run in any JS environment.
lib builds on top of core,
relying on the Web Audio API to provide an easy-to-use wrapper that runs the engine off the main thread.
It depends on core, so all writing and conversion features can be used directly from core.
So:
Use spessasynth_lib if:
You want to play MIDI files in the browser without much work.
You don't want to have to program your own audio processor or threading.
You don't need direct access to the audio engine from the main thread.
Use spessasynth_core if:
You want direct audio engine access on the main thread.
You need full control over the audio.
You are not in a browser.
You don't have access to the Web Audio API.
Tip If you intend on using the "Microsoft GS Wavetable Synth" as your sound bank of choice,
it is highly recommended to use the original gm.dls (from c:/windows/system32/drivers)
file directly instead of an SF2 conversion for better accuracy.
If you want to fully recreate the sound, disable effects and set the sample rate to 22050 Hz.
Installation
npm install --save spessasynth_core spessasynth_lib
Copy
Warning Consider installing spessasynth_core as shown above,
as it provides essential types for many of the API functions.
Minimal setup
The minimal working setup requires the WorkletSynthesizer class and adding the worklet module .
The setup is initialized as follows:
const context = new AudioContext () ; await context . audioWorklet . addModule ( "path/to/worklet" ) ; const synth = new WorkletSynthesizer (context) ;
Copy
Make sure to replace path/to/worklet with one of the paths described here .
That's it! Now you can move on to learning how a simple MIDI player works.
Examples
Simple MIDI Player - Play a MIDI file with a synthesizer and a sequencer.
Advanced Example - Add a playlist, pause and seek controls.
Clickable Piano - Play notes with the mouse and load a custom sound bank.
Adding Visualizations - Draw per-channel waveforms and the pressed keys.
Rendering Audio To File - Render a MIDI file to WAV with an OfflineAudioContext.
Rendering Separate Channels To File - Render each MIDI channel to its own WAV file.
Worker Synthesizer - Use the WorkerSynthesizer and its export methods.
Direct Audio Engine Access - Render with spessasynth_core on the main thread.
Warning This documentation only describes the Web Audio API wrappers that spessasynth_lib itself provides.
Most of the types (such as BasicMIDI, BasicSoundBank and more) are documented in the spessasynth_core documentation .
If what you're looking for isn't here, it's probably there.