[gen] Sound overflow

James Ponder james at squish.net
Wed Nov 7 21:48:12 GMT 2001


On Wed, Nov 07, 2001 at 07:23:00AM +0100, Richard Bannister wrote:
>     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...

You're saying that the code does not match the comment:

    /* SN76496 outputs sound in range -0x4000 to 0x3fff
       YM2612 ouputs sound in range -0x8000 to 0x7fff - therefore
       we take 3/4 of the YM2612 and add half the SN76496 */

By my calculations (0x3fff >> 1) + (0x7fff * 3) >> 2 = 0x7ffe.


Best wishes, James
-- 
James Ponder; www.squish.net; London, UK




More information about the gen mailing list