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 3 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
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
165 changes: 165 additions & 0 deletions sdl2-hyper-sonic-drivers/examples/adl-play.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#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 = 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<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.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<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_Quit();
return 0;
}
166 changes: 113 additions & 53 deletions sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <HyperSonicDrivers/utils/sound.hpp>
#include <HyperSonicDrivers/drivers/PCMDriver.hpp>
#include <HyperSonicDrivers/audio/PCMSound.hpp>
#include <HyperSonicDrivers/files/VOCFile.hpp>

Check warning on line 39 in sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp#L39

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


using namespace std;
Expand Down Expand Up @@ -130,7 +131,7 @@


// TODO try with channels.
Mix_HookMusic(pcSpeaker.callback, &pcSpeaker);
Mix_Hook(pcSpeaker.callback, &pcSpeaker);

cout << "SQUARE" << endl;
playNotes(&pcSpeaker, PCSpeaker::eWaveForm::SQUARE, 440, 300);
Expand Down Expand Up @@ -355,57 +356,115 @@
}
}

//void adldune2filestest()
//{
// auto mixer = audio::make_mixer<audio::sdl2::Mixer>(8, 44100, 1024);
// mixer->init();
//
// auto device = devices::make_device<devices::Adlib, devices::Opl>(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<files::westwood::ADLFile>(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<audio::sdl2::Mixer>(8, 44100, 1024);
mixer->init();
//utils::ILogger::instance->setLevelAll(utils::ILogger::eLevel::Debug);
auto device = devices::make_device<devices::Adlib, devices::Opl>(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<files::westwood::ADLFile>(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<audio::sdl2::Mixer>(8, 44100, 1024);
mixer->init();

auto device = devices::make_device<devices::Adlib, devices::Opl>(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<files::VOCFile>(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[])
{
Expand All @@ -417,7 +476,8 @@
//testMT32();

//pcm_sound_append();
//adldune2filestest();
adldune2filestest();
//vocdune2filestest();
//return 0;
//sdlMixer();
//SDL_Delay(100);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <HyperSonicDrivers/drivers/midi/IMidiChannelVoice.hpp>
#include <HyperSonicDrivers/drivers/midi/IMidiChannel.hpp>
#include <cmath>
#include <algorithm>

Check warning on line 3 in sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/IMidiChannelVoice.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/IMidiChannelVoice.cpp#L3

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

namespace HyperSonicDrivers::drivers::midi
{
Expand Down
Loading
Loading