From bd686ef67d70aa3d850444bb959ccf97106e2553 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Thu, 29 Sep 2022 10:20:05 +0100 Subject: [PATCH] use time.time() to steady rate of updates. reduce loop time if waiting for new event --- voicemeeterlib/updater.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/voicemeeterlib/updater.py b/voicemeeterlib/updater.py index daa6ef8..1820b39 100644 --- a/voicemeeterlib/updater.py +++ b/voicemeeterlib/updater.py @@ -18,6 +18,7 @@ class Updater(threading.Thread): Runs updates at a rate of self.ratelimit. """ while self._remote.running: + start = time.time() if self._remote.event.pdirty and self._remote.pdirty: self._remote.subject.notify("pdirty") if self._remote.event.mdirty and self._remote.mdirty: @@ -43,4 +44,8 @@ class Updater(threading.Thread): self._remote.cache["bus_level"] = self._remote._bus_buf self._remote.subject.notify("ldirty") - time.sleep(self._remote.ratelimit if self._remote.event.any() else 0.1) + elapsed = time.time() - start + if self._remote.event.any() and self._remote.ratelimit - elapsed > 0: + time.sleep(self._remote.ratelimit - elapsed) + else: + time.sleep(0.1)