--- np2/sound/psggeng.c 2003/10/16 17:58:05 1.1 +++ np2/sound/psggeng.c 2003/10/25 17:29:38 1.4 @@ -5,6 +5,27 @@ extern PSGGENCFG psggencfg; +// ¥Æ¥¹¥È + +static UINT32 rnds; + +static UINT psg_rand(void) { + + UINT32 rand0; + UINT32 rand1; + UINT c; + + rand0 = rnds & 0xffff; + rand1 = rnds >> 16; + rand0 = (rand0 >> 5) + (rand0 << 11); + rand0 += 60043; + rand1 -= 4953 + ((rand0 >> 16) & 1); + c = (rand1 >> 15) & 1; + rand1 = (rand1 << 1) + c; + rand0 += rand1 + c; + rnds = (rand1 << 16) + (rand0 & 0xffff); + return(rand0); +} void SOUNDCALL psggen_getpcm(PSGGEN psg, SINT32 *pcm, UINT count) { @@ -19,7 +40,14 @@ void SOUNDCALL psggen_getpcm(PSGGEN psg, UINT i; UINT noise; - while(count--) { + if ((psg->mixer & 0x3f) == 0) { + count = min(count, psg->puchicount); + psg->puchicount -= count; + } + if (count == 0) { + return; + } + do { noisevol = 0; if (psg->envcnt) { psg->envcnt--; @@ -51,7 +79,8 @@ void SOUNDCALL psggen_getpcm(PSGGEN psg, countbak = psg->noise.count; psg->noise.count -= psg->noise.freq; if (psg->noise.count > countbak) { - psg->noise.base = rand() & (1 << (1 << PSGADDEDBIT)); +// psg->noise.base = GETRAND() & (1 << (1 << PSGADDEDBIT)); + psg->noise.base = psg_rand() & (1 << (1 << PSGADDEDBIT)); } noisetbl += psg->noise.base; noisetbl >>= 1; @@ -68,7 +97,7 @@ void SOUNDCALL psggen_getpcm(PSGGEN psg, case 0: // no mix if (tone->puchi) { tone->puchi--; - samp += vol; + samp += vol << PSGADDEDBIT; } break; @@ -107,6 +136,6 @@ void SOUNDCALL psggen_getpcm(PSGGEN psg, pcm[0] += samp; pcm[1] += samp; pcm += 2; - } + } while(--count); }