-
Notifications
You must be signed in to change notification settings - Fork 1
/
Voice.cpp
34 lines (25 loc) · 977 Bytes
/
Voice.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
#include "Voice.h"
double Voice::nextSample() {
if (!isActive) return 0.0;
double oscillatorOneOutput = mOscillatorOne.nextSample();
double oscillatorTwoOutput = mOscillatorTwo.nextSample();
double oscillatorSum = ((1 - mOscillatorMix) * oscillatorOneOutput) + (mOscillatorMix * oscillatorTwoOutput);
double volumeEnvelopeValue = mVolumeEnvelope.nextSample();
double filterEnvelopeValue = mFilterEnvelope.nextSample();
mFilter.setCutoffMod(filterEnvelopeValue * mFilterEnvelopeAmount + mLFOValue * mFilterLFOAmount);
mOscillatorOne.setPitchMod(mLFOValue * mOscillatorOnePitchAmount);
mOscillatorTwo.setPitchMod(mLFOValue * mOscillatorTwoPitchAmount);
return mFilter.process(oscillatorSum * volumeEnvelopeValue * mVelocity / 127.0);
}
void Voice::setFree() {
isActive = false;
}
void Voice::reset() {
mNoteNumber = -1;
mVelocity = 0;
mOscillatorOne.reset();
mOscillatorTwo.reset();
mVolumeEnvelope.reset();
mFilterEnvelope.reset();
mFilter.reset();
}