[gen] Sound overflow

Richard Bannister richard at bannister.org
Wed Nov 7 07:23:00 GMT 2001


On 7/11/01 12:26 am, James Ponder at james at squish.netake thus:

> But 0x8000 and higher is just a negative sample - that's supposed to happen,
> isn't it?  gensound.c uses signed 16 bit values.

No, you're doing an integer calculation:

    if (sound_fm && sound_psg) {
      for (i = 0; i < samples; i++) {
        sint16 snsample = sn76496buf[i] - 0x4000;
        sint32 l = (tbuf[0][i] * 3) >> 2; /* left channel */
        sint32 r = (tbuf[1][i] * 3) >> 2; /* right channel */
        l += snsample >> 1;
        r += snsample >> 1;
        if ((abs(l) > 0x7FFF) || (abs(r) > 0x7FFF))
            ; // OOPS!
            
        tbuf[0][i] = l;
        tbuf[1][i] = r;
      }

Maybe just adding a clip to 0x7FFF would work...

Regards,
Richard

--------------------------------------------------------------------
            Richard Bannister - http://www.bannister.org/
--------------------------------------------------------------------
                  Noli umquam docere porcum cantare;
                  perdes tempus et irritabis porcum.
--------------------------------------------------------------------





More information about the gen mailing list