2016-06-29 14:47:03 +03:00
|
|
|
#ifndef FMOPL_H
|
|
|
|
#define FMOPL_H
|
2004-11-07 21:04:02 +03:00
|
|
|
|
2017-04-26 01:37:18 +03:00
|
|
|
|
2017-06-21 07:34:00 +03:00
|
|
|
typedef void (*OPL_TIMERHANDLER)(void *param, int channel, double interval_Sec);
|
2004-11-07 21:04:02 +03:00
|
|
|
|
|
|
|
/* !!!!! here is private section , do not access there member direct !!!!! */
|
|
|
|
|
|
|
|
/* Saving is necessary for member of the 'R' mark for suspend/resume */
|
|
|
|
/* ---------- OPL one of slot ---------- */
|
|
|
|
typedef struct fm_opl_slot {
|
2017-04-26 01:37:23 +03:00
|
|
|
int32_t TL; /* total level :TL << 8 */
|
|
|
|
int32_t TLL; /* adjusted now TL */
|
2017-04-26 01:37:18 +03:00
|
|
|
uint8_t KSR; /* key scale rate :(shift down bit) */
|
2017-04-26 01:37:23 +03:00
|
|
|
int32_t *AR; /* attack rate :&AR_TABLE[AR<<2] */
|
|
|
|
int32_t *DR; /* decay rate :&DR_TALBE[DR<<2] */
|
|
|
|
int32_t SL; /* sustin level :SL_TALBE[SL] */
|
|
|
|
int32_t *RR; /* release rate :&DR_TABLE[RR<<2] */
|
2017-04-26 01:37:18 +03:00
|
|
|
uint8_t ksl; /* keyscale level :(shift down bits) */
|
|
|
|
uint8_t ksr; /* key scale rate :kcode>>KSR */
|
2017-04-26 01:37:20 +03:00
|
|
|
uint32_t mul; /* multiple :ML_TABLE[ML] */
|
|
|
|
uint32_t Cnt; /* frequency count : */
|
|
|
|
uint32_t Incr; /* frequency step : */
|
2004-11-07 21:04:02 +03:00
|
|
|
/* envelope generator state */
|
2017-04-26 01:37:18 +03:00
|
|
|
uint8_t eg_typ; /* envelope type flag */
|
|
|
|
uint8_t evm; /* envelope phase */
|
2017-04-26 01:37:23 +03:00
|
|
|
int32_t evc; /* envelope counter */
|
|
|
|
int32_t eve; /* envelope counter end point */
|
|
|
|
int32_t evs; /* envelope counter step */
|
|
|
|
int32_t evsa; /* envelope step for AR :AR[ksr] */
|
|
|
|
int32_t evsd; /* envelope step for DR :DR[ksr] */
|
|
|
|
int32_t evsr; /* envelope step for RR :RR[ksr] */
|
2004-11-07 21:04:02 +03:00
|
|
|
/* LFO */
|
2017-04-26 01:37:18 +03:00
|
|
|
uint8_t ams; /* ams flag */
|
|
|
|
uint8_t vib; /* vibrate flag */
|
2004-11-07 21:04:02 +03:00
|
|
|
/* wave selector */
|
2017-04-26 01:37:23 +03:00
|
|
|
int32_t **wavetable;
|
2004-11-07 21:04:02 +03:00
|
|
|
}OPL_SLOT;
|
|
|
|
|
|
|
|
/* ---------- OPL one of channel ---------- */
|
|
|
|
typedef struct fm_opl_channel {
|
|
|
|
OPL_SLOT SLOT[2];
|
2017-04-26 01:37:18 +03:00
|
|
|
uint8_t CON; /* connection type */
|
|
|
|
uint8_t FB; /* feed back :(shift down bit) */
|
2017-04-26 01:37:23 +03:00
|
|
|
int32_t *connect1; /* slot1 output pointer */
|
|
|
|
int32_t *connect2; /* slot2 output pointer */
|
|
|
|
int32_t op1_out[2]; /* slot1 output for selfeedback */
|
2004-11-07 21:04:02 +03:00
|
|
|
/* phase generator state */
|
2017-04-26 01:37:20 +03:00
|
|
|
uint32_t block_fnum; /* block+fnum : */
|
2017-04-26 01:37:18 +03:00
|
|
|
uint8_t kcode; /* key code : KeyScaleCode */
|
2017-04-26 01:37:20 +03:00
|
|
|
uint32_t fc; /* Freq. Increment base */
|
|
|
|
uint32_t ksl_base; /* KeyScaleLevel Base step */
|
2017-04-26 01:37:18 +03:00
|
|
|
uint8_t keyon; /* key on/off flag */
|
2004-11-07 21:04:02 +03:00
|
|
|
} OPL_CH;
|
|
|
|
|
|
|
|
/* OPL state */
|
|
|
|
typedef struct fm_opl_f {
|
|
|
|
int clock; /* master clock (Hz) */
|
|
|
|
int rate; /* sampling rate (Hz) */
|
|
|
|
double freqbase; /* frequency base */
|
|
|
|
double TimerBase; /* Timer base time (==sampling time) */
|
2017-04-26 01:37:18 +03:00
|
|
|
uint8_t address; /* address register */
|
|
|
|
uint8_t status; /* status flag */
|
|
|
|
uint8_t statusmask; /* status mask */
|
2017-04-26 01:37:20 +03:00
|
|
|
uint32_t mode; /* Reg.08 : CSM , notesel,etc. */
|
2004-11-07 21:04:02 +03:00
|
|
|
/* Timer */
|
|
|
|
int T[2]; /* timer counter */
|
2017-04-26 01:37:18 +03:00
|
|
|
uint8_t st[2]; /* timer enable */
|
2004-11-07 21:04:02 +03:00
|
|
|
/* FM channel slots */
|
|
|
|
OPL_CH *P_CH; /* pointer of CH */
|
|
|
|
int max_ch; /* maximum channel */
|
2011-12-10 03:19:42 +04:00
|
|
|
/* Rhythm sention */
|
2017-04-26 01:37:18 +03:00
|
|
|
uint8_t rhythm; /* Rhythm mode , key flag */
|
2004-11-07 21:04:02 +03:00
|
|
|
/* time tables */
|
2018-10-30 11:23:40 +03:00
|
|
|
int32_t AR_TABLE[76]; /* attack rate tables */
|
|
|
|
int32_t DR_TABLE[76]; /* decay rate tables */
|
2017-04-26 01:37:20 +03:00
|
|
|
uint32_t FN_TABLE[1024]; /* fnumber -> increment counter */
|
2004-11-07 21:04:02 +03:00
|
|
|
/* LFO */
|
2017-04-26 01:37:23 +03:00
|
|
|
int32_t *ams_table;
|
|
|
|
int32_t *vib_table;
|
|
|
|
int32_t amsCnt;
|
|
|
|
int32_t amsIncr;
|
|
|
|
int32_t vibCnt;
|
|
|
|
int32_t vibIncr;
|
2004-11-07 21:04:02 +03:00
|
|
|
/* wave selector enable flag */
|
2017-04-26 01:37:18 +03:00
|
|
|
uint8_t wavesel;
|
2004-11-07 21:04:02 +03:00
|
|
|
/* external event callback handler */
|
|
|
|
OPL_TIMERHANDLER TimerHandler; /* TIMER handler */
|
2017-06-21 07:34:00 +03:00
|
|
|
void *TimerParam; /* TIMER parameter */
|
2004-11-07 21:04:02 +03:00
|
|
|
} FM_OPL;
|
|
|
|
|
|
|
|
/* ---------- Generic interface section ---------- */
|
2017-04-26 01:37:26 +03:00
|
|
|
FM_OPL *OPLCreate(int clock, int rate);
|
2004-11-07 21:04:02 +03:00
|
|
|
void OPLDestroy(FM_OPL *OPL);
|
2017-06-21 07:34:00 +03:00
|
|
|
void OPLSetTimerHandler(FM_OPL *OPL, OPL_TIMERHANDLER TimerHandler,
|
|
|
|
void *param);
|
2004-11-07 21:04:02 +03:00
|
|
|
|
|
|
|
int OPLWrite(FM_OPL *OPL,int a,int v);
|
|
|
|
unsigned char OPLRead(FM_OPL *OPL,int a);
|
|
|
|
int OPLTimerOver(FM_OPL *OPL,int c);
|
|
|
|
|
2017-04-26 01:37:22 +03:00
|
|
|
void YM3812UpdateOne(FM_OPL *OPL, int16_t *buffer, int length);
|
2004-11-07 21:04:02 +03:00
|
|
|
#endif
|