diff --git a/sources/APU/APU.cpp b/sources/APU/APU.cpp index b80c6e6..221af87 100644 --- a/sources/APU/APU.cpp +++ b/sources/APU/APU.cpp @@ -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) diff --git a/sources/APU/APU.hpp b/sources/APU/APU.hpp index 937ae86..a56a0d6 100644 --- a/sources/APU/APU.hpp +++ b/sources/APU/APU.hpp @@ -143,10 +143,8 @@ namespace ComSquare::APU //! @brief Internal APU memory separated according to their utility std::shared_ptr _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 _soundBuffer; //! @brief The DSP component used to produce sound DSP::DSP _dsp; diff --git a/sources/APU/DSP/DSP.cpp b/sources/APU/DSP/DSP.cpp index a3036a0..fbc570a 100644 --- a/sources/APU/DSP/DSP.cpp +++ b/sources/APU/DSP/DSP.cpp @@ -8,7 +8,8 @@ namespace ComSquare::APU::DSP { - DSP::DSP(int16_t *buffer, uint32_t size, std::weak_ptr map) : _map(map) + DSP::DSP(std::array &buffer, uint32_t size, std::weak_ptr map) : + _state(buffer), _map(map) { this->_state.buffer = buffer; this->_state.bufferSize = size; diff --git a/sources/APU/DSP/DSP.hpp b/sources/APU/DSP/DSP.hpp index 284b8c8..e4f542d 100644 --- a/sources/APU/DSP/DSP.hpp +++ b/sources/APU/DSP/DSP.hpp @@ -186,10 +186,12 @@ namespace ComSquare::APU::DSP //! @brief Current state of the DSP struct State { + State(std::array &array) : buffer(array) {}; + //! @brief Current voice modification to do uint8_t voice = 0; //! @brief Current buffer of samples - int16_t *buffer; + std::array &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 map); + DSP(std::array &buffer, uint32_t size, std::weak_ptr map); DSP(const DSP &) = default; DSP &operator=(const DSP &) = default; ~DSP() = default;