Merge pull request #1177 from sfztools/issue-1176

Fix FlexEGs shape
This commit is contained in:
Paul Ferrand 2023-08-03 17:19:32 +02:00 committed by GitHub
commit 27228226f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -56,14 +56,14 @@ std::shared_ptr<Curve> FlexEGs::getShapeCurve(float shape)
else if (shape > 0) {
for (unsigned i = 0; i < numPoints; ++i) {
float x = float(i) / (numPoints - 1);
points[i] = std::pow(x, shape);
points[i] = std::pow(x, 1 + shape);
}
*curve = Curve::buildFromPoints(points);
}
else if (shape < 0) {
for (unsigned i = 0; i < numPoints; ++i) {
float x = float(i) / (numPoints - 1);
points[i] = 1 - std::pow(1 - x, -shape);
points[i] = 1 - std::pow(1 - x, 1 - shape);
}
*curve = Curve::buildFromPoints(points);
}

View file

@ -251,10 +251,10 @@ TEST_CASE("[FlexEG] Detailed numerical envelope test (with shapes)")
std::vector<float> output;
std::vector<float> expected {
0.0f,
0.01f, 0.04f, 0.09f, 0.16f, 0.25f,
0.58f, 0.72f, 0.83f, 0.92f, 1.0f,
0.002f, 0.016f, 0.054f, 0.128f, 0.25f,
0.317f, 0.44f, 0.6f, 0.787f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
0.99f, 0.97f, 0.87f, 0.59f, 0.0f,
1.0f, 0.99f, 0.922f, 0.672f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 0.0f
};
output.resize(expected.size());