lib/encoder.js
function Encoder (opts) {
  if (!(this instanceof Encoder)) {
    return new Encoder(opts);
  }
  Transform.call(this, opts);

  // lame malloc()s the "gfp" buffer
  this.gfp = binding.lame_init();

  // set default options
  if (!opts) opts = {};
  if (null == opts.channels) opts.channels = 2;
  if (null == opts.bitDepth) opts.bitDepth = 16;
  if (null == opts.sampleRate) opts.sampleRate = 44100;
  if (null == opts.signed) opts.signed = opts.bitDepth != 8;

  if (opts.float && opts.bitDepth == DOUBLE_BITS) {
    this.inputType = PCM_TYPE_DOUBLE;
  } else if (opts.float && opts.bitDepth == FLOAT_BITS) {
    this.inputType = PCM_TYPE_FLOAT;
  } else if (!opts.float && opts.bitDepth == SHORT_BITS) {
    this.inputType = PCM_TYPE_SHORT_INT;
  } else {
    throw new Error('unsupported PCM format!');
  }

  // copy over opts to the encoder instance
  Object.keys(opts).forEach(function(key){
    if (key[0] != '_' && Encoder.prototype.hasOwnProperty(key)) {
      debug('setting opt %j', key);
      this[key] = opts[key];
    }
  }, this);
}
function Encoder (opts) {
  if (!(this instanceof Encoder)) {
    return new Encoder(opts);
  }
  Transform.call(this, opts);

  // lame malloc()s the "gfp" buffer
  this.gfp = binding.lame_init();

  // set default options
  if (!opts) opts = {};
  if (null == opts.channels) opts.channels = 2;
  if (null == opts.bitDepth) opts.bitDepth = 16;
  if (null == opts.sampleRate) opts.sampleRate = 44100;
  if (null == opts.signed) opts.signed = opts.bitDepth != 8;

  if (opts.float && opts.bitDepth == DOUBLE_BITS) {
    this.inputType = PCM_TYPE_DOUBLE;
  } else if (opts.float && opts.bitDepth == FLOAT_BITS) {
    this.inputType = PCM_TYPE_FLOAT;
  } else if (!opts.float && opts.bitDepth == SHORT_BITS) {
    this.inputType = PCM_TYPE_SHORT_INT;
  } else {
    throw new Error('unsupported PCM format!');
  }

  // copy over opts to the encoder instance
  Object.keys(opts).forEach(function(key){
    if (key[0] != '_' && Encoder.prototype.hasOwnProperty(key)) {
      debug('setting opt %j', key);
      this[key] = opts[key];
    }
  }, this);
}
function Encoder ( opts ) { if ( ! ( this instanceof Encoder ) ) { return new Encoder ( opts ) ; } Transform . call ( this , opts ) ; // lame malloc()s the "gfp" buffer this . gfp = binding . lame_init ( ) ; // set default options if ( ! opts ) opts = { } ; if ( null == opts . channels ) opts . channels = 2 ; if ( null == opts . bitDepth ) opts . bitDepth = 16 ; if ( null == opts . sampleRate ) opts . sampleRate = 44100 ; if ( null == opts . signed ) opts . signed = opts . bitDepth != 8 ; if ( opts . float && opts . bitDepth == DOUBLE_BITS ) { this . inputType = PCM_TYPE_DOUBLE ; } else if ( opts . float && opts . bitDepth == FLOAT_BITS ) { this . inputType = PCM_TYPE_FLOAT ; } else if ( ! opts . float && opts . bitDepth == SHORT_BITS ) { this . inputType = PCM_TYPE_SHORT_INT ; } else { throw new Error ( 'unsupported PCM format!' ) ; } // copy over opts to the encoder instance Object . keys ( opts ) . forEach ( function ( key ) { if ( key [ 0 ] != '_' && Encoder . prototype . hasOwnProperty ( key ) ) { debug ( 'setting opt %j' , key ) ; this [ key ] = opts [ key ] ; } } , this ) ; }
The `Encoder` class is a Transform stream class.
Write raw PCM data, out comes an MP3 file.

@param {Object} opts PCM stream format info and stream options
@api public
The Encoder class is a Transform stream class . Write raw PCM data out comes an MP3 file .