Closed magnetophon closed 1 year ago
Can you explain what problem this PR solves?
For .val
, we want to read the value closest to id, so we take the int of id.
For the lin case we want to interpolate between the closest value below or at id and the one above it.
So we need floor(id)
.
To illustrate:
Say we have a table with 3 values, 1, 1.1 and 2^24.
id
is 0.75, so the final output should be close to 1.
The current implementation will read 1.1 and 2^24 and feed it to the interpolator with a negative dv
.
The new one will read 1 and 1.1 and will have a positive dv
.
process =
it.interpolate_linear(0.75,1,1.1)
,it.interpolate_linear(-0.25,1.1,pow(2,24));
virtual void compute(int count, FAUSTFLOAT** RESTRICT inputs, FAUSTFLOAT** RESTRICT outputs) {
FAUSTFLOAT* output0 = outputs[0];
FAUSTFLOAT* output1 = outputs[1];
for (int i0 = 0; i0 < count; i0 = i0 + 1) {
output0[i0] = FAUSTFLOAT(1.075f);
output1[i0] = FAUSTFLOAT(-4194302.5f);
}
}
AFAICS int
and floor
behave the same for positive value (see https://stackoverflow.com/questions/3300290/cast-to-int-vs-floor). Are you speaking about and issue with negatives values ?
You are right, I always thought int
was rounding and floor
was rounding down.
That sheds light on another bug though.
For .val
we do want the rounded value, not the rounded down one.
I updated the PR accordingly.
Thanks.
Since we are looking for the closest value below id. Also: d needs to be positive.