ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

poolsound.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "common/str.h"
00024 #include "engines/grim/emi/sound/emisound.h"
00025 #include "engines/grim/emi/poolsound.h"
00026 #include "engines/grim/resource.h"
00027 
00028 
00029 namespace Grim {
00030 
00031 PoolSound::PoolSound() : _filename(""), _loaded(false), _soundId(0) {
00032 }
00033 
00034 PoolSound::PoolSound(const Common::String &filename) : _filename(""), _loaded(false), _soundId(0) {
00035     openFile(filename);
00036 }
00037 
00038 // Called when the engine restarts or Lua code calls FreeSound
00039 PoolSound::~PoolSound() {
00040     if (_loaded) {
00041         g_emiSound->freeLoadedSound(_soundId);
00042     }
00043 }
00044 
00045 void PoolSound::setVolume(int volume) {
00046     if (_loaded) {
00047         g_emiSound->setLoadedSoundVolume(_soundId, volume);
00048     }
00049 }
00050 
00051 void PoolSound::setBalance(int balance) {
00052     if (_loaded) {
00053         g_emiSound->setLoadedSoundPan(_soundId, balance);
00054     }
00055 }
00056 
00057 void PoolSound::setPosition(Math::Vector3d &pos) {
00058     if (_loaded) {
00059         g_emiSound->setLoadedSoundPosition(_soundId, pos);
00060     }
00061 }
00062 
00063 void PoolSound::play(bool looping) {
00064     if (_loaded) {
00065         g_emiSound->playLoadedSound(_soundId, looping);
00066     }
00067 }
00068 
00069 void PoolSound::playFrom(const Math::Vector3d &pos, bool looping) {
00070     if (_loaded) {
00071         g_emiSound->playLoadedSoundFrom(_soundId, pos, looping);
00072     }
00073 }
00074 
00075 void PoolSound::stop() {
00076     if (_loaded) {
00077         g_emiSound->stopLoadedSound(_soundId);
00078     }
00079 }
00080 
00081 int PoolSound::getVolume() {
00082     if (_loaded) {
00083         return g_emiSound->getLoadedSoundVolume(_soundId);
00084     }
00085     return 0;
00086 }
00087 
00088 bool PoolSound::isPlaying() {
00089     if (_loaded) {
00090         return g_emiSound->getLoadedSoundStatus(_soundId);
00091     }
00092     return false;
00093 }
00094 
00095 void PoolSound::openFile(const Common::String &filename) {
00096     _filename = filename;
00097     _loaded = g_emiSound->loadSfx(filename.c_str(), _soundId);
00098     if (!_loaded) {
00099         warning("Could not open PoolSound file %s", filename.c_str());
00100     }
00101 }
00102 
00103 void PoolSound::saveState(SaveGame *state) {
00104     state->writeBool(_loaded);
00105     state->writeLESint32(_soundId);
00106 }
00107 
00108 void PoolSound::restoreState(SaveGame *state) {
00109     if (state->saveMinorVersion() >= 21) {
00110         _loaded = state->readBool();
00111         _soundId = state->readLESint32();
00112     } else {
00113         bool hasStream = state->readBool();
00114         if (hasStream)
00115             openFile(state->readString());
00116     }
00117 }
00118 }


Generated on Sat May 18 2019 05:01:12 for ResidualVM by doxygen 1.7.1
curved edge   curved edge