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