@jdeighan/coffee-utils 4.1.24 → 4.1.25
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/browser_utils.coffee +11 -5
package/package.json
CHANGED
package/src/browser_utils.coffee
CHANGED
@@ -1,17 +1,23 @@
|
|
1
1
|
# browser_utils.coffee
|
2
2
|
|
3
|
+
import {undef} from '@jdeighan/coffee-utils'
|
4
|
+
|
5
|
+
audio = undef # audio context - create only when needed, then keep
|
6
|
+
|
3
7
|
# ---------------------------------------------------------------------------
|
4
8
|
# beep - play a sound
|
5
9
|
|
6
10
|
export beep = (volume=100, freq=520, duration=200) ->
|
7
11
|
|
8
|
-
|
9
|
-
|
12
|
+
if audio == undef
|
13
|
+
audio = new AudioContext()
|
14
|
+
v = audio.createOscillator()
|
15
|
+
u = audio.createGain()
|
10
16
|
v.connect(u)
|
11
17
|
v.frequency.value = freq
|
12
18
|
v.type = "square"
|
13
|
-
u.connect(
|
19
|
+
u.connect(audio.destination)
|
14
20
|
u.gain.value = volume * 0.01
|
15
|
-
v.start(
|
16
|
-
v.stop(
|
21
|
+
v.start(audio.currentTime)
|
22
|
+
v.stop(audio.currentTime + duration * 0.001)
|
17
23
|
return
|