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

105 lines
2.1 KiB
C++
Raw Normal View History

2024-05-24 15:05:06 -03:00
#include "platform-dx/implementations.hpp"
2024-04-20 13:39:19 -03:00
using DxSoundEffect = DirectX::SoundEffect;
namespace xna {
2024-05-24 23:12:29 -03:00
SoundEffectInstance::SoundEffectInstance() {
impl = unew<PlatformImplementation>();
}
SoundEffectInstance::~SoundEffectInstance() {
impl = nullptr;
}
2024-05-27 21:12:46 -03:00
SoundEffect::SoundEffect(String const& fileName) {
if (!AudioEngine::impl || !AudioEngine::impl->_dxAudioEngine)
2024-04-20 13:39:19 -03:00
return;
const auto file = XnaHToWString(fileName);
2024-05-27 21:12:46 -03:00
impl->_dxSoundEffect = unew<DxSoundEffect>(AudioEngine::impl->_dxAudioEngine.get(), file.c_str());
2024-05-24 23:12:29 -03:00
}
SoundEffect::~SoundEffect() {
impl = nullptr;
2024-04-20 13:39:19 -03:00
}
void SoundEffect::Play() {
2024-05-24 23:12:29 -03:00
if (!impl->_dxSoundEffect)
2024-04-20 13:39:19 -03:00
return;
2024-05-24 23:12:29 -03:00
impl->_dxSoundEffect->Play();
2024-04-20 13:39:19 -03:00
}
void SoundEffect::Play(float volume, float pitch, float pan) {
2024-05-24 23:12:29 -03:00
if (!impl->_dxSoundEffect)
2024-04-20 13:39:19 -03:00
return;
2024-05-24 23:12:29 -03:00
impl->_dxSoundEffect->Play(volume, pitch, pan);
2024-04-20 13:39:19 -03:00
}
2024-05-24 23:12:29 -03:00
uptr<SoundEffectInstance> SoundEffect::CreateInstance() {
if (!impl->_dxSoundEffect)
return unew<SoundEffectInstance>();
2024-04-20 13:39:19 -03:00
2024-05-24 23:12:29 -03:00
auto instance = unew<SoundEffectInstance>();
instance->impl->_dxInstance = impl->_dxSoundEffect->CreateInstance();
2024-04-20 13:39:19 -03:00
2024-05-24 23:12:29 -03:00
return instance;
2024-04-20 13:39:19 -03:00
}
void SoundEffectInstance::Play(bool loop) {
2024-05-24 23:12:29 -03:00
if (!impl->_dxInstance)
2024-04-20 13:39:19 -03:00
return;
2024-05-24 23:12:29 -03:00
impl->_dxInstance->Play(loop);
2024-04-20 13:39:19 -03:00
}
void SoundEffectInstance::Stop(bool immediate) {
2024-05-24 23:12:29 -03:00
if (!impl->_dxInstance)
2024-04-20 13:39:19 -03:00
return;
2024-05-24 23:12:29 -03:00
impl->_dxInstance->Stop(immediate);
2024-04-20 13:39:19 -03:00
}
void SoundEffectInstance::Pause() {
2024-05-24 23:12:29 -03:00
if (!impl->_dxInstance)
2024-04-20 13:39:19 -03:00
return;
2024-05-24 23:12:29 -03:00
impl->_dxInstance->Pause();
2024-04-20 13:39:19 -03:00
}
void SoundEffectInstance::Resume() {
2024-05-24 23:12:29 -03:00
if (!impl->_dxInstance)
2024-04-20 13:39:19 -03:00
return;
2024-05-24 23:12:29 -03:00
impl->_dxInstance->Resume();
2024-04-20 13:39:19 -03:00
}
void SoundEffectInstance::Volume(float volume) {
2024-05-24 23:12:29 -03:00
if (!impl->_dxInstance)
2024-04-20 13:39:19 -03:00
return;
2024-05-24 23:12:29 -03:00
impl->_dxInstance->SetVolume(volume);
2024-04-20 13:39:19 -03:00
}
void SoundEffectInstance::Pitch(float pitch) {
2024-05-24 23:12:29 -03:00
if (!impl->_dxInstance)
2024-04-20 13:39:19 -03:00
return;
2024-05-24 23:12:29 -03:00
impl->_dxInstance->SetPitch(pitch);
2024-04-20 13:39:19 -03:00
}
void SoundEffectInstance::Pan(float pan) {
2024-05-24 23:12:29 -03:00
if (!impl->_dxInstance)
2024-04-20 13:39:19 -03:00
return;
2024-05-24 23:12:29 -03:00
impl->_dxInstance->SetPan(pan);
2024-04-20 13:39:19 -03:00
}
bool SoundEffectInstance::IsLooped() {
2024-05-24 23:12:29 -03:00
if (!impl->_dxInstance)
2024-04-20 13:39:19 -03:00
return false;
2024-05-24 23:12:29 -03:00
return impl->_dxInstance->IsLooped();
2024-04-20 13:39:19 -03:00
}
}