-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoicehandler.h
More file actions
162 lines (132 loc) · 4.1 KB
/
voicehandler.h
File metadata and controls
162 lines (132 loc) · 4.1 KB
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
//
// voicehandler.h
//
#ifndef _VOICEHANDLER_H_
#define _VOICEHANDLER_H_
#include <circle/types.h>
#include <circle/string.h>
#include <circle/multicore.h>
#include <circle/memory.h>
#include "voice.h"
#include "patch.h"
#include "sdload.h"
#include "chorus.h"
#include "delay.h"
#define VH_MAX_VOICES 16
#define VOICES_PER_CORE_0 4
#define VOICES_PER_MULTICORE 4
enum TCoreStatus
{
CoreStatusInit,
CoreStatusIdle,
CoreStatusBusy,
CoreStatusExit,
CoreStatusUnknown
};
class CVoiceHandler : public CMultiCoreSupport
{
public:
// sampleRate needed for voices when NoteOn occurs
CVoiceHandler(CMemorySystem *pMemorySystem, unsigned sampleRate);
~CVoiceHandler();
// MIDI events: these are the public API your existing MidiHandler/SerialMIDI can call
void NoteOn(unsigned note, unsigned velocity);
void NoteOff(unsigned note);
void SetPatch(unsigned patch);
// Oscillator parameters
void SetCoarse(unsigned osc, float coarse);
void SetFine(unsigned osc, float fine);
void SetWaveformSaw(unsigned osc, bool wave);
void SetWaveformSquare(unsigned osc, bool wave);
void SetWaveformTri(bool wave);
void SetPulseWidth(unsigned osc, float pw);
void SetOscVol(unsigned osc, float fine);
void SetOsc2KbdTrk(bool kbd);
void SetOsc2LowFreq(bool low);
void SetOsc1Sync(bool sync);
// Filter Parameters
void SetCutoff(float freq);
void SetResonance(float res);
void SetEnvAmt(float amt);
void SetKbdTrk(float amt);
// Lfo Parameters
void SetLfoFreq(float freq);
void SetLfoWaveSaw(bool wave);
void SetLfoWaveSquare(bool wave);
void SetLfoWaveTri(bool wave);
void SetLfoFm(unsigned osc, bool fm);
void SetPulseWidthModulation(unsigned osc, bool pwm);
void SetLfoFilter(bool fil);
void SetLfoAmp(bool amp);
void SetLfoMix(float mix);
// PolyMod Parameters
void SetPolyModFreq(bool polyFreq);
void SetPolyModPw(bool polyPw);
void SetPolyModFil(bool polyFil);
void SetPolyModOsc2(float polyOsc2);
void SetPolyModFilEnv(float polyFilEnv);
// Envelope Parameters
void SetEnv(unsigned param, float value);
// Noise Parameters
void SetNoiseVol(float n);
// General Parameters
void SetModWheel(float mod);
void SetUnisonVoices(unsigned v);
void SetUnison(bool u);
void SetUnisonSpread(float spread);
void SetGlideTime(float time);
void SetLegato(bool leg);
void SetGain(float gain);
void SetVelocityToVolume(float scale);
void SetVelocityToFilter(float scale);
void SetSustainPedal(bool s);
// Fx Parameters
void SetChorusI(bool chI);
void SetChorusII(bool chII);
void SetDelayTimeL(float time);
void SetDelayTimeR(float time);
void SetDelayFeedbackL(float feed);
void SetDelayFeedbackR(float feed);
void SetDelayMixL(float mix);
void SetDelayMixR(float mix);
// Voice access for Synth:
// RenderVoice writes the specified voice's mono samples into pBuffer
float RenderVoice(unsigned index);
float RenderMixedVoices(void);
void GetMixedVoices(float *pOutBuffer, unsigned nFrames, unsigned nChannels);
// Return number of voices
unsigned GetVoiceCount() const { return VH_MAX_VOICES; }
// Return number of active voices (helper)
unsigned GetActiveVoiceCount() const;
bool IsVoiceActive(unsigned index) const { return m_voices[index].IsActive(); }
boolean Initialize (void);
void Run (unsigned nCore); // secondary core entry
void InitPatches(CSDLoad* pSD);
void ResetVoiceHandler(void);
private:
CVoice m_voices[VH_MAX_VOICES];
unsigned m_sampleRate;
CPatch m_patch;
CSDLoad* m_pSD;
Chorus* m_pChorus[4];
StereoDelay* m_pDelay;
unsigned m_nFrames;
unsigned m_activeCount;
bool m_unison;
unsigned m_unisonVoices;
float m_spread;
float m_fine[2];
bool m_sustain;
signed m_sustainNotes[VH_MAX_VOICES];
bool m_legato;
bool m_chorusI;
bool m_chorusII;
bool m_split;
unsigned m_splitNote;
bool m_layer;
unsigned m_layerCount;
unsigned m_currentPatch;
volatile TCoreStatus m_CoreStatus[CORES];
volatile float m_voicesBuffer[CORES];
};
#endif