Skip to content

review ADLFile #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 23, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
12 changes: 12 additions & 0 deletions sdl2-hyper-sonic-drivers/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
174 changes: 174 additions & 0 deletions sdl2-hyper-sonic-drivers/examples/adl-play.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#include <HyperSonicDrivers/audio/sdl2/Mixer.hpp>

Check warning on line 1 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdl2-hyper-sonic-drivers/examples/adl-play.cpp#L1

Include file: <HyperSonicDrivers/audio/sdl2/Mixer.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <HyperSonicDrivers/hardware/opl/OPL.hpp>

Check warning on line 2 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdl2-hyper-sonic-drivers/examples/adl-play.cpp#L2

Include file: <HyperSonicDrivers/hardware/opl/OPL.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <HyperSonicDrivers/hardware/opl/OPLFactory.hpp>

Check warning on line 3 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdl2-hyper-sonic-drivers/examples/adl-play.cpp#L3

Include file: <HyperSonicDrivers/hardware/opl/OPLFactory.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <HyperSonicDrivers/utils/algorithms.hpp>

Check warning on line 4 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdl2-hyper-sonic-drivers/examples/adl-play.cpp#L4

Include file: <HyperSonicDrivers/utils/algorithms.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <HyperSonicDrivers/files/westwood/ADLFile.hpp>

Check warning on line 5 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdl2-hyper-sonic-drivers/examples/adl-play.cpp#L5

Include file: <HyperSonicDrivers/files/westwood/ADLFile.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <HyperSonicDrivers/drivers/westwood/ADLDriver.hpp>

Check warning on line 6 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdl2-hyper-sonic-drivers/examples/adl-play.cpp#L6

Include file: <HyperSonicDrivers/drivers/westwood/ADLDriver.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <HyperSonicDrivers/utils/ILogger.hpp>

Check warning on line 7 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdl2-hyper-sonic-drivers/examples/adl-play.cpp#L7

Include file: <HyperSonicDrivers/utils/ILogger.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <HyperSonicDrivers/devices/Adlib.hpp>

Check warning on line 8 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdl2-hyper-sonic-drivers/examples/adl-play.cpp#L8

Include file: <HyperSonicDrivers/devices/Adlib.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <HyperSonicDrivers/devices/SbPro.hpp>

Check warning on line 9 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdl2-hyper-sonic-drivers/examples/adl-play.cpp#L9

Include file: <HyperSonicDrivers/devices/SbPro.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <HyperSonicDrivers/devices/SbPro2.hpp>

Check warning on line 10 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdl2-hyper-sonic-drivers/examples/adl-play.cpp#L10

Include file: <HyperSonicDrivers/devices/SbPro2.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <spdlog/spdlog.h>

Check warning on line 12 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdl2-hyper-sonic-drivers/examples/adl-play.cpp#L12

Include file: <spdlog/spdlog.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <fmt/color.h>

Check warning on line 13 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdl2-hyper-sonic-drivers/examples/adl-play.cpp#L13

Include file: <fmt/color.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <SDL2/SDL.h>

Check warning on line 15 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdl2-hyper-sonic-drivers/examples/adl-play.cpp#L15

Include file: <SDL2/SDL.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <memory>

Check warning on line 17 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdl2-hyper-sonic-drivers/examples/adl-play.cpp#L17

Include file: <memory> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <cstdint>

Check warning on line 18 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdl2-hyper-sonic-drivers/examples/adl-play.cpp#L18

Include file: <cstdint> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <map>

Check warning on line 19 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdl2-hyper-sonic-drivers/examples/adl-play.cpp#L19

Include file: <map> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <string>

Check warning on line 20 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdl2-hyper-sonic-drivers/examples/adl-play.cpp#L20

Include file: <string> not found. Please note: Cppcheck does not need standard library headers to get proper results.

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<audio::IMixer> mixer, const std::string& filename)
{
using devices::make_device;
using utils::ILogger;

auto adlFile = std::make_shared<ADLFile>(filename);
std::shared_ptr<devices::Opl> device;
switch (type)
{
using enum OplType;

case OPL2:
device = make_device<devices::Adlib, devices::Opl>(mixer, emu);
break;
case DUAL_OPL2:
device = make_device<devices::SbPro, devices::Opl>(mixer, emu);
break;
case OPL3:
device = make_device<devices::SbPro2, devices::Opl>(mixer, emu);
break;

}

uint8_t track = 5; // 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<int>(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.stopAllChannels();
return;
}
case SDLK_RIGHT:
{
adlDrv.stopAllChannels();
track++;
if (track >= adlFile->getNumTracks())
track = 0;

break;
}
case SDLK_LEFT:
{
adlDrv.stopAllChannels();
if (track > 0)
track--;
else
track = adlFile->getNumTracks() - 1;
}
}
}
}

} while (true);
}

int main(int argc, char* argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) != 0)
return -1;

auto pWin = SDL_CreateWindow("", 0, 0, 100, 100, 0);
if (!pWin)
{
SDL_Quit();
return -2;
}


auto mixer = audio::make_mixer<audio::sdl2::Mixer>(8, 44100, 1024);
if (!mixer->init())
{
spdlog::error("can't init mixer");
return 1;
}


const std::map<OplEmulator, std::string> emus = {
{ OplEmulator::DOS_BOX, "DOS_BOX" },
//{ OplEmulator::MAME, "MAME" },
//{ OplEmulator::NUKED, "NUKED" },
//{ OplEmulator::WOODY, "WOODY" },
};

const std::map<OplType, std::string> 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_DestroyWindow(pWin);
SDL_Quit();
return 0;
}
Loading
Loading