• Stars
    star
    670
  • Rank 64,899 (Top 2 %)
  • Language
    JavaScript
  • Created over 13 years ago
  • Updated over 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

audiolib.js is a powerful audio tools library for javascript.

audiolib.js

Overview

audiolib.js is a powerful toolkit for audio written in JS.

It ships with most of the common tools such as:

  • Reverbs
  • Comb/IIR/Biquad/All-Pass/Low-Pass/Band-Pass/High-Pass filters
  • Delays
  • Oscillators
  • FFT and other analyzing tools
  • Step sequencers
  • Envelope controls
  • Noise generators
  • Samplers

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.

How to get it

audiolib.js is available both in browser and CLI environments.

Node

To install via npm:

$ npm install audiolib

Please note that you'll need grunt for this to work.

Browser

For browser environments, download the latest version here, or get the source code from GitHub and build it yourself. Don't worry, instructions are included.

Documentation

Documentation is available at http://docs.audiolibjs.org/ . Tutorials can be found in the wiki

Demos

(if you have your own, please fork & add | msg me)

Libraries bundled with audiolib.js

  • sink.js, for output and buffer handling.
  • PCMData.js, for WAV codecs. (project deprecated and adopted)
  • binary.js, for PCMData.js and general binary data processing. (project deprecated and adopted)
  • fft.js, for super fast FT. (project deprecated and adopted)

Related libraries

  • XAudioJS is an alternative audio sink with built-in resampling and a Flash fallback. More developer-controlled output environment, that might be more sane for example games.
  • dynamicaudio.js is a Flash fallback for Mozilla Audio Data API.
  • Audiolet is a graph-based audio routing framework with a lot of nice stuff.
  • DSP.js is an extensive DSP toolkit originally designed for the Mozilla Audio Data API.

Plugins

Specifications for plugin developers can be found in https://github.com/jussi-kalliokoski/audiolib.js/tree/master/specs

Credits

This project is maintained by Jussi Kalliokoski, with significant contributions from David Govea.

License

Licensed under MIT license.

Example usage

/* Create an output. */

var dev = audioLib.Sink(function(sampleBuffer){
	// Fill the buffer here.
}, channelCount, preBufferSize, sampleRate);

/*
 Note that all the arguments are optional,
 so if you want to create a write-only
 device, you can leave the arguments blank.
 Also, it is highly discouraged to set any
 of the arguments if you aren't sure that you
 need them. Use null if you need to skip
 arguments.
*/

/* Writing buffers: */
dev.writeBuffer(buffer);

/*
 You can also attach multiple listeners
 to the same Sink instance.
*/
dev.on('audioprocess', function(...){});


/* Effects */

var del = audioLib.Delay(sampleRate, delay, feedback);

var flt = audioLib.IIRFilter(sampleRate, cutoffFreq, resonance);

var flt = audioLib.LP12Filter(sampleRate, cutoffFreq, resonance);

var flt = audioLib.Reverb(sampleRate, channelCount, wet, dry, roomSize, damping);

var dist = audioLib.BiquadFilter(sampleRate, b0, b1, b2, a1, a2);

/* to feed a new input sample */
effect.pushSample(sample);
/* to get the output */
sample = effect.getMix();

/* Synthesis */

var osc = audioLib.Oscillator(sampleRate, frequency);

/* to generate a new sample */
osc.generate();
/* to get the output */
osc.getMix();

/* Sampler */

var sampler = audioLib.Sampler(sampleRate, sampleBuffer, defaultPitch);

/* Envelopes */

var adsr = audioLib.ADSREnvelope(sampleRate, attack, decay, sustain, release);

/* to trigger the gate */
adsr.triggerGate(isOpen);
/* to update the value ** Do this on every sample fetch for this to work properly. */
adsr.generate();
/* Get the value */
adsr.value; // 0.0 - 1.0, unless you put something more as sustain

var stepSeq = new audioLib.StepSequencer(sampleRate, stepLength, stepArray, attack);

/* To start the sequence over */
stepSeq.triggerGate();
/* to update the value ** Do this on every sample fetch for this to work properly. */
stepSeq.generate();
/* Get the value */
stepSeq.value; // 0.0 - 1.0

/* Recording */

var rec = dev.record();

/* To stop */
rec.stop();
// To export wav
var audioElement = new Audio(
	'data:audio/wav;base64,' +
	btoa( rec.toWav() ) // presuming btoa is supported
);

/* Resampling buffers */
audioLib.Sampler.resample(buffer, fromSampleRate,
	fromFrequency, toSampleRate, toFrequency);

/*
 If you are used to buffer based approach (for example DSP.js)
 and don't need to do any raw manipulation, all the effects
 can be used as buffer based too.
*/

var bufFx = audioLib.Delay/* or any effect */.createBufferBased(
	channelCount, /* the parameters needed by the specific effect */);

bufFx.append(buffer);

Audio Workers

You can also use audiolib.js inside Audio Workers (Firefox 6.0+ only), but this is a whole another story. There are many approaches to that, you can include audiolib.js via an external javascript worker file, but audiolib.js offers an alternative approach to this: inline workers. Inline audio workers include the source code already downloaded, and thus creates a new worker that already contains audiolib.js. Inline Audio Workers also allow you to inject code into workers. Here is some code to get started, also see tests/audioworker.html.

var worker = audioLib.AudioWorker(function(){
	device = audioLib.Sink(function(buffer, channelCount){
		/* Do some audio processing, like you weren't in a worker. */
	});
}, true /* enables injections */);

/* Injection */

worker.inject(function(){
	/* Execute some code inside the worker. */
});

/* Close the worker */

worker.terminate();

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.

More Repositories

1

trine

A utility library for modern JavaScript.
JavaScript
1,416
star
2

html5Preloader.js

A javascript library to preload all kinds of content, be it text, xml, audio, video or image, with simple syntax.
JavaScript
228
star
3

sink.js

A javascript library for audio output
JavaScript
200
star
4

react-no-jsx

A pure JS alternative to JSX
JavaScript
69
star
5

babel-plugin-operator-overload

Babel plugin for overloading operators
JavaScript
67
star
6

pcmdata.js

A javascript library to read / write .wav pcm data files
JavaScript
42
star
7

node-dsp

An implementation of the DSP API
CoffeeScript
38
star
8

binary.js

Provides a very fast and robust interface for binary conversions in JavaScript
JavaScript
33
star
9

gulp-awspublish-router

A router for defining file-specific rules with gulp-awspublish
JavaScript
29
star
10

htmlentities.js

A minimal html entities decoder/encoder using DOM.
JavaScript
26
star
11

jQuery.grab

A port of Jin's grab gesture.
JavaScript
21
star
12

node-progress-bar

An STDOUT progress bar for NodeJS
JavaScript
20
star
13

merry-go-round

Merry-go-Round is a React-based component library for building amazing carousels!
JavaScript
19
star
14

polyfill-service-webpack

A webpack plugin for polyfill.io.
JavaScript
18
star
15

eslint-plugin-no-implicit-side-effects

ESLint plugin for requiring side effects to be explicit.
JavaScript
18
star
16

BrainScript

BrainScript is a scripting language that is a subset of JavaScript and inspired by Urban Müller's brainfuck.
18
star
17

gulp-spa

Define your build sources in HTML.
JavaScript
16
star
18

mike.js

JavaScript
14
star
19

web-midi-test-suite

A test suite for Web MIDI API
JavaScript
14
star
20

fft.js

A Fast Fourier Transform in JavaScript
JavaScript
13
star
21

node-cubeb

Node module for libcubeb
C++
13
star
22

vectorizer.js

A JS library for raster->vector
JavaScript
13
star
23

weakbind

Memoized bind for higher performance.
JavaScript
10
star
24

slogdriver

Stackdriver Logging / GCP Cloud Logging handler for the go 1.21 slog package.
Go
10
star
25

react-mistyped-props

Warnings for mistyped props in your React components.
JavaScript
10
star
26

simplesynth

A simple synth example for Firefox 4 Audio API
JavaScript
9
star
27

atom-npm-plus

npm integration for atom
JavaScript
8
star
28

src.js

Sample Rate Conversion for JS
JavaScript
7
star
29

btoa-atob

Command line utility to convert files to base64 and vice versa.
JavaScript
7
star
30

http.js

A HTTP utilities library for client-side applications.
JavaScript
5
star
31

macnjs

C Preprocessor for JS (or anything, really)
C
5
star
32

kakku

A backend agnostic cache layer for node.js
JavaScript
5
star
33

jin.js

A lightweight javascript library / framework
JavaScript
5
star
34

virtual-midi-keyboard

A virtual HTML5 MIDI keyboard
JavaScript
5
star
35

canvas-history.js

Binds an easy undo/redo API to Canvas 2D Drawing Context.
JavaScript
5
star
36

node-blessings

node.js port of python's blessings
JavaScript
5
star
37

asifier

JavaScript
4
star
38

dotfiles

My workflow, probably nothing you'd care about.
Vim Script
4
star
39

midinode

A NodeJS module providing cross-platform JS bindings for MIDI device control.
C++
4
star
40

grunt-pack

Packaging tasks for Grunt
JavaScript
4
star
41

setImmediate.js

A small shim for the setImmediate() that creates a callback similar to process.nextTick() on node.js
JavaScript
4
star
42

sweet-es7-async

A sweet.js macro for ES7 async functions.
JavaScript
4
star
43

par

A go library to perform slice operations (e.g. map, filter, reduce) in parallel.
Go
4
star
44

harmony.vim

Extensive JS syntax support for VIM
Vim Script
3
star
45

Featurizr

A Modernizr extension to spice up your media queries with feature queries
JavaScript
3
star
46

Colourizr

Colourizr is a color conversion tool for web use, especially CSS
JavaScript
3
star
47

Calculatoure

A slick HTML5 calculator, able to handle a multitude of mathematical things.
JavaScript
3
star
48

inceptionscript

Write JS macros in JS
JavaScript
3
star
49

gointerfacefunc

Generate function types for go interfaces for testing
Go
3
star
50

makejs

A javascript-based build tool, similar to make.
C++
2
star
51

restzilla

A RESTful API wrapper for Bugzilla
CoffeeScript
2
star
52

rawcanvas.js

Raw pixel access with WebGL, fallback with 2DContext
JavaScript
2
star
53

script-builder

Makes it easier to manage bigger script projects.
JavaScript
2
star
54

tool-belt.js

Small JS utilities I often use
JavaScript
2
star
55

grunt-fixtures2js

Convert your fixtures into a JS object for use in tests.
JavaScript
2
star
56

paramon

paramon is a tool for parsing command line arguments. Its agenda is to make it nice to make nice command line options.
JavaScript
2
star
57

fonticon-loader

Webpack loader for icons, converting them into iconfonts.
JavaScript
2
star
58

gostringenum

Generate efficient string encodings and decodings for go enums.
Go
2
star
59

mpmc

A go library to manage communications across Multiple Producers and Multiple Consumers.
Go
2
star
60

grunt-doctor.js

A grunt task for doctor.js
CoffeeScript
1
star
61

fixtures2js

The shared library for the gulp and grunt tasks.
JavaScript
1
star
62

oocubeb

ooc port of libcubeb
ooc
1
star
63

advent-of-code-2022

Advent of Code 2022 solutions
1
star
64

Solo.js

An ES6 Promise-based task queue utility.
JavaScript
1
star
65

struct.js

Structs for JS
JavaScript
1
star
66

stupid.js

The Stupid JS Style Guide
1
star
67

orbisyn

JavaScript
1
star
68

express-riak

A Riak session store adapter for Express.
JavaScript
1
star
69

concat-vs-multiplex

A benchmark of HTTP2 push multiplexing vs concatenation/bundling.
JavaScript
1
star
70

helsinkijs-2013-10-17

My slides for my talk at HelsinkiJS 2013-10-17
CoffeeScript
1
star
71

doctor.js

Formatting agnostic documentation
JavaScript
1
star
72

privateEval.js

A javascript library to allow javascript execution in a completely safe and private scope.
JavaScript
1
star
73

chai-gulp-helpers

A simple test helper to verify that your stream returns the expected files.
JavaScript
1
star
74

watch-and-run

A simple tool for running commands when files change.
JavaScript
1
star
75

kakku-redis-store

A Redis Store for Kakku.
JavaScript
1
star
76

go-prettyformat

Stringify go values
Go
1
star
77

through2-sequence

Combine streams into a sequence where input is the first stream and output is the last.
JavaScript
1
star
78

kakku-multi-store

A multi-backend Store for Kakku.
JavaScript
1
star
79

lowlite

A syntax highlighting library for NodeJS
JavaScript
1
star
80

blog

My personal blog
JavaScript
1
star
81

kakku-lru-cache-store

An in-memory LRU cache Store for Kakku
JavaScript
1
star
82

CodeExpression.js

A javascript library to parse a multitude of languages. Use cases include syntax highlighting, minifiers, etc.
JavaScript
1
star
83

gulp-fixtures2js

A gulp plugin for fixtures2js
JavaScript
1
star
84

gulp-resolver

Replace references to source files with references to generated files.
JavaScript
1
star