--- np2/sound/opngenc.c 2003/11/28 08:01:33 1.7 +++ np2/sound/opngenc.c 2007/10/28 16:01:35 1.12 @@ -31,13 +31,13 @@ static SINT32 decaytable[94]; static const SINT32 decayleveltable[16] = { SC( 0),SC( 1),SC( 2),SC( 3),SC( 4),SC( 5),SC( 6),SC( 7), SC( 8),SC( 9),SC(10),SC(11),SC(12),SC(13),SC(14),SC(31)}; -static const BYTE multipletable[] = { +static const UINT8 multipletable[] = { 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30}; static const SINT32 nulltable[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; -static const BYTE kftable[16] = {0,0,0,0,0,0,0,1,2,3,3,3,3,3,3,3}; -static const BYTE dttable[] = { +static const UINT8 kftable[16] = {0,0,0,0,0,0,0,1,2,3,3,3,3,3,3,3}; +static const UINT8 dttable[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, @@ -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; istereo) { @@ -270,13 +279,13 @@ static void set_algorithm(OPNCH *ch) { ch->outslot = outslot; } -static void set_dt1_mul(OPNSLOT *slot, BYTE value) { +static void set_dt1_mul(OPNSLOT *slot, REG8 value) { slot->multiple = (SINT32)multipletable[value & 0x0f]; slot->detune1 = detunetable[(value >> 4) & 7]; } -static void set_tl(OPNSLOT *slot, BYTE value) { +static void set_tl(OPNSLOT *slot, REG8 value) { #if (EVC_BITS >= 7) slot->totallevel = ((~value) & 0x007f) << (EVC_BITS - 7); @@ -285,28 +294,28 @@ static void set_tl(OPNSLOT *slot, BYTE v #endif } -static void set_ks_ar(OPNSLOT *slot, BYTE value) { +static void set_ks_ar(OPNSLOT *slot, REG8 value) { - slot->keyscale = (BYTE)(((~value)>>6)&3); + slot->keyscale = ((~value) >> 6) & 3; value &= 0x1f; slot->attack = (value)?(attacktable + (value << 1)):nulltable; - slot->env_inc_attack = slot->attack[slot->envraito]; + slot->env_inc_attack = slot->attack[slot->envratio]; if (slot->env_mode == EM_ATTACK) { slot->env_inc = slot->env_inc_attack; } } -static void set_d1r(OPNSLOT *slot, BYTE value) { +static void set_d1r(OPNSLOT *slot, REG8 value) { value &= 0x1f; slot->decay1 = (value)?(decaytable + (value << 1)):nulltable; - slot->env_inc_decay1 = slot->decay1[slot->envraito]; + slot->env_inc_decay1 = slot->decay1[slot->envratio]; if (slot->env_mode == EM_DECAY1) { slot->env_inc = slot->env_inc_decay1; } } -static void set_dt2_d2r(OPNSLOT *slot, BYTE value) { +static void set_dt2_d2r(OPNSLOT *slot, REG8 value) { value &= 0x1f; slot->decay2 = (value)?(decaytable + (value << 1)):nulltable; @@ -314,18 +323,18 @@ static void set_dt2_d2r(OPNSLOT *slot, B slot->env_inc_decay2 = 0; } else { - slot->env_inc_decay2 = slot->decay2[slot->envraito]; + slot->env_inc_decay2 = slot->decay2[slot->envratio]; } if (slot->env_mode == EM_DECAY2) { slot->env_inc = slot->env_inc_decay2; } } -static void set_d1l_rr(OPNSLOT *slot, BYTE value) { +static void set_d1l_rr(OPNSLOT *slot, REG8 value) { slot->decaylevel = decayleveltable[(value >> 4)]; slot->release = decaytable + ((value & 0x0f) << 2) + 2; - slot->env_inc_release = slot->release[slot->envraito]; + slot->env_inc_release = slot->release[slot->envratio]; if (slot->env_mode == EM_RELEASE) { slot->env_inc = slot->env_inc_release; if (value == 0xff) { @@ -337,7 +346,7 @@ static void set_d1l_rr(OPNSLOT *slot, BY } } -static void set_ssgeg(OPNSLOT *slot, BYTE value) { +static void set_ssgeg(OPNSLOT *slot, REG8 value) { value &= 0xf; if ((value == 0xb) || (value == 0xd)) { @@ -346,7 +355,7 @@ static void set_ssgeg(OPNSLOT *slot, BYT } else { slot->ssgeg1 = 0; - slot->env_inc_decay2 = slot->decay2[slot->envraito]; + slot->env_inc_decay2 = slot->decay2[slot->envratio]; } if (slot->env_mode == EM_DECAY2) { slot->env_inc = slot->env_inc_decay2; @@ -357,8 +366,8 @@ static void channleupdate(OPNCH *ch) { int i; UINT32 fc = ch->keynote[0]; // ver0.27 - BYTE kc = ch->kcode[0]; - BYTE evr; + UINT8 kc = ch->kcode[0]; + UINT evr; OPNSLOT *slot; int s; @@ -366,9 +375,9 @@ 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); - if (slot->envraito != evr) { - slot->envraito = evr; + evr = kc >> slot->keyscale; + if (slot->envratio != evr) { + slot->envratio = evr; slot->env_inc_attack = slot->attack[evr]; slot->env_inc_decay1 = slot->decay1[evr]; slot->env_inc_decay2 = slot->decay2[evr]; @@ -381,9 +390,9 @@ 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); - if (slot->envraito != evr) { - slot->envraito = evr; + evr = ch->kcode[s] >> slot->keyscale; + if (slot->envratio != evr) { + slot->envratio = evr; slot->env_inc_attack = slot->attack[evr]; slot->env_inc_decay1 = slot->decay1[evr]; slot->env_inc_decay2 = slot->decay2[evr]; @@ -426,14 +435,14 @@ void opngen_reset(void) { ch++; } for (i=0x30; i<0xc0; i++) { - opngen_setreg(0, (BYTE)i, 0xff); - opngen_setreg(3, (BYTE)i, 0xff); - opngen_setreg(6, (BYTE)i, 0xff); - opngen_setreg(9, (BYTE)i, 0xff); + opngen_setreg(0, i, 0xff); + opngen_setreg(3, i, 0xff); + opngen_setreg(6, i, 0xff); + opngen_setreg(9, i, 0xff); } } -void opngen_setcfg(BYTE maxch, UINT flag) { +void opngen_setcfg(REG8 maxch, UINT32 flag) { OPNCH *ch; UINT i; @@ -460,7 +469,7 @@ void opngen_setcfg(BYTE maxch, UINT flag } } -void opngen_setextch(UINT chnum, BYTE data) { +void opngen_setextch(UINT chnum, REG8 data) { OPNCH *ch; @@ -468,13 +477,13 @@ void opngen_setextch(UINT chnum, BYTE da ch[chnum].extop = data; } -void opngen_setreg(BYTE chbase, BYTE reg, BYTE value) { +void opngen_setreg(REG8 chbase, UINT reg, REG8 value) { UINT chpos; OPNCH *ch; OPNSLOT *slot; UINT fn; - BYTE blk; + UINT8 blk; chpos = reg & 3; if (chpos == 3) { @@ -549,7 +558,7 @@ void opngen_setreg(BYTE chbase, BYTE 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,18 +570,18 @@ void opngen_setreg(BYTE chbase, BYTE reg break; case 0xb4: - ch->pan = (BYTE)(value & 0xc0); + ch->pan = (UINT8)(value & 0xc0); set_algorithm(ch); break; } } } -void opngen_keyon(UINT chnum, BYTE value) { +void opngen_keyon(UINT chnum, REG8 value) { OPNCH *ch; OPNSLOT *slot; - BYTE bit; + REG8 bit; UINT i; sound_sync(); @@ -609,6 +618,6 @@ void opngen_keyon(UINT chnum, BYTE value slot++; bit <<= 1; } - keydisp_fmkeyon((BYTE)chnum, value); + keydisp_fmkeyon((UINT8)chnum, value); }