ScummVM API documentation
mame.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * LGPL licensed version of MAMEs fmopl (V0.37a modified) by
21 * Tatsuyuki Satoh. Included from LGPL'ed AdPlug.
22 *
23 */
24
25
26#ifndef AUDIO_SOFTSYNTH_OPL_MAME_H
27#define AUDIO_SOFTSYNTH_OPL_MAME_H
28
29#ifndef DISABLE_MAME_OPL
30
31#include "common/scummsys.h"
32#include "common/random.h"
33
34#include "audio/fmopl.h"
35
36namespace OPL {
37namespace MAME {
38
39enum {
40 FMOPL_ENV_BITS_HQ = 16,
41 FMOPL_ENV_BITS_MQ = 8,
42 FMOPL_ENV_BITS_LQ = 8,
43 FMOPL_EG_ENT_HQ = 4096,
44 FMOPL_EG_ENT_MQ = 1024,
45 FMOPL_EG_ENT_LQ = 128
46};
47
48
49typedef void (*OPL_TIMERHANDLER)(int channel,double interval_Sec);
50typedef void (*OPL_IRQHANDLER)(int param,int irq);
51typedef void (*OPL_UPDATEHANDLER)(int param,int min_interval_us);
52
53#define OPL_TYPE_WAVESEL 0x01 /* waveform select */
54
55/* Saving is necessary for member of the 'R' mark for suspend/resume */
56/* ---------- OPL one of slot ---------- */
57typedef struct fm_opl_slot {
58 int TL; /* total level :TL << 8 */
59 int TLL; /* adjusted now TL */
60 uint8 KSR; /* key scale rate :(shift down bit) */
61 int *AR; /* attack rate :&AR_TABLE[AR<<2] */
62 int *DR; /* decay rate :&DR_TABLE[DR<<2] */
63 int SL; /* sustain level :SL_TABLE[SL] */
64 int *RR; /* release rate :&DR_TABLE[RR<<2] */
65 uint8 ksl; /* keyscale level :(shift down bits) */
66 uint8 ksr; /* key scale rate :kcode>>KSR */
67 uint mul; /* multiple :ML_TABLE[ML] */
68 uint Cnt; /* frequency count */
69 uint Incr; /* frequency step */
70
71 /* envelope generator state */
72 uint8 eg_typ;/* envelope type flag */
73 uint8 evm; /* envelope phase */
74 int evc; /* envelope counter */
75 int eve; /* envelope counter end point */
76 int evs; /* envelope counter step */
77 int evsa; /* envelope step for AR :AR[ksr] */
78 int evsd; /* envelope step for DR :DR[ksr] */
79 int evsr; /* envelope step for RR :RR[ksr] */
80
81 /* LFO */
82 uint8 ams; /* ams flag */
83 uint8 vib; /* vibrate flag */
84 /* wave selector */
85 int **wavetable;
86} OPL_SLOT;
87
88/* ---------- OPL one of channel ---------- */
89typedef struct fm_opl_channel {
90 OPL_SLOT SLOT[2];
91 uint8 CON; /* connection type */
92 uint8 FB; /* feed back :(shift down bit)*/
93 int *connect1; /* slot1 output pointer */
94 int *connect2; /* slot2 output pointer */
95 int op1_out[2]; /* slot1 output for selfeedback */
96
97 /* phase generator state */
98 uint block_fnum; /* block+fnum */
99 uint8 kcode; /* key code : KeyScaleCode */
100 uint fc; /* Freq. Increment base */
101 uint ksl_base; /* KeyScaleLevel Base step */
102 uint8 keyon; /* key on/off flag */
103} OPL_CH;
104
105/* OPL state */
106typedef struct fm_opl_f {
107 uint8 type; /* chip type */
108 int clock; /* master clock (Hz) */
109 int rate; /* sampling rate (Hz) */
110 double freqbase; /* frequency base */
111 double TimerBase; /* Timer base time (==sampling time) */
112 uint8 address; /* address register */
113 uint8 status; /* status flag */
114 uint8 statusmask; /* status mask */
115 uint mode; /* Reg.08 : CSM , notesel,etc. */
116
117 /* Timer */
118 int T[2]; /* timer counter */
119 uint8 st[2]; /* timer enable */
120
121 /* FM channel slots */
122 OPL_CH *P_CH; /* pointer of CH */
123 int max_ch; /* maximum channel */
124
125 /* Rhythm sention */
126 uint8 rhythm; /* Rhythm mode , key flag */
127
128 /* time tables */
129 int AR_TABLE[76]; /* atttack rate tables */
130 int DR_TABLE[76]; /* decay rate tables */
131 uint FN_TABLE[1024];/* fnumber -> increment counter */
132
133 /* LFO */
134 int *ams_table;
135 int *vib_table;
136 int amsCnt;
137 int amsIncr;
138 int vibCnt;
139 int vibIncr;
140
141 /* wave selector enable flag */
142 uint8 wavesel;
143
144 /* external event callback handler */
145 OPL_TIMERHANDLER TimerHandler; /* TIMER handler */
146 int TimerParam; /* TIMER parameter */
147 OPL_IRQHANDLER IRQHandler; /* IRQ handler */
148 int IRQParam; /* IRQ parameter */
149 OPL_UPDATEHANDLER UpdateHandler; /* stream update handler */
150 int UpdateParam; /* stream update parameter */
151
153} FM_OPL;
154
155/* ---------- Generic interface section ---------- */
156#define OPL_TYPE_YM3526 (0)
157#define OPL_TYPE_YM3812 (OPL_TYPE_WAVESEL)
158
159void OPLBuildTables(int ENV_BITS_PARAM, int EG_ENT_PARAM);
160
161FM_OPL *OPLCreate(int type, int clock, int rate);
162void OPLDestroy(FM_OPL *OPL);
163void OPLSetTimerHandler(FM_OPL *OPL, OPL_TIMERHANDLER TimerHandler, int channelOffset);
164void OPLSetIRQHandler(FM_OPL *OPL, OPL_IRQHANDLER IRQHandler, int param);
165void OPLSetUpdateHandler(FM_OPL *OPL, OPL_UPDATEHANDLER UpdateHandler, int param);
166
167void OPLResetChip(FM_OPL *OPL);
168int OPLWrite(FM_OPL *OPL, int a, int v);
169unsigned char OPLRead(FM_OPL *OPL, int a);
170int OPLTimerOver(FM_OPL *OPL, int c);
171void OPLWriteReg(FM_OPL *OPL, int r, int v);
172void YM3812UpdateOne(FM_OPL *OPL, int16 *buffer, int length);
173
174// Factory method
175FM_OPL *makeAdLibOPL(int rate);
176
177// OPL API implementation
178class OPL : public ::OPL::OPL, public Audio::EmulatedChip {
179private:
180 FM_OPL *_opl;
181public:
182 OPL() : _opl(0) {}
183 ~OPL();
184
185 bool init() override;
186 void reset() override;
187
188 void write(int a, int v) override;
189
190 void writeReg(int r, int v) override;
191
192 bool isStereo() const override { return false; }
193
194protected:
195 void generateSamples(int16 *buffer, int length) override;
196};
197
198} // End of namespace MAME
199} // End of namespace OPL
200
201#endif // !DISABLE_MAME_OPL
202
203#endif
Definition: chip.h:112
Definition: random.h:44
Definition: mame.h:178
void reset() override
bool isStereo() const override
Definition: mame.h:192
void generateSamples(int16 *buffer, int length) override
void write(int a, int v) override
void writeReg(int r, int v) override
bool init() override
Definition: fmopl.h:116
Definition: mame.h:89
Definition: mame.h:106
Definition: mame.h:57