diff --git a/CMakeLists.txt b/CMakeLists.txt index 11db3319..1c4ae495 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) endif() -project ("sdl2-hyper-sonic-drivers" VERSION 0.14.0 DESCRIPTION "SDL2 based Hyper-Sonic Drivers for emulating old soundcards") +project ("sdl2-hyper-sonic-drivers" VERSION 0.13.0 DESCRIPTION "SDL2 based Hyper-Sonic Drivers for emulating old soundcards") include (TestBigEndian) TEST_BIG_ENDIAN(IS_BIG_ENDIAN) if(IS_BIG_ENDIAN) diff --git a/sdl2-hyper-sonic-drivers/CMakeLists.txt b/sdl2-hyper-sonic-drivers/CMakeLists.txt index 2854e4d6..692571eb 100644 --- a/sdl2-hyper-sonic-drivers/CMakeLists.txt +++ b/sdl2-hyper-sonic-drivers/CMakeLists.txt @@ -75,9 +75,9 @@ target_include_directories(${LIB_NAME} PUBLIC target_sources(${LIB_NAME} PRIVATE # --- # ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/audio/IMixer.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/audio/Renderer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/audio/mixer/Channel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/audio/sdl2/Mixer.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp # --- # ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/audio/MIDI.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/audio/midi/MIDITrack.cpp diff --git a/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp b/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp index 18f6276c..87c1aab1 100644 --- a/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp +++ b/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp new file mode 100644 index 00000000..c47b346e --- /dev/null +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace HyperSonicDrivers::audio +{ + class IRenderer + { + public: + IRenderer() = default; + virtual ~IRenderer() = default; + + virtual void openOutputFile(const std::filesystem::path& path) = 0; + virtual void closeOutputFile() noexcept = 0; + + inline std::shared_ptr getMixer() const noexcept { return m_mixer; }; + + virtual void renderBuffer(IAudioStream* stream) = 0; + inline void renderBuffer(const std::shared_ptr& device) { renderBuffer(device->getHardware()->getAudioStream().get()); }; + + protected: + std::shared_ptr m_mixer; + }; +} diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/Renderer.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/Renderer.hpp deleted file mode 100644 index e3836a59..00000000 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/Renderer.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace HyperSonicDrivers::audio -{ - class Renderer - { - public: - explicit Renderer(const size_t buffer_size); - virtual ~Renderer() = default; - - void openOutputFile(const std::filesystem::path& path); - void closeOutputFile() noexcept; - - void renderBuffer(IAudioStream* stream); - - inline void renderBuffer(const std::shared_ptr& device) { renderBuffer(device->getHardware()->getAudioStream().get()); }; - - private: - const size_t m_buf_size; - std::unique_ptr m_out; - std::vector m_buf; - }; -} diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/Renderer.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp similarity index 62% rename from sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/Renderer.cpp rename to sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp index 2157f620..7f27958d 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/Renderer.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp @@ -1,10 +1,13 @@ -#include -#include +#include +#include +#include -namespace HyperSonicDrivers::audio + +namespace HyperSonicDrivers::audio::sdl2 { - Renderer::Renderer(const size_t buffer_size) : m_buf_size(buffer_size) + Renderer::Renderer(const uint32_t freq, const uint16_t buffer_size) { + m_mixer = make_mixer(1, freq, buffer_size); } void Renderer::openOutputFile(const std::filesystem::path& path) @@ -15,7 +18,6 @@ namespace HyperSonicDrivers::audio void Renderer::closeOutputFile() noexcept { - m_out->save_end(); m_out.reset(); } @@ -24,7 +26,7 @@ namespace HyperSonicDrivers::audio if (m_buf.empty()) { m_out->save_prepare(stream->getRate(), stream->isStereo()); - m_buf.resize(m_buf_size); + m_buf.resize(m_mixer->getBufferSize()); } const size_t read = stream->readBuffer(m_buf.data(), m_buf.size()); diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.hpp new file mode 100644 index 00000000..9774f659 --- /dev/null +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +namespace HyperSonicDrivers::audio::sdl2 +{ + class Renderer : public IRenderer + { + public: + Renderer(const uint32_t freq, const uint16_t buffer_size); + ~Renderer() override = default; + + void openOutputFile(const std::filesystem::path& path) override; + void closeOutputFile() noexcept override; + + void renderBuffer(IAudioStream* stream) override; + using IRenderer::renderBuffer; + private: + std::unique_ptr m_out; + std::vector m_buf; + }; +} diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/IHardware.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/IHardware.hpp index c2cbc8c2..1385ade0 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/IHardware.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/IHardware.hpp @@ -10,7 +10,7 @@ namespace HyperSonicDrivers::audio { - class Renderer; + class IRenderer; namespace streams { @@ -27,7 +27,7 @@ namespace HyperSonicDrivers::hardware class IHardware { friend audio::streams::EmulatedStream; - friend audio::Renderer; + friend audio::IRenderer; public: explicit IHardware(const std::shared_ptr& mixer); diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/CMakeLists.txt b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/CMakeLists.txt index e6ad891b..5873f81a 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/CMakeLists.txt +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/CMakeLists.txt @@ -262,7 +262,7 @@ macro_test( macro_test( EXE TestRenderer - FILES "audio/TestRenderer.cpp" + FILES "audio/sdl2/TestRenderer.cpp" LINKS_PRIVATE hyper-sonic-drivers-static FIXTURES "../fixtures/test_renderer_adlib_mame2.wav" diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/TestRenderer.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp similarity index 67% rename from sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/TestRenderer.cpp rename to sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp index 87b1cd8c..47dd27d6 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/TestRenderer.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -9,7 +9,7 @@ #include #include -namespace HyperSonicDrivers::audio +namespace HyperSonicDrivers::audio::sdl2 { using audio::mixer::eChannelGroup; using hardware::opl::OplEmulator; @@ -55,7 +55,7 @@ namespace HyperSonicDrivers::audio ASSERT_FALSE(std::filesystem::exists(rfile)); { - audio::Renderer r(freq); + audio::sdl2::Renderer r(freq, 1024); r.openOutputFile(rfile); auto drv1 = drivers::westwood::ADLDriver(opl, eChannelGroup::Music); @@ -92,50 +92,6 @@ namespace HyperSonicDrivers::audio std::make_tuple<>("sbpro2_dosbox", 44100, eDeviceName::SbPro2, OplEmulator::DOS_BOX) ) ); - - - // This disabled test are generating a shorter wav file. WHY? - TEST(DISABLED_Renderer, adlib_mame2) - { - constexpr const char* exp_renderer = "../fixtures/test_renderer_adlib_mame2.wav"; - constexpr const char* rfile = "test_renderer_adlib_mame2_out.wav"; - - if (std::filesystem::exists(rfile)) - std::filesystem::remove(rfile); - - ASSERT_FALSE(std::filesystem::exists(rfile)); - - audio::Renderer r(1024); - r.openOutputFile(rfile); - - auto mixer = std::make_shared(); - - auto adlib = devices::make_device(mixer, OplEmulator::MAME); - auto drv1 = drivers::westwood::ADLDriver(adlib, eChannelGroup::Music); - auto af = std::make_shared("../fixtures/DUNE0.ADL"); - drv1.setADLFile(af); - - drv1.play(4); - while (drv1.isPlaying()) - r.renderBuffer(adlib); - - r.closeOutputFile(); - - files::WAVFile w(rfile); - auto sound = w.getSound(); - files::WAVFile wexp(exp_renderer); - auto exp_sound = wexp.getSound(); - - ASSERT_EQ(sound->dataSize, exp_sound->dataSize); - ASSERT_EQ(sound->freq, exp_sound->freq); - ASSERT_EQ(sound->stereo, exp_sound->stereo); - EXPECT_EQ(sound->freq, 44100); - EXPECT_FALSE(sound->stereo); - for (uint32_t i = 0; i < sound->dataSize; i++) - { - EXPECT_EQ(sound->data[i], exp_sound->data[i]); - } - } } int main(int argc, char** argv) diff --git a/sdl2-hyper-sonic-drivers/test/fixtures/test_renderer_adlib_mame2.wav b/sdl2-hyper-sonic-drivers/test/fixtures/test_renderer_adlib_mame2.wav index eac53834..1fb2ded8 100644 Binary files a/sdl2-hyper-sonic-drivers/test/fixtures/test_renderer_adlib_mame2.wav and b/sdl2-hyper-sonic-drivers/test/fixtures/test_renderer_adlib_mame2.wav differ diff --git a/sdl2-hyper-sonic-drivers/test/fixtures/test_renderer_sbpro2_dosbox.wav b/sdl2-hyper-sonic-drivers/test/fixtures/test_renderer_sbpro2_dosbox.wav index 29f033f9..5e642b66 100644 Binary files a/sdl2-hyper-sonic-drivers/test/fixtures/test_renderer_sbpro2_dosbox.wav and b/sdl2-hyper-sonic-drivers/test/fixtures/test_renderer_sbpro2_dosbox.wav differ