audio-contour
A 5 stage audio envelope generator. You can see the demo here:
var Contour = var ac = var vca = acvar osc = acosc var env = env envstartenv { oscstartwhen }env { osc }env
This module implements a alpha-juno style envelope generator:
If you want to learn more about envelope generators, read this
There are a lot of envelope generator implementations. Here are the standalone ones I know (there are several audio libraries that implements them):
- https://github.com/mmckegg/adsr
- https://www.npmjs.com/package/adsr-envelope
- https://github.com/itsjoesullivan/envelope-generator
Why choose this library over the others:
- Unlike others, it implements a 5 stage envelope (and can be reduced to a standard ADSR envelope)
- It supports
onstart
andonended
events - Can specify gate duration (for sequencer style)
- It's small (2.5Kb minified)
Why don't choose this library:
- It's very young project, still in development and not battle tested.
- Other libraries are great too!
Installation
Via npm: npm i --save audio-contour
Usage
Create an envelope
To create an envelope use the Contour
function:
var ac = var Contour = var env =
You can pass options to that function:
var env =
or change them on the object before start:
var env = envt1 = 1envt4 = 05
Apply the envelope
To apply the envelope, you have to connect it to something. For example, you can create a vca (voltage controlled amplifier) connecting it to a gain's gain param:
var vca = acenv
Or create a vcf (voltage controlled filter) ocnnecting it to a filter frequency param:
var vcf = acenv
Start and stop the envelope
You can use start
and stop
function to the envelope:
var now = accurrentTimeenvstartnow// suppose your audio source is an oscillatoroscstartnowvar finish = env
The stop
function returns the time when the release phase ended. Can be used to stop the audio sources:
oscstartfinish
Remeber that if duration is not Infinity
, the envelope will stop automatically:
var env = envduration = 1envstart // => it will automatically stop after 1 second
Events
Two events are supported: onstart
and onended
. The onstart
event handler will be trigger at same time as the start
function of the envelope, so it receives a time parameter. The onended
event handler will be called when the envelope effectively stops:
envduration = 1env { oscstartwhen }env { osc }envstart // since duration is not Infinity, both envent handlers will be called
Create a standard ADSR
When t3
is 0, the audio-contour behaves like a normal ADSR envelope.
Additionally, you can use the standard attack
, decay
, sustain
and release
parameters in the constructor to build the envelope:
var env = envt1 // => 0.1 (the attack)envt2 // => 0.2 (the decay)envt3 // => 0envt4 // => 0.5 (the release)
Run tests and examples
To run the tests, clone this repo and: npm install && npm test
.
To run the example you need watchify installed: npm install -g watchify
. Then, move to examples
directory and type: npm install && npm start
License
MIT License