Declarative low-level Web Audio Sound Generator.
You pass in a static object, which defines an arbitrarily complex audio graph and its parameters. This library will then construct all the nodes, connect everything, apply the necessary parameters and envelopes, and clean up afterwards.
Live demo open that and hit keys to play sounds.
NOTE! Are you reasonably familiar with terms like "FM synthesis" and "ADSR envelope"? If not, you may find
wafxr
more useful than this library.
Install as a dependency:
npm install --save wasgen
Instantiate and invoke:
var Generator = require('wasgen')
var ctx = new AudioContext()
var gen = new Generator(ctx, ctx.destination) // both args optional
var program = { type:'sine' } // see below
var freq = 440 // in Hz
var velocity = 1 // 0..1
// fixed-duration sounds:
var startTime = gen.now() + 0.1
var releaseTime = startTime + 1
gen.play(program, freq, velocity, startTime, releaseTime)
// dynamic sounds:
var noteID = gen.play(program, freq, velocity, startTime)
setInterval(() => {
gen.release(noteID) // sound's release envelope starts when this is called
}, 1000)
And so on. See source for other APIs
Sound programs for wasgen
use an ad-hoc format that's
easy to read but hard to describe. You may find it easiest to
open the demo page and
browse the examples to get the general idea.
For the full details:
Program format spec
0.18.0
Fixes bitcrusher
and adds tanh
distortion0.17.0
Supports playing into OfflineAudioContext0.16.0
simplifies program format, and many internals0.12.0
adds bit-crushing, bug fixes0.10.0
soundgen
Made with by Andy Hall.
License is ISC.
Inspired by (and demo preset programs converted from) TinySynth