diff options
author | Torbjörn Andersson | 2009-02-20 22:43:13 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2009-02-20 22:43:13 +0000 |
commit | 478257f624cf665b315192ebab48732c54bbcc4b (patch) | |
tree | c4520a346599c6df679d18487938ac23a48dddc7 /engines | |
parent | dbb81ab516316d640336153714d1c90622bbdc1b (diff) | |
download | scummvm-rg350-478257f624cf665b315192ebab48732c54bbcc4b.tar.gz scummvm-rg350-478257f624cf665b315192ebab48732c54bbcc4b.tar.bz2 scummvm-rg350-478257f624cf665b315192ebab48732c54bbcc4b.zip |
Instead of reading an entire compressed sound into a memory stream, use a
slightly extended SeekableSubReadStream to stream the sound from a file instead.
This change is experimental, so it should almost certainly not go into 0.13.
svn-id: r38637
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sword2/music.cpp | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/engines/sword2/music.cpp b/engines/sword2/music.cpp index 3b5a09578b..4e7aa74c71 100644 --- a/engines/sword2/music.cpp +++ b/engines/sword2/music.cpp @@ -49,6 +49,39 @@ namespace Sword2 { +// This class behaves like SeekableSubReadStream, except it remembers where the +// previous read() or seek() took it, so that it can continue from that point +// the next time. This is because we're frequently streaming two pieces of +// music from the same file. + +class SafeSubReadStream : public Common::SeekableSubReadStream { +protected: + uint32 _previousPos; +public: + SafeSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, bool disposeParentStream); + virtual uint32 read(void *dataPtr, uint32 dataSize); + virtual bool seek(int32 offset, int whence = SEEK_SET); +}; + +SafeSubReadStream::SafeSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, bool disposeParentStream) + : SeekableSubReadStream(parentStream, begin, end, disposeParentStream) { + _previousPos = 0; +} + +uint32 SafeSubReadStream::read(void *dataPtr, uint32 dataSize) { + uint32 result; + SeekableSubReadStream::seek(_previousPos); + result = SeekableSubReadStream::read(dataPtr, dataSize); + _previousPos = pos(); + return result; +} + +bool SafeSubReadStream::seek(int32 offset, int whence) { + bool result = SeekableSubReadStream::seek(offset, whence); + _previousPos = pos(); + return result; +} + static Audio::AudioStream *makeCLUStream(Common::File *fp, int size); static Audio::AudioStream *getAudioStream(SoundFileHandle *fh, const char *base, int cd, uint32 id, uint32 *numSamples) { @@ -147,27 +180,24 @@ static Audio::AudioStream *getAudioStream(SoundFileHandle *fh, const char *base, fh->file.seek(pos, SEEK_SET); - Common::MemoryReadStream *tmp = 0; + SafeSubReadStream *tmp = 0; switch (fh->fileType) { case kCLUMode: return makeCLUStream(&fh->file, enc_len); #ifdef USE_MAD case kMP3Mode: - tmp = fh->file.readStream(enc_len); - assert(tmp); + tmp = new SafeSubReadStream(&fh->file, pos, pos + enc_len, false); return Audio::makeMP3Stream(tmp, true); #endif #ifdef USE_VORBIS case kVorbisMode: - tmp = fh->file.readStream(enc_len); - assert(tmp); + tmp = new SafeSubReadStream(&fh->file, pos, pos + enc_len, false); return Audio::makeVorbisStream(tmp, true); #endif #ifdef USE_FLAC case kFlacMode: - tmp = fh->file.readStream(enc_len); - assert(tmp); + tmp = new SafeSubReadStream(&fh->file, pos, pos + enc_len, false); return Audio::makeFlacStream(tmp, true); #endif default: |