-
Notifications
You must be signed in to change notification settings - Fork 1
/
Voice.h
63 lines (52 loc) · 1.64 KB
/
Voice.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
#pragma once
#include "Oscillator.h"
#include "EnvelopeGenerator.h"
#include "Filter.h"
class Voice
{
public:
friend class VoiceManager;
Voice()
:mNoteNumber(-1),
mVelocity(0),
mFilterEnvelopeAmount(0.0),
mFilterLFOAmount(0.0),
mOscillatorOnePitchAmount(0.0),
mOscillatorTwoPitchAmount(0.0),
mOscillatorMix(0.5),
mLFOValue(0.0),
isActive(false) {
// set myself free everytime my volume has fully faded out of RELEASE state:
mVolumeEnvelope.finishedEnvelopeCycle.Connect(this, &Voice::setFree);
};
inline void setFilterEnvelopeAmount(double amount) { mFilterEnvelopeAmount = amount; }
inline void setFilterLFOAmount(double amount) { mFilterLFOAmount = amount; }
inline void setOscillatorOnePitchAmount(double amount) { mOscillatorOnePitchAmount = amount; }
inline void setOscillatorTwoPitchAmount(double amount) { mOscillatorTwoPitchAmount = amount; }
inline void setOscillatorMix(double mix) { mOscillatorMix = mix; }
inline void setLFOValue(double value) { mLFOValue = value; }
inline void setNoteNumber(int noteNumber) {
mNoteNumber = noteNumber;
double frequency = 440.0* pow(2.0, (mNoteNumber - 69.0) / 12.0);
mOscillatorOne.setFrequency(frequency);
mOscillatorTwo.setFrequency(frequency);
}
double nextSample();
void setFree();
void reset();
private:
Oscillator mOscillatorOne;
Oscillator mOscillatorTwo;
EnvelopeGenerator mVolumeEnvelope;
EnvelopeGenerator mFilterEnvelope;
Filter mFilter;
int mNoteNumber;
int mVelocity;
double mFilterEnvelopeAmount;
double mOscillatorMix;
double mFilterLFOAmount;
double mOscillatorOnePitchAmount;
double mOscillatorTwoPitchAmount;
double mLFOValue;
bool isActive;
};