mirror of
https://github.com/bendtherules/multimeter-connect-web.git
synced 2026-08-18 13:52:26 +00:00
buzzSound.ts - Defer AudioContext creation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// The browser will limit the number of concurrent audio contexts
|
||||
// So be sure to re-use them whenever you can
|
||||
const myAudioContext = new AudioContext();
|
||||
let myAudioContext: AudioContext | undefined = undefined;
|
||||
let lastOscillatorNode: OscillatorNode | undefined = undefined;
|
||||
|
||||
/**
|
||||
@@ -18,6 +18,9 @@ export function startBuzz({
|
||||
volume = 70,
|
||||
onEnd = () => {},
|
||||
} = {}) {
|
||||
if (myAudioContext === undefined) {
|
||||
myAudioContext = new AudioContext();
|
||||
}
|
||||
if (lastOscillatorNode !== undefined) {
|
||||
lastOscillatorNode.stop(myAudioContext.currentTime + duration * 0.001);
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user