Merge branch 'main' into glossing/random
This commit is contained in:
commit
0a4b6a01b3
1 changed files with 20 additions and 2 deletions
|
|
@ -211,11 +211,29 @@ export function getVibratoOscillator(param, value, t) {
|
||||||
export function webAudioTimeout(audioContext, onComplete, startTime, stopTime) {
|
export function webAudioTimeout(audioContext, onComplete, startTime, stopTime) {
|
||||||
const constantNode = new ConstantSourceNode(audioContext);
|
const constantNode = new ConstantSourceNode(audioContext);
|
||||||
|
|
||||||
constantNode.start(startTime);
|
// Certain browsers requires audio nodes to be connected in order for their onended events
|
||||||
constantNode.stop(stopTime);
|
// to fire, so we _mute it_ and then connect it to the destination
|
||||||
|
const zeroGain = gainNode(0);
|
||||||
|
zeroGain.connect(audioContext.destination);
|
||||||
|
constantNode.connect(zeroGain);
|
||||||
|
|
||||||
|
// Schedule the `onComplete` callback to occur at `stopTime`
|
||||||
constantNode.onended = () => {
|
constantNode.onended = () => {
|
||||||
|
// Ensure garbage collection
|
||||||
|
try {
|
||||||
|
zeroGain.disconnect();
|
||||||
|
} catch {
|
||||||
|
// pass
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
constantNode.disconnect();
|
||||||
|
} catch {
|
||||||
|
// pass
|
||||||
|
}
|
||||||
onComplete();
|
onComplete();
|
||||||
};
|
};
|
||||||
|
constantNode.start(startTime);
|
||||||
|
constantNode.stop(stopTime);
|
||||||
return constantNode;
|
return constantNode;
|
||||||
}
|
}
|
||||||
const mod = (freq, range = 1, type = 'sine') => {
|
const mod = (freq, range = 1, type = 'sine') => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue