mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Corrige SoundEffect
This commit is contained in:
parent
d17d36cc15
commit
26dd91ffa3
@ -1,94 +1,105 @@
|
||||
#include "platform-dx/soundeffect-dx.hpp"
|
||||
#include "platform-dx/implementations.hpp"
|
||||
|
||||
using DxSoundEffect = DirectX::SoundEffect;
|
||||
|
||||
namespace xna {
|
||||
SoundEffectInstance::SoundEffectInstance() {
|
||||
impl = unew<PlatformImplementation>();
|
||||
}
|
||||
|
||||
SoundEffectInstance::~SoundEffectInstance() {
|
||||
impl = nullptr;
|
||||
}
|
||||
|
||||
SoundEffect::SoundEffect(AudioEngine& audioEngine, String const& fileName) {
|
||||
if (!audioEngine.impl->_dxAudioEngine)
|
||||
return;
|
||||
|
||||
const auto file = XnaHToWString(fileName);
|
||||
_dxSoundEffect = New<DxSoundEffect>(audioEngine.impl->_dxAudioEngine.get(), file.c_str());
|
||||
impl->_dxSoundEffect = unew<DxSoundEffect>(audioEngine.impl->_dxAudioEngine.get(), file.c_str());
|
||||
}
|
||||
|
||||
SoundEffect::~SoundEffect() {
|
||||
impl = nullptr;
|
||||
}
|
||||
|
||||
void SoundEffect::Play() {
|
||||
if (!_dxSoundEffect)
|
||||
if (!impl->_dxSoundEffect)
|
||||
return;
|
||||
|
||||
_dxSoundEffect->Play();
|
||||
impl->_dxSoundEffect->Play();
|
||||
}
|
||||
|
||||
void SoundEffect::Play(float volume, float pitch, float pan) {
|
||||
if (!_dxSoundEffect)
|
||||
if (!impl->_dxSoundEffect)
|
||||
return;
|
||||
|
||||
_dxSoundEffect->Play(volume, pitch, pan);
|
||||
impl->_dxSoundEffect->Play(volume, pitch, pan);
|
||||
}
|
||||
|
||||
SoundEffectInstance SoundEffect::CreateInstance() {
|
||||
if (!_dxSoundEffect)
|
||||
return SoundEffectInstance();
|
||||
uptr<SoundEffectInstance> SoundEffect::CreateInstance() {
|
||||
if (!impl->_dxSoundEffect)
|
||||
return unew<SoundEffectInstance>();
|
||||
|
||||
SoundEffectInstance i{};
|
||||
i._dxInstance = _dxSoundEffect->CreateInstance();
|
||||
auto instance = unew<SoundEffectInstance>();
|
||||
instance->impl->_dxInstance = impl->_dxSoundEffect->CreateInstance();
|
||||
|
||||
return i;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void SoundEffectInstance::Play(bool loop) {
|
||||
if (!_dxInstance)
|
||||
if (!impl->_dxInstance)
|
||||
return;
|
||||
|
||||
_dxInstance->Play(loop);
|
||||
impl->_dxInstance->Play(loop);
|
||||
}
|
||||
|
||||
void SoundEffectInstance::Stop(bool immediate) {
|
||||
if (!_dxInstance)
|
||||
if (!impl->_dxInstance)
|
||||
return;
|
||||
|
||||
_dxInstance->Stop(immediate);
|
||||
impl->_dxInstance->Stop(immediate);
|
||||
}
|
||||
|
||||
void SoundEffectInstance::Pause() {
|
||||
if (!_dxInstance)
|
||||
if (!impl->_dxInstance)
|
||||
return;
|
||||
|
||||
_dxInstance->Pause();
|
||||
impl->_dxInstance->Pause();
|
||||
}
|
||||
|
||||
void SoundEffectInstance::Resume() {
|
||||
if (!_dxInstance)
|
||||
if (!impl->_dxInstance)
|
||||
return;
|
||||
|
||||
_dxInstance->Resume();
|
||||
impl->_dxInstance->Resume();
|
||||
}
|
||||
|
||||
void SoundEffectInstance::Volume(float volume) {
|
||||
if (!_dxInstance)
|
||||
if (!impl->_dxInstance)
|
||||
return;
|
||||
|
||||
_dxInstance->SetVolume(volume);
|
||||
impl->_dxInstance->SetVolume(volume);
|
||||
}
|
||||
|
||||
void SoundEffectInstance::Pitch(float pitch) {
|
||||
if (!_dxInstance)
|
||||
if (!impl->_dxInstance)
|
||||
return;
|
||||
|
||||
_dxInstance->SetPitch(pitch);
|
||||
impl->_dxInstance->SetPitch(pitch);
|
||||
}
|
||||
|
||||
void SoundEffectInstance::Pan(float pan) {
|
||||
if (!_dxInstance)
|
||||
if (!impl->_dxInstance)
|
||||
return;
|
||||
|
||||
_dxInstance->SetPan(pan);
|
||||
impl->_dxInstance->SetPan(pan);
|
||||
}
|
||||
|
||||
bool SoundEffectInstance::IsLooped() {
|
||||
if (!_dxInstance)
|
||||
if (!impl->_dxInstance)
|
||||
return false;
|
||||
|
||||
return _dxInstance->IsLooped();
|
||||
return impl->_dxInstance->IsLooped();
|
||||
}
|
||||
}
|
@ -4,24 +4,36 @@
|
||||
#include "../default.hpp"
|
||||
|
||||
namespace xna {
|
||||
struct ISoundEffectInstance {
|
||||
struct SoundEffectInstance {
|
||||
public:
|
||||
virtual void Play(bool loop = false) = 0;
|
||||
virtual void Stop(bool immediate = true) = 0;
|
||||
virtual void Pause() = 0;
|
||||
virtual void Resume() = 0;
|
||||
virtual void Volume(float volume) = 0;
|
||||
virtual void Pitch(float pitch) = 0;
|
||||
virtual void Pan(float pan) = 0;
|
||||
virtual bool IsLooped() = 0;
|
||||
SoundEffectInstance();
|
||||
~SoundEffectInstance();
|
||||
|
||||
void Play(bool loop = false);
|
||||
void Stop(bool immediate = true);
|
||||
void Pause();
|
||||
void Resume();
|
||||
void Volume(float volume);
|
||||
void Pitch(float pitch);
|
||||
void Pan(float pan);
|
||||
bool IsLooped();
|
||||
|
||||
public:
|
||||
struct PlatformImplementation;
|
||||
uptr<PlatformImplementation> impl = nullptr;
|
||||
};
|
||||
|
||||
class ISoundEffect {
|
||||
class SoundEffect {
|
||||
public:
|
||||
virtual ~ISoundEffect(){}
|
||||
virtual void Play() = 0;
|
||||
virtual void Play(float volume, float pitch, float pan) = 0;
|
||||
virtual SoundEffectInstance CreateInstance() = 0;
|
||||
SoundEffect(AudioEngine& audioEngine, String const& fileName);
|
||||
~SoundEffect();
|
||||
void Play();
|
||||
void Play(float volume, float pitch, float pan);
|
||||
uptr<SoundEffectInstance> CreateInstance();
|
||||
|
||||
public:
|
||||
struct PlatformImplementation;
|
||||
uptr<PlatformImplementation> impl = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "graphics/rendertarget.hpp"
|
||||
#include "game/window.hpp"
|
||||
#include "audio/audioengine.hpp"
|
||||
#include "audio/soundeffect.hpp"
|
||||
#include "graphics/viewport.hpp"
|
||||
#include "common/color.hpp"
|
||||
#include "game/game.hpp"
|
||||
@ -470,6 +471,14 @@ namespace xna {
|
||||
DX::StepTimer _stepTimer{};
|
||||
};
|
||||
|
||||
struct SoundEffectInstance::PlatformImplementation {
|
||||
uptr<DirectX::SoundEffectInstance> _dxInstance = nullptr;
|
||||
};
|
||||
|
||||
struct SoundEffect::PlatformImplementation {
|
||||
uptr<DirectX::SoundEffect> _dxSoundEffect = nullptr;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline bool IndexBuffer::Initialize(std::vector<T> const& data, xna_error_ptr_arg) {
|
||||
if (!impl || !m_device || !m_device->impl->_device || data.empty()) {
|
||||
|
@ -1,37 +0,0 @@
|
||||
#ifndef XNA_PLATFORM_SOUNDEFFECT_DX_HPP
|
||||
#define XNA_PLATFORM_SOUNDEFFECT_DX_HPP
|
||||
|
||||
#include "../audio/soundeffect.hpp"
|
||||
#include <Audio.h>
|
||||
|
||||
namespace xna {
|
||||
struct SoundEffectInstance : public ISoundEffectInstance {
|
||||
public:
|
||||
SoundEffectInstance() = default;
|
||||
|
||||
virtual void Play(bool loop = false) override;
|
||||
virtual void Stop(bool immediate = true) override;
|
||||
virtual void Pause() override;
|
||||
virtual void Resume() override;
|
||||
virtual void Volume(float volume) override;
|
||||
virtual void Pitch(float pitch) override;
|
||||
virtual void Pan(float pan) override;
|
||||
virtual bool IsLooped() override;
|
||||
|
||||
public:
|
||||
uptr<DirectX::SoundEffectInstance> _dxInstance = nullptr;
|
||||
};
|
||||
|
||||
class SoundEffect : public ISoundEffect {
|
||||
public:
|
||||
SoundEffect(AudioEngine& audioEngine, String const& fileName);
|
||||
virtual void Play() override;
|
||||
virtual void Play(float volume, float pitch, float pan) override;
|
||||
virtual SoundEffectInstance CreateInstance() override;
|
||||
|
||||
public:
|
||||
sptr<DirectX::SoundEffect> _dxSoundEffect = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -2,5 +2,4 @@
|
||||
#include "dx/StepTimer.hpp"
|
||||
#include "dxheaders.hpp"
|
||||
#include "init-dx.hpp"
|
||||
#include "soundeffect-dx.hpp"
|
||||
#include "implementations.hpp"
|
Loading…
x
Reference in New Issue
Block a user