diff --git a/lib/input.js b/lib/input.js index 458220a..7f0c3d2 100644 --- a/lib/input.js +++ b/lib/input.js @@ -35,6 +35,8 @@ function Input(args) { this.channels = args.channels; this.bitDepth = args.bitDepth; this.sampleRate = args.sampleRate; + + this.getMoreData = null; } util.inherits(Input, Writable); @@ -44,6 +46,13 @@ Input.prototype.read = function (samples) { if (this.buffer.length < bytes) bytes = this.buffer.length; var r = this.buffer.slice(0, bytes); this.buffer = this.buffer.slice(bytes); + + if (this.buffer.length <= 131072 && this.getMoreData !== null) { + var getMoreData = this.getMoreData; + this.getMoreData = null; + process.nextTick(getMoreData); + } + return r; } @@ -85,6 +94,12 @@ Input.prototype._write = function (chunk, encoding, next) { } */ this.buffer = Buffer.concat([this.buffer, chunk]); - next(); + if (this.buffer.length > 131072) { + this.getMoreData = next; + } else { + next(); + } + + }