2021-10-19 10:27:59 -04:00
|
|
|
#include "audio.h"
|
|
|
|
|
2021-10-25 10:50:08 -04:00
|
|
|
Audio::Audio() {
|
|
|
|
m_engine = irrklang::createIrrKlangDevice();
|
2023-10-16 12:02:37 -04:00
|
|
|
m_engine->setDopplerEffectParameters(10);
|
|
|
|
m_engine->setRolloffFactor(2);
|
|
|
|
m_engine->setDefault3DSoundMinDistance(.1);
|
2021-10-25 10:50:08 -04:00
|
|
|
m_engine->setDefault3DSoundMaxDistance(1000);
|
|
|
|
}
|
|
|
|
|
2023-12-13 10:55:58 -05:00
|
|
|
Audio::Audio(const char * music, const char* menumusic) {
|
2021-10-25 10:50:08 -04:00
|
|
|
m_engine = irrklang::createIrrKlangDevice();
|
|
|
|
m_engine->setDopplerEffectParameters(1);
|
2023-10-16 12:02:37 -04:00
|
|
|
m_engine->setRolloffFactor(2);
|
|
|
|
m_engine->setDefault3DSoundMinDistance(.1);
|
2021-10-25 10:50:08 -04:00
|
|
|
m_engine->setDefault3DSoundMaxDistance(1000);
|
2023-12-09 16:51:43 -05:00
|
|
|
m_music = m_engine->play2D(music, true, true, true, irrklang::ESM_STREAMING);
|
2023-12-13 10:55:58 -05:00
|
|
|
m_menumusic = m_engine->play2D(menumusic, true, true, true, irrklang::ESM_STREAMING);
|
|
|
|
m_music->setVolume(.5);
|
|
|
|
m_menumusic->setVolume(.5);
|
2021-10-25 10:50:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Audio::~Audio() {
|
2021-10-26 17:28:37 -04:00
|
|
|
if (m_music) m_music->drop();
|
2023-12-13 10:55:58 -05:00
|
|
|
if (m_menumusic) m_menumusic->drop();
|
2021-10-26 17:28:37 -04:00
|
|
|
if (m_engine) m_engine->drop();
|
2021-10-25 10:50:08 -04:00
|
|
|
}
|
2021-10-19 10:27:59 -04:00
|
|
|
|
2023-12-13 10:55:58 -05:00
|
|
|
void Audio::playSound(const char* sound) {
|
|
|
|
m_engine->play2D(sound);
|
|
|
|
}
|
|
|
|
|
2021-10-26 17:28:37 -04:00
|
|
|
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));
|
2021-10-25 10:50:08 -04:00
|
|
|
}
|
|
|
|
|
2023-10-16 12:02:37 -04:00
|
|
|
irrklang::ISound* Audio::Create3DAudioObj(irrklang::ISound* sound, const char* name, Vector3f pos, Vector3f vel, bool is_looped = false, float volume = 1) {
|
|
|
|
sound = m_engine->play3D(name, irrklang::vec3df(pos.x, pos.y, pos.z), is_looped, false, true, is_looped? irrklang::ESM_STREAMING: irrklang::ESM_NO_STREAMING, true);
|
2021-10-26 17:28:37 -04:00
|
|
|
sound->setVelocity(irrklang::vec3df(vel.x, vel.y, vel.z));
|
2021-10-25 10:50:08 -04:00
|
|
|
sound->setVolume(volume);
|
2023-10-16 12:02:37 -04:00
|
|
|
return sound;
|
2021-10-25 10:50:08 -04:00
|
|
|
}
|
2021-10-19 10:27:59 -04:00
|
|
|
|
2021-10-26 17:28:37 -04:00
|
|
|
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));
|
2021-10-25 10:50:08 -04:00
|
|
|
sound->setVolume(volume);
|
2021-10-19 10:27:59 -04:00
|
|
|
}
|
2021-10-25 10:50:08 -04:00
|
|
|
|
2023-09-15 11:24:43 -04:00
|
|
|
//void Audio::PlaySong(const char* music) {
|
|
|
|
// m_music = m_engine->play2D(music, false, false, false, irrklang::ESM_STREAMING);
|
|
|
|
//}
|
2021-11-16 20:48:52 -05:00
|
|
|
|
2023-12-13 10:55:58 -05:00
|
|
|
void Audio::ToggleMusicState(GameState state) {
|
|
|
|
if (m_music_on) {
|
|
|
|
switch (state) {
|
|
|
|
case PLAY:
|
|
|
|
m_music->setIsPaused(false);
|
|
|
|
m_menumusic->setIsPaused(true);
|
|
|
|
break;
|
|
|
|
case PAUSE:
|
|
|
|
m_music->setIsPaused(true);
|
|
|
|
m_menumusic->setIsPaused(true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
m_music->setIsPaused(true);
|
|
|
|
m_menumusic->setIsPaused(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_music->setIsPaused(true);
|
|
|
|
m_menumusic->setIsPaused(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Audio::SetMusic(bool ison, GameState state) {
|
|
|
|
m_music_on = state;
|
|
|
|
if (!state) {
|
|
|
|
m_music->setIsPaused(true);
|
|
|
|
m_menumusic->setIsPaused(true);
|
|
|
|
}
|
|
|
|
else ToggleMusicState(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Audio::GetMusic() {
|
|
|
|
return m_music_on;
|
|
|
|
}
|
2021-10-25 10:50:08 -04:00
|
|
|
|
|
|
|
void Audio::PauseEngine() { m_engine->setAllSoundsPaused(); }
|
2023-11-27 16:03:06 -05:00
|
|
|
|
|
|
|
float Audio::GetMusicVolume() const {
|
|
|
|
return m_music->getVolume();
|
|
|
|
}
|