-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapu.hpp
More file actions
61 lines (48 loc) · 1.44 KB
/
apu.hpp
File metadata and controls
61 lines (48 loc) · 1.44 KB
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
#ifndef APU_H
#define APU_H
#include <cstdlib>
#include <string>
#include <vector>
#include "portaudio.h"
#include "PulseWave.hpp"
#include "TriangleWave.hpp"
const int N_PULSE_WAVES = 2;
const float SAMPLE_RATE = 44100.0;
const float PULSE_MIX_COEFFICIENT = 0.00752;
const float TRIANGLE_MIX_COEFFICIENT = 0.00851;
const float NOISE_MIX_COEFFICIENT = 0.00494;
const float DMC_MIX_COEFFICIENT = 0.00335;
class APU {
public:
APU(float sampleRate);
~APU();
void apuInit();
float tick();
void updateFrameCounter(bool);
void frameCounterQuarterFrame();
void frameCounterHalfFrame();
// pulse wave interface
void resetPulse(unsigned int);
void setPulseDivider(unsigned int, unsigned int);
void setPulseEnabled(unsigned int, bool);
void setPulseDuty(unsigned int, float);
void setPulseLengthCounterHalt(unsigned int, bool);
void setPulseLengthCounter(unsigned int, unsigned int);
void setPulseDuration(unsigned int, float);
void updatePulseSweep(unsigned int pulse_n,
bool enabled, unsigned int divider,
unsigned int shift, bool negate);
void updatePulseEnvelope(unsigned int pulse_n,
bool loop, bool constant,
unsigned char timerReload);
float lastSample;
std::vector<PulseWave> pulses;
TriangleWave triangle;
protected:
float time;
float sampleRate;
float timeStep;
bool frameCounterMode;
PaStream *stream;
};
#endif