diff --git a/sources/APU/DSP/DSP.hpp b/sources/APU/DSP/DSP.hpp index 6de6b07..284b8c8 100644 --- a/sources/APU/DSP/DSP.hpp +++ b/sources/APU/DSP/DSP.hpp @@ -203,123 +203,6 @@ namespace ComSquare::APU::DSP bool sample = true; }; - /*//! @brief All the registers of the DSP - struct Registers { - //! @brief Main Volume register - std::array mVol; //master.volume - - //! @brief Echo Volume register - std::array eVol; //echo.volume - - //! @brief Flags register - union { - struct { - uint8_t noiseClock : 5; //noise.frequency - bool ecen : 1; //echo.readonly - bool mute : 1; //master.mute - bool reset : 1; //master.reset - }; - uint8_t flg; - }; - - //! @brief Echo feedback register - uint8_t efb; //echo.feedback - - //! @brief Not used register - uint8_t unused; - - //! @brief Source Directory offset register - uint8_t dir; //brr.bank - - //! @brief Echo data start register - uint8_t esa; //echo.bank - //! @brief Echo delay size register - uint8_t edl; //echo.delay - }; - - struct BRR { - //! @brief BRR Header - union { - struct { - //! @brief Shift value range - unsigned range : 4; - //! @brief Decompression filter - unsigned filter : 2; - //! @brief Flag if the sample loops - bool loop : 1; - //! @brief Stop the sample (or restart from loop point) - bool end : 1; - }; - uint8_t head; - }; - //! @brief Sample data inside BRR - uint64_t block; - }; - - struct Voice { - //! @brief Volume register - std::array volume; //voice.volume - - union { - struct { - //! @brief Lower 8 bits of pitch register - uint8_t pitchL; - //! @brief Higher 8 bits of pitch register - uint8_t pitchH; - }; - uint16_t pitch; //voice.pitch - }; - - //! @brief Source number register - uint8_t srcn; //voice.source - - union { - struct { - //! @brief Envelope register - uint8_t adsr1; //voice.adsr0 - //! @brief Envelope controllers register - uint8_t adsr2; //voice.adsr1 - }; - uint16_t envelope; - }; - - //! @brief Gain register - uint8_t gain; //voice.gain - - //! @brief Envelope value register - uint8_t envx; //latch.envx - //! @brief Wave height register - uint8_t outx; //latch.outx - - //! @brief Key On register - bool kon : 1; //voice.keyon - //! @brief Key Off register - bool kof : 1; //voice.keyoff - bool keyLatch : 1; //voice._keylatch - - //! @brief Sample end register - bool endx : 1; //voice._end - //! @brief Noise enable register - bool non : 1; //voice.noise - //! @brief Echo enable register - bool eon : 1; //voice.echo - - //! @brief Pitch modulation register - bool pmon : 1; //voice.modulate - - //! @brief Echo FIR filter coefficients - uint8_t coeff; //echo.fir - - bool latchEon : 1; //voice._echo - }; - - struct Latch - { - uint8_t adsr0; - uint16_t pitch; - uint16_t output; - };*/ - class DSP { private: //! @brief Number of samples per counter event @@ -415,7 +298,9 @@ namespace ComSquare::APU::DSP void misc29(); void misc30(); + //! @brief Interpolate voice samples with gauss table int32_t interpolate(const Voice &voice); + //! @brief Modify voice samples with its envelope void runEnvelope(Voice &voice); int32_t loadFIR(bool channel, int fir); @@ -423,14 +308,20 @@ namespace ComSquare::APU::DSP int16_t outputEcho(bool channel); void writeEcho(bool channel); + //! @brief Remove one tick from timer void timerTick(); + //! @brief Check if timer value is equal to rate value bool timerPoll(uint32_t rate); + //! @brief Transform BRR value to samples void decodeBRR(Voice &voice); + //! @brief Whole APU RAM map std::weak_ptr _map; + //! @brief Read inside APU RAM uint8_t _readRAM(uint24_t addr); + //! @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); diff --git a/sources/Debugger/APUDebug.cpp b/sources/Debugger/APUDebug.cpp index fa768b5..3222f8d 100644 --- a/sources/Debugger/APUDebug.cpp +++ b/sources/Debugger/APUDebug.cpp @@ -97,11 +97,11 @@ namespace ComSquare::Debugger this->_ui.evolRprogressBar->setValue(echo.volume[1]); this->_ui.echoprogressBar->setValue(echo.feedback); - uint8_t flg = 0; - flg += master.reset << 7; - flg += master.mute << 6; - flg += echo.enabled << 5; - flg += noise.clock; + uint8_t flg = 0; + flg += master.reset << 7; + flg += master.mute << 6; + flg += echo.enabled << 5; + flg += noise.clock; this->_ui.flagslineEdit->setText(Utility::to_binary(flg).c_str()); this->_ui.sourceDirectoryLineEdit->setText(Utility::to_hex(brr.offset).c_str()); this->_ui.echoBufferOffsetLineEdit->setText(Utility::to_hex(echo.data).c_str()); diff --git a/sources/Renderer/IRenderer.hpp b/sources/Renderer/IRenderer.hpp index 43b4aba..7ce97cb 100644 --- a/sources/Renderer/IRenderer.hpp +++ b/sources/Renderer/IRenderer.hpp @@ -31,9 +31,9 @@ namespace ComSquare //! @param maxFPS The number of FPS you aim to run on. virtual void createWindow(SNES &snes, int maxFPS) = 0; - //! @brief Playing all samples from buffer - //! @param samples Buffer containing samples - //! @param sampleCount number of samples inside buffer + //! @brief Playing all samples from buffer + //! @param samples Buffer containing samples + //! @param sampleCount number of samples inside buffer virtual void playAudio(int16_t *samples, uint64_t sampleCount) = 0; }; } diff --git a/sources/Renderer/NoRenderer.cpp b/sources/Renderer/NoRenderer.cpp index 505ebcc..2ff3757 100644 --- a/sources/Renderer/NoRenderer.cpp +++ b/sources/Renderer/NoRenderer.cpp @@ -20,9 +20,9 @@ namespace ComSquare::Renderer (void)rgba; } - void NoRenderer::playAudio(int16_t *, uint64_t) - { - } + void NoRenderer::playAudio(int16_t *, uint64_t) + { + } void NoRenderer::getEvents() { } diff --git a/sources/Renderer/NoRenderer.hpp b/sources/Renderer/NoRenderer.hpp index 37fd940..149e92e 100644 --- a/sources/Renderer/NoRenderer.hpp +++ b/sources/Renderer/NoRenderer.hpp @@ -22,10 +22,10 @@ namespace ComSquare::Renderer //! @param Y vertical index. //! @param rgba The color of the pixel. void putPixel(unsigned y, unsigned x, uint32_t rgba) override; - //! @brief Playing all samples from buffer - //! @param samples Buffer containing samples - //! @param sampleCount number of samples inside buffer - void playAudio(int16_t *samples, uint64_t sampleCount) override; + //! @brief Playing all samples from buffer + //! @param samples Buffer containing samples + //! @param sampleCount number of samples inside buffer + void playAudio(int16_t *samples, uint64_t sampleCount) override; //! @brief Get the inputs from the Window void getEvents(); //! @brief Use this function to create the window. diff --git a/sources/Renderer/QtRenderer/QtSFML.cpp b/sources/Renderer/QtRenderer/QtSFML.cpp index d7baf96..53d1e35 100644 --- a/sources/Renderer/QtRenderer/QtSFML.cpp +++ b/sources/Renderer/QtRenderer/QtSFML.cpp @@ -12,7 +12,7 @@ #ifdef Q_WS_X11 #include - #include + #include #endif namespace ComSquare::Renderer @@ -87,7 +87,7 @@ namespace ComSquare::Renderer void QtSFML::playAudio(int16_t *samples, uint64_t sampleCount) { - this->_sfWidget->playAudio(samples, sampleCount); + this->_sfWidget->playAudio(samples, sampleCount); } void QtSFML::drawScreen() { } diff --git a/sources/Renderer/QtRenderer/QtSFML.hpp b/sources/Renderer/QtRenderer/QtSFML.hpp index 7d1791a..204a046 100644 --- a/sources/Renderer/QtRenderer/QtSFML.hpp +++ b/sources/Renderer/QtRenderer/QtSFML.hpp @@ -65,11 +65,11 @@ namespace ComSquare::Renderer void putPixel(unsigned y, unsigned x, uint32_t rgba) override; //! @brief This function doesn't do anything because QT internally handle drawing to the screen. void drawScreen() override; - //! @brief Playing all samples from buffer - //! @param samples Buffer containing samples - //! @param sampleCount number of samples inside buffer - void playAudio(int16_t *samples, uint64_t sampleCount) override; - //! @brief Set a new name to the window, if there is already a name it will be overwrite. + //! @brief Playing all samples from buffer + //! @param samples Buffer containing samples + //! @param sampleCount number of samples inside buffer + void playAudio(int16_t *samples, uint64_t sampleCount) override; + //! @brief Set a new name to the window, if there is already a name it will be overwrite. //! @param newWindowName new title for the window. void setWindowName(std::string &newWindowName) override; //! @brief Constructor that return a SFML renderer inside a QT window. diff --git a/sources/Renderer/SFRenderer.cpp b/sources/Renderer/SFRenderer.cpp index a7c99b3..faae54b 100644 --- a/sources/Renderer/SFRenderer.cpp +++ b/sources/Renderer/SFRenderer.cpp @@ -18,8 +18,8 @@ namespace ComSquare::Renderer this->_texture.create(width, height); this->_sprite.setTexture(this->_texture); this->_pixelBuffer = new sf::Color[height * width]; - this->_sound.setBuffer(this->_soundBuffer); - } + this->_sound.setBuffer(this->_soundBuffer); + } void SFRenderer::createWindow(SNES &snes, int maxFPS) { @@ -55,10 +55,10 @@ namespace ComSquare::Renderer } void SFRenderer::playAudio(int16_t *samples, uint64_t sampleCount) - { - this->_soundBuffer.loadFromSamples(samples, sampleCount, 2, 32040); - this->_sound.play(); - } + { + this->_soundBuffer.loadFromSamples(samples, sampleCount, 2, 32040); + this->_sound.play(); + } void SFRenderer::putPixel(unsigned y, unsigned x, uint32_t rgba) { diff --git a/sources/Renderer/SFRenderer.hpp b/sources/Renderer/SFRenderer.hpp index 9d902c8..8cceb3b 100644 --- a/sources/Renderer/SFRenderer.hpp +++ b/sources/Renderer/SFRenderer.hpp @@ -40,7 +40,7 @@ namespace ComSquare::Renderer //! @brief The buffer containing samples to be played sf::SoundBuffer _soundBuffer; //! @brief the sound played - sf::Sound _sound; + sf::Sound _sound; public: //! @brief Tells to the program if the window has been closed, and therefore if he should stop bool shouldExit = false; @@ -54,9 +54,9 @@ namespace ComSquare::Renderer //! @param Y vertical index. //! @param rgba The color of the pixel. void putPixel(unsigned y, unsigned x, uint32_t rgba) override; - //! @brief Playing all samples from buffer - //! @param samples Buffer containing samples - //! @param sampleCount number of samples inside buffer + //! @brief Playing all samples from buffer + //! @param samples Buffer containing samples + //! @param sampleCount number of samples inside buffer void playAudio(int16_t *samples, uint64_t sampleCount) override; //! @brief Get the inputs from the Window void getEvents();