]>
Commit | Line | Data |
---|---|---|
2a6a4076 MA |
1 | #ifndef FMOPL_H |
2 | #define FMOPL_H | |
85571bc7 | 3 | |
4a796e97 JQ |
4 | #include <stdint.h> |
5 | ||
85571bc7 | 6 | typedef void (*OPL_TIMERHANDLER)(int channel,double interval_Sec); |
85571bc7 FB |
7 | |
8 | /* !!!!! here is private section , do not access there member direct !!!!! */ | |
9 | ||
85571bc7 FB |
10 | /* Saving is necessary for member of the 'R' mark for suspend/resume */ |
11 | /* ---------- OPL one of slot ---------- */ | |
12 | typedef struct fm_opl_slot { | |
7f643fb5 JQ |
13 | int32_t TL; /* total level :TL << 8 */ |
14 | int32_t TLL; /* adjusted now TL */ | |
4a796e97 | 15 | uint8_t KSR; /* key scale rate :(shift down bit) */ |
7f643fb5 JQ |
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] */ | |
4a796e97 JQ |
20 | uint8_t ksl; /* keyscale level :(shift down bits) */ |
21 | uint8_t ksr; /* key scale rate :kcode>>KSR */ | |
3795f180 JQ |
22 | uint32_t mul; /* multiple :ML_TABLE[ML] */ |
23 | uint32_t Cnt; /* frequency count : */ | |
24 | uint32_t Incr; /* frequency step : */ | |
85571bc7 | 25 | /* envelope generator state */ |
4a796e97 JQ |
26 | uint8_t eg_typ; /* envelope type flag */ |
27 | uint8_t evm; /* envelope phase */ | |
7f643fb5 JQ |
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] */ | |
85571bc7 | 34 | /* LFO */ |
4a796e97 JQ |
35 | uint8_t ams; /* ams flag */ |
36 | uint8_t vib; /* vibrate flag */ | |
85571bc7 | 37 | /* wave selector */ |
7f643fb5 | 38 | int32_t **wavetable; |
85571bc7 FB |
39 | }OPL_SLOT; |
40 | ||
41 | /* ---------- OPL one of channel ---------- */ | |
42 | typedef struct fm_opl_channel { | |
43 | OPL_SLOT SLOT[2]; | |
4a796e97 JQ |
44 | uint8_t CON; /* connection type */ |
45 | uint8_t FB; /* feed back :(shift down bit) */ | |
7f643fb5 JQ |
46 | int32_t *connect1; /* slot1 output pointer */ |
47 | int32_t *connect2; /* slot2 output pointer */ | |
48 | int32_t op1_out[2]; /* slot1 output for selfeedback */ | |
85571bc7 | 49 | /* phase generator state */ |
3795f180 | 50 | uint32_t block_fnum; /* block+fnum : */ |
4a796e97 | 51 | uint8_t kcode; /* key code : KeyScaleCode */ |
3795f180 JQ |
52 | uint32_t fc; /* Freq. Increment base */ |
53 | uint32_t ksl_base; /* KeyScaleLevel Base step */ | |
4a796e97 | 54 | uint8_t keyon; /* key on/off flag */ |
85571bc7 FB |
55 | } OPL_CH; |
56 | ||
57 | /* OPL state */ | |
58 | typedef struct fm_opl_f { | |
85571bc7 FB |
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) */ | |
4a796e97 JQ |
63 | uint8_t address; /* address register */ |
64 | uint8_t status; /* status flag */ | |
65 | uint8_t statusmask; /* status mask */ | |
3795f180 | 66 | uint32_t mode; /* Reg.08 : CSM , notesel,etc. */ |
85571bc7 FB |
67 | /* Timer */ |
68 | int T[2]; /* timer counter */ | |
4a796e97 | 69 | uint8_t st[2]; /* timer enable */ |
85571bc7 FB |
70 | /* FM channel slots */ |
71 | OPL_CH *P_CH; /* pointer of CH */ | |
72 | int max_ch; /* maximum channel */ | |
c11e80e2 | 73 | /* Rhythm sention */ |
4a796e97 | 74 | uint8_t rhythm; /* Rhythm mode , key flag */ |
85571bc7 | 75 | /* time tables */ |
7f643fb5 JQ |
76 | int32_t AR_TABLE[75]; /* atttack rate tables */ |
77 | int32_t DR_TABLE[75]; /* decay rate tables */ | |
3795f180 | 78 | uint32_t FN_TABLE[1024]; /* fnumber -> increment counter */ |
85571bc7 | 79 | /* LFO */ |
7f643fb5 JQ |
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; | |
85571bc7 | 86 | /* wave selector enable flag */ |
4a796e97 | 87 | uint8_t wavesel; |
85571bc7 FB |
88 | /* external event callback handler */ |
89 | OPL_TIMERHANDLER TimerHandler; /* TIMER handler */ | |
90 | int TimerParam; /* TIMER parameter */ | |
85571bc7 FB |
91 | } FM_OPL; |
92 | ||
93 | /* ---------- Generic interface section ---------- */ | |
8f7e2c2c | 94 | FM_OPL *OPLCreate(int clock, int rate); |
85571bc7 FB |
95 | void OPLDestroy(FM_OPL *OPL); |
96 | void OPLSetTimerHandler(FM_OPL *OPL,OPL_TIMERHANDLER TimerHandler,int channelOffset); | |
85571bc7 | 97 | |
85571bc7 FB |
98 | int OPLWrite(FM_OPL *OPL,int a,int v); |
99 | unsigned char OPLRead(FM_OPL *OPL,int a); | |
100 | int OPLTimerOver(FM_OPL *OPL,int c); | |
101 | ||
7bf10b1d | 102 | void YM3812UpdateOne(FM_OPL *OPL, int16_t *buffer, int length); |
85571bc7 | 103 | #endif |