forked from osoumen/C700
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC700Driver.h
276 lines (239 loc) · 9.65 KB
/
C700Driver.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
269
270
271
272
273
274
275
276
/*
* C700Driver.h
* C700
*
* Created by osoumen on 06/09/06.
* Copyright 2006 Vermicelli Magic. All rights reserved.
*
*/
#pragma once
#include "MemManager.h"
#include "C700defines.h"
#include "C700DSP.h"
#include "DynamicVoiceManager.h"
#include "C700TimeThread.h"
//-----------------------------------------------------------------------------
typedef enum
{
kVelocityMode_Constant,
kVelocityMode_Square,
kVelocityMode_Linear
} velocity_mode;
//-----------------------------------------------------------------------------
typedef enum
{
kEngineType_Old = 0,
kEngineType_Relaxed,
kEngineType_Accurate
} engine_type;
//-----------------------------------------------------------------------------
typedef enum
{
kVoiceAllocMode_Oldest = 0,
kVoiceAllocMode_SameChannel,
} voicealloc_mode;
//-----------------------------------------------------------------------------
class C700Driver
{
public:
typedef struct {
int prog;
float pitchBend;
int vibDepth;
int volume;
int expression;
int pan;
float pbRange;
//bool portaOn;
float portaTc;
float portaStartPitch;
int lastNote;
bool damper;
unsigned int changeFlg;
InstParams changedVP;
} ChannelStatus;
typedef struct VoiceStatus {
int pb;
int vibdepth;
bool reg_pmod;
float vibPhase;
float portaPitch;
//int ar,dr,sl,sr,vol_l,vol_r; // ミラー
int vol_l,vol_r;
int velo;
int volume;
int expression;
int pan;
int srcn;
//unsigned char *brrdata; // ミラー
//unsigned int loopPoint; // ミラー
//bool loop; // ミラー
//bool echoOn; // ミラー
bool non;
int targetPitch;
VoiceStatus() : pb(0), vibdepth(0), reg_pmod(0), vibPhase(0), portaPitch(0),
vol_l(0), vol_r(0), velo(0), volume(0), expression(0), pan(0), srcn(0),
targetPitch(0) {}
void Reset();
} VoiceStatus;
C700Driver();
virtual ~C700Driver();
virtual void Reset();
void NoteOn( int ch, int note, int velo, unsigned int uniqueID, int inFrame );
void NoteOff( int ch, int note, int velo, unsigned int uniqueID, int inFrame );
void ProgramChange( int ch, int value, int inFrame );
void PitchBend( int ch, int value1, int value2, int inFrame );
void ControlChange( int ch, int controlNum, int value, int inFrame );
void DirectRegisterWrite( int ch, int regAddr, int value, int inFrame );
void AllNotesOff();
void AllSoundOff();
void ResetAllControllers();
void StartRegisterLog( int inFrame );
void MarkLoopRegisterLog( int inFrame );
void EndRegisterLog( int inFrame );
// channel params
void ModWheel( int ch, int value );
void Damper( int ch, bool on );
void Volume( int ch, int value );
void Expression( int ch, int value );
void Panpot( int ch, int value );
void ChangeChRate(int ch, double rate);
void ChangeChBasekey(int ch, int basekey);
void ChangeChLowkey(int ch, int lowkey);
void ChangeChHighkey(int ch, int highkey);
void ChangeChAR(int ch, int ar);
void ChangeChDR(int ch, int dr);
void ChangeChSL(int ch, int sl);
void ChangeChSR1(int ch, int sr);
void ChangeChSR2(int ch, int sr);
//void ChangeChVolL(int ch, int voll);
//void ChangeChVolR(int ch, int volr);
void ChangeChEcho(int ch, int echo);
void ChangeChPMON(int ch, int pmon);
void ChangeChNON(int ch, int non);
void ChangeChBank(int ch, int bank);
void ChangeChSustainMode(int ch, int sustainMode);
void SetPortamentOn( int ch, bool on );
void SetPortamentTime( int ch, int value );
void UpdatePortamentoTime( int prog );
void SetPortamentControl( int ch, int note );
void SetChPriority( int ch, int value );
void SetChLimit( int ch, int value );
void SetReleasePriority( int ch, int value );
void SetMonoMode( int ch, bool on );
// global params
void SetVoiceLimit( int value );
void SetPBRange( float value );
void SetPBRange( int ch, float value );
void SetEngineType( engine_type type );
void SetVoiceAllocMode( voicealloc_mode mode );
void SetFastReleaseAsKeyOff( bool value );
void SetMultiMode( int bank, bool value );
bool GetMultiMode( int bank ) const;
void SetVelocityMode( velocity_mode value );
void SetVibFreq( int ch, float value );
void SetVibDepth( int ch, float value );
void SetMainVol_L( int value );
void SetMainVol_R( int value );
void SetEchoVol_L( int value );
void SetEchoVol_R( int value );
void SetFeedBackLevel( int value );
void SetDelayTime( int value );
int GetDelayTime();
void SetFIRTap( int tap, int value );
void SetBrrSample( int prog, const unsigned char *data, int size, int loopPoint);
void DelBrrSample( int prog );
void UpdateLoopPoint( int prog );
void UpdateLoopFlag( int prog );
void SetSampleRate( double samplerate );
void SetEventDelayClocks(int clocks);
double GetProcessDelayTime();
int GetNoteOnNotes(int ch) { return mVoiceManager.GetNoteOns(ch); }
void Process( unsigned int frames, float *output[2] );
int GetKeyMap( int bank, int key ) const { return mKeyMap[bank][key]; }
const InstParams *getVP(int pg) const { return &mVPset[pg]; }
const InstParams *getMappedVP(int bank, int key) const { return &mVPset[mKeyMap[bank][key]]; }
void SetVPSet( InstParams *vp );
void RefreshKeyMap(void);
//bool IsHwAvailable() { return mDSP.IsHwAvailable(); }
C700DSP* GetDsp() { return &mDSP; }
private:
static const int INTERNAL_CLOCK = 32000;
static const int CYCLES_PER_SAMPLE = 21168;
static const int PORTAMENT_CYCLE_SAMPLES = 32; // ポルタメント処理を行うサンプル数(32kHz換算)
static const int PITCH_CYCLE_SAMPLES = 32; // ピッチ変更を行うサンプル数(32kHz換算)
static const int CLOCKS_PER_SAMPLE = 32;
static const int VOLUME_DEFAULT = 100;
static const int EXPRESSION_DEFAULT = 127;
static const int DEFAULT_PBRANGE = 2;
enum EvtType {
NOTE_ON = 0,
NOTE_OFF,
PROGRAM_CHANGE,
PITCH_BEND,
CONTROL_CHANGE,
START_REGLOG,
MARKLOOP_REGLOG,
END_REGLOG,
REGISTER_WRITE
};
typedef struct {
EvtType type;
unsigned char ch;
unsigned char note;
unsigned char velo;
unsigned int uniqueID;
int remain_samples;
} MIDIEvt;
double mSampleRate;
int mProcessFrac;
int mProcessbuf[2][16]; //リサンプリング用バッファ
int mProcessbufPtr; //リサンプリング用バッファ書き込み位置
MutexObject mREGLOGEvtMtx;
std::list<MIDIEvt> mREGLOGEvt; //レジスタログのためのキュー
MutexObject mMIDIEvtMtx;
std::list<MIDIEvt> mMIDIEvt; //受け取ったイベントのキュー
std::list<MIDIEvt> mDelayedEvt; //遅延実行イベントのキュー
bool mKeyOnFlag[kMaximumVoices]; // 次のProcessでKeyOnする
bool mKeyOffFlag[kMaximumVoices]; // 次のProcessでKeyOffする
int mEchoOnFlag; // 次のProcessでEchoOnする
bool mEchoOnMask[kMaximumVoices]; // 次のProcessでEchoを変更する
int mPMOnFlag; // 次のProcessでPMOnする
bool mPMOnMask[kMaximumVoices]; // 次のProcessでPMONを変更する
int mNoiseOnFlag; // 次のProcessでNoiseOnする
bool mNoiseOnMask[kMaximumVoices]; // 次のProcessでNONを変更する
DynamicVoiceManager mVoiceManager;
bool mDrumMode[NUM_BANKS];
velocity_mode mVelocityMode;
ChannelStatus mChStat[16];
float mVibfreq;
float mVibdepth;
int mPortamentCount; // DSP処理が1サンプル出力される毎にカウントされ、ポルタメント処理されるとPORTAMENT_CYCLE_SAMPLES 減らす
int mPitchCount[kMaximumVoices];// DSP処理が1サンプル出力される毎にカウントされ、ピッチ変更されるとPITCH_CYCLE_SAMPLES 減らす、ノートオン時にも0にする
int mEventDelaySamples; // 動作遅延サンプル(処理サンプリングレート)
int mEventDelayClocks; // 動作遅延クロック
int mKeyMap[NUM_BANKS][128]; //各キーに対応するプログラムNo.
const InstParams *mVPset;
MemManager mMemManager;
C700DSP mDSP;
VoiceStatus mVoiceStat[kMaximumVoices];
int mVoiceLimit;
bool mIsAccurateMode;
bool mFastReleaseAsKeyOff; // sustainmodeでsr=31の場合キーオフで処理する
InstParams getChannelVP(int ch, int note);
void processPortament(int vo);
void calcPanVolume(int value, int *volL, int *volR);
void doProgramChange( int ch, int value );
void doPitchBend( int ch, int value1, int value2 );
void doControlChange( int ch, int controlNum, int value );
float VibratoWave(float phase);
int CalcPBValue(int ch, float pitchBend, int basePitch);
bool doNoteOn1( MIDIEvt dEvt );
void doNoteOn2(const MIDIEvt *evt);
int doNoteOff( const MIDIEvt *evt );
bool doRegLogEvents( const MIDIEvt *evt );
bool doEvents1( const MIDIEvt *evt );
bool doEvents2( const MIDIEvt *evt );
int calcEventDelaySamples() { return ((mEventDelayClocks / CLOCKS_PER_SAMPLE) * mSampleRate) / INTERNAL_CLOCK; }
float calcGM2PortamentCurve(int value);
};