| version 1.4, 2004/08/13 04:08:33 | version 1.7, 2005/02/04 06:42:12 | 
| Line 1 | Line 1 | 
 | #include        "compiler.h" | #include        "compiler.h" | 
 | #include        <math.h> |  | 
 | #include        "sound.h" | #include        "sound.h" | 
 | #include        "sndctrl.h" | #include        "sndctrl.h" | 
 |  |  | 
 |  |  | 
 | PSGGENCFG       psggencfg; | 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] = | const UINT8 psggen_deftbl[0x10] = | 
 | {0, 0, 0, 0, 0, 0, 0, 0xbf, 0, 0, 0, 0, 0, 0, 0xff, 0xff}; | {0, 0, 0, 0, 0, 0, 0, 0xbf, 0, 0, 0, 0, 0, 0, 0xff, 0xff}; | 
 |  |  | 
| Line 30  static const UINT8 psgenv_pat[16] = { | Line 33  static const UINT8 psgenv_pat[16] = { | 
 |  |  | 
 | void psggen_initialize(UINT rate) { | void psggen_initialize(UINT rate) { | 
 |  |  | 
 | double  pom; |  | 
 | UINT    i; | UINT    i; | 
 |  |  | 
 | ZeroMemory(&psggencfg, sizeof(psggencfg)); | ZeroMemory(&psggencfg, sizeof(psggencfg)); | 
 | psggencfg.rate = rate; | psggencfg.rate = rate; | 
| pom = (double)0x0c00; | for (i=0; i<16; i++) { | 
| for (i=15; i; i--) { | psggencfg.voltbl[i] = (0x0c00 * psgvolrate[i]) >> 16; | 
| psggencfg.voltbl[i] = (SINT32)pom; |  | 
| pom /= 1.41492; |  | 
 | } | } | 
| psggencfg.puchidec = (UINT16)(rate / 11025) * 2; | psggencfg.puchidec = (UINT16)(rate * 2 / 11025); | 
 | if (psggencfg.puchidec == 0) { | if (psggencfg.puchidec == 0) { | 
 | psggencfg.puchidec = 1; | psggencfg.puchidec = 1; | 
 | } | } | 
| Line 106  void psggen_setreg(PSGGEN psg, REG8 reg, | Line 106  void psggen_setreg(PSGGEN psg, REG8 reg, | 
 | } | } | 
 | else { | else { | 
 | psg->tone[ch].freq = 0; | psg->tone[ch].freq = 0; | 
 |  | psg->tone[ch].count = 0;        // としておかないとノイズ出ない | 
 | } | } | 
 | break; | break; | 
 |  |  | 
| Line 152  void psggen_setreg(PSGGEN psg, REG8 reg, | Line 153  void psggen_setreg(PSGGEN psg, REG8 reg, | 
 | case 13: | case 13: | 
 | psg->envmode = psgenv_pat[value & 0x0f]; | psg->envmode = psgenv_pat[value & 0x0f]; | 
 | psg->envvolcnt = 16; | psg->envvolcnt = 16; | 
| psg->envcnt = 1; | psg->envcnt = 0; | 
 | break; | break; | 
 | } | } | 
 | } | } |