Skip to content

Commit 95594c7

Browse files
authored
renderer max_channels | package test mocks (#267)
* refactor * code rev
1 parent e3174a9 commit 95594c7

File tree

25 files changed

+113
-126
lines changed

25 files changed

+113
-126
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
55
endif()
66

77

8-
project ("sdl2-hyper-sonic-drivers" VERSION 0.13.0 DESCRIPTION "SDL2 based Hyper-Sonic Drivers for emulating old soundcards")
8+
project ("sdl2-hyper-sonic-drivers" VERSION 0.13.1 DESCRIPTION "SDL2 based Hyper-Sonic Drivers for emulating old soundcards")
99
include (TestBigEndian)
1010
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
1111
if(IS_BIG_ENDIAN)

sdl2-hyper-sonic-drivers/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ install(DIRECTORY
4444
PATTERN "*.h"
4545
)
4646

47+
install(DIRECTORY
48+
test/
49+
DESTINATION static/test/include
50+
FILES_MATCHING
51+
PATTERN "*Mock.hpp"
52+
)
53+
4754
write_basic_package_version_file(
4855
${CMAKE_CURRENT_BINARY_DIR}/${LIB_VER}.cmake
4956
VERSION ${CMAKE_PROJECT_VERSION}

sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#pragma once
22

3+
#include <cstdint>
34
#include <filesystem>
45
#include <memory>
6+
#include <vector>
57
#include <HyperSonicDrivers/audio/IMixer.hpp>
68
#include <HyperSonicDrivers/audio/IAudioStream.hpp>
79
#include <HyperSonicDrivers/hardware/opl/OPL.hpp>
810
#include <HyperSonicDrivers/devices/IDevice.hpp>
11+
#include <HyperSonicDrivers/files/WAVFile.hpp>
912

1013
namespace HyperSonicDrivers::audio
1114
{
@@ -25,5 +28,7 @@ namespace HyperSonicDrivers::audio
2528

2629
protected:
2730
std::shared_ptr<IMixer> m_mixer;
31+
std::unique_ptr<files::WAVFile> m_out;
32+
std::vector<int16_t> m_buf;
2833
};
2934
}

sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ namespace HyperSonicDrivers::audio::sdl2
2525

2626
Mixer::~Mixer()
2727
{
28-
SDL_CloseAudioDevice(m_device_id);
29-
30-
SDL_QuitSubSystem(SDL_INIT_AUDIO);
28+
if (m_ready)
29+
{
30+
SDL_CloseAudioDevice(m_device_id);
31+
SDL_QuitSubSystem(SDL_INIT_AUDIO);
32+
m_ready = false;
33+
}
3134
}
3235

3336
bool Mixer::init()

sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
namespace HyperSonicDrivers::audio::sdl2
77
{
8-
Renderer::Renderer(const uint32_t freq, const uint16_t buffer_size)
8+
Renderer::Renderer(const uint32_t freq, const uint16_t buffer_size, const uint8_t max_channels)
99
{
10-
m_mixer = make_mixer<Mixer>(1, freq, buffer_size);
10+
m_mixer = make_mixer<Mixer>(max_channels, freq, buffer_size);
1111
}
1212

1313
void Renderer::openOutputFile(const std::filesystem::path& path)
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
#pragma once
22

3+
#include <cstdint>
4+
#include <filesystem>
35
#include <HyperSonicDrivers/audio/IRenderer.hpp>
4-
#include <HyperSonicDrivers/audio/IMixer.hpp>
56
#include <HyperSonicDrivers/audio/IAudioStream.hpp>
6-
#include <HyperSonicDrivers/files/WAVFile.hpp>
7-
#include <vector>
8-
#include <memory>
9-
#include <filesystem>
107

118
namespace HyperSonicDrivers::audio::sdl2
129
{
1310
class Renderer : public IRenderer
1411
{
1512
public:
16-
Renderer(const uint32_t freq, const uint16_t buffer_size);
13+
Renderer(const uint32_t freq, const uint16_t buffer_size, const uint8_t max_channels = 1);
1714
~Renderer() override = default;
1815

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

2219
void renderBuffer(IAudioStream* stream) override;
2320
using IRenderer::renderBuffer;
24-
private:
25-
std::unique_ptr<files::WAVFile> m_out;
26-
std::vector<int16_t> m_buf;
2721
};
2822
}

sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/stubs/StubMixer.hpp renamed to sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/IMixerMock.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
#include <HyperSonicDrivers/audio/IAudioStream.hpp>
77
#include <HyperSonicDrivers/audio/scummvm/Timestamp.hpp>
88

9-
namespace HyperSonicDrivers::audio::stubs
9+
namespace HyperSonicDrivers::audio
1010
{
11-
class StubMixer : public IMixer
11+
class IMixerMock : public IMixer
1212
{
1313
public:
1414
int rate = 44100;
1515

16-
StubMixer() : IMixer(32, 44100, 1024) {};
17-
explicit StubMixer(const int freq) : IMixer(32, freq, 1024) {};
16+
IMixerMock() : IMixer(32, 44100, 1024) {};
17+
explicit IMixerMock(const int freq) : IMixer(32, freq, 1024) {};
1818

1919
bool init() override { return true; };
2020

sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <HyperSonicDrivers/drivers/westwood/ADLDriver.hpp>
66
#include <HyperSonicDrivers/audio/mixer/ChannelGroup.hpp>
77
#include <HyperSonicDrivers/hardware/opl/OplEmulator.hpp>
8-
#include <HyperSonicDrivers/audio/stubs/StubMixer.hpp>
8+
#include <HyperSonicDrivers/audio/IMixerMock.hpp>
99
#include <filesystem>
1010
#include <string>
1111

@@ -28,7 +28,7 @@ namespace HyperSonicDrivers::audio::sdl2
2828

2929
RendererTest()
3030
{
31-
mixer = std::make_shared<stubs::StubMixer>();
31+
mixer = std::make_shared<IMixerMock>();
3232
switch (device_name)
3333
{
3434
using enum devices::eDeviceName;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
3+
#include <HyperSonicDrivers/audio/midi/MIDIEvent.hpp>
4+
#include <HyperSonicDrivers/devices/IDevice.hpp>
5+
#include <HyperSonicDrivers/audio/IMixerMock.hpp>
6+
7+
8+
namespace HyperSonicDrivers::devices
9+
{
10+
template<class T>
11+
class DeviceMock : public T
12+
{
13+
public:
14+
explicit DeviceMock(const std::shared_ptr<audio::IMixer>& mixer) : T(mixer) {
15+
static_assert(std::is_base_of_v<IDevice, T>);
16+
};
17+
DeviceMock() : T(audio::make_mixer<audio::IMixerMock>()) {
18+
static_assert(std::is_base_of_v<IDevice, T>);
19+
};
20+
21+
bool init() noexcept override { return true; };
22+
bool shutdown() noexcept override { return true; };
23+
std::optional<uint8_t> getChannelId() const noexcept { return std::nullopt; };
24+
};
25+
}
26+

sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/EmulatorTestCase.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#include <gtest/gtest.h>
44
#include <gmock/gmock.h>
55
#include <HyperSonicDrivers/hardware/opl/OplEmulator.hpp>
6-
#include <HyperSonicDrivers/audio/stubs/StubMixer.hpp>
6+
#include <HyperSonicDrivers/audio/IMixerMock.hpp>
77
#include <stdexcept>
88

99
namespace HyperSonicDrivers::devices
1010
{
11-
using audio::stubs::StubMixer;
11+
using audio::IMixerMock;
1212
using hardware::opl::OplEmulator;
1313

1414
template<class T>
@@ -17,7 +17,7 @@ namespace HyperSonicDrivers::devices
1717
public:
1818
const OplEmulator oplEmu = std::get<0>(GetParam());
1919
const bool shouldFail = std::get<1>(GetParam());
20-
const std::shared_ptr<StubMixer> mixer = std::make_shared<StubMixer>();
20+
const std::shared_ptr<IMixerMock> mixer = std::make_shared<IMixerMock>();
2121

2222
void test_case()
2323
{

0 commit comments

Comments
 (0)