Implementation of a bit-crush effect using the Web Audio API.
Browserify is recommended; alternatively you can grab a UMD module from the build
directory. If using npm
:
$ npm install bitcrusher
var bitcrusher = require('bitcrusher');
var audioContext = window.createAudioContext();
var bitcrushNode = bitcrush(audioContext, {
bitDepth: 6,
frequency: 0.5
});
var mySource = // ... create audio source
mySource.connect(bitcrushNode);
bitcrushNode.connect(audioContext.destination);
Create a new bitcrusher in the Web Audio Context audioContext
configured with the supplied options:
bufferSize
: defaults to 4096channelCount
: defaults to 2bitDepth
: output resolution, defaults to 8frequency
: sample-and-hold ratio; used to reduce the perceived output frequency. Defaults to 1 (no change).
Returns a ScriptProcessorNode
configured with a bitcrush effect.
If you're running OS X, open graph.gcx
in Grapher.app
to visualise the algorithm.
bitDepth
and frequency
options would ideally instances of AudioParam
. Unfortunately the Web Audio API does not yet allow standalone instances to be created.