aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/hdb/sound.cpp36
-rw-r--r--engines/hdb/sound.h2
2 files changed, 21 insertions, 17 deletions
diff --git a/engines/hdb/sound.cpp b/engines/hdb/sound.cpp
index b2c3602509..2d260bf976 100644
--- a/engines/hdb/sound.cpp
+++ b/engines/hdb/sound.cpp
@@ -23,6 +23,7 @@
#include "common/debug.h"
#include "common/file.h"
#include "common/fs.h"
+#include "common/memstream.h"
#include "hdb/hdb.h"
#include "hdb/file-manager.h"
@@ -1493,10 +1494,12 @@ void Sound::playSound(int index) {
if (g_hdb->getPlatform() == Common::kPlatformLinux)
updatedName.replace(updatedName.begin() + updatedName.size() - 4, updatedName.end(), "_OGG");
- _soundCache[index].data = g_hdb->_fileMan->findFirstData(updatedName.c_str(), TYPE_BINARY);
+ Common::SeekableReadStream *stream = g_hdb->_fileMan->findFirstData(updatedName.c_str(), TYPE_BINARY, &_soundCache[index].size);
+
+ _soundCache[index].data = (byte *)malloc(_soundCache[index].size);
+ stream->read(_soundCache[index].data, _soundCache[index].size);
+
_soundCache[index].loaded = SNDMEM_LOADED;
- } else {
- _soundCache[index].data->seek(0);
}
int soundChannel = 0;
@@ -1519,17 +1522,18 @@ void Sound::playSound(int index) {
return;
Audio::SeekableAudioStream *audioStream = nullptr;
+ Common::MemoryReadStream *stream = new Common::MemoryReadStream(_soundCache[index].data, _soundCache[index].size, DisposeAfterUse::NO);
if (_soundCache[index].ext == SNDTYPE_MP3) {
#ifdef USE_MAD
- audioStream = Audio::makeMP3Stream(_soundCache[index].data, DisposeAfterUse::NO);
+ audioStream = Audio::makeMP3Stream(stream, DisposeAfterUse::YES);
#endif // USE_MAD
} else if (_soundCache[index].ext == SNDTYPE_OGG) {
#ifdef USE_VORBIS
- audioStream = Audio::makeVorbisStream(_soundCache[index].data, DisposeAfterUse::NO);
+ audioStream = Audio::makeVorbisStream(stream, DisposeAfterUse::YES);
#endif // USE_VORBIS
} else {
- audioStream = Audio::makeWAVStream(_soundCache[index].data, DisposeAfterUse::NO);
+ audioStream = Audio::makeWAVStream(stream, DisposeAfterUse::YES);
}
g_hdb->_mixer->playStream(
@@ -1558,17 +1562,16 @@ void Sound::playSoundEx(int index, int channel, bool loop) {
// is sound marked as cached?
if (_soundCache[index].loaded == SNDMEM_NOTCACHED) {
+ Common::String updatedName(_soundCache[index].name);
- if (g_hdb->getPlatform() == Common::kPlatformLinux) {
- Common::String updatedName(_soundCache[index].name);
+ if (g_hdb->getPlatform() == Common::kPlatformLinux)
updatedName.replace(updatedName.begin() + updatedName.size() - 4, updatedName.end(), "_OGG");
- _soundCache[index].data = g_hdb->_fileMan->findFirstData(updatedName.c_str(), TYPE_BINARY);
- } else
- _soundCache[index].data = g_hdb->_fileMan->findFirstData(_soundCache[index].name, TYPE_BINARY);
+ Common::SeekableReadStream *stream = g_hdb->_fileMan->findFirstData(updatedName.c_str(), TYPE_BINARY, &_soundCache[index].size);
+
+ _soundCache[index].data = (byte *)malloc(_soundCache[index].size);
+ stream->read(_soundCache[index].data, _soundCache[index].size);
_soundCache[index].loaded = SNDMEM_LOADED;
- } else {
- _soundCache[index].data->seek(0);
}
g_hdb->_mixer->setChannelVolume(_handles[channel], _sfxVolume);
@@ -1578,17 +1581,18 @@ void Sound::playSoundEx(int index, int channel, bool loop) {
return;
Audio::SeekableAudioStream *audioStream = nullptr;
+ Common::MemoryReadStream *stream = new Common::MemoryReadStream(_soundCache[index].data, _soundCache[index].size, DisposeAfterUse::NO);
if (_soundCache[index].ext == SNDTYPE_MP3) {
#ifdef USE_MAD
- audioStream = Audio::makeMP3Stream(_soundCache[index].data, DisposeAfterUse::NO);
+ audioStream = Audio::makeMP3Stream(stream, DisposeAfterUse::YES);
#endif // USE_MAD
} else if (_soundCache[index].ext == SNDTYPE_OGG) {
#ifdef USE_VORBIS
- audioStream = Audio::makeVorbisStream(_soundCache[index].data, DisposeAfterUse::NO);
+ audioStream = Audio::makeVorbisStream(stream, DisposeAfterUse::YES);
#endif // USE_VORBIS
} else {
- audioStream = Audio::makeWAVStream(_soundCache[index].data, DisposeAfterUse::NO);
+ audioStream = Audio::makeWAVStream(stream, DisposeAfterUse::YES);
}
if (loop) {
diff --git a/engines/hdb/sound.h b/engines/hdb/sound.h
index 6578faa83e..6797808a7d 100644
--- a/engines/hdb/sound.h
+++ b/engines/hdb/sound.h
@@ -1454,7 +1454,7 @@ struct SoundCache {
const char *name; // filename / MSD name
const char *luaName; // name used by Lua for i.d.
SndType ext; // 0 = Uninitialized, -1 = WAV, 1 = MP3
- Common::SeekableReadStream *data;
+ byte *data;
SoundCache() : loaded(SNDMEM_NOTCACHED), size(0), name(nullptr), luaName(nullptr), ext(SNDTYPE_NONE), data(nullptr) {}
};