--- xmil/sound/psggenc.c 2004/08/05 11:30:12 1.2 +++ xmil/sound/psggenc.c 2005/02/04 06:42:12 1.7 @@ -1,15 +1,14 @@ #include "compiler.h" -#include #include "sound.h" #include "sndctrl.h" -// extern int s_cnt; -// extern DWORD basedclk; - - PSGGENCFG psggencfg; +static const SINT32 psgvolrate[16] = { + 0, 508, 719, 1017, 1440, 2037, 2883, 4079, + 5772, 8167,11556,16351,23135,32735,46317,65536}; + const UINT8 psggen_deftbl[0x10] = {0, 0, 0, 0, 0, 0, 0, 0xbf, 0, 0, 0, 0, 0, 0, 0xff, 0xff}; @@ -34,17 +33,14 @@ static const UINT8 psgenv_pat[16] = { void psggen_initialize(UINT rate) { - double pom; UINT i; ZeroMemory(&psggencfg, sizeof(psggencfg)); psggencfg.rate = rate; - pom = (double)0x0c00; - for (i=15; i; i--) { - psggencfg.voltbl[i] = (SINT32)pom; - pom /= 1.41492; + for (i=0; i<16; i++) { + psggencfg.voltbl[i] = (0x0c00 * psgvolrate[i]) >> 16; } - psggencfg.puchidec = (UINT16)(rate / 11025) * 2; + psggencfg.puchidec = (UINT16)(rate * 2 / 11025); if (psggencfg.puchidec == 0) { psggencfg.puchidec = 1; } @@ -91,15 +87,10 @@ void psggen_setreg(PSGGEN psg, REG8 reg, UINT freq; UINT ch; -// if (romeo_exist) { -// juliet2_YMF288A(reg, value, (basedclk * s_cnt / 1600)); -// return; -// } - - reg &= 15; -// if (reg < 14) { -// sound_sync(); -// } + if (reg >= 14) { + return; + } + sound_sync(); ((UINT8 *)&psg->reg)[reg] = value; switch(reg) { case 0: @@ -115,6 +106,7 @@ void psggen_setreg(PSGGEN psg, REG8 reg, } else { psg->tone[ch].freq = 0; + psg->tone[ch].count = 0; // としておかないとノイズ出ない } break; @@ -131,7 +123,6 @@ void psggen_setreg(PSGGEN psg, REG8 reg, // keydisp_psgmix(psg); psg->mixer = ~value; psg->puchicount = psggencfg.puchidec; -// TRACEOUT(("psg %x 7 %d", (long)psg, value)); break; case 8: @@ -147,7 +138,6 @@ void psggen_setreg(PSGGEN psg, REG8 reg, } psg->tone[ch].puchi = psggencfg.puchidec; psg->puchicount = psggencfg.puchidec; -// TRACEOUT(("psg %x %x %d", (long)psg, reg, value)); break; case 11: @@ -163,7 +153,7 @@ void psggen_setreg(PSGGEN psg, REG8 reg, case 13: psg->envmode = psgenv_pat[value & 0x0f]; psg->envvolcnt = 16; - psg->envcnt = 1; + psg->envcnt = 0; break; } }