-
Notifications
You must be signed in to change notification settings - Fork 0
/
PulseUnit.hpp
89 lines (66 loc) · 1.98 KB
/
PulseUnit.hpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef PULSE_UNIT_H
#define PULSE_UNIT_H
#include <cstdint>
class PulseUnit {
public:
PulseUnit(float sampleRate);
void reset();
void setDivider(unsigned int divider);
void setDuty(float duty);
void setEnabled(bool);
void setLengthCounterHalt(bool halt);
void setLengthCounter(unsigned int c);
void updateSweep(bool enabled, unsigned int divider,
unsigned int shift, bool negate);
void sweepReset();
void updateEnvelope(bool loop, bool constant,
unsigned char timerReload);
void frameTick();
unsigned char tick();
void printState(void);
void write_sweep_control(uint8_t);
void write_duration_control(uint8_t);
void write_duty_control(uint8_t);
void write_envelope_control(uint8_t);
void write_frequency_low(uint8_t);
void write_frequency_high(uint8_t);
void write_duration_enable(bool);
uint8_t read_sweep_control(void);
// can't read duration control
uint8_t read_duty_control(void);
uint8_t read_envelope_control(void);
// can't read frequency
bool read_duration_enable(void);
private:
float period();
void sweepAct();
void envelopeAct();
void lengthCounterAct();
unsigned char envelope();
const float sampleRate;
int frameStep;
unsigned int divider;
unsigned int dutyControl;
float duty();
bool enabled;
float time;
bool lengthCounterEnable;
int lengthCounterValue;
uint16_t frequencyControl;
// placeholder to store envelope byte until envelope functionality
// is implemented
uint8_t envelopeControl;
bool envelopeLoop;
bool envelopeConstant;
// Note: the timer reload also specifies the envelope in constant mode
unsigned char envelopeDividerReload;
unsigned char envelopeDivider;
unsigned char envelopeCounter;
unsigned int sweepPeriod;
unsigned int sweepDividerReload; // TODO maybe same as period
unsigned int sweepDivider; // TODO implementation
unsigned int sweepShift;
bool sweepNegate;
bool frameCounterMode;
};
#endif // PULSE_UNIT_H