Comparing version 0.2.6 to 0.2.7
@@ -9,3 +9,3 @@ | ||
var Decoder = function( rate, channels, frameSize ) { | ||
Transform.call( this, { readableObjectMode: true } ); | ||
Transform.call( this, { writableObjectMode: true } ); | ||
@@ -12,0 +12,0 @@ this.rate = rate || 48000; |
@@ -31,2 +31,3 @@ | ||
this.pos = 0; | ||
this.granulepos = 0; | ||
this.samplesWritten = 0; | ||
@@ -41,7 +42,2 @@ }; | ||
// Write the header if it hasn't been written yet | ||
if( !this.headerWritten ) { | ||
this._writeHeader(); | ||
} | ||
// Transform the buffer | ||
@@ -77,7 +73,6 @@ this._processOutput( buf ); | ||
packet.e_o_s = 0; | ||
packet.granulepos = 0; | ||
packet.granulepos = -1; | ||
packet.packetno = this.pos++; | ||
this.push( packet ); | ||
this.samplesWritten += header.length; | ||
@@ -101,3 +96,3 @@ // OpusTags packet | ||
packet.e_o_s = 0; | ||
packet.granulepos = this.samplesWritten; | ||
packet.granulepos = -1; | ||
packet.packetno = this.pos++; | ||
@@ -155,3 +150,12 @@ packet.flush = true; | ||
Encoder.prototype._flushFrame = function( frame, end ) { | ||
var encoded = this.encoder.encode( frame ); | ||
this._pushEncodedBuffer(encoded, end); | ||
}; | ||
Encoder.prototype._pushEncodedBuffer = function( encoded, end ) { | ||
// Write the header if it hasn't been written yet | ||
if( !this.headerWritten ) { | ||
this._writeHeader(); | ||
} | ||
if( this.lastPacket ) { | ||
@@ -161,4 +165,6 @@ this.push( this.lastPacket ); | ||
var encoded = this.encoder.encode( frame ); | ||
// Scale the frame size into 48 kHz bitrate, which is used for the | ||
// granule positioning. We'll still update the samplesWritten just to | ||
// ensure backwards compatibility. | ||
this.granulepos += this.frameSize / this.rate * 48000; | ||
this.samplesWritten += this.frameSize; | ||
@@ -171,5 +177,5 @@ | ||
packet.e_o_s = 0; | ||
packet.granulepos = this.samplesWritten; | ||
packet.granulepos = this.granulepos; | ||
packet.packetno = this.pos++; | ||
packet.flush = true; | ||
packet.flush = true; | ||
@@ -176,0 +182,0 @@ this.lastPacket = packet; |
{ | ||
"name": "node-opus", | ||
"description": "NodeJS native binding to OPUS", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"author": "Mikko Rantanen <jubjub@jubjubnest.net>", | ||
@@ -9,2 +9,5 @@ "homepage": "https://github.com/Rantanen/node-opus", | ||
"license": "MIT", | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"repository": { | ||
@@ -31,2 +34,3 @@ "type": "git", | ||
"bindings": "~1.2.1", | ||
"commander": "^2.9.0", | ||
"nan": "^2.3.2" | ||
@@ -36,3 +40,9 @@ }, | ||
"ogg-packet": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"mocha": "^3.3.0", | ||
"ogg": "^1.2.5", | ||
"stream-equal": "^1.0.0" | ||
} | ||
} |
7677580
444
2147
4
4
7
+ Addedcommander@^2.9.0
+ Addedcommander@2.20.3(transitive)