Stop trying to read if no inputs are connected
If no inputs are connected, the `_read` function still keeps looping ( using `setImmediate(this._read.bind(this));` ) to wait for more samples to be available. This can cause the CPU usage to go up (60% on my 2014 MBP) even when no audio is being played. This fix stops the looping if `this.inputs` array is empty and starts it again when new inputs are connected.
This commit is contained in:
parent
564d31654f
commit
72d7965521
@ -73,8 +73,10 @@ Mixer.prototype._read = function() {
|
||||
|
||||
this.push(mixedBuffer);
|
||||
} else {
|
||||
if (this.inputs.length){
|
||||
setImmediate(this._read.bind(this));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Mixer.prototype.input = function (args) {
|
||||
@ -92,6 +94,10 @@ Mixer.prototype.input = function (args) {
|
||||
this.inputs.splice(this.inputs.indexOf(input), 1);
|
||||
});
|
||||
|
||||
if (this.inputs.length === 1){
|
||||
setImmediate(this._read.bind(this));
|
||||
}
|
||||
|
||||
return input;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user