Skip to content

Commit

Permalink
restore to v0.12 and then upgrade to correct fix on v0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
Raffaello committed Nov 1, 2023
1 parent 2fa3b7a commit 0861b5a
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 72 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
endif()


project ("sdl2-hyper-sonic-drivers" VERSION 0.12.4 DESCRIPTION "SDL2 based Hyper-Sonic Drivers for emulating old soundcards")
project ("sdl2-hyper-sonic-drivers" VERSION 0.13.0 DESCRIPTION "SDL2 based Hyper-Sonic Drivers for emulating old soundcards")
include (TestBigEndian)
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
if(IS_BIG_ENDIAN)
Expand Down
2 changes: 1 addition & 1 deletion sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <HyperSonicDrivers/audio/sdl2/Mixer.hpp>
#include <HyperSonicDrivers/utils/sdl2/Logger.hpp>
#include <HyperSonicDrivers/devices/Adlib.hpp>
#include <HyperSonicDrivers/audio/sdl2/Renderer.hpp>
#include <HyperSonicDrivers/audio/Renderer.hpp>
#include <mt32emu/c_interface/cpp_interface.h>
#include <HyperSonicDrivers/hardware/mt32/MT32.hpp>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <HyperSonicDrivers/audio/IMixer.hpp>
#include <HyperSonicDrivers/audio/IAudioStream.hpp>
#include <HyperSonicDrivers/hardware/opl/OPL.hpp>
#include <HyperSonicDrivers/devices/Opl.hpp>
#include <HyperSonicDrivers/devices/iDevice.hpp>

namespace HyperSonicDrivers::audio
{
Expand All @@ -15,14 +15,13 @@ namespace HyperSonicDrivers::audio
IRenderer() = default;
virtual ~IRenderer() = default;

virtual void setOutputFile(const std::filesystem::path& path) = 0;
virtual void releaseOutputFile() noexcept = 0;
virtual void openOutputFile(const std::filesystem::path& path) = 0;
virtual void closeOutputFile() noexcept = 0;

inline std::shared_ptr<IMixer> getMixer() const noexcept { return m_mixer; };

virtual void renderBuffer(IAudioStream* stream) = 0;
inline void renderBuffer(const std::shared_ptr<hardware::opl::OPL>& opl) { renderBuffer(opl->getAudioStream().get()); };
inline void renderBuffer(const std::shared_ptr<devices::Opl>& opl) { renderBuffer(opl->getHardware()->getAudioStream().get()); };
inline void renderBuffer(const std::shared_ptr<devices::IDevice>& device) { renderBuffer(device->getHardware()->getAudioStream().get()); };

protected:
std::shared_ptr<IMixer> m_mixer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ namespace HyperSonicDrivers::audio::sdl2
m_mixer = make_mixer<Mixer>(1, freq, buffer_size);
}

void Renderer::setOutputFile(const std::filesystem::path& path)
void Renderer::openOutputFile(const std::filesystem::path& path)
{
m_out = std::make_unique<files::WAVFile>(path.string(), audio::mixer::eChannelGroup::Unknown, false);
m_buf.resize(0);
}

void Renderer::releaseOutputFile() noexcept
void Renderer::closeOutputFile() noexcept
{
m_out.reset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace HyperSonicDrivers::audio::sdl2
Renderer(const uint32_t freq, const uint16_t buffer_size);
~Renderer() override = default;

void setOutputFile(const std::filesystem::path& path) override;
void releaseOutputFile() noexcept override;
void openOutputFile(const std::filesystem::path& path) override;
void closeOutputFile() noexcept override;

void renderBuffer(IAudioStream* stream) override;
using IRenderer::renderBuffer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,11 @@ namespace HyperSonicDrivers::drivers::westwood

bool ADLDriver::isPlaying() const noexcept
{
return isChannelPlaying(0) || m_programQueueStart != m_programQueueEnd;
bool res = false;
for (int i = 0; i <= NUM_CHANNELS; i++)
res |= isChannelPlaying(i);

return res || (m_programQueueStart != m_programQueueEnd);
}

uint8_t* ADLDriver::getProgram_(const int progId, const files::westwood::ADLFile::PROG_TYPE progType) const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace HyperSonicDrivers::audio
{
//class IRenderer;
class IRenderer;

namespace streams
{
Expand All @@ -27,6 +27,7 @@ namespace HyperSonicDrivers::hardware
class IHardware
{
friend audio::streams::EmulatedStream;
friend audio::IRenderer;

public:
explicit IHardware(const std::shared_ptr<audio::IMixer>& mixer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
#include <HyperSonicDrivers/hardware/opl/OplType.hpp>
#include <HyperSonicDrivers/audio/IMixer.hpp>

namespace HyperSonicDrivers::audio
{
class IRenderer;
}

namespace HyperSonicDrivers::hardware::opl
{
constexpr uint8_t opl2_num_channels = 9;
Expand All @@ -22,8 +17,6 @@ namespace HyperSonicDrivers::hardware::opl
*/
class OPL : public IHardware
{
friend audio::IRenderer;

public:
explicit OPL(const std::shared_ptr<audio::IMixer>& mixer, const OplType type);
~OPL() override = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ macro_test(
LINKS_PRIVATE hyper-sonic-drivers-static
FIXTURES
"../fixtures/test_renderer_adlib_mame2.wav"
"../fixtures/test_renderer_sbpro2_dosbox.wav"
"../fixtures/DUNE0.ADL"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,83 +1,73 @@
#include <gtest/gtest.h>
#include <HyperSonicDrivers/audio/sdl2/Renderer.hpp>
#include <HyperSonicDrivers/devices/Adlib.hpp>
#include <HyperSonicDrivers/devices/SbPro2.hpp>
#include <HyperSonicDrivers/drivers/westwood/ADLDriver.hpp>
#include <HyperSonicDrivers/audio/mixer/ChannelGroup.hpp>
#include <HyperSonicDrivers/hardware/opl/OplEmulator.hpp>
#include <HyperSonicDrivers/audio/stubs/StubMixer.hpp>
#include <filesystem>
#include <string>

namespace HyperSonicDrivers::audio::sdl2
{
using audio::mixer::eChannelGroup;
using devices::Adlib;
using hardware::opl::OplEmulator;
using devices::eDeviceName;

TEST(Renderer, adlib_mame2)
class RendererTest : public ::testing::TestWithParam<std::tuple<std::string, const int, const devices::eDeviceName, const OplEmulator>>
{
constexpr const char* exp_renderer = "../fixtures/test_renderer_adlib_mame2.wav";
constexpr const char* rfile = "test_renderer_adlib_mame2_out.wav";
public:
const std::string test_name = std::get<0>(GetParam());
const int freq = std::get<1>(GetParam());
const eDeviceName device_name = std::get<2>(GetParam());
const OplEmulator opl_emu = std::get<3>(GetParam());

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();
std::shared_ptr<devices::Opl> opl;
std::shared_ptr<IMixer> mixer;

auto adlib = devices::make_device<devices::Adlib, devices::Opl>(mixer, OplEmulator::MAME);
auto drv1 = drivers::westwood::ADLDriver(adlib, eChannelGroup::Music);
auto af = std::make_shared<files::westwood::ADLFile>("../fixtures/DUNE0.ADL");
drv1.setADLFile(af);

auto eo = adlib->getOpl();
drv1.play(4);
while (drv1.isPlaying())
r.renderBuffer(eo);

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++)
RendererTest()
{
EXPECT_EQ(sound->data[i], exp_sound->data[i]);
mixer = std::make_shared<stubs::StubMixer>();
switch (device_name)
{
using enum devices::eDeviceName;
case Adlib:
opl = devices::make_device<devices::Adlib, devices::Opl>(mixer, opl_emu);
break;
case SbPro2:
opl = devices::make_device<devices::SbPro2, devices::Opl>(mixer, opl_emu);
break;
default:
throw std::invalid_argument("");
}
}
}
};

TEST(Renderer, adlib_mame2_device)
TEST_P(RendererTest, render_wav)
{
constexpr const char* exp_renderer = "../fixtures/test_renderer_adlib_mame2.wav";
constexpr const char* rfile = "test_renderer_adlib_mame2_out.wav";
const std::string exp_renderer = "../fixtures/test_renderer_" + test_name + ".wav";
const std::string rfile = "../fixtures/test_renderer_" + test_name + "_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();
{
audio::sdl2::Renderer r(freq, 1024);
r.openOutputFile(rfile);

auto adlib = devices::make_device<devices::Adlib, devices::Opl>(mixer, OplEmulator::MAME);
auto drv1 = drivers::westwood::ADLDriver(adlib, eChannelGroup::Music);
auto af = std::make_shared<files::westwood::ADLFile>("../fixtures/DUNE0.ADL");
drv1.setADLFile(af);
auto drv1 = drivers::westwood::ADLDriver(opl, eChannelGroup::Music);
auto af = std::make_shared<files::westwood::ADLFile>("../fixtures/DUNE0.ADL");
drv1.setADLFile(af);

drv1.play(4);
while (drv1.isPlaying())
r.renderBuffer(adlib);
drv1.play(4);
while (drv1.isPlaying())
r.renderBuffer(opl);

r.releaseOutputFile();
r.closeOutputFile();
}

files::WAVFile w(rfile);
auto sound = w.getSound();
Expand All @@ -87,11 +77,21 @@ namespace HyperSonicDrivers::audio::sdl2
ASSERT_EQ(sound->dataSize, exp_sound->dataSize);
ASSERT_EQ(sound->freq, exp_sound->freq);
ASSERT_EQ(sound->stereo, exp_sound->stereo);
EXPECT_EQ(sound->freq, freq);
EXPECT_EQ(sound->stereo, opl->getHardware()->isStereo());
for (uint32_t i = 0; i < sound->dataSize; i++)
{
EXPECT_EQ(sound->data[i], exp_sound->data[i]);
}
}
INSTANTIATE_TEST_SUITE_P(
Renderer,
RendererTest,
::testing::Values(
std::make_tuple<>("adlib_mame2", 44100, eDeviceName::Adlib, OplEmulator::MAME),
std::make_tuple<>("sbpro2_dosbox", 44100, eDeviceName::SbPro2, OplEmulator::DOS_BOX)
)
);
}

int main(int argc, char** argv)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ namespace HyperSonicDrivers::audio::stubs
public:
int rate = 44100;

StubMixer() : IMixer(32, 44100, 1024/*, const uint8_t bitsDepth*/) {};
StubMixer() : IMixer(32, 44100, 1024) {};
explicit StubMixer(const int freq) : IMixer(32, freq, 1024) {};

bool init() override { return true; };

Expand Down
Binary file not shown.

0 comments on commit 0861b5a

Please sign in to comment.