Very minor mistake in Audio/synth_sine.cpp

kpc

Well-known member
I was verifying my code and used the sine wave. I noticed the sine not to be antisymmetric. ie sin(x) != -sin(-x).
The cause of this lies in Audio/synth_sine.cpp:53
Code:
51: scale = (ph >> 8) & 0xFFFF;
52: val2 *= scale;
53: val1 *= 0xFFFF - scale;
IMHO line 53 should read
Code:
val1 *= 0x10000 - scale;
In fractional terms, the interpolation should run from [0,1>, ie 0 through 0.9999....
The value of 1 would actually be the next index value with a fractional offset of 0. Hence the replacement of 0xffff by 0x10000. This causes the maximum fractional value to be 0xffff/0x10000 = 0.999...

I agree it is being very pedantic, and in practice nobody will ever notice the difference.
However this costed me several hours of debugging, trying to find where the small offset in my code were coming from, whereas there could theoreticaly not be there. Turned out that my code was OK.

Edit: I tried to confince you with the story above, but I just see in Audio/effect_fade.cpp:65, that you actually implemented it the right way there.
Code:
val2 *= scale;
val1 *= 0x10000 - scale;
val = (val1 + val2) >> 16;
 
Last edited:
Back
Top