-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathLFO.cpp
62 lines (46 loc) · 1.03 KB
/
LFO.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
/*
* LFO.cpp
*
* Created on: 07.04.2015
* Author: user
*/
#include "LFO.h"
LFO::LFO() :currentPhase(0), lastTimestamp(0), flopVector(0), xorVector(0), thres(255)
{
}
void LFO::setFrequency(uint16_t bastlCyclesPerPeriod) {
if (bastlCyclesPerPeriod == 0) {
phaseIncrement = 0;
return;
}
phaseIncrement = ((uint32_t)65536 + (bastlCyclesPerPeriod>>1))/bastlCyclesPerPeriod;
}
void LFO::setToStep(uint8_t stepNumber, uint16_t timestamp) {
lastTimestamp = timestamp;
currentPhase = stepNumber << 8;
}
void LFO::setFlop(uint8_t bitVector) {
flopVector = bitVector;
}
void LFO::setXOR(uint8_t bitVector) {
xorVector = bitVector;
}
void LFO::setFolding(uint8_t thres) {
this->thres = thres;
isFolding = true;
}
void LFO::setOverflow(uint8_t thres) {
this->thres = thres;
isFolding = false;
}
void LFO::step() {
currentPhase += phaseIncrement;
}
uint8_t LFO::getValue(uint16_t timestamp) {
while(lastTimestamp != timestamp) {
step();
lastTimestamp++;
}
currentStep = currentPhase >> 8;
return calcOutput();
}