Learned something new from

this
f = 1 - exp(-1 / d) gives you the coefficient to use to get to 63.2% of the target amplitude in d number of samples. After another d number of samples have passed, the amplitude is 63.2% of the remaining amplitude. This continues forever.

So if our target is 1, i.e. y += f * (1 - y), we get the following results:

- Code: Select all
`1d 0.632`

2d 0.865: (1 - 0.632) * 0.632 + 0.632

3d 0.951: (1 - 0.865) * 0.632 + 0.865

4d 0.982: (1 - 0.951) * 0.632 + 0.951

5d 0.993: (1 - 0.982) * 0.632 + 0.982

We can calculate the amplitude of the curve arbitrarily by using this formula:

a = 1 - exp(-x / fs)

Where x is the position in samples and fs is the sample rate.

Say the sample rate is 44100 and we wish to calculate the curve at 22050:

a = 1 - exp(-22050 / 44100)

Which gives us:

0.3934693403