ComSquare
DSP.hpp
Go to the documentation of this file.
1 //
2 // Created by Melefo on 28/01/2020.
3 //
4 
5 #ifndef COMSQUARE_DSP_HPP
6 #define COMSQUARE_DSP_HPP
7 
8 #include <cstdint>
9 #include <SFML/Audio.hpp>
10 #include "../Memory/IMemory.hpp"
11 
12 namespace ComSquare::APU::DSP
13 {
15  struct Registers {
17  uint8_t volL[8];
19  uint8_t volR[8];
20 
22  uint8_t pitchL[8];
24  uint8_t pitchH[8];
25 
27  uint8_t srcn[8];
28 
30  uint8_t adsr1[8];
32  uint8_t adsr2[8];
34  uint8_t gain[8];
36  uint8_t envx[8];
38  uint8_t outx[8];
39 
41  uint8_t mvolL;
43  uint8_t mvolR;
44 
46  uint8_t evolL;
48  uint8_t evolR;
49 
51  union {
52  struct {
53  bool kon7 : 1;
54  bool kon6 : 1;
55  bool kon5 : 1;
56  bool kon4 : 1;
57  bool kon3 : 1;
58  bool kon2 : 1;
59  bool kon1 : 1;
60  bool kon0 : 1;
61  };
62  uint8_t kon;
63  };
65  union {
66  struct {
67  bool kof7 : 1;
68  bool kof6 : 1;
69  bool kof5 : 1;
70  bool kof4 : 1;
71  bool kof3 : 1;
72  bool kof2 : 1;
73  bool kof1 : 1;
74  bool kof0 : 1;
75  };
76  uint8_t kof;
77  };
78 
80  uint8_t flg;
81 
83  union {
84  struct {
85  bool endx7 : 1;
86  bool endx6 : 1;
87  bool endx5 : 1;
88  bool endx4 : 1;
89  bool endx3 : 1;
90  bool endx2 : 1;
91  bool endx1 : 1;
92  bool endx0 : 1;
93  };
94  uint8_t endx;
95  };
96 
98  uint8_t efb;
99 
101  uint8_t unused;
102 
104  union {
105  struct {
106  bool pmon7 : 1;
107  bool pmon6 : 1;
108  bool pmon5 : 1;
109  bool pmon4 : 1;
110  bool pmon3 : 1;
111  bool pmon2 : 1;
112  bool pmon1 : 1;
113  bool __ : 1;
114  };
115  uint8_t pmon;
116  };
117 
119  union {
120  struct {
121  bool non7 : 1;
122  bool non6 : 1;
123  bool non5 : 1;
124  bool non4 : 1;
125  bool non3 : 1;
126  bool non2 : 1;
127  bool non1 : 1;
128  bool non0 : 1;
129  };
130  uint8_t non;
131  };
133  union {
134  struct {
135  bool eon7 : 1;
136  bool eon6 : 1;
137  bool eon5 : 1;
138  bool eon4 : 1;
139  bool eon3 : 1;
140  bool eon2 : 1;
141  bool eon1 : 1;
142  bool eon0 : 1;
143  };
144  uint8_t eon;
145  };
147  uint8_t dir;
148 
150  uint8_t esa;
152  uint8_t edl;
154  uint8_t coeff[8];
155  };
156 
157  class DSP : public Memory::IMemory {
158  private:
161 
163  sf::Sound _channels[8];
164 
166  sf::SoundBuffer _soundBuffer;
167  public:
168  explicit DSP();
169 
174  uint8_t read(uint24_t addr) override;
179  void write(uint24_t addr, uint8_t data) override;
180  };
181 }
182 
183 #endif //COMSQUARE_DSP_HPP
ComSquare::APU::DSP::DSP::_registers
Registers _registers
All registers of the DSP.
Definition: DSP.hpp:160
ComSquare::APU::DSP::Registers::kof6
bool kof6
Definition: DSP.hpp:68
ComSquare::APU::DSP::Registers::flg
uint8_t flg
Flags register.
Definition: DSP.hpp:80
ComSquare::APU::DSP::Registers::eon5
bool eon5
Definition: DSP.hpp:137
ComSquare::APU::DSP::Registers::mvolL
uint8_t mvolL
Left output of the Main Volume register.
Definition: DSP.hpp:41
ComSquare::APU::DSP::Registers::kof3
bool kof3
Definition: DSP.hpp:71
ComSquare::APU::DSP::Registers::kon6
bool kon6
Definition: DSP.hpp:54
ComSquare::APU::DSP::Registers::gain
uint8_t gain[8]
Gain register.
Definition: DSP.hpp:34
ComSquare::APU::DSP::Registers::pitchL
uint8_t pitchL[8]
Lower 8 bits of pitch register.
Definition: DSP.hpp:22
ComSquare::APU::DSP::Registers::non3
bool non3
Definition: DSP.hpp:125
ComSquare::APU::DSP::Registers::adsr1
uint8_t adsr1[8]
Envelope register.
Definition: DSP.hpp:30
ComSquare::APU::DSP::Registers::eon6
bool eon6
Definition: DSP.hpp:136
ComSquare::APU::DSP::DSP::read
uint8_t read(uint24_t addr) override
Read from the internal DSP register.
Definition: DSP.cpp:19
ComSquare::APU::DSP::Registers::pmon7
bool pmon7
Definition: DSP.hpp:106
ComSquare::APU::DSP::Registers::non1
bool non1
Definition: DSP.hpp:127
ComSquare::APU::DSP::Registers::non5
bool non5
Definition: DSP.hpp:123
ComSquare::APU::DSP::Registers::volL
uint8_t volL[8]
Left channel volume register.
Definition: DSP.hpp:17
ComSquare::APU::DSP::Registers::kof2
bool kof2
Definition: DSP.hpp:72
ComSquare::APU::DSP::Registers::eon1
bool eon1
Definition: DSP.hpp:141
ComSquare::APU::DSP::Registers::pmon
uint8_t pmon
Definition: DSP.hpp:115
ComSquare::APU::DSP::Registers::endx7
bool endx7
Definition: DSP.hpp:85
ComSquare::APU::DSP::Registers::evolR
uint8_t evolR
Right output of the Echo Volume register.
Definition: DSP.hpp:48
ComSquare::APU::DSP::Registers::pmon1
bool pmon1
Definition: DSP.hpp:112
ComSquare::APU::DSP::Registers::kof7
bool kof7
Definition: DSP.hpp:67
ComSquare::APU::DSP::Registers::endx1
bool endx1
Definition: DSP.hpp:91
ComSquare::APU::DSP::Registers::envx
uint8_t envx[8]
Envelope value register.
Definition: DSP.hpp:36
ComSquare::APU::DSP::Registers::pmon3
bool pmon3
Definition: DSP.hpp:110
ComSquare::APU::DSP::Registers::outx
uint8_t outx[8]
Wave height register.
Definition: DSP.hpp:38
ComSquare::APU::DSP::Registers::kon5
bool kon5
Definition: DSP.hpp:55
uint24_t
unsigned uint24_t
Definition: Ints.hpp:8
ComSquare::APU::DSP::Registers::kon3
bool kon3
Definition: DSP.hpp:57
ComSquare::APU::DSP::Registers::endx0
bool endx0
Definition: DSP.hpp:92
ComSquare::APU::DSP::Registers::non4
bool non4
Definition: DSP.hpp:124
ComSquare::APU::DSP::Registers::__
bool __
Definition: DSP.hpp:113
ComSquare::Memory::IMemory
Common interface implemented by all components mapping memory.
Definition: IMemory.hpp:16
ComSquare::APU::DSP::Registers::non
uint8_t non
Definition: DSP.hpp:130
ComSquare::APU::DSP::Registers::kon4
bool kon4
Definition: DSP.hpp:56
ComSquare::APU::DSP::Registers::kof1
bool kof1
Definition: DSP.hpp:73
ComSquare::APU::DSP::Registers::esa
uint8_t esa
Echo data start register.
Definition: DSP.hpp:150
ComSquare::APU::DSP::Registers::non2
bool non2
Definition: DSP.hpp:126
ComSquare::APU::DSP::Registers::pmon4
bool pmon4
Definition: DSP.hpp:109
ComSquare::APU::DSP::DSP::write
void write(uint24_t addr, uint8_t data) override
Write data to the internal DSP register.
Definition: DSP.cpp:235
ComSquare::APU::DSP::Registers::eon
uint8_t eon
Definition: DSP.hpp:144
ComSquare::APU::DSP::Registers::endx
uint8_t endx
Definition: DSP.hpp:94
ComSquare::APU::DSP::Registers::mvolR
uint8_t mvolR
Right output of the Main Volume register.
Definition: DSP.hpp:43
ComSquare::APU::DSP::Registers::efb
uint8_t efb
Echo feedback register.
Definition: DSP.hpp:98
ComSquare::APU::DSP::Registers::srcn
uint8_t srcn[8]
Source number register.
Definition: DSP.hpp:27
ComSquare::APU::DSP::Registers::kof5
bool kof5
Definition: DSP.hpp:69
ComSquare::APU::DSP::Registers::kof0
bool kof0
Definition: DSP.hpp:74
ComSquare::APU::DSP::Registers::pitchH
uint8_t pitchH[8]
Higher 8 bits of pitch register.
Definition: DSP.hpp:24
ComSquare::APU::DSP::Registers::non7
bool non7
Definition: DSP.hpp:121
ComSquare::APU::DSP::Registers::eon0
bool eon0
Definition: DSP.hpp:142
ComSquare::APU::DSP::Registers
All the registers of the DSP.
Definition: DSP.hpp:15
ComSquare::APU::DSP::Registers::endx2
bool endx2
Definition: DSP.hpp:90
ComSquare::APU::DSP::Registers::adsr2
uint8_t adsr2[8]
Envelope controllers register.
Definition: DSP.hpp:32
ComSquare::APU::DSP::Registers::non0
bool non0
Definition: DSP.hpp:128
ComSquare::APU::DSP::Registers::pmon6
bool pmon6
Definition: DSP.hpp:107
ComSquare::APU::DSP::Registers::unused
uint8_t unused
Not used register.
Definition: DSP.hpp:101
ComSquare::APU::DSP::Registers::endx5
bool endx5
Definition: DSP.hpp:87
ComSquare::APU::DSP::DSP::_soundBuffer
sf::SoundBuffer _soundBuffer
A buffer containing current wave.
Definition: DSP.hpp:166
ComSquare::APU::DSP::Registers::kon0
bool kon0
Definition: DSP.hpp:60
ComSquare::APU::DSP::DSP::_channels
sf::Sound _channels[8]
8x channels of sample used to make sound
Definition: DSP.hpp:163
ComSquare::APU::DSP::Registers::kon
uint8_t kon
Definition: DSP.hpp:62
ComSquare::APU::DSP::Registers::eon7
bool eon7
Definition: DSP.hpp:135
ComSquare::APU::DSP::Registers::volR
uint8_t volR[8]
Left channel volume register.
Definition: DSP.hpp:19
ComSquare::APU::DSP::Registers::endx4
bool endx4
Definition: DSP.hpp:88
ComSquare::APU::DSP::DSP
Definition: DSP.hpp:157
ComSquare::APU::DSP::Registers::coeff
uint8_t coeff[8]
Echo FIR filter coefficients.
Definition: DSP.hpp:154
ComSquare::APU::DSP::Registers::non6
bool non6
Definition: DSP.hpp:122
ComSquare::APU::DSP::Registers::endx3
bool endx3
Definition: DSP.hpp:89
ComSquare::APU::DSP::Registers::kon1
bool kon1
Definition: DSP.hpp:59
ComSquare::APU::DSP::Registers::pmon2
bool pmon2
Definition: DSP.hpp:111
ComSquare::APU::DSP::Registers::kon2
bool kon2
Definition: DSP.hpp:58
ComSquare::APU::DSP::Registers::endx6
bool endx6
Definition: DSP.hpp:86
ComSquare::APU::DSP::Registers::eon4
bool eon4
Definition: DSP.hpp:138
ComSquare::APU::DSP::Registers::kof4
bool kof4
Definition: DSP.hpp:70
ComSquare::APU::DSP
Definition: DSP.cpp:8
ComSquare::APU::DSP::DSP::DSP
DSP()
Definition: DSP.cpp:10
ComSquare::APU::DSP::Registers::evolL
uint8_t evolL
Left output of the Echo Volume register.
Definition: DSP.hpp:46
ComSquare::APU::DSP::Registers::pmon5
bool pmon5
Definition: DSP.hpp:108
ComSquare::APU::DSP::Registers::eon2
bool eon2
Definition: DSP.hpp:140
ComSquare::APU::DSP::Registers::edl
uint8_t edl
Echo delay size register.
Definition: DSP.hpp:152
ComSquare::APU::DSP::Registers::eon3
bool eon3
Definition: DSP.hpp:139
ComSquare::APU::DSP::Registers::kof
uint8_t kof
Definition: DSP.hpp:76
ComSquare::APU::DSP::Registers::dir
uint8_t dir
Source Directory offset register.
Definition: DSP.hpp:147
ComSquare::APU::DSP::Registers::kon7
bool kon7
Definition: DSP.hpp:53