-
Notifications
You must be signed in to change notification settings - Fork 0
/
Oscillator.cpp
40 lines (35 loc) · 930 Bytes
/
Oscillator.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
#include "Oscillator.h"
#include "mozzi_midi.h"
int8_t Oscillator::next() {
int8_t signal = 0;
if (enabled) {
switch (waveform) {
case Saw:
signal = aSaw.next();
break;
case Square:
signal = aSquare.next();
break;
case Sine:
signal = aSin.next();
break;
case Triangle:
signal = aTriangle.next();
break;
}
}
return ((uint16_t)gain * signal) >> 8;
}
void Oscillator::updateFrequency() {
int8_t midiNote = note + rangeModifier[range];
Q16n16 majorSixthFreq = Q16n16_mtof(Q8n0_to_Q16n16(midiNote + 9));
Q16n16 majorSixthLowFreq = Q16n16_mtof(Q8n0_to_Q16n16(midiNote - 3));
Q16n16 freq = majorSixthLowFreq + detune * ((majorSixthFreq - majorSixthLowFreq) / (uint16_t)1023);
aSaw.setFreq_Q16n16(freq);
aSquare.setFreq_Q16n16(freq);
aSin.setFreq_Q16n16(freq);
aTriangle.setFreq_Q16n16(freq);
}
void Oscillator::setNote(int8_t note) {
this->note = note;
}