32 #include "vfs/raw/rawdata.h"
34 #include "util/log/logger.h"
35 #include "util/base/exception.h"
37 #include "soundmanager.h"
38 #include "soundemitter.h"
39 #include "soundclippool.h"
42 static Logger _log(LM_AUDIO);
44 SoundManager::SoundManager(SoundClipPool* pool) : m_context(0),
51 SoundManager::~SoundManager() {
55 for (std::vector<SoundEmitter*>::iterator it = m_emittervec.begin(), it_end = m_emittervec.end(); it != it_end; ++it) {
64 alcDestroyContext(m_context);
65 alcCloseDevice(m_device);
69 if (alcGetError(NULL) != ALC_NO_ERROR) {
70 FL_ERR(_log, LMsg() <<
"error closing openal device");
74 void SoundManager::init() {
75 m_device = alcOpenDevice(NULL);
77 if (!m_device || alcGetError(m_device) != ALC_NO_ERROR) {
78 FL_ERR(_log, LMsg() <<
"Could not open audio device - deactivating audio module");
83 m_context = alcCreateContext(m_device, NULL);
84 if (!m_context || alcGetError(m_device) != ALC_NO_ERROR) {
85 FL_ERR(_log, LMsg() <<
"Couldn't create audio context - deactivating audio module");
90 alcMakeContextCurrent(m_context);
91 if (alcGetError(m_device) != ALC_NO_ERROR) {
92 FL_ERR(_log, LMsg() <<
"Couldn't change current audio context - deactivating audio module");
98 alListener3f(AL_POSITION, 0.0, 0.0, 0.0);
99 ALfloat vec1[6] = { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0};
100 alListenerfv(AL_ORIENTATION, vec1);
103 alListenerf(AL_GAIN, m_volume);
106 SoundEmitter* SoundManager::getEmitter(
unsigned int emitterid)
const{
107 return m_emittervec.at(emitterid);
110 SoundEmitter* SoundManager::createEmitter() {
111 SoundEmitter* ptr =
new SoundEmitter(
this, m_pool, m_emittervec.size());
112 m_emittervec.push_back(ptr);
116 void SoundManager::releaseEmitter(
unsigned int emitterid) {
117 SoundEmitter** ptr = &m_emittervec.at(emitterid);