forked from crazyqk2019/libretro-px68k
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfmgeninl.h
268 lines (226 loc) · 4.52 KB
/
fmgeninl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
// ---------------------------------------------------------------------------
// FM Sound Generator
// Copyright (C) cisc 1998, 2003.
// ---------------------------------------------------------------------------
// $fmgen-Id: fmgeninl.h,v 1.26 2003/06/12 13:14:36 cisc Exp $
#ifndef FM_GEN_INL_H
#define FM_GEN_INL_H
// ---------------------------------------------------------------------------
// 定数その2
//
#define FM_PI 3.14159265358979323846
#define FM_SINEPRESIS 2 // EGとサイン波の精度の差 0(低)-2(高)
#define FM_OPSINBITS 10
#define FM_OPSINENTS (1 << FM_OPSINBITS)
#define FM_EGCBITS 18 // eg の count のシフト値
#define FM_LFOCBITS 14
#ifdef FM_TUNEBUILD
#define FM_PGBITS 2
#define FM_RATIOBITS 0
#else
#define FM_PGBITS 9
#define FM_RATIOBITS 7 // 8-12 くらいまで?
#endif
#define FM_EGBITS 16
//extern int paramcount[];
//#define PARAMCHANGE(i) paramcount[i]++;
#define PARAMCHANGE(i)
namespace FM
{
// ---------------------------------------------------------------------------
// Operator
//
// フィードバックバッファをクリア
inline void Operator::ResetFB()
{
out_ = out2_ = 0;
}
// キーオン
inline void Operator::KeyOn()
{
if (!keyon_)
{
keyon_ = true;
if (eg_phase_ == off || eg_phase_ == release)
{
ssg_phase_ = -1;
ShiftPhase(attack);
EGUpdate();
in2_ = out_ = out2_ = 0;
pg_count_ = 0;
}
}
}
// キーオフ
inline void Operator::KeyOff()
{
if (keyon_)
{
keyon_ = false;
ShiftPhase(release);
}
}
// オペレータは稼働中か?
inline int Operator::IsOn()
{
return eg_phase_ - off;
}
// Detune (0-7)
inline void Operator::SetDT(uint dt)
{
detune_ = dt * 0x20, param_changed_ = true;
PARAMCHANGE(4);
}
// DT2 (0-3)
inline void Operator::SetDT2(uint dt2)
{
detune2_ = dt2 & 3, param_changed_ = true;
PARAMCHANGE(5);
}
// Multiple (0-15)
inline void Operator::SetMULTI(uint mul)
{
multiple_ = mul, param_changed_ = true;
PARAMCHANGE(6);
}
// Total Level (0-127) (0.75dB step)
inline void Operator::SetTL(uint tl, bool csm)
{
if (!csm)
{
tl_ = tl, param_changed_ = true;
PARAMCHANGE(7);
}
tl_latch_ = tl;
}
// Attack Rate (0-63)
inline void Operator::SetAR(uint ar)
{
ar_ = ar;
param_changed_ = true;
PARAMCHANGE(8);
}
// Decay Rate (0-63)
inline void Operator::SetDR(uint dr)
{
dr_ = dr;
param_changed_ = true;
PARAMCHANGE(9);
}
// Sustain Rate (0-63)
inline void Operator::SetSR(uint sr)
{
sr_ = sr;
param_changed_ = true;
PARAMCHANGE(10);
}
// Sustain Level (0-127)
inline void Operator::SetSL(uint sl)
{
sl_ = sl;
param_changed_ = true;
PARAMCHANGE(11);
}
// Release Rate (0-63)
inline void Operator::SetRR(uint rr)
{
rr_ = rr;
param_changed_ = true;
PARAMCHANGE(12);
}
// Keyscale (0-3)
inline void Operator::SetKS(uint ks)
{
ks_ = ks;
param_changed_ = true;
PARAMCHANGE(13);
}
// SSG-type Envelop (0-15)
inline void Operator::SetSSGEC(uint ssgec)
{
if (ssgec & 8)
ssg_type_ = ssgec;
else
ssg_type_ = 0;
}
inline void Operator::SetAMON(bool amon)
{
amon_ = amon;
param_changed_ = true;
PARAMCHANGE(14);
}
inline void Operator::Mute(bool mute)
{
mute_ = mute;
param_changed_ = true;
PARAMCHANGE(15);
}
inline void Operator::SetMS(uint ms)
{
ms_ = ms;
param_changed_ = true;
PARAMCHANGE(16);
}
// ---------------------------------------------------------------------------
// 4-op Channel
// オペレータの種類 (LFO) を設定
inline void Channel4::SetType(OpType type)
{
for (int i=0; i<4; i++)
op[i].type_ = type;
}
// セルフ・フィードバックレートの設定 (0-7)
inline void Channel4::SetFB(uint feedback)
{
fb = fbtable[feedback];
}
// OPNA 系 LFO の設定
inline void Channel4::SetMS(uint ms)
{
op[0].SetMS(ms);
op[1].SetMS(ms);
op[2].SetMS(ms);
op[3].SetMS(ms);
}
// チャンネル・マスク
inline void Channel4::Mute(bool m)
{
for (int i=0; i<4; i++)
op[i].Mute(m);
}
// 内部パラメータを再計算
inline void Channel4::Refresh()
{
for (int i=0; i<4; i++)
op[i].param_changed_ = true;
PARAMCHANGE(3);
}
inline void Channel4::SetChip(Chip* chip)
{
chip_ = chip;
for (int i=0; i<4; i++)
op[i].SetChip(chip);
}
// ---------------------------------------------------------------------------
//
//
inline void StoreSample(Sample& dest, ISample data)
{
if (sizeof(Sample) == 2)
dest = (Sample) Limit(dest + data, 0x7fff, -0x8000);
else
dest += data;
}
// ---------------------------------------------------------------------------
// AM のレベルを設定
inline void Chip::SetAML(uint l)
{
aml_ = l & (FM_LFOENTS - 1);
}
// PM のレベルを設定
inline void Chip::SetPML(uint l)
{
pml_ = l & (FM_LFOENTS - 1);
}
}
#endif // FM_GEN_INL_H