disconnect worklet at scheduled time to destroy faster

This commit is contained in:
Jade (Rose) Rowland 2024-03-17 01:15:07 -04:00
parent 5d55b9c9ef
commit dad18a24fb
3 changed files with 44 additions and 17 deletions

View file

@ -186,6 +186,16 @@ export function getVibratoOscillator(param, value, t) {
return vibratoOscillator;
}
}
// ConstantSource inherits AudioScheduledSourceNode, which has scheduling abilities
// a bit of a hack, but it works very well :)
export function webAudioTimeout(audioContext, onComplete, startTime, stopTime) {
const constantNode = audioContext.createConstantSource();
constantNode.start(startTime);
constantNode.stop(stopTime);
constantNode.onended = () => {
onComplete();
};
}
const mod = (freq, range = 1, type = 'sine') => {
const ctx = getAudioContext();
const osc = ctx.createOscillator();