Reputation: 1300
When calling stop() on a web audio oscillator, the oscillator node just hangs around, disconnected and unused.
If I tell an oscillator to stop in 2 seconds:
oscillator.stop( audioCtx.currentTime + 2 );
Is there a way to set a callback so I can delete the oscillator immediately after stop() has ran ?
I thought about using a setTimeout with the stop time plus half a second or so but that may end up deleting the wrong oscillator.
Upvotes: 0
Views: 742
Reputation: 13908
Why do you even keep a reference to the oscillator around? If you release your reference to the oscillator immediately after calling stop(), the WA system will keep it around until it completes, then it will get garbage collected automatically. You don't need to hold on to it yourself.
Upvotes: 2
Reputation: 6048
Oscillator nodes support the onended event that is called when the oscillator ends (stops).
Upvotes: 7