aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/sfx
diff options
context:
space:
mode:
authorEugene Sandulenko2011-06-28 22:55:14 +0300
committerEugene Sandulenko2011-06-29 17:16:25 +0300
commit15a16e556ca03b51b1fc03f135834bf57f592b52 (patch)
tree33b1fab3325c2ed4b7cc55e559526a2d08b9672a /engines/sword25/sfx
parentc32a3ea0d30336771bab460ecccb58c4614e6294 (diff)
downloadscummvm-rg350-15a16e556ca03b51b1fc03f135834bf57f592b52.tar.gz
scummvm-rg350-15a16e556ca03b51b1fc03f135834bf57f592b52.tar.bz2
scummvm-rg350-15a16e556ca03b51b1fc03f135834bf57f592b52.zip
SWORD25: Implement persistence functions for soundengine
Now sound is properly saved/restored. Implemented savegame versioning. Compatibility with old saves pertained.
Diffstat (limited to 'engines/sword25/sfx')
-rw-r--r--engines/sword25/sfx/soundengine.cpp75
-rw-r--r--engines/sword25/sfx/soundengine.h11
2 files changed, 77 insertions, 9 deletions
diff --git a/engines/sword25/sfx/soundengine.cpp b/engines/sword25/sfx/soundengine.cpp
index 7c8a6593aa..1b424dac65 100644
--- a/engines/sword25/sfx/soundengine.cpp
+++ b/engines/sword25/sfx/soundengine.cpp
@@ -33,6 +33,8 @@
#include "sword25/sfx/soundengine.h"
#include "sword25/package/packagemanager.h"
#include "sword25/kernel/resource.h"
+#include "sword25/kernel/inputpersistenceblock.h"
+#include "sword25/kernel/outputpersistenceblock.h"
#include "audio/decoders/vorbis.h"
@@ -202,17 +204,29 @@ bool SoundEngine::playSound(const Common::String &fileName, SOUND_TYPES type, fl
return true;
}
-uint SoundEngine::playSoundEx(const Common::String &fileName, SOUND_TYPES type, float volume, float pan, bool loop, int loopStart, int loopEnd, uint layer) {
+uint SoundEngine::playSoundEx(const Common::String &fileName, SOUND_TYPES type, float volume, float pan, bool loop, int loopStart, int loopEnd, uint layer, uint handleId) {
Common::SeekableReadStream *in = Kernel::getInstance()->getPackage()->getStream(fileName);
#ifdef USE_VORBIS
Audio::SeekableAudioStream *stream = Audio::makeVorbisStream(in, DisposeAfterUse::YES);
#endif
uint id;
- SndHandle *handle = getHandle(&id);
+ SndHandle *handle;
- debugC(1, kDebugSound, "SoundEngine::playSoundEx(%s, %d, %f, %f, %d, %d, %d, %d)", fileName.c_str(), type, volume, pan, loop, loopStart, loopEnd, layer);
+ if (handleId == 0x1337)
+ handle = getHandle(&id);
+ else
+ handle = &_handles[handleId];
- handle->type = kAllocatedHandle;
+ handle->fileName = fileName;
+ handle->sndType = type;
+ handle->volume = volume;
+ handle->pan = pan;
+ handle->loop = loop;
+ handle->loopStart = loopStart;
+ handle->loopEnd = loopEnd;
+ handle->layer = layer;
+
+ debugC(1, kDebugSound, "SoundEngine::playSoundEx(%s, %d, %f, %f, %d, %d, %d, %d)", fileName.c_str(), type, volume, pan, loop, loopStart, loopEnd, layer);
#ifdef USE_VORBIS
_mixer->playStream(getType(type), &(handle->handle), stream, -1, (byte)(volume * 255), (int8)(pan * 127));
@@ -311,16 +325,61 @@ bool SoundEngine::canLoadResource(const Common::String &fileName) {
}
-bool SoundEngine::persist(OutputPersistenceBlock &writer) {
- warning("STUB: SoundEngine::persist()");
+ bool SoundEngine::persist(OutputPersistenceBlock &writer) {
+ writer.write(_maxHandleId);
+
+ for (uint i = 0; i < SOUND_HANDLES; i++) {
+ writer.write(_handles[i].id);
+
+ writer.writeString(_handles[i].fileName);
+ writer.write((int)_handles[i].sndType);
+ writer.write(_handles[i].volume);
+ writer.write(_handles[i].pan);
+ writer.write(_handles[i].loop);
+ writer.write(_handles[i].loopStart);
+ writer.write(_handles[i].loopEnd);
+ writer.write(_handles[i].layer);
+ }
return true;
}
bool SoundEngine::unpersist(InputPersistenceBlock &reader) {
- warning("STUB: SoundEngine::unpersist()");
+ _mixer->stopAll();
- return true;
+ if (reader.getVersion() < 2)
+ return true;
+
+ reader.read(_maxHandleId);
+
+ for (uint i = 0; i < SOUND_HANDLES; i++) {
+ reader.read(_handles[i].id);
+
+ Common::String fileName;
+ int sndType;
+ float volume;
+ float pan;
+ bool loop;
+ int loopStart;
+ int loopEnd;
+ uint layer;
+
+ reader.readString(fileName);
+ reader.read(sndType);
+ reader.read(volume);
+ reader.read(pan);
+ reader.read(loop);
+ reader.read(loopStart);
+ reader.read(loopEnd);
+ reader.read(layer);
+
+ if (reader.isGood()) {
+ playSoundEx(fileName, (SOUND_TYPES)sndType, volume, pan, loop, loopStart, loopEnd, layer, i);
+ } else
+ return false;
+ }
+
+ return reader.isGood();
}
diff --git a/engines/sword25/sfx/soundengine.h b/engines/sword25/sfx/soundengine.h
index 71f1602484..8132ec556e 100644
--- a/engines/sword25/sfx/soundengine.h
+++ b/engines/sword25/sfx/soundengine.h
@@ -65,6 +65,15 @@ struct SndHandle {
Audio::SoundHandle handle;
sndHandleType type;
uint32 id;
+
+ Common::String fileName;
+ int sndType;
+ float volume;
+ float pan;
+ bool loop;
+ int loopStart;
+ int loopEnd;
+ uint layer;
};
@@ -176,7 +185,7 @@ public:
* @remark If more control is needed over the playing, eg. changing the sound parameters
* for Volume and Panning, then PlaySoundEx should be used.
*/
- uint playSoundEx(const Common::String &fileName, SOUND_TYPES type, float volume = 1.0f, float pan = 0.0f, bool loop = false, int loopStart = -1, int loopEnd = -1, uint layer = 0);
+ uint playSoundEx(const Common::String &fileName, SOUND_TYPES type, float volume = 1.0f, float pan = 0.0f, bool loop = false, int loopStart = -1, int loopEnd = -1, uint layer = 0, uint handleId = 0x1337);
/**
* Sets the volume of a playing sound