diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp index eb223cc8..5e16bf16 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp @@ -26,11 +26,21 @@ namespace HyperSonicDrivers::audio virtual void renderBuffer(IAudioStream* stream) = 0; inline void renderBuffer(const std::shared_ptr& device) { renderBuffer(device->getHardware()->getAudioStream().get()); }; + + /** + * It flushes the AudioStream until it detects the silence. + * It returns false if it reached max iterations but it didn't flush it completely. + * It returns true when silence is detected or nothing more to read from the stream + **/ virtual bool renderFlush(IAudioStream* stream) = 0; inline bool renderFlush(const std::shared_ptr& device) { return renderFlush(device->getHardware()->getAudioStream().get()); }; - virtual bool renderBuffer(IAudioStream* stream, drivers::IAudioDriver& drv, const int track) = 0; - inline bool renderBuffer(const std::shared_ptr& device, drivers::IAudioDriver& drv, const int track) { return renderBuffer(device->getHardware()->getAudioStream().get(), drv, track); }; + /** + * this is doing the render until the drv is play the track and call the render flush after all + * it returns the renderFlush returned value + **/ + virtual bool renderBufferFlush(IAudioStream* stream, drivers::IAudioDriver& drv, const int track) = 0; + inline bool renderBufferFlush(const std::shared_ptr& device, drivers::IAudioDriver& drv, const int track) { return renderBufferFlush(device->getHardware()->getAudioStream().get(), drv, track); }; protected: std::shared_ptr m_mixer; std::unique_ptr m_out; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp index 7d245c75..e8f67527 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp @@ -62,7 +62,7 @@ namespace HyperSonicDrivers::audio::sdl2 return false; } - bool Renderer::renderBuffer(IAudioStream* stream, drivers::IAudioDriver& drv, const int track) + bool Renderer::renderBufferFlush(IAudioStream* stream, drivers::IAudioDriver& drv, const int track) { drv.play(track); while (drv.isPlaying()) diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.hpp index 50255ac4..0ff2886c 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.hpp @@ -15,12 +15,13 @@ namespace HyperSonicDrivers::audio::sdl2 void openOutputFile(const std::filesystem::path& path) override; void closeOutputFile() noexcept override; - - void renderBuffer(IAudioStream* stream) override; + using IRenderer::renderBuffer; - bool renderFlush(IAudioStream* stream) override; using IRenderer::renderFlush; + using IRenderer::renderBufferFlush; - bool renderBuffer(IAudioStream* stream, drivers::IAudioDriver& drv, const int track) override; + void renderBuffer(IAudioStream* stream) override; + bool renderFlush(IAudioStream* stream) override; + bool renderBufferFlush(IAudioStream* stream, drivers::IAudioDriver& drv, const int track) override; }; } diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp index 3fd587e2..50d2e054 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp @@ -102,7 +102,7 @@ namespace HyperSonicDrivers::audio::sdl2 auto af = std::make_shared("../fixtures/DUNE0.ADL"); drv1.setADLFile(af); - ASSERT_TRUE(r.renderBuffer(opl, drv1, 4)); + ASSERT_TRUE(r.renderBufferFlush(opl, drv1, 4)); r.closeOutputFile(); }