diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt index afe3bc1..7ddc875 100644 --- a/framework/CMakeLists.txt +++ b/framework/CMakeLists.txt @@ -41,7 +41,8 @@ add_executable (xna WIN32 "common/gjk.cpp" "common/numerics.cpp" "common/packedvalue.cpp" -"platform/buffer.cpp" ) +"platform/buffer.cpp" +"platform/audioengine-dx.cpp" ) if (CMAKE_VERSION VERSION_GREATER 3.12) set_property(TARGET xna PROPERTY CXX_STANDARD 20) diff --git a/framework/platform/audioengine-dx.cpp b/framework/platform/audioengine-dx.cpp new file mode 100644 index 0000000..c52bc0d --- /dev/null +++ b/framework/platform/audioengine-dx.cpp @@ -0,0 +1,73 @@ +#include "platform-dx/implementations.hpp" + +namespace xna { + AudioEngine::AudioEngine() + { + impl = unew(); + } + + AudioEngine::~AudioEngine() { + impl = nullptr; + } + + bool AudioEngine::Reset() { + if (!impl || !impl->_dxAudioEngine) + return false; + + return impl->_dxAudioEngine->Reset(); + } + + bool AudioEngine::Update() { + if (!impl || !impl->_dxAudioEngine) + return false; + + return impl->_dxAudioEngine->Update(); + } + + bool AudioEngine::Resume() { + if (!impl || !impl->_dxAudioEngine) + return false; + + impl->_dxAudioEngine->Resume(); + + return true; + } + + bool AudioEngine::Suspend() { + if (!impl || !impl->_dxAudioEngine) + return false; + + impl->_dxAudioEngine->Resume(); + + return true; + } + + void AudioEngine::DefaultSampleRate(int value) { + if (!impl || !impl->_dxAudioEngine) + return; + + impl->_dxAudioEngine->SetDefaultSampleRate(value); + } + + void AudioEngine::MasteringLimit(int limit, int loudness) { + if (!impl || !impl->_dxAudioEngine) + return; + + impl->_dxAudioEngine->SetMasteringLimit(limit, loudness); + } + + void AudioEngine::MasterVolume(float value) { + if (!impl || !impl->_dxAudioEngine) + return; + + impl->_dxAudioEngine->SetMasterVolume(value); + } + + void AudioEngine::Reverb(AudioReverb value) { + if (!impl || !impl->_dxAudioEngine) + return; + + const auto reverb = static_cast(value); + impl->_dxAudioEngine->SetReverb(reverb); + } +} \ No newline at end of file diff --git a/framework/platform/audioengine.dx.cpp b/framework/platform/audioengine.dx.cpp deleted file mode 100644 index dea214f..0000000 --- a/framework/platform/audioengine.dx.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "platform-dx/audioengine-dx.hpp" - -namespace xna { - -} \ No newline at end of file diff --git a/framework/platform/game-dx.cpp b/framework/platform/game-dx.cpp index efdf2df..efc2434 100644 --- a/framework/platform/game-dx.cpp +++ b/framework/platform/game-dx.cpp @@ -1,9 +1,8 @@ #include "csharp/type.hpp" +#include "game/gdevicemanager.hpp" #include "game/time.hpp" -#include "platform-dx/audioengine-dx.hpp" #include "platform-dx/game-dx.hpp" #include "platform-dx/implementations.hpp" -#include "game/gdevicemanager.hpp" namespace xna { Game::Game() { diff --git a/framework/platform/soundeffect-dx.cpp b/framework/platform/soundeffect-dx.cpp index 141e165..cdc1df9 100644 --- a/framework/platform/soundeffect-dx.cpp +++ b/framework/platform/soundeffect-dx.cpp @@ -1,15 +1,15 @@ #include "platform-dx/soundeffect-dx.hpp" -#include "platform-dx/audioengine-dx.hpp" +#include "platform-dx/implementations.hpp" using DxSoundEffect = DirectX::SoundEffect; namespace xna { SoundEffect::SoundEffect(AudioEngine& audioEngine, String const& fileName) { - if (!audioEngine._dxAudioEngine) + if (!audioEngine.impl->_dxAudioEngine) return; const auto file = XnaHToWString(fileName); - _dxSoundEffect = New(audioEngine._dxAudioEngine.get(), file.c_str()); + _dxSoundEffect = New(audioEngine.impl->_dxAudioEngine.get(), file.c_str()); } void SoundEffect::Play() { diff --git a/inc/audio/audioengine.hpp b/inc/audio/audioengine.hpp index 5255234..cbf7a3f 100644 --- a/inc/audio/audioengine.hpp +++ b/inc/audio/audioengine.hpp @@ -4,17 +4,22 @@ #include "../default.hpp" namespace xna { - class IAudioEngine { + class AudioEngine { public: - virtual ~IAudioEngine(){} - virtual bool Reset() = 0; - virtual bool Resume() = 0; - virtual bool Suspend() = 0; - virtual bool Update() = 0; - virtual void DefaultSampleRate(int value) = 0; - virtual void MasterVolume(float value) = 0; - virtual void MasteringLimit(int limit, int loudness) = 0; - virtual void Reverb(AudioReverb value) = 0; + AudioEngine(); + ~AudioEngine(); + bool Reset(); + bool Resume(); + bool Suspend(); + bool Update(); + void DefaultSampleRate(int value); + void MasterVolume(float value); + void MasteringLimit(int limit, int loudness); + void Reverb(AudioReverb value); + + public: + struct PlatformImplementation; + uptr impl = nullptr; }; } diff --git a/inc/platform-dx/audioengine-dx.hpp b/inc/platform-dx/audioengine-dx.hpp deleted file mode 100644 index 9741de7..0000000 --- a/inc/platform-dx/audioengine-dx.hpp +++ /dev/null @@ -1,96 +0,0 @@ -#ifndef XNA_PLATFORM_SOUNDENGINE_DX_HPP -#define XNA_PLATFORM_SOUNDENGINE_DX_HPP - -#include "../audio/audioengine.hpp" -#include - -namespace xna { - struct WaveFormat { - Ushort FormatTag{ 0 }; - Ushort Channels{ 0 }; - Ulong SamplesPerSecond{ 0 }; - Ulong Buffer{ 0 }; - Ushort BlockAlign{ 0 }; - Ushort BitsPerSamples{ 0 }; - Ushort ByteSize{ 0 }; - }; - - class AudioEngine : public IAudioEngine { - public: - AudioEngine() { - _dxAudioEngine = New( -#ifdef _DEBUG - DirectX::AudioEngine_Debug -#endif - ); - } - - virtual ~AudioEngine() { - if (_dxAudioEngine) { - _dxAudioEngine->Suspend(); - } - } - - virtual bool Reset() override { - if (!_dxAudioEngine) - return false; - - return _dxAudioEngine->Reset(); - } - - virtual bool Update() override { - if (!_dxAudioEngine) - return false; - - return _dxAudioEngine->Update(); - } - - virtual bool Resume() override { - if (!_dxAudioEngine) - return false; - - _dxAudioEngine->Resume(); - - return true; - } - - virtual bool Suspend() override { - if (!_dxAudioEngine) - return false; - - _dxAudioEngine->Resume(); - - return true; - } - - virtual void DefaultSampleRate(int value) override { - if (!_dxAudioEngine) return; - - _dxAudioEngine->SetDefaultSampleRate(value); - } - - virtual void MasteringLimit(int limit, int loudness) override { - if (!_dxAudioEngine) return; - - _dxAudioEngine->SetMasteringLimit(limit, loudness); - } - - virtual void MasterVolume(float value) override { - if (!_dxAudioEngine) return; - - _dxAudioEngine->SetMasterVolume(value); - } - - virtual void Reverb(AudioReverb value) override { - if (!_dxAudioEngine) return; - - const auto reverb = static_cast(value); - _dxAudioEngine->SetReverb(reverb); - } - - public: - sptr _dxAudioEngine = nullptr; - }; -} - -#endif \ No newline at end of file diff --git a/inc/platform-dx/game-dx.hpp b/inc/platform-dx/game-dx.hpp index adf3fff..45d9724 100644 --- a/inc/platform-dx/game-dx.hpp +++ b/inc/platform-dx/game-dx.hpp @@ -4,8 +4,8 @@ #include "../content/manager.hpp" #include "../default.hpp" #include "../game/game.hpp" -#include "dx/StepTimer.hpp" #include "dxheaders.hpp" +#include "platform-dx/dx/StepTimer.hpp" namespace xna { class Game : public IGame, public std::enable_shared_from_this { diff --git a/inc/platform-dx/implementations.hpp b/inc/platform-dx/implementations.hpp index 30d6ed2..e88b2af 100644 --- a/inc/platform-dx/implementations.hpp +++ b/inc/platform-dx/implementations.hpp @@ -20,6 +20,7 @@ #include "graphics/texture.hpp" #include "graphics/rendertarget.hpp" #include "game/window.hpp" +#include "audio/audioengine.hpp" namespace xna { struct SpriteFont::PlatformImplementation { @@ -456,6 +457,24 @@ namespace xna { _windowCenterX = _windowWidth / 2.0f; _windowCenterY = _windowHeight / 2.0f; } + }; + + struct AudioEngine::PlatformImplementation { + PlatformImplementation() { + _dxAudioEngine = unew( +#ifdef _DEBUG + DirectX::AudioEngine_Debug +#endif + ); + } + + ~PlatformImplementation(){ + if (_dxAudioEngine) { + _dxAudioEngine->Suspend(); + } + } + + uptr _dxAudioEngine = nullptr; }; } diff --git a/inc/platform-dx/xna-dx.hpp b/inc/platform-dx/xna-dx.hpp index 98381f9..ed3bd63 100644 --- a/inc/platform-dx/xna-dx.hpp +++ b/inc/platform-dx/xna-dx.hpp @@ -1,4 +1,3 @@ -#include "audioengine-dx.hpp" #include "content-readers/texture2Dreader-dx.hpp" #include "device-dx.hpp" #include "dx/StepTimer.hpp"