1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00

Corrige AudioEngine

This commit is contained in:
Danilo 2024-05-24 15:05:06 -03:00
parent 2aa02112cf
commit c682cb0691
10 changed files with 114 additions and 119 deletions

View File

@ -41,7 +41,8 @@ add_executable (xna WIN32
"common/gjk.cpp" "common/gjk.cpp"
"common/numerics.cpp" "common/numerics.cpp"
"common/packedvalue.cpp" "common/packedvalue.cpp"
"platform/buffer.cpp" ) "platform/buffer.cpp"
"platform/audioengine-dx.cpp" )
if (CMAKE_VERSION VERSION_GREATER 3.12) if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET xna PROPERTY CXX_STANDARD 20) set_property(TARGET xna PROPERTY CXX_STANDARD 20)

View File

@ -0,0 +1,73 @@
#include "platform-dx/implementations.hpp"
namespace xna {
AudioEngine::AudioEngine()
{
impl = unew<PlatformImplementation>();
}
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<DirectX::AUDIO_ENGINE_REVERB>(value);
impl->_dxAudioEngine->SetReverb(reverb);
}
}

View File

@ -1,5 +0,0 @@
#include "platform-dx/audioengine-dx.hpp"
namespace xna {
}

View File

@ -1,9 +1,8 @@
#include "csharp/type.hpp" #include "csharp/type.hpp"
#include "game/gdevicemanager.hpp"
#include "game/time.hpp" #include "game/time.hpp"
#include "platform-dx/audioengine-dx.hpp"
#include "platform-dx/game-dx.hpp" #include "platform-dx/game-dx.hpp"
#include "platform-dx/implementations.hpp" #include "platform-dx/implementations.hpp"
#include "game/gdevicemanager.hpp"
namespace xna { namespace xna {
Game::Game() { Game::Game() {

View File

@ -1,15 +1,15 @@
#include "platform-dx/soundeffect-dx.hpp" #include "platform-dx/soundeffect-dx.hpp"
#include "platform-dx/audioengine-dx.hpp" #include "platform-dx/implementations.hpp"
using DxSoundEffect = DirectX::SoundEffect; using DxSoundEffect = DirectX::SoundEffect;
namespace xna { namespace xna {
SoundEffect::SoundEffect(AudioEngine& audioEngine, String const& fileName) { SoundEffect::SoundEffect(AudioEngine& audioEngine, String const& fileName) {
if (!audioEngine._dxAudioEngine) if (!audioEngine.impl->_dxAudioEngine)
return; return;
const auto file = XnaHToWString(fileName); const auto file = XnaHToWString(fileName);
_dxSoundEffect = New<DxSoundEffect>(audioEngine._dxAudioEngine.get(), file.c_str()); _dxSoundEffect = New<DxSoundEffect>(audioEngine.impl->_dxAudioEngine.get(), file.c_str());
} }
void SoundEffect::Play() { void SoundEffect::Play() {

View File

@ -4,17 +4,22 @@
#include "../default.hpp" #include "../default.hpp"
namespace xna { namespace xna {
class IAudioEngine { class AudioEngine {
public: public:
virtual ~IAudioEngine(){} AudioEngine();
virtual bool Reset() = 0; ~AudioEngine();
virtual bool Resume() = 0; bool Reset();
virtual bool Suspend() = 0; bool Resume();
virtual bool Update() = 0; bool Suspend();
virtual void DefaultSampleRate(int value) = 0; bool Update();
virtual void MasterVolume(float value) = 0; void DefaultSampleRate(int value);
virtual void MasteringLimit(int limit, int loudness) = 0; void MasterVolume(float value);
virtual void Reverb(AudioReverb value) = 0; void MasteringLimit(int limit, int loudness);
void Reverb(AudioReverb value);
public:
struct PlatformImplementation;
uptr<PlatformImplementation> impl = nullptr;
}; };
} }

View File

@ -1,96 +0,0 @@
#ifndef XNA_PLATFORM_SOUNDENGINE_DX_HPP
#define XNA_PLATFORM_SOUNDENGINE_DX_HPP
#include "../audio/audioengine.hpp"
#include <Audio.h>
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<DirectX::AudioEngine>(
#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<DirectX::AUDIO_ENGINE_REVERB>(value);
_dxAudioEngine->SetReverb(reverb);
}
public:
sptr<DirectX::AudioEngine> _dxAudioEngine = nullptr;
};
}
#endif

View File

@ -4,8 +4,8 @@
#include "../content/manager.hpp" #include "../content/manager.hpp"
#include "../default.hpp" #include "../default.hpp"
#include "../game/game.hpp" #include "../game/game.hpp"
#include "dx/StepTimer.hpp"
#include "dxheaders.hpp" #include "dxheaders.hpp"
#include "platform-dx/dx/StepTimer.hpp"
namespace xna { namespace xna {
class Game : public IGame, public std::enable_shared_from_this<Game> { class Game : public IGame, public std::enable_shared_from_this<Game> {

View File

@ -20,6 +20,7 @@
#include "graphics/texture.hpp" #include "graphics/texture.hpp"
#include "graphics/rendertarget.hpp" #include "graphics/rendertarget.hpp"
#include "game/window.hpp" #include "game/window.hpp"
#include "audio/audioengine.hpp"
namespace xna { namespace xna {
struct SpriteFont::PlatformImplementation { struct SpriteFont::PlatformImplementation {
@ -456,6 +457,24 @@ namespace xna {
_windowCenterX = _windowWidth / 2.0f; _windowCenterX = _windowWidth / 2.0f;
_windowCenterY = _windowHeight / 2.0f; _windowCenterY = _windowHeight / 2.0f;
} }
};
struct AudioEngine::PlatformImplementation {
PlatformImplementation() {
_dxAudioEngine = unew<DirectX::AudioEngine>(
#ifdef _DEBUG
DirectX::AudioEngine_Debug
#endif
);
}
~PlatformImplementation(){
if (_dxAudioEngine) {
_dxAudioEngine->Suspend();
}
}
uptr<DirectX::AudioEngine> _dxAudioEngine = nullptr;
}; };
} }

View File

@ -1,4 +1,3 @@
#include "audioengine-dx.hpp"
#include "content-readers/texture2Dreader-dx.hpp" #include "content-readers/texture2Dreader-dx.hpp"
#include "device-dx.hpp" #include "device-dx.hpp"
#include "dx/StepTimer.hpp" #include "dx/StepTimer.hpp"