diff options
-rw-r--r-- | engines/kyra/kyra_v3.cpp | 23 | ||||
-rw-r--r-- | engines/kyra/resource.cpp | 10 | ||||
-rw-r--r-- | engines/kyra/sound.h | 4 | ||||
-rw-r--r-- | engines/kyra/sound_digital.cpp | 36 |
4 files changed, 30 insertions, 43 deletions
diff --git a/engines/kyra/kyra_v3.cpp b/engines/kyra/kyra_v3.cpp index 971f96c7ff..666de9f478 100644 --- a/engines/kyra/kyra_v3.cpp +++ b/engines/kyra/kyra_v3.cpp @@ -244,13 +244,9 @@ void KyraEngine_v3::playMenuAudioFile() { if (_soundDigital->isPlaying(_musicSoundChannel)) return; - /*Common::File *handle = new Common::File(); - uint32 temp = 0; - _res->getFileHandle(_menuAudioFile, &temp, *handle); - if (handle->isOpen()) - _musicSoundChannel = _soundDigital->playSound(handle, true); - else - delete handle;*/ + Common::SeekableReadStream *stream = _res->getFileStream(_menuAudioFile); + if (stream) + _musicSoundChannel = _soundDigital->playSound(stream, true); } void KyraEngine_v3::playMusicTrack(int track, int force) { @@ -271,22 +267,17 @@ void KyraEngine_v3::playMusicTrack(int track, int force) { if (_musicSoundChannel == -1) { assert(track < _soundListSize && track >= 0); - /*Common::File *handle = new Common::File(); - uint32 temp = 0; - _res->getFileHandle(_soundList[track], &temp, *handle); - if (handle->isOpen()) - _musicSoundChannel = _soundDigital->playSound(handle); - else - delete handle;*/ + Common::SeekableReadStream *stream = _res->getFileStream(_soundList[track]); + if (stream) + _musicSoundChannel = _soundDigital->playSound(stream); } _musicSoundChannel = track; } void KyraEngine_v3::stopMusicTrack() { - if (_musicSoundChannel != -1 && _soundDigital->isPlaying(_musicSoundChannel)) { + if (_musicSoundChannel != -1 && _soundDigital->isPlaying(_musicSoundChannel)) _soundDigital->stopSound(_musicSoundChannel); - } _curMusicTrack = -1; _musicSoundChannel = -1; diff --git a/engines/kyra/resource.cpp b/engines/kyra/resource.cpp index 52ab363608..02cc114105 100644 --- a/engines/kyra/resource.cpp +++ b/engines/kyra/resource.cpp @@ -460,10 +460,8 @@ bool ResLoaderPak::loadFile(const Common::String &filename, Common::SeekableRead Common::List<ResFileEntry>::iterator entry = entries.begin(); Common::List<Common::String>::iterator file = filenames.begin(); - for (; entry != entries.end(); ++entry, ++file) { - map.erase(*file); + for (; entry != entries.end(); ++entry, ++file) map[*file] = *entry; - } return true; } @@ -496,10 +494,10 @@ bool ResLoaderIns::isLoadable(const Common::String &filename, Common::SeekableRe stream.seek(3); uint32 size = stream.readUint32LE(); - if (size > stream.size()) + if (size+7 > stream.size()) return false; - stream.seek(size+1, SEEK_SET); + stream.seek(size+5, SEEK_SET); uint8 buffer[2]; stream.read(&buffer, 2); @@ -536,8 +534,6 @@ bool ResLoaderIns::loadFile(const Common::String &filename, Common::SeekableRead stream.seek(3, SEEK_SET); for (Common::List<Common::String>::iterator file = filenames.begin(); file != filenames.end(); ++file) { - map.erase(*file); - ResFileEntry entry; entry.parent = filename; entry.type = ResFileEntry::kAutoDetect; diff --git a/engines/kyra/sound.h b/engines/kyra/sound.h index ea1eb738b3..426d7b6896 100644 --- a/engines/kyra/sound.h +++ b/engines/kyra/sound.h @@ -476,7 +476,7 @@ public: /** * Plays a sound. * - * @param fileHandle file handle used for playback. + * @param stream Data stream used for playback * It will be deleted when playback is finished * @param loop true if the sound should loop (endlessly) * @param fadeIn true if the sound should be faded in volume wise @@ -484,7 +484,7 @@ public: * * @return channel playing the sound */ - int playSound(Common::File *fileHandle, bool loop = false, bool fadeIn = false, int channel = -1); + int playSound(Common::SeekableReadStream *stream, bool loop = false, bool fadeIn = false, int channel = -1); /** * Checks if a given channel is playing a sound. diff --git a/engines/kyra/sound_digital.cpp b/engines/kyra/sound_digital.cpp index 89ebe50d02..0f59e0664d 100644 --- a/engines/kyra/sound_digital.cpp +++ b/engines/kyra/sound_digital.cpp @@ -36,7 +36,7 @@ namespace Kyra { class AUDStream : public Audio::AudioStream { public: - AUDStream(Common::File *file, bool loop = false); + AUDStream(Common::SeekableReadStream *stream, bool loop = false); ~AUDStream(); int readBuffer(int16 *buffer, const int numSamples); @@ -49,7 +49,7 @@ public: void beginFadeIn(); void beginFadeOut(); private: - Common::File *_file; + Common::SeekableReadStream *_stream; bool _loop; uint32 _loopStart; bool _endOfData; @@ -82,12 +82,12 @@ const int8 AUDStream::WSTable4Bit[] = { 0, 1, 2, 3, 4, 5, 6, 8 }; -AUDStream::AUDStream(Common::File *file, bool loop) : _file(file), _endOfData(true), _rate(0), +AUDStream::AUDStream(Common::SeekableReadStream *stream, bool loop) : _stream(stream), _endOfData(true), _rate(0), _processedSize(0), _totalSize(0), _bytesLeft(0), _outBuffer(0), _outBufferOffset(0), _outBufferSize(0), _inBuffer(0), _inBufferSize(0) { - _rate = _file->readUint16LE(); - _totalSize = _file->readUint32LE(); + _rate = _stream->readUint16LE(); + _totalSize = _stream->readUint32LE(); _loop = loop; // TODO: Find the correct number of samples for a fade-in/out. Should @@ -97,10 +97,10 @@ AUDStream::AUDStream(Common::File *file, bool loop) : _file(file), _endOfData(tr _fading = 0; // TODO?: add checks - int flags = _file->readByte(); // flags - int type = _file->readByte(); // type + int flags = _stream->readByte(); // flags + int type = _stream->readByte(); // type - _loopStart = file->pos(); + _loopStart = stream->pos(); if (type == 1 && !flags) { _endOfData = false; @@ -111,7 +111,7 @@ AUDStream::AUDStream(Common::File *file, bool loop) : _file(file), _endOfData(tr AUDStream::~AUDStream() { delete [] _outBuffer; delete [] _inBuffer; - delete _file; + delete _stream; } void AUDStream::beginFadeIn() { @@ -154,7 +154,7 @@ int AUDStream::readChunk(int16 *buffer, const int maxSamples) { if (_bytesLeft <= 0) { if (_processedSize >= _totalSize) { if (_loop) { - _file->seek(_loopStart); + _stream->seek(_loopStart); _processedSize = 0; } else { _endOfData = true; @@ -162,9 +162,9 @@ int AUDStream::readChunk(int16 *buffer, const int maxSamples) { } } - uint16 size = _file->readUint16LE(); - uint16 outSize = _file->readUint16LE(); - uint32 id = _file->readUint32LE(); + uint16 size = _stream->readUint16LE(); + uint16 outSize = _stream->readUint16LE(); + uint32 id = _stream->readUint32LE(); assert(id == 0x0000DEAF); @@ -181,7 +181,7 @@ int AUDStream::readChunk(int16 *buffer, const int maxSamples) { _bytesLeft = size; - _file->read(_outBuffer, _bytesLeft); + _stream->read(_outBuffer, _bytesLeft); } else { _bytesLeft = outSize; @@ -199,7 +199,7 @@ int AUDStream::readChunk(int16 *buffer, const int maxSamples) { assert(_inBuffer); } - if (_file->read(_inBuffer, size) != size) { + if (_stream->read(_inBuffer, size) != size) { _endOfData = true; return 0; } @@ -328,7 +328,7 @@ SoundDigital::~SoundDigital() { stopSound(i); } -int SoundDigital::playSound(Common::File *fileHandle, bool loop, bool fadeIn, int channel) { +int SoundDigital::playSound(Common::SeekableReadStream *stream, bool loop, bool fadeIn, int channel) { Sound *use = 0; if (channel != -1 && channel < SOUND_STREAMS) { stopSound(channel); @@ -343,12 +343,12 @@ int SoundDigital::playSound(Common::File *fileHandle, bool loop, bool fadeIn, in if (!use) { warning("no free sound channel"); - delete fileHandle; + delete stream; return -1; } } - use->stream = new AUDStream(fileHandle, loop); + use->stream = new AUDStream(stream, loop); if (use->stream->endOfData()) { delete use->stream; use->stream = 0; |