From cd0956b21946ed3cf5f50d06ec70a56bd01db59b Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sun, 24 Jan 2021 00:56:13 +0000 Subject: [PATCH] Limit FPS of VU meters to help weedy CPUs. --- src/optionsMenu/helpers/VUMeter.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/optionsMenu/helpers/VUMeter.tsx b/src/optionsMenu/helpers/VUMeter.tsx index 97c07d1..0e7791b 100644 --- a/src/optionsMenu/helpers/VUMeter.tsx +++ b/src/optionsMenu/helpers/VUMeter.tsx @@ -27,6 +27,8 @@ export function VUMeter(props: VUMeterProps) { const isMic = props.source.substr(0, 3) === "mic"; + const FPS = 30; // Limit the FPS so that lower spec machines have a better time juggling CPU. + useEffect(() => { const animate = () => { if (!isMic || isMicOpen) { @@ -38,7 +40,9 @@ export function VUMeter(props: VUMeterProps) { if (props.stereo) { setPeakR(result[1]); } - rafRef.current = requestAnimationFrame(animate); + setTimeout((current = rafRef.current, a = animate) => { + current = requestAnimationFrame(a); + }, 1000 / FPS); } }; if (!isMic || isMicOpen) {