aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute/base/sound
diff options
context:
space:
mode:
authorEinar Johan Trøan Sømåen2012-07-21 18:19:07 +0200
committerEinar Johan Trøan Sømåen2012-07-21 19:15:33 +0200
commit5683f076331d2831eb4720b65bb53e8d01ca33ee (patch)
tree4357d989476643db887d5f5a95f6fd165afd0514 /engines/wintermute/base/sound
parent0622b2c5b8260c0f0c01122d6fbc5e10013d1613 (diff)
downloadscummvm-rg350-5683f076331d2831eb4720b65bb53e8d01ca33ee.tar.gz
scummvm-rg350-5683f076331d2831eb4720b65bb53e8d01ca33ee.tar.bz2
scummvm-rg350-5683f076331d2831eb4720b65bb53e8d01ca33ee.zip
WINTERMUTE: Rename CamelCased filenames to prefixed_under_score-filenames
This is mostly a lead-up to namespacing the Ad/Base folders, and then possibly removing the prefixes from the files, it also has the added benefit of getting rid of the odd case-typos that makes for issues on platforms that don't ignore case.
Diffstat (limited to 'engines/wintermute/base/sound')
-rw-r--r--engines/wintermute/base/sound/base_sound.cpp288
-rw-r--r--engines/wintermute/base/sound/base_sound.h88
-rw-r--r--engines/wintermute/base/sound/base_sound_buffer.cpp383
-rw-r--r--engines/wintermute/base/sound/base_sound_buffer.h100
-rw-r--r--engines/wintermute/base/sound/base_sound_manager.cpp292
-rw-r--r--engines/wintermute/base/sound/base_sound_manager.h69
6 files changed, 1220 insertions, 0 deletions
diff --git a/engines/wintermute/base/sound/base_sound.cpp b/engines/wintermute/base/sound/base_sound.cpp
new file mode 100644
index 0000000000..e1819e3c65
--- /dev/null
+++ b/engines/wintermute/base/sound/base_sound.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/sound/base_sound.h"
+#include "engines/wintermute/base/base_game.h"
+#include "engines/wintermute/base/sound/base_sound_manager.h"
+#include "engines/wintermute/base/sound/base_sound_buffer.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
diff --git a/engines/wintermute/base/sound/base_sound.h b/engines/wintermute/base/sound/base_sound.h
new file mode 100644
index 0000000000..ef52194090
--- /dev/null
+++ b/engines/wintermute/base/sound/base_sound.h
@@ -0,0 +1,88 @@
+/* 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
+ */
+
+#ifndef WINTERMUTE_BSOUND_H
+#define WINTERMUTE_BSOUND_H
+
+#include "engines/wintermute/base/base.h"
+#include "engines/wintermute/dctypes.h" // Added by ClassView
+#include "engines/wintermute/persistent.h"
+#include "audio/mixer.h"
+
+namespace WinterMute {
+
+class CBSoundBuffer;
+class CBSound : public CBBase {
+public:
+ bool setPan(float pan);
+ int _soundPrivateVolume;
+ int getVolume();
+ int getVolumePercent();
+ bool setVolumePercent(int percent);
+ bool setVolume(int volume);
+ bool setPrivateVolume(int volume);
+ bool setLoopStart(uint32 pos);
+ uint32 getPositionTime();
+ bool setPositionTime(uint32 time);
+ bool _soundPaused;
+ bool _soundFreezePaused;
+ bool isPlaying();
+ bool isPaused();
+ bool _soundPlaying;
+ bool _soundLooping;
+ uint32 _soundLoopStart;
+ uint32 _soundPosition;
+ DECLARE_PERSISTENT(CBSound, CBBase)
+ bool resume();
+ bool pause(bool freezePaused = false);
+ bool stop();
+ bool play(bool looping = false);
+ uint32 getLength();
+ bool _soundStreamed;
+ Audio::Mixer::SoundType _soundType;
+ char *_soundFilename;
+ bool setSoundSimple();
+ bool setSound(const char *filename, Audio::Mixer::SoundType type = Audio::Mixer::kSFXSoundType, bool streamed = false);
+ CBSound(CBGame *inGame);
+ virtual ~CBSound();
+
+ bool ApplyFX(TSFXType type = SFX_NONE, float param1 = 0, float param2 = 0, float param3 = 0, float param4 = 0);
+
+private:
+ TSFXType _sFXType;
+ float _sFXParam1;
+ float _sFXParam2;
+ float _sFXParam3;
+ float _sFXParam4;
+ CBSoundBuffer *_sound;
+
+};
+
+} // end of namespace WinterMute
+
+#endif
diff --git a/engines/wintermute/base/sound/base_sound_buffer.cpp b/engines/wintermute/base/sound/base_sound_buffer.cpp
new file mode 100644
index 0000000000..a868f99823
--- /dev/null
+++ b/engines/wintermute/base/sound/base_sound_buffer.cpp
@@ -0,0 +1,383 @@
+/* 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/dcgf.h"
+#include "engines/wintermute/base/file/base_file.h"
+#include "engines/wintermute/base/base_game.h"
+#include "engines/wintermute/base/sound/base_sound_manager.h"
+#include "engines/wintermute/base/sound/base_sound_buffer.h"
+#include "engines/wintermute/base/base_file_manager.h"
+#include "engines/wintermute/utils/utils.h"
+#include "audio/audiostream.h"
+#include "audio/mixer.h"
+#include "audio/decoders/vorbis.h"
+#include "audio/decoders/wave.h"
+#include "audio/decoders/raw.h"
+#include "common/system.h"
+#include "common/substream.h"
+
+namespace WinterMute {
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+#define MAX_NONSTREAMED_FILE_SIZE 1024*1024
+
+//////////////////////////////////////////////////////////////////////////
+CBSoundBuffer::CBSoundBuffer(CBGame *inGame): CBBase(inGame) {
+ _stream = NULL;
+ _handle = NULL;
+// _sync = NULL;
+
+ _streamed = false;
+ _filename = NULL;
+ _file = NULL;
+ _privateVolume = 255;
+ _volume = 255;
+
+ _looping = false;
+ _loopStart = 0;
+
+ _type = Audio::Mixer::kSFXSoundType;
+
+ _freezePaused = false;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+CBSoundBuffer::~CBSoundBuffer() {
+ stop();
+
+ if (_handle) {
+ g_system->getMixer()->stopHandle(*_handle);
+ delete _handle;
+ _handle = NULL;
+ }
+ delete _stream;
+ _stream = NULL;
+
+ delete[] _filename;
+ _filename = NULL;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+void CBSoundBuffer::setStreaming(bool Streamed, uint32 NumBlocks, uint32 BlockSize) {
+ _streamed = Streamed;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundBuffer::loadFromFile(const char *filename, bool forceReload) {
+ warning("BSoundBuffer::LoadFromFile(%s,%d)", filename, forceReload);
+#if 0
+ if (_stream) {
+ BASS_StreamFree(_stream);
+ _stream = NULL;
+ }
+#endif
+
+ // Load a file, but avoid having the File-manager handle the disposal of it.
+ _file = _gameRef->_fileManager->openFile(filename, true, false);
+ if (!_file) {
+ _gameRef->LOG(0, "Error opening sound file '%s'", filename);
+ return STATUS_FAILED;
+ }
+ Common::String strFilename(filename);
+ if (strFilename.hasSuffix(".ogg")) {
+ _stream = Audio::makeVorbisStream(_file, DisposeAfterUse::YES);
+ } else if (strFilename.hasSuffix(".wav")) {
+ int waveSize, waveRate;
+ byte waveFlags;
+ uint16 waveType;
+
+ if (Audio::loadWAVFromStream(*_file, waveSize, waveRate, waveFlags, &waveType)) {
+ if (waveType == 1) {
+ // We need to wrap the file in a substream to make sure the size is right.
+ _file = new Common::SeekableSubReadStream(_file, 0, waveSize);
+ _stream = Audio::makeRawStream(_file, waveRate, waveFlags, DisposeAfterUse::YES);
+ } else {
+ warning("BSoundBuffer::LoadFromFile - WAVE not supported yet for %s with type %d", filename, waveType);
+ }
+ }
+ } else {
+ warning("BSoundBuffer::LoadFromFile - Unknown filetype for %s", filename);
+ }
+ if (!_stream) {
+ return STATUS_FAILED;
+ }
+ CBUtils::setString(&_filename, filename);
+
+ return STATUS_OK;
+#if 0
+ BASS_FILEPROCS fileProc;
+ fileProc.close = CBSoundBuffer::FileCloseProc;
+ fileProc.read = CBSoundBuffer::FileReadProc;
+ fileProc.seek = CBSoundBuffer::FileSeekProc;
+ fileProc.length = CBSoundBuffer::FileLenProc;
+
+ _stream = BASS_StreamCreateFileUser(STREAMFILE_NOBUFFER, 0, &fileProc, (void *)_file);
+ if (!_stream) {
+ _gameRef->LOG(0, "BASS error: %d while loading '%s'", BASS_ErrorGetCode(), filename);
+ return STATUS_FAILED;
+ }
+
+ CBUtils::setString(&_filename, filename);
+
+ /*
+ bool res;
+ bool NewlyCreated = false;
+
+ if(!_soundBuffer || ForceReload || _streamed){
+ if(!_file) _file = _gameRef->_fileManager->openFile(filename);
+ if(!_file){
+ _gameRef->LOG(0, "Error opening sound file '%s'", filename);
+ return STATUS_FAILED;
+ }
+ // switch to streamed for big files
+ if(!_streamed && (_file->GetSize() > MAX_NONSTREAMED_FILE_SIZE && !_gameRef->_forceNonStreamedSounds)) SetStreaming(true);
+ }
+
+ // create buffer
+ if(!_soundBuffer){
+ NewlyCreated = true;
+
+ res = InitializeBuffer(_file);
+ if(DID_FAIL(res)){
+ _gameRef->LOG(res, "Error creating sound buffer for file '%s'", filename);
+ return res;
+ }
+ }
+
+
+
+ // store filename
+ if(!_filename){
+ _filename = new char[strlen(filename)+1];
+ strcpy(_filename, filename);
+ }
+
+ // close file (if not streaming)
+ if(!_streamed && _file){
+ _gameRef->_fileManager->closeFile(_file);
+ _file = NULL;
+ }
+ */
+
+ return STATUS_OK;
+#endif
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundBuffer::play(bool looping, uint32 startSample) {
+ if (startSample != 0) {
+ warning("BSoundBuffer::Play - Should start playback at %d, but currently we don't", startSample);
+ }
+ if (_handle) {
+ g_system->getMixer()->stopHandle(*_handle);
+ delete _handle;
+ _handle = NULL;
+ }
+ if (_stream) {
+ _stream->seek(startSample);
+ _handle = new Audio::SoundHandle;
+ if (looping) {
+ Audio::AudioStream *loopStream = new Audio::LoopingAudioStream(_stream, 0, DisposeAfterUse::NO);
+ g_system->getMixer()->playStream(_type, _handle, loopStream, -1, _volume, 0, DisposeAfterUse::YES);
+ } else {
+ g_system->getMixer()->playStream(_type, _handle, _stream, -1, _volume, 0, DisposeAfterUse::NO);
+ }
+ }
+
+ return STATUS_OK;
+}
+
+//////////////////////////////////////////////////////////////////////////
+void CBSoundBuffer::setLooping(bool looping) {
+ warning("BSoundBuffer::SetLooping(%d) - won't change a playing sound", looping);
+ _looping = looping;
+#if 0
+
+
+ if (_stream) {
+ BASS_ChannelFlags(_stream, looping ? BASS_SAMPLE_LOOP : 0, BASS_SAMPLE_LOOP);
+ }
+#endif
+}
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundBuffer::resume() {
+ if (_stream && _handle) {
+ g_system->getMixer()->pauseHandle(*_handle, false);
+ }
+ return STATUS_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundBuffer::stop() {
+ if (_stream && _handle) {
+ g_system->getMixer()->stopHandle(*_handle);
+ }
+ return STATUS_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundBuffer::pause() {
+ if (_stream && _handle) {
+ g_system->getMixer()->pauseHandle(*_handle, true);
+ }
+ return STATUS_OK;
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+uint32 CBSoundBuffer::getLength() {
+ if (_stream) {
+ uint32 len = _stream->getLength().msecs();
+ return len * 1000;
+ }
+ return 0;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+void CBSoundBuffer::setType(Audio::Mixer::SoundType type) {
+ _type = type;
+}
+
+//////////////////////////////////////////////////////////////////////////
+void CBSoundBuffer::updateVolume() {
+ setVolume(_privateVolume);
+}
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundBuffer::setVolume(int volume) {
+ _volume = volume * _gameRef->_soundMgr->getMasterVolume() / 255;
+ if (_stream && _handle) {
+ byte vol = (byte)(_volume);
+ g_system->getMixer()->setChannelVolume(*_handle, vol);
+ }
+ return STATUS_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundBuffer::setPrivateVolume(int volume) {
+ _privateVolume = volume;
+ return setVolume(_privateVolume);
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundBuffer::isPlaying() {
+ if (_stream && _handle) {
+ return _freezePaused || g_system->getMixer()->isSoundHandleActive(*_handle);
+ } else {
+ return false;
+ }
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+uint32 CBSoundBuffer::getPosition() {
+ if (_stream && _handle) {
+ uint32 pos = g_system->getMixer()->getSoundElapsedTime(*_handle);
+ return pos;
+ }
+ return 0;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundBuffer::setPosition(uint32 pos) {
+ warning("CBSoundBuffer::SetPosition - not implemented yet");
+#if 0
+ if (_stream) {
+ QWORD pos = BASS_ChannelSeconds2Bytes(_stream, (float)Pos / 1000.0f);
+ BASS_ChannelSetPosition(_stream, pos, BASS_POS_BYTE);
+ }
+#endif
+ return STATUS_OK;
+}
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundBuffer::setLoopStart(uint32 pos) {
+ _loopStart = pos;
+#if 0
+ if (_stream) {
+ if (_sync) {
+ BASS_ChannelRemoveSync(_stream, _sync);
+ _sync = NULL;
+ }
+ if (_loopStart > 0) {
+ QWORD len = BASS_ChannelGetLength(_stream, BASS_POS_BYTE);
+ _sync = BASS_ChannelSetSync(_stream, BASS_SYNC_POS | BASS_SYNC_MIXTIME, len, CBSoundBuffer::LoopSyncProc, (void *)this);
+ }
+ }
+#endif
+ return STATUS_OK;
+}
+#if 0
+//////////////////////////////////////////////////////////////////////////
+void CBSoundBuffer::LoopSyncProc(HSYNC handle, uint32 channel, uint32 data, void *user) {
+ CBSoundBuffer *soundBuf = static_cast<CBSoundBuffer *>(user);
+ QWORD pos = BASS_ChannelSeconds2Bytes(channel, (float)soundBuf->GetLoopStart() / 1000.0f);
+
+ if (!BASS_ChannelSetPosition(channel, pos, BASS_POS_BYTE))
+ BASS_ChannelSetPosition(channel, 0, BASS_POS_BYTE);
+}
+#endif
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundBuffer::setPan(float pan) {
+ if (_handle) {
+ g_system->getMixer()->setChannelBalance(*_handle, (int8)(pan * 127));
+ }
+ return STATUS_OK;
+}
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundBuffer::applyFX(TSFXType type, float param1, float param2, float param3, float param4) {
+ warning("CBSoundBuffer::ApplyFX - not implemented yet");
+ switch (type) {
+ case SFX_ECHO:
+ break;
+
+ case SFX_REVERB:
+ break;
+
+ default:
+ break;
+ }
+ return STATUS_OK;
+}
+
+} // end of namespace WinterMute
diff --git a/engines/wintermute/base/sound/base_sound_buffer.h b/engines/wintermute/base/sound/base_sound_buffer.h
new file mode 100644
index 0000000000..a491bd49ad
--- /dev/null
+++ b/engines/wintermute/base/sound/base_sound_buffer.h
@@ -0,0 +1,100 @@
+/* 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
+ */
+
+#ifndef WINTERMUTE_BSOUNDBUFFER_H
+#define WINTERMUTE_BSOUNDBUFFER_H
+
+
+#include "engines/wintermute/base/base.h"
+#include "audio/mixer.h"
+#include "common/stream.h"
+
+namespace Audio {
+class SeekableAudioStream;
+class SoundHandle;
+}
+
+namespace WinterMute {
+
+class CBFile;
+class CBSoundBuffer : public CBBase {
+public:
+
+ CBSoundBuffer(CBGame *inGame);
+ virtual ~CBSoundBuffer();
+
+
+ bool pause();
+ bool play(bool looping = false, uint32 startSample = 0);
+ bool resume();
+ bool stop();
+ bool isPlaying();
+
+ void setLooping(bool looping);
+
+ uint32 getPosition();
+ bool setPosition(uint32 pos);
+ uint32 getLength();
+
+ bool setLoopStart(uint32 pos);
+ uint32 getLoopStart() const {
+ return _loopStart;
+ }
+
+ bool setPan(float pan);
+ bool setPrivateVolume(int colume);
+ bool setVolume(int colume);
+ void updateVolume();
+
+ void setType(Audio::Mixer::SoundType Type);
+
+ bool loadFromFile(const char *filename, bool forceReload = false);
+ void setStreaming(bool streamed, uint32 numBlocks = 0, uint32 blockSize = 0);
+ bool applyFX(TSFXType type, float param1, float param2, float param3, float param4);
+
+ //HSTREAM _stream;
+ //HSYNC _sync;
+ Audio::SeekableAudioStream *_stream;
+ Audio::SoundHandle *_handle;
+
+ bool _freezePaused;
+ uint32 _loopStart;
+ Audio::Mixer::SoundType _type;
+ bool _looping;
+ Common::SeekableReadStream *_file;
+ char *_filename;
+ bool _streamed;
+
+ int _privateVolume;
+private:
+ int _volume;
+};
+
+} // end of namespace WinterMute
+
+#endif
diff --git a/engines/wintermute/base/sound/base_sound_manager.cpp b/engines/wintermute/base/sound/base_sound_manager.cpp
new file mode 100644
index 0000000000..c2174dea6a
--- /dev/null
+++ b/engines/wintermute/base/sound/base_sound_manager.cpp
@@ -0,0 +1,292 @@
+/* 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/dcgf.h"
+#include "engines/wintermute/base/sound/base_sound_manager.h"
+#include "engines/wintermute/base/base_registry.h"
+#include "engines/wintermute/utils/path_util.h"
+#include "engines/wintermute/utils/string_util.h"
+#include "engines/wintermute/base/base_game.h"
+#include "engines/wintermute/base/base_file_manager.h"
+#include "engines/wintermute/base/sound/base_sound_buffer.h"
+#include "engines/wintermute/wintermute.h"
+#include "common/config-manager.h"
+#include "audio/mixer.h"
+
+namespace WinterMute {
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+//IMPLEMENT_PERSISTENT(CBSoundMgr, true);
+
+//////////////////////////////////////////////////////////////////////////
+CBSoundMgr::CBSoundMgr(CBGame *inGame): CBBase(inGame) {
+ _soundAvailable = false;
+ _volumeMaster = 255;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+CBSoundMgr::~CBSoundMgr() {
+ saveSettings();
+ cleanup();
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundMgr::cleanup() {
+ for (uint32 i = 0; i < _sounds.size(); i++)
+ delete _sounds[i];
+ _sounds.clear();
+#if 0
+ BASS_Free();
+#endif
+ return STATUS_OK;
+}
+
+//////////////////////////////////////////////////////////////////////////
+void CBSoundMgr::saveSettings() {
+ if (_soundAvailable) {
+ _gameRef->_registry->writeInt("Audio", "MasterVolume", _volumeMaster);
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundMgr::initialize() {
+ _soundAvailable = false;
+
+ if (!g_system->getMixer()->isReady()) {
+ return STATUS_FAILED;
+ }
+ _volumeMaster = _gameRef->_registry->readInt("Audio", "MasterVolume", 255);
+ _soundAvailable = true;
+
+ return STATUS_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundMgr::initLoop() {
+ if (!_soundAvailable)
+ return STATUS_OK;
+#if 0
+
+ BASS_Update(500);
+#endif
+ return STATUS_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+CBSoundBuffer *CBSoundMgr::addSound(const char *filename, Audio::Mixer::SoundType type, bool streamed) {
+ if (!_soundAvailable)
+ return NULL;
+
+ CBSoundBuffer *sound;
+
+ // try to switch WAV to OGG file (if available)
+ AnsiString ext = PathUtil::getExtension(filename);
+ if (StringUtil::compareNoCase(ext, "wav")) {
+ AnsiString path = PathUtil::getDirectoryName(filename);
+ AnsiString name = PathUtil::getFileNameWithoutExtension(filename);
+
+ AnsiString newFile = PathUtil::combine(path, name + "ogg");
+ if (_gameRef->_fileManager->hasFile(newFile)) {
+ filename = newFile.c_str();
+ }
+ }
+
+ sound = new CBSoundBuffer(_gameRef);
+ if (!sound) return NULL;
+
+ sound->setStreaming(streamed);
+ sound->setType(type);
+
+
+ bool res = sound->loadFromFile(filename);
+ if (DID_FAIL(res)) {
+ _gameRef->LOG(res, "Error loading sound '%s'", filename);
+ delete sound;
+ return NULL;
+ }
+
+ // Make sure the master-volume is applied to the sound.
+ sound->updateVolume();
+
+ // register sound
+ _sounds.push_back(sound);
+
+ return sound;
+
+ return NULL;
+}
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundMgr::addSound(CBSoundBuffer *sound, Audio::Mixer::SoundType type) {
+ if (!sound)
+ return STATUS_FAILED;
+
+ // Make sure the master-volume is applied to the sound.
+ sound->updateVolume();
+
+ // register sound
+ _sounds.push_back(sound);
+
+ return STATUS_OK;
+}
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundMgr::removeSound(CBSoundBuffer *sound) {
+ for (uint32 i = 0; i < _sounds.size(); i++) {
+ if (_sounds[i] == sound) {
+ delete _sounds[i];
+ _sounds.remove_at(i);
+ return STATUS_OK;
+ }
+ }
+
+ return STATUS_FAILED;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundMgr::setVolume(Audio::Mixer::SoundType type, int volume) {
+ if (!_soundAvailable)
+ return STATUS_OK;
+
+ switch (type) {
+ case Audio::Mixer::kSFXSoundType:
+ ConfMan.setInt("sfx_volume", volume);
+ break;
+ case Audio::Mixer::kSpeechSoundType:
+ ConfMan.setInt("speech_volume", volume);
+ break;
+ case Audio::Mixer::kMusicSoundType:
+ ConfMan.setInt("music_volume", volume);
+ break;
+ case Audio::Mixer::kPlainSoundType:
+ error("Plain sound type shouldn't be used in WME");
+ }
+ g_wintermute->syncSoundSettings();
+
+ return STATUS_OK;
+}
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundMgr::setVolumePercent(Audio::Mixer::SoundType type, byte percent) {
+ return setVolume(type, percent * 255 / 100);
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+byte CBSoundMgr::getVolumePercent(Audio::Mixer::SoundType type) {
+ int volume = 0;
+
+ switch (type) {
+ case Audio::Mixer::kSFXSoundType:
+ case Audio::Mixer::kSpeechSoundType:
+ case Audio::Mixer::kMusicSoundType:
+ volume = g_system->getMixer()->getVolumeForSoundType(type);
+ break;
+ default:
+ error("Sound-type not set");
+ break;
+ }
+
+ return (byte)(volume * 100 / 255);
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundMgr::setMasterVolume(byte value) {
+ _volumeMaster = value;
+ for (uint32 i = 0; i < _sounds.size(); i++) {
+ _sounds[i]->updateVolume();
+ }
+ return STATUS_OK;
+}
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundMgr::setMasterVolumePercent(byte percent) {
+ setMasterVolume(percent * 255 / 100);
+ return STATUS_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+byte CBSoundMgr::getMasterVolumePercent() {
+ return getMasterVolume() * 100 / 255;
+}
+
+//////////////////////////////////////////////////////////////////////////
+byte CBSoundMgr::getMasterVolume() {
+ return (byte)_volumeMaster;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundMgr::pauseAll(bool includingMusic) {
+
+ for (uint32 i = 0; i < _sounds.size(); i++) {
+ if (_sounds[i]->isPlaying() && (_sounds[i]->_type != Audio::Mixer::kMusicSoundType || includingMusic)) {
+ _sounds[i]->pause();
+ _sounds[i]->_freezePaused = true;
+ }
+ }
+
+ return STATUS_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool CBSoundMgr::resumeAll() {
+
+ for (uint32 i = 0; i < _sounds.size(); i++) {
+ if (_sounds[i]->_freezePaused) {
+ _sounds[i]->resume();
+ _sounds[i]->_freezePaused = false;
+ }
+ }
+
+ return STATUS_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+float CBSoundMgr::posToPan(int x, int y) {
+ float relPos = (float)x / ((float)_gameRef->_renderer->_width);
+
+ float minPan = -0.7f;
+ float maxPan = 0.7f;
+
+ return minPan + relPos * (maxPan - minPan);
+}
+
+} // end of namespace WinterMute
diff --git a/engines/wintermute/base/sound/base_sound_manager.h b/engines/wintermute/base/sound/base_sound_manager.h
new file mode 100644
index 0000000000..2c05bbfcb8
--- /dev/null
+++ b/engines/wintermute/base/sound/base_sound_manager.h
@@ -0,0 +1,69 @@
+/* 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
+ */
+
+#ifndef WINTERMUTE_BSOUNDMGR_H
+#define WINTERMUTE_BSOUNDMGR_H
+
+#include "engines/wintermute/coll_templ.h"
+#include "engines/wintermute/base/base.h"
+#include "audio/mixer.h"
+#include "common/array.h"
+
+namespace WinterMute {
+class CBSoundBuffer;
+class CBSoundMgr : public CBBase {
+public:
+ float posToPan(int x, int y);
+ bool resumeAll();
+ bool pauseAll(bool includingMusic = true);
+ bool cleanup();
+ //DECLARE_PERSISTENT(CBSoundMgr, CBBase);
+ byte getMasterVolumePercent();
+ byte getMasterVolume();
+ bool setMasterVolume(byte percent);
+ bool setMasterVolumePercent(byte percent);
+ byte getVolumePercent(Audio::Mixer::SoundType type);
+ bool setVolumePercent(Audio::Mixer::SoundType type, byte percent);
+ bool setVolume(Audio::Mixer::SoundType type, int volume);
+ uint32 _volumeOriginal;
+ int _volumeMaster;
+ bool removeSound(CBSoundBuffer *sound);
+ CBSoundBuffer *addSound(const char *filename, Audio::Mixer::SoundType type = Audio::Mixer::kSFXSoundType, bool streamed = false);
+ bool addSound(CBSoundBuffer *sound, Audio::Mixer::SoundType type = Audio::Mixer::kSFXSoundType);
+ bool initLoop();
+ bool initialize();
+ bool _soundAvailable;
+ CBSoundMgr(CBGame *inGame);
+ virtual ~CBSoundMgr();
+ Common::Array<CBSoundBuffer *> _sounds;
+ void saveSettings();
+};
+
+} // end of namespace WinterMute
+
+#endif