@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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "4.1.24",
4
+ "version": "4.1.25",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -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
- v = @audio.createOscillator()
9
- u = @audio.createGain()
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(@audio.destination)
19
+ u.connect(audio.destination)
14
20
  u.gain.value = volume * 0.01
15
- v.start(@audio.currentTime)
16
- v.stop(@audio.currentTime + duration * 0.001)
21
+ v.start(audio.currentTime)
22
+ v.stop(audio.currentTime + duration * 0.001)
17
23
  return