-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTriangleWave.hpp
60 lines (42 loc) · 1.22 KB
/
TriangleWave.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
#ifndef TRIANGLE_WAVE_H
#define TRIANGLE_WAVE_H
#include "nesconstants.hpp"
const int TRIANGLE_WAVE_SEQUENCE_LENGTH = 32;
// start with output 0 so there's no popping sound
const int TRIANGLE_WAVE_SEQUENCE_START = 15;
const int TRIANGLE_MINIMUM_DIVIDER = 2;
class TriangleWave {
public:
TriangleWave(float sampleRate);
void setEnabled(bool enabled);
void setDivider(unsigned int divider);
void setLinearCounterInit(unsigned int c);
void setTimerHalts(bool halt);
void setLengthCounter(unsigned int c);
void linearCounterReload();
void updateFrameCounter(bool mode);
void frameCounterQuarterFrame();
void frameCounterHalfFrame();
unsigned char tick();
protected:
const float sampleRate;
bool enabled;
unsigned int divider;
unsigned int sequenceIndex;
float time;
// these two bits are actually the same bit in the NES
bool linearCounterHalt; // a.k.a. linear counter control bit
bool lengthCounterHalt;
int linearCounterInit;
int linearCounterValue;
int lengthCounterValue;
float sequencerPeriod();
void linearCounterAct();
void lengthCounterAct();
void sequencerAct();
float sequencerLastActed;
bool silent();
unsigned char envelope();
bool frameCounterMode;
};
#endif