Music Notation Sounds library
Canonical version: Music Notation Sounds library.
The instrument sounds of my Music Notation library, as one small soundfont (a file of recorded instrument samples) per instrument. I cut them from GeneralUser GS, a soundfont by S. Christian Collins.
The package is @dsebastien/music-notation-sounds.
Why I built it
A page should load only the instruments it plays. The whole GeneralUser GS bank weighs 30.82 MB. Cut into pieces, a steel-string guitar is 112 KB, a grand piano 392 KB, and the median instrument 84 KB. The index that points to them is 3 KB.
I picked GeneralUser GS after a listening test: it sounded better than sonivox, the small bank that ships with alphaTab.
What's in it
p000.sf3top127.sf3: one soundfont per General MIDI program (General MIDI is the standard numbered list of instruments).drums.sf3: the standard drum kit.click.sf3: the kit's metronome click alone, so a score without drums doesn't load the whole kit.index.json(3 KB): each program's file. This is what players read.report.json: sizes, loudness and gains, for people.
How it's made
A script in the library's repository, scripts/sounds/split-soundfont.ts, cuts the bank (it needs FFmpeg). It compresses each sample to Ogg Vorbis, which makes the files SoundFont 3 (hence .sf3).
Each compressed sample is played alone in alphaTab and compared with its uncompressed form. The script raises the quality until the two sound the same, and a sample that never does stays uncompressed. So every sample that ships plays in alphaTab.
Each compressed sample also gets a short tail after its end, so a held note loops cleanly in browsers that decode Ogg Vorbis a little short, such as Chrome.
Each file also carries a gain, so every instrument plays at about the same loudness (-21 dBFS on a test phrase). The gain is capped so a strummed six-note chord stays under full scale.
How it's used
Apps pass the files to the library as bytes. For Node.js, Bun and Electron, the package has a reader:
import { generaluser } from '@dsebastien/music-notation-sounds/node'
Then assets: { instruments: generaluser } goes in the library's options.
Web pages name their own folder:
window.musicNotationOptions = { play: { instruments: '<folder URL>' } }
The library has no built-in address for the sounds. That's my choice: I don't want it to depend on a CDN (a third-party server that hosts the files). Without a folder, the soundfont that ships with alphaTab plays. With nothing at all, the library's small built-in synthesizer does.
On a page of chord diagrams with no tab, a sample player in the library plays these files without loading alphaTab (about 1 MB of script). A chord reads the index and one guitar.
The library's guide plays these sounds on every page: it names the package's generaluser folder on jsDelivr, pinned to a version. Its Sounds page plays the same music with each sound, side by side, so you can hear what you pick: https://dsebastien.github.io/music-notation/sounds.html
A page or a block can choose the engine: generaluser (these files), sonivox (alphaTab's bank) or light (the built-in synthesizer). A page sets it with play: { engine }, a block with an engine: line. When the engine isn't there, the next one plays, so nothing goes silent.
The four guitars of the library are four of these files: the steel-string acoustic (p025.sf3), the nylon-string classical guitar (p024.sf3), the clean electric (p027.sf3) and the overdriven electric (p029.sf3). Each one is read at its first use, so a page that plays only nylon never reads the steel-string file.
My Publish site uses them too: its publish.js names the package's generaluser folder on jsDelivr.
The Music Practice plugin offers them as its sound pack: Settings → Playback → Sound pack downloads the whole folder (14.9 MB) from jsDelivr into the plugin's own folder, and checks each file against the size and hash that ship with the plugin. Nothing is downloaded until you click Download; without the pack, the plugin plays its built-in soundfont.
License
The sound files are under the GeneralUser GS license v2.0. It allows use in software projects and changes to the bank. Its author also says they can't be 100% sure where every sample came from, which matters for a commercial product.
The code and packaging (node.js, package.json, the README) are under the MIT License.
Status
On npm, and the repository is public. The package has its own guide: https://dsebastien.github.io/music-notation-sounds/
The sounds are not checked on Safari and phones yet.
What changed in each release is in the repository: https://github.com/dsebastien/music-notation-sounds
References
- GeneralUser GS, by S. Christian Collins: https://github.com/mrbumpy409/GeneralUser-GS
- Guide: https://dsebastien.github.io/music-notation-sounds/
- Source code: https://github.com/dsebastien/music-notation-sounds
- npm: https://www.npmjs.com/package/@dsebastien/music-notation-sounds
Related
- Music Notation library
- Music Practice plugin for Obsidian
- GeneralUser GS
- S. Christian Collins
- AlphaTab
- Guitar (MoC)
- Piano (MoC)
About Sébastien
Ready to get to the next level?
Found this valuable? Share it with someone who needs it.