blob: 89086b93f449e47da6976971f27320b06894ec4c [file] [log] [blame]
Markus Armbruster2a6a4072016-06-29 13:47:03 +02001#ifndef FMOPL_H
2#define FMOPL_H
bellard85571bc2004-11-07 18:04:02 +00003
Juan Quintela4a796e92017-04-26 00:37:18 +02004
Hervé Poussineauc57fbf52017-06-21 06:34:00 +02005typedef void (*OPL_TIMERHANDLER)(void *param, int channel, double interval_Sec);
bellard85571bc2004-11-07 18:04:02 +00006
7/* !!!!! here is private section , do not access there member direct !!!!! */
8
bellard85571bc2004-11-07 18:04:02 +00009/* Saving is necessary for member of the 'R' mark for suspend/resume */
10/* ---------- OPL one of slot ---------- */
11typedef struct fm_opl_slot {
Juan Quintela7f643fb2017-04-26 00:37:23 +020012 int32_t TL; /* total level :TL << 8 */
13 int32_t TLL; /* adjusted now TL */
Juan Quintela4a796e92017-04-26 00:37:18 +020014 uint8_t KSR; /* key scale rate :(shift down bit) */
Juan Quintela7f643fb2017-04-26 00:37:23 +020015 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 Quintela4a796e92017-04-26 00:37:18 +020019 uint8_t ksl; /* keyscale level :(shift down bits) */
20 uint8_t ksr; /* key scale rate :kcode>>KSR */
Juan Quintela3795f182017-04-26 00:37:20 +020021 uint32_t mul; /* multiple :ML_TABLE[ML] */
22 uint32_t Cnt; /* frequency count : */
23 uint32_t Incr; /* frequency step : */
bellard85571bc2004-11-07 18:04:02 +000024 /* envelope generator state */
Juan Quintela4a796e92017-04-26 00:37:18 +020025 uint8_t eg_typ; /* envelope type flag */
26 uint8_t evm; /* envelope phase */
Juan Quintela7f643fb2017-04-26 00:37:23 +020027 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] */
bellard85571bc2004-11-07 18:04:02 +000033 /* LFO */
Juan Quintela4a796e92017-04-26 00:37:18 +020034 uint8_t ams; /* ams flag */
35 uint8_t vib; /* vibrate flag */
bellard85571bc2004-11-07 18:04:02 +000036 /* wave selector */
Juan Quintela7f643fb2017-04-26 00:37:23 +020037 int32_t **wavetable;
bellard85571bc2004-11-07 18:04:02 +000038}OPL_SLOT;
39
40/* ---------- OPL one of channel ---------- */
41typedef struct fm_opl_channel {
42 OPL_SLOT SLOT[2];
Juan Quintela4a796e92017-04-26 00:37:18 +020043 uint8_t CON; /* connection type */
44 uint8_t FB; /* feed back :(shift down bit) */
Juan Quintela7f643fb2017-04-26 00:37:23 +020045 int32_t *connect1; /* slot1 output pointer */
46 int32_t *connect2; /* slot2 output pointer */
47 int32_t op1_out[2]; /* slot1 output for selfeedback */
bellard85571bc2004-11-07 18:04:02 +000048 /* phase generator state */
Juan Quintela3795f182017-04-26 00:37:20 +020049 uint32_t block_fnum; /* block+fnum : */
Juan Quintela4a796e92017-04-26 00:37:18 +020050 uint8_t kcode; /* key code : KeyScaleCode */
Juan Quintela3795f182017-04-26 00:37:20 +020051 uint32_t fc; /* Freq. Increment base */
52 uint32_t ksl_base; /* KeyScaleLevel Base step */
Juan Quintela4a796e92017-04-26 00:37:18 +020053 uint8_t keyon; /* key on/off flag */
bellard85571bc2004-11-07 18:04:02 +000054} OPL_CH;
55
56/* OPL state */
57typedef struct fm_opl_f {
bellard85571bc2004-11-07 18:04:02 +000058 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 Quintela4a796e92017-04-26 00:37:18 +020062 uint8_t address; /* address register */
63 uint8_t status; /* status flag */
64 uint8_t statusmask; /* status mask */
Juan Quintela3795f182017-04-26 00:37:20 +020065 uint32_t mode; /* Reg.08 : CSM , notesel,etc. */
bellard85571bc2004-11-07 18:04:02 +000066 /* Timer */
67 int T[2]; /* timer counter */
Juan Quintela4a796e92017-04-26 00:37:18 +020068 uint8_t st[2]; /* timer enable */
bellard85571bc2004-11-07 18:04:02 +000069 /* FM channel slots */
70 OPL_CH *P_CH; /* pointer of CH */
71 int max_ch; /* maximum channel */
Michael Tokarev528ea572023-07-14 14:30:34 +030072 /* Rhythm section */
Juan Quintela4a796e92017-04-26 00:37:18 +020073 uint8_t rhythm; /* Rhythm mode , key flag */
bellard85571bc2004-11-07 18:04:02 +000074 /* time tables */
Gerd Hoffmann57ac4a72018-10-30 09:23:40 +010075 int32_t AR_TABLE[76]; /* attack rate tables */
76 int32_t DR_TABLE[76]; /* decay rate tables */
Juan Quintela3795f182017-04-26 00:37:20 +020077 uint32_t FN_TABLE[1024]; /* fnumber -> increment counter */
bellard85571bc2004-11-07 18:04:02 +000078 /* LFO */
Juan Quintela7f643fb2017-04-26 00:37:23 +020079 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;
bellard85571bc2004-11-07 18:04:02 +000085 /* wave selector enable flag */
Juan Quintela4a796e92017-04-26 00:37:18 +020086 uint8_t wavesel;
bellard85571bc2004-11-07 18:04:02 +000087 /* external event callback handler */
88 OPL_TIMERHANDLER TimerHandler; /* TIMER handler */
Hervé Poussineauc57fbf52017-06-21 06:34:00 +020089 void *TimerParam; /* TIMER parameter */
bellard85571bc2004-11-07 18:04:02 +000090} FM_OPL;
91
92/* ---------- Generic interface section ---------- */
Juan Quintela8f7e2c22017-04-26 00:37:26 +020093FM_OPL *OPLCreate(int clock, int rate);
bellard85571bc2004-11-07 18:04:02 +000094void OPLDestroy(FM_OPL *OPL);
Hervé Poussineauc57fbf52017-06-21 06:34:00 +020095void OPLSetTimerHandler(FM_OPL *OPL, OPL_TIMERHANDLER TimerHandler,
96 void *param);
bellard85571bc2004-11-07 18:04:02 +000097
bellard85571bc2004-11-07 18:04:02 +000098int OPLWrite(FM_OPL *OPL,int a,int v);
99unsigned char OPLRead(FM_OPL *OPL,int a);
100int OPLTimerOver(FM_OPL *OPL,int c);
101
Juan Quintela7bf10b12017-04-26 00:37:22 +0200102void YM3812UpdateOne(FM_OPL *OPL, int16_t *buffer, int length);
bellard85571bc2004-11-07 18:04:02 +0000103#endif