From e73a9b3ff748e413a76a069630b0c228c77e9f75 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sun, 31 Dec 2023 22:51:10 +0000 Subject: [PATCH 01/15] review ADLFile --- .../src/HyperSonicDrivers/files/westwood/ADLFile.cpp | 3 +++ .../test/HyperSonicDrivers/files/westwood/TestADLFile.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp index 65894631..b905ed42 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp @@ -111,6 +111,7 @@ namespace HyperSonicDrivers::files::westwood readDataFromFile_(m_meta_version.data_offset, m_meta_version.data_header_size); + // TODO: count_loop_ for version 3 is wrong to be 8 bit i think m_num_tracks = count_loop_(0, m_header); m_num_track_offsets = count_loop_(m_meta_version.offset_start, m_track_offsets); m_num_instrument_offsets = count_loop_(m_meta_version.offset_start, m_instrument_offsets); @@ -262,6 +263,8 @@ namespace HyperSonicDrivers::files::westwood void ADLFile::readHeaderFromFile_(const int header_size, std::function read) { m_header.resize(header_size); + // TODO: pass the byte size instead of a function read and read at once, + // and do read in LE when is greter than 1, basically if version 3 for (int i = 0; i < header_size; i++) { m_header[i] = read(); diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/files/westwood/TestADLFile.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/files/westwood/TestADLFile.cpp index d425daa4..6acdb674 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/files/westwood/TestADLFile.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/files/westwood/TestADLFile.cpp @@ -56,7 +56,7 @@ namespace HyperSonicDrivers::files::westwood ADLFileMock f("../fixtures/DUNE0.ADL"); EXPECT_EQ(f.getVersion(), 2); - EXPECT_EQ(f.getNumTracks(), 18); + EXPECT_EQ(f.getNumTracks(), 200); EXPECT_EQ(f.getNumTrackOffsets(), 52); EXPECT_EQ(f.getNumInstrumentOffsets(), 63); EXPECT_EQ(f.parentSize(), 14473); From f7047282e45cb91d8c16182bf37007ccc20e26ca Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sat, 23 Aug 2025 04:26:30 +0100 Subject: [PATCH 02/15] code rev --- .../sdl2-hyper-sonic-drivers.cpp | 166 ++++++++++++------ .../drivers/midi/IMidiChannelVoice.cpp | 2 +- .../files/westwood/ADLFile.hpp | 3 +- 3 files changed, 116 insertions(+), 55 deletions(-) diff --git a/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp b/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp index 63f5030e..616ecc26 100644 --- a/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp +++ b/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp @@ -36,6 +36,7 @@ #include #include #include +#include using namespace std; @@ -130,7 +131,7 @@ int pcspkr(const int freq, const uint16_t audio, const int channels,const int ch // TODO try with channels. - Mix_HookMusic(pcSpeaker.callback, &pcSpeaker); + Mix_Hook(pcSpeaker.callback, &pcSpeaker); cout << "SQUARE" << endl; playNotes(&pcSpeaker, PCSpeaker::eWaveForm::SQUARE, 440, 300); @@ -355,57 +356,115 @@ void pcm_sound_append() } } -//void adldune2filestest() -//{ -// auto mixer = audio::make_mixer(8, 44100, 1024); -// mixer->init(); -// -// auto device = devices::make_device(mixer); -// drivers::westwood::ADLDriver drv(device, audio::mixer::eChannelGroup::Music); -// -// SDL_InitSubSystem(SDL_INIT_EVENTS); -// SDL_InitSubSystem(SDL_INIT_VIDEO); -// -// auto window = SDL_CreateWindow("a", 0, 0, 320, 200, 0); -// -// for (int f = 0; f <= 0; f++) -// { -// const std::string fn = "adl/DUNE" + std::to_string(f) + ".ADL"; -// utils::ILogger::instance->info(std::format("opening file: {}", fn), utils::ILogger::eCategory::Application); -// auto adlf = std::make_shared(fn); -// drv.setADLFile(adlf); -// for (int i = 0; i < adlf->getNumTracks(); i++) -// { -// utils::ILogger::instance->info(std::format("playing track: {}", i), utils::ILogger::eCategory::Application); -// drv.play(i); -// while (drv.isPlaying()) -// { -// utils::delayMillis(200); -// SDL_Event e; -// while (SDL_PollEvent(&e)) -// switch (e.type) -// { -// case SDL_QUIT: -// goto QUIT; -// case SDL_KEYDOWN: -// //case SDL_KEYUP: -// if (e.key.keysym.sym == SDLK_ESCAPE) -// goto QUIT; -// if (e.key.keysym.sym == SDLK_RETURN) -// drv.stop(); -// break; -// -// default: -// std::cout << "event: " << e.type << std::endl; -// } -// } -// drv.stopAllChannels(); -// utils::delayMillis(1000); -// } -// } -//QUIT: -// SDL_DestroyWindow(window); -//} +void adldune2filestest() +{ + auto mixer = audio::make_mixer(8, 44100, 1024); + mixer->init(); + //utils::ILogger::instance->setLevelAll(utils::ILogger::eLevel::Debug); + auto device = devices::make_device(mixer); + drivers::westwood::ADLDriver drv(device, audio::mixer::eChannelGroup::Music); + + SDL_InitSubSystem(SDL_INIT_EVENTS); + SDL_InitSubSystem(SDL_INIT_VIDEO); + + auto window = SDL_CreateWindow("a", 0, 0, 320, 200, 0); + + for (int f = 0; f <= 0; f++) + { + //const std::string fn = "adl/DUNE" + std::to_string(f) + ".ADL"; + const std::string fn = "adl/KYRA1A.ADL"; + utils::ILogger::instance->info(std::format("opening file: {}", fn), utils::ILogger::eCategory::Application); + auto adlf = std::make_shared(fn); + drv.setADLFile(adlf); + for (int i = 1; i < adlf->getNumTracks(); i++) + { + utils::ILogger::instance->info(std::format("playing track: {}", i), utils::ILogger::eCategory::Application); + for (int j = 0; j < 3; j++) + { + utils::ILogger::instance->info(std::format("times: {}", j), utils::ILogger::eCategory::Application); + + drv.play(i); + while (drv.isPlaying()) + { + utils::delayMillis(200); + SDL_Event e; + while (SDL_PollEvent(&e)) + switch (e.type) + { + case SDL_QUIT: + goto QUIT; + case SDL_KEYDOWN: + //case SDL_KEYUP: + if (e.key.keysym.sym == SDLK_ESCAPE) + goto QUIT; + if (e.key.keysym.sym == SDLK_RETURN) + drv.stop(); + break; + + default: + std::cout << "event: " << e.type << std::endl; + } + } + } + drv.stopAllChannels(); + utils::delayMillis(1000); + } + } +QUIT: + SDL_DestroyWindow(window); +} + +void vocdune2filestest() +{ + auto mixer = audio::make_mixer(8, 44100, 1024); + mixer->init(); + + auto device = devices::make_device(mixer); + drivers::PCMDriver drv(mixer); + + SDL_InitSubSystem(SDL_INIT_EVENTS); + SDL_InitSubSystem(SDL_INIT_VIDEO); + + auto window = SDL_CreateWindow("a", 0, 0, 320, 200, 0); + + for (auto const& dir_entry : std::filesystem::directory_iterator{ "voc/" }) + { + const std::string fn = dir_entry.path().string(); + utils::ILogger::instance->info(std::format("opening file: {}", fn), utils::ILogger::eCategory::Application); + auto vocf = std::make_shared(fn); + + for (int j = 0; j < 10; j++) + { + utils::ILogger::instance->info(std::format("times: {}", j), utils::ILogger::eCategory::Application); + + drv.play(vocf->getSound()); + while (drv.isPlaying()) + { + //utils::delayMillis(200); + SDL_Event e; + while (SDL_PollEvent(&e)) + switch (e.type) + { + case SDL_QUIT: + goto QUIT; + case SDL_KEYDOWN: + //case SDL_KEYUP: + if (e.key.keysym.sym == SDLK_ESCAPE) + goto QUIT; + if (e.key.keysym.sym == SDLK_RETURN) + drv.stop(); + break; + + default: + std::cout << "event: " << e.type << std::endl; + } + } + } + utils::delayMillis(1000); + } +QUIT: + SDL_DestroyWindow(window); +} int main(int argc, char* argv[]) { @@ -417,7 +476,8 @@ int main(int argc, char* argv[]) //testMT32(); //pcm_sound_append(); - //adldune2filestest(); + adldune2filestest(); + //vocdune2filestest(); //return 0; //sdlMixer(); //SDL_Delay(100); diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/IMidiChannelVoice.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/IMidiChannelVoice.cpp index 11f6d800..6ff67c68 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/IMidiChannelVoice.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/IMidiChannelVoice.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include namespace HyperSonicDrivers::drivers::midi { diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp index 44cd4d2e..88df632c 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp @@ -16,7 +16,8 @@ namespace HyperSonicDrivers::files::westwood public: enum class PROG_TYPE { - Track, Instrument + Track, + Instrument }; typedef struct meta_version_t From f373a4c23c7b2162b1ff8613ef24e1441c5d188a Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sat, 23 Aug 2025 05:02:06 +0100 Subject: [PATCH 03/15] adl-play example --- .../examples/CMakeLists.txt | 12 ++ .../examples/adl-play.cpp | 165 ++++++++++++++++++ 2 files changed, 177 insertions(+) create mode 100644 sdl2-hyper-sonic-drivers/examples/adl-play.cpp diff --git a/sdl2-hyper-sonic-drivers/examples/CMakeLists.txt b/sdl2-hyper-sonic-drivers/examples/CMakeLists.txt index 7019e32c..d1ca6022 100644 --- a/sdl2-hyper-sonic-drivers/examples/CMakeLists.txt +++ b/sdl2-hyper-sonic-drivers/examples/CMakeLists.txt @@ -87,6 +87,18 @@ macro_example( NONE ) +macro_example( + EXE ADLPlay + FILE "adl-play.cpp" + DEPS hyper-sonic-drivers-static + LINKS ${LIB_SDL2main} hyper-sonic-drivers-static spdlog::spdlog SDL2::SDL2 + FIXTURES + "../test/fixtures/DUNE0.ADL" + #"../test/fixtures/EOBSOUND.ADL" + #"../test/fixtures/LOREINTR.ADL" + NONE +) + macro_example( EXE PCMExample FILE "pcm-example.cpp" diff --git a/sdl2-hyper-sonic-drivers/examples/adl-play.cpp b/sdl2-hyper-sonic-drivers/examples/adl-play.cpp new file mode 100644 index 00000000..697b074b --- /dev/null +++ b/sdl2-hyper-sonic-drivers/examples/adl-play.cpp @@ -0,0 +1,165 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include + +using namespace HyperSonicDrivers; + +using hardware::opl::OPLFactory; +using hardware::opl::OplEmulator; +using hardware::opl::OplType; +using utils::delayMillis; +using files::westwood::ADLFile; +using drivers::westwood::ADLDriver; + + +void adl_play(const OplEmulator emu, const OplType type, std::shared_ptr mixer, const std::string& filename) +{ + using devices::make_device; + using utils::ILogger; + + auto adlFile = std::make_shared(filename); + std::shared_ptr device; + switch (type) + { + using enum OplType; + + case OPL2: + device = make_device(mixer, emu); + break; + case DUAL_OPL2: + device = make_device(mixer, emu); + break; + case OPL3: + device = make_device(mixer, emu); + break; + + } + + uint8_t track = 3; // starting from 2 + + ADLDriver adlDrv(device, audio::mixer::eChannelGroup::Music); + adlDrv.setADLFile(adlFile); + + if(!mixer->isReady()) { + spdlog::error("mixer not ready yet.."); + return; + } + + do + { + if (!adlDrv.isPlaying()) + { + adlDrv.play(++track); + ILogger::instance->info(std::format("Playing track: {}/{}", static_cast(track), adlFile->getNumTracks()), ILogger::eCategory::Application); + } + //delayMillis(1000); + SDL_Event e; + while (SDL_PollEvent(&e)) + { + if (e.type == SDL_KEYDOWN) + { + switch (e.key.keysym.sym) + { + case SDLK_ESCAPE: + { + adlDrv.stop(); + return; + } + case SDLK_RIGHT: + { + adlDrv.stop(); + track++; + if (track >= adlFile->getNumTracks()) + track = 0; + + break; + } + case SDLK_LEFT: + { + adlDrv.stop(); + if (track > 0) + track--; + else + track = adlFile->getNumTracks() - 1; + } + } + } + } + + } while (true); +} + +int main(int argc, char* argv[]) +{ + //if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_EVENTS | SDL_INIT_VIDEO) != 0) + //return -1; + + auto mixer = audio::make_mixer(8, 44100, 1024); + if (!mixer->init()) + { + spdlog::error("can't init mixer"); + return 1; + } + + + const std::map emus = { + { OplEmulator::DOS_BOX, "DOS_BOX" }, + //{ OplEmulator::MAME, "MAME" }, + //{ OplEmulator::NUKED, "NUKED" }, + //{ OplEmulator::WOODY, "WOODY" }, + }; + + const std::map types = { + {OplType::OPL2, "OPL2"}, + //{OplType::DUAL_OPL2, "DUAL_OPL2"}, + //{OplType::OPL3, "OPL3"}, + }; + + const std::string m = "##### {} {} #####"; + + spdlog::set_level(spdlog::level::info); + HyperSonicDrivers::utils::ILogger::instance->setLevelAll(HyperSonicDrivers::utils::ILogger::eLevel::Info); + for (const auto& emu : emus) + { + for (const auto& type : types) + { + using enum fmt::color; + + for (const auto& c : { white_smoke, yellow, aqua, + lime_green, blue_violet, indian_red }) { + spdlog::info(fmt::format(fg(c), m, emu.second, type.second)); + } + + try + { + adl_play(emu.first, type.first, mixer, "DUNE0.ADL"); + //adl_test(emu.first, type.first, mixer, "EOBSOUND.ADL", 1); + //adl_test(emu.first, type.first, mixer, "LOREINTR.ADL", 3); + } + catch (const std::exception& e) + { + spdlog::default_logger()->error(e.what()); + } + } + } + + //SDL_Quit(); + return 0; +} From 8b0d34f44f0e0c2e52a8b12025b426f56c34fa8f Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sat, 23 Aug 2025 05:47:59 +0100 Subject: [PATCH 04/15] fix adlFile num tracks --- .../examples/adl-play.cpp | 25 +++++++++++++------ .../files/westwood/ADLFile.cpp | 25 +++++++++++++++++-- .../files/westwood/ADLFile.hpp | 2 +- .../files/westwood/TestADLFile.cpp | 8 +++--- 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/sdl2-hyper-sonic-drivers/examples/adl-play.cpp b/sdl2-hyper-sonic-drivers/examples/adl-play.cpp index 697b074b..2106bae9 100644 --- a/sdl2-hyper-sonic-drivers/examples/adl-play.cpp +++ b/sdl2-hyper-sonic-drivers/examples/adl-play.cpp @@ -52,7 +52,7 @@ void adl_play(const OplEmulator emu, const OplType type, std::shared_ptrinfo(std::format("Playing track: {}/{}", static_cast(track), adlFile->getNumTracks()), ILogger::eCategory::Application); } //delayMillis(1000); @@ -79,12 +79,12 @@ void adl_play(const OplEmulator emu, const OplType type, std::shared_ptr= adlFile->getNumTracks()) track = 0; @@ -93,7 +93,7 @@ void adl_play(const OplEmulator emu, const OplType type, std::shared_ptr 0) track--; else @@ -108,8 +108,16 @@ void adl_play(const OplEmulator emu, const OplType type, std::shared_ptr(8, 44100, 1024); if (!mixer->init()) @@ -160,6 +168,7 @@ int main(int argc, char* argv[]) } } - //SDL_Quit(); + SDL_DestroyWindow(pWin); + SDL_Quit(); return 0; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp index b905ed42..15c7b9f9 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp @@ -111,8 +111,16 @@ namespace HyperSonicDrivers::files::westwood readDataFromFile_(m_meta_version.data_offset, m_meta_version.data_header_size); - // TODO: count_loop_ for version 3 is wrong to be 8 bit i think - m_num_tracks = count_loop_(0, m_header); + // TODO: m_header is wrong for v3s + /*for (int i = m_meta_version.num_headers - 1; i >= 0; --i) + { + if (m_header[i] < m_meta_version.num_track_offsets) + { + m_num_tracks = i; + break; + } + }*/ + m_num_tracks = m_meta_version.num_headers; m_num_track_offsets = count_loop_(m_meta_version.offset_start, m_track_offsets); m_num_instrument_offsets = count_loop_(m_meta_version.offset_start, m_instrument_offsets); @@ -132,6 +140,19 @@ namespace HyperSonicDrivers::files::westwood int ADLFile::getNumTracks() const noexcept { return m_num_tracks; + + // find last subsong + //int numSubSongs = 0; + /*for (int i = m_meta_version.num_headers - 1; i >= 0; --i) + { + if (m_header[i] < m_meta_version.num_track_offsets) + { + numSubSongs = i; + break; + } + }*/ + + //return numSubSongs; } int ADLFile::getNumTrackOffsets() const noexcept diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp index 88df632c..d1f13e53 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp @@ -62,7 +62,7 @@ namespace HyperSonicDrivers::files::westwood void readOffsetsFromFile_(const int num_offsets, std::vector& vec, const int offset_start) const noexcept; void readDataFromFile_(const int data_offsets, const int data_heder_size); - std::vector m_header; + std::vector m_header; // TODO: This is wrong for v3 as it is uint16_t instead! std::vector m_track_offsets; std::vector m_instrument_offsets; std::shared_ptr m_data; diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/files/westwood/TestADLFile.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/files/westwood/TestADLFile.cpp index 6acdb674..48cbb54b 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/files/westwood/TestADLFile.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/files/westwood/TestADLFile.cpp @@ -20,7 +20,7 @@ namespace HyperSonicDrivers::files::westwood { ADLFile f("../fixtures/EOBSOUND.ADL"); EXPECT_EQ(f.getVersion(), 1); - EXPECT_EQ(f.getNumTracks(), 15); + EXPECT_EQ(f.getNumTracks(), 120); EXPECT_EQ(f.getNumTrackOffsets(), 42); EXPECT_EQ(f.getNumInstrumentOffsets(), 40); EXPECT_EQ(f.getDataSize(), 13019 - 600); @@ -33,7 +33,7 @@ namespace HyperSonicDrivers::files::westwood { ADLFileMock f("../fixtures/DUNE19.ADL"); EXPECT_EQ(f.getVersion(), 2); - EXPECT_EQ(f.getNumTracks(), 49); + EXPECT_EQ(f.getNumTracks(), 120); EXPECT_EQ(f.getNumTrackOffsets(), 72); EXPECT_EQ(f.getNumInstrumentOffsets(), 71); EXPECT_EQ(f.parentSize(), 7257); @@ -56,7 +56,7 @@ namespace HyperSonicDrivers::files::westwood ADLFileMock f("../fixtures/DUNE0.ADL"); EXPECT_EQ(f.getVersion(), 2); - EXPECT_EQ(f.getNumTracks(), 200); + EXPECT_EQ(f.getNumTracks(), 120); EXPECT_EQ(f.getNumTrackOffsets(), 52); EXPECT_EQ(f.getNumInstrumentOffsets(), 63); EXPECT_EQ(f.parentSize(), 14473); @@ -78,7 +78,7 @@ namespace HyperSonicDrivers::files::westwood { ADLFile f("../fixtures/LOREINTR.ADL"); EXPECT_EQ(f.getVersion(), 3); - EXPECT_EQ(f.getNumTracks(), 30); + EXPECT_EQ(f.getNumTracks(), 250); EXPECT_EQ(f.getNumTrackOffsets(), 58); EXPECT_EQ(f.getNumInstrumentOffsets(), 71); EXPECT_EQ(f.getDataSize(), 13812 - 2000); From 50888071c16daeb3642b7ecd0fbf336bbcef44e0 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sat, 23 Aug 2025 05:50:50 +0100 Subject: [PATCH 05/15] Fix CI --- .github/workflows/ci-windows.yml | 2 +- .github/workflows/sonarcloud.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-windows.yml b/.github/workflows/ci-windows.yml index d3064cad..0846e849 100644 --- a/.github/workflows/ci-windows.yml +++ b/.github/workflows/ci-windows.yml @@ -67,7 +67,7 @@ jobs: - uses: actions/checkout@v4 - name: create build dir run: mkdir build - - uses: actions/cache@v2 + - uses: actions/cache@v4 id: dep-cache with: path: C:/vcpkg/packages diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 54918cff..98d90b22 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -53,13 +53,13 @@ jobs: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - name: create build dir run: mkdir build - - uses: actions/cache@v2 + - uses: actions/cache@v4 id: dep-cache with: path: C:/vcpkg/packages key: ${{ runner.os }}-x64-windows-dep-cache-${{ hashFiles('**/*') }} restore-keys: ${{ runner.os }}-x64-windows-dep-cache - - uses: actions/cache@v2 + - uses: actions/cache@v4 id: sonar-cache with: path: | From e6bb4a9d35e21ba998a17cb5ab534d1c8f1e4e91 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Sat, 23 Aug 2025 06:08:59 +0100 Subject: [PATCH 06/15] =?UTF-8?q?=F0=9F=93=9D=20Add=20docstrings=20to=20`r?= =?UTF-8?q?efactor`=20(#286)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docstrings generation was requested by @Raffaello. * https://github.com/Raffaello/sdl2-hyper-sonic-drivers/pull/285#issuecomment-1873050385 The following files were modified: * `sdl2-hyper-sonic-drivers/examples/adl-play.cpp` * `sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp` * `sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp` * `sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/files/westwood/TestADLFile.cpp` Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../examples/adl-play.cpp | 40 ++++++++++++++ .../sdl2-hyper-sonic-drivers.cpp | 55 ++++++++++++++++++- .../files/westwood/ADLFile.cpp | 54 ++++++++++++++++++ .../files/westwood/TestADLFile.cpp | 8 +++ 4 files changed, 156 insertions(+), 1 deletion(-) diff --git a/sdl2-hyper-sonic-drivers/examples/adl-play.cpp b/sdl2-hyper-sonic-drivers/examples/adl-play.cpp index 2106bae9..17671736 100644 --- a/sdl2-hyper-sonic-drivers/examples/adl-play.cpp +++ b/sdl2-hyper-sonic-drivers/examples/adl-play.cpp @@ -29,6 +29,32 @@ using files::westwood::ADLFile; using drivers::westwood::ADLDriver; +/** + * @brief Play an ADL file using a chosen OPL emulator/type until the user exits. + * + * Plays the given ADL file through an OPL device constructed from the specified + * emulator and OPL type. The function creates an ADLDriver bound to the + * Music channel group and enters an SDL event-driven loop that starts playback + * (initial track index is 5) and responds to key presses to control playback. + * + * Behavior: + * - Selects an OPL device based on `type`: + * - OPL2 -> Adlib + Opl + * - DUAL_OPL2-> SbPro + Opl + * - OPL3 -> SbPro2 + Opl + * - If the provided mixer is not ready, logs an error and returns immediately. + * - Starts playing the current track when not already playing. + * - Key controls (during playback): + * - ESC: stop all channels and return (exit function) + * - RIGHT: stop channels and advance to the next track (wraps to 0) + * - LEFT: stop channels and go to the previous track (wraps to last) + * + * This function blocks until ESC is pressed. + * + * @param emu OPL emulator selection used when constructing the device. + * @param type OPL hardware type used to choose the concrete device implementation. + * @param filename Path to the ADL file to load and play. + */ void adl_play(const OplEmulator emu, const OplType type, std::shared_ptr mixer, const std::string& filename) { using devices::make_device; @@ -106,6 +132,20 @@ void adl_play(const OplEmulator emu, const OplType type, std::shared_ptr @@ -336,6 +336,16 @@ void testMT32() } +/** + * @brief Load a WAV fixture, append it to itself, and play the result to completion. + * + * Initializes an SDL2 mixer, loads "test/fixtures/test_renderer_adlib_mame2.wav" into two sound + * objects, concatenates them into a single PCM sound, and plays that combined sound via a + * PCMDriver. The function blocks, polling until playback finishes. + * + * @note This function is a test utility: it uses a hard-coded test fixture path and performs + * synchronous waiting while playback is active. + */ void pcm_sound_append() { auto mixer = audio::make_mixer(8, 44100, 1024); @@ -356,6 +366,24 @@ void pcm_sound_append() } } +/** + * @brief Test harness that plays Westwood ADL music tracks through an Adlib/OPL driver using SDL2. + * + * This routine initializes an SDL2-backed audio mixer and an Adlib/OPL device, loads a Westwood + * ADL file (fixed to "adl/KYRA1A.ADL"), and uses drivers::westwood::ADLDriver to play each + * track (tracks are iterated from index 1 to getNumTracks()-1). Each track is played up to three + * times. The function creates a small SDL window and pumps SDL events while waiting for playback + * to finish; pressing Escape or receiving SDL_QUIT will abort the test, and pressing Return stops + * the current track. After completing playback or aborting, the SDL window is destroyed. + * + * Side effects: + * - Initializes SDL event and video subsystems and creates an SDL window. + * - Initializes audio mixer and constructs Adlib/OPL device and ADL driver. + * - Blocks while tracks are playing (polls events and sleeps). + * + * Notes: + * - File name and iteration counts are hard-coded for this test harness. + */ void adldune2filestest() { auto mixer = audio::make_mixer(8, 44100, 1024); @@ -414,6 +442,18 @@ void adldune2filestest() SDL_DestroyWindow(window); } +/** + * @brief Plays VOC files through an Adlib/OPL-backed PCM driver using SDL for event handling. + * + * Initializes an SDL-backed audio mixer and Adlib/OPL device, scans the local "voc/" directory, + * and plays each VOC file's PCM sound multiple times. While a sound is playing the function + * processes SDL events so the user can quit (window close or Escape) or stop the current playback + * early (Enter). A small SDL window is created for event delivery and destroyed on exit. + * + * This is a test/harness routine with side effects: it initializes SDL subsystems, creates an + * audio mixer and device, opens a window, iterates the filesystem, and drives playback via a + * PCMDriver. It does not return any value. + */ void vocdune2filestest() { auto mixer = audio::make_mixer(8, 44100, 1024); @@ -466,6 +506,19 @@ void vocdune2filestest() SDL_DestroyWindow(window); } +/** + * @brief Program entry point that runs selected test routines. + * + * The main function serves as the test harness entry. It dispatches to various + * SDL2/HyperSonicDrivers test routines; currently it invokes adldune2filestest() + * and then returns immediately. The function performs global initialization + * and teardown only for the test routines it calls (handled by those routines). + * + * Note: many test calls are present but commented out; uncommenting changes the + * executed test sequence. + * + * @return int Process exit code (0 on normal completion). + */ int main(int argc, char* argv[]) { //newMixerTest(); diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp index 15c7b9f9..a681fe66 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp @@ -91,6 +91,27 @@ namespace HyperSonicDrivers::files::westwood V3_DATA_HEADER_SIZE }; + /** + * @brief Construct an ADLFile by loading and parsing a Westwood ADL file from disk. + * + * Reads the file header, track offsets, instrument offsets and raw data payload + * according to the detected ADL version (V1/V2/V3), validates sizes, computes + * counts for tracks/offsets, then closes the file and converts absolute offsets + * into data-relative offsets (using 0xFFFF as the sentinel for invalid entries). + * + * The constructor: + * - validates the file meets the minimum size for an ADL file, + * - determines the on-disk ADL version and associated metadata, + * - reads version-appropriate header entries, + * - reads track and instrument offset tables, + * - reads the raw data payload and stores its size/header size, + * - sets m_num_tracks from the version metadata and computes the number of + * valid track/instrument offsets, + * - closes the underlying file handle, + * - adjusts offsets to be relative to the in-memory data payload (and maps 0 -> 0xFFFF). + * + * @param filename Path to the ADL file to open and parse. + */ ADLFile::ADLFile(const std::string& filename) : File(filename) { assertValid_(size() >= FILE_SIZE_MIN); @@ -137,6 +158,16 @@ namespace HyperSonicDrivers::files::westwood return m_version; } + /** + * @brief Return the number of tracks (subsongs) in the ADL file. + * + * The value is the internally stored track count determined at file load + * from the version-specific metadata. For some V3 files the in-memory + * header is known to be incorrect, so this returned count reflects the + * metadata-derived value rather than any inferred count from the header. + * + * @return int Number of tracks (subsongs). + */ int ADLFile::getNumTracks() const noexcept { return m_num_tracks; @@ -155,6 +186,16 @@ namespace HyperSonicDrivers::files::westwood //return numSubSongs; } + /** + * @brief Return the number of program (track) offsets present in the ADL file. + * + * This value is determined during construction from the file's version-specific + * metadata and offset tables. It represents how many valid track/program + * offset entries are available (sentinel/invalid entries are counted according + * to the parsed offset table). + * + * @return int Number of track/program offsets. + */ int ADLFile::getNumTrackOffsets() const noexcept { return m_num_track_offsets; @@ -281,6 +322,19 @@ namespace HyperSonicDrivers::files::westwood } } + /** + * @brief Read and populate the in-memory header table from the open file. + * + * Resizes ADLFile::m_header to header_size and fills it by invoking the supplied + * read callback header_size times. The read callback is expected to return the + * next header entry (as a 16-bit value) each time it is called. After reading, + * the method validates that the header vector length matches header_size. + * + * @param header_size Number of header entries to read and store into m_header. + * @param read A zero-argument callable that returns the next header entry as uint16_t. + * The caller is responsible for using the correct byte-width and endianness + * for the target ADL version. + */ void ADLFile::readHeaderFromFile_(const int header_size, std::function read) { m_header.resize(header_size); diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/files/westwood/TestADLFile.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/files/westwood/TestADLFile.cpp index 48cbb54b..b2aff2fd 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/files/westwood/TestADLFile.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/files/westwood/TestADLFile.cpp @@ -74,6 +74,14 @@ namespace HyperSonicDrivers::files::westwood EXPECT_EQ(chan, 9); } + /** + * @brief Tests ADLFile parsing for a version 3 ADL fixture (LOREINTR.ADL). + * + * Verifies that the file is recognized as version 3, reports the expected + * counts (tracks, track offsets, instrument offsets) and data size, and that + * program offsets for a track resolve to the corresponding track and + * instrument offsets. Also checks that the first track's data byte equals 9. + */ TEST(ADLFile, ADLv3) { ADLFile f("../fixtures/LOREINTR.ADL"); From 8d7a0ea9ae090fd3299705536b88e8aaa025ba98 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sat, 23 Aug 2025 06:51:14 +0100 Subject: [PATCH 07/15] code rev --- .../examples/adl-play.cpp | 22 +++++++++++---- .../sdl2-hyper-sonic-drivers.cpp | 8 ++++-- .../files/westwood/ADLFile.cpp | 28 ++----------------- 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/sdl2-hyper-sonic-drivers/examples/adl-play.cpp b/sdl2-hyper-sonic-drivers/examples/adl-play.cpp index 2106bae9..ab3cda84 100644 --- a/sdl2-hyper-sonic-drivers/examples/adl-play.cpp +++ b/sdl2-hyper-sonic-drivers/examples/adl-play.cpp @@ -12,6 +12,7 @@ #include #include + #include #include @@ -52,7 +53,7 @@ void adl_play(const OplEmulator emu, const OplType type, std::shared_ptrinfo(std::format("Playing track: {}/{}", static_cast(track), adlFile->getNumTracks()), ILogger::eCategory::Application); + ILogger::instance->info(fmt::format("Playing track: {}/{}", static_cast(track), adlFile->getNumTracks()), ILogger::eCategory::Application); } //delayMillis(1000); SDL_Event e; - while (SDL_PollEvent(&e)) + while (SDL_WaitEventTimeout(&e, 100)) { - if (e.type == SDL_KEYDOWN) + if (e.type == SDL_QUIT) + { + adlDrv.stopAllChannels(); + return; + } + else if (e.type == SDL_KEYDOWN) { switch (e.key.keysym.sym) { @@ -98,6 +104,8 @@ void adl_play(const OplEmulator emu, const OplType type, std::shared_ptrgetNumTracks() - 1; + + break; } } } @@ -108,10 +116,10 @@ void adl_play(const OplEmulator emu, const OplType type, std::shared_ptrinit()) { spdlog::error("can't init mixer"); + SDL_DestroyWindow(pWin); + SDL_Quit(); return 1; } diff --git a/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp b/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp index 616ecc26..9c326a8d 100644 --- a/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp +++ b/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp @@ -1,8 +1,10 @@ // sdl2-hyper-sonic-drivers.cpp : Defines the entry point for the application. -// TODO: delete this file and its target, this is kinda scratch pad +// TODO: delete this file and its target, this is kind of scratch pad #include #include +#include +#include #include @@ -131,7 +133,7 @@ int pcspkr(const int freq, const uint16_t audio, const int channels,const int ch // TODO try with channels. - Mix_Hook(pcSpeaker.callback, &pcSpeaker); + Mix_HookMusic(pcSpeaker.callback, &pcSpeaker); cout << "SQUARE" << endl; playNotes(&pcSpeaker, PCSpeaker::eWaveForm::SQUARE, 440, 300); @@ -412,6 +414,8 @@ void adldune2filestest() } QUIT: SDL_DestroyWindow(window); + SDL_QuitSubSystem(SDL_INIT_VIDEO); + SDL_QuitSubSystem(SDL_INIT_EVENTS); } void vocdune2filestest() diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp index 15c7b9f9..fabcb12e 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp @@ -111,15 +111,6 @@ namespace HyperSonicDrivers::files::westwood readDataFromFile_(m_meta_version.data_offset, m_meta_version.data_header_size); - // TODO: m_header is wrong for v3s - /*for (int i = m_meta_version.num_headers - 1; i >= 0; --i) - { - if (m_header[i] < m_meta_version.num_track_offsets) - { - m_num_tracks = i; - break; - } - }*/ m_num_tracks = m_meta_version.num_headers; m_num_track_offsets = count_loop_(m_meta_version.offset_start, m_track_offsets); m_num_instrument_offsets = count_loop_(m_meta_version.offset_start, m_instrument_offsets); @@ -140,19 +131,6 @@ namespace HyperSonicDrivers::files::westwood int ADLFile::getNumTracks() const noexcept { return m_num_tracks; - - // find last subsong - //int numSubSongs = 0; - /*for (int i = m_meta_version.num_headers - 1; i >= 0; --i) - { - if (m_header[i] < m_meta_version.num_track_offsets) - { - numSubSongs = i; - break; - } - }*/ - - //return numSubSongs; } int ADLFile::getNumTrackOffsets() const noexcept @@ -285,7 +263,7 @@ namespace HyperSonicDrivers::files::westwood { m_header.resize(header_size); // TODO: pass the byte size instead of a function read and read at once, - // and do read in LE when is greter than 1, basically if version 3 + // and do read in LE when is greater than 1, basically if version 3 for (int i = 0; i < header_size; i++) { m_header[i] = read(); @@ -304,14 +282,14 @@ namespace HyperSonicDrivers::files::westwood assertValid_(vec.size() == num_offsets); } - void ADLFile::readDataFromFile_(const int data_offsets, const int data_heder_size) + void ADLFile::readDataFromFile_(const int data_offsets, const int data_header_size) { m_dataSize = size() - data_offsets; assertValid_(m_dataSize > 0); assertValid_(tell() == data_offsets); m_data.reset(new uint8_t[m_dataSize]); read(m_data.get(), m_dataSize); - m_dataHeaderSize = data_heder_size; + m_dataHeaderSize = data_header_size; } void ADLFile::adjust_offsets_(std::vector& vec) From f81f89e3e9736d7d2634471108c2f18983c1e8d8 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sat, 23 Aug 2025 07:05:05 +0100 Subject: [PATCH 08/15] Fix Build --- .../sdl2-hyper-sonic-drivers.cpp | 177 +++++------------- 1 file changed, 51 insertions(+), 126 deletions(-) diff --git a/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp b/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp index f68d296c..39115f7a 100644 --- a/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp +++ b/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp @@ -446,132 +446,57 @@ void adldune2filestest() SDL_QuitSubSystem(SDL_INIT_EVENTS); } -/** - * @brief Plays VOC files through an Adlib/OPL-backed PCM driver using SDL for event handling. - * - * Initializes an SDL-backed audio mixer and Adlib/OPL device, scans the local "voc/" directory, - * and plays each VOC file's PCM sound multiple times. While a sound is playing the function - * processes SDL events so the user can quit (window close or Escape) or stop the current playback - * early (Enter). A small SDL window is created for event delivery and destroyed on exit. - * - * This is a test/harness routine with side effects: it initializes SDL subsystems, creates an - * audio mixer and device, opens a window, iterates the filesystem, and drives playback via a - * PCMDriver. It does not return any value. - */ -void vocdune2filestest() -{ - auto mixer = audio::make_mixer(8, 44100, 1024); - mixer->init(); - -void adldune2filestest() -{ - auto mixer = audio::make_mixer(8, 44100, 1024); - mixer->init(); - //utils::ILogger::instance->setLevelAll(utils::ILogger::eLevel::Debug); - auto device = devices::make_device(mixer); - drivers::westwood::ADLDriver drv(device, audio::mixer::eChannelGroup::Music); - - SDL_InitSubSystem(SDL_INIT_EVENTS); - SDL_InitSubSystem(SDL_INIT_VIDEO); - - auto window = SDL_CreateWindow("a", 0, 0, 320, 200, 0); - - for (int f = 0; f <= 0; f++) - { - //const std::string fn = "adl/DUNE" + std::to_string(f) + ".ADL"; - const std::string fn = "adl/KYRA1A.ADL"; - utils::ILogger::instance->info(std::format("opening file: {}", fn), utils::ILogger::eCategory::Application); - auto adlf = std::make_shared(fn); - drv.setADLFile(adlf); - for (int i = 1; i < adlf->getNumTracks(); i++) - { - utils::ILogger::instance->info(std::format("playing track: {}", i), utils::ILogger::eCategory::Application); - for (int j = 0; j < 3; j++) - { - utils::ILogger::instance->info(std::format("times: {}", j), utils::ILogger::eCategory::Application); - - drv.play(i); - while (drv.isPlaying()) - { - utils::delayMillis(200); - SDL_Event e; - while (SDL_PollEvent(&e)) - switch (e.type) - { - case SDL_QUIT: - goto QUIT; - case SDL_KEYDOWN: - //case SDL_KEYUP: - if (e.key.keysym.sym == SDLK_ESCAPE) - goto QUIT; - if (e.key.keysym.sym == SDLK_RETURN) - drv.stop(); - break; - - default: - std::cout << "event: " << e.type << std::endl; - } - } - } - drv.stopAllChannels(); - utils::delayMillis(1000); - } - } -QUIT: - SDL_DestroyWindow(window); -} - -void vocdune2filestest() -{ - auto mixer = audio::make_mixer(8, 44100, 1024); - mixer->init(); - - auto device = devices::make_device(mixer); - drivers::PCMDriver drv(mixer); - - SDL_InitSubSystem(SDL_INIT_EVENTS); - SDL_InitSubSystem(SDL_INIT_VIDEO); - - auto window = SDL_CreateWindow("a", 0, 0, 320, 200, 0); - - for (auto const& dir_entry : std::filesystem::directory_iterator{ "voc/" }) - { - const std::string fn = dir_entry.path().string(); - utils::ILogger::instance->info(std::format("opening file: {}", fn), utils::ILogger::eCategory::Application); - auto vocf = std::make_shared(fn); - - for (int j = 0; j < 10; j++) - { - utils::ILogger::instance->info(std::format("times: {}", j), utils::ILogger::eCategory::Application); - - drv.play(vocf->getSound()); - while (drv.isPlaying()) - { - //utils::delayMillis(200); - SDL_Event e; - while (SDL_PollEvent(&e)) - switch (e.type) - { - case SDL_QUIT: - goto QUIT; - case SDL_KEYDOWN: - //case SDL_KEYUP: - if (e.key.keysym.sym == SDLK_ESCAPE) - goto QUIT; - if (e.key.keysym.sym == SDLK_RETURN) - drv.stop(); - break; - - default: - std::cout << "event: " << e.type << std::endl; - } - } - } - utils::delayMillis(1000); - } -QUIT: - SDL_DestroyWindow(window); -} +//void vocdune2filestest() +//{ +// auto mixer = audio::make_mixer(8, 44100, 1024); +// mixer->init(); +// +// auto device = devices::make_device(mixer); +// drivers::PCMDriver drv(mixer); +// +// SDL_InitSubSystem(SDL_INIT_EVENTS); +// SDL_InitSubSystem(SDL_INIT_VIDEO); +// +// auto window = SDL_CreateWindow("a", 0, 0, 320, 200, 0); +// +// for (auto const& dir_entry : std::filesystem::directory_iterator{ "voc/" }) +// { +// const std::string fn = dir_entry.path().string(); +// utils::ILogger::instance->info(std::format("opening file: {}", fn), utils::ILogger::eCategory::Application); +// auto vocf = std::make_shared(fn); +// +// for (int j = 0; j < 10; j++) +// { +// utils::ILogger::instance->info(std::format("times: {}", j), utils::ILogger::eCategory::Application); +// +// drv.play(vocf->getSound()); +// while (drv.isPlaying()) +// { +// //utils::delayMillis(200); +// SDL_Event e; +// while (SDL_PollEvent(&e)) +// switch (e.type) +// { +// case SDL_QUIT: +// goto QUIT; +// case SDL_KEYDOWN: +// //case SDL_KEYUP: +// if (e.key.keysym.sym == SDLK_ESCAPE) +// goto QUIT; +// if (e.key.keysym.sym == SDLK_RETURN) +// drv.stop(); +// break; +// +// default: +// std::cout << "event: " << e.type << std::endl; +// } +// } +// } +// utils::delayMillis(1000); +// } +//QUIT: +// SDL_DestroyWindow(window); +//} /** * @brief Program entry point that runs selected test routines. From f4c764aaa59075795cca0d29eece07ec2790b53b Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sat, 23 Aug 2025 14:55:16 +0100 Subject: [PATCH 09/15] Fix SonarCloud --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index c2893529..22a4629a 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,5 +1,5 @@ sonar.organization=raffaello-github -sonar.projectKey=Raffaello_sdl2-sonic-drivers +sonar.projectKey=Raffaello_sdl2-hyper-sonic-drivers sonar.sources=sdl2-hyper-sonic-drivers/src,sdl2-hyper-sonic-drivers/examples sonar.tests=sdl2-hyper-sonic-drivers/test From 53ce2bcdf3261a91dcf613263d94531e8bc51ae9 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sat, 23 Aug 2025 15:25:51 +0100 Subject: [PATCH 10/15] Fix ADL v3 header type word instead of byte --- .../src/HyperSonicDrivers/files/westwood/ADLFile.cpp | 6 +----- .../src/HyperSonicDrivers/files/westwood/ADLFile.hpp | 10 +++++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp index e54b8ce1..71b6b6a0 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp @@ -159,7 +159,7 @@ namespace HyperSonicDrivers::files::westwood * * @return int Number of tracks (subsongs). */ - int ADLFile::getNumTracks() const noexcept + uint16_t ADLFile::getNumTracks() const noexcept { return m_num_tracks; } @@ -316,12 +316,8 @@ namespace HyperSonicDrivers::files::westwood void ADLFile::readHeaderFromFile_(const int header_size, std::function read) { m_header.resize(header_size); - // TODO: pass the byte size instead of a function read and read at once, - // and do read in LE when is greater than 1, basically if version 3 for (int i = 0; i < header_size; i++) - { m_header[i] = read(); - } assertValid_(m_header.size() == header_size); } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp index d1f13e53..3ec6d43b 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp @@ -37,9 +37,9 @@ namespace HyperSonicDrivers::files::westwood uint8_t getVersion() const noexcept; - int getNumTracks() const noexcept; - int getNumTrackOffsets() const noexcept; - int getNumInstrumentOffsets() const noexcept; + uint16_t getNumTracks() const noexcept; + int getNumTrackOffsets() const noexcept; + int getNumInstrumentOffsets() const noexcept; uint8_t getTrack(const int track) const; uint16_t getTrackOffset(const int programId) const; @@ -62,7 +62,7 @@ namespace HyperSonicDrivers::files::westwood void readOffsetsFromFile_(const int num_offsets, std::vector& vec, const int offset_start) const noexcept; void readDataFromFile_(const int data_offsets, const int data_heder_size); - std::vector m_header; // TODO: This is wrong for v3 as it is uint16_t instead! + std::vector m_header; std::vector m_track_offsets; std::vector m_instrument_offsets; std::shared_ptr m_data; @@ -72,7 +72,7 @@ namespace HyperSonicDrivers::files::westwood template int count_loop_(const int num_offs, const std::vector& vec); void adjust_offsets_(std::vector& vec); - int m_num_tracks = -1; + uint16_t m_num_tracks = 0; int m_num_track_offsets = -1; int m_num_instrument_offsets = -1; }; From 0f6f3eb993ec692c7f481fd6afce62f25591eb52 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sat, 23 Aug 2025 15:33:26 +0100 Subject: [PATCH 11/15] update Version patch --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 555645ad..5de1f0b8 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.18.0 DESCRIPTION "SDL2 based Hyper-Sonic Drivers for emulating old soundcards") +project ("sdl2-hyper-sonic-drivers" VERSION 0.18.1 DESCRIPTION "SDL2 based Hyper-Sonic Drivers for emulating old soundcards") include (TestBigEndian) TEST_BIG_ENDIAN(IS_BIG_ENDIAN) if(IS_BIG_ENDIAN) From 88a95c74db965cf39cf9514dcf8ad1aa23c1b1ee Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sat, 23 Aug 2025 15:54:03 +0100 Subject: [PATCH 12/15] codeRabbit rev --- .../src/HyperSonicDrivers/files/westwood/ADLFile.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp index 3ec6d43b..fa1ffe3f 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp @@ -60,7 +60,7 @@ namespace HyperSonicDrivers::files::westwood void readHeaderFromFile_(const int header_size, std::function read); void readOffsetsFromFile_(const int num_offsets, std::vector& vec, const int offset_start) const noexcept; - void readDataFromFile_(const int data_offsets, const int data_heder_size); + void readDataFromFile_(const int data_offsets, const int data_header_size); std::vector m_header; std::vector m_track_offsets; @@ -73,8 +73,8 @@ namespace HyperSonicDrivers::files::westwood int count_loop_(const int num_offs, const std::vector& vec); void adjust_offsets_(std::vector& vec); uint16_t m_num_tracks = 0; - int m_num_track_offsets = -1; - int m_num_instrument_offsets = -1; + uint16_t m_num_track_offsets = 0; + uint16_t m_num_instrument_offsets = 0; }; template @@ -82,7 +82,7 @@ namespace HyperSonicDrivers::files::westwood { int tot = 0; constexpr T max_ = std::numeric_limits::max(); - for (int i = 0; i < vec.size(); ++i) + for (size_t i = 0; i < vec.size(); ++i) { if (vec[i] >= offs_start && vec[i] < max_) { ++tot; From 614cba686784c1c6bfc97688541b5294a54bbff7 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sat, 23 Aug 2025 16:02:42 +0100 Subject: [PATCH 13/15] Fix Audio Driver Play track type to uint16_t --- .../src/HyperSonicDrivers/drivers/IAudioDriver.hpp | 2 +- .../src/HyperSonicDrivers/drivers/MIDDriver.cpp | 2 +- .../src/HyperSonicDrivers/drivers/MIDDriver.hpp | 2 +- .../HyperSonicDrivers/drivers/westwood/ADLDriver.cpp | 4 ++-- .../HyperSonicDrivers/drivers/westwood/ADLDriver.hpp | 4 ++-- .../src/HyperSonicDrivers/files/westwood/ADLFile.cpp | 12 ++++++------ .../src/HyperSonicDrivers/files/westwood/ADLFile.hpp | 12 ++++++------ .../HyperSonicDrivers/drivers/TestIAudioDriver.cpp | 2 +- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/IAudioDriver.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/IAudioDriver.hpp index 777c9980..a410dba3 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/IAudioDriver.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/IAudioDriver.hpp @@ -22,7 +22,7 @@ namespace HyperSonicDrivers::drivers explicit IAudioDriver(const std::shared_ptr& device); virtual ~IAudioDriver() = default; - virtual void play(const uint8_t track) noexcept = 0; + virtual void play(const uint16_t track) noexcept = 0; virtual void stop() noexcept = 0; // TODO: it might not be required diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp index e7074947..bb04aff5 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp @@ -163,7 +163,7 @@ namespace HyperSonicDrivers::drivers // m_isPlaying = true; //} - void MIDDriver::play(const uint8_t track) noexcept + void MIDDriver::play(const uint16_t track) noexcept { if (m_midi == nullptr) return; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.hpp index a0950016..8b1508a3 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.hpp @@ -37,7 +37,7 @@ namespace HyperSonicDrivers::drivers // this restore the default MidiDriver (scummvm::MidiAdlib, MT32) bool resetBankOP2() noexcept; - void play(const uint8_t track = 0) noexcept override; + void play(const uint16_t track = 0) noexcept override; void stop() noexcept override; void pause() noexcept; 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 6451c4c9..fb18343d 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.cpp @@ -82,7 +82,7 @@ namespace HyperSonicDrivers::drivers::westwood resetAdLibState_(); } - void ADLDriver::startSound_(const uint8_t track, const uint8_t volume) + void ADLDriver::startSound_(const uint16_t track, const uint8_t volume) { uint8_t* trackData = getProgram_(track); if (trackData == nullptr) { @@ -231,7 +231,7 @@ namespace HyperSonicDrivers::drivers::westwood } } - void ADLDriver::play(const uint8_t track) noexcept + void ADLDriver::play(const uint16_t track) noexcept { std::scoped_lock lock(m_mutex); 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 aba97f91..a07c0e64 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.hpp @@ -53,13 +53,13 @@ namespace HyperSonicDrivers::drivers::westwood void setOplMusicVolume(const uint8_t volume); void setOplSfxVolume(const uint8_t volume); - void play(const uint8_t track) noexcept override; + void play(const uint16_t track) noexcept override; void stop() noexcept override; bool isPlaying() const noexcept override; private: void initDriver_(); - void startSound_(const uint8_t track, const uint8_t volume); + void startSound_(const uint16_t track, const uint8_t volume); std::shared_ptr m_adl_file = nullptr; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp index 71b6b6a0..1f98e694 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp @@ -174,32 +174,32 @@ namespace HyperSonicDrivers::files::westwood * * @return int Number of track/program offsets. */ - int ADLFile::getNumTrackOffsets() const noexcept + uint16_t ADLFile::getNumTrackOffsets() const noexcept { return m_num_track_offsets; } - int ADLFile::getNumInstrumentOffsets() const noexcept + uint16_t ADLFile::getNumInstrumentOffsets() const noexcept { return m_num_instrument_offsets; } - uint8_t ADLFile::getTrack(const int track) const + uint16_t ADLFile::getTrack(const uint16_t track) const { return m_header.at(track); } - uint16_t ADLFile::getTrackOffset(const int programId) const + uint16_t ADLFile::getTrackOffset(const uint16_t programId) const { return m_track_offsets.at(programId); } - uint16_t ADLFile::getInstrumentOffset(const int instrument) const + uint16_t ADLFile::getInstrumentOffset(const uint16_t instrument) const { return m_instrument_offsets.at(instrument); } - uint16_t ADLFile::getProgramOffset(const int progId, const PROG_TYPE prog_type) const + uint16_t ADLFile::getProgramOffset(const uint16_t progId, const PROG_TYPE prog_type) const { switch (prog_type) { diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp index fa1ffe3f..946b668c 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp @@ -38,13 +38,13 @@ namespace HyperSonicDrivers::files::westwood uint8_t getVersion() const noexcept; uint16_t getNumTracks() const noexcept; - int getNumTrackOffsets() const noexcept; - int getNumInstrumentOffsets() const noexcept; + uint16_t getNumTrackOffsets() const noexcept; + uint16_t getNumInstrumentOffsets() const noexcept; - uint8_t getTrack(const int track) const; - uint16_t getTrackOffset(const int programId) const; - uint16_t getInstrumentOffset(const int instrument) const; - uint16_t getProgramOffset(const int progId, const PROG_TYPE prog_type) const; + uint16_t getTrack(const uint16_t track) const; + uint16_t getTrackOffset(const uint16_t programId) const; + uint16_t getInstrumentOffset(const uint16_t instrument) const; + uint16_t getProgramOffset(const uint16_t progId, const PROG_TYPE prog_type) const; uint32_t getDataSize() const noexcept; std::shared_ptr getData() const noexcept; diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestIAudioDriver.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestIAudioDriver.cpp index 56213cd2..12094124 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestIAudioDriver.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestIAudioDriver.cpp @@ -8,7 +8,7 @@ namespace HyperSonicDrivers::drivers { public: IAudioDriverMock(const std::shared_ptr& device) : IAudioDriver(device) {} - void play(const uint8_t track) noexcept override {}; + void play(const uint16_t track) noexcept override {}; void stop() noexcept override {}; bool isPlaying() const noexcept override { return false; }; }; From 305d18a1791186ece9932289ce5ef415b1ac812f Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sat, 23 Aug 2025 16:14:05 +0100 Subject: [PATCH 14/15] code rev --- .../src/HyperSonicDrivers/files/westwood/ADLFile.cpp | 2 +- .../src/HyperSonicDrivers/files/westwood/ADLFile.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp index 1f98e694..b704347d 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.cpp @@ -322,7 +322,7 @@ namespace HyperSonicDrivers::files::westwood assertValid_(m_header.size() == header_size); } - void ADLFile::readOffsetsFromFile_(const int num_offsets, std::vector& vec, const int offset_start) const noexcept + void ADLFile::readOffsetsFromFile_(const int num_offsets, std::vector& vec, const int offset_start) const { assertValid_(tell() == offset_start); vec.resize(num_offsets); diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp index 946b668c..50c20bf7 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/westwood/ADLFile.hpp @@ -59,7 +59,7 @@ namespace HyperSonicDrivers::files::westwood void detectVersion_(); void readHeaderFromFile_(const int header_size, std::function read); - void readOffsetsFromFile_(const int num_offsets, std::vector& vec, const int offset_start) const noexcept; + void readOffsetsFromFile_(const int num_offsets, std::vector& vec, const int offset_start) const; void readDataFromFile_(const int data_offsets, const int data_header_size); std::vector m_header; From 5fcf3f76313ef4c8462d245fc717bb21ae73641d Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sat, 23 Aug 2025 16:35:22 +0100 Subject: [PATCH 15/15] minor improve of cross-OS code compatibility --- .gitignore | 1 + .../HyperSonicDrivers/audio/converters/IRateConverter.hpp | 1 + .../src/HyperSonicDrivers/devices/IDevice.hpp | 1 + .../src/HyperSonicDrivers/drivers/westwood/ADLDriver.cpp | 5 +++-- .../src/HyperSonicDrivers/hardware/opl/mame/MameOPL3.cpp | 1 + 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index cd28babb..5380ca54 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ **/out /CMakeSettings.json /.vs +/.vscode /build *.bak sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/version.h diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/IRateConverter.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/IRateConverter.hpp index 6bf0a2ca..5889f713 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/IRateConverter.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/IRateConverter.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/IDevice.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/IDevice.hpp index b5154614..5cf07c71 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/IDevice.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/IDevice.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include 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 fb18343d..a35b2686 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -31,7 +32,7 @@ namespace HyperSonicDrivers::drivers::westwood IAudioDriver(opl), m_opl(opl->getOpl()) { - memset(m_channels.data(), 0, sizeof(m_channels)); + std::memset(m_channels.data(), 0, sizeof(m_channels)); hardware::TimerCallBack cb = std::bind(&ADLDriver::onCallback, this); auto p = std::make_shared(cb); @@ -557,7 +558,7 @@ namespace HyperSonicDrivers::drivers::westwood logD(std::format("initChannel({})", (long)(&channel - m_channels.data()))); const int8_t backupEL2 = channel.opExtraLevel2; - memset(&channel, 0, sizeof(Channel)); + std::memset(&channel, 0, sizeof(Channel)); channel.opExtraLevel2 = backupEL2; channel.tempo = 0xFF; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/mame/MameOPL3.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/mame/MameOPL3.cpp index 7dace502..49a71924 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/mame/MameOPL3.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/mame/MameOPL3.cpp @@ -1,4 +1,5 @@ #include +#include namespace HyperSonicDrivers::hardware::opl::mame {