Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 1 of 1

Thread: Very minor mistake in Audio/synth_sine.cpp

  1. #1
    Senior Member
    Join Date
    Jan 2015

    Very minor mistake in Audio/synth_sine.cpp

    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
    51: scale = (ph >> 8) & 0xFFFF;
    52: val2 *= scale;
    53: val1 *= 0xFFFF - scale;
    IMHO line 53 should read
    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.
    val2 *= scale;
    val1 *= 0x10000 - scale;
    val = (val1 + val2) >> 16;
    Last edited by kpc; 01-24-2015 at 10:10 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts