lbmrn-pcm-utils
Version:
PCM audio utilities for Node.js
61 lines (51 loc) • 1.92 kB
JavaScript
// Generated by CoffeeScript 1.11.1
var Unzipper, binding, pcm, stream,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
binding = require('../build/Release/binding');
stream = require('stream');
pcm = require('./constants');
Unzipper = (function(superClass) {
extend(Unzipper, superClass);
function Unzipper(channels, format) {
var i, ref;
this.channels = channels != null ? channels : 2;
this.format = format != null ? format : pcm.FMT_F32LE;
stream.Writable.call(this);
this.alignment = pcm.ALIGNMENTS[this.format];
this.unzipper = new binding.Unzipper(this.channels, this.alignment);
this.outputs = (function() {
var j, ref, results;
results = [];
for (i = j = 0, ref = this.channels; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
results.push(new stream.PassThrough);
}
return results;
}).call(this);
if (this.channels === 1) {
this.mono = this.outputs[0];
}
if (this.channels === 2) {
ref = [this.outputs[0], this.outputs[1]], this.left = ref[0], this.right = ref[1];
}
}
Unzipper.prototype._write = function(chunk, encoding, callback) {
return this.unzipper.unzip(chunk, (function(_this) {
return function(err, chunks, done) {
var i, j, len;
if (err != null) {
throw err;
}
for (i = j = 0, len = chunks.length; j < len; i = ++j) {
chunk = chunks[i];
_this.outputs[i].write(chunk);
}
if (done) {
return callback();
}
};
})(this));
};
return Unzipper;
})(stream.Writable);
module.exports = Unzipper;