WebAudio: how does timeConstant work in setTargetAtTime?

I want to quickly loosen the oscillator to remove the pop / hiss that I get by simply stopping it. Chris Wilson suggested a method to set setTargetAtTime to gain.

Now I don’t quite understand his last parameter "timeConstant":

What is his unit? Seconds? What do I need to put there to get to the target value of 1 ms?

+7
html5 web-audio
source share
2 answers

This guy Chris Wilson, such a problem. :)

setTargetAtTime - exponential decline. Parameter - time constant:

"timeConstant is the time when a linear continuous first-time continuous system is required to achieve a value of 1 - 1 / e (about 63.2%), taking into account the input response of the step (transition from 0 to 1 value).

Thus, for each time period, the level will decrease by 2 / 3rds (assuming that the gain is 1, and you set the target to 0. At some point, the decline becomes so close to zero, it is below the noise threshold and you don’t you need to worry about it, he will never “reach the target value” - he will come close to it, although, of course, at some point the difference falls below the accuracy that you can imagine in the float.

I would suggest experimenting a bit, but here is a quick guess at what you started:

// only setting this up as a var to multiply it later - you can hardcode. // initial value is 1 millisecond - experiment with this value if it not fading // quickly enough. var timeConstant = 0.001; gain = ctx.createGain(); // connect up the node in place here gain.gain.setTargetAtTime(0, ctx.currentTime, timeConstant); // by my quick math, 8x TC should take you to around 2.5% of the original level // - more than enough to smooth the envelope off. myBufferSourceNode.stop( ctx.currentTime + (8 * timeConstant) ); 
+9
source share

although I understand that this may not be technically correct (given the exponential nature of the time constant), but I used this formula to “convert” from seconds to “time constant”

 function secondsToTimeConstant( sec ){ return ( sec * 2 ) / 10; } 

... it was just through a trial version and an error, but it more or less worked for me

+1
source share

All Articles