Giter VIP home page Giter VIP logo

sonant-x's Introduction

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.

sonant-x's People

Contributors

dependabot[bot] avatar mbitsnbites avatar nicolas-van avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.