Make envelope computation more robust

When pollint() returns 100.0, multiplying by 2.55 doesn't actually seem to
be getting 255 on i386. Multiplying by 255 and dividing by 100, however,
does (probably because float computation with small integer values are
guaranteed to have integer results).

Fixes #1151
This commit is contained in:
Samuel Thibault
2022-04-10 22:12:28 +02:00
parent 310e8fc768
commit a34d74ed43
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -1410,9 +1410,9 @@ static int LoadEnvelope2(FILE *f)
if (env_lin[ix2] > 0) {
y = (env_y[ix2] + (env_y[ix2+1] - env_y[ix2]) * ((float)x - env_x[ix2]) / (env_x[ix2+1] - env_x[ix2])) * 2.55;
} else if (n_points > 3)
y = (int)(polint(&env_x[ix], &env_y[ix], 4, x) * 2.55); // convert to range 0-255
y = (int)(polint(&env_x[ix], &env_y[ix], 4, x) * 255 / 100); // convert to range 0-255
else
y = (int)(polint(&env_x[ix], &env_y[ix], 3, x) * 2.55);
y = (int)(polint(&env_x[ix], &env_y[ix], 3, x) * 255 / 100);
if (y < 0) y = 0;
if (y > 255) y = 255;
env[x] = y;