1 // ---------------------------------------------------------------------------
3 // Copyright (C) cisc 1998, 2001.
4 // ---------------------------------------------------------------------------
5 // $Id: fmgen.h,v 1.37 2003/08/25 13:33:11 cisc Exp $
13 // ---------------------------------------------------------------------------
14 //
\8fo
\97Í
\83T
\83\93\83v
\83\8b\82Ì
\8c^
16 #define FM_SAMPLETYPE int32 // int16 or int32
18 // ---------------------------------------------------------------------------
19 //
\92è
\90\94\82»
\82Ì
\82P
20 //
\90Ã
\93I
\83e
\81[
\83u
\83\8b\82Ì
\83T
\83C
\83Y
22 #define FM_LFOBITS 8 //
\95Ï
\8dX
\95s
\89Â
25 // ---------------------------------------------------------------------------
27 #define FM_TLENTS (1 << FM_TLBITS)
28 #define FM_LFOENTS (1 << FM_LFOBITS)
29 #define FM_TLPOS (FM_TLENTS/4)
31 //
\83T
\83C
\83\93\94g
\82Ì
\90¸
\93x
\82Í 2^(1/256)
32 #define FM_CLENTS (0x1000 * 2) // sin + TL + LFO
34 // ---------------------------------------------------------------------------
36 class csp_state_utils;
40 // Types ----------------------------------------------------------------
41 typedef FM_SAMPLETYPE Sample;
42 typedef int32 ISample;
44 enum OpType { typeN=0, typeM=1 };
46 void StoreSample(ISample& dest, int data);
49 // Operator -------------------------------------------------------------
53 csp_state_utils *state_entry;
54 class CSP_Logger *p_logger;
60 void SetChip(Chip* chip) { chip_ = chip; }
62 static void MakeTimeTable(uint ratio);
64 ISample Calc(ISample in);
65 ISample CalcL(ISample in);
66 ISample CalcFB(uint fb);
67 ISample CalcFBL(uint fb);
68 ISample CalcN(uint noise);
77 void SetDT2(uint dt2);
78 void SetMULTI(uint multi);
79 void SetTL(uint tl, bool csm);
86 void SetSSGEC(uint ssgec);
87 void SetFNum(uint fnum);
88 void SetDPBN(uint dp, uint bn);
89 void SetMode(bool modulator);
90 void SetAMON(bool on);
94 // static void SetAML(uint l);
95 // static void SetPML(uint l);
97 int Out() { return out_; }
99 int dbgGetIn2() { return in2_; }
100 void dbgStopPG() { pg_diff_ = 0; pg_diff_lfo_ = 0; }
103 void DeclState(void *f);
104 void SaveState(void *f);
105 bool LoadState(void *f);
108 typedef uint32 Counter;
114 // Phase Generator ------------------------------------------------------
119 uint detune_; // Detune
120 uint detune2_; // DT2
121 uint multiple_; // Multiple
122 uint32 pg_count_; // Phase
\8c»
\8dÝ
\92l
123 uint32 pg_diff_; // Phase
\8d·
\95ª
\92l
124 int32 pg_diff_lfo_; // Phase
\8d·
\95ª
\92l >> x
126 // Envelop Generator ---------------------------------------------------
127 enum EGPhase { next, attack, decay, sustain, release, off };
131 void ShiftPhase(EGPhase nextphase);
132 void SSGShiftPhase(int mode);
133 void SetEGRate(uint);
136 ISample LogToLin(uint a);
139 OpType type_; // OP
\82Ì
\8eí
\97Þ (M, N...)
140 uint bn_; // Block/Note
141 int eg_level_; // EG
\82Ì
\8fo
\97Í
\92l
142 int eg_level_on_next_phase_; //
\8e\9f\82Ì eg_phase_
\82É
\88Ú
\82é
\92l
143 int eg_count_; // EG
\82Ì
\8e\9f\82Ì
\95Ï
\88Ú
\82Ü
\82Å
\82Ì
\8e\9e\8aÔ
144 int eg_count_diff_; // eg_count_
\82Ì
\8d·
\95ª
145 int eg_out_; // EG+TL
\82ð
\8d\87\82í
\82¹
\82½
\8fo
\97Í
\92l
146 int tl_out_; // TL
\95ª
\82Ì
\8fo
\97Í
\92l
147 // int pm_depth_; // PM depth
148 // int am_depth_; // AM depth
156 uint key_scale_rate_; // key scale rate
161 uint tl_; // Total Level (0-127)
162 uint tl_latch_; // Total Level Latch (for CSM mode)
163 uint ar_; // Attack Rate (0-63)
164 uint dr_; // Decay Rate (0-63)
165 uint sr_; // Sustain Rate (0-63)
166 uint sl_; // Sustain Level (0-127)
167 uint rr_; // Release Rate (0-63)
168 uint ks_; // Keyscale (0-3)
169 uint ssg_type_; // SSG-Type Envelop Control
172 bool amon_; // enable Amplitude Modulation
173 bool param_changed_; //
\83p
\83\89\83\81\81[
\83^
\82ª
\8dX
\90V
\82³
\82ê
\82½
176 // Tables ---------------------------------------------------------------
177 static Counter rate_table[16];
178 static uint32 multable[4][16];
180 static const uint8 notetable[128];
181 static const int8 dttable[256];
182 static const int8 decaytable1[64][8];
183 static const int decaytable2[16];
184 static const int8 attacktable[64][8];
185 static const int ssgenvtable[8][2][3][2];
187 static uint sinetable[1024];
188 static int32 cltable[FM_CLENTS];
190 static bool tablehasmade;
191 static void MakeTable();
195 // friends --------------------------------------------------------------
196 friend class Channel4;
197 // friend void __stdcall FM_NextPhase(Operator* op);
202 static const int32* dbgGetClTable() { return cltable; }
203 static const uint* dbgGetSineTable() { return sinetable; }
206 // 4-op Channel ---------------------------------------------------------
210 int tmp_in_bufptr[3];
211 int tmp_out_bufptr[3];
214 csp_state_utils *state_entry;
215 class CSP_Logger *p_logger;
218 void SetChip(Chip* chip);
219 void SetType(OpType type);
223 ISample CalcN(uint noise);
224 ISample CalcLN(uint noise);
225 void SetFNum(uint fnum);
227 void SetKCKF(uint kc, uint kf);
228 void SetAlgorithm(uint algo);
230 void KeyControl(uint key);
236 void dbgStopPG() { for (int i=0; i<4; i++) op[i].dbgStopPG(); }
238 void DeclState(void *f);
239 void SaveState(void *f);
240 bool LoadState(void *f);
243 static const uint8 fbtable[8];
246 int* in[3]; //
\8ae OP
\82Ì
\93ü
\97Í
\83|
\83C
\83\93\83^
247 int* out[3]; //
\8ae OP
\82Ì
\8fo
\97Í
\83|
\83C
\83\93\83^
252 static void MakeTable();
254 static bool tablehasmade;
255 static int kftable[64];
266 class CSP_Logger *p_logger;
267 csp_state_utils *state_entry;
271 void SetRatio(uint ratio);
274 void SetPMV(int pmv) { pmv_ = pmv; }
276 uint32 GetMulValue(uint dt2, uint mul) { return multable_[dt2][mul]; }
277 uint GetAML() { return aml_; }
278 uint GetPML() { return pml_; }
279 int GetPMV() { return pmv_; }
280 uint GetRatio() { return ratio_; }
282 void DeclState(void *f);
283 void SaveState(void *f);
284 bool LoadState(void *f);
294 uint32 multable_[4][16];