From 5941636419ed17f517c122aa1edf273af7a0be4a Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Tue, 31 Oct 2023 00:15:30 +0000 Subject: [PATCH] Renderer OPL through device test --- .../audio/sdl2/TestRenderer.cpp | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp index 8def41fe..40a2d3af 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp @@ -12,7 +12,7 @@ namespace HyperSonicDrivers::audio::sdl2 using devices::Adlib; using hardware::opl::OplEmulator; - TEST(Renderer, test_adlib_mame2) + TEST(Renderer, adlib_mame2) { constexpr const char* exp_renderer = "../fixtures/test_renderer_adlib_mame2.wav"; constexpr const char* rfile = "test_renderer_adlib_mame2_out.wav"; @@ -52,6 +52,46 @@ namespace HyperSonicDrivers::audio::sdl2 EXPECT_EQ(sound->data[i], exp_sound->data[i]); } } + + TEST(Renderer, adlib_mame2_device) + { + constexpr const char* exp_renderer = "../fixtures/test_renderer_adlib_mame2.wav"; + constexpr const char* rfile = "test_renderer_adlib_mame2_out.wav"; + + if (std::filesystem::exists(rfile)) + std::filesystem::remove(rfile); + + ASSERT_FALSE(std::filesystem::exists(rfile)); + + audio::sdl2::Renderer r(44100, 1024); + r.setOutputFile(rfile); + + auto mixer = r.getMixer(); + + auto adlib = devices::make_device(mixer, OplEmulator::MAME); + auto drv1 = drivers::westwood::ADLDriver(adlib, eChannelGroup::Music); + auto af = std::make_shared("../fixtures/DUNE0.ADL"); + drv1.setADLFile(af); + + drv1.play(4); + while (drv1.isPlaying()) + r.renderBuffer(adlib); + + r.releaseOutputFile(); + + files::WAVFile w(rfile); + auto sound = w.getSound(); + files::WAVFile wexp(exp_renderer); + auto exp_sound = wexp.getSound(); + + ASSERT_EQ(sound->dataSize, exp_sound->dataSize); + ASSERT_EQ(sound->freq, exp_sound->freq); + ASSERT_EQ(sound->stereo, exp_sound->stereo); + for (uint32_t i = 0; i < sound->dataSize; i++) + { + EXPECT_EQ(sound->data[i], exp_sound->data[i]); + } + } } int main(int argc, char** argv)