diff --git a/CMakeLists.txt b/CMakeLists.txt index e85d7f4e..1e250421 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.12.3 DESCRIPTION "SDL2 based Hyper-Sonic Drivers for emulating old soundcards") +project ("sdl2-hyper-sonic-drivers" VERSION 0.12.4 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 e3f305a7..692571eb 100644 --- a/sdl2-hyper-sonic-drivers/CMakeLists.txt +++ b/sdl2-hyper-sonic-drivers/CMakeLists.txt @@ -100,6 +100,7 @@ target_sources(${LIB_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/devices/MT32.cpp # --- # ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/PCMDriver.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/IMusicDriver.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/MIDDriver.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/midi/IMidiDriver.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/midi/IMidiChannel.cpp diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp index d7a78948..0cf8adc2 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace HyperSonicDrivers::audio { @@ -21,6 +22,7 @@ namespace HyperSonicDrivers::audio virtual void renderBuffer(IAudioStream* stream) = 0; inline void renderBuffer(const std::shared_ptr& opl) { renderBuffer(opl->getAudioStream().get()); }; + inline void renderBuffer(const std::shared_ptr& opl) { renderBuffer(opl->getHardware()->getAudioStream().get()); }; protected: std::shared_ptr m_mixer; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/Adlib.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/Adlib.cpp index d1b346ee..9333e80d 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/Adlib.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/Adlib.cpp @@ -12,4 +12,9 @@ namespace HyperSonicDrivers::devices Opl(mixer, emulator, OplType::OPL2, volume, pan) { } + + eDeviceName Adlib::getName() const noexcept + { + return eDeviceName::Adlib; + } } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/Adlib.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/Adlib.hpp index 75a7d552..bb766deb 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/Adlib.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/Adlib.hpp @@ -23,5 +23,7 @@ namespace HyperSonicDrivers::devices ); ~Adlib() override = default; + + eDeviceName getName() const noexcept override; }; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/IDevice.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/IDevice.hpp index 2f088bb1..d8ec2d79 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/IDevice.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/IDevice.hpp @@ -4,56 +4,64 @@ #include #include #include -#include #include #include #include -namespace HyperSonicDrivers::devices +namespace HyperSonicDrivers { - /** - * general interface for sound cards used by the drivers - * that is bound to a specific hardware - **/ - class IDevice + namespace drivers { - public: - IDevice(const std::shared_ptr& mixer, const eDeviceType type); - virtual ~IDevice() = default; - - virtual bool init() noexcept = 0; - virtual bool shutdown() noexcept = 0; - inline bool isInit() const noexcept { return m_init; }; - - std::optional getChannelId() const noexcept { return m_hardware->getChannelId(); }; - - inline bool isAcquired() const noexcept { return m_acquired; } - inline bool isOwned(const drivers::IMusicDriver* owner) const noexcept { return m_owner == owner; } - - bool acquire(drivers::IMusicDriver* owner); - bool release(const drivers::IMusicDriver* owner); - - // helpers methods - void setVolume(const uint8_t volume); - void setPan(const uint8_t pan); - void setVolumePan(const uint8_t volume, const uint8_t pan); - - inline std::shared_ptr getMixer() const noexcept { return m_mixer; }; - virtual hardware::IHardware* getHardware() const noexcept { return m_hardware; }; - const eDeviceType type; - protected: - bool m_init = false; - std::shared_ptr m_mixer; - hardware::IHardware* m_hardware = nullptr; - private: - // TODO: remove the atomic when removing the thread in MIDDrv - std::atomic m_acquired = false; - std::atomic m_owner = nullptr; - }; - - template - std::shared_ptr make_device(Args... args) + class IMusicDriver; + } + + namespace devices { - return std::dynamic_pointer_cast(std::make_shared(args...)); + /** + * general interface for sound cards used by the drivers + * that is bound to a specific hardware + **/ + class IDevice + { + public: + IDevice(const std::shared_ptr& mixer, const eDeviceType type); + virtual ~IDevice() = default; + + virtual bool init() noexcept = 0; + virtual bool shutdown() noexcept = 0; + inline bool isInit() const noexcept { return m_init; }; + + std::optional getChannelId() const noexcept { return m_hardware->getChannelId(); }; + + inline bool isAcquired() const noexcept { return m_acquired; } + inline bool isOwned(const drivers::IMusicDriver* owner) const noexcept { return m_owner == owner; } + + bool acquire(drivers::IMusicDriver* owner); + bool release(const drivers::IMusicDriver* owner); + + // helpers methods + void setVolume(const uint8_t volume); + void setPan(const uint8_t pan); + void setVolumePan(const uint8_t volume, const uint8_t pan); + + inline std::shared_ptr getMixer() const noexcept { return m_mixer; }; + virtual hardware::IHardware* getHardware() const noexcept { return m_hardware; }; + virtual eDeviceName getName() const noexcept = 0; + const eDeviceType type; + protected: + bool m_init = false; + std::shared_ptr m_mixer; + hardware::IHardware* m_hardware = nullptr; + private: + // TODO: remove the atomic when removing the thread in MIDDrv + std::atomic m_acquired = false; + std::atomic m_owner = nullptr; + }; + + template + std::shared_ptr make_device(Args... args) + { + return std::dynamic_pointer_cast(std::make_shared(args...)); + } } } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/MT32.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/MT32.cpp index b8e6c614..ca89f6b3 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/MT32.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/MT32.cpp @@ -32,6 +32,11 @@ namespace HyperSonicDrivers::devices return false; } + eDeviceName MT32::getName() const noexcept + { + return eDeviceName::MT32; + } + void MT32::lcd_message(const std::string& msg) noexcept { m_mt32->sysEx( diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/MT32.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/MT32.hpp index 60a5a19f..4b854fe3 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/MT32.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/MT32.hpp @@ -24,6 +24,8 @@ namespace HyperSonicDrivers::devices bool init() noexcept override; bool shutdown() noexcept override; + eDeviceName getName() const noexcept override; + inline std::shared_ptr getMt32() const noexcept { return m_mt32; }; void lcd_message(const std::string& msg) noexcept; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/Opl.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/Opl.cpp index 0b3ab61c..982cc123 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/Opl.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/Opl.cpp @@ -15,7 +15,8 @@ namespace HyperSonicDrivers::devices const hardware::opl::OplEmulator emulator, const hardware::opl::OplType type, const uint8_t volume, const uint8_t pan) : - IDevice(mixer, eDeviceType::Opl) + IDevice(mixer, eDeviceType::Opl), + m_emulator(emulator) { using hardware::opl::OPLFactory; using utils::logC; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/Opl.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/Opl.hpp index 911d8251..14f70526 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/Opl.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/Opl.hpp @@ -27,8 +27,10 @@ namespace HyperSonicDrivers::devices bool shutdown() noexcept override; inline std::shared_ptr getOpl() const noexcept { return m_opl; }; - hardware::opl::OPL* getHardware() const noexcept override { return dynamic_cast(IDevice::getHardware()); }; + inline hardware::opl::OPL* getHardware() const noexcept override { return dynamic_cast(IDevice::getHardware()); }; + inline hardware::opl::OplEmulator getEmulatorType() const noexcept { return m_emulator; }; private: std::shared_ptr m_opl; + const hardware::opl::OplEmulator m_emulator; }; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/SbPro.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/SbPro.cpp index c5ca9139..2ed2d4ed 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/SbPro.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/SbPro.cpp @@ -12,4 +12,9 @@ namespace HyperSonicDrivers::devices Opl(mixer, emulator, OplType::DUAL_OPL2, volume, pan) { } + + eDeviceName SbPro::getName() const noexcept + { + return eDeviceName::SbPro; + } } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/SbPro.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/SbPro.hpp index 861d0909..1b1c0e28 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/SbPro.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/SbPro.hpp @@ -23,5 +23,7 @@ namespace HyperSonicDrivers::devices ); ~SbPro() override = default; + + eDeviceName getName() const noexcept override; }; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/SbPro2.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/SbPro2.cpp index d690e1f1..b5a0672c 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/SbPro2.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/SbPro2.cpp @@ -12,4 +12,9 @@ namespace HyperSonicDrivers::devices Opl(mixer, emulator, OplType::OPL3, volume, pan) { } + + eDeviceName SbPro2::getName() const noexcept + { + return eDeviceName::SbPro2; + } } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/SbPro2.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/SbPro2.hpp index fea3c64d..aac515f6 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/SbPro2.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/SbPro2.hpp @@ -23,5 +23,7 @@ namespace HyperSonicDrivers::devices ); ~SbPro2() override = default; + + eDeviceName getName() const noexcept override; }; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/types.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/types.hpp index e43e4109..52ac9ad0 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/types.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/types.hpp @@ -7,4 +7,12 @@ namespace HyperSonicDrivers::devices Opl = 0, Mt32, }; + + enum class eDeviceName + { + Adlib, + SbPro, + SbPro2, + MT32 + }; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/IMusicDriver.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/IMusicDriver.cpp new file mode 100644 index 00000000..95c82099 --- /dev/null +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/IMusicDriver.cpp @@ -0,0 +1,14 @@ +#include +#include + +namespace HyperSonicDrivers::drivers +{ + IMusicDriver::IMusicDriver(const std::shared_ptr& device) : + m_device(device) + { + if (m_device == nullptr) + { + utils::throwLogC("device is null"); + } + } +} diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/IMusicDriver.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/IMusicDriver.hpp index d8b38b61..482fff31 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/IMusicDriver.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/IMusicDriver.hpp @@ -1,5 +1,8 @@ #pragma once +#include +#include + namespace HyperSonicDrivers::drivers { /** @@ -16,7 +19,7 @@ namespace HyperSonicDrivers::drivers IMusicDriver(IMusicDriver&&) = delete; IMusicDriver& operator=(IMusicDriver&) = delete; - IMusicDriver() = default; + explicit IMusicDriver(const std::shared_ptr& device); virtual ~IMusicDriver() = default; virtual void play(const uint8_t track) noexcept = 0; @@ -31,5 +34,10 @@ namespace HyperSonicDrivers::drivers // TODO: it might not be required //virtual bool isPaused() const noexcept = 0; + + inline std::shared_ptr getDevice() const noexcept { return m_device; }; + protected: + // this is used to "lock" the device to a specific driver output and passed to IMidiDriver + std::shared_ptr m_device; }; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp index f2dec378..6eb6e6c8 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp @@ -38,7 +38,8 @@ namespace HyperSonicDrivers::drivers const audio::mixer::eChannelGroup group, const uint8_t volume, const uint8_t pan - ) : m_device(device), m_group(group), m_volume(volume), m_pan(pan) + ) : IMusicDriver(device), + m_group(group), m_volume(volume), m_pan(pan) { // TODO: move the acquire logic where the callback is set // NOTE/TODO: this brings up the acquire should set up the callback too? diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.hpp index 50390305..89a47314 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.hpp @@ -56,8 +56,6 @@ namespace HyperSonicDrivers::drivers inline void setTempo(const uint32_t tempo) noexcept { m_midiTempoChanged = true; m_tempo = tempo; } bool open_() noexcept; private: - // this is used to "lock" the device to a specific driver output and passed to IMidiDriver - std::shared_ptr m_device; // this is to abstract the specific midi driver implementation std::unique_ptr m_midiDriver; std::shared_ptr m_midi; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.cpp index cb1ec3d8..49e5af33 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.cpp @@ -28,7 +28,8 @@ namespace HyperSonicDrivers::drivers::westwood const audio::mixer::eChannelGroup group, const uint8_t volume, const uint8_t pan) : - m_device(opl), m_opl(opl->getOpl()) + IMusicDriver(opl), + m_opl(opl->getOpl()) { memset(m_channels.data(), 0, sizeof(m_channels)); hardware::TimerCallBack cb = std::bind(&ADLDriver::onCallback, this); diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.hpp index bc57f6e2..3ac691fe 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.hpp @@ -255,7 +255,6 @@ namespace HyperSonicDrivers::drivers::westwood uint8_t m_opExtraLevel1BD = 0; uint8_t m_opExtraLevel2BD = 0; - std::shared_ptr m_device; std::shared_ptr m_opl; struct QueueEntry diff --git a/sdl2-hyper-sonic-drivers/src/std/IDeviceTypesFormatter.hpp b/sdl2-hyper-sonic-drivers/src/std/IDeviceTypesFormatter.hpp new file mode 100644 index 00000000..97916edb --- /dev/null +++ b/sdl2-hyper-sonic-drivers/src/std/IDeviceTypesFormatter.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include + +namespace std +{ + template<> + struct formatter : formatter + { + template + auto format(HyperSonicDrivers::devices::eDeviceName device_name, FormatContext& fc) const + { + string str; + + switch (device_name) + { + using enum HyperSonicDrivers::devices::eDeviceName; + + case Adlib: + str = "Adlib"; + break; + case SbPro: + str = "SbPro"; + break; + case SbPro2: + str = "SbPro2"; + break; + case MT32: + str = "MT32"; + break; + } + + return formatter::format(str, fc); + } + }; +} diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/CMakeLists.txt b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/CMakeLists.txt index 0a286685..bfea9ca4 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/CMakeLists.txt +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/CMakeLists.txt @@ -170,6 +170,13 @@ macro_test( "../fixtures/midifile_sample.mid" ) +macro_test( + EXE TestIMusicDriver + FILES "drivers/TestIMusicDriver.cpp" + LINKS_PRIVATE hyper-sonic-drivers-static + FIXTURES +) + macro_test( EXE TestMameOPL2 FILES "hardware/opl/scummvm/mame/TestMameOPL2.cpp" 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 8def41fe..40a2d3af 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp @@ -12,7 +12,7 @@ namespace HyperSonicDrivers::audio::sdl2 using devices::Adlib; using hardware::opl::OplEmulator; - TEST(Renderer, test_adlib_mame2) + TEST(Renderer, adlib_mame2) { constexpr const char* exp_renderer = "../fixtures/test_renderer_adlib_mame2.wav"; constexpr const char* rfile = "test_renderer_adlib_mame2_out.wav"; @@ -52,6 +52,46 @@ namespace HyperSonicDrivers::audio::sdl2 EXPECT_EQ(sound->data[i], exp_sound->data[i]); } } + + TEST(Renderer, adlib_mame2_device) + { + 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::sdl2::Renderer r(44100, 1024); + r.setOutputFile(rfile); + + auto mixer = r.getMixer(); + + 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.releaseOutputFile(); + + 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); + 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/HyperSonicDrivers/devices/OplDeviceMock.hpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/OplDeviceMock.hpp index 7ad2da8b..4c88ec3a 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/OplDeviceMock.hpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/OplDeviceMock.hpp @@ -17,6 +17,12 @@ namespace HyperSonicDrivers::devices : Opl(mixer, emuType, type, 255, 0) { } + ~OplDeviceMock() override = default; + + eDeviceName getName() const noexcept + { + return eDeviceName::Adlib; + } }; } diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/TestAdlib.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/TestAdlib.cpp index b75b854f..b752f150 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/TestAdlib.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/TestAdlib.cpp @@ -17,6 +17,13 @@ namespace HyperSonicDrivers::devices EXPECT_NO_THROW(auto a = std::make_shared(mixer)); } + TEST(Adlib, device_name) + { + auto mixer = std::make_shared(); + auto a = std::make_shared(mixer); + EXPECT_EQ(a->getName(), eDeviceName::Adlib); + } + class AdliblEmulator_ : public EmulatorTestCase {}; TEST_P(AdliblEmulator_, cstr_TYPE) { diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/TestSbPro.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/TestSbPro.cpp index 1a182de8..9490577e 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/TestSbPro.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/TestSbPro.cpp @@ -15,6 +15,13 @@ namespace HyperSonicDrivers::devices EXPECT_NO_THROW(auto s = SbPro(mixer, OplEmulator::DOS_BOX)); } + TEST(Adlib, device_name) + { + auto mixer = std::make_shared(); + auto s = std::make_shared(mixer); + EXPECT_EQ(s->getName(), eDeviceName::SbPro); + } + class SbProEmulator_ : public EmulatorTestCase {}; TEST_P(SbProEmulator_, cstr_TYPE) { diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/TestSbPro2.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/TestSbPro2.cpp index 86524dec..c2ae4e04 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/TestSbPro2.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/TestSbPro2.cpp @@ -13,6 +13,13 @@ namespace HyperSonicDrivers::devices EXPECT_NO_THROW(auto s = SbPro2(mixer, OplEmulator::NUKED)); } + TEST(Adlib, device_name) + { + auto mixer = std::make_shared(); + auto s = std::make_shared(mixer); + EXPECT_EQ(s->getName(), eDeviceName::SbPro2); + } + class SbPro2Emulator_ : public EmulatorTestCase {}; TEST_P(SbPro2Emulator_, cstr_TYPE) diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestIMusicDriver.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestIMusicDriver.cpp new file mode 100644 index 00000000..4993e965 --- /dev/null +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestIMusicDriver.cpp @@ -0,0 +1,26 @@ +#include +#include +#include + +namespace HyperSonicDrivers::drivers +{ + class IMusicDriverMock : public IMusicDriver + { + public: + IMusicDriverMock(const std::shared_ptr& device) : IMusicDriver(device) {} + void play(const uint8_t track) noexcept override {}; + void stop() noexcept override {}; + bool isPlaying() const noexcept override { return false; }; + }; + + TEST(IMusicDriver, cstor_nullptr) + { + EXPECT_THROW(IMusicDriverMock md(nullptr), std::runtime_error); + } +} + +int main(int argc, char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/sdl2-hyper-sonic-drivers/test/std/CMakeLists.txt b/sdl2-hyper-sonic-drivers/test/std/CMakeLists.txt index e29adebc..e8d07148 100644 --- a/sdl2-hyper-sonic-drivers/test/std/CMakeLists.txt +++ b/sdl2-hyper-sonic-drivers/test/std/CMakeLists.txt @@ -66,3 +66,7 @@ macro_test( FILES "ILoggerFormatterTest.cpp" ) +macro_test( + EXE TestIDeviceFormatter + FILES "IDeviceTypesFormatterTest.cpp" +) diff --git a/sdl2-hyper-sonic-drivers/test/std/IDeviceTypesFormatterTest.cpp b/sdl2-hyper-sonic-drivers/test/std/IDeviceTypesFormatterTest.cpp new file mode 100644 index 00000000..cfc0b437 --- /dev/null +++ b/sdl2-hyper-sonic-drivers/test/std/IDeviceTypesFormatterTest.cpp @@ -0,0 +1,17 @@ +#include +#include +#include + +namespace std +{ + TEST(IDeviceTypesFormatter, Music) + { + ASSERT_STRCASEEQ(std::format("{}", HyperSonicDrivers::devices::eDeviceName::Adlib).c_str(), "Adlib"); + } +} + +int main(int argc, char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}