Mercurial > fife-parpg
view engine/core/audio/soundmanager.cpp @ 104:2c7101e4d81d
* Removing old testmaps as they're not needed for the 2008.2 release
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 24 Jul 2008 10:18:44 +0000 |
parents | 90005975cdbb |
children | 64738befdf3b |
line wrap: on
line source
/*************************************************************************** * 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 Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, 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