Skip to content
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

renderer rename open/close file methods | ADLDriver::isPlaying minor improvements #266

Merged
merged 4 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 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.14.0 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/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ target_include_directories(${LIB_NAME} PUBLIC
target_sources(${LIB_NAME} PRIVATE
# --- #
${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/audio/IMixer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/audio/Renderer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/audio/mixer/Channel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/audio/sdl2/Mixer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp
# --- #
${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/audio/MIDI.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/audio/midi/MIDITrack.cpp
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/Renderer.hpp>
#include <HyperSonicDrivers/audio/sdl2/Renderer.hpp>
#include <mt32emu/c_interface/cpp_interface.h>
#include <HyperSonicDrivers/hardware/mt32/MT32.hpp>

Expand Down
29 changes: 29 additions & 0 deletions sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <filesystem>
#include <memory>
#include <HyperSonicDrivers/audio/IMixer.hpp>
#include <HyperSonicDrivers/audio/IAudioStream.hpp>
#include <HyperSonicDrivers/hardware/opl/OPL.hpp>
#include <HyperSonicDrivers/devices/IDevice.hpp>

namespace HyperSonicDrivers::audio
{
class IRenderer
{
public:
IRenderer() = default;
virtual ~IRenderer() = default;

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<devices::IDevice>& device) { renderBuffer(device->getHardware()->getAudioStream().get()); };

protected:
std::shared_ptr<IMixer> m_mixer;
};
}
33 changes: 0 additions & 33 deletions sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/Renderer.hpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include <HyperSonicDrivers/audio/Renderer.hpp>
#include <HyperSonicDrivers/audio/mixer/ChannelGroup.hpp>
#include <HyperSonicDrivers/audio/sdl2/Renderer.hpp>
#include <HyperSonicDrivers/audio/sdl2/Mixer.hpp>
#include <HyperSonicDrivers/utils/ILogger.hpp>

namespace HyperSonicDrivers::audio

namespace HyperSonicDrivers::audio::sdl2
{
Renderer::Renderer(const size_t buffer_size) : m_buf_size(buffer_size)
Renderer::Renderer(const uint32_t freq, const uint16_t buffer_size)
{
m_mixer = make_mixer<Mixer>(1, freq, buffer_size);
}

void Renderer::openOutputFile(const std::filesystem::path& path)
Expand All @@ -15,7 +18,6 @@ namespace HyperSonicDrivers::audio

void Renderer::closeOutputFile() noexcept
{
m_out->save_end();
m_out.reset();
}

Expand All @@ -24,7 +26,7 @@ namespace HyperSonicDrivers::audio
if (m_buf.empty())
{
m_out->save_prepare(stream->getRate(), stream->isStereo());
m_buf.resize(m_buf_size);
m_buf.resize(m_mixer->getBufferSize());
}

const size_t read = stream->readBuffer(m_buf.data(), m_buf.size());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <HyperSonicDrivers/audio/IRenderer.hpp>
#include <HyperSonicDrivers/audio/IMixer.hpp>
#include <HyperSonicDrivers/audio/IAudioStream.hpp>
#include <HyperSonicDrivers/files/WAVFile.hpp>
#include <vector>
#include <memory>
#include <filesystem>

namespace HyperSonicDrivers::audio::sdl2
{
class Renderer : public IRenderer
{
public:
Renderer(const uint32_t freq, const uint16_t buffer_size);
~Renderer() override = default;

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

void renderBuffer(IAudioStream* stream) override;
using IRenderer::renderBuffer;
private:
std::unique_ptr<files::WAVFile> m_out;
std::vector<int16_t> m_buf;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

namespace streams
{
Expand All @@ -27,7 +27,7 @@ namespace HyperSonicDrivers::hardware
class IHardware
{
friend audio::streams::EmulatedStream;
friend audio::Renderer;
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 @@ -262,7 +262,7 @@ macro_test(

macro_test(
EXE TestRenderer
FILES "audio/TestRenderer.cpp"
FILES "audio/sdl2/TestRenderer.cpp"
LINKS_PRIVATE hyper-sonic-drivers-static
FIXTURES
"../fixtures/test_renderer_adlib_mame2.wav"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include <HyperSonicDrivers/audio/Renderer.hpp>
#include <HyperSonicDrivers/audio/sdl2/Renderer.hpp>
#include <HyperSonicDrivers/devices/Adlib.hpp>
#include <HyperSonicDrivers/devices/SbPro2.hpp>
#include <HyperSonicDrivers/drivers/westwood/ADLDriver.hpp>
Expand All @@ -9,7 +9,7 @@
#include <filesystem>
#include <string>

namespace HyperSonicDrivers::audio
namespace HyperSonicDrivers::audio::sdl2
{
using audio::mixer::eChannelGroup;
using hardware::opl::OplEmulator;
Expand Down Expand Up @@ -55,7 +55,7 @@ namespace HyperSonicDrivers::audio
ASSERT_FALSE(std::filesystem::exists(rfile));

{
audio::Renderer r(freq);
audio::sdl2::Renderer r(freq, 1024);
r.openOutputFile(rfile);

auto drv1 = drivers::westwood::ADLDriver(opl, eChannelGroup::Music);
Expand Down Expand Up @@ -92,50 +92,6 @@ namespace HyperSonicDrivers::audio
std::make_tuple<>("sbpro2_dosbox", 44100, eDeviceName::SbPro2, OplEmulator::DOS_BOX)
)
);


// This disabled test are generating a shorter wav file. WHY?
TEST(DISABLED_Renderer, adlib_mame2)
{
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::Renderer r(1024);
r.openOutputFile(rfile);

auto mixer = std::make_shared<stubs::StubMixer>();

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);

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

r.closeOutputFile();

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);
EXPECT_EQ(sound->freq, 44100);
EXPECT_FALSE(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)
Expand Down
Binary file not shown.
Binary file not shown.
Loading