50 lines
1.7 KiB
C++
50 lines
1.7 KiB
C++
#include "audio.h"
|
|
|
|
Audio::Audio() {
|
|
m_engine = irrklang::createIrrKlangDevice();
|
|
m_engine->setDopplerEffectParameters(1);
|
|
m_engine->setRolloffFactor(1);
|
|
m_engine->setDefault3DSoundMinDistance(1);
|
|
m_engine->setDefault3DSoundMaxDistance(1000);
|
|
}
|
|
|
|
Audio::Audio(const char * music) {
|
|
m_engine = irrklang::createIrrKlangDevice();
|
|
m_engine->setDopplerEffectParameters(1);
|
|
m_engine->setRolloffFactor(1);
|
|
m_engine->setDefault3DSoundMinDistance(1);
|
|
m_engine->setDefault3DSoundMaxDistance(1000);
|
|
m_music = m_engine->play2D(music, true, true, true, irrklang::ESM_STREAMING);
|
|
}
|
|
|
|
Audio::~Audio() {
|
|
if (m_music) m_music->drop();
|
|
if (m_engine) m_engine->drop();
|
|
}
|
|
|
|
void Audio::Update3DAudio(Vector3f pos, Vector3f dir, Vector3f vel) {
|
|
m_engine->setListenerPosition(irrklang::vec3df(pos.x, pos.y, pos.z),
|
|
irrklang::vec3df(dir.x, dir.y, dir.z),
|
|
irrklang::vec3df(vel.x, vel.y, vel.z));
|
|
}
|
|
|
|
void Audio::Create3DAudioObj(irrklang::ISound* sound, const char* name, Vector3f& pos, Vector3f& vel, float volume = 1) {
|
|
sound = m_engine->play3D(name, irrklang::vec3df(pos.x, pos.y, pos.z), false, false, true, irrklang::ESM_NO_STREAMING, true);
|
|
sound->setVelocity(irrklang::vec3df(vel.x, vel.y, vel.z));
|
|
sound->setVolume(volume);
|
|
}
|
|
|
|
void Audio::Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& vel, float volume = 1) {
|
|
sound->setPosition(irrklang::vec3df(pos.x, pos.y, pos.z));
|
|
sound->setVelocity(irrklang::vec3df(vel.x, vel.y, vel.z));
|
|
sound->setVolume(volume);
|
|
}
|
|
|
|
void Audio::PlaySong(const char* music) {
|
|
m_music = m_engine->play2D(music, true, true, true, irrklang::ESM_STREAMING);
|
|
}
|
|
|
|
void Audio::ToggleMusicState() { m_music->setIsPaused(!m_music->getIsPaused()); }
|
|
|
|
void Audio::PauseEngine() { m_engine->setAllSoundsPaused(); }
|