i've had a lot of problems with something i didn't expect to. my envelope code has a 32 bit float "level" variable that ranges from 0.0f to 1.0f

the release is performed, imo predictably by decrementing. level -= dec. a check to shut the envelope off is then performed.. this used to be if (level <= 0.f) envelope = off, but i've had significant issues with the code not reaching this point. if i increase the threshold to (level < .0005f) the performance is much better, notes rarely hang. but, this is of course lousy resolution.

okay, so f**k me. i haven't made any great effort to educate myself on the thresholds of floating point, i know that after a certain size, precision is lost (eg. integers over a certain size cannot be precisely indicated). the solution is to scale my envelope to 100000 or something instead of 1.

i'm guessing that 32 bit floating point precision is resulting in something like small#a minus small#b = no discernible difference, therefore floating point calculation returns the same, there is effectively no subtraction. that seems reasonable to me, but i wouldn't expect to reach this threshold until about six decimal places.

anyone?

you come and go, you come and go. amitabha xoxos.net free vst. neither a follower nor a leader betagore "where roads are made i lose my way"where there is certainty, consideration is absent.

On my machine std::numeric_limits<f32>::epsilon() is 1.19209290e-007 (the spec says it should be smaller than 1e-5).
Maybe the floating point precision compiler settings have an effect on this too, I haven't checked (see for example http://msdn.microsoft.com/library/e7s85ffb.aspx)

Are you scaling the dec value per increment? If you are using multiplication by a value smaller than one anywhere with dec than you are slowing and possibly sustaining the envelope. It looks linear so far. What kind of dynamic range are you expecting? Single or double precision?

You can figure a threshold with defined dynamic range by multiplying every power change of the exponent segment by 6 db. 2^-24 exponent would be -144 dBFS. Then just use the hex value as a constant instead of the numeric.

I suspect there is a bug in your control logic which is not related to precision issues. btw, the higher the scale, the bigger the epsilon size. Scaling the range up will not help.

However, you can reduce precision problem to irrelevant levels by using double precision floats, careful dithering and/or by working in the dB domain (btw, the latter is practically a "must" for accurate followers in the audio context).

That would assume rounding errors don't propagate at each step. You'd have to actually store ints for that to work, or use special summation formulae.

2^24 is 16 million.

Anyway, I'd have to sit down and actually think to figure this out as the exponent will come into it as well (hence my advice to check it empirically) but 32 floats should deal with this kind of range just fine.

You could always calculate it it the other way, by counting samples, if you don't mind a multiplication at every sample. But I'd take a look at what the actual values are first, I suspect the issue isn't what xoxos thinks it is.

Anyway, I'd have to sit down and actually think to figure this out as the exponent will come into it as well (hence my advice to check it empirically) but 32 floats should deal with this kind of range just fine.

You could always calculate it it the other way, by counting samples, if you don't mind a multiplication at every sample. But I'd take a look at what the actual values are first, I suspect the issue isn't what xoxos thinks it is.

Yep, sorry I was a bit too quick there, the rest of the calculation holds tough.
I just edited my prev post with a test.
Cheers

I did it the same way and it worked for me. (I've since changed everything to doubles but never had any problem when it was all 32 bit.)

You're thinking too much. You can definitely count to 16 million with floats. The problem is something ELSE. Probably dec is zero or something.

Wait, is this not just the envelope counter but also the output level? If so, what happens if a long release time activates when a decay or sustain level was almost at zero, does it start counting down from THERE? Or from 1? (Another way of asking, are they rate envelope segments or time envelope segments?)