node-pcm-utils
PCM audio utilities for Node.js
Features
-
Interleaving/deinterleaving - Unzip interleaved PCM data into separate channel streams and vice-versa.
-
Mixing - Mix 2 or more PCM channels into one.
-
Format conversion - Transform a stream from one PCM format to another (ie. float to int).
-
Evented - Doesn't block the main loop, thanks to
uv_queue_work
. -
Streams2 compatible - Everything's just a pipeable stream.
Note: For sample rate conversion, check out resampler. For playback, try speaker or alsa (which also records).
Installation
Install with npm:
$ npm install pcm-utils
or via git:
$ npm install git+https://github.com/xdissent/node-pcm-utils.git
Usage
var pcmUtils = // The following variables represent the defaults for all constructors. channels = 2 // 2 channels (left/right) format = pcmUtilsFMT_F32LE // 32 bit little-endian float // Available formats: No big-endian support yet! // // pcmUtils.FMT_F32LE - 32 bit little-endian float // pcmUtils.FMT_F32BE - 32 bit big-endian float **Not currently supported** // pcmUtils.FMT_S16LE - signed 16 bit little-endian integer // pcmUtils.FMT_S16BE - signed 16 bit big-endian integer **Not currently supported** // pcmUtils.FMT_U16LE - unsigned 16 bit little-endian integer // pcmUtils.FMT_U16BE - unsigned 16 bit big-endian integer **Not currently supported** // Unzipper deinterleaves PCM data into multiple single-channel streams. unzipper = channels format // Zipper interleaves multiple single-channel PCM streams into one. zipper = channels format // Mixer mixes multiple channels into a single channel stream. mixer = channels format // Formatter transforms single-channel PCM data from one format to another, // 32 bit little-endian float to signed 16 bit little-endian integer in this case. formatter = format pcmUtilsFMT_S16LE; // Read interleaved PCM data from stdinprocessstdin; // Unzip (de-interleave) it then zip it right back up to stdoutunzipperleft; // or `unzipper.outputs[0].pipe(zipper.inputs[0]);unzipperright; // or `unzipper.outputs[1].pipe(zipper.inputs[1]);zipper; // Mix left and right channels and pipe mono to stderrunzipperleft; // or `unzipper.outputs[0].pipe(mixer.inputs[0]);unzipperright; // or `unzipper.outputs[1].pipe(mixer.inputs[1]);mixer; // Convert the mono mixer output into signed 16 bit little-endian and write to file.var fs = outFileStream = fs;formatter;mixer;