• Stars
    star
    233
  • Rank 172,230 (Top 4 %)
  • Language
    JavaScript
  • License
    zlib License
  • Created over 10 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Small JavaScript synthesizer library

Sonant-X

Build Status npm

A very small JavaScript synthesizer library, suitable for small JavaScript demos or video games.

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.

Example

Just test one of the available songs for Sonant-X Live, like this one: Synth 4k by m / Bits'n'Bites.

Installation

npm install --save sonantx

Usage

Song Generation

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 generateSong() function:

import * as sonantx from 'sonantx'
import mySong from './mySong.json'

const audioCtx = new AudioContext()

sonantx.generateSong(mySong, audioCtx.sampleRate).then((audioBuffer) => {
  const audioBufferSource = audioCtx.createBufferSource()
  audioBufferSource.buffer = audioBuffer
  audioBufferSource.connect(audioCtx.destination)
  audioBufferSource.start()
})

The 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 generateSound() function:

import * as sonantx from 'sonantx'
import myInstrument from './myInstrument.json'

const audioCtx = new AudioContext()

const midiNote = 67
const bpm = 120

sonantx.generateSound(myInstrument, midiNote, audioCtx.sampleRate, bpm).then((audioBuffer) => {
  const audioBufferSource = audioCtx.createBufferSource()
  audioBufferSource.buffer = audioBuffer
  audioBufferSource.connect(audioCtx.destination)
  audioBufferSource.start()
})

Single sound generation can be very fast but sounds can still be generated ahead of time if precise timing is very important for you.

More Repositories

1

bootstrap-4-github-pages

A Bootstrap 4 template project for Github Pages and Jekyll
SCSS
249
star
2

ring.js

Ring.js - JavaScript Class System with Multiple Inheritance
JavaScript
221
star
3

modern-async

A modern JavaScript tooling library for asynchronous operations using async/await, promises and async generators
JavaScript
195
star
4

multirun

A minimalist init process designed for Docker
C
171
star
5

pygreen

A micro web framework/static web site generator.
Python
167
star
6

easy-markdown-to-github-pages

Convert Markdown files in Github to a full website using Github Pages
103
star
7

sonant-x-live

Tracker web application to compose music in a brower
JavaScript
90
star
8

jiko

Full Featured Template Engine for JavaScript
JavaScript
71
star
9

rust-cross-compile-example

A working example of multi targets compilation for Rust using Github Actions. Supports Windows, MacOSX, x86_64, ARM and Raspberry PI Linux.
Rust
58
star
10

wordpress-simple-bootstrap

A clean base theme to use Twitter Boostrap 4 with Wordpress
PHP
57
star
11

steelseries

A collection of gauge components for JavaScript.
JavaScript
29
star
12

docker-compose-wait

Some useful script to wait until all services declared in a docker-compose file are up and running.
Python
29
star
13

parcel-github-pages-boilerplate

A Parcel boilerplate to deploy on Github Pages using Github Actions.
SCSS
23
star
14

widget.js

A lightweight JavaScript component framework
JavaScript
16
star
15

bisync

A bidirectional folder synchronizer with distributed history.
Python
12
star
16

egm96-universal

A JavaScript library to convert between EGM96-relative altitudes and WGS84 ellipsoid-relative altitudes
Fortran
10
star
17

win-cmd-escaper

A Python library to properly handle escaping of command line arguments in Windows' CMD.exe and Powershell.
Python
9
star
18

lightningmf

Lightning MAME Frontend
Python
9
star
19

mailflash

A simple python library to send emails.
Python
9
star
20

snoweffect

A snow effect made with three.js
JavaScript
8
star
21

nicolas-van.github.io

My personal blog
SCSS
8
star
22

parcel-pwa

A minimalistic PWA made with Parcel
HTML
6
star
23

react-bootstrap-confirmation

A library to easily display alerts and confirmations using React and Bootstrap
JavaScript
6
star
24

install-chrome-dialog

A simple javascript script to display an "install chrome" dialog in old browsers
JavaScript
5
star
25

sw_stats

A Savage Worlds success rate calculator
CSS
4
star
26

github-actions-multiarch-docker-image-build

An example Github Actions configuration to build a Docker image for multiple architectures.
JavaScript
4
star
27

sai-synth

An experimental subtractive synthesizer using the Web Audio API
JavaScript
4
star
28

letsencrypt-renew

A small guide to install letsencrypt certificates with autorenew
Shell
3
star
29

loadingquest

Loading Quest
JavaScript
3
star
30

simple-duration

A JavaScript library to convert seconds to strings and back using a human readable format
JavaScript
3
star
31

ibook-generator

parser to generate interactive books
Python
1
star
32

js-console

A collection of librairies on a web page to make tests using your browser console
HTML
1
star
33

protocms

A starter cms in Python
JavaScript
1
star
34

pi-expander

A small script to turn a Raspberry pi into a MIDI expander
Shell
1
star
35

oxonet

A tic-tac-toe made with Socket.io
CSS
1
star
36

dictionaryjs

DictionaryJS, a javascript library to define dictionaries that can be indexed using any data type.
JavaScript
1
star
37

php-nginx-docker

A php-fpm + nginx combination for both debian and alpine.
PHP
1
star
38

boostcstream

character stream helpers for boost
C++
1
star
39

test-pygame

A test of pygame
Python
1
star
40

nbf

nobrainfuck
Python
1
star
41

3dphotogallery

A 3D photo gallery made with three.js
JavaScript
1
star
42

jsgame

Some test video game in JavaScript
JavaScript
1
star
43

cesium-cartographic

Math helper extensions for cartographic calculation in Cesium.js
JavaScript
1
star