Mercurial > fife-parpg
diff engine/core/audio/soundmanager.cpp @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | 90005975cdbb |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/engine/core/audio/soundmanager.cpp Sun Jun 29 18:44:17 2008 +0000 @@ -0,0 +1,121 @@ +/*************************************************************************** + * Copyright (C) 2005-2008 by the FIFE Team * + * http://www.fifengine.de * + * This file is part of FIFE. * + * * + * FIFE is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +// Standard C++ library includes + +// Platform specific includes + +// 3rd party library includes + +// FIFE includes +// These includes are split up in two parts, separated by one empty line +// First block: files included from the FIFE root src directory +// Second block: files included from the same folder +#include "vfs/raw/rawdata.h" +#include "vfs/vfs.h" +#include "util/log/logger.h" +#include "util/base/exception.h" + +#include "soundmanager.h" +#include "soundemitter.h" +#include "soundclippool.h" + +namespace FIFE { + static Logger _log(LM_AUDIO); + + SoundManager::SoundManager(SoundClipPool* pool) : m_context(0), + m_device(0), + m_pool(pool), + m_mutevol(0), + m_volume(1.0) { + } + + SoundManager::~SoundManager() { + + // free all soundemitters + std::vector<SoundEmitter*>::iterator it; + for (it = m_emittervec.begin(); it != m_emittervec.end(); ++it) { + if ((*it) != NULL) { + delete (*it); + } + } + + m_emittervec.clear(); + + if (m_device) { + alcDestroyContext(m_context); + alcCloseDevice(m_device); + m_device = NULL; + } + + if (alcGetError(NULL) != ALC_NO_ERROR) { + FL_ERR(_log, LMsg() << "error closing openal device"); + } + } + + void SoundManager::init() { + m_device = alcOpenDevice(NULL); + + if (!m_device || alcGetError(m_device) != ALC_NO_ERROR) { + FL_ERR(_log, LMsg() << "Could not open audio device - deactivating audio module"); + m_device = NULL; + return; + } + + m_context = alcCreateContext(m_device, NULL); + if (!m_context || alcGetError(m_device) != ALC_NO_ERROR) { + FL_ERR(_log, LMsg() << "Couldn't create audio context - deactivating audio module"); + m_device = NULL; + return; + } + + alcMakeContextCurrent(m_context); + if (alcGetError(m_device) != ALC_NO_ERROR) { + FL_ERR(_log, LMsg() << "Couldn't change current audio context - deactivating audio module"); + m_device = NULL; + return; + } + + // set listener position + alListener3f(AL_POSITION, 0.0, 0.0, 0.0); + ALfloat vec1[6] = { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0}; + alListenerfv(AL_ORIENTATION, vec1); + + // set volume + alListenerf(AL_GAIN, m_volume); + } + + SoundEmitter* SoundManager::getEmitter(unsigned int emitterid) { + return m_emittervec.at(emitterid); + } + + SoundEmitter* SoundManager::createEmitter() { + SoundEmitter* ptr = new SoundEmitter(this, m_pool, m_emittervec.size()); + m_emittervec.push_back(ptr); + return ptr; + } + + void SoundManager::releaseEmitter(unsigned int emitterid) { + SoundEmitter** ptr = &m_emittervec.at(emitterid); + delete *ptr; + *ptr = NULL; + } +} //FIFE