Sonant-X was created with video games' sound effects and music in mind, as well as size-restrained demos. It uses the Web Audio API.
Songs for Sonant-X can be composed using Sonant-X Live.
Sonant-X is a fork of js-sonant by Marcus Geelnard.
Just test one of the available songs for Sonant-X Live, like this one: Synth 4k by m / Bits'n'Bites.
npm install --save sonantx
To generate a whole song, you'll first need a song in JSON format generated by Sonant-X Live. An example can be found by clicking here and choosing "Export JSON" in the menu on the left.
With that JSON song, we will be able to use the
const audioCtx =sonantx
generateSong() function can take multiple seconds before returning, depending on the length of your song. It is recommended to initialize your music at the startup of the application and keep a reference to the audio buffer.
Single sounds generation
To generate single sound (suitable for video games sound effects) you'll first need an instrument description in JSON format generated by Sonant-X Live. To get an example one, you can click here then choose one of the tracks of the sample song and click on the "Export" button on the top right of the application. You will then get a JSON description of the instrument used for the selected track.
With that instrument, we will be able to use the
const audioCtx =const midiNote = 67const bpm = 120sonantx
Single sound generation can be very fast but sounds can still be generated ahead of time if precise timing is very important for you.