Using std::array instead of a raw pointer

This commit is contained in:
Melefo
2021-02-10 16:13:09 +01:00
parent b976b16f43
commit 18bf27c318
4 changed files with 10 additions and 9 deletions
+2 -2
View File
@@ -14,7 +14,7 @@ namespace ComSquare::APU
_renderer(renderer),
_map(new MemoryMap()),
_soundBuffer(),
_dsp(_soundBuffer, APU::bufferSize / 2, _map)
_dsp(this->_soundBuffer, this->_soundBuffer.size() / 2, _map)
{
this->reset();
}
@@ -728,7 +728,7 @@ namespace ComSquare::APU
this->_dsp.update();
samples = this->_dsp.getSamplesCount();
if (samples > 0)
this->_renderer.playAudio(this->_soundBuffer, samples / 2);
this->_renderer.playAudio(this->_soundBuffer.data(), samples / 2);
}
void APU::_setNZflags(uint8_t value)
+1 -3
View File
@@ -143,10 +143,8 @@ namespace ComSquare::APU
//! @brief Internal APU memory separated according to their utility
std::shared_ptr<MemoryMap> _map;
//! @brief Total size of the buffer containing samples
static constexpr int32_t bufferSize = 0x10000;
//! @brief Buffer containing samples to be played
int16_t _soundBuffer[bufferSize];
std::array<int16_t, 0x10000> _soundBuffer;
//! @brief The DSP component used to produce sound
DSP::DSP _dsp;
+2 -1
View File
@@ -8,7 +8,8 @@
namespace ComSquare::APU::DSP
{
DSP::DSP(int16_t *buffer, uint32_t size, std::weak_ptr<MemoryMap> map) : _map(map)
DSP::DSP(std::array<int16_t, 0x10000> &buffer, uint32_t size, std::weak_ptr<MemoryMap> map) :
_state(buffer), _map(map)
{
this->_state.buffer = buffer;
this->_state.bufferSize = size;
+5 -3
View File
@@ -186,10 +186,12 @@ namespace ComSquare::APU::DSP
//! @brief Current state of the DSP
struct State
{
State(std::array<int16_t, 0x10000> &array) : buffer(array) {};
//! @brief Current voice modification to do
uint8_t voice = 0;
//! @brief Current buffer of samples
int16_t *buffer;
std::array<int16_t, 0x10000> &buffer;
//! @brief Size of buffer
uint32_t bufferSize;
//! @brief Current position in the buffer of samples
@@ -268,7 +270,7 @@ namespace ComSquare::APU::DSP
Noise _noise {};
BRR _brr {};
Latch _latch {};
State _state {};
State _state;
Timer _timer {};
void voiceOutput(Voice &voice, bool channel);
@@ -324,7 +326,7 @@ namespace ComSquare::APU::DSP
//! @brief Write into APU RAM
void _writeRAM(uint24_t addr, uint8_t data);
public:
DSP(int16_t *buffer, uint32_t size, std::weak_ptr<MemoryMap> map);
DSP(std::array<int16_t, 0x10000> &buffer, uint32_t size, std::weak_ptr<MemoryMap> map);
DSP(const DSP &) = default;
DSP &operator=(const DSP &) = default;
~DSP() = default;