Reputation: 1333
I've found I like the sound of setTargetAtTime()
applied to gain. So I'd like to do this:
gainNode.gain.setTargetAtTime(0, audioContext.currentTime, timeConst)
oscillator.stop(audioContext.currentTime + timeConstToSeconds(timeConst));
So that the oscillator stops when the sound is functionally inaudible.
What is an effective timeConstToSeconds()
function for this?
And/or, what is an effective formula for the reverse operation? (input seconds, return time constant.)
Upvotes: 0
Views: 154
Reputation: 6048
The spec tells you exactly how setTargetAtTime
works: https://webaudio.github.io/web-audio-api/#dom-audioparam-settargetattime
As a rough general rule, these kinds of exponential approaches are generally considered to have converged to the final value after 5 or 10 time constants, so
function timeConstToSeconds(t) {
return 10*t;
}
Change 10
to some other appropriate value for what you consider to be close enough.
Upvotes: 1