Permalink
Browse files

encoder: make the "quality" be configurable

  • Loading branch information...
1 parent a678a17 commit e400b35714d2b71039be275fbf375a46e421db36 @TooTallNate committed Jan 30, 2013
Showing with 6 additions and 2 deletions.
  1. +6 −2 lib/encoder.js
View
8 lib/encoder.js
@@ -31,6 +31,7 @@ module.exports = Encoder;
function Encoder (opts) {
if (!(this instanceof Encoder)) return new Encoder(opts);
+ if (!opts) opts = {};
Transform.call(this, opts);
// the readable side (the output end) should output regular objects
@@ -42,7 +43,10 @@ function Encoder (opts) {
this._headerWritten = false;
// range from -0.1 to 1.0
- this._quality = 0.6;
+ this.quality = null == opts.quality ? 0.6 : +opts.quality;
+ if (this.quality < -0.1 || this.quality > 1.0) {
+ throw new Error('"quality must be in the range -0.1...1.0, got ' + this.quality);
+ }
// PCM formatting options
this.channels = 2;
@@ -125,7 +129,7 @@ Encoder.prototype._writeHeader = function (output, fn) {
var channels = this.channels;
var sampleRate = this.sampleRate;
// TODO: async maybe?
- r = binding.vorbis_encode_init_vbr(this.vi, channels, sampleRate, this._quality);
+ r = binding.vorbis_encode_init_vbr(this.vi, channels, sampleRate, this.quality);
debug('vorbis_encode_init_vbr() return = %d', r);
if (0 !== r) return fn(new Error(r));

0 comments on commit e400b35

Please sign in to comment.