mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-13 07:14:59 +00:00
HDB: Cache sounds as data pointers. This fixes problem with distorted sounds
This commit is contained in:
parent
9907ebed0a
commit
d1ef6fc008
@ -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) {
|
||||
|
@ -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) {}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user