33 #include "util/log/logger.h"
34 #include "util/base/exception.h"
36 #include "soundmanager.h"
37 #include "soundemitter.h"
40 static Logger _log(LM_AUDIO);
42 SoundManager::SoundManager() : m_context(0),
48 SoundManager::~SoundManager() {
52 for (std::vector<SoundEmitter*>::iterator it = m_emittervec.begin(), it_end = m_emittervec.end(); it != it_end; ++it) {
61 alcDestroyContext(m_context);
62 alcCloseDevice(m_device);
66 if (alcGetError(NULL) != ALC_NO_ERROR) {
67 FL_ERR(_log, LMsg() <<
"error closing openal device");
71 void SoundManager::init() {
72 m_device = alcOpenDevice(NULL);
74 if (!m_device || alcGetError(m_device) != ALC_NO_ERROR) {
75 FL_ERR(_log, LMsg() <<
"Could not open audio device - deactivating audio module");
80 m_context = alcCreateContext(m_device, NULL);
81 if (!m_context || alcGetError(m_device) != ALC_NO_ERROR) {
82 FL_ERR(_log, LMsg() <<
"Couldn't create audio context - deactivating audio module");
87 alcMakeContextCurrent(m_context);
88 if (alcGetError(m_device) != ALC_NO_ERROR) {
89 FL_ERR(_log, LMsg() <<
"Couldn't change current audio context - deactivating audio module");
95 alListener3f(AL_POSITION, 0.0, 0.0, 0.0);
96 ALfloat vec1[6] = { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0};
97 alListenerfv(AL_ORIENTATION, vec1);
100 alListenerf(AL_GAIN, m_volume);
103 SoundEmitter* SoundManager::getEmitter(uint32_t emitterid)
const{
104 return m_emittervec.at(emitterid);
107 SoundEmitter* SoundManager::createEmitter() {
108 SoundEmitter* ptr =
new SoundEmitter(
this, m_emittervec.size());
109 m_emittervec.push_back(ptr);
113 void SoundManager::releaseEmitter(uint32_t emitterid) {
114 SoundEmitter** ptr = &m_emittervec.at(emitterid);
credit to phoku for his NodeDisplay example which the visitor code is adapted from ( he coded the qua...