1 #ifndef FMOPL_H 2 #define FMOPL_H 3 4 #include <stdint.h> 5 6 typedef void (*OPL_TIMERHANDLER)(int channel,double interval_Sec); 7 typedef void (*OPL_IRQHANDLER)(int param,int irq); 8 typedef void (*OPL_UPDATEHANDLER)(int param,int min_interval_us); 9 typedef void (*OPL_PORTHANDLER_W)(int param,unsigned char data); 10 typedef unsigned char (*OPL_PORTHANDLER_R)(int param); 11 12 /* !!!!! here is private section , do not access there member direct !!!!! */ 13 14 /* Saving is necessary for member of the 'R' mark for suspend/resume */ 15 /* ---------- OPL one of slot ---------- */ 16 typedef struct fm_opl_slot { 17 int32_t TL; /* total level :TL << 8 */ 18 int32_t TLL; /* adjusted now TL */ 19 uint8_t KSR; /* key scale rate :(shift down bit) */ 20 int32_t *AR; /* attack rate :&AR_TABLE[AR<<2] */ 21 int32_t *DR; /* decay rate :&DR_TALBE[DR<<2] */ 22 int32_t SL; /* sustin level :SL_TALBE[SL] */ 23 int32_t *RR; /* release rate :&DR_TABLE[RR<<2] */ 24 uint8_t ksl; /* keyscale level :(shift down bits) */ 25 uint8_t ksr; /* key scale rate :kcode>>KSR */ 26 uint32_t mul; /* multiple :ML_TABLE[ML] */ 27 uint32_t Cnt; /* frequency count : */ 28 uint32_t Incr; /* frequency step : */ 29 /* envelope generator state */ 30 uint8_t eg_typ; /* envelope type flag */ 31 uint8_t evm; /* envelope phase */ 32 int32_t evc; /* envelope counter */ 33 int32_t eve; /* envelope counter end point */ 34 int32_t evs; /* envelope counter step */ 35 int32_t evsa; /* envelope step for AR :AR[ksr] */ 36 int32_t evsd; /* envelope step for DR :DR[ksr] */ 37 int32_t evsr; /* envelope step for RR :RR[ksr] */ 38 /* LFO */ 39 uint8_t ams; /* ams flag */ 40 uint8_t vib; /* vibrate flag */ 41 /* wave selector */ 42 int32_t **wavetable; 43 }OPL_SLOT; 44 45 /* ---------- OPL one of channel ---------- */ 46 typedef struct fm_opl_channel { 47 OPL_SLOT SLOT[2]; 48 uint8_t CON; /* connection type */ 49 uint8_t FB; /* feed back :(shift down bit) */ 50 int32_t *connect1; /* slot1 output pointer */ 51 int32_t *connect2; /* slot2 output pointer */ 52 int32_t op1_out[2]; /* slot1 output for selfeedback */ 53 /* phase generator state */ 54 uint32_t block_fnum; /* block+fnum : */ 55 uint8_t kcode; /* key code : KeyScaleCode */ 56 uint32_t fc; /* Freq. Increment base */ 57 uint32_t ksl_base; /* KeyScaleLevel Base step */ 58 uint8_t keyon; /* key on/off flag */ 59 } OPL_CH; 60 61 /* OPL state */ 62 typedef struct fm_opl_f { 63 int clock; /* master clock (Hz) */ 64 int rate; /* sampling rate (Hz) */ 65 double freqbase; /* frequency base */ 66 double TimerBase; /* Timer base time (==sampling time) */ 67 uint8_t address; /* address register */ 68 uint8_t status; /* status flag */ 69 uint8_t statusmask; /* status mask */ 70 uint32_t mode; /* Reg.08 : CSM , notesel,etc. */ 71 /* Timer */ 72 int T[2]; /* timer counter */ 73 uint8_t st[2]; /* timer enable */ 74 /* FM channel slots */ 75 OPL_CH *P_CH; /* pointer of CH */ 76 int max_ch; /* maximum channel */ 77 /* Rhythm sention */ 78 uint8_t rhythm; /* Rhythm mode , key flag */ 79 /* time tables */ 80 int32_t AR_TABLE[75]; /* atttack rate tables */ 81 int32_t DR_TABLE[75]; /* decay rate tables */ 82 uint32_t FN_TABLE[1024]; /* fnumber -> increment counter */ 83 /* LFO */ 84 int32_t *ams_table; 85 int32_t *vib_table; 86 int32_t amsCnt; 87 int32_t amsIncr; 88 int32_t vibCnt; 89 int32_t vibIncr; 90 /* wave selector enable flag */ 91 uint8_t wavesel; 92 /* external event callback handler */ 93 OPL_TIMERHANDLER TimerHandler; /* TIMER handler */ 94 int TimerParam; /* TIMER parameter */ 95 OPL_UPDATEHANDLER UpdateHandler; /* stream update handler */ 96 int UpdateParam; /* stream update parameter */ 97 } FM_OPL; 98 99 /* ---------- Generic interface section ---------- */ 100 FM_OPL *OPLCreate(int clock, int rate); 101 void OPLDestroy(FM_OPL *OPL); 102 void OPLSetTimerHandler(FM_OPL *OPL,OPL_TIMERHANDLER TimerHandler,int channelOffset); 103 104 void OPLResetChip(FM_OPL *OPL); 105 int OPLWrite(FM_OPL *OPL,int a,int v); 106 unsigned char OPLRead(FM_OPL *OPL,int a); 107 int OPLTimerOver(FM_OPL *OPL,int c); 108 109 void YM3812UpdateOne(FM_OPL *OPL, int16_t *buffer, int length); 110 #endif 111