sfztools/sfizz

FlexEGs behaving incorrectly for shape values between -1 and 0 / 0 and +1

Lyve1981 opened this issue · 1 comments

According to the specification, a shape value of 0 should be linear, values < 0 should be faster, values > 0 slower. However, this does not apply for values that are between -1 and +1 (and not 0):

I looked up the code and found the formula, which is:

For positive shape values:
std::pow(x, shape);

For negative shape values:
1 - std::pow(1 - x, -shape)

Note that, in both cases above, a shape value of 1 results in a linear curve, even though this should happen for a value of 0 (which it does because for the value 0, a default curve is returned).

However, this causes the curve to be the opposite of what you want if the value is -1 < shape < 0 or 0 < shape < 1

For a shape value of -6, its looking good:
image

But notice what happens for a shape value of -1:
image

A very extreme case, a shape value of -0.1, this should be very close to being linear, but it isn't:
image

The correct formula should be:

For positive shape values:
std::pow(x, shape + 1);

For negative shape values:
1 - std::pow(1 - x, -shape + 1)

Speaking as the person responsible for the pull requests that, among other things, added this feature, I appreciate your corrections. I fully admit my own appreoach was a bit crude and may not have been completely accurate to the ARIA implementation.