document setSound api

This commit is contained in:
Felix Roos 2023-03-09 21:27:24 +01:00
parent 41d82eaadf
commit ff1e6714c6
3 changed files with 81 additions and 2 deletions

View file

@ -18,6 +18,9 @@ export const soundMap = map();
export function setSound(key, onTrigger, data = {}) {
soundMap.setKey(key, { onTrigger, data });
}
export function getSound(s) {
return soundMap.get()[s];
}
export const resetLoadedSounds = () => soundMap.set({});
let audioContext;
@ -166,8 +169,8 @@ export const webaudioOutput = async (hap, deadline, hapDuration, cps) => {
let sourceNode;
if (source) {
sourceNode = source(t, hap.value);
} else if (soundMap.get()[s]) {
const { onTrigger } = soundMap.get()[s];
} else if (getSound(s)) {
const { onTrigger } = getSound(s);
const soundHandle = await onTrigger(t, hap.value, onended);
if (soundHandle) {
sourceNode = soundHandle.node;