Improve getOscillator/noiseMix release
This commit is contained in:
parent
1225d04437
commit
71d36b79ed
3 changed files with 13 additions and 6 deletions
|
|
@ -283,9 +283,12 @@ export function drywet(dry, wet, wetAmount = 0) {
|
||||||
wet_gain.connect(mix);
|
wet_gain.connect(mix);
|
||||||
return {
|
return {
|
||||||
node: mix,
|
node: mix,
|
||||||
onended: () => {
|
teardown: () => {
|
||||||
dry_gain.disconnect(mix);
|
releaseAudioNode(dry_gain);
|
||||||
wet_gain.disconnect(mix);
|
releaseAudioNode(wet_gain);
|
||||||
|
// it is not the responsability of drywet
|
||||||
|
// to call `releaseAudioNode` on
|
||||||
|
// the 2 external args dry and wet
|
||||||
dry.disconnect(dry_gain);
|
dry.disconnect(dry_gain);
|
||||||
wet.disconnect(wet_gain);
|
wet.disconnect(wet_gain);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { drywet, onceEnded } from './helpers.mjs';
|
import { drywet, onceEnded, releaseAudioNode } from './helpers.mjs';
|
||||||
import { getAudioContext } from './audioContext.mjs';
|
import { getAudioContext } from './audioContext.mjs';
|
||||||
|
|
||||||
let noiseCache = {};
|
let noiseCache = {};
|
||||||
|
|
@ -65,9 +65,12 @@ export function getNoiseOscillator(type = 'white', t, density = 0.02) {
|
||||||
export function getNoiseMix(inputNode, wet, t) {
|
export function getNoiseMix(inputNode, wet, t) {
|
||||||
const noiseOscillator = getNoiseOscillator('pink', t);
|
const noiseOscillator = getNoiseOscillator('pink', t);
|
||||||
const noiseMix = drywet(inputNode, noiseOscillator.node, wet);
|
const noiseMix = drywet(inputNode, noiseOscillator.node, wet);
|
||||||
onceEnded(noiseOscillator.node, () => noiseMix.onended());
|
onceEnded(noiseOscillator.node, () => {
|
||||||
|
releaseAudioNode(noiseOscillator.node);
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
node: noiseMix.node,
|
node: noiseMix.node,
|
||||||
stop: (time) => noiseOscillator?.stop(time),
|
stop: (time) => noiseOscillator?.stop(time),
|
||||||
|
teardown: noiseMix.teardown,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -491,7 +491,8 @@ export function getOscillator(s, t, value, onended) {
|
||||||
}
|
}
|
||||||
|
|
||||||
onceEnded(o, () => {
|
onceEnded(o, () => {
|
||||||
noiseMix || releaseAudioNode(o);
|
noiseMix?.teardown();
|
||||||
|
releaseAudioNode(o);
|
||||||
releaseAudioNode(noiseMix?.node);
|
releaseAudioNode(noiseMix?.node);
|
||||||
onended();
|
onended();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue