Skip to content

Commit

Permalink
limit frequency of sounds playing
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoBSalgueiro committed Apr 12, 2024
1 parent 5ce8cfb commit b6cd522
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/utils/sound.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { soundCollectionAtom, soundVolumeAtom } from "@/state/atoms";
import { getDefaultStore } from "jotai";

let lastTime = 0;

export function playSound(capture: boolean, check: boolean) {
// only play at most 1 sound every 75ms
const now = Date.now();
if (now - lastTime < 75) {
return;
}
lastTime = now;

const store = getDefaultStore();
const collection = store.get(soundCollectionAtom);
const volume = store.get(soundVolumeAtom);
Expand Down

0 comments on commit b6cd522

Please sign in to comment.