-
Notifications
You must be signed in to change notification settings - Fork 1
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
review ADLFile #285
Changes from 5 commits
e73a9b3
f704728
f373a4c
8b0d34f
5088807
e6bb4a9
8d7a0ea
2415d64
a049e63
f81f89e
f4c764a
53ce2bc
0f6f3eb
88a95c7
614cba6
305d18a
5fcf3f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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
|
||
#include <HyperSonicDrivers/hardware/opl/OPL.hpp> | ||
Check warning on line 2 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp
|
||
#include <HyperSonicDrivers/hardware/opl/OPLFactory.hpp> | ||
Check warning on line 3 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp
|
||
#include <HyperSonicDrivers/utils/algorithms.hpp> | ||
Check warning on line 4 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp
|
||
#include <HyperSonicDrivers/files/westwood/ADLFile.hpp> | ||
Check warning on line 5 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp
|
||
#include <HyperSonicDrivers/drivers/westwood/ADLDriver.hpp> | ||
Check warning on line 6 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp
|
||
#include <HyperSonicDrivers/utils/ILogger.hpp> | ||
Check warning on line 7 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp
|
||
#include <HyperSonicDrivers/devices/Adlib.hpp> | ||
Check warning on line 8 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp
|
||
#include <HyperSonicDrivers/devices/SbPro.hpp> | ||
Check warning on line 9 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp
|
||
#include <HyperSonicDrivers/devices/SbPro2.hpp> | ||
Check warning on line 10 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp
|
||
|
||
#include <spdlog/spdlog.h> | ||
Check warning on line 12 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp
|
||
#include <fmt/color.h> | ||
Check warning on line 13 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp
|
||
|
||
#include <SDL2/SDL.h> | ||
Check warning on line 15 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp
|
||
|
||
#include <memory> | ||
Check warning on line 17 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp
|
||
#include <cstdint> | ||
Check warning on line 18 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp
|
||
#include <map> | ||
Check warning on line 19 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp
|
||
#include <string> | ||
Check warning on line 20 in sdl2-hyper-sonic-drivers/examples/adl-play.cpp
|
||
|
||
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; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.