From 113961fd2a2203434b03766d722a0f8c0854bfd0 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Thu, 19 Jul 2012 19:29:15 +0200 Subject: WINTERMUTE: Change all folder-names to lowercase. --- engines/wintermute/base/BSound.cpp | 288 +++++++++++++++++++++++++++++++++++++ 1 file changed, 288 insertions(+) create mode 100644 engines/wintermute/base/BSound.cpp (limited to 'engines/wintermute/base/BSound.cpp') diff --git a/engines/wintermute/base/BSound.cpp b/engines/wintermute/base/BSound.cpp new file mode 100644 index 0000000000..2b54b39500 --- /dev/null +++ b/engines/wintermute/base/BSound.cpp @@ -0,0 +1,288 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program 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 Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +/* + * This file is based on WME Lite. + * http://dead-code.org/redir.php?target=wmelite + * Copyright (c) 2011 Jan Nedoma + */ + +#include "engines/wintermute/base/BSound.h" +#include "engines/wintermute/base/BGame.h" +#include "engines/wintermute/base/BSoundMgr.h" +#include "engines/wintermute/base/BSoundBuffer.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CBSound, false) + +////////////////////////////////////////////////////////////////////////// +CBSound::CBSound(CBGame *inGame): CBBase(inGame) { + _sound = NULL; + _soundFilename = NULL; + + _soundType = Audio::Mixer::kSFXSoundType; + _soundStreamed = false; + _soundLooping = false; + _soundPlaying = false; + _soundPaused = false; + _soundFreezePaused = false; + _soundPosition = 0; + _soundPrivateVolume = 0; + _soundLoopStart = 0; + + _sFXType = SFX_NONE; + _sFXParam1 = _sFXParam2 = _sFXParam3 = _sFXParam4 = 0; +} + + +////////////////////////////////////////////////////////////////////////// +CBSound::~CBSound() { + if (_sound) _gameRef->_soundMgr->removeSound(_sound); + _sound = NULL; + + delete[] _soundFilename; + _soundFilename = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CBSound::setSound(const char *filename, Audio::Mixer::SoundType type, bool streamed) { + if (_sound) { + _gameRef->_soundMgr->removeSound(_sound); + _sound = NULL; + } + delete[] _soundFilename; + _soundFilename = NULL; + + _sound = _gameRef->_soundMgr->addSound(filename, type, streamed); + if (_sound) { + _soundFilename = new char[strlen(filename) + 1]; + strcpy(_soundFilename, filename); + + _soundType = type; + _soundStreamed = streamed; + + return STATUS_OK; + } else return STATUS_FAILED; +} + + +////////////////////////////////////////////////////////////////////////// +bool CBSound::setSoundSimple() { + _sound = _gameRef->_soundMgr->addSound(_soundFilename, _soundType, _soundStreamed); + if (_sound) { + if (_soundPosition) _sound->setPosition(_soundPosition); + _sound->setLooping(_soundLooping); + _sound->setPrivateVolume(_soundPrivateVolume); + _sound->setLoopStart(_soundLoopStart); + _sound->_freezePaused = _soundFreezePaused; + if (_soundPlaying) return _sound->resume(); + else return STATUS_OK; + } else return STATUS_FAILED; +} + + + +////////////////////////////////////////////////////////////////////////// +uint32 CBSound::getLength() { + if (_sound) return _sound->getLength(); + else return 0; +} + + +////////////////////////////////////////////////////////////////////////// +bool CBSound::play(bool looping) { + if (_sound) { + _soundPaused = false; + return _sound->play(looping, _soundPosition); + } else return STATUS_FAILED; +} + + +////////////////////////////////////////////////////////////////////////// +bool CBSound::stop() { + if (_sound) { + _soundPaused = false; + return _sound->stop(); + } else return STATUS_FAILED; +} + + +////////////////////////////////////////////////////////////////////////// +bool CBSound::pause(bool freezePaused) { + if (_sound) { + _soundPaused = true; + if (freezePaused) _sound->_freezePaused = true; + return _sound->pause(); + } else return STATUS_FAILED; +} + + +////////////////////////////////////////////////////////////////////////// +bool CBSound::resume() { + if (_sound && _soundPaused) { + _soundPaused = false; + return _sound->resume(); + } else return STATUS_FAILED; +} + + +////////////////////////////////////////////////////////////////////////// +bool CBSound::persist(CBPersistMgr *persistMgr) { + if (persistMgr->_saving && _sound) { + _soundPlaying = _sound->isPlaying(); + _soundLooping = _sound->_looping; + _soundPrivateVolume = _sound->_privateVolume; + if (_soundPlaying) + _soundPosition = _sound->getPosition(); + _soundLoopStart = _sound->_loopStart; + _soundFreezePaused = _sound->_freezePaused; + } + + if (persistMgr->_saving) { + _sFXType = SFX_NONE; + _sFXParam1 = _sFXParam2 = _sFXParam3 = _sFXParam4 = 0; + } + + persistMgr->transfer(TMEMBER(_gameRef)); + + persistMgr->transfer(TMEMBER(_soundFilename)); + persistMgr->transfer(TMEMBER(_soundLooping)); + persistMgr->transfer(TMEMBER(_soundPaused)); + persistMgr->transfer(TMEMBER(_soundFreezePaused)); + persistMgr->transfer(TMEMBER(_soundPlaying)); + persistMgr->transfer(TMEMBER(_soundPosition)); + persistMgr->transfer(TMEMBER(_soundPrivateVolume)); + persistMgr->transfer(TMEMBER(_soundStreamed)); + persistMgr->transfer(TMEMBER_INT(_soundType)); + persistMgr->transfer(TMEMBER(_soundLoopStart)); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CBSound::isPlaying() { + return _sound && _sound->isPlaying(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CBSound::isPaused() { + return _sound && _soundPaused; +} + + +////////////////////////////////////////////////////////////////////////// +bool CBSound::setPositionTime(uint32 time) { + if (!_sound) return STATUS_FAILED; + _soundPosition = time; + bool ret = _sound->setPosition(_soundPosition); + if (_sound->isPlaying()) + _soundPosition = 0; + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +uint32 CBSound::getPositionTime() { + if (!_sound) return 0; + + if (!_sound->isPlaying()) + return 0; + else return _sound->getPosition(); +} + +////////////////////////////////////////////////////////////////////////// +bool CBSound::setVolumePercent(int percent) { + if (!_sound) + return STATUS_FAILED; + else return _sound->setPrivateVolume(percent * 255 / 100); +} + +////////////////////////////////////////////////////////////////////////// +bool CBSound::setVolume(int volume) { + if (!_sound) + return STATUS_FAILED; + else return _sound->setPrivateVolume(volume); +} + +////////////////////////////////////////////////////////////////////////// +bool CBSound::setPrivateVolume(int volume) { + if (!_sound) + return STATUS_FAILED; + else return _sound->_privateVolume = volume; +} + +////////////////////////////////////////////////////////////////////////// +int CBSound::getVolumePercent() { + if (!_sound) + return 0; + else return _sound->_privateVolume * 100 / 255; +} + +////////////////////////////////////////////////////////////////////////// +int CBSound::getVolume() { + if (!_sound) + return 0; + else return _sound->_privateVolume; +} + +////////////////////////////////////////////////////////////////////////// +bool CBSound::setLoopStart(uint32 pos) { + if (!_sound) + return STATUS_FAILED; + else { + _sound->setLoopStart(pos); + return STATUS_OK; + } +} + +////////////////////////////////////////////////////////////////////////// +bool CBSound::setPan(float pan) { + if (_sound) + return _sound->setPan(pan); + else return STATUS_FAILED; +} + + +////////////////////////////////////////////////////////////////////////// +bool CBSound::ApplyFX(TSFXType type, float param1, float param2, float param3, float param4) { + if (!_sound) + return STATUS_OK; + + if (type != _sFXType || param1 != _sFXParam1 || param2 != _sFXParam2 || param3 != _sFXParam3 || param4 != _sFXParam4) { + bool ret = _sound->applyFX(type, param1, param2, param3, param4); + + _sFXType = type; + _sFXParam1 = param1; + _sFXParam2 = param2; + _sFXParam3 = param3; + _sFXParam4 = param4; + + return ret; + } + return STATUS_OK; +} + +} // end of namespace WinterMute -- cgit v1.2.3