|
|
| version 1.3, 2003/10/18 09:02:38 | version 1.7, 2003/11/28 08:01:33 |
|---|---|
| Line 5 | Line 5 |
| #include "fmboard.h" | #include "fmboard.h" |
| extern OPNCFG opncfg; | #if defined(OPNGENX86) |
| #error use opngen.x86 | |
| extern SINT32 env_curve[]; // ver0.27 | #endif |
| extern SINT32 envtable[]; | |
| extern SINT32 sintable[]; // ver0.27 | |
| #define SLOTOUT(s, e, c) \ | extern OPNCFG opncfg; |
| ((sintable[(((s).freq_cnt + (c)) >> (FREQ_BITS - SIN_BITS)) & \ | |
| (SIN_ENT-1)] * envtable[(e)]) >> (ENVTBL_BIT+SINTBL_BIT-TL_BITS)) | |
| static SINT32 calcrateenvlope(OPNSLOT *slot) { | |
| /* calcrate phage generator */ | |
| slot->freq_cnt += slot->freq_inc; | |
| /* calcrate envelope generator */ | |
| slot->env_cnt += slot->env_inc; | |
| if (slot->env_cnt >= slot->env_end) { | |
| switch(slot->env_mode) { | |
| case EM_ATTACK: // DECAY1 start | |
| slot->env_mode = EM_DECAY1; | |
| slot->env_cnt = EC_DECAY; | |
| slot->env_end = slot->decaylevel; | |
| slot->env_inc = slot->env_inc_decay1; | |
| break; | |
| case EM_DECAY1: // DECAY2 start | #define CALCENV(e, c, s) \ |
| slot->env_mode = EM_DECAY2; | (c)->slot[(s)].freq_cnt += (c)->slot[(s)].freq_inc; \ |
| slot->env_cnt = slot->decaylevel; | (c)->slot[(s)].env_cnt += (c)->slot[(s)].env_inc; \ |
| slot->env_end = EC_OFF; | if ((c)->slot[(s)].env_cnt >= (c)->slot[(s)].env_end) { \ |
| slot->env_inc = slot->env_inc_decay2; | switch((c)->slot[(s)].env_mode) { \ |
| break; | case EM_ATTACK: \ |
| (c)->slot[(s)].env_mode = EM_DECAY1; \ | |
| (c)->slot[(s)].env_cnt = EC_DECAY; \ | |
| (c)->slot[(s)].env_end = (c)->slot[(s)].decaylevel; \ | |
| (c)->slot[(s)].env_inc = (c)->slot[(s)].env_inc_decay1; \ | |
| break; \ | |
| case EM_DECAY1: \ | |
| (c)->slot[(s)].env_mode = EM_DECAY2; \ | |
| (c)->slot[(s)].env_cnt = (c)->slot[(s)].decaylevel; \ | |
| (c)->slot[(s)].env_end = EC_OFF; \ | |
| (c)->slot[(s)].env_inc = (c)->slot[(s)].env_inc_decay2; \ | |
| break; \ | |
| case EM_RELEASE: \ | |
| (c)->slot[(s)].env_mode = EM_OFF; \ | |
| case EM_DECAY2: \ | |
| (c)->slot[(s)].env_cnt = EC_OFF; \ | |
| (c)->slot[(s)].env_end = EC_OFF + 1; \ | |
| (c)->slot[(s)].env_inc = 0; \ | |
| (c)->playing &= ~(1 << (s)); \ | |
| break; \ | |
| } \ | |
| } \ | |
| (e) = (c)->slot[(s)].totallevel - \ | |
| opncfg.envcurve[(c)->slot[(s)].env_cnt >> ENV_BITS]; | |
| case EM_RELEASE: // OFF timing | #define SLOTOUT(s, e, c) \ |
| slot->env_mode = EM_OFF; | ((opncfg.sintable[(((s).freq_cnt + (c)) >> \ |
| (FREQ_BITS - SIN_BITS)) & (SIN_ENT-1)] * \ | |
| opncfg.envtable[(e)]) >> (ENVTBL_BIT+SINTBL_BIT-TL_BITS)) | |
| case EM_DECAY2: // DECAY end | |
| slot->env_cnt = EC_OFF; | |
| slot->env_end = EC_OFF + 1; | |
| slot->env_inc = 0; | |
| break; | |
| } | |
| } | |
| return(slot->totallevel - env_curve[slot->env_cnt >> ENV_BITS]); | |
| } | |
| static void calcratechannel(OPNCH *ch) { | static void calcratechannel(OPNCH *ch) { |
| Line 61 static void calcratechannel(OPNCH *ch) { | Line 59 static void calcratechannel(OPNCH *ch) { |
| opngen.feedback4 = 0; | opngen.feedback4 = 0; |
| /* SLOT 1 */ | /* SLOT 1 */ |
| envout = calcrateenvlope(ch->slot + 0); | CALCENV(envout, ch, 0); |
| if (envout > 0) { | if (envout > 0) { |
| if (ch->feedback) { | if (ch->feedback) { |
| /* with self feed back */ | /* with self feed back */ |
| Line 83 static void calcratechannel(OPNCH *ch) { | Line 81 static void calcratechannel(OPNCH *ch) { |
| } | } |
| } | } |
| /* SLOT 2 */ | /* SLOT 2 */ |
| envout = calcrateenvlope(ch->slot + 1); | CALCENV(envout, ch, 1); |
| if (envout > 0) { | if (envout > 0) { |
| *ch->connect2 += SLOTOUT(ch->slot[1], envout, opngen.feedback2); | *ch->connect2 += SLOTOUT(ch->slot[1], envout, opngen.feedback2); |
| } | } |
| /* SLOT 3 */ | /* SLOT 3 */ |
| envout = calcrateenvlope(ch->slot + 2); | CALCENV(envout, ch, 2); |
| if (envout > 0) { | if (envout > 0) { |
| *ch->connect3 += SLOTOUT(ch->slot[2], envout, opngen.feedback3); | *ch->connect3 += SLOTOUT(ch->slot[2], envout, opngen.feedback3); |
| } | } |
| /* SLOT 4 */ | /* SLOT 4 */ |
| envout = calcrateenvlope(ch->slot + 3); | CALCENV(envout, ch, 3); |
| if (envout > 0) { | if (envout > 0) { |
| *ch->connect4 += SLOTOUT(ch->slot[3], envout, opngen.feedback4); | *ch->connect4 += SLOTOUT(ch->slot[3], envout, opngen.feedback4); |
| } | } |
| Line 103 void SOUNDCALL opngen_getpcm(void *hdl, | Line 101 void SOUNDCALL opngen_getpcm(void *hdl, |
| OPNCH *fm; | OPNCH *fm; |
| UINT i; | UINT i; |
| UINT playing; | |
| SINT32 samp_l; | SINT32 samp_l; |
| SINT32 samp_r; | SINT32 samp_r; |
| if ((!opngen.playing) || (!count)) { | |
| return; | |
| } | |
| fm = opnch; | fm = opnch; |
| while(count--) { | do { |
| samp_l = opngen.outdl * (opngen.calcremain * -1); | samp_l = opngen.outdl * (opngen.calcremain * -1); |
| samp_r = opngen.outdr * (opngen.calcremain * -1); | samp_r = opngen.outdr * (opngen.calcremain * -1); |
| opngen.calcremain += FMDIV_ENT; | opngen.calcremain += FMDIV_ENT; |
| Line 115 void SOUNDCALL opngen_getpcm(void *hdl, | Line 117 void SOUNDCALL opngen_getpcm(void *hdl, |
| opngen.outdc = 0; | opngen.outdc = 0; |
| opngen.outdl = 0; | opngen.outdl = 0; |
| opngen.outdr = 0; | opngen.outdr = 0; |
| playing = 0; | |
| for (i=0; i<opngen.playchannels; i++) { | for (i=0; i<opngen.playchannels; i++) { |
| calcratechannel(fm + i); | if (fm[i].playing & fm[i].outslot) { |
| calcratechannel(fm + i); | |
| playing++; | |
| } | |
| } | } |
| opngen.outdl += opngen.outdc; | opngen.outdl += opngen.outdc; |
| opngen.outdr += opngen.outdc; | opngen.outdr += opngen.outdc; |
| Line 143 void SOUNDCALL opngen_getpcm(void *hdl, | Line 149 void SOUNDCALL opngen_getpcm(void *hdl, |
| pcm[1] += samp_r; | pcm[1] += samp_r; |
| opngen.calcremain -= opncfg.calc1024; | opngen.calcremain -= opncfg.calc1024; |
| pcm += 2; | pcm += 2; |
| } | } while(--count); |
| opngen.playing = playing; | |
| (void)hdl; | (void)hdl; |
| } | } |