We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d9e82dc commit 881d57eCopy full SHA for 881d57e
workspaces/simon-game/src/app/util/playSound.ts
@@ -0,0 +1,18 @@
1
+export const playSound = (
2
+ context: BaseAudioContext,
3
+ frequency: number,
4
+ duration: number,
5
+ volume: number,
6
+) => {
7
+ const oscillatorNode = context.createOscillator();
8
+ oscillatorNode.frequency.setValueAtTime(frequency, context.currentTime);
9
+
10
+ const gainNode = context.createGain();
11
+ gainNode.gain.setValueAtTime(volume, context.currentTime);
12
13
+ oscillatorNode.connect(gainNode);
14
+ gainNode.connect(context.destination);
15
16
+ oscillatorNode.start();
17
+ oscillatorNode.stop(context.currentTime + duration / 1000);
18
+};
0 commit comments