From fe6a86cc7f8cc5d264c5e857e552eed0bd572cd1 Mon Sep 17 00:00:00 2001 From: Kareem <28524112+karyeet@users.noreply.github.com> Date: Wed, 21 Dec 2022 23:24:32 -0800 Subject: [PATCH] Update mixer.ts https://github.com/ConnorChristie/Audio-Mixer/issues/5#issuecomment-1345594399 Unfortunately it seems this repo is no longer maintained. I was able to fork the repo (to our company repo) - you will be able to fix the CPU issue by doing the following here: https://github.com/ConnorChristie/Audio-Mixer/blob/master/src/mixer.ts#L82 Replace this bit: clearImmediate(this._timer) this._timer = setImmediate(this._read.bind(this)); with clearTimeout(this._timer) this._timer = setTimeout(this._read.bind(this), 0); I dont know what kind of impact it would have in terms of realtime processing. But for our use-case it works and all 2000 unit tests are still passing after this change. But CPU basically went down to 0 :) --- src/mixer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mixer.ts b/src/mixer.ts index 5e2ec17..54c6c4b 100644 --- a/src/mixer.ts +++ b/src/mixer.ts @@ -80,7 +80,7 @@ export class Mixer extends Readable { this.push(mixedBuffer); } else if(this.needReadable) { clearImmediate(this._timer) - this._timer = setImmediate(this._read.bind(this)); + this._timer = setTimeout(this._read.bind(this), 0); } this.clearBuffers();