--- np2/sound/opngenc.c 2003/12/08 00:55:33 1.8 +++ np2/sound/opngenc.c 2004/07/26 18:52:55 1.10 @@ -52,15 +52,24 @@ static const int fmslot[4] = {0, 2, 1, 3 void opngen_initialize(UINT rate) { + UINT ratebit; int i; int j; double pom; double freq; UINT32 calcrate; - calcrate = rate * 55466 / 44100; - - opncfg.calc1024 = FMDIV_ENT * 44100 / 55466; + if (rate == 44100) { + ratebit = 0; + } + else if (rate == 22050) { + ratebit = 1; + } + else { + ratebit = 2; + } + calcrate = (OPNA_CLOCK / 72) >> ratebit; + opncfg.calc1024 = FMDIV_ENT * 44100 / (OPNA_CLOCK / 72); for (i=0; ikeynote[0]; // ver0.27 - BYTE kc = ch->kcode[0]; - BYTE evr; + UINT8 kc = ch->kcode[0]; + UINT evr; OPNSLOT *slot; int s; @@ -366,7 +375,7 @@ static void channleupdate(OPNCH *ch) { if (!(ch->extop)) { for (i=0; i<4; i++, slot++) { slot->freq_inc = (fc + slot->detune1[kc]) * slot->multiple; - evr = (BYTE)(kc >> slot->keyscale); + evr = kc >> slot->keyscale; if (slot->envratio != evr) { slot->envratio = evr; slot->env_inc_attack = slot->attack[evr]; @@ -381,7 +390,7 @@ static void channleupdate(OPNCH *ch) { s = extendslot[i]; slot->freq_inc = (ch->keynote[s] + slot->detune1[ch->kcode[s]]) * slot->multiple; - evr = (BYTE)(ch->kcode[s] >> slot->keyscale); + evr = ch->kcode[s] >> slot->keyscale; if (slot->envratio != evr) { slot->envratio = evr; slot->env_inc_attack = slot->attack[evr]; @@ -474,7 +483,7 @@ void opngen_setreg(REG8 chbase, REG8 reg OPNCH *ch; OPNSLOT *slot; UINT fn; - BYTE blk; + UINT8 blk; chpos = reg & 3; if (chpos == 3) { @@ -549,7 +558,7 @@ void opngen_setreg(REG8 chbase, REG8 reg break; case 0xb0: - ch->algorithm = (BYTE)(value & 7); + ch->algorithm = (UINT8)(value & 7); value = (value >> 3) & 7; if (value) { ch->feedback = 8 - value; @@ -561,7 +570,7 @@ void opngen_setreg(REG8 chbase, REG8 reg break; case 0xb4: - ch->pan = (BYTE)(value & 0xc0); + ch->pan = (UINT8)(value & 0xc0); set_algorithm(ch); break; } @@ -609,6 +618,6 @@ void opngen_keyon(UINT chnum, REG8 value slot++; bit <<= 1; } - keydisp_fmkeyon((BYTE)chnum, value); + keydisp_fmkeyon((UINT8)chnum, value); }