--- np2/sound/opngenc.c 2003/10/18 07:28:50 1.2 +++ np2/sound/opngenc.c 2003/11/28 08:01:33 1.7 @@ -18,9 +18,6 @@ OPNCFG opncfg; - SINT32 env_curve[EVC_ENT*2 + 1]; - SINT32 envtable[EVC_ENT]; - SINT32 sintable[SIN_ENT]; #ifdef OPNGENX86 char envshift[EVC_ENT]; char sinshift[SIN_ENT]; @@ -71,16 +68,16 @@ void opngen_initialize(UINT rate) { sft = ENVTBL_BIT; while(sft < (ENVTBL_BIT + 8)) { pom = (double)(1 << sft) / pow(10.0, EG_STEP*(EVC_ENT-i)/20.0); - envtable[i] = (long)pom; + opncfg.envtable[i] = (long)pom; envshift[i] = sft - TL_BITS; - if (envtable[i] >= (1 << (ENVTBL_BIT - 1))) { + if (opncfg.envtable[i] >= (1 << (ENVTBL_BIT - 1))) { break; } sft++; } #else pom = (double)(1 << ENVTBL_BIT) / pow(10.0, EG_STEP*(EVC_ENT-i)/20.0); - envtable[i] = (long)pom; + opncfg.envtable[i] = (long)pom; #endif } for (i=0; i= (1 << (SINTBL_BIT - 1))) { + if (opncfg.sintable[i] >= (1 << (SINTBL_BIT - 1))) { break; } - if (sintable[i] <= -1 * (1 << (SINTBL_BIT - 1))) { + if (opncfg.sintable[i] <= -1 * (1 << (SINTBL_BIT - 1))) { break; } sft++; } #else pom = (double)((1 << SINTBL_BIT) - 1) * sin(2*PI*i/SIN_ENT); - sintable[i] = (long)pom; // ver0.27 + opncfg.sintable[i] = (long)pom; #endif } for (i=0; i> 2) - 1)); +#if 0 + attacktable[i] = (long)((freq + OPM_ARRATE - 1) / OPM_ARRATE); + decaytable[i] = (long)((freq + OPM_DRRATE - 1) / OPM_DRRATE); +#else attacktable[i] = (long)(freq / OPM_ARRATE); decaytable[i] = (long)(freq / OPM_DRRATE); +#endif + if (attacktable[i] >= EC_DECAY) { + TRACEOUT(("attacktable %d %d %d", i, attacktable[i], EC_DECAY)); + } + if (decaytable[i] >= EC_DECAY) { + TRACEOUT(("decaytable %d %d %d", i, decaytable[i], EC_DECAY)); + } } attacktable[62] = EC_DECAY - 1; attacktable[63] = EC_DECAY - 1; @@ -169,12 +177,25 @@ void opngen_setvol(UINT vol) { #endif } +void opngen_setVR(BYTE channel, BYTE value) { + + if ((channel & 3) && (value)) { + opncfg.vr_en = TRUE; + opncfg.vr_l = (channel & 1)?value:0; + opncfg.vr_r = (channel & 2)?value:0; + } + else { + opncfg.vr_en = FALSE; + } +} + // ---- static void set_algorithm(OPNCH *ch) { SINT32 *outd; + BYTE outslot; outd = &opngen.outdc; if (ch->stereo) { @@ -193,42 +214,49 @@ static void set_algorithm(OPNCH *ch) { ch->connect1 = &opngen.feedback2; ch->connect2 = &opngen.feedback3; ch->connect3 = &opngen.feedback4; + outslot = 0x08; break; case 1: ch->connect1 = &opngen.feedback3; ch->connect2 = &opngen.feedback3; ch->connect3 = &opngen.feedback4; + outslot = 0x08; break; case 2: ch->connect1 = &opngen.feedback4; ch->connect2 = &opngen.feedback3; ch->connect3 = &opngen.feedback4; + outslot = 0x08; break; case 3: ch->connect1 = &opngen.feedback2; ch->connect2 = &opngen.feedback4; ch->connect3 = &opngen.feedback4; + outslot = 0x08; break; case 4: ch->connect1 = &opngen.feedback2; ch->connect2 = outd; ch->connect3 = &opngen.feedback4; + outslot = 0x0a; break; case 5: ch->connect1 = 0; ch->connect2 = outd; ch->connect3 = outd; + outslot = 0x0e; break; case 6: ch->connect1 = &opngen.feedback2; ch->connect2 = outd; ch->connect3 = outd; + outslot = 0x0e; break; case 7: @@ -236,8 +264,10 @@ static void set_algorithm(OPNCH *ch) { ch->connect1 = outd; ch->connect2 = outd; ch->connect3 = outd; + outslot = 0x0f; } ch->connect4 = outd; + ch->outslot = outslot; } static void set_dt1_mul(OPNSLOT *slot, BYTE value) { @@ -248,7 +278,11 @@ static void set_dt1_mul(OPNSLOT *slot, B static void set_tl(OPNSLOT *slot, BYTE value) { +#if (EVC_BITS >= 7) slot->totallevel = ((~value) & 0x007f) << (EVC_BITS - 7); +#else + slot->totallevel = ((~value) & 0x007f) >> (7 - EVC_BITS); +#endif } static void set_ks_ar(OPNSLOT *slot, BYTE value) { @@ -297,7 +331,7 @@ static void set_d1l_rr(OPNSLOT *slot, BY if (value == 0xff) { slot->env_mode = EM_OFF; slot->env_cnt = EC_OFF; - slot->env_end = EC_OFF+1; + slot->env_end = EC_OFF + 1; slot->env_inc = 0; } } @@ -392,10 +426,10 @@ void opngen_reset(void) { ch++; } for (i=0x30; i<0xc0; i++) { - opngen_setreg((BYTE)i, 0xff, 0); - opngen_setreg((BYTE)i, 0xff, 3); - opngen_setreg((BYTE)i, 0xff, 6); - opngen_setreg((BYTE)i, 0xff, 9); + opngen_setreg(0, (BYTE)i, 0xff); + opngen_setreg(3, (BYTE)i, 0xff); + opngen_setreg(6, (BYTE)i, 0xff); + opngen_setreg(9, (BYTE)i, 0xff); } } @@ -543,7 +577,9 @@ void opngen_keyon(UINT chnum, BYTE value sound_sync(); opngen.keyreg[chnum] = value; + opngen.playing++; ch = opnch + chnum; + ch->playing |= value >> 4; slot = ch->slot; bit = 0x10; for (i=0; i<4; i++) { @@ -563,8 +599,8 @@ void opngen_keyon(UINT chnum, BYTE value if (slot->env_mode > EM_RELEASE) { slot->env_mode = EM_RELEASE; if (!(slot->env_cnt & EC_DECAY)) { - slot->env_cnt = (env_curve[slot->env_cnt >> ENV_BITS] - << ENV_BITS) + EC_DECAY; + slot->env_cnt = (opncfg.envcurve[slot->env_cnt + >> ENV_BITS] << ENV_BITS) + EC_DECAY; } slot->env_end = EC_OFF; slot->env_inc = slot->env_inc_release;