wasgen v0.18.4
wasgen
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 findwafxrmore useful than this library.
Usage:
Install as a dependency:
npm install --save wasgenInstantiate 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
Program Format
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
Recent updates
0.18.0Fixesbitcrusherand addstanhdistortion0.17.0Supports playing into OfflineAudioContext0.16.0simplifies program format, and many internals0.12.0adds bit-crushing, bug fixes0.10.0- adds waveshaper distortion effects
- rewrites most documentation
- renamed from
soundgen
By
Made with 🍺 by Andy Hall.
License is ISC.
Inspired by (and demo preset programs converted from) TinySynth