audiolib.js is a powerful toolkit for audio written in JS.
It ships with most of the common tools such as:
In addition, it hosts these tools in a comprehensive framework, that makes it simple to write a single effect and provides the higher level abstraction on top of that, making the whole system comfortable for both users and plugin authors.
As for the higher level abstraction, audiolib.js features a sophisticated automation API, alongside with pre-processing hooks, sample level access and buffer level management.
audiolib.js is bundled with some tools to make an audio developer's life in a browser much easier, such as sink.js for a consistent API between the experimental browser audio APIs. To complement that, audiolib.js also bundles pcmdata.js that is a WAV encoder/decoder, so that you can turn the recordings you make using Sink.js into WAV files that the user can save. Other tools include the AudioWorker API that allows you to create web workers from strings or functions, bundling audiolib.js and its plugins, all ready to use from the worker.
audiolib.js is available both in browser and CLI environments.
To install via npm:
$ npm install audiolib
Please note that you'll need grunt for this to work.
(if you have your own, please fork & add | msg me)
Specifications for plugin developers can be found in https://github.com/jussi-kalliokoski/audiolib.js/tree/master/specs
Licensed under MIT license.
/* Create an output. */var dev = audioLib;/*Note that all the arguments are optional,so if you want to create a write-onlydevice, you can leave the arguments blank.Also, it is highly discouraged to set anyof the arguments if you aren't sure that youneed them. Use null if you need to skiparguments.*//* Writing buffers: */dev;/*You can also attach multiple listenersto the same Sink instance.*/dev;/* Effects */var del = audioLib;var flt = audioLib;var flt = audioLib;var flt = audioLib;var dist = audioLib;/* to feed a new input sample */effect;/* to get the output */sample = effect;/* Synthesis */var osc = audioLib;/* to generate a new sample */osc;/* to get the output */osc;/* Sampler */var sampler = audioLib;/* Envelopes */var adsr = audioLib;/* to trigger the gate */adsr;/* to update the value ** Do this on every sample fetch for this to work properly. */adsr;/* Get the value */adsrvalue; // 0.0 - 1.0, unless you put something more as sustainvar stepSeq = sampleRate stepLength stepArray attack;/* To start the sequence over */stepSeq;/* to update the value ** Do this on every sample fetch for this to work properly. */stepSeq;/* Get the value */stepSeqvalue; // 0.0 - 1.0/* Recording */var rec = dev;/* To stop */rec;// To export wavvar audioElement ='data:audio/wav;base64,' +// presuming btoa is supported;/* Resampling buffers */audioLibSampler;/*If you are used to buffer based approach (for example DSP.js)and don't need to do any raw manipulation, all the effectscan be used as buffer based too.*/var bufFx = audioLibDelay/* or any effect */;bufFx;
var worker = audioLib;/* Injection */worker;/* Close the worker */worker;
It's important to remember that even though that code looks like it's running in the same environment as the code it's written in, it's actually not and runs in the context of the worker, meaning you can't cross-reference variables. Also, the injections are sandboxed, so if you need to create a global variable, drop var.