-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathVAEngine.cpp
65 lines (60 loc) · 1.36 KB
/
VAEngine.cpp
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
#include "SynthVoice.h"
#define NUM_VOICES 2
class VAEngine
{
public:
VAEngine()
{
}
~VAEngine()
{
}
Num Process()
{
s = 0;
for (int i = 0; i < NUM_VOICES; i++)
{
s = s + (int32_t)(mSynthVoice[i].Process() + Num(127));
}
}
void handleNoteOn(uint8_t channel, uint8_t note, uint8_t velocity)
{
bool found = false;
int maxnote = -1;
int maxnoteidx = -1;
for (int i = 0; i < NUM_VOICES; i++)
{
if (voices_notes[i] == -1)
{
voices_notes[i] = note;
mSynthVoice[i].MidiNoteOn(note, velocity);
found = true;
return;
}
if (voices_notes[i] > maxnote)
{
maxnote = voices_notes[i];
maxnoteidx = i;
}
}
voices_notes[maxnoteidx] = note;
mSynthVoice[maxnoteidx].MidiNoteOn(note, velocity);
}
void handleNoteOff(uint8_t channel, uint8_t note, uint8_t velocity)
{
//digitalWrite(LED, LOW);
for (int i = 0; i < NUM_VOICES; i++)
{
if (voices_notes[i] == note)
{
voices_notes[i] = -1;
mSynthVoice[i].MidiNoteOff();
//break;
}
}
}
private:
SynthVoice mSynthVoice[NUM_VOICES];
int voices_notes[NUM_VOICES];
volatile int64_t s = 0;
};