Refactor to remove need for magic constant.

- Removed need for magic constant (largest Number)
- Refactored code to find minimum samples available.
This commit is contained in:
Chinmay Pendharkar 2016-08-09 17:45:35 +08:00 committed by GitHub
parent 72d7965521
commit a8142b20c3

View File

@ -50,13 +50,18 @@ function Mixer(args) {
util.inherits(Mixer, Readable); util.inherits(Mixer, Readable);
Mixer.prototype._read = function() { Mixer.prototype._read = function() {
var samples = 0;
var samples = 9007199254740992; if (this.inputs.length){
this.inputs.forEach(function (input) { samples = this.inputs.map(function (input) {
var as = input.availSamples(); return input.availSamples() || 0;
if (as < samples) samples = as; }).reduce(function(a,b){
}); return Math.min(a,b);
if (samples > 0 && samples != 9007199254740992) { });
}
if (samples) {
var mixedBuffer = new Buffer(samples * this.sampleByteLength * this.channels); var mixedBuffer = new Buffer(samples * this.sampleByteLength * this.channels);
mixedBuffer.fill(0); mixedBuffer.fill(0);