Skip to content

Commit 881d57e

Browse files
committed
feat: added playSound function to simons game
1 parent d9e82dc commit 881d57e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)