1 // ---------------------------------------------------------------------------
3 // Copyright (C) cisc 1998, 2001.
4 // ---------------------------------------------------------------------------
5 // $Id: fmgen.h,v 1.37 2003/08/25 13:33:11 cisc Exp $
13 // ---------------------------------------------------------------------------
16 #define FM_SAMPLETYPE int32 // int16 or int32
18 // ---------------------------------------------------------------------------
22 #define FM_LFOBITS 8 // 変更不可
25 // ---------------------------------------------------------------------------
27 #define FM_TLENTS (1 << FM_TLBITS)
28 #define FM_LFOENTS (1 << FM_LFOBITS)
29 #define FM_TLPOS (FM_TLENTS/4)
32 #define FM_CLENTS (0x1000 * 2) // sin + TL + LFO
34 // ---------------------------------------------------------------------------
39 // Types ----------------------------------------------------------------
40 typedef FM_SAMPLETYPE Sample;
41 typedef int32 ISample;
43 enum OpType { typeN=0, typeM=1 };
45 void StoreSample(ISample& dest, int data);
48 // Operator -------------------------------------------------------------
52 std::shared_ptr<CSP_Logger> p_logger;
58 void SetChip(Chip* chip) { chip_ = chip; }
60 static void MakeTimeTable(uint ratio);
62 ISample Calc(ISample in);
63 ISample CalcL(ISample in);
64 ISample CalcFB(uint fb);
65 ISample CalcFBL(uint fb);
66 ISample CalcN(uint noise);
75 void SetDT2(uint dt2);
76 void SetMULTI(uint multi);
77 void SetTL(uint tl, bool csm);
84 void SetSSGEC(uint ssgec);
85 void SetFNum(uint fnum);
86 void SetDPBN(uint dp, uint bn);
87 void SetMode(bool modulator);
88 void SetAMON(bool on);
92 // static void SetAML(uint l);
93 // static void SetPML(uint l);
95 int Out() { return out_; }
97 int dbgGetIn2() { return in2_; }
98 void dbgStopPG() { pg_diff_ = 0; pg_diff_lfo_ = 0; }
101 bool ProcessState(void *f, bool loading);
104 typedef uint32 Counter;
110 // Phase Generator ------------------------------------------------------
115 uint detune_; // Detune
116 uint detune2_; // DT2
117 uint multiple_; // Multiple
118 uint32 pg_count_; // Phase 現在値
119 uint32 pg_diff_; // Phase 差分値
120 int32 pg_diff_lfo_; // Phase 差分値 >> x
122 // Envelop Generator ---------------------------------------------------
123 enum EGPhase { next, attack, decay, sustain, release, off };
127 void ShiftPhase(EGPhase nextphase);
128 void SSGShiftPhase(int mode);
129 void SetEGRate(uint);
132 ISample LogToLin(uint a);
135 OpType type_; // OP の種類 (M, N...)
136 uint bn_; // Block/Note
137 int eg_level_; // EG の出力値
138 int eg_level_on_next_phase_; // 次の eg_phase_ に移る値
139 int eg_count_; // EG の次の変移までの時間
140 int eg_count_diff_; // eg_count_ の差分
141 int eg_out_; // EG+TL を合わせた出力値
142 int tl_out_; // TL 分の出力値
143 // int pm_depth_; // PM depth
144 // int am_depth_; // AM depth
152 uint key_scale_rate_; // key scale rate
157 uint tl_; // Total Level (0-127)
158 uint tl_latch_; // Total Level Latch (for CSM mode)
159 uint ar_; // Attack Rate (0-63)
160 uint dr_; // Decay Rate (0-63)
161 uint sr_; // Sustain Rate (0-63)
162 uint sl_; // Sustain Level (0-127)
163 uint rr_; // Release Rate (0-63)
164 uint ks_; // Keyscale (0-3)
165 uint ssg_type_; // SSG-Type Envelop Control
168 bool amon_; // enable Amplitude Modulation
169 bool param_changed_; // パラメータが更新された
172 // Tables ---------------------------------------------------------------
173 static Counter rate_table[16];
174 static uint32 multable[4][16];
176 static const uint8 notetable[128];
177 static const int8 dttable[256];
178 static const int8 decaytable1[64][8];
179 static const int decaytable2[16];
180 static const int8 attacktable[64][8];
181 static const int ssgenvtable[8][2][3][2];
183 static uint sinetable[1024];
184 static int32 cltable[FM_CLENTS];
186 static bool tablehasmade;
187 static void MakeTable();
191 // friends --------------------------------------------------------------
192 friend class Channel4;
193 // friend void __stdcall FM_NextPhase(Operator* op);
198 static const int32* dbgGetClTable() { return cltable; }
199 static const uint* dbgGetSineTable() { return sinetable; }
202 // 4-op Channel ---------------------------------------------------------
206 int tmp_in_bufptr[3];
207 int tmp_out_bufptr[3];
210 std::shared_ptr<CSP_Logger> p_logger;
213 void SetChip(Chip* chip);
214 void SetType(OpType type);
218 ISample CalcN(uint noise);
219 ISample CalcLN(uint noise);
220 void SetFNum(uint fnum);
222 void SetKCKF(uint kc, uint kf);
223 void SetAlgorithm(uint algo);
225 void KeyControl(uint key);
231 void dbgStopPG() { for (int i=0; i<4; i++) op[i].dbgStopPG(); }
233 bool ProcessState(void *f, bool loading);
236 static const uint8 fbtable[8];
239 int* in[3]; // 各 OP の入力ポインタ
240 int* out[3]; // 各 OP の出力ポインタ
245 static void MakeTable();
247 static bool tablehasmade;
248 static int kftable[64];
259 std::shared_ptr<CSP_Logger> p_logger;
263 void SetRatio(uint ratio);
266 void SetPMV(int pmv) { pmv_ = pmv; }
268 uint32 GetMulValue(uint dt2, uint mul) { return multable_[dt2][mul]; }
269 uint GetAML() { return aml_; }
270 uint GetPML() { return pml_; }
271 int GetPMV() { return pmv_; }
272 uint GetRatio() { return ratio_; }
274 bool ProcessState(void *f, bool loading);
284 uint32 multable_[4][16];
286 DLL_PREFIX const char *get_libfmgen_version(void);