-
Notifications
You must be signed in to change notification settings - Fork 2
/
Voice.h
71 lines (69 loc) · 2.38 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
63
64
65
66
67
68
69
70
71
#pragma once
#pragma once
#include "Oscillator.h"
#include "EnvelopeGenerator.h"
#include "Filter.h"
class Voice {
private:
// Voice Attribute
bool isActive; // osc isMuted
double mOscillatorMix;
int mNoteNumber;
int mVelocity;
// Component
Oscillator mOscillator1;
Oscillator mOscillator2;
Filter mFilter;
EnvelopeGenerator mAmpEnvelope;
EnvelopeGenerator mFilterEnvelope;
// Component Attribute
double mFilterEnvelopeAmount;
double mAmpEnvelopeAmount;
// Freq Adjust
int mSemiOffset1; //Coarse knob
int mSemiOffset2;
int mCentOffset1; //Fine knob
int mCentOffset2;
double pbendamount;
int mchannel;
public:
friend class VoiceManager;
Voice() :
mNoteNumber(-1),
mVelocity(0),
mFilterEnvelopeAmount(0.0),
mAmpEnvelopeAmount(50.0),
mSemiOffset1(0),
mSemiOffset2(0),
mCentOffset1(0),
mCentOffset2(0),
mOscillatorMix(0.0),
isActive(false) {
// Set myself free everytime my volume envelope has fully faded out of RELEASE stage:
mAmpEnvelope.finishedEnvelopeCycle.Connect(this, &Voice::setFree);
}
// Setters
inline void setFilterEnvelopeAmount(double amount) { mFilterEnvelopeAmount = amount; }
inline void setAmpEnvelopeAmount(double amount) { mAmpEnvelopeAmount = amount; }
inline void setSemiOffset1(int semi) { mSemiOffset1 = semi; }
inline void setSemiOffset2(int semi) { mSemiOffset2 = semi; }
inline void setCentOffset1(int cent) { mCentOffset1 = cent; }
inline void setCentOffset2(int cent) { mCentOffset2 = cent; }
inline void setPBAmount(double pb) { pbendamount=pb;setNoteNumber(mNoteNumber); }
inline void setChannel(int ch) { mchannel=ch; }
inline int channel() { return mchannel; }
inline void setOscillatorBitCrusher(bool enabled) { mOscillator1.setBitCrusher(enabled); mOscillator2.setBitCrusher(enabled); };
inline void setPhaseStart(bool enabled) { mOscillator1.setPhaseStart(enabled); mOscillator2.setPhaseStart(enabled); };
inline void setOscillatorMix(double mix) { mOscillatorMix = mix; }
inline void setNoteNumber(int noteNumber) {
mNoteNumber = noteNumber;
double frequency1 = 440.0 * pow(2.0, (mNoteNumber + mSemiOffset1 + pbendamount + (mCentOffset1 * 0.01) - 69.0) / 12.0);
double frequency2 = 440.0 * pow(2.0, (mNoteNumber + mSemiOffset2 + pbendamount + (mCentOffset2 * 0.01) - 69.0) / 12.0);
mOscillator1.setFrequency(frequency1);
mOscillator2.setFrequency(frequency2);
}
// Method
double nextSample();
void setFree();
void reset();
};