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