Skip to content

A versatile JavaScript library for SoundFont2/3 synthesis and MIDI playback, offering powerful features and zero dependencies.

License

Notifications You must be signed in to change notification settings

spessasus/SpessaSynth

Repository files navigation

SpessaSynth logo

SpessaSynth is a SoundFont2-based real-time synthesizer and MIDI player written in vanilla JavaScript. It’s a powerful library that allows you to read, write, or play MIDI files and read/write SF2/SF3 files with ease.

SpessaSynth Promotional Image

npm package now available!

npm install --save spessasynth_lib

YouTube Video

Watch the YouTube video

This repository contains both the library and a complete musical web application. See below:

spessasynth_lib

A flexible, powerful, and feature-packed SoundFont synthesizer library for the WebAudio API. Comes with the ability to edit MIDIs and SoundFonts!

Features

Easy Integration

Powerful SoundFont Synthesizer

  • Suitable for both real-time and offline synthesis
  • Excellent SoundFont support:
    • Generator Support
    • Modulator Support: First (to my knowledge) JavaScript SoundFont synth with that feature!
    • SoundFont3 Support: Play compressed SoundFonts!
    • Can load very large SoundFonts: up to 4GB! Note: Only Firefox handles this well; Chromium has a hard-coded memory limit
  • Reverb and chorus support: customizable!
  • Export audio files using OfflineAudioContext
  • Custom modulators for additional controllers: Why not?
  • Written using AudioWorklets: runs in a separate thread for maximum performance, works perfectly in Firefox and Chrome!
  • Unlimited channel count: Your CPU is the limit!
  • Various MIDI Standards Support:
    • MIDI Controller Support: Default supported controllers here
  • High-performance mode: Play Rush E! note: may kill your browser ;)
  • Written in pure JavaScript using the WebAudio API: Supported by all modern browsers!

Built-in Powerful and Fast Sequencer

  • Supports MIDI formats 0, 1, and 2: note: format 2 support is experimental as it's very, very rare
  • Multi-Port MIDI support: More than 16 channels!
  • Smart preloading: Only preloads the samples used in the MIDI file for smooth playback (down to key and velocity!)
  • Lyrics support: Add karaoke to your program!
  • Raw lyrics available: Decode in any encoding! (Kanji? No problem!)

Read and Write SoundFont and MIDI Files with Ease

Read and write MIDI files

  • Smart name detection: Handles incorrectly formatted and non-standard track names
  • Port detection during load time: Manage ports and channels easily!
  • Used channels on track: Quickly determine which channels are used
  • Key range detection: Detect the key range of the MIDI
  • Easy MIDI editing: Use helper functions to modify the song to your needs!
  • Loop detection: Automatically detects loops in MIDIs (e.g., from Touhou Project)
  • First note detection: Skip unnecessary silence at the start by jumping to the first note!
  • Easy saving: Save with just one function!

Read and write SoundFont2 files

  • Smart trimming: Trim the SoundFont to only include samples used in the MIDI (down to key and velocity!)
  • sf3 conversion: Compress SoundFont2 files to SoundFont3!
  • Easy saving: Also just one function!

Read and write SoundFont3 files

  • Same features as SoundFont2 but with now with Ogg Vorbis compression!
  • Variable compression quality: You choose between file size and quality!
  • Compression preserving: Avoid decompressing and recompressing uncompressed samples for minimal quality loss!

Limitations

  • Synth's performance may be suboptimal, especially on mobile devices.

Installation

  1. Clone this repository.
  2. Copy src/spessasynth_lib to your project.
  3. Use the library

Tip

Looking for a Node.js version? Try spessasynth_core!

Web App / Local Edition

The complete GUI for spessasynth_lib, allowing remixing, experimenting, and playing MIDIs in the coolest way possible.

Features

  • Visualization of the played sequence with effects like visual pitch bend and note-on effects
  • Playable keyboard with various sizes (mobile friendly!)
  • Integrated controller for the synthesizer with numerous options
  • Support for lyrics embedded in the file (karaoke feature)
  • Music player mode if you prefer not to use visualizations
  • Mobile-friendly UI (synthesizer performance not optimized for mobile... don't tell anyone!)
  • Multiple language support: English, Polish, Japanese
  • Web MIDI API support (Enables use of actual MIDI devices)
  • WebMidiLink support
  • Edit instruments, controllers, and more!
  • Render the MIDI file (modified or unmodified) to .wav
  • Render each channel as a separate .wav file
  • Export the modified MIDI file to .mid
  • Export the trimmed SoundFont to .sf2 or compressed .sf3
  • Bundle both as .rmi!
  • Comes bundled with a compressed SGM SoundFont to get you started
  • No additional dependencies!

Still not convinced? Check out these screenshots:

Screenshot 1 Screenshot 2 Screenshot 3 Screenshot 4

Installation

Important

Firefox is recommended for large SoundFonts due to memory constraints. A decent computer is also recommended for handling large SoundFonts.

Recommended high-quality SoundFont (better than the built-in one)

Requires Node.js

Windows

  1. Download the code as a ZIP file and extract, or use git clone https://github.com/spessasus/SpessaSynth.
  2. Put your SoundFonts into the soundfonts folder (you can select SoundFonts in the program).
  3. Double-click start.bat.
  4. Enjoy!

Linux

  1. Clone the repository:
    git clone https://github.com/spessasus/SpessaSynth
    cd SpessaSynth
    npm start
  2. Put your SoundFonts into the soundfonts folder (you can select SoundFonts in the program).
  3. Enjoy!

If you would like to help translate SpessaSynth, please read this guide (and thank you!)

If you like this project, consider giving it a star. It really helps out!

TODO

  • Improve the performance of the worklet system
  • Potentially port the worklet system to Emscripten
  • Enhance the built-in chorus and reverb effects (suggestions welcome!)
  • Fix issues with release during attack

Special Thanks

  • FluidSynth - for the source code that helped implement functionality and fixes
  • Polyphone - for the soundfont testing and editing tool
  • Meltysynth - for the initial low-pass filter implementation
  • RecordingBlogs - for detailed explanations on MIDI messages
  • stbvorbis.js - for the Vorbis decoder
  • OggVorbisEncoder - for the MIT Vorbis encoder
  • And You! - for checking out this project. I hope you like it :)

Major Releases

  • 0.0.1 - Initial release
  • 1.0.0 - Removed the 2-sample limit
  • 2.0.0 - Implemented the worklet system and added support for modulators
  • 3.0.0 - Moved to audioWorkletGlobalScope for offline audio rendering

License

Copyright © 2024 Spessasus. Licensed under the MIT License.

Important

Please note that the bundled stbvorbis_sync.js is licensed under the Apache-2.0 license.