Limit FPS of VU meters to help weedy CPUs.

This commit is contained in:
Matthew Stratford 2021-01-24 00:56:13 +00:00
parent f1c637120c
commit cd0956b219

View file

@ -27,6 +27,8 @@ export function VUMeter(props: VUMeterProps) {
const isMic = props.source.substr(0, 3) === "mic"; 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(() => { useEffect(() => {
const animate = () => { const animate = () => {
if (!isMic || isMicOpen) { if (!isMic || isMicOpen) {
@ -38,7 +40,9 @@ export function VUMeter(props: VUMeterProps) {
if (props.stereo) { if (props.stereo) {
setPeakR(result[1]); setPeakR(result[1]);
} }
rafRef.current = requestAnimationFrame(animate); setTimeout((current = rafRef.current, a = animate) => {
current = requestAnimationFrame(a);
}, 1000 / FPS);
} }
}; };
if (!isMic || isMicOpen) { if (!isMic || isMicOpen) {